shadow slots work + minor fixes
This commit is contained in:
parent
7041d29ede
commit
8a21594dbc
10 changed files with 153 additions and 88 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { convert, brightness } from 'chromatism'
|
||||
import { alphaBlend, relativeLuminance } from '../color_convert/color_convert.js'
|
||||
|
||||
export const process = (text, functions, findColor, dynamicVars, staticVars) => {
|
||||
export const process = (text, functions, { findColor, findShadow }, { dynamicVars, staticVars }) => {
|
||||
const { funcName, argsString } = /\$(?<funcName>\w+)\((?<argsString>[#a-zA-Z0-9-,.'"\s]*)\)/.exec(text).groups
|
||||
const args = argsString.split(/,/g).map(a => a.trim())
|
||||
|
||||
|
|
@ -9,27 +9,27 @@ export const process = (text, functions, findColor, dynamicVars, staticVars) =>
|
|||
if (args.length < func.argsNeeded) {
|
||||
throw new Error(`$${funcName} requires at least ${func.argsNeeded} arguments, but ${args.length} were provided`)
|
||||
}
|
||||
return func.exec(args, findColor, dynamicVars, staticVars)
|
||||
return func.exec(args, { findColor, findShadow }, { dynamicVars, staticVars })
|
||||
}
|
||||
|
||||
export const colorFunctions = {
|
||||
alpha: {
|
||||
argsNeeded: 2,
|
||||
exec: (args, findColor, dynamicVars, staticVars) => {
|
||||
exec: (args, { findColor }, { dynamicVars, staticVars }) => {
|
||||
const [color, amountArg] = args
|
||||
|
||||
const colorArg = convert(findColor(color, dynamicVars, staticVars)).rgb
|
||||
const colorArg = convert(findColor(color, { dynamicVars, staticVars })).rgb
|
||||
const amount = Number(amountArg)
|
||||
return { ...colorArg, a: amount }
|
||||
}
|
||||
},
|
||||
blend: {
|
||||
argsNeeded: 3,
|
||||
exec: (args, findColor, dynamicVars, staticVars) => {
|
||||
exec: (args, { findColor }, { dynamicVars, staticVars }) => {
|
||||
const [backgroundArg, amountArg, foregroundArg] = args
|
||||
|
||||
const background = convert(findColor(backgroundArg, dynamicVars, staticVars)).rgb
|
||||
const foreground = convert(findColor(foregroundArg, dynamicVars, staticVars)).rgb
|
||||
const background = convert(findColor(backgroundArg, { dynamicVars, staticVars })).rgb
|
||||
const foreground = convert(findColor(foregroundArg, { dynamicVars, staticVars })).rgb
|
||||
const amount = Number(amountArg)
|
||||
|
||||
return alphaBlend(background, amount, foreground)
|
||||
|
|
@ -37,10 +37,10 @@ export const colorFunctions = {
|
|||
},
|
||||
mod: {
|
||||
argsNeeded: 2,
|
||||
exec: (args, findColor, dynamicVars, staticVars) => {
|
||||
exec: (args, { findColor }, { dynamicVars, staticVars }) => {
|
||||
const [colorArg, amountArg] = args
|
||||
|
||||
const color = convert(findColor(colorArg, dynamicVars, staticVars)).rgb
|
||||
const color = convert(findColor(colorArg, { dynamicVars, staticVars })).rgb
|
||||
const amount = Number(amountArg)
|
||||
|
||||
const effectiveBackground = dynamicVars.lowerLevelBackground
|
||||
|
|
@ -54,7 +54,7 @@ export const colorFunctions = {
|
|||
export const shadowFunctions = {
|
||||
borderSide: {
|
||||
argsNeeded: 3,
|
||||
exec: (args, findColor, dynamicVars, staticVars) => {
|
||||
exec: (args, { findColor }) => {
|
||||
const [color, side, alpha = '1', widthArg = '1', inset = 'inset'] = args
|
||||
|
||||
const width = Number(widthArg)
|
||||
|
|
@ -86,7 +86,7 @@ export const shadowFunctions = {
|
|||
break
|
||||
}
|
||||
})
|
||||
return targetShadow
|
||||
return [targetShadow]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue