@qikdev/sdk 0.1.208 → 0.1.209
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-DEO1byBA.js +24 -0
- package/dist/main.js +1699 -1684
- package/package.json +1 -1
- package/src/api/qik.content.js +58 -23
- package/src/version.js +1 -1
- package/src/workers/inflate-glossary.worker.js +25 -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;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get or create the inflate worker instance
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
async function getInflateWorker() {
|
|
90
|
+
if (inflateWorker) return inflateWorker;
|
|
91
|
+
const module = await loadWorkerModule();
|
|
92
|
+
inflateWorker = new module.default();
|
|
93
|
+
return inflateWorker;
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
/**
|
|
85
|
-
*
|
|
86
|
-
* Processes in chunks to avoid blocking the main thread
|
|
97
|
+
* Sync fallback for SSR/Node environments where Workers don't exist
|
|
87
98
|
* @private
|
|
88
99
|
*/
|
|
89
|
-
|
|
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,45 @@ export default function (qik) {
|
|
|
101
112
|
}
|
|
102
113
|
return val;
|
|
103
114
|
}
|
|
115
|
+
return types.map(inflate);
|
|
116
|
+
}
|
|
104
117
|
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Inflate compressed glossary data using a Web Worker
|
|
120
|
+
* Runs on a separate thread to avoid blocking the UI
|
|
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
|
+
}
|
|
107
128
|
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
results.push(...chunk.map(inflate));
|
|
129
|
+
try {
|
|
130
|
+
const worker = await getInflateWorker();
|
|
111
131
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
const handler = (e) => {
|
|
134
|
+
worker.removeEventListener("message", handler);
|
|
135
|
+
worker.removeEventListener("error", errorHandler);
|
|
136
|
+
resolve(e.data);
|
|
137
|
+
};
|
|
117
138
|
|
|
118
|
-
|
|
139
|
+
const errorHandler = () => {
|
|
140
|
+
worker.removeEventListener("message", handler);
|
|
141
|
+
worker.removeEventListener("error", errorHandler);
|
|
142
|
+
// Fallback to sync on error
|
|
143
|
+
resolve(inflateGlossarySync(data));
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
worker.addEventListener("message", handler);
|
|
147
|
+
worker.addEventListener("error", errorHandler);
|
|
148
|
+
worker.postMessage(data);
|
|
149
|
+
});
|
|
150
|
+
} catch {
|
|
151
|
+
// Dynamic import failed (Node.js or unsupported environment)
|
|
152
|
+
return inflateGlossarySync(data);
|
|
153
|
+
}
|
|
119
154
|
}
|
|
120
155
|
|
|
121
156
|
/**
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.1.
|
|
1
|
+
export const version = "0.1.209";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Worker for inflating compressed glossary data
|
|
3
|
+
* Runs on a separate thread to avoid blocking the main UI
|
|
4
|
+
*/
|
|
5
|
+
self.onmessage = 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
|
+
const result = types.map(inflate);
|
|
24
|
+
self.postMessage(result);
|
|
25
|
+
};
|