@stacksjs/stx 0.2.413 → 0.2.415
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/appearance-bootstrap.js +1 -1
- package/dist/binding-manifest.d.ts +1 -1
- package/dist/builtins/image-delivery.js +19 -11
- package/dist/bundle-analyzer.js +20 -20
- package/dist/chunk-020xyn9q.js +3 -0
- package/dist/chunk-04jhmfbz.js +2 -0
- package/dist/chunk-0pnj3zt2.js +2 -0
- package/dist/{chunk-bwjxk1dw.js → chunk-0zaess6f.js} +29 -29
- package/dist/chunk-1098mas0.js +2 -0
- package/dist/chunk-169n1vpx.js +12 -0
- package/dist/chunk-18vmfkcc.js +2 -0
- package/dist/chunk-1b6t12hd.js +2 -0
- package/dist/chunk-1xdzcy9d.js +14 -0
- package/dist/chunk-1zs30k3y.js +2 -0
- package/dist/chunk-2ce7f416.js +2 -0
- package/dist/chunk-340a824p.js +2 -0
- package/dist/chunk-393341w7.js +2 -0
- package/dist/chunk-39g1134q.js +2 -0
- package/dist/chunk-3efw27as.js +2785 -0
- package/dist/chunk-3kthfs03.js +3 -0
- package/dist/chunk-3qn1wcdg.js +2 -0
- package/dist/chunk-3s2vnqcf.js +2 -0
- package/dist/chunk-42wbs8vq.js +17 -0
- package/dist/chunk-4bjravgk.js +2 -0
- package/dist/chunk-5gsxpaqk.js +2 -0
- package/dist/{chunk-bwsxym3d.js → chunk-5qns2sdz.js} +17 -17
- package/dist/chunk-6cfa3g0r.js +2 -0
- package/dist/{chunk-bjar18jd.js → chunk-6h38kkjf.js} +46 -52
- package/dist/chunk-6hc5vz20.js +3 -0
- package/dist/chunk-6q6g76vg.js +499 -0
- package/dist/chunk-74j18qk0.js +930 -0
- package/dist/chunk-752hw7cd.js +4 -0
- package/dist/{chunk-kgd8kchy.js → chunk-765e1s44.js} +11 -76
- package/dist/chunk-7gkv67ky.js +4 -0
- package/dist/chunk-7z2ra0yf.js +2 -0
- package/dist/chunk-8eqrwj1k.js +20 -0
- package/dist/chunk-8nhshfz6.js +5 -0
- package/dist/chunk-92ps1xpk.js +2 -0
- package/dist/chunk-96k8s808.js +3 -0
- package/dist/chunk-9amp82bx.js +7 -0
- package/dist/chunk-9g27ybyr.js +3 -0
- package/dist/chunk-9p9qkbtg.js +3 -0
- package/dist/{chunk-xq1acw1r.js → chunk-9pt8fd2n.js} +13 -13
- package/dist/{chunk-24zher49.js → chunk-9vrja6vp.js} +4 -4
- package/dist/chunk-9xrbve19.js +2 -0
- package/dist/chunk-a688m6js.js +3 -0
- package/dist/chunk-ak1cgcah.js +5 -0
- package/dist/{chunk-4m7ajama.js → chunk-amd6ey3t.js} +14 -14
- package/dist/chunk-amtr3rmf.js +11 -0
- package/dist/chunk-atws6p5s.js +2 -0
- package/dist/chunk-b84h16er.js +61 -0
- package/dist/chunk-b98be3yp.js +32 -0
- package/dist/{chunk-hx998w7n.js → chunk-bay9s6rs.js} +13 -13
- package/dist/chunk-ce1sejr3.js +3 -0
- package/dist/chunk-cg8hg6cs.js +3 -0
- package/dist/{chunk-4f9zyfdw.js → chunk-czxt605c.js} +4 -5
- package/dist/chunk-dd8cja4h.js +2 -0
- package/dist/chunk-dgdm3hy3.js +2 -0
- package/dist/chunk-e9hs7kk6.js +12 -0
- package/dist/chunk-eed4fwps.js +3 -0
- package/dist/chunk-ej9j6k1q.js +3 -0
- package/dist/chunk-et0rr8c7.js +3 -0
- package/dist/chunk-f1sxycmv.js +2 -0
- package/dist/chunk-f46qsp4m.js +4 -0
- package/dist/chunk-fbcv4fes.js +2 -0
- package/dist/{chunk-bjcsc6wx.js → chunk-fh1qrp68.js} +21 -21
- package/dist/chunk-fjs0a8h7.js +2 -0
- package/dist/chunk-fpfzm238.js +2 -0
- package/dist/chunk-fr2txj8q.js +829 -0
- package/dist/{chunk-xssw417m.js → chunk-ft4p6d28.js} +14 -14
- package/dist/chunk-fyzajkrx.js +2 -0
- package/dist/chunk-fzapbw9p.js +3 -0
- package/dist/chunk-g03s93qr.js +3 -0
- package/dist/chunk-g186znp9.js +33 -0
- package/dist/chunk-gawrg4gb.js +216 -0
- package/dist/chunk-gc1drn2p.js +2 -0
- package/dist/chunk-gea5hf0v.js +2 -0
- package/dist/chunk-gqv3ta5d.js +2 -0
- package/dist/chunk-h6kp2m9r.js +2 -0
- package/dist/chunk-h6zsqb9r.js +3 -0
- package/dist/{chunk-2snqdnk9.js → chunk-h85hrwkq.js} +13 -13
- package/dist/chunk-hbxz85wy.js +2 -0
- package/dist/chunk-hepd9qgx.js +6 -0
- package/dist/chunk-hhnw2sn3.js +2 -0
- package/dist/chunk-hjg3ndgh.js +2 -0
- package/dist/chunk-hk1mj4tz.js +2 -0
- package/dist/{chunk-smcj3442.js → chunk-hkrmcbwy.js} +79 -79
- package/dist/chunk-hn9pkyv8.js +2 -0
- package/dist/chunk-hpgr4qgp.js +2 -0
- package/dist/chunk-hrbbbtbn.js +2 -0
- package/dist/chunk-j03revz2.js +8 -0
- package/dist/chunk-j9qcrwbg.js +2 -0
- package/dist/chunk-jk4njz0w.js +2 -0
- package/dist/chunk-jmabeqfq.js +2 -0
- package/dist/chunk-jnkrn913.js +4 -0
- package/dist/chunk-jp10q90g.js +2 -0
- package/dist/chunk-jt0n43mk.js +2 -0
- package/dist/chunk-kjbv8a3m.js +2 -0
- package/dist/chunk-m1vdghnx.js +2 -0
- package/dist/chunk-m4sk62wb.js +5 -0
- package/dist/chunk-md8rqn48.js +30 -0
- package/dist/chunk-mp6hy8g4.js +2 -0
- package/dist/chunk-nc8my58s.js +2 -0
- package/dist/chunk-ngc2wke4.js +3 -0
- package/dist/chunk-nn2vstke.js +2 -0
- package/dist/chunk-nppdrf0x.js +2 -0
- package/dist/chunk-p2v2a68k.js +2 -0
- package/dist/chunk-pazfr1a1.js +2 -0
- package/dist/{chunk-qn5srnj3.js → chunk-pbh4smw3.js} +16 -16
- package/dist/chunk-pdb5fw3r.js +2 -0
- package/dist/chunk-pdt69hpb.js +2 -0
- package/dist/chunk-pgzvyrv6.js +29 -0
- package/dist/chunk-px7fvbj6.js +3 -0
- package/dist/chunk-q6vrb2pe.js +2 -0
- package/dist/chunk-q7qchkvk.js +2 -0
- package/dist/chunk-q9bdh4s5.js +8 -0
- package/dist/chunk-qghxz7jm.js +194 -0
- package/dist/chunk-r3f9jcf7.js +5 -0
- package/dist/chunk-re8b5r9x.js +3 -0
- package/dist/chunk-s5xezjps.js +3 -0
- package/dist/chunk-sd321bn3.js +2 -0
- package/dist/chunk-shr559s7.js +3 -0
- package/dist/chunk-t4hzprsm.js +3 -0
- package/dist/chunk-t5pvq5mx.js +2 -0
- package/dist/{chunk-pv3d7sfn.js → chunk-t61vdbje.js} +89 -89
- package/dist/chunk-tafqyf2g.js +2033 -0
- package/dist/chunk-tfexmdkt.js +3 -0
- package/dist/chunk-thyt8ed8.js +6 -0
- package/dist/chunk-v91p6ekp.js +24 -0
- package/dist/chunk-vgvtnwxa.js +4 -0
- package/dist/chunk-w72qx0eb.js +2 -0
- package/dist/chunk-wfy1zq53.js +30 -0
- package/dist/chunk-wzx0164n.js +18 -0
- package/dist/chunk-x0q32ees.js +3 -0
- package/dist/chunk-xfp7k0v8.js +64 -0
- package/dist/chunk-xtvf6n6f.js +4 -0
- package/dist/chunk-xwzvfqcb.js +2 -0
- package/dist/chunk-y1cmjvk3.js +43 -0
- package/dist/chunk-y5310237.js +311 -0
- package/dist/chunk-ya0qecph.js +27 -0
- package/dist/chunk-yazk54jr.js +8 -0
- package/dist/chunk-ydjfar14.js +2 -0
- package/dist/chunk-ym95v4nc.js +3 -0
- package/dist/chunk-z0g9jvv0.js +40 -0
- package/dist/chunk-z23kaxq6.js +2 -0
- package/dist/chunk-z8xn5ta3.js +2 -0
- package/dist/{chunk-8sdhs0zk.js → chunk-zhxdpzga.js} +4 -4
- package/dist/cli.js +110 -110
- package/dist/craft-entry.js +7 -7
- package/dist/craft.js +7 -7
- package/dist/database.js +2 -2
- package/dist/image-optimization/component.js +4 -4
- package/dist/media/image/component.js +5 -5
- package/dist/media/protected/component.js +2 -2
- package/dist/media/video/index.js +4 -4
- package/dist/native/bridge/protocol.d.ts +325 -0
- package/dist/native/bridge/protocol.js +219 -0
- package/dist/native/cli.d.ts +24 -0
- package/dist/native/cli.js +52 -0
- package/dist/native/compiler/bundle.d.ts +41 -0
- package/dist/native/compiler/bundle.js +90 -0
- package/dist/native/compiler/client-script.d.ts +8 -0
- package/dist/native/compiler/client-script.js +31 -0
- package/dist/native/compiler/codegen.d.ts +10 -0
- package/dist/native/compiler/codegen.js +145 -0
- package/dist/native/compiler/headwind-to-style.d.ts +395 -0
- package/dist/native/compiler/headwind-to-style.js +1163 -0
- package/dist/native/compiler/html-to-ir.d.ts +41 -0
- package/dist/native/compiler/html-to-ir.js +411 -0
- package/dist/native/compiler/icons.d.ts +220 -0
- package/dist/native/compiler/icons.js +208 -0
- package/dist/native/compiler/ir.d.ts +234 -0
- package/dist/native/compiler/ir.js +15 -0
- package/dist/native/compiler/parser.d.ts +88 -0
- package/dist/native/compiler/parser.js +753 -0
- package/dist/native/compiler/render-screen.d.ts +26 -0
- package/dist/native/compiler/render-screen.js +31 -0
- package/dist/native/components/primitives.d.ts +291 -0
- package/dist/native/components/primitives.js +22 -0
- package/dist/native/hot-reload/client.d.ts +62 -0
- package/dist/native/hot-reload/client.js +324 -0
- package/dist/native/index.d.ts +90 -0
- package/dist/native/index.js +34 -0
- package/dist/native/primitives/ActivityIndicator.stx +5 -0
- package/dist/native/primitives/Button.stx +5 -0
- package/dist/native/primitives/DatePicker.stx +5 -0
- package/dist/native/primitives/FlatList.stx +5 -0
- package/dist/native/primitives/Image.stx +5 -0
- package/dist/native/primitives/ImageBackground.stx +5 -0
- package/dist/native/primitives/KeyboardAvoidingView.stx +5 -0
- package/dist/native/primitives/Modal.stx +5 -0
- package/dist/native/primitives/Picker.stx +5 -0
- package/dist/native/primitives/Pressable.stx +5 -0
- package/dist/native/primitives/RefreshControl.stx +5 -0
- package/dist/native/primitives/SafeAreaView.stx +5 -0
- package/dist/native/primitives/ScrollView.stx +5 -0
- package/dist/native/primitives/SectionList.stx +5 -0
- package/dist/native/primitives/Slider.stx +5 -0
- package/dist/native/primitives/StatusBar.stx +5 -0
- package/dist/native/primitives/Switch.stx +5 -0
- package/dist/native/primitives/Text.stx +5 -0
- package/dist/native/primitives/TextInput.stx +5 -0
- package/dist/native/primitives/TouchableHighlight.stx +5 -0
- package/dist/native/primitives/TouchableOpacity.stx +5 -0
- package/dist/native/primitives/View.stx +5 -0
- package/dist/native/runtime/craft.d.ts +75 -0
- package/dist/native/runtime/craft.js +0 -0
- package/dist/native/runtime/entry.d.ts +1 -0
- package/dist/native/runtime/entry.js +3 -0
- package/dist/native/runtime/index.d.ts +45 -0
- package/dist/native/runtime/index.js +165 -0
- package/dist/native/runtime/native-host.d.ts +33 -0
- package/dist/native/runtime/native-host.js +184 -0
- package/dist/native/runtime/screen.d.ts +43 -0
- package/dist/native/runtime/screen.js +808 -0
- package/dist/pwa/service-worker.js +1 -1
- package/dist/pwa/workbox.js +1 -1
- package/dist/pwa.js +8 -8
- package/dist/site-url.d.ts +1 -1
- package/dist/ssg.js +53 -53
- package/dist/visual-testing.js +42 -42
- package/dist/web-components/reactive-generator.js +2 -2
- package/package.json +9 -5
- package/dist/chunk-0btmm4m2.js +0 -147
- package/dist/chunk-0c2h69k2.js +0 -4
- package/dist/chunk-0d0qeqvv.js +0 -2
- package/dist/chunk-0psndabd.js +0 -2
- package/dist/chunk-0qv8yf53.js +0 -2
- package/dist/chunk-0vkxyvsd.js +0 -2
- package/dist/chunk-0we9nw1d.js +0 -3
- package/dist/chunk-0xqdmemy.js +0 -3
- package/dist/chunk-0y46fbkx.js +0 -3
- package/dist/chunk-158wqccn.js +0 -4422
- package/dist/chunk-1cyxbb8y.js +0 -16
- package/dist/chunk-1enwnh2a.js +0 -2
- package/dist/chunk-213pzm0d.js +0 -3
- package/dist/chunk-21hzqyja.js +0 -12
- package/dist/chunk-266t58b8.js +0 -5
- package/dist/chunk-27fgag95.js +0 -4
- package/dist/chunk-2a9n102n.js +0 -2
- package/dist/chunk-2eqzrczk.js +0 -2
- package/dist/chunk-2ke37m54.js +0 -14
- package/dist/chunk-35ds08e7.js +0 -3
- package/dist/chunk-3mtwkjcg.js +0 -2
- package/dist/chunk-4xr8zwkp.js +0 -2
- package/dist/chunk-58v77x2c.js +0 -2
- package/dist/chunk-5mhq8605.js +0 -2
- package/dist/chunk-5se8xt9e.js +0 -64
- package/dist/chunk-5zh0h080.js +0 -2
- package/dist/chunk-62435225.js +0 -2
- package/dist/chunk-6kdrncsx.js +0 -30
- package/dist/chunk-6n2rr3x7.js +0 -2
- package/dist/chunk-6xk87qf2.js +0 -30
- package/dist/chunk-72rwcbp6.js +0 -3
- package/dist/chunk-76w34xne.js +0 -3
- package/dist/chunk-7ekd7zj9.js +0 -2
- package/dist/chunk-7pr3wdd5.js +0 -3
- package/dist/chunk-7rxvafwc.js +0 -24
- package/dist/chunk-7tnwfa7w.js +0 -8
- package/dist/chunk-8c5je0wf.js +0 -2
- package/dist/chunk-8dz6nyvx.js +0 -2
- package/dist/chunk-98zj3fv2.js +0 -7
- package/dist/chunk-9e8t0twa.js +0 -3
- package/dist/chunk-9fqp72ze.js +0 -5
- package/dist/chunk-anydpa34.js +0 -3
- package/dist/chunk-ay6zjq8v.js +0 -3
- package/dist/chunk-az4v4ard.js +0 -3
- package/dist/chunk-ba5erggg.js +0 -2
- package/dist/chunk-bnagrdz6.js +0 -2
- package/dist/chunk-by8wghtf.js +0 -2
- package/dist/chunk-cd7h4q51.js +0 -2
- package/dist/chunk-cjmv8hgp.js +0 -33
- package/dist/chunk-cthf912y.js +0 -2
- package/dist/chunk-cxbpmwq5.js +0 -4
- package/dist/chunk-d3sy16qn.js +0 -2
- package/dist/chunk-dh6s7mrj.js +0 -1199
- package/dist/chunk-dm2nzg7a.js +0 -2
- package/dist/chunk-e2sgcnxc.js +0 -2
- package/dist/chunk-e3b7jj74.js +0 -2
- package/dist/chunk-ec4wq2sv.js +0 -6
- package/dist/chunk-ekzg97dn.js +0 -29
- package/dist/chunk-epjt342x.js +0 -2
- package/dist/chunk-eqe26g14.js +0 -18
- package/dist/chunk-ev0v1yma.js +0 -2
- package/dist/chunk-f53psr2y.js +0 -5
- package/dist/chunk-f8p69dsg.js +0 -3
- package/dist/chunk-f95drhdb.js +0 -194
- package/dist/chunk-ff5a6hvb.js +0 -17
- package/dist/chunk-fs5fy4h8.js +0 -2
- package/dist/chunk-fzsygce3.js +0 -2
- package/dist/chunk-g465x63k.js +0 -2
- package/dist/chunk-g708ekh1.js +0 -2
- package/dist/chunk-gcr9e83g.js +0 -11
- package/dist/chunk-gdmyrsr8.js +0 -4
- package/dist/chunk-gkms2ngq.js +0 -2
- package/dist/chunk-gnfywmgs.js +0 -7
- package/dist/chunk-hpf8kq7e.js +0 -2
- package/dist/chunk-j4x3faf8.js +0 -2
- package/dist/chunk-jkavtw9f.js +0 -2
- package/dist/chunk-kg1rdena.js +0 -3
- package/dist/chunk-km91wx0v.js +0 -2
- package/dist/chunk-kmsyvaex.js +0 -8
- package/dist/chunk-mrahwn5v.js +0 -8
- package/dist/chunk-nk3czvnk.js +0 -2
- package/dist/chunk-nmw4eewb.js +0 -2
- package/dist/chunk-nq5zxrk0.js +0 -4
- package/dist/chunk-ny67c03k.js +0 -3
- package/dist/chunk-p4wdxp2c.js +0 -2
- package/dist/chunk-pcxp4r9n.js +0 -3
- package/dist/chunk-pdyeaxc1.js +0 -2
- package/dist/chunk-pf06ded4.js +0 -2
- package/dist/chunk-pfs0gpzm.js +0 -2
- package/dist/chunk-pshdwq44.js +0 -2
- package/dist/chunk-pwgv84pn.js +0 -32
- package/dist/chunk-pwsnafp3.js +0 -4367
- package/dist/chunk-q9n5swx7.js +0 -3
- package/dist/chunk-qr346wnp.js +0 -2
- package/dist/chunk-r02hke04.js +0 -2
- package/dist/chunk-ranshpyc.js +0 -3
- package/dist/chunk-rn194bhp.js +0 -20
- package/dist/chunk-rn1hgyc8.js +0 -930
- package/dist/chunk-s7z5dp70.js +0 -43
- package/dist/chunk-s8jd13nb.js +0 -3
- package/dist/chunk-sn7exv0n.js +0 -2
- package/dist/chunk-t1tdjjht.js +0 -216
- package/dist/chunk-t6qx04s8.js +0 -499
- package/dist/chunk-t6y6gyps.js +0 -2
- package/dist/chunk-tjfs7cc3.js +0 -2
- package/dist/chunk-tkyrk66a.js +0 -3
- package/dist/chunk-tntv9hvq.js +0 -2
- package/dist/chunk-v3nwkveg.js +0 -12
- package/dist/chunk-vd4cb5xr.js +0 -2
- package/dist/chunk-vkhdce50.js +0 -2
- package/dist/chunk-w183av08.js +0 -2
- package/dist/chunk-w2m02njv.js +0 -2
- package/dist/chunk-wpjrcrs5.js +0 -2
- package/dist/chunk-wqmppf6b.js +0 -3
- package/dist/chunk-wtb9fxdy.js +0 -2
- package/dist/chunk-xmzygmcz.js +0 -3
- package/dist/chunk-xsng1mtq.js +0 -3
- package/dist/chunk-xxzefj4j.js +0 -2
- package/dist/chunk-yq8x8bxq.js +0 -47
- package/dist/chunk-ytma76qe.js +0 -3
- package/dist/chunk-yw1m115e.js +0 -2
- package/dist/chunk-z64a924m.js +0 -2
- package/dist/chunk-zcz9rs6p.js +0 -3
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-detect and initialize the bridge
|
|
3
|
+
*/
|
|
4
|
+
export declare function createBridge(): STXBridge;
|
|
5
|
+
/**
|
|
6
|
+
* Get the global bridge instance
|
|
7
|
+
*/
|
|
8
|
+
export declare function getBridge(): STXBridge;
|
|
9
|
+
/**
|
|
10
|
+
* Create an event handler that calls the bridge
|
|
11
|
+
*/
|
|
12
|
+
export declare function createEventHandler(handlerName: string, targetKey: string): (nativeEvent: EventPayload['nativeEvent']) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Register a JS function to be callable from native
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerHandler(name: string, handler: (...args: unknown[]) => unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* Call a registered handler (used by native)
|
|
19
|
+
*/
|
|
20
|
+
export declare function callHandler(name: string, ...args: unknown[]): unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Platform-specific native bridge implementations
|
|
23
|
+
* @defaultValue
|
|
24
|
+
* ```ts
|
|
25
|
+
* {
|
|
26
|
+
* ios: () => NativeBridgeInterface | null,
|
|
27
|
+
* android: () => NativeBridgeInterface | null,
|
|
28
|
+
* web: () => NativeBridgeInterface | null
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const NativeBridges: {
|
|
33
|
+
/**
|
|
34
|
+
* iOS (JavaScriptCore)
|
|
35
|
+
*/
|
|
36
|
+
ios: () => NativeBridgeInterface | null;
|
|
37
|
+
/**
|
|
38
|
+
* Android (JavaScriptInterface)
|
|
39
|
+
*/
|
|
40
|
+
android: () => NativeBridgeInterface | null;
|
|
41
|
+
/**
|
|
42
|
+
* Web (PostMessage)
|
|
43
|
+
*/
|
|
44
|
+
web: () => NativeBridgeInterface | null
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Base message structure
|
|
48
|
+
*/
|
|
49
|
+
export declare interface BridgeMessage<T = unknown> {
|
|
50
|
+
id: string
|
|
51
|
+
type: BridgeMessageType
|
|
52
|
+
timestamp: number
|
|
53
|
+
payload: T
|
|
54
|
+
correlationId?: string
|
|
55
|
+
source: 'js' | 'native'
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* RENDER message payload
|
|
59
|
+
*/
|
|
60
|
+
export declare interface RenderPayload {
|
|
61
|
+
document: import('../compiler/ir').STXDocument | import('../compiler/ir').STXNode
|
|
62
|
+
containerId?: string
|
|
63
|
+
mode: 'replace' | 'append' | 'prepend'
|
|
64
|
+
}
|
|
65
|
+
export declare interface NativeMutationNode {
|
|
66
|
+
type: string
|
|
67
|
+
props?: Record<string, unknown>
|
|
68
|
+
style?: Partial<import('../compiler/ir').STXStyle>
|
|
69
|
+
events?: Record<string, string>
|
|
70
|
+
children?: string[]
|
|
71
|
+
}
|
|
72
|
+
export declare interface NativeMutationPayload {
|
|
73
|
+
version: 1
|
|
74
|
+
batchId: string
|
|
75
|
+
baseRevision: number
|
|
76
|
+
revision: number
|
|
77
|
+
operations: NativeMutationOperation[]
|
|
78
|
+
}
|
|
79
|
+
export declare interface NativeMutationAckPayload {
|
|
80
|
+
version: 1
|
|
81
|
+
batchId: string
|
|
82
|
+
revision: number
|
|
83
|
+
}
|
|
84
|
+
export declare interface NativeMutationErrorPayload {
|
|
85
|
+
version: 1
|
|
86
|
+
batchId: string
|
|
87
|
+
code: string
|
|
88
|
+
message: string
|
|
89
|
+
operationIndex?: number
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* UPDATE message payload
|
|
93
|
+
*/
|
|
94
|
+
export declare interface UpdatePayload {
|
|
95
|
+
updates: Array<{
|
|
96
|
+
key: string
|
|
97
|
+
props?: Record<string, unknown>
|
|
98
|
+
style?: Partial<import('../compiler/ir').STXStyle>
|
|
99
|
+
children?: (import('../compiler/ir').STXNode | string)[]
|
|
100
|
+
}>
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* REMOVE message payload
|
|
104
|
+
*/
|
|
105
|
+
export declare interface RemovePayload {
|
|
106
|
+
keys: string[]
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* EVENT message payload (Native → JS)
|
|
110
|
+
*/
|
|
111
|
+
export declare interface EventPayload {
|
|
112
|
+
eventType: string
|
|
113
|
+
targetKey: string
|
|
114
|
+
handlerName: string
|
|
115
|
+
nativeEvent: {
|
|
116
|
+
timestamp: number
|
|
117
|
+
touches?: Array<{
|
|
118
|
+
x: number
|
|
119
|
+
y: number
|
|
120
|
+
force?: number
|
|
121
|
+
identifier: number
|
|
122
|
+
}>
|
|
123
|
+
contentOffset?: { x: number; y: number }
|
|
124
|
+
contentSize?: { width: number; height: number }
|
|
125
|
+
layoutMeasurement?: { width: number; height: number }
|
|
126
|
+
text?: string
|
|
127
|
+
selection?: { start: number; end: number }
|
|
128
|
+
layout?: { x: number; y: number; width: number; height: number }
|
|
129
|
+
[key: string]: unknown
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* STATE_UPDATE message payload
|
|
134
|
+
*/
|
|
135
|
+
export declare interface StateUpdatePayload {
|
|
136
|
+
key: string
|
|
137
|
+
value: unknown
|
|
138
|
+
previousValue?: unknown
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* NAVIGATE message payload
|
|
142
|
+
*/
|
|
143
|
+
export declare interface NavigatePayload {
|
|
144
|
+
screen: string
|
|
145
|
+
params?: Record<string, unknown>
|
|
146
|
+
animation?: 'push' | 'modal' | 'fade' | 'none'
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* APP_STATE message payload
|
|
150
|
+
*/
|
|
151
|
+
export declare interface AppStatePayload {
|
|
152
|
+
state: 'active' | 'inactive' | 'background'
|
|
153
|
+
previousState?: 'active' | 'inactive' | 'background'
|
|
154
|
+
}
|
|
155
|
+
/** A normalized deep link delivered by either native host. */
|
|
156
|
+
export declare interface DeepLinkPayload {
|
|
157
|
+
url: string
|
|
158
|
+
scheme: string
|
|
159
|
+
host: string
|
|
160
|
+
path: string
|
|
161
|
+
query: string
|
|
162
|
+
queryParams?: Record<string, string>
|
|
163
|
+
initial?: boolean
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* API_REQUEST message payload
|
|
167
|
+
*/
|
|
168
|
+
export declare interface ApiRequestPayload {
|
|
169
|
+
version: 1
|
|
170
|
+
module: string
|
|
171
|
+
method: string
|
|
172
|
+
args: unknown[]
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The single argument of a `Network.fetch` capability request. The bundle's
|
|
176
|
+
* global `fetch` builds it; header names are lower-cased and bodies are text.
|
|
177
|
+
*/
|
|
178
|
+
export declare interface NativeFetchRequest {
|
|
179
|
+
url: string
|
|
180
|
+
method: string
|
|
181
|
+
headers: Record<string, string>
|
|
182
|
+
body: string | null
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The `API_RESPONSE` data for `Network.fetch`. HTTP error statuses are
|
|
186
|
+
* responses; transport failures are `API_ERROR`s with `NETWORK_ERROR`,
|
|
187
|
+
* `TIMEOUT`, `INVALID_ARGUMENT` or `RESPONSE_TOO_LARGE`.
|
|
188
|
+
*/
|
|
189
|
+
export declare interface NativeFetchResponse {
|
|
190
|
+
url: string
|
|
191
|
+
status: number
|
|
192
|
+
statusText: string
|
|
193
|
+
redirected: boolean
|
|
194
|
+
headers: Record<string, string>
|
|
195
|
+
body: string
|
|
196
|
+
}
|
|
197
|
+
/** A request that no longer has a JavaScript consumer. */
|
|
198
|
+
export declare interface ApiCancelPayload {
|
|
199
|
+
version: 1
|
|
200
|
+
requestId: string
|
|
201
|
+
reason: 'timeout' | 'screen-closed' | 'aborted'
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* API_RESPONSE message payload
|
|
205
|
+
*/
|
|
206
|
+
export declare interface ApiResponsePayload {
|
|
207
|
+
version: 1
|
|
208
|
+
requestId: string
|
|
209
|
+
data: unknown
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* API_ERROR message payload
|
|
213
|
+
*/
|
|
214
|
+
export declare interface ApiErrorPayload {
|
|
215
|
+
version: 1
|
|
216
|
+
requestId: string
|
|
217
|
+
code: string
|
|
218
|
+
message: string
|
|
219
|
+
stack?: string
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* HOT_RELOAD message payload
|
|
223
|
+
*/
|
|
224
|
+
export declare interface HotReloadPayload {
|
|
225
|
+
changedFiles: string[]
|
|
226
|
+
document?: import('../compiler/ir').STXDocument
|
|
227
|
+
preserveState: boolean
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* PERFORMANCE message payload
|
|
231
|
+
*/
|
|
232
|
+
export declare interface PerformancePayload {
|
|
233
|
+
metric: 'fps' | 'memory' | 'render_time' | 'bridge_latency'
|
|
234
|
+
value: number
|
|
235
|
+
context?: Record<string, unknown>
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Interface that native code must implement
|
|
239
|
+
*/
|
|
240
|
+
export declare interface NativeBridgeInterface {
|
|
241
|
+
platform?: 'ios' | 'android'
|
|
242
|
+
capabilityProtocolVersion?: 1
|
|
243
|
+
capabilities?: string[]
|
|
244
|
+
capabilityTimeoutMs?: number
|
|
245
|
+
initialAppState?: 'active' | 'inactive' | 'background'
|
|
246
|
+
postMessage(message: string): void
|
|
247
|
+
onMessage(callback: (message: string) => void): void
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* All possible message types in the bridge protocol
|
|
251
|
+
*/
|
|
252
|
+
export type BridgeMessageType = | 'RENDER' // Render a new component tree
|
|
253
|
+
| 'MUTATE' // Apply one atomic native-tree mutation batch
|
|
254
|
+
| 'MUTATION_ACK' // Native host committed a mutation batch
|
|
255
|
+
| 'MUTATION_ERROR' // Native host rejected a mutation batch
|
|
256
|
+
| 'UPDATE' // Update existing component(s)
|
|
257
|
+
| 'REMOVE' // Remove component(s) from tree
|
|
258
|
+
|
|
259
|
+
// Events
|
|
260
|
+
| 'EVENT' // Native event (touch, scroll, etc.)
|
|
261
|
+
| 'EVENT_RESPONSE' // JS response to event
|
|
262
|
+
|
|
263
|
+
// State
|
|
264
|
+
| 'STATE_UPDATE' // State changed, need re-render
|
|
265
|
+
| 'STATE_SYNC' // Sync state between JS and native
|
|
266
|
+
|
|
267
|
+
// Navigation
|
|
268
|
+
| 'NAVIGATE' // Navigate to a new screen
|
|
269
|
+
| 'NAVIGATE_BACK' // Go back
|
|
270
|
+
| 'NAVIGATE_REPLACE' // Replace current screen
|
|
271
|
+
|
|
272
|
+
// Lifecycle
|
|
273
|
+
| 'APP_STATE' // App foreground/background
|
|
274
|
+
| 'DEEP_LINK' // App opened or resumed through a URL
|
|
275
|
+
| 'SCREEN_FOCUS' // Screen gained/lost focus
|
|
276
|
+
| 'MEMORY_WARNING' // Low memory warning
|
|
277
|
+
|
|
278
|
+
// API
|
|
279
|
+
| 'API_REQUEST' // Call native API
|
|
280
|
+
| 'API_CANCEL' // Cancel an in-flight native API request
|
|
281
|
+
| 'API_RESPONSE' // Native API response
|
|
282
|
+
| 'API_ERROR' // Native API error
|
|
283
|
+
|
|
284
|
+
// Dev Tools
|
|
285
|
+
| 'HOT_RELOAD' // Hot reload triggered
|
|
286
|
+
| 'DEBUG_LOG' // Debug logging
|
|
287
|
+
| 'INSPECT' // Inspector request
|
|
288
|
+
| 'PERFORMANCE' // Performance metrics;
|
|
289
|
+
export type NativeMutationOperation = | { op: 'createNode', id: string, node: NativeMutationNode, root?: boolean }
|
|
290
|
+
| { op: 'updateNode', id: string, patch: Omit<NativeMutationNode, 'type'> }
|
|
291
|
+
| { op: 'insertChild', parentId: string, childId: string, index: number }
|
|
292
|
+
| { op: 'moveChild', parentId: string, childId: string, index: number }
|
|
293
|
+
| { op: 'removeNode', id: string }
|
|
294
|
+
// ============================================================================
|
|
295
|
+
// Bridge Implementation
|
|
296
|
+
// ============================================================================
|
|
297
|
+
// eslint-disable-next-line pickier/no-unused-vars
|
|
298
|
+
declare type MessageHandler<T = unknown> = (message: BridgeMessage<T>) => void | Promise<void>;
|
|
299
|
+
declare type PendingRequest = {
|
|
300
|
+
resolve: (value: unknown) => void
|
|
301
|
+
reject: (error: Error) => void
|
|
302
|
+
timeout: ReturnType<typeof setTimeout> | null
|
|
303
|
+
}
|
|
304
|
+
export declare class NativeCapabilityError extends Error {
|
|
305
|
+
public readonly code: string;
|
|
306
|
+
constructor(code: string, message: string);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Bridge class for JS side
|
|
310
|
+
*/
|
|
311
|
+
export declare class STXBridge {
|
|
312
|
+
initialize(nativeBridge: NativeBridgeInterface): void;
|
|
313
|
+
send<T>(type: BridgeMessageType, payload: T): string;
|
|
314
|
+
request<T, R>(type: BridgeMessageType, payload: T, timeout?: unknown): Promise<R>;
|
|
315
|
+
on<T>(type: BridgeMessageType, handler: MessageHandler<T>): () => void;
|
|
316
|
+
once<T>(type: BridgeMessageType, handler: MessageHandler<T>): () => void;
|
|
317
|
+
render(document: import('../compiler/ir').STXDocument | import('../compiler/ir').STXNode, options?: { containerId?: string; mode?: 'replace' | 'append' | 'prepend' }): string;
|
|
318
|
+
mutate(payload: NativeMutationPayload): string;
|
|
319
|
+
update(updates: UpdatePayload['updates']): string;
|
|
320
|
+
remove(keys: string[]): string;
|
|
321
|
+
navigate(screen: string, params?: Record<string, unknown>, animation?: NavigatePayload['animation']): string;
|
|
322
|
+
goBack(): string;
|
|
323
|
+
callNativeAPI<T>(module: string, method: string, ...args: unknown[]): Promise<T>;
|
|
324
|
+
log(level: 'info' | 'warn' | 'error', message: string, data?: unknown): void;
|
|
325
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
export class NativeCapabilityError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = "NativeCapabilityError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class STXBridge {
|
|
11
|
+
messageId = 0;
|
|
12
|
+
handlers = new Map;
|
|
13
|
+
pendingRequests = new Map;
|
|
14
|
+
nativeBridge = null;
|
|
15
|
+
defaultTimeout = 30000;
|
|
16
|
+
initialize(nativeBridge) {
|
|
17
|
+
this.nativeBridge = nativeBridge;
|
|
18
|
+
nativeBridge.onMessage((rawMessage) => {
|
|
19
|
+
try {
|
|
20
|
+
const message = JSON.parse(rawMessage);
|
|
21
|
+
this.handleIncomingMessage(message);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("[STXBridge] Failed to parse message:", error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
send(type, payload) {
|
|
28
|
+
const message = this.createMessage(type, payload);
|
|
29
|
+
this.postToNative(message);
|
|
30
|
+
return message.id;
|
|
31
|
+
}
|
|
32
|
+
async request(type, payload, timeout = this.defaultTimeout) {
|
|
33
|
+
const message = this.createMessage(type, payload);
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const scheduleTimeout = typeof globalThis.setTimeout === "function" ? globalThis.setTimeout.bind(globalThis) : null, timeoutId = scheduleTimeout ? scheduleTimeout(() => {
|
|
36
|
+
this.pendingRequests.delete(message.id);
|
|
37
|
+
if (type === "API_REQUEST")
|
|
38
|
+
this.postToNative(this.createMessage("API_CANCEL", {
|
|
39
|
+
version: 1,
|
|
40
|
+
requestId: message.id,
|
|
41
|
+
reason: "timeout"
|
|
42
|
+
}));
|
|
43
|
+
reject(new NativeCapabilityError("TIMEOUT", `Request ${message.id} timed out after ${timeout}ms`));
|
|
44
|
+
}, timeout) : null;
|
|
45
|
+
this.pendingRequests.set(message.id, {
|
|
46
|
+
resolve,
|
|
47
|
+
reject,
|
|
48
|
+
timeout: timeoutId
|
|
49
|
+
});
|
|
50
|
+
this.postToNative(message);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
on(type, handler) {
|
|
54
|
+
if (!this.handlers.has(type))
|
|
55
|
+
this.handlers.set(type, new Set);
|
|
56
|
+
this.handlers.get(type).add(handler);
|
|
57
|
+
return () => {
|
|
58
|
+
this.handlers.get(type)?.delete(handler);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
once(type, handler) {
|
|
62
|
+
const wrappedHandler = (message) => {
|
|
63
|
+
unsubscribe();
|
|
64
|
+
handler(message);
|
|
65
|
+
}, unsubscribe = this.on(type, wrappedHandler);
|
|
66
|
+
return unsubscribe;
|
|
67
|
+
}
|
|
68
|
+
render(document, options = {}) {
|
|
69
|
+
return this.send("RENDER", {
|
|
70
|
+
document,
|
|
71
|
+
containerId: options.containerId,
|
|
72
|
+
mode: options.mode || "replace"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
mutate(payload) {
|
|
76
|
+
return this.send("MUTATE", payload);
|
|
77
|
+
}
|
|
78
|
+
update(updates) {
|
|
79
|
+
return this.send("UPDATE", { updates });
|
|
80
|
+
}
|
|
81
|
+
remove(keys) {
|
|
82
|
+
return this.send("REMOVE", { keys });
|
|
83
|
+
}
|
|
84
|
+
navigate(screen, params, animation) {
|
|
85
|
+
return this.send("NAVIGATE", { screen, params, animation });
|
|
86
|
+
}
|
|
87
|
+
goBack() {
|
|
88
|
+
return this.send("NAVIGATE_BACK", {});
|
|
89
|
+
}
|
|
90
|
+
async callNativeAPI(module, method, ...args) {
|
|
91
|
+
return this.request("API_REQUEST", {
|
|
92
|
+
version: 1,
|
|
93
|
+
module,
|
|
94
|
+
method,
|
|
95
|
+
args
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
log(level, message, data) {
|
|
99
|
+
this.send("DEBUG_LOG", { level, message, data });
|
|
100
|
+
}
|
|
101
|
+
createMessage(type, payload) {
|
|
102
|
+
return {
|
|
103
|
+
id: `js_${++this.messageId}_${Date.now()}`,
|
|
104
|
+
type,
|
|
105
|
+
timestamp: Date.now(),
|
|
106
|
+
payload,
|
|
107
|
+
source: "js"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
postToNative(message) {
|
|
111
|
+
if (!this.nativeBridge) {
|
|
112
|
+
console.error("[STXBridge] Native bridge not initialized");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
this.nativeBridge.postMessage(JSON.stringify(message));
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("[STXBridge] Failed to post message:", error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
handleIncomingMessage(message) {
|
|
122
|
+
if (message.correlationId && this.pendingRequests.has(message.correlationId)) {
|
|
123
|
+
const pending = this.pendingRequests.get(message.correlationId);
|
|
124
|
+
this.pendingRequests.delete(message.correlationId);
|
|
125
|
+
if (pending.timeout !== null && typeof globalThis.clearTimeout === "function")
|
|
126
|
+
globalThis.clearTimeout(pending.timeout);
|
|
127
|
+
if (message.type === "API_ERROR") {
|
|
128
|
+
const error = message.payload;
|
|
129
|
+
pending.reject(new NativeCapabilityError(error.code, error.message));
|
|
130
|
+
} else
|
|
131
|
+
pending.resolve(message.payload.data);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const handlers = this.handlers.get(message.type);
|
|
135
|
+
if (handlers)
|
|
136
|
+
for (const handler of handlers)
|
|
137
|
+
try {
|
|
138
|
+
handler(message);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(`[STXBridge] Handler error for ${message.type}:`, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export const NativeBridges = {
|
|
145
|
+
ios: () => {
|
|
146
|
+
if (typeof webkit < "u" && webkit.messageHandlers?.stx)
|
|
147
|
+
return {
|
|
148
|
+
postMessage: (message) => {
|
|
149
|
+
webkit.messageHandlers.stx.postMessage(message);
|
|
150
|
+
},
|
|
151
|
+
onMessage: (callback) => {
|
|
152
|
+
globalThis.__stxNativeCallback = callback;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return null;
|
|
156
|
+
},
|
|
157
|
+
android: () => {
|
|
158
|
+
if (typeof STXNative < "u")
|
|
159
|
+
return {
|
|
160
|
+
postMessage: (message) => {
|
|
161
|
+
STXNative.postMessage(message);
|
|
162
|
+
},
|
|
163
|
+
onMessage: (callback) => {
|
|
164
|
+
globalThis.__stxNativeCallback = callback;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return null;
|
|
168
|
+
},
|
|
169
|
+
web: () => {
|
|
170
|
+
if (typeof window < "u")
|
|
171
|
+
return {
|
|
172
|
+
postMessage: (message) => {
|
|
173
|
+
window.postMessage({ type: "stx", message }, "*");
|
|
174
|
+
},
|
|
175
|
+
onMessage: (callback) => {
|
|
176
|
+
window.addEventListener("message", (event) => {
|
|
177
|
+
if (event.data?.type === "stx-native")
|
|
178
|
+
callback(event.data.message);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
export function createBridge() {
|
|
186
|
+
const bridge = new STXBridge, nativeBridge = NativeBridges.ios() || NativeBridges.android() || NativeBridges.web();
|
|
187
|
+
if (nativeBridge)
|
|
188
|
+
bridge.initialize(nativeBridge);
|
|
189
|
+
else
|
|
190
|
+
console.warn("[STXBridge] No native bridge available, running in mock mode");
|
|
191
|
+
return bridge;
|
|
192
|
+
}
|
|
193
|
+
let bridgeInstance = null;
|
|
194
|
+
export function getBridge() {
|
|
195
|
+
if (!bridgeInstance)
|
|
196
|
+
bridgeInstance = createBridge();
|
|
197
|
+
return bridgeInstance;
|
|
198
|
+
}
|
|
199
|
+
export function createEventHandler(handlerName, targetKey) {
|
|
200
|
+
return (nativeEvent) => {
|
|
201
|
+
getBridge().send("EVENT_RESPONSE", {
|
|
202
|
+
eventType: "callback",
|
|
203
|
+
targetKey,
|
|
204
|
+
handlerName,
|
|
205
|
+
nativeEvent
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export function registerHandler(name, handler) {
|
|
210
|
+
globalThis.__stxHandlers = globalThis.__stxHandlers || {};
|
|
211
|
+
globalThis.__stxHandlers[name] = handler;
|
|
212
|
+
}
|
|
213
|
+
export function callHandler(name, ...args) {
|
|
214
|
+
const handler = globalThis.__stxHandlers?.[name];
|
|
215
|
+
if (handler)
|
|
216
|
+
return handler(...args);
|
|
217
|
+
console.warn(`[STXBridge] Handler not found: ${name}`);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { NativeDiagnostic } from './compiler/bundle';
|
|
2
|
+
/** The screens config for a project, or null when it has none. */
|
|
3
|
+
export declare function loadNativeScreensConfig(cwd?: string, configFile?: string): NativeScreensConfig | null;
|
|
4
|
+
/** What `stx native compile` does, without the process around it. */
|
|
5
|
+
export declare function runNativeCompile(file: string | undefined, options?: NativeCompileOptions): Promise<NativeCompileResult>;
|
|
6
|
+
/** The config file names looked for, in order. The second is the old name. */
|
|
7
|
+
export declare const NATIVE_CONFIG_FILES: string[];
|
|
8
|
+
export declare interface NativeScreensConfig {
|
|
9
|
+
initialScreen: string
|
|
10
|
+
screens: Record<string, string>
|
|
11
|
+
file: string
|
|
12
|
+
}
|
|
13
|
+
export declare interface NativeCompileOptions {
|
|
14
|
+
format?: 'ir' | 'bundle'
|
|
15
|
+
output?: string
|
|
16
|
+
minify?: boolean
|
|
17
|
+
config?: string
|
|
18
|
+
cwd?: string
|
|
19
|
+
}
|
|
20
|
+
export declare interface NativeCompileResult {
|
|
21
|
+
output: string
|
|
22
|
+
written?: string
|
|
23
|
+
diagnostics: NativeDiagnostic[]
|
|
24
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { compileNativeBundle, compileScreenBundle } from "./compiler/bundle.js";
|
|
4
|
+
import { parseSTX } from "./compiler/parser.js";
|
|
5
|
+
export const NATIVE_CONFIG_FILES = ["native.config.json", "stx-native.config.json"];
|
|
6
|
+
export function loadNativeScreensConfig(cwd = process.cwd(), configFile) {
|
|
7
|
+
const file = configFile ? path.resolve(cwd, configFile) : NATIVE_CONFIG_FILES.map((name) => path.join(cwd, name)).find((candidate) => existsSync(candidate));
|
|
8
|
+
if (!file)
|
|
9
|
+
return null;
|
|
10
|
+
if (!existsSync(file))
|
|
11
|
+
throw Error(`Native config not found: ${file}`);
|
|
12
|
+
const raw = JSON.parse(readFileSync(file, "utf8")), entries = Object.entries(raw.screens ?? {});
|
|
13
|
+
if (entries.length === 0)
|
|
14
|
+
throw Error(`${path.basename(file)} must name at least one screen in "screens"`);
|
|
15
|
+
const screens = {};
|
|
16
|
+
for (const [name, screen] of entries) {
|
|
17
|
+
if (!/^[A-Z][\w-]*$/i.test(name))
|
|
18
|
+
throw Error(`Invalid native screen name: ${name}`);
|
|
19
|
+
if (typeof screen !== "string" || !screen.endsWith(".stx"))
|
|
20
|
+
throw Error(`Screen ${name} must name a .stx file`);
|
|
21
|
+
screens[name] = path.resolve(path.dirname(file), screen);
|
|
22
|
+
if (!existsSync(screens[name]))
|
|
23
|
+
throw Error(`Screen ${name} not found: ${screens[name]}`);
|
|
24
|
+
}
|
|
25
|
+
const initialScreen = raw.initialScreen || entries[0][0];
|
|
26
|
+
if (!screens[initialScreen])
|
|
27
|
+
throw Error(`Initial screen ${initialScreen} is not in screens`);
|
|
28
|
+
return { initialScreen, screens, file };
|
|
29
|
+
}
|
|
30
|
+
export async function runNativeCompile(file, options = {}) {
|
|
31
|
+
const cwd = path.resolve(options.cwd ?? process.cwd()), format = options.format ?? "ir";
|
|
32
|
+
if (format !== "ir" && format !== "bundle")
|
|
33
|
+
throw Error(`Unknown compile format: ${format}. Expected ir or bundle.`);
|
|
34
|
+
const config = file ? null : loadNativeScreensConfig(cwd, options.config);
|
|
35
|
+
if (!file && !config)
|
|
36
|
+
throw Error(`Please specify an input file: stx native compile <file.stx>, or add ${NATIVE_CONFIG_FILES[0]}`);
|
|
37
|
+
let output, diagnostics = [];
|
|
38
|
+
if (format === "bundle") {
|
|
39
|
+
const bundle = config ? await compileNativeBundle({ screens: config.screens, initialScreen: config.initialScreen, minify: options.minify, root: cwd }) : await compileScreenBundle(path.resolve(cwd, file), { minify: options.minify });
|
|
40
|
+
output = bundle.code;
|
|
41
|
+
diagnostics = bundle.diagnostics;
|
|
42
|
+
} else {
|
|
43
|
+
const parse = (source) => parseSTX(readFileSync(source, "utf8"), source), ir = config ? { initialScreen: config.initialScreen, screens: Object.fromEntries(Object.entries(config.screens).map(([name, source]) => [name, parse(source)])) } : parse(path.resolve(cwd, file));
|
|
44
|
+
output = JSON.stringify(ir, null, 2);
|
|
45
|
+
}
|
|
46
|
+
if (!options.output)
|
|
47
|
+
return { output, diagnostics };
|
|
48
|
+
const written = path.resolve(cwd, options.output);
|
|
49
|
+
mkdirSync(path.dirname(written), { recursive: !0 });
|
|
50
|
+
await Bun.write(written, output);
|
|
51
|
+
return { output, written, diagnostics };
|
|
52
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RUNTIME_SPECIFIER } from './codegen';
|
|
2
|
+
/**
|
|
3
|
+
* Build the bundle the host loads as `native-screen.js`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { compileNativeBundle } from '@stacksjs/stx/native'
|
|
8
|
+
*
|
|
9
|
+
* const { outFile, diagnostics } = await compileNativeBundle({
|
|
10
|
+
* screens: { Today: 'resources/native/Today.stx' },
|
|
11
|
+
* initialScreen: 'Today',
|
|
12
|
+
* minify: true,
|
|
13
|
+
* outFile: 'storage/framework/native/native-screen.js',
|
|
14
|
+
* root: process.cwd(),
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function compileNativeBundle(options: CompileNativeBundleOptions): Promise<NativeBundleResult>;
|
|
19
|
+
/** One `.stx` file, as the single-screen bundle `compile <file> --format bundle` writes. */
|
|
20
|
+
export declare function compileScreenBundle(file: string, options?: Pick<CompileNativeBundleOptions, 'minify' | 'outFile' | 'root'>): Promise<NativeBundleResult>;
|
|
21
|
+
export declare interface CompileNativeBundleOptions {
|
|
22
|
+
screens: Record<string, string>
|
|
23
|
+
initialScreen?: string
|
|
24
|
+
minify?: boolean
|
|
25
|
+
routed?: boolean
|
|
26
|
+
outFile?: string
|
|
27
|
+
root?: string
|
|
28
|
+
}
|
|
29
|
+
/** Something the compiler could not translate exactly: an unknown icon or class. */
|
|
30
|
+
export declare interface NativeDiagnostic {
|
|
31
|
+
level: 'warning'
|
|
32
|
+
message: string
|
|
33
|
+
}
|
|
34
|
+
export declare interface NativeBundleResult {
|
|
35
|
+
code: string
|
|
36
|
+
outFile?: string
|
|
37
|
+
diagnostics: NativeDiagnostic[]
|
|
38
|
+
}
|
|
39
|
+
/** @deprecated Use `CompileNativeBundleOptions`. */
|
|
40
|
+
export type BundleOptions = CompileNativeBundleOptions;
|
|
41
|
+
export { RUNTIME_SPECIFIER };
|