@stacksjs/stx 0.2.474 → 0.2.476
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-s545g4mf.js → chunk-08pfhmk0.js} +1 -1
- package/dist/chunk-0bfkjrq9.js +2 -0
- package/dist/{chunk-jkeyh3tk.js → chunk-0vcqc3d4.js} +1 -1
- package/dist/{chunk-vrs86fxc.js → chunk-23bgy025.js} +1 -1
- package/dist/{chunk-xweh2gem.js → chunk-26mz7hyg.js} +1 -1
- package/dist/{chunk-y4nk5b2h.js → chunk-26zad6kf.js} +1 -1
- package/dist/{chunk-grzm54tq.js → chunk-2pfevhmz.js} +2 -2
- package/dist/{chunk-bbx35ba3.js → chunk-2z3fsgnm.js} +1 -1
- package/dist/{chunk-jce36k67.js → chunk-3dtz8pws.js} +1 -1
- package/dist/{chunk-qkps282f.js → chunk-494t857g.js} +1 -1
- package/dist/{chunk-mm82qk7b.js → chunk-4y62shxz.js} +1 -1
- package/dist/{chunk-7tw5m0y7.js → chunk-5c6ta229.js} +1 -1
- package/dist/{chunk-h5wbt9kn.js → chunk-5fn2wczm.js} +1 -1
- package/dist/{chunk-0s3kjdqz.js → chunk-6bf687m6.js} +1 -1
- package/dist/{chunk-jcddb0cg.js → chunk-6kdjjv3h.js} +1 -1
- package/dist/{chunk-sqat6rbj.js → chunk-7f658pm7.js} +1 -1
- package/dist/chunk-9sxwhb26.js +2847 -0
- package/dist/{chunk-0tv7srqw.js → chunk-c31z877d.js} +1 -1
- package/dist/{chunk-mwr2mfy0.js → chunk-c5dcyb9y.js} +1 -1
- package/dist/{chunk-8wfs6753.js → chunk-ckb8935d.js} +1 -1
- package/dist/{chunk-5jxxfs61.js → chunk-em70a2vz.js} +1 -1
- package/dist/{chunk-1h3xv51f.js → chunk-fq2vjk8t.js} +1 -1
- package/dist/{chunk-kq81b4g2.js → chunk-fqzjt6n4.js} +1 -1
- package/dist/{chunk-62vwxyvr.js → chunk-gmcj4av9.js} +1 -1
- package/dist/{chunk-2sq74c7t.js → chunk-j7ae2ah3.js} +1 -1
- package/dist/{chunk-1385gt0h.js → chunk-mde796zf.js} +1 -1
- package/dist/chunk-n16e5fmq.js +2 -0
- package/dist/{chunk-4dn8fjv6.js → chunk-nqfb33rv.js} +1 -1
- package/dist/{chunk-yr17q3z0.js → chunk-p6av17y4.js} +1 -1
- package/dist/{chunk-x99t4atr.js → chunk-pgnqzjbv.js} +1 -1
- package/dist/chunk-q1hx1th8.js +2 -0
- package/dist/{chunk-v81y568k.js → chunk-qewjmma1.js} +1 -1
- package/dist/{chunk-99j03b1k.js → chunk-qy4qp8w1.js} +1 -1
- package/dist/{chunk-zs131awg.js → chunk-rh6k1daj.js} +2 -2
- package/dist/{chunk-31rx2tgv.js → chunk-rqy8p8e1.js} +1 -1
- package/dist/{chunk-2e0bgme3.js → chunk-s94n9tr6.js} +1 -1
- package/dist/{chunk-xgw58rzk.js → chunk-tdv7h1tq.js} +1 -1
- package/dist/{chunk-ebxkd6t4.js → chunk-txkgkyf4.js} +14 -14
- package/dist/{chunk-2j105ssm.js → chunk-v5pg1jgb.js} +1 -1
- package/dist/{chunk-fwxc574x.js → chunk-vmp6yf2v.js} +1 -1
- package/dist/{chunk-46zk1sva.js → chunk-vrsnkj84.js} +1 -1
- package/dist/{chunk-k4yv8d99.js → chunk-vt3f3hm2.js} +1 -1
- package/dist/{chunk-dhd4fy4d.js → chunk-vxb1x36c.js} +1 -1
- package/dist/{chunk-2cjz23ed.js → chunk-wg3ag5e3.js} +1 -1
- package/dist/{chunk-qm9hwar4.js → chunk-y0m9zz0x.js} +1 -1
- package/dist/{chunk-06h5b4ae.js → chunk-yhjn4kej.js} +1 -1
- package/dist/{chunk-9j5xghg9.js → chunk-yqdt6sxq.js} +2 -2
- package/dist/{chunk-vvqxq8s1.js → chunk-z4w57s7r.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/component-renderer.js +42 -6
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/expressions.js +7 -4
- package/dist/loop-binding.d.ts +39 -0
- package/dist/loop-binding.js +131 -0
- package/dist/pwa.js +1 -1
- package/dist/server-bindings.d.ts +11 -0
- package/dist/server-bindings.js +12 -5
- package/dist/ssg.js +2 -2
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +9 -3
- package/package.json +5 -5
- package/dist/chunk-910yr22j.js +0 -2847
- package/dist/chunk-bepnzs0v.js +0 -2
- package/dist/chunk-mxb3pcjk.js +0 -2
- package/dist/chunk-mz1mrxeg.js +0 -2
package/dist/loop-binding.js
CHANGED
|
@@ -10,3 +10,134 @@ export function parseLoopBinding(params) {
|
|
|
10
10
|
const itemVar = inMatch[1].trim().replace(/^\(([\s\S]*)\)$/, "$1").trim(), arrayExpr = inMatch[2].trim();
|
|
11
11
|
return itemVar && arrayExpr ? { arrayExpr, itemVar } : null;
|
|
12
12
|
}
|
|
13
|
+
function splitTopLevel(source) {
|
|
14
|
+
const parts = [];
|
|
15
|
+
let depth = 0, quote = "", start = 0;
|
|
16
|
+
for (let i = 0;i < source.length; i++) {
|
|
17
|
+
const ch = source[i];
|
|
18
|
+
if (quote) {
|
|
19
|
+
if (ch === "\\")
|
|
20
|
+
i++;
|
|
21
|
+
else if (ch === quote)
|
|
22
|
+
quote = "";
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (ch === "'" || ch === '"' || ch === "`")
|
|
26
|
+
quote = ch;
|
|
27
|
+
else if (ch === "(" || ch === "[" || ch === "{")
|
|
28
|
+
depth++;
|
|
29
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
30
|
+
depth--;
|
|
31
|
+
else if (ch === "," && depth === 0) {
|
|
32
|
+
parts.push(source.slice(start, i));
|
|
33
|
+
start = i + 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
parts.push(source.slice(start));
|
|
37
|
+
return parts;
|
|
38
|
+
}
|
|
39
|
+
function topLevelIndexOf(source, char) {
|
|
40
|
+
let depth = 0;
|
|
41
|
+
for (let i = 0;i < source.length; i++) {
|
|
42
|
+
const ch = source[i];
|
|
43
|
+
if (ch === "(" || ch === "[" || ch === "{")
|
|
44
|
+
depth++;
|
|
45
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
46
|
+
depth--;
|
|
47
|
+
else if (ch === char && depth === 0)
|
|
48
|
+
return i;
|
|
49
|
+
}
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
52
|
+
function closingParen(source) {
|
|
53
|
+
let depth = 0;
|
|
54
|
+
for (let i = 0;i < source.length; i++) {
|
|
55
|
+
const ch = source[i];
|
|
56
|
+
if (ch === "(" || ch === "[" || ch === "{")
|
|
57
|
+
depth++;
|
|
58
|
+
else if ((ch === ")" || ch === "]" || ch === "}") && --depth === 0)
|
|
59
|
+
return i;
|
|
60
|
+
}
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
function patternNames(pattern, out) {
|
|
64
|
+
let target = pattern.trim().replace(/^\.\.\./, "").trim();
|
|
65
|
+
const assign = topLevelIndexOf(target, "=");
|
|
66
|
+
if (assign !== -1 && target[assign + 1] !== ">")
|
|
67
|
+
target = target.slice(0, assign).trim();
|
|
68
|
+
if (!target)
|
|
69
|
+
return;
|
|
70
|
+
if (target.startsWith("{") && target.endsWith("}")) {
|
|
71
|
+
for (const property of splitTopLevel(target.slice(1, -1))) {
|
|
72
|
+
const element = property.trim();
|
|
73
|
+
if (!element)
|
|
74
|
+
continue;
|
|
75
|
+
if (element.startsWith("...")) {
|
|
76
|
+
patternNames(element, out);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const colon = topLevelIndexOf(element, ":");
|
|
80
|
+
patternNames(colon === -1 ? element : element.slice(colon + 1), out);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (target.startsWith("[") && target.endsWith("]")) {
|
|
85
|
+
for (const element of splitTopLevel(target.slice(1, -1)))
|
|
86
|
+
patternNames(element, out);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (/^[A-Z_$][\w$]*$/i.test(target))
|
|
90
|
+
out.push(target);
|
|
91
|
+
}
|
|
92
|
+
export function loopBoundNames(expression) {
|
|
93
|
+
const trimmed = expression.trim(), names = [];
|
|
94
|
+
let depth = 0;
|
|
95
|
+
for (let i = 0;i < trimmed.length; i++) {
|
|
96
|
+
const ch = trimmed[i];
|
|
97
|
+
if (ch === "(" || ch === "[" || ch === "{")
|
|
98
|
+
depth++;
|
|
99
|
+
else if (ch === ")" || ch === "]" || ch === "}")
|
|
100
|
+
depth--;
|
|
101
|
+
else if (depth === 0 && /\s/.test(ch)) {
|
|
102
|
+
if (!/^\s+(?:in|of)\s/.exec(trimmed.slice(i)))
|
|
103
|
+
continue;
|
|
104
|
+
let head = trimmed.slice(0, i).trim();
|
|
105
|
+
if (head.startsWith("(") && closingParen(head) === head.length - 1)
|
|
106
|
+
head = head.slice(1, -1);
|
|
107
|
+
for (const pattern of splitTopLevel(head))
|
|
108
|
+
patternNames(pattern, names);
|
|
109
|
+
if (names.length > 0)
|
|
110
|
+
return names;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const asMatch = /^[\s\S]+?\s+as\s+([\s\S]+)$/.exec(trimmed);
|
|
115
|
+
if (asMatch) {
|
|
116
|
+
let spec = asMatch[1].trim();
|
|
117
|
+
if (spec.startsWith("(") && closingParen(spec) === spec.length - 1)
|
|
118
|
+
spec = spec.slice(1, -1);
|
|
119
|
+
const arrow = /^([\w$]+)\s*=>\s*([\s\S]+)$/.exec(spec);
|
|
120
|
+
if (arrow) {
|
|
121
|
+
patternNames(arrow[2], names);
|
|
122
|
+
patternNames(arrow[1], names);
|
|
123
|
+
} else
|
|
124
|
+
for (const pattern of splitTopLevel(spec))
|
|
125
|
+
patternNames(pattern, names);
|
|
126
|
+
}
|
|
127
|
+
return names;
|
|
128
|
+
}
|
|
129
|
+
export function readsAnyName(expression, names) {
|
|
130
|
+
const wanted = names instanceof Set ? names : new Set(names);
|
|
131
|
+
if (wanted.size === 0)
|
|
132
|
+
return !1;
|
|
133
|
+
const withoutKeys = expression.replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, " ").replace(/`(?:[^`\\$]|\\.|\$(?!\{))*`/g, " ").replace(/\??\.\s*[a-zA-Z_$][\w$]*/g, " ").replace(/([{,]\s*)[a-zA-Z_$][\w$]*(\s*:(?!:))/g, "$1$2");
|
|
134
|
+
for (const identifier of withoutKeys.match(/[a-zA-Z_$][\w$]*/g) || [])
|
|
135
|
+
if (wanted.has(identifier))
|
|
136
|
+
return !0;
|
|
137
|
+
return !1;
|
|
138
|
+
}
|
|
139
|
+
export const CLIENT_LOOP_NAMES_KEY = "__stx_client_loop_names";
|
|
140
|
+
export function inheritedClientLoopNames(context) {
|
|
141
|
+
const names = context?.[CLIENT_LOOP_NAMES_KEY];
|
|
142
|
+
return Array.isArray(names) ? names : [];
|
|
143
|
+
}
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import{In,De,Mo,Na}from"./chunk-33h9ggbz.js";import{Pn,zr,Da,Oa,Ma}from"./chunk-33gkx5z1.js";import{Io,Do,Oo,Pa,Ia}from"./chunk-04qmr675.js";import{oe,ft,Hr}from"./chunk-kp5tv8jx.js";import{Bc,Fc,zc,Hc,dr,id}from"./chunk-27kb6nrb.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-vt3f3hm2.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -30,6 +30,17 @@
|
|
|
30
30
|
* must remain intact until each row is cloned in the browser.
|
|
31
31
|
*/
|
|
32
32
|
export declare function reactiveLoopRanges(template: string): Array<[number, number]>;
|
|
33
|
+
/**
|
|
34
|
+
* The same regions, each with the names its loop binds.
|
|
35
|
+
*
|
|
36
|
+
* A component tag inside one of these renders its slot in a separate pass,
|
|
37
|
+
* which needs the names to keep treating them as the loop's.
|
|
38
|
+
*/
|
|
39
|
+
export declare function reactiveLoopScopes(template: string): Array<{
|
|
40
|
+
start: number;
|
|
41
|
+
end: number;
|
|
42
|
+
names: string[];
|
|
43
|
+
}>;
|
|
33
44
|
/**
|
|
34
45
|
* Process server-side `:attr="expr"` bindings in a template.
|
|
35
46
|
*
|
package/dist/server-bindings.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inheritedClientLoopNames, loopBoundNames, readsAnyName } from "./loop-binding.js";
|
|
1
2
|
import { isRuntimeOwnedColonAttr } from "./runtime-globals.js";
|
|
2
3
|
const BOOLEAN_ATTRS = new Set([
|
|
3
4
|
"disabled",
|
|
@@ -38,15 +39,18 @@ const BOOLEAN_ATTRS = new Set([
|
|
|
38
39
|
"wbr"
|
|
39
40
|
]);
|
|
40
41
|
export function reactiveLoopRanges(template) {
|
|
42
|
+
return reactiveLoopScopes(template).map((scope) => [scope.start, scope.end]);
|
|
43
|
+
}
|
|
44
|
+
export function reactiveLoopScopes(template) {
|
|
41
45
|
const ranges = [], openingTag = /<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g;
|
|
42
46
|
let match;
|
|
43
47
|
while ((match = openingTag.exec(template)) !== null) {
|
|
44
|
-
const attributes = match[2] || "";
|
|
45
|
-
if (
|
|
48
|
+
const attributes = match[2] || "", loopAttr = /(?:^|\s)(?::for|x-for|v-for|@for)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/.exec(attributes);
|
|
49
|
+
if (!loopAttr)
|
|
46
50
|
continue;
|
|
47
|
-
const start = match.index, openingEnd = start + match[0].length, tagName = match[1].toLowerCase();
|
|
51
|
+
const names = loopBoundNames(loopAttr[1] ?? loopAttr[2] ?? loopAttr[3] ?? ""), start = match.index, openingEnd = start + match[0].length, tagName = match[1].toLowerCase();
|
|
48
52
|
if (match[0].endsWith("/>") || VOID_TAGS.has(tagName)) {
|
|
49
|
-
ranges.push(
|
|
53
|
+
ranges.push({ start, end: openingEnd, names });
|
|
50
54
|
continue;
|
|
51
55
|
}
|
|
52
56
|
const escapedTag = tagName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), sameTag = new RegExp(`<\\/?${escapedTag}\\b(?:[^>"']|"[^"]*"|'[^']*')*>`, "gi");
|
|
@@ -61,7 +65,7 @@ export function reactiveLoopRanges(template) {
|
|
|
61
65
|
}
|
|
62
66
|
} else if (!nested[0].endsWith("/>"))
|
|
63
67
|
depth++;
|
|
64
|
-
ranges.push(
|
|
68
|
+
ranges.push({ start, end: closingEnd, names });
|
|
65
69
|
}
|
|
66
70
|
return ranges;
|
|
67
71
|
}
|
|
@@ -83,6 +87,7 @@ export function processServerBindings(template, context) {
|
|
|
83
87
|
while ((match = scriptStyleRegex.exec(template)) !== null)
|
|
84
88
|
protectedRanges.push([match.index, match.index + match[0].length]);
|
|
85
89
|
protectedRanges.push(...reactiveLoopRanges(template));
|
|
90
|
+
const enclosingLoopNames = new Set(inheritedClientLoopNames(context));
|
|
86
91
|
function isProtected(pos) {
|
|
87
92
|
return protectedRanges.some(([start, end]) => pos >= start && pos < end);
|
|
88
93
|
}
|
|
@@ -99,6 +104,8 @@ export function processServerBindings(template, context) {
|
|
|
99
104
|
const attrName = attrMatch[1], expression = attrMatch[2];
|
|
100
105
|
if (isRuntimeOwnedColonAttr(attrName))
|
|
101
106
|
continue;
|
|
107
|
+
if (readsAnyName(expression, enclosingLoopNames))
|
|
108
|
+
continue;
|
|
102
109
|
if (expression.includes("()") && !expression.includes(".get(") || expression.includes("$store") || expression.includes("$ref"))
|
|
103
110
|
continue;
|
|
104
111
|
try {
|
package/dist/ssg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-8scw1bes.js";import"./chunk-ab7vh24b.js";import"./chunk-wkc34drs.js";import{Qe,et,tt,nt,rt,st}from"./chunk-9ztdvnkk.js";import"./chunk-01nx6zcw.js";import"./chunk-pf0d8y9n.js";import{f,je,N,K,n,o}from"./chunk-
|
|
2
|
+
import"./chunk-8scw1bes.js";import"./chunk-ab7vh24b.js";import"./chunk-wkc34drs.js";import{Qe,et,tt,nt,rt,st}from"./chunk-9ztdvnkk.js";import"./chunk-01nx6zcw.js";import"./chunk-pf0d8y9n.js";import{f,je,N,K,n,o}from"./chunk-9sxwhb26.js";import"./chunk-tbef3yyk.js";import{er}from"./chunk-s10r6hxp.js";import"./chunk-99kt56fn.js";import"./chunk-tdv7h1tq.js";import"./chunk-pcq6vphz.js";import"./chunk-j4afmryj.js";import"./chunk-26mz7hyg.js";import{ie,gt,mt}from"./chunk-nqfb33rv.js";import{Ro,Ao,Po}from"./chunk-2gmbxp60.js";import{pt,Gt,Jt}from"./chunk-5pjsc9zv.js";import"./chunk-8adstrk5.js";import{a}from"./chunk-kk5cyjfs.js";import x from"fs";import g from"path";import{createHash as $t}from"crypto";function Dt(t){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(t).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return t}}var Rt=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function kt(t){return Bun.hash(t).toString(16)}function lt(t,i={}){if(!t.includes('type="stx/island"'))return{html:t,chunks:[]};let s=new Map,r=t.replace(Rt,(e,l,w,y)=>{let h=y.trim();if(!h)return e;if(/\bdata-stx-src=/.test(w))return e;if(i.minify)h=Dt(h);let S=kt(h);if(!s.has(S))s.set(S,h);let P=i.integrity?` data-stx-integrity="sha384-${$t("sha384").update(h).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${l}" data-stx-src="/_stx/islands/${S}.js"${P}${w}></script>`}),c=Array.from(s,([e,l])=>({hash:e,code:l}));return{html:r,chunks:c}}var Ct=new Set(["visible","idle"]);function ut(t){if(!t.includes("data-stx-src="))return t;let i=new Map,s=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,r;while((r=s.exec(t))!==null)i.set(r[1],r[2]);let c=new Set,e=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,l;while((l=e.exec(t))!==null)if(Ct.has(i.get(l[1])||""))c.add(l[2]);let w=t.lastIndexOf("</head>");if(c.size===0||w===-1)return t;let y=Array.from(c).filter((h)=>!t.includes(`rel="prefetch" href="${h}"`)).map((h)=>`<link rel="prefetch" href="${h}" as="script">`).join("");if(!y)return t;return t.slice(0,w)+y+t.slice(w)}var Et=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function q(t){let i=t.trim();if(!i)return null;let s=/^https?:\/\//i.test(i)?i:`https://${i}`;try{return new URL(s).origin+new URL(s).pathname.replace(/\/$/,"")}catch{return null}}function It(t){for(let i of Et){let s=t[i];if(!s)continue;let r=q(s);if(r)return{url:r,source:"env",via:i}}return null}function dt(t){if(!t||typeof t!=="object")return null;let i=t,s=i.site?.url??i.url??i.app?.url;return typeof s==="string"?q(s):null}async function Bt(t){let{existsSync:i}=await import("fs"),s=await import("path");for(let r of["site.config.ts","site.config.js",".config/site.config.ts"]){let c=s.resolve(t,r);if(!i(c))continue;try{let e=await import(c),l=dt(e.default??e);if(l)return l}catch{}}return null}async function ht(t={}){let i=t.cwd??process.cwd(),s=t.env??process.env;if(t.explicit){let l=q(t.explicit);if(l)return{url:l,source:"option"}}let r=dt(t.stxConfig);if(r)return{url:r,source:"stx.config",via:"site.url"};let c=await Bt(i);if(c)return{url:c,source:"site.config",via:"url"};let e=It(s);if(e)return e;return{url:"http://localhost",source:"fallback"}}function ft(){return["No site URL configured \u2014 sitemap.xml and robots.txt will point at http://localhost."," Set one in stx.config.ts (site: { url: 'https://example.com' }), in site.config.ts,"," via --domain, or with SITE_URL in the build environment."].join(`
|
|
3
3
|
`)}class wt{cacheDir;cache=new Map;loaded=!1;salt;constructor(t,i=""){this.cacheDir=t,this.salt=i}async load(){if(this.loaded)return;let t=g.join(this.cacheDir,"build-cache.json");if(await Bun.file(t).exists())try{let i=JSON.parse(await Bun.file(t).text());for(let[s,r]of Object.entries(i))this.cache.set(s,r)}catch{}this.loaded=!0}async save(){await x.promises.mkdir(this.cacheDir,{recursive:!0});let t=g.join(this.cacheDir,"build-cache.json"),i={};for(let[s,r]of this.cache)i[s]=r;await Bun.write(t,JSON.stringify(i))}getHash(t,i){let s=x.statSync(t),r=`${this.salt}|${t}:${s.mtimeMs}`;for(let e of i)if(x.existsSync(e)){let l=x.statSync(e);r+=`:${e}:${l.mtimeMs}`}let c=0;for(let e=0;e<r.length;e++){let l=r.charCodeAt(e);c=(c<<5)-c+l,c=c&c}return Math.abs(c).toString(36)}get(t,i){let s=this.cache.get(t);if(!s)return null;let r=this.getHash(i,s.dependencies??[]);if(s.hash!==r)return this.cache.delete(t),null;return s.html}set(t,i,s,r){let c=this.getHash(i,s);this.cache.set(t,{hash:c,html:r,generatedAt:Date.now(),dependencies:s})}}class yt{cacheDir;constructor(t){this.cacheDir=t}getFilePath(t){let i=t.replace(/[^a-zA-Z0-9]/g,"_")+".json";return g.join(this.cacheDir,"isr",i)}async get(t){let i=this.getFilePath(t);if(!await Bun.file(i).exists())return null;try{return JSON.parse(await Bun.file(i).text())}catch{return null}}async set(t,i){let s=this.getFilePath(t);await x.promises.mkdir(g.dirname(s),{recursive:!0}),await Bun.write(s,JSON.stringify(i))}async invalidate(t){let i=this.getFilePath(t);if(await Bun.file(i).exists())await x.promises.unlink(i)}async invalidatePattern(t){let i=g.join(this.cacheDir,"isr");if(!x.existsSync(i))return;let s=await x.promises.readdir(i);for(let r of s){let c=r.replace(/_/g,"/").replace(".json","");if(t.test(c))await x.promises.unlink(g.join(i,r))}}async needsRevalidation(t){let i=await this.get(t);if(!i)return!0;return Date.now()>i.revalidateAfter}}async function jt(t){try{let s=(await Bun.file(t).text()).match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return null;let r=s[1];if(!r.includes("getStaticPaths"))return null;let c=r.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticPaths\s*\([^)]*\)\s*\{([\s\S]*?)\n[\t ]*\}/);if(!c)return null;return await Function(`
|
|
4
4
|
return (async function getStaticPaths() {
|
|
5
5
|
${c[1]}
|
|
@@ -41,7 +41,7 @@ ${t.map((r)=>{let c=new URL(r.loc,i).href,e=` <url>
|
|
|
41
41
|
${s.join(`
|
|
42
42
|
`)}
|
|
43
43
|
</channel>
|
|
44
|
-
</rss>`}async function zt(t={}){let i=Date.now();mt();let s=await o(process.cwd()),r=s.build||{},c=await ht({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(ft());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-
|
|
44
|
+
</rss>`}async function zt(t={}){let i=Date.now();mt();let s=await o(process.cwd()),r=s.build||{},c=await ht({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(ft());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-fqzjt6n4.js");try{D=m(await u(process.cwd()))}catch{}}let{prepareImageDelivery:p}=await import("./chunk-0vcqc3d4.js"),b=await p(e.publicDir,e.outputDir);if(b.count>0)console.log(`Optimized ${b.count} image(s) for responsive delivery`),D=[D,b.fingerprint].filter(Boolean).join(":");let B=new wt(e.cacheDir,D);if(e.cache)await B.load();try{let{generateCss:u}=await import("./chunk-fqzjt6n4.js");await u('<div class="bg-black"></div>')}catch{}Qe();let xt=s?.routeMiddleware?.dir||"middleware";await tt(process.cwd(),xt);let H=et();if(H.length>0)console.log(`Loaded ${H.length} middleware: ${H.join(", ")}`);let vt=s?.routeMiddleware?.global||[];Po(s?.layoutsDir,a(process.cwd()));let V=N(".",{pagesDir:e.pagesDir,pagesDirs:s?._layerPageDirs});console.log(`Found ${V.length} routes`);let _=[];for(let u of V){let m=await Ft(u);for(let v of m)_.push({route:u,url:v.url,params:v.params,props:v.props,revalidate:v.revalidate??e.revalidate})}l.totalPages=_.length,console.log(`Generating ${l.totalPages} pages...`);let A=[],X=[];for(let u=0;u<_.length;u+=e.concurrency)X.push(_.slice(u,u+e.concurrency));for(let u of X)await Promise.all(u.map(async(m)=>{let{route:v,url:d,params:L,props:bt,revalidate:Q}=m;try{await e.hooks.onPageStart?.(d);let j=await Bun.file(v.filePath).text(),F=Vt(j),Pt=F?.middleware?Array.isArray(F.middleware)?F.middleware:[F.middleware]:[],it=[...vt,...Pt];if(it.length>0){let C=nt(d,L,F||{}),O=rt(C,null,void 0,{isServer:!0}),E=await st(it,O);if(E.redirect){let R=typeof E.redirect==="string"?E.redirect:E.redirect.path||E.redirect,U=Kt(String(R),d),T=Xt(d,e);await x.promises.mkdir(g.dirname(T),{recursive:!0}),await Bun.write(T,U),l.successCount++,l.pages.push({route:d,outputPath:T,size:Buffer.byteLength(U),cached:!1}),A.push({loc:d,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${d} \u2192 redirect to ${R}`);return}if(E.abort){let R=typeof E.abort==="string"?E.abort:E.abort?.error?.message||"aborted";console.warn(` \u21B3 ${d} \u2014 middleware aborted: ${R}`);return}}let at=j.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(at)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${at[1]};
|
|
46
46
|
return validate(route);
|
|
47
47
|
`)({params:L})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,ot=!1;if(e.cache){if(k=B.get(d,v.filePath),k)ot=!0,l.cachedCount++}if(!k){let C=await St(v,L,bt,e,s);if(k=C.html,e.failOnIncludeError&&C.includeFailures.length>0)throw Error(`${C.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
package/dist/utils.d.ts
CHANGED
|
@@ -75,7 +75,15 @@ export declare function slotContentHasExpressions(slotContent: string): boolean;
|
|
|
75
75
|
* named `title` also exists in the server context.
|
|
76
76
|
*/
|
|
77
77
|
export declare function componentClientSignalNames(scripts: string[]): string[];
|
|
78
|
-
export declare function renderComponentWithSlot(componentPath: string, props: Record<string, unknown>, slotContent: string, componentsDir: string, parentContext: Record<string, unknown>, parentFilePath: string, options: StxOptions, processedComponents: Set<string> | undefined, dependencies: Set<string
|
|
78
|
+
export declare function renderComponentWithSlot(componentPath: string, props: Record<string, unknown>, slotContent: string, componentsDir: string, parentContext: Record<string, unknown>, parentFilePath: string, options: StxOptions, processedComponents: Set<string> | undefined, dependencies: Set<string>,
|
|
79
|
+
/**
|
|
80
|
+
* The client loop variables in scope where the tag stands: those of any
|
|
81
|
+
* `:for` around it and of a `:for` on the tag itself. The slot is the
|
|
82
|
+
* caller's markup inside that loop, but it is rendered here, away from the
|
|
83
|
+
* loop, so the names have to be handed over. Defaults to the ones the
|
|
84
|
+
* caller's context already carries.
|
|
85
|
+
*/
|
|
86
|
+
clientLoopNames?: readonly string[]): Promise<string>;
|
|
79
87
|
/**
|
|
80
88
|
* Check if a file exists
|
|
81
89
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -22,6 +22,7 @@ import { importOnce } from "./lazy-module.js";
|
|
|
22
22
|
import { scanAtElementPosition, stashScriptElements } from "./html-masking.js";
|
|
23
23
|
import { markProjectedRefs } from "./misc-directives.js";
|
|
24
24
|
import { collectBlockDeclarations } from "./stx-virtual-ts.js";
|
|
25
|
+
import { CLIENT_LOOP_NAMES_KEY, inheritedClientLoopNames } from "./loop-binding.js";
|
|
25
26
|
export {
|
|
26
27
|
extractDirectiveNames,
|
|
27
28
|
getPositionInfo,
|
|
@@ -576,7 +577,7 @@ export function componentClientSignalNames(scripts) {
|
|
|
576
577
|
}
|
|
577
578
|
return [...names];
|
|
578
579
|
}
|
|
579
|
-
export async function renderComponentWithSlot(componentPath, props, slotContent, componentsDir, parentContext, parentFilePath, options, processedComponents = new Set, dependencies) {
|
|
580
|
+
export async function renderComponentWithSlot(componentPath, props, slotContent, componentsDir, parentContext, parentFilePath, options, processedComponents = new Set, dependencies, clientLoopNames = inheritedClientLoopNames(parentContext)) {
|
|
580
581
|
const { extractVariables } = await importOnce("stx/variable-extractor", () => import("./variable-extractor.js")), components = processedComponents ?? new Set;
|
|
581
582
|
if (components.has(componentPath))
|
|
582
583
|
return `[Circular component reference: ${componentPath}]`;
|
|
@@ -746,6 +747,7 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
746
747
|
for (const [key, val] of Object.entries(parentContext))
|
|
747
748
|
if (!key.startsWith("__") || internalKeysToPreserve.has(key))
|
|
748
749
|
filteredParentContext[key] = val;
|
|
750
|
+
const callerLoopScope = clientLoopNames.length > 0 ? { [CLIENT_LOOP_NAMES_KEY]: [...clientLoopNames] } : {};
|
|
749
751
|
let callerSlotContent = slotContent;
|
|
750
752
|
if (slotContent.includes("@include")) {
|
|
751
753
|
const { processIncludes } = await importOnce("stx/includes", () => import("./includes.js"));
|
|
@@ -753,11 +755,11 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
753
755
|
}
|
|
754
756
|
if (/<[A-Z][\w.-]*[\s/>]/.test(callerSlotContent)) {
|
|
755
757
|
const { processComponents } = await importOnce("stx/component-renderer", () => import("./component-renderer.js"));
|
|
756
|
-
callerSlotContent = await processComponents(callerSlotContent, { ...parentContext, __processedComponents: components }, parentFilePath, options, dependencies);
|
|
758
|
+
callerSlotContent = await processComponents(callerSlotContent, { ...parentContext, __processedComponents: components, ...callerLoopScope }, parentFilePath, options, dependencies);
|
|
757
759
|
}
|
|
758
760
|
const callerPreservedExpressions = [];
|
|
759
761
|
if (slotContentHasExpressions(callerSlotContent)) {
|
|
760
|
-
const { processExpressions: resolveCallerExpressions } = await importOnce("stx/expressions", () => import("./expressions.js")), callerExpressionContext = parentContext.__stx_signals_gate === void 0 ? { ...parentContext, __stx_signals_gate: !0 } : parentContext;
|
|
762
|
+
const { processExpressions: resolveCallerExpressions } = await importOnce("stx/expressions", () => import("./expressions.js")), callerExpressionContext = parentContext.__stx_signals_gate === void 0 ? { ...parentContext, __stx_signals_gate: !0, ...callerLoopScope } : clientLoopNames.length > 0 ? { ...parentContext, ...callerLoopScope } : parentContext;
|
|
761
763
|
callerSlotContent = resolveCallerExpressions(callerSlotContent, callerExpressionContext, parentFilePath);
|
|
762
764
|
for (const match of callerSlotContent.matchAll(/\{\{([\s\S]*?)\}\}/g))
|
|
763
765
|
callerPreservedExpressions.push(match[1].trim());
|
|
@@ -809,6 +811,7 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
809
811
|
slotContext: slotContent.trim() ? componentSlotCacheContext(filteredParentContext) : void 0,
|
|
810
812
|
buildMode: options.buildMode ?? "",
|
|
811
813
|
skipEventDirectives: options.skipEventDirectives === !0,
|
|
814
|
+
clientLoopNames: [...clientLoopNames].sort(),
|
|
812
815
|
layers: options._layerGraph?.layers.map((layer) => layer.configFile),
|
|
813
816
|
uid: componentUid
|
|
814
817
|
});
|
|
@@ -896,6 +899,9 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
896
899
|
componentContext.__stx_client_signal_names = [...new Set([...inheritedClientSignalNames, ...clientSignalNames])];
|
|
897
900
|
else
|
|
898
901
|
delete componentContext.__stx_client_signal_names;
|
|
902
|
+
const slotLoopNames = clientLoopNames.filter((name) => !ownServerNames.has(name) && !(name in props));
|
|
903
|
+
if (slotLoopNames.length > 0)
|
|
904
|
+
componentContext[CLIENT_LOOP_NAMES_KEY] = slotLoopNames;
|
|
899
905
|
const componentOptions = {
|
|
900
906
|
...options,
|
|
901
907
|
_rootComponentsDir: options._rootComponentsDir || options.componentsDir,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.476",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -122,12 +122,12 @@
|
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@stacksjs/ts-css": "^0.3.2",
|
|
124
124
|
"@stacksjs/clapp": "^0.2.16",
|
|
125
|
-
"@stacksjs/desktop": "0.2.
|
|
126
|
-
"@stacksjs/sanitizer": "0.2.
|
|
125
|
+
"@stacksjs/desktop": "0.2.476",
|
|
126
|
+
"@stacksjs/sanitizer": "0.2.476",
|
|
127
127
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
128
|
-
"bun-plugin-stx": "0.2.
|
|
128
|
+
"bun-plugin-stx": "0.2.476",
|
|
129
129
|
"bunfig": "^0.15.19",
|
|
130
|
-
"stx-router": "0.2.
|
|
130
|
+
"stx-router": "0.2.476",
|
|
131
131
|
"ts-broadcasting": "^0.0.11",
|
|
132
132
|
"ts-images": "^0.2.22",
|
|
133
133
|
"ts-syntax-highlighter": "^0.2.1"
|