@qwik.dev/core 2.0.0-beta.34 → 2.0.0-beta.36

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.
@@ -0,0 +1,163 @@
1
+ const Q_RESOLVED_SELECTOR = 'template[q\\:r="';
2
+ const Q_RESOLVED_ATTR = "q:r";
3
+ const Q_RESULT_PARENT_SELECTOR = '[q\\:rp="';
4
+ const Q_GROUP_ATTR = "q:g";
5
+ const Q_INDEX_ATTR = "q:i";
6
+ const Q_ORDER_ATTR = "q:o";
7
+ const Q_CONTAINER_SELECTOR = "[q\\:container]:not([q\\:container=html]):not([q\\:container=text])";
8
+ const installOutOfOrderExecutor = (doc) => {
9
+ const groups = /* @__PURE__ */ new WeakMap();
10
+ const process = (boundaryId, content) => {
11
+ var _a;
12
+ const executorDoc = doc;
13
+ (_a = executorDoc.qProcessOOOS) == null ? void 0 : _a.call(executorDoc, boundaryId, content);
14
+ };
15
+ const getScope = () => {
16
+ const script = doc.currentScript;
17
+ return script ? script.closest(Q_CONTAINER_SELECTOR) || doc : doc;
18
+ };
19
+ const group = (scope, groupId, total, order) => {
20
+ let scopedGroups = groups.get(scope);
21
+ if (!scopedGroups) {
22
+ groups.set(scope, scopedGroups = {});
23
+ }
24
+ return scopedGroups[groupId] || (scopedGroups[groupId] = {
25
+ r: {},
26
+ n: 0,
27
+ t: total,
28
+ o: order
29
+ });
30
+ };
31
+ const getResolvedTemplate = (scope, boundaryId) => {
32
+ const currentScript = doc.currentScript;
33
+ const previousElement = currentScript ? currentScript.previousElementSibling : null;
34
+ if (previousElement && previousElement.localName === "template" && previousElement.getAttribute(Q_RESOLVED_ATTR) === String(boundaryId)) {
35
+ return previousElement;
36
+ }
37
+ const templates = scope.querySelectorAll(Q_RESOLVED_SELECTOR + boundaryId + '"]');
38
+ return templates.length ? templates[templates.length - 1] : null;
39
+ };
40
+ const getPlaceholderTemplate = (content, boundaryId) => {
41
+ return content.querySelector(Q_RESOLVED_SELECTOR + boundaryId + '"]');
42
+ };
43
+ const getResultParent = (scope, boundaryId) => {
44
+ return scope.querySelector(Q_RESULT_PARENT_SELECTOR + boundaryId + '"]');
45
+ };
46
+ const reveal = (content, fallback) => {
47
+ if (!content) {
48
+ return 0;
49
+ }
50
+ if (fallback && fallback.style) {
51
+ fallback.style.display = "none";
52
+ }
53
+ if (content.style) {
54
+ content.style.display = "contents";
55
+ }
56
+ return 1;
57
+ };
58
+ const move = (scope, boundaryId, resolved) => {
59
+ if (!resolved) {
60
+ return null;
61
+ }
62
+ const content = getResultParent(scope, boundaryId);
63
+ const placeholder = content ? getPlaceholderTemplate(content, boundaryId) : null;
64
+ const parent = placeholder ? placeholder.parentNode : null;
65
+ if (!placeholder || !content || !parent) {
66
+ return null;
67
+ }
68
+ parent.insertBefore(resolved.content, placeholder);
69
+ placeholder.remove();
70
+ resolved.remove();
71
+ return [content, content.previousElementSibling];
72
+ };
73
+ const flush = (group2) => {
74
+ const order = group2.o;
75
+ let entry;
76
+ let index;
77
+ let swapped = 0;
78
+ if (order === "p") {
79
+ for (const key in group2.r) {
80
+ entry = group2.r[key];
81
+ if (entry[0] && reveal(entry[0], entry[1])) {
82
+ entry[0] = 0;
83
+ swapped++;
84
+ }
85
+ }
86
+ } else if (order === "s") {
87
+ for (index = group2.n; (entry = group2.r[index]) && entry[0]; index++) {
88
+ if (!reveal(entry[0], entry[1])) {
89
+ break;
90
+ }
91
+ entry[0] = 0;
92
+ swapped++;
93
+ group2.n = index + 1;
94
+ }
95
+ } else if (order === "r") {
96
+ if (group2.t < 0) {
97
+ return 0;
98
+ }
99
+ if (group2.n < 0) {
100
+ group2.n = group2.t - 1;
101
+ }
102
+ for (index = group2.n; (entry = group2.r[index]) && entry[0]; index--) {
103
+ if (!reveal(entry[0], entry[1])) {
104
+ break;
105
+ }
106
+ entry[0] = 0;
107
+ swapped++;
108
+ group2.n = index - 1;
109
+ }
110
+ } else {
111
+ if (group2.t < 0) {
112
+ return 0;
113
+ }
114
+ for (index = 0; index < group2.t; index++) {
115
+ entry = group2.r[index];
116
+ if (!entry) {
117
+ return 0;
118
+ }
119
+ }
120
+ for (index = 0; index < group2.t; index++) {
121
+ entry = group2.r[index];
122
+ if (entry[0] && reveal(entry[0], entry[1])) {
123
+ entry[0] = 0;
124
+ swapped++;
125
+ }
126
+ }
127
+ }
128
+ return swapped;
129
+ };
130
+ const qO = ((boundaryId) => {
131
+ const scope = getScope();
132
+ const resolved = getResolvedTemplate(scope, boundaryId);
133
+ if (!resolved) {
134
+ return;
135
+ }
136
+ const entry = move(scope, boundaryId, resolved);
137
+ if (!entry) {
138
+ return;
139
+ }
140
+ process(boundaryId, entry[0] || null);
141
+ const groupId = resolved.getAttribute(Q_GROUP_ATTR);
142
+ if (groupId) {
143
+ const index = +(resolved.getAttribute(Q_INDEX_ATTR) || 0);
144
+ const currentGroup = group(scope, groupId, -1, resolved.getAttribute(Q_ORDER_ATTR) || "p");
145
+ currentGroup.r[index] = entry;
146
+ flush(currentGroup);
147
+ return;
148
+ }
149
+ reveal(entry[0] || null, entry[1]);
150
+ });
151
+ qO.g = (groupId, total, order) => {
152
+ const currentGroup = group(getScope(), groupId, total, order);
153
+ currentGroup.t = total;
154
+ currentGroup.o = order;
155
+ if (currentGroup.o === "r" && currentGroup.n === 0) {
156
+ currentGroup.n = total - 1;
157
+ }
158
+ flush(currentGroup);
159
+ };
160
+ qO.d = doc;
161
+ globalThis.qO = qO;
162
+ };
163
+ installOutOfOrderExecutor(document);
@@ -0,0 +1 @@
1
+ const t='template[q\\:r="',e="q:r",n='[q\\:rp="',r="q:g",l="q:i",o="q:o",s="[q\\:container]:not([q\\:container=html]):not([q\\:container=text])",u=u=>{const i=new WeakMap,c=()=>{const t=u.currentScript;return t&&t.closest(s)||u},f=(t,e,n,r)=>{let l=i.get(t);return l||i.set(t,l={}),l[e]||(l[e]={r:{},n:0,t:n,o:r})},a=(t,e)=>t?(e&&e.style&&(e.style.display="none"),t.style&&(t.style.display="contents"),1):0,q=t=>{const e=t.o;let n,r,l=0;if("p"===e)for(const e in t.r)n=t.r[e],n[0]&&a(n[0],n[1])&&(n[0]=0,l++);else if("s"===e)for(r=t.n;(n=t.r[r])&&n[0]&&a(n[0],n[1]);r++)n[0]=0,l++,t.n=r+1;else if("r"===e){if(t.t<0)return 0;for(t.n<0&&(t.n=t.t-1),r=t.n;(n=t.r[r])&&n[0]&&a(n[0],n[1]);r--)n[0]=0,l++,t.n=r-1}else{if(t.t<0)return 0;for(r=0;r<t.t;r++)if(n=t.r[r],!n)return 0;for(r=0;r<t.t;r++)n=t.r[r],n[0]&&a(n[0],n[1])&&(n[0]=0,l++)}return l},p=s=>{const i=c(),p=((n,r)=>{const l=u.currentScript,o=l?l.previousElementSibling:null;if(o&&"template"===o.localName&&o.getAttribute(e)===r+"")return o;const s=n.querySelectorAll(t+r+'"]');return s.length?s[s.length-1]:null})(i,s);if(!p)return;const g=((e,r,l)=>{if(!l)return null;const o=((t,e)=>t.querySelector(n+e+'"]'))(e,r),s=o?((e,n)=>e.querySelector(t+n+'"]'))(o,r):null,u=s?s.parentNode:null;return s&&o&&u?(u.insertBefore(l.content,s),s.remove(),l.remove(),[o,o.previousElementSibling]):null})(i,s,p);if(!g)return;((t,e)=>{var n;const r=u;null==(n=r.qProcessOOOS)||n.call(r,t,e)})(s,g[0]||null);const m=p.getAttribute(r);if(m){const t=+(p.getAttribute(l)||0),e=f(i,m,-1,p.getAttribute(o)||"p");return e.r[t]=g,void q(e)}a(g[0]||null,g[1])};p.g=(t,e,n)=>{const r=f(c(),t,e,n);r.t=e,r.o=n,"r"===r.o&&0===r.n&&(r.n=e-1),q(r)},p.d=u,globalThis.qO=p};u(document);
@@ -1,268 +1 @@
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: 25 };
14
- const rel = isBrowser$1 && doc.createElement("link").relList?.supports?.("modulepreload") ? "modulePreload" : "preload";
15
- performance.now();
16
- const isJSRegex = /\.[mc]?js$/;
17
- const yieldInterval = 1e3 / 60;
18
- const BundleImportState_None = 0;
19
- const BundleImportState_Queued = 1;
20
- const BundleImportState_Preload = 2;
21
- const BundleImportState_Alias = 3;
22
- const BundleImportState_Loaded = 4;
23
- const bundles = /* @__PURE__ */ new Map();
24
- let queueDirty;
25
- let preloadCount = 0;
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 = [];
34
- const sortQueue = () => {
35
- if (queueDirty) {
36
- queue.sort((e, t) => e.o - t.o);
37
- queueDirty = 0;
38
- }
39
- };
40
- function trigger() {
41
- isTriggerScheduled = 0;
42
- if (!queue.length) return;
43
- sortQueue();
44
- const e = performance.now() + yieldInterval;
45
- let t = 0;
46
- while (queue.length) {
47
- const n = queue[0];
48
- const s = n.o;
49
- const r = 1 - s;
50
- if (r >= 0.99 || preloadCount < config.t) {
51
- queue.shift();
52
- preloadOne(n);
53
- if (performance.now() >= e) {
54
- t = 1;
55
- break;
56
- }
57
- } else break;
58
- }
59
- if (t && queue.length && !isTriggerScheduled) {
60
- isTriggerScheduled = 1;
61
- nextTriggerMacroTask();
62
- }
63
- }
64
- const enqueueAdjustment = (e, t, n) => {
65
- adjustmentStack.unshift({ u: e, o: t, i: n });
66
- };
67
- const processAdjustmentFrame = () => {
68
- const e = adjustmentStack[adjustmentStack.length - 1];
69
- const t = e.u;
70
- if (e.l) {
71
- const n2 = e.m;
72
- if (n2 >= e.l.length) {
73
- adjustmentStack.pop();
74
- return 0;
75
- }
76
- const s = e.l[n2];
77
- e.m = n2 + 1;
78
- const r = getBundle(s.p);
79
- if (r.o === 0) return 1;
80
- const o = 1 - t.o;
81
- let a;
82
- if (o === 1 || o >= 0.99) a = Math.min(0.01, 1 - s.$);
83
- else {
84
- const e2 = 1 - s.$ * o;
85
- const t2 = s.B;
86
- const n3 = e2 / t2;
87
- a = Math.max(0.02, r.o * n3);
88
- s.B = n3;
89
- }
90
- adjustmentStack.push({ u: r, o: a, i: e.i });
91
- return 1;
92
- }
93
- if (e.i?.has(t)) {
94
- adjustmentStack.pop();
95
- return 0;
96
- }
97
- const n = t.o;
98
- t.o = e.o;
99
- if (n - t.o < 0.01) {
100
- adjustmentStack.pop();
101
- return 0;
102
- }
103
- if (
104
- // don't queue until we have initialized the preloader
105
- base != null && t.S < BundleImportState_Preload
106
- ) {
107
- if (t.S === BundleImportState_None) {
108
- t.S = BundleImportState_Queued;
109
- queue.push(t);
110
- }
111
- queueDirty = 1;
112
- }
113
- if (t.l?.length) {
114
- const n2 = e.i || /* @__PURE__ */ new Set();
115
- n2.add(t);
116
- e.i = n2;
117
- e.l = t.l;
118
- e.m = 0;
119
- return 0;
120
- }
121
- adjustmentStack.pop();
122
- return 0;
123
- };
124
- function processPendingAdjustments() {
125
- if (isProcessingAdjustments || !adjustmentStack.length) return;
126
- isAdjustmentScheduled = 0;
127
- isProcessingAdjustments = 1;
128
- const e = shouldYieldInBrowser ? performance.now() + yieldInterval : 0;
129
- let t = 0;
130
- while (adjustmentStack.length) {
131
- t = 1;
132
- const n = processAdjustmentFrame();
133
- if (shouldYieldInBrowser && n && performance.now() >= e) {
134
- if (!isAdjustmentScheduled) {
135
- isAdjustmentScheduled = 1;
136
- nextAdjustmentMacroTask();
137
- }
138
- break;
139
- }
140
- }
141
- isProcessingAdjustments = 0;
142
- if (t && shouldYieldInBrowser) nextTriggerMacroTask();
143
- }
144
- const preloadOne = (e) => {
145
- if (e.S >= BundleImportState_Preload) return;
146
- preloadCount++;
147
- const t = performance.now();
148
- e.h = t - e.j;
149
- e.S = BundleImportState_Preload;
150
- const n = doc.createElement("link");
151
- n.href = new URL(`${base}${e.p}`, doc.baseURI).toString();
152
- n.rel = rel;
153
- n.as = "script";
154
- n.onload = n.onerror = () => {
155
- preloadCount--;
156
- const s = performance.now();
157
- e.k = s - t;
158
- e.S = BundleImportState_Loaded;
159
- n.remove();
160
- nextTriggerMacroTask();
161
- };
162
- doc.head.appendChild(n);
163
- };
164
- const adjustProbabilities = (e, t, n) => {
165
- enqueueAdjustment(e, t, n);
166
- if (shouldYieldInBrowser) nextAdjustmentMacroTask();
167
- else processPendingAdjustments();
168
- };
169
- const handleBundle = (e, t) => {
170
- const n = getBundle(e);
171
- if (n) enqueueAdjustment(n, t);
172
- };
173
- const preload = (e, t) => {
174
- if (!e?.length) return;
175
- const n = t ? 1 - t : 0.4;
176
- if (Array.isArray(e)) for (let t2 = e.length - 1; t2 >= 0; t2--) {
177
- const s = e[t2];
178
- handleBundle(s, n);
179
- }
180
- else handleBundle(e, n);
181
- if (shouldYieldInBrowser) nextAdjustmentMacroTask();
182
- else processPendingAdjustments();
183
- };
184
- if (isBrowser$2) document.addEventListener("qsymbol", (e) => {
185
- const { symbol: t, href: n } = e.detail;
186
- if (n) {
187
- const e2 = t.slice(t.lastIndexOf("_") + 1);
188
- preload(e2, 1);
189
- }
190
- });
191
- let base;
192
- let graph;
193
- const isBrowser = !isServer;
194
- const makeBundle = (e, t) => ({ p: e, S: isJSRegex.test(e) ? BundleImportState_None : BundleImportState_Alias, l: t, o: 1, j: performance.now(), h: 0, k: 0 });
195
- const parseBundleGraph = (e) => {
196
- const t = /* @__PURE__ */ new Map();
197
- let n = 0;
198
- while (n < e.length) {
199
- const s = e[n++];
200
- const r = [];
201
- let o;
202
- let a = 1;
203
- while (o = e[n], typeof o === "number") {
204
- if (o < 0) a = -o / 10;
205
- else r.push({ p: e[o], $: a, B: 1 });
206
- n++;
207
- }
208
- t.set(s, r);
209
- }
210
- return t;
211
- };
212
- const getBundle = (e) => {
213
- let t = bundles.get(e);
214
- if (!t) {
215
- let n;
216
- if (graph) {
217
- n = graph.get(e);
218
- if (!n) return;
219
- if (!n.length) n = void 0;
220
- }
221
- t = makeBundle(e, n);
222
- bundles.set(e, t);
223
- }
224
- return t;
225
- };
226
- const loadBundleGraph = (e, t, n) => {
227
- if (n) {
228
- if ("P" in n) config.t = n["P"];
229
- }
230
- if (!isBrowser || e == null) return;
231
- base = e;
232
- if (t) t.then((e2) => e2.text()).then((e2) => {
233
- graph = parseBundleGraph(JSON.parse(e2));
234
- const t2 = [];
235
- for (const [e3, n3] of graph.entries()) {
236
- const s2 = getBundle(e3);
237
- s2.l = n3;
238
- if (s2.o < 1) {
239
- t2.push([s2, s2.o]);
240
- s2.o = 1;
241
- }
242
- }
243
- if (!t2.length) {
244
- nextTriggerMacroTask();
245
- return;
246
- }
247
- let n2 = 0;
248
- const s = createMacroTask(() => {
249
- const e3 = performance.now() + yieldInterval;
250
- while (n2 < t2.length) {
251
- const [r, o] = t2[n2];
252
- n2++;
253
- adjustProbabilities(r, o);
254
- if (n2 < t2.length && performance.now() >= e3) {
255
- s();
256
- return;
257
- }
258
- }
259
- nextTriggerMacroTask();
260
- });
261
- s();
262
- }).catch(console.warn);
263
- };
264
- export {
265
- parseBundleGraph as g,
266
- loadBundleGraph as l,
267
- preload as p
268
- };
1
+ import{isServer as e}from"@qwik.dev/core/build";const n=e=>{let n;if(typeof MessageChannel!=="undefined"){const t=new MessageChannel;t.port1.onmessage=()=>e();n=()=>t.port2.postMessage(null)}else n=()=>setTimeout(e);return n};const t=typeof document!=="undefined";const o=!e&&t;const s=o?document:void 0;const c={t:25};const r=o&&s.createElement("link").relList?.supports?.("modulepreload")?"modulePreload":"preload";const i=/\.[mc]?js$/;const f=1e3/60;const l=0;const a=1;const $=2;const u=3;const d=4;const m=/* @__PURE__ */new Map;let p;let b=0;const w=[];const h=n(q);const y=n(S);let M=0;let P=0;let k=0;const v=[];const g=()=>{if(p){w.sort((e,n)=>e.o-n.o);p=0}};function q(){M=0;if(!w.length)return;g();const e=performance.now()+f;let n=0;while(w.length){const t=w[0];const o=t.o;const s=1-o;if(s>=.99||b<c.t){w.shift();T(t);if(performance.now()>=e){n=1;break}}else break}if(n&&w.length&&!M){M=1;h()}}const x=(e,n,t)=>{v.unshift({i:e,o:n,l:t})};const C=()=>{const e=v[v.length-1];const n=e.i;if(e.$){const t=e.u;if(t>=e.$.length){v.pop();return 0}const o=e.$[t];e.u=t+1;const s=R(o.m);if(s.o===0)return 1;const c=1-n.o;let r;if(c===1||c>=.99)r=Math.min(.01,1-o.p);else{const e=1-o.p*c;const n=o.h;const t=e/n;r=Math.max(.02,s.o*t);o.h=t}v.push({i:s,o:r,l:e.l});return 1}if(e.l?.has(n)){v.pop();return 0}const t=n.o;n.o=e.o;if(t-n.o<.01){v.pop();return 0}if(J!=null&&n.M<$){if(n.M===l){n.M=a;w.push(n)}p=1}if(n.$?.length){const t=e.l||/* @__PURE__ */new Set;t.add(n);e.l=t;e.$=n.$;e.u=0;return 0}v.pop();return 0};function S(){if(k||!v.length)return;P=0;k=1;const e=o?performance.now()+f:0;let n=0;while(v.length){n=1;const t=C();if(o&&t&&performance.now()>=e){if(!P){P=1;y()}break}}k=0;if(n&&o)h()}const T=e=>{if(e.M>=$)return;b++;const n=performance.now();e.k=n-e.v;e.M=$;const t=s.createElement("link");t.href=new URL(`${J}${e.m}`,s.baseURI).toString();t.rel=r;t.as="script";t.onload=t.onerror=()=>{b--;const o=performance.now();e.q=o-n;e.M=d;t.remove();h()};s.head.appendChild(t)};const j=(e,n,t)=>{x(e,n,t);if(o)y();else S()};const A=(e,n)=>{const t=R(e);if(t)x(t,n)};const I=(e,n)=>{if(!e?.length)return;const t=n?1-n:.4;if(Array.isArray(e))for(let o=e.length-1;o>=0;o--){const n=e[o];A(n,t)}else A(e,t);if(o)y();else S()};if(o)document.addEventListener("qsymbol",e=>{const{symbol:n,href:t}=e.detail;if(t){const e=n.slice(n.lastIndexOf("_")+1);I(e,1)}});let J;let L;const N=(e,n)=>({m:e,M:i.test(e)?l:u,$:n,o:1,v:performance.now(),k:0,q:0});const O=e=>{const n=/* @__PURE__ */new Map;let t=0;while(t<e.length){const o=e[t++];const s=[];let c;let r=1;while(c=e[t],typeof c==="number"){if(c<0)r=-c/10;else s.push({m:e[c],p:r,h:1});t++}n.set(o,s)}return n};const R=e=>{let n=m.get(e);if(!n){let t;if(L){t=L.get(e);if(!t)return;if(!t.length)t=void 0}n=N(e,t);m.set(e,n)}return n};const U=(e,t,s)=>{if(s)if("P"in s)c.t=s["P"];if(!o||e==null)return;J=e;if(t)t.then(e=>e.text()).then(e=>{L=O(JSON.parse(e));const t=[];for(const[n,c]of L.entries()){const e=R(n);e.$=c;if(e.o<1){t.push([e,e.o]);e.o=1}}if(!t.length){h();return}let o=0;const s=n(()=>{const e=performance.now()+f;while(o<t.length){const[n,c]=t[o];o++;j(n,c);if(o<t.length&&performance.now()>=e){s();return}}h()});s()}).catch(console.warn)};export{O as g,U as l,I as p};
@@ -7,6 +7,8 @@ const passiveDocumentPrefix = "dp";
7
7
  const elementPrefix = "e";
