@stacksjs/stx 0.2.888 → 0.2.889
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-c0g30cjs.js → chunk-05x1rd86.js} +2 -2
- package/dist/chunk-0g9cceht.js +2 -0
- package/dist/chunk-0k437z3q.js +2 -0
- package/dist/{chunk-1xpq83mc.js → chunk-0ncafcs2.js} +4 -4
- package/dist/chunk-0rpj5t80.js +2 -0
- package/dist/{chunk-btsgt6w3.js → chunk-1gyxxfdf.js} +2 -2
- package/dist/{chunk-vazk5qbh.js → chunk-1knk403z.js} +2 -2
- package/dist/{chunk-6qq3wy3m.js → chunk-1n33yrar.js} +2 -2
- package/dist/chunk-1p4q6t48.js +2 -0
- package/dist/chunk-1z6pqvmf.js +2 -0
- package/dist/{chunk-s29hp1qw.js → chunk-2a5g80mq.js} +3 -3
- package/dist/chunk-2ba4zfa0.js +2 -0
- package/dist/chunk-2gn2nc2j.js +2 -0
- package/dist/chunk-2nqmw4dv.js +2 -0
- package/dist/chunk-2wkpksg1.js +2 -0
- package/dist/{chunk-xw291tn7.js → chunk-3dqfjpz4.js} +34 -29
- package/dist/{chunk-3ed2erm6.js → chunk-3hsv6ejp.js} +4 -4
- package/dist/{chunk-w624s5jf.js → chunk-3qk8vf9m.js} +3 -3
- package/dist/chunk-3yjyjq0m.js +2 -0
- package/dist/chunk-444haxxa.js +2 -0
- package/dist/{chunk-y76znqmh.js → chunk-446tb2th.js} +27 -27
- package/dist/{chunk-qjy5yq25.js → chunk-48rwqchc.js} +10 -10
- package/dist/chunk-4akw3bym.js +2 -0
- package/dist/{chunk-mm1eg2pg.js → chunk-4kmg6g5n.js} +9 -9
- package/dist/chunk-4rvfeee5.js +2 -0
- package/dist/{chunk-605g9qhp.js → chunk-51720m79.js} +5 -5
- package/dist/chunk-53kcqdjj.js +2 -0
- package/dist/{chunk-0dq9svfb.js → chunk-55tc5w32.js} +3 -3
- package/dist/{chunk-7s3j8pqq.js → chunk-58qzyyyv.js} +3 -3
- package/dist/chunk-5aa83bpm.js +2 -0
- package/dist/{chunk-ah6nc29h.js → chunk-5kqezrjt.js} +2 -2
- package/dist/chunk-5ssv10ep.js +2 -0
- package/dist/chunk-67rppc5v.js +2 -0
- package/dist/{chunk-care745q.js → chunk-6gtecbe7.js} +2 -2
- package/dist/{chunk-p33npqjt.js → chunk-6kyqejnq.js} +22 -22
- package/dist/{chunk-vjfp8n6p.js → chunk-6pdy7ajr.js} +3 -3
- package/dist/{chunk-9tecekzq.js → chunk-6pz5gq6v.js} +9 -9
- package/dist/{chunk-wpa3r3b9.js → chunk-700m927w.js} +2 -2
- package/dist/{chunk-2assyczz.js → chunk-7212fwzz.js} +2 -2
- package/dist/chunk-732gb689.js +2 -0
- package/dist/chunk-77c89d23.js +2 -0
- package/dist/chunk-79vbkez0.js +2 -0
- package/dist/{chunk-whsdyf4t.js → chunk-7hpca9c7.js} +6 -6
- package/dist/chunk-80xzjxah.js +2 -0
- package/dist/chunk-8354mzpd.js +2 -0
- package/dist/{chunk-r561zt9v.js → chunk-87g5xmmr.js} +12 -12
- package/dist/{chunk-ry6w43p6.js → chunk-8hwfdwgn.js} +6 -6
- package/dist/chunk-8ygf6jnt.js +2 -0
- package/dist/{chunk-5ymf5c8m.js → chunk-95sd8h5g.js} +7 -7
- package/dist/{chunk-gdtj5rfa.js → chunk-967ydrq4.js} +6 -6
- package/dist/chunk-9afkttvz.js +2 -0
- package/dist/{chunk-55kwxxm5.js → chunk-9d91h636.js} +2 -2
- package/dist/{chunk-kvxdyg7e.js → chunk-9n5h4sqc.js} +2 -2
- package/dist/chunk-9ztn7w4y.js +2 -0
- package/dist/chunk-ah8az9vv.js +2 -0
- package/dist/chunk-ankap9pc.js +2 -0
- package/dist/chunk-asnd03sr.js +2 -0
- package/dist/chunk-b0b5yr97.js +2 -0
- package/dist/chunk-b0e7dgv8.js +3 -0
- package/dist/{chunk-372xh1g1.js → chunk-b15c4g3e.js} +5 -5
- package/dist/{chunk-7hm1tpw0.js → chunk-b6bf0t02.js} +6 -6
- package/dist/chunk-b7jj45bz.js +2 -0
- package/dist/{chunk-r57jz09p.js → chunk-bgfs3mbg.js} +5 -5
- package/dist/{chunk-fepezvdq.js → chunk-bqtj62ys.js} +8 -8
- package/dist/{chunk-wbxmn5gk.js → chunk-bw2m1e7g.js} +5 -5
- package/dist/chunk-bwx6w87c.js +2 -0
- package/dist/{chunk-9qrgdekg.js → chunk-cgfjrgfw.js} +14 -14
- package/dist/{chunk-98mj0es1.js → chunk-ch9028z3.js} +1 -1
- package/dist/{chunk-sbwvvjkc.js → chunk-cmg9x1ka.js} +3 -3
- package/dist/{chunk-9f31gs4m.js → chunk-cz1sdes5.js} +2 -2
- package/dist/{chunk-dj9ztcth.js → chunk-dvjv4c3a.js} +1 -1
- package/dist/{chunk-edysherg.js → chunk-dymck524.js} +5 -5
- package/dist/chunk-dzqfv801.js +3 -0
- package/dist/{chunk-b8528fra.js → chunk-eceeqy74.js} +4 -4
- package/dist/{chunk-52mhrbps.js → chunk-eqffvse2.js} +1 -1
- package/dist/chunk-ery4tty7.js +20 -0
- package/dist/chunk-evwrxsxd.js +3 -0
- package/dist/{chunk-6t04tqvh.js → chunk-eyx92t9n.js} +2 -2
- package/dist/{chunk-c1b0fy70.js → chunk-f3cyghnb.js} +5 -5
- package/dist/chunk-f60k8j9m.js +2 -0
- package/dist/chunk-fdqdz018.js +2 -0
- package/dist/chunk-g6ap4085.js +2 -0
- package/dist/chunk-gz9pknbw.js +1204 -0
- package/dist/{chunk-e1qcfesw.js → chunk-hgf7bc50.js} +6 -6
- package/dist/chunk-hjb4c8g2.js +2 -0
- package/dist/chunk-hk241gt2.js +2 -0
- package/dist/{chunk-wscry63p.js → chunk-hm9d40yf.js} +2 -2
- package/dist/{chunk-vgr7gd8k.js → chunk-hpzje67q.js} +2 -2
- package/dist/{chunk-c3ca056p.js → chunk-htx5yezj.js} +2 -2
- package/dist/{chunk-b0jekg4c.js → chunk-hxws025y.js} +3 -3
- package/dist/chunk-jhbj9ja2.js +2 -0
- package/dist/chunk-k4x680e3.js +2 -0
- package/dist/chunk-k9abxnpa.js +2 -0
- package/dist/{chunk-c73c0wf9.js → chunk-kbbbpae2.js} +2 -2
- package/dist/chunk-kfdmm240.js +2 -0
- package/dist/{chunk-5ysv0499.js → chunk-kj43fbzm.js} +1 -1
- package/dist/{chunk-303vzq80.js → chunk-kk2p2tgv.js} +3 -3
- package/dist/{chunk-r8xper92.js → chunk-ksmn19qw.js} +2 -2
- package/dist/{chunk-v47xc2fr.js → chunk-kx09v9ya.js} +7 -7
- package/dist/{chunk-wm287dz2.js → chunk-m95sygv4.js} +3 -3
- package/dist/{chunk-j51wss7s.js → chunk-mctzpw0w.js} +1 -1
- package/dist/{chunk-2rmqmajd.js → chunk-me4yq8c2.js} +3 -3
- package/dist/{chunk-11fxbd71.js → chunk-mgh5rst1.js} +2 -2
- package/dist/{chunk-1kc0jyhj.js → chunk-mhxg6j6s.js} +1 -1
- package/dist/{chunk-wf8pdjq5.js → chunk-mjp1z9kz.js} +1 -1
- package/dist/{chunk-znnvq1jp.js → chunk-mt8edb75.js} +46 -46
- package/dist/chunk-mvavjydq.js +2 -0
- package/dist/{chunk-s7wp7a2x.js → chunk-mw7hacm3.js} +30 -30
- package/dist/{chunk-e2ws79vt.js → chunk-nbdscgvj.js} +6 -6
- package/dist/{chunk-mk6thhwf.js → chunk-njpva3zq.js} +2 -2
- package/dist/{chunk-q3bkxg2n.js → chunk-nkyff7v6.js} +11 -11
- package/dist/{chunk-zje94z0k.js → chunk-p8shtje2.js} +32 -32
- package/dist/{chunk-0hj5apb9.js → chunk-pctf14yw.js} +1 -1
- package/dist/{chunk-0d7ypcjb.js → chunk-pjj54ddk.js} +3 -3
- package/dist/{chunk-qsnpqa8q.js → chunk-pnmafbv5.js} +1 -1
- package/dist/{chunk-vgsasnwm.js → chunk-pz554g43.js} +3 -3
- package/dist/{chunk-6zq3eh7d.js → chunk-q0y8gv18.js} +2 -2
- package/dist/{chunk-w50yggy3.js → chunk-q9tc9rdv.js} +2 -2
- package/dist/chunk-qqng9545.js +2 -0
- package/dist/{chunk-xavx271y.js → chunk-r5ecgcx2.js} +5 -5
- package/dist/{chunk-v8e2c2r1.js → chunk-ranjkpc8.js} +2 -2
- package/dist/{chunk-zf29ahhd.js → chunk-rb2zbdqd.js} +4 -4
- package/dist/{chunk-4nnmrp7w.js → chunk-rf0smj4c.js} +2 -2
- package/dist/chunk-rjm515e2.js +2 -0
- package/dist/chunk-rye4b2x3.js +2 -0
- package/dist/chunk-ryj8139z.js +2 -0
- package/dist/{chunk-e9tjxnhn.js → chunk-s0mf56y1.js} +5 -5
- package/dist/{chunk-fce8wj3t.js → chunk-s93yh7ed.js} +2 -2
- package/dist/chunk-s9b809n2.js +2 -0
- package/dist/chunk-sb67wg5x.js +2 -0
- package/dist/{chunk-6fsnnj5v.js → chunk-sjjw6y49.js} +6 -6
- package/dist/chunk-snkbn5y8.js +2 -0
- package/dist/{chunk-7mcs59pr.js → chunk-snv80b1b.js} +2 -2
- package/dist/chunk-sqwx2g02.js +2 -0
- package/dist/{chunk-4c9p434g.js → chunk-t0ttxayz.js} +2 -2
- package/dist/chunk-tbh7r1wh.js +2 -0
- package/dist/chunk-tpyekw0q.js +2 -0
- package/dist/chunk-v2627s75.js +2 -0
- package/dist/chunk-v3jyb8k6.js +2 -0
- package/dist/chunk-v98n53nk.js +2 -0
- package/dist/{chunk-pm4kn9h2.js → chunk-vc432a0w.js} +9 -9
- package/dist/{chunk-7nhgpjjw.js → chunk-vf4ejngv.js} +6 -6
- package/dist/{chunk-hxhmhw23.js → chunk-vk2jy6mn.js} +3 -3
- package/dist/chunk-w34vvhm7.js +2 -0
- package/dist/chunk-w82nk19t.js +2 -0
- package/dist/{chunk-mbm3ma63.js → chunk-x5bn2svk.js} +2 -2
- package/dist/chunk-x6565mhk.js +2 -0
- package/dist/{chunk-3fbgpv1d.js → chunk-xvncq3m5.js} +2 -2
- package/dist/chunk-xwgdcc7w.js +2 -0
- package/dist/{chunk-1wkp3pks.js → chunk-xy8smv5e.js} +2 -2
- package/dist/{chunk-y8p59h6c.js → chunk-y1d3j2j7.js} +4 -4
- package/dist/chunk-yjwa7ktk.js +2 -0
- package/dist/{chunk-xy4j8t7w.js → chunk-ytjn0gq2.js} +2 -2
- package/dist/chunk-z47p2gx8.js +2 -0
- package/dist/chunk-z4tdnfxd.js +2 -0
- package/dist/chunk-z6kw6sct.js +4 -0
- package/dist/{chunk-w1q86c89.js → chunk-zf68afyh.js} +3 -3
- package/dist/chunk-zhywjwdr.js +2 -0
- package/dist/{chunk-em6fqvjy.js → chunk-zwwhpxp7.js} +2 -2
- package/dist/cli.js +21 -21
- package/dist/component-library.d.ts +2 -1
- package/dist/component-library.js +17 -296
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/directive-arguments.js +39 -6
- package/dist/parser/tokenizer.d.ts +2 -1
- package/dist/parser/tokenizer.js +7 -5
- package/dist/props-declaration.d.ts +64 -0
- package/dist/props-declaration.js +354 -0
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +5 -5
- package/dist/utils.js +20 -109
- package/package.json +5 -5
- package/dist/chunk-000mwmfq.js +0 -1203
- package/dist/chunk-043d0en0.js +0 -2
- package/dist/chunk-0w66z6eq.js +0 -2
- package/dist/chunk-13wd9gf0.js +0 -3
- package/dist/chunk-1znqedae.js +0 -2
- package/dist/chunk-2drzzjcm.js +0 -2
- package/dist/chunk-3c7nt5qp.js +0 -2
- package/dist/chunk-3zyzhcd9.js +0 -2
- package/dist/chunk-44rb9fk0.js +0 -2
- package/dist/chunk-472j3bhp.js +0 -2
- package/dist/chunk-4acce1m8.js +0 -2
- package/dist/chunk-4kasmp98.js +0 -2
- package/dist/chunk-53kkjn23.js +0 -2
- package/dist/chunk-5gwvy612.js +0 -2
- package/dist/chunk-61vbqrde.js +0 -2
- package/dist/chunk-6fpzwryt.js +0 -2
- package/dist/chunk-7195598h.js +0 -2
- package/dist/chunk-7zvf79vb.js +0 -2
- package/dist/chunk-88a735jw.js +0 -2
- package/dist/chunk-8v7yjq3b.js +0 -2
- package/dist/chunk-97kgrevs.js +0 -4
- package/dist/chunk-a8c9j9cj.js +0 -2
- package/dist/chunk-acw851e8.js +0 -2
- package/dist/chunk-andfvr3g.js +0 -2
- package/dist/chunk-aqxh80vh.js +0 -2
- package/dist/chunk-ay5zkfdg.js +0 -2
- package/dist/chunk-b4gptdtc.js +0 -2
- package/dist/chunk-baaw9w7y.js +0 -2
- package/dist/chunk-bw2p9h2g.js +0 -2
- package/dist/chunk-ce0vv7kz.js +0 -2
- package/dist/chunk-d1yj29g2.js +0 -2
- package/dist/chunk-dbhmbef1.js +0 -20
- package/dist/chunk-dfsykk1r.js +0 -2
- package/dist/chunk-e9p596bp.js +0 -2
- package/dist/chunk-ftecsa8e.js +0 -2
- package/dist/chunk-ge2h5v46.js +0 -2
- package/dist/chunk-gqvnz8a7.js +0 -2
- package/dist/chunk-j41gp8p3.js +0 -2
- package/dist/chunk-jxvccj30.js +0 -2
- package/dist/chunk-k5bbre7d.js +0 -2
- package/dist/chunk-kd47vgs8.js +0 -2
- package/dist/chunk-keqjafdz.js +0 -2
- package/dist/chunk-kz3mejc4.js +0 -2
- package/dist/chunk-ngkh0t5b.js +0 -2
- package/dist/chunk-nx9895m6.js +0 -2
- package/dist/chunk-nxgtt1t1.js +0 -2
- package/dist/chunk-nyw2ztar.js +0 -2
- package/dist/chunk-p5q27adr.js +0 -2
- package/dist/chunk-p6hcrg3r.js +0 -3
- package/dist/chunk-pa2vt2ej.js +0 -2
- package/dist/chunk-pczb7xav.js +0 -2
- package/dist/chunk-ps37r6hj.js +0 -2
- package/dist/chunk-pvbhk17r.js +0 -2
- package/dist/chunk-q252qvsy.js +0 -2
- package/dist/chunk-q5b0vpmm.js +0 -2
- package/dist/chunk-qg1kw5yf.js +0 -2
- package/dist/chunk-sbr85vda.js +0 -2
- package/dist/chunk-tkab24xr.js +0 -2
- package/dist/chunk-vn59yrjh.js +0 -2
- package/dist/chunk-w5zzwe2f.js +0 -2
- package/dist/chunk-wa9q1gyv.js +0 -2
- package/dist/chunk-wpgxhrd7.js +0 -2
- package/dist/chunk-x3azrbpr.js +0 -2
- package/dist/chunk-x50hk1hq.js +0 -2
- package/dist/chunk-xbkbvfcg.js +0 -2
- package/dist/chunk-z55rpt3s.js +0 -3
- package/dist/chunk-zwde52kw.js +0 -2
- package/dist/chunk-zxff7kq9.js +0 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The index just past a balanced bracket pair starting at `index`, or -1 when
|
|
3
|
+
* it never closes.
|
|
4
|
+
*
|
|
5
|
+
* Quotes and template literals are skipped, so a bracket inside a string
|
|
6
|
+
* default does not unbalance the scan.
|
|
7
|
+
*/
|
|
8
|
+
export declare function skipBalanced(source: string, index: number, open: string, close: string): number;
|
|
9
|
+
/**
|
|
10
|
+
* Split a list on separators that are not nested inside brackets or quotes.
|
|
11
|
+
*
|
|
12
|
+
* `angles` decides whether `<` and `>` nest. They must in a type literal, so
|
|
13
|
+
* `Array<string, number>` stays one member, and must NOT in a value, where
|
|
14
|
+
* `>` is a comparison and `=>` an arrow and counting either unbalances
|
|
15
|
+
* everything after it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function splitTopLevel(body: string, separators: string, angles: boolean): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Read a `defineProps` declaration, in every form it is written
|
|
20
|
+
* (stacksjs/stx#2009).
|
|
21
|
+
*
|
|
22
|
+
* This used to be one regex that required a destructuring assignment AND an
|
|
23
|
+
* explicit type argument, so four of the five documented spellings produced no
|
|
24
|
+
* properties at all and the component silently had no public surface. The one
|
|
25
|
+
* that did match split its names on `:` only, so
|
|
26
|
+
*
|
|
27
|
+
* const { label = 'Hello' } = defineProps<{ label?: string }>()
|
|
28
|
+
*
|
|
29
|
+
* produced a property literally named `label = 'Hello'`, documented as the
|
|
30
|
+
* attribute `label-hello`, and nothing a page wrote as `label="x"` ever
|
|
31
|
+
* arrived. That is worse than not reading it, because it looks like it worked.
|
|
32
|
+
*
|
|
33
|
+
* Handled here:
|
|
34
|
+
*
|
|
35
|
+
* const { a, b = 1 } = defineProps<{ a?: string, b?: number }>()
|
|
36
|
+
* const { a } = defineProps(['a'])
|
|
37
|
+
* const props = defineProps<{ a?: string }>()
|
|
38
|
+
* const props = defineProps<Props>()
|
|
39
|
+
* const props = withDefaults(defineProps<{ a?: string }>(), { a: 'x' })
|
|
40
|
+
* const props = defineProps({ a: { type: String, default: 'x' } })
|
|
41
|
+
*
|
|
42
|
+
* Names come from the destructuring pattern when there is one, since that is
|
|
43
|
+
* the author naming them, and otherwise from whichever of the type literal,
|
|
44
|
+
* the object form or the array form is present. Types come from the type
|
|
45
|
+
* literal or the object form's `type:`, never inferred from a default: a
|
|
46
|
+
* `title?: string` with no default was being typed as an object, and the
|
|
47
|
+
* attribute `"Revenue"` was then JSON-parsed, failed, and reached the page as
|
|
48
|
+
* `[object Object]`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parsePropsDeclaration(source: string): PropsDeclaration | null;
|
|
51
|
+
export declare function parseDefaults(object: string): Array<[string, string]>;
|
|
52
|
+
/** Literal defaults only: no client functions, imports, identifiers or getters run in SSR. */
|
|
53
|
+
export declare function literalValue(source: string): unknown;
|
|
54
|
+
declare interface PropsDeclaration {
|
|
55
|
+
text: string
|
|
56
|
+
propNames: string[]
|
|
57
|
+
propBindings: Record<string, string>
|
|
58
|
+
localBindings: Record<string, string>
|
|
59
|
+
defaults: Record<string, string>
|
|
60
|
+
declared: Record<string, string>
|
|
61
|
+
typeName?: string
|
|
62
|
+
identifier?: string
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { topLevelDeclarationSites } from "./client-parameter-bindings.js";
|
|
2
|
+
import { Tokenizer } from "./parser/tokenizer.js";
|
|
3
|
+
import { parseStringLiteral } from "./directive-arguments.js";
|
|
4
|
+
function withoutComments(source) {
|
|
5
|
+
const tokens = new Tokenizer(source, "javascript").tokenize();
|
|
6
|
+
let code = source;
|
|
7
|
+
for (const token of tokens.reverse())
|
|
8
|
+
if (token.type === "COMMENT")
|
|
9
|
+
code = code.slice(0, token.start) + token.value.replace(/[^\r\n]/g, " ") + code.slice(token.end);
|
|
10
|
+
return code;
|
|
11
|
+
}
|
|
12
|
+
export function skipBalanced(source, index, open, close) {
|
|
13
|
+
if (source[index] !== open)
|
|
14
|
+
return -1;
|
|
15
|
+
let depth = 0, quote = null;
|
|
16
|
+
for (let i = index;i < source.length; i++) {
|
|
17
|
+
const char = source[i];
|
|
18
|
+
if (quote) {
|
|
19
|
+
if (char === "\\") {
|
|
20
|
+
i++;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (char === quote)
|
|
24
|
+
quote = null;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (char === "'" || char === '"' || char === "`") {
|
|
28
|
+
quote = char;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (char === open)
|
|
32
|
+
depth++;
|
|
33
|
+
else if (char === close) {
|
|
34
|
+
if (close === ">" && source[i - 1] === "=")
|
|
35
|
+
continue;
|
|
36
|
+
depth--;
|
|
37
|
+
if (depth === 0)
|
|
38
|
+
return i + 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
43
|
+
export function splitTopLevel(body, separators, angles) {
|
|
44
|
+
const opening = angles ? "([{<" : "([{", closing = angles ? ")]}>" : ")]}", parts = [];
|
|
45
|
+
let depth = 0, quote = null, current = "";
|
|
46
|
+
for (let i = 0;i < body.length; i++) {
|
|
47
|
+
const char = body[i];
|
|
48
|
+
if (quote) {
|
|
49
|
+
current += char;
|
|
50
|
+
if (char === "\\") {
|
|
51
|
+
current += body[++i] ?? "";
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (char === quote)
|
|
55
|
+
quote = null;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (char === "'" || char === '"' || char === "`") {
|
|
59
|
+
quote = char;
|
|
60
|
+
current += char;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (opening.includes(char))
|
|
64
|
+
depth++;
|
|
65
|
+
else if (closing.includes(char) && !(angles && char === ">" && body[i - 1] === "="))
|
|
66
|
+
depth--;
|
|
67
|
+
if (depth === 0 && separators.includes(char)) {
|
|
68
|
+
parts.push(current);
|
|
69
|
+
current = "";
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
current += char;
|
|
73
|
+
}
|
|
74
|
+
parts.push(current);
|
|
75
|
+
return parts.map((part) => part.trim()).filter(Boolean);
|
|
76
|
+
}
|
|
77
|
+
function defaultAssignmentIndex(entry) {
|
|
78
|
+
let depth = 0, quote = null;
|
|
79
|
+
for (let i = 0;i < entry.length; i++) {
|
|
80
|
+
const char = entry[i];
|
|
81
|
+
if (quote) {
|
|
82
|
+
if (char === "\\") {
|
|
83
|
+
i++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (char === quote)
|
|
87
|
+
quote = null;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (char === "'" || char === '"' || char === "`") {
|
|
91
|
+
quote = char;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if ("([{".includes(char))
|
|
95
|
+
depth++;
|
|
96
|
+
else if (")]}".includes(char))
|
|
97
|
+
depth--;
|
|
98
|
+
if (depth !== 0 || char !== "=")
|
|
99
|
+
continue;
|
|
100
|
+
const previous = entry[i - 1];
|
|
101
|
+
if (entry[i + 1] === "=" || previous === "=" || previous === "!" || previous === "<" || previous === ">")
|
|
102
|
+
continue;
|
|
103
|
+
return i;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
function typeFromConstructor(value) {
|
|
108
|
+
switch (value.trim()) {
|
|
109
|
+
case "String":
|
|
110
|
+
return "string";
|
|
111
|
+
case "Number":
|
|
112
|
+
return "number";
|
|
113
|
+
case "Boolean":
|
|
114
|
+
return "boolean";
|
|
115
|
+
case "Array":
|
|
116
|
+
return "unknown[]";
|
|
117
|
+
case "Object":
|
|
118
|
+
return "Record<string, unknown>";
|
|
119
|
+
default:
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function parsePropsDeclaration(source) {
|
|
124
|
+
const code = withoutComments(source);
|
|
125
|
+
for (const start of new Set(topLevelDeclarationSites(code).map((site) => site.start))) {
|
|
126
|
+
const declaration = parsePropsAt(code, start);
|
|
127
|
+
if (declaration)
|
|
128
|
+
return { ...declaration, text: source.slice(start, start + declaration.text.length) };
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
function parsePropsAt(code, start) {
|
|
133
|
+
const declared = Object.create(null), defaults = Object.create(null), propNames = [], propBindings = Object.create(null), localBindings = Object.create(null);
|
|
134
|
+
let cursor = start + (/^(?:const|let|var)\s+/.exec(code.slice(start))?.[0].length ?? 0);
|
|
135
|
+
const skipSpace = () => {
|
|
136
|
+
while (cursor < code.length && /\s/.test(code[cursor]))
|
|
137
|
+
cursor++;
|
|
138
|
+
};
|
|
139
|
+
let pattern;
|
|
140
|
+
if (code[cursor] === "{") {
|
|
141
|
+
const end = skipBalanced(code, cursor, "{", "}");
|
|
142
|
+
if (end === -1)
|
|
143
|
+
return null;
|
|
144
|
+
pattern = code.slice(cursor, end);
|
|
145
|
+
cursor = end;
|
|
146
|
+
} else {
|
|
147
|
+
const identifier = /^[A-Za-z_$][\w$]*/.exec(code.slice(cursor));
|
|
148
|
+
if (!identifier)
|
|
149
|
+
return null;
|
|
150
|
+
pattern = identifier[0];
|
|
151
|
+
cursor += identifier[0].length;
|
|
152
|
+
}
|
|
153
|
+
skipSpace();
|
|
154
|
+
if (code[cursor] !== "=")
|
|
155
|
+
return null;
|
|
156
|
+
cursor++;
|
|
157
|
+
skipSpace();
|
|
158
|
+
const wrapper = /^withDefaults\s*\(\s*/.exec(code.slice(cursor)), wrapped = Boolean(wrapper);
|
|
159
|
+
if (wrapper)
|
|
160
|
+
cursor += wrapper[0].length;
|
|
161
|
+
const marker = /^defineProps\b/.exec(code.slice(cursor));
|
|
162
|
+
if (!marker)
|
|
163
|
+
return null;
|
|
164
|
+
cursor += marker[0].length;
|
|
165
|
+
let typeText = "";
|
|
166
|
+
skipSpace();
|
|
167
|
+
if (code[cursor] === "<") {
|
|
168
|
+
const end = skipBalanced(code, cursor, "<", ">");
|
|
169
|
+
if (end === -1)
|
|
170
|
+
return null;
|
|
171
|
+
typeText = code.slice(cursor + 1, end - 1).trim();
|
|
172
|
+
cursor = end;
|
|
173
|
+
}
|
|
174
|
+
skipSpace();
|
|
175
|
+
if (code[cursor] !== "(")
|
|
176
|
+
return null;
|
|
177
|
+
const callEnd = skipBalanced(code, cursor, "(", ")");
|
|
178
|
+
if (callEnd === -1)
|
|
179
|
+
return null;
|
|
180
|
+
const runtimeArgument = code.slice(cursor + 1, callEnd - 1).trim();
|
|
181
|
+
cursor = callEnd;
|
|
182
|
+
if (wrapped) {
|
|
183
|
+
skipSpace();
|
|
184
|
+
if (code[cursor] === ",") {
|
|
185
|
+
cursor++;
|
|
186
|
+
skipSpace();
|
|
187
|
+
}
|
|
188
|
+
if (code[cursor] === "{") {
|
|
189
|
+
const end = skipBalanced(code, cursor, "{", "}");
|
|
190
|
+
if (end === -1)
|
|
191
|
+
return null;
|
|
192
|
+
for (const [name, value] of parseDefaults(code.slice(cursor, end)))
|
|
193
|
+
defaults[name] = value;
|
|
194
|
+
cursor = end;
|
|
195
|
+
}
|
|
196
|
+
skipSpace();
|
|
197
|
+
if (code[cursor] === ",") {
|
|
198
|
+
cursor++;
|
|
199
|
+
skipSpace();
|
|
200
|
+
}
|
|
201
|
+
if (code[cursor] === ")")
|
|
202
|
+
cursor++;
|
|
203
|
+
}
|
|
204
|
+
if (code[cursor] === ";")
|
|
205
|
+
cursor++;
|
|
206
|
+
const typeName = /^[A-Za-z_$][\w$]*$/.test(typeText) ? typeText : void 0;
|
|
207
|
+
if (typeText.startsWith("{"))
|
|
208
|
+
for (const member of splitTopLevel(typeText.replace(/^\{/, "").replace(/\}$/, ""), ",;", !0)) {
|
|
209
|
+
const parsed = /^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(member);
|
|
210
|
+
if (parsed)
|
|
211
|
+
declared[parsed[1]] = parsed[2].trim();
|
|
212
|
+
}
|
|
213
|
+
if (runtimeArgument.startsWith("{"))
|
|
214
|
+
for (const [name, value] of parseDefaults(runtimeArgument)) {
|
|
215
|
+
propNames.push(name);
|
|
216
|
+
if (!value.startsWith("{")) {
|
|
217
|
+
const fromConstructor = typeFromConstructor(value);
|
|
218
|
+
if (fromConstructor)
|
|
219
|
+
declared[name] = fromConstructor;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
for (const [key, inner] of parseDefaults(value))
|
|
223
|
+
if (key === "default")
|
|
224
|
+
defaults[name] = inner;
|
|
225
|
+
else if (key === "type") {
|
|
226
|
+
const fromConstructor = typeFromConstructor(inner);
|
|
227
|
+
if (fromConstructor)
|
|
228
|
+
declared[name] = fromConstructor;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (runtimeArgument.startsWith("["))
|
|
232
|
+
for (const entry of splitTopLevel(runtimeArgument.slice(1, -1), ",", !1))
|
|
233
|
+
propNames.push(entry.replace(/^['"`]/, "").replace(/['"`]$/, ""));
|
|
234
|
+
if (pattern.startsWith("{")) {
|
|
235
|
+
propNames.length = 0;
|
|
236
|
+
for (const entry of splitTopLevel(pattern.replace(/^\{/, "").replace(/\}$/, ""), ",", !1)) {
|
|
237
|
+
const assignment = defaultAssignmentIndex(entry), binding = assignment === -1 ? entry : entry.slice(0, assignment), name = binding.split(":")[0].trim().replace(/^\.\.\./, "");
|
|
238
|
+
if (!name)
|
|
239
|
+
continue;
|
|
240
|
+
propNames.push(name);
|
|
241
|
+
propBindings[name] = binding.trim();
|
|
242
|
+
const local = binding.split(":").at(-1).trim();
|
|
243
|
+
if (/^[A-Za-z_$][\w$]*$/.test(local))
|
|
244
|
+
localBindings[name] = local;
|
|
245
|
+
if (assignment !== -1)
|
|
246
|
+
defaults[name] = entry.slice(assignment + 1).trim();
|
|
247
|
+
}
|
|
248
|
+
} else if (propNames.length === 0)
|
|
249
|
+
propNames.push(...Object.keys(declared));
|
|
250
|
+
return { text: code.slice(start, cursor), propNames, propBindings, localBindings, defaults, declared, typeName, identifier: pattern.startsWith("{") ? void 0 : pattern };
|
|
251
|
+
}
|
|
252
|
+
export function parseDefaults(object) {
|
|
253
|
+
const body = object.trim().replace(/^\{/, "").replace(/\}$/, ""), pairs = [];
|
|
254
|
+
let index = 0;
|
|
255
|
+
while (index < body.length) {
|
|
256
|
+
const key = /\s*([A-Za-z_$][\w$]*)\s*:/y;
|
|
257
|
+
key.lastIndex = index;
|
|
258
|
+
const match = key.exec(body);
|
|
259
|
+
if (!match)
|
|
260
|
+
break;
|
|
261
|
+
index = key.lastIndex;
|
|
262
|
+
let depth = 0, quote = "";
|
|
263
|
+
const start = index;
|
|
264
|
+
while (index < body.length) {
|
|
265
|
+
const char = body[index];
|
|
266
|
+
if (quote) {
|
|
267
|
+
if (char === "\\")
|
|
268
|
+
index++;
|
|
269
|
+
else if (char === quote)
|
|
270
|
+
quote = "";
|
|
271
|
+
} else if (char === "'" || char === '"' || char === "`")
|
|
272
|
+
quote = char;
|
|
273
|
+
else if (char === "{" || char === "[" || char === "(")
|
|
274
|
+
depth++;
|
|
275
|
+
else if (char === "}" || char === "]" || char === ")")
|
|
276
|
+
depth--;
|
|
277
|
+
else if (char === "," && depth === 0)
|
|
278
|
+
break;
|
|
279
|
+
index++;
|
|
280
|
+
}
|
|
281
|
+
const value = body.slice(start, index).trim();
|
|
282
|
+
if (value)
|
|
283
|
+
pairs.push([match[1], value]);
|
|
284
|
+
index++;
|
|
285
|
+
}
|
|
286
|
+
return pairs;
|
|
287
|
+
}
|
|
288
|
+
function numberLiteral(source) {
|
|
289
|
+
const decimal = /^(?:(?:0|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?$/, radix = /^(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[bB][01](?:_?[01])*|0[oO][0-7](?:_?[0-7])*)$/;
|
|
290
|
+
if (!decimal.test(source) && !radix.test(source))
|
|
291
|
+
throw Error("Invalid prop number");
|
|
292
|
+
return Number(source.replaceAll("_", ""));
|
|
293
|
+
}
|
|
294
|
+
export function literalValue(source) {
|
|
295
|
+
const tokens = new Tokenizer(source, "javascript").tokenize().filter((token) => !["COMMENT", "WHITESPACE", "EOF"].includes(token.type));
|
|
296
|
+
let cursor = 0;
|
|
297
|
+
function read(depth) {
|
|
298
|
+
if (depth > 64)
|
|
299
|
+
throw Error("Prop literal too deep");
|
|
300
|
+
const token = tokens[cursor++];
|
|
301
|
+
if (!token)
|
|
302
|
+
throw Error("Missing prop literal");
|
|
303
|
+
if (token.type === "STRING" || token.type === "TEMPLATE_STRING") {
|
|
304
|
+
const value = parseStringLiteral(token.value);
|
|
305
|
+
if (value === null)
|
|
306
|
+
throw Error("Dynamic prop string");
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
if (token.type === "NUMBER")
|
|
310
|
+
return numberLiteral(token.value);
|
|
311
|
+
if (token.value === "-" || token.value === "+") {
|
|
312
|
+
const number = tokens[cursor++];
|
|
313
|
+
if (number?.type !== "NUMBER")
|
|
314
|
+
throw Error("Dynamic prop number");
|
|
315
|
+
return (token.value === "-" ? -1 : 1) * numberLiteral(number.value);
|
|
316
|
+
}
|
|
317
|
+
if (token.value === "true")
|
|
318
|
+
return !0;
|
|
319
|
+
if (token.value === "false")
|
|
320
|
+
return !1;
|
|
321
|
+
if (token.value === "null")
|
|
322
|
+
return null;
|
|
323
|
+
if (token.value === "undefined")
|
|
324
|
+
return;
|
|
325
|
+
if (token.value !== "[" && token.value !== "{")
|
|
326
|
+
throw Error("Dynamic prop default");
|
|
327
|
+
const array = token.value === "[", close = array ? "]" : "}", entries = [], values = [];
|
|
328
|
+
while (tokens[cursor]?.value !== close) {
|
|
329
|
+
if (array)
|
|
330
|
+
values.push(read(depth + 1));
|
|
331
|
+
else {
|
|
332
|
+
const key = tokens[cursor++];
|
|
333
|
+
if (!key || !["STRING", "IDENTIFIER", "NUMBER"].includes(key.type))
|
|
334
|
+
throw Error("Dynamic prop key");
|
|
335
|
+
const name = key.type === "STRING" ? parseStringLiteral(key.value) : key.type === "NUMBER" ? String(numberLiteral(key.value)) : key.value;
|
|
336
|
+
if (name === null || tokens[cursor++]?.value !== ":")
|
|
337
|
+
throw Error("Dynamic prop key");
|
|
338
|
+
entries.push([name, read(depth + 1)]);
|
|
339
|
+
}
|
|
340
|
+
if (tokens[cursor]?.value !== ",")
|
|
341
|
+
break;
|
|
342
|
+
cursor++;
|
|
343
|
+
}
|
|
344
|
+
if (tokens[cursor++]?.value !== close)
|
|
345
|
+
throw Error("Unclosed prop literal");
|
|
346
|
+
return array ? values : Object.fromEntries(entries);
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const result = read(0);
|
|
350
|
+
return cursor === tokens.length ? result : void 0;
|
|
351
|
+
} catch {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
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-
|
|
2
|
+
import{xo,Qt,Yl,rm}from"./chunk-0ncafcs2.js";import{vo,ra,em,tm,nm}from"./chunk-967ydrq4.js";import{Gl,Xl,Jl,Zg,Qg}from"./chunk-rf0smj4c.js";import{tt,zn,sa}from"./chunk-55tc5w32.js";import{sm,om,im,am,So,Wy}from"./chunk-ksmn19qw.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-8354mzpd.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">
|
|
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
|
|
|
233
233
|
}, 5000);
|
|
234
234
|
</script>
|
|
235
235
|
</body>
|
|
236
|
-
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=tt(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=
|
|
236
|
+
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=tt(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=xo(n,t);if(a){let s=Qt(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return ra(n,t)}function se(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Xl as auditBuildOutput,Gl as auditConfig,re as buildPwaAssets,Jl as calculateAuditResult,Qg as formatAuditResult,sa as formatSize,j as generateManifest,_ as generateManifestJson,tm as generateManifestLink,F as generateOfflinePage,tt as generatePrecacheManifest,zn as generatePrecacheManifestJs,M as generatePwaIcons,vo as generatePwaTags,xo as generateServiceWorker,rm as generateServiceWorkerAuto,em as generateSwRegistrationScript,nm as generateThemeColorMeta,N as getExpectedIconPaths,Qt as getServiceWorkerFileName,ra as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Yl as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,So as pwaDirectives,sm as pwaInstallDirective,im as pwaOfflineDirective,am as pwaPushDirective,om as pwaUpdateDirective,Wy as registerPwaDirectives,Zg as runPwaAudit,D as validateManifest};
|
package/dist/ssg.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
3
|
-
`)}function V(e){return async()=>({paths:await e(),fallback:!1})}var Ot;function Ut(e){let n=t(e),{depths:s}=E(n),o=/\b(?:async\s+)?function\s+getStaticPaths\s*\(/g,c;while((c=o.exec(n))!==null){if(s[c.index]!==0)continue;let u=k(n,"(",")",o.lastIndex-1),g=n.indexOf("{",u+1),v=k(n,"{","}",g);if(u<0||g<0||v<0)break;return e.slice(c.index,v+1)}let r=/\b(?:const|let|var)\s+getStaticPaths\s*=/g;while((c=r.exec(n))!==null){if(s[c.index]!==0)continue;let u
|
|
2
|
+
import"./chunk-2a5g80mq.js";import"./chunk-9n5h4sqc.js";import"./chunk-cz1sdes5.js";import{k,Rl}from"./chunk-3dqfjpz4.js";import"./chunk-mgh5rst1.js";import"./chunk-vk2jy6mn.js";import{zt,w}from"./chunk-gz9pknbw.js";import"./chunk-eyx92t9n.js";import"./chunk-s93yh7ed.js";import"./chunk-q0y8gv18.js";import{Mt,Dt,Lt,jt,Bt,Ft}from"./chunk-eceeqy74.js";import{a}from"./chunk-p8shtje2.js";import{Vs}from"./chunk-95sd8h5g.js";import"./chunk-rb2zbdqd.js";import"./chunk-s0mf56y1.js";import{Ee,fn,gn}from"./chunk-ery4tty7.js";import"./chunk-9d91h636.js";import{x}from"./chunk-vc432a0w.js";import{Rt,i}from"./chunk-mt8edb75.js";import"./chunk-hgf7bc50.js";import"./chunk-48rwqchc.js";import{As}from"./chunk-4kmg6g5n.js";import"./chunk-dymck524.js";import"./chunk-05x1rd86.js";import{Sc,kc,_c}from"./chunk-kk2p2tgv.js";import{dn,dr,pr}from"./chunk-evwrxsxd.js";import{pn}from"./chunk-7212fwzz.js";import"./chunk-b0e7dgv8.js";import"./chunk-5kqezrjt.js";import{ne,Re}from"./chunk-bqtj62ys.js";import"./chunk-pctf14yw.js";import"./chunk-eqffvse2.js";import"./chunk-58qzyyyv.js";import{l}from"./chunk-dzqfv801.js";import{et}from"./chunk-q9tc9rdv.js";import{t,E}from"./chunk-3hsv6ejp.js";import{f}from"./chunk-hxws025y.js";import R from"fs";import m from"path";import{createHash as Pt}from"crypto";function $t(e){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(e).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return e}}var kt=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function Et(e){return Bun.hash(e).toString(16)}function lt(e,n={}){if(!e.includes('type="stx/island"'))return{html:e,chunks:[]};let s=new Map,o=e.replace(kt,(r,u,g,v)=>{let S=v.trim();if(!S)return r;if(/\bdata-stx-src=/.test(g))return r;if(n.minify)S=$t(S);let p=Et(S);if(!s.has(p))s.set(p,S);let P=n.integrity?` data-stx-integrity="sha384-${Pt("sha384").update(S).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${u}" data-stx-src="/_stx/islands/${p}.js"${P}${g}></script>`}),c=Array.from(s,([r,u])=>({hash:r,code:u}));return{html:o,chunks:c}}var Ct=new Set(["visible","idle"]);function ut(e){if(!e.includes("data-stx-src="))return e;let n=new Map,s=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,o;while((o=s.exec(e))!==null)n.set(o[1],o[2]);let c=new Set,r=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,u;while((u=r.exec(e))!==null)if(Ct.has(n.get(u[1])||""))c.add(u[2]);let g=/<\/head\s*>/iy,v=w(e,(p,P)=>(g.lastIndex=P,g.exec(p)?g.lastIndex:-1))[0]?.start??-1;if(c.size===0||v===-1)return e;let S=Array.from(c).filter((p)=>!e.includes(`rel="prefetch" href="${p}"`)).map((p)=>`<link rel="prefetch" href="${p}" as="script">`).join("");if(!S)return e;return e.slice(0,v)+S+e.slice(v)}var It=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function Y(e){let n=e.trim();if(!n)return null;let s=/^https?:\/\//i.test(n)?n:`https://${n}`;try{return new URL(s).origin+new URL(s).pathname.replace(/\/$/,"")}catch{return null}}function Tt(e){for(let n of It){let s=e[n];if(!s)continue;let o=Y(s);if(o)return{url:o,source:"env",via:n}}return null}function dt(e){if(!e||typeof e!=="object")return null;let n=e,s=n.site?.url??n.url??n.app?.url;return typeof s==="string"?Y(s):null}async function At(e){let{existsSync:n}=await import("fs"),s=await import("path");for(let o of["site.config.ts","site.config.js",".config/site.config.ts"]){let c=s.resolve(e,o);if(!n(c))continue;try{let r=await import(c),u=dt(r.default??r);if(u)return u}catch{}}return null}async function gt(e={}){let n=e.cwd??process.cwd(),s=e.env??process.env;if(e.explicit){let u=Y(e.explicit);if(u)return{url:u,source:"option"}}let o=dt(e.stxConfig);if(o)return{url:o,source:"stx.config",via:"site.url"};let c=await At(n);if(c)return{url:c,source:"site.config",via:"url"};let r=Tt(s);if(r)return r;return{url:"http://localhost",source:"fallback"}}function pt(){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
|
+
`)}function V(e){return async()=>({paths:await e(),fallback:!1})}var Ot;function Ut(e){let n=t(e),{depths:s}=E(n),o=/\b(?:async\s+)?function\s+getStaticPaths\s*\(/g,c;while((c=o.exec(n))!==null){if(s[c.index]!==0)continue;let u=k(n,"(",")",o.lastIndex-1),g=n.indexOf("{",u+1),v=k(n,"{","}",g);if(u<0||g<0||v<0)break;return e.slice(c.index,v+1)}let r=/\b(?:const|let|var)\s+getStaticPaths\s*=/g;while((c=r.exec(n))!==null){if(s[c.index]!==0)continue;let u=Rl(n,r.lastIndex).endPos;return e.slice(r.lastIndex,u).trim()}throw SyntaxError("Could not extract getStaticPaths; use a top-level function or const declaration")}async function ft(e){let n="read";try{let s=await Bun.file(e).text();n="parse";let o=pn(s),c=[...o.server,...o.client,...o.signals].filter((r)=>/(?:^|\s)server(?:\s|=|$)/i.test(t(r.attrs))).sort((r,u)=>s.indexOf(r.fullTag)-s.indexOf(u.fullTag));for(let r of c){if(!/\bgetStaticPaths\b/.test(t(r.content)))continue;let u=(Ot??=new Bun.Transpiler({loader:"ts",target:"bun"})).transformSync(r.content);if(!/\bgetStaticPaths\b/.test(t(u)))continue;let g=Ut(u);if(/\bdefineStaticPaths\b/.test(t(g))&&zt(u,"defineStaticPaths"))throw SyntaxError("Cannot evaluate a module-local defineStaticPaths binding during isolated hook extraction");n="execute";let v=Function("defineStaticPaths",`return (${g})`)(V);if(typeof v!=="function")throw TypeError("getStaticPaths must be a function");let S=await v();n="result";let p=Array.isArray(S)?{paths:S}:S;if(!p||typeof p!=="object"||!("paths"in p)||!Array.isArray(p.paths))throw TypeError("getStaticPaths must return { paths: [...] } or an array of paths");for(let P of p.paths)if(!P||typeof P!=="object"||!P.params||typeof P.params!=="object"||Array.isArray(P.params))throw TypeError("Each getStaticPaths path must contain a params object");return{kind:"ok",value:p}}return{kind:"absent"}}catch(s){return{kind:"error",phase:n,error:s instanceof Error?s:Error(String(s))}}}class ht{cacheDir;cache=new Map;loaded=!1;salt;constructor(e,n=""){this.cacheDir=e,this.salt=n}async load(){if(this.loaded)return;let e=m.join(this.cacheDir,"build-cache.json");if(await Bun.file(e).exists())try{let n=JSON.parse(await Bun.file(e).text());for(let[s,o]of Object.entries(n))this.cache.set(s,o)}catch{}this.loaded=!0}async save(){await R.promises.mkdir(this.cacheDir,{recursive:!0});let e=m.join(this.cacheDir,"build-cache.json"),n={};for(let[s,o]of this.cache)n[s]=o;await Bun.write(e,JSON.stringify(n))}getHash(e,n){let s=R.statSync(e),o=`${this.salt}|${e}:${s.mtimeMs}`;for(let r of n)if(R.existsSync(r)){let u=R.statSync(r);o+=`:${r}:${u.mtimeMs}`}let c=0;for(let r=0;r<o.length;r++){let u=o.charCodeAt(r);c=(c<<5)-c+u,c=c&c}return Math.abs(c).toString(36)}get(e,n){let s=this.cache.get(e);if(!s)return null;let o=wt(n).some((u)=>R.existsSync(u)),c=[n,...s.dependencies??[]].some((u)=>u.endsWith(".stx")&&R.existsSync(u)&&As(R.readFileSync(u,"utf8")).some((g)=>/\bserver\b/.test(g.attrs)));if(o||c)return this.cache.delete(e),null;let r=this.getHash(n,s.dependencies??[]);if(s.hash!==r)return this.cache.delete(e),null;return s.html}set(e,n,s,o){let c=this.getHash(n,s);this.cache.set(e,{hash:c,html:o,generatedAt:Date.now(),dependencies:s})}}class mt{cacheDir;constructor(e){this.cacheDir=e}getFilePath(e){let n=e.replace(/[^a-zA-Z0-9]/g,"_")+".json";return m.join(this.cacheDir,"isr",n)}async get(e){let n=this.getFilePath(e);if(!await Bun.file(n).exists())return null;try{return JSON.parse(await Bun.file(n).text())}catch{return null}}async set(e,n){let s=this.getFilePath(e);await R.promises.mkdir(m.dirname(s),{recursive:!0}),await Bun.write(s,JSON.stringify(n))}async invalidate(e){let n=this.getFilePath(e);if(await Bun.file(n).exists())await R.promises.unlink(n)}async invalidatePattern(e){let n=m.join(this.cacheDir,"isr");if(!R.existsSync(n))return;let s=await R.promises.readdir(n);for(let o of s){let c=o.replace(/_/g,"/").replace(".json","");if(e.test(c))await R.promises.unlink(m.join(n,o))}}async needsRevalidation(e){let n=await this.get(e);if(!n)return!0;return Date.now()>n.revalidateAfter}}async function _t(e){let n=[];if(!e.isDynamic)n.push({url:e.pattern,params:{}});else{let s=await ft(e.filePath);if(s.kind==="error")throw Error(`getStaticPaths ${s.phase} failed for ${e.pattern} (${e.filePath}): ${s.error.message}`,{cause:s.error});if(s.kind==="absent")return console.warn(`Warning: Dynamic route ${e.pattern} (${e.filePath}) has no getStaticPaths`),n;let o=s.value;if(o.paths.length===0)return console.info(`getStaticPaths returned no paths for dynamic route ${e.pattern} (${e.filePath})`),n;for(let c of o.paths){let r=e.pattern;for(let[u,g]of Object.entries(c.params))r=r.replace(`:${u}`,g).replace(`:${u}*`,g);n.push({url:r,params:c.params,props:c.props,revalidate:c.revalidate})}}return n}function wt(e){return[e.replace(/\.stx$/,".data.ts"),e.replace(/\.stx$/,".data.js"),e+".data.ts",e+".data.js"]}async function Gt(e){for(let n of wt(e))if(await Bun.file(n).exists())try{let s=await import(n);if(typeof s.default==="function")return await s.default();else if(typeof s.default==="object")return s.default;else if(typeof s.getData==="function")return await s.getData();else{let{default:o,...c}=s;return c}}catch(s){console.error(`Error loading data file ${n}:`,s)}return null}async function Ht(e,n,s){let o=e.match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!o)return null;let c=o[1];if(!c.includes("getStaticProps"))return null;try{let r=c.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticProps\s*\([^)]*\)\s*\{([\s\S]*?)\n\}/);if(!r)return null;return await Function("params",`
|
|
4
4
|
return (async function getStaticProps() {
|
|
5
5
|
${r[1]}
|
|
6
6
|
})()
|
|
@@ -36,13 +36,13 @@ ${e.map((o)=>{let c=new URL(o.loc,n).href,r=` <url>
|
|
|
36
36
|
${s.join(`
|
|
37
37
|
`)}
|
|
38
38
|
</channel>
|
|
39
|
-
</rss>`}async function Xt(e={}){let n=Date.now();
|
|
39
|
+
</rss>`}async function Xt(e={}){let n=Date.now();gn();let s=await a(process.cwd()),o=s.build||{},c=await gt({explicit:e.domain||o.domain,stxConfig:s});if(c.source==="fallback"&&(e.sitemap??o.sitemap??!0))console.warn(pt());let r={router:e.router??s?.router??{},pagesDir:e.pagesDir||o.pagesDir||"pages",outputDir:e.outputDir||o.outputDir||"dist",baseUrl:e.baseUrl||o.baseUrl||"/",domain:c.url,revalidate:e.revalidate??o.revalidate??!1,sitemap:e.sitemap??o.sitemap??!0,sitemapExclude:e.sitemapExclude||o.sitemapExclude||[],robots:e.robots??o.robots??!0,rss:e.rss??o.rss??!1,concurrency:e.concurrency||o.concurrency||10,cache:e.cache??o.cache??!0,cacheDir:e.cacheDir||o.cacheDir||l(process.cwd(),"ssg-cache"),contentLoaders:e.contentLoaders||[],hooks:e.hooks||{},minify:e.minify??o.minify??!0,generate404:e.generate404??o.generate404??!0,publicDir:e.publicDir||o.publicDir||"public",trailingSlash:e.trailingSlash??o.trailingSlash??!1,cleanOutput:e.cleanOutput??o.cleanOutput??!0,cacheSalt:e.cacheSalt??"",partialsDir:e.partialsDir||s?.partialsDir||"",componentsDir:e.componentsDir||s?.componentsDir||"",failOnIncludeError:e.failOnIncludeError??!0,failOnServerScriptError:e.failOnServerScriptError??!0,chunkIslands:e.chunkIslands===!0,prefetchIslands:e.prefetchIslands===!0,integrityIslands:e.integrityIslands===!0},u={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},g=new Set,v=0,S={},p={};await r.hooks.onBuildStart?.();try{if(r.cleanOutput&&R.existsSync(r.outputDir))await R.promises.rm(r.outputDir,{recursive:!0});await R.promises.mkdir(r.outputDir,{recursive:!0});let I=r.cacheSalt;if(!I){let{resolveUserCssConfig:d,fingerprintConfig:y}=await import("./chunk-asnd03sr.js");try{I=y(await d(process.cwd()))}catch{}}let{prepareImageDelivery:b}=await import("./chunk-bwx6w87c.js"),C=await b(r.publicDir,r.outputDir);if(C.count>0)console.log(`Optimized ${C.count} image(s) for responsive delivery`),I=[I,C.fingerprint].filter(Boolean).join(":");let L=new ht(r.cacheDir,I);if(r.cache)await L.load();try{let{generateCss:d}=await import("./chunk-asnd03sr.js");await d('<div class="bg-black"></div>')}catch{}Mt();let St=s?.routeMiddleware?.dir||"middleware";await Lt(process.cwd(),St);let K=Dt();if(K.length>0)console.log(`Loaded ${K.length} middleware: ${K.join(", ")}`);let xt=s?.routeMiddleware?.global||[];_c(s?.layoutsDir,l(process.cwd()));let Q=ne(".",{pagesDir:r.pagesDir,pagesDirs:s?._layerPageDirs});console.log(`Found ${Q.length} routes`);let _=[];for(let d of Q)try{let y=await _t(d);for(let D of y)_.push({route:d,url:D.url,params:D.params,props:D.props,revalidate:D.revalidate??r.revalidate})}catch(y){let D=y instanceof Error?y:Error(String(y));u.failedCount++,u.errors.push({route:d.pattern,error:D}),await r.hooks.onError?.(D,d.pattern),console.error(`Error discovering paths for ${d.pattern}:`,D)}u.totalPages=_.length+u.failedCount,console.log(`Generating ${_.length} pages...`);let M=[],tt=[];for(let d=0;d<_.length;d+=r.concurrency)tt.push(_.slice(d,d+r.concurrency));for(let d of tt)await Promise.all(d.map(async(y)=>{let{route:D,url:h,params:G,props:bt,revalidate:it}=y;try{await r.hooks.onPageStart?.(h);let H=await Bun.file(D.filePath).text(),O=Qt(H),vt=O?.middleware?Array.isArray(O.middleware)?O.middleware:[O.middleware]:[],st=[...xt,...vt];if(st.length>0){let F=jt(h,G,O||{}),z=Bt(F,null,void 0,{isServer:!0}),T=await Ft(st,z);if(T.redirect){let B=typeof T.redirect==="string"?T.redirect:T.redirect.path||T.redirect,W=te(String(B),h),U=ee(h,r);await R.promises.mkdir(m.dirname(U),{recursive:!0}),await Bun.write(U,W),u.successCount++,u.pages.push({route:h,outputPath:U,size:Buffer.byteLength(W),cached:!1}),M.push({loc:h,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${h} \u2192 redirect to ${B}`);return}if(T.abort){let B=typeof T.abort==="string"?T.abort:T.abort?.error?.message||"aborted";console.warn(` \u21B3 ${h} \u2014 middleware aborted: ${B}`);return}}let at=O?.validate;if(typeof at==="function")try{if(!await at({params:G})){console.warn(`Validation failed for ${h}, skipping...`);return}}catch{}let j=null,ot=!1;if(r.cache){if(j=L.get(h,D.filePath),j)ot=!0,u.cachedCount++}if(!j){let F=await yt(D,G,bt,r,s);if(j=F.html,r.failOnIncludeError&&F.includeFailures.length>0)throw Error(`${F.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
|
40
40
|
${F.includeFailures.join(`
|
|
41
41
|
`)}
|
|
42
42
|
Set ssg.failOnIncludeError to false to build anyway.`);if(r.failOnServerScriptError&&F.serverScriptFailures.length>0)throw Error(`${F.serverScriptFailures.length} <script server> block(s) failed, so this page would have shipped with the content they produce missing:
|
|
43
43
|
${F.serverScriptFailures.join(`
|
|
44
44
|
`)}
|
|
45
|
-
Set ssg.failOnServerScriptError to false to build anyway.`);if(r.cache)L.set(h,D.filePath,F.dependencies,j)}let N;if(r.trailingSlash)N=m.join(r.outputDir,h,"index.html");else N=h==="/"?m.join(r.outputDir,"index.html"):m.join(r.outputDir,`${h}.html`);if(r.chunkIslands){let{html:F,chunks:z}=lt(j,{integrity:r.integrityIslands,minify:r.minify});if(z.length>0){let T=m.join(r.outputDir,"_stx","islands");await R.promises.mkdir(T,{recursive:!0});for(let B of z){let W=m.join(T,`${B.hash}.js`);if(!await Bun.file(W).exists())await Bun.write(W,B.code);if(!g.has(B.hash)){g.add(B.hash);let U=Buffer.byteLength(B.code,"utf8");v+=U,S[B.hash]={bytes:U,file:`/_stx/islands/${B.hash}.js`}}}if(p[h]=z.map((B)=>B.hash),j=F,r.prefetchIslands)j=ut(j)}}if(await R.promises.mkdir(m.dirname(N),{recursive:!0}),await Bun.write(N,j),!Jt(h,j,O,r.sitemapExclude))M.push({loc:h,lastmod:new Date().toISOString().split("T")[0],priority:h==="/"?1:0.8});let ct={route:h,outputPath:N,size:Buffer.byteLength(j,"utf8"),cached:ot};if(it!==!1)ct.revalidateAt=Date.now()+it*1000;u.pages.push(ct),u.successCount++,await r.hooks.onPageEnd?.(h,j)}catch(H){u.failedCount++,u.errors.push({route:h,error:H}),await r.hooks.onError?.(H,h),console.error(`Error generating ${h}:`,H)}}));let rt=
|
|
45
|
+
Set ssg.failOnServerScriptError to false to build anyway.`);if(r.cache)L.set(h,D.filePath,F.dependencies,j)}let N;if(r.trailingSlash)N=m.join(r.outputDir,h,"index.html");else N=h==="/"?m.join(r.outputDir,"index.html"):m.join(r.outputDir,`${h}.html`);if(r.chunkIslands){let{html:F,chunks:z}=lt(j,{integrity:r.integrityIslands,minify:r.minify});if(z.length>0){let T=m.join(r.outputDir,"_stx","islands");await R.promises.mkdir(T,{recursive:!0});for(let B of z){let W=m.join(T,`${B.hash}.js`);if(!await Bun.file(W).exists())await Bun.write(W,B.code);if(!g.has(B.hash)){g.add(B.hash);let U=Buffer.byteLength(B.code,"utf8");v+=U,S[B.hash]={bytes:U,file:`/_stx/islands/${B.hash}.js`}}}if(p[h]=z.map((B)=>B.hash),j=F,r.prefetchIslands)j=ut(j)}}if(await R.promises.mkdir(m.dirname(N),{recursive:!0}),await Bun.write(N,j),!Jt(h,j,O,r.sitemapExclude))M.push({loc:h,lastmod:new Date().toISOString().split("T")[0],priority:h==="/"?1:0.8});let ct={route:h,outputPath:N,size:Buffer.byteLength(j,"utf8"),cached:ot};if(it!==!1)ct.revalidateAt=Date.now()+it*1000;u.pages.push(ct),u.successCount++,await r.hooks.onPageEnd?.(h,j)}catch(H){u.failedCount++,u.errors.push({route:h,error:H}),await r.hooks.onError?.(H,h),console.error(`Error generating ${h}:`,H)}}));let rt=fn();if(rt.length>0){let d=rt.map((y)=>`${y.filePath}: ${y.message}`).join(`
|
|
46
46
|
`);throw Error(`Client script bundling failed:
|
|
47
47
|
${d}`)}if(r.cache)await L.save();if(r.generate404){let d=m.join(r.pagesDir,"404.stx");if(await Bun.file(d).exists()){let y=new Set,D={...s,minifyClient:!0,debug:!1,cache:!1},h=await i(await Bun.file(d).text(),{},d,D,y);await Bun.write(m.join(r.outputDir,"404.html"),h)}else await Bun.write(m.join(r.outputDir,"404.html"),`<!DOCTYPE html>
|
|
48
48
|
<html lang="en">
|
|
@@ -65,7 +65,7 @@ ${d}`)}if(r.cache)await L.save();if(r.generate404){let d=m.join(r.pagesDir,"404.
|
|
|
65
65
|
<a href="/">Go home</a>
|
|
66
66
|
</div>
|
|
67
67
|
</body>
|
|
68
|
-
</html>`)}for(let d of[500]){let y=m.join(r.pagesDir,`${d}.stx`);if(await Bun.file(y).exists()){let D=new Set,h={...s,minifyClient:!0,debug:!1,cache:!1},G=await i(await Bun.file(y).text(),{},y,h,D);await Bun.write(m.join(r.outputDir,`${d}.html`),G)}}let X=m.join(r.pagesDir,"error.stx");if(await Bun.file(X).exists()){let d=new Set,y={...s,minifyClient:!0,debug:!1,cache:!1},D=await i(await Bun.file(X).text(),{},X,y,d);await Bun.write(m.join(r.outputDir,"error.html"),D)}if(r.sitemap&&M.length>0){let d=Vt(M,r.domain),y=m.join(r.outputDir,"sitemap.xml");await Bun.write(y,d),u.sitemapPath=y,console.log(`Generated sitemap.xml with ${M.length} URLs`)}if(r.robots!==!1){let d=typeof r.robots==="object"?r.robots:{},y=[...r.sitemapExclude.filter((h)=>typeof h==="string"),...d.disallow||[]],D=
|
|
68
|
+
</html>`)}for(let d of[500]){let y=m.join(r.pagesDir,`${d}.stx`);if(await Bun.file(y).exists()){let D=new Set,h={...s,minifyClient:!0,debug:!1,cache:!1},G=await i(await Bun.file(y).text(),{},y,h,D);await Bun.write(m.join(r.outputDir,`${d}.html`),G)}}let X=m.join(r.pagesDir,"error.stx");if(await Bun.file(X).exists()){let d=new Set,y={...s,minifyClient:!0,debug:!1,cache:!1},D=await i(await Bun.file(X).text(),{},X,y,d);await Bun.write(m.join(r.outputDir,"error.html"),D)}if(r.sitemap&&M.length>0){let d=Vt(M,r.domain),y=m.join(r.outputDir,"sitemap.xml");await Bun.write(y,d),u.sitemapPath=y,console.log(`Generated sitemap.xml with ${M.length} URLs`)}if(r.robots!==!1){let d=typeof r.robots==="object"?r.robots:{},y=[...r.sitemapExclude.filter((h)=>typeof h==="string"),...d.disallow||[]],D=Vs({rules:[{userAgent:d.userAgent||"*",allow:d.allow||["/"],...y.length>0?{disallow:y}:{}}],...d.sitemap!==!1&&u.sitemapPath?{sitemap:new URL("/sitemap.xml",r.domain).href}:{}});await Bun.write(m.join(r.outputDir,"robots.txt"),D),console.log("Generated robots.txt")}if(r.rss){let d=typeof r.rss==="object"?r.rss:{title:"Site Feed",description:"Latest updates",link:r.domain},y=[];if(d.getItems)y=await d.getItems();let D=Kt(d,y),h=m.join(r.outputDir,"rss.xml");await Bun.write(h,D),u.rssPath=h,console.log(`Generated rss.xml with ${y.length} items`)}let q=Sc(r.outputDir);if(q.assets>0)console.log(`Externalized ${q.assets} asset(s) from ${q.pages} page(s) (${(q.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);let J=kc(r.outputDir);if(J.assets>0)console.log(`Externalized ${J.assets} repeated asset(s) from ${J.pages} page(s) (${(J.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);if(r.publicDir&&R.existsSync(r.publicDir))await Z(r.publicDir,r.outputDir),console.log(`Copied public assets from ${r.publicDir}`);let nt=pr();if(nt)await Z(nt,m.join(r.outputDir,dr)),console.log(`Copied assets from ${dn}`)}catch(I){throw await r.hooks.onError?.(I),I}if(u.buildTime=Date.now()-n,g.size>0){u.islandChunks={count:g.size,totalBytes:v};let I={generatedChunks:g.size,totalBytes:v,chunks:S,pages:p};await Bun.write(m.join(r.outputDir,"_stx","islands-manifest.json"),JSON.stringify(I,null,2))}await r.hooks.onBuildEnd?.(u);let P=u.islandChunks?`
|
|
69
69
|
Island chunks: ${u.islandChunks.count} (${(u.islandChunks.totalBytes/1024).toFixed(1)} KB lifted out of inline HTML)`:"";return console.log(`
|
|
70
70
|
Build complete!
|
|
71
71
|
Total: ${u.totalPages} pages
|