@qikdev/sdk 0.1.207 → 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 +1589 -1564
- package/package.json +1 -1
- package/src/api/qik.content.js +68 -4
- 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,11 +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
|
|
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;
|
|
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 }) {
|
|
75
101
|
function inflate(val) {
|
|
76
102
|
if (typeof val === "string" && val[0] === "~") {
|
|
77
103
|
return strings[parseInt(val.slice(1))];
|
|
@@ -89,6 +115,44 @@ export default function (qik) {
|
|
|
89
115
|
return types.map(inflate);
|
|
90
116
|
}
|
|
91
117
|
|
|
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
|
+
}
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const worker = await getInflateWorker();
|
|
131
|
+
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
const handler = (e) => {
|
|
134
|
+
worker.removeEventListener("message", handler);
|
|
135
|
+
worker.removeEventListener("error", errorHandler);
|
|
136
|
+
resolve(e.data);
|
|
137
|
+
};
|
|
138
|
+
|
|
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
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
92
156
|
/**
|
|
93
157
|
*
|
|
94
158
|
* Retrieves the glossary of all content types visible to the requesting user.
|
|
@@ -133,9 +197,9 @@ export default function (qik) {
|
|
|
133
197
|
// Now we have the glossary
|
|
134
198
|
const { data } = await inflightGlossaryRequest;
|
|
135
199
|
|
|
136
|
-
// Inflate if compressed format
|
|
200
|
+
// Inflate if compressed format (async to avoid blocking UI)
|
|
137
201
|
const glossaryData =
|
|
138
|
-
data._s && data._k && data.types ? inflateGlossary(data) : data;
|
|
202
|
+
data._s && data._k && data.types ? await inflateGlossary(data) : data;
|
|
139
203
|
|
|
140
204
|
// Cache it for later
|
|
141
205
|
glossaryCache.set("glossary", glossaryData);
|
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
|
+
};
|