Convert multiple pages into SPA
This commit is contained in:
@@ -2,10 +2,38 @@ import parse from "pure-color/parse";
|
||||
import rgb2hsl from "pure-color/convert/rgb2hsl";
|
||||
import hsl2rgb from "pure-color/convert/hsl2rgb";
|
||||
import rgb2hex from "pure-color/convert/rgb2hex";
|
||||
import type { FSNode, FSNodeProperties } from "lib/FilesystemAPI";
|
||||
|
||||
type Style = {
|
||||
input_background: string,
|
||||
input_hover_background: string,
|
||||
input_text: string,
|
||||
highlight_color: string,
|
||||
highlight_background: string,
|
||||
highlight_text_color: string,
|
||||
link_color: string,
|
||||
danger_color: string,
|
||||
danger_text_color: string,
|
||||
background_color: string,
|
||||
background: string,
|
||||
background_text_color: string,
|
||||
background_pattern_color: string,
|
||||
body_color: string,
|
||||
body_background: string,
|
||||
body_text_color: string,
|
||||
shaded_background: string,
|
||||
separator: string,
|
||||
shadow_color: string,
|
||||
card_color: string,
|
||||
background_image: string,
|
||||
background_image_size: string,
|
||||
background_image_position: string,
|
||||
background_image_repeat: string,
|
||||
}
|
||||
|
||||
// Generate a branding style from a file's properties map
|
||||
export const branding_from_path = path => {
|
||||
let style = {}
|
||||
export const branding_from_path = (path: Array<FSNode>) => {
|
||||
let style = <Style>{}
|
||||
for (let node of path) {
|
||||
add_styles(style, node.properties)
|
||||
}
|
||||
@@ -15,17 +43,17 @@ export const branding_from_path = path => {
|
||||
|
||||
// The last style which was generated is cached, when we don't have a complete
|
||||
// path to generate the style with we will use the cached style as a basis
|
||||
let last_generated_style = {}
|
||||
export const branding_from_node = node => {
|
||||
let last_generated_style = <Style>{}
|
||||
export const branding_from_node = (node: FSNode) => {
|
||||
add_styles(last_generated_style, node.properties)
|
||||
return gen_css(last_generated_style)
|
||||
}
|
||||
|
||||
export const css_from_path = path => {
|
||||
export const css_from_path = (path: Array<FSNode>) => {
|
||||
return gen_css(branding_from_path(path))
|
||||
}
|
||||
|
||||
const gen_css = style => {
|
||||
const gen_css = (style: Style) => {
|
||||
return Object.entries(style).map(([key, value]) => `--${key}:${value}`).join(';');
|
||||
}
|
||||
|
||||
@@ -33,7 +61,7 @@ const gen_css = style => {
|
||||
// existing style which is passed as the first argument. When navigating to a
|
||||
// path this function is executed on every member of the path so all the styles
|
||||
// get combined
|
||||
const add_styles = (style, properties) => {
|
||||
const add_styles = (style: Style, properties: FSNodeProperties) => {
|
||||
if (!properties || !properties.branding_enabled || properties.branding_enabled !== "true") {
|
||||
return
|
||||
}
|
||||
@@ -83,7 +111,7 @@ const add_styles = (style, properties) => {
|
||||
}
|
||||
}
|
||||
|
||||
const add_contrast = (color, amt) => {
|
||||
const add_contrast = (color: string, amt: number) => {
|
||||
let hsl = rgb2hsl(parse(color)) // Convert hex to hsl
|
||||
// If the lightness is less than 40 it is considered a dark colour. This
|
||||
// threshold is 40 instead of 50 because overall dark text is more legible
|
||||
@@ -96,20 +124,20 @@ const add_contrast = (color, amt) => {
|
||||
}
|
||||
|
||||
// Darken and desaturate. Only used for shadows
|
||||
const darken = (color, percent) => {
|
||||
const darken = (color: string, percent: number) => {
|
||||
let hsl = rgb2hsl(parse(color)) // Convert hex to hsl
|
||||
hsl[1] = hsl[1] * percent
|
||||
hsl[2] = hsl[2] * percent
|
||||
return rgb2hex(hsl2rgb(hsl)) // Convert back to hex
|
||||
}
|
||||
|
||||
const set_alpha = (color, amt) => {
|
||||
const set_alpha = (color: string, amt: number) => {
|
||||
let rgb = parse(color)
|
||||
rgb.push(amt)
|
||||
return "rgba(" + rgb.join(", ") + ")"
|
||||
}
|
||||
|
||||
const generate_link_color = (link_color, body_color) => {
|
||||
const generate_link_color = (link_color: string, body_color: string) => {
|
||||
let link = rgb2hsl(parse(link_color))
|
||||
let body = rgb2hsl(parse(body_color))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user