commit: 0c91c376456520b0b58779696067bbf78e46bfd0
parent af3b2e3dc9043e66806be85869d867e6b0d23c3c
Author: Henry Jameson <me@hjkos.com>
Date: Thu, 19 Sep 2024 21:42:14 +0300
somehow i lost this file and had to rewrite it. now it's even better than before!
Diffstat:
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/src/services/theme_data/iss_serializer.js b/src/services/theme_data/iss_serializer.js
@@ -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')
+}
diff --git a/src/services/theme_data/theme_data_3.service.js b/src/services/theme_data/theme_data_3.service.js
@@ -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,