@qwik.dev/core 2.0.0-beta.30 → 2.0.0-beta.31
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/backpatch/package.json +1 -1
- package/dist/build/package.json +1 -1
- package/dist/cli.mjs +215 -170
- package/dist/core-internal.d.ts +51 -11
- package/dist/core.min.mjs +2 -2
- package/dist/core.mjs +9314 -8994
- package/dist/core.mjs.map +1 -1
- package/dist/core.prod.mjs +5672 -5412
- package/dist/insights/vite/index.mjs +36 -33
- package/dist/loader/index.mjs +2 -2
- package/dist/loader/package.json +1 -1
- package/dist/optimizer.mjs +787 -763
- package/dist/preloader.mjs +210 -112
- package/dist/qwikloader.debug.js +26 -13
- package/dist/qwikloader.js +1 -1
- package/dist/server.mjs +266 -92
- package/dist/server.prod.mjs +552 -364
- package/dist/testing/index.d.ts +4 -1
- package/dist/testing/index.mjs +530 -212
- package/dist/testing/package.json +1 -1
- package/package.json +3 -3
package/dist/preloader.mjs
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { isBrowser } from "@qwik.dev/core/build";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
1
|
+
import { isServer, isBrowser as isBrowser$2 } from "@qwik.dev/core/build";
|
|
2
|
+
const createMacroTask = (e) => {
|
|
3
|
+
let t;
|
|
4
|
+
if (typeof MessageChannel !== "undefined") {
|
|
5
|
+
const n = new MessageChannel();
|
|
6
|
+
n.port1.onmessage = () => e();
|
|
7
|
+
t = () => n.port2.postMessage(null);
|
|
8
|
+
} else t = () => setTimeout(e);
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
const isBrowser$1 = !isServer;
|
|
12
|
+
const doc = isBrowser$1 ? document : void 0;
|
|
13
|
+
const config = { t: 0, o: 25, u: 0.65 };
|
|
14
|
+
const rel = isBrowser$1 && doc.createElement("link").relList?.supports?.("modulepreload") ? "modulePreload" : "preload";
|
|
15
|
+
const loadStart = performance.now();
|
|
6
16
|
const isJSRegex = /\.[mc]?js$/;
|
|
17
|
+
const yieldInterval = 1e3 / 60;
|
|
7
18
|
const BundleImportState_None = 0;
|
|
8
19
|
const BundleImportState_Queued = 1;
|
|
9
20
|
const BundleImportState_Preload = 2;
|
|
@@ -13,178 +24,265 @@ const bundles = /* @__PURE__ */ new Map();
|
|
|
13
24
|
let queueDirty;
|
|
14
25
|
let preloadCount = 0;
|
|
15
26
|
const queue = [];
|
|
27
|
+
const nextTriggerMacroTask = createMacroTask(trigger);
|
|
28
|
+
const nextAdjustmentMacroTask = createMacroTask(processPendingAdjustments);
|
|
29
|
+
let isTriggerScheduled = 0;
|
|
30
|
+
let isAdjustmentScheduled = 0;
|
|
31
|
+
let isProcessingAdjustments = 0;
|
|
32
|
+
const shouldYieldInBrowser = isBrowser$2;
|
|
33
|
+
const adjustmentStack = [];
|
|
16
34
|
const log = (...e) => {
|
|
17
|
-
console.log(`Preloader ${
|
|
35
|
+
console.log(`Preloader ${performance.now() - loadStart}ms ${preloadCount}/${queue.length} queued>`, ...e);
|
|
18
36
|
};
|
|
19
37
|
const sortQueue = () => {
|
|
20
38
|
if (queueDirty) {
|
|
21
|
-
queue.sort((e, t) => e.
|
|
39
|
+
queue.sort((e, t) => e.l - t.l);
|
|
22
40
|
queueDirty = 0;
|
|
23
41
|
}
|
|
24
42
|
};
|
|
25
|
-
|
|
43
|
+
function trigger() {
|
|
44
|
+
isTriggerScheduled = 0;
|
|
26
45
|
if (!queue.length) return;
|
|
27
46
|
sortQueue();
|
|
47
|
+
const e = performance.now() + yieldInterval;
|
|
48
|
+
let t = 0;
|
|
28
49
|
while (queue.length) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const o = 1 -
|
|
32
|
-
const
|
|
50
|
+
const n = queue[0];
|
|
51
|
+
const s = n.l;
|
|
52
|
+
const o = 1 - s;
|
|
53
|
+
const r = graph ? config.o : (
|
|
33
54
|
// While the graph is not available, we limit to 5 preloads
|
|
34
55
|
5
|
|
35
56
|
);
|
|
36
|
-
if (o >= 0.99 || preloadCount <
|
|
57
|
+
if (o >= 0.99 || preloadCount < r) {
|
|
37
58
|
queue.shift();
|
|
38
|
-
preloadOne(
|
|
59
|
+
preloadOne(n);
|
|
60
|
+
if (performance.now() >= e) {
|
|
61
|
+
t = 1;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
39
64
|
} else break;
|
|
40
65
|
}
|
|
66
|
+
if (t && queue.length && !isTriggerScheduled) {
|
|
67
|
+
isTriggerScheduled = 1;
|
|
68
|
+
nextTriggerMacroTask();
|
|
69
|
+
}
|
|
41
70
|
if (config.t && !queue.length) {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
log(`>>>> done ${
|
|
71
|
+
const e2 = [...bundles.values()].filter((e3) => e3.i > BundleImportState_None);
|
|
72
|
+
const t2 = e2.reduce((e3, t3) => e3 + t3.m, 0);
|
|
73
|
+
const n = e2.reduce((e3, t3) => e3 + t3.p, 0);
|
|
74
|
+
log(`>>>> done ${e2.length}/${bundles.size} total: ${t2}ms waited, ${n}ms loaded`);
|
|
46
75
|
}
|
|
76
|
+
}
|
|
77
|
+
const enqueueAdjustment = (e, t, n, s) => {
|
|
78
|
+
adjustmentStack.unshift({ $: e, l: t, B: s, h: n });
|
|
47
79
|
};
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
e.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
const processAdjustmentFrame = () => {
|
|
81
|
+
const e = adjustmentStack[adjustmentStack.length - 1];
|
|
82
|
+
const t = e.$;
|
|
83
|
+
if (e.S) {
|
|
84
|
+
const n2 = e.j;
|
|
85
|
+
if (n2 >= e.S.length) {
|
|
86
|
+
adjustmentStack.pop();
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const s = e.S[n2];
|
|
90
|
+
e.j = n2 + 1;
|
|
91
|
+
const o = getBundle(s.k);
|
|
92
|
+
if (o.l === 0) return 1;
|
|
93
|
+
const r = 1 - t.l;
|
|
94
|
+
let a;
|
|
95
|
+
if (r === 1 || r >= 0.99 && e.h.T < 100) {
|
|
96
|
+
e.h.T++;
|
|
97
|
+
a = Math.min(0.01, 1 - s.I);
|
|
98
|
+
} else {
|
|
99
|
+
const e2 = 1 - s.I * r;
|
|
100
|
+
const t2 = s.A;
|
|
101
|
+
const n3 = e2 / t2;
|
|
102
|
+
a = Math.max(0.02, o.l * n3);
|
|
103
|
+
s.A = n3;
|
|
104
|
+
}
|
|
105
|
+
adjustmentStack.push({ $: o, l: a, B: e.B, h: e.h });
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
if (e.B?.has(t)) {
|
|
109
|
+
adjustmentStack.pop();
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
const n = t.l;
|
|
113
|
+
t.l = e.l;
|
|
114
|
+
if (n - t.l < 0.01) {
|
|
115
|
+
adjustmentStack.pop();
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
75
118
|
if (
|
|
76
119
|
// don't queue until we have initialized the preloader
|
|
77
|
-
base != null &&
|
|
120
|
+
base != null && t.i < BundleImportState_Preload
|
|
78
121
|
) {
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
queue.push(
|
|
82
|
-
config.t && log(`queued ${Math.round((1 -
|
|
122
|
+
if (t.i === BundleImportState_None) {
|
|
123
|
+
t.i = BundleImportState_Queued;
|
|
124
|
+
queue.push(t);
|
|
125
|
+
config.t && log(`queued ${Math.round((1 - t.l) * 100)}%`, t.k);
|
|
83
126
|
}
|
|
84
127
|
queueDirty = 1;
|
|
85
128
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
if (t.S?.length) {
|
|
130
|
+
const n2 = e.B || /* @__PURE__ */ new Set();
|
|
131
|
+
n2.add(t);
|
|
132
|
+
e.B = n2;
|
|
133
|
+
e.S = t.S;
|
|
134
|
+
e.j = 0;
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
adjustmentStack.pop();
|
|
138
|
+
return 0;
|
|
139
|
+
};
|
|
140
|
+
function processPendingAdjustments() {
|
|
141
|
+
if (isProcessingAdjustments || !adjustmentStack.length) return;
|
|
142
|
+
isAdjustmentScheduled = 0;
|
|
143
|
+
isProcessingAdjustments = 1;
|
|
144
|
+
const e = shouldYieldInBrowser ? performance.now() + yieldInterval : 0;
|
|
145
|
+
let t = 0;
|
|
146
|
+
while (adjustmentStack.length) {
|
|
147
|
+
t = 1;
|
|
148
|
+
const n = processAdjustmentFrame();
|
|
149
|
+
if (shouldYieldInBrowser && n && performance.now() >= e) {
|
|
150
|
+
if (!isAdjustmentScheduled) {
|
|
151
|
+
isAdjustmentScheduled = 1;
|
|
152
|
+
nextAdjustmentMacroTask();
|
|
103
153
|
}
|
|
104
|
-
|
|
154
|
+
break;
|
|
105
155
|
}
|
|
106
156
|
}
|
|
157
|
+
isProcessingAdjustments = 0;
|
|
158
|
+
if (t && shouldYieldInBrowser) nextTriggerMacroTask();
|
|
159
|
+
}
|
|
160
|
+
const preloadOne = (e) => {
|
|
161
|
+
if (e.i >= BundleImportState_Preload) return;
|
|
162
|
+
preloadCount++;
|
|
163
|
+
const t = performance.now();
|
|
164
|
+
e.m = t - e.M;
|
|
165
|
+
e.i = BundleImportState_Preload;
|
|
166
|
+
config.t && log(`<< load ${Math.round((1 - e.l) * 100)}% after ${`${e.m}ms`}`, e.k);
|
|
167
|
+
const n = doc.createElement("link");
|
|
168
|
+
n.href = new URL(`${base}${e.k}`, doc.baseURI).toString();
|
|
169
|
+
n.rel = rel;
|
|
170
|
+
n.as = "script";
|
|
171
|
+
n.onload = n.onerror = () => {
|
|
172
|
+
preloadCount--;
|
|
173
|
+
const s = performance.now();
|
|
174
|
+
e.p = s - t;
|
|
175
|
+
e.i = BundleImportState_Loaded;
|
|
176
|
+
config.t && log(`>> done after ${e.p}ms`, e.k);
|
|
177
|
+
n.remove();
|
|
178
|
+
nextTriggerMacroTask();
|
|
179
|
+
};
|
|
180
|
+
doc.head.appendChild(n);
|
|
107
181
|
};
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (
|
|
182
|
+
const adjustProbabilities = (e, t, n) => {
|
|
183
|
+
enqueueAdjustment(e, t, { T: 0 }, n);
|
|
184
|
+
if (shouldYieldInBrowser) nextAdjustmentMacroTask();
|
|
185
|
+
else processPendingAdjustments();
|
|
186
|
+
};
|
|
187
|
+
const handleBundle = (e, t, n) => {
|
|
188
|
+
const s = getBundle(e);
|
|
189
|
+
if (s && s.l > t) if (n) enqueueAdjustment(s, t, n);
|
|
190
|
+
else adjustProbabilities(s, t);
|
|
111
191
|
};
|
|
112
|
-
let depsCount;
|
|
113
192
|
const preload = (e, t) => {
|
|
114
193
|
if (!e?.length) return;
|
|
115
|
-
|
|
116
|
-
|
|
194
|
+
let n = t ? 1 - t : 0.4;
|
|
195
|
+
const s = { T: 0 };
|
|
117
196
|
if (Array.isArray(e)) for (let t2 = e.length - 1; t2 >= 0; t2--) {
|
|
118
|
-
const
|
|
119
|
-
if (typeof
|
|
120
|
-
else handleBundle(n,
|
|
197
|
+
const o = e[t2];
|
|
198
|
+
if (typeof o === "number") n = 1 - o / 10;
|
|
199
|
+
else handleBundle(o, n, s);
|
|
121
200
|
}
|
|
122
|
-
else handleBundle(e,
|
|
123
|
-
if (
|
|
201
|
+
else handleBundle(e, n, s);
|
|
202
|
+
if (shouldYieldInBrowser) nextAdjustmentMacroTask();
|
|
203
|
+
else processPendingAdjustments();
|
|
124
204
|
};
|
|
125
|
-
if (isBrowser) document.addEventListener("qsymbol", (e) => {
|
|
126
|
-
const { symbol: t, href:
|
|
127
|
-
if (
|
|
205
|
+
if (isBrowser$2) document.addEventListener("qsymbol", (e) => {
|
|
206
|
+
const { symbol: t, href: n } = e.detail;
|
|
207
|
+
if (n) {
|
|
128
208
|
const e2 = t.slice(t.lastIndexOf("_") + 1);
|
|
129
209
|
preload(e2, 1);
|
|
130
210
|
}
|
|
131
211
|
});
|
|
132
212
|
let base;
|
|
133
213
|
let graph;
|
|
134
|
-
const
|
|
214
|
+
const isBrowser = !isServer;
|
|
215
|
+
const makeBundle = (e, t) => ({ k: e, i: isJSRegex.test(e) ? BundleImportState_None : BundleImportState_Alias, S: t, l: 1, M: performance.now(), m: 0, p: 0 });
|
|
135
216
|
const parseBundleGraph = (e) => {
|
|
136
217
|
const t = /* @__PURE__ */ new Map();
|
|
137
|
-
let
|
|
138
|
-
while (
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
let
|
|
142
|
-
let
|
|
143
|
-
while (
|
|
144
|
-
if (
|
|
145
|
-
else
|
|
146
|
-
|
|
218
|
+
let n = 0;
|
|
219
|
+
while (n < e.length) {
|
|
220
|
+
const s = e[n++];
|
|
221
|
+
const o = [];
|
|
222
|
+
let r;
|
|
223
|
+
let a = 1;
|
|
224
|
+
while (r = e[n], typeof r === "number") {
|
|
225
|
+
if (r < 0) a = -r / 10;
|
|
226
|
+
else o.push({ k: e[r], I: a, A: 1 });
|
|
227
|
+
n++;
|
|
147
228
|
}
|
|
148
|
-
t.set(
|
|
229
|
+
t.set(s, o);
|
|
149
230
|
}
|
|
150
231
|
return t;
|
|
151
232
|
};
|
|
152
233
|
const getBundle = (e) => {
|
|
153
234
|
let t = bundles.get(e);
|
|
154
235
|
if (!t) {
|
|
155
|
-
let
|
|
236
|
+
let n;
|
|
156
237
|
if (graph) {
|
|
157
|
-
|
|
158
|
-
if (!
|
|
159
|
-
if (!
|
|
238
|
+
n = graph.get(e);
|
|
239
|
+
if (!n) return;
|
|
240
|
+
if (!n.length) n = void 0;
|
|
160
241
|
}
|
|
161
|
-
t = makeBundle(e,
|
|
242
|
+
t = makeBundle(e, n);
|
|
162
243
|
bundles.set(e, t);
|
|
163
244
|
}
|
|
164
245
|
return t;
|
|
165
246
|
};
|
|
166
|
-
const loadBundleGraph = (e, t,
|
|
167
|
-
if (
|
|
168
|
-
if ("d" in
|
|
169
|
-
if ("P" in
|
|
170
|
-
if ("Q" in
|
|
247
|
+
const loadBundleGraph = (e, t, n) => {
|
|
248
|
+
if (n) {
|
|
249
|
+
if ("d" in n) config.t = !!n.d;
|
|
250
|
+
if ("P" in n) config.o = n["P"];
|
|
251
|
+
if ("Q" in n) config.u = 1 - n["Q"];
|
|
171
252
|
}
|
|
172
253
|
if (!isBrowser || e == null) return;
|
|
173
254
|
base = e;
|
|
174
255
|
if (t) t.then((e2) => e2.text()).then((e2) => {
|
|
175
256
|
graph = parseBundleGraph(JSON.parse(e2));
|
|
176
257
|
const t2 = [];
|
|
177
|
-
for (const [e3,
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
t2.push([
|
|
182
|
-
|
|
258
|
+
for (const [e3, n3] of graph.entries()) {
|
|
259
|
+
const s2 = getBundle(e3);
|
|
260
|
+
s2.S = n3;
|
|
261
|
+
if (s2.l < 1) {
|
|
262
|
+
t2.push([s2, s2.l]);
|
|
263
|
+
s2.l = 1;
|
|
183
264
|
}
|
|
184
265
|
}
|
|
185
266
|
config.t && log(`parseBundleGraph got ${graph.size} bundles, adjusting ${t2.length}`);
|
|
186
|
-
|
|
187
|
-
|
|
267
|
+
if (!t2.length) {
|
|
268
|
+
nextTriggerMacroTask();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
let n2 = 0;
|
|
272
|
+
const s = createMacroTask(() => {
|
|
273
|
+
const e3 = performance.now() + yieldInterval;
|
|
274
|
+
while (n2 < t2.length) {
|
|
275
|
+
const [o, r] = t2[n2];
|
|
276
|
+
n2++;
|
|
277
|
+
adjustProbabilities(o, r);
|
|
278
|
+
if (n2 < t2.length && performance.now() >= e3) {
|
|
279
|
+
s();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
nextTriggerMacroTask();
|
|
284
|
+
});
|
|
285
|
+
s();
|
|
188
286
|
}).catch(console.warn);
|
|
189
287
|
};
|
|
190
288
|
export {
|
package/dist/qwikloader.debug.js
CHANGED
|
@@ -16,10 +16,12 @@ const querySelectorAll = (query) => {
|
|
|
16
16
|
const addEventListener = (el, eventName, handler, capture = false) => el.addEventListener(eventName, handler, { capture, passive: false });
|
|
17
17
|
const findShadowRoots = (fragment) => {
|
|
18
18
|
addEventOrRoot(fragment);
|
|
19
|
-
nativeQuerySelectorAll(fragment, "[q\\:shadowroot]")
|
|
19
|
+
const shadowRoots = nativeQuerySelectorAll(fragment, "[q\\:shadowroot]");
|
|
20
|
+
for (let i = 0; i < shadowRoots.length; i++) {
|
|
21
|
+
const parent = shadowRoots[i];
|
|
20
22
|
const shadowRoot = parent.shadowRoot;
|
|
21
23
|
shadowRoot && findShadowRoots(shadowRoot);
|
|
22
|
-
}
|
|
24
|
+
}
|
|
23
25
|
};
|
|
24
26
|
const isPromise = (promise) => promise && typeof promise.then === "function";
|
|
25
27
|
const resolveContainer = (containerEl) => {
|
|
@@ -81,7 +83,9 @@ const dispatch = async (element, ev, scopedKebabName, kebabName) => {
|
|
|
81
83
|
);
|
|
82
84
|
const qBase = container.getAttribute("q:base");
|
|
83
85
|
const base = new URL(qBase, doc.baseURI);
|
|
84
|
-
|
|
86
|
+
const qrls = attrValue.split("|");
|
|
87
|
+
for (let i = 0; i < qrls.length; i++) {
|
|
88
|
+
const qrl = qrls[i];
|
|
85
89
|
const reqTime = performance.now();
|
|
86
90
|
const [chunk, symbol, capturedIds] = qrl.split("#");
|
|
87
91
|
const eventData = {
|
|
@@ -163,9 +167,11 @@ const processElementEvent = async (ev) => {
|
|
|
163
167
|
const broadcast = (infix, ev) => {
|
|
164
168
|
const kebabName = camelToKebab(ev.type);
|
|
165
169
|
const scopedKebabName = infix + ":" + kebabName;
|
|
166
|
-
querySelectorAll("[q-" + infix + "\\:" + kebabName + "]")
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
const elements = querySelectorAll("[q-" + infix + "\\:" + kebabName + "]");
|
|
171
|
+
for (let i = 0; i < elements.length; i++) {
|
|
172
|
+
const el = elements[i];
|
|
173
|
+
dispatch(el, ev, scopedKebabName, kebabName);
|
|
174
|
+
}
|
|
169
175
|
};
|
|
170
176
|
const processDocumentEvent = async (ev) => {
|
|
171
177
|
broadcast(documentPrefix, ev);
|
|
@@ -181,35 +187,42 @@ const processReadyStateChange = () => {
|
|
|
181
187
|
if (events.has("d:qinit")) {
|
|
182
188
|
events.delete("d:qinit");
|
|
183
189
|
const ev = createEvent("qinit");
|
|
184
|
-
querySelectorAll("[q-d\\:qinit]")
|
|
190
|
+
const elements = querySelectorAll("[q-d\\:qinit]");
|
|
191
|
+
for (let i = 0; i < elements.length; i++) {
|
|
192
|
+
const el = elements[i];
|
|
185
193
|
dispatch(el, ev, "d:qinit");
|
|
186
194
|
el.removeAttribute("q-d:qinit");
|
|
187
|
-
}
|
|
195
|
+
}
|
|
188
196
|
}
|
|
189
197
|
if (events.has("d:qidle")) {
|
|
190
198
|
events.delete("d:qidle");
|
|
191
199
|
const riC = win.requestIdleCallback ?? win.setTimeout;
|
|
192
200
|
riC.bind(win)(() => {
|
|
193
201
|
const ev = createEvent("qidle");
|
|
194
|
-
querySelectorAll("[q-d\\:qidle]")
|
|
202
|
+
const elements = querySelectorAll("[q-d\\:qidle]");
|
|
203
|
+
for (let i = 0; i < elements.length; i++) {
|
|
204
|
+
const el = elements[i];
|
|
195
205
|
dispatch(el, ev, "d:qidle");
|
|
196
206
|
el.removeAttribute("q-d:qidle");
|
|
197
|
-
}
|
|
207
|
+
}
|
|
198
208
|
});
|
|
199
209
|
}
|
|
200
210
|
if (events.has("e:qvisible")) {
|
|
201
211
|
observer || (observer = new IntersectionObserver((entries) => {
|
|
202
|
-
for (
|
|
212
|
+
for (let i = 0; i < entries.length; i++) {
|
|
213
|
+
const entry = entries[i];
|
|
203
214
|
if (entry.isIntersecting) {
|
|
204
215
|
observer.unobserve(entry.target);
|
|
205
216
|
dispatch(entry.target, createEvent("qvisible", entry), "e:qvisible");
|
|
206
217
|
}
|
|
207
218
|
}
|
|
208
219
|
}));
|
|
209
|
-
querySelectorAll("[q-e\\:qvisible]:not([q\\:observed])")
|
|
220
|
+
const elements = querySelectorAll("[q-e\\:qvisible]:not([q\\:observed])");
|
|
221
|
+
for (let i = 0; i < elements.length; i++) {
|
|
222
|
+
const el = elements[i];
|
|
210
223
|
observer.observe(el);
|
|
211
224
|
el.setAttribute("q:observed", "true");
|
|
212
|
-
}
|
|
225
|
+
}
|
|
213
226
|
}
|
|
214
227
|
}
|
|
215
228
|
};
|
package/dist/qwikloader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=document,t=window,
|
|
1
|
+
const e=document,t=window,n="w",o="d",r=new Set,s=new Set([e]),i=new Map;let a,c;const l=(e,t)=>Array.from(e.querySelectorAll(t)),q=e=>{const t=[];return s.forEach(n=>t.push(...l(n,e))),t},d=(e,t,n,o=!1)=>e.addEventListener(t,n,{capture:o,passive:!1}),b=e=>{_(e);const t=l(e,"[q\\:shadowroot]");for(let e=0;e<t.length;e++){const n=t[e].shadowRoot;n&&b(n)}},f=e=>e&&"function"==typeof e.then,p=t=>{if(void 0===t._qwikjson_){let n=(t===e.documentElement?e.body:t).lastElementChild;for(;n;){if("SCRIPT"===n.tagName&&"qwik/json"===n.getAttribute("type")){t._qwikjson_=JSON.parse(n.textContent.replace(/\\x3C(\/?script)/gi,"<$1"));break}n=n.previousElementSibling}}},u=(e,t)=>new CustomEvent(e,{detail:t}),h=(t,n)=>{e.dispatchEvent(u(t,n))},g=e=>e.replace(/([A-Z-])/g,e=>"-"+e.toLowerCase()),m=e=>e.replace(/-./g,e=>e[1].toUpperCase()),v=e=>({scope:e.charAt(0),eventName:m(e.slice(2))}),w=async(t,n,o,r)=>{r&&(t.hasAttribute("preventdefault:"+r)&&n.preventDefault(),t.hasAttribute("stoppropagation:"+r)&&n.stopPropagation());const s=t._qDispatch?.[o];if(s){if("function"==typeof s){const e=s(n,t);f(e)&&await e}else if(s.length)for(let e=0;e<s.length;e++){const o=s[e],r=o?.(n,t);f(r)&&await r}return}const a=t.getAttribute("q-"+o);if(a){const o=t.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])"),r=o.getAttribute("q:base"),s=new URL(r,e.baseURI),c=a.split("|");for(let a=0;a<c.length;a++){const l=c[a],q=performance.now(),[d,b,u]=l.split("#"),g={qBase:r,symbol:b,element:t,reqTime:q};let m,v,w;if(""===d){const t=o.getAttribute("q:instance");m=(e["qFuncs_"+t]||[])[Number.parseInt(b)],m||(v="sync",w=Error("sym:"+b))}else{const e=`${b}|${r}|${d}`;if(m=i.get(e),!m){const t=new URL(d,s).href;try{const n=import(t);p(o),m=(await n)[b],m?(i.set(e,m),h("qsymbol",g)):(v="no-symbol",w=Error(`${b} not in ${t}`))}catch(e){v="async",w=e}}}if(m){if(t.isConnected)try{const e=m.call(u,n,t);f(e)&&await e}catch(e){h("qerror",{error:e,...g})}}else h("qerror",{importError:v,error:w,...g}),console.error(w)}}},y=async e=>{const t=g(e.type),n="e:"+t;let o=e.target;for(;o&&o.getAttribute;){const r=w(o,e,n,t),s=e.bubbles&&!e.cancelBubble;f(r)&&await r,o=s&&e.bubbles&&!e.cancelBubble?o.parentElement:null}},A=(e,t)=>{const n=g(t.type),o=e+":"+n,r=q("[q-"+e+"\\:"+n+"]");for(let e=0;e<r.length;e++){const s=r[e];w(s,t,o,n)}},E=async e=>{A(o,e)},C=e=>{A(n,e)},k=()=>{const n=e.readyState;if("interactive"==n||"complete"==n){if(c=1,s.forEach(b),r.has("d:qinit")){r.delete("d:qinit");const e=u("qinit"),t=q("[q-d\\:qinit]");for(let n=0;n<t.length;n++){const o=t[n];w(o,e,"d:qinit"),o.removeAttribute("q-d:qinit")}}if(r.has("d:qidle")&&(r.delete("d:qidle"),(t.requestIdleCallback??t.setTimeout).bind(t)(()=>{const e=u("qidle"),t=q("[q-d\\:qidle]");for(let n=0;n<t.length;n++){const o=t[n];w(o,e,"d:qidle"),o.removeAttribute("q-d:qidle")}})),r.has("e:qvisible")){a||(a=new IntersectionObserver(e=>{for(let t=0;t<e.length;t++){const n=e[t];n.isIntersecting&&(a.unobserve(n.target),w(n.target,u("qvisible",n),"e:qvisible"))}}));const e=q("[q-e\\:qvisible]:not([q\\:observed])");for(let t=0;t<e.length;t++){const n=e[t];a.observe(n),n.setAttribute("q:observed","true")}}}},_=(...e)=>{for(let i=0;i<e.length;i++){const a=e[i];if("string"==typeof a){if(!r.has(a)){r.add(a);const{scope:e,eventName:i}=v(a);e===n?d(t,i,C,!0):s.forEach(t=>d(t,i,e===o?E:y,!0)),1!==c||"e:qvisible"!==a&&"d:qinit"!==a&&"d:qidle"!==a||k()}}else s.has(a)||(r.forEach(e=>{const{scope:t,eventName:r}=v(e);t!==n&&d(a,r,t===o?E:y,!0)}),s.add(a))}},S=t._qwikEv;S?.roots||(Array.isArray(S)?_(...S):_("e:click","e:input"),t._qwikEv={events:r,roots:s,push:_},d(e,"readystatechange",k),k());
|