@torpor/view 0.3.0 → 0.3.2

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 (441) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/Component-C6Y3UwGs.d.cts +11 -0
  3. package/dist/Component-C6Y3UwGs.d.cts.map +1 -0
  4. package/dist/ServerSlotRender-COS6H8Yk.d.cts +41 -0
  5. package/dist/ServerSlotRender-COS6H8Yk.d.cts.map +1 -0
  6. package/dist/compile.cjs +3735 -0
  7. package/dist/compile.cjs.map +1 -0
  8. package/dist/compile.d.cts +216 -0
  9. package/dist/compile.d.cts.map +1 -0
  10. package/dist/compile.d.ts +6 -0
  11. package/dist/compile.d.ts.map +1 -1
  12. package/dist/compile.js +128 -76
  13. package/dist/compile.js.map +1 -1
  14. package/dist/formatText-B0FXBdFT.js.map +1 -1
  15. package/dist/formatText-DufG5l83.cjs +500 -0
  16. package/dist/formatText-DufG5l83.cjs.map +1 -0
  17. package/dist/index.cjs +906 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +411 -0
  20. package/dist/index.d.cts.map +1 -0
  21. package/dist/ssr.cjs +40 -0
  22. package/dist/ssr.cjs.map +1 -0
  23. package/dist/ssr.d.cts +19 -0
  24. package/dist/ssr.d.cts.map +1 -0
  25. package/package.json +7 -4
  26. package/src/compile/build/client/buildAwaitNode.ts +15 -7
  27. package/src/compile/build/client/buildCode.ts +8 -1
  28. package/src/compile/build/client/buildIfNode.ts +11 -5
  29. package/src/compile/build/client/buildSwitchNode.ts +12 -5
  30. package/src/compile/buildType.ts +11 -12
  31. package/src/compile/parse/ParseComponentStatus.ts +6 -0
  32. package/src/compile/parse/parseCode.ts +61 -7
  33. package/src/compile/parse/parseTag.ts +7 -0
  34. package/src/types/TemplateComponent.ts +6 -0
  35. package/src/watch/checkEffect.ts +2 -0
  36. package/test/attributes/components/output/Attributes-client.ts +3 -0
  37. package/test/attributes/components/output/Attributes-types.ts +10 -0
  38. package/test/attributes/components/temp/{Attributes-client-9b2935d7824ba501776fdc6c48861422c15b6a12.ts → Attributes-client-ffbdd4d85a50436c1a51a4499921304098c1b396.ts} +3 -0
  39. package/test/attributes/components/temp/Attributes-types-5892927754ac19a8b3a8560fa1c78ce653e5f318.ts +10 -0
  40. package/test/attributes/errors.test.ts +35 -0
  41. package/test/await/components/output/Await-client.ts +12 -5
  42. package/test/await/components/output/Await-types.ts +10 -0
  43. package/test/await/components/temp/{Await-client-e969f4bd0712acf259ddfaa5a3b3448307201fd2.ts → Await-client-4d2c318baf00e6fb8fea11e34189817ca8002a1f.ts} +12 -5
  44. package/test/await/components/temp/Await-types-355b335acd1c17a2271920d51e542ce1fc61eeef.ts +10 -0
  45. package/test/bench/components/output/Bench-client.ts +3 -0
  46. package/test/bench/components/output/Bench-types.ts +10 -0
  47. package/test/bench/components/temp/{Bench-client-7f31596dafc8077370d8d90b1bb9b6e0208154e7.ts → Bench-client-33b5a23562f6a00687449c5ffe72dc42ac7f766e.ts} +3 -0
  48. package/test/bench/components/temp/Bench-types-a798f6c7b7ec235754ff5fdd5d7020633253b042.ts +10 -0
  49. package/test/bind/components/output/BindComponent-client.ts +5 -0
  50. package/test/bind/components/output/BindComponent-types.ts +10 -0
  51. package/test/bind/components/output/BindText-client.ts +3 -0
  52. package/test/bind/components/output/BindText-types.ts +10 -0
  53. package/test/bind/components/temp/{BindComponent-client-22eccb5354a2b0267841e015f3a2a0baf534bf89.ts → BindComponent-client-eb816edf9f83c19641ced9ecb1c2c5fc87e8e32c.ts} +5 -0
  54. package/test/bind/components/temp/BindComponent-types-8a10f6efddd92990ed5390f3c89ba17db179d801.ts +10 -0
  55. package/test/bind/components/temp/{BindText-client-7692ae1570533cc17e2186e9c7d4768529e4a2fe.ts → BindText-client-63e98b4407a8f0f22f4766d029567ac0aac7dba8.ts} +3 -0
  56. package/test/bind/components/temp/BindText-types-5892d9ef33c61a0de524b74323ba135accee8175.ts +10 -0
  57. package/test/build-server/components/output/IfNested-client.ts +17 -8
  58. package/test/build-server/components/output/IfNested-types.ts +10 -0
  59. package/test/build-server/components/temp/{IfNested-client-eefdd449fa700b2e7326bc72df8b32ddcadf9d21.ts → IfNested-client-2af78cceff5dbce510db31fd5b8bb4da5d30d53a.ts} +17 -8
  60. package/test/build-server/components/temp/IfNested-types-692d58ca98f3534102193a44aa358994f798ca7b.ts +10 -0
  61. package/test/buildOutputFiles.ts +16 -4
  62. package/test/child-component/components/output/ParentChild-client.ts +5 -0
  63. package/test/child-component/components/output/ParentChild-types.ts +10 -0
  64. package/test/child-component/components/temp/{ParentChild-client-2dfd600f7d409630d429a1d2d18c038bd08b08da.ts → ParentChild-client-93ca4d2ac521ef996a6548bfacb3e36f6f71fcf9.ts} +5 -0
  65. package/test/child-component/components/temp/ParentChild-types-4d26850ef18600f398f7aa9c4502071349bf5624.ts +10 -0
  66. package/test/class/components/output/Class-client.ts +5 -0
  67. package/test/class/components/output/Class-types.ts +10 -0
  68. package/test/class/components/temp/{Class-client-5af6a50cd454ae019b2aa79457ba7ead83b8c056.ts → Class-client-284ac46628b2d3d6b4a4edbdbfd1700626d3fed0.ts} +5 -0
  69. package/test/class/components/temp/Class-types-38567e85c9ec17739c7c97e12281fc1818267190.ts +10 -0
  70. package/test/component/components/output/Component-client.ts +3 -0
  71. package/test/component/components/output/Component-types.ts +10 -0
  72. package/test/component/components/output/Header-client.ts +3 -0
  73. package/test/component/components/output/Header-types.ts +10 -0
  74. package/test/component/components/temp/{Component-client-fdc327499be0a01f987d0f2897baf022a247c77c.ts → Component-client-3cb873dd1782874af78544c1d8886bbfa4bef11b.ts} +3 -0
  75. package/test/component/components/temp/Component-types-3ef4f140ba29c98357caf0f2618785437b5804de.ts +10 -0
  76. package/test/component/components/temp/{Header-client-6beb5770e68e6b19595e53e20bc906765fc6c260.ts → Header-client-cb780b85ee6e0587eca3d9ad7a8b8c947075e394.ts} +3 -0
  77. package/test/component/components/temp/Header-types-c56a108c6fb5a22b8ae156936bc05e58eef199c2.ts +10 -0
  78. package/test/console/components/output/Console-client.ts +3 -0
  79. package/test/console/components/output/Console-types.ts +10 -0
  80. package/test/console/components/temp/{Console-client-2b58290ac407ebbe89a0613d64eb9cd141b99887.ts → Console-client-b0feb868a912138e8af01bd06902d28c536ebb87.ts} +3 -0
  81. package/test/console/components/temp/Console-types-93ad3f25ddc6280fcff2cf4db7c2913d3a474912.ts +10 -0
  82. package/test/const/components/output/Const-client.ts +3 -0
  83. package/test/const/components/output/Const-types.ts +10 -0
  84. package/test/const/components/temp/{Const-client-d1037557e7ef75a8fe06f56816e65883047e9421.ts → Const-client-149dbc44ee609c54a99bacb715d04034a1d33c9c.ts} +3 -0
  85. package/test/const/components/temp/Const-types-afba269310bd143aa325752d3cc7e0c598fd0de2.ts +10 -0
  86. package/test/context/components/output/ChildA-client.ts +3 -0
  87. package/test/context/components/output/ChildA-types.ts +10 -0
  88. package/test/context/components/output/ChildB-client.ts +3 -0
  89. package/test/context/components/output/ChildB-types.ts +10 -0
  90. package/test/context/components/{temp/Parent-client-9898b2e521527c86d69905053b6727ea8fd28166.ts → output/Parent-client.ts} +3 -0
  91. package/test/context/components/output/Parent-types.ts +10 -0
  92. package/test/context/components/temp/{ChildA-client-9dea3e29ffcb82ca1779f6ff671e19b1c106fc4a.ts → ChildA-client-b9ad03bb0c64e9fb27a38b85792df79dc3ebf7f1.ts} +3 -0
  93. package/test/context/components/temp/ChildA-types-2ee15b25e68166d1574582f08e2280cbae948e5d.ts +10 -0
  94. package/test/context/components/temp/{ChildB-client-4b801099936c8aa013a1220f291375f67eba1acb.ts → ChildB-client-f4e1a447378a9a9be05aa37c8b3eae7ca6be8411.ts} +3 -0
  95. package/test/context/components/temp/ChildB-types-531f67cfda5bd04468e827c14f9358a431853fc5.ts +10 -0
  96. package/test/context/components/temp/Parent-client-2ecf387911773f5cd74c7bf1d04f98da08bc4450.ts +44 -0
  97. package/test/context/components/temp/Parent-types-e6be7d1cf118d7a8927af59db780010392966d01.ts +10 -0
  98. package/test/effects/components/output/For-client.ts +3 -0
  99. package/test/effects/components/output/For-types.ts +10 -0
  100. package/test/effects/components/output/If-client.ts +10 -4
  101. package/test/effects/components/output/If-types.ts +10 -0
  102. package/test/effects/components/output/NestedIf-client.ts +17 -8
  103. package/test/effects/components/output/NestedIf-types.ts +10 -0
  104. package/test/effects/components/temp/{For-client-7c7d7c0dba2547f816b9bd9c6a95d6873ec00ffd.ts → For-client-af16b99099e237c988932845b79500dfc28c6642.ts} +3 -0
  105. package/test/effects/components/temp/For-types-cfec41b41b054674bf8b01ce0e0003c8a6640a82.ts +10 -0
  106. package/test/effects/components/temp/{If-client-f0480a98f80b32612d12765c6838ff6db5982e82.ts → If-client-7f0b171f29a1f1ff969b21c33b241cd35eb1ce0e.ts} +10 -4
  107. package/test/effects/components/temp/If-types-7b245b6e531e122e0d0cfb72903bb88223b98793.ts +10 -0
  108. package/test/effects/components/temp/{NestedIf-client-702deffd158f219c5da4199b563a62cd54385a7f.ts → NestedIf-client-e2dd594c8f77f5ce53265b234e72b7c2f29ba76d.ts} +17 -8
  109. package/test/effects/components/temp/NestedIf-types-0912466d777f52f3616557823a7e47f5901cb755.ts +10 -0
  110. package/test/events/components/output/Increment-client.ts +3 -0
  111. package/test/events/components/output/Increment-types.ts +10 -0
  112. package/test/events/components/temp/{Increment-client-84c09711baf098c82ee226598ba7a36913616b75.ts → Increment-client-aeee696f3a4363c5c4c1ecf86de8ec071342ba22.ts} +3 -0
  113. package/test/events/components/temp/Increment-types-f259dd221aa967b0426746303f1f2c33aeeaf068.ts +10 -0
  114. package/test/for/components/output/For-client.ts +3 -0
  115. package/test/for/components/output/For-types.ts +10 -0
  116. package/test/for/components/output/ForEscape-client.ts +3 -0
  117. package/test/for/components/output/ForEscape-types.ts +10 -0
  118. package/test/for/components/output/ForIn-client.ts +3 -0
  119. package/test/for/components/output/ForIn-types.ts +10 -0
  120. package/test/for/components/output/ForOf-client.ts +3 -0
  121. package/test/for/components/output/ForOf-types.ts +10 -0
  122. package/test/for/components/temp/{For-client-2f6b4b81670b0ba31b01176b4f61ebf321e945bb.ts → For-client-bc23ebc49e3cf710762bce7cd1b73244c94a3abb.ts} +3 -0
  123. package/test/for/components/temp/For-types-8bcd17ab2e0faebb340a19f56e052cc94820a29a.ts +10 -0
  124. package/test/for/components/temp/{ForEscape-client-8d0fcc940851e687173b6a9129c3d83e0fc771ef.ts → ForEscape-client-a475ec9bdab5d57d30c27124fcf9ce38110ddf75.ts} +3 -0
  125. package/test/for/components/temp/ForEscape-types-bb4f3457b02c2ad97a7b6cbc66f9097a37728ed2.ts +10 -0
  126. package/test/for/components/temp/{ForIn-client-fa0614a1c7b8aa6e8819ed91a518479fd80453ae.ts → ForIn-client-890cee3ac35ede73eafad4e935eefd2fe7ecb9e2.ts} +3 -0
  127. package/test/for/components/temp/ForIn-types-fb4f7b02e23a40d27376760b7e1d06f8ecaa13ba.ts +10 -0
  128. package/test/for/components/temp/{ForOf-client-11006c4239d9018363e582dc5b54b50477d652e7.ts → ForOf-client-309297e25afd249f1a3e27126af23b7329c5c727.ts} +3 -0
  129. package/test/for/components/temp/ForOf-types-6e2fbcd0fbfd3c0a2c3d8c458fdda7b05c2a19b1.ts +10 -0
  130. package/test/function/components/output/Function-client.ts +3 -0
  131. package/test/function/components/output/Function-types.ts +10 -0
  132. package/test/function/components/temp/{Function-client-ec5fe7d599d6099bdfab78c2a0c8edf77a23cd9b.ts → Function-client-8423f53837e6503cdcc0d997684dd3e208b5dd13.ts} +3 -0
  133. package/test/function/components/temp/Function-types-5479cb46b9bef3251b7961fb6e99a8c30cd4220f.ts +10 -0
  134. package/test/html/components/output/Html-client.ts +3 -0
  135. package/test/html/components/output/Html-types.ts +10 -0
  136. package/test/html/components/temp/{Html-client-82ff34dcdcbdf4be1112bcb1baac8027cdc32de7.ts → Html-client-83b1a1be5c4b8e9cc06a616acf8418c786804255.ts} +3 -0
  137. package/test/html/components/temp/Html-types-c5dc816f932e3fb021c006f266a7c9a2f2fb5353.ts +10 -0
  138. package/test/if/components/IfCache.torp +14 -0
  139. package/test/if/components/output/IfAfterIf-client.ts +17 -8
  140. package/test/if/components/output/IfAfterIf-types.ts +10 -0
  141. package/test/if/components/output/IfCache-client.ts +70 -0
  142. package/test/if/components/output/IfCache-server.ts +22 -0
  143. package/test/if/components/output/IfCache-types.ts +10 -0
  144. package/test/if/components/output/IfElse-client.ts +10 -4
  145. package/test/if/components/output/IfElse-types.ts +10 -0
  146. package/test/if/components/output/IfElseIf-client.ts +12 -5
  147. package/test/if/components/output/IfElseIf-types.ts +10 -0
  148. package/test/if/components/output/IfFalse-client.ts +10 -4
  149. package/test/if/components/output/IfFalse-types.ts +10 -0
  150. package/test/if/components/output/IfNested-client.ts +17 -8
  151. package/test/if/components/output/IfNested-types.ts +10 -0
  152. package/test/if/components/temp/{IfAfterIf-client-c1cfd21a6ace4945703ba8f46aada923a60265d9.ts → IfAfterIf-client-5aa5aac7099224e0ec1e8bff6162d729f89267ec.ts} +17 -8
  153. package/test/if/components/temp/IfAfterIf-types-c4bd4f93c103a618889f40c77d55fa7de454f70b.ts +10 -0
  154. package/test/if/components/temp/IfCache-client-8433b3b239bc225d616f12e8904c4f2ba530efb4.ts +70 -0
  155. package/test/if/components/temp/IfCache-server-8b35e6a2009d72083013cfb01b187a1d027fdcc9.ts +22 -0
  156. package/test/if/components/temp/IfCache-types-02f467ce9ebc23ae68c9e5f33c90ecc96b666452.ts +10 -0
  157. package/test/if/components/temp/{IfElse-client-06dfcacd3a5225dcb0947587bcd4fae9ec3d3c1e.ts → IfElse-client-8bd2aa123e050847fdf28172479f0cc1a3ddb01c.ts} +10 -4
  158. package/test/if/components/temp/IfElse-types-e81080227f8f69ac1d81141d97a07e0a0e9391c1.ts +10 -0
  159. package/test/if/components/temp/{IfElseIf-client-26df9a728c9cb712d5ac0235b4c99885f25545b8.ts → IfElseIf-client-a17e2408252495ef0e90ba303a2d9e076867b6fd.ts} +12 -5
  160. package/test/if/components/temp/IfElseIf-types-a492d2b6e8517f598befca7127cd514244239984.ts +10 -0
  161. package/test/if/components/temp/{IfFalse-client-de6fc8e9eb222153608490e6d172e9aae9000aa1.ts → IfFalse-client-00a24a722347d2c711064dd504db9443747e5099.ts} +10 -4
  162. package/test/if/components/temp/IfFalse-types-1d512c6d82e2af9efe0221a9929b05ad62fd97fb.ts +10 -0
  163. package/test/if/components/temp/{IfNested-client-eefdd449fa700b2e7326bc72df8b32ddcadf9d21.ts → IfNested-client-2af78cceff5dbce510db31fd5b8bb4da5d30d53a.ts} +17 -8
  164. package/test/if/components/temp/IfNested-types-692d58ca98f3534102193a44aa358994f798ca7b.ts +10 -0
  165. package/test/if/if-cache.test.ts +68 -0
  166. package/test/mount/components/output/Mount-client.ts +3 -0
  167. package/test/mount/components/output/Mount-types.ts +10 -0
  168. package/test/mount/components/temp/{Mount-client-29896228d7d0ef3692a9d13065c1bbfbe3198cdc.ts → Mount-client-f4dd3d5a21d287d3d22a797805816fe09528dfb6.ts} +3 -0
  169. package/test/mount/components/temp/Mount-types-2d88616243f860d43b8b7d74a6bbeff9b2c6f27b.ts +10 -0
  170. package/test/on-mount/components/output/OnMount-client.ts +3 -0
  171. package/test/on-mount/components/output/OnMount-types.ts +10 -0
  172. package/test/on-mount/components/temp/{OnMount-client-038f8c6bbcf0278406909d6ba5394f311924fda9.ts → OnMount-client-8afb8473b51815e9b0ba994f3476217506b41b1d.ts} +3 -0
  173. package/test/on-mount/components/temp/OnMount-types-d0f834addb351520cc75a589cb9ec5b6a5a787b4.ts +10 -0
  174. package/test/party/components/output/AnswerButton-client.ts +3 -0
  175. package/test/party/components/output/AnswerButton-types.ts +10 -0
  176. package/test/party/components/output/AnswerButtonApp-client.ts +3 -0
  177. package/test/party/components/output/AnswerButtonApp-types.ts +10 -0
  178. package/test/party/components/output/ColorSelect-client.ts +3 -0
  179. package/test/party/components/output/ColorSelect-types.ts +10 -0
  180. package/test/party/components/output/Colors-client.ts +3 -0
  181. package/test/party/components/output/Colors-types.ts +10 -0
  182. package/test/party/components/output/Counter-client.ts +3 -0
  183. package/test/party/components/output/Counter-types.ts +10 -0
  184. package/test/party/components/output/CssStyle-client.ts +3 -0
  185. package/test/party/components/output/CssStyle-types.ts +10 -0
  186. package/test/party/components/output/DoubleCount-client.ts +3 -0
  187. package/test/party/components/output/DoubleCount-types.ts +10 -0
  188. package/test/party/components/output/FunnyButton-client.ts +3 -0
  189. package/test/party/components/output/FunnyButton-types.ts +10 -0
  190. package/test/party/components/output/FunnyButtonApp-client.ts +3 -0
  191. package/test/party/components/output/FunnyButtonApp-types.ts +10 -0
  192. package/test/party/components/output/HelloWorld-client.ts +3 -0
  193. package/test/party/components/output/HelloWorld-types.ts +10 -0
  194. package/test/party/components/output/InputFocused-client.ts +3 -0
  195. package/test/party/components/output/InputFocused-types.ts +10 -0
  196. package/test/party/components/output/InputHello-client.ts +3 -0
  197. package/test/party/components/output/InputHello-types.ts +10 -0
  198. package/test/party/components/output/IsAvailable-client.ts +3 -0
  199. package/test/party/components/output/IsAvailable-types.ts +10 -0
  200. package/test/party/components/output/Name-client.ts +3 -0
  201. package/test/party/components/output/Name-types.ts +10 -0
  202. package/test/party/components/output/NameUpdate-client.ts +3 -0
  203. package/test/party/components/output/NameUpdate-types.ts +10 -0
  204. package/test/party/components/output/PageTitle-client.ts +3 -0
  205. package/test/party/components/output/PageTitle-types.ts +10 -0
  206. package/test/party/components/output/PickPill-client.ts +3 -0
  207. package/test/party/components/output/PickPill-types.ts +10 -0
  208. package/test/party/components/output/Time-client.ts +3 -0
  209. package/test/party/components/output/Time-types.ts +10 -0
  210. package/test/party/components/output/TrafficLight-client.ts +14 -6
  211. package/test/party/components/output/TrafficLight-types.ts +10 -0
  212. package/test/party/components/output/UserProfile-client.ts +3 -0
  213. package/test/party/components/output/UserProfile-types.ts +15 -0
  214. package/test/party/components/output/UserProfileApp-client.ts +3 -0
  215. package/test/party/components/output/UserProfileApp-types.ts +10 -0
  216. package/test/party/components/output/UserProfileContext-client.ts +3 -0
  217. package/test/party/components/output/UserProfileContext-types.ts +10 -0
  218. package/test/party/components/output/UserProfileContextApp-client.ts +3 -0
  219. package/test/party/components/output/UserProfileContextApp-types.ts +10 -0
  220. package/test/party/components/temp/{AnswerButton-client-df895c3e7a88fd7ede9f951fc9de2ed75c27a5cb.ts → AnswerButton-client-2119fa9523949bca3e8ef264eff7e72611d70bac.ts} +3 -0
  221. package/test/party/components/temp/AnswerButton-types-7dc4d046e52be1e6cb46d6235ce7540bd3e7b2a5.ts +10 -0
  222. package/test/party/components/temp/{AnswerButtonApp-client-4c05ef36b1c0e93370fb463643419928717fa701.ts → AnswerButtonApp-client-87979b0578066e637c4257d6a7dbc2bfa1542515.ts} +3 -0
  223. package/test/party/components/temp/AnswerButtonApp-types-10a6f55029e859366f9a3a73cdcdb3f63e89dbeb.ts +10 -0
  224. package/test/party/components/temp/{ColorSelect-client-5db8d1b0924361fdb5efb867c14491402ec9668c.ts → ColorSelect-client-d7eb9276031b613439d7bd6212c76b4a972ebcad.ts} +3 -0
  225. package/test/party/components/temp/ColorSelect-types-e652a36ebdd98e8c23a8de3156c4499023f09301.ts +10 -0
  226. package/test/party/components/temp/{Colors-client-6d3ac693e85bdda50b8742282915997063a32769.ts → Colors-client-42c890154b9a132ebd784cccc4f4f9962f400b3e.ts} +3 -0
  227. package/test/party/components/temp/Colors-types-075975e9b9074b49f96f99d660f0ee580546a630.ts +10 -0
  228. package/test/party/components/temp/{Counter-client-0c604a107c5b84cdbf725f307dfe29d34f8a2cc8.ts → Counter-client-ad5e891eaea79548afabef156b87fee5317319b2.ts} +3 -0
  229. package/test/party/components/temp/Counter-types-206b0704ee2e25f5f3198d716fa524295581c075.ts +10 -0
  230. package/test/party/components/temp/{CssStyle-client-2a642d115ad52539f97c051c34687b8d6d12b324.ts → CssStyle-client-5078b4c735f6273e2565c7d7688c41afa026a2c3.ts} +3 -0
  231. package/test/party/components/temp/CssStyle-types-f1ce4f0b03d404c70704f271ce9bfc5d5107346c.ts +10 -0
  232. package/test/party/components/temp/{DoubleCount-client-8c85c3af12c471ea23bb702bbf5a3e240420f3ec.ts → DoubleCount-client-9406fd993ae8d0efa1f87848ae6e952591b20c3d.ts} +3 -0
  233. package/test/party/components/temp/DoubleCount-types-436bd75fe7808c3a30389aeb1740aea361aa8681.ts +10 -0
  234. package/test/party/components/temp/{FunnyButton-client-850dd3da0fa803c1bce5c53e88fcd2d48d279eb8.ts → FunnyButton-client-f8dea087fd6e3f2d7d0697cd3c87444c6866daf5.ts} +3 -0
  235. package/test/party/components/temp/FunnyButton-types-7780d5c5dfe3ff2369f8e3c505616036cfcd3759.ts +10 -0
  236. package/test/party/components/temp/{FunnyButtonApp-client-00300846d11a3d0a5a620c2ade87b935b7f0ebf8.ts → FunnyButtonApp-client-22aa2ee00b25a3ee0bda442372da843828231242.ts} +3 -0
  237. package/test/party/components/temp/FunnyButtonApp-types-ea73d641565a4478759166f462206dd97c92cedd.ts +10 -0
  238. package/test/party/components/temp/{HelloWorld-client-890b311ad9a3919379acdc1d52807ea36cc9f489.ts → HelloWorld-client-84fa7bd70d75149892044f4a15fdbf9ac8c7fcff.ts} +3 -0
  239. package/test/party/components/temp/HelloWorld-types-3c153ac7af343dbce6cb081f1ae1b4f85d7f0b10.ts +10 -0
  240. package/test/party/components/temp/{InputFocused-client-03527f9ceb52f66ac53887dbc884a0aa83bb7a23.ts → InputFocused-client-504b10731a6c96079a0abd7bb4a8381634ff4a0d.ts} +3 -0
  241. package/test/party/components/temp/InputFocused-types-33da14c13216ca00edaa8f02508db21f5cd32d31.ts +10 -0
  242. package/test/party/components/temp/{InputHello-client-f65a477624975b68b7aaa3614fbf198d4476480f.ts → InputHello-client-b9dd846c4cc129749781955f645327cc3c0956ac.ts} +3 -0
  243. package/test/party/components/temp/InputHello-types-ab629048402441fde9a292bc2d376c0deea482a8.ts +10 -0
  244. package/test/party/components/temp/{IsAvailable-client-8767437fd92cf79713de5b00828e1502e38d79e3.ts → IsAvailable-client-3bd6d53a45c3dcda3e958bb4b5000fef78301b04.ts} +3 -0
  245. package/test/party/components/temp/IsAvailable-types-23d4e196c659901c347a7b3e5c9e4a6668234adb.ts +10 -0
  246. package/test/party/components/temp/{Name-client-08903a8df8bdff5288170d3c89658192956587a9.ts → Name-client-b2cd160fc076bb34c0421a673358e7b7f61e4b49.ts} +3 -0
  247. package/test/party/components/temp/Name-types-06f89338c785a1fd352ed7de3ebe02b30722760d.ts +10 -0
  248. package/test/party/components/temp/{NameUpdate-client-d65b2476c3721d2efddf9385a61433e2a2dd0d72.ts → NameUpdate-client-f2dfcab63d80c25681aa6b15a61c547a0aab2f96.ts} +3 -0
  249. package/test/party/components/temp/NameUpdate-types-9c69805006d2d3bb457c5d4d87db8baeb431aeb6.ts +10 -0
  250. package/test/party/components/temp/{PageTitle-client-c006df9a3e662488a1db089de53fd485c6b923e4.ts → PageTitle-client-f4094f4b23126a99a211f804ed7c4a97a34733b3.ts} +3 -0
  251. package/test/party/components/temp/PageTitle-types-dfb55ea9b607c89167dbd7538523a484a6eec300.ts +10 -0
  252. package/test/party/components/temp/{PickPill-client-af8357daf3f6633c7f451d0bddd72fefe786d5c3.ts → PickPill-client-0a4e095bc2c963a2f091ae2f69c8d075f7d9b5a5.ts} +3 -0
  253. package/test/party/components/temp/PickPill-types-526e2bb4c36ec1bed87eaf5722093a0eaefcd9d3.ts +10 -0
  254. package/test/party/components/temp/{Time-client-94380d45de7275a5cec98e5f58c15b74b13e9c3e.ts → Time-client-95ee134377911d1c1cddbf074b8f943cdcf2a966.ts} +3 -0
  255. package/test/party/components/temp/Time-types-2bf6facfbb2d6e7de472d18760029afaefbb93e1.ts +10 -0
  256. package/test/party/components/temp/{TrafficLight-client-12b20962b4146ef08fe0c37597441533c7699408.ts → TrafficLight-client-dc0248dc967afbbbce4873cd37677cd97cc4933c.ts} +14 -6
  257. package/test/party/components/temp/TrafficLight-types-d301a2317da01a215fc8e5222dc6ff87226fa250.ts +10 -0
  258. package/test/party/components/temp/{UserProfile-client-e5330b2c96bd8b225cb6291bc8b1d9f35c93307e.ts → UserProfile-client-352291dcaf115cc563ae3a07ec6aed901fcc2bc1.ts} +3 -0
  259. package/test/party/components/temp/UserProfile-types-412089462c8dcc757d2f53e7ff8030296d3100c2.ts +15 -0
  260. package/test/party/components/temp/{UserProfileApp-client-4c86e4f9a0d042f4f4811868f0146e872b17353c.ts → UserProfileApp-client-18ad0243fd853dac3c3f71bea21b021bbd5b35f4.ts} +3 -0
  261. package/test/party/components/temp/UserProfileApp-types-3e70c106e03c68b4aa06c2fe21dfeceffe7cc313.ts +10 -0
  262. package/test/party/components/temp/{UserProfileContext-client-424131db3cc89ae4babe127b9108ffc5696c9e1d.ts → UserProfileContext-client-a3f521facb10ae64007c362e34bce41d8144bf96.ts} +3 -0
  263. package/test/party/components/temp/UserProfileContext-types-076b9fa0a87d3ca098884a003284050b36172cc6.ts +10 -0
  264. package/test/party/components/temp/{UserProfileContextApp-client-5f94a7ccf3e4542ea40d8046ad75eeb21005c55f.ts → UserProfileContextApp-client-cccb3b8e819279cd7f729af61b84ad9801213597.ts} +3 -0
  265. package/test/party/components/temp/UserProfileContextApp-types-d04199ab7d43ecc12ceccb7a0bef7ff38ac1e8b1.ts +10 -0
  266. package/test/props/components/output/Reactive-client.ts +5 -0
  267. package/test/props/components/output/Reactive-types.ts +10 -0
  268. package/test/props/components/temp/{Reactive-client-9bc3643675fc563f96efb00bc3c4b843ba4b7f2e.ts → Reactive-client-644526502a3c5db2be797056d127a124f76976d5.ts} +5 -0
  269. package/test/props/components/temp/Reactive-types-bd642939107f1be06666bfce1ad97a94ccc21ee1.ts +10 -0
  270. package/test/replace/components/output/Replace-client.ts +3 -0
  271. package/test/replace/components/output/Replace-types.ts +10 -0
  272. package/test/replace/components/temp/{Replace-client-6f21ff3eb303bd5488d211087dc35fcf998d4e2a.ts → Replace-client-b80bc4591f8638cf125e8de9c1b25ea840dc75e9.ts} +3 -0
  273. package/test/replace/components/temp/Replace-types-9aedaa79e9b616ea1780ea97306f3428faa5d477.ts +10 -0
  274. package/test/slots/components/output/Article-client.ts +3 -0
  275. package/test/slots/components/output/Article-types.ts +10 -0
  276. package/test/slots/components/output/Basic-client.ts +3 -0
  277. package/test/slots/components/output/Basic-types.ts +10 -0
  278. package/test/slots/components/output/Header-client.ts +3 -0
  279. package/test/slots/components/output/Header-types.ts +10 -0
  280. package/test/slots/components/output/Let-client.ts +3 -0
  281. package/test/slots/components/output/Let-types.ts +10 -0
  282. package/test/slots/components/output/List-client.ts +3 -0
  283. package/test/slots/components/output/List-types.ts +10 -0
  284. package/test/slots/components/output/Named-client.ts +3 -0
  285. package/test/slots/components/output/Named-types.ts +10 -0
  286. package/test/slots/components/output/Unused-client.ts +3 -0
  287. package/test/slots/components/output/Unused-types.ts +10 -0
  288. package/test/slots/components/temp/{Article-client-0b674ee98ae7f85021bfb8b912f28e3c4b35e877.ts → Article-client-df86e549f8681f2329bffb4bc6bdf8ef60659d82.ts} +3 -0
  289. package/test/slots/components/temp/Article-types-d3d960fbab7644ec2d90dfe39d908fbb65abaaa2.ts +10 -0
  290. package/test/slots/components/temp/{Basic-client-196f7f0244dca0baeffb547eec55c089a108283d.ts → Basic-client-5bf137a656d5bc8739443df8e6876ac6ffdaeddd.ts} +3 -0
  291. package/test/slots/components/temp/Basic-types-709765786c453e34088db3e894a59fb3332d3ed1.ts +10 -0
  292. package/test/slots/components/temp/{Header-client-e5c784d60469523803898ee4d8b85fb82a7b7c0b.ts → Header-client-89439803e4de9b44da53fc051088ded2b4816a83.ts} +3 -0
  293. package/test/slots/components/temp/Header-types-c56a108c6fb5a22b8ae156936bc05e58eef199c2.ts +10 -0
  294. package/test/slots/components/temp/{Let-client-645271fcd63cd500001c75740b22b1b387330657.ts → Let-client-1e404c72bae5fe99bdced72d497dc3700d001112.ts} +3 -0
  295. package/test/slots/components/temp/Let-types-3d05614de77a23df63a3cc1873b27ce1b0148c58.ts +10 -0
  296. package/test/slots/components/temp/{List-client-ee6047ac396dc0b6fce5e38af51c38093fae83a2.ts → List-client-73ebb1a2d1364d807ca67c2b3008efb73e5bc74f.ts} +3 -0
  297. package/test/slots/components/temp/List-types-fd59ad7d85c06e67ee766a2cf14a637dd129569e.ts +10 -0
  298. package/test/slots/components/temp/{Named-client-559988562c5de1ae6017d2ad6de063f4363064b6.ts → Named-client-fae857376ae748995be367ea0b78c86cb778dcee.ts} +3 -0
  299. package/test/slots/components/temp/Named-types-ed10fb6338eb9bd67281b9658bd7b10b572d346a.ts +10 -0
  300. package/test/slots/components/temp/{Unused-client-52d1828bd28ebf7046a2e948a369563c0ea83b98.ts → Unused-client-715ddd9fa963f8185b11dd3725849dddc9b4a8e0.ts} +3 -0
  301. package/test/slots/components/temp/Unused-types-88f7e38611b4cae1067969cf702cde41422837ae.ts +10 -0
  302. package/test/source-maps/components/output/Source-client.ts +10 -4
  303. package/test/source-maps/components/output/Source-types.ts +10 -0
  304. package/test/source-maps/components/temp/{Source-client-ae8c4811ff658c13ee8c9b9e0e53fff1b83b178b.ts → Source-client-ea4254d629d7270203bf98ffae915e9b753a2fe2.ts} +10 -4
  305. package/test/source-maps/components/temp/Source-types-69770c124317e0a0fd6aeb3d4f331b50231452fa.ts +10 -0
  306. package/test/special-component/components/output/BigTitle-client.ts +3 -0
  307. package/test/special-component/components/output/BigTitle-types.ts +10 -0
  308. package/test/special-component/components/output/Component-client.ts +3 -0
  309. package/test/special-component/components/output/Component-types.ts +10 -0
  310. package/test/special-component/components/output/SmallTitle-client.ts +3 -0
  311. package/test/special-component/components/output/SmallTitle-types.ts +10 -0
  312. package/test/special-component/components/temp/{BigTitle-client-cb3055f809aaf17bd1fa82748d039ac3730a8d44.ts → BigTitle-client-d46e785f86a5daee62360043056359ca3e1cb7a0.ts} +3 -0
  313. package/test/special-component/components/temp/BigTitle-types-cb6363da78f853772d3408240f32030d5e826859.ts +10 -0
  314. package/test/special-component/components/temp/{Component-client-0eb9553b52acce2dfa564242295a4c57a38bd540.ts → Component-client-bd3af877909777431434a02fb77e751980a0b822.ts} +3 -0
  315. package/test/special-component/components/temp/Component-types-196e5e5c55f61a9d24837f8de1fb9e9eeb2dd3f1.ts +10 -0
  316. package/test/special-component/components/temp/{SmallTitle-client-5a65b233be29395e9650f57d9708a33de1279af3.ts → SmallTitle-client-28035d0154e3af173e9e3a1921be3a358e236cc5.ts} +3 -0
  317. package/test/special-component/components/temp/SmallTitle-types-629b435eb6f9a402ff576511db3e1d150f8c612b.ts +10 -0
  318. package/test/special-element/components/output/Element-client.ts +3 -0
  319. package/test/special-element/components/output/Element-types.ts +10 -0
  320. package/test/special-element/components/temp/{Element-client-745e610fbd5c652d327c8ac349d49d5ee4c8d9ea.ts → Element-client-83bfbaab3d8c85cce6b97675d8955e03ae99ba24.ts} +3 -0
  321. package/test/special-element/components/temp/Element-types-478aac6fcc8cc71dc587b534bb45ddcde069e2cb.ts +10 -0
  322. package/test/special-head/components/output/Head-client.ts +3 -0
  323. package/test/special-head/components/output/Head-types.ts +10 -0
  324. package/test/special-head/components/temp/{Head-client-bbbb5e712247ee41ca65a7ffd457987de5e99b3e.ts → Head-client-9e828c39f1930711e6c7db1d318b63f195e01e92.ts} +3 -0
  325. package/test/special-head/components/temp/Head-types-88772e6c9aefe7f65c342350ad45b29e7fa16604.ts +10 -0
  326. package/test/special-self/components/output/Self-client.ts +10 -4
  327. package/test/special-self/components/output/Self-types.ts +10 -0
  328. package/test/special-self/components/temp/{Self-client-dfe57df69e3677e94f7b5f3657c82602054ef19e.ts → Self-client-6846c5e6cdac15947ab4361f2e2b4ec900abd988.ts} +10 -4
  329. package/test/special-self/components/temp/Self-types-d438955d6f42951942dfa72ec1b79ad4ee95e966.ts +10 -0
  330. package/test/style/components/output/Style-client.ts +3 -0
  331. package/test/style/components/output/Style-types.ts +10 -0
  332. package/test/style/components/temp/{Style-client-9491a5aff97f118df542f976d7f7a21e7cc88c62.ts → Style-client-710dc4eba0e6a6ecbee26adc0d739ffdfb73ef10.ts} +3 -0
  333. package/test/style/components/temp/Style-types-d7ced2961f74be74eebaedfb98c492c6789d3cb8.ts +10 -0
  334. package/test/svg/components/output/Shape-client.ts +10 -4
  335. package/test/svg/components/output/Shape-types.ts +10 -0
  336. package/test/svg/components/temp/{Shape-client-4cc148d8b70d3750d2982360aad76b74d194b60e.ts → Shape-client-691decdc6064d94b0951c7a08da10feebd087324.ts} +10 -4
  337. package/test/svg/components/temp/Shape-types-70f9e311a005452b58286636c0dcb67a73e9fab4.ts +10 -0
  338. package/test/switch/components/Switch.torp +6 -4
  339. package/test/switch/components/output/Switch-client.ts +18 -9
  340. package/test/switch/components/output/Switch-server.ts +6 -4
  341. package/test/switch/components/output/Switch-types.ts +18 -0
  342. package/test/switch/components/temp/{Switch-client-5fc00f4d41300dc7587b113d8e53a102beca7558.ts → Switch-client-dcb3511bb3db12ad47e2237afc32a788184ad566.ts} +18 -9
  343. package/test/switch/components/temp/{Switch-server-440f7e852145b79656c0023ddc776e4d1d077d2a.ts → Switch-server-bbb3b40226e88388eb6f016cb0fd4be54f6139e7.ts} +6 -4
  344. package/test/switch/components/temp/Switch-types-fad2e2b194747eb6c06474c81de5f814c15e06aa.ts +18 -0
  345. package/test/text/components/output/Text-client.ts +3 -0
  346. package/test/text/components/output/Text-types.ts +16 -0
  347. package/test/text/components/temp/{Text-client-6c3be8a1a31a13eff86ce8b5330829cd15b07fab.ts → Text-client-e05d0c431475bf49349b4f6c162c9e78e0577b10.ts} +3 -0
  348. package/test/text/components/temp/Text-types-f9e6d77cf5a6def5aff78be41ebca3e8e6a54278.ts +16 -0
  349. package/test/watch-array/components/output/Array-client.ts +3 -0
  350. package/test/watch-array/components/output/Array-types.ts +10 -0
  351. package/test/watch-array/components/output/ArrayEntries-client.ts +3 -0
  352. package/test/watch-array/components/output/ArrayEntries-types.ts +10 -0
  353. package/test/watch-array/components/output/ArrayIndexes-client.ts +3 -0
  354. package/test/watch-array/components/output/ArrayIndexes-types.ts +10 -0
  355. package/test/watch-array/components/output/ArrayUnkeyed-client.ts +3 -0
  356. package/test/watch-array/components/output/ArrayUnkeyed-types.ts +10 -0
  357. package/test/watch-array/components/temp/{Array-client-552f81452d33fe6dc715c9f6bb7986f06475d761.ts → Array-client-3110972e940a678cc26316f5f38b9315a27559ee.ts} +3 -0
  358. package/test/watch-array/components/temp/Array-types-4afcc38999fa0a5d5b28b8c54ea8f25659d91165.ts +10 -0
  359. package/test/watch-array/components/temp/{ArrayEntries-client-736755fba2492e74812ff9c905202810de54e15a.ts → ArrayEntries-client-7f1e7bf740768a929f21e62f6b8ee31db8a50918.ts} +3 -0
  360. package/test/watch-array/components/temp/ArrayEntries-types-ae83cd05c68e5e6b7e8d31212035c14ec9ea6b85.ts +10 -0
  361. package/test/watch-array/components/temp/{ArrayIndexes-client-a496328fa92ffca676ab8893013a0cfec1734ad1.ts → ArrayIndexes-client-9861162934f1d779326d4d268cd95d765155a085.ts} +3 -0
  362. package/test/watch-array/components/temp/ArrayIndexes-types-5f02ec73d46553fd5730abfe022dba9a76a341f7.ts +10 -0
  363. package/test/watch-array/components/temp/{ArrayUnkeyed-client-5a2c5cb1fecba52653f7f35cfd07627682930c15.ts → ArrayUnkeyed-client-4ae3d9a74e763f8879458012de2a3c3837956c99.ts} +3 -0
  364. package/test/watch-array/components/temp/ArrayUnkeyed-types-6f544a6b354c46913b9ee0e843d0a6482af2745d.ts +10 -0
  365. package/test/watch-object/components/output/Watched-client.ts +3 -0
  366. package/test/watch-object/components/output/Watched-types.ts +10 -0
  367. package/test/watch-object/components/temp/{Watched-client-1f0409aa6e2c425d0319a23caec7d10ad313d579.ts → Watched-client-a7ddca317e29ef12d882d90e7b043d9c99a5f355.ts} +3 -0
  368. package/test/watch-object/components/temp/Watched-types-70c7bde732f624bfbb8e353bf9d1be8dbaea63e1.ts +10 -0
  369. package/tsdown.config.ts +1 -1
  370. package/test/attributes/components/Attributes.d.ts +0 -18
  371. package/test/await/components/Await.d.ts +0 -18
  372. package/test/bench/components/Bench.d.ts +0 -18
  373. package/test/bind/components/BindText.d.ts +0 -18
  374. package/test/child-component/components/ParentChild.d.ts +0 -34
  375. package/test/class/components/Class.d.ts +0 -18
  376. package/test/component/components/Component.d.ts +0 -18
  377. package/test/component/components/Header.d.ts +0 -18
  378. package/test/console/components/Console.d.ts +0 -18
  379. package/test/const/components/Const.d.ts +0 -18
  380. package/test/effects/components/For.d.ts +0 -18
  381. package/test/effects/components/If.d.ts +0 -18
  382. package/test/effects/components/NestedIf.d.ts +0 -18
  383. package/test/events/components/Increment.d.ts +0 -18
  384. package/test/for/components/For.d.ts +0 -18
  385. package/test/for/components/ForEscape.d.ts +0 -18
  386. package/test/for/components/ForIn.d.ts +0 -18
  387. package/test/for/components/ForOf.d.ts +0 -18
  388. package/test/function/components/Function.d.ts +0 -18
  389. package/test/html/components/Html.d.ts +0 -18
  390. package/test/if/components/IfAfterIf.d.ts +0 -18
  391. package/test/if/components/IfElse.d.ts +0 -18
  392. package/test/if/components/IfElseIf.d.ts +0 -18
  393. package/test/if/components/IfNested.d.ts +0 -18
  394. package/test/mount/components/Mount.d.ts +0 -18
  395. package/test/on-mount/components/OnMount.d.ts +0 -18
  396. package/test/party/components/AnswerButton.d.ts +0 -18
  397. package/test/party/components/AnswerButtonApp.d.ts +0 -18
  398. package/test/party/components/ColorSelect.d.ts +0 -18
  399. package/test/party/components/Colors.d.ts +0 -18
  400. package/test/party/components/Counter.d.ts +0 -18
  401. package/test/party/components/CssStyle.d.ts +0 -18
  402. package/test/party/components/DoubleCount.d.ts +0 -18
  403. package/test/party/components/FunnyButton.d.ts +0 -18
  404. package/test/party/components/FunnyButtonApp.d.ts +0 -18
  405. package/test/party/components/HelloWorld.d.ts +0 -18
  406. package/test/party/components/InputFocused.d.ts +0 -18
  407. package/test/party/components/InputHello.d.ts +0 -18
  408. package/test/party/components/IsAvailable.d.ts +0 -18
  409. package/test/party/components/Name.d.ts +0 -18
  410. package/test/party/components/NameUpdate.d.ts +0 -18
  411. package/test/party/components/PageTitle.d.ts +0 -18
  412. package/test/party/components/PickPill.d.ts +0 -18
  413. package/test/party/components/Time.d.ts +0 -18
  414. package/test/party/components/TrafficLight.d.ts +0 -18
  415. package/test/party/components/UserProfile.d.ts +0 -23
  416. package/test/party/components/UserProfileApp.d.ts +0 -18
  417. package/test/party/components/UserProfileContext.d.ts +0 -18
  418. package/test/party/components/UserProfileContextApp.d.ts +0 -18
  419. package/test/replace/components/Replace.d.ts +0 -18
  420. package/test/slots/components/Article.d.ts +0 -18
  421. package/test/slots/components/Basic.d.ts +0 -18
  422. package/test/slots/components/Header.d.ts +0 -18
  423. package/test/slots/components/Let.d.ts +0 -18
  424. package/test/slots/components/List.d.ts +0 -18
  425. package/test/slots/components/Named.d.ts +0 -18
  426. package/test/slots/components/Unused.d.ts +0 -18
  427. package/test/special-component/components/BigTitle.d.ts +0 -18
  428. package/test/special-component/components/Component.d.ts +0 -18
  429. package/test/special-component/components/SmallTitle.d.ts +0 -18
  430. package/test/special-element/components/Element.d.ts +0 -18
  431. package/test/special-head/components/Head.d.ts +0 -18
  432. package/test/special-self/components/Self.d.ts +0 -18
  433. package/test/style/components/Style.d.ts +0 -18
  434. package/test/svg/components/Shape.d.ts +0 -18
  435. package/test/switch/components/Switch.d.ts +0 -21
  436. package/test/text/components/Text.d.ts +0 -21
  437. package/test/watch-array/components/Array.d.ts +0 -18
  438. package/test/watch-array/components/ArrayEntries.d.ts +0 -18
  439. package/test/watch-array/components/ArrayIndexes.d.ts +0 -18
  440. package/test/watch-array/components/ArrayUnkeyed.d.ts +0 -18
  441. package/test/watch-object/components/Watched.d.ts +0 -18
