@stacksjs/stx 0.2.582 → 0.2.584
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-qazn64pm.js → chunk-03qf2z4d.js} +1 -1
- package/dist/{chunk-yk3fbzx5.js → chunk-07869zev.js} +4 -4
- package/dist/chunk-08g5j4fq.js +2 -0
- package/dist/chunk-0hpw65yr.js +2 -0
- package/dist/chunk-11jmasqb.js +2 -0
- package/dist/chunk-2c7ysn9s.js +2 -0
- package/dist/chunk-2wb1w0p6.js +2 -0
- package/dist/chunk-2wx2aczp.js +2 -0
- package/dist/chunk-325dn55d.js +4 -0
- package/dist/chunk-34kxj258.js +2 -0
- package/dist/{chunk-ktyctev3.js → chunk-3y5tzxm6.js} +2 -2
- package/dist/{chunk-h0a2s340.js → chunk-49xtxzr8.js} +2 -2
- package/dist/chunk-4efqcpg5.js +2 -0
- package/dist/{chunk-5kh5ehfh.js → chunk-4h58as2c.js} +2 -2
- package/dist/chunk-4k6h00kk.js +2 -0
- package/dist/{chunk-y8q1n7hx.js → chunk-4myvw20e.js} +10 -10
- package/dist/chunk-4szz2esp.js +2 -0
- package/dist/chunk-4wkghwag.js +2 -0
- package/dist/chunk-53grq69s.js +2 -0
- package/dist/chunk-55n8mhq4.js +2 -0
- package/dist/chunk-5s229r1e.js +2 -0
- package/dist/chunk-5zg3xj45.js +18 -0
- package/dist/{chunk-hzfhn2vr.js → chunk-67m2prah.js} +2 -2
- package/dist/chunk-6djvj6hg.js +2 -0
- package/dist/chunk-6ebj7gfr.js +2 -0
- package/dist/{chunk-g4crr86j.js → chunk-6hgngmn0.js} +3 -3
- package/dist/chunk-71tnfe1n.js +2 -0
- package/dist/{chunk-101ekf6y.js → chunk-794v5crp.js} +2 -2
- package/dist/chunk-7dkwf9h5.js +2 -0
- package/dist/{chunk-cnknvvwm.js → chunk-7fghm9zy.js} +1 -1
- package/dist/{chunk-ayy9mmrw.js → chunk-7ra30crf.js} +7 -7
- package/dist/{chunk-117xss52.js → chunk-7xw1e8t6.js} +2 -2
- package/dist/{chunk-c0s3k64c.js → chunk-7ydavm3h.js} +2 -2
- package/dist/{chunk-qdyp2zqf.js → chunk-82bttwqm.js} +2 -2
- package/dist/chunk-8992smwz.js +2 -0
- package/dist/{chunk-0vnngvy1.js → chunk-8s7zbhdd.js} +4 -4
- package/dist/chunk-8zn83jfs.js +2 -0
- package/dist/{chunk-zz02hwec.js → chunk-96zgn94z.js} +26 -26
- package/dist/{chunk-43h8q2cm.js → chunk-9cpxzze0.js} +9 -9
- package/dist/{chunk-vx75fb0d.js → chunk-9e091vkf.js} +3 -3
- package/dist/chunk-9pk5jhqa.js +3 -0
- package/dist/{chunk-dvgvvy5b.js → chunk-9r5w6s80.js} +3 -3
- package/dist/{chunk-c0h2eqe0.js → chunk-a8n6mt7s.js} +2 -2
- package/dist/{chunk-djft0m5h.js → chunk-agy4mxn8.js} +2 -2
- package/dist/{chunk-ev5f79mg.js → chunk-axz1x4r9.js} +5 -5
- package/dist/{chunk-6w2yqtrd.js → chunk-b5van393.js} +2 -2
- package/dist/{chunk-w3rmepwy.js → chunk-bfbmdjh4.js} +2 -2
- package/dist/chunk-bqtph83n.js +2 -0
- package/dist/chunk-bs1bdhvp.js +2 -0
- package/dist/{chunk-0k5faspy.js → chunk-bsy10tz6.js} +6 -6
- package/dist/chunk-c1c4sh7t.js +2 -0
- package/dist/{chunk-zk2xk0wd.js → chunk-c6egfhy6.js} +2 -2
- package/dist/chunk-ce2d0hz9.js +2 -0
- package/dist/chunk-cjq9k1xb.js +2 -0
- package/dist/{chunk-k9th7hc4.js → chunk-d2jb1rkp.js} +5 -5
- package/dist/{chunk-yfq2v7x5.js → chunk-d4awfk42.js} +7 -7
- package/dist/chunk-d9vjsqs4.js +2 -0
- package/dist/{chunk-8v19753h.js → chunk-e26pzdxy.js} +1 -1
- package/dist/{chunk-nrfh7gaa.js → chunk-e556dvy4.js} +3 -3
- package/dist/{chunk-3qrrv6af.js → chunk-e6h7pzym.js} +1 -1
- package/dist/{chunk-cb2pyg5t.js → chunk-ebfpjnf3.js} +2 -2
- package/dist/chunk-ede39b7h.js +3 -0
- package/dist/chunk-f0fxyh3e.js +2 -0
- package/dist/{chunk-4srg0qbv.js → chunk-f29fk7dw.js} +2 -2
- package/dist/chunk-fjyhc41r.js +2 -0
- package/dist/{chunk-1v1mew46.js → chunk-fkq55rh7.js} +1 -1
- package/dist/chunk-fn4wwgnc.js +2 -0
- package/dist/{chunk-t8wpzqs4.js → chunk-g8mxprxj.js} +1 -1
- package/dist/chunk-h2534p6q.js +2 -0
- package/dist/{chunk-9jh2ake5.js → chunk-h7atbtds.js} +5 -5
- package/dist/{chunk-yy3ser06.js → chunk-h988fxh3.js} +5 -5
- package/dist/chunk-hr34x6sx.js +2 -0
- package/dist/{chunk-ta3wn842.js → chunk-hsy9rhct.js} +2 -2
- package/dist/chunk-hygxh993.js +2 -0
- package/dist/{chunk-s12bnv32.js → chunk-hz11wmx9.js} +2 -2
- package/dist/{chunk-71sdgv7e.js → chunk-j7kcjgxy.js} +215 -56
- package/dist/chunk-j87tntna.js +2 -0
- package/dist/{chunk-tszkg6sj.js → chunk-jqbk6pfk.js} +2 -2
- package/dist/{chunk-be2ba3hj.js → chunk-k1szsenr.js} +2 -2
- package/dist/{chunk-3wy8q3aq.js → chunk-k3rnpjxf.js} +5 -5
- package/dist/{chunk-jtbzmbzz.js → chunk-k71e38fk.js} +4 -4
- package/dist/chunk-kgtnfvqb.js +2 -0
- package/dist/chunk-krwrx9x9.js +2 -0
- package/dist/{chunk-t61vdbje.js → chunk-ktvr45qg.js} +6 -6
- package/dist/{chunk-4rkvwm6v.js → chunk-m3w67x05.js} +9 -9
- package/dist/chunk-m5j8hht5.js +2 -0
- package/dist/chunk-mc8j6dwa.js +2 -0
- package/dist/{chunk-vpdx7qr3.js → chunk-mmbspaqh.js} +2 -2
- package/dist/{chunk-pmpb34md.js → chunk-n0t938d2.js} +7 -7
- package/dist/{chunk-c1r7zq0q.js → chunk-n2gy2arh.js} +89 -89
- package/dist/chunk-n2j3pn9s.js +2 -0
- package/dist/{chunk-sv5nvfmb.js → chunk-np6nm4rq.js} +2 -2
- package/dist/chunk-ns1jqzqk.js +2 -0
- package/dist/chunk-p973efbe.js +2 -0
- package/dist/{chunk-m8tm44rq.js → chunk-pg164sdw.js} +2 -2
- package/dist/{chunk-yhpyqsbr.js → chunk-pxw4edw8.js} +4 -4
- package/dist/{chunk-1r1maqep.js → chunk-q1cvef6b.js} +3 -3
- package/dist/chunk-q765v7b2.js +2 -0
- package/dist/{chunk-620szfcp.js → chunk-qebxzf9w.js} +3 -3
- package/dist/{chunk-jpqkm8tm.js → chunk-qf3axv86.js} +3 -3
- package/dist/{chunk-7hkc96de.js → chunk-qhr1tkhj.js} +7 -7
- package/dist/chunk-qq59xzwc.js +2 -0
- package/dist/chunk-r0e743c3.js +2 -0
- package/dist/{chunk-qccgncp2.js → chunk-rdm5mfc5.js} +6 -6
- package/dist/chunk-s043hpvd.js +2 -0
- package/dist/{chunk-rr8a7d4q.js → chunk-s1ptn02h.js} +3 -3
- package/dist/{chunk-xpnpg967.js → chunk-s5vxxwg6.js} +2 -2
- package/dist/chunk-sckze59r.js +2 -0
- package/dist/chunk-sjkdpsca.js +3 -0
- package/dist/chunk-sr1md7vv.js +2845 -0
- package/dist/chunk-t431anrx.js +2 -0
- package/dist/chunk-t7mxbt40.js +2 -0
- package/dist/{chunk-r47cs92n.js → chunk-tc15vkfh.js} +2 -2
- package/dist/{chunk-6z3e1tyz.js → chunk-tnafnb23.js} +1 -1
- package/dist/{chunk-ah9xyss2.js → chunk-v8ze2q95.js} +2 -2
- package/dist/{chunk-t4g2fptt.js → chunk-vf15db1j.js} +6 -6
- package/dist/chunk-vvqxbhfx.js +2 -0
- package/dist/{chunk-cdgwkzms.js → chunk-w24qmxc3.js} +3 -3
- package/dist/chunk-w7zgftez.js +2 -0
- package/dist/chunk-wfp36qf4.js +2 -0
- package/dist/chunk-wn2gzwmv.js +2 -0
- package/dist/{chunk-wwj8zbzc.js → chunk-wywprjc5.js} +5 -5
- package/dist/chunk-x5qymgxa.js +2 -0
- package/dist/chunk-xfe2nzxd.js +2 -0
- package/dist/chunk-xjwgzp6s.js +2 -0
- package/dist/chunk-xyepqdjy.js +2 -0
- package/dist/chunk-y5ryjdpv.js +122 -0
- package/dist/{chunk-3e3dpp7w.js → chunk-y5x8xnnf.js} +3 -3
- package/dist/{chunk-74j18qk0.js → chunk-y8h823cb.js} +28 -28
- package/dist/chunk-yhqaafsw.js +2 -0
- package/dist/chunk-yn2d8x8m.js +3 -0
- package/dist/{chunk-kp0hg06s.js → chunk-z2mg470f.js} +4 -4
- package/dist/chunk-z7trbwn3.js +2 -0
- package/dist/{chunk-eww6sdzz.js → chunk-zgv1h2np.js} +2 -2
- package/dist/{chunk-bj29pwm0.js → chunk-zrw1zf54.js} +3 -3
- package/dist/chunk-zxf8f71v.js +2 -0
- package/dist/chunk-zxt75k06.js +2 -0
- package/dist/cli.js +46 -46
- package/dist/client/signals-authoring-runtime.js +13 -6
- package/dist/client/signals-binding-utils-runtime.js +14 -1
- package/dist/client/signals-component-api-runtime.js +3 -1
- package/dist/client/signals-event-shorthand-runtime.js +1 -1
- package/dist/client/signals-expression-runtime.js +1 -1
- package/dist/client/signals-host-runtime.js +72 -1
- package/dist/client/signals-manifest-hydration-runtime.js +20 -0
- package/dist/client/signals-model-runtime.js +2 -0
- package/dist/client/signals-mount-runtime.js +5 -1
- package/dist/client/signals-overlay-runtime.js +29 -6
- package/dist/client/signals-process-element-runtime.js +22 -7
- package/dist/client/signals-public-api-runtime.js +2 -0
- package/dist/client/signals-style-runtime.js +1 -1
- package/dist/component-model.d.ts +1 -1
- package/dist/component-model.js +6 -3
- package/dist/component-renderer.js +26 -6
- package/dist/composition-api.js +3 -2
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/native/compiler/bundle.js +8 -3
- package/dist/native/compiler/design-tokens.d.ts +4 -0
- package/dist/native/compiler/design-tokens.js +28 -0
- package/dist/native/compiler/headwind-to-style.d.ts +5 -4
- package/dist/native/compiler/headwind-to-style.js +105 -65
- package/dist/native/compiler/html-to-ir.d.ts +5 -1
- package/dist/native/compiler/html-to-ir.js +75 -244
- package/dist/native/compiler/inline-style.d.ts +13 -0
- package/dist/native/compiler/inline-style.js +285 -0
- package/dist/native/compiler/ir.d.ts +5 -1
- package/dist/native/compiler/render-screen.js +3 -1
- package/dist/native/compiler/style-variables.d.ts +8 -0
- package/dist/native/compiler/style-variables.js +142 -0
- package/dist/native/compiler/stylesheet-theme.d.ts +6 -0
- package/dist/native/compiler/stylesheet-theme.js +110 -0
- package/dist/native/runtime/binding-tree.js +12 -0
- package/dist/native/runtime/craft-bridge.js +5 -2
- package/dist/native/runtime/jsc-globals.d.ts +10 -3
- package/dist/native/runtime/jsc-globals.js +23 -4
- package/dist/native/runtime/native-host.d.ts +17 -2
- package/dist/native/runtime/native-host.js +492 -39
- package/dist/native/runtime/overlay-presenter.d.ts +29 -0
- package/dist/native/runtime/overlay-presenter.js +69 -0
- package/dist/native/runtime/shared-screen.js +13 -1
- package/dist/native/runtime/view-operations.d.ts +20 -0
- package/dist/native/runtime/view-operations.js +35 -0
- package/dist/native/testing-mutations.d.ts +4 -0
- package/dist/native/testing-mutations.js +64 -0
- package/dist/native/testing.d.ts +2 -0
- package/dist/native/testing.js +19 -2
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +8 -8
- package/dist/testing.js +2 -0
- package/dist/types/config-types.d.ts +2 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +25 -5
- package/package.json +5 -5
- package/dist/chunk-0047meje.js +0 -2
- package/dist/chunk-00p22wzr.js +0 -3
- package/dist/chunk-1cat8kdj.js +0 -2
- package/dist/chunk-1dwnp35v.js +0 -2
- package/dist/chunk-2dnr5qfk.js +0 -2
- package/dist/chunk-2rx9d75e.js +0 -4
- package/dist/chunk-2v73cjbc.js +0 -2
- package/dist/chunk-30rf7k4n.js +0 -122
- package/dist/chunk-3akgppsy.js +0 -2
- package/dist/chunk-3x6p9me0.js +0 -2
- package/dist/chunk-4t67wmcg.js +0 -2
- package/dist/chunk-51zn42jy.js +0 -2
- package/dist/chunk-5702x95v.js +0 -2
- package/dist/chunk-5db5sxy3.js +0 -3
- package/dist/chunk-5pgbsc3a.js +0 -2
- package/dist/chunk-60c2bsh9.js +0 -2
- package/dist/chunk-79v4d9qh.js +0 -2
- package/dist/chunk-7pp2vx1g.js +0 -2
- package/dist/chunk-84f9dnq5.js +0 -2
- package/dist/chunk-8tq5x4z8.js +0 -2
- package/dist/chunk-8zm6tkqb.js +0 -2
- package/dist/chunk-a1z36dt5.js +0 -2
- package/dist/chunk-atsf1fe0.js +0 -2
- package/dist/chunk-b8qd6h1q.js +0 -2
- package/dist/chunk-ccxs40xy.js +0 -2
- package/dist/chunk-cg8hg6cs.js +0 -3
- package/dist/chunk-cp442y7a.js +0 -2
- package/dist/chunk-d4en5d3s.js +0 -2
- package/dist/chunk-dh80d57p.js +0 -2
- package/dist/chunk-dpn1pmxj.js +0 -2
- package/dist/chunk-dtcc09x1.js +0 -2
- package/dist/chunk-dyqte1xq.js +0 -2
- package/dist/chunk-e4n4v022.js +0 -2
- package/dist/chunk-efgk2xv1.js +0 -2
- package/dist/chunk-faghmmrs.js +0 -2838
- package/dist/chunk-fj70wq7k.js +0 -2
- package/dist/chunk-g2fw68zm.js +0 -2
- package/dist/chunk-hcgm37dy.js +0 -2
- package/dist/chunk-hd2bn5q7.js +0 -2
- package/dist/chunk-j1nqnmcd.js +0 -18
- package/dist/chunk-k7jqkt93.js +0 -2
- package/dist/chunk-mhjwtkx9.js +0 -2
- package/dist/chunk-mqy7g74k.js +0 -2
- package/dist/chunk-mxe21m6q.js +0 -2
- package/dist/chunk-ne03tfje.js +0 -2
- package/dist/chunk-p2sns0bn.js +0 -2
- package/dist/chunk-q2a58n2a.js +0 -2
- package/dist/chunk-s1sycp43.js +0 -2
- package/dist/chunk-s932zfjz.js +0 -2
- package/dist/chunk-sp46w7z9.js +0 -2
- package/dist/chunk-sy1bk1ry.js +0 -2
- package/dist/chunk-t48ws5j0.js +0 -2
- package/dist/chunk-thbc9gtj.js +0 -2
- package/dist/chunk-tn9v10q2.js +0 -2
- package/dist/chunk-tpd5nwa3.js +0 -2
- package/dist/chunk-tpt4bgs5.js +0 -2
- package/dist/chunk-v8p5p2kp.js +0 -2
- package/dist/chunk-v9jd283e.js +0 -2
- package/dist/chunk-vq0cb1m9.js +0 -2
- package/dist/chunk-wg2w7zmt.js +0 -3
- package/dist/chunk-wgkxgsqx.js +0 -2
- package/dist/chunk-y1bppxgw.js +0 -2
- package/dist/chunk-yv5rwthv.js +0 -2
- package/dist/chunk-yygze2s0.js +0 -2
- package/dist/chunk-z1r4tdqy.js +0 -2
- package/dist/chunk-z732tf98.js +0 -2
- package/dist/chunk-zv288w4e.js +0 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NativeFocusOptions } from './view-operations';
|
|
2
|
+
import type { NativeNode } from './native-host';
|
|
3
|
+
export declare function createNativeOverlayPresenter(host: OverlayHost): NativeOverlayPresenter;
|
|
4
|
+
/** Overlay policy stays in the shared runtime; this adapter presents native Modal nodes. */
|
|
5
|
+
export declare interface NativeOverlayEntry {
|
|
6
|
+
id: string
|
|
7
|
+
root: NativeNode | null
|
|
8
|
+
modal: boolean
|
|
9
|
+
zIndex?: number | null
|
|
10
|
+
panel?: FocusTarget
|
|
11
|
+
initialFocus?: FocusTarget
|
|
12
|
+
onRequestClose?: ((event?: unknown) => void) | null
|
|
13
|
+
}
|
|
14
|
+
declare interface OverlayHost {
|
|
15
|
+
canFocus: boolean
|
|
16
|
+
focus: (node: NativeNode, options: NativeFocusOptions) => Promise<true>
|
|
17
|
+
descendants: (node: NativeNode) => NativeNode[]
|
|
18
|
+
hasAutofocus: (node: NativeNode) => boolean
|
|
19
|
+
isAvailable: (node: NativeNode) => boolean
|
|
20
|
+
type: (node: NativeNode) => string | undefined
|
|
21
|
+
setAttribute: (node: NativeNode, name: string, value: unknown) => void
|
|
22
|
+
setStyle: (node: NativeNode, style: Record<string, unknown>) => void
|
|
23
|
+
listen: (node: NativeNode, event: string, callback: (event?: unknown) => void) => void
|
|
24
|
+
}
|
|
25
|
+
export declare interface NativeOverlayPresenter {
|
|
26
|
+
sync: (entries: NativeOverlayEntry[]) => void
|
|
27
|
+
dispose: () => void
|
|
28
|
+
}
|
|
29
|
+
declare type FocusTarget = NativeNode | (() => NativeNode | null) | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export function createNativeOverlayPresenter(host) {
|
|
2
|
+
let current = [];
|
|
3
|
+
const listening = new WeakSet;
|
|
4
|
+
let focusing = null;
|
|
5
|
+
function focusInitial(entry) {
|
|
6
|
+
if (!host.canFocus) {
|
|
7
|
+
if (entry.initialFocus)
|
|
8
|
+
console.warn(`[stx:overlays] Native initialFocus for "${entry.id}" requires viewFocus support; focus was not moved.`);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const controller = focusing = new AbortController;
|
|
12
|
+
queueMicrotask(async () => {
|
|
13
|
+
if (controller.signal.aborted || current.at(-1)?.root !== entry.root)
|
|
14
|
+
return;
|
|
15
|
+
try {
|
|
16
|
+
const resolve = (value) => typeof value === "function" ? value() : value ?? null, panel = resolve(entry.panel) ?? entry.root, explicit = resolve(entry.initialFocus), candidates = [panel, ...host.descendants(panel)].filter((node) => host.isAvailable(node)), target = explicit ?? candidates.find((node) => host.hasAutofocus(node)) ?? candidates.find((node) => ["TextInput", "Button", "Pressable", "Checkbox", "Switch", "Picker", "Slider", "Link"].includes(host.type(node) ?? "")) ?? (host.isAvailable(panel) ? panel : null);
|
|
17
|
+
if (!target || !host.isAvailable(target)) {
|
|
18
|
+
if (explicit)
|
|
19
|
+
console.warn(`[stx:overlays] Native initialFocus for "${entry.id}" must reference a mounted, visible, enabled view; focus was not moved.`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await host.focus(target, { mode: host.type(target) === "TextInput" ? "keyboard" : "accessibility", signal: controller.signal });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (!controller.signal.aborted)
|
|
25
|
+
console.warn(`[stx:overlays] Native focus failed for "${entry.id}": ${error instanceof Error ? error.message : String(error)}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function sync(entries) {
|
|
30
|
+
for (const entry of entries)
|
|
31
|
+
if (!entry.root || host.type(entry.root) !== "Modal" || !entry.modal)
|
|
32
|
+
throw Error(`[stx:overlays] Native overlay "${entry.id}" requires a Modal root (data-native="Modal"). Anchored/non-modal popups require a host positioning capability.`);
|
|
33
|
+
const previous = current;
|
|
34
|
+
current = entries.slice();
|
|
35
|
+
for (const entry of previous)
|
|
36
|
+
if (!current.some((next) => next.root === entry.root))
|
|
37
|
+
host.setAttribute(entry.root, "visible", !1);
|
|
38
|
+
for (const [index, entry] of current.entries()) {
|
|
39
|
+
const root = entry.root;
|
|
40
|
+
if (!listening.has(root)) {
|
|
41
|
+
listening.add(root);
|
|
42
|
+
host.listen(root, "request-close", (event) => {
|
|
43
|
+
const top = current.at(-1);
|
|
44
|
+
try {
|
|
45
|
+
if (top?.root === root)
|
|
46
|
+
top.onRequestClose?.(event);
|
|
47
|
+
} finally {
|
|
48
|
+
if (current.some((active) => active.root === root))
|
|
49
|
+
host.setAttribute(root, "visible", !0);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
host.setAttribute(root, "visible", !0);
|
|
54
|
+
host.setStyle(root, { zIndex: (entry.zIndex ?? 1000) + index });
|
|
55
|
+
}
|
|
56
|
+
const top = current.at(-1);
|
|
57
|
+
if (top?.root !== previous.at(-1)?.root) {
|
|
58
|
+
focusing?.abort();
|
|
59
|
+
focusing = null;
|
|
60
|
+
if (top && !previous.some((entry) => entry.root === top.root))
|
|
61
|
+
focusInitial(top);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { sync, dispose() {
|
|
65
|
+
focusing?.abort();
|
|
66
|
+
focusing = null;
|
|
67
|
+
current = [];
|
|
68
|
+
} };
|
|
69
|
+
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
import { createNode } from "../compiler/ir.js";
|
|
1
2
|
import { STXBridge } from "../bridge/protocol.js";
|
|
2
3
|
import { materializeNativeBindingTree } from "./binding-tree.js";
|
|
3
4
|
import { installCraftBridge } from "./craft-bridge.js";
|
|
4
5
|
import { createNativeHost } from "./native-host.js";
|
|
6
|
+
import { createNativeViewOperations, nativeViewError } from "./view-operations.js";
|
|
5
7
|
export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
|
|
6
|
-
let revision = 0, generation = 0;
|
|
8
|
+
let revision = 0, generation = 0, rendered = !1;
|
|
7
9
|
const protocol = new STXBridge;
|
|
8
10
|
protocol.initialize(bridge);
|
|
9
11
|
installCraftBridge(protocol, bridge, globalThis, options);
|
|
10
12
|
const host = createNativeHost({
|
|
13
|
+
views: createNativeViewOperations(protocol, bridge.capabilities ?? [], () => {
|
|
14
|
+
if (!rendered)
|
|
15
|
+
throw nativeViewError("VIEW_NOT_MOUNTED", "The native screen has not rendered");
|
|
16
|
+
}),
|
|
11
17
|
colorScheme: bridge.colorScheme === "dark" ? "dark" : "light",
|
|
18
|
+
stylesheetTheme: document.root._stylesheetTheme,
|
|
12
19
|
send(operations) {
|
|
13
20
|
const baseRevision = revision;
|
|
14
21
|
revision++;
|
|
@@ -28,6 +35,8 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
|
|
|
28
35
|
host.setColorScheme(scheme);
|
|
29
36
|
}
|
|
30
37
|
});
|
|
38
|
+
if (manifest.entries.find((entry) => entry.id === document.root.bindingId)?.bindings.some((binding) => binding.kind === "if" || binding.kind === "for"))
|
|
39
|
+
document = { ...document, root: createNode("View", {}, { flex: 1 }, {}, [document.root]) };
|
|
31
40
|
const tree = materializeNativeBindingTree(document, manifest, host);
|
|
32
41
|
let dispose = null;
|
|
33
42
|
protocol.on("MUTATION_ERROR", (message) => {
|
|
@@ -53,11 +62,14 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
|
|
|
53
62
|
dispose?.();
|
|
54
63
|
dispose = runtime.hydrateHost(tree.root, setup, manifest, tree.nodes);
|
|
55
64
|
protocol.render(document.root);
|
|
65
|
+
rendered = !0;
|
|
56
66
|
host.flush();
|
|
57
67
|
},
|
|
58
68
|
unmount() {
|
|
69
|
+
rendered = !1;
|
|
59
70
|
dispose?.();
|
|
60
71
|
dispose = null;
|
|
72
|
+
host.dispose();
|
|
61
73
|
protocol.dispose("screen-closed");
|
|
62
74
|
}
|
|
63
75
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { STXBridge } from '../bridge/protocol';
|
|
2
|
+
export declare function nativeViewError(code: string, message: string): Error & { code: string };
|
|
3
|
+
/** Craft #373: stable node ids and logical viewport coordinates, not DOM geometry. */
|
|
4
|
+
export declare function createNativeViewOperations(protocol: Pick<STXBridge, 'callNativeAPI'>, capabilities: readonly string[], beforeRequest: () => void): NativeViewOperations;
|
|
5
|
+
export declare interface NativeFocusOptions { mode?: 'keyboard' | 'accessibility', signal?: AbortSignal }
|
|
6
|
+
export declare interface NativeViewBounds {
|
|
7
|
+
x: number
|
|
8
|
+
y: number
|
|
9
|
+
width: number
|
|
10
|
+
height: number
|
|
11
|
+
viewportWidth: number
|
|
12
|
+
viewportHeight: number
|
|
13
|
+
unit: 'points' | 'dp'
|
|
14
|
+
coordinateSpace: 'screenViewport'
|
|
15
|
+
}
|
|
16
|
+
export declare interface NativeViewOperations {
|
|
17
|
+
readonly capabilities: { focus: boolean, measure: boolean }
|
|
18
|
+
focus: (nodeId: string, options?: NativeFocusOptions) => Promise<true>
|
|
19
|
+
measure: (nodeId: string) => Promise<NativeViewBounds>
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function nativeViewError(code, message) {
|
|
2
|
+
return Object.assign(Error(message), { code });
|
|
3
|
+
}
|
|
4
|
+
export function createNativeViewOperations(protocol, capabilities, beforeRequest) {
|
|
5
|
+
const supported = new Set(capabilities);
|
|
6
|
+
function prepare(capability) {
|
|
7
|
+
if (!supported.has(capability))
|
|
8
|
+
throw nativeViewError("UNSUPPORTED", `This Craft host does not advertise ${capability}`);
|
|
9
|
+
beforeRequest();
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
capabilities: { focus: supported.has("viewFocus"), measure: supported.has("viewMeasure") },
|
|
13
|
+
async focus(nodeId, options = {}) {
|
|
14
|
+
if (options.signal?.aborted)
|
|
15
|
+
throw nativeViewError("CANCELLED", "Native focus was cancelled");
|
|
16
|
+
const mode = options.mode ?? "keyboard";
|
|
17
|
+
if (mode !== "keyboard" && mode !== "accessibility")
|
|
18
|
+
throw nativeViewError("INVALID_ARGUMENT", "View.focus mode must be keyboard or accessibility");
|
|
19
|
+
prepare("viewFocus");
|
|
20
|
+
const result = await protocol.callNativeAPI("View", "focus", { nodeId, mode });
|
|
21
|
+
if (options.signal?.aborted)
|
|
22
|
+
throw nativeViewError("CANCELLED", "Native focus was cancelled");
|
|
23
|
+
if (result !== !0)
|
|
24
|
+
throw nativeViewError("INVALID_RESPONSE", "View.focus did not confirm focus");
|
|
25
|
+
return !0;
|
|
26
|
+
},
|
|
27
|
+
async measure(nodeId) {
|
|
28
|
+
prepare("viewMeasure");
|
|
29
|
+
const box = await protocol.callNativeAPI("View", "measure", { nodeId });
|
|
30
|
+
if (!box || !["x", "y", "width", "height", "viewportWidth", "viewportHeight"].every((key) => typeof box[key] === "number" && Number.isFinite(box[key])) || box.width < 0 || box.height < 0 || box.viewportWidth < 0 || box.viewportHeight < 0 || !["points", "dp"].includes(box.unit) || box.coordinateSpace !== "screenViewport")
|
|
31
|
+
throw nativeViewError("INVALID_RESPONSE", "View.measure returned invalid viewport bounds");
|
|
32
|
+
return box;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NativeNode, NativeOperation } from './testing';
|
|
2
|
+
/** Preflight topology on a copy: a rejected batch must never partially alter the test phone. */
|
|
3
|
+
export declare function validateTestMutations(source: Map<string, NativeNode>, operations: NativeOperation[]): TestMutationError | null;
|
|
4
|
+
export declare interface TestMutationError { code: string, message: string, operationIndex: number }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export function validateTestMutations(source, operations) {
|
|
2
|
+
const containers = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "Modal", "Pressable", "TouchableOpacity", "TouchableHighlight", "ImageBackground", "FlatList", "SectionList", "Fragment", "Svg", "G", "Map"].map((type) => type.toLowerCase())), nodes = new Map([...source].map(([id, node]) => [id, {
|
|
3
|
+
type: node.type,
|
|
4
|
+
parent: null,
|
|
5
|
+
children: node.children.filter((child) => typeof child !== "string").map((child) => child.id)
|
|
6
|
+
}]));
|
|
7
|
+
for (const [id, node] of nodes)
|
|
8
|
+
for (const child of node.children) {
|
|
9
|
+
const entry = nodes.get(child);
|
|
10
|
+
if (entry)
|
|
11
|
+
entry.parent = id;
|
|
12
|
+
}
|
|
13
|
+
const drop = (id) => {
|
|
14
|
+
const node = nodes.get(id);
|
|
15
|
+
if (!node)
|
|
16
|
+
return;
|
|
17
|
+
node.children.forEach(drop);
|
|
18
|
+
nodes.delete(id);
|
|
19
|
+
};
|
|
20
|
+
for (const [operationIndex, op] of operations.entries()) {
|
|
21
|
+
const fail = (code, message) => ({ code, message, operationIndex });
|
|
22
|
+
if (op.op === "createNode") {
|
|
23
|
+
if (nodes.has(op.id))
|
|
24
|
+
return fail("DUPLICATE_NODE", `Node ${op.id} already exists`);
|
|
25
|
+
if (!op.node?.type)
|
|
26
|
+
return fail("INVALID_NODE", "createNode requires a node type");
|
|
27
|
+
nodes.set(op.id, { type: op.node.type, parent: null, children: [] });
|
|
28
|
+
} else if (op.op === "insertChild" || op.op === "moveChild") {
|
|
29
|
+
const parent = nodes.get(op.parentId), child = nodes.get(op.childId);
|
|
30
|
+
if (!parent)
|
|
31
|
+
return fail("UNKNOWN_PARENT", `Node ${op.parentId} does not exist`);
|
|
32
|
+
if (!child)
|
|
33
|
+
return fail("UNKNOWN_NODE", `Node ${op.childId} does not exist`);
|
|
34
|
+
if (!containers.has(parent.type.toLowerCase()))
|
|
35
|
+
return fail("INVALID_PARENT", `Node ${op.parentId} cannot contain children`);
|
|
36
|
+
if (op.op === "insertChild" && child.parent !== null)
|
|
37
|
+
return fail("NODE_ATTACHED", `Node ${op.childId} already has a parent`);
|
|
38
|
+
if (op.op === "moveChild") {
|
|
39
|
+
if (child.parent !== op.parentId || !parent.children.includes(op.childId))
|
|
40
|
+
return fail("NOT_A_CHILD", `Node ${op.childId} is not a child of ${op.parentId}`);
|
|
41
|
+
parent.children.splice(parent.children.indexOf(op.childId), 1);
|
|
42
|
+
}
|
|
43
|
+
for (let id = op.parentId;id; id = nodes.get(id)?.parent ?? null)
|
|
44
|
+
if (id === op.childId)
|
|
45
|
+
return fail("CYCLE", "Placement would create a cycle");
|
|
46
|
+
if (!Number.isInteger(op.index) || op.index < 0 || op.index > parent.children.length)
|
|
47
|
+
return fail("INVALID_INDEX", `Index must be between 0 and ${parent.children.length}`);
|
|
48
|
+
parent.children.splice(op.index, 0, op.childId);
|
|
49
|
+
child.parent = op.parentId;
|
|
50
|
+
} else if (op.op === "removeNode" || op.op === "updateNode") {
|
|
51
|
+
const node = nodes.get(op.id);
|
|
52
|
+
if (!node)
|
|
53
|
+
return fail("UNKNOWN_NODE", `Node ${op.id} does not exist`);
|
|
54
|
+
if (op.op === "removeNode") {
|
|
55
|
+
const parent = node.parent ? nodes.get(node.parent) : null;
|
|
56
|
+
if (parent)
|
|
57
|
+
parent.children = parent.children.filter((id) => id !== op.id);
|
|
58
|
+
drop(op.id);
|
|
59
|
+
}
|
|
60
|
+
} else
|
|
61
|
+
return fail("INVALID_OPERATION", `Unknown mutation ${op.op}`);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
package/dist/native/testing.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TestMutationError } from './testing-mutations';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import vm from 'node:vm';
|
|
3
4
|
/** Wait for `check` to hold, polling every 5ms; throws after `timeoutMs`. */
|
|
@@ -68,6 +69,7 @@ export declare interface NativeScreenOptions {
|
|
|
68
69
|
export declare interface NativeScreen {
|
|
69
70
|
nodes: Map<string, NativeNode>
|
|
70
71
|
messages: NativeMessage[]
|
|
72
|
+
mutationErrors: TestMutationError[]
|
|
71
73
|
requests: string[]
|
|
72
74
|
headers: Array<Record<string, string>>
|
|
73
75
|
opened: string[]
|
package/dist/native/testing.js
CHANGED
|
@@ -2,6 +2,7 @@ var {require}=import.meta;import path from "node:path";
|
|
|
2
2
|
import vm from "node:vm";
|
|
3
3
|
import { compileSharedScreenBundle } from "./compiler/bundle.js";
|
|
4
4
|
import { NativeFormData } from "./runtime/jsc-globals.js";
|
|
5
|
+
import { validateTestMutations } from "./testing-mutations.js";
|
|
5
6
|
import { createTempDir } from "../temp-dir.js";
|
|
6
7
|
|
|
7
8
|
export class StatusAnswer {
|
|
@@ -69,7 +70,7 @@ export function mountNativeScreen(code, screen, options = {}) {
|
|
|
69
70
|
intervals.delete(id);
|
|
70
71
|
clearInterval(id);
|
|
71
72
|
}
|
|
72
|
-
}, apiBase = options.apiBase || "", label = options.requestLabel || ((method, at, init) => `${method} ${at}${init.headers && Object.keys(init.headers).some((name) => name.toLowerCase() === "authorization") ? "" : " (guest)"}`), nodes = new Map, messages = [], requests = [], headers = [], opened = [], replaced = [], moves = [], stored = copy(options.storage ?? {}), natives = [], animations = [], streams = [], secureStorage = { ...options.keychain, ...options.secureStorage }, sessionTokenKey = options.sessionTokenKey ?? "auth.token", sessionWritten = (key, previous) => {
|
|
73
|
+
}, apiBase = options.apiBase || "", label = options.requestLabel || ((method, at, init) => `${method} ${at}${init.headers && Object.keys(init.headers).some((name) => name.toLowerCase() === "authorization") ? "" : " (guest)"}`), nodes = new Map, messages = [], mutationErrors = [], requests = [], headers = [], opened = [], replaced = [], moves = [], stored = copy(options.storage ?? {}), natives = [], animations = [], streams = [], secureStorage = { ...options.keychain, ...options.secureStorage }, sessionTokenKey = options.sessionTokenKey ?? "auth.token", sessionWritten = (key, previous) => {
|
|
73
74
|
if (key !== sessionTokenKey || options.sessionEvents === !1)
|
|
74
75
|
return;
|
|
75
76
|
const token = secureStorage[key] || null;
|
|
@@ -247,10 +248,21 @@ export function mountNativeScreen(code, screen, options = {}) {
|
|
|
247
248
|
appURL: options.appURL ?? "https://fixture.invalid/m",
|
|
248
249
|
appVersion: options.appVersion ?? "1.0.0",
|
|
249
250
|
appBuild: options.appBuild ?? "1",
|
|
250
|
-
sessionTokenKey,
|
|
251
|
+
...options.sessionEvents === !1 ? {} : { sessionTokenKey },
|
|
251
252
|
postMessage: (raw) => {
|
|
252
253
|
const message = JSON.parse(raw);
|
|
253
254
|
messages.push(JSON.parse(raw));
|
|
255
|
+
if (message.type === "MUTATE") {
|
|
256
|
+
const error = validateTestMutations(nodes, message.payload.operations || []);
|
|
257
|
+
if (error) {
|
|
258
|
+
mutationErrors.push(error);
|
|
259
|
+
queueMicrotask(() => {
|
|
260
|
+
if (!ended)
|
|
261
|
+
receive(JSON.stringify({ type: "MUTATION_ERROR", payload: { ...error, version: 1, batchId: message.payload.batchId } }));
|
|
262
|
+
});
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
254
266
|
if (message.payload.document)
|
|
255
267
|
visit(message.payload.document);
|
|
256
268
|
for (const operation of message.payload.operations || []) {
|
|
@@ -374,6 +386,7 @@ export function mountNativeScreen(code, screen, options = {}) {
|
|
|
374
386
|
return {
|
|
375
387
|
nodes,
|
|
376
388
|
messages,
|
|
389
|
+
mutationErrors,
|
|
377
390
|
requests,
|
|
378
391
|
headers,
|
|
379
392
|
opened,
|
|
@@ -440,6 +453,10 @@ export function mountNativeScreen(code, screen, options = {}) {
|
|
|
440
453
|
await Bun.sleep(ms);
|
|
441
454
|
while (performance.now() - started < 5000 && (fetching > 0 || performance.now() - answeredAt < ms))
|
|
442
455
|
await Bun.sleep(5);
|
|
456
|
+
if (mutationErrors.length) {
|
|
457
|
+
const error = mutationErrors[0];
|
|
458
|
+
throw Error(`Native mutation rejected (${error.code}, operation ${error.operationIndex}): ${error.message}`);
|
|
459
|
+
}
|
|
443
460
|
},
|
|
444
461
|
operations: () => messages.filter((message) => message.type === "MUTATE").flatMap((message) => message.payload.operations || []),
|
|
445
462
|
get ended() {
|
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{Yn,je,ni,lc}from"./chunk-07869zev.js";import{Jn,ss,ic,ac,cc}from"./chunk-vf15db1j.js";import{Qo,ei,ti,sc,oc}from"./chunk-a8n6mt7s.js";import{ae,bt,os}from"./chunk-qf3axv86.js";import{dl,pl,fl,gl,Rr,Dd}from"./chunk-67m2prah.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-55n8mhq4.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=ae(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=ae(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Yn(n,t);if(a){let s=je(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 se(n,t){return ss(n,t)}function oe(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,ei as auditBuildOutput,Qo as auditConfig,re as buildPwaAssets,ti as calculateAuditResult,oc as formatAuditResult,os as formatSize,j as generateManifest,_ as generateManifestJson,ac as generateManifestLink,F as generateOfflinePage,ae as generatePrecacheManifest,bt as generatePrecacheManifestJs,M as generatePwaIcons,Jn as generatePwaTags,Yn as generateServiceWorker,lc as generateServiceWorkerAuto,ic as generateSwRegistrationScript,cc as generateThemeColorMeta,N as getExpectedIconPaths,je as getServiceWorkerFileName,ss as injectPwaTags,oe as isPwaEnabled,I as isSharpAvailable,ni as isWorkboxEnabled,q as mergeManifestConfig,se as processPwaHtml,Rr as pwaDirectives,dl as pwaInstallDirective,fl as pwaOfflineDirective,gl as pwaPushDirective,pl as pwaUpdateDirective,Dd as registerPwaDirectives,sc as runPwaAudit,D as validateManifest};
|
package/dist/ssg.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
3
|
-
`)}class
|
|
2
|
+
import"./chunk-3y5tzxm6.js";import"./chunk-qhr1tkhj.js";import"./chunk-v8ze2q95.js";import{st,ot,it,at,ct,lt}from"./chunk-pxw4edw8.js";import"./chunk-c6egfhy6.js";import"./chunk-mmbspaqh.js";import{f,Ue,L,J,n,o}from"./chunk-sr1md7vv.js";import"./chunk-9cpxzze0.js";import{yr}from"./chunk-7ra30crf.js";import"./chunk-k1szsenr.js";import"./chunk-zgv1h2np.js";import"./chunk-82bttwqm.js";import"./chunk-k71e38fk.js";import"./chunk-h988fxh3.js";import{ce,vt,wt}from"./chunk-z2mg470f.js";import{Jo,Yo,Zo}from"./chunk-zrw1zf54.js";import{yt,an,cn}from"./chunk-9pk5jhqa.js";import"./chunk-w24qmxc3.js";import{a}from"./chunk-sjkdpsca.js";import x from"fs";import g from"path";import{createHash as Dt}from"crypto";function Rt(t){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(t).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return t}}var kt=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function Ct(t){return Bun.hash(t).toString(16)}function ut(t,i={}){if(!t.includes('type="stx/island"'))return{html:t,chunks:[]};let s=new Map,r=t.replace(kt,(e,l,w,y)=>{let h=y.trim();if(!h)return e;if(/\bdata-stx-src=/.test(w))return e;if(i.minify)h=Rt(h);let S=Ct(h);if(!s.has(S))s.set(S,h);let P=i.integrity?` data-stx-integrity="sha384-${Dt("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 Et=new Set(["visible","idle"]);function dt(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(Et.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 It=["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 Bt(t){for(let i of It){let s=t[i];if(!s)continue;let r=q(s);if(r)return{url:r,source:"env",via:i}}return null}function gt(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 jt(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=gt(e.default??e);if(l)return l}catch{}}return null}async function pt(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=gt(t.stxConfig);if(r)return{url:r,source:"stx.config",via:"site.url"};let c=await jt(i);if(c)return{url:c,source:"site.config",via:"url"};let e=Bt(s);if(e)return e;return{url:"http://localhost",source:"fallback"}}function ht(){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
|
+
`)}class ft{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 mt{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 Ft(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]}
|
|
6
6
|
})()
|
|
@@ -41,16 +41,16 @@ ${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();wt();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(
|
|
44
|
+
</rss>`}async function zt(t={}){let i=Date.now();wt();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(ht());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-f0fxyh3e.js");try{D=m(await u(process.cwd()))}catch{}}let{prepareImageDelivery:p}=await import("./chunk-hr34x6sx.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 ft(e.cacheDir,D);if(e.cache)await B.load();try{let{generateCss:u}=await import("./chunk-f0fxyh3e.js");await u('<div class="bg-black"></div>')}catch{}st();let xt=s?.routeMiddleware?.dir||"middleware";await it(process.cwd(),xt);let H=ot();if(H.length>0)console.log(`Loaded ${H.length} middleware: ${H.join(", ")}`);let bt=s?.routeMiddleware?.global||[];Zo(s?.layoutsDir,a(process.cwd()));let K=L(".",{pagesDir:e.pagesDir,pagesDirs:s?._layerPageDirs});console.log(`Found ${K.length} routes`);let G=[];for(let u of K){let m=await Ot(u);for(let v of m)G.push({route:u,url:v.url,params:v.params,props:v.props,revalidate:v.revalidate??e.revalidate})}l.totalPages=G.length,console.log(`Generating ${l.totalPages} pages...`);let A=[],X=[];for(let u=0;u<G.length;u+=e.concurrency)X.push(G.slice(u,u+e.concurrency));for(let u of X)await Promise.all(u.map(async(m)=>{let{route:v,url:d,params:M,props:Pt,revalidate:Q}=m;try{await e.hooks.onPageStart?.(d);let j=await Bun.file(v.filePath).text(),F=Jt(j),$t=F?.middleware?Array.isArray(F.middleware)?F.middleware:[F.middleware]:[],tt=[...bt,...$t];if(tt.length>0){let C=at(d,M,F||{}),O=ct(C,null,void 0,{isServer:!0}),E=await lt(tt,O);if(E.redirect){let R=typeof E.redirect==="string"?E.redirect:E.redirect.path||E.redirect,_=Vt(String(R),d),T=Kt(d,e);await x.promises.mkdir(g.dirname(T),{recursive:!0}),await Bun.write(T,_),l.successCount++,l.pages.push({route:d,outputPath:T,size:Buffer.byteLength(_),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 et=j.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(et)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${et[1]};
|
|
46
46
|
return validate(route);
|
|
47
|
-
`)({params:M})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,
|
|
47
|
+
`)({params:M})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,rt=!1;if(e.cache){if(k=B.get(d,v.filePath),k)rt=!0,l.cachedCount++}if(!k){let C=await St(v,M,Pt,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:
|
|
48
48
|
${C.includeFailures.join(`
|
|
49
49
|
`)}
|
|
50
50
|
Set ssg.failOnIncludeError to false to build anyway.`);if(e.failOnServerScriptError&&C.serverScriptFailures.length>0)throw Error(`${C.serverScriptFailures.length} <script server> block(s) failed, so this page would have shipped with the content they produce missing:
|
|
51
51
|
${C.serverScriptFailures.join(`
|
|
52
52
|
`)}
|
|
53
|
-
Set ssg.failOnServerScriptError to false to build anyway.`);if(e.cache)B.set(d,v.filePath,C.dependencies,k)}let U;if(e.trailingSlash)U=g.join(e.outputDir,d,"index.html");else U=d==="/"?g.join(e.outputDir,"index.html"):g.join(e.outputDir,`${d}.html`);if(e.chunkIslands){let{html:C,chunks:O}=ut(k,{integrity:e.integrityIslands,minify:e.minify});if(O.length>0){let E=g.join(e.outputDir,"_stx","islands");await x.promises.mkdir(E,{recursive:!0});for(let R of O){let _=g.join(E,`${R.hash}.js`);if(!await Bun.file(_).exists())await Bun.write(_,R.code);if(!w.has(R.hash)){w.add(R.hash);let T=Buffer.byteLength(R.code,"utf8");y+=T,h[R.hash]={bytes:T,file:`/_stx/islands/${R.hash}.js`}}}if(S[d]=O.map((R)=>R.hash),k=C,e.prefetchIslands)k=dt(k)}}if(await x.promises.mkdir(g.dirname(U),{recursive:!0}),await Bun.write(U,k),!_t(d,k,F,e.sitemapExclude))A.push({loc:d,lastmod:new Date().toISOString().split("T")[0],priority:d==="/"?1:0.8});let
|
|
53
|
+
Set ssg.failOnServerScriptError to false to build anyway.`);if(e.cache)B.set(d,v.filePath,C.dependencies,k)}let U;if(e.trailingSlash)U=g.join(e.outputDir,d,"index.html");else U=d==="/"?g.join(e.outputDir,"index.html"):g.join(e.outputDir,`${d}.html`);if(e.chunkIslands){let{html:C,chunks:O}=ut(k,{integrity:e.integrityIslands,minify:e.minify});if(O.length>0){let E=g.join(e.outputDir,"_stx","islands");await x.promises.mkdir(E,{recursive:!0});for(let R of O){let _=g.join(E,`${R.hash}.js`);if(!await Bun.file(_).exists())await Bun.write(_,R.code);if(!w.has(R.hash)){w.add(R.hash);let T=Buffer.byteLength(R.code,"utf8");y+=T,h[R.hash]={bytes:T,file:`/_stx/islands/${R.hash}.js`}}}if(S[d]=O.map((R)=>R.hash),k=C,e.prefetchIslands)k=dt(k)}}if(await x.promises.mkdir(g.dirname(U),{recursive:!0}),await Bun.write(U,k),!_t(d,k,F,e.sitemapExclude))A.push({loc:d,lastmod:new Date().toISOString().split("T")[0],priority:d==="/"?1:0.8});let nt={route:d,outputPath:U,size:Buffer.byteLength(k,"utf8"),cached:rt};if(Q!==!1)nt.revalidateAt=Date.now()+Q*1000;l.pages.push(nt),l.successCount++,await e.hooks.onPageEnd?.(d,k)}catch(j){l.failedCount++,l.errors.push({route:d,error:j}),await e.hooks.onError?.(j,d),console.error(`Error generating ${d}:`,j)}}));let Y=vt();if(Y.length>0){let u=Y.map((m)=>`${m.filePath}: ${m.message}`).join(`
|
|
54
54
|
`);throw Error(`Client script bundling failed:
|
|
55
55
|
${u}`)}if(e.cache)await B.save();if(e.generate404){let u=g.join(e.pagesDir,"404.stx");if(await Bun.file(u).exists()){let m=new Set,v={...s,debug:!1,cache:!1},d=await n(await Bun.file(u).text(),{},u,v,m);await Bun.write(g.join(e.outputDir,"404.html"),d)}else await Bun.write(g.join(e.outputDir,"404.html"),`<!DOCTYPE html>
|
|
56
56
|
<html lang="en">
|
|
@@ -73,7 +73,7 @@ ${u}`)}if(e.cache)await B.save();if(e.generate404){let u=g.join(e.pagesDir,"404.
|
|
|
73
73
|
<a href="/">Go home</a>
|
|
74
74
|
</div>
|
|
75
75
|
</body>
|
|
76
|
-
</html>`)}for(let u of[500]){let m=g.join(e.pagesDir,`${u}.stx`);if(await Bun.file(m).exists()){let v=new Set,d={...s,debug:!1,cache:!1},M=await n(await Bun.file(m).text(),{},m,d,v);await Bun.write(g.join(e.outputDir,`${u}.html`),M)}}let W=g.join(e.pagesDir,"error.stx");if(await Bun.file(W).exists()){let u=new Set,m={...s,debug:!1,cache:!1},v=await n(await Bun.file(W).text(),{},W,m,u);await Bun.write(g.join(e.outputDir,"error.html"),v)}if(e.sitemap&&A.length>0){let u=Gt(A,e.domain),m=g.join(e.outputDir,"sitemap.xml");await Bun.write(m,u),l.sitemapPath=m,console.log(`Generated sitemap.xml with ${A.length} URLs`)}if(e.robots!==!1){let u=typeof e.robots==="object"?e.robots:{},m=[...e.sitemapExclude.filter((d)=>typeof d==="string"),...u.disallow||[]],v=
|
|
76
|
+
</html>`)}for(let u of[500]){let m=g.join(e.pagesDir,`${u}.stx`);if(await Bun.file(m).exists()){let v=new Set,d={...s,debug:!1,cache:!1},M=await n(await Bun.file(m).text(),{},m,d,v);await Bun.write(g.join(e.outputDir,`${u}.html`),M)}}let W=g.join(e.pagesDir,"error.stx");if(await Bun.file(W).exists()){let u=new Set,m={...s,debug:!1,cache:!1},v=await n(await Bun.file(W).text(),{},W,m,u);await Bun.write(g.join(e.outputDir,"error.html"),v)}if(e.sitemap&&A.length>0){let u=Gt(A,e.domain),m=g.join(e.outputDir,"sitemap.xml");await Bun.write(m,u),l.sitemapPath=m,console.log(`Generated sitemap.xml with ${A.length} URLs`)}if(e.robots!==!1){let u=typeof e.robots==="object"?e.robots:{},m=[...e.sitemapExclude.filter((d)=>typeof d==="string"),...u.disallow||[]],v=yr({rules:[{userAgent:u.userAgent||"*",allow:u.allow||["/"],...m.length>0?{disallow:m}:{}}],...u.sitemap!==!1&&l.sitemapPath?{sitemap:new URL("/sitemap.xml",e.domain).href}:{}});await Bun.write(g.join(e.outputDir,"robots.txt"),v),console.log("Generated robots.txt")}if(e.rss){let u=typeof e.rss==="object"?e.rss:{title:"Site Feed",description:"Latest updates",link:e.domain},m=[];if(u.getItems)m=await u.getItems();let v=Nt(u,m),d=g.join(e.outputDir,"rss.xml");await Bun.write(d,v),l.rssPath=d,console.log(`Generated rss.xml with ${m.length} items`)}let N=Jo(e.outputDir);if(N.assets>0)console.log(`Externalized ${N.assets} asset(s) from ${N.pages} page(s) (${(N.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);let z=Yo(e.outputDir);if(z.assets>0)console.log(`Externalized ${z.assets} repeated asset(s) from ${z.pages} page(s) (${(z.bytesInlined/1024).toFixed(1)}KB removed from HTML)`);if(e.publicDir&&x.existsSync(e.publicDir))await V(e.publicDir,e.outputDir),console.log(`Copied public assets from ${e.publicDir}`);let Z=cn();if(Z)await V(Z,g.join(e.outputDir,an)),console.log(`Copied assets from ${yt}`)}catch(D){throw await e.hooks.onError?.(D),D}if(l.buildTime=Date.now()-i,w.size>0){l.islandChunks={count:w.size,totalBytes:y};let D={generatedChunks:w.size,totalBytes:y,chunks:h,pages:S};await Bun.write(g.join(e.outputDir,"_stx","islands-manifest.json"),JSON.stringify(D,null,2))}await e.hooks.onBuildEnd?.(l);let P=l.islandChunks?`
|
|
77
77
|
Island chunks: ${l.islandChunks.count} (${(l.islandChunks.totalBytes/1024).toFixed(1)} KB lifted out of inline HTML)`:"";return console.log(`
|
|
78
78
|
Build complete!
|
|
79
79
|
Total: ${l.totalPages} pages
|
|
@@ -81,8 +81,8 @@ Build complete!
|
|
|
81
81
|
Cached: ${l.cachedCount}
|
|
82
82
|
Failed: ${l.failedCount}
|
|
83
83
|
Time: ${l.buildTime}ms${P}
|
|
84
|
-
`),l}async function V(t,i){await x.promises.mkdir(i,{recursive:!0});let s=await x.promises.readdir(t,{withFileTypes:!0});for(let r of s){let c=g.join(t,r.name),e=g.join(i,r.name);if(r.isDirectory())await x.promises.mkdir(e,{recursive:!0}),await V(c,e);else await x.promises.copyFile(c,e)}}function Ht(t={}){let i=t.cacheDir||a(process.cwd(),"ssg-cache"),s=new
|
|
85
|
-
`)){let P=S.indexOf(":");if(P>0){let D=S.slice(0,P).trim(),p=S.slice(P+1).trim();if(p==="true")p=!0;else if(p==="false")p=!1;else if(/^\d+$/.test(p))p=parseInt(p,10);else if(/^\d+\.\d+$/.test(p))p=parseFloat(p);else if(p.startsWith("[")&&p.endsWith("]"))p=p.slice(1,-1).split(",").map((b)=>b.trim().replace(/^['"]|['"]$/g,""));r[D]=p}}}let e=c.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*)\*/gim,"<em>$1</em>").replace(/`([^`]+)`/gim,"<code>$1</code>").replace(/\[([^\]]+)\]\(([^)]+)\)/gim,'<a href="$2">$1</a>').replace(/\n/gim,"<br>"),l=[],w=/<h([1-6])>([^<]+)<\/h[1-6]>/gi,y;while((y=w.exec(e))!==null){let h=parseInt(y[1],10),S=y[2],P=S.toLowerCase().replace(/[^a-z0-9]+/g,"-");l.push({id:P,text:S,level:h})}return{content:e,data:r,toc:l}}}}function Jt(t){return
|
|
84
|
+
`),l}async function V(t,i){await x.promises.mkdir(i,{recursive:!0});let s=await x.promises.readdir(t,{withFileTypes:!0});for(let r of s){let c=g.join(t,r.name),e=g.join(i,r.name);if(r.isDirectory())await x.promises.mkdir(e,{recursive:!0}),await V(c,e);else await x.promises.copyFile(c,e)}}function Ht(t={}){let i=t.cacheDir||a(process.cwd(),"ssg-cache"),s=new mt(i),r=t.revalidate||3600;return{async get(c){let e=await s.get(c);if(!e)return null;if(Date.now()>e.revalidateAfter)this.revalidate(c).catch(console.error);return{html:e.html,headers:{"Cache-Control":`public, max-age=${r}, stale-while-revalidate=${r*2}`,ETag:e.etag,"X-ISR-Generated":new Date(e.generatedAt).toISOString(),...e.headers}}},async revalidate(c){let l=L(".",{pagesDir:t.pagesDir||"pages"}).find((P)=>c.match(P.regex)!==null);if(!l){console.warn(`Route not found for revalidation: ${c}`);return}let w=c.match(l.regex),y={};if(w)l.params.forEach((P,D)=>{y[P]=w[D+1]});let h=await o(),{html:S}=await St(l,y,{},t,h);await s.set(c,{html:S,generatedAt:Date.now(),revalidateAfter:Date.now()+r*1000,etag:Ut(S)}),console.log(`Revalidated: ${c}`)},async invalidate(c){if(typeof c==="string")await s.invalidate(c);else await s.invalidatePattern(c)}}}function Wt(t){return async()=>({paths:await t(),fallback:!1})}function qt(){return{name:"markdown",extensions:[".md",".mdx"],async load(t){let i=await Bun.file(t).text(),s=i.match(/^---\n([\s\S]*?)\n---/),r={},c=i;if(s){let h=s[1];c=i.slice(s[0].length).trim();for(let S of h.split(`
|
|
85
|
+
`)){let P=S.indexOf(":");if(P>0){let D=S.slice(0,P).trim(),p=S.slice(P+1).trim();if(p==="true")p=!0;else if(p==="false")p=!1;else if(/^\d+$/.test(p))p=parseInt(p,10);else if(/^\d+\.\d+$/.test(p))p=parseFloat(p);else if(p.startsWith("[")&&p.endsWith("]"))p=p.slice(1,-1).split(",").map((b)=>b.trim().replace(/^['"]|['"]$/g,""));r[D]=p}}}let e=c.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*)\*/gim,"<em>$1</em>").replace(/`([^`]+)`/gim,"<code>$1</code>").replace(/\[([^\]]+)\]\(([^)]+)\)/gim,'<a href="$2">$1</a>').replace(/\n/gim,"<br>"),l=[],w=/<h([1-6])>([^<]+)<\/h[1-6]>/gi,y;while((y=w.exec(e))!==null){let h=parseInt(y[1],10),S=y[2],P=S.toLowerCase().replace(/[^a-z0-9]+/g,"-");l.push({id:P,text:S,level:h})}return{content:e,data:r,toc:l}}}}function Jt(t){return Ue(t)}function Vt(t,i){return`<!DOCTYPE html>
|
|
86
86
|
<html>
|
|
87
87
|
<head>
|
|
88
88
|
<meta charset="utf-8">
|
package/dist/testing.js
CHANGED
|
@@ -23,6 +23,8 @@ export function shimAttributes(root) {
|
|
|
23
23
|
const map = el.attributes;
|
|
24
24
|
if (!(map instanceof Map))
|
|
25
25
|
continue;
|
|
26
|
+
if (el.tagName === "INPUT" && !("indeterminate" in el))
|
|
27
|
+
el.indeterminate = !1;
|
|
26
28
|
el.__attrMap = map;
|
|
27
29
|
Object.defineProperty(el, "attributes", {
|
|
28
30
|
configurable: !0,
|
|
@@ -304,6 +304,8 @@ export declare interface StxConfig {
|
|
|
304
304
|
componentsDir: string
|
|
305
305
|
_rootComponentsDir?: string
|
|
306
306
|
_targetComponentDirs?: string[]
|
|
307
|
+
_targetComponentFallbackNames?: string[]
|
|
308
|
+
_nativeHostAttrs?: boolean
|
|
307
309
|
layoutsDir?: string
|
|
308
310
|
fallbackLayoutsDir?: string
|
|
309
311
|
fallbackComponentsDir?: string
|
package/dist/utils.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare function slotContentHasExpressions(slotContent: string): boolean;
|
|
|
65
65
|
* named `title` also exists in the server context.
|
|
66
66
|
*/
|
|
67
67
|
export declare function componentClientSignalNames(scripts: string[]): string[];
|
|
68
|
-
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>, clientLoopNames?: readonly string[], renderMetadata?: { declaredProps: Set<string
|
|
68
|
+
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>, clientLoopNames?: readonly string[], renderMetadata?: { declaredProps: Set<string>, consumedProps?: Set<string>, reactiveProps?: string[] }, lookupName?: string): Promise<string>;
|
|
69
69
|
/**
|
|
70
70
|
* Check if a file exists
|
|
71
71
|
*/
|