@qikdev/sdk 0.1.208 → 0.1.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/inflate-glossary.worker-CGZQmJtn.js +24 -0
- package/dist/main.js +1739 -1723
- package/package.json +1 -1
- package/src/api/qik.content.js +65 -23
- package/src/version.js +1 -1
- package/src/workers/inflate-glossary.worker.js +38 -0
package/package.json
CHANGED
package/src/api/qik.content.js
CHANGED
|
@@ -67,26 +67,37 @@ export default function (qik) {
|
|
|
67
67
|
|
|
68
68
|
let inflightGlossaryRequest;
|
|
69
69
|
|
|
70
|
+
let inflateWorker = null;
|
|
71
|
+
let workerLoadPromise = null;
|
|
72
|
+
|
|
70
73
|
/**
|
|
71
|
-
*
|
|
74
|
+
* Lazily load the Worker module (Vite-specific import)
|
|
72
75
|
* @private
|
|
73
76
|
*/
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
});
|
|
77
|
+
async function loadWorkerModule() {
|
|
78
|
+
if (workerLoadPromise) return workerLoadPromise;
|
|
79
|
+
workerLoadPromise = import(
|
|
80
|
+
"../workers/inflate-glossary.worker.js?worker&inline"
|
|
81
|
+
);
|
|
82
|
+
return workerLoadPromise;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/**
|
|
85
|
-
*
|
|
86
|
-
* Processes in chunks to avoid blocking the main thread
|
|
86
|
+
* Get or create the inflate worker instance
|
|
87
87
|
* @private
|
|
88
88
|
*/
|
|
89
|
-
async function
|
|
89
|
+
async function getInflateWorker() {
|
|
90
|
+
if (inflateWorker) return inflateWorker;
|
|
91
|
+
const module = await loadWorkerModule();
|
|
92
|
+
inflateWorker = new module.default();
|
|
93
|
+
return inflateWorker;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Sync fallback for SSR/Node environments where Workers don't exist
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
function inflateGlossarySync({ _s: strings, _k: keyMap, types }) {
|
|
90
101
|
function inflate(val) {
|
|
91
102
|
if (typeof val === "string" && val[0] === "~") {
|
|
92
103
|
return strings[parseInt(val.slice(1))];
|
|
@@ -101,21 +112,52 @@ export default function (qik) {
|
|
|
101
112
|
}
|
|
102
113
|
return val;
|
|
103
114
|
}
|
|
115
|
+
return types.map(inflate);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Inflate compressed glossary data using a Web Worker
|
|
120
|
+
* Receives results in chunks to avoid blocking during deserialization
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
async function inflateGlossary(data) {
|
|
124
|
+
// Fallback for non-browser environments (SSR/Node)
|
|
125
|
+
if (typeof Worker === "undefined") {
|
|
126
|
+
return inflateGlossarySync(data);
|
|
127
|
+
}
|
|
104
128
|
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
try {
|
|
130
|
+
const worker = await getInflateWorker();
|
|
107
131
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
results.push(...chunk.map(inflate));
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
const results = [];
|
|
111
134
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
}
|
|
135
|
+
const handler = (e) => {
|
|
136
|
+
const { chunk, done } = e.data;
|
|
137
|
+
results.push(...chunk);
|
|
117
138
|
|
|
118
|
-
|
|
139
|
+
if (done) {
|
|
140
|
+
worker.removeEventListener("message", handler);
|
|
141
|
+
worker.removeEventListener("error", errorHandler);
|
|
142
|
+
resolve(results);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const errorHandler = () => {
|
|
147
|
+
worker.removeEventListener("message", handler);
|
|
148
|
+
worker.removeEventListener("error", errorHandler);
|
|
149
|
+
// Fallback to sync on error
|
|
150
|
+
resolve(inflateGlossarySync(data));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
worker.addEventListener("message", handler);
|
|
154
|
+
worker.addEventListener("error", errorHandler);
|
|
155
|
+
worker.postMessage(data);
|
|
156
|
+
});
|
|
157
|
+
} catch {
|
|
158
|
+
// Dynamic import failed (Node.js or unsupported environment)
|
|
159
|
+
return inflateGlossarySync(data);
|
|
160
|
+
}
|
|
119
161
|
}
|
|
120
162
|
|
|
121
163
|
/**
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.1.
|
|
1
|
+
export const version = "0.1.210";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Worker for inflating compressed glossary data
|
|
3
|
+
* Streams results back in chunks with delays to avoid blocking the main thread
|
|
4
|
+
*/
|
|
5
|
+
self.onmessage = async function (e) {
|
|
6
|
+
const { _s: strings, _k: keyMap, types } = e.data;
|
|
7
|
+
|
|
8
|
+
function inflate(val) {
|
|
9
|
+
if (typeof val === "string" && val[0] === "~") {
|
|
10
|
+
return strings[parseInt(val.slice(1))];
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(val)) return val.map(inflate);
|
|
13
|
+
if (val && typeof val === "object") {
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const [k, v] of Object.entries(val)) {
|
|
16
|
+
result[keyMap[k] || k] = inflate(v);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
return val;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Send results back in chunks with small delays
|
|
24
|
+
// This lets the main thread process each chunk before receiving the next
|
|
25
|
+
const CHUNK_SIZE = 20;
|
|
26
|
+
const total = types.length;
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < total; i += CHUNK_SIZE) {
|
|
29
|
+
const chunk = types.slice(i, i + CHUNK_SIZE).map(inflate);
|
|
30
|
+
const done = i + CHUNK_SIZE >= total;
|
|
31
|
+
self.postMessage({ chunk, done });
|
|
32
|
+
|
|
33
|
+
// Small delay between chunks to let main thread breathe
|
|
34
|
+
if (!done) {
|
|
35
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|