@@ -0,0 +1,3735 @@
1
+
2
+ //#region src/compile/utils/endOfTemplateString.ts
3
+ function endOfTemplateString(content, start) {
4
+ let level = 0;
5
+ for (let j = start + 1; j < content.length; j++) if (content[j] === "`" && content[j - 1] !== "\\" && level === 0) return j;
6
+ else if (content[j] === "{" && (level > 0 || content[j - 1] === "$")) level += 1;
7
+ else if (content[j] === "}" && level > 0) level -= 1;
8
+ return content.length;
9
+ }
10
+
11
+ //#endregion
12
+ //#region src/compile/utils/Builder.ts
13
+ var Builder = class {
14
+ #text = "";
15
+ #space = 0;
16
+ #mapped = false;
17
+ lineMap = [];
18
+ constructor(mapped) {
19
+ this.#mapped = mapped === true;
20
+ }
21
+ prepend(text) {
22
+ this.#text = text + "\n" + this.#text;
23
+ }
24
+ append(text) {
25
+ if (this.#mapped) {
26
+ this.lineMap.push(this.#text.length);
27
+ for (let i$1 = 0; i$1 < text.length; i$1++) if (text[i$1] === "\n") this.lineMap.push(this.#text.length + i$1);
28
+ this.#text += "\n" + text;
29
+ return;
30
+ }
31
+ const start = this.#text.length;
32
+ text = text.trim();
33
+ let i = 0;
34
+ while (i < text.length) {
35
+ while (text[i] === " " || text[i] === " ") i++;
36
+ if (text[i] === ";") i++;
37
+ else if (text[i] === "\n") {
38
+ this.lineMap.push(start + i);
39
+ this.#text += "\n";
40
+ } else {
41
+ if (text[i] === "}" || text[i] === ")" || text[i] === "]") this.#space -= 1;
42
+ this.#text += " ".repeat(Math.max(0, this.#space));
43
+ const start$1 = i;
44
+ while (i < text.length && text[i] !== "\n") {
45
+ if (text[i] === "`") i = endOfTemplateString(text, i);
46
+ i++;
47
+ }
48
+ const line = text.substring(start$1, i + 1);
49
+ if (line.startsWith("*")) this.#text += " ";
50
+ this.#text += line;
51
+ if (text[i - 1] === "{" || text[i - 1] === "(" || text[i - 1] === "[") this.#space += 1;
52
+ }
53
+ i++;
54
+ }
55
+ if (!this.#text.endsWith("\n\n")) this.#text += "\n";
56
+ }
57
+ toString() {
58
+ return this.#text;
59
+ }
60
+ };
61
+
62
+ //#endregion
63
+ //#region src/compile/build/client/addMappedText.ts
64
+ function addMappedText(preText, text, postText, range, status, b) {
65
+ if (status.options?.mapped) {
66
+ let start = b.toString().length + preText.length;
67
+ b.append(preText + text + postText);
68
+ let end = start + text.length - postText.length;
69
+ status.map.push({
70
+ script: text,
71
+ source: range,
72
+ compiled: {
73
+ start,
74
+ end
75
+ }
76
+ });
77
+ } else b.append(preText + text + postText);
78
+ }
79
+
80
+ //#endregion
81
+ //#region src/compile/types/comments.ts
82
+ const ANCHOR_COMMENT = "<!>";
83
+ const HYDRATION_START_COMMENT = "<![>";
84
+ const HYDRATION_END_COMMENT = "<!]>";
85
+ const HYDRATION_BREAK_COMMENT = "<!^>";
86
+
87
+ //#endregion
88
+ //#region src/compile/utils/isReactive.ts
89
+ /**
90
+ * Checks whether the supplied string is fully or partially reactive (i.e. contains braces)
91
+ *
92
+ * @param text The string to check
93
+ *
94
+ * @returns True if the supplied string is fully or partially reactive
95
+ */
96
+ function isReactive(text) {
97
+ return text.includes("{") && text.includes("}");
98
+ }
99
+
100
+ //#endregion
101
+ //#region src/compile/utils/trimQuotes.ts
102
+ /**
103
+ * Trims matching quotes from the start and end of the supplied text
104
+ *
105
+ * @param text The text to trim
106
+ *
107
+ * @returns The text without the quotes at the start or the end
108
+ */
109
+ function trimQuotes(text) {
110
+ let start = 0;
111
+ let end = text.length;
112
+ while (text[start] === "'" && text[end - 1] === "'" || text[start] === "\"" && text[end - 1] === "\"" || text[start] === "`" && text[end - 1] === "`") {
113
+ start += 1;
114
+ end -= 1;
115
+ }
116
+ return text.substring(start, end);
117
+ }
118
+
119
+ //#endregion
120
+ //#region src/compile/build/client/buildFragmentText.ts
121
+ /**
122
+ * Builds the HTML template text for all of the fragments in a component
123
+ */
124
+ function buildFragmentText(node, status, b) {
125
+ const fragments = [];
126
+ buildNodeFragmentText(node, status, fragments);
127
+ if (fragments.length) b.append(`const t_fragments: DocumentFragment[] = [];`);
128
+ }
129
+ function buildNodeFragmentText(node, status, fragments, currentFragment) {
130
+ switch (node.type) {
131
+ case "root":
132
+ buildRootFragmentText(node, status, fragments);
133
+ break;
134
+ case "control":
135
+ buildControlFragmentText(node, status, fragments, currentFragment);
136
+ break;
137
+ case "component":
138
+ buildComponentFragmentText(node, status, fragments, currentFragment);
139
+ break;
140
+ case "element": {
141
+ let ns = node.tagName === "svg";
142
+ if (ns) status.ns = true;
143
+ buildElementFragmentText(node, status, fragments, currentFragment);
144
+ if (ns) status.ns = false;
145
+ break;
146
+ }
147
+ case "text": {
148
+ const content = node.content;
149
+ if (currentFragment) currentFragment.text += isReactive(content) ? "#" : content;
150
+ break;
151
+ }
152
+ case "special":
153
+ buildSpecialFragmentText(node, status, fragments, currentFragment);
154
+ break;
155
+ }
156
+ }
157
+ function buildRootFragmentText(node, status, fragments) {
158
+ node.fragment = {
159
+ number: fragments.length,
160
+ text: "",
161
+ ns: status.ns,
162
+ effects: [],
163
+ events: [],
164
+ animations: []
165
+ };
166
+ fragments.push(node.fragment);
167
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, node.fragment);
168
+ }
169
+ function buildControlFragmentText(node, status, fragments, currentFragment) {
170
+ switch (node.operation) {
171
+ case "@if group":
172
+ case "@switch group":
173
+ case "@for group":
174
+ case "@await group":
175
+ case "@replace group":
176
+ case "@html group":
177
+ currentFragment.text += ANCHOR_COMMENT;
178
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, currentFragment);
179
+ break;
180
+ default:
181
+ node.fragment = {
182
+ number: fragments.length,
183
+ text: "",
184
+ ns: status.ns,
185
+ effects: [],
186
+ events: [],
187
+ animations: []
188
+ };
189
+ fragments.push(node.fragment);
190
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, node.fragment);
191
+ break;
192
+ }
193
+ }
194
+ function buildComponentFragmentText(node, status, fragments, currentFragment) {
195
+ currentFragment.text += ANCHOR_COMMENT;
196
+ if (node.children.length) {
197
+ node.fragment = {
198
+ number: fragments.length,
199
+ text: "",
200
+ ns: status.ns,
201
+ effects: [],
202
+ events: [],
203
+ animations: []
204
+ };
205
+ fragments.push(node.fragment);
206
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, node.fragment);
207
+ }
208
+ }
209
+ function buildElementFragmentText(node, status, fragments, currentFragment) {
210
+ let needsClass = node.scopeStyles;
211
+ currentFragment.text += `<${node.tagName}`;
212
+ let attributesText = node.attributes.filter((a) => !a.name.startsWith("on")).map((a) => {
213
+ if (a.value && a.reactive) {
214
+ if (a.name.startsWith("data-")) return `${a.name}=""`;
215
+ } else if (a.name === "class" && node.scopeStyles) {
216
+ needsClass = false;
217
+ let value = a.value ? `"${trimQuotes(a.value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
218
+ return `${a.name}=${value}`;
219
+ } else return `${a.name}${a.value != null ? `=${a.value}` : ""}`;
220
+ }).filter(Boolean).join(" ");
221
+ if (attributesText) currentFragment.text += " " + attributesText;
222
+ if (needsClass) currentFragment.text += ` class="torp-${status.styleHash}"`;
223
+ currentFragment.text += ">";
224
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, currentFragment);
225
+ currentFragment.text += `</${node.tagName}>`;
226
+ }
227
+ function buildSpecialFragmentText(node, status, fragments, currentFragment) {
228
+ switch (node.tagName) {
229
+ case "slot":
230
+ currentFragment.text += ANCHOR_COMMENT;
231
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, node.fragment);
232
+ break;
233
+ case "fill":
234
+ node.fragment = {
235
+ number: fragments.length,
236
+ text: "",
237
+ ns: status.ns,
238
+ effects: [],
239
+ events: [],
240
+ animations: []
241
+ };
242
+ fragments.push(node.fragment);
243
+ for (let child of node.children) buildNodeFragmentText(child, status, fragments, node.fragment);
244
+ break;
245
+ case "@element":
246
+ buildComponentFragmentText(node, status, fragments, currentFragment);
247
+ break;
248
+ case "@component":
249
+ buildComponentFragmentText(node, status, fragments, currentFragment);
250
+ break;
251
+ default: throw new Error(`Invalid special node: ${node.tagName}`);
252
+ }
253
+ }
254
+
255
+ //#endregion
256
+ //#region src/compile/utils/isSpecialNode.ts
257
+ function isSpecialNode(node) {
258
+ return node.type === "special";
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/compile/build/utils/nextVarName.ts
263
+ /**
264
+ * Makes a supplied variable name (hopefully!) unique by prepending `t_` and
265
+ * appending a sequence number
266
+ *
267
+ * @param name The variable name
268
+ * @param status The build status
269
+ *
270
+ * @returns A unique variable name
271
+ */
272
+ function nextVarName(name, status) {
273
+ if (!status.varNames[name]) status.varNames[name] = 1;
274
+ let varName = `t_${name}_${status.varNames[name]}`;
275
+ status.varNames[name] += 1;
276
+ return varName;
277
+ }
278
+
279
+ //#endregion
280
+ //#region src/compile/build/client/buildAddFragment.ts
281
+ function buildAddFragment(node, status, b, parentName, anchorName) {
282
+ if (node.fragment) {
283
+ const fragment = node.fragment;
284
+ const fragmentName = `t_fragment_${fragment.number}`;
285
+ status.imports.add("t_add_fragment");
286
+ if (fragment.effects.length > 0) {
287
+ status.imports.add("$run");
288
+ b.append(`$run(function setAttributes() {`);
289
+ if (status.options?.mapped) for (let effect of fragment.effects) for (let i = 0; i < effect.ranges.length; i++) {
290
+ let start = b.toString().length + effect.offsets[i];
291
+ b.append(effect.functionBody);
292
+ let end = start + effect.lengths[i];
293
+ status.map.push({
294
+ script: effect.functionBody,
295
+ source: effect.ranges[i],
296
+ compiled: {
297
+ start,
298
+ end
299
+ }
300
+ });
301
+ }
302
+ else b.append(fragment.effects.map((e) => e.functionBody).join("\n"));
303
+ b.append("});");
304
+ }
305
+ let params = [
306
+ fragmentName,
307
+ parentName,
308
+ anchorName
309
+ ];
310
+ if (fragment.endVarName) params.push(fragment.endVarName);
311
+ b.append(`t_add_fragment(${params.join(", ")});`);
312
+ if (fragment.endVarName) {
313
+ status.imports.add("t_next");
314
+ b.append(`t_next(${fragment.endVarName});`);
315
+ }
316
+ }
317
+ }
318
+
319
+ //#endregion
320
+ //#region src/compile/parse/utils/isSpaceChar.ts
321
+ /**
322
+ * Checks whether the supplied character is a space
323
+ *
324
+ * @param text The string to check
325
+ * @param index The index of the character in the string
326
+ *
327
+ * @returns True if the supplied character is a space
328
+ */
329
+ function isSpaceChar(text, index) {
330
+ let code = text.charCodeAt(index);
331
+ return code === 32 || code >= 9 && code <= 13;
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/compile/parse/utils/isSpace.ts
336
+ /**
337
+ * Checks whether the supplied string contains only space characters
338
+ *
339
+ * @param text The string to check
340
+ *
341
+ * @returns True if the supplied string contains only space characters
342
+ */
343
+ function isSpace(text) {
344
+ for (let i = 0; i < text.length; i++) if (!isSpaceChar(text, i)) return false;
345
+ return true;
346
+ }
347
+
348
+ //#endregion
349
+ //#region src/compile/utils/isControlNode.ts
350
+ function isControlNode(node) {
351
+ return node.type === "control";
352
+ }
353
+
354
+ //#endregion
355
+ //#region src/compile/utils/isElementNode.ts
356
+ function isElementNode(node) {
357
+ return node.type === "element";
358
+ }
359
+
360
+ //#endregion
361
+ //#region src/compile/utils/isTextNode.ts
362
+ function isTextNode(node) {
363
+ return node.type === "text";
364
+ }
365
+
366
+ //#endregion
367
+ //#region src/compile/build/client/buildFragment.ts
368
+ /**
369
+ * Builds the variables and code in a fragment
370
+ */
371
+ function buildFragment(node, status, b, parentName, anchorName) {
372
+ if (node.fragment) {
373
+ const fragment = node.fragment;
374
+ const fragmentName = `t_fragment_${fragment.number}`;
375
+ if (status.options?.useCreateElement) {
376
+ let fragmentPath = {
377
+ parent: null,
378
+ type: "fragment",
379
+ children: []
380
+ };
381
+ let varPaths = /* @__PURE__ */ new Map();
382
+ declareFragmentVars(node.fragment, node, fragmentPath, status, b, parentName, anchorName, varPaths, false, true);
383
+ fragmentPath.children.length = 0;
384
+ varPaths.clear();
385
+ status.imports.add("t_frg");
386
+ b.append(`const ${fragmentName} = t_frg([`);
387
+ declareFragmentVars(node.fragment, node, fragmentPath, status, b, parentName, anchorName, varPaths, false, false);
388
+ b.append(`]);`);
389
+ } else {
390
+ status.imports.add("t_fragment");
391
+ const fragmentText = fragment.text.replaceAll("`", "\\`").replaceAll(/\s+/g, " ");
392
+ b.append(`const ${fragmentName} = t_fragment($parent.ownerDocument!, t_fragments, ${fragment.number}, \`${fragmentText}\`${fragment.ns ? ", true" : ""});`);
393
+ let fragmentPath = {
394
+ parent: null,
395
+ type: "fragment",
396
+ children: []
397
+ };
398
+ let varPaths = /* @__PURE__ */ new Map();
399
+ maybeAddRootNodeDeclaration(node, fragment, fragmentName, status, b, varPaths);
400
+ declareFragmentVars(node.fragment, node, fragmentPath, status, b, parentName, anchorName, varPaths, false, true);
401
+ }
402
+ }
403
+ }
404
+ function maybeAddRootNodeDeclaration(node, fragment, fragmentName, status, b, varPaths) {
405
+ if (!node.children.length) return;
406
+ let firstNode = node.children[0];
407
+ let firstNodeIsLastNode = node.children.length === 1;
408
+ if (isControlNode(firstNode) && firstNode.operation.endsWith(" group") || isElementNode(firstNode) && elementNodeNeedsDeclaration(firstNode, true, firstNodeIsLastNode) || isTextNode(firstNode) && textNodeNeedsDeclaration(firstNode, true, firstNodeIsLastNode)) {} else {
409
+ status.imports.add("t_root");
410
+ const rootName = `t_root_${fragment.number}`;
411
+ const params = [fragmentName];
412
+ if (firstNode.type === "text") params.push("true");
413
+ const rootPath = `t_root(${params.join(", ")})`;
414
+ b.append(`const ${rootName} = ${rootPath};`);
415
+ varPaths.set(`t_root(${fragmentName})`, rootName);
416
+ printDebug(rootName, status, b);
417
+ }
418
+ }
419
+ function declareFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
420
+ switch (node.type) {
421
+ case "root":
422
+ declareRootFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare);
423
+ break;
424
+ case "control":
425
+ declareControlFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare);
426
+ break;
427
+ case "component":
428
+ declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare);
429
+ break;
430
+ case "element":
431
+ declareElementFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare);
432
+ break;
433
+ case "text":
434
+ declareTextFragmentVars(fragment, node, path, status, b, varPaths, lastChild, declare);
435
+ break;
436
+ case "special":
437
+ declareSpecialFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare);
438
+ break;
439
+ default: throw new Error(`Invalid node type: ${node.type}`);
440
+ }
441
+ }
442
+ function declareRootFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
443
+ for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
444
+ }
445
+ function declareControlFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
446
+ switch (node.operation) {
447
+ case "@if group":
448
+ case "@switch group":
449
+ case "@for group":
450
+ case "@await group":
451
+ case "@replace group":
452
+ case "@html group": {
453
+ const operation = node.operation.substring(1).replace(" group", "");
454
+ declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, operation, declare);
455
+ break;
456
+ }
457
+ default:
458
+ for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
459
+ break;
460
+ }
461
+ }
462
+ function declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
463
+ declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, "comp", declare);
464
+ }
465
+ function elementTypeName(node) {
466
+ switch (node.tagName.toLowerCase()) {
467
+ case "div":
468
+ case "input": return `HTML${node.tagName.substring(0, 1).toUpperCase() + node.tagName.substring(1)}Element`;
469
+ case "textarea": return "HTMLTextAreaElement";
470
+ }
471
+ return "HTMLElement";
472
+ }
473
+ function declareElementFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
474
+ const tagName = node.tagName === "@element" ? "element" : node.tagName;
475
+ let elementPath = {
476
+ parent: path,
477
+ type: tagName,
478
+ children: []
479
+ };
480
+ path.children.push(elementPath);
481
+ const topLevel = !path.parent;
482
+ const declareVariable = elementNodeNeedsDeclaration(node, topLevel, lastChild);
483
+ if (declare) {
484
+ if (declareVariable) {
485
+ node.varName = nextVarName(tagName, status);
486
+ if (topLevel) fragment.endVarName = node.varName;
487
+ const varPath = getFragmentVarPath(fragment, status, node.varName, elementPath, varPaths);
488
+ if (status.options?.useCreateElement) b.append(`let ${node.varName};`);
489
+ else if (node.tagName === "@element") b.append(`let ${node.varName} = ${varPath} as ${elementTypeName(node)};`);
490
+ else {
491
+ b.append(`const ${node.varName} = ${varPath} as ${elementTypeName(node)};`);
492
+ printDebug(node.varName, status, b);
493
+ }
494
+ }
495
+ }
496
+ let childParentName = node.children.find((c) => !!c.parentName)?.parentName;
497
+ if (!declare) {
498
+ let attributes = node.attributes.filter((a) => !a.name.startsWith("on")).map((a) => {
499
+ if (a.value && a.reactive) return `"${a.name}": "#"`;
500
+ else if (a.value) return `"${a.name}": "${trimQuotes(a.value) || a.name}"`;
501
+ else return `"${a.name}": true"`;
502
+ }).join(", ");
503
+ status.imports.add("t_elm");
504
+ if (declareVariable) b.append(`(${childParentName ? `${childParentName} = ` : ""}${node.varName} = t_elm("${node.tagName}", {${attributes}}, [`);
505
+ else if (childParentName) b.append(`(${childParentName} = t_elm("${node.tagName}", {${attributes}}, [`);
506
+ else b.append(`t_elm("${node.tagName}", {${attributes}}, [`);
507
+ }
508
+ for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, elementPath, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
509
+ if (!declare) if (declareVariable || childParentName) b.append("])),");
510
+ else b.append("]),");
511
+ }
512
+ function elementNodeNeedsDeclaration(node, topLevel, lastChild) {
513
+ const hasReactiveAttribute = node.attributes.some((a) => a.value && a.reactive);
514
+ const isDynamicElement = node.tagName === "@element" && node.attributes.find((a) => a.name === "self");
515
+ return hasReactiveAttribute || isDynamicElement || topLevel && lastChild;
516
+ }
517
+ function declareTextFragmentVars(fragment, node, path, status, b, varPaths, lastChild, declare) {
518
+ const lastType = path.children[path.children.length - 1]?.type;
519
+ if (lastType === "text" || lastType === "space") return;
520
+ let textPath = {
521
+ parent: path,
522
+ type: isSpace(node.content) ? "space" : "text",
523
+ children: []
524
+ };
525
+ path.children.push(textPath);
526
+ const topLevel = !path.parent;
527
+ const declareVariable = textNodeNeedsDeclaration(node, topLevel, lastChild);
528
+ if (declare) {
529
+ if (declareVariable) {
530
+ node.varName = nextVarName("text", status);
531
+ if (topLevel) fragment.endVarName = node.varName;
532
+ const varPath = getFragmentVarPath(fragment, status, node.varName, textPath, varPaths);
533
+ if (status.options?.useCreateElement) b.append(`let ${node.varName};`);
534
+ else {
535
+ b.append(`const ${node.varName} = ${varPath};`);
536
+ printDebug(node.varName, status, b);
537
+ }
538
+ }
539
+ } else {
540
+ status.imports.add("t_txt");
541
+ if (declareVariable) b.append(`(${node.varName} = t_txt(" ")),`);
542
+ else b.append(`t_txt("${node.content}"),`);
543
+ }
544
+ }
545
+ function textNodeNeedsDeclaration(node, topLevel, lastChild) {
546
+ return isReactive(node.content) || topLevel && lastChild;
547
+ }
548
+ function declareSpecialFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
549
+ if (node.tagName === "slot") declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, "slot", declare);
550
+ switch (node.tagName) {
551
+ case "slot":
552
+ case "fill":
553
+ for (let [i, child] of node.children.entries()) {
554
+ if (node.tagName === "slot" && isSpecialNode(child) && child.tagName === "fill") continue;
555
+ declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
556
+ }
557
+ break;
558
+ case "@element":
559
+ declareElementFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare);
560
+ break;
561
+ case "@component":
562
+ declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare);
563
+ break;
564
+ default: throw new Error(`Invalid special node: ${node.tagName}`);
565
+ }
566
+ }
567
+ function declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, name, declare) {
568
+ if (!path.parent) node.parentName = `t_fragment_${fragment.number}`;
569
+ else {
570
+ const parentPath = path;
571
+ const oldChildren = parentPath.children;
572
+ parentPath.children = [];
573
+ const parentVarPath = getFragmentVarPath(fragment, status, "?", parentPath, varPaths);
574
+ parentPath.children = oldChildren;
575
+ if (varPaths.has(parentVarPath)) node.parentName = varPaths.get(parentVarPath);
576
+ else if (declare) {
577
+ node.parentName = nextVarName(`${name}_parent`, status);
578
+ if (status.options?.useCreateElement) b.append(`let ${node.parentName} as HTMLElement;`);
579
+ else {
580
+ b.append(`const ${node.parentName} = ${parentVarPath} as HTMLElement;`);
581
+ printDebug(node.parentName, status, b);
582
+ }
583
+ varPaths.set(parentVarPath, node.parentName);
584
+ }
585
+ }
586
+ if (declare) {
587
+ const anchorPath = {
588
+ parent: path,
589
+ type: "#",
590
+ children: []
591
+ };
592
+ path.children.push(anchorPath);
593
+ node.varName = nextVarName(`${name}_anchor`, status);
594
+ const anchorVarPath = getFragmentVarPath(fragment, status, node.varName, anchorPath, varPaths);
595
+ if (status.options?.useCreateElement) b.append(`let ${node.varName};`);
596
+ else {
597
+ status.imports.add("t_anchor");
598
+ b.append(`let ${node.varName} = t_anchor(${anchorVarPath}) as HTMLElement;`);
599
+ printDebug(node.varName, status, b);
600
+ }
601
+ } else {
602
+ status.imports.add("t_cmt");
603
+ b.append(`(${node.varName} = t_cmt()),`);
604
+ }
605
+ buildNode(node, status, b, parentName, anchorName);
606
+ node.handled = true;
607
+ }
608
+ function getFragmentVarPath(fragment, status, name, path, varPaths) {
609
+ let node = path;
610
+ while (node.parent) node = node.parent;
611
+ let varName = `t_fragment_${fragment.number}`;
612
+ let varPath = getFragmentVarPathPart(node, varName, status, true);
613
+ for (let [existingPath, existingName] of varPaths) if (varPath.includes(existingPath)) varPath = varPath.replace(existingPath, existingName);
614
+ if (name !== "?") {
615
+ varPaths.set(varPath, name);
616
+ varPaths.set(name, name);
617
+ }
618
+ while (varPath.includes("t_next(t_next(")) {
619
+ status.imports.add("t_skip");
620
+ const match = varPath.match(/(t_next\(){2,}/)[0];
621
+ const count = match.length / 7;
622
+ const pos = varPath.indexOf("t_next(t_next(");
623
+ const head = varPath.substring(0, pos);
624
+ let level = 0;
625
+ let end = 0;
626
+ for (let i = pos + match.length; i < varPath.length; i++) if (varPath[i] === "(") level++;
627
+ else if (varPath[i] === ")") if (level === 0) {
628
+ end = i;
629
+ break;
630
+ } else level--;
631
+ const tail = varPath.substring(end + count);
632
+ const param = varPath.substring(pos + match.length, end);
633
+ varPath = `${head}t_skip(${param}, ${count})${tail}`;
634
+ }
635
+ varPath = varPath.replaceAll("t_next_text", "t_next");
636
+ return varPath;
637
+ }
638
+ function getFragmentVarPathPart(path, varPath, status, root = false) {
639
+ if (root) {
640
+ status.imports.add("t_root");
641
+ varPath = `t_root(${varPath})`;
642
+ } else {
643
+ status.imports.add("t_child");
644
+ varPath = `t_child(${varPath})`;
645
+ }
646
+ for (let [i, child] of path.children.entries()) {
647
+ if (i > 0) if (child.type === "text" || child.type === "space") varPath = `t_next_text(${varPath}, true)`;
648
+ else {
649
+ status.imports.add("t_next");
650
+ varPath = `t_next(${varPath})`;
651
+ }
652
+ if (i === path.children.length - 1 && child.children.length) varPath = getFragmentVarPathPart(child, varPath, status);
653
+ }
654
+ return varPath;
655
+ }
656
+ function printDebug(varName, status, b) {}
657
+
658
+ //#endregion
659
+ //#region src/compile/build/client/replaceForVarNames.ts
660
+ /**
661
+ * Variables used within a for loop need to be retrieved from the loop data.
662
+ */
663
+ function replaceForVarNames(value, status) {
664
+ for (let varName of status.forVarNames) value = value.replaceAll(new RegExp(`(^|\\s|\\(|\\[|\\{)${varName}($|\\s|\\.|\\(|\\)|\\[|\\]|\\}|;)`, "g"), `$1t_item.data.${varName}$2`);
665
+ return value;
666
+ }
667
+
668
+ //#endregion
669
+ //#region src/compile/build/client/buildRun.ts
670
+ function buildRun(functionName, functionBody, status, b) {
671
+ functionBody = replaceForVarNames(functionBody, status);
672
+ status.imports.add("$run");
673
+ b.append(`$run(function ${functionName}() {`);
674
+ b.append(functionBody);
675
+ b.append("});");
676
+ }
677
+
678
+ //#endregion
679
+ //#region src/compile/build/client/buildComponentNode.ts
680
+ function buildComponentNode(node, status, b, root = false) {
681
+ b.append("");
682
+ b.append("/* @component */");
683
+ const componentHasProps = node.attributes.length || root;
684
+ const propsName = componentHasProps ? nextVarName("props", status) : "undefined";
685
+ if (componentHasProps) {
686
+ status.imports.add("$watch");
687
+ b.append(`const ${propsName}: any = $watch({});`);
688
+ for (let { name, value, reactive, fullyReactive } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (name.startsWith("&") && value != null && fullyReactive) {
689
+ name = name.substring(1);
690
+ buildRun("setProp", `${propsName}["${name}"] = ${value};`, status, b);
691
+ buildRun("setBinding", `${value} = ${propsName}["${name}"];`, status, b);
692
+ } else if (name === "class" && value != null) {
693
+ status.imports.add("t_class");
694
+ const params = [value];
695
+ if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
696
+ buildRun("setClasses", `${propsName}["class"] = t_class(${params.join(", ")});`, status, b);
697
+ } else if (name === "style" && value != null) {
698
+ status.imports.add("t_style");
699
+ buildRun("setStyles", `${propsName}["style"] = t_style(${value});`, status, b);
700
+ } else if (value != null) {
701
+ const setProp = `${propsName}["${name}"] = ${value};`;
702
+ if (reactive) buildRun("setProp", setProp, status, b);
703
+ else b.append(setProp);
704
+ } else b.append(`${propsName}["${name}"] = true;`);
705
+ if (root) {
706
+ status.imports.add("$run");
707
+ b.append(`
708
+ if ($props) {
709
+ const propNames = [${status.props.map((p) => `'${p}'`).join(", ")}];
710
+ for (let name of Object.keys($props)) {
711
+ if (!name.startsWith("$") && !propNames.includes(name)) {
712
+ $run(() => ${propsName}[name] = $props[name]);
713
+ }
714
+ }
715
+ }`);
716
+ }
717
+ }
718
+ const componentHasSlots = node.children.length;
719
+ const slotsName = componentHasSlots ? nextVarName("slots", status) : "undefined";
720
+ if (componentHasSlots) {
721
+ b.append(`const ${slotsName}: Record<string, SlotRender> = {};`);
722
+ for (let slot of node.children) if (isSpecialNode(slot) && slot.tagName === "fill") {
723
+ const nameAttribute = slot.attributes.find((a) => a.name === "name");
724
+ const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
725
+ const slotParams = [
726
+ "$sparent: ParentNode",
727
+ "$sanchor: Node | null",
728
+ `${slot.hasSlotProps ? "$sprops" : "_$sprops?"}: Record<PropertyKey, any>`,
729
+ "// @ts-ignore\n$context?: Record<PropertyKey, any>"
730
+ ];
731
+ b.append(`${slotsName}["${slotName}"] = (\n${slotParams.join(",\n")}\n) => {`);
732
+ buildFragment(slot, status, b, "$sparent", "$sanchor");
733
+ status.fragmentStack.push({
734
+ fragment: slot.fragment,
735
+ path: ""
736
+ });
737
+ for (let child of slot.children) buildNode(child, status, b, "$sparent", "$sanchor");
738
+ status.fragmentStack.pop();
739
+ buildAddFragment(slot, status, b, "$sparent", "$sanchor");
740
+ b.append(`}`);
741
+ }
742
+ }
743
+ const compParentName = node.parentName;
744
+ const compAnchorName = node.varName;
745
+ let renderParams = `${compParentName}, ${compAnchorName}, ${propsName}, $context`;
746
+ if (slotsName !== "undefined") renderParams += `, ${slotsName}`;
747
+ let componentName = node.tagName;
748
+ if (componentName === "@component") {
749
+ let selfAttribute = node.attributes.find((a) => a.name === "self");
750
+ if (selfAttribute && selfAttribute.value && selfAttribute.fullyReactive) componentName = selfAttribute.value;
751
+ }
752
+ addMappedText("", `${componentName}(${renderParams})`, ";", node.range, status, b);
753
+ b.append("");
754
+ }
755
+
756
+ //#endregion
757
+ //#region src/compile/utils/trimMatched.ts
758
+ /**
759
+ * Trims chars from the start and end of the supplied text when both the start and end match
760
+ *
761
+ * @param text The text to trim
762
+ *
763
+ * @returns The text without the chars at the start or the end
764
+ */
765
+ function trimMatched(text, startChar, endChar) {
766
+ let start = 0;
767
+ let end = text.length;
768
+ while (text[start] === startChar && text[end - 1] === endChar) {
769
+ start += 1;
770
+ end -= 1;
771
+ }
772
+ return text.substring(start, end);
773
+ }
774
+
775
+ //#endregion
776
+ //#region src/compile/build/client/buildAwaitNode.ts
777
+ function buildAwaitNode(node, status, b) {
778
+ const anchorName = node.varName;
779
+ const parentName = node.parentName;
780
+ const rangeName = nextVarName("await_range", status);
781
+ const stateName = "$" + nextVarName("await_state", status);
782
+ const creatorsName = nextVarName("await_creators", status);
783
+ const awaitVarsName = nextVarName("await_vars", status);
784
+ const branches = node.children.filter((n) => isControlNode(n));
785
+ let awaitBranch = branches.find((n) => n.operation === "@await");
786
+ if (!awaitBranch) {}
787
+ let thenBranch = branches.find((n) => n.operation === "@then");
788
+ if (!thenBranch) thenBranch = {
789
+ type: "control",
790
+ operation: "@then",
791
+ statement: "then",
792
+ children: [],
793
+ range: {
794
+ start: 0,
795
+ end: 0
796
+ }
797
+ };
798
+ let catchBranch = branches.find((n) => n.operation === "@catch");
799
+ if (!catchBranch) catchBranch = {
800
+ type: "control",
801
+ operation: "@catch",
802
+ statement: "catch",
803
+ children: [],
804
+ range: {
805
+ start: 0,
806
+ end: 0
807
+ }
808
+ };
809
+ const awaiterName = trimMatched(awaitBranch.statement.substring(5).trim(), "(", ")");
810
+ const thenVar = trimMatched(thenBranch.statement.substring(4).trim(), "(", ")");
811
+ const catchVar = trimMatched(catchBranch.statement.substring(5).trim(), "(", ")");
812
+ status.imports.add("$watch");
813
+ status.imports.add("$run");
814
+ status.imports.add("t_range");
815
+ status.imports.add("t_run_control");
816
+ status.imports.add("t_run_branch");
817
+ b.append("");
818
+ b.append(`
819
+ /* @await */
820
+ const ${rangeName} = t_range();
821
+ let ${stateName} = $watch({ index: -1 });
822
+ let ${creatorsName}: ((t_before: Node | null) => void)[] = [];`);
823
+ b.append(`
824
+ let ${awaitVarsName} = { t_token: 0 };
825
+ $run(function runAwait() {`);
826
+ let index = 0;
827
+ buildAwaitBranch(awaitBranch, status, b, parentName, stateName, creatorsName, index++);
828
+ b.append(`${awaitVarsName}.t_token++;
829
+ ((t_token) => {`);
830
+ awaitBranch.range.start += 7;
831
+ addMappedText("", replaceForVarNames(awaiterName, status), "", awaitBranch.range, status, b);
832
+ thenBranch.range.start -= 1;
833
+ addMappedText(".then((", replaceForVarNames(thenVar, status), ") => {", thenBranch.range, status, b);
834
+ b.append(`if (t_token === ${awaitVarsName}.t_token) {`);
835
+ buildAwaitBranch(thenBranch, status, b, parentName, stateName, creatorsName, index++);
836
+ b.append(`}
837
+ })`);
838
+ catchBranch.range.start -= 1;
839
+ addMappedText(".catch((", replaceForVarNames(catchVar, status), ") => {", catchBranch.range, status, b);
840
+ b.append(`
841
+ if (t_token === ${awaitVarsName}.t_token) {`);
842
+ buildAwaitBranch(catchBranch, status, b, parentName, stateName, creatorsName, index++);
843
+ b.append(`}
844
+ });
845
+ })(${awaitVarsName}.t_token);
846
+ });`);
847
+ b.append(`
848
+ t_run_control(${rangeName}, ${anchorName}, (t_before) => {
849
+ t_run_branch(${rangeName}, () => ${creatorsName}[${stateName}.index](t_before));
850
+ });`);
851
+ b.append("");
852
+ }
853
+ function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName, index) {
854
+ if (node.children.length > 0) {
855
+ b.append(`${creatorsName}[${index}] = (t_before) => {`);
856
+ buildFragment(node, status, b, parentName, "t_before");
857
+ status.fragmentStack.push({
858
+ fragment: node.fragment,
859
+ path: ""
860
+ });
861
+ for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
862
+ status.fragmentStack.pop();
863
+ buildAddFragment(node, status, b, parentName, "t_before");
864
+ b.append("};");
865
+ } else b.append(`${creatorsName}[${index}] = (_) => {};`);
866
+ b.append(`${stateName}.index = ${index};`);
867
+ }
868
+
869
+ //#endregion
870
+ //#region src/compile/utils/trimEnd.ts
871
+ /**
872
+ * Trims a char from the end of the supplied text
873
+ *
874
+ * @param text The text to trim
875
+ * @param char The char to remove from the end of the text
876
+ *
877
+ * @returns The text without the char on the end
878
+ */
879
+ function trimEnd(text, char) {
880
+ let end = text.length;
881
+ while (text[end - 1] === char) end -= 1;
882
+ return text.substring(0, end);
883
+ }
884
+
885
+ //#endregion
886
+ //#region src/compile/build/client/buildForNode.ts
887
+ const forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
888
+ const forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,1}/g;
889
+ const forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
890
+ function buildForNode(node, status, b) {
891
+ const forParentName = node.parentName;
892
+ const forAnchorName = node.varName;
893
+ node = node.children[0];
894
+ const forVarNames = [];
895
+ const forIndexMatch = node.statement.match(forLoopRegex);
896
+ if (forIndexMatch) {
897
+ const forVarMatches = forIndexMatch[1].matchAll(forLoopVarsRegex);
898
+ for (let match of forVarMatches) forVarNames.push(match[1]);
899
+ } else {
900
+ const forOfMatch = node.statement.match(forOfRegex);
901
+ if (forOfMatch) {
902
+ const match = forOfMatch[1];
903
+ if (match.startsWith("{") && match.endsWith("}") || match.startsWith("[") && match.endsWith("]")) forVarNames.push(...trimMatched(trimMatched(match, "{", "}"), "[", "]").split(",").map((m) => m.trim()));
904
+ else forVarNames.push(match);
905
+ }
906
+ }
907
+ const forRangeName = nextVarName("for_range", status);
908
+ const key = node.children.find((n) => n.type === "control" && n.operation === "@key");
909
+ let keyStatement = key ? key.statement : "";
910
+ if (keyStatement) keyStatement = trimEnd(keyStatement.substring(keyStatement.indexOf("=") + 1).trim(), ";");
911
+ status.imports.add("t_range");
912
+ status.imports.add("t_run_list");
913
+ status.imports.add("t_list_item");
914
+ status.imports.add("ListItem");
915
+ b.append("");
916
+ b.append(`
917
+ /* @for */
918
+ let ${forRangeName} = t_range();
919
+ t_run_list(
920
+ ${forRangeName},
921
+ ${forParentName},
922
+ ${forAnchorName},
923
+ function createNewItems() {
924
+ let t_new_items: ListItem[] = [];
925
+ let t_previous_item = ${forRangeName};
926
+ let t_next_item = ${forRangeName}.nextRange;`);
927
+ addMappedText("", `${node.statement}`, " {", node.range, status, b);
928
+ b.append(`
929
+ let t_new_item = t_list_item({ ${forVarNames.join(",\n")} }${keyStatement ? `, ${keyStatement}` : ""});
930
+ t_new_item.previousRange = t_previous_item;
931
+ t_previous_item.nextRange = t_new_item;
932
+ t_previous_item = t_new_item;
933
+ t_new_items.push(t_new_item);
934
+ }
935
+ ${forRangeName}.nextRange = t_next_item;
936
+ return t_new_items;
937
+ },
938
+ function createListItem(t_item, t_before) {`);
939
+ status.forVarNames = forVarNames;
940
+ buildForItem(node, status, b, forParentName);
941
+ status.forVarNames = [];
942
+ b.append(`},
943
+ function updateListItem(t_old_item, t_new_item) {`);
944
+ for (let varName of forVarNames) b.append(`t_old_item.data.${varName} = t_new_item.data.${varName};`);
945
+ b.append(`}
946
+ );`);
947
+ b.append("");
948
+ }
949
+ function buildForItem(node, status, b, parentName) {
950
+ const oldRangeName = nextVarName("old_range", status);
951
+ status.imports.add("t_push_range");
952
+ b.append(`let ${oldRangeName} = t_push_range(t_item);`);
953
+ buildFragment(node, status, b, parentName, "t_before");
954
+ status.fragmentStack.push({
955
+ fragment: node.fragment,
956
+ path: ""
957
+ });
958
+ for (let child of node.children) {
959
+ if (isControlNode(child) && child.operation === "@key") continue;
960
+ buildNode(child, status, b, parentName, "t_before");
961
+ }
962
+ status.fragmentStack.pop();
963
+ buildAddFragment(node, status, b, parentName, "t_before");
964
+ status.imports.add("t_pop_range");
965
+ b.append(`t_pop_range(${oldRangeName});`);
966
+ }
967
+
968
+ //#endregion
969
+ //#region src/compile/build/client/buildHtmlNode.ts
970
+ function buildHtmlNode(node, status, b) {
971
+ const htmlAnchorName = node.varName;
972
+ const htmlParentName = node.parentName || htmlAnchorName + ".parentNode";
973
+ const htmlRangeName = nextVarName("html_range", status);
974
+ node = node.children[0];
975
+ status.imports.add("t_range");
976
+ status.imports.add("t_run_control");
977
+ b.append("");
978
+ b.append(`
979
+ /* @html */
980
+ const ${htmlRangeName} = t_range();
981
+ t_run_control(${htmlRangeName}, ${htmlAnchorName}, (t_before) => {`);
982
+ buildHtmlBranch(node, status, b, htmlParentName, htmlRangeName);
983
+ b.append("});");
984
+ b.append("");
985
+ }
986
+ function buildHtmlBranch(node, status, b, parentName, rangeName) {
987
+ status.imports.add("t_run_branch");
988
+ b.append(`${node.statement};`);
989
+ b.append(`t_run_branch(${rangeName}, () => {`);
990
+ const templateName = nextVarName("template", status);
991
+ const fragmentName = `t_fragment_${node.fragment.number}`;
992
+ b.append(`const ${templateName} = document.createElement("template");`);
993
+ b.append(`${templateName}.innerHTML = ${node.statement};`);
994
+ b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
995
+ buildAddFragment(node, status, b, parentName, "t_before");
996
+ b.append(`});`);
997
+ }
998
+
999
+ //#endregion
1000
+ //#region src/compile/build/client/buildIfNode.ts
1001
+ function buildIfNode(node, status, b) {
1002
+ const anchorName = node.varName;
1003
+ const parentName = node.parentName || anchorName + ".parentNode";
1004
+ const rangeName = nextVarName("if_range", status);
1005
+ const stateName = "$" + nextVarName("if_state", status);
1006
+ const creatorsName = nextVarName("if_creators", status);
1007
+ const branches = node.children.filter((n) => isControlNode(n));
1008
+ if (branches.findIndex((n) => n.operation === "@else") === -1) branches.push({
1009
+ type: "control",
1010
+ operation: "@else",
1011
+ statement: "else",
1012
+ children: [],
1013
+ range: {
1014
+ start: 0,
1015
+ end: 0
1016
+ }
1017
+ });
1018
+ status.imports.add("$watch");
1019
+ status.imports.add("$run");
1020
+ status.imports.add("t_range");
1021
+ status.imports.add("t_run_control");
1022
+ status.imports.add("t_run_branch");
1023
+ b.append("");
1024
+ b.append(`
1025
+ /* @if */
1026
+ const ${rangeName} = t_range();
1027
+ let ${stateName} = $watch({ index: -1 });
1028
+ let ${creatorsName}: ((t_before: Node | null) => void)[] = [];`);
1029
+ b.append(`$run(function runIf() {`);
1030
+ let index = 0;
1031
+ for (let branch of branches) buildIfBranch(branch, status, b, parentName, stateName, creatorsName, index++);
1032
+ b.append(`});`);
1033
+ b.append(`
1034
+ t_run_control(${rangeName}, ${anchorName}, (t_before) => {
1035
+ t_run_branch(${rangeName}, () => ${creatorsName}[${stateName}.index](t_before));
1036
+ });`);
1037
+ b.append("");
1038
+ }
1039
+ function buildIfBranch(node, status, b, parentName, stateName, creatorsName, index) {
1040
+ addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.range, status, b);
1041
+ if (node.children.length > 0) {
1042
+ b.append(`${creatorsName}[${index}] = (t_before) => {`);
1043
+ buildFragment(node, status, b, parentName, "t_before");
1044
+ status.fragmentStack.push({
1045
+ fragment: node.fragment,
1046
+ path: ""
1047
+ });
1048
+ for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
1049
+ status.fragmentStack.pop();
1050
+ buildAddFragment(node, status, b, parentName, "t_before");
1051
+ b.append("};");
1052
+ } else b.append(`${creatorsName}[${index}] = (_) => {};`);
1053
+ b.append(`${stateName}.index = ${index};`);
1054
+ b.append("}");
1055
+ }
1056
+
1057
+ //#endregion
1058
+ //#region src/compile/build/client/buildReplaceNode.ts
1059
+ function buildReplaceNode(node, status, b) {
1060
+ const replaceAnchorName = node.varName;
1061
+ const replaceParentName = node.parentName || replaceAnchorName + ".parentNode";
1062
+ const replaceRangeName = nextVarName("replace_range", status);
1063
+ node = node.children[0];
1064
+ status.imports.add("t_range");
1065
+ status.imports.add("t_run_control");
1066
+ b.append("");
1067
+ b.append(`
1068
+ /* @replace */
1069
+ const ${replaceRangeName} = t_range();
1070
+ t_run_control(${replaceRangeName}, ${replaceAnchorName}, (t_before) => {`);
1071
+ buildReplaceBranch(node, status, b, replaceParentName, replaceRangeName);
1072
+ b.append("});");
1073
+ b.append("");
1074
+ }
1075
+ function buildReplaceBranch(node, status, b, parentName, rangeName) {
1076
+ status.imports.add("t_run_branch");
1077
+ b.append(`${replaceForVarNames(node.statement, status)};`);
1078
+ b.append(`t_run_branch(${rangeName}, () => {`);
1079
+ buildFragment(node, status, b, parentName, "t_before");
1080
+ status.fragmentStack.push({
1081
+ fragment: node.fragment,
1082
+ path: ""
1083
+ });
1084
+ for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
1085
+ status.fragmentStack.pop();
1086
+ buildAddFragment(node, status, b, parentName, "t_before");
1087
+ b.append(`});`);
1088
+ }
1089
+
1090
+ //#endregion
1091
+ //#region src/compile/build/client/buildScriptNode.ts
1092
+ function buildScriptNode(node, status, b) {
1093
+ b.append(`/* ${node.operation} */`);
1094
+ addMappedText("", `${maybeAppend$1(node.statement, ";")}`, "", node.range, status, b);
1095
+ }
1096
+ function maybeAppend$1(text, end) {
1097
+ if (!text.endsWith(end)) text += end;
1098
+ return text;
1099
+ }
1100
+
1101
+ //#endregion
1102
+ //#region src/compile/build/client/buildSwitchNode.ts
1103
+ function buildSwitchNode(node, status, b) {
1104
+ const anchorName = node.varName;
1105
+ const parentName = node.parentName;
1106
+ const rangeName = nextVarName("switch_range", status);
1107
+ const stateName = "$" + nextVarName("switch_state", status);
1108
+ const creatorsName = nextVarName("switch_creators", status);
1109
+ const branches = node.children.filter((n) => isControlNode(n));
1110
+ if (branches.findIndex((n) => n.operation === "@default") === -1) branches.push({
1111
+ type: "control",
1112
+ operation: "@default",
1113
+ statement: "default",
1114
+ children: [],
1115
+ range: {
1116
+ start: 0,
1117
+ end: 0
1118
+ }
1119
+ });
1120
+ status.imports.add("$watch");
1121
+ status.imports.add("$run");
1122
+ status.imports.add("t_range");
1123
+ status.imports.add("t_run_control");
1124
+ status.imports.add("t_run_branch");
1125
+ b.append("");
1126
+ b.append(`
1127
+ /* @switch */
1128
+ const ${rangeName} = t_range();
1129
+ let ${stateName} = $watch({ index: -1 });
1130
+ let ${creatorsName}: ((t_before: Node | null) => void)[] = [];`);
1131
+ b.append(`
1132
+ $run(function runSwitch() {`);
1133
+ let index = 0;
1134
+ addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.range, status, b);
1135
+ for (let branch of branches) buildSwitchBranch(branch, status, b, parentName, stateName, creatorsName, index++);
1136
+ b.append(`
1137
+ }
1138
+ });`);
1139
+ b.append(`
1140
+ t_run_control(${rangeName}, ${anchorName}, (t_before) => {
1141
+ t_run_branch(${rangeName}, () => ${creatorsName}[${stateName}.index](t_before));
1142
+ });`);
1143
+ b.append("");
1144
+ }
1145
+ function buildSwitchBranch(node, status, b, parentName, stateName, creatorsName, index) {
1146
+ addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.range, status, b);
1147
+ if (node.children.length > 0) {
1148
+ b.append(`${creatorsName}[${index}] = (t_before) => {`);
1149
+ buildFragment(node, status, b, parentName, "t_before");
1150
+ status.fragmentStack.push({
1151
+ fragment: node.fragment,
1152
+ path: ""
1153
+ });
1154
+ for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
1155
+ status.fragmentStack.pop();
1156
+ buildAddFragment(node, status, b, parentName, "t_before");
1157
+ b.append("};");
1158
+ } else b.append(`${creatorsName}[${index}] = (_) => {};`);
1159
+ b.append(`${stateName}.index = ${index};`);
1160
+ b.append(`
1161
+ break;
1162
+ }`);
1163
+ }
1164
+
1165
+ //#endregion
1166
+ //#region src/compile/build/client/buildControlNode.ts
1167
+ function buildControlNode(node, status, b) {
1168
+ switch (node.operation) {
1169
+ case "@if group":
1170
+ buildIfNode(node, status, b);
1171
+ break;
1172
+ case "@if":
1173
+ case "@else if":
1174
+ case "@else": break;
1175
+ case "@switch group":
1176
+ buildSwitchNode(node, status, b);
1177
+ break;
1178
+ case "@case":
1179
+ case "@default": break;
1180
+ case "@for group":
1181
+ buildForNode(node, status, b);
1182
+ break;
1183
+ case "@for":
1184
+ case "@key": break;
1185
+ case "@await group":
1186
+ buildAwaitNode(node, status, b);
1187
+ break;
1188
+ case "@await":
1189
+ case "@then":
1190
+ case "@catch": break;
1191
+ case "@replace group":
1192
+ buildReplaceNode(node, status, b);
1193
+ break;
1194
+ case "@replace": break;
1195
+ case "@html group":
1196
+ buildHtmlNode(node, status, b);
1197
+ break;
1198
+ case "@html": break;
1199
+ case "@const":
1200
+ case "@console":
1201
+ case "@debugger":
1202
+ buildScriptNode(node, status, b);
1203
+ break;
1204
+ case "@function":
1205
+ case "@async function":
1206
+ b.append("");
1207
+ buildScriptNode(node, status, b);
1208
+ b.append("");
1209
+ break;
1210
+ default: throw new Error(`Invalid operation: ${node.operation}`);
1211
+ }
1212
+ }
1213
+
1214
+ //#endregion
1215
+ //#region src/compile/build/client/buildMount.ts
1216
+ function buildMount(functionName, functionBody, status, b) {
1217
+ functionBody = replaceForVarNames(functionBody, status);
1218
+ status.imports.add("$mount");
1219
+ b.append(`$mount(function ${functionName}() {`);
1220
+ b.append(functionBody);
1221
+ b.append("});");
1222
+ }
1223
+
1224
+ //#endregion
1225
+ //#region src/compile/build/client/stashRun.ts
1226
+ function stashRun(fragment, functionStart, value, functionEnd, range, status) {
1227
+ value = replaceForVarNames(value, status);
1228
+ let functionBody = functionStart + value + functionEnd;
1229
+ fragment.effects.push({
1230
+ functionBody,
1231
+ ranges: [range],
1232
+ offsets: [functionStart.length],
1233
+ lengths: [value.length]
1234
+ });
1235
+ }
1236
+
1237
+ //#endregion
1238
+ //#region src/compile/build/client/buildElementNode.ts
1239
+ function buildElementNode(node, status, b, parentName, root = false) {
1240
+ if (status.inHead) {
1241
+ if (node.tagName === "title") buildTitleNode(node, status, b);
1242
+ else buildHeadNode(node, status, b);
1243
+ return;
1244
+ }
1245
+ const svgElement = node.tagName === "svg";
1246
+ const oldns = status.ns;
1247
+ if (svgElement) status.ns = true;
1248
+ const varName = node.varName;
1249
+ if (varName) {
1250
+ if (node.tagName === "@element") buildDynamicElementNode(node, status, b);
1251
+ if (root) {}
1252
+ buildElementAttributes$1(node, varName, status, b);
1253
+ }
1254
+ const oldPreserveWhitespace = status.preserveWhitespace;
1255
+ status.preserveWhitespace = node.tagName === "code" || node.tagName === "pre";
1256
+ for (let child of node.children) buildNode(child, status, b, parentName, "null");
1257
+ status.preserveWhitespace = oldPreserveWhitespace;
1258
+ if (svgElement) status.ns = oldns;
1259
+ }
1260
+ function buildDynamicElementNode(node, status, b) {
1261
+ let selfAttribute = node.attributes.find((a) => a.name === "self");
1262
+ if (selfAttribute && selfAttribute.value && selfAttribute.fullyReactive) {
1263
+ status.imports.add("$run");
1264
+ status.imports.add("t_dynamic");
1265
+ let selfValue = selfAttribute.value;
1266
+ b.append(`$run(function setDynamic() {`);
1267
+ b.append(`${node.varName} = t_dynamic(${node.varName}, ${selfValue});`);
1268
+ let parentName = node.varName;
1269
+ buildFragment(node, status, b, parentName, "null");
1270
+ status.fragmentStack.push({
1271
+ fragment: node.fragment,
1272
+ path: ""
1273
+ });
1274
+ for (let child of node.children) buildNode(child, status, b, parentName, "null");
1275
+ status.fragmentStack.pop();
1276
+ buildAddFragment(node, status, b, parentName, "null");
1277
+ b.append(`});`);
1278
+ }
1279
+ }
1280
+ function buildTitleNode(node, status, b) {
1281
+ let content = node.children[0].content || "";
1282
+ content = content.replace(/\s+/g, " ");
1283
+ let reactiveStarted = false;
1284
+ let reactiveCount = 0;
1285
+ for (let i = 0; i < content.length; i++) if (content[i] === "{") reactiveStarted = true;
1286
+ else if (content[i] === "}") {
1287
+ if (reactiveStarted) {
1288
+ reactiveCount += 1;
1289
+ reactiveStarted = false;
1290
+ }
1291
+ }
1292
+ if (reactiveCount) {
1293
+ status.imports.add("t_fmt");
1294
+ if (reactiveCount === 1 && content.startsWith("{") && content.endsWith("}")) content = `t_fmt(${content.substring(1, content.length - 1)})`;
1295
+ else content = `\`${content.replaceAll("{", "${t_fmt(").replaceAll("}", ")}")}\``;
1296
+ } else content = `"${content}"`;
1297
+ status.imports.add("$run");
1298
+ b.append(`
1299
+ $run(function runTitle() {
1300
+ const t_old_title = document.title;
1301
+ document.title = ${content};
1302
+ return () => document.title = t_old_title;
1303
+ });`);
1304
+ }
1305
+ function buildHeadNode(node, status, b) {
1306
+ status.imports.add("$run");
1307
+ b.append(`
1308
+ $run(function runHead() {
1309
+ const t_headel = document.createElement("${node.tagName}");
1310
+ document.getElementsByTagName("head")[0].appendChild(t_headel);`);
1311
+ for (let { name, value } of node.attributes) if (value != null) {
1312
+ status.imports.add("t_attribute");
1313
+ b.append(`t_attribute(t_headel, "${name}", ${value});`);
1314
+ }
1315
+ b.append(`
1316
+ });`);
1317
+ }
1318
+ function buildElementAttributes$1(node, varName, status, b) {
1319
+ let fragment = status.fragmentStack.at(-1)?.fragment;
1320
+ if (!fragment) throw new Error("No fragment on stack");
1321
+ const refAttribute = node.attributes.find((a) => a.name === "&ref");
1322
+ if (refAttribute) {
1323
+ let { value, fullyReactive } = refAttribute;
1324
+ if (value != null && fullyReactive) b.append(`${value} = ${varName};`);
1325
+ }
1326
+ for (let { name, value, reactive, range } of node.attributes) if (name === "self" && node.tagName === "@element") {} else if (name === "&ref") {} else if (value != null && reactive) if (name === "&group") buildBindGroupAttribute(node, varName, value, status, b);
1327
+ else if (name === "&value" || name === "&checked") buildBindAttribute(node, varName, name, value, status, b);
1328
+ else if (name === "onmount") buildMount("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
1329
+ else if (name.startsWith("on")) buildEventAttribute(varName, name, value, range, status, b);
1330
+ else if (name.startsWith("transition")) buildTransitionAttribute(node, varName, name, value, status, b);
1331
+ else if (name === "class") {
1332
+ status.imports.add("t_class");
1333
+ const params = [value];
1334
+ if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
1335
+ const propName = status.ns ? "className.baseVal" : "className";
1336
+ stashRun(fragment, `${varName}.${propName} = t_class(`, params.join(", "), ");", range, status);
1337
+ } else if (name === "style") {
1338
+ status.imports.add("t_style");
1339
+ stashRun(fragment, `${varName}.setAttribute("style", t_style(`, value, "));", range, status);
1340
+ } else if (name.includes("-")) {
1341
+ status.imports.add("t_attribute");
1342
+ stashRun(fragment, `t_attribute(${varName}, "${name}", `, value, ");", range, status);
1343
+ } else {
1344
+ status.imports.add("t_attribute");
1345
+ stashRun(fragment, `t_attribute(${varName}, "${name}", `, value, ");", range, status);
1346
+ }
1347
+ }
1348
+ function buildBindGroupAttribute(node, varName, value, status, b) {
1349
+ value = replaceForVarNames(value, status);
1350
+ let eventName = "change";
1351
+ let inputValue = node.attributes.find((a) => a.name === "value")?.value;
1352
+ let set = `${value} == ${inputValue}`;
1353
+ let propName = "checked";
1354
+ const setAttribute = `${varName}.${propName} = ${set}`;
1355
+ buildRun("setBinding", `${setAttribute};`, status, b);
1356
+ status.imports.add("t_event");
1357
+ b.append(`t_event(${varName}, "${eventName}", (e) => {
1358
+ if (e.target.${propName}) ${value} = ${inputValue};
1359
+ });`);
1360
+ }
1361
+ function buildBindAttribute(node, varName, name, value, status, b) {
1362
+ value = replaceForVarNames(value, status);
1363
+ let eventName = "input";
1364
+ let defaultValue = "\"\"";
1365
+ let inputValue = "e.target.value";
1366
+ if (node.tagName === "input") {
1367
+ let typeAttribute = node.attributes.find((a) => a.name === "type");
1368
+ if (typeAttribute && typeAttribute.value) switch (trimQuotes(typeAttribute.value)) {
1369
+ case "number":
1370
+ defaultValue = "0";
1371
+ inputValue = "Number(e.target.value)";
1372
+ break;
1373
+ case "checkbox":
1374
+ defaultValue = "false";
1375
+ inputValue = "e.target.checked";
1376
+ break;
1377
+ case "radio":
1378
+ eventName = "change";
1379
+ inputValue = "e.target.value";
1380
+ break;
1381
+ }
1382
+ } else if (node.tagName === "select") eventName = "change";
1383
+ let set = `${value} || ${defaultValue}`;
1384
+ const propName = name.substring(1);
1385
+ const setAttribute = `${varName}.${propName} = ${set}`;
1386
+ buildRun("setBinding", `${setAttribute};`, status, b);
1387
+ status.imports.add("t_event");
1388
+ b.append(`t_event(${varName}, "${eventName}", (e) => ${value} = ${inputValue});`);
1389
+ }
1390
+ function buildEventAttribute(varName, name, value, range, status, b) {
1391
+ value = replaceForVarNames(value, status);
1392
+ const eventName = name.substring(2);
1393
+ status.imports.add("t_event");
1394
+ addMappedText(`t_event(${varName}, "${eventName}", `, value, `);`, range, status, b);
1395
+ }
1396
+ function buildTransitionAttribute(node, varName, name, value, status, b) {
1397
+ value = replaceForVarNames(value, status);
1398
+ status.imports.add("t_animate");
1399
+ let entryVarName = nextVarName("trans_in", status);
1400
+ let exitVarName = nextVarName("trans_out", status);
1401
+ if (name === "transition") {
1402
+ b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
1403
+ b.append(`const ${exitVarName} = ${entryVarName};`);
1404
+ b.append(`t_animate(${varName}, ${entryVarName}, ${exitVarName});`);
1405
+ } else if (name === "transition-in") {
1406
+ let outAttribute = node.attributes.find((a) => a.name === "transition-out");
1407
+ if (outAttribute && outAttribute.value && outAttribute.fullyReactive) {
1408
+ let outValue = outAttribute.value;
1409
+ b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
1410
+ b.append(`const ${exitVarName} = ${getAnimationDetails(outValue)};`);
1411
+ b.append(`t_animate(${varName}, ${entryVarName}, ${exitVarName});`);
1412
+ } else {
1413
+ b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
1414
+ b.append(`t_animate(${varName}, ${entryVarName});`);
1415
+ }
1416
+ } else if (name === "transition-out") if (node.attributes.find((a) => a.name === "transition-in")) return;
1417
+ else {
1418
+ b.append(`const ${exitVarName} = ${getAnimationDetails(value)};`);
1419
+ b.append(`t_animate(${varName}, null, ${entryVarName});`);
1420
+ }
1421
+ }
1422
+ function getAnimationDetails(value) {
1423
+ let parts = [];
1424
+ let start = 0;
1425
+ let squareCount = 0;
1426
+ let curlyCount = 0;
1427
+ for (let i = 0; i < value.length; i++) switch (value[i]) {
1428
+ case ",":
1429
+ if (squareCount === 0 && curlyCount === 0) {
1430
+ parts.push(value.substring(start, i));
1431
+ start = i + 1;
1432
+ }
1433
+ break;
1434
+ case "[":
1435
+ squareCount += 1;
1436
+ break;
1437
+ case "]":
1438
+ squareCount -= 1;
1439
+ break;
1440
+ case "{":
1441
+ curlyCount += 1;
1442
+ break;
1443
+ case "}":
1444
+ curlyCount -= 1;
1445
+ break;
1446
+ }
1447
+ parts.push(value.substring(start));
1448
+ let keyframes = parts[0]?.trim();
1449
+ let options = parts[1]?.trim();
1450
+ return `{ ${[`keyframes: ${keyframes}`, options ? `options: ${options}` : null].filter(Boolean).join(", ")} }`;
1451
+ }
1452
+
1453
+ //#endregion
1454
+ //#region src/compile/build/client/buildRootNode.ts
1455
+ function buildRootNode(node, status, b, parentName, anchorName) {
1456
+ buildFragment(node, status, b, parentName, anchorName);
1457
+ status.fragmentStack.push({
1458
+ fragment: node.fragment,
1459
+ path: "0:ch/"
1460
+ });
1461
+ for (let child of node.children) buildNode(child, status, b, parentName, anchorName, true);
1462
+ status.fragmentStack.pop();
1463
+ buildAddFragment(node, status, b, parentName, anchorName);
1464
+ }
1465
+
1466
+ //#endregion
1467
+ //#region src/compile/build/client/buildSlotNode.ts
1468
+ function buildSlotNode(node, status, b) {
1469
+ let slotName = node.attributes.find((a) => a.name === "name")?.value;
1470
+ slotName = slotName ? trimQuotes(slotName) : "_";
1471
+ const propsName = nextVarName("sprops", status);
1472
+ const slotAttributes = node.attributes.filter((a) => a.name !== "name");
1473
+ const slotHasProps = slotAttributes.length;
1474
+ if (slotHasProps) {
1475
+ status.imports.add("$watch");
1476
+ b.append(`const ${propsName} = $watch({});`);
1477
+ for (let { name, value, reactive } of slotAttributes) if (value != null) {
1478
+ const setProp = `${propsName}["${name}"] = ${value}`;
1479
+ if (reactive) buildRun("setProp", `${setProp};`, status, b);
1480
+ else b.append(`${setProp};`);
1481
+ } else b.append(`${propsName}["${name}"] = true;`);
1482
+ }
1483
+ const slotParentName = node.parentName;
1484
+ const slotAnchorName = node.varName;
1485
+ b.append(`if ($slots && $slots["${slotName}"]) {`);
1486
+ let params = [
1487
+ slotParentName,
1488
+ slotAnchorName,
1489
+ slotHasProps ? propsName : "undefined",
1490
+ "$context"
1491
+ ];
1492
+ b.append(`$slots["${slotName}"](${params.join(", ")})`);
1493
+ const fill = node.children.find((c) => isSpecialNode(c) && c.tagName === "fill");
1494
+ if (fill && isSpecialNode(fill) && fill.children.length) {
1495
+ b.append(`} else {`);
1496
+ buildFragment(fill, status, b, slotParentName, slotAnchorName);
1497
+ status.fragmentStack.push({
1498
+ fragment: fill.fragment,
1499
+ path: "0:ch/"
1500
+ });
1501
+ for (let child of fill.children) buildNode(child, status, b, slotParentName, slotAnchorName);
1502
+ status.fragmentStack.pop();
1503
+ buildAddFragment(fill, status, b, slotParentName, slotAnchorName);
1504
+ }
1505
+ b.append(`}`);
1506
+ }
1507
+
1508
+ //#endregion
1509
+ //#region src/compile/build/client/buildSpecialNode.ts
1510
+ function buildSpecialNode(node, status, b, parentName, root = false) {
1511
+ switch (node.tagName) {
1512
+ case "slot":
1513
+ buildSlotNode(node, status, b);
1514
+ break;
1515
+ case "fill": break;
1516
+ case "@element":
1517
+ buildElementNode(node, status, b, parentName, root);
1518
+ break;
1519
+ case "@component":
1520
+ buildComponentNode(node, status, b, root);
1521
+ break;
1522
+ default: throw new Error(`Invalid special node: ${node.tagName}`);
1523
+ }
1524
+ return "";
1525
+ }
1526
+
1527
+ //#endregion
1528
+ //#region src/compile/utils/endOfString.ts
1529
+ function endOfString(char, content, start) {
1530
+ for (let j = start + 1; j < content.length; j++) if (content[j] === char && content[j - 1] !== "\\") return j;
1531
+ return content.length;
1532
+ }
1533
+
1534
+ //#endregion
1535
+ //#region src/compile/build/client/stashRunWithOffsets.ts
1536
+ function stashRunWithOffsets(fragment, functionBody, ranges, offsets, lengths, status) {
1537
+ for (let i = 0; i < offsets.length; i++) {
1538
+ const oldLength = functionBody.length;
1539
+ functionBody = functionBody.substring(0, offsets[i]) + replaceForVarNames(functionBody.substring(offsets[i], offsets[i] + lengths[i]), status) + functionBody.substring(offsets[i] + lengths[i]);
1540
+ const changedLength = functionBody.length - oldLength;
1541
+ lengths[i] += changedLength;
1542
+ for (let j = i + 1; j < offsets.length; j++) offsets[j] += changedLength;
1543
+ }
1544
+ fragment.effects.push({
1545
+ functionBody,
1546
+ ranges,
1547
+ offsets,
1548
+ lengths
1549
+ });
1550
+ }
1551
+
1552
+ //#endregion
1553
+ //#region src/compile/build/client/buildTextNode.ts
1554
+ function buildTextNode(node, status) {
1555
+ let fragment = status.fragmentStack.at(-1)?.fragment;
1556
+ if (!fragment) return;
1557
+ let content = node.content || "";
1558
+ if (!status.preserveWhitespace) content = content.replaceAll(/\s+/g, " ");
1559
+ let textContent = "";
1560
+ let reactiveCount = 0;
1561
+ let reactiveStart = 0;
1562
+ let offsets = [];
1563
+ let lengths = [];
1564
+ let level = 0;
1565
+ let maxLevel = 0;
1566
+ for (let i = 0; i < content.length; i++) {
1567
+ const char = content[i];
1568
+ const nextChar = content[i + 1];
1569
+ if (char === "{") {
1570
+ level++;
1571
+ maxLevel = Math.max(level, maxLevel);
1572
+ if (level === 1) {
1573
+ reactiveCount += 1;
1574
+ textContent += "${t_fmt(";
1575
+ reactiveStart = textContent.length;
1576
+ offsets.push(reactiveStart);
1577
+ continue;
1578
+ }
1579
+ } else if (char === "}") {
1580
+ level--;
1581
+ if (level === 0) {
1582
+ lengths.push(textContent.length - reactiveStart);
1583
+ textContent += ")";
1584
+ }
1585
+ } else if (char === "`" && level === 0) textContent += "\\";
1586
+ else if (level > 0) {
1587
+ if (char === "/" && nextChar === "/") {
1588
+ let start = i;
1589
+ i = content.indexOf("\n", i);
1590
+ textContent += content.substring(start, i + 1);
1591
+ continue;
1592
+ } else if (char === "/" && nextChar === "*") {
1593
+ let start = i;
1594
+ i = content.indexOf("*/", i) + 1;
1595
+ textContent += content.substring(start, i + 1);
1596
+ continue;
1597
+ } else if (char === "\"" || char === "'") {
1598
+ let start = i;
1599
+ i = endOfString(char, content, i);
1600
+ textContent += content.substring(start, i + 1);
1601
+ continue;
1602
+ } else if (char === "`") {
1603
+ let start = i;
1604
+ i = endOfTemplateString(content, i);
1605
+ textContent += content.substring(start, i + 1);
1606
+ continue;
1607
+ }
1608
+ }
1609
+ textContent += content[i];
1610
+ }
1611
+ if (maxLevel) {
1612
+ let offsetChange = 0;
1613
+ if (reactiveCount === 1 && content.startsWith("{") && content.endsWith("}")) {
1614
+ textContent = textContent.substring(2, textContent.length - 1);
1615
+ offsetChange = -2;
1616
+ } else {
1617
+ textContent = `\`${textContent}\``;
1618
+ offsetChange = 1;
1619
+ }
1620
+ status.imports.add("t_fmt");
1621
+ let functionBody = `${node.varName}.textContent = `;
1622
+ offsetChange += functionBody.length;
1623
+ offsets.map((_, i) => offsets[i] += offsetChange);
1624
+ functionBody += `${textContent};`;
1625
+ stashRunWithOffsets(fragment, functionBody, node.ranges, offsets, lengths, status);
1626
+ }
1627
+ }
1628
+
1629
+ //#endregion
1630
+ //#region src/compile/build/client/buildNode.ts
1631
+ function buildNode(node, status, b, parentName, anchorName, root = false) {
1632
+ if (node.handled) {
1633
+ node.handled = false;
1634
+ return;
1635
+ }
1636
+ switch (node.type) {
1637
+ case "root":
1638
+ buildRootNode(node, status, b, parentName, anchorName);
1639
+ break;
1640
+ case "control":
1641
+ buildControlNode(node, status, b);
1642
+ break;
1643
+ case "component":
1644
+ buildComponentNode(node, status, b, root);
1645
+ break;
1646
+ case "element":
1647
+ buildElementNode(node, status, b, parentName, root);
1648
+ break;
1649
+ case "text":
1650
+ buildTextNode(node, status);
1651
+ break;
1652
+ case "special":
1653
+ buildSpecialNode(node, status, b, parentName, root);
1654
+ break;
1655
+ default: throw new Error(`Invalid node type: ${node.type}`);
1656
+ }
1657
+ }
1658
+
1659
+ //#endregion
1660
+ //#region src/compile/build/client/buildCode.ts
1661
+ const importsMap$1 = {
1662
+ $watch: "import { $watch } from \"${folder}\";",
1663
+ $cache: "import { $cache } from \"${folder}\";",
1664
+ $run: "import { $run } from \"${folder}\";",
1665
+ $mount: "import { $mount } from \"${folder}\";",
1666
+ $unwrap: "import { $unwrap } from \"${folder}\";",
1667
+ $peek: "import { $peek } from \"${folder}\";",
1668
+ $batch: "import { $batch } from \"${folder}\";",
1669
+ t_range: "import { t_range } from \"${folder}\";",
1670
+ t_push_range: "import { t_push_range } from \"${folder}\";",
1671
+ t_pop_range: "import { t_pop_range } from \"${folder}\";",
1672
+ t_run_control: "import { t_run_control } from \"${folder}\";",
1673
+ t_run_branch: "import { t_run_branch } from \"${folder}\";",
1674
+ t_list_item: "import { t_list_item } from \"${folder}\";",
1675
+ t_run_list: "import { t_run_list } from \"${folder}\";",
1676
+ t_add_fragment: "import { t_add_fragment } from \"${folder}\";",
1677
+ t_apply_props: "import { t_apply_props } from \"${folder}\";",
1678
+ t_class: "import { t_class } from \"${folder}\";",
1679
+ t_style: "import { t_style } from \"${folder}\";",
1680
+ t_attribute: "import { t_attribute } from \"${folder}\";",
1681
+ t_dynamic: "import { t_dynamic } from \"${folder}\";",
1682
+ t_fmt: "import { t_fmt } from \"${folder}\";",
1683
+ t_fragment: "import { t_fragment } from \"${folder}\";",
1684
+ t_event: "import { t_event } from \"${folder}\";",
1685
+ t_animate: "import { t_animate } from \"${folder}\";",
1686
+ t_root: "import { t_root } from \"${folder}\";",
1687
+ t_anchor: "import { t_anchor } from \"${folder}\";",
1688
+ t_child: "import { t_child } from \"${folder}\";",
1689
+ t_next: "import { t_next } from \"${folder}\";",
1690
+ t_skip: "import { t_skip } from \"${folder}\";",
1691
+ t_frg: "import { t_frg } from \"${folder}\";",
1692
+ t_elm: "import { t_elm } from \"${folder}\";",
1693
+ t_txt: "import { t_txt } from \"${folder}\";",
1694
+ t_cmt: "import { t_cmt } from \"${folder}\";",
1695
+ t_print: "import { t_print } from \"${folder}\";",
1696
+ ListItem: "import { type ListItem } from \"${folder}\";",
1697
+ SlotRender: "import { type SlotRender } from \"${folder}\";"
1698
+ };
1699
+ function buildCode(template, map, options) {
1700
+ let b = new Builder(options?.mapped);
1701
+ let imports = /* @__PURE__ */ new Set();
1702
+ imports.add("SlotRender");
1703
+ buildTemplate(template, map, imports, b, options);
1704
+ let startSize = b.toString().length;
1705
+ if (imports.size) {
1706
+ b.prepend("");
1707
+ for (let imp of Array.from(imports).sort().reverse()) {
1708
+ imp = importsMap$1[imp] || imp;
1709
+ b.prepend(imp.replace("${folder}", options?.renderFolder || "@torpor/view"));
1710
+ }
1711
+ }
1712
+ if (options?.mapped) {
1713
+ let diff = b.toString().length - startSize + 1;
1714
+ for (let m of map) {
1715
+ m.compiled.start += diff;
1716
+ m.compiled.end += diff;
1717
+ }
1718
+ }
1719
+ return b.toString();
1720
+ }
1721
+ function buildTemplate(template, map, imports, b, options) {
1722
+ let script = template.script.map((s) => s.script).join("\n");
1723
+ if (/\$watch\b/.test(script)) imports.add("$watch");
1724
+ if (/\$cache\b/.test(script)) imports.add("$cache");
1725
+ if (/\$run\b/.test(script)) imports.add("$run");
1726
+ if (/\$mount\b/.test(script)) imports.add("$mount");
1727
+ if (/\$unwrap\b/.test(script)) imports.add("$unwrap");
1728
+ imports.add("$peek");
1729
+ if (/\$batch\b/.test(script)) imports.add("$batch");
1730
+ let currentIndex = 0;
1731
+ let current = template.components[0];
1732
+ for (let chunk of template.script) if (chunk.script === "/* @params */") {
1733
+ let params = [
1734
+ `${current.markup ? "$parent" : "_$parent"}: ParentNode`,
1735
+ `${current.markup ? "$anchor" : "_$anchor"}: Node | null`,
1736
+ current.params ?? `${current.props?.length ? "$props: Record<PropertyKey, any>" : "_$props: Record<PropertyKey, any> | undefined"}`,
1737
+ `${current.contextProps?.length || current.needsContext ? "$context" : "_$context"}: Record<PropertyKey, any>`,
1738
+ `${current.slotProps?.length ? "$slots" : "_$slots"}?: Record<string, SlotRender>`
1739
+ ];
1740
+ b.append(params.join(",\n"));
1741
+ } else if (chunk.script === ") /* @return_type */ {") b.append("): void {");
1742
+ else if (chunk.script === "/* @start */") {
1743
+ if (current.contextProps?.length) b.append(`$context = Object.assign({}, $context);`);
1744
+ b.append("$peek(() => { /**/");
1745
+ b.append("");
1746
+ } else if (chunk.script === "/* @render */") {
1747
+ if (current.markup) {
1748
+ let status = makeStatus(imports, map, current, options);
1749
+ b.append("");
1750
+ b.append("/* User interface */");
1751
+ buildFragmentText(current.markup, status, b);
1752
+ b.append("");
1753
+ buildNode(current.markup, status, b, "$parent", "$anchor", true);
1754
+ }
1755
+ } else if (chunk.script === "/* @head */") {
1756
+ if (current.head) {
1757
+ let status = makeStatus(imports, map, current, options);
1758
+ b.append("");
1759
+ b.append("/* Head */");
1760
+ status.inHead = true;
1761
+ buildNode(current.head, status, b, "$parent", "$anchor", true);
1762
+ status.inHead = false;
1763
+ }
1764
+ } else if (chunk.script === "/* @style */") {} else if (chunk.script === "/* @end */") {
1765
+ b.append("/**/ });");
1766
+ currentIndex += 1;
1767
+ current = template.components[currentIndex];
1768
+ } else {
1769
+ let status = makeStatus(imports, map, current, options);
1770
+ addMappedText("", chunk.script, "", chunk.range, status, b);
1771
+ }
1772
+ }
1773
+ function makeStatus(imports, map, current, options) {
1774
+ return {
1775
+ imports,
1776
+ props: current?.props ?? [],
1777
+ contextProps: current?.contextProps ?? [],
1778
+ slotProps: current?.slotProps ?? [],
1779
+ styleHash: current?.style?.hash ?? "",
1780
+ map,
1781
+ varNames: {},
1782
+ fragmentStack: [],
1783
+ forVarNames: [],
1784
+ ns: false,
1785
+ preserveWhitespace: false,
1786
+ options
1787
+ };
1788
+ }
1789
+
1790
+ //#endregion
1791
+ //#region src/compile/build/client/buildStyles.ts
1792
+ function buildStyles(style, styleHash) {
1793
+ const b = new Builder();
1794
+ for (let block of style.blocks) buildStyleBlock(block, b, styleHash);
1795
+ return b.toString();
1796
+ }
1797
+ function buildStyleBlock(block, b, styleHash) {
1798
+ if (block.selector.startsWith("@")) b.append(`${block.selector} {`);
1799
+ else {
1800
+ block.selector = block.selector.replaceAll(/\s+/g, " ");
1801
+ let selectors = [];
1802
+ let global = false;
1803
+ let start = 0;
1804
+ for (let i = 0; i <= block.selector.length; i++) if (block.selector.substring(i).startsWith(":global(")) {
1805
+ i += 7;
1806
+ start = i + 1;
1807
+ global = true;
1808
+ } else if (global && block.selector[i] === ")") {
1809
+ addSelector(selectors, block.selector, styleHash, start, i, global);
1810
+ start = i + 1;
1811
+ global = false;
1812
+ } else if ("*,>+~".includes(block.selector[i])) {
1813
+ addSelector(selectors, block.selector, styleHash, start, i, global);
1814
+ selectors.push(block.selector[i]);
1815
+ start = i + 1;
1816
+ } else if (i === block.selector.length) addSelector(selectors, block.selector, styleHash, start, i, global);
1817
+ else if (block.selector[i] === " ") {
1818
+ addSelector(selectors, block.selector, styleHash, start, i, global);
1819
+ start = i + 1;
1820
+ }
1821
+ b.append(`${selectors.join(" ").replaceAll(" ,", ",")} {`);
1822
+ }
1823
+ for (let attribute of block.attributes) buildStyleAttribute(attribute, b);
1824
+ for (let child of block.children) buildStyleBlock(child, b, styleHash);
1825
+ b.append(`}`);
1826
+ }
1827
+ function addSelector(selectors, selector, styleHash, start, end, global) {
1828
+ if (end > start) {
1829
+ let s = selector.substring(start, end);
1830
+ if (!global) {
1831
+ let pre = s;
1832
+ let post = "";
1833
+ let colonPosition = s.indexOf(":");
1834
+ if (colonPosition !== -1) {
1835
+ pre = s.substring(0, colonPosition);
1836
+ post = s.substring(colonPosition);
1837
+ }
1838
+ s = `${pre}.torp-${styleHash}${post}`;
1839
+ }
1840
+ selectors.push(s);
1841
+ }
1842
+ }
1843
+ function buildStyleAttribute(attribute, b) {
1844
+ b.append(`${attribute.name}: ${attribute.value};`);
1845
+ }
1846
+
1847
+ //#endregion
1848
+ //#region src/compile/build/server/buildServerComponentNode.ts
1849
+ function buildServerComponentNode(node, status, b) {
1850
+ status.output += HYDRATION_START_COMMENT;
1851
+ if (status.output) {
1852
+ b.append(`t_body += \`${status.output}\`;`);
1853
+ status.output = "";
1854
+ }
1855
+ const componentHasProps = node.attributes.length;
1856
+ const propsName = componentHasProps ? nextVarName("props", status) : "undefined";
1857
+ if (componentHasProps) {
1858
+ b.append(`const ${propsName}: any = {};`);
1859
+ for (let { name, value } of node.attributes) if (name === "class" && value != null) {
1860
+ status.imports.add("t_class");
1861
+ const params = [value];
1862
+ if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
1863
+ b.append(`${propsName}["class"] = t_class(${params.join(", ")});`);
1864
+ } else if (name === "style" && value != null) {
1865
+ status.imports.add("t_style");
1866
+ b.append(`${propsName}["style"] = t_style(${value});`);
1867
+ } else if (value != null) b.append(`${propsName}["${name}"] = ${value};`);
1868
+ else b.append(`${propsName}["${name}"] = true;`);
1869
+ }
1870
+ const componentHasSlots = node.children.length;
1871
+ const slotsName = componentHasSlots ? nextVarName("slots", status) : "undefined";
1872
+ if (componentHasSlots) {
1873
+ b.append(`const ${slotsName}: Record<string, ServerSlotRender> = {};`);
1874
+ for (let slot of node.children) if (isSpecialNode(slot) && slot.tagName === "fill") {
1875
+ const nameAttribute = slot.attributes.find((a) => a.name === "name");
1876
+ const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
1877
+ const slotParams = [`${slot.hasSlotProps ? "$sprops" : "_$sprops?"}: Record<PropertyKey, any>`, "// @ts-ignore\n$context?: Record<PropertyKey, any>"];
1878
+ b.append(`${slotsName}["${slotName}"] = (\n${slotParams.join(",\n")}\n) => {`);
1879
+ b.append(`let t_body = "";`);
1880
+ for (let child of slot.children) buildServerNode(child, status, b);
1881
+ if (status.output) {
1882
+ b.append(`t_body += \`${status.output}\`;`);
1883
+ status.output = "";
1884
+ }
1885
+ b.append("return t_body;");
1886
+ b.append(`}`);
1887
+ }
1888
+ }
1889
+ let componentName = node.tagName;
1890
+ if (componentName === "@component") {
1891
+ let selfAttribute = node.attributes.find((a) => a.name === "self");
1892
+ if (selfAttribute && selfAttribute.value && selfAttribute.fullyReactive) componentName = selfAttribute.value;
1893
+ }
1894
+ let renderParams = `${propsName}, $context`;
1895
+ if (slotsName !== "undefined") renderParams += `, ${slotsName}`;
1896
+ b.append("");
1897
+ const componentResult = nextVarName("comp", status);
1898
+ b.append(`const ${componentResult} = ${componentName}(${renderParams});`);
1899
+ b.append(`t_body += ${componentResult}.body;`);
1900
+ b.append(`t_head += ${componentResult}.head;`);
1901
+ status.output += HYDRATION_END_COMMENT;
1902
+ status.output += ANCHOR_COMMENT;
1903
+ }
1904
+
1905
+ //#endregion
1906
+ //#region src/compile/build/server/buildServerAwaitNode.ts
1907
+ function buildServerAwaitNode(node, status, b) {
1908
+ status.output += HYDRATION_START_COMMENT;
1909
+ if (status.output) {
1910
+ b.append(`t_body += \`${status.output}\`;`);
1911
+ status.output = "";
1912
+ }
1913
+ for (let branch of node.children) if (isControlNode(branch) && branch.operation === "@await") buildServerAwaitBranch(branch, status, b);
1914
+ status.output += HYDRATION_END_COMMENT;
1915
+ status.output += ANCHOR_COMMENT;
1916
+ }
1917
+ function buildServerAwaitBranch(node, status, b) {
1918
+ for (let child of node.children) buildServerNode(child, status, b);
1919
+ if (status.output) {
1920
+ b.append(`t_body += \`${status.output}\`;`);
1921
+ status.output = "";
1922
+ }
1923
+ }
1924
+
1925
+ //#endregion
1926
+ //#region src/compile/build/server/buildServerForNode.ts
1927
+ function buildServerForNode(node, status, b) {
1928
+ status.output += HYDRATION_START_COMMENT;
1929
+ if (status.output) {
1930
+ b.append(`t_body += \`${status.output}\`;`);
1931
+ status.output = "";
1932
+ }
1933
+ for (let branch of node.children) if (isControlNode(branch)) buildServerForBranch(branch, status, b);
1934
+ status.output += HYDRATION_END_COMMENT;
1935
+ status.output += ANCHOR_COMMENT;
1936
+ }
1937
+ function buildServerForBranch(node, status, b) {
1938
+ b.append(`${node.statement} {`);
1939
+ status.output += HYDRATION_BREAK_COMMENT;
1940
+ for (let child of node.children) buildServerNode(child, status, b);
1941
+ if (status.output) {
1942
+ b.append(`t_body += \`${status.output}\`;`);
1943
+ status.output = "";
1944
+ }
1945
+ b.append("}");
1946
+ }
1947
+
1948
+ //#endregion
1949
+ //#region src/compile/build/server/buildServerHtmlNode.ts
1950
+ function buildServerHtmlNode(node, status) {
1951
+ status.output += HYDRATION_START_COMMENT;
1952
+ for (let branch of node.children) if (isControlNode(branch)) status.output += `\${${branch.statement}}`;
1953
+ status.output += HYDRATION_END_COMMENT;
1954
+ status.output += ANCHOR_COMMENT;
1955
+ }
1956
+
1957
+ //#endregion
1958
+ //#region src/compile/build/server/buildServerIfNode.ts
1959
+ function buildServerIfNode(node, status, b) {
1960
+ status.output += HYDRATION_START_COMMENT;
1961
+ if (status.output) {
1962
+ b.append(`t_body += \`${status.output}\`;`);
1963
+ status.output = "";
1964
+ }
1965
+ for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b);
1966
+ status.output += HYDRATION_END_COMMENT;
1967
+ status.output += ANCHOR_COMMENT;
1968
+ }
1969
+ function buildServerIfBranch(node, status, b) {
1970
+ b.append(`${node.statement} {`);
1971
+ status.output += HYDRATION_BREAK_COMMENT;
1972
+ for (let child of node.children) buildServerNode(child, status, b);
1973
+ if (status.output) {
1974
+ b.append(`t_body += \`${status.output}\`;`);
1975
+ status.output = "";
1976
+ }
1977
+ b.append("}");
1978
+ }
1979
+
1980
+ //#endregion
1981
+ //#region src/compile/build/server/buildServerReplaceNode.ts
1982
+ function buildServerReplaceNode(node, status, b) {
1983
+ status.output += HYDRATION_START_COMMENT;
1984
+ if (status.output) {
1985
+ b.append(`t_body += \`${status.output}\`;`);
1986
+ status.output = "";
1987
+ }
1988
+ for (let branch of node.children) if (isControlNode(branch)) buildServerReplaceBranch(branch, status, b);
1989
+ status.output += HYDRATION_END_COMMENT;
1990
+ status.output += ANCHOR_COMMENT;
1991
+ }
1992
+ function buildServerReplaceBranch(node, status, b) {
1993
+ b.append(`${node.statement};`);
1994
+ for (let child of node.children) buildServerNode(child, status, b);
1995
+ if (status.output) {
1996
+ b.append(`t_body += \`${status.output}\`;`);
1997
+ status.output = "";
1998
+ }
1999
+ }
2000
+
2001
+ //#endregion
2002
+ //#region src/compile/build/server/buildServerScriptNode.ts
2003
+ function buildServerScriptNode(node, b) {
2004
+ b.append(`${maybeAppend(node.statement, ";")}`);
2005
+ }
2006
+ function maybeAppend(text, end) {
2007
+ if (!text.endsWith(end)) text += end;
2008
+ return text;
2009
+ }
2010
+
2011
+ //#endregion
2012
+ //#region src/compile/build/server/buildServerSwitchNode.ts
2013
+ function buildServerSwitchNode(node, status, b) {
2014
+ status.output += HYDRATION_START_COMMENT;
2015
+ if (status.output) {
2016
+ b.append(`t_body += \`${status.output}\`;`);
2017
+ status.output = "";
2018
+ }
2019
+ b.append(`${node.statement} {`);
2020
+ for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b);
2021
+ b.append("}");
2022
+ status.output += HYDRATION_END_COMMENT;
2023
+ status.output += ANCHOR_COMMENT;
2024
+ }
2025
+ function buildServerSwitchBranch(node, status, b) {
2026
+ b.append(`${node.statement} {`);
2027
+ status.output += HYDRATION_BREAK_COMMENT;
2028
+ for (let child of node.children) buildServerNode(child, status, b);
2029
+ if (status.output) {
2030
+ b.append(`t_body += \`${status.output}\`;`);
2031
+ status.output = "";
2032
+ }
2033
+ b.append("break;");
2034
+ b.append("}");
2035
+ }
2036
+
2037
+ //#endregion
2038
+ //#region src/compile/build/server/buildServerControlNode.ts
2039
+ function buildServerControlNode(node, status, b) {
2040
+ switch (node.operation) {
2041
+ case "@if group":
2042
+ buildServerIfNode(node, status, b);
2043
+ break;
2044
+ case "@if":
2045
+ case "@else if":
2046
+ case "@else": break;
2047
+ case "@switch group":
2048
+ buildServerSwitchNode(node, status, b);
2049
+ break;
2050
+ case "@case":
2051
+ case "@default": break;
2052
+ case "@for group":
2053
+ buildServerForNode(node, status, b);
2054
+ break;
2055
+ case "@for":
2056
+ case "@key": break;
2057
+ case "@await group":
2058
+ buildServerAwaitNode(node, status, b);
2059
+ break;
2060
+ case "@await":
2061
+ case "@then":
2062
+ case "@catch": break;
2063
+ case "@replace group":
2064
+ buildServerReplaceNode(node, status, b);
2065
+ break;
2066
+ case "@replace": break;
2067
+ case "@html group":
2068
+ buildServerHtmlNode(node, status);
2069
+ break;
2070
+ case "@html": break;
2071
+ case "@const":
2072
+ if (status.output) {
2073
+ b.append(`t_body += \`${status.output}\`;`);
2074
+ status.output = "";
2075
+ }
2076
+ buildServerScriptNode(node, b);
2077
+ break;
2078
+ case "@function":
2079
+ case "@async function":
2080
+ if (status.output) {
2081
+ b.append(`t_body += \`${status.output}\`;`);
2082
+ status.output = "";
2083
+ }
2084
+ b.append("");
2085
+ buildServerScriptNode(node, b);
2086
+ b.append("");
2087
+ break;
2088
+ case "@console":
2089
+ case "@debugger": break;
2090
+ default: throw new Error(`Invalid operation: ${node.operation}`);
2091
+ }
2092
+ }
2093
+
2094
+ //#endregion
2095
+ //#region src/compile/utils/voidTags.ts
2096
+ const voidTags = [
2097
+ "area",
2098
+ "base",
2099
+ "br",
2100
+ "col",
2101
+ "embed",
2102
+ "hr",
2103
+ "img",
2104
+ "input",
2105
+ "link",
2106
+ "meta",
2107
+ "param",
2108
+ "source",
2109
+ "track",
2110
+ "wbr"
2111
+ ];
2112
+ var voidTags_default = voidTags;
2113
+
2114
+ //#endregion
2115
+ //#region src/compile/build/server/buildServerElementNode.ts
2116
+ function buildServerElementNode(node, status, b) {
2117
+ let attributes = buildElementAttributes(node, status);
2118
+ if (attributes.length) attributes = " " + attributes;
2119
+ let tagName = node.tagName;
2120
+ if (tagName === "@element") {
2121
+ let selfAttribute = node.attributes.find((a) => a.name === "self");
2122
+ if (selfAttribute) tagName = `$\{${selfAttribute.value}}`;
2123
+ }
2124
+ status.output += `<${tagName}${attributes}>`;
2125
+ if (!voidTags_default.includes(tagName)) {
2126
+ const oldPreserveWhitespace = status.preserveWhitespace;
2127
+ status.preserveWhitespace = ["pre", "code"].includes(tagName);
2128
+ for (let child of node.children) buildServerNode(child, status, b);
2129
+ status.preserveWhitespace = oldPreserveWhitespace;
2130
+ status.output += `</${tagName}>`;
2131
+ }
2132
+ }
2133
+ function buildElementAttributes(node, status) {
2134
+ let needsClass = node.scopeStyles;
2135
+ let attributes = [];
2136
+ for (let { name, value, reactive, fullyReactive } of node.attributes) if (name === "self" && node.tagName === "@element") {} else if (name === "&ref") {} else if (name.startsWith("on") || name.startsWith(":on")) {} else if (name.startsWith("transition") && value) {
2137
+ value = value.split(",")[0].trim();
2138
+ if (value.startsWith("[")) value = value.substring(1);
2139
+ else value = value + "[0]";
2140
+ attributes.push(`style="\${Object.entries(${value}).map(([k, v]) => \`$\{k}: $\{v}\`).join("; ")}"`);
2141
+ } else if (value != null && fullyReactive) if (name === "&value" || name === "&checked" || name === "&group") {
2142
+ let defaultValue = "";
2143
+ let typeAttribute = node.attributes.find((a) => a.name === "type");
2144
+ if (typeAttribute && typeAttribute.value) switch (trimQuotes(typeAttribute.value)) {
2145
+ case "number":
2146
+ defaultValue = "0";
2147
+ break;
2148
+ case "checkbox":
2149
+ defaultValue = "false";
2150
+ break;
2151
+ }
2152
+ if (!defaultValue) {
2153
+ status.imports.add("t_attr");
2154
+ value = `t_attr(${value})`;
2155
+ defaultValue = "\"\"";
2156
+ }
2157
+ let valueOrDefault = `${value} || ${defaultValue}`;
2158
+ const propName = name.substring(1);
2159
+ attributes.push(`${propName}="\${${valueOrDefault}}"`);
2160
+ } else if (name === "class") {
2161
+ status.imports.add("t_class");
2162
+ let params = [value];
2163
+ if (node.scopeStyles) {
2164
+ params.push(`"torp-${status.styleHash}"`);
2165
+ needsClass = false;
2166
+ }
2167
+ attributes.push(`class="\${t_class(${params.join(", ")})}"`);
2168
+ } else if (name === "style") {
2169
+ status.imports.add("t_style");
2170
+ attributes.push(`style="\${t_style(${value})}"`);
2171
+ } else {
2172
+ status.imports.add("t_attr");
2173
+ attributes.push(`\${${value} ? \`${name}="\${t_attr(${value})}"\` : ''}`);
2174
+ }
2175
+ else if (value != null && reactive) {
2176
+ status.imports.add("t_attr");
2177
+ attributes.push(`${name}="${trimQuotes(value).replaceAll("${", "${t_attr(").replaceAll("}", ")}")}"`);
2178
+ } else if (name === "class" && node.scopeStyles) {
2179
+ value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
2180
+ attributes.push(`${name}="${trimQuotes(value).replaceAll("\"", "&quot;")}"`);
2181
+ needsClass = false;
2182
+ } else if (value != null) attributes.push(`${name}="${trimQuotes(value).replaceAll("\"", "&quot;")}"`);
2183
+ else attributes.push(`${name}`);
2184
+ if (needsClass) attributes.push(`class="torp-${status.styleHash}"`);
2185
+ return attributes.join(" ");
2186
+ }
2187
+
2188
+ //#endregion
2189
+ //#region src/compile/build/server/buildServerRootNode.ts
2190
+ function buildServerRootNode(node, status, b) {
2191
+ for (let child of node.children) buildServerNode(child, status, b);
2192
+ }
2193
+
2194
+ //#endregion
2195
+ //#region src/compile/build/server/buildServerSlotNode.ts
2196
+ function buildServerSlotNode(node, status, b) {
2197
+ status.output += HYDRATION_START_COMMENT;
2198
+ if (status.output) {
2199
+ b.append(`t_body += \`${status.output}\`;`);
2200
+ status.output = "";
2201
+ }
2202
+ let slotName = node.attributes.find((a) => a.name === "name")?.value;
2203
+ slotName = slotName ? trimQuotes(slotName) : "_";
2204
+ const propsName = nextVarName("sprops", status);
2205
+ const slotAttributes = node.attributes.filter((a) => a.name !== "name");
2206
+ const slotHasProps = slotAttributes.length;
2207
+ if (slotHasProps) {
2208
+ b.append(`const ${propsName}: any = {};`);
2209
+ for (let { name, value } of slotAttributes) if (value != null) b.append(`${propsName}["${name}"] = ${value};`);
2210
+ else b.append(`${propsName}["${name}"] = true;`);
2211
+ }
2212
+ b.append(`if ($slots && $slots["${slotName}"]) {`);
2213
+ b.append(`t_body += $slots["${slotName}"](${slotHasProps ? propsName : "undefined"}, $context);`);
2214
+ const fill = node.children.find((c) => isSpecialNode(c) && c.tagName === "fill");
2215
+ if (fill && isSpecialNode(fill) && fill.children.length) {
2216
+ b.append(`} else {`);
2217
+ for (let child of fill.children) buildServerNode(child, status, b);
2218
+ if (status.output) {
2219
+ b.append(`t_body += \`${status.output}\`;`);
2220
+ status.output = "";
2221
+ }
2222
+ }
2223
+ b.append(`}`);
2224
+ status.output += HYDRATION_END_COMMENT;
2225
+ status.output += ANCHOR_COMMENT;
2226
+ }
2227
+
2228
+ //#endregion
2229
+ //#region src/compile/build/server/buildServerSpecialNode.ts
2230
+ function buildServerSpecialNode(node, status, b) {
2231
+ switch (node.tagName) {
2232
+ case "slot":
2233
+ buildServerSlotNode(node, status, b);
2234
+ break;
2235
+ case "fill": break;
2236
+ case "@element":
2237
+ buildServerElementNode(node, status, b);
2238
+ break;
2239
+ case "@component":
2240
+ buildServerComponentNode(node, status, b);
2241
+ break;
2242
+ default: throw new Error(`Invalid special node: ${node.tagName}`);
2243
+ }
2244
+ }
2245
+
2246
+ //#endregion
2247
+ //#region src/compile/build/server/buildServerTextNode.ts
2248
+ function buildServerTextNode(node, status) {
2249
+ let content = node.content || "";
2250
+ if (!status.preserveWhitespace) content = content.replaceAll(/\s+/g, " ");
2251
+ let level = 0;
2252
+ for (let i = 0; i < content.length; i++) {
2253
+ const char = content[i];
2254
+ const nextChar = content[i + 1];
2255
+ if (char === "{") {
2256
+ level++;
2257
+ if (level === 1) {
2258
+ status.imports.add("t_fmt");
2259
+ status.output += "${t_fmt(";
2260
+ continue;
2261
+ }
2262
+ } else if (char === "}") {
2263
+ level--;
2264
+ if (level === 0) status.output += ")";
2265
+ } else if (char === "`" && level === 0) status.output += "\\";
2266
+ else if (level > 0) {
2267
+ if (char === "/" && nextChar === "/") {
2268
+ let start = i;
2269
+ i = content.indexOf("\n", i);
2270
+ status.output += escapeHtml(content.substring(start, i + 1));
2271
+ continue;
2272
+ } else if (char === "/" && nextChar === "*") {
2273
+ let start = i;
2274
+ i = content.indexOf("*/", i) + 1;
2275
+ status.output += escapeHtml(content.substring(start, i + 1));
2276
+ continue;
2277
+ } else if (char === "\"" || char === "'") {
2278
+ let start = i;
2279
+ i = endOfString(char, content, i);
2280
+ status.output += escapeHtml(content.substring(start, i + 1));
2281
+ continue;
2282
+ } else if (char === "`") {
2283
+ let start = i;
2284
+ i = endOfTemplateString(content, i);
2285
+ status.output += escapeHtml(content.substring(start, i + 1));
2286
+ continue;
2287
+ }
2288
+ }
2289
+ status.output += char;
2290
+ }
2291
+ }
2292
+ function escapeHtml(text) {
2293
+ return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
2294
+ }
2295
+
2296
+ //#endregion
2297
+ //#region src/compile/build/server/buildServerNode.ts
2298
+ function buildServerNode(node, status, b) {
2299
+ switch (node.type) {
2300
+ case "root":
2301
+ buildServerRootNode(node, status, b);
2302
+ break;
2303
+ case "control":
2304
+ buildServerControlNode(node, status, b);
2305
+ break;
2306
+ case "component":
2307
+ buildServerComponentNode(node, status, b);
2308
+ break;
2309
+ case "element":
2310
+ buildServerElementNode(node, status, b);
2311
+ break;
2312
+ case "text":
2313
+ buildServerTextNode(node, status);
2314
+ break;
2315
+ case "special":
2316
+ buildServerSpecialNode(node, status, b);
2317
+ break;
2318
+ default: throw new Error(`Invalid node type: ${node.type}`);
2319
+ }
2320
+ }
2321
+
2322
+ //#endregion
2323
+ //#region src/compile/build/server/buildServerCode.ts
2324
+ const importsMap = {
2325
+ $watch: "import { $watch } from \"${folder}\";",
2326
+ $cache: "import { $cache } from \"${folder}\";",
2327
+ $run: "import { $run } from \"${folder}\";",
2328
+ $mount: "import { $mount } from \"${folder}\";",
2329
+ $unwrap: "import { $unwrap } from \"${folder}\";",
2330
+ $peek: "import { $peek } from \"${folder}\";",
2331
+ $batch: "import { $batch } from \"${folder}\";",
2332
+ t_fmt: "import { t_fmt } from \"${folder}\";",
2333
+ t_attr: "import { t_attr } from \"${folder}\";",
2334
+ t_class: "import { t_class } from \"${folder}\";",
2335
+ t_style: "import { t_style } from \"${folder}\";",
2336
+ ServerSlotRender: "import { type ServerSlotRender } from \"${folder}\";"
2337
+ };
2338
+ function buildServerCode(template, options) {
2339
+ let b = new Builder(options?.mapped);
2340
+ let imports = /* @__PURE__ */ new Set();
2341
+ imports.add("ServerSlotRender");
2342
+ buildServerTemplate(template, imports, b, options);
2343
+ if (imports.size) {
2344
+ b.prepend("");
2345
+ for (let imp of Array.from(imports).sort().reverse()) {
2346
+ imp = importsMap[imp] || imp;
2347
+ b.prepend(imp.replace("${folder}", options?.renderFolder || "@torpor/view/ssr"));
2348
+ }
2349
+ }
2350
+ return b.toString();
2351
+ }
2352
+ function buildServerTemplate(template, imports, b, options) {
2353
+ let script = template.script.map((s) => s.script).join("\n");
2354
+ if (/\$watch\b/.test(script)) imports.add("$watch");
2355
+ if (/\$cache\b/.test(script)) imports.add("$cache");
2356
+ if (/\$run\b/.test(script)) imports.add("$run");
2357
+ if (/\$mount\b/.test(script)) imports.add("$mount");
2358
+ if (/\$unwrap\b/.test(script)) imports.add("$unwrap");
2359
+ if (/\$peek\b/.test(script)) imports.add("$peek");
2360
+ if (/\$batch\b/.test(script)) imports.add("$batch");
2361
+ let currentIndex = 0;
2362
+ let current = template.components[0];
2363
+ for (let chunk of template.script) if (chunk.script === "/* @params */") {
2364
+ let params = [
2365
+ current.params ?? `${current.props?.length ? "$props: Record<PropertyKey, any>" : "_$props: Record<PropertyKey, any> | undefined"}`,
2366
+ `${current.contextProps?.length || current.needsContext ? "$context" : "_$context"}: Record<PropertyKey, any>`,
2367
+ `${current.slotProps?.length ? "$slots" : "_$slots"}?: Record<string, ServerSlotRender>`
2368
+ ];
2369
+ b.append(params.join(",\n"));
2370
+ } else if (chunk.script === ") /* @return_type */ {") b.append("): { body: string, head: string } {");
2371
+ else if (chunk.script === "/* @start */") {
2372
+ if (current.contextProps?.length) b.append(`$context = Object.assign({}, $context);`);
2373
+ b.append(`let t_body = "";`);
2374
+ b.append(`let t_head = "";`);
2375
+ } else if (chunk.script === "/* @render */") {
2376
+ if (current.markup) {
2377
+ const status = {
2378
+ imports,
2379
+ output: "",
2380
+ styleHash: current.style?.hash || "",
2381
+ varNames: {},
2382
+ preserveWhitespace: false,
2383
+ options
2384
+ };
2385
+ b.append("");
2386
+ b.append("/* User interface */");
2387
+ buildServerNode(current.markup, status, b);
2388
+ if (status.output) {
2389
+ b.append(`t_body += \`${status.output}\`;`);
2390
+ status.output = "";
2391
+ }
2392
+ }
2393
+ } else if (chunk.script === "/* @head */") {} else if (chunk.script === "/* @style */") {
2394
+ if (current.style) {
2395
+ b.append("");
2396
+ b.append("/* Style */");
2397
+ const styles = buildStyles(current.style, current.style.hash).replaceAll("\"", "\\\"").replaceAll(/\s+/g, " ");
2398
+ b.append(`t_head += "<style id='${current.style.hash}'>${styles}</style>";\n`);
2399
+ }
2400
+ } else if (chunk.script === "/* @end */") {
2401
+ b.append(`return { body: t_body, head: t_head };`);
2402
+ currentIndex += 1;
2403
+ current = template.components[currentIndex];
2404
+ } else b.append(chunk.script);
2405
+ }
2406
+
2407
+ //#endregion
2408
+ //#region src/compile/build.ts
2409
+ /**
2410
+ * Builds a component template into code and styles for rendering
2411
+ *
2412
+ * @param template The component template, possibly including script, markup and styles
2413
+ *
2414
+ * @returns The component's code and styles
2415
+ */
2416
+ function build(template, options) {
2417
+ let map = [];
2418
+ let code = options?.server ? buildServerCode(template, options) : buildCode(template, map, options);
2419
+ let styles = template.components.map((c) => c.style ? {
2420
+ style: buildStyles(c.style, c.style.hash),
2421
+ hash: c.style.hash
2422
+ } : void 0).filter((c) => c !== void 0);
2423
+ return {
2424
+ code,
2425
+ styles,
2426
+ map
2427
+ };
2428
+ }
2429
+
2430
+ //#endregion
2431
+ //#region src/compile/buildType.ts
2432
+ /**
2433
+ * Builds a component template into a d.ts file
2434
+ *
2435
+ * @param name The name of the component
2436
+ * @param template The component template, possibly including script, markup and styles
2437
+ *
2438
+ * @returns The d.ts file content
2439
+ */
2440
+ function buildType(template, options) {
2441
+ let b = new Builder();
2442
+ b.append(`import { type SlotRender } from "${options?.renderFolder || "@torpor/view"}";`);
2443
+ for (let component of template.components) if (component.exported) {
2444
+ b.append("");
2445
+ if (component.propsType) {
2446
+ b.append(component.propsType);
2447
+ b.append("");
2448
+ }
2449
+ b.append(`
2450
+ ${component.documentation ?? ""}
2451
+ ${component.default ? "declare" : "export declare"} function ${component.name}(
2452
+ $parent: ParentNode,
2453
+ $anchor: Node | null,
2454
+ ${component.params || "$props?: Record<PropertyKey, any>"},
2455
+ $context?: Record<PropertyKey, any>,
2456
+ $slots?: Record<string, SlotRender>,
2457
+ ): void;
2458
+ `);
2459
+ if (component.default) b.append(`export default ${component.name};`);
2460
+ }
2461
+ return b.toString();
2462
+ }
2463
+
2464
+ //#endregion
2465
+ //#region src/compile/utils/isSpaceNode.ts
2466
+ function isSpaceNode(node) {
2467
+ return isTextNode(node) && isSpace(node.content);
2468
+ }
2469
+
2470
+ //#endregion
2471
+ //#region src/compile/parse/utils/accept.ts
2472
+ /**
2473
+ * Checks whether the source at the current parse position matches the supplied
2474
+ * string
2475
+ *
2476
+ * @param value The string to check
2477
+ * @param status The parse status
2478
+ * @param advance (Optional) If true, advances the parse position past the
2479
+ * checked string (defaults to true)
2480
+ *
2481
+ * @returns True if the supplied string was found at the current parse position
2482
+ */
2483
+ function accept(value, status, advance = true) {
2484
+ if (status.source.substring(status.i, status.i + value.length) == value) {
2485
+ status.i += advance ? value.length : 0;
2486
+ return true;
2487
+ }
2488
+ return false;
2489
+ }
2490
+
2491
+ //#endregion
2492
+ //#region src/compile/parse/parseInlineScript.ts
2493
+ function parseInlineScript(status) {
2494
+ const start = status.i;
2495
+ let braceCount = 0;
2496
+ while (status.i < status.source.length) if (accept("{", status)) braceCount += 1;
2497
+ else if (accept("}", status)) if (braceCount > 0) braceCount -= 1;
2498
+ else return status.source.substring(start, status.i - 1);
2499
+ else if (accept("//", status)) status.i = status.source.indexOf("\n", status.i) + 1;
2500
+ else if (accept("/*", status)) status.i = status.source.indexOf("*/", status.i) + 2;
2501
+ else if (accept("\"", status) || accept("'", status)) {
2502
+ const char = status.source[status.i - 1];
2503
+ status.i = endOfString(char, status.source, status.i - 1) + 1;
2504
+ } else if (accept("`", status)) status.i = endOfTemplateString(status.source, status.i - 1) + 1;
2505
+ else status.i += 1;
2506
+ return "";
2507
+ }
2508
+
2509
+ //#endregion
2510
+ //#region src/compile/utils/trimStart.ts
2511
+ /**
2512
+ * Trims a char from the start of the supplied text
2513
+ *
2514
+ * @param text The text to trim
2515
+ * @param char The char to remove from the start of the text
2516
+ *
2517
+ * @returns The text without the char on the start
2518
+ */
2519
+ function trimStart(text, char) {
2520
+ let start = 0;
2521
+ while (text[start] === char) start += 1;
2522
+ return text.substring(start);
2523
+ }
2524
+
2525
+ //#endregion
2526
+ //#region src/compile/parse/utils/consumeSpace.ts
2527
+ /**
2528
+ * Consumes space characters and advances the current parse position to before
2529
+ * the next non-space character
2530
+ *
2531
+ * @param status The parse status
2532
+ *
2533
+ * @returns The string of space characters from the current parse position to
2534
+ * the next non-space character
2535
+ */
2536
+ function consumeSpace(status) {
2537
+ const start = status.i;
2538
+ for (status.i; status.i < status.source.length; status.i++) if (!isSpaceChar(status.source, status.i)) return status.source.substring(start, status.i);
2539
+ return "";
2540
+ }
2541
+
2542
+ //#endregion
2543
+ //#region src/compile/parse/addSpaceElement.ts
2544
+ function addSpaceElement(parent, status) {
2545
+ const content = consumeSpace(status);
2546
+ if (content) {
2547
+ const previousNode = parent.children[parent.children.length - 1];
2548
+ if (previousNode && isTextNode(previousNode)) previousNode.content += content;
2549
+ else {
2550
+ const space = {
2551
+ type: "text",
2552
+ content,
2553
+ ranges: []
2554
+ };
2555
+ parent.children.push(space);
2556
+ }
2557
+ }
2558
+ }
2559
+
2560
+ //#endregion
2561
+ //#region src/compile/utils/isFullyReactive.ts
2562
+ /**
2563
+ * Checks whether the supplied string is fully reactive (i.e. starts and ends with braces)
2564
+ *
2565
+ * @param text The string to check
2566
+ *
2567
+ * @returns True if the supplied string is fully reactive
2568
+ */
2569
+ function isFullyReactive(text) {
2570
+ return text.trim().startsWith("{") && text.trim().endsWith("}");
2571
+ }
2572
+
2573
+ //#endregion
2574
+ //#region src/compile/parse/utils/isAlphaNumericChar.ts
2575
+ /**
2576
+ * Checks whether the supplied character is a alpha-numeric
2577
+ *
2578
+ * @param text The string to check
2579
+ * @param index The index of the character in the string
2580
+ *
2581
+ * @returns True if the supplied character is alpha-numeric
2582
+ */
2583
+ function isAlphaNumericChar(text, index) {
2584
+ let code = text.charCodeAt(index);
2585
+ return code > 47 && code < 58 || code > 64 && code < 91 || code > 96 && code < 123;
2586
+ }
2587
+
2588
+ //#endregion
2589
+ //#region src/compile/parse/utils/consumeAlphaNumeric.ts
2590
+ /**
2591
+ * Consumes alpha-numeric characters and advances the current parse position to
2592
+ * before the next non-alpha character
2593
+ *
2594
+ * @param status The parse status
2595
+ *
2596
+ * @returns The string of alpha-numeric characters from the current parse position
2597
+ * to the next non-alpha character
2598
+ */
2599
+ function consumeAlphaNumeric(status) {
2600
+ const start = status.i;
2601
+ for (status.i; status.i < status.source.length; status.i++) if (!isAlphaNumericChar(status.source, status.i)) return status.source.substring(start, status.i);
2602
+ return "";
2603
+ }
2604
+
2605
+ //#endregion
2606
+ //#region src/compile/parse/utils/consumeUntil.ts
2607
+ /**
2608
+ * Consumes characters until one of the characters in the supplied string is
2609
+ * found. The parse position will be advanced to before the found character
2610
+ *
2611
+ * @param chars The characters to match
2612
+ * @param status The parse status
2613
+ *
2614
+ * @returns The string of characters from the current parse position to the
2615
+ * found character
2616
+ */
2617
+ function consumeUntil(chars, status) {
2618
+ const start = status.i;
2619
+ for (status.i; status.i < status.source.length; status.i++) if (chars.includes(status.source[status.i])) return status.source.substring(start, status.i);
2620
+ return "";
2621
+ }
2622
+
2623
+ //#endregion
2624
+ //#region src/compile/parse/parseTag.ts
2625
+ function parseTag(status) {
2626
+ accept("<", status);
2627
+ let closeTag = accept("/", status);
2628
+ consumeSpace(status);
2629
+ let tagStart = status.i;
2630
+ let snailed = accept("@", status);
2631
+ let tagName = consumeAlphaNumeric(status);
2632
+ let tagEnd = status.i;
2633
+ if (snailed) tagName = "@" + tagName;
2634
+ if (closeTag) tagName = "/" + tagName;
2635
+ consumeSpace(status);
2636
+ let attributes = parseTagAttributes(status);
2637
+ let selfClosed = false;
2638
+ if (accept("/>", status)) selfClosed = true;
2639
+ else accept(">", status);
2640
+ if (closeTag) selfClosed = true;
2641
+ return {
2642
+ type: [
2643
+ "slot",
2644
+ "fill",
2645
+ "@component",
2646
+ "@element"
2647
+ ].includes(tagName) ? "special" : "element",
2648
+ tagName,
2649
+ selfClosed: selfClosed || void 0,
2650
+ closed: selfClosed || void 0,
2651
+ attributes,
2652
+ children: [],
2653
+ range: {
2654
+ start: tagStart,
2655
+ end: tagEnd
2656
+ }
2657
+ };
2658
+ }
2659
+ function parseTagAttributes(status) {
2660
+ let attributes = [];
2661
+ while (status.i < status.source.length) {
2662
+ consumeSpace(status);
2663
+ if (accept("@//", status)) status.i = status.source.indexOf("\n", status.i) + 1;
2664
+ else if (accept("@/*", status)) status.i = status.source.indexOf("*/", status.i) + 2;
2665
+ else if (accept("/>", status, false) || accept(">", status, false)) break;
2666
+ else if (accept("<", status, false) || accept("@", status, false) || accept("}", status, false)) break;
2667
+ else {
2668
+ const attribute = parseAttribute(status);
2669
+ attributes.push(attribute);
2670
+ }
2671
+ }
2672
+ return attributes;
2673
+ }
2674
+ function parseAttribute(status) {
2675
+ let valueStart = status.i;
2676
+ let valueEnd = status.i;
2677
+ let name = consumeUntil("= \r\n/>", status);
2678
+ let value = void 0;
2679
+ let reactive = false;
2680
+ let fullyReactive = false;
2681
+ consumeSpace(status);
2682
+ if (accept("=", status)) {
2683
+ consumeSpace(status);
2684
+ valueStart = status.i;
2685
+ value = parseAttributeValue(status);
2686
+ valueEnd = status.i;
2687
+ reactive = isReactive(value);
2688
+ fullyReactive = isFullyReactive(value);
2689
+ if (fullyReactive) {
2690
+ value = value.substring(1, value.length - 1);
2691
+ valueStart++;
2692
+ valueEnd--;
2693
+ } else if (reactive) value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
2694
+ } else if (name.startsWith("{") && name.endsWith("}")) {
2695
+ value = name.substring(1, name.length - 1);
2696
+ valueStart++;
2697
+ valueEnd = valueStart + name.length;
2698
+ name = value.split(".").at(-1);
2699
+ reactive = fullyReactive = true;
2700
+ }
2701
+ return {
2702
+ name,
2703
+ value,
2704
+ reactive,
2705
+ fullyReactive,
2706
+ range: {
2707
+ start: valueStart,
2708
+ end: valueEnd
2709
+ }
2710
+ };
2711
+ }
2712
+ function parseAttributeValue(status) {
2713
+ if (accept("\"", status)) {
2714
+ const value = consumeUntil("\"", status);
2715
+ accept("\"", status);
2716
+ return `"${value}"`;
2717
+ } else if (accept("'", status)) {
2718
+ const value = consumeUntil("'", status);
2719
+ accept("'", status);
2720
+ return `'${value}'`;
2721
+ } else if (accept("{", status)) return `{${parseInlineScript(status)}}`;
2722
+ else {
2723
+ let value = consumeUntil(" \r\n>", status);
2724
+ if (status.source.substring(status.i - 1, status.i + 1) === "/>") {
2725
+ value = value.substring(0, value.length - 1);
2726
+ status.i -= 1;
2727
+ }
2728
+ return value;
2729
+ }
2730
+ }
2731
+
2732
+ //#endregion
2733
+ //#region src/compile/parse/parseText.ts
2734
+ function parseText(status, element) {
2735
+ let ranges = [];
2736
+ const start = status.i;
2737
+ let end = -1;
2738
+ for (let j = status.i; j < status.source.length; j++) {
2739
+ if (status.source[j] === "}") end = j;
2740
+ else if (status.source[j] === "{") {
2741
+ const reactiveStart = j + 1;
2742
+ let level = 0;
2743
+ for (let k = j; k < status.source.length; k++) {
2744
+ const char = status.source[k];
2745
+ const nextChar = status.source[k + 1];
2746
+ if (char === "/" && nextChar === "/") k = status.source.indexOf("\n", k);
2747
+ else if (char === "/" && nextChar === "*") k = status.source.indexOf("*/", k) + 1;
2748
+ else if (char === "\"" || char === "'") k = endOfString(char, status.source, k);
2749
+ else if (char === "`") k = endOfTemplateString(status.source, k);
2750
+ else if (char === "{") level += 1;
2751
+ else if (char === "}") {
2752
+ level -= 1;
2753
+ if (level === 0) {
2754
+ j = k;
2755
+ break;
2756
+ }
2757
+ }
2758
+ }
2759
+ ranges.push({
2760
+ start: reactiveStart,
2761
+ end: j
2762
+ });
2763
+ } else if (status.source[j] === "<") end = j;
2764
+ else if (status.source[j] === "@") {
2765
+ for (let k = j - 1; k > status.i; k--) if (status.source[k] === "\n") {
2766
+ end = j;
2767
+ break;
2768
+ } else if (!isSpaceChar(status.source, k)) break;
2769
+ }
2770
+ if (end !== -1) break;
2771
+ }
2772
+ if (end !== -1) {
2773
+ const content = status.source.substring(start, end).trimEnd();
2774
+ const spaceContent = status.source.substring(start + content.length, end);
2775
+ if (content || spaceContent) {
2776
+ const previousNode = element.children[element.children.length - 1];
2777
+ if (previousNode && isTextNode(previousNode)) {
2778
+ previousNode.content += content + spaceContent;
2779
+ previousNode.ranges.push(...ranges);
2780
+ } else {
2781
+ const text = {
2782
+ type: "text",
2783
+ content: content + spaceContent,
2784
+ ranges
2785
+ };
2786
+ element.children.push(text);
2787
+ }
2788
+ }
2789
+ status.i = end;
2790
+ } else status.i += 1;
2791
+ }
2792
+
2793
+ //#endregion
2794
+ //#region src/compile/parse/slottifyChildNodes.ts
2795
+ /**
2796
+ * Moves any child nodes that aren't already in a <fill> node into a default
2797
+ * <fill> node
2798
+ */
2799
+ function slottifyChildNodes(node) {
2800
+ const nonFillNodes = node.children.filter((c) => !isFillNode(c));
2801
+ if (nonFillNodes.length) {
2802
+ let defaultFillNode = node.children.find((n) => isFillNode(n) && !n.attributes.find((a) => a.name === "name"));
2803
+ if (!defaultFillNode) {
2804
+ defaultFillNode = {
2805
+ type: "special",
2806
+ tagName: "fill",
2807
+ attributes: [],
2808
+ children: nonFillNodes,
2809
+ range: {
2810
+ start: 0,
2811
+ end: 0
2812
+ }
2813
+ };
2814
+ node.children.unshift(defaultFillNode);
2815
+ }
2816
+ }
2817
+ node.children = node.children.filter((c) => isFillNode(c));
2818
+ }
2819
+ function isFillNode(n) {
2820
+ return isSpecialNode(n) && n.tagName === "fill";
2821
+ }
2822
+
2823
+ //#endregion
2824
+ //#region src/compile/parse/utils/addError.ts
2825
+ /**
2826
+ * Adds an error to the parse status
2827
+ *
2828
+ * @param status The parse status
2829
+ * @param message The error message to add
2830
+ * @param start (Optional) The start position of the error (defaults to the
2831
+ * current parse position)
2832
+ */
2833
+ function addError(status, message, start = status.i, end = status.i) {
2834
+ let startLine = 0;
2835
+ let lastLineStart = 0;
2836
+ let i = 0;
2837
+ for (; i < start; i++) if (status.source[i] === "\n") {
2838
+ startLine += 1;
2839
+ lastLineStart = i + 1;
2840
+ }
2841
+ let startChar = start - lastLineStart;
2842
+ let endLine = startLine;
2843
+ for (; i < end; i++) if (status.source[i] === "\n") {
2844
+ endLine += 1;
2845
+ lastLineStart = i + 1;
2846
+ }
2847
+ let endChar = end - lastLineStart;
2848
+ status.errors.push({
2849
+ message,
2850
+ startIndex: start,
2851
+ startLine,
2852
+ startChar,
2853
+ endIndex: end,
2854
+ endLine,
2855
+ endChar
2856
+ });
2857
+ }
2858
+
2859
+ //#endregion
2860
+ //#region src/compile/parse/parseElement.ts
2861
+ function parseElement(status) {
2862
+ const current = status.components.at(-1);
2863
+ if (!current) throw new Error("No component in stack");
2864
+ const start = status.i;
2865
+ const element = parseTag(status);
2866
+ if (element.tagName.startsWith("/")) {
2867
+ addError(status, `Non-matching close tag: ${element.tagName.substring(1)}`, start, start + element.tagName.length);
2868
+ return element;
2869
+ }
2870
+ if (voidTags_default.includes(element.tagName)) checkVoidElement(status, element);
2871
+ if (!element.selfClosed && !voidTags_default.includes(element.tagName)) {
2872
+ current.stack ??= [];
2873
+ current.stack.push(element);
2874
+ while (status.i < status.source.length) {
2875
+ addSpaceElement(element, status);
2876
+ if (accept("}", status, false)) break;
2877
+ else if (accept("<!--", status)) status.i = status.source.indexOf("-->", status.i) + 3;
2878
+ else if (accept("@//", status)) status.i = status.source.indexOf("\n", status.i) + 1;
2879
+ else if (accept("@/*", status)) status.i = status.source.indexOf("*/", status.i) + 2;
2880
+ else if (accept("</", status, false)) {
2881
+ if (checkCloseTag(status, element, current)) break;
2882
+ } else if (accept("<", status, false)) {
2883
+ const child = parseElement(status);
2884
+ element.children.push(child);
2885
+ } else if (accept("@", status, false)) parseControl(status, element);
2886
+ else parseText(status, element);
2887
+ }
2888
+ current.stack.pop();
2889
+ }
2890
+ if (/[A-Z]/.test(element.tagName[0])) {
2891
+ element.type = "component";
2892
+ slottifyChildNodes(element);
2893
+ current.needsContext = true;
2894
+ }
2895
+ if (isSpecialNode(element)) {
2896
+ if (element.tagName === "slot") {
2897
+ slottifyChildNodes(element);
2898
+ current.needsContext = true;
2899
+ current.slotProps ??= [];
2900
+ current.slotProps.push(element.attributes.find((a) => a.name === "name")?.name ?? "default");
2901
+ } else if (element.tagName === "fill") {
2902
+ const fillSource = status.source.substring(start, status.i);
2903
+ element.hasSlotProps = /\$sprops\b/.test(fillSource);
2904
+ } else if (element.tagName === "@component") {
2905
+ const selfAttribute = element.attributes.find((a) => a.name === "self");
2906
+ if (selfAttribute && selfAttribute.value && selfAttribute.fullyReactive) {
2907
+ element.type = "component";
2908
+ slottifyChildNodes(element);
2909
+ current.needsContext = true;
2910
+ const selfValue = selfAttribute.value;
2911
+ return {
2912
+ type: "control",
2913
+ operation: "@replace group",
2914
+ statement: selfValue,
2915
+ children: [{
2916
+ type: "control",
2917
+ operation: "@replace",
2918
+ statement: selfValue,
2919
+ children: [element],
2920
+ range: {
2921
+ start: 0,
2922
+ end: 0
2923
+ }
2924
+ }],
2925
+ range: {
2926
+ start: 0,
2927
+ end: 0
2928
+ }
2929
+ };
2930
+ } else addError(status, "@component element must have a self attribute", start, start + element.tagName.length + 1);
2931
+ }
2932
+ }
2933
+ if (!element.closed && !voidTags_default.includes(element.tagName)) addError(status, `Unclosed non-void element: ${element.tagName}`, start, start + element.tagName.length + 1);
2934
+ return element;
2935
+ }
2936
+ function checkVoidElement(status, element) {
2937
+ let i = status.i;
2938
+ consumeSpace(status);
2939
+ if (accept("</", status)) {
2940
+ consumeSpace(status);
2941
+ if (accept(element.tagName, status)) {
2942
+ addError(status, `Closed void element: ${element.tagName}`, i, i + element.tagName.length + 1);
2943
+ consumeSpace(status);
2944
+ accept(">", status);
2945
+ return;
2946
+ }
2947
+ }
2948
+ status.i = i;
2949
+ }
2950
+ function checkCloseTag(status, element, current) {
2951
+ const start = status.i;
2952
+ accept("</", status);
2953
+ consumeSpace(status);
2954
+ let snailed = accept("@", status);
2955
+ let closingTagName = consumeAlphaNumeric(status);
2956
+ if (snailed) closingTagName = "@" + closingTagName;
2957
+ consumeSpace(status);
2958
+ accept(">", status);
2959
+ let found = false;
2960
+ if (current.stack) {
2961
+ for (let i = current.stack.length - 1; i >= 0; i--) if (closingTagName === current.stack[i].tagName) {
2962
+ current.stack[i].closed = true;
2963
+ found = true;
2964
+ break;
2965
+ }
2966
+ }
2967
+ if (!found) addError(status, `Non-matching close tag: ${closingTagName} (expected ${element.tagName})`, start, start + element.tagName.length + 1);
2968
+ return found;
2969
+ }
2970
+
2971
+ //#endregion
2972
+ //#region src/compile/parse/parseControl.ts
2973
+ const controlOperations = [
2974
+ "@if",
2975
+ "@else",
2976
+ "@for",
2977
+ "@key",
2978
+ "@switch",
2979
+ "@case",
2980
+ "@default",
2981
+ "@await",
2982
+ "@then",
2983
+ "@catch",
2984
+ "@replace",
2985
+ "@html",
2986
+ "@const",
2987
+ "@console",
2988
+ "@debugger",
2989
+ "@function",
2990
+ "@async function"
2991
+ ];
2992
+ const standaloneOperations = [
2993
+ "@key",
2994
+ "@html",
2995
+ "@const",
2996
+ "@console",
2997
+ "@debugger",
2998
+ "@function",
2999
+ "@async function"
3000
+ ];
3001
+ function parseControl(status, parentNode) {
3002
+ const node = parseControlOpen(status);
3003
+ if (!node) return;
3004
+ if (standaloneOperations.includes(node.operation)) {
3005
+ wrangleControlNode(node, parentNode);
3006
+ return;
3007
+ }
3008
+ while (status.i < status.source.length) {
3009
+ addSpaceElement(node, status);
3010
+ if (accept("}", status)) break;
3011
+ else if (accept("<", status, false)) {
3012
+ const child = parseElement(status);
3013
+ node.children.push(child);
3014
+ } else if (accept("@//", status)) status.i = status.source.indexOf("\n", status.i) + 1;
3015
+ else if (accept("@/*", status)) status.i = status.source.indexOf("*/", status.i) + 2;
3016
+ else if (accept("@", status, false)) parseControl(status, node);
3017
+ else if (accept("case", status, false) || accept("key", status, false)) parseControl(status, node);
3018
+ else {
3019
+ const char = status.source[status.i];
3020
+ addError(status, `Unexpected token in control block: ${char}`, status.i, status.i + 1);
3021
+ break;
3022
+ }
3023
+ }
3024
+ wrangleControlNode(node, parentNode);
3025
+ parseControlBranches(status, parentNode);
3026
+ }
3027
+ function parseControlOpen(status) {
3028
+ const start = status.i;
3029
+ let statementStart = start;
3030
+ let operation = "";
3031
+ for (status.i; status.i < status.source.length; status.i++) {
3032
+ const char = status.source[status.i];
3033
+ if (isSpaceChar(status.source, status.i) && operation !== "@async" || accept(":", status) && operation === "default" || accept(".", status) && operation === "@console" || accept("(", status, false) && operation === "@html") break;
3034
+ operation += char;
3035
+ }
3036
+ if (!operation.startsWith("@")) operation = "@" + operation;
3037
+ else statementStart++;
3038
+ let statement = "";
3039
+ if (controlOperations.includes(operation)) {
3040
+ statement = parseControlStatement(start, operation, status);
3041
+ if (operation === "@function" || operation === "@async function") {
3042
+ statement += ` {${parseInlineScript(status)}}`;
3043
+ accept("}", status);
3044
+ }
3045
+ if (operation === "@replace" || operation === "@html") statement = trimMatched(statement.substring(statement.indexOf("(")).trim(), "(", ")");
3046
+ } else {
3047
+ addError(status, `Unknown operation: ${operation}`, status.i, status.i + operation.length);
3048
+ return null;
3049
+ }
3050
+ return {
3051
+ type: "control",
3052
+ operation,
3053
+ statement,
3054
+ children: [],
3055
+ range: {
3056
+ start: statementStart,
3057
+ end: status.i
3058
+ }
3059
+ };
3060
+ }
3061
+ function parseControlStatement(start, operation, status) {
3062
+ let parenCount = 0;
3063
+ while (status.i < status.source.length) if (accept("(", status)) parenCount += 1;
3064
+ else if (accept(")", status)) parenCount -= 1;
3065
+ else if (accept("{", status) || accept("\n", status) && standaloneOperations.includes(operation)) {
3066
+ if (parenCount === 0) return trimStart(status.source.substring(start, status.i - 1).trim(), "@");
3067
+ } else if (accept("//", status)) status.i = status.source.indexOf("\n", status.i) + 1;
3068
+ else if (accept("/*", status)) status.i = status.source.indexOf("*/", status.i) + 2;
3069
+ else if (accept("\"", status) || accept("'", status)) {
3070
+ let char = status.source[status.i - 1];
3071
+ status.i = endOfString(char, status.source, status.i - 1) + 1;
3072
+ } else if (accept("`", status)) status.i = endOfTemplateString(status.source, status.i - 1) + 1;
3073
+ else status.i += 1;
3074
+ return "";
3075
+ }
3076
+ /**
3077
+ * Groups the control node into the correct parent e.g. if/else into an if group
3078
+ * @param node The control node
3079
+ * @param parentNode The parent node
3080
+ */
3081
+ function wrangleControlNode(node, parentNode) {
3082
+ if (node.operation === "@if") {
3083
+ const ifGroup = {
3084
+ type: "control",
3085
+ operation: "@if group",
3086
+ statement: "",
3087
+ children: [node],
3088
+ range: {
3089
+ start: 0,
3090
+ end: 0
3091
+ }
3092
+ };
3093
+ parentNode.children.push(ifGroup);
3094
+ } else if (node.operation === "@else") {
3095
+ if (/^else\s+if/.test(node.statement)) node.operation = "@else if";
3096
+ for (let i = parentNode.children.length - 1; i >= 0; i--) {
3097
+ const lastChild = parentNode.children[i];
3098
+ if (isControlNode(lastChild) && lastChild.operation === "@if group") {
3099
+ lastChild.children.push(node);
3100
+ break;
3101
+ }
3102
+ }
3103
+ } else if (node.operation === "@for") {
3104
+ const forGroup = {
3105
+ type: "control",
3106
+ operation: "@for group",
3107
+ statement: "",
3108
+ children: [node],
3109
+ range: {
3110
+ start: 0,
3111
+ end: 0
3112
+ }
3113
+ };
3114
+ parentNode.children.push(forGroup);
3115
+ } else if (node.operation === "@switch") {
3116
+ node.operation = "@switch group";
3117
+ parentNode.children.push(node);
3118
+ } else if (node.operation === "@await") {
3119
+ const awaitGroup = {
3120
+ type: "control",
3121
+ operation: "@await group",
3122
+ statement: "",
3123
+ children: [node],
3124
+ range: {
3125
+ start: 0,
3126
+ end: 0
3127
+ }
3128
+ };
3129
+ parentNode.children.push(awaitGroup);
3130
+ } else if (node.operation === "@then" || node.operation === "@catch") for (let i = parentNode.children.length - 1; i >= 0; i--) {
3131
+ const lastChild = parentNode.children[i];
3132
+ if (isControlNode(lastChild) && lastChild.operation === "@await group") {
3133
+ lastChild.children.push(node);
3134
+ break;
3135
+ }
3136
+ }
3137
+ else if (node.operation === "@replace") {
3138
+ const replaceGroup = {
3139
+ type: "control",
3140
+ operation: "@replace group",
3141
+ statement: "",
3142
+ children: [node],
3143
+ range: {
3144
+ start: 0,
3145
+ end: 0
3146
+ }
3147
+ };
3148
+ parentNode.children.push(replaceGroup);
3149
+ } else if (node.operation === "@html") {
3150
+ const htmlGroup = {
3151
+ type: "control",
3152
+ operation: "@html group",
3153
+ statement: "",
3154
+ children: [node],
3155
+ range: {
3156
+ start: 0,
3157
+ end: 0
3158
+ }
3159
+ };
3160
+ parentNode.children.push(htmlGroup);
3161
+ } else parentNode.children.push(node);
3162
+ }
3163
+ /**
3164
+ * Parses control branches that don't start with an @ symbol e.g. else or case
3165
+ * @param status The parse status
3166
+ * @param parentNode The parent node
3167
+ */
3168
+ function parseControlBranches(status, parentNode) {
3169
+ let gotAnotherBranch = true;
3170
+ while (gotAnotherBranch) {
3171
+ let start = status.i;
3172
+ status.i += 1;
3173
+ consumeSpace(status);
3174
+ if (accept("else", status, false) || accept("case", status, false) || accept("default", status, false) || accept("then", status, false) || accept("catch", status, false)) parseControl(status, parentNode);
3175
+ else {
3176
+ gotAnotherBranch = false;
3177
+ status.i = start;
3178
+ }
3179
+ }
3180
+ }
3181
+
3182
+ //#endregion
3183
+ //#region src/compile/parse/parseMarkup.ts
3184
+ function parseMarkup(status, source) {
3185
+ const current = status.components.at(-1);
3186
+ if (!current) return;
3187
+ while (status.i < source.length) if (accept("}", status, false)) return;
3188
+ else if (accept("<!--", status)) status.i = status.source.indexOf("-->", status.i) + 3;
3189
+ else if (accept("@//", status)) status.i = status.source.indexOf("\n", status.i) + 1;
3190
+ else if (accept("@/*", status)) status.i = status.source.indexOf("*/", status.i) + 2;
3191
+ else if (isSpaceChar(status.source, status.i)) {
3192
+ current.markup ??= {
3193
+ type: "root",
3194
+ children: []
3195
+ };
3196
+ const text = {
3197
+ type: "text",
3198
+ content: consumeSpace(status),
3199
+ ranges: []
3200
+ };
3201
+ current.markup.children.push(text);
3202
+ } else if (accept("<", status, false)) {
3203
+ current.markup ??= {
3204
+ type: "root",
3205
+ children: []
3206
+ };
3207
+ const element = parseElement(status);
3208
+ current.markup.children.push(element);
3209
+ } else if (accept("@", status, false)) {
3210
+ current.markup ??= {
3211
+ type: "root",
3212
+ children: []
3213
+ };
3214
+ parseControl(status, current.markup);
3215
+ } else status.i += 1;
3216
+ }
3217
+
3218
+ //#endregion
3219
+ //#region src/compile/utils/hash.ts
3220
+ const returnRegex = /\r/g;
3221
+ function hash(input) {
3222
+ input = input.replace(returnRegex, "");
3223
+ let hash$1 = 5381;
3224
+ let i = input.length;
3225
+ while (i--) hash$1 = (hash$1 << 5) - hash$1 ^ input.charCodeAt(i);
3226
+ return (hash$1 >>> 0).toString(36);
3227
+ }
3228
+
3229
+ //#endregion
3230
+ //#region src/compile/parse/utils/expect.ts
3231
+ /**
3232
+ * Checks whether the source at the current parse position matches the supplied
3233
+ * string and if not, adds an error to the parse status
3234
+ *
3235
+ * @param value The string to check
3236
+ * @param status The parse status
3237
+ * @param advance (Optional) If true, advances the parse position past the
3238
+ * checked string (defaults to true)
3239
+ *
3240
+ * @returns True if the supplied string was found at the current parse position
3241
+ */
3242
+ function expect(value, status, advance = true) {
3243
+ if (status.i < status.source.length) if (status.source.substring(status.i, status.i + value.length) == value) {
3244
+ status.i += advance ? value.length : 0;
3245
+ return true;
3246
+ } else addError(status, `Expected ${value}`);
3247
+ else addError(status, "Expected token");
3248
+ return false;
3249
+ }
3250
+
3251
+ //#endregion
3252
+ //#region src/compile/parse/parseStyles.ts
3253
+ function parseStyles(source, status) {
3254
+ const current = status.components.at(-1);
3255
+ if (!current) return;
3256
+ current.style = {
3257
+ global: false,
3258
+ blocks: [],
3259
+ hash: hash(source)
3260
+ };
3261
+ const styleStatus = {
3262
+ source,
3263
+ i: 0,
3264
+ marker: 0,
3265
+ level: 0,
3266
+ imports: [],
3267
+ script: [],
3268
+ components: [],
3269
+ errors: []
3270
+ };
3271
+ while (styleStatus.i < styleStatus.source.length) if (isSpaceChar(styleStatus.source, styleStatus.i)) consumeSpace(styleStatus);
3272
+ else {
3273
+ const block = parseStyleBlock(styleStatus);
3274
+ if (block) current.style.blocks.push(block);
3275
+ else break;
3276
+ }
3277
+ status.errors = status.errors.concat(styleStatus.errors);
3278
+ }
3279
+ function parseStyleBlock(status) {
3280
+ const selector = consumeUntil("{", status).trim();
3281
+ if (expect("{", status)) {
3282
+ const block = {
3283
+ selector,
3284
+ attributes: [],
3285
+ children: []
3286
+ };
3287
+ consumeSpace(status);
3288
+ while (status.source[status.i] !== "}") {
3289
+ let nextColon = status.source.indexOf(":", status.i);
3290
+ if (nextColon === -1) nextColon = status.source.length;
3291
+ let nextOpenBrace = status.source.indexOf("{", status.i);
3292
+ if (nextOpenBrace === -1) nextOpenBrace = status.source.length;
3293
+ if (nextColon < nextOpenBrace) {
3294
+ const attribute = parseStyleAttribute(status);
3295
+ block.attributes.push(attribute);
3296
+ } else if (nextOpenBrace < nextColon) {
3297
+ const child = parseStyleBlock(status);
3298
+ if (child) block.children.push(child);
3299
+ else break;
3300
+ } else return block;
3301
+ consumeSpace(status);
3302
+ }
3303
+ accept("}", status);
3304
+ return block;
3305
+ }
3306
+ }
3307
+ function parseStyleAttribute(status) {
3308
+ const name = consumeUntil(":", status).trim();
3309
+ accept(":", status);
3310
+ const value = consumeUntil(";", status).trim();
3311
+ accept(";", status);
3312
+ return {
3313
+ name,
3314
+ value
3315
+ };
3316
+ }
3317
+
3318
+ //#endregion
3319
+ //#region src/compile/utils/isComponentNode.ts
3320
+ function isComponentNode(node) {
3321
+ return node.type === "component";
3322
+ }
3323
+
3324
+ //#endregion
3325
+ //#region src/compile/utils/isParentNode.ts
3326
+ function isParentNode(node) {
3327
+ return "children" in node;
3328
+ }
3329
+
3330
+ //#endregion
3331
+ //#region src/compile/parse/scopeStyles.ts
3332
+ function scopeStyles(status) {
3333
+ let selectors = [];
3334
+ for (let component of status.components) if (component.style && component.markup) {
3335
+ for (let block of component.style.blocks) collectStyleSelectors(block, selectors);
3336
+ scopeStylesOnNode(component.markup, selectors);
3337
+ }
3338
+ }
3339
+ function scopeStylesOnNode(node, selectors) {
3340
+ if (isElementNode(node) || isComponentNode(node)) {
3341
+ let scopeStyles$1 = selectors.includes(node.tagName);
3342
+ if (!scopeStyles$1) for (let a of node.attributes) {
3343
+ if (a.name === "class" && a.reactive) scopeStyles$1 = true;
3344
+ else if (a.name === "id" && a.value) scopeStyles$1 = selectors.includes(`#${trimQuotes(a.value)}`);
3345
+ else if (a.name === "class" && a.value) scopeStyles$1 = selectors.includes(`.${trimQuotes(a.value)}`);
3346
+ if (scopeStyles$1) break;
3347
+ }
3348
+ node.scopeStyles = scopeStyles$1;
3349
+ }
3350
+ if (isParentNode(node)) for (let child of node.children) scopeStylesOnNode(child, selectors);
3351
+ }
3352
+ function collectStyleSelectors(block, selectors) {
3353
+ for (let s of block.selector.split(/[\s*,>+~]/)) selectors.push(s);
3354
+ }
3355
+
3356
+ //#endregion
3357
+ //#region src/compile/parse/parseCode.ts
3358
+ function parseCode(source) {
3359
+ const status = {
3360
+ source,
3361
+ i: 0,
3362
+ marker: 0,
3363
+ level: 0,
3364
+ imports: [],
3365
+ script: [],
3366
+ components: [],
3367
+ errors: []
3368
+ };
3369
+ for (status.i; status.i < source.length; status.i++) if (consumeScriptComments(status)) {} else if (status.source[status.i] === "{") status.level += 1;
3370
+ else if (status.source[status.i] === "}") {
3371
+ status.level -= 1;
3372
+ if (status.level === 0) parseComponentEnd(status);
3373
+ } else if (accept("function", status)) {
3374
+ if (consumeSpace(status)) if (/[A-Z]/.test(source[status.i])) parseComponentStart(status);
3375
+ else status.i--;
3376
+ } else if (accept("const", status)) {
3377
+ if (consumeSpace(status)) if (/[A-Z]/.test(source[status.i])) {
3378
+ const start = status.i;
3379
+ consumeAlphaNumeric(status);
3380
+ consumeSpace(status);
3381
+ if (accept("=", status)) {
3382
+ consumeSpace(status);
3383
+ if (accept("(", status, false)) {
3384
+ status.i = start;
3385
+ parseComponentStart(status);
3386
+ }
3387
+ }
3388
+ } else status.i--;
3389
+ } else if (accept("export", status)) {
3390
+ const start = status.i;
3391
+ if (consumeSpace(status) && accept("default", status) && consumeSpace(status) && accept("(", status, false)) parseComponentStart(status);
3392
+ else status.i = start;
3393
+ } else if (accept("@render", status, false)) parseComponentRender(status);
3394
+ else if (accept("@head", status, false)) parseComponentHead(status);
3395
+ else if (accept("@style", status, false)) parseComponentStyle(status);
3396
+ status.script.push({
3397
+ script: source.substring(status.marker, source.length),
3398
+ range: {
3399
+ start: status.marker,
3400
+ end: source.length
3401
+ }
3402
+ });
3403
+ scopeStyles(status);
3404
+ const ok = !status.errors.length;
3405
+ if (!ok) status.errors = status.errors.sort((a, b) => a.startIndex - b.startIndex);
3406
+ return {
3407
+ ok,
3408
+ errors: status.errors,
3409
+ template: ok ? {
3410
+ imports: status.imports,
3411
+ script: status.script,
3412
+ components: status.components.map((c) => {
3413
+ return {
3414
+ start: c.start,
3415
+ name: c.name,
3416
+ exported: c.exported,
3417
+ default: c.default,
3418
+ documentation: c.documentation,
3419
+ params: c.params,
3420
+ markup: c.markup,
3421
+ head: c.head,
3422
+ style: c.style,
3423
+ propsType: c.propsType,
3424
+ props: c.props,
3425
+ contextProps: c.contextProps,
3426
+ slotProps: c.slotProps,
3427
+ needsContext: c.needsContext
3428
+ };
3429
+ })
3430
+ } : void 0
3431
+ };
3432
+ }
3433
+ function parseComponentStart(status) {
3434
+ let source = status.source.substring(status.marker, status.i);
3435
+ let exported = /export\s+(default\s+)*(function\s+|const\s+)*$/.test(source);
3436
+ let def = /export\s+default\s+(function\s+|const\s+)*$/.test(source);
3437
+ let isConst = /const\s+$/.test(source);
3438
+ let isAnon = /export default\s+$/.test(source);
3439
+ let componentStart = status.i;
3440
+ let name = consumeAlphaNumeric(status);
3441
+ const current = {
3442
+ start: componentStart,
3443
+ name,
3444
+ exported,
3445
+ default: def
3446
+ };
3447
+ status.components.push(current);
3448
+ let presource = source.substring(0, status.i).trimEnd();
3449
+ let lastNewline = presource.lastIndexOf("\n");
3450
+ if (lastNewline !== -1) {
3451
+ presource = presource.substring(0, lastNewline).trimEnd();
3452
+ if (presource.endsWith("*/")) {
3453
+ for (let i = presource.length; i >= 0; i--) if (presource.substring(i, i + 3) === "/**") {
3454
+ current.documentation = presource.substring(i);
3455
+ break;
3456
+ }
3457
+ }
3458
+ }
3459
+ let start = -1;
3460
+ let end = -1;
3461
+ let level = 0;
3462
+ for (status.i; status.i < status.source.length; status.i++) {
3463
+ const char = status.source[status.i];
3464
+ if (consumeScriptComments(status)) {} else if (char === "(") {
3465
+ level += 1;
3466
+ if (start === -1) start = status.i + 1;
3467
+ } else if (char === ")") {
3468
+ level -= 1;
3469
+ if (level === 0) {
3470
+ end = status.i;
3471
+ break;
3472
+ }
3473
+ }
3474
+ }
3475
+ status.script.push({
3476
+ script: status.source.substring(status.marker, start),
3477
+ range: {
3478
+ start: status.marker,
3479
+ end: start
3480
+ }
3481
+ });
3482
+ status.script.push({
3483
+ script: "/* @params */",
3484
+ range: {
3485
+ start: 0,
3486
+ end: 0
3487
+ }
3488
+ });
3489
+ current.params = status.source.substring(start, end).trim() || void 0;
3490
+ const paramsMatch = current.params?.match(/\$props:\s*([$A-Za-z0-9]+)/);
3491
+ if (paramsMatch) {
3492
+ let propsTypeName = paramsMatch[1];
3493
+ let propsTypeStart = status.source.search(/* @__PURE__ */ new RegExp(`interface\\s+${propsTypeName}`));
3494
+ if (propsTypeStart === -1) propsTypeStart = status.source.search(/* @__PURE__ */ new RegExp(`type\\s+${propsTypeName}`));
3495
+ if (propsTypeStart !== -1) {
3496
+ let bracesStart = status.source.indexOf("{", propsTypeStart);
3497
+ if (bracesStart !== -1) {
3498
+ const status2 = {
3499
+ source: status.source,
3500
+ i: bracesStart + 1,
3501
+ marker: 0,
3502
+ level: 0,
3503
+ imports: [],
3504
+ script: [],
3505
+ components: [],
3506
+ errors: []
3507
+ };
3508
+ const propsType = parseInlineScript(status2);
3509
+ if (propsType) current.propsType = `${status.source.substring(propsTypeStart, bracesStart)}{${propsType}}`;
3510
+ }
3511
+ }
3512
+ }
3513
+ status.marker = end;
3514
+ status.i = status.marker;
3515
+ accept(")", status);
3516
+ consumeSpace(status);
3517
+ if (isConst || isAnon) {
3518
+ accept("=>", status);
3519
+ consumeSpace(status);
3520
+ }
3521
+ accept("{", status);
3522
+ status.level += 1;
3523
+ const postFunctionChunk = {
3524
+ script: status.source.substring(status.marker, status.i),
3525
+ range: {
3526
+ start: status.marker,
3527
+ end: status.i
3528
+ }
3529
+ };
3530
+ if (/\)\s+\{/.test(postFunctionChunk.script)) postFunctionChunk.script = ") /* @return_type */ {";
3531
+ status.script.push(postFunctionChunk);
3532
+ status.script.push({
3533
+ script: "/* @start */",
3534
+ range: {
3535
+ start: 0,
3536
+ end: 0
3537
+ }
3538
+ });
3539
+ status.marker = status.i;
3540
+ const space = consumeSpace(status);
3541
+ status.script.push({
3542
+ script: space,
3543
+ range: {
3544
+ start: status.marker,
3545
+ end: status.i
3546
+ }
3547
+ });
3548
+ status.marker = status.i;
3549
+ status.i -= 1;
3550
+ }
3551
+ function parseComponentRender(status) {
3552
+ const current = status.components.at(-1);
3553
+ if (!current) return;
3554
+ if (current.markup) addError(status, `Multiple @render sections`, status.i, status.i + 7);
3555
+ status.script.push({
3556
+ script: status.source.substring(status.marker, status.i),
3557
+ range: {
3558
+ start: status.marker,
3559
+ end: status.i
3560
+ }
3561
+ });
3562
+ status.script.push({
3563
+ script: "/* @render */",
3564
+ range: {
3565
+ start: 0,
3566
+ end: 0
3567
+ }
3568
+ });
3569
+ accept("@render", status);
3570
+ consumeSpace(status);
3571
+ if (accept("{", status)) {
3572
+ parseMarkup(status, status.source);
3573
+ accept("}", status);
3574
+ }
3575
+ status.marker = status.i;
3576
+ }
3577
+ function parseComponentHead(status) {
3578
+ const current = status.components.at(-1);
3579
+ if (!current) return;
3580
+ if (current.head) addError(status, `Multiple @head sections`, status.i, status.i + 5);
3581
+ status.script.push({
3582
+ script: status.source.substring(status.marker, status.i),
3583
+ range: {
3584
+ start: status.marker,
3585
+ end: status.i
3586
+ }
3587
+ });
3588
+ status.script.push({
3589
+ script: "/* @head */",
3590
+ range: {
3591
+ start: 0,
3592
+ end: 0
3593
+ }
3594
+ });
3595
+ status.components.push({ start: status.i });
3596
+ accept("@head", status);
3597
+ consumeSpace(status);
3598
+ if (accept("{", status)) {
3599
+ parseMarkup(status, status.source);
3600
+ accept("}", status);
3601
+ }
3602
+ current.head = status.components.pop()?.markup;
3603
+ status.marker = status.i;
3604
+ }
3605
+ function parseComponentStyle(status) {
3606
+ const current = status.components.at(-1);
3607
+ if (!current) return;
3608
+ if (current.style) addError(status, `Multiple @style sections`, status.i, status.i + 6);
3609
+ status.script.push({
3610
+ script: status.source.substring(status.marker, status.i),
3611
+ range: {
3612
+ start: status.marker,
3613
+ end: status.i
3614
+ }
3615
+ });
3616
+ status.script.push({
3617
+ script: "/* @style */",
3618
+ range: {
3619
+ start: 0,
3620
+ end: 0
3621
+ }
3622
+ });
3623
+ let start = -1;
3624
+ let end = status.source.length;
3625
+ let level = 0;
3626
+ let styleSource = "";
3627
+ for (; status.i < status.source.length; status.i++) {
3628
+ const char = status.source[status.i];
3629
+ const nextChar = status.source[status.i + 1];
3630
+ if (char === "/" && nextChar === "/") status.i = status.source.indexOf("\n", status.i);
3631
+ else if (char === "/" && nextChar === "*") status.i = status.source.indexOf("*/", status.i) + 1;
3632
+ else if (char === "\"" || char === "'") {
3633
+ let start$1 = status.i;
3634
+ status.i = endOfString(char, status.source, start$1);
3635
+ styleSource += status.source.substring(start$1, status.i + 1);
3636
+ } else if (char === "`") {
3637
+ let start$1 = status.i;
3638
+ status.i = endOfTemplateString(status.source, start$1);
3639
+ styleSource += status.source.substring(start$1, status.i + 1);
3640
+ } else if (char === "{") {
3641
+ level += 1;
3642
+ if (start === -1) start = status.i + 1;
3643
+ else styleSource += char;
3644
+ } else if (char === "}") {
3645
+ level -= 1;
3646
+ if (level === 0) {
3647
+ end = status.i - 1;
3648
+ break;
3649
+ } else styleSource += char;
3650
+ } else if (start !== -1) styleSource += char;
3651
+ }
3652
+ status.i = start;
3653
+ parseStyles(styleSource.trim(), status);
3654
+ status.i = end + 2;
3655
+ status.marker = status.i;
3656
+ }
3657
+ function parseComponentEnd(status) {
3658
+ const current = status.components.at(-1);
3659
+ if (!current) return;
3660
+ status.script.push({
3661
+ script: status.source.substring(status.marker, status.i),
3662
+ range: {
3663
+ start: status.marker,
3664
+ end: status.i
3665
+ }
3666
+ });
3667
+ status.script.push({
3668
+ script: "/* @end */",
3669
+ range: {
3670
+ start: 0,
3671
+ end: 0
3672
+ }
3673
+ });
3674
+ const componentSource = status.source.substring(current.start || 0, status.i);
3675
+ current.props = getPropsUsage(componentSource);
3676
+ current.contextProps = getContextUsage(componentSource);
3677
+ if (current.markup && isElementNode(current.markup.children[0]) && current.markup.children[0].tagName === "html" && isSpaceNode(current.markup.children[0].children[0])) current.markup.children.splice(1, 1);
3678
+ status.marker = status.i;
3679
+ }
3680
+ function getPropsUsage(source) {
3681
+ const propsMatches = source.matchAll(/\$props\s*(?:\.([\d\w]+)|\[([^\]]+)\])/g);
3682
+ const props = [];
3683
+ for (let match of propsMatches) {
3684
+ const name = trimQuotes(match[1] || match[2]);
3685
+ if (!props.includes(name)) props.push(name);
3686
+ }
3687
+ return props.length ? props : void 0;
3688
+ }
3689
+ function getContextUsage(source) {
3690
+ const contextsMatches = source.matchAll(/\$context\s*(?:\.([\d\w]+)|\[([^\]]+)\])/g);
3691
+ const contexts = [];
3692
+ for (let match of contextsMatches) {
3693
+ const name = trimQuotes(match[1] || match[2]);
3694
+ if (!contexts.includes(name)) contexts.push(name);
3695
+ }
3696
+ return contexts.length ? contexts : void 0;
3697
+ }
3698
+ function consumeScriptComments(status) {
3699
+ const char = status.source[status.i];
3700
+ const nextChar = status.source[status.i + 1];
3701
+ if (char === "/" && nextChar === "/") {
3702
+ status.i = status.source.indexOf("\n", status.i);
3703
+ return true;
3704
+ } else if (char === "/" && nextChar === "*") {
3705
+ status.i = status.source.indexOf("*/", status.i) + 1;
3706
+ return true;
3707
+ } else if (char === "\"" || char === "'") {
3708
+ status.i = endOfString(char, status.source, status.i);
3709
+ return true;
3710
+ } else if (char === "`") {
3711
+ status.i = endOfTemplateString(status.source, status.i);
3712
+ return true;
3713
+ }
3714
+ return false;
3715
+ }
3716
+
3717
+ //#endregion
3718
+ //#region src/compile/parse.ts
3719
+ /**
3720
+ * Parses source code into a component template
3721
+ *
3722
+ * @param source The source code
3723
+ *
3724
+ * @returns A result indicating whether parsing was ok, and if so, containing
3725
+ * the component template's parts such as script, markup and styles
3726
+ */
3727
+ function parse(source) {
3728
+ return parseCode(source);
3729
+ }
3730
+
3731
+ //#endregion
3732
+ exports.build = build;
3733
+ exports.buildType = buildType;
3734
+ exports.parse = parse;
3735
+ //# sourceMappingURL=compile.cjs.map