@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,753 @@
|
|
|
1
|
+
import { createNode, createDocument } from "./ir.js";
|
|
2
|
+
import { compileClassStyles } from "./headwind-to-style.js";
|
|
3
|
+
import { iconClassIn, resolveIconName } from "./icons.js";
|
|
4
|
+
|
|
5
|
+
class Lexer {
|
|
6
|
+
input;
|
|
7
|
+
pos = 0;
|
|
8
|
+
line = 1;
|
|
9
|
+
column = 1;
|
|
10
|
+
inTag = !1;
|
|
11
|
+
templates = [];
|
|
12
|
+
constructor(input) {
|
|
13
|
+
this.input = input;
|
|
14
|
+
}
|
|
15
|
+
tokenize() {
|
|
16
|
+
const tokens = [];
|
|
17
|
+
while (this.pos < this.input.length) {
|
|
18
|
+
const token = this.nextToken();
|
|
19
|
+
if (token)
|
|
20
|
+
tokens.push(token);
|
|
21
|
+
}
|
|
22
|
+
tokens.push({ type: "EOF", value: "", line: this.line, column: this.column });
|
|
23
|
+
return tokens;
|
|
24
|
+
}
|
|
25
|
+
nextToken() {
|
|
26
|
+
if (this.inTag)
|
|
27
|
+
this.skipWhitespace();
|
|
28
|
+
if (this.pos >= this.input.length)
|
|
29
|
+
return null;
|
|
30
|
+
const startLine = this.line, startColumn = this.column;
|
|
31
|
+
if (this.match("<!--")) {
|
|
32
|
+
const endIndex = this.input.indexOf("-->", this.pos);
|
|
33
|
+
if (endIndex === -1)
|
|
34
|
+
throw Error(`Unclosed comment at line ${startLine}`);
|
|
35
|
+
const value = this.input.slice(this.pos, endIndex);
|
|
36
|
+
this.advance(endIndex - this.pos + 3);
|
|
37
|
+
return { type: "COMMENT", value, line: startLine, column: startColumn };
|
|
38
|
+
}
|
|
39
|
+
if (this.match("<script")) {
|
|
40
|
+
const closeTag = "</script>", contentStart = this.input.indexOf(">", this.pos) + 1, contentEnd = this.input.indexOf(closeTag, contentStart);
|
|
41
|
+
if (contentEnd === -1)
|
|
42
|
+
throw Error(`Unclosed <script> block at line ${startLine}`);
|
|
43
|
+
const value = this.input.slice(contentStart, contentEnd).trim(), attributes = this.input.slice(this.pos + 7, contentStart - 1);
|
|
44
|
+
this.advance(contentEnd - this.pos + closeTag.length);
|
|
45
|
+
if (/\bserver\b/.test(attributes))
|
|
46
|
+
return null;
|
|
47
|
+
return { type: "SCRIPT_BLOCK", value, line: startLine, column: startColumn };
|
|
48
|
+
}
|
|
49
|
+
if (this.match("<style")) {
|
|
50
|
+
const closeTag = "</style>", contentStart = this.input.indexOf(">", this.pos) + 1, contentEnd = this.input.indexOf(closeTag, contentStart);
|
|
51
|
+
if (contentEnd === -1)
|
|
52
|
+
throw Error(`Unclosed <style> block at line ${startLine}`);
|
|
53
|
+
const value = this.input.slice(contentStart, contentEnd).trim();
|
|
54
|
+
this.advance(contentEnd - this.pos + closeTag.length);
|
|
55
|
+
return { type: "STYLE_BLOCK", value, line: startLine, column: startColumn };
|
|
56
|
+
}
|
|
57
|
+
if (this.match("<template>")) {
|
|
58
|
+
this.templates.push(!1);
|
|
59
|
+
this.advance(10);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (this.match("<template"))
|
|
63
|
+
this.templates.push(!0);
|
|
64
|
+
if (this.match("</template>") && this.templates.pop() !== !0) {
|
|
65
|
+
this.advance(11);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (this.match("</")) {
|
|
69
|
+
this.advance(2);
|
|
70
|
+
const tagName = this.readTagName();
|
|
71
|
+
this.skipWhitespace();
|
|
72
|
+
if (this.peek() !== ">")
|
|
73
|
+
throw Error(`Expected > at line ${this.line}`);
|
|
74
|
+
this.advance(1);
|
|
75
|
+
this.inTag = !1;
|
|
76
|
+
return { type: "TAG_CLOSE", value: tagName, line: startLine, column: startColumn };
|
|
77
|
+
}
|
|
78
|
+
if (this.peek() === "<") {
|
|
79
|
+
this.advance(1);
|
|
80
|
+
const tagName = this.readTagName();
|
|
81
|
+
this.inTag = !0;
|
|
82
|
+
return { type: "TAG_OPEN", value: tagName, line: startLine, column: startColumn };
|
|
83
|
+
}
|
|
84
|
+
if (this.match("/>")) {
|
|
85
|
+
this.advance(2);
|
|
86
|
+
this.inTag = !1;
|
|
87
|
+
return { type: "TAG_SELF_CLOSE", value: "/>", line: startLine, column: startColumn };
|
|
88
|
+
}
|
|
89
|
+
if (this.peek() === ">") {
|
|
90
|
+
this.advance(1);
|
|
91
|
+
this.inTag = !1;
|
|
92
|
+
return { type: "TAG_END", value: ">", line: startLine, column: startColumn };
|
|
93
|
+
}
|
|
94
|
+
if (!this.inTag && this.match("{{")) {
|
|
95
|
+
const end = this.input.indexOf("}}", this.pos + 2);
|
|
96
|
+
if (end !== -1) {
|
|
97
|
+
const value = this.input.slice(this.pos + 2, end);
|
|
98
|
+
this.advance(end - this.pos + 2);
|
|
99
|
+
return { type: "EXPRESSION", value: value.trim(), line: startLine, column: startColumn };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (this.peek() === "{") {
|
|
103
|
+
this.advance(1);
|
|
104
|
+
let depth = 1, value = "";
|
|
105
|
+
while (depth > 0 && this.pos < this.input.length) {
|
|
106
|
+
const char = this.peek();
|
|
107
|
+
if (char === "{")
|
|
108
|
+
depth++;
|
|
109
|
+
else if (char === "}")
|
|
110
|
+
depth--;
|
|
111
|
+
if (depth > 0)
|
|
112
|
+
value += char;
|
|
113
|
+
this.advance(1);
|
|
114
|
+
}
|
|
115
|
+
return { type: "EXPRESSION", value: value.trim(), line: startLine, column: startColumn };
|
|
116
|
+
}
|
|
117
|
+
if (this.inTag && (this.isAlpha(this.peek()) || this.peek() === ":" || this.peek() === "@")) {
|
|
118
|
+
const attrName = this.readAttributeName();
|
|
119
|
+
this.skipWhitespace();
|
|
120
|
+
if (this.peek() === "=") {
|
|
121
|
+
this.advance(1);
|
|
122
|
+
this.skipWhitespace();
|
|
123
|
+
let attrValue, raw;
|
|
124
|
+
if (this.peek() === '"' || this.peek() === "'") {
|
|
125
|
+
const quote = this.peek();
|
|
126
|
+
this.advance(1);
|
|
127
|
+
attrValue = "";
|
|
128
|
+
while (this.peek() !== quote && this.pos < this.input.length) {
|
|
129
|
+
attrValue += this.peek();
|
|
130
|
+
this.advance(1);
|
|
131
|
+
}
|
|
132
|
+
this.advance(1);
|
|
133
|
+
} else if (this.peek() === "{") {
|
|
134
|
+
this.advance(1);
|
|
135
|
+
let depth = 1;
|
|
136
|
+
attrValue = "";
|
|
137
|
+
while (depth > 0 && this.pos < this.input.length) {
|
|
138
|
+
const char = this.peek();
|
|
139
|
+
if (char === "{")
|
|
140
|
+
depth++;
|
|
141
|
+
else if (char === "}")
|
|
142
|
+
depth--;
|
|
143
|
+
if (depth > 0)
|
|
144
|
+
attrValue += char;
|
|
145
|
+
this.advance(1);
|
|
146
|
+
}
|
|
147
|
+
raw = `{${attrValue}}`;
|
|
148
|
+
attrValue = attrValue.trim();
|
|
149
|
+
} else
|
|
150
|
+
throw Error(`Expected " or { after = at line ${this.line}`);
|
|
151
|
+
return {
|
|
152
|
+
type: "ATTRIBUTE",
|
|
153
|
+
value: `${attrName}=${attrValue}`,
|
|
154
|
+
raw,
|
|
155
|
+
line: startLine,
|
|
156
|
+
column: startColumn
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return { type: "ATTRIBUTE", value: `${attrName}=true`, line: startLine, column: startColumn };
|
|
160
|
+
}
|
|
161
|
+
let text = "";
|
|
162
|
+
while (this.pos < this.input.length && this.peek() !== "<" && this.peek() !== "{") {
|
|
163
|
+
text += this.peek();
|
|
164
|
+
this.advance(1);
|
|
165
|
+
}
|
|
166
|
+
if (text.trim() || text && !text.includes(`
|
|
167
|
+
`))
|
|
168
|
+
return { type: "TEXT", value: text, line: startLine, column: startColumn };
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
match(str) {
|
|
172
|
+
return this.input.slice(this.pos, this.pos + str.length) === str;
|
|
173
|
+
}
|
|
174
|
+
peek() {
|
|
175
|
+
return this.input[this.pos] || "";
|
|
176
|
+
}
|
|
177
|
+
advance(n) {
|
|
178
|
+
for (let i = 0;i < n; i++) {
|
|
179
|
+
if (this.input[this.pos] === `
|
|
180
|
+
`) {
|
|
181
|
+
this.line++;
|
|
182
|
+
this.column = 1;
|
|
183
|
+
} else
|
|
184
|
+
this.column++;
|
|
185
|
+
this.pos++;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
skipWhitespace() {
|
|
189
|
+
while (this.pos < this.input.length && /\s/.test(this.peek()))
|
|
190
|
+
this.advance(1);
|
|
191
|
+
}
|
|
192
|
+
readTagName() {
|
|
193
|
+
let name = "";
|
|
194
|
+
while (this.pos < this.input.length && /[a-zA-Z0-9_-]/.test(this.peek())) {
|
|
195
|
+
name += this.peek();
|
|
196
|
+
this.advance(1);
|
|
197
|
+
}
|
|
198
|
+
return name;
|
|
199
|
+
}
|
|
200
|
+
readAttributeName() {
|
|
201
|
+
let name = "";
|
|
202
|
+
while (this.pos < this.input.length && /[a-zA-Z0-9_\-:@]/.test(this.peek())) {
|
|
203
|
+
name += this.peek();
|
|
204
|
+
this.advance(1);
|
|
205
|
+
}
|
|
206
|
+
return name;
|
|
207
|
+
}
|
|
208
|
+
isAlpha(char) {
|
|
209
|
+
return /[a-zA-Z_]/.test(char);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
class Parser {
|
|
214
|
+
ctx;
|
|
215
|
+
constructor(tokens, source) {
|
|
216
|
+
this.ctx = {
|
|
217
|
+
source,
|
|
218
|
+
tokens,
|
|
219
|
+
pos: 0,
|
|
220
|
+
scriptCode: "",
|
|
221
|
+
exports: {},
|
|
222
|
+
functions: [],
|
|
223
|
+
warnings: []
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
parse() {
|
|
227
|
+
this.extractScriptBlocks();
|
|
228
|
+
this.ctx.pos = 0;
|
|
229
|
+
const root = this.parseElement();
|
|
230
|
+
if (!root)
|
|
231
|
+
throw Error("No root element found in template");
|
|
232
|
+
const document = createDocument(root, {
|
|
233
|
+
exports: this.ctx.exports,
|
|
234
|
+
functions: this.ctx.functions,
|
|
235
|
+
code: this.ctx.scriptCode
|
|
236
|
+
}, {
|
|
237
|
+
source: this.ctx.source,
|
|
238
|
+
compiledAt: Date.now()
|
|
239
|
+
});
|
|
240
|
+
if (this.ctx.warnings.length)
|
|
241
|
+
document.meta.warnings = [...new Set(this.ctx.warnings)];
|
|
242
|
+
return document;
|
|
243
|
+
}
|
|
244
|
+
extractScriptBlocks() {
|
|
245
|
+
while (this.ctx.pos < this.ctx.tokens.length) {
|
|
246
|
+
const token = this.peek();
|
|
247
|
+
if (token.type === "SCRIPT_BLOCK") {
|
|
248
|
+
this.ctx.scriptCode += `${token.value}
|
|
249
|
+
`;
|
|
250
|
+
this.extractExportsAndFunctions(token.value);
|
|
251
|
+
}
|
|
252
|
+
this.advance();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
extractExportsAndFunctions(code) {
|
|
256
|
+
const varPattern = /(?:let|const|var)\s+(\w+)\s*=\s*([^;\n]+)/g;
|
|
257
|
+
let match;
|
|
258
|
+
while ((match = varPattern.exec(code)) !== null) {
|
|
259
|
+
const [, name, value] = match;
|
|
260
|
+
try {
|
|
261
|
+
this.ctx.exports[name] = JSON.parse(value.trim());
|
|
262
|
+
} catch {
|
|
263
|
+
this.ctx.exports[name] = value.trim();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const funcPattern = /(?:function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)|[^=])\s*=>)/g;
|
|
267
|
+
while ((match = funcPattern.exec(code)) !== null) {
|
|
268
|
+
const name = match[1] || match[2];
|
|
269
|
+
if (name && !this.ctx.functions.includes(name))
|
|
270
|
+
this.ctx.functions.push(name);
|
|
271
|
+
}
|
|
272
|
+
const asyncFuncPattern = /async\s+function\s+(\w+)/g;
|
|
273
|
+
while ((match = asyncFuncPattern.exec(code)) !== null) {
|
|
274
|
+
const name = match[1];
|
|
275
|
+
if (name && !this.ctx.functions.includes(name))
|
|
276
|
+
this.ctx.functions.push(name);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
parseElement() {
|
|
280
|
+
this.skipNonElements();
|
|
281
|
+
const token = this.peek();
|
|
282
|
+
if (token.type === "EOF")
|
|
283
|
+
return null;
|
|
284
|
+
if (token.type !== "TAG_OPEN") {
|
|
285
|
+
if (token.type === "TEXT") {
|
|
286
|
+
this.advance();
|
|
287
|
+
return createNode("Text", {}, {}, {}, [token.value]);
|
|
288
|
+
}
|
|
289
|
+
if (token.type === "EXPRESSION") {
|
|
290
|
+
this.advance();
|
|
291
|
+
return createNode("Text", {}, {}, {}, [`{${token.value}}`]);
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
const tagName = token.value, source = { file: this.ctx.source, line: token.line, column: token.column };
|
|
296
|
+
this.advance();
|
|
297
|
+
const attributes = this.parseAttributes(tagName, token.line), { props, style, events } = attributes, nextToken = this.peek();
|
|
298
|
+
if (nextToken.type === "TAG_SELF_CLOSE") {
|
|
299
|
+
this.advance();
|
|
300
|
+
const node = createNode(tagName, props, style, events, []);
|
|
301
|
+
this.finishNode(node, attributes, source);
|
|
302
|
+
return node;
|
|
303
|
+
}
|
|
304
|
+
if (nextToken.type !== "TAG_END")
|
|
305
|
+
throw Error(`Expected > or /> at line ${nextToken.line}, got ${nextToken.type}`);
|
|
306
|
+
this.advance();
|
|
307
|
+
const children = [];
|
|
308
|
+
while (!0) {
|
|
309
|
+
this.skipComments();
|
|
310
|
+
const childToken = this.peek();
|
|
311
|
+
if (childToken.type === "EOF")
|
|
312
|
+
throw Error(`Unclosed tag <${tagName}> at line ${token.line}`);
|
|
313
|
+
if (childToken.type === "TAG_CLOSE") {
|
|
314
|
+
if (childToken.value !== tagName)
|
|
315
|
+
throw Error(`Mismatched closing tag: expected </${tagName}>, got </${childToken.value}> at line ${childToken.line}`);
|
|
316
|
+
this.advance();
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
if (childToken.type === "TEXT") {
|
|
320
|
+
children.push(childToken.value);
|
|
321
|
+
this.advance();
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (childToken.type === "EXPRESSION") {
|
|
325
|
+
children.push(`{${childToken.value}}`);
|
|
326
|
+
this.advance();
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (childToken.type === "TAG_OPEN") {
|
|
330
|
+
const childNode = this.parseElement();
|
|
331
|
+
if (childNode)
|
|
332
|
+
children.push(childNode);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
this.advance();
|
|
336
|
+
}
|
|
337
|
+
const node = createNode(tagName, props, style, events, children);
|
|
338
|
+
this.finishNode(node, attributes, source);
|
|
339
|
+
return node;
|
|
340
|
+
}
|
|
341
|
+
finishNode(node, attributes, source) {
|
|
342
|
+
if (typeof node.props.__text === "string") {
|
|
343
|
+
node.children = [`{${node.props.__text}}`];
|
|
344
|
+
delete node.props.__text;
|
|
345
|
+
}
|
|
346
|
+
normalizeWhitespace(node);
|
|
347
|
+
if (attributes.classes)
|
|
348
|
+
node._classes = attributes.classes;
|
|
349
|
+
node._source = source;
|
|
350
|
+
if (attributes.darkStyle)
|
|
351
|
+
node.darkStyle = attributes.darkStyle;
|
|
352
|
+
if (Object.keys(attributes.directives).length)
|
|
353
|
+
node.directives = attributes.directives;
|
|
354
|
+
if (Object.keys(attributes.bindings).length)
|
|
355
|
+
node.bindings = attributes.bindings;
|
|
356
|
+
if (attributes.numberOfLines !== void 0 && node.props.numberOfLines === void 0)
|
|
357
|
+
node.props.numberOfLines = attributes.numberOfLines;
|
|
358
|
+
if (node.type === "Icon")
|
|
359
|
+
this.finishIcon(node, attributes.icon);
|
|
360
|
+
}
|
|
361
|
+
finishIcon(node, iconClass) {
|
|
362
|
+
const props = node.props, isExpression = (value) => typeof value === "string" && /\{[^}]*\}/.test(value);
|
|
363
|
+
if (props.size !== void 0) {
|
|
364
|
+
const size = Number(props.size);
|
|
365
|
+
if (Number.isFinite(size)) {
|
|
366
|
+
node.style.width ??= size;
|
|
367
|
+
node.style.height ??= size;
|
|
368
|
+
delete props.size;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
node.children = [];
|
|
372
|
+
if (props.symbol !== void 0) {
|
|
373
|
+
delete props.name;
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const name = props.name ?? props.icon ?? iconClass;
|
|
377
|
+
delete props.icon;
|
|
378
|
+
if (name === void 0) {
|
|
379
|
+
if (!node.bindings?.class)
|
|
380
|
+
this.ctx.warnings.push(`<Icon> without symbol, name or an i-* class in ${this.ctx.source}; drawn as circle`);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (isExpression(name)) {
|
|
384
|
+
props.name = name;
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
delete props.name;
|
|
388
|
+
const icon = resolveIconName(String(name));
|
|
389
|
+
props.symbol = icon.symbol;
|
|
390
|
+
if (icon.iconify)
|
|
391
|
+
props.iconify = icon.iconify;
|
|
392
|
+
if (!icon.known)
|
|
393
|
+
this.ctx.warnings.push(`Unknown icon ${name} in ${this.ctx.source}; drawn as ${icon.symbol}`);
|
|
394
|
+
}
|
|
395
|
+
parseAttributes(tagName, line) {
|
|
396
|
+
const props = {}, events = {}, directives = {}, bindings = {};
|
|
397
|
+
let classes = "", inlineStyle = {};
|
|
398
|
+
while (this.peek().type === "ATTRIBUTE") {
|
|
399
|
+
const token = this.peek();
|
|
400
|
+
this.advance();
|
|
401
|
+
const [rawName, ...valueParts] = token.value.split("="), value = valueParts.join("="), name = rawName.startsWith("x-bind:") ? `:${rawName.slice(7)}` : rawName.startsWith("x-on:") ? `@${rawName.slice(5)}` : rawName, bound = name.startsWith(":") || name.startsWith("x-") && name !== "x-cloak", binding = bound ? name.startsWith(":") ? name.slice(1) : name.slice(2) : "", boolean = !token.raw && value === "true" && !token.value.endsWith('="true"');
|
|
402
|
+
if (bound && binding === "if") {
|
|
403
|
+
directives.if = value;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (bound && (binding === "else-if" || binding === "elseif")) {
|
|
407
|
+
directives.elseIf = value;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (bound && binding === "else") {
|
|
411
|
+
directives.else = !0;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (bound && binding === "show") {
|
|
415
|
+
directives.show = value;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (bound && binding === "for") {
|
|
419
|
+
const loop = parseForExpression(value);
|
|
420
|
+
if (!loop)
|
|
421
|
+
throw Error(`Cannot read :for="${value}" at line ${line}: expected "item in items" or "(item, index) in items"`);
|
|
422
|
+
directives.for = loop;
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (bound && binding === "key") {
|
|
426
|
+
props.key = `{${value}}`;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (bound && binding === "text") {
|
|
430
|
+
props.__text = value;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (name === "x-cloak" || name === "x-data")
|
|
434
|
+
continue;
|
|
435
|
+
if (name === "class" || name === "className" || bound && (binding === "class" || binding === "className")) {
|
|
436
|
+
if (bound || token.raw)
|
|
437
|
+
bindings.class = value;
|
|
438
|
+
else
|
|
439
|
+
classes = classes ? `${classes} ${value}` : value;
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (name === "style" || bound && binding === "style") {
|
|
443
|
+
if (bound) {
|
|
444
|
+
bindings.style = value;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (token.raw) {
|
|
448
|
+
try {
|
|
449
|
+
inlineStyle = { ...inlineStyle, ...JSON.parse(value) };
|
|
450
|
+
} catch {
|
|
451
|
+
bindings.style = value;
|
|
452
|
+
}
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
if (value.startsWith("{") && value.endsWith("}"))
|
|
457
|
+
inlineStyle = { ...inlineStyle, ...JSON.parse(value) };
|
|
458
|
+
else
|
|
459
|
+
inlineStyle = { ...inlineStyle, ...JSON.parse(`{${value}}`) };
|
|
460
|
+
} catch {
|
|
461
|
+
inlineStyle = { ...inlineStyle, ...this.parseCSSInJS(value) };
|
|
462
|
+
}
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (/^on[A-Z]/.test(name) && !NOT_EVENTS.has(name) || name.startsWith("@")) {
|
|
466
|
+
const eventName = name.startsWith("@") ? nativeEventName(name.slice(1)) : name;
|
|
467
|
+
if (!boolean)
|
|
468
|
+
events[eventName] = value;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (name === "key") {
|
|
472
|
+
props.key = token.raw ?? value;
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
if (bound) {
|
|
476
|
+
props[binding] = `{${value}}`;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (token.raw) {
|
|
480
|
+
try {
|
|
481
|
+
props[name] = JSON.parse(value);
|
|
482
|
+
} catch {
|
|
483
|
+
props[name] = token.raw;
|
|
484
|
+
}
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
try {
|
|
488
|
+
props[name] = JSON.parse(value);
|
|
489
|
+
} catch {
|
|
490
|
+
props[name] = value;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const compiled = classes ? compileClassStyles(classes) : null;
|
|
494
|
+
if (compiled && compiled.unknown.length)
|
|
495
|
+
this.ctx.warnings.push(`Classes with no native style on <${tagName}> at line ${line}: ${compiled.unknown.join(" ")}`);
|
|
496
|
+
const style = { ...compiled?.style ?? {}, ...inlineStyle };
|
|
497
|
+
return {
|
|
498
|
+
props,
|
|
499
|
+
style,
|
|
500
|
+
events,
|
|
501
|
+
classes,
|
|
502
|
+
directives,
|
|
503
|
+
bindings,
|
|
504
|
+
darkStyle: compiled?.dark,
|
|
505
|
+
numberOfLines: compiled?.numberOfLines,
|
|
506
|
+
icon: compiled?.icon ?? (classes ? iconClassIn(classes) : void 0)
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
parseCSSInJS(value) {
|
|
510
|
+
const style = {}, pairs = value.split(",").map((p) => p.trim());
|
|
511
|
+
for (const pair of pairs) {
|
|
512
|
+
const colonIndex = pair.indexOf(":");
|
|
513
|
+
if (colonIndex === -1)
|
|
514
|
+
continue;
|
|
515
|
+
const key = pair.slice(0, colonIndex).trim();
|
|
516
|
+
let val = pair.slice(colonIndex + 1).trim();
|
|
517
|
+
if (val.startsWith("'") && val.endsWith("'") || val.startsWith('"') && val.endsWith('"'))
|
|
518
|
+
val = val.slice(1, -1);
|
|
519
|
+
const numVal = Number(val);
|
|
520
|
+
style[key] = Number.isNaN(numVal) ? val : numVal;
|
|
521
|
+
}
|
|
522
|
+
return style;
|
|
523
|
+
}
|
|
524
|
+
skipNonElements() {
|
|
525
|
+
while (this.peek().type === "SCRIPT_BLOCK" || this.peek().type === "STYLE_BLOCK" || this.peek().type === "COMMENT")
|
|
526
|
+
this.advance();
|
|
527
|
+
}
|
|
528
|
+
skipComments() {
|
|
529
|
+
while (this.peek().type === "COMMENT")
|
|
530
|
+
this.advance();
|
|
531
|
+
}
|
|
532
|
+
peek() {
|
|
533
|
+
return this.ctx.tokens[this.ctx.pos] || { type: "EOF", value: "", line: 0, column: 0 };
|
|
534
|
+
}
|
|
535
|
+
advance() {
|
|
536
|
+
this.ctx.pos++;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function normalizeWhitespace(node) {
|
|
540
|
+
const hasElements = node.children.some((child) => typeof child !== "string");
|
|
541
|
+
let children = node.children.map((child) => typeof child === "string" && !/^\{[\s\S]*\}$/.test(child) ? child.replace(/\s+/g, " ") : child).filter((child) => !(hasElements && typeof child === "string" && !child.trim()));
|
|
542
|
+
if (!hasElements && children.length) {
|
|
543
|
+
const first = children[0], last = children[children.length - 1];
|
|
544
|
+
if (typeof first === "string")
|
|
545
|
+
children[0] = first.replace(/^\s+/, "");
|
|
546
|
+
if (typeof last === "string")
|
|
547
|
+
children[children.length - 1] = children[children.length - 1].replace(/\s+$/, "");
|
|
548
|
+
children = children.filter((child) => child !== "");
|
|
549
|
+
}
|
|
550
|
+
node.children = children;
|
|
551
|
+
}
|
|
552
|
+
const NOT_EVENTS = new Set(["onEndReachedThreshold"]), NATIVE_EVENT_NAMES = {
|
|
553
|
+
click: "onPress",
|
|
554
|
+
press: "onPress",
|
|
555
|
+
tap: "onPress",
|
|
556
|
+
longpress: "onLongPress",
|
|
557
|
+
contextmenu: "onLongPress",
|
|
558
|
+
input: "onChangeText",
|
|
559
|
+
change: "onChange",
|
|
560
|
+
focus: "onFocus",
|
|
561
|
+
blur: "onBlur",
|
|
562
|
+
submit: "onSubmitEditing",
|
|
563
|
+
scroll: "onScroll",
|
|
564
|
+
refresh: "onRefresh",
|
|
565
|
+
close: "onRequestClose",
|
|
566
|
+
layout: "onLayout"
|
|
567
|
+
};
|
|
568
|
+
function nativeEventName(spelling) {
|
|
569
|
+
const [base] = spelling.split(".");
|
|
570
|
+
return NATIVE_EVENT_NAMES[base.toLowerCase()] ?? `on${base.charAt(0).toUpperCase()}${base.slice(1)}`;
|
|
571
|
+
}
|
|
572
|
+
export function parseForExpression(value) {
|
|
573
|
+
const trimmed = value.trim(), inForm = /^\(?\s*([$\w]+)\s*(?:,\s*([$\w]+)\s*)?\)?\s+(?:in|of)\s+([\s\S]+)$/.exec(trimmed);
|
|
574
|
+
if (inForm)
|
|
575
|
+
return { item: inForm[1], index: inForm[2], source: inForm[3].trim() };
|
|
576
|
+
const asForm = /^([\s\S]+?)\s+as\s+(?:([$\w]+)\s*=>\s*)?([$\w]+)$/.exec(trimmed);
|
|
577
|
+
if (asForm)
|
|
578
|
+
return { item: asForm[3], index: asForm[2], source: asForm[1].trim() };
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
function balancedParens(source, open) {
|
|
582
|
+
let depth = 0, quote = "";
|
|
583
|
+
for (let i = open;i < source.length; i++) {
|
|
584
|
+
const char = source[i];
|
|
585
|
+
if (quote) {
|
|
586
|
+
if (char === "\\")
|
|
587
|
+
i++;
|
|
588
|
+
else if (char === quote)
|
|
589
|
+
quote = "";
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (char === '"' || char === "'" || char === "`")
|
|
593
|
+
quote = char;
|
|
594
|
+
else if (char === "(")
|
|
595
|
+
depth++;
|
|
596
|
+
else if (char === ")" && --depth === 0)
|
|
597
|
+
return i;
|
|
598
|
+
}
|
|
599
|
+
return -1;
|
|
600
|
+
}
|
|
601
|
+
function attribute(name, expression) {
|
|
602
|
+
return expression.includes('"') ? `${name}={${expression}}` : `${name}="${expression}"`;
|
|
603
|
+
}
|
|
604
|
+
export function expandTextDirectives(source) {
|
|
605
|
+
const pattern = /<script\b[\s\S]*?<\/script>|<style\b[\s\S]*?<\/style>|@(if|elseif|unless|foreach|for)\s*\(|@(else|endif|endunless|endforeach|endfor)\b/g;
|
|
606
|
+
let out = "", last = 0;
|
|
607
|
+
for (let match = pattern.exec(source);match; match = pattern.exec(source)) {
|
|
608
|
+
if (match[0].startsWith("<"))
|
|
609
|
+
continue;
|
|
610
|
+
const before = source[match.index - 1];
|
|
611
|
+
if (before && /[\w@.]/.test(before))
|
|
612
|
+
continue;
|
|
613
|
+
out += source.slice(last, match.index);
|
|
614
|
+
if (match[1]) {
|
|
615
|
+
const open = match.index + match[0].length - 1, close = balancedParens(source, open);
|
|
616
|
+
if (close === -1)
|
|
617
|
+
throw Error(`Unclosed @${match[1]}( in template`);
|
|
618
|
+
const expression = source.slice(open + 1, close).trim();
|
|
619
|
+
if (match[1] === "if")
|
|
620
|
+
out += `<Fragment ${attribute(":if", expression)}>`;
|
|
621
|
+
else if (match[1] === "unless")
|
|
622
|
+
out += `<Fragment ${attribute(":if", `!(${expression})`)}>`;
|
|
623
|
+
else if (match[1] === "elseif")
|
|
624
|
+
out += `</Fragment><Fragment ${attribute(":else-if", expression)}>`;
|
|
625
|
+
else {
|
|
626
|
+
const loop = parseForExpression(expression);
|
|
627
|
+
if (!loop)
|
|
628
|
+
throw Error(`Cannot read @${match[1]}(${expression})`);
|
|
629
|
+
const head = loop.index ? `(${loop.item}, ${loop.index})` : loop.item;
|
|
630
|
+
out += `<Fragment ${attribute(":for", `${head} in ${loop.source}`)}>`;
|
|
631
|
+
}
|
|
632
|
+
last = close + 1;
|
|
633
|
+
pattern.lastIndex = last;
|
|
634
|
+
} else {
|
|
635
|
+
out += match[2] === "else" ? "</Fragment><Fragment :else>" : "</Fragment>";
|
|
636
|
+
last = match.index + match[0].length;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return out + source.slice(last);
|
|
640
|
+
}
|
|
641
|
+
export function parseSTX(template, source = "unknown.stx") {
|
|
642
|
+
const tokens = new Lexer(expandTextDirectives(template)).tokenize();
|
|
643
|
+
return new Parser(tokens, source).parse();
|
|
644
|
+
}
|
|
645
|
+
export function parseSTXToNode(template) {
|
|
646
|
+
return parseSTX(template).root;
|
|
647
|
+
}
|
|
648
|
+
export function compileSTX(template, source = "unknown.stx") {
|
|
649
|
+
const doc = parseSTX(template, source);
|
|
650
|
+
return JSON.stringify(doc, null, 2);
|
|
651
|
+
}
|
|
652
|
+
export function compileSTXFiles(files) {
|
|
653
|
+
const results = {};
|
|
654
|
+
for (const [path, content] of Object.entries(files))
|
|
655
|
+
results[path] = parseSTX(content, path);
|
|
656
|
+
return results;
|
|
657
|
+
}
|
|
658
|
+
export function mapToNativeComponent(tag) {
|
|
659
|
+
return {
|
|
660
|
+
view: "View",
|
|
661
|
+
text: "Text",
|
|
662
|
+
button: "Button",
|
|
663
|
+
image: "Image",
|
|
664
|
+
img: "Image",
|
|
665
|
+
input: "TextInput",
|
|
666
|
+
textarea: "TextInput",
|
|
667
|
+
scroll: "ScrollView",
|
|
668
|
+
scrollview: "ScrollView",
|
|
669
|
+
list: "FlatList",
|
|
670
|
+
flatlist: "FlatList",
|
|
671
|
+
modal: "Modal",
|
|
672
|
+
switch: "Switch",
|
|
673
|
+
slider: "Slider",
|
|
674
|
+
picker: "Picker",
|
|
675
|
+
select: "Picker",
|
|
676
|
+
loading: "ActivityIndicator",
|
|
677
|
+
spinner: "ActivityIndicator",
|
|
678
|
+
div: "View",
|
|
679
|
+
span: "Text",
|
|
680
|
+
p: "Text",
|
|
681
|
+
h1: "Text",
|
|
682
|
+
h2: "Text",
|
|
683
|
+
h3: "Text",
|
|
684
|
+
h4: "Text",
|
|
685
|
+
h5: "Text",
|
|
686
|
+
h6: "Text",
|
|
687
|
+
a: "TouchableOpacity",
|
|
688
|
+
section: "View",
|
|
689
|
+
article: "View",
|
|
690
|
+
header: "SafeAreaView",
|
|
691
|
+
footer: "View",
|
|
692
|
+
main: "View",
|
|
693
|
+
nav: "View",
|
|
694
|
+
aside: "View",
|
|
695
|
+
form: "View",
|
|
696
|
+
label: "Text",
|
|
697
|
+
fieldset: "View",
|
|
698
|
+
legend: "Text",
|
|
699
|
+
option: "Text",
|
|
700
|
+
dialog: "Modal",
|
|
701
|
+
figure: "View",
|
|
702
|
+
figcaption: "Text",
|
|
703
|
+
picture: "View",
|
|
704
|
+
hr: "View",
|
|
705
|
+
ul: "View",
|
|
706
|
+
ol: "View",
|
|
707
|
+
li: "View",
|
|
708
|
+
dl: "View",
|
|
709
|
+
dt: "Text",
|
|
710
|
+
dd: "Text",
|
|
711
|
+
table: "View",
|
|
712
|
+
thead: "View",
|
|
713
|
+
tbody: "View",
|
|
714
|
+
tfoot: "View",
|
|
715
|
+
tr: "View",
|
|
716
|
+
th: "Text",
|
|
717
|
+
td: "Text",
|
|
718
|
+
caption: "Text",
|
|
719
|
+
strong: "Text",
|
|
720
|
+
b: "Text",
|
|
721
|
+
em: "Text",
|
|
722
|
+
i: "Text",
|
|
723
|
+
u: "Text",
|
|
724
|
+
s: "Text",
|
|
725
|
+
small: "Text",
|
|
726
|
+
mark: "Text",
|
|
727
|
+
abbr: "Text",
|
|
728
|
+
time: "Text",
|
|
729
|
+
code: "Text",
|
|
730
|
+
kbd: "Text",
|
|
731
|
+
samp: "Text",
|
|
732
|
+
pre: "Text",
|
|
733
|
+
blockquote: "Text",
|
|
734
|
+
cite: "Text",
|
|
735
|
+
q: "Text",
|
|
736
|
+
sub: "Text",
|
|
737
|
+
sup: "Text"
|
|
738
|
+
}[tag.toLowerCase()] || tag;
|
|
739
|
+
}
|
|
740
|
+
export function transformToNativeComponents(node) {
|
|
741
|
+
const mappedType = mapToNativeComponent(node.type), transformedChildren = node.children.map((child) => {
|
|
742
|
+
if (typeof child === "string")
|
|
743
|
+
return child;
|
|
744
|
+
return transformToNativeComponents(child);
|
|
745
|
+
});
|
|
746
|
+
return {
|
|
747
|
+
...node,
|
|
748
|
+
type: mappedType,
|
|
749
|
+
children: transformedChildren
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
export { Lexer, Parser };
|