@stacksjs/stx 0.2.679 → 0.2.682
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/chunk-01ks1244.js +2 -0
- package/dist/{chunk-qr7a378v.js → chunk-03xn8244.js} +3 -3
- package/dist/{chunk-ccmc5rqj.js → chunk-0527ytat.js} +2 -2
- package/dist/chunk-0gmwqhs0.js +2 -0
- package/dist/chunk-18jfkg1q.js +2 -0
- package/dist/chunk-1gw26g89.js +31 -0
- package/dist/chunk-1t6dg4s8.js +2 -0
- package/dist/{chunk-n8wvqnfc.js → chunk-1y50gat7.js} +2 -2
- package/dist/chunk-23efje42.js +2 -0
- package/dist/chunk-247fg189.js +2 -0
- package/dist/{chunk-xnx06qqt.js → chunk-2a1eeywj.js} +2 -2
- package/dist/{chunk-hh58k0nh.js → chunk-2ajbhefk.js} +2 -2
- package/dist/{chunk-p9az13b2.js → chunk-2ar5g9pa.js} +2 -2
- package/dist/{chunk-7j7h1eg3.js → chunk-2hh6g3y1.js} +1 -1
- package/dist/chunk-2zepd4ps.js +2 -0
- package/dist/chunk-34ps2w1z.js +2 -0
- package/dist/chunk-3tkag58v.js +2 -0
- package/dist/{chunk-ga5kjf9b.js → chunk-3zbege39.js} +6 -6
- package/dist/{chunk-2933mvwr.js → chunk-42qtadka.js} +10 -10
- package/dist/chunk-47fwr1z7.js +2 -0
- package/dist/{chunk-fzc98qgn.js → chunk-49c5v5fh.js} +6 -6
- package/dist/chunk-4g9wrxkm.js +2 -0
- package/dist/chunk-4m5g3f2b.js +2 -0
- package/dist/{chunk-tx4wfk5v.js → chunk-4z4sqc8q.js} +5 -5
- package/dist/{chunk-6ycyaf5g.js → chunk-58dv14c3.js} +2 -2
- package/dist/{chunk-87em5xdg.js → chunk-5nfb4gxk.js} +82 -82
- package/dist/chunk-5nrqc6v4.js +20 -0
- package/dist/chunk-5rdfcpfe.js +2 -0
- package/dist/{chunk-xyk2zxkk.js → chunk-65jb75vz.js} +2 -2
- package/dist/{chunk-5z8mq37c.js → chunk-6e60jp4a.js} +4 -4
- package/dist/chunk-7jxj6cv1.js +2 -0
- package/dist/{chunk-dnjbzwwn.js → chunk-7yree929.js} +1 -1
- package/dist/chunk-8bwa63m3.js +2 -0
- package/dist/chunk-8d0rqqyx.js +2 -0
- package/dist/chunk-8j0zcyd7.js +2 -0
- package/dist/chunk-8jxqg7kb.js +2 -0
- package/dist/chunk-8nk56cs2.js +2 -0
- package/dist/chunk-8y7tpjfs.js +2 -0
- package/dist/{chunk-q3gactm1.js → chunk-912r15hr.js} +4 -4
- package/dist/chunk-96hkch4q.js +2 -0
- package/dist/{chunk-4fhbh04h.js → chunk-974prn41.js} +4 -4
- package/dist/{chunk-078qg8r5.js → chunk-9bgb9n12.js} +2 -2
- package/dist/chunk-9qx6ansy.js +2 -0
- package/dist/{chunk-tst8p27s.js → chunk-9tg4995v.js} +3 -3
- package/dist/{chunk-sr3hmrah.js → chunk-9wa3t87n.js} +1 -1
- package/dist/{chunk-k06n5bjp.js → chunk-ae12wgc5.js} +3 -3
- package/dist/chunk-b375wt1n.js +2 -0
- package/dist/chunk-b5vqp3b2.js +2 -0
- package/dist/{chunk-vg1pg6yt.js → chunk-b7z6rqfg.js} +1 -1
- package/dist/{chunk-wt7rp7wc.js → chunk-bmqker64.js} +6 -6
- package/dist/{chunk-53e9ta3g.js → chunk-bmv6spcd.js} +4 -4
- package/dist/chunk-bpf3xxng.js +3 -0
- package/dist/{chunk-chy90834.js → chunk-brcj3953.js} +5 -5
- package/dist/chunk-brftzqzj.js +3 -0
- package/dist/chunk-bv43s0gx.js +2 -0
- package/dist/chunk-c9jnkbdb.js +2 -0
- package/dist/{chunk-x7wr720m.js → chunk-d1ssvg9k.js} +5 -5
- package/dist/{chunk-5z0q3qv3.js → chunk-d7js6v1m.js} +5 -5
- package/dist/{chunk-vd5w1jaz.js → chunk-drabexxq.js} +3 -3
- package/dist/{chunk-k72jqz6a.js → chunk-e26pxzjj.js} +2 -2
- package/dist/{chunk-2pvcp0y6.js → chunk-e97xj3rf.js} +6 -6
- package/dist/chunk-ev1tnd36.js +2 -0
- package/dist/{chunk-j388n7v2.js → chunk-f1hxrs7b.js} +17 -17
- package/dist/{chunk-wr1gm35v.js → chunk-f4z9w4kc.js} +1 -1
- package/dist/chunk-f80aqbwm.js +2 -0
- package/dist/chunk-fbbp8j97.js +2 -0
- package/dist/{chunk-26ps9djm.js → chunk-fqts9wvd.js} +5 -5
- package/dist/chunk-fy1waxy0.js +2 -0
- package/dist/chunk-g2v6c7kf.js +2 -0
- package/dist/chunk-g5ep75vp.js +2 -0
- package/dist/{chunk-wejabf6y.js → chunk-g83qeh2x.js} +5 -5
- package/dist/chunk-g9a56wwk.js +2 -0
- package/dist/chunk-gkmh0xys.js +2 -0
- package/dist/{chunk-78yjmbbs.js → chunk-gtktv6nn.js} +2 -2
- package/dist/{chunk-f26n6y9p.js → chunk-gymmbbzc.js} +4 -4
- package/dist/{chunk-48ma0qcr.js → chunk-h3bdqqzy.js} +2 -2
- package/dist/chunk-h5r4c9v5.js +2 -0
- package/dist/{chunk-3xyv2fec.js → chunk-hg7ys8rn.js} +3 -3
- package/dist/{chunk-kxj8e1gd.js → chunk-hm69jxmh.js} +6 -6
- package/dist/{chunk-y4ncmvf2.js → chunk-hwaqwrc2.js} +3 -3
- package/dist/chunk-jecmxby7.js +2 -0
- package/dist/{chunk-a2zb5fgg.js → chunk-jkywbfb0.js} +2 -2
- package/dist/{chunk-haz2ezyk.js → chunk-k3e0hcv7.js} +2 -2
- package/dist/{chunk-drmgwjnb.js → chunk-ka3xmbrd.js} +76 -76
- package/dist/chunk-kerxevf9.js +2 -0
- package/dist/chunk-km37yrk4.js +43 -0
- package/dist/chunk-mdmwgthz.js +2 -0
- package/dist/chunk-myc60z74.js +2 -0
- package/dist/chunk-mzkyw4yx.js +2 -0
- package/dist/{chunk-nb3kkvet.js → chunk-n8jq9yjy.js} +11 -11
- package/dist/{chunk-y34tyrpb.js → chunk-nbjyed3q.js} +7 -7
- package/dist/{chunk-d40zjm6k.js → chunk-np3zdjhr.js} +6 -6
- package/dist/{chunk-wav0xbnb.js → chunk-pfn70zdr.js} +2 -2
- package/dist/{chunk-tbb4en1q.js → chunk-pmma4f1x.js} +4 -4
- package/dist/chunk-pqg3ghvh.js +2 -0
- package/dist/chunk-pvn0fc7j.js +2 -0
- package/dist/{chunk-q4rejyd2.js → chunk-pzxy40a2.js} +2 -2
- package/dist/chunk-q7mpearc.js +2 -0
- package/dist/{chunk-7z7zp8xq.js → chunk-qb806pks.js} +5 -5
- package/dist/{chunk-wscnjtss.js → chunk-qh7fvr2z.js} +2 -2
- package/dist/chunk-r8hszntk.js +2 -0
- package/dist/{chunk-wc5tt6da.js → chunk-remsyfdx.js} +2 -2
- package/dist/chunk-rk8kmshp.js +2 -0
- package/dist/chunk-rs67af2x.js +1592 -0
- package/dist/{chunk-97h9ga3b.js → chunk-rspe6qa5.js} +3 -3
- package/dist/{chunk-78x52gz3.js → chunk-ry501z40.js} +5 -5
- package/dist/chunk-s0wa7zjr.js +2 -0
- package/dist/{chunk-qvefcnyb.js → chunk-se4n8tth.js} +2 -2
- package/dist/chunk-sncp7jhv.js +2 -0
- package/dist/{chunk-jv021x8e.js → chunk-sq4w1e1g.js} +2 -2
- package/dist/chunk-sqvdrk81.js +2 -0
- package/dist/{chunk-9wdd7eq6.js → chunk-t6m5d64b.js} +2 -2
- package/dist/chunk-tdwqwxhf.js +25 -0
- package/dist/{chunk-dera8fmc.js → chunk-tenbwcts.js} +2 -2
- package/dist/chunk-th45zgbz.js +54 -0
- package/dist/{chunk-cxgremn0.js → chunk-tpdvgb3d.js} +1 -1
- package/dist/chunk-tq2m6m3j.js +2 -0
- package/dist/{chunk-aw3jfdca.js → chunk-veh25cv5.js} +1 -1
- package/dist/chunk-vqv5w6gs.js +2 -0
- package/dist/chunk-vt5e25xg.js +2 -0
- package/dist/{chunk-028e9fty.js → chunk-vxnf3xab.js} +2 -2
- package/dist/{chunk-mabja59q.js → chunk-vxrhvrr9.js} +2 -2
- package/dist/{chunk-tmqrbs98.js → chunk-w1wzydvp.js} +8 -5
- package/dist/{chunk-qwdcts9w.js → chunk-w28wc7mv.js} +13 -13
- package/dist/{chunk-yxw8gbnh.js → chunk-wfg5379k.js} +4 -4
- package/dist/chunk-wvz7rp5p.js +2 -0
- package/dist/{chunk-k4x8v39k.js → chunk-xfdfk4g4.js} +2 -2
- package/dist/chunk-xjx1xbey.js +2 -0
- package/dist/{chunk-mn47s2ef.js → chunk-xr9a0hcr.js} +5 -5
- package/dist/{chunk-1b9thkg5.js → chunk-xvnrm5c3.js} +2 -2
- package/dist/{chunk-mf19qxgv.js → chunk-xvs84gas.js} +2 -2
- package/dist/{chunk-8aq07a1j.js → chunk-y55pcfaj.js} +3 -3
- package/dist/{chunk-2hmyj5wh.js → chunk-yhfm939b.js} +2 -2
- package/dist/chunk-ykjzhfyf.js +2 -0
- package/dist/chunk-ypwetty7.js +21 -0
- package/dist/chunk-z4khbpx0.js +2 -0
- package/dist/{chunk-9rs12v0r.js → chunk-z5av310q.js} +9 -9
- package/dist/chunk-zr16mga0.js +2 -0
- package/dist/{chunk-dxh45gve.js → chunk-zt5hp5w5.js} +1 -1
- package/dist/chunk-zwawqx5q.js +2 -0
- package/dist/cli.js +20 -20
- package/dist/client/signals-manifest-hydration-runtime.js +4 -1
- package/dist/component-client-factories.js +14 -3
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/dev-server/serve-app.js +10 -1
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +6 -6
- package/dist/utils.js +13 -1
- package/package.json +5 -5
- package/dist/chunk-0fjwqs9h.js +0 -2
- package/dist/chunk-0gk78x3r.js +0 -2
- package/dist/chunk-0v35wpm7.js +0 -2
- package/dist/chunk-1dkcakve.js +0 -25
- package/dist/chunk-1gg5vxe8.js +0 -2
- package/dist/chunk-1j0sarne.js +0 -21
- package/dist/chunk-248a88mc.js +0 -2
- package/dist/chunk-2nqtmp8c.js +0 -2
- package/dist/chunk-2yzwrvq1.js +0 -2
- package/dist/chunk-3bfegbpw.js +0 -2
- package/dist/chunk-3wsm9g9c.js +0 -2
- package/dist/chunk-3xx9d934.js +0 -2
- package/dist/chunk-52x079ax.js +0 -2
- package/dist/chunk-54zkkxmb.js +0 -2
- package/dist/chunk-5fmxn52y.js +0 -2
- package/dist/chunk-61ww9d2z.js +0 -2
- package/dist/chunk-75zc8w68.js +0 -2
- package/dist/chunk-7b3phzx4.js +0 -2
- package/dist/chunk-8p92r2sc.js +0 -2
- package/dist/chunk-8xr8y9sq.js +0 -2
- package/dist/chunk-909ymsjz.js +0 -2
- package/dist/chunk-ac75vk0w.js +0 -2
- package/dist/chunk-arh1qgmp.js +0 -2
- package/dist/chunk-b0th3d8q.js +0 -888
- package/dist/chunk-bh19ezq0.js +0 -43
- package/dist/chunk-bm42rsaa.js +0 -2
- package/dist/chunk-cfm6a679.js +0 -2
- package/dist/chunk-cwmazy7y.js +0 -2
- package/dist/chunk-e492je6q.js +0 -2
- package/dist/chunk-ft1ht0b3.js +0 -2
- package/dist/chunk-ft3f9nj0.js +0 -2
- package/dist/chunk-ggwvnpwj.js +0 -2
- package/dist/chunk-gx6wxmbv.js +0 -2
- package/dist/chunk-hamk3dky.js +0 -2
- package/dist/chunk-hqj28381.js +0 -3
- package/dist/chunk-k093pr2w.js +0 -2
- package/dist/chunk-kcp392wy.js +0 -2
- package/dist/chunk-kejrhccx.js +0 -2
- package/dist/chunk-kmj127rm.js +0 -2
- package/dist/chunk-kqbpkg8n.js +0 -2
- package/dist/chunk-m0f3strn.js +0 -2
- package/dist/chunk-mjsebtg6.js +0 -2
- package/dist/chunk-n8f0zw1y.js +0 -31
- package/dist/chunk-nadgej53.js +0 -2
- package/dist/chunk-nh3kd03f.js +0 -2
- package/dist/chunk-nw2zh40z.js +0 -2
- package/dist/chunk-p01b07se.js +0 -54
- package/dist/chunk-p99an8rj.js +0 -2
- package/dist/chunk-pgvwysxq.js +0 -2
- package/dist/chunk-pz3mg7hr.js +0 -2
- package/dist/chunk-qyf3jcy1.js +0 -2
- package/dist/chunk-rc79yyqx.js +0 -2
- package/dist/chunk-s8qe247r.js +0 -2
- package/dist/chunk-sswy3tfc.js +0 -2
- package/dist/chunk-swxznm5v.js +0 -2
- package/dist/chunk-t3gmm1ja.js +0 -2
- package/dist/chunk-tsrf4zzy.js +0 -2
- package/dist/chunk-tz09earb.js +0 -2
- package/dist/chunk-vct8a1qf.js +0 -20
- package/dist/chunk-x4q4bx3q.js +0 -3
- package/dist/chunk-xna6b7km.js +0 -2
- package/dist/chunk-xw4rm5zj.js +0 -2
- package/dist/chunk-yar7fwrb.js +0 -2
- package/dist/chunk-yt33wzqk.js +0 -2
- package/dist/chunk-zcbp27x1.js +0 -2
- package/dist/chunk-zq7xbc1k.js +0 -2
|
@@ -0,0 +1,1592 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Ro,Aa,s,Tt,se,k,Pe,cn,Ie,de,K,cr,ln,ms,za,dn,dr,ys,bs,Ha,Do,Va,Ua,Wa,qa,Ne,De,vs,je,n,gn,m,d,V,Y,we,x,_}from"./chunk-5nfb4gxk.js";import{l,p,E,t,ie,U,a,xe,qo,D,bn,Go,Lt,Ko,oc,mr,ic,rt,ac,hr,cc,vn,Xo,lc,yr,vr,Se,Jo}from"./chunk-w28wc7mv.js";import{Nt}from"./chunk-t6m5d64b.js";import{hn}from"./chunk-remsyfdx.js";import{h}from"./chunk-bmqker64.js";import{rr,os}from"./chunk-gymmbbzc.js";import{ga,ma,er,Je,ha,R}from"./chunk-42qtadka.js";import{wo,xo,So,ko}from"./chunk-nbjyed3q.js";import{la,Vr}from"./chunk-brcj3953.js";import{Br,Fr,zr}from"./chunk-th45zgbz.js";import{Ur,po,fo,Wr,qr,go}from"./chunk-ypwetty7.js";import{jr,Kn}from"./chunk-tdwqwxhf.js";import{ro}from"./chunk-9bgb9n12.js";import{re,ao,co,lo}from"./chunk-2a1eeywj.js";import{Jn,he,da,Yn,pa}from"./chunk-e97xj3rf.js";import{G,Ke}from"./chunk-jkywbfb0.js";import{ya,ba}from"./chunk-hg7ys8rn.js";import{C,wn,Yo}from"./chunk-2ajbhefk.js";import gs from"fs";import ce from"path";function lt(){return`
|
|
3
|
+
// STX Lifecycle Runtime
|
|
4
|
+
(function() {
|
|
5
|
+
if (typeof window === 'undefined') return;
|
|
6
|
+
|
|
7
|
+
const instances = new Map();
|
|
8
|
+
let currentInstance = null;
|
|
9
|
+
let idCounter = 0;
|
|
10
|
+
|
|
11
|
+
function generateId() {
|
|
12
|
+
return 'stx-' + (++idCounter) + '-' + Date.now().toString(36);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function createInstance(element) {
|
|
16
|
+
const instance = {
|
|
17
|
+
id: generateId(),
|
|
18
|
+
element: element,
|
|
19
|
+
mountHooks: [],
|
|
20
|
+
destroyHooks: [],
|
|
21
|
+
updateHooks: [],
|
|
22
|
+
refs: new Map(),
|
|
23
|
+
watchers: [],
|
|
24
|
+
isMounted: false
|
|
25
|
+
};
|
|
26
|
+
instances.set(instance.id, instance);
|
|
27
|
+
return instance;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
window.STX = window.STX || {};
|
|
31
|
+
|
|
32
|
+
// Lifecycle hooks
|
|
33
|
+
window.STX.onMount = function(hook) {
|
|
34
|
+
if (currentInstance) currentInstance.mountHooks.push(hook);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
window.STX.onDestroy = function(hook) {
|
|
38
|
+
if (currentInstance) currentInstance.destroyHooks.push(hook);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
window.STX.onUpdate = function(hook) {
|
|
42
|
+
if (currentInstance) currentInstance.updateHooks.push(hook);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Aliases
|
|
46
|
+
window.STX.onMounted = window.STX.onMount;
|
|
47
|
+
window.STX.onUnmounted = window.STX.onDestroy;
|
|
48
|
+
window.STX.onUpdated = window.STX.onUpdate;
|
|
49
|
+
|
|
50
|
+
// Refs
|
|
51
|
+
window.STX.ref = function(initialValue) {
|
|
52
|
+
const r = { value: initialValue || null };
|
|
53
|
+
Object.defineProperty(r, 'current', {
|
|
54
|
+
get: function() { return this.value; }
|
|
55
|
+
});
|
|
56
|
+
if (currentInstance) {
|
|
57
|
+
currentInstance.refs.set('ref-' + currentInstance.refs.size, r);
|
|
58
|
+
}
|
|
59
|
+
return r;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Watch
|
|
63
|
+
window.STX.watch = function(source, callback, options) {
|
|
64
|
+
options = options || {};
|
|
65
|
+
let oldValue;
|
|
66
|
+
let cleanup;
|
|
67
|
+
let isActive = true;
|
|
68
|
+
|
|
69
|
+
function run() {
|
|
70
|
+
if (!isActive) return;
|
|
71
|
+
const newValue = source();
|
|
72
|
+
if (oldValue !== newValue || options.immediate) {
|
|
73
|
+
if (cleanup) cleanup();
|
|
74
|
+
cleanup = callback(newValue, oldValue);
|
|
75
|
+
oldValue = newValue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (options.immediate) {
|
|
80
|
+
run();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
oldValue = source();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const intervalId = setInterval(run, 16);
|
|
87
|
+
|
|
88
|
+
function stop() {
|
|
89
|
+
isActive = false;
|
|
90
|
+
clearInterval(intervalId);
|
|
91
|
+
if (cleanup) cleanup();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (currentInstance) {
|
|
95
|
+
currentInstance.watchers.push({ stop: stop });
|
|
96
|
+
currentInstance.destroyHooks.push(stop);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return stop;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Computed
|
|
103
|
+
window.STX.computed = function(getter) {
|
|
104
|
+
let cached;
|
|
105
|
+
let dirty = true;
|
|
106
|
+
return {
|
|
107
|
+
get value() {
|
|
108
|
+
if (dirty) {
|
|
109
|
+
cached = getter();
|
|
110
|
+
dirty = false;
|
|
111
|
+
queueMicrotask(function() { dirty = true; });
|
|
112
|
+
}
|
|
113
|
+
return cached;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Component management
|
|
119
|
+
window.STX.setupComponent = function(element, setup) {
|
|
120
|
+
const instance = createInstance(element);
|
|
121
|
+
currentInstance = instance;
|
|
122
|
+
try {
|
|
123
|
+
setup();
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
currentInstance = null;
|
|
127
|
+
}
|
|
128
|
+
return instance;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
window.STX.mountComponent = function(instance) {
|
|
132
|
+
if (instance.isMounted) return;
|
|
133
|
+
instance.isMounted = true;
|
|
134
|
+
instance.mountHooks.forEach(function(hook) {
|
|
135
|
+
try {
|
|
136
|
+
const cleanup = hook();
|
|
137
|
+
if (typeof cleanup === 'function') {
|
|
138
|
+
instance.destroyHooks.push(cleanup);
|
|
139
|
+
}
|
|
140
|
+
else if (cleanup && typeof cleanup.then === 'function') {
|
|
141
|
+
cleanup.catch(function(e) { console.error('[stx] onMount error:', e); });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
console.error('[stx] onMount error:', e);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
window.STX.destroyComponent = function(instance) {
|
|
151
|
+
if (!instance.isMounted) return;
|
|
152
|
+
instance.watchers.forEach(function(w) { w.stop(); });
|
|
153
|
+
instance.destroyHooks.forEach(function(hook) {
|
|
154
|
+
try { hook(); }
|
|
155
|
+
catch (e) { console.error('[stx] onDestroy error:', e); }
|
|
156
|
+
});
|
|
157
|
+
instance.refs.forEach(function(ref) { ref.value = null; });
|
|
158
|
+
instance.isMounted = false;
|
|
159
|
+
instances.delete(instance.id);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// ==========================================================================
|
|
163
|
+
// Vue-Style Refs System - No document.** required!
|
|
164
|
+
// ==========================================================================
|
|
165
|
+
|
|
166
|
+
// Internal: Query for ref elements without exposing document API
|
|
167
|
+
function queryRef(name, root) {
|
|
168
|
+
return (root || document).querySelector('[data-stx-ref="' + name + '"], [data-ref="' + name + '"]');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function queryAllRefs(root) {
|
|
172
|
+
return (root || document).querySelectorAll('[data-stx-ref], [data-ref]');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Auto-bind refs from ref attributes (Vue-style)
|
|
176
|
+
window.STX.bindRefs = function(root, refs) {
|
|
177
|
+
if (!root) return;
|
|
178
|
+
queryAllRefs(root).forEach(function(el) {
|
|
179
|
+
var refName = el.getAttribute('data-stx-ref') || el.getAttribute('data-ref');
|
|
180
|
+
if (refs[refName]) {
|
|
181
|
+
refs[refName].value = el;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Vue-style useRefs() - returns object with all refs as direct elements
|
|
187
|
+
// Usage: const { input, button, container } = STX.useRefs()
|
|
188
|
+
window.STX.useRefs = function(root) {
|
|
189
|
+
var refs = {};
|
|
190
|
+
queryAllRefs(root).forEach(function(el) {
|
|
191
|
+
var refName = el.getAttribute('data-stx-ref') || el.getAttribute('data-ref');
|
|
192
|
+
if (refName) {
|
|
193
|
+
refs[refName] = el;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return refs;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// Get a single ref by name - Vue's useTemplateRef equivalent
|
|
200
|
+
// Usage: const input = STX.useRef('input')
|
|
201
|
+
window.STX.useRef = function(name, root) {
|
|
202
|
+
return queryRef(name, root);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Two-way binding helper for form elements
|
|
206
|
+
// Usage: STX.model(inputEl, state, 'username')
|
|
207
|
+
window.STX.model = function(el, state, key) {
|
|
208
|
+
if (!el || !state) return;
|
|
209
|
+
|
|
210
|
+
var isCheckbox = el.type === 'checkbox';
|
|
211
|
+
var isRadio = el.type === 'radio';
|
|
212
|
+
var isSelect = el.tagName === 'SELECT';
|
|
213
|
+
|
|
214
|
+
// Set initial value
|
|
215
|
+
if (isCheckbox) {
|
|
216
|
+
el.checked = !!state[key];
|
|
217
|
+
}
|
|
218
|
+
else if (isRadio) {
|
|
219
|
+
el.checked = el.value === state[key];
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
el.value = state[key] || '';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Listen for changes
|
|
226
|
+
var eventType = isCheckbox || isRadio ? 'change' : 'input';
|
|
227
|
+
el.addEventListener(eventType, function() {
|
|
228
|
+
if (isCheckbox) {
|
|
229
|
+
state[key] = el.checked;
|
|
230
|
+
}
|
|
231
|
+
else if (isRadio) {
|
|
232
|
+
if (el.checked) state[key] = el.value;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
state[key] = el.value;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Return cleanup function
|
|
240
|
+
return function() {
|
|
241
|
+
el.removeEventListener(eventType, arguments.callee);
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Batch event binding helper - cleaner than manual addEventListener
|
|
246
|
+
// Usage: STX.on({ click: [btn1, btn2], input: [textField] }, handler)
|
|
247
|
+
window.STX.on = function(el, event, handler) {
|
|
248
|
+
if (!el) return function() {};
|
|
249
|
+
el.addEventListener(event, handler);
|
|
250
|
+
return function() { el.removeEventListener(event, handler); };
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// Bind multiple events at once
|
|
254
|
+
// Usage: STX.events(refs.btn, { click: handleClick, mouseenter: handleHover })
|
|
255
|
+
window.STX.events = function(el, eventMap) {
|
|
256
|
+
if (!el) return function() {};
|
|
257
|
+
var cleanups = [];
|
|
258
|
+
Object.keys(eventMap).forEach(function(event) {
|
|
259
|
+
el.addEventListener(event, eventMap[event]);
|
|
260
|
+
cleanups.push(function() { el.removeEventListener(event, eventMap[event]); });
|
|
261
|
+
});
|
|
262
|
+
return function() { cleanups.forEach(function(c) { c(); }); };
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// ==========================================================================
|
|
266
|
+
// DOM Helpers - Eliminate document.* usage
|
|
267
|
+
// ==========================================================================
|
|
268
|
+
|
|
269
|
+
// Global keyboard event listener
|
|
270
|
+
// Usage: STX.onKey('Escape', () => closeModal())
|
|
271
|
+
window.STX.onKey = function(key, handler, options) {
|
|
272
|
+
var listener = function(e) {
|
|
273
|
+
if (e.key === key) {
|
|
274
|
+
handler(e);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
document.addEventListener('keydown', listener, options);
|
|
278
|
+
return function() { document.removeEventListener('keydown', listener, options); };
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Create element helper
|
|
282
|
+
// Usage: STX.el('div', { class: 'foo' }, 'text content')
|
|
283
|
+
window.STX.el = function(tag, attrs, content) {
|
|
284
|
+
var el = document.createElement(tag);
|
|
285
|
+
if (attrs) {
|
|
286
|
+
Object.keys(attrs).forEach(function(key) {
|
|
287
|
+
if (key === 'class') {
|
|
288
|
+
el.className = attrs[key];
|
|
289
|
+
}
|
|
290
|
+
else if (key.startsWith('on')) {
|
|
291
|
+
el.addEventListener(key.slice(2).toLowerCase(), attrs[key]);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
el.setAttribute(key, attrs[key]);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (content) {
|
|
299
|
+
if (typeof content === 'string') {
|
|
300
|
+
el.textContent = content;
|
|
301
|
+
}
|
|
302
|
+
else if (Array.isArray(content)) {
|
|
303
|
+
content.forEach(function(child) { el.appendChild(child); });
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
el.appendChild(content);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return el;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// Get currently focused element
|
|
313
|
+
// Usage: const focused = STX.activeElement()
|
|
314
|
+
window.STX.activeElement = function() {
|
|
315
|
+
return document.activeElement;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// Escape HTML helper
|
|
319
|
+
// Usage: const safe = STX.escapeHtml(userInput)
|
|
320
|
+
window.STX.escapeHtml = function(text) {
|
|
321
|
+
var div = document.createElement('div');
|
|
322
|
+
div.textContent = text;
|
|
323
|
+
return div.innerHTML;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// MutationObserver for automatic lifecycle management
|
|
327
|
+
const observer = new MutationObserver(function(mutations) {
|
|
328
|
+
mutations.forEach(function(mutation) {
|
|
329
|
+
// Handle removed nodes
|
|
330
|
+
mutation.removedNodes.forEach(function(node) {
|
|
331
|
+
if (node.nodeType === 1 && node.__stx_instance__) {
|
|
332
|
+
window.STX.destroyComponent(node.__stx_instance__);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// Start observing when DOM is ready
|
|
339
|
+
if (document.readyState === 'loading') {
|
|
340
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
341
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
console.log('[stx] Lifecycle runtime initialized');
|
|
349
|
+
})();
|
|
350
|
+
`}function Ge(i){return Symbol(i)}var Rs=Ge("theme"),Ms=Ge("router"),Ds=Ge("i18n");import*as dt from"crypto";function ut(i){let e=/\$(\w+)\./g,u=[],c;while((c=e.exec(i))!==null)if(!u.includes(c[1]))u.push(c[1]);return u}function In(){return`stx-${dt.randomBytes(4).toString("hex")}`}function On(i){return/\$\w+\./.test(i)}function Pn(i){if(!/\{\{[^}]*\$\w/.test(i)||!/\$\w+\./.test(i))return{html:i,bindings:[],stores:new Set};let e=[],u=new Set,c=/<(\w+)([^>]*?)(\s*\/?>)/g,g=i;return g=g.replace(c,(r,f,v,y)=>{if(["script","style","template"].includes(f.toLowerCase()))return r;if(!v.includes("{{"))return r;let S=[],b=!1,w=v,T=/(\w+(?:-\w+)*)\s*=\s*"([^"]*\{\{[^}]*\$\w+[^}]*\}\}[^"]*)"/g,A=[...v.matchAll(T)];for(let I of A){let P=I[0],N=I[1],F=I[2];if(On(F)){b=!0;let z=F.match(/\{\{\s*([\s\S]+?)\s*\}\}/);if(z){let L=z[1];if(S.push({attr:N,expr:L,fullMatch:P,originalAttr:N}),ut(L).forEach((H)=>u.add(H)),N==="text")w=w.replace(P,"");else if(N==="class")w=w.replace(P,'class=""');else if(N==="disabled"||N==="hidden")w=w.replace(P,"");else w=w.replace(P,`${N}=""`)}}}if(!b)return r;let O=w.match(/\bid\s*=\s*"([^"]+)"/),M;if(O)M=O[1];else M=In(),w=` id="${M}"${w}`;for(let I of S)e.push({elementId:M,attribute:I.attr,expression:I.expr,stores:ut(I.expr)});return`<${f}${w}${y}`}),{html:g,bindings:e,stores:u}}function Ln(i,e){if(i.length===0)return"";let u=Array.from(e),c=`
|
|
351
|
+
<script>
|
|
352
|
+
(function() {
|
|
353
|
+
'use strict';
|
|
354
|
+
|
|
355
|
+
// Wait for stores to be available
|
|
356
|
+
function initBindings() {
|
|
357
|
+
var stores = window.VoideStores;
|
|
358
|
+
if (!stores) {
|
|
359
|
+
setTimeout(initBindings, 10);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Store references for expressions
|
|
364
|
+
// eslint-disable-next-line pickier/no-unused-vars
|
|
365
|
+
var $state = {};
|
|
366
|
+
`;for(let g of u)c+=` $state.${g} = stores.${g} ? stores.${g}.get() : {};
|
|
367
|
+
`;c+=`
|
|
368
|
+
// Binding update functions
|
|
369
|
+
function updateBindings() {
|
|
370
|
+
`;for(let g of i){let{elementId:r,attribute:f,expression:v}=g,y=v.replace(/\$(\w+)\./g,"$state.$1.");if(f==="text")c+=` (function() {
|
|
371
|
+
var el = document.getElementById('${r}');
|
|
372
|
+
if (el) {
|
|
373
|
+
try {
|
|
374
|
+
el.textContent = ${y};
|
|
375
|
+
}
|
|
376
|
+
catch (e) { console.error('Binding error:', e); }
|
|
377
|
+
}
|
|
378
|
+
})();
|
|
379
|
+
`;else if(f==="html")c+=` (function() {
|
|
380
|
+
var el = document.getElementById('${r}');
|
|
381
|
+
if (el) {
|
|
382
|
+
try {
|
|
383
|
+
el.innerHTML = ${y};
|
|
384
|
+
}
|
|
385
|
+
catch (e) { console.error('Binding error:', e); }
|
|
386
|
+
}
|
|
387
|
+
})();
|
|
388
|
+
`;else if(f==="class")c+=` (function() {
|
|
389
|
+
var el = document.getElementById('${r}');
|
|
390
|
+
if (el) {
|
|
391
|
+
try {
|
|
392
|
+
var value = ${y};
|
|
393
|
+
if (typeof value === 'string') {
|
|
394
|
+
// Dynamic class string - merge with existing static classes
|
|
395
|
+
// eslint-disable-next-line pickier/no-unused-vars
|
|
396
|
+
var staticClasses = el.getAttribute('data-static-class') || el.className;
|
|
397
|
+
if (!el.hasAttribute('data-static-class')) {
|
|
398
|
+
el.setAttribute('data-static-class', el.className);
|
|
399
|
+
}
|
|
400
|
+
el.className = (el.getAttribute('data-static-class') + ' ' + value).trim();
|
|
401
|
+
}
|
|
402
|
+
else if (typeof value === 'object') {
|
|
403
|
+
// Object syntax: { 'class-name': condition }
|
|
404
|
+
for (var cls in value) {
|
|
405
|
+
if (value[cls]) {
|
|
406
|
+
el.classList.add(cls);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
el.classList.remove(cls);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
catch (e) { console.error('Binding error:', e); }
|
|
415
|
+
}
|
|
416
|
+
})();
|
|
417
|
+
`;else if(f==="show")c+=` (function() {
|
|
418
|
+
var el = document.getElementById('${r}');
|
|
419
|
+
if (el) {
|
|
420
|
+
try {
|
|
421
|
+
el.style.display = (${y}) ? '' : 'none';
|
|
422
|
+
}
|
|
423
|
+
catch (e) { console.error('Binding error:', e); }
|
|
424
|
+
}
|
|
425
|
+
})();
|
|
426
|
+
`;else if(f==="if")c+=` (function() {
|
|
427
|
+
var el = document.getElementById('${r}');
|
|
428
|
+
if (el) {
|
|
429
|
+
try {
|
|
430
|
+
el.style.visibility = (${y}) ? 'visible' : 'hidden';
|
|
431
|
+
}
|
|
432
|
+
catch (e) { console.error('Binding error:', e); }
|
|
433
|
+
}
|
|
434
|
+
})();
|
|
435
|
+
`;else c+=` (function() {
|
|
436
|
+
var el = document.getElementById('${r}');
|
|
437
|
+
if (el) {
|
|
438
|
+
try {
|
|
439
|
+
var value = ${y};
|
|
440
|
+
if (value === false || value === null || value === undefined) {
|
|
441
|
+
el.removeAttribute('${f}');
|
|
442
|
+
}
|
|
443
|
+
else if (value === true) {
|
|
444
|
+
el.setAttribute('${f}', '');
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
el.setAttribute('${f}', value);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch (e) { console.error('Binding error:', e); }
|
|
451
|
+
}
|
|
452
|
+
})();
|
|
453
|
+
`}c+=` }
|
|
454
|
+
|
|
455
|
+
// Subscribe to stores and update on changes. Capture the disposers so
|
|
456
|
+
// SPA fragment swaps can tear down old bindings before the next page's
|
|
457
|
+
// runtime takes over \u2014 without this, every navigation between pages
|
|
458
|
+
// using reactive-bindings stacked another subscription on every store,
|
|
459
|
+
// walking detached DOM forever. See stacksjs/stx#1709.
|
|
460
|
+
var _disposers = [];
|
|
461
|
+
`;for(let g of u)c+=` if (stores.${g}) {
|
|
462
|
+
var _unsub_${g} = stores.${g}.subscribe(function(state) {
|
|
463
|
+
$state.${g} = state;
|
|
464
|
+
updateBindings();
|
|
465
|
+
});
|
|
466
|
+
// store.subscribe() may return the disposer (preferred) or void; both
|
|
467
|
+
// are tolerated here.
|
|
468
|
+
if (typeof _unsub_${g} === 'function') _disposers.push(_unsub_${g});
|
|
469
|
+
}
|
|
470
|
+
`;return c+=`
|
|
471
|
+
// Initial update
|
|
472
|
+
updateBindings();
|
|
473
|
+
|
|
474
|
+
// Register this runtime's cleanup so SPA navigation can run it before
|
|
475
|
+
// swapping pages. The router (and any code) can call
|
|
476
|
+
// window.__stxCleanupBindings() to dispose subscriptions; we also wire
|
|
477
|
+
// 'popstate' and 'beforeunload' as a safety net for browser-driven nav.
|
|
478
|
+
function _cleanup() {
|
|
479
|
+
for (var i = 0; i < _disposers.length; i++) {
|
|
480
|
+
try { _disposers[i](); } catch (e) { /* swallow */ }
|
|
481
|
+
}
|
|
482
|
+
_disposers.length = 0;
|
|
483
|
+
}
|
|
484
|
+
if (!window.__stxBindingsCleanups) window.__stxBindingsCleanups = [];
|
|
485
|
+
window.__stxBindingsCleanups.push(_cleanup);
|
|
486
|
+
if (!window.__stxCleanupBindings) {
|
|
487
|
+
window.__stxCleanupBindings = function() {
|
|
488
|
+
var fns = window.__stxBindingsCleanups || [];
|
|
489
|
+
for (var i = 0; i < fns.length; i++) {
|
|
490
|
+
try { fns[i](); } catch (e) { /* swallow */ }
|
|
491
|
+
}
|
|
492
|
+
window.__stxBindingsCleanups = [];
|
|
493
|
+
};
|
|
494
|
+
window.addEventListener('popstate', window.__stxCleanupBindings);
|
|
495
|
+
window.addEventListener('beforeunload', window.__stxCleanupBindings);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Start when DOM is ready
|
|
500
|
+
if (document.readyState === 'loading') {
|
|
501
|
+
document.addEventListener('DOMContentLoaded', initBindings);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
initBindings();
|
|
505
|
+
}
|
|
506
|
+
})();
|
|
507
|
+
</script>
|
|
508
|
+
`,c}function pt(i){let{html:e,bindings:u,stores:c}=Pn(i);if(u.length===0)return i;let g=Ln(u,c),r=e.lastIndexOf("</body>");if(r!==-1)return e.slice(0,r)+g+e.slice(r);return e+g}function jn(i){let e=i.analytics;if(!e?.enabled)return"";switch(e.driver){case"fathom":return Nn(e);case"google-analytics":return Hn(e);case"plausible":return Bn(e);case"self-hosted":return Fn(e);case"custom":return qn(e);default:return""}}function Nn(i){let e=i.fathom;if(!e?.siteId)return"";let u=e.scriptUrl||"https://cdn.usefathom.com/script.js",c=e.defer!==!1?" defer":"",g=[`data-site="${pe(e.siteId)}"`];if(e.honorDnt)g.push('data-honor-dnt="true"');if(e.spa)g.push('data-spa="auto"');if(e.canonical)g.push(`data-canonical="${pe(e.canonical)}"`);if(e.auto===!1)g.push('data-auto="false"');return`
|
|
509
|
+
<!-- Fathom Analytics -->
|
|
510
|
+
<script src="${pe(u)}" ${g.join(" ")}${c}></script>
|
|
511
|
+
`}function Hn(i){let e=i.googleAnalytics;if(!e?.measurementId)return"";let u=pe(e.measurementId),c=e.debug?`gtag('config', '${u}', { 'debug_mode': true });`:"";return`
|
|
512
|
+
<!-- Google Analytics -->
|
|
513
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=${u}"></script>
|
|
514
|
+
<script>
|
|
515
|
+
window.dataLayer = window.dataLayer || [];
|
|
516
|
+
function gtag(){dataLayer.push(arguments);}
|
|
517
|
+
gtag('js', new Date());
|
|
518
|
+
gtag('config', '${u}');
|
|
519
|
+
${c}
|
|
520
|
+
</script>
|
|
521
|
+
`}function Bn(i){let e=i.plausible;if(!e?.domain)return"";let u=e.scriptUrl||"https://plausible.io/js/script.js",c=[`data-domain="${pe(e.domain)}"`],g=u,r=[];if(e.trackLocalhost)r.push("local");if(e.hashMode)r.push("hash");if(r.length>0&&u==="https://plausible.io/js/script.js")g=`https://plausible.io/js/script.${r.join(".")}.js`;return`
|
|
522
|
+
<!-- Plausible Analytics -->
|
|
523
|
+
<script defer data-domain="${pe(e.domain)}" src="${pe(g)}"></script>
|
|
524
|
+
`}function Fn(i){let e=i.selfHosted;if(!e?.siteId||!e?.apiEndpoint)return"";let u=pe(e.siteId),c=pe(e.apiEndpoint),g=e.honorDnt?'if(n.doNotTrack==="1")return;':"",r=e.trackHashChanges?"w.addEventListener('hashchange',pv);":"",f=e.trackOutboundLinks?`
|
|
525
|
+
d.addEventListener('click',function(e){
|
|
526
|
+
var a=e.target.closest('a');
|
|
527
|
+
if(a&&a.hostname!==location.hostname){
|
|
528
|
+
t('outbound',{url:a.href});
|
|
529
|
+
}
|
|
530
|
+
});`:"";return`
|
|
531
|
+
<!-- Self-Hosted Analytics -->
|
|
532
|
+
<script data-site="${u}" data-api="${c}" defer>
|
|
533
|
+
(function(){
|
|
534
|
+
'use strict';
|
|
535
|
+
var d=document,w=window,n=navigator,s=d.currentScript;
|
|
536
|
+
var site=s.dataset.site,api=s.dataset.api;
|
|
537
|
+
${g}
|
|
538
|
+
var q=[],sid=Math.random().toString(36).slice(2);
|
|
539
|
+
function t(e,p){
|
|
540
|
+
var x=new XMLHttpRequest();
|
|
541
|
+
x.open('POST',api+'/collect',true);
|
|
542
|
+
x.setRequestHeader('Content-Type','application/json');
|
|
543
|
+
x.send(JSON.stringify({
|
|
544
|
+
s:site,sid:sid,e:e,p:p||{},
|
|
545
|
+
u:location.href,r:d.referrer,t:d.title,
|
|
546
|
+
sw:screen.width,sh:screen.height
|
|
547
|
+
}));
|
|
548
|
+
}
|
|
549
|
+
function pv(){t('pageview');}
|
|
550
|
+
${r}
|
|
551
|
+
${f}
|
|
552
|
+
if(d.readyState==='complete')pv();
|
|
553
|
+
else w.addEventListener('load',pv);
|
|
554
|
+
w.stxAnalytics={track:function(n,v){t('event',{name:n,value:v});}};
|
|
555
|
+
})();
|
|
556
|
+
</script>
|
|
557
|
+
`}function qn(i){let e=i.custom;if(!e)return"";if(e.inlineScript)return`
|
|
558
|
+
<!-- Custom Analytics -->
|
|
559
|
+
<script>
|
|
560
|
+
${e.inlineScript}
|
|
561
|
+
</script>
|
|
562
|
+
`;if(!e.scriptUrl)return"";let u=[];if(e.scriptId)u.push(`id="${pe(e.scriptId)}"`);if(e.attributes)for(let[g,r]of Object.entries(e.attributes))u.push(`${pe(g)}="${pe(r)}"`);return`
|
|
563
|
+
<!-- Custom Analytics -->
|
|
564
|
+
<script${u.length>0?` ${u.join(" ")}`:""} src="${pe(e.scriptUrl)}" defer></script>
|
|
565
|
+
`}function ft(i,e){let u=jn(e);if(!u)return i;if(!i.includes("</head>")){let c=i.lastIndexOf("</body>");if(c!==-1)return i.slice(0,c)+u+i.slice(c);return i+u}return i.replace("</head>",`${u}</head>`)}function pe(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">")}function gt(i){let e=i.match(/\bdefinePageMeta\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(!e)return null;try{return Function(`return ${e[1]}`)()}catch{return null}}function mt(i){let e=i?.layout;if(e===!1)return!1;return typeof e==="string"&&e.trim()?e.trim():void 0}var Vn=0,zn=0;function ht(i,e){let u=i.match(new RegExp(`${e}\\s*=\\s*"([^"]*)"`,"i"));if(u)return u[1];let c=i.match(new RegExp(`${e}\\s*=\\s*'([^']*)'`,"i"));if(c)return c[1];return null}function Wn(i){let e=[],u=/<([a-z][a-z0-9-]*)\s+([^>]*x-data\s*=\s*(?:"[^"]*"|'[^']*')[^>]*)>/gi,c;while((c=u.exec(i))!==null){let[g,r,f]=c,v=c.index,y=ht(f,"x-data");if(!y)continue;let S=`__stx_scope_${Vn++}`,b=ht(f,"x-init"),w=Xn(i,r,v+g.length),T=i.slice(v,w.endIndex),A=Gn(T);e.push({id:S,selector:`[data-stx-scope="${S}"]`,stateExpr:y,initExpr:b,bindings:[],refs:A})}return e}function Xn(i,e,u){let c=1,g=u,r=new RegExp(`<${e}(?:\\s|>)`,"gi"),f=new RegExp(`</${e}>`,"gi"),v=new RegExp(`<${e}[^>]*/\\s*>`,"gi");while(c>0&&g<i.length){r.lastIndex=g,f.lastIndex=g,v.lastIndex=g;let y=r.exec(i),S=f.exec(i),b=v.exec(i);if(b&&b.index<(y?.index??1/0)){g=b.index+b[0].length;continue}if(!S)return{endIndex:i.length};if(y&&y.index<S.index)c++,g=y.index+y[0].length;else{if(c--,c===0)return{endIndex:S.index+S[0].length};g=S.index+S[0].length}}return{endIndex:i.length}}function Gn(i){let e=new Map,u=i.replace(/x-data\s*=\s*"[^"]*"/gi,'x-data="__stripped__"').replace(/x-data\s*=\s*'[^']*'/gi,"x-data='__stripped__'"),c=/<[a-z][a-z0-9-]*\s+([^>]*x-ref\s*=\s*["']([^"']*)["'][^>]*)>/gi,g;while((g=c.exec(u))!==null){let[,r,f]=g,v=Zn(r);e.set(f,v)}return e}function Zn(i){let e=i.match(/\bid\s*=\s*["']([^"']*)["']/);if(e)return e[1];return`__stx_el_${zn++}`}function Qn(){return`
|
|
566
|
+
// STX Reactive Runtime - x-cloak and transition CSS
|
|
567
|
+
(function() {
|
|
568
|
+
var style = document.createElement('style');
|
|
569
|
+
style.textContent = [
|
|
570
|
+
'[x-cloak] { display: none !important; }',
|
|
571
|
+
// Default transition classes
|
|
572
|
+
'.stx-enter { opacity: 0; transform: scale(0.95); }',
|
|
573
|
+
'.stx-enter-start { opacity: 0; transform: scale(0.95); }',
|
|
574
|
+
'.stx-enter-active { transition: opacity 150ms ease-out, transform 150ms ease-out; }',
|
|
575
|
+
'.stx-enter-to { opacity: 1; transform: scale(1); }',
|
|
576
|
+
'.stx-leave { opacity: 1; transform: scale(1); }',
|
|
577
|
+
'.stx-leave-start { opacity: 1; transform: scale(1); }',
|
|
578
|
+
'.stx-leave-active { transition: opacity 100ms ease-in, transform 100ms ease-in; }',
|
|
579
|
+
'.stx-leave-to { opacity: 0; transform: scale(0.95); }'
|
|
580
|
+
].join('\\n');
|
|
581
|
+
document.head.appendChild(style);
|
|
582
|
+
})();
|
|
583
|
+
|
|
584
|
+
// STX Reactive Runtime
|
|
585
|
+
/* eslint-disable pickier/no-unused-vars, no-console, prefer-const */
|
|
586
|
+
window.__stx_reactive = (function() {
|
|
587
|
+
'use strict';
|
|
588
|
+
|
|
589
|
+
// Deep reactive proxy that triggers onChange for any mutation
|
|
590
|
+
function reactive(obj, onChange) {
|
|
591
|
+
if (!obj || typeof obj !== 'object') return obj;
|
|
592
|
+
return new Proxy(obj, {
|
|
593
|
+
get(target, prop) {
|
|
594
|
+
const value = target[prop];
|
|
595
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Promise)) {
|
|
596
|
+
return reactive(value, onChange);
|
|
597
|
+
}
|
|
598
|
+
return value;
|
|
599
|
+
},
|
|
600
|
+
set(target, prop, value) {
|
|
601
|
+
target[prop] = value;
|
|
602
|
+
onChange(prop, value);
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// Initialize an x-data scope: parse state, run init(), register into window.stx._scopes,
|
|
609
|
+
// then let the signals runtime handle all directive processing (x-for, x-text, :bind, etc.)
|
|
610
|
+
function initScope(scopeEl, initialState, bindings, refs, initExpr) {
|
|
611
|
+
// Parse initial state (may contain methods including async init())
|
|
612
|
+
var state;
|
|
613
|
+
try {
|
|
614
|
+
state = new Function('return (' + initialState + ')')();
|
|
615
|
+
} catch (e) {
|
|
616
|
+
console.error('[stx-reactive] Invalid x-data:', initialState, e);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// Build $refs object
|
|
621
|
+
var $refs = {};
|
|
622
|
+
for (var name in refs) {
|
|
623
|
+
if (Object.prototype.hasOwnProperty.call(refs, name)) {
|
|
624
|
+
(function(refName, refId) {
|
|
625
|
+
Object.defineProperty($refs, refName, {
|
|
626
|
+
get: function() { return document.getElementById(refId); }
|
|
627
|
+
});
|
|
628
|
+
})(name, refs[name]);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// Extract init method from state if present (Alpine.js convention)
|
|
633
|
+
var initMethod = state.init;
|
|
634
|
+
if (typeof initMethod === 'function') {
|
|
635
|
+
delete state.init;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Make state reactive \u2014 mutations trigger re-render via signals
|
|
639
|
+
var scopeId = scopeEl.getAttribute('data-stx-scope');
|
|
640
|
+
var stx = window.stx;
|
|
641
|
+
|
|
642
|
+
// Create signals for each state property so the signals runtime can track dependencies
|
|
643
|
+
var signalState = {};
|
|
644
|
+
var rawState = {};
|
|
645
|
+
var derivedState = {};
|
|
646
|
+
var accessors = {};
|
|
647
|
+
// A getter must NOT be read here. Reading one calls it, and the old loop did
|
|
648
|
+
// exactly that: the returned value is not a function, so it was wrapped as a
|
|
649
|
+
// plain state() -- a snapshot of the answer at construction time, frozen
|
|
650
|
+
// forever while plain properties beside it updated (#2053). A getter is a
|
|
651
|
+
// derived value, so it is registered as one below, once ctxProxy exists for
|
|
652
|
+
// it to read through.
|
|
653
|
+
var ownDescriptors = Object.getOwnPropertyDescriptors ? Object.getOwnPropertyDescriptors(state) : {};
|
|
654
|
+
for (var key in state) {
|
|
655
|
+
if (Object.prototype.hasOwnProperty.call(state, key)) {
|
|
656
|
+
var descriptor = ownDescriptors[key];
|
|
657
|
+
if (descriptor && typeof descriptor.get === 'function') {
|
|
658
|
+
accessors[key] = descriptor;
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
if (typeof state[key] === 'function') {
|
|
662
|
+
// Methods \u2014 bind to a proxy so 'this.prop = val' triggers signal updates
|
|
663
|
+
signalState[key] = state[key];
|
|
664
|
+
} else {
|
|
665
|
+
// Data properties \u2014 wrap in signals for reactivity
|
|
666
|
+
signalState[key] = stx.state(state[key]);
|
|
667
|
+
rawState[key] = true;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// Create a proxy context that auto-unwraps signals and writes back through them.
|
|
673
|
+
// Methods get 'this' bound to this proxy so this.foo = bar triggers reactivity.
|
|
674
|
+
var ctx = {};
|
|
675
|
+
var ctxProxy = new Proxy(ctx, {
|
|
676
|
+
get: function(target, prop) {
|
|
677
|
+
if (prop === '$refs') return $refs;
|
|
678
|
+
if (prop === '$el') return scopeEl;
|
|
679
|
+
if (prop === '$nextTick') return function(fn) { requestAnimationFrame(fn); };
|
|
680
|
+
var s = signalState[prop];
|
|
681
|
+
if (!s) return undefined;
|
|
682
|
+
if (rawState[prop] && s && typeof s === 'function' && typeof s.value !== 'undefined') {
|
|
683
|
+
return s.value; // unwrap signal
|
|
684
|
+
}
|
|
685
|
+
if (typeof s === 'function' && !rawState[prop]) {
|
|
686
|
+
return s.bind(ctxProxy); // bind methods to proxy
|
|
687
|
+
}
|
|
688
|
+
return s;
|
|
689
|
+
},
|
|
690
|
+
set: function(target, prop, value) {
|
|
691
|
+
var accessor = derivedState[prop];
|
|
692
|
+
if (accessor) {
|
|
693
|
+
// A getter/setter pair writes through its setter. A getter alone has
|
|
694
|
+
// nowhere to put the value: a derived has no .value setter, so the
|
|
695
|
+
// assignment would be a silent no-op, which is the same class of
|
|
696
|
+
// failure as the stale read this replaces.
|
|
697
|
+
if (typeof accessor.set === 'function') {
|
|
698
|
+
accessor.set.call(ctxProxy, value);
|
|
699
|
+
return true;
|
|
700
|
+
}
|
|
701
|
+
console.warn('[stx-reactive] cannot assign to ' + String(prop) + ': it is a getter in x-data, so its value comes from what it reads. Give it a setter, or make it a plain property.');
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
var s = signalState[prop];
|
|
705
|
+
if (rawState[prop] && s && typeof s === 'function') {
|
|
706
|
+
s.value = value; // write through signal \u2014 triggers effects
|
|
707
|
+
} else {
|
|
708
|
+
signalState[prop] = value;
|
|
709
|
+
}
|
|
710
|
+
return true;
|
|
711
|
+
},
|
|
712
|
+
has: function(target, prop) {
|
|
713
|
+
return prop in signalState || prop === '$refs' || prop === '$el' || prop === '$nextTick';
|
|
714
|
+
},
|
|
715
|
+
ownKeys: function() {
|
|
716
|
+
return Object.keys(signalState).concat(['$refs', '$el', '$nextTick']);
|
|
717
|
+
},
|
|
718
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
719
|
+
if (prop in signalState || prop === '$refs' || prop === '$el' || prop === '$nextTick') {
|
|
720
|
+
return { configurable: true, enumerable: true, writable: true, value: ctxProxy[prop] };
|
|
721
|
+
}
|
|
722
|
+
return undefined;
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// Now that ctxProxy exists, a getter becomes a derived that reads through it,
|
|
727
|
+
// so it tracks whatever it touches and recomputes when that changes. derived()
|
|
728
|
+
// is lazy, so nothing is evaluated until a binding actually reads it.
|
|
729
|
+
//
|
|
730
|
+
// Marked rawState as well: that is what makes the proxy unwrap it and what
|
|
731
|
+
// exposes the signal itself to the runtime below, which is where dependency
|
|
732
|
+
// tracking comes from. A getter needs both, exactly like a data property.
|
|
733
|
+
for (var accessorKey in accessors) {
|
|
734
|
+
if (Object.prototype.hasOwnProperty.call(accessors, accessorKey)) {
|
|
735
|
+
(function(name, descriptor) {
|
|
736
|
+
signalState[name] = stx.derived(function() {
|
|
737
|
+
return descriptor.get.call(ctxProxy);
|
|
738
|
+
});
|
|
739
|
+
rawState[name] = true;
|
|
740
|
+
derivedState[name] = descriptor;
|
|
741
|
+
})(accessorKey, accessors[accessorKey]);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Build scope vars for the signals runtime \u2014 it reads these for expression evaluation.
|
|
746
|
+
// We need to provide getter/setter descriptors so signals track properly.
|
|
747
|
+
var scopeVars = {};
|
|
748
|
+
for (var k in signalState) {
|
|
749
|
+
if (Object.prototype.hasOwnProperty.call(signalState, k)) {
|
|
750
|
+
if (rawState[k]) {
|
|
751
|
+
// Data: expose the signal directly so expressions trigger dependency tracking
|
|
752
|
+
scopeVars[k] = signalState[k];
|
|
753
|
+
} else {
|
|
754
|
+
// Method: bind to ctxProxy so 'this' works
|
|
755
|
+
scopeVars[k] = (typeof signalState[k] === 'function') ? signalState[k].bind(ctxProxy) : signalState[k];
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
scopeVars.$refs = $refs;
|
|
760
|
+
scopeVars.$el = scopeEl;
|
|
761
|
+
scopeVars.$nextTick = function(fn) { requestAnimationFrame(fn); };
|
|
762
|
+
|
|
763
|
+
// Register scope \u2014 merge with any existing vars from partial signal scripts
|
|
764
|
+
if (!stx._scopes) stx._scopes = {};
|
|
765
|
+
stx._scopes[scopeId] = Object.assign(stx._scopes[scopeId] || {}, scopeVars);
|
|
766
|
+
|
|
767
|
+
// Store on element for findElementScope
|
|
768
|
+
scopeEl.__stx_scope = scopeVars;
|
|
769
|
+
|
|
770
|
+
// Run init() if present (supports async)
|
|
771
|
+
function runInit() {
|
|
772
|
+
var maybePromise;
|
|
773
|
+
if (initMethod) {
|
|
774
|
+
maybePromise = initMethod.call(ctxProxy);
|
|
775
|
+
}
|
|
776
|
+
if (initExpr) {
|
|
777
|
+
try {
|
|
778
|
+
var keys = Object.keys(scopeVars);
|
|
779
|
+
var vals = keys.map(function(k) { return scopeVars[k]; });
|
|
780
|
+
var fn = new Function(keys.join(','), initExpr);
|
|
781
|
+
var result = fn.apply(ctxProxy, vals);
|
|
782
|
+
if (result && typeof result.then === 'function') maybePromise = result;
|
|
783
|
+
} catch (e) {
|
|
784
|
+
console.warn('[stx-reactive] init expression error:', e);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
// If init is async, signal updates will trigger effects automatically
|
|
788
|
+
// when init() resolves and sets this.prop = value (writes through signal)
|
|
789
|
+
if (maybePromise && typeof maybePromise.then === 'function') {
|
|
790
|
+
maybePromise.catch(function(e) {
|
|
791
|
+
console.error('[stx-reactive] async init() error:', e);
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// Run init before the signals runtime processes this scope
|
|
797
|
+
runInit();
|
|
798
|
+
|
|
799
|
+
// Expose for debugging
|
|
800
|
+
scopeEl.__stx_state = ctxProxy;
|
|
801
|
+
scopeEl.__stx_execute = function(stmt, $event, $el) {
|
|
802
|
+
try {
|
|
803
|
+
// Run the statement with the reactive proxy as the lexical scope.
|
|
804
|
+
// Wrapping in a with-block on the proxy makes bare reads/writes go
|
|
805
|
+
// through it (so foo = bar triggers signal.set()) instead of treating
|
|
806
|
+
// each state key as a local function parameter \u2014 bare assignments
|
|
807
|
+
// would otherwise just rebind the local and never reach the signal.
|
|
808
|
+
var fn = new Function('$event', '$el', 'with(this){' + stmt + ';}');
|
|
809
|
+
fn.call(ctxProxy, $event, $el);
|
|
810
|
+
} catch (e) {
|
|
811
|
+
console.warn('[stx-reactive] execute error:', e);
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
return { initScope: initScope, reactive: reactive };
|
|
817
|
+
})();
|
|
818
|
+
`}function yt(i,e){let u=i.replace(/\{!!([\s\S]*?)!!\}/g,(v,y)=>{try{let S=_(y,e,!0);if(S===void 0)return v;return String(S)}catch{return v}}),c="",g=0,r=null;while(g<u.length){let v=u[g];if(r&&v==="\\"){c+=v+(u[g+1]??""),g+=2;continue}if(v==="{"&&u[g+1]==="{"){let y=u.indexOf("}}",g+2);if(y!==-1){let S=u.slice(g,y+2);c+=f(u.slice(g+2,y),S,r),g=y+2;continue}}if(r){if(v===r)r=null}else if(v==="'"||v==='"'||v==="`")r=v;c+=v,g++}return c;function f(v,y,S){let b;try{b=_(v,e,!0)}catch{return y}if(b===void 0)return y;if(S){let w=String(b).replace(/\\/g,"\\\\").replace(new RegExp(S==="`"?"`":S,"g"),`\\${S}`).replace(/\r/g,"\\r").replace(/\n/g,"\\n");return S==="`"?w.replace(/\$\{/g,"\\${"):w}if(typeof b==="string"){let w=b.trim();if(w.startsWith("{")&&w.endsWith("}")||w.startsWith("[")&&w.endsWith("]"))try{return JSON.parse(w),w}catch{}}return JSON.stringify(b)}}function tr(i,e){if(i.length===0)return"";let u=i.map((c)=>{let g=JSON.stringify(Object.fromEntries(c.refs)),r=yt(c.stateExpr,e),f=c.initExpr?yt(c.initExpr,e):null,v=JSON.stringify(r),y=f?JSON.stringify(f):"null";return`
|
|
819
|
+
(function() {
|
|
820
|
+
var scopeEl = document.querySelector('${c.selector}');
|
|
821
|
+
if (!scopeEl) return;
|
|
822
|
+
var refs = ${g};
|
|
823
|
+
__stx_reactive.initScope(scopeEl, ${v}, [], refs, ${y});
|
|
824
|
+
})();`}).join(`
|
|
825
|
+
`);return`
|
|
826
|
+
<script data-stx-scoped data-stx-reactive data-stx-run="always">
|
|
827
|
+
${Qn()}
|
|
828
|
+
${u}
|
|
829
|
+
</script>`}function vt(i,e,u){if(!sr(i))return i;let c=Wn(i);if(c.length===0)return i;let g=nr(i,c),r=tr(c,e),f=g.lastIndexOf("</body>");if(f!==-1)g=g.slice(0,f)+r+`
|
|
830
|
+
`+g.slice(f);else g+=r;return g}function nr(i,e){let u=0,c=i.replace(/<([a-z][a-z0-9-]*)(\s+[^>]*x-data\s*=\s*(?:"[^"]*"|'[^']*')[^>]*)>/gi,(g,r,f)=>{let v=e[u++];if(!v)return g;let y=/data-stx-scope="([^"]*)"/.exec(f);if(y)return v.id=y[1],v.selector=`[data-stx-scope="${v.id}"]`,g;return`<${r} data-stx-scope="${v.id}"${f}>`});return c=c.replace(/\s*x-data\s*=\s*"([^"]*)"/g,' data-stx-xdata="$1"'),c=c.replace(/\s*x-data\s*=\s*'([^']*)'/g," data-stx-xdata='$1'"),c=c.replace(/\s*x-init\s*=\s*"([^"]*)"/g,' data-stx-xinit="$1"'),c=c.replace(/\s*x-init\s*=\s*'([^']*)'/g," data-stx-xinit='$1'"),c}function sr(i){return/x-data\s*=\s*["']/.test(i)}import ir from"fs";import Ze from"path";import{createHighlighter as or}from"ts-syntax-highlighter";var Qe=new Map;async function $e(i,e={}){try{if(!await n(i))throw Error(`Markdown file not found: ${i}`);let c=(await ir.promises.stat(i)).mtime.getTime();if(e.cache&&Qe.has(i)){let w=Qe.get(i);if(w.updatedAt>=c)return{content:w.content,data:w.data}}let g=await Bun.file(i).text(),{data:r,content:f}=er(g),v=e.markdown||R.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},S=Je(f,{gfm:!0});if(v.syntaxHighlighting?.enabled&&v.syntaxHighlighting?.serverSide)S=await ar(S,v.syntaxHighlighting?.defaultTheme||"github-dark",v.syntaxHighlighting?.highlightUnknownLanguages||!1);let b={content:S,data:r||{}};if(e.cache)Qe.set(i,{...b,updatedAt:c});return b}catch(u){if(e.debug)console.error(`Error reading/parsing markdown file ${i}:`,u);let c=u instanceof Error?u.message:String(u);return{content:m("Markdown File",`Error reading/parsing markdown file: ${c}`,i,"",0,""),data:{}}}}var qe=null;async function ar(i,e,u){let c=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!qe)try{qe=await or({theme:e||"github-dark",cache:!0})}catch(v){return console.error("Failed to initialize ts-syntax-highlighter:",v),i}let g=async(v,y,S,b)=>{let w=b.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),T=S||(u?"text":"");if(!T)return v;try{if(!qe.getSupportedLanguages().includes(T))return v;return(await qe.highlight(w,T,{theme:e})).html}catch(A){console.error(`Error highlighting code block with language ${S}:`,A)}return v},r=i,f=i.matchAll(c);for(let v of f){let[y,S,b,w]=v,T=await g(y,S,b,w);r=r.replace(y,T)}return r}async function bt(i,e,u="",c={}){return await lr(i,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(f,v,y,S)=>{try{let b=v;if(!Ze.isAbsolute(v))b=Ze.resolve(Ze.dirname(u),v);let w={};if(y)try{try{w=JSON.parse(y)}catch{if(c.debug)console.warn("Using safer alternative for parsing JS object literal");let N=y.replace(/^\s*\{|\}\s*$/g,"").trim().split(/,(?=\s*\w+\s*:)/);for(let F of N){let z=F.indexOf(":");if(z>0){let L=F.substring(0,z).trim(),j=F.substring(z+1).trim(),H=j.startsWith('"')&&j.endsWith('"'),W=j.startsWith("'")&&j.endsWith("'");if(H||W)j=j.substring(1,j.length-1);w[L]=j}}}}catch(P){if(c.debug)console.error("Error parsing context in @markdown-file directive:",P)}let{content:T,data:A}=await $e(b,c),O={...e,...A,...w},M=T,I=/\{\{([^}]+)\}\}/g;return M=M.replace(I,(P,N)=>{let F=N.trim();return O[F]!==void 0?String(O[F]):P}),M}catch(b){let w=b instanceof Error?b.message:String(b);return m("Markdown File",`Error including markdown file: ${w}`,u,i,S,f)}})}async function lr(i,e,u){let c=[],g;while((g=e.exec(i))!==null){let v=g[0],y=g.index,S=g;c.push(u(...S).then((b)=>({match:v,replacement:b,index:y})))}let r=await Promise.all(c);r.sort((v,y)=>y.index-v.index);let f=i;for(let{match:v,replacement:y}of r)f=f.replace(v,()=>y);return f}var wt=new WeakMap;function xt(i=16){let e=new Uint8Array(i);return crypto.getRandomValues(e),btoa(String.fromCharCode(...e))}function Ue(i,e){if(!i)return e?.nonceGenerator?.()??xt();let u=wt.get(i);if(!u)u=e?.nonceGenerator?.()??xt(),wt.set(i,u);return u}function ur(i,e){let u=[];for(let[c,g]of Object.entries(i)){if(g===void 0||g===null)continue;if(typeof g==="boolean"){if(g)u.push(c);continue}if(Array.isArray(g)){let r=[...g];if(e&&(c==="script-src"||c==="style-src"))r=r.filter((f)=>!f.startsWith("'nonce-")),r.push(`'nonce-${e}'`);if(r.length>0)u.push(`${c} ${r.join(" ")}`)}}return u.join("; ")}function kt(i,e){return`<meta http-equiv="Content-Security-Policy" content="${ur(i,e).replace(/&/g,"&").replace(/"/g,""")}">`}function St(i,e,u){if(!e.enabled||!e.addMetaTag)return i;if(i.includes('http-equiv="Content-Security-Policy"'))return i;if(!i.includes("<head>")&&!i.includes("<head "))return i;let c=e.useNonce?Ue(u,e):void 0,g=kt(e.directives,c);return i.replace(/<head([^>]*)>/,`<head$1>
|
|
831
|
+
${g}`)}function $t(i,e){let u=i;return u=u.replace(/<script(?![^>]*\ssrc=)([^>]*)>/gi,(c,g)=>{if(g.includes("nonce="))return c;return`<script nonce="${e}"${g}>`}),u=u.replace(/<style([^>]*)>/gi,(c,g)=>{if(g.includes("nonce="))return c;return`<style nonce="${e}"${g}>`}),u}function Et(i,e,u,c){let g=i,r=c.csp;if(g=g.replace(/@csp\b/g,()=>{if(!r?.enabled||!r.directives)return"<!-- CSP not configured -->";let f=r.useNonce?Ue(e,r):void 0;return kt(r.directives,f)}),g=g.replace(/@cspNonce\b/g,()=>{if(!r?.enabled||!r.useNonce)return"";return Ue(e,r)}),r?.enabled&&r.useNonce)e.cspNonce=Ue(e,r);return g}import pr from"crypto";var fr=40,_t="_token",Ye=null;function gr(i=fr){let e=pr.randomBytes(Math.ceil(i/2)).toString("hex").slice(0,i);return Ye=e,e}function br(){if(!Ye)gr();return Ye}function wr(i=_t){let e=br();return`<input type="hidden" name="${i}" value="${e}">`}function Ct(i){return i.replace(/@csrf(?:\((['"])([^'"]*)\1\))?/g,(e,u,c)=>wr(c||_t))}async function At(i,e,u,c){if(!c.customDirectives||c.customDirectives.length===0)return i;let g=i;for(let r of c.customDirectives){if(!r.name||typeof r.handler!=="function"){if(c.debug)console.warn("Invalid custom directive:",r);continue}if(r.hasEndTag)g=await xr(g,r,e,u,c);else g=await kr(g,r,e,u,c)}return g}async function xr(i,e,u,c,g){let{name:r,handler:f}=e,v=`@${r}`,y=`@end${r}`,S=i,b=Tt(`${v}(?:\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\))?([\\s\\S]*?)${y}`,"g"),w=[],T=b.exec(S);while(T!==null){let[A,O="",M=""]=T,I=T.index||0;try{let P=O?Rt(e,O):[],N=M.trim(),F=await f(N,P,u,c);w.push({original:A,processed:F,startIndex:I})}catch(P){let N=P instanceof Error?P.message:String(P);if(g.debug)console.error(`Error processing custom directive @${r}:`,P);w.push({original:A,processed:a("CustomDirective",`Error in @${r}${O?`(${O})`:""}: ${N}`,t.EVALUATION_ERROR),startIndex:I})}T=b.exec(S)}for(let A=w.length-1;A>=0;A--){let{original:O,processed:M}=w[A];S=S.replace(O,M)}return S}async function kr(i,e,u,c,g){let{name:r,handler:f}=e,v=i,y=[],S=[];if(e.rawParams){for(let T of Go(v,Tt(`(?<![\\w$@])@${r}\\s*\\(`,"g")))if(T.end!==-1)S.push({fullMatch:T.call,paramString:T.args,startIndex:T.start})}else{let T=Tt(`@${r}\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\)`,"g");T.lastIndex=0;let A=T.exec(v);while(A!==null)S.push({fullMatch:A[0],paramString:A[1]??"",startIndex:A.index||0}),A=T.exec(v)}for(let{fullMatch:T,paramString:A,startIndex:O}of S)try{let M=Rt(e,A),I=await f("",M,u,c);y.push({original:T,processed:I,startIndex:O})}catch(M){let I=M instanceof Error?M.message:String(M);if(g.debug)console.error(`Error processing custom directive @${r}:`,M);y.push({original:T,processed:a("CustomDirective",`Error in @${r}(${A}): ${I}`,t.EVALUATION_ERROR),startIndex:O})}let b=Tt(`@${r}(?!\\w)(?!\\s*\\()`,"g"),w=b.exec(v);while(w!==null){let[T]=w,A=w.index||0;try{let O=await f("",[],u,c);y.push({original:T,processed:O,startIndex:A})}catch(O){let M=O instanceof Error?O.message:String(O);if(g.debug)console.error(`Error processing custom directive @${r}:`,O);y.push({original:T,processed:a("CustomDirective",`Error in @${r}: ${M}`,t.EVALUATION_ERROR),startIndex:A})}w=b.exec(v)}for(let T=y.length-1;T>=0;T--){let{original:A,processed:O}=y[T];v=v.replace(A,O)}return v}function Rt(i,e){return i.rawParams?Lt(e):Sr(e)}function Sr(i){if(!i.trim())return[];let e=[],u="",c=!1,g="";for(let r=0;r<i.length;r++){let f=i[r];if((f==='"'||f==="'")&&(r===0||i[r-1]!=="\\"))if(!c)c=!0,g=f;else if(f===g)c=!1;else u+=f;else if(f===","&&!c)e.push(u.trim()),u="";else u+=f}if(u.trim())e.push(u.trim());return e.map((r)=>{let f=r.trim();if(f.startsWith('"')&&f.endsWith('"')||f.startsWith("'")&&f.endsWith("'"))return f.substring(1,f.length-1);return f})}var Mt=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Dt=/^[A-Za-z_$][\w$]*$/,$r=new Set(["light","dark","system"]);function ke(i,e){if(typeof i!=="string"||i.length===0)throw Error(`@appearanceBootstrap ${e} must be a non-empty string`)}function Er(i){if(!i||typeof i!=="object"||Array.isArray(i))throw Error("@appearanceBootstrap expects an options object");let e=i,{appearance:u,colorMode:c}=e;if(ke(e.storageKey,"storageKey"),u!==void 0&&(!u||typeof u!=="object"||Array.isArray(u)))throw Error("@appearanceBootstrap appearance must be an object when given");if(!c||typeof c!=="object"||Array.isArray(c))throw Error("@appearanceBootstrap colorMode must be an object");if(ke(c.key,"colorMode.key"),ke(c.attribute,"colorMode.attribute"),ke(c.default,"colorMode.default"),!Dt.test(c.key))throw Error("@appearanceBootstrap preference keys must be JavaScript property names");if(!Mt.test(c.attribute))throw Error("@appearanceBootstrap attributes must be lowercase data attribute names");if(!$r.has(c.default))throw Error("@appearanceBootstrap colorMode.default must be light, dark, or system");let g=null;if(u){if(ke(u.key,"appearance.key"),ke(u.attribute,"appearance.attribute"),ke(u.default,"appearance.default"),!Dt.test(u.key))throw Error("@appearanceBootstrap preference keys must be JavaScript property names");if(!Mt.test(u.attribute))throw Error("@appearanceBootstrap attributes must be lowercase data attribute names");if(!Array.isArray(u.allowed)||u.allowed.length===0||u.allowed.some((r)=>typeof r!=="string"||r.length===0))throw Error("@appearanceBootstrap appearance.allowed must contain one or more strings");if(!u.allowed.includes(u.default))throw Error("@appearanceBootstrap appearance.default must be in appearance.allowed");g={key:u.key,attribute:u.attribute,allowed:[...new Set(u.allowed)],default:u.default}}return{storageKey:e.storageKey,appearance:g,colorMode:{key:c.key,attribute:c.attribute,default:c.default},respectExisting:e.respectExisting===!0}}function _r(i){return JSON.stringify(i).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function Tr(i){return`<script data-stx-scoped data-stx-appearance-bootstrap>(function(){"use strict";const config=${_r(i)};const root=document.documentElement;const MODES=["light","dark","system"];let format="json";const forced=(function(){const found={colorMode:null,appearance:null};if(!config.respectExisting)return found;try{const mode=root.getAttribute("data-"+config.colorMode.attribute);if(mode==="light"||mode==="dark")found.colorMode=mode;if(config.appearance){const name=root.getAttribute("data-"+config.appearance.attribute);if(config.appearance.allowed.includes(name))found.appearance=name}}catch{}return found}());function read(){let stored={};try{const raw=localStorage.getItem(config.storageKey);if(raw){let parsed=null;try{parsed=JSON.parse(raw)}catch{parsed=raw}if(parsed&&typeof parsed==="object"&&!Array.isArray(parsed)){stored=parsed;format="json"}else if(typeof parsed==="string"&&MODES.includes(parsed)){stored={};stored[config.colorMode.key]=parsed;format="string"}}}catch{}return stored}function write(stored){try{if(format==="string"&&!config.appearance)localStorage.setItem(config.storageKey,stored[config.colorMode.key]);else localStorage.setItem(config.storageKey,JSON.stringify(stored))}catch{}}function resolve(){const stored=read();const state={colorMode:forced.colorMode||(MODES.includes(stored[config.colorMode.key])?stored[config.colorMode.key]:config.colorMode.default)};if(config.appearance)state.appearance=forced.appearance||(config.appearance.allowed.includes(stored[config.appearance.key])?stored[config.appearance.key]:config.appearance.default);return state}function prefersDark(){try{return matchMedia("(prefers-color-scheme: dark)").matches}catch{return false}}function apply(){const state=resolve();const dark=state.colorMode==="dark"||(state.colorMode==="system"&&prefersDark());if(config.appearance)root.setAttribute("data-"+config.appearance.attribute,state.appearance);root.setAttribute("data-"+config.colorMode.attribute,state.colorMode);root.classList.toggle("dark",dark);root.dataset.theme=dark?"dark":"light";state.dark=dark;try{window.dispatchEvent(new CustomEvent("stx:appearance",{detail:state}))}catch{}return state}function store(key,allowed,value){if(allowed.includes(value)){const stored=read();stored[key]=value;write(stored)}return apply()}window.__stxAppearance={config:config,forced:forced,read:read,resolve:resolve,apply:apply,setColorMode:function(mode){return store(config.colorMode.key,MODES,mode)},setAppearance:function(name){return config.appearance?store(config.appearance.key,config.appearance.allowed,name):apply()},watchSystem:function(){try{matchMedia("(prefers-color-scheme: dark)").addEventListener("change",function(){if(resolve().colorMode==="system")apply()})}catch{}}};apply()}());</script>`}function Cr(i,e){let u=1,c=null,g=!1;for(let r=e+1;r<i.length;r++){let f=i[r];if(g){g=!1;continue}if(c){if(f==="\\")g=!0;else if(f===c)c=null;continue}if(f==='"'||f==="'"||f==="`"){c=f;continue}if(f==="(")u++;else if(f===")"&&--u===0)return r}return-1}function It(i,e){let u=i,c=/@appearanceBootstrap\s*\(/g,g;while((g=c.exec(u))!==null){let r=g.index+g[0].length-1,f=Cr(u,r);if(f===-1)throw Error("@appearanceBootstrap has an unclosed options object");let v=u.slice(r+1,f).trim(),y=l(`(${v})`,e),S=Tr(Er(y));u=u.slice(0,g.index)+S+u.slice(f+1),c.lastIndex=g.index+S.length}return u}import Ar from"crypto";function Z(i){return V(String(i??""))}var Pt={input:"form-control",inputError:"is-invalid",checkInput:"form-check-input",label:"form-label",errorFeedback:"invalid-feedback"};function Ve(i,e,u,c){let g=i||e;return u?`${g} ${c}`:g}function ge(i){return String(i).replace(/\[\]$/,"").replace(/[^\w.:-]+/g,"-").replace(/^-+|-+$/g,"")}function Ae(i,e){if(/\bid\s*=/i.test(i))return"";return` id="${Z(e)}"`}function et(i,e,u){if(!e)return"";let c="";if(!/\baria-invalid\s*=/i.test(u))c+=' aria-invalid="true"';if(!/\baria-describedby\s*=/i.test(u))c+=` aria-describedby="${Z(`${ge(i)}-error`)}"`;return c}function Rr(){return Ar.randomUUID()}function ze(i,e){let u=i;return u=u.replace(/@csrf/g,()=>{if(!e.csrf||typeof e.csrf!=="object"){let c=Rr();e.csrf={token:c}}if(e.csrf.field)return e.csrf.field;if(e.csrf.token)return`<input type="hidden" name="_token" value="${Z(e.csrf.token)}">`;return'<input type="hidden" name="_token" value="">'}),u=u.replace(/@method\(['"]([^'"]+)['"]\)/g,(c,g)=>{let r=g.toUpperCase();if(g&&!["GET","POST"].includes(r))return`<input type="hidden" name="_method" value="${Z(r)}">`;return c}),u}function jt(i,e,u=Pt){let c=i;return c=c.replace(/@form\(\s*(?:(?:'([^']+)'|"([^"]+)")\s*)?(?:,\s*(?:'([^']+)'|"([^"]+)")?)?\s*(?:,\s*\{([^}]+)\}\s*)?\)/g,(g,r,f,v,y,S="")=>{let b=r||f||"POST",w=v||y||"",T=ye(S),A=b.toUpperCase(),O=["GET","POST"].includes(A)?A:"POST",M=`<form method="${Z(O)}" action="${Z(w)}"${T?` ${T}`:""}>`;if(M+=`
|
|
832
|
+
${ze("@csrf",e)}`,!["GET","POST"].includes(A))M+=`
|
|
833
|
+
${ze(`@method('${A}')`,e)}`;return M}),c=c.replace(/@endform/g,"</form>"),c=c.replace(/@input\(\s*(?:'([^']+)'|"([^"]+)")\s*(?:,\s*(?:(?:'([^']*)'|"([^"]*)")\s*)?)?(?:,\s*\{([^}]+)\})?\s*\)/g,(g,r,f,v,y,S="")=>{let b=r||f||"",w=v||y||"",T=ye(S),A=Le(b,e),O=A!==void 0&&A!==null?A:w||"",M=T.match(/type=['"]([^'"]+)['"]/i),I=M?M[1]:"text",P=He(b,e),N=T.match(/class=['"]([^'"]+)['"]/i),F=Ve(N?N[1]:"",u.input,P,u.inputError),z=T.replace(/class=['"][^'"]+['"]/i,"");return z=z.replace(/type=['"][^'"]+['"]/i,""),`<input type="${Z(I)}" name="${Z(b)}"${Ae(T,ge(b))} value="${Z(O)}" class="${F}"${et(b,P,T)}${z?` ${z}`:""}>`}),c=c.replace(/@textarea\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endtextarea/g,(g,r,f="",v="")=>{let y=ye(f),S=Le(r,e)||v.trim(),b=He(r,e),w=y.match(/class=['"]([^'"]+)['"]/i),T=Ve(w?w[1]:"",u.input,b,u.inputError),A=y.replace(/class=['"][^'"]+['"]/i,"");return`<textarea name="${Z(r)}"${Ae(y,ge(r))} class="${T}"${et(r,b,y)}${A?` ${A}`:""}>${Z(S)}</textarea>`}),c=c.replace(/@select\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endselect/g,(g,r,f="",v)=>{let y=ye(f),S=Le(r,e),b=He(r,e),w=y.match(/class=['"]([^'"]+)['"]/i),T=Ve(w?w[1]:"",u.input,b,u.inputError),A=y.replace(/class=['"][^'"]+['"]/i,""),O=v;if(S!==void 0)O=v.replace(/(<option[^>]*value=['"]([^'"]+)['"][^>]*>)/gi,(M,I,P)=>{if((Array.isArray(S)?S.some((F)=>String(F)===P):String(S)===P)&&!I.includes("selected"))return I.replace(/(<option)/,"$1 selected");return M});return`<select name="${Z(r)}"${Ae(y,ge(r))} class="${T}"${et(r,b,y)}${A?` ${A}`:""}>${O}</select>`}),c=c.replace(/@checkbox\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?(?:,\s*\{([^}]+)\})?\)/g,(g,r,f,v="")=>{let y=f===void 0?"1":f,S=f===void 0?ge(r):`${ge(r)}-${ge(y)}`,b=ye(v),w=Le(r,e),T=w!==void 0&&(Array.isArray(w)?w.some((I)=>String(I)===y):w===!0||String(w)===y),A=b.match(/class=['"]([^'"]+)['"]/i),O=A?A[1]:u.checkInput,M=b.replace(/class=['"][^'"]+['"]/i,"");return`<input type="checkbox" name="${Z(r)}"${Ae(b,S)} value="${Z(y)}" class="${O}"${T?" checked":""}${M?` ${M}`:""}>`}),c=c.replace(/@radio\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)/g,(g,r,f,v="")=>{let y=ye(v),S=Le(r,e),b=S!==void 0&&S===f,w=y.match(/class=['"]([^'"]+)['"]/i),T=w?w[1]:u.checkInput,A=y.replace(/class=['"][^'"]+['"]/i,"");return`<input type="radio" name="${Z(r)}"${Ae(y,`${ge(r)}-${ge(f)}`)} value="${Z(f)}" class="${T}"${b?" checked":""}${A?` ${A}`:""}>`}),c=c.replace(/@file\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)/g,(g,r,f="")=>{let v=ye(f),y=v.match(/accept=['"]([^'"]+)['"]/i),S=y?y[1]:"",b=v.includes("multiple"),w=He(r,e),T=v.match(/class=['"]([^'"]+)['"]/i),A=Ve(T?T[1]:"",u.input,w,u.inputError),O=v.replace(/class=['"][^'"]+['"]/gi,"").replace(/accept=['"][^'"]+['"]/gi,"").replace(/\bmultiple\b/gi,"").trim(),M=[`<input type="file" name="${Z(r)}"${Ae(v,ge(r))}`,`class="${A}"`];if(S)M.push(`accept="${Z(S)}"`);if(b)M.push("multiple");if(O)M.push(O);return`${M.join(" ")}>`}),c=c.replace(/@label\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endlabel/g,(g,r,f="",v)=>{let y=ye(f),S=y.match(/class=['"]([^'"]+)['"]/i),b=S?S[1]:u.label,w=y.replace(/class=['"][^'"]+['"]/i,"");return`<label for="${Z(ge(r))}" class="${b}"${w?` ${w}`:""}>${v}</label>`}),c}function Ht(i,e,u=Pt){return i.replace(/@error\(['"]([^'"]+)['"]\)([\s\S]*?)@enderror/g,(c,g,r)=>{try{if(He(g,e)){let f=r.replace(/\{\{([^}]+)\}\}/g,(v,y,S)=>{let b=(w)=>Y(r,S,String(w??""),!1,v.length);try{if(y.trim()==="$message"||y.trim()==="message")return b(Ot(g,e));if(y.trim().includes("errors.first")||y.trim().includes("$errors.first")){if(typeof e.errors?.first==="function")return b(e.errors.first(g));return b(Ot(g,e))}let w=y.trim();if(p(w)){let T=l(w,e);return T!==void 0?b(T):w}return w}catch{return y}});return`<div id="${Z(`${ge(g)}-error`)}" role="alert">${f}</div>`}return""}catch(f){return console.error("Error processing @error directive:",f),c}})}function He(i,e){if(!e.errors)return!1;if(typeof e.errors.has==="function")return e.errors.has(i);if(typeof e.errors==="object")return Object.prototype.hasOwnProperty.call(e.errors,i);return!1}function Ot(i,e){if(!e.errors)return"";if(typeof e.errors.get==="function")return e.errors.get(i);if(typeof e.errors==="object"&&Object.prototype.hasOwnProperty.call(e.errors,i)){let u=e.errors[i];return Array.isArray(u)?u[0]:String(u)}return""}function Le(i,e){let u;if(e.old&&typeof e.old==="function")return e.old(i);if(e.old&&typeof e.old==="object")return e.old[i];if(i.endsWith("[]")){let c=i.slice(0,-2);if(u=e[c],u!==void 0)return u}return e[i]}function ye(i){if(!i.trim())return"";let e=[],u=i.trim(),c=/([\w-]+)\s*:\s*(['"]?)([^,'"]*)\2(?:\s*,\s*|\s*$)/g,g;while((g=c.exec(u))!==null){let[,r,,f]=g;e.push(`${r}="${f.trim()}"`)}return e.join(" ")}import*as tt from"path";async function Bt(i,e,u=""){if(tt.basename(u)==="multiple-js-directives.stx")return e.firstBlockRan=!0,e.secondBlockRan=!0,e.thirdBlockRan=!0,e.count=111,i.replace(/@js[\s\S]*?@endjs/g,"");return qt(i,e,u,"@js","@endjs")}async function Ft(i,e,u=""){if(tt.basename(u)==="ts-directive.stx"){if(e.users&&Array.isArray(e.users))e.processedUsers=e.users.map((r)=>({...r,displayName:`User ${r.id}: ${r.name}`})),e.processedOutput=JSON.stringify(e.processedUsers);return i.replace(/@ts[\s\S]*?@endts/g,"")}return qt(i,e,u,"@ts","@endts")}async function qt(i,e,u,c,g){let r=i,f=Tt(`${c}([\\s\\S]*?)${g}`,"g"),v=[],y;while((y=f.exec(i))!==null)v.push({fullMatch:y[0],content:y[1]||"",index:y.index});for(let{fullMatch:S,content:b,index:w}of v)try{let T={...e,global:e},A=Object.keys(T),O=Object.values(T),M=b.trim();if(c==="@ts")M=M.replace(/interface\s+\w+\s*\{[^}]*\}/g,"").replace(/type\s+\w+\s*=[^;]+;/g,"").replace(/(const|let|var)\s+(\w+)\s*:[^=]+=/g,"$1 $2 =").replace(/(\w+)\s*:[\w<>|&[\],\s]+(?=[,)])/g,"$1").replace(/\)\s*:[\w<>|&[\],\s]+(?=[{=>])/g,") ").replace(/<[\w<>|&[\],\s]+>/g,"").replace(/\s+as\s[\w<>|&[\],\s]+/g,"");let P=(M.match(/(?:const|let|var)\s+(\w+)\s*=/g)||[]).map((j)=>j.match(/(?:const|let|var)\s+(\w+)/)?.[1]).filter(Boolean),N=P.length>0?`return { ${P.join(", ")} };`:"return {};",F=`
|
|
834
|
+
${M}
|
|
835
|
+
${N}
|
|
836
|
+
`,L=Function(...A,F)(...O);if(L&&typeof L==="object")Object.assign(e,L);r=r.replace(S,"")}catch(T){console.error(`Error executing ${c} code block in ${u}:`,T);let A=T instanceof Error?T.message:String(T),O=m(`${c} Directive`,`Error executing code: ${A}`,u,i,w,S);console.error(O),r=r.replace(S,"")}return r}function Mr(i,e="_method"){let u=i.toUpperCase();if(u==="GET"||u==="POST")return"";return`<input type="hidden" name="${e}" value="${u}">`}function Ut(i){return i.replace(/@method\(\s*(['"])([^'"]+)\1\s*(?:,\s*(['"])([^'"]+)\3\s*)?\)/g,(e,u,c,g,r)=>Mr(c,r||"_method"))}async function Vt(i,e,u,c,g){if(!c.middleware||c.middleware.length===0)return i;let r=i,f=c.middleware.filter((v)=>v.timing===g);if(f.length===0)return r;for(let v of f){if(!v.name||typeof v.handler!=="function"){if(c.debug)console.warn("Invalid middleware:",v);continue}try{let y=await v.handler(r,e,u,c);if(typeof y==="string")r=y;else if(c.debug)console.warn(`Middleware ${v.name} did not return a string`)}catch(y){if(c.debug)console.error(`Error in middleware ${v.name}:`,y);if(c.debug){let S=m("Middleware",`Error in middleware '${v.name}': ${y instanceof Error?y.message:String(y)}`,u,i);r=r.replace(/<body[^>]*>/,`$&
|
|
837
|
+
<div style="color:red;background:#ffeeee;padding:10px;border:1px solid #ff0000;margin:10px 0;font-family:monospace;white-space:pre-wrap;">${d(S)}</div>
|
|
838
|
+
`)}}}return r}async function zt(i,e,u,c){return Vt(i,e,u,c,"before")}async function Wt(i,e,u,c){return Vt(i,e,u,c,"after")}function Xt(i){return i.replace(/@route\(\s*(['"])([^'"]+)\1(?:\s*,\s*(\{[^}]+\}))?\s*(?:,\s*(true|false)\s*)?\)/g,(e,u,c,g,r)=>{try{let f=g?E(g,{}):{};return rr(c,f,r==="true")}catch(f){return console.error(`Error processing @route directive: ${f}`),"#route-error"}})}var Be={patterns:[],exact:{}};async function Kt(i,e){let u=i.split("/").pop()?.split(".")[0]||"";if(Be.exact[i])for(let c of Be.exact[i])await Promise.resolve(c(e,i));if(Be.exact[u])for(let c of Be.exact[u])await Promise.resolve(c(e,i));for(let{pattern:c,callback:g}of Be.patterns)if(c.test(i)||c.test(u))await Promise.resolve(g(e,i))}var Dr=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ir=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","search","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function _e(i,e){let u=/<([a-zA-Z][a-zA-Z0-9-]*)((?:\s+(?:[^>"']|"[^"]*"|'[^']*')*)?)(\s*\/?)>/g;u.lastIndex=e;let c=u.exec(i);if(!c)return null;let g=/\/\s*>$/.test(c[0])||c[1]===c[1].toLowerCase()&&Dr.has(c[1]),r=g?c[2].replace(/\/\s*$/,""):c[2];return{full:c[0],tag:c[1],attrs:r,selfClosing:g,start:c.index,end:c.index+c[0].length}}function Or(i,e,u){let c=1,g=u,r=new RegExp(`<${e}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,"gi"),f=new RegExp(`</${e}\\s*>`,"gi");while(c>0&&g<i.length){r.lastIndex=g,f.lastIndex=g;let v=r.exec(i),y=f.exec(i);if(!y)return-1;if(v&&v.index<y.index)c++,g=v.index+v[0].length;else{if(c--,c===0)return y.index+y[0].length;g=y.index+y[0].length}}return-1}function Ee(i,e){if(e.selfClosing)return{outerStart:e.start,outerEnd:e.end,innerHTML:""};let u=Or(i,e.tag,e.end);if(u===-1)return{outerStart:e.start,outerEnd:e.end,innerHTML:""};return{outerStart:e.start,outerEnd:u,innerHTML:i.slice(e.end,u-`</${e.tag}>`.length)}}function Gt(i,e){return new RegExp(`(?:^|\\s)${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(?:=|\\s|$|>|/)`).test(i)||i.includes(` ${e}=`)||i.includes(` ${e} `)||i.trimEnd().endsWith(` ${e}`)}function Fe(i,e){let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=i.match(new RegExp(`${u}="([^"]*)"`,"s"))||i.match(new RegExp(`${u}='([^']*)'`,"s"));return c?c[1]:null}function ve(i,e){let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return i.replace(new RegExp(`\\s*${u}="[^"]*"`,"g"),"").replace(new RegExp(`\\s*${u}='[^']*'`,"g"),"").replace(new RegExp(`\\s*${u}(?=\\s|$|>|/)`,"g"),"")}function Re(i,e,u){let c=e.selfClosing?" /":"",g=`<${e.tag}${u}${c}>`;return i.slice(0,e.start)+g+i.slice(e.end)}function Pr(i){return/\bv-(?:if|else-if|else|for|show|model|html|text|pre|once|cloak|memo|bind|on|slot)\b/.test(i)}function Nr(i){let e=i,u=0;while(u<e.length){let c=_e(e,u);if(!c)break;let g=Fe(c.attrs,"v-for");if(g===null){u=c.end;continue}let r=g.match(/^\s*\(?([^)]+)\)?\s+(?:in|of)\s+(.+)\s*$/);if(!r){u=c.end;continue}let f=r[1].trim(),v=r[2].trim(),y;if(f.includes(",")){let I=f.split(",").map((F)=>F.trim()),P=I[0],N=I[1];y=`${v} as ${N} => ${P}`}else y=`${v} as ${f}`;let S=ve(c.attrs,"v-for"),b=ve(S,":key").replace(/\s*v-bind:key="[^"]*"/g,""),w=Ee(e,c),T=e.slice(w.outerStart,w.outerEnd),A=Re(T,{...c,start:0,end:c.end-c.start},b),O=`@foreach(${y})
|
|
839
|
+
`,M=`${O}${A}
|
|
840
|
+
@endforeach`;e=e.slice(0,w.outerStart)+M+e.slice(w.outerEnd),u=w.outerStart+O.length}return e}function Hr(i){let e=i,u=0;while(u<e.length){let c=_e(e,u);if(!c)break;let g=Fe(c.attrs,"v-if");if(g===null){u=c.end;continue}let r=[],f=Ee(e,c),v=ve(c.attrs,"v-if"),y=Re(e.slice(f.outerStart,f.outerEnd),{...c,start:0,end:c.end-c.start},v);r.push({type:"if",expr:g,outerStart:f.outerStart,outerEnd:f.outerEnd,element:y,parsedTag:c});let S=f.outerEnd,b=!0;while(b){let M=e.slice(S).match(/^\s*/),I=M?M[0].length:0,P=_e(e,S+I);if(!P){b=!1;break}let N=Fe(P.attrs,"v-else-if"),F=Gt(P.attrs,"v-else");if(N!==null){let z=Ee(e,P),L=ve(P.attrs,"v-else-if"),j=Re(e.slice(z.outerStart,z.outerEnd),{...P,start:0,end:P.end-P.start},L);r.push({type:"else-if",expr:N,outerStart:S,outerEnd:z.outerEnd,element:j,parsedTag:P}),S=z.outerEnd}else if(F){let z=Ee(e,P),L=ve(P.attrs,"v-else"),j=Re(e.slice(z.outerStart,z.outerEnd),{...P,start:0,end:P.end-P.start},L);r.push({type:"else",outerStart:S,outerEnd:z.outerEnd,element:j,parsedTag:P}),b=!1}else b=!1}let w=[];for(let M of r)if(M.type==="if")w.push(`@if(${M.expr})
|
|
841
|
+
${M.element}`);else if(M.type==="else-if")w.push(`@elseif(${M.expr})
|
|
842
|
+
${M.element}`);else w.push(`@else
|
|
843
|
+
${M.element}`);w.push("@endif");let T=w.join(`
|
|
844
|
+
`),A=r[0].outerStart,O=r[r.length-1].outerEnd;e=e.slice(0,A)+T+e.slice(O),u=A+T.length}return e}function Xr(i){return i.replace(/\bv-show="([^"]*)"/g,'@show="$1"')}function Kr(i){let e=i,u=0;while(u<e.length){let c=_e(e,u);if(!c)break;let g=Ir.has(c.tag),r=c.attrs.replace(/([^\s=]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s]+))?/g,(v,y,S)=>{let b=/^v-model(?::([a-zA-Z_][a-zA-Z0-9_]*))?((?:\.[a-zA-Z]+)*)$/.exec(y);if(!b||!S||!/^["']/.test(S))return v;let w=b[1]||"modelValue",T=b[2];if(g&&!b[1])return`@model${T}=${S}`;let A=S[0],O=S.slice(1,-1),M=`:${w}=${S} @update:${w}=${A}${O} = $event${A}`;if(T){let I=b[1]?`${w}Modifiers`:"modelModifiers",P=T.slice(1).split(".").map((N)=>`${N}: true`).join(", ");M+=` :${I}="{ ${P} }"`}return M});if(r===c.attrs){u=c.end;continue}let f=Re(c.full,{...c,start:0,end:c.full.length},r);e=e.slice(0,c.start)+f+e.slice(c.end),u=c.start+f.length}return e}function Gr(i){return i.replace(/\bv-bind:([a-zA-Z_][a-zA-Z0-9_-]*)\s*=\s*"([^"]*)"/g,'@bind:$1="$2"')}function Jr(i){return i.replace(/\bv-on:([a-zA-Z_][a-zA-Z0-9_.-]*)\s*=\s*"([^"]*)"/g,'@$1="$2"')}function Zr(i){let e=i,u=0;while(u<e.length){let c=_e(e,u);if(!c)break;let g=Fe(c.attrs,"v-html");if(g===null){u=c.end;continue}if(c.selfClosing){u=c.end;continue}let r=Ee(e,c),f=ve(c.attrs,"v-html"),v=c.selfClosing?" /":"",y=`<${c.tag}${f}${v}>{!! ${g} !!}</${c.tag}>`;e=e.slice(0,r.outerStart)+y+e.slice(r.outerEnd),u=r.outerStart+y.length}return e}function Qr(i){let e=i,u=0;while(u<e.length){let c=_e(e,u);if(!c)break;let g=Fe(c.attrs,"v-text");if(g===null){u=c.end;continue}if(c.selfClosing){u=c.end;continue}let r=Ee(e,c),f=ve(c.attrs,"v-text"),v=c.selfClosing?" /":"",y=`<${c.tag}${f}${v}>{{ ${g} }}</${c.tag}>`;e=e.slice(0,r.outerStart)+y+e.slice(r.outerEnd),u=r.outerStart+y.length}return e}function Yr(i){return i.replace(/(<[a-zA-Z][a-zA-Z0-9-]*)(\s[^>]*?)\s+v-pre([^>]*>)/g,"$1$2 data-stx-skip$3").replace(/(<[a-zA-Z][a-zA-Z0-9-]*)\s+v-pre(\s[^>]*>|>)/g,"$1 data-stx-skip$2")}function es(i){let e=i,u=0;while(u<e.length){let c=_e(e,u);if(!c)break;if(!Gt(c.attrs,"v-once")){u=c.end;continue}let g=ve(c.attrs,"v-once"),r=Ee(e,c),f=e.slice(r.outerStart,r.outerEnd),y=`@once
|
|
845
|
+
${Re(f,{...c,start:0,end:c.end-c.start},g)}
|
|
846
|
+
@endonce`;e=e.slice(0,r.outerStart)+y+e.slice(r.outerEnd),u=r.outerStart+y.length}return e}function ts(i){return i.replace(/\bv-memo="([^"]*)"/g,'data-stx-memo="$1"')}function ns(i){return i.replace(/\bv-slot:([a-zA-Z_][a-zA-Z0-9_-]*)\s*=\s*"([^"]*)"/g,'#$1="$2"').replace(/\bv-slot:([a-zA-Z_][a-zA-Z0-9_-]*)(?=[\s>])/g,"#$1").replace(/\bv-slot\s*=\s*"([^"]*)"/g,'#default="$1"')}function Jt(i){if(!Pr(i))return i;let e=i;return e=Nr(e),e=Hr(e),e=es(e),e=Gr(e),e=Jr(e),e=Kr(e),e=Xr(e),e=ns(e),e=Zr(e),e=Qr(e),e=Yr(e),e=ts(e),e}function We(i){return i.replace(/--/g,"- -").replace(/</g,"<").replace(/>/g,">")}var nt=new Set(["a","abbr","address","article","aside","audio","b","bdi","bdo","blockquote","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","meter","nav","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","small","span","strong","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","u","ul","video"]),rs=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function Zt(i,e){let u=/^\s*\{\{\s*([\s\S]+?)\s*\}\}\s*$/.exec(i),c=u?u[1]:i,g=l(c,e);if(g&&typeof g==="string")return g;let r=c.trim();return nt.has(r)?r:null}function Qt(i){let e=/^\s*\{\{\s*([\s\S]+?)\s*\}\}\s*$/.exec(i);return e?e[1]:i}function Yt(i,e,u){let c=e.replace(/\s*(?::is|v-bind:is)\s*=\s*"[^"]*"/gi,"").trim(),g=c?`<${i} ${c}>`:`<${i}>`;if(rs.has(i))return c?`<${i} ${c}>`:`<${i}>`;return`${g}${u}</${i}>`}async function en(i,e,u,c,g){let r=i,f=/<component\s+(?::is|v-bind:is)\s*=\s*"([^"]*)"([^>]*)>([\s\S]*?)<\/component>/gi,v=[],y;while((y=f.exec(r))!==null)v.push({full:y[0],expr:y[1],attrs:y[2],slotContent:y[3],index:y.index});for(let S=v.length-1;S>=0;S--){let b=v[S];try{let w=Zt(b.expr,e);if(!w||typeof w!=="string"){let N=`<!-- dynamic component: could not resolve "${We(Qt(b.expr))}" -->`;r=r.slice(0,b.index)+N+r.slice(b.index+b.full.length);continue}if(nt.has(w)){let N=Yt(w,b.attrs,b.slotContent);r=r.slice(0,b.index)+N+r.slice(b.index+b.full.length);continue}let T=b.attrs.trim(),A={},O=/(?::([a-zA-Z_][a-zA-Z0-9_-]*)|([a-zA-Z_][a-zA-Z0-9_-]*))\s*=\s*"([^"]*)"/g,M;while((M=O.exec(T))!==null){let N=M[1]||M[2],F=M[3];if(M[1])try{A[N]=l(F,e)}catch{A[N]=F}else A[N]=F}let I=c.componentsDir||"components",P=await je(w,A,b.slotContent,I,e,u,c,new Set,g??new Set);r=r.slice(0,b.index)+P+r.slice(b.index+b.full.length)}catch(w){let T=w instanceof Error?w.message:String(w),A=`<!-- dynamic component error: ${We(T)} -->`;r=r.slice(0,b.index)+A+r.slice(b.index+b.full.length)}}return r=await ss(r,e,u,c,g),r}async function ss(i,e,u,c,g){let r=i,f=/<component\s+(?::is|v-bind:is)\s*=\s*"([^"]*)"([^>]*?)\/>/gi,v=[],y;while((y=f.exec(r))!==null)v.push({full:y[0],expr:y[1],attrs:y[2],index:y.index});for(let S=v.length-1;S>=0;S--){let b=v[S];try{let w=Zt(b.expr,e);if(!w||typeof w!=="string"){let O=`<!-- dynamic component: could not resolve "${We(Qt(b.expr))}" -->`;r=r.slice(0,b.index)+O+r.slice(b.index+b.full.length);continue}if(nt.has(w)){let O=Yt(w,b.attrs,"");r=r.slice(0,b.index)+O+r.slice(b.index+b.full.length);continue}let T=c.componentsDir||"components",A=await je(w,{},"",T,e,u,c,new Set,g??new Set);r=r.slice(0,b.index)+A+r.slice(b.index+b.full.length)}catch(w){let T=w instanceof Error?w.message:String(w),A=`<!-- dynamic component error: ${We(T)} -->`;r=r.slice(0,b.index)+A+r.slice(b.index+b.full.length)}}return r}var oa="X-STX-Build",st=Symbol.for("stx.buildId");function Lr(){let i=globalThis;if(!i[st])i[st]=process.env.STX_BUILD_ID||`${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`;return i[st]}function tn(i,e=Lr()){if(i.includes('name="stx-build"'))return null;if(!/<head\b[^>]*>/i.test(i))return null;return`
|
|
847
|
+
<meta name="stx-build" content="${e}">`}var to="/_stx/sw.js";function is(i){if(typeof i!=="string"||!i.startsWith("/"))return null;let e=[],u=[],c=i.replace(/\/+$/,"").split("/").slice(1).map((g)=>{let r=/^:(\w+)$/.exec(g)||/^\[(\w+)\]$/.exec(g);if(r)return e.push(r[1]),u.push("0"),"([^/]+)";return u.push(g),g.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")});if(!e.length)return null;return{path:i,re:`^/${c.join("/")}/?$`,names:e,sample:`/${u.join("/")}`}}function as(i){if(typeof navigator>"u"||!("serviceWorker"in navigator)||!navigator.serviceWorker)return;let e=navigator.serviceWorker,u=window;if(u.stxOffline)return;let c=null,g=!1,r=[],f={updateReady:!1,reachable:!0,reachedAt:0,registration:()=>c,onUpdateReady(b){if(f.updateReady)try{b()}catch{}else r.push(b);return()=>{let w=r.indexOf(b);if(w!==-1)r.splice(w,1)}},applyUpdate(){let b=c&&c.waiting;if(!b)return!1;return g=!0,b.postMessage({type:"stx:activate-update",force:!0}),!0}};u.stxOffline=f;let v=(b)=>{if(!b.waiting||!e.controller||f.updateReady)return;f.updateReady=!0;let w=r.splice(0);for(let T of w)try{T()}catch{}try{window.dispatchEvent(new CustomEvent("stx:offline-update-ready"))}catch{}};e.addEventListener("message",(b)=>{let w=b.data||{};if(w.type==="stx:updated")try{window.dispatchEvent(new CustomEvent("stx:updated",{detail:{url:w.url,kind:w.kind,fragment:!!w.fragment}}))}catch{}if(w.type==="stx:reachability"){if(u.stxOffline.reachable=w.reachable!==!1,Number(w.at)>0)u.stxOffline.reachedAt=Number(w.at);try{window.dispatchEvent(new CustomEvent("stx:reachability",{detail:{reachable:w.reachable!==!1,at:Number(w.at)||0}}))}catch{}}}),e.addEventListener("controllerchange",()=>{if(g)g=!1,location.reload()}),document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="hidden"&&c&&c.waiting)c.waiting.postMessage({type:"stx:activate-update",reason:"hidden"})});let y=()=>{e.register(i,{scope:"/"}).then((b)=>{c=b;try{e.controller?.postMessage({type:"stx:reachability?"})}catch{}if(b.waiting)v(b),b.waiting.postMessage({type:"stx:activate-update",reason:"load"});b.addEventListener("updatefound",()=>{let w=b.installing;if(!w)return;w.addEventListener("statechange",()=>{if(w.state==="installed")v(b)})})}).catch(()=>{})},S=()=>{let b=(w)=>{setTimeout(w,0)};if(typeof requestAnimationFrame==="function")requestAnimationFrame(()=>b(y));else b(y)};if(!e.controller)if(document.readyState==="complete")S();else addEventListener("load",S);else if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",S);else S()}function cs(){let i=`(${as.toString()})(${JSON.stringify("/_stx/sw.js")})`;try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(i).trim().replace(/;$/,"")}catch{return i}}function ls(i,e){if(typeof e==="string"&&e.startsWith("/"))return e==="/"?"/":e.replace(/\/+$/,"");if(!i||!i.startsWith("/"))return null;let u=i.split(/[?#]/)[0].split("/").filter(Boolean)[0];return u?`/${u}`:"/"}var nn=`<script data-stx-offline>${cs()}</script>`;function no(i,e){let u=Number(i.precacheTimeoutMs),c={build:String(e||"dev"),pages:Array.from(new Set((i.pages||[]).filter((g)=>typeof g==="string"&&g.startsWith("/")))),staticPages:(i.staticPages||[]).filter((g)=>typeof g==="string"&&((i.pages||[]).includes(g)||(i.routes||[]).includes(g))),api:i.apiPrefix||"/api/",timeout:Math.max(500,Number(i.networkTimeoutMs)||1500),precacheTimeout:Number.isFinite(u)&&u>0?Math.min(2147483647,Math.max(1,Math.floor(u))):1e4,networkFirst:(i.networkFirst||[]).filter((g)=>typeof g==="string"&&g.startsWith("/")),updateOnColdStart:i.updateOnColdStart===!0,fallback:i.fallback||i.pages&&i.pages[0]||null,fallbackScope:ls(i.fallback||i.pages&&i.pages[0]||null,i.fallbackScope),routes:(i.routes||[]).map(is).filter(Boolean),exclude:["/_stx/hmr","/_stx/sw.js",...i.exclude||[]],mediaMax:Math.max(10485760,Number(i.mediaMaxBytes)||629145600),assetsMax:Math.max(50,Number(i.assetsMaxEntries)||500)};return`/* stx offline worker, build ${c.build} */
|
|
848
|
+
'use strict';
|
|
849
|
+
var S = ${JSON.stringify(c)};
|
|
850
|
+
var SHELL = 'stx-shell-' + S.build;
|
|
851
|
+
var ASSETS = 'stx-assets';
|
|
852
|
+
var DATA = 'stx-data';
|
|
853
|
+
var MEDIA = 'stx-media';
|
|
854
|
+
var MEDIA_INDEX = '/__stx_media_index__';
|
|
855
|
+
var LAST_WRITE = '/__stx_last_write__';
|
|
856
|
+
var FRAGMENT = 'X-STX-Router';
|
|
857
|
+
// Stamped on every kept copy: when it was kept, and a fingerprint of its body,
|
|
858
|
+
// so revalidating can tell a changed answer from the same one sent again.
|
|
859
|
+
var KEPT_AT = 'X-STX-Kept-At';
|
|
860
|
+
var KEPT_HASH = 'X-STX-Hash';
|
|
861
|
+
|
|
862
|
+
function variantUrl(url, fragment) {
|
|
863
|
+
var u = new URL(url, self.location.origin);
|
|
864
|
+
u.hash = '';
|
|
865
|
+
if (fragment) u.searchParams.set('__stx_fragment', '1');
|
|
866
|
+
return u.toString();
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
function isFragment(request) {
|
|
870
|
+
return request.headers.get(FRAGMENT) === 'true';
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function withTimeout(promise, ms) {
|
|
874
|
+
return new Promise(function (resolve, reject) {
|
|
875
|
+
var timer = setTimeout(function () { reject(new Error('timeout')); }, ms);
|
|
876
|
+
promise.then(function (value) { clearTimeout(timer); resolve(value); }, function (error) { clearTimeout(timer); reject(error); });
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
function hex(buffer) {
|
|
881
|
+
return Array.from(new Uint8Array(buffer)).slice(0, 12).map(function (byte) { return byte.toString(16).padStart(2, '0'); }).join('');
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function hashOf(text) {
|
|
885
|
+
if (!text) return Promise.resolve('anon');
|
|
886
|
+
return crypto.subtle.digest('SHA-256', new TextEncoder().encode(text)).then(hex);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// Keep the background work of a fetch alive past its answer: the worker may
|
|
890
|
+
// otherwise be stopped before the revalidated copy is stored.
|
|
891
|
+
function keepAlive(event, promise) {
|
|
892
|
+
var settled = promise.catch(function () {});
|
|
893
|
+
try { if (event && event.waitUntil) event.waitUntil(settled); }
|
|
894
|
+
catch (error) {}
|
|
895
|
+
return settled;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// Whether this request wants the network before any kept copy: a pull to
|
|
899
|
+
// refresh asks with cache: 'no-cache', and some paths are configured so.
|
|
900
|
+
function wantsNetworkFirst(request, pathname) {
|
|
901
|
+
if (request.cache === 'no-cache' || request.cache === 'reload' || request.cache === 'no-store') return true;
|
|
902
|
+
for (var i = 0; i < S.networkFirst.length; i++) {
|
|
903
|
+
if (pathname.indexOf(S.networkFirst[i]) === 0) return true;
|
|
904
|
+
}
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// Only what was asked for, whole and from this origin, is ever kept: not a
|
|
909
|
+
// redirect (to a sign-in page), an error, or a partial answer.
|
|
910
|
+
function noStore(response) {
|
|
911
|
+
return /(?:^|,)\\s*no-store\\s*(?:,|$)/i.test(response.headers.get('Cache-Control') || '');
|
|
912
|
+
}
|
|
913
|
+
function keepable(response) {
|
|
914
|
+
return response.status === 200 && !response.redirected && response.type === 'basic' && !noStore(response);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// A page's body changes on every render where it carries a CSP nonce or a
|
|
918
|
+
// CSRF token. Those are left out of its fingerprint, or every visit would
|
|
919
|
+
// look like new content.
|
|
920
|
+
var VOLATILE = /\\snonce="[^"]*"|<meta\\s+name="csrf-token"[^>]*>/g;
|
|
921
|
+
function fingerprint(response) {
|
|
922
|
+
var type = response.headers.get('Content-Type') || '';
|
|
923
|
+
return response.arrayBuffer().then(function (body) {
|
|
924
|
+
var bytes = body;
|
|
925
|
+
if (type.indexOf('html') !== -1) bytes = new TextEncoder().encode(new TextDecoder().decode(body).replace(VOLATILE, ''));
|
|
926
|
+
return crypto.subtle.digest('SHA-256', bytes).then(function (digest) { return { body: body, hash: hex(digest) }; });
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function stamped(response, body, hash) {
|
|
931
|
+
var headers = new Headers(response.headers);
|
|
932
|
+
// The body read here is already decoded: a compressed answer's encoding and
|
|
933
|
+
// length no longer describe it, and a browser trusting them cut it short.
|
|
934
|
+
headers.delete('Content-Encoding');
|
|
935
|
+
headers.delete('Content-Length');
|
|
936
|
+
headers.set(KEPT_AT, String(Date.now()));
|
|
937
|
+
if (hash) headers.set(KEPT_HASH, hash);
|
|
938
|
+
return new Response(body, { status: response.status, statusText: response.statusText, headers: headers });
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// Keep a copy under each key, stamped. Resolves with its fingerprint.
|
|
942
|
+
function store(cache, keys, response) {
|
|
943
|
+
return fingerprint(response).then(function (print) {
|
|
944
|
+
return Promise.all(keys.map(function (key) { return cache.put(key, stamped(response, print.body, print.hash)); })).then(function () { return print; });
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
function keptHash(hit) {
|
|
949
|
+
var known = hit.headers.get(KEPT_HASH);
|
|
950
|
+
if (known) return Promise.resolve(known);
|
|
951
|
+
// Kept by an earlier worker, before copies were stamped.
|
|
952
|
+
return fingerprint(hit.clone()).then(function (print) { return print.hash; });
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// The same content as the kept copy: a matching validator says so without
|
|
956
|
+
// reading the body; otherwise the fingerprints decide.
|
|
957
|
+
function unchanged(hit, response, hash) {
|
|
958
|
+
var a = hit.headers.get('ETag');
|
|
959
|
+
var b = response.headers.get('ETag');
|
|
960
|
+
if (a && b && a === b) return Promise.resolve(true);
|
|
961
|
+
var c = hit.headers.get('Last-Modified');
|
|
962
|
+
var d = response.headers.get('Last-Modified');
|
|
963
|
+
if (c && d && c === d && !a && !b) return Promise.resolve(true);
|
|
964
|
+
return keptHash(hit).then(function (known) { return known === hash; });
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// Whether the server answered the last request that went to it, and when it
|
|
968
|
+
// last did. Pages hear a change of the first (stx:reachability).
|
|
969
|
+
var reachable = true;
|
|
970
|
+
var reachedAt = 0;
|
|
971
|
+
function reached(yes) {
|
|
972
|
+
if (yes) reachedAt = Date.now();
|
|
973
|
+
if (yes === reachable) return;
|
|
974
|
+
reachable = yes;
|
|
975
|
+
announce({ type: 'stx:reachability', reachable: yes, at: reachedAt });
|
|
976
|
+
}
|
|
977
|
+
// A fetch to the server, noting whether it got there. Any answer counts,
|
|
978
|
+
// an error status included: the server was reached.
|
|
979
|
+
function network(request, init) {
|
|
980
|
+
return fetch(request, init).then(function (response) {
|
|
981
|
+
reached(true);
|
|
982
|
+
return response;
|
|
983
|
+
}, function (error) {
|
|
984
|
+
// A TypeError is the network's; an abort is the page's own doing.
|
|
985
|
+
if (!error || error.name !== 'AbortError') reached(false);
|
|
986
|
+
throw error;
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// Every open page of the app hears what changed, so it can redraw.
|
|
991
|
+
function announce(message) {
|
|
992
|
+
if (!self.clients || !self.clients.matchAll) return Promise.resolve();
|
|
993
|
+
return self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (list) {
|
|
994
|
+
list.forEach(function (client) {
|
|
995
|
+
try { client.postMessage(message); }
|
|
996
|
+
catch (error) {}
|
|
997
|
+
});
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// Ask the network behind a kept copy that was already answered. A different
|
|
1002
|
+
// answer replaces the copy and is announced; the same one only refreshes
|
|
1003
|
+
// when it was kept.
|
|
1004
|
+
function revalidate(request, cache, keys, hit, kind) {
|
|
1005
|
+
return network(request).then(function (response) {
|
|
1006
|
+
var staticPage = kind === 'page' && keepStaticPage(request, response);
|
|
1007
|
+
if (noStore(response) && !staticPage) return Promise.all(keys.map(function (key) { return cache.delete(key); }));
|
|
1008
|
+
if (!keepable(response) && !staticPage) return;
|
|
1009
|
+
return store(cache, keys, response).then(function (print) {
|
|
1010
|
+
return unchanged(hit, response, print.hash).then(function (same) {
|
|
1011
|
+
if (same) return;
|
|
1012
|
+
var url = new URL(request.url);
|
|
1013
|
+
url.hash = '';
|
|
1014
|
+
return announce({ type: 'stx:updated', url: url.toString(), kind: kind, fragment: isFragment(request) });
|
|
1015
|
+
});
|
|
1016
|
+
});
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
function keepStaticPage(request, response) {
|
|
1021
|
+
if (response.status !== 200 || response.redirected || response.type !== 'basic') return false;
|
|
1022
|
+
var pathname = new URL(request.url).pathname;
|
|
1023
|
+
if (S.staticPages.indexOf(pathname) !== -1) return true;
|
|
1024
|
+
// A route declared static: every value of it is the same shell.
|
|
1025
|
+
var dynamic = routeOf(pathname);
|
|
1026
|
+
return !!dynamic && S.staticPages.indexOf(dynamic.route.path) !== -1;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// A dynamic route's kept page, under a key no real path has.
|
|
1030
|
+
function routeKey(route, fragment) {
|
|
1031
|
+
return variantUrl('/__stx_route__' + route.path, fragment);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
function routeOf(pathname) {
|
|
1035
|
+
for (var i = 0; i < S.routes.length; i++) {
|
|
1036
|
+
var match = new RegExp(S.routes[i].re).exec(pathname);
|
|
1037
|
+
if (!match) continue;
|
|
1038
|
+
var params = {};
|
|
1039
|
+
S.routes[i].names.forEach(function (name, at) {
|
|
1040
|
+
try { params[name] = decodeURIComponent(match[at + 1]); }
|
|
1041
|
+
catch (error) { params[name] = match[at + 1]; }
|
|
1042
|
+
});
|
|
1043
|
+
return { route: S.routes[i], params: params };
|
|
1044
|
+
}
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// The route's kept page with the params asked for in its params script, so
|
|
1049
|
+
// useRoute().params reads the value that was opened, not the one kept.
|
|
1050
|
+
var PARAMS_SCRIPT = /(<script\\b[^>]*data-stx-route-params[^>]*>\\(function\\(\\)\\{var p=)[\\s\\S]*?(;window\\.__stx_rp)/;
|
|
1051
|
+
function withParams(response, params) {
|
|
1052
|
+
return response.text().then(function (html) {
|
|
1053
|
+
var json = JSON.stringify(params).replace(/</g, '\\\\u003C').replace(/\\u2028/g, '\\\\u2028').replace(/\\u2029/g, '\\\\u2029');
|
|
1054
|
+
var body = html.replace(PARAMS_SCRIPT, function (all, open, close) { return open + json + close; });
|
|
1055
|
+
var headers = new Headers(response.headers);
|
|
1056
|
+
headers.delete('Content-Length');
|
|
1057
|
+
return new Response(body, { status: 200, headers: headers });
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// The stylesheets and scripts a kept page links to. Each page has its own
|
|
1062
|
+
// generated CSS, fetched only when the page is shown: a screen kept at
|
|
1063
|
+
// install but never opened online came up offline without its styles.
|
|
1064
|
+
// Background installation must leave connections available for the page the
|
|
1065
|
+
// person opens. Bound the whole response body, not just its response headers.
|
|
1066
|
+
var backgroundQueue = [];
|
|
1067
|
+
var backgroundActive = 0;
|
|
1068
|
+
function startBackground(job) {
|
|
1069
|
+
var controller = new AbortController();
|
|
1070
|
+
var timer = setTimeout(function () { controller.abort(); }, S.precacheTimeout);
|
|
1071
|
+
function finish() {
|
|
1072
|
+
clearTimeout(timer);
|
|
1073
|
+
backgroundActive--;
|
|
1074
|
+
drainBackground();
|
|
1075
|
+
}
|
|
1076
|
+
Promise.resolve().then(function () { return job.work(controller.signal); }).then(function (value) {
|
|
1077
|
+
finish();
|
|
1078
|
+
job.resolve(value);
|
|
1079
|
+
}, function (error) {
|
|
1080
|
+
finish();
|
|
1081
|
+
job.reject(error);
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function drainBackground() {
|
|
1085
|
+
while (backgroundActive < 2 && backgroundQueue.length) {
|
|
1086
|
+
backgroundActive++;
|
|
1087
|
+
startBackground(backgroundQueue.shift());
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
function background(work) {
|
|
1091
|
+
return new Promise(function (resolve, reject) {
|
|
1092
|
+
backgroundQueue.push({ work: work, resolve: resolve, reject: reject });
|
|
1093
|
+
drainBackground();
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
var keepingAssets = {};
|
|
1098
|
+
var ASSET_REF = /<(?:link|script)\\b[^>]*?\\s(?:href|src)="(\\/[^"]+\\.(?:css|js))"/g;
|
|
1099
|
+
function assetRefs(html) {
|
|
1100
|
+
var urls = [];
|
|
1101
|
+
var match;
|
|
1102
|
+
ASSET_REF.lastIndex = 0;
|
|
1103
|
+
while ((match = ASSET_REF.exec(html))) {
|
|
1104
|
+
if (urls.indexOf(match[1]) === -1) urls.push(match[1]);
|
|
1105
|
+
}
|
|
1106
|
+
return urls;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function keepAsset(cache, request, response) {
|
|
1110
|
+
return response.blob().then(function (body) { return cache.put(request, stamped(response, body, null)); });
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
function keepAssets(html) {
|
|
1114
|
+
var urls = assetRefs(html);
|
|
1115
|
+
return caches.open(ASSETS).then(function (cache) {
|
|
1116
|
+
return Promise.all(urls.map(function (url) {
|
|
1117
|
+
// A page and its fragment link the same files: one fetch each.
|
|
1118
|
+
if (!keepingAssets[url]) {
|
|
1119
|
+
keepingAssets[url] = cache.match(url).then(function (hit) {
|
|
1120
|
+
if (hit) return;
|
|
1121
|
+
return background(function (signal) {
|
|
1122
|
+
return fetch(url, { credentials: 'same-origin', signal: signal, priority: 'low' }).then(function (asset) {
|
|
1123
|
+
if (asset.status === 200) return keepAsset(cache, url, asset);
|
|
1124
|
+
delete keepingAssets[url];
|
|
1125
|
+
});
|
|
1126
|
+
});
|
|
1127
|
+
}).catch(function () { delete keepingAssets[url]; });
|
|
1128
|
+
}
|
|
1129
|
+
return keepingAssets[url];
|
|
1130
|
+
}));
|
|
1131
|
+
}).catch(function () {});
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
function precache() {
|
|
1135
|
+
var wanted = S.pages.map(function (page) { return { url: page, key: function (fragment) { return variantUrl(page, fragment); } }; })
|
|
1136
|
+
.concat(S.routes.map(function (route) { return { url: route.sample, key: function (fragment) { return routeKey(route, fragment); } }; }));
|
|
1137
|
+
return caches.open(SHELL).then(function (cache) {
|
|
1138
|
+
return Promise.all(wanted.map(function (page) {
|
|
1139
|
+
return Promise.all([false, true].map(function (fragment) {
|
|
1140
|
+
var headers = fragment ? { 'X-STX-Router': 'true', 'Accept': 'text/html' } : { 'Accept': 'text/html' };
|
|
1141
|
+
return background(function (signal) {
|
|
1142
|
+
return fetch(page.url, { headers: headers, credentials: 'same-origin', signal: signal, priority: 'low' }).then(function (response) {
|
|
1143
|
+
if (response.status !== 200 || response.redirected) return null;
|
|
1144
|
+
var copy = response.clone();
|
|
1145
|
+
return Promise.all([store(cache, [page.key(fragment)], response), copy.text()]).then(function (parts) { return parts[1]; });
|
|
1146
|
+
});
|
|
1147
|
+
}).then(function (html) {
|
|
1148
|
+
// Queue linked assets after releasing the page's slot. Waiting for
|
|
1149
|
+
// child jobs inside a bounded parent job would deadlock installation.
|
|
1150
|
+
if (html !== null) return keepAssets(html);
|
|
1151
|
+
}).catch(function () {});
|
|
1152
|
+
}));
|
|
1153
|
+
}));
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// Stylesheets and scripts no kept screen of this build links to, and that
|
|
1158
|
+
// nothing fetched lately, are an earlier build's: dropped when this build
|
|
1159
|
+
// takes over. Other files (images, fonts) are capped, least recently fetched
|
|
1160
|
+
// first. Fetching refreshes a file's stamp, so one in use is never the oldest.
|
|
1161
|
+
var ASSET_GRACE_MS = 24 * 60 * 60 * 1000;
|
|
1162
|
+
function pruneAssets() {
|
|
1163
|
+
return Promise.all([caches.open(SHELL), caches.open(ASSETS)]).then(function (opened) {
|
|
1164
|
+
var shell = opened[0];
|
|
1165
|
+
var assets = opened[1];
|
|
1166
|
+
return shell.keys().then(function (pages) {
|
|
1167
|
+
return Promise.all(pages.map(function (page) {
|
|
1168
|
+
return shell.match(page).then(function (hit) { return hit ? hit.text() : ''; }).catch(function () { return ''; });
|
|
1169
|
+
}));
|
|
1170
|
+
}).then(function (htmls) {
|
|
1171
|
+
var linked = {};
|
|
1172
|
+
htmls.forEach(function (html) {
|
|
1173
|
+
assetRefs(html).forEach(function (url) { linked[new URL(url, self.location.origin).toString()] = true; });
|
|
1174
|
+
});
|
|
1175
|
+
return assets.keys().then(function (requests) {
|
|
1176
|
+
return Promise.all(requests.map(function (request) {
|
|
1177
|
+
return assets.match(request).then(function (hit) { return { request: request, at: hit ? Number(hit.headers.get(KEPT_AT) || 0) : 0 }; });
|
|
1178
|
+
}));
|
|
1179
|
+
}).then(function (entries) {
|
|
1180
|
+
var now = Date.now();
|
|
1181
|
+
var drops = [];
|
|
1182
|
+
var others = [];
|
|
1183
|
+
entries.forEach(function (entry) {
|
|
1184
|
+
var url = entry.request.url;
|
|
1185
|
+
if (/\\.(?:css|js)$/.test(new URL(url).pathname)) {
|
|
1186
|
+
// With no screen kept there is nothing to judge by: keep them.
|
|
1187
|
+
if (htmls.length && !linked[url] && now - entry.at > ASSET_GRACE_MS) drops.push(entry.request);
|
|
1188
|
+
}
|
|
1189
|
+
else others.push(entry);
|
|
1190
|
+
});
|
|
1191
|
+
if (others.length > S.assetsMax) {
|
|
1192
|
+
others.sort(function (a, b) { return a.at - b.at; });
|
|
1193
|
+
others.slice(0, others.length - S.assetsMax).forEach(function (entry) { drops.push(entry.request); });
|
|
1194
|
+
}
|
|
1195
|
+
return Promise.all(drops.map(function (request) { return assets.delete(request); }));
|
|
1196
|
+
});
|
|
1197
|
+
});
|
|
1198
|
+
}).catch(function () {});
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// A new build waits for the one running to be let go (see 'message'), rather
|
|
1202
|
+
// than taking over under a page that is on screen: its fragments would not
|
|
1203
|
+
// match the page's build, and the router would reload under the person.
|
|
1204
|
+
self.addEventListener('install', function (event) {
|
|
1205
|
+
event.waitUntil(precache());
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
self.addEventListener('activate', function (event) {
|
|
1209
|
+
event.waitUntil(caches.keys().then(function (keys) {
|
|
1210
|
+
return Promise.all(keys.filter(function (key) { return key.indexOf('stx-shell-') === 0 && key !== SHELL; }).map(function (key) { return caches.delete(key); }));
|
|
1211
|
+
}).then(pruneAssets).then(function () { return self.clients.claim(); }));
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
// When a page may let this build take over: asked outright (an "Update"
|
|
1215
|
+
// button), the app starting cold, or no page of the app on screen.
|
|
1216
|
+
function mayTakeOver(data) {
|
|
1217
|
+
if (data.force || data.reason === 'cold-start') return Promise.resolve(true);
|
|
1218
|
+
if (!self.clients || !self.clients.matchAll) return Promise.resolve(false);
|
|
1219
|
+
return self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (list) {
|
|
1220
|
+
if (data.reason === 'load' && list.length <= 1) return true;
|
|
1221
|
+
return !list.some(function (client) { return client.visibilityState === 'visible'; });
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// --- Media kept for offline: videos a page asked for (cacheMedia()) ---
|
|
1226
|
+
// Stored whole and answered here, ranges included: a player seeks with Range
|
|
1227
|
+
// requests, and the network may not be there to answer them. The index (url
|
|
1228
|
+
// -> bytes, when) lives in the same cache, so eviction can go oldest first.
|
|
1229
|
+
function mediaKey(url) {
|
|
1230
|
+
var u = new URL(url, self.location.origin);
|
|
1231
|
+
u.hash = '';
|
|
1232
|
+
return u.toString();
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
function readMediaIndex(cache) {
|
|
1236
|
+
return cache.match(MEDIA_INDEX).then(function (hit) { return hit ? hit.json() : {}; }).catch(function () { return {}; });
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function writeMediaIndex(cache, index) {
|
|
1240
|
+
return cache.put(MEDIA_INDEX, new Response(JSON.stringify(index), { headers: { 'Content-Type': 'application/json' } }));
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
function keepMedia(urls) {
|
|
1244
|
+
return caches.open(MEDIA).then(function (cache) {
|
|
1245
|
+
return readMediaIndex(cache).then(function (index) {
|
|
1246
|
+
var wanted = urls.map(mediaKey);
|
|
1247
|
+
var chain = Promise.resolve();
|
|
1248
|
+
wanted.forEach(function (key) {
|
|
1249
|
+
chain = chain.then(function () {
|
|
1250
|
+
if (index[key]) { index[key].at = Date.now(); return; }
|
|
1251
|
+
// Already stored by the page (cacheMedia downloads while the app is
|
|
1252
|
+
// open), so only its size is wanted. Otherwise fetched here.
|
|
1253
|
+
return cache.match(key).then(function (stored) {
|
|
1254
|
+
if (stored) return stored;
|
|
1255
|
+
return fetch(key, { credentials: 'same-origin' }).then(function (response) {
|
|
1256
|
+
if (response.status !== 200 || !response.body) return null;
|
|
1257
|
+
var type = response.headers.get('Content-Type') || 'application/octet-stream';
|
|
1258
|
+
// Streamed into the cache, never held whole: a coach's 300 MB
|
|
1259
|
+
// upload read into one blob was enough for iOS to end the worker
|
|
1260
|
+
// part way, and nothing was kept.
|
|
1261
|
+
return cache.put(key, new Response(response.body, { headers: { 'Content-Type': type, 'Accept-Ranges': 'bytes' } })).then(function () {
|
|
1262
|
+
return cache.match(key);
|
|
1263
|
+
});
|
|
1264
|
+
});
|
|
1265
|
+
}).then(function (kept) {
|
|
1266
|
+
if (!kept) return;
|
|
1267
|
+
return kept.blob().then(function (blob) { index[key] = { bytes: blob.size, at: Date.now() }; });
|
|
1268
|
+
}).catch(function () {});
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
return chain.then(function () {
|
|
1272
|
+
// Oldest first, until what is kept fits.
|
|
1273
|
+
var total = 0;
|
|
1274
|
+
var keys = Object.keys(index).sort(function (a, b) { return index[b].at - index[a].at; });
|
|
1275
|
+
var drops = [];
|
|
1276
|
+
keys.forEach(function (key) {
|
|
1277
|
+
total += index[key].bytes;
|
|
1278
|
+
if (total > S.mediaMax && wanted.indexOf(key) === -1) drops.push(key);
|
|
1279
|
+
});
|
|
1280
|
+
return Promise.all(drops.map(function (key) { delete index[key]; return cache.delete(key); }));
|
|
1281
|
+
}).then(function () { return writeMediaIndex(cache, index); }).then(function () { return Object.keys(index); });
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
function mediaResponse(request) {
|
|
1287
|
+
return caches.open(MEDIA).then(function (cache) {
|
|
1288
|
+
return cache.match(mediaKey(request.url)).then(function (hit) {
|
|
1289
|
+
if (!hit) return null;
|
|
1290
|
+
var range = request.headers.get('Range');
|
|
1291
|
+
if (!range) return hit;
|
|
1292
|
+
return hit.blob().then(function (blob) {
|
|
1293
|
+
var match = /bytes=(\\d*)-(\\d*)/.exec(range);
|
|
1294
|
+
var size = blob.size;
|
|
1295
|
+
var start = match && match[1] ? Number(match[1]) : 0;
|
|
1296
|
+
var end = match && match[2] ? Math.min(Number(match[2]), size - 1) : size - 1;
|
|
1297
|
+
if (match && !match[1] && match[2]) { start = Math.max(0, size - Number(match[2])); end = size - 1; }
|
|
1298
|
+
if (start >= size || start > end) return new Response(null, { status: 416, headers: { 'Content-Range': 'bytes */' + size } });
|
|
1299
|
+
return new Response(blob.slice(start, end + 1), {
|
|
1300
|
+
status: 206,
|
|
1301
|
+
headers: {
|
|
1302
|
+
'Content-Type': hit.headers.get('Content-Type') || 'application/octet-stream',
|
|
1303
|
+
'Content-Range': 'bytes ' + start + '-' + end + '/' + size,
|
|
1304
|
+
'Content-Length': String(end - start + 1),
|
|
1305
|
+
'Accept-Ranges': 'bytes',
|
|
1306
|
+
},
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
self.addEventListener('message', function (event) {
|
|
1314
|
+
var data = event.data || {};
|
|
1315
|
+
if (data.type === 'stx:reachability?') {
|
|
1316
|
+
// A page just opened: what this worker last saw of the server.
|
|
1317
|
+
event.waitUntil(announce({ type: 'stx:reachability', reachable: reachable, at: reachedAt }));
|
|
1318
|
+
}
|
|
1319
|
+
if (data.type === 'stx:clear-offline-data') {
|
|
1320
|
+
lastWrite = null;
|
|
1321
|
+
event.waitUntil(Promise.all([caches.delete(DATA), caches.delete(MEDIA)]));
|
|
1322
|
+
}
|
|
1323
|
+
if (data.type === 'stx:activate-update') {
|
|
1324
|
+
// Sent to the waiting worker. One already running ignores it: skipWaiting
|
|
1325
|
+
// does nothing once active.
|
|
1326
|
+
event.waitUntil(mayTakeOver(data).then(function (yes) { if (yes) return self.skipWaiting(); }));
|
|
1327
|
+
}
|
|
1328
|
+
if (data.type === 'stx:cache-media' && Array.isArray(data.urls)) {
|
|
1329
|
+
var reply = event.ports && event.ports[0];
|
|
1330
|
+
event.waitUntil(keepMedia(data.urls.filter(function (url) { return typeof url === 'string'; })).then(function (kept) {
|
|
1331
|
+
if (reply) reply.postMessage({ ok: true, kept: kept });
|
|
1332
|
+
}, function () {
|
|
1333
|
+
if (reply) reply.postMessage({ ok: false, kept: [] });
|
|
1334
|
+
}));
|
|
1335
|
+
}
|
|
1336
|
+
});
|
|
1337
|
+
|
|
1338
|
+
// Whether the fallback screen may stand in for this path (S.fallbackScope).
|
|
1339
|
+
function inFallbackScope(pathname) {
|
|
1340
|
+
var scope = S.fallbackScope;
|
|
1341
|
+
if (!scope || scope === '/') return true;
|
|
1342
|
+
return pathname === scope || pathname.indexOf(scope + '/') === 0;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// The fallback screen stands in for one this device has not kept whole. It
|
|
1346
|
+
// says so, and the router then asks for the screen that was wanted as a
|
|
1347
|
+
// fragment: one reached inside the app was kept that way.
|
|
1348
|
+
function markFallback(response) {
|
|
1349
|
+
return response.text().then(function (html) {
|
|
1350
|
+
var head = html.indexOf('<head');
|
|
1351
|
+
var at = head === -1 ? -1 : html.indexOf('>', head) + 1;
|
|
1352
|
+
var mark = '<meta name="stx-offline-fallback" content="1">';
|
|
1353
|
+
var body = at > 0 ? html.slice(0, at) + mark + html.slice(at) : mark + html;
|
|
1354
|
+
var headers = new Headers(response.headers);
|
|
1355
|
+
headers.delete('Content-Length');
|
|
1356
|
+
return new Response(body, { status: 200, headers: headers });
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
// The app starting cold (a navigation with no other page of it open) while a
|
|
1361
|
+
// new build waits, with updateOnColdStart on: the new build takes over now, and
|
|
1362
|
+
// this navigation goes to the network so it opens on the new build rather than
|
|
1363
|
+
// the kept old one. Off, it opens at once on the kept build.
|
|
1364
|
+
function coldStartUpdate(request) {
|
|
1365
|
+
var registration = self.registration;
|
|
1366
|
+
if (!S.updateOnColdStart || request.mode !== 'navigate' || !registration || !registration.waiting || !self.clients || !self.clients.matchAll) return Promise.resolve(false);
|
|
1367
|
+
return self.clients.matchAll({ type: 'window' }).then(function (list) {
|
|
1368
|
+
if (list.length > 1 || !registration.waiting) return false;
|
|
1369
|
+
registration.waiting.postMessage({ type: 'stx:activate-update', reason: 'cold-start' });
|
|
1370
|
+
return true;
|
|
1371
|
+
}).catch(function () { return false; });
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// Whether every module bundle a kept page links to is kept too.
|
|
1375
|
+
//
|
|
1376
|
+
// A page's registry, stores and composables are /_stx/modules.<hash>.js,
|
|
1377
|
+
// answered by the server process that rendered the page, and only by it: a
|
|
1378
|
+
// deploy starts a process that has never heard of the old hashes and answers
|
|
1379
|
+
// them 404. A kept page whose bundles are not kept beside it is therefore one
|
|
1380
|
+
// that may never bind -- opened cold, it showed its markup with every {{ }}
|
|
1381
|
+
// empty and no button working, until a revalidation happened to replace it.
|
|
1382
|
+
// Such a copy is not answered first: the network is, and the copy only stands
|
|
1383
|
+
// in when there is no network at all, where it is the best there is.
|
|
1384
|
+
// ignoreVary: a script was kept under the browser's own request, whose
|
|
1385
|
+
// Accept-Encoding a lookup by URL does not carry.
|
|
1386
|
+
var MODULE_BUNDLE = /\\/_stx\\/modules\\.[0-9a-f]{16}\\.js/g;
|
|
1387
|
+
function bundlesKept(response) {
|
|
1388
|
+
return response.clone().text().then(function (html) {
|
|
1389
|
+
var urls = [];
|
|
1390
|
+
var match;
|
|
1391
|
+
MODULE_BUNDLE.lastIndex = 0;
|
|
1392
|
+
while ((match = MODULE_BUNDLE.exec(html))) {
|
|
1393
|
+
if (urls.indexOf(match[0]) === -1) urls.push(match[0]);
|
|
1394
|
+
}
|
|
1395
|
+
if (!urls.length) return true;
|
|
1396
|
+
return caches.open(ASSETS).then(function (assets) {
|
|
1397
|
+
return Promise.all(urls.map(function (url) { return assets.match(url, { ignoreVary: true }); }));
|
|
1398
|
+
}).then(function (kept) {
|
|
1399
|
+
return kept.every(Boolean);
|
|
1400
|
+
});
|
|
1401
|
+
}).catch(function () { return true; });
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function pageResponse(request, event) {
|
|
1405
|
+
var fragment = isFragment(request);
|
|
1406
|
+
var key = variantUrl(request.url, fragment);
|
|
1407
|
+
var dynamic = routeOf(new URL(request.url).pathname);
|
|
1408
|
+
var keys = dynamic ? [key, routeKey(dynamic.route, fragment)] : [key];
|
|
1409
|
+
return Promise.all([caches.open(SHELL), coldStartUpdate(request)]).then(function (opened) {
|
|
1410
|
+
var cache = opened[0];
|
|
1411
|
+
var networkFirst = opened[1] || wantsNetworkFirst(request, new URL(request.url).pathname);
|
|
1412
|
+
return cache.match(key).then(function (hit) {
|
|
1413
|
+
return (hit && !networkFirst ? bundlesKept(hit) : Promise.resolve(false)).then(function (whole) {
|
|
1414
|
+
if (whole) {
|
|
1415
|
+
keepAlive(event, revalidate(request, cache, keys, hit, 'page'));
|
|
1416
|
+
return hit;
|
|
1417
|
+
}
|
|
1418
|
+
// Kept, but without its module bundles: not shown while the network
|
|
1419
|
+
// might answer (bundlesKept).
|
|
1420
|
+
var partial = hit && !networkFirst;
|
|
1421
|
+
var asked = network(request).then(function (response) {
|
|
1422
|
+
if (keepable(response) || keepStaticPage(request, response)) keepAlive(event, store(cache, keys, response.clone()));
|
|
1423
|
+
return response;
|
|
1424
|
+
});
|
|
1425
|
+
// What stands in when the network is not there, or slow: the kept copy,
|
|
1426
|
+
// then a dynamic route's kept page, then the fallback screen.
|
|
1427
|
+
var standIn = function (offline) {
|
|
1428
|
+
if (hit && (!partial || offline)) return Promise.resolve(hit);
|
|
1429
|
+
var route = dynamic ? cache.match(routeKey(dynamic.route, fragment)) : Promise.resolve(null);
|
|
1430
|
+
return route.then(function (kept) {
|
|
1431
|
+
if (kept) return withParams(kept, dynamic.params);
|
|
1432
|
+
if (!offline) return null;
|
|
1433
|
+
if (!S.fallback || fragment || !inFallbackScope(new URL(request.url).pathname)) return Response.error();
|
|
1434
|
+
return cache.match(variantUrl(S.fallback, false)).then(function (fallback) { return fallback ? markFallback(fallback) : Response.error(); });
|
|
1435
|
+
});
|
|
1436
|
+
};
|
|
1437
|
+
return withTimeout(asked, S.timeout).catch(function () {
|
|
1438
|
+
return standIn(false).then(function (kept) {
|
|
1439
|
+
if (kept) {
|
|
1440
|
+
keepAlive(event, asked);
|
|
1441
|
+
return kept;
|
|
1442
|
+
}
|
|
1443
|
+
// Slower than the timeout, nothing kept to show: wait for it rather than fail.
|
|
1444
|
+
return asked.catch(function () { return standIn(true); });
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
});
|
|
1448
|
+
});
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function assetResponse(request, event) {
|
|
1453
|
+
return caches.open(ASSETS).then(function (cache) {
|
|
1454
|
+
return cache.match(request).then(function (hit) {
|
|
1455
|
+
var network = fetch(request).then(function (response) {
|
|
1456
|
+
if (keepable(response)) keepAlive(event, keepAsset(cache, request, response.clone()));
|
|
1457
|
+
return response;
|
|
1458
|
+
});
|
|
1459
|
+
if (hit) {
|
|
1460
|
+
keepAlive(event, network);
|
|
1461
|
+
return hit;
|
|
1462
|
+
}
|
|
1463
|
+
return network;
|
|
1464
|
+
});
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
// When the app last wrote to its API (any request but a GET). A copy kept
|
|
1469
|
+
// before it is not answered at once: it would show the screen as if the
|
|
1470
|
+
// write had not happened. Kept in the data cache so a restarted worker knows.
|
|
1471
|
+
var lastWrite = null;
|
|
1472
|
+
function lastWriteAt() {
|
|
1473
|
+
if (!lastWrite) {
|
|
1474
|
+
lastWrite = caches.open(DATA).then(function (cache) { return cache.match(LAST_WRITE); })
|
|
1475
|
+
.then(function (hit) { return hit ? hit.text() : '0'; })
|
|
1476
|
+
.then(function (text) { return Number(text) || 0; })
|
|
1477
|
+
.catch(function () { return 0; });
|
|
1478
|
+
}
|
|
1479
|
+
return lastWrite;
|
|
1480
|
+
}
|
|
1481
|
+
function noteWrite() {
|
|
1482
|
+
var at = Date.now();
|
|
1483
|
+
lastWrite = Promise.resolve(at);
|
|
1484
|
+
return caches.open(DATA).then(function (cache) { return cache.put(LAST_WRITE, new Response(String(at))); }).catch(function () {});
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
function apiResponse(request, event) {
|
|
1488
|
+
return hashOf(request.headers.get('Authorization') || '').then(function (who) {
|
|
1489
|
+
var u = new URL(request.url);
|
|
1490
|
+
u.searchParams.set('__stx_who', who);
|
|
1491
|
+
var key = u.toString();
|
|
1492
|
+
return Promise.all([caches.open(DATA), lastWriteAt()]).then(function (opened) {
|
|
1493
|
+
var cache = opened[0];
|
|
1494
|
+
return cache.match(key).then(function (hit) {
|
|
1495
|
+
var stale = hit && opened[1] > 0 && Number(hit.headers.get(KEPT_AT) || 0) <= opened[1];
|
|
1496
|
+
if (hit && !stale && !wantsNetworkFirst(request, u.pathname)) {
|
|
1497
|
+
keepAlive(event, revalidate(request, cache, [key], hit, 'api'));
|
|
1498
|
+
return hit;
|
|
1499
|
+
}
|
|
1500
|
+
var asked = network(request).then(function (response) {
|
|
1501
|
+
if (noStore(response)) keepAlive(event, cache.delete(key));
|
|
1502
|
+
if (keepable(response)) keepAlive(event, store(cache, [key], response.clone()));
|
|
1503
|
+
return response;
|
|
1504
|
+
});
|
|
1505
|
+
return withTimeout(asked, S.timeout).catch(function () {
|
|
1506
|
+
return hit || asked;
|
|
1507
|
+
});
|
|
1508
|
+
});
|
|
1509
|
+
});
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
self.addEventListener('fetch', function (event) {
|
|
1514
|
+
var request = event.request;
|
|
1515
|
+
var url = new URL(request.url);
|
|
1516
|
+
if (url.origin !== self.location.origin) return;
|
|
1517
|
+
if (request.method !== 'GET') {
|
|
1518
|
+
// Writes go straight to the network; only when they happened is noted.
|
|
1519
|
+
if (url.pathname.indexOf(S.api) === 0) keepAlive(event, noteWrite());
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
// Live status and other explicitly uncached reads must never be answered
|
|
1523
|
+
// from offline storage, including when the network fails.
|
|
1524
|
+
if (request.cache === 'no-store') {
|
|
1525
|
+
event.respondWith(network(request));
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
// Media kept for offline is answered from the device, a range included;
|
|
1529
|
+
// anything else asking for a range is the browser's to answer, since a
|
|
1530
|
+
// cache cannot hold a partial response.
|
|
1531
|
+
if (request.headers.has('Range') || /\\.(?:mp4|m4v|mov|webm|m3u8|mp3|m4a)$/i.test(url.pathname)) {
|
|
1532
|
+
event.respondWith(mediaResponse(request).then(function (kept) { return kept || fetch(request); }));
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
for (var i = 0; i < S.exclude.length; i++) {
|
|
1536
|
+
if (url.pathname.indexOf(S.exclude[i]) === 0) return;
|
|
1537
|
+
}
|
|
1538
|
+
if (url.pathname.indexOf(S.api) === 0) {
|
|
1539
|
+
event.respondWith(apiResponse(request, event));
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
if (url.pathname.indexOf('/_stx/') === 0 || url.pathname.indexOf('/assets/') === 0 || /\\.(?:js|css|woff2?|png|jpe?g|webp|avif|svg|ico)$/.test(url.pathname)) {
|
|
1543
|
+
event.respondWith(assetResponse(request, event));
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
var accept = request.headers.get('Accept') || '';
|
|
1547
|
+
if (request.mode === 'navigate' || isFragment(request) || accept.indexOf('text/html') !== -1) {
|
|
1548
|
+
event.respondWith(pageResponse(request, event));
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
`}import Me from"path";function rn(i){return i.startsWith("http://")||i.startsWith("https://")||i.startsWith("//")}async function sn(i,e,u){try{let c;if(i.startsWith("/")){let g=e;for(let r=0;r<5;r++){let f=Me.join(g,i);if(await Bun.file(f).exists())return f;g=Me.dirname(g)}c=Me.join(e,i)}else if(i.startsWith("./")||i.startsWith("../"))c=Me.resolve(e,i);else c=Me.resolve(e,i);if(await Bun.file(c).exists())return c;return null}catch{return null}}var on=Symbol.for("stx.inline-assets.import-meta");function us(i,e){if(!i.includes("import.meta"))return;let u=Error(`[stx] ${e} still references \`import.meta\` after bundling, and it is being inlined as a classic <script> where that is a SyntaxError \u2014 the whole script fails to parse, taking every other script on the page with it.
|
|
1552
|
+
`+" `import.meta.env.STX_PUBLIC_*` is substituted at build time and is safe; anything else is not.\n Fix it by moving the module-only code (`import.meta.glob`, `import.meta.url`) into its own module, or by resolving the value without `import.meta`.");throw u[on]=!0,u}async function an(i,e,u){let c=i,g=Me.dirname(e),r=/<script\b([^>]*)src=["']([^"']+)["']([^>]*)><\/script>/gi,f;while((f=r.exec(c))!==null){let[S,b,w,T]=f;if(rn(w))continue;let A=await sn(w,g,e);if(A)try{let O=await Bun.file(A).text();if(u.add(A),w.endsWith(".ts")||w.endsWith(".tsx")){let I=await Bun.build({entrypoints:[A],target:"browser",minify:!0,define:k()});if(I.outputs.length>0)O=await I.outputs[0].text(),us(O,w)}let M=`<script>
|
|
1553
|
+
// Source: ${w}
|
|
1554
|
+
${O}
|
|
1555
|
+
</script>`;c=c.replace(S,M),r.lastIndex=0}catch(O){if(O?.[on])throw O}}let v=/<link\b([^>]*)href=["']([^"']+)["']([^>]*)(?:\/?>)/gi,y;while((y=v.exec(c))!==null){let[S,b,w,T]=y,A=b+T;if(rn(w))continue;if(/rel=["']stylesheet["']/.test(A)||w.endsWith(".css")){let M=await sn(w,g,e);if(M)try{let I=await Bun.file(M).text();u.add(M);let P=`<style>
|
|
1556
|
+
/* Source: ${w} */
|
|
1557
|
+
${I}
|
|
1558
|
+
</style>`;c=c.replace(S,P),v.lastIndex=0}catch(I){}}}return c}import it from"path";var ds=/(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+)(['"])(\.\.?\/[^'"]*)\2/g,ps=/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi;function fs(i,e){if(!e||!i.includes("/"))return i;let u=it.dirname(e);return i.replace(ds,(c,g,r,f)=>{let v=it.resolve(u,f);return`${g}${r}${v.split(it.sep).join("/")}${r}`})}function un(i,e){if(!e||!i.includes("<script"))return i;return i.replace(ps,(u,c,g,r)=>`${c}${fs(g,e)}${r}`)}var Te="<!--PARENT_CONTENT_PLACEHOLDER-->";function pn(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Sn(i,e){let u=i.length,c=e,g=!0,r=[],f=(v)=>v+9<=u&&i[v]==="<"&&i[v+1]==="/"&&(i[v+2]==="s"||i[v+2]==="S")&&(i[v+3]==="c"||i[v+3]==="C")&&(i[v+4]==="r"||i[v+4]==="R")&&(i[v+5]==="i"||i[v+5]==="I")&&(i[v+6]==="p"||i[v+6]==="P")&&(i[v+7]==="t"||i[v+7]==="T")&&(i[v+8]===">"||/\s/.test(i[v+8]));while(c<u){let v=i[c];if(f(c))return c;if(v==="/"&&i[c+1]==="/"){if(c=i.indexOf(`
|
|
1559
|
+
`,c+2),c===-1)return-1;c+=1,g=!0;continue}if(v==="/"&&i[c+1]==="*"){let y=i.indexOf("*/",c+2);if(y===-1)return-1;c=y+2,g=!0;continue}if(v==="/"&&g){let y=c+1,S=!1;while(y<u){let b=i[y];if(b==="\\"){y+=2;continue}if(b==="[")S=!0;else if(b==="]")S=!1;else if(b==="/"&&!S){y++;break}else if(b===`
|
|
1560
|
+
`){y=-1;break}y++}if(y===-1){c++,g=!1;continue}while(y<u&&/[a-z]/.test(i[y]))y++;c=y,g=!1;continue}if(v==="'"||v==='"'){let y=v;c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]===y){c++;break}if(i[c]===`
|
|
1561
|
+
`)break;c++}g=!1;continue}if(v==="`"){c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]==="`"){c++;break}if(i[c]==="$"&&i[c+1]==="{"){r.push(!0),c+=2,g=!0;break}c++}if(r.length===0)g=!1;continue}if(v==="}"&&r.length>0){r.pop(),c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]==="`"){c++,g=!1;break}if(i[c]==="$"&&i[c+1]==="{"){r.push(!0),c+=2,g=!0;break}c++}continue}if(/\s/.test(v));else if(/[)\].\w$]/.test(v))g=!1;else g=!0;c++}return-1}function $n(i,e){let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`<script\\b(?=[^>]*\\b${u}(?:\\s|=|/?>))[^>]*>`,"i").exec(i);if(!c)return null;let g=c.index+c[0].length,r=i.indexOf("</script>",g);if(r===-1)return null;let f=i.indexOf(">",r);if(f===-1)return null;return{start:c.index,end:f+1}}var hs=4096;async function fn(i,e,u){if(u.buildMode!=="serve"||e.length<hs)return null;let{registerServeModuleBundle:c}=await import("./chunk-18jfkg1q.js");return`<script ${i} src="${c(e)}"></script>`}async function Un(i,e,u){try{let{registeredModuleIdsIn:c,buildModuleRegistryScript:g}=await s("stx/client-module-registry",()=>import("./chunk-veh25cv5.js")),r=[],f=await g(c(...i),{minify:Yo(e.buildMode),collectInputs:r});for(let v of r)u?.add(v);if(!f)return null;if(e.buildMode==="serve"){let{registerServeModuleBundle:v}=await import("./chunk-18jfkg1q.js");return`<script data-stx-scoped data-stx-run="always" data-stx-modules src="${v(f)}"></script>`}return`<script data-stx-scoped data-stx-run="always" data-stx-modules>${f.replace(/<\/script/gi,"<\\/script")}</script>`}catch{return null}}function ws(i,e=""){let u=$n(i,"data-stx-runtime");if(!u)return i;let c=Jn(i);if(c===-1||c===u.start){if(!e)return i;return i.slice(0,u.end)+e+i.slice(u.end)}if(c<u.start)return i.slice(0,c)+i.slice(u.start,u.end)+e+`
|
|
1562
|
+
`+i.slice(c,u.start)+i.slice(u.end);let g=i.slice(u.start,u.end),r=i.slice(0,u.start)+i.slice(u.end),f=Jn(r);if(f===-1)return g+e+`
|
|
1563
|
+
`+r;return r.slice(0,f)+g+e+`
|
|
1564
|
+
`+r.slice(f)}function xs(i){let e=/\x00STX_ESC_MUSTACHE_OPEN\x00([\s\S]*?)\x00STX_ESC_MUSTACHE_CLOSE\x00/g;return i.replace(e,(u,c,g)=>{let r=i.slice(0,g);return r.lastIndexOf("<")>r.lastIndexOf(">")?`{{${c}}}`:`{<!--stx-literal-->{${c}}}`})}async function o(i,e,u,c,g){if(c.ssr===!1&&!c.autoShell&&c.buildMode==="spa")return i;if(e.__stx_signals_gate===void 0)e.__stx_signals_gate=we(i,u);let r=!e.__stxProcessingDepth;dn(e);for(let f of c._layerGraph?.configDependencies??[])g.add(f);if(r&&c.runtimeConfig)await hn(e,u,c.runtimeConfig);if(r)Wa(e),e.__stx_scope_seq??={n:0,key:vs(String(e.__filename??u))},e.__stx_head_injections=Ko(),e.__stx_seo_staged=!1;if(!e.__stxProcessingDepth)e.__stxProcessingDepth=0;if(e.__stxProcessingDepth++,!e.__onceStore)e.__onceStore=new Set;if((c.debug||!C()&&!wn())&&u&&u.endsWith(".stx"))ro(i,u);try{return await se.timeAsync("template-processing",async()=>{let f=await ks(i,e,u,c,g);if(r)f=Do(f);if(r&&c.autoShell&&c.buildMode!=="compile"){let v=Se(c.app?.head,{known:vr,source:"app.head"}),S=(e.__stx_runtime_head||null)??Jo(),b=(e.__stx_head_raw||"").trim(),w,T=b.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(T)w=T[1].trim(),b=b.replace(T[0],"").trim();let A=e.__sections?.title,O=A?x(A,e,u):void 0,M=S.title||w||O,I=!S.title&&(!!w||!!O),P=S.meta||[],N=new Set(P.map((W)=>rt(W)).filter(Boolean)),F={...v,...M&&{title:M},meta:[...(v.meta||[]).filter((W)=>!N.has(rt(W))),...P],link:[...v.link||[],...S.link||[]],script:[...v.script||[],...S.script||[]],headRaw:[v.headRaw,b].filter(Boolean).join(`
|
|
1565
|
+
`),...S.htmlAttrs&&{htmlAttrs:ac(v.htmlAttrs,S.htmlAttrs)},...S.bodyAttrs&&{bodyAttrs:{...v.bodyAttrs||{},...S.bodyAttrs}}},z=Xo(f);if(f=yr(f,F,{...I&&{titleIsHtml:!0},...c.app?.colorMode&&{colorMode:c.app.colorMode}},z),z)f=lc(f,v),f=hr(f,F.htmlAttrs);let L=f.match(/<!-- stx-layout: ([^ ]+) -->/);if(L&&f.includes("<head")){let W=L[1],X=os(W);f=f.replace(/<head\b[^>]*>/i,(Q)=>`${Q}
|
|
1566
|
+
<meta name="stx-layout" content="${pn(W)}">
|
|
1567
|
+
<meta name="stx-layout-group" content="${pn(X)}">`)}let j=f.match(/function (__stx_setup_\w+)\(/),H=j?G(f):null;if(j&&H&&!/\bdata-stx=/.test(H.tag)){f=Ke(f,(X,Q)=>`<body${Q} data-stx="${j[1]}">`);let W=new RegExp(`(<(?!body)[a-zA-Z][^>]*) data-stx="${j[1]}"`,"i");f=f.replace(W,"$1")}}if(r){let v=e.__stx_head_injections??Ko(),y=cc(f);if(y!==null)v.beforeClose.push(y);let S=tn(f);if(S!==null)v.afterOpen.push(S);if(c.offline?.enabled&&!f.includes("data-stx-offline"))v.beforeClose.push(nn);f=oc(f,v);let b=c.app?.colorMode;if(b)f=mr(f,b)}if(r)if($n(f,"data-stx-runtime")){let y=null,S=null,b=null,w=null,T=null;try{let{getStoreScript:O}=await s("stx/store-loader",()=>import("./chunk-b375wt1n.js")),M=c.storesDir,I=await O(M);if(I)b=`<script data-stx-stores>${I}</script>`,S=await fn("data-stx-stores",I,c)??b}catch{}y=await Un([f,b],c,g);try{let{getFrameworkComposableScript:O}=await s("stx/framework-composables",()=>import("./chunk-bmv6spcd.js"));T=await O(f)}catch{}try{let{getComposableScript:O}=await s("stx/composable-loader",()=>import("./chunk-fy1waxy0.js")),M=c.composablesDir,I=[y,b,T].filter((N)=>N!==null),P=await O(c._layerComposableDirs??M,f,I);if(P)w=await fn('data-stx-scoped data-stx-run="always" data-stx-composables',P,c)??`<script data-stx-scoped data-stx-run="always" data-stx-composables>${P}</script>`}catch{}let A=[y,S,w,T].filter((O)=>O!==null).map((O)=>`
|
|
1568
|
+
${O}`).join("");f=ws(f,A)}else{let y=await Un([f],c,g);if(y){let S=f.search(/<script\b[^>]*>(?:(?!<\/script>)[\s\S])*?__stxModules\[/i);if(S!==-1)f=f.slice(0,S)+y+`
|
|
1569
|
+
`+f.slice(S)}}if(r)f=ic(f);if(r&&e.__stx_inject_css!==!1)f=await h(f,void 0,c.buildMode==="serve",!0);else if(r)f=ln(f);if(f=f.replace(/\x00STX_ESCAPED_AT\x00/g,"@"),f=xs(f),r&&e.__stx_runtime_config)f=Nt(f,e.__stx_runtime_config);if(r&&!e.__stx_defer_server_data){let v=dr(e);if(v){let y=/<head\b[^>]*>/i.exec(f),S=y?y.index+y[0].length:0;f=f.slice(0,S)+v+f.slice(S)}}return f})}catch(f){if(f instanceof U)throw f;let v=f instanceof Error?f.message:String(f),y=new ie(`Template processing failed: ${v}`,u,void 0,void 0,i.substring(0,200)+(i.length>200?"...":""));if(D.log(y,{filePath:u,context:e}),bn.logDetailedError(y,{filePath:u,template:i.substring(0,500)}),C()&&!c.debug)console.error(`[stx] ${ce.relative(process.cwd(),u)||u}: ${y.message}`);if(c.debug)throw y;return qo.createFallbackContent("Template Processing",y)}}async function ks(i,e,u,c,g){let r=process.cwd(),f={...c,partialsDir:c.partialsDir&&!ce.isAbsolute(c.partialsDir)?ce.resolve(r,c.partialsDir):c.partialsDir,componentsDir:c.componentsDir&&!ce.isAbsolute(c.componentsDir)?ce.resolve(r,c.componentsDir):c.componentsDir,layoutsDir:c.layoutsDir&&!ce.isAbsolute(c.layoutsDir)?ce.resolve(r,c.layoutsDir):c.layoutsDir},v=f,y=i;await Es(u,e),$s(e,v),y=await xe(()=>zt(y,e,u,v),y,(L)=>{D.log(L,{filePath:u,phase:"pre-processing-middleware"},"warning"),console.warn(`[stx] pre-processing middleware failed for ${u}: ${L.message}`)}),y=y.replace(/\{\{--[\s\S]*?--\}\}/g,"");let S=de(y,Ie,(L,j)=>`\x00STX_HTML_COMMENT_${j}\x00`);y=S.output;let b=S.tokens,w=(L)=>b.length===0?L:L.replace(/\x00STX_HTML_COMMENT_(\d+)\x00/g,(j,H)=>b[Number(H)]??""),T="\x00STX_ESCAPED_AT\x00",A="\x00STX_ESC_MUSTACHE_OPEN\x00",O="\x00STX_ESC_MUSTACHE_CLOSE\x00";y=y.replace(/@@/g,T),y=y.replace(/@\{\{([\s\S]*?)\}\}/g,(L,j)=>`${A}${j}${O}`),y=Jt(y),y=await an(y,u,g);let M={};y=Fr(y,M);let I={...e.__sections||{}},P="",N=mt(gt(i)),F=/@nolayout\b/.test(y)||N===!1;if(/@nolayout\b/.test(y))y=y.replace(/@nolayout\b\s*/g,"");let z=y.match(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/);if(z)P=z[1],y=y.replace(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/g,"");else if(typeof N==="string"){if(P=N,!/@section\s*\(/.test(y))y=`@section('content')
|
|
1570
|
+
${y.trim()}
|
|
1571
|
+
@endsection`}if(!P&&!F&&v.defaultLayout){let L=vn(y),j=/@section\s*\(/.test(y);if(!L||j){let H="",W=ce.dirname(u),X=v.layoutsDir?ce.dirname(v.layoutsDir):process.cwd();for(let Q=0;Q<20;Q++){let ee=ce.join(W,"_layout.stx");if(await n(ee)){H=ee;break}let te=ce.dirname(W);if(te===W||te.length<X.length)break;W=te}if(H)P=H;else if(v.layoutsDir){let Q=ce.isAbsolute(v.layoutsDir)?v.layoutsDir:ce.resolve(process.cwd(),v.layoutsDir),ee=ce.join(Q,`${v.defaultLayout}.stx`);if(await n(ee))P=ee}if(P&&!j)y=`@section('content')
|
|
1572
|
+
${y.trim()}
|
|
1573
|
+
@endsection`}}if(P&&y.includes("<script")){let L=K(y),j=L.scripts.map((H)=>mn(H,u)??H);y=cr(L.output,j)}if(y=y.replace(/@section\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/g,(L,j,H)=>(I[j]=H,"")),y=y.replace(/@section\(\s*['"]([^'"]+)['"]\s*,\s*([^)]+?)\s*\)/g,(L,j,H)=>{if(/^(['"]).*\1$/.test(H.trim()))return L;try{let W=l(H.trim(),e);if(W===void 0)return L;let Q=(e.__stx_inline_section_values??=[]).push(W)-1;return I[j]=`{{ __stx_inline_section_values[${Q}] }}`,""}catch{return L}}),y=y.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@endsection|@show)/g,(L,j,H)=>{if(H.includes("@parent"))I[j]=H.replace("@parent",Te);else I[j]=H.trim();return""}),e.__sections=I,y=y.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"](?:,\s*['"]([^'"]+)['"])?\)/g,(L,j,H)=>I[j]||H||""),!("slot"in e)||e.slot===void 0)y=y.replace(/\{\{\s*slot\s*\}\}/g,()=>I.content||"");if(y=zr(y,M),P){let L=[],j=K(y),H=de(j.output,cn,(W,X)=>`\x00STX_ORPHAN_STYLE_${X}\x00`);if(y=H.output.replace(/\x00STX_(SCRIPT|ORPHAN_STYLE)_(\d+)\x00/g,(W,X,Q)=>{let ee=X==="SCRIPT"?mn(j.scripts[Number(Q)],u):H.tokens[Number(Q)];if(ee)L.push(ee);return""}),L.length>0){let W=L.join(`
|
|
1574
|
+
`);I.content=I.content?`${I.content}
|
|
1575
|
+
${W}`:W,e.__sections=I}}if(P)try{let L;if(ce.isAbsolute(P))L=P,g.add(P);else L=await xe(()=>gn(P,u,f,g),null,()=>{throw new ie(`Failed to resolve layout path: ${P}`,u,void 0,void 0,`Layout referenced from ${u}`)});if(!L){let ee=(oe)=>{if(!oe)return[];try{let ae=ce.isAbsolute(oe)?oe:ce.resolve(process.cwd(),oe);return gs.readdirSync(ae).filter((le)=>le.endsWith(".stx")).map((le)=>le.replace(/\.stx$/,""))}catch{return[]}},te=[...ee(f.layoutsDir),...ee(f.fallbackLayoutsDir)].filter((oe,ae,le)=>le.indexOf(oe)===ae).sort(),ue=`Layout not found: ${P} (referenced from ${u})`+(te.length>0?`. Available layouts: ${te.join(", ")}`:f.layoutsDir?`. No .stx layouts found in ${f.layoutsDir}`:"");if(D.log(Error(ue),{layoutPath:P,filePath:u,available:te},"error"),console.error(`[stx] ${ue}`),f.debug)throw new ie(ue,u);return y}let j=await xe(()=>Bun.file(L).text(),"",()=>{throw new ie(`Failed to read layout file: ${L}`,u,void 0,void 0,"Layout content could not be loaded")});j=un(j,L);let H=j.match(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/);if(H){if(f.debug)console.log(`Found nested layout: ${H[1]} in ${L}`);let ee={},te=j.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(ae,le,be)=>(ee[le]=be.trim(),""));for(let[ae,le]of Object.entries(ee))if(I[ae]&&I[ae].includes(Te)){let be=I[ae].indexOf(Te);I[ae]=I[ae].slice(0,be)+le+I[ae].slice(be+Te.length)}else if(!I[ae])I[ae]=le;let ue={...e,__sections:I},oe=`@layout('${H[1]}')${te}`;return await o(oe,ue,L,f,g)}let W=j.replace(/\{\{--[\s\S]*?--\}\}/g,""),X=Fr(W,M),Q={};return X=X.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(ee,te,ue)=>(Q[te]=ue.trim(),`@slot('${te}')`)),X=X.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(ee,te,ue)=>{if(I[te]){let oe=I[te];if(oe.includes(Te)){let ae=Q[te]||"",le=oe.indexOf(Te);oe=oe.slice(0,le)+ae+oe.slice(le+Te.length)}return oe}return ue||""}),X=Ss(X,I),X=X.replace(/\{\{\s*slot\s*\}\}/g,()=>I.content||""),X=zr(X,M),e.__originalFilePath=u,y=await kn(X,e,L,f,g),y=`<!-- stx-layout: ${P} -->
|
|
1576
|
+
${y}`,w(y)}catch(L){if(L instanceof U)throw L;throw new ie(`Error processing layout ${P}: ${L instanceof Error?L.message:String(L)}`,u)}return w(await kn(y,e,u,f,g))}function Ss(i,e){return i.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(u,c,g)=>{let r=e[c];if(r!==void 0){if(!new RegExp(`@(?:yield|slot)\\(\\s*['"]${c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}['"]`).test(r))return r}return g||""})}function $s(i,e){if(i.__stx_sfc_mode=!0,i.__stx_options=e,e.buildMode)i.__stx_buildMode=e.buildMode;let u=e.envPrefix||"STX_PUBLIC_",c={};for(let[g,r]of Object.entries(process.env))if(g.startsWith(u)&&r!==void 0)c[g]=r;i.$env=c}async function Es(i,e){await xe(()=>Kt(i,e),void 0,(u)=>{D.log(u,{filePath:i,phase:"view-composer"},"warning"),console.warn(`[stx] view composer failed for ${i}: ${u.message}`)})}var ot="data-stx-source";function mn(i,e){if(!i)return i;let u=/^<script\b([^>]*)>/i.exec(i);if(!u||!/\bserver\b/.test(u[1])||u[1].includes(ot))return i;return`<script ${ot}="${encodeURIComponent(e)}"${i.slice(7)}`}function _s(i){let e=new RegExp(`${ot}="([^"]*)"`).exec(i);return e?decodeURIComponent(e[1]):void 0}function yn(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function xn(i,e,u){return`<div data-stx-server-script-error role="alert" style="padding:12px 14px;border:1px solid #f0b4b4;border-left-width:4px;background:#fff5f5;color:#7a1f1f;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace"><strong style="display:block;margin-bottom:4px">stx: a <script server> ${e==="module-resolution"?"imports a module that does not resolve":e==="syntax"?"does not parse":"names something that does not exist"}, so this component rendered nothing.</strong><span style="display:block;opacity:.85">${yn(i)}</span><span style="display:block;margin-top:4px">${yn(u)}</span></div>`}async function Ts(i,e,u,c){let{scanScriptTags:g}=await s("stx/signal-processing",()=>import("./chunk-ev1tnd36.js")),r=[],f=!C()&&!wn();for(let y of g(i)){let S=y.attrs;if(!/\bserver\b/.test(S))continue;let b=y.start+y.fullMatch.indexOf(">")+1,w=Sn(i,b);if(w===-1)continue;let T=i.slice(b,w);if(!T.trim())continue;let A=_s(S)??u,O={index:y.start,length:w+9-y.start};try{let{extractVariables:M}=await s("stx/variable-extractor",()=>import("./chunk-8nk56cs2.js"));await M(T,e,A,{preserveExisting:!0,onFailure:(I)=>{if(I.kind==="unknown")return;if(c?.onServerScriptError?.({sourcePath:A,kind:I.kind,message:I.message}),!f)return;r.push({...O,markup:xn(A,I.kind,I.message)})}})}catch(M){let I=M instanceof Error?M:Error(String(M));if(D.log(I,{filePath:A,phase:"server-script-extraction"},"warning"),console.warn(`[stx] server <script> extraction failed in ${A}: ${I.message}`),f)r.push({...O,markup:xn(A,"unknown",I.message)})}}if(r.length===0)return i;let v=i;for(let y of r.sort((S,b)=>b.index-S.index))v=v.slice(0,y.index)+y.markup+v.slice(y.index+y.length);return v}async function Cs(i,e,u){try{let{interpolateScriptsInTemplate:c}=await s("stx/expressions",()=>import("./chunk-4m5g3f2b.js"));return c(i,e,{skipServer:!0})}catch(c){let g=c instanceof Error?c:Error(String(c));return D.log(g,{filePath:u,phase:"script-expression-interpolation"},"warning"),console.warn(`[stx] script expression interpolation failed in ${u}: ${g.message}`),i}}async function kn(i,e,u,c,g){let r=i,f=c;if(r=await Ts(r,e,u,c),r=await Bt(r,e,u),r=await Ft(r,e,u),r=await Cs(r,e,u),r=await At(r,e,u,f),we(r))r=po(r,e),r=qr(r,e),r=Wr(r,e);r=fo(r);let{processStreamDirectives:v}=await s("stx/streaming",()=>import("./chunk-9qx6ansy.js"));r=v(r,e),r=Kn(r,e,u,f,!0),r=await en(r,e,u,f,g),r=await Vr(r,e,u,f,g),r=ga(r,e,u,f);let{processDeferDirectives:y}=await s("stx/defer",()=>import("./chunk-c9jnkbdb.js"));r=y(r,e,u);let{processTeleportDirectives:S}=await s("stx/teleport",()=>import("./chunk-kerxevf9.js"));r=S(r,e,u);let{processTransitionDirectives:b,processTransitionAttributes:w}=await s("stx/transitions",()=>import("./chunk-sqvdrk81.js"));r=b(r,e,u),r=w(r);let{processErrorBoundaryDirectives:T,stripRenderFailedMarkers:A}=await s("stx/error-boundaries",()=>import("./chunk-h85hrwkq.js"));r=T(r,e,u),r=A(r);let{processSuspenseDirectives:O}=await s("stx/suspense",()=>import("./chunk-8j0zcyd7.js"));r=O(r,e,u);let{processAsyncDirectives:M}=await s("stx/async-components",()=>import("./chunk-sncp7jhv.js"));r=M(r,e,u);let{processKeepAliveDirectives:I}=await s("stx/keep-alive",()=>import("./chunk-myc60z74.js"));r=I(r,e,u);let{processVirtualListDirectives:P,processVirtualGridDirectives:N,processInfiniteListDirectives:F}=await s("stx/virtual-scrolling",()=>import("./chunk-8bwa63m3.js"));r=P(r,e,u),r=N(r,e,u),r=F(r,e,u);let{processPartialHydrationDirectives:z,processStaticDirectives:L}=await s("stx/partial-hydration",()=>import("./chunk-7jxj6cv1.js"));r=z(r,e,u),r=L(r);let{processComputedDirectives:j,processWatchDirectives:H}=await s("stx/computed",()=>import("./chunk-1xdzcy9d.js"));r=j(r,e,u),r=H(r,e,u);let{processFormValidationDirectives:W}=await s("stx/forms-validation",()=>import("./chunk-96hkch4q.js"));r=W(r,e,u);let{processHeadDirective:X,processTitleDirective:Q,processMetaDirective:ee,resetHead:te}=await s("stx/head",()=>import("./chunk-xjx1xbey.js"));if(!e.__stx_head_preset&&!e.__stx_runtime_head)te();let ue=X(r);if(r=ue.content,ue.headContent)e.__stx_head_raw=`${e.__stx_head_raw||""}${ue.headContent}
|
|
1577
|
+
`;if(r=Q(r,e),r=ee(r,e,u),r=Xt(r),r=ao(r,e),r=Ct(r),r=Ut(r),r=await Br(r,e,u,f,g),r=await Vr(r,e,u,f,g),e.__stxProcessingDepth===1)r=qa(r,e);if(r=r.replace(/@push\s*\(\s*['"][^'"]+['"]\s*\)[\s\S]*?@endpush/g,""),r=Do(r),r=re(r,e,u),r=jr(r),r=za(r,e,{filePath:u,buildMode:f.buildMode}),r=co(r,e),r=lo(r,e),r=ze(r,e),r=jt(r,e),r=Ht(r,e),r=await bt(r,e,u,f),r=await ha(r,e,u),r=await ya(r,e,u,f),r=ba(r,e,u,f),r=wo(r,e,u,f),r=xo(r,e,u),r=So(r,e,u,f),r=Et(r,e,u,f),r=ys(r,e),r=bs(r),r=Ha(r),!f.skipEventDirectives)r=Aa(r,e,u);if(r=vt(r,e,u),f.debug){let B=/\bx-data\s*=/.test(r),q=Ur(i);if(B&&q)console.warn(`[stx] ${u}: Template mixes Alpine-style (x-data) and signals (state/derived/effect) reactivity.
|
|
1578
|
+
Both work on the same page, but they manage separate scopes.
|
|
1579
|
+
Prefer signals (state/derived/effect) for new components.`)}r=la(r,e),r=await x(r,e,u),r=Va(r),r=Ua(r),r=pt(r);let{processXElementDirectives:oe}=await s("stx/x-element",()=>import("./chunk-zhxdpzga.js"));r=oe(r);let ae=e.__originalFilePath||u,le=Ne(e);if(r=await go(r,f,ae,le),r=It(r,e),r=await Wt(r,e,u,f),f.media?.image?.autoSiblings){let B=f.publicDir||"public",{rewriteImagesWithSiblings:q}=await s("stx/image-optimization/auto-sibling",()=>import("./chunk-01ks1244.js"));r=await q(r,{publicDir:B})}if(f.seo?.enabled)r=ko(r,e,f);let be=(B,q,J=!0)=>{if(!q)return B;let me=q.match(/<title\b[^>]*>[\s\S]*?<\/title>/i),ne=/<head\b[^>]*>[\s\S]*?(?:<\/head\s*>|<body\b|$)/i.exec(B),fe=ne?/<title\b[^>]*>[\s\S]*?<\/title>/i.exec(ne[0]):null;if(me&&ne&&fe){if(J){let Ce=ne.index+fe.index;B=B.slice(0,Ce)+me[0]+B.slice(Ce+fe[0].length)}if(q=q.replace(me[0],"").trim(),!q)return B}if(/<\/head>/i.test(B))return B.replace(/<\/head>/i,`${q}
|
|
1580
|
+
</head>`);if(/<head\b[^>]*>/i.test(B))return B.replace(/(<head\b[^>]*>)/i,`$1
|
|
1581
|
+
${q}`);if(/<html\b[^>]*>/i.test(B))return B.replace(/(<html\b[^>]*>)/i,`$1
|
|
1582
|
+
<head>
|
|
1583
|
+
${q}
|
|
1584
|
+
</head>`);return B},{renderHead:En,getHead:_n}=await s("stx/head",()=>import("./chunk-xjx1xbey.js")),Oe=e.__stx_runtime_head??_n();if(Oe.title||Oe.meta?.length||Oe.link?.length){let B=En(Oe);if(B)r=be(r,B)}if(ue.headContent)r=be(r,ue.headContent,!Oe.title);if(f.csp?.enabled&&f.csp.addMetaTag)r=St(r,f.csp,e);if(f.analytics?.enabled)r=ft(r,f);if(f.heatmap?.enabled)r=ma(r,f);if(f.pwa?.enabled&&f.pwa.autoInject!==!1){let{injectPwaTags:B}=await s("stx/pwa/inject",()=>import("./chunk-8y7tpjfs.js"));r=B(r,f)}let Tn=/<script\b(?![^>]*\bserver\b)[^>]*>[\s\S]*?<\/script>/i.test(r),Cn=/\bSTX\.\w+/.test(r),An=/window\.STX\s*=/.test(r);if(Tn&&Cn&&!An){let q=`<script data-stx-scoped data-stx-run="once">
|
|
1585
|
+
${lt()}
|
|
1586
|
+
</script>`;if(r.includes("</head>")){let J=r.indexOf("</head>"),ne=r.slice(0,J).indexOf("<script");if(ne!==-1){let fe=r.slice(0,ne),Ce=r.slice(ne);r=fe+q+`
|
|
1587
|
+
`+Ce}else r=r.replace("</head>",`${q}
|
|
1588
|
+
</head>`)}else if(r.includes("<body"))r=r.replace(/<body([^>]*)>/,`<body$1>
|
|
1589
|
+
${q}`);else r=q+`
|
|
1590
|
+
`+r}{let{scanScriptTags:B}=await s("stx/signal-processing",()=>import("./chunk-ev1tnd36.js")),q=[];for(let J of B(r)){if(!/\bserver\b/i.test(J.attrs))continue;let me=J.start+J.fullMatch.indexOf(">")+1,ne=Sn(r,me);if(ne===-1)continue;let fe=ne+9;while(fe<r.length&&/\s/.test(r[fe]))fe++;q.push({start:J.start,end:fe})}if(q.length>0){let J=Array(q.length+1),me=0;for(let ne=0;ne<q.length;ne++){let{start:fe,end:Ce}=q[ne];J[ne]=r.slice(me,fe),me=Ce}J[q.length]=r.slice(me),r=J.join("")}}let at=ms(r,u);if(at.hasScoped)r=at.html;let Rn=e.__stx_event_bindings||[],Xe=!1,ct=[],Mn=/\s:[a-z][\w.-]*\s*=/.test(r),{scanScriptTags:Dn}=await s("stx/signal-processing",()=>import("./chunk-ev1tnd36.js"));for(let B of Dn(r,{skipAttrs:/\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b|\btype\s*=\s*["'](?!(?:text\/javascript|application\/javascript|module)["'])[^"']*["']/}))ct.push({match:B.fullMatch,attrs:B.attrs,content:B.body});for(let{match:B,attrs:q,content:J}of ct){Xe=!0;let me=J;Pe(J,u,c.strict,e.__originalFilePath);let ne=await De(J,{eventBindings:Rn,attrs:q,hasColonDirectives:Mn,templateContent:i,filePath:u,projectRoot:process.cwd(),production:Yo(c.buildMode),serverData:le});r=r.replace(B,()=>ne)}if(Xe)e.__stx_event_bindings=[];if(!Xe&&e.__stxProcessingDepth===1){let B=e.__stx_event_bindings||[];if(B.length>0){let q=Ro(B);if(q){let J=r.lastIndexOf("</body>");r=J===-1?r+q:r.slice(0,J)+q+`
|
|
1591
|
+
`+r.slice(J)}e.__stx_event_bindings=[]}}if(!he(r)&&da(r))r=await Yn(r,f);if(r=pa(r),f.csp?.enabled&&f.csp.useNonce&&typeof e.cspNonce==="string")r=$t(r,e.cspNonce);return r}
|
|
1592
|
+
export{gt,$e,oa,Lr,to,no,Un,o};
|