aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2024-09-19 20:37:14 +0300
committerHenry Jameson <me@hjkos.com>2024-09-19 20:37:14 +0300
commitaf3b2e3dc9043e66806be85869d867e6b0d23c3c (patch)
treef7b720759b49f5581766a913cc60f260c83606e9 /src
parent74e5bb9104551bfd8105ef6780c40502e9087adc (diff)
temp
Diffstat (limited to 'src')
-rw-r--r--src/services/theme_data/iss_deserializer.js44
-rw-r--r--src/services/theme_data/theme_data_3.service.js30
2 files changed, 70 insertions, 4 deletions
diff --git a/src/services/theme_data/iss_deserializer.js b/src/services/theme_data/iss_deserializer.js
index 44a0fade..431e1b94 100644
--- a/src/services/theme_data/iss_deserializer.js
+++ b/src/services/theme_data/iss_deserializer.js
@@ -1,3 +1,43 @@
-export const deserializer (string) {
-let level = 0
+// this works nearly the same as HTML tree converter
+export const deserialize = (input) => {
+ const buffer = []
+ let textBuffer = ''
+
+ const getCurrentBuffer = () => {
+ let current = buffer[buffer.length - 1][1]
+ if (current == null) {
+ current = { name: null, content: [] }
+ }
+ buffer.push(current)
+ return current
+ }
+
+ // Processes current line buffer, adds it to output buffer and clears line buffer
+ const flushText = (content) => {
+ if (textBuffer === '') return
+ if (content) {
+ getCurrentBuffer().content.push(textBuffer)
+ } else {
+ getCurrentBuffer().name = textBuffer
+ }
+ textBuffer = ''
+ }
+
+ for (let i = 0; i < input.length; i++) {
+ const char = input[i]
+
+ if (char === ';') {
+ flushText(true)
+ } else if (char === '{') {
+ flushText(false)
+ } else if (char === '}') {
+ buffer.push({ name: null, content: [] })
+ textBuffer = ''
+ } else {
+ textBuffer += char
+ }
+ }
+
+ flushText()
+ return buffer
}
diff --git a/src/services/theme_data/theme_data_3.service.js b/src/services/theme_data/theme_data_3.service.js
index cf58da11..cac450a8 100644
--- a/src/services/theme_data/theme_data_3.service.js
+++ b/src/services/theme_data/theme_data_3.service.js
@@ -23,6 +23,9 @@ import {
findRules
} from './iss_utils.js'
import { parseCssShadow } from './css_utils.js'
+import {
+ serialize
+} from './iss_serializer.js'
// Ensuring the order of components
const components = {
@@ -504,9 +507,32 @@ export const init = ({
console.debug('Eager processing took ' + (t2 - t1) + ' ms')
}
+ // optimization to traverse big-ass array only once instead of twice
+ const eager = []
+ const lazy = []
+
+ result.forEach(x => {
+ if (typeof x === 'function') {
+ lazy.push(x)
+ } else {
+ eager.push(x)
+ }
+ })
+
+ 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: result.filter(x => typeof x === 'function'),
- eager: result.filter(x => typeof x !== 'function'),
+ lazy,
+ eager,
staticVars,
engineChecksum
}