@stacksjs/stx 0.2.422 → 0.2.424

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.
Files changed (250) hide show
  1. package/dist/{chunk-ep5jnqdb.js → chunk-02n071n7.js} +6 -6
  2. package/dist/chunk-03n23sh6.js +2 -0
  3. package/dist/chunk-07mxghsz.js +2 -0
  4. package/dist/{chunk-kjkwycce.js → chunk-0bmc75w6.js} +4 -4
  5. package/dist/{chunk-hyak4dzg.js → chunk-0hhq9hbq.js} +3 -3
  6. package/dist/{chunk-66k7yxnr.js → chunk-12pvnn1e.js} +4 -4
  7. package/dist/chunk-1497wcxc.js +2 -0
  8. package/dist/chunk-17n9e5wk.js +2 -0
  9. package/dist/chunk-1p8hc1ve.js +2 -0
  10. package/dist/chunk-1r3ghgsz.js +2 -0
  11. package/dist/{chunk-681cxw8j.js → chunk-24e7qjb8.js} +2 -2
  12. package/dist/chunk-259ecbwa.js +2 -0
  13. package/dist/chunk-26gfsa9w.js +2 -0
  14. package/dist/{chunk-zp0mg8b2.js → chunk-2bpjq1qz.js} +2 -2
  15. package/dist/{chunk-11ra3sbc.js → chunk-2x9jd5w0.js} +3 -3
  16. package/dist/{chunk-k31fwm2w.js → chunk-3hmy75tw.js} +5 -5
  17. package/dist/{chunk-12b8akfg.js → chunk-3pxp0r0a.js} +3 -3
  18. package/dist/{chunk-x5ks23vx.js → chunk-3ry9ca1s.js} +2 -2
  19. package/dist/{chunk-th9s15es.js → chunk-45rfv3a5.js} +2 -2
  20. package/dist/chunk-47apfsxp.js +2 -0
  21. package/dist/{chunk-w72p2ak0.js → chunk-48kgnqpk.js} +4 -4
  22. package/dist/{chunk-rsxvbnp4.js → chunk-4hd5wb8x.js} +3 -3
  23. package/dist/chunk-535nrr6j.js +2 -0
  24. package/dist/chunk-5mfhk69g.js +2 -0
  25. package/dist/{chunk-aync8qmk.js → chunk-5vwg3h5g.js} +2 -2
  26. package/dist/{chunk-tspmynvh.js → chunk-62chbqev.js} +1 -1
  27. package/dist/chunk-6c7294j8.js +2 -0
  28. package/dist/{chunk-qwgdtrhj.js → chunk-6cbvx87h.js} +5 -5
  29. package/dist/{chunk-q0cehgy2.js → chunk-6fsbny9m.js} +3 -3
  30. package/dist/chunk-6gh2rvyz.js +2 -0
  31. package/dist/chunk-6j6gbp0y.js +2 -0
  32. package/dist/chunk-6jgjmycb.js +2 -0
  33. package/dist/{chunk-w83djypm.js → chunk-6t278w29.js} +2 -2
  34. package/dist/{chunk-5vfyxxrp.js → chunk-6t7mxb0b.js} +2 -2
  35. package/dist/chunk-6wmxrn6x.js +2 -0
  36. package/dist/chunk-6wweqfg7.js +2 -0
  37. package/dist/{chunk-ja7znxnz.js → chunk-7a9h7ycs.js} +5 -5
  38. package/dist/chunk-7pbv9mg7.js +2 -0
  39. package/dist/{chunk-09hhrjk9.js → chunk-89b2r1q0.js} +6 -6
  40. package/dist/{chunk-0varh725.js → chunk-8a0r2j8f.js} +3 -3
  41. package/dist/{chunk-gp8xzbyt.js → chunk-8nsbf2mz.js} +1074 -1074
  42. package/dist/{chunk-mg13q1kd.js → chunk-8zf5q1m3.js} +2 -2
  43. package/dist/chunk-9d53d0t6.js +2 -0
  44. package/dist/chunk-9j72har9.js +2 -0
  45. package/dist/chunk-9yqz5ge5.js +2 -0
  46. package/dist/chunk-a5c9n7an.js +2 -0
  47. package/dist/chunk-a836zn7c.js +2 -0
  48. package/dist/{chunk-kzkjc12e.js → chunk-a8g6y9kw.js} +5 -5
  49. package/dist/{chunk-21a7p956.js → chunk-acwgap78.js} +1 -1
  50. package/dist/{chunk-qx3js9tk.js → chunk-aen2baze.js} +1 -1
  51. package/dist/chunk-ahgrkva8.js +2 -0
  52. package/dist/chunk-akbb6j7s.js +2 -0
  53. package/dist/chunk-avakcrbs.js +2 -0
  54. package/dist/{chunk-tafebmtg.js → chunk-axydabse.js} +2 -2
  55. package/dist/{chunk-4n6c5rp5.js → chunk-b7973zvk.js} +2 -2
  56. package/dist/{chunk-ebkpdc45.js → chunk-bxwe7wxj.js} +10 -10
  57. package/dist/{chunk-2ewa2sg5.js → chunk-c1dmr865.js} +3 -3
  58. package/dist/chunk-cenq2n6e.js +2 -0
  59. package/dist/{chunk-zvh2nnzr.js → chunk-cf6htz63.js} +1 -1
  60. package/dist/chunk-cnmz9543.js +2 -0
  61. package/dist/{chunk-h1585jbm.js → chunk-cx2rdew4.js} +13 -13
  62. package/dist/{chunk-wg1ttvs5.js → chunk-cznsm2n3.js} +2 -2
  63. package/dist/chunk-d1qzhawc.js +2 -0
  64. package/dist/chunk-d6hnvwre.js +2 -0
  65. package/dist/{chunk-7abgzdsm.js → chunk-dcwjxq8n.js} +2 -2
  66. package/dist/chunk-dhqwg62x.js +2 -0
  67. package/dist/{chunk-95e3rz88.js → chunk-dmd6yk2x.js} +5 -5
  68. package/dist/chunk-e18qfegt.js +2 -0
  69. package/dist/chunk-eej89wkt.js +2 -0
  70. package/dist/chunk-ekxffxbd.js +2 -0
  71. package/dist/{chunk-hy9e3ny6.js → chunk-ex0tq6x2.js} +1 -1
  72. package/dist/{chunk-nqr77pxk.js → chunk-fg5ve6ey.js} +2 -2
  73. package/dist/{chunk-dejsjk4h.js → chunk-fnt1q1sp.js} +11 -11
  74. package/dist/chunk-g67gg66e.js +2 -0
  75. package/dist/chunk-gq16fxc2.js +2 -0
  76. package/dist/{chunk-5e9zkd65.js → chunk-h3c7z73m.js} +2 -2
  77. package/dist/chunk-h4avjh3q.js +2 -0
  78. package/dist/chunk-h7qte7ye.js +2 -0
  79. package/dist/{chunk-hmdnn9ja.js → chunk-hb9gxad0.js} +3 -3
  80. package/dist/{chunk-dmxh7zwq.js → chunk-hg4k3nkr.js} +1 -1
  81. package/dist/{chunk-dhxbjw6k.js → chunk-hnep9jbj.js} +2 -2
  82. package/dist/chunk-hwycbxg7.js +2 -0
  83. package/dist/{chunk-34gy5zjm.js → chunk-j1q65enz.js} +2 -2
  84. package/dist/chunk-j5myfxe8.js +18 -0
  85. package/dist/{chunk-8jqy69td.js → chunk-j7zywbq0.js} +2 -2
  86. package/dist/{chunk-788g87ft.js → chunk-jbrdebzs.js} +7 -7
  87. package/dist/{chunk-wr6b99pw.js → chunk-jj4pyeyj.js} +1 -1
  88. package/dist/{chunk-g1fxmp9z.js → chunk-k8sqs7j2.js} +4 -4
  89. package/dist/chunk-mg7jhx5v.js +2 -0
  90. package/dist/chunk-n16wa755.js +2 -0
  91. package/dist/chunk-ngv1c807.js +2 -0
  92. package/dist/{chunk-krr2vb0s.js → chunk-p2x7tjbt.js} +3 -3
  93. package/dist/{chunk-62r4fa4q.js → chunk-ptjqacjd.js} +2 -2
  94. package/dist/{chunk-597rfddk.js → chunk-qm1tt8g1.js} +2334 -2334
  95. package/dist/chunk-r7r5h2eh.js +2 -0
  96. package/dist/chunk-rhkx17d9.js +2 -0
  97. package/dist/{chunk-b1fg9vg7.js → chunk-s28eh0jn.js} +2 -2
  98. package/dist/{chunk-837nb4zv.js → chunk-s295vp9x.js} +3 -3
  99. package/dist/chunk-sazpw71r.js +4 -0
  100. package/dist/{chunk-20tdz0zs.js → chunk-sbdzqqr1.js} +6 -6
  101. package/dist/{chunk-qby6wxat.js → chunk-spx27cs4.js} +2 -2
  102. package/dist/{chunk-n7jjp08m.js → chunk-stxmwytg.js} +2 -2
  103. package/dist/{chunk-2tfe2g58.js → chunk-t3wh1jbk.js} +6 -6
  104. package/dist/{chunk-802pr252.js → chunk-tfexmdkt.js} +2 -2
  105. package/dist/{chunk-2cn8krpp.js → chunk-tfz95n7j.js} +5 -5
  106. package/dist/chunk-thdbqsxq.js +2 -0
  107. package/dist/chunk-tpnfcb83.js +2 -0
  108. package/dist/chunk-tqkv4th9.js +2 -0
  109. package/dist/chunk-tznejj9h.js +2 -0
  110. package/dist/{chunk-ap6fehea.js → chunk-vfk725vm.js} +5 -5
  111. package/dist/chunk-vsrm9k7p.js +2 -0
  112. package/dist/chunk-vwms759h.js +2 -0
  113. package/dist/{chunk-xvzxrt9a.js → chunk-w2085fwx.js} +5 -5
  114. package/dist/chunk-w252cgnv.js +30 -0
  115. package/dist/chunk-whdw6dhb.js +2 -0
  116. package/dist/chunk-wtms9jhs.js +3 -0
  117. package/dist/chunk-wtqjfar3.js +2 -0
  118. package/dist/chunk-wx7kfet5.js +2 -0
  119. package/dist/chunk-wy873fy8.js +2 -0
  120. package/dist/{chunk-d2z6828s.js → chunk-xa3wsmt5.js} +11 -11
  121. package/dist/chunk-xrbqf77j.js +2 -0
  122. package/dist/{chunk-757ec865.js → chunk-yaebdyfr.js} +2 -2
  123. package/dist/chunk-ycpq3gxc.js +2 -0
  124. package/dist/chunk-yd50awqp.js +3 -0
  125. package/dist/{chunk-csjw5esc.js → chunk-ydz7w2mt.js} +2 -2
  126. package/dist/chunk-yjgbxf26.js +2 -0
  127. package/dist/{chunk-jjnfj9nf.js → chunk-yqsza22w.js} +2 -2
  128. package/dist/{chunk-3xm6dyab.js → chunk-zbr333kf.js} +88 -27
  129. package/dist/chunk-zcyjdcpx.js +33 -0
  130. package/dist/{chunk-tqnysw0k.js → chunk-zfzcedw4.js} +4 -4
  131. package/dist/chunk-zm73n103.js +2 -0
  132. package/dist/cli.js +20 -20
  133. package/dist/component-renderer.js +54 -2
  134. package/dist/composables/use-outbox.d.ts +1 -0
  135. package/dist/composables/use-outbox.js +23 -10
  136. package/dist/craft-entry.js +2 -2
  137. package/dist/craft.js +2 -2
  138. package/dist/database.js +2 -2
  139. package/dist/native/bridge/protocol.d.ts +5 -0
  140. package/dist/native/bridge/protocol.js +3 -0
  141. package/dist/native/cli.js +12 -2
  142. package/dist/native/compiler/bundle.d.ts +4 -3
  143. package/dist/native/compiler/bundle.js +46 -51
  144. package/dist/native/compiler/component-mapping.d.ts +5 -0
  145. package/dist/native/compiler/component-mapping.js +90 -0
  146. package/dist/native/compiler/html-to-ir.js +42 -6
  147. package/dist/native/compiler/ir.d.ts +2 -0
  148. package/dist/native/compiler/render-screen.d.ts +4 -0
  149. package/dist/native/compiler/render-screen.js +10 -2
  150. package/dist/native/compiler/setup-script.d.ts +6 -0
  151. package/dist/native/compiler/setup-script.js +10 -0
  152. package/dist/native/components/primitives.d.ts +10 -0
  153. package/dist/native/index.d.ts +6 -24
  154. package/dist/native/index.js +1 -17
  155. package/dist/native/primitives/Button.stx +2 -1
  156. package/dist/native/primitives/Text.stx +2 -1
  157. package/dist/native/primitives/TextInput.stx +3 -1
  158. package/dist/native/prop-names.d.ts +2 -0
  159. package/dist/native/prop-names.js +71 -0
  160. package/dist/native/runtime/binding-tree.d.ts +31 -0
  161. package/dist/native/runtime/binding-tree.js +100 -0
  162. package/dist/native/runtime/craft-bridge.d.ts +9 -0
  163. package/dist/native/runtime/craft-bridge.js +231 -0
  164. package/dist/native/runtime/craft.d.ts +28 -3
  165. package/dist/native/runtime/jsc-globals.d.ts +16 -0
  166. package/dist/native/runtime/jsc-globals.js +64 -0
  167. package/dist/native/runtime/native-host.d.ts +3 -1
  168. package/dist/native/runtime/native-host.js +183 -33
  169. package/dist/native/runtime/shared-screen.d.ts +15 -0
  170. package/dist/native/runtime/shared-screen.js +41 -0
  171. package/dist/pwa.js +3 -3
  172. package/dist/signal-processing.d.ts +3 -1
  173. package/dist/signal-processing.js +4 -3
  174. package/dist/signals.js +77 -16
  175. package/dist/ssg.js +28 -28
  176. package/package.json +5 -5
  177. package/dist/chunk-10fh9qhe.js +0 -2
  178. package/dist/chunk-1569v24d.js +0 -2
  179. package/dist/chunk-18awnp9d.js +0 -2
  180. package/dist/chunk-1r0c5920.js +0 -30
  181. package/dist/chunk-2hswgxpb.js +0 -2
  182. package/dist/chunk-4363reg4.js +0 -2
  183. package/dist/chunk-48axv7bm.js +0 -2
  184. package/dist/chunk-50hgr79y.js +0 -2
  185. package/dist/chunk-54wczcee.js +0 -2
  186. package/dist/chunk-74gz26zs.js +0 -2
  187. package/dist/chunk-7906p8zs.js +0 -2
  188. package/dist/chunk-7dkfjmjw.js +0 -2
  189. package/dist/chunk-7vr5w75r.js +0 -4
  190. package/dist/chunk-7zn0yyqk.js +0 -2
  191. package/dist/chunk-8d2kamh2.js +0 -2
  192. package/dist/chunk-8ttvazck.js +0 -2
  193. package/dist/chunk-8y4bqsxz.js +0 -2
  194. package/dist/chunk-9bpnz431.js +0 -2
  195. package/dist/chunk-ac033b93.js +0 -2
  196. package/dist/chunk-aj43359g.js +0 -2
  197. package/dist/chunk-aj8yq228.js +0 -2
  198. package/dist/chunk-as72dvvm.js +0 -2
  199. package/dist/chunk-bfvaxrq0.js +0 -2
  200. package/dist/chunk-bkaw7sgz.js +0 -2
  201. package/dist/chunk-d0q2x8e3.js +0 -2
  202. package/dist/chunk-d2c5727w.js +0 -2
  203. package/dist/chunk-d5amzers.js +0 -2
  204. package/dist/chunk-dfchrqw5.js +0 -2
  205. package/dist/chunk-epv0ahg1.js +0 -2
  206. package/dist/chunk-f5489ese.js +0 -2
  207. package/dist/chunk-fqq1w9m1.js +0 -2
  208. package/dist/chunk-hcgsgnq8.js +0 -2
  209. package/dist/chunk-hgqcqg1h.js +0 -2
  210. package/dist/chunk-hjdwf9gp.js +0 -2
  211. package/dist/chunk-hp7ewdnp.js +0 -2
  212. package/dist/chunk-jjtzm6dn.js +0 -3
  213. package/dist/chunk-js79j12f.js +0 -18
  214. package/dist/chunk-kfsp322p.js +0 -2
  215. package/dist/chunk-kt557jaj.js +0 -2
  216. package/dist/chunk-n8kqvzba.js +0 -2
  217. package/dist/chunk-na70r4sp.js +0 -2
  218. package/dist/chunk-p083sckk.js +0 -2
  219. package/dist/chunk-pc178389.js +0 -2
  220. package/dist/chunk-psqk7932.js +0 -2
  221. package/dist/chunk-pv5nr9pd.js +0 -2
  222. package/dist/chunk-q1v0jwr4.js +0 -2
  223. package/dist/chunk-qeye0901.js +0 -2
  224. package/dist/chunk-qy59yp2v.js +0 -2
  225. package/dist/chunk-r5gjb55x.js +0 -2
  226. package/dist/chunk-tf44jyrh.js +0 -2
  227. package/dist/chunk-tfypkw4y.js +0 -3
  228. package/dist/chunk-vv4kkwhn.js +0 -2
  229. package/dist/chunk-vwhd3h8x.js +0 -2
  230. package/dist/chunk-vxj8kd2v.js +0 -2
  231. package/dist/chunk-vzzpvn21.js +0 -2
  232. package/dist/chunk-w1a2v264.js +0 -2
  233. package/dist/chunk-wcs7w8wv.js +0 -2
  234. package/dist/chunk-x6ndnpvr.js +0 -2
  235. package/dist/chunk-x8rckpyz.js +0 -2
  236. package/dist/chunk-ya0qecph.js +0 -27
  237. package/dist/chunk-ykwmqh8z.js +0 -2
  238. package/dist/chunk-ys71pmrb.js +0 -2
  239. package/dist/chunk-z5y4qyhg.js +0 -2
  240. package/dist/chunk-zpcz2kh6.js +0 -2
  241. package/dist/native/compiler/codegen.d.ts +0 -10
  242. package/dist/native/compiler/codegen.js +0 -145
  243. package/dist/native/compiler/parser.d.ts +0 -88
  244. package/dist/native/compiler/parser.js +0 -753
  245. package/dist/native/runtime/entry.d.ts +0 -1
  246. package/dist/native/runtime/entry.js +0 -3
  247. package/dist/native/runtime/index.d.ts +0 -45
  248. package/dist/native/runtime/index.js +0 -165
  249. package/dist/native/runtime/screen.d.ts +0 -43
  250. package/dist/native/runtime/screen.js +0 -808
@@ -1,753 +0,0 @@
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 };