dotfiles/build/render.js
2025-03-25 17:12:09 +01:00

78 lines
2.3 KiB
JavaScript

const mustache = require( 'mustache' );
const colorThief = require( '@janishutz/colorthief' );
const convert = require( 'color-convert' );
const build = ( wallpaper, lockpaper, theme ) => {
console.log( '\n=> Extracting colours' );
// Extract colour palette from chosen wallpaper using Color-Thief
colorThief.getPalette( wallpaper ).then( palette => {
// Define view options (for rendering with mustache)
console.log( palette );
const view = {
'wallpaper-path': wallpaper,
'lockpaper-path': lockpaper,
// Colours
'colour-foreground-hex': renderColourAsHex( palette[ 0 ] ),
'colour-foreground-rgb': renderColourAsRGB( palette[ 0 ] ),
'colour-accent-hex': renderColourAsHex( palette[ 1 ] ),
'colour-accent-rgb': renderColourAsRGB( palette[ 1 ] ),
'colour-accent-2-hex': renderColourAsHex( palette[ 2 ] ),
'colour-accent-2-rgb': renderColourAsRGB( palette[ 2 ] ),
'colour-accent-3-hex': renderColourAsHex( palette[ 3 ] ),
'colour-accent-3-rgb': renderColourAsRGB( palette[ 3 ] ),
'colour-background-hex': '',
'colour-background-rgb': '',
'colour-shadow-hex': '',
'colour-shadow-rgb': '',
'colour-inavtive-hex': '',
'colour-inavtive-rgb': '',
// General style
'style-corner-rounding': 5000,
// Fonts
'font-primary': 'Comfortaa',
'font-accent': 'Source Code Pro',
// yazi theme
'yazi-theme': 'tokyo-night',
// Path to this repo on disk
'path-to-dotfiles': __dirname.slice(0, __dirname.length - 5),
}
// TODO: Maybe bar config? Reordering? Same for quick actions?
console.log( view );
} ).catch( () => {
console.error( '\n=> Failed to load image or retrieve colour palette from it' );
} )
}
const colours = {
}
const fonts = {
}
const yaziThemes = {
}
const renderColourAsHex = ( colour ) => {
return '#' + convert.default.rgb.hex( colour[ 0 ], colour[ 1 ], colour[ 2 ] );
}
const renderColourAsRGB = ( colour ) => {
return `rgb( ${ colour[ 0 ] }, ${ colour[ 1 ] }, ${ colour[ 2 ] } )`
}
const render = ( templatePath, view ) => {
}
module.exports = build;