somehow i lost this file and had to rewrite it. now it's even better than before!

This commit is contained in:
Henry Jameson 2024-09-19 21:42:14 +03:00
parent af3b2e3dc9
commit 0c91c37645
2 changed files with 38 additions and 11 deletions

View file

@ -0,0 +1,38 @@
import { unroll } from './iss_utils.js'
const serializeShadow = s => `{${s.inset ? 'inset ' : ''}${s.x} ${s.y} ${s.blur} ${s.spread} ${s.color} / ${s.alpha}}`
export const serialize = (ruleset) => {
return ruleset.map((rule) => {
if (Object.keys(rule.directives || {}).length === 0) return false
const header = unroll(rule).reverse().map(rule => {
const { component } = rule
const newVariant = rule.variant === 'normal' ? '' : ('.' + rule.variant)
const newState = rule.state.filter(st => st !== 'normal')
return `${component}${newVariant}${newState.map(st => ':' + st).join('')}`
}).join(' ')
const content = Object.entries(rule.directives).map(([directive, value]) => {
if (directive.startsWith('--')) {
const [valType, newValue] = value.split('|') // only first one! intentional!
switch (valType) {
case 'shadow':
return ` ${directive}: ${newValue.map(serializeShadow).join(', ')}`
default:
return ` ${directive}: ${newValue}`
}
} else {
switch (directive) {
case 'shadow':
return ` ${directive}: ${value.map(serializeShadow).join(', ')}`
default:
return ` ${directive}: ${value}`
}
}
})
return `${header} {\n${content.join(';\n')}\n}`
}).filter(x => x).join('\n\n')
}

View file

@ -519,17 +519,6 @@ export const init = ({
}
})
const serializedData = serialize(eager)
const file = new File(serializedData, 'ruleset.piss')
const blobUrl = URL.createObjectURL(file)
const a = document.createElement('a')
a.href = blobUrl
a.download = 'ruleset.piss'
document.body.appendChild(a)
a.dispatchEvent(new MouseEvent('click'))
URL.revokeObjectURL(blobUrl)
document.body.removeChild(a)
return {
lazy,
eager,