8
8
  const passiveElementPrefix = "ep";
9
9
  const capturePrefix = "capture:";
10
+ const readyStateChange = "readystatechange";
11
+ const containerReady = "qready";
10
12
  const events = /* @__PURE__ */ new Set();
11
13
  const roots = /* @__PURE__ */ new Set([doc]);
12
14
  const symbols = /* @__PURE__ */ new Map();
@@ -56,6 +58,19 @@ const resolveContainer = (containerEl) => {
56
58
  }
57
59
  }
58
60
  };
61
+ const waitForContainerReady = (container) => {
62
+ const hash = container.getAttribute("q:instance");
63
+ return container.getAttribute("q:container") === "paused" && doc.readyState === "loading" && !doc[containerReady]?.[hash] && new Promise((resolve) => {
64
+ const ready = (ev) => {
65
+ if (ev.detail === hash) {
66
+ doc.removeEventListener(containerReady, ready);
67
+ resolve();
68
+ }
69
+ };
70
+ addEventListener(doc, readyStateChange, resolve);
71
+ addEventListener(doc, containerReady, ready);
72
+ });
73
+ };
59
74
  const createEvent = (eventName, detail) => new CustomEvent(eventName, { detail });
60
75
  const emitEvent = (eventName, detail) => {
61
76
  doc.dispatchEvent(createEvent(eventName, detail));
@@ -74,17 +89,16 @@ const isPassiveScope = (scope) => scope.length === 2;
74
89
  const getRootScope = (scope) => scope.charAt(0);
75
90
  const isElementNode = (node) => !!node && node.nodeType === 1;
76
91
  const isCaptureHandlerElement = (element, scopedKebabName, captureAttribute) => element.hasAttribute(captureAttribute) && (!!element._qDispatch?.[scopedKebabName] || element.hasAttribute("q-" + scopedKebabName));
77
- const resolveHandler = (container, element, qBase, base, chunk, symbol, reqTime) => {
92
+ const resolveHandler = (container, element, qBase, base, chunk, symbol, reqTime, reportSyncError = true) => {
78
93
  const eventData = {
79
94
  qBase,
80
95
  symbol,
81
96
  element,
82
97
  reqTime
83
98
  };
84
- if (chunk === "") {
85
- const hash = container.getAttribute("q:instance");
86
- const handler2 = (doc["qFuncs_" + hash] || [])[Number.parseInt(symbol)];
87
- if (!handler2) {
99
+ if (!chunk) {
100
+ const handler2 = (doc["qFuncs_" + container.getAttribute("q:instance")] || [])[+symbol];
101
+ if (!handler2 && reportSyncError) {
88
102
  const error = new Error("sym:" + symbol);
89
103
  emitEvent("qerror", {
90
104
  importError: "sync",
@@ -194,26 +208,18 @@ const dispatch = (element, ev, scopedKebabName, tasks, kebabName, allowPreventDe
194
208
  const qBase = container.getAttribute("q:base");
195
209
  const base = new URL(qBase, doc.baseURI);
196
210
  const qrls = attrValue.split("|");
211
+ const waitForReady = waitForContainerReady(container);
197
212
  for (let i = 0; i < qrls.length; i++) {
198
213
  const qrl = qrls[i];
199
214
  const reqTime = performance.now();
200
215
  const [chunk, symbol, capturedIds] = qrl.split("#");
201
216
  const run = (handler2) => {
202
217
  if (handler2 && element.isConnected) {
203
- try {
204
- const result = handler2.call(capturedIds, ev, element);
205
- if (isPromise(result)) {
206
- return result.catch((error) => {
207
- emitEvent("qerror", {
208
- error,
209
- qBase,
210
- symbol,
211
- element,
212
- reqTime
213
- });
214
- });
218
+ const onError = (error) => {
219
+ const retry = waitForContainerReady(container);
220
+ if (retry) {
221
+ return retry.then(() => run(handler2));
215
222
  }
216
- } catch (error) {
217
223
  emitEvent("qerror", {
218
224
  error,
219
225
  qBase,
@@ -221,14 +227,31 @@ const dispatch = (element, ev, scopedKebabName, tasks, kebabName, allowPreventDe
221
227
  element,
222
228
  reqTime
223
229
  });
230
+ };
231
+ try {
232
+ const result = handler2.call(capturedIds, ev, element);
233
+ if (isPromise(result)) {
234
+ return result.catch(onError);
235
+ }
236
+ } catch (error) {
237
+ return onError(error);
224
238
  }
225
239
  }
226
240
  };
227
- const handler = resolveHandler(container, element, qBase, base, chunk, symbol, reqTime);
228
- if (defer || isPromise(handler)) {
241
+ const resolve = (reportSyncError = true) => resolveHandler(container, element, qBase, base, chunk, symbol, reqTime, reportSyncError);
242
+ const handler = waitForReady && !chunk ? resolve(false) : resolve();
243
+ if (isPromise(handler)) {
244
+ defer = true;
245
+ tasks.push(() => handler.then(run));
246
+ } else if (defer || waitForReady && !chunk && !handler) {
229
247
  defer = true;
230
248
  tasks.push(async () => {
231
- await run(isPromise(handler) ? await handler : handler);
249
+ let retryHandler = handler;
250
+ if (!retryHandler && waitForReady) {
251
+ await waitForReady;
252
+ retryHandler = resolve(false);
253
+ }
254
+ await run(retryHandler || await resolve());
232
255
  });
233
256
  } else {
234
257
  const result = run(handler);
@@ -260,8 +283,7 @@ const processElementEvent = (ev, scope = elementPrefix, allowPreventDefault = tr
260
283
  for (let i = elements.length - 1; i >= 0; i--) {
261
284
  if (captureHandlers[i]) {
262
285
  dispatch(elements[i], ev, scopedKebabName, tasks, kebabName, allowPreventDefault);
263
- const continuePropagation = !ev.cancelBubble;
264
- if (!continuePropagation || ev.cancelBubble) {
286
+ if (ev.cancelBubble) {
265
287
  queueTasks(tasks);
266
288
  return;
267
289
  }
@@ -270,8 +292,7 @@ const processElementEvent = (ev, scope = elementPrefix, allowPreventDefault = tr
270
292
  for (let i = 0; i < elements.length; i++) {
271
293
  if (!captureHandlers[i]) {
272
294
  dispatch(elements[i], ev, scopedKebabName, tasks, kebabName, allowPreventDefault);
273
- const doBubble = ev.bubbles && !ev.cancelBubble;
274
- if (!doBubble || ev.cancelBubble) {
295
+ if (!ev.bubbles || ev.cancelBubble) {
275
296
  queueTasks(tasks);
276
297
  return;
277
298
  }
@@ -426,6 +447,6 @@ if (!_qwikEv?.roots) {
426
447
  roots,
427
448
  push: addEventOrRoot
428
449
  };
429
- addEventListener(doc, "readystatechange", processReadyStateChange);
450
+ addEventListener(doc, readyStateChange, processReadyStateChange);
430
451
  processReadyStateChange();
431
452
  }
@@ -1 +1 @@
1
- const e=document,t=window,r="w",n="wp",o="d",s="dp",i="e",c="ep",l="capture:",a=new Set,p=new Set([e]),q=new Map;let u,f,h;const d=(e,t)=>Array.from(e.querySelectorAll(t)),b=e=>{const t=[];return p.forEach(r=>t.push(...d(r,e))),t},m=(e,t,r,n=!1,o=!1)=>e.addEventListener(t,r,{capture:n,passive:o}),g=e=>{J(e);const t=d(e,"[q\\:shadowroot]");for(let e=0;e<t.length;e++){const r=t[e].shadowRoot;r&&g(r)}},v=e=>e&&"function"==typeof e.then,y=async e=>{for(let t=0;t<e.length;t++)await e[t]()},w=e=>{if(e.length){const t=()=>y(e);h=h?h.then(t,t):t()}},E=t=>{if(void 0===t._qwikjson_){let r=(t===e.documentElement?e.body:t).lastElementChild;for(;r;){if("SCRIPT"===r.tagName&&"qwik/json"===r.getAttribute("type")){t._qwikjson_=JSON.parse(r.textContent.replace(/\\x3C(\/?script)/gi,"<$1"));break}r=r.previousElementSibling}}},A=(e,t)=>new CustomEvent(e,{detail:t}),C=(t,r)=>{e.dispatchEvent(A(t,r))},_=e=>e.replace(/([A-Z-])/g,e=>"-"+e.toLowerCase()),k=e=>e.replace(/-./g,e=>e[1].toUpperCase()),B=e=>{const t=e.indexOf(":");return{scope:e.slice(0,t),eventName:k(e.slice(t+1))}},S=e=>2===e.length,I=e=>e.charAt(0),N=e=>!!e&&1===e.nodeType,T=(e,t,r)=>e.hasAttribute(r)&&(!!e._qDispatch?.[t]||e.hasAttribute("q-"+t)),$=(t,r,n,o,s,i,c)=>{const l={qBase:n,symbol:i,element:r,reqTime:c};if(""===s){const r=t.getAttribute("q:instance"),n=(e["qFuncs_"+r]||[])[Number.parseInt(i)];if(!n){const e=Error("sym:"+i);C("qerror",{importError:"sync",error:e,...l}),console.error(e)}return n}const a=`${i}|${n}|${s}`,p=q.get(a);if(p)return p;const u=new URL(s,o).href,f=import(u);return E(t),f.then(e=>{const t=e[i];if(t)q.set(a,t),C("qsymbol",l);else{const e=Error(`${i} not in ${u}`);C("qerror",{importError:"no-symbol",error:e,...l}),console.error(e)}return t},e=>{C("qerror",{importError:"async",error:e,...l}),console.error(e)})},R=(t,r,n,o,s,i=!0)=>{let c=!1;s&&(i&&t.hasAttribute("preventdefault:"+s)&&r.preventDefault(),t.hasAttribute("stoppropagation:"+s)&&r.stopPropagation());const l=t._qDispatch?.[n];if(l){if("function"==typeof l){const e=()=>l(r,t);if(c)o.push(async()=>{const t=e();v(t)&&await t});else{const t=e();v(t)&&(c=!0,o.push(()=>t))}}else if(l.length)for(let e=0;e<l.length;e++){const n=l[e];if(n){const e=()=>n(r,t);if(c)o.push(async()=>{const t=e();v(t)&&await t});else{const t=e();v(t)&&(c=!0,o.push(()=>t))}}}return}const a=t.getAttribute("q-"+n);if(a){const n=t.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])"),s=n.getAttribute("q:base"),i=new URL(s,e.baseURI),l=a.split("|");for(let e=0;e<l.length;e++){const a=l[e],p=performance.now(),[q,u,f]=a.split("#"),h=e=>{if(e&&t.isConnected)try{const n=e.call(f,r,t);if(v(n))return n.catch(e=>{C("qerror",{error:e,qBase:s,symbol:u,element:t,reqTime:p})})}catch(e){C("qerror",{error:e,qBase:s,symbol:u,element:t,reqTime:p})}},d=$(n,t,s,i,q,u,p);if(c||v(d))c=!0,o.push(async()=>{await h(v(d)?await d:d)});else{const e=h(d);v(e)&&(c=!0,o.push(()=>e))}}}},x=(e,t=i,r=!0)=>{const n=_(e.type),o=t+":"+n,s=l+n,c=[],a=[],p=[];let q=e.target;for(;q;)N(q)?(c.push(q),a.push(T(q,o,s)),q=q.parentElement):q=q.parentElement;for(let t=c.length-1;t>=0;t--)if(a[t]&&(R(c[t],e,o,p,n,r),e.cancelBubble||e.cancelBubble))return void w(p);for(let t=0;t<c.length;t++)if(!a[t]&&(R(c[t],e,o,p,n,r),!e.bubbles||e.cancelBubble||e.cancelBubble))return void w(p);w(p)},L=e=>x(e,c,!1),U=(e,t,r=!0)=>{const n=_(t.type),o=e+":"+n,s=b("[q-"+e+"\\:"+n+"]"),i=[];for(let e=0;e<s.length;e++){const c=s[e];R(c,t,o,i,n,r)}w(i)},j=e=>{U(o,e)},D=e=>{U(s,e,!1)},O=e=>{U(r,e)},P=e=>{U(n,e,!1)},F=()=>{const r=e.readyState;if("interactive"==r||"complete"==r){if(f=1,p.forEach(g),a.has("d:qinit")){a.delete("d:qinit");const e=A("qinit"),t=b("[q-d\\:qinit]"),r=[];for(let n=0;n<t.length;n++){const o=t[n];R(o,e,"d:qinit",r),o.removeAttribute("q-d:qinit")}w(r)}if(a.has("d:qidle")&&(a.delete("d:qidle"),(t.requestIdleCallback??t.setTimeout).bind(t)(()=>{const e=A("qidle"),t=b("[q-d\\:qidle]"),r=[];for(let n=0;n<t.length;n++){const o=t[n];R(o,e,"d:qidle",r),o.removeAttribute("q-d:qidle")}w(r)})),a.has("e:qvisible")){u||(u=new IntersectionObserver(e=>{const t=[];for(let r=0;r<e.length;r++){const n=e[r];n.isIntersecting&&(u.unobserve(n.target),R(n.target,A("qvisible",n),"e:qvisible",t))}w(t)}));const e=b("[q-e\\:qvisible]:not([q\\:observed])");for(let t=0;t<e.length;t++){const r=e[t];u.observe(r),r.setAttribute("q:observed","true")}}}},J=(...e)=>{for(let n=0;n<e.length;n++){const s=e[n];if("string"==typeof s){if(!a.has(s)){a.add(s);const{scope:e,eventName:n}=B(s),i=S(e),c=I(e);c===r?m(t,n,i?P:O,!0,i):p.forEach(e=>m(e,n,c===o?i?D:j:i?L:x,!0,i)),1!==f||"e:qvisible"!==s&&"d:qinit"!==s&&"d:qidle"!==s||F()}}else p.has(s)||(a.forEach(e=>{const{scope:t,eventName:n}=B(e),i=S(t),c=I(t);c!==r&&m(s,n,c===o?i?D:j:i?L:x,!0,i)}),p.add(s))}},M=t._qwikEv;M?.roots||(Array.isArray(M)?J(...M):J("e:click","e:input"),t._qwikEv={events:a,roots:p,push:J},m(e,"readystatechange",F),F());
1
+ const e=document,t=window,n="w",r="wp",o="d",s="dp",i="e",c="ep",a="capture:",l="readystatechange",p="qready",u=new Set,q=new Set([e]),d=new Map;let h,f,b;const g=(e,t)=>Array.from(e.querySelectorAll(t)),m=e=>{const t=[];return q.forEach(n=>t.push(...g(n,e))),t},v=(e,t,n,r=!1,o=!1)=>e.addEventListener(t,n,{capture:r,passive:o}),y=e=>{z(e);const t=g(e,"[q\\:shadowroot]");for(let e=0;e<t.length;e++){const n=t[e].shadowRoot;n&&y(n)}},w=e=>e&&"function"==typeof e.then,E=async e=>{for(let t=0;t<e.length;t++)await e[t]()},A=e=>{if(e.length){const t=()=>E(e);b=b?b.then(t,t):t()}},C=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}}},_=t=>{const n=t.getAttribute("q:instance");return"paused"===t.getAttribute("q:container")&&"loading"===e.readyState&&!e[p]?.[n]&&new Promise(t=>{const r=o=>{o.detail===n&&(e.removeEventListener(p,r),t())};v(e,l,t),v(e,p,r)})},k=(e,t)=>new CustomEvent(e,{detail:t}),S=(t,n)=>{e.dispatchEvent(k(t,n))},$=e=>e.replace(/([A-Z-])/g,e=>"-"+e.toLowerCase()),I=e=>e.replace(/-./g,e=>e[1].toUpperCase()),L=e=>{const t=e.indexOf(":");return{scope:e.slice(0,t),eventName:I(e.slice(t+1))}},N=e=>2===e.length,R=e=>e.charAt(0),T=e=>!!e&&1===e.nodeType,x=(e,t,n)=>e.hasAttribute(n)&&(!!e._qDispatch?.[t]||e.hasAttribute("q-"+t)),B=(t,n,r,o,s,i,c,a=!0)=>{const l={qBase:r,symbol:i,element:n,reqTime:c};if(!s){const n=(e["qFuncs_"+t.getAttribute("q:instance")]||[])[+i];if(!n&&a){const e=Error("sym:"+i);S("qerror",{importError:"sync",error:e,...l}),console.error(e)}return n}const p=`${i}|${r}|${s}`,u=d.get(p);if(u)return u;const q=new URL(s,o).href,h=import(q);return C(t),h.then(e=>{const t=e[i];if(t)d.set(p,t),S("qsymbol",l);else{const e=Error(`${i} not in ${q}`);S("qerror",{importError:"no-symbol",error:e,...l}),console.error(e)}return t},e=>{S("qerror",{importError:"async",error:e,...l}),console.error(e)})},U=(t,n,r,o,s,i=!0)=>{let c=!1;s&&(i&&t.hasAttribute("preventdefault:"+s)&&n.preventDefault(),t.hasAttribute("stoppropagation:"+s)&&n.stopPropagation());const a=t._qDispatch?.[r];if(a){if("function"==typeof a){const e=()=>a(n,t);if(c)o.push(async()=>{const t=e();w(t)&&await t});else{const t=e();w(t)&&(c=!0,o.push(()=>t))}}else if(a.length)for(let e=0;e<a.length;e++){const r=a[e];if(r){const e=()=>r(n,t);if(c)o.push(async()=>{const t=e();w(t)&&await t});else{const t=e();w(t)&&(c=!0,o.push(()=>t))}}}return}const l=t.getAttribute("q-"+r);if(l){const r=t.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])"),s=r.getAttribute("q:base"),i=new URL(s,e.baseURI),a=l.split("|"),p=_(r);for(let e=0;e<a.length;e++){const l=a[e],u=performance.now(),[q,d,h]=l.split("#"),f=e=>{if(e&&t.isConnected){const o=n=>{const o=_(r);if(o)return o.then(()=>f(e));S("qerror",{error:n,qBase:s,symbol:d,element:t,reqTime:u})};try{const r=e.call(h,n,t);if(w(r))return r.catch(o)}catch(e){return o(e)}}},b=(e=!0)=>B(r,t,s,i,q,d,u,e),g=p&&!q?b(!1):b();if(w(g))c=!0,o.push(()=>g.then(f));else if(c||p&&!q&&!g)c=!0,o.push(async()=>{let e=g;!e&&p&&(await p,e=b(!1)),await f(e||await b())});else{const e=f(g);w(e)&&(c=!0,o.push(()=>e))}}}},j=(e,t=i,n=!0)=>{const r=$(e.type),o=t+":"+r,s=a+r,c=[],l=[],p=[];let u=e.target;for(;u;)T(u)?(c.push(u),l.push(x(u,o,s)),u=u.parentElement):u=u.parentElement;for(let t=c.length-1;t>=0;t--)if(l[t]&&(U(c[t],e,o,p,r,n),e.cancelBubble))return void A(p);for(let t=0;t<c.length;t++)if(!l[t]&&(U(c[t],e,o,p,r,n),!e.bubbles||e.cancelBubble))return void A(p);A(p)},D=e=>j(e,c,!1),O=(e,t,n=!0)=>{const r=$(t.type),o=e+":"+r,s=m("[q-"+e+"\\:"+r+"]"),i=[];for(let e=0;e<s.length;e++){const c=s[e];U(c,t,o,i,r,n)}A(i)},P=e=>{O(o,e)},F=e=>{O(s,e,!1)},J=e=>{O(n,e)},M=e=>{O(r,e,!1)},Z=()=>{const n=e.readyState;if("interactive"==n||"complete"==n){if(f=1,q.forEach(y),u.has("d:qinit")){u.delete("d:qinit");const e=k("qinit"),t=m("[q-d\\:qinit]"),n=[];for(let r=0;r<t.length;r++){const o=t[r];U(o,e,"d:qinit",n),o.removeAttribute("q-d:qinit")}A(n)}if(u.has("d:qidle")&&(u.delete("d:qidle"),(t.requestIdleCallback??t.setTimeout).bind(t)(()=>{const e=k("qidle"),t=m("[q-d\\:qidle]"),n=[];for(let r=0;r<t.length;r++){const o=t[r];U(o,e,"d:qidle",n),o.removeAttribute("q-d:qidle")}A(n)})),u.has("e:qvisible")){h||(h=new IntersectionObserver(e=>{const t=[];for(let n=0;n<e.length;n++){const r=e[n];r.isIntersecting&&(h.unobserve(r.target),U(r.target,k("qvisible",r),"e:qvisible",t))}A(t)}));const e=m("[q-e\\:qvisible]:not([q\\:observed])");for(let t=0;t<e.length;t++){const n=e[t];h.observe(n),n.setAttribute("q:observed","true")}}}},z=(...e)=>{for(let r=0;r<e.length;r++){const s=e[r];if("string"==typeof s){if(!u.has(s)){u.add(s);const{scope:e,eventName:r}=L(s),i=N(e),c=R(e);c===n?v(t,r,i?M:J,!0,i):q.forEach(e=>v(e,r,c===o?i?F:P:i?D:j,!0,i)),1!==f||"e:qvisible"!==s&&"d:qinit"!==s&&"d:qidle"!==s||Z()}}else q.has(s)||(u.forEach(e=>{const{scope:t,eventName:r}=L(e),i=N(t),c=R(t);c!==n&&v(s,r,c===o?i?F:P:i?D:j,!0,i)}),q.add(s))}},G=t._qwikEv;G?.roots||(Array.isArray(G)?z(...G):z("e:click","e:input"),t._qwikEv={events:u,roots:q,push:z},v(e,l,Z),Z());
@@ -1,5 +1,6 @@
1
1
  /// <reference types="./server" />
2
2
  declare module '@qwik-client-manifest' {
3
+ /** @deprecated Use `getClientManifest()` instead */
3
4
  const manifest: import('./optimizer').QwikManifest;
4
5
  export { manifest };
5
6
  }
package/dist/server.d.ts CHANGED
@@ -98,6 +98,9 @@ declare interface JSXNode<T extends string | FunctionComponent | unknown = unkno
98
98
  */
99
99
  declare type JSXOutput = JSXNode | string | number | boolean | null | undefined | JSXOutput[];
100
100
 
101
+ /** @public */
102
+ export declare type OutOfOrderStreaming = boolean;
103
+
101
104
  /** @public */
102
105
  export declare interface PrefetchResource {
103
106
  url: string;
@@ -289,6 +292,7 @@ declare interface Signal<T = any> {
289
292
  /** @public */
290
293
  export declare interface StreamingOptions {
291
294
  inOrder?: InOrderStreaming;
295
+ outOfOrder?: OutOfOrderStreaming;
292
296
  }
293
297
 
294
298
  /** @public */