@hyperfixi/core 3.3.0 → 4.0.1

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 (378) hide show
  1. package/README.md +57 -179
  2. package/dist/ast-utils/index.cjs +74 -806
  3. package/dist/ast-utils/index.d.ts +1 -1
  4. package/dist/ast-utils/index.mjs +74 -805
  5. package/dist/ast-utils/interchange/engine-positions.d.ts +3 -0
  6. package/dist/ast-utils/interchange/index.d.ts +1 -2
  7. package/dist/hyperfixi.js +19 -2
  8. package/dist/index.d.ts +2 -22
  9. package/dist/index.mjs +3 -29128
  10. package/dist/lsp-metadata.cjs +77 -73
  11. package/dist/lsp-metadata.d.ts +4 -4
  12. package/dist/lsp-metadata.mjs +77 -73
  13. package/dist/metadata.cjs +34 -266
  14. package/dist/metadata.d.ts +31 -26
  15. package/dist/metadata.mjs +34 -266
  16. package/dist/multilingual/index.cjs +16 -382
  17. package/dist/multilingual/index.d.ts +4 -32
  18. package/dist/multilingual/index.mjs +15 -377
  19. package/dist/reference/index.cjs +67 -216
  20. package/dist/reference/index.d.ts +0 -3
  21. package/dist/reference/index.mjs +68 -216
  22. package/dist/version.d.ts +1 -1
  23. package/package.json +13 -179
  24. package/dist/__test-utils__/context-builders.d.ts +0 -42
  25. package/dist/__test-utils__/error-testing.d.ts +0 -18
  26. package/dist/__test-utils__/index.d.ts +0 -6
  27. package/dist/__test-utils__/mock-types.d.ts +0 -57
  28. package/dist/__test-utils__/parser-context-mock.d.ts +0 -7
  29. package/dist/__test-utils__/parser-helpers.d.ts +0 -38
  30. package/dist/api/hyperscript-api.d.ts +0 -90
  31. package/dist/api/lokascript-api.d.ts +0 -9
  32. package/dist/ast/command-slots.d.ts +0 -140
  33. package/dist/ast/guards.d.ts +0 -15
  34. package/dist/ast/legacy.d.ts +0 -15
  35. package/dist/ast/nodes.d.ts +0 -243
  36. package/dist/ast-utils/interchange/from-core.d.ts +0 -12
  37. package/dist/ast-utils/interchange/to-core.d.ts +0 -8
  38. package/dist/behaviors/boosted.d.ts +0 -29
  39. package/dist/behaviors/history-swap.d.ts +0 -24
  40. package/dist/behaviors/index.cjs +0 -1155
  41. package/dist/behaviors/index.d.ts +0 -4
  42. package/dist/behaviors/index.mjs +0 -1145
  43. package/dist/bundle-generator/executor-core.d.ts +0 -4
  44. package/dist/bundle-generator/generator.d.ts +0 -4
  45. package/dist/bundle-generator/index.cjs +0 -2804
  46. package/dist/bundle-generator/index.d.ts +0 -6
  47. package/dist/bundle-generator/index.mjs +0 -2779
  48. package/dist/bundle-generator/parser-templates.d.ts +0 -6
  49. package/dist/bundle-generator/template-capabilities.d.ts +0 -12
  50. package/dist/bundle-generator/templates.d.ts +0 -12
  51. package/dist/bundle-generator/types.d.ts +0 -34
  52. package/dist/chunks/bridge-CI9SOl8u.js +0 -2
  53. package/dist/chunks/browser-modular-7CpI5VF2.js +0 -2
  54. package/dist/chunks/index-BwXDEK0m.js +0 -2
  55. package/dist/chunks/index-DQi2o8Lk.js +0 -2
  56. package/dist/chunks/index-uCOQ8Qn0.js +0 -2
  57. package/dist/commands/advanced/js.d.ts +0 -40
  58. package/dist/commands/animation/measure.d.ts +0 -43
  59. package/dist/commands/animation/settle.d.ts +0 -38
  60. package/dist/commands/animation/start-view-transition.d.ts +0 -38
  61. package/dist/commands/animation/take.d.ts +0 -41
  62. package/dist/commands/animation/transition.d.ts +0 -49
  63. package/dist/commands/async/fetch.d.ts +0 -61
  64. package/dist/commands/async/wait.d.ts +0 -51
  65. package/dist/commands/behaviors/install.d.ts +0 -40
  66. package/dist/commands/content/append.d.ts +0 -26
  67. package/dist/commands/content/insertion-base.d.ts +0 -60
  68. package/dist/commands/content/prepend.d.ts +0 -26
  69. package/dist/commands/control-flow/break.d.ts +0 -29
  70. package/dist/commands/control-flow/continue.d.ts +0 -29
  71. package/dist/commands/control-flow/exit.d.ts +0 -29
  72. package/dist/commands/control-flow/halt.d.ts +0 -39
  73. package/dist/commands/control-flow/if.d.ts +0 -58
  74. package/dist/commands/control-flow/repeat.d.ts +0 -50
  75. package/dist/commands/control-flow/return.d.ts +0 -33
  76. package/dist/commands/control-flow/signal-base.d.ts +0 -18
  77. package/dist/commands/control-flow/throw.d.ts +0 -34
  78. package/dist/commands/control-flow/unless.d.ts +0 -3
  79. package/dist/commands/data/clear.d.ts +0 -37
  80. package/dist/commands/data/decrement.d.ts +0 -3
  81. package/dist/commands/data/default.d.ts +0 -60
  82. package/dist/commands/data/get.d.ts +0 -35
  83. package/dist/commands/data/increment.d.ts +0 -42
  84. package/dist/commands/data/set.d.ts +0 -76
  85. package/dist/commands/decorators/index.d.ts +0 -14
  86. package/dist/commands/dom/add.d.ts +0 -44
  87. package/dist/commands/dom/close.d.ts +0 -32
  88. package/dist/commands/dom/dom-modification-base.d.ts +0 -48
  89. package/dist/commands/dom/empty.d.ts +0 -32
  90. package/dist/commands/dom/hide.d.ts +0 -28
  91. package/dist/commands/dom/make.d.ts +0 -34
  92. package/dist/commands/dom/open.d.ts +0 -34
  93. package/dist/commands/dom/process-partials.d.ts +0 -51
  94. package/dist/commands/dom/put.d.ts +0 -42
  95. package/dist/commands/dom/remove.d.ts +0 -46
  96. package/dist/commands/dom/reset.d.ts +0 -32
  97. package/dist/commands/dom/select.d.ts +0 -32
  98. package/dist/commands/dom/show.d.ts +0 -29
  99. package/dist/commands/dom/swap.d.ts +0 -65
  100. package/dist/commands/dom/toggle.d.ts +0 -69
  101. package/dist/commands/dom/visibility-base.d.ts +0 -22
  102. package/dist/commands/events/send.d.ts +0 -3
  103. package/dist/commands/events/trigger.d.ts +0 -49
  104. package/dist/commands/execution/blur.d.ts +0 -32
  105. package/dist/commands/execution/call.d.ts +0 -35
  106. package/dist/commands/execution/focus.d.ts +0 -32
  107. package/dist/commands/execution/pseudo-command.d.ts +0 -41
  108. package/dist/commands/helpers/attribute-manipulation.d.ts +0 -11
  109. package/dist/commands/helpers/attribute-target.d.ts +0 -9
  110. package/dist/commands/helpers/batch-dom-operations.d.ts +0 -12
  111. package/dist/commands/helpers/body-ops.d.ts +0 -10
  112. package/dist/commands/helpers/class-manipulation.d.ts +0 -11
  113. package/dist/commands/helpers/condition-helpers.d.ts +0 -4
  114. package/dist/commands/helpers/dom-mutation.d.ts +0 -16
  115. package/dist/commands/helpers/duration-parsing.d.ts +0 -8
  116. package/dist/commands/helpers/element-property-access.d.ts +0 -7
  117. package/dist/commands/helpers/element-resolution.d.ts +0 -16
  118. package/dist/commands/helpers/error-helpers.d.ts +0 -17
  119. package/dist/commands/helpers/event-helpers.d.ts +0 -13
  120. package/dist/commands/helpers/event-waiting.d.ts +0 -37
  121. package/dist/commands/helpers/index.d.ts +0 -32
  122. package/dist/commands/helpers/input-validator.d.ts +0 -23
  123. package/dist/commands/helpers/loop-executor.d.ts +0 -56
  124. package/dist/commands/helpers/numeric-target-parser.d.ts +0 -21
  125. package/dist/commands/helpers/property-target.d.ts +0 -20
  126. package/dist/commands/helpers/selector-type-detection.d.ts +0 -24
  127. package/dist/commands/helpers/slots.d.ts +0 -5
  128. package/dist/commands/helpers/smart-element.d.ts +0 -16
  129. package/dist/commands/helpers/style-manipulation.d.ts +0 -16
  130. package/dist/commands/helpers/target-elements.d.ts +0 -5
  131. package/dist/commands/helpers/temporal-modifiers.d.ts +0 -15
  132. package/dist/commands/helpers/url-argument-parser.d.ts +0 -13
  133. package/dist/commands/helpers/url-validation.d.ts +0 -7
  134. package/dist/commands/helpers/variable-access.d.ts +0 -13
  135. package/dist/commands/helpers/visibility-target-parser.d.ts +0 -15
  136. package/dist/commands/helpers/write-target.d.ts +0 -42
  137. package/dist/commands/index.cjs +0 -24168
  138. package/dist/commands/index.d.ts +0 -171
  139. package/dist/commands/index.mjs +0 -23981
  140. package/dist/commands/manifest.d.ts +0 -17
  141. package/dist/commands/navigation/go.d.ts +0 -58
  142. package/dist/commands/navigation/push-url.d.ts +0 -48
  143. package/dist/commands/navigation/replace-url.d.ts +0 -3
  144. package/dist/commands/navigation/scroll-to.d.ts +0 -43
  145. package/dist/commands/templates/render.d.ts +0 -47
  146. package/dist/commands/utility/beep.d.ts +0 -41
  147. package/dist/commands/utility/breakpoint.d.ts +0 -32
  148. package/dist/commands/utility/copy.d.ts +0 -41
  149. package/dist/commands/utility/log.d.ts +0 -36
  150. package/dist/commands/utility/pick.d.ts +0 -47
  151. package/dist/commands/utility/tell.d.ts +0 -39
  152. package/dist/compatibility/browser-bundle-classic.d.ts +0 -17
  153. package/dist/compatibility/browser-bundle-hybrid-complete.d.ts +0 -22
  154. package/dist/compatibility/browser-bundle-hybrid-hx.d.ts +0 -43
  155. package/dist/compatibility/browser-bundle-lite.d.ts +0 -15
  156. package/dist/compatibility/browser-bundle-modular.d.ts +0 -18
  157. package/dist/compatibility/browser-bundle-multilingual.d.ts +0 -19
  158. package/dist/compatibility/browser-bundle-semantic-complete.d.ts +0 -24
  159. package/dist/compatibility/browser-bundle-textshelf-minimal.d.ts +0 -16
  160. package/dist/compatibility/browser-bundle-textshelf-profile.d.ts +0 -18
  161. package/dist/compatibility/browser-modular.d.ts +0 -42
  162. package/dist/compatibility/browser-tests/helpers/semantic-page.d.ts +0 -3
  163. package/dist/compatibility/browser-tests/test-utils.d.ts +0 -21
  164. package/dist/compatibility/bundle-shell.d.ts +0 -13
  165. package/dist/compatibility/bundle-sources.d.ts +0 -4
  166. package/dist/compatibility/eval-hyperscript.d.ts +0 -16
  167. package/dist/compatibility/hyperscript-adapter.d.ts +0 -38
  168. package/dist/core/ast-property-utils.d.ts +0 -2
  169. package/dist/core/context.d.ts +0 -19
  170. package/dist/core/dom.d.ts +0 -15
  171. package/dist/core/evaluator-types.d.ts +0 -5
  172. package/dist/core/events.d.ts +0 -48
  173. package/dist/core/executor.d.ts +0 -34
  174. package/dist/core/expression-evaluator.d.ts +0 -6
  175. package/dist/core/expression-registry.d.ts +0 -8
  176. package/dist/core/scope-hooks.d.ts +0 -24
  177. package/dist/debug/debug-controller.d.ts +0 -62
  178. package/dist/debug/index.d.ts +0 -5
  179. package/dist/dom/attribute-processor.d.ts +0 -75
  180. package/dist/dom/detect-language.d.ts +0 -3
  181. package/dist/dom/minimal-attribute-processor.d.ts +0 -20
  182. package/dist/expressions/base-expression.d.ts +0 -27
  183. package/dist/expressions/bundles/common-expressions.d.ts +0 -10
  184. package/dist/expressions/bundles/core-expressions.d.ts +0 -8
  185. package/dist/expressions/bundles/full-expressions.d.ts +0 -11
  186. package/dist/expressions/bundles/index.d.ts +0 -7
  187. package/dist/expressions/collection/index.d.ts +0 -10
  188. package/dist/expressions/conversion/index.d.ts +0 -31
  189. package/dist/expressions/expression-tiers.d.ts +0 -13
  190. package/dist/expressions/index.cjs +0 -4331
  191. package/dist/expressions/index.d.ts +0 -13
  192. package/dist/expressions/index.mjs +0 -4312
  193. package/dist/expressions/logical/index.d.ts +0 -61
  194. package/dist/expressions/mathematical/index.d.ts +0 -80
  195. package/dist/expressions/positional/index.d.ts +0 -31
  196. package/dist/expressions/properties/index.d.ts +0 -27
  197. package/dist/expressions/property-access-utils.d.ts +0 -23
  198. package/dist/expressions/references/index.d.ts +0 -39
  199. package/dist/expressions/shared/comparison-utils.d.ts +0 -10
  200. package/dist/expressions/shared/index.d.ts +0 -10
  201. package/dist/expressions/shared/number-utils.d.ts +0 -8
  202. package/dist/expressions/shared/tracking.d.ts +0 -20
  203. package/dist/expressions/shared/validation-utils.d.ts +0 -13
  204. package/dist/expressions/special/index.d.ts +0 -78
  205. package/dist/expressions/type-helpers.d.ts +0 -11
  206. package/dist/expressions/type-registry.d.ts +0 -57
  207. package/dist/expressions/validation-helpers.d.ts +0 -15
  208. package/dist/htmx/hcon.d.ts +0 -9
  209. package/dist/htmx/htmx-attribute-processor.d.ts +0 -120
  210. package/dist/htmx/htmx-translator.d.ts +0 -22
  211. package/dist/htmx/i18n-hooks.d.ts +0 -18
  212. package/dist/htmx/i18n-orchestrator.d.ts +0 -16
  213. package/dist/htmx/index.d.ts +0 -3
  214. package/dist/htmx/lang-resolver.d.ts +0 -3
  215. package/dist/htmx/sse.d.ts +0 -60
  216. package/dist/htmx/ws.d.ts +0 -59
  217. package/dist/hyperfixi-browser-classic-i18n.js +0 -2
  218. package/dist/hyperfixi-browser.js +0 -2
  219. package/dist/hyperfixi-classic-i18n.js +0 -2
  220. package/dist/hyperfixi-hx-v4.js +0 -1
  221. package/dist/hyperfixi-hx.js +0 -1
  222. package/dist/hyperfixi-hybrid-complete.js +0 -1
  223. package/dist/hyperfixi-hybrid-hx.js +0 -1
  224. package/dist/hyperfixi-multilingual.js +0 -2
  225. package/dist/hyperfixi.mjs +0 -2
  226. package/dist/i18n/error-catalog.d.ts +0 -12
  227. package/dist/index.cjs +0 -29159
  228. package/dist/index.min.js +0 -2
  229. package/dist/lib/dom-globals-shim.d.ts +0 -2
  230. package/dist/lib/index.d.ts +0 -4
  231. package/dist/lib/morph-adapter.d.ts +0 -9
  232. package/dist/lib/swap-executor.d.ts +0 -12
  233. package/dist/lib/view-transitions.d.ts +0 -7
  234. package/dist/lokascript-browser-classic-i18n.js +0 -2
  235. package/dist/lokascript-browser.js +0 -2
  236. package/dist/lokascript-hybrid-complete.js +0 -1
  237. package/dist/lokascript-hybrid-hx.js +0 -1
  238. package/dist/lokascript-multilingual.js +0 -2
  239. package/dist/lse/index.cjs +0 -84
  240. package/dist/lse/index.d.ts +0 -15
  241. package/dist/lse/index.mjs +0 -71
  242. package/dist/multilingual/bridge.d.ts +0 -38
  243. package/dist/multilingual/schema-roles.d.ts +0 -3
  244. package/dist/parser/__types__/test-helpers.d.ts +0 -25
  245. package/dist/parser/command-grammar.d.ts +0 -14
  246. package/dist/parser/command-node-builder.d.ts +0 -46
  247. package/dist/parser/command-parsers/animation-commands.d.ts +0 -6
  248. package/dist/parser/command-parsers/async-commands.d.ts +0 -5
  249. package/dist/parser/command-parsers/control-flow-commands.d.ts +0 -7
  250. package/dist/parser/command-parsers/declared-commands.d.ts +0 -6
  251. package/dist/parser/command-parsers/dom-commands.d.ts +0 -11
  252. package/dist/parser/command-parsers/event-commands.d.ts +0 -4
  253. package/dist/parser/command-parsers/navigation-commands.d.ts +0 -6
  254. package/dist/parser/command-parsers/utility-commands.d.ts +0 -14
  255. package/dist/parser/command-parsers/variable-commands.d.ts +0 -12
  256. package/dist/parser/error-handler.d.ts +0 -34
  257. package/dist/parser/extensions.d.ts +0 -43
  258. package/dist/parser/full-parser.cjs +0 -7943
  259. package/dist/parser/full-parser.d.ts +0 -4
  260. package/dist/parser/full-parser.mjs +0 -7940
  261. package/dist/parser/helpers/ast-helpers.d.ts +0 -24
  262. package/dist/parser/helpers/parsing-helpers.d.ts +0 -19
  263. package/dist/parser/helpers/token-helpers.d.ts +0 -28
  264. package/dist/parser/hybrid/aliases.cjs +0 -44
  265. package/dist/parser/hybrid/aliases.d.ts +0 -7
  266. package/dist/parser/hybrid/aliases.mjs +0 -37
  267. package/dist/parser/hybrid/ast-types.cjs +0 -3
  268. package/dist/parser/hybrid/ast-types.d.ts +0 -97
  269. package/dist/parser/hybrid/ast-types.mjs +0 -2
  270. package/dist/parser/hybrid/index.cjs +0 -1185
  271. package/dist/parser/hybrid/index.d.ts +0 -6
  272. package/dist/parser/hybrid/index.mjs +0 -1175
  273. package/dist/parser/hybrid/parser-core.cjs +0 -1171
  274. package/dist/parser/hybrid/parser-core.d.ts +0 -69
  275. package/dist/parser/hybrid/parser-core.mjs +0 -1169
  276. package/dist/parser/hybrid/tokenizer.cjs +0 -255
  277. package/dist/parser/hybrid/tokenizer.d.ts +0 -9
  278. package/dist/parser/hybrid/tokenizer.mjs +0 -252
  279. package/dist/parser/hybrid-parser.cjs +0 -1249
  280. package/dist/parser/hybrid-parser.d.ts +0 -10
  281. package/dist/parser/hybrid-parser.mjs +0 -1242
  282. package/dist/parser/parser-constants.d.ts +0 -100
  283. package/dist/parser/parser-interface.d.ts +0 -12
  284. package/dist/parser/parser-types.d.ts +0 -164
  285. package/dist/parser/parser.d.ts +0 -165
  286. package/dist/parser/pratt-parser.d.ts +0 -41
  287. package/dist/parser/regex-parser.cjs +0 -422
  288. package/dist/parser/regex-parser.d.ts +0 -4
  289. package/dist/parser/regex-parser.mjs +0 -419
  290. package/dist/parser/runtime.d.ts +0 -14
  291. package/dist/parser/semantic-integration.d.ts +0 -17
  292. package/dist/parser/token-consumer.d.ts +0 -34
  293. package/dist/parser/token-predicates.d.ts +0 -77
  294. package/dist/parser/tokenizer.d.ts +0 -28
  295. package/dist/parser/types.d.ts +0 -105
  296. package/dist/performance/expression-cache.d.ts +0 -78
  297. package/dist/performance/integration.d.ts +0 -40
  298. package/dist/performance/production-monitor.d.ts +0 -67
  299. package/dist/registry/browser-types.cjs +0 -81
  300. package/dist/registry/browser-types.d.ts +0 -20
  301. package/dist/registry/browser-types.mjs +0 -76
  302. package/dist/registry/environment.cjs +0 -36
  303. package/dist/registry/environment.d.ts +0 -19
  304. package/dist/registry/environment.mjs +0 -30
  305. package/dist/registry/event-source-registry.d.ts +0 -54
  306. package/dist/registry/examples/server-commands.d.ts +0 -6
  307. package/dist/registry/examples/server-event-source.d.ts +0 -32
  308. package/dist/registry/index.cjs +0 -14055
  309. package/dist/registry/index.d.ts +0 -39
  310. package/dist/registry/index.mjs +0 -14039
  311. package/dist/registry/runtime-integration.d.ts +0 -23
  312. package/dist/registry/universal-types.cjs +0 -91
  313. package/dist/registry/universal-types.d.ts +0 -35
  314. package/dist/registry/universal-types.mjs +0 -86
  315. package/dist/runtime/cleanup-registry.d.ts +0 -47
  316. package/dist/runtime/command-adapter.d.ts +0 -69
  317. package/dist/runtime/environment.d.ts +0 -75
  318. package/dist/runtime/plugin.d.ts +0 -14
  319. package/dist/runtime/runtime-base.d.ts +0 -100
  320. package/dist/runtime/runtime-factory.d.ts +0 -29
  321. package/dist/runtime/runtime.d.ts +0 -20
  322. package/dist/runtime/temporal-modifiers.d.ts +0 -37
  323. package/dist/test-setup.d.ts +0 -28
  324. package/dist/test-utilities.d.ts +0 -39
  325. package/dist/types/base-types.d.ts +0 -231
  326. package/dist/types/code-fix.d.ts +0 -39
  327. package/dist/types/command-metadata.d.ts +0 -57
  328. package/dist/types/command-types.d.ts +0 -262
  329. package/dist/types/context-types.d.ts +0 -106
  330. package/dist/types/core-context.d.ts +0 -22
  331. package/dist/types/core.d.ts +0 -143
  332. package/dist/types/error-codes.d.ts +0 -207
  333. package/dist/types/expression-types.d.ts +0 -155
  334. package/dist/types/hooks.d.ts +0 -45
  335. package/dist/types/index.d.ts +0 -32
  336. package/dist/types/program.d.ts +0 -8
  337. package/dist/types/result.d.ts +0 -73
  338. package/dist/types/template-types.d.ts +0 -162
  339. package/dist/types/type-guards.d.ts +0 -24
  340. package/dist/types/unified-types.d.ts +0 -91
  341. package/dist/utils/beep.d.ts +0 -8
  342. package/dist/utils/debug-events.d.ts +0 -41
  343. package/dist/utils/debug.d.ts +0 -35
  344. package/dist/utils/dom-utils.d.ts +0 -16
  345. package/dist/utils/element-check.d.ts +0 -8
  346. package/dist/utils/keyboard-shortcuts.d.ts +0 -18
  347. package/dist/utils/performance.d.ts +0 -40
  348. package/dist/validation/command-pattern-validator.d.ts +0 -53
  349. package/dist/validation/common-validators.d.ts +0 -24
  350. package/dist/validation/lightweight-validators.d.ts +0 -113
  351. package/dist/validation/partial-validation-types.d.ts +0 -50
  352. package/dist/validation/partial-validator.d.ts +0 -6
  353. package/dist/validation/partial-warning-formatter.d.ts +0 -6
  354. package/dist/validation/validate-cli.d.ts +0 -41
  355. package/vocab/htmx/ar.js +0 -62
  356. package/vocab/htmx/bn.js +0 -65
  357. package/vocab/htmx/de.js +0 -83
  358. package/vocab/htmx/en.js +0 -24
  359. package/vocab/htmx/es.js +0 -79
  360. package/vocab/htmx/fr.js +0 -79
  361. package/vocab/htmx/he.js +0 -61
  362. package/vocab/htmx/hi.js +0 -81
  363. package/vocab/htmx/id.js +0 -76
  364. package/vocab/htmx/it.js +0 -79
  365. package/vocab/htmx/ja.js +0 -85
  366. package/vocab/htmx/ko.js +0 -81
  367. package/vocab/htmx/ms.js +0 -58
  368. package/vocab/htmx/pl.js +0 -80
  369. package/vocab/htmx/pt.js +0 -81
  370. package/vocab/htmx/qu.js +0 -83
  371. package/vocab/htmx/ru.js +0 -82
  372. package/vocab/htmx/sw.js +0 -79
  373. package/vocab/htmx/th.js +0 -67
  374. package/vocab/htmx/tl.js +0 -56
  375. package/vocab/htmx/tr.js +0 -86
  376. package/vocab/htmx/uk.js +0 -82
  377. package/vocab/htmx/vi.js +0 -59
  378. package/vocab/htmx/zh.js +0 -79
@@ -1,2779 +0,0 @@
1
- function stripTypes(code, format) {
2
- if (format === 'ts')
3
- return code;
4
- return (code
5
- .replace(/\s+as\s+\w+(?:\[\])?/g, '')
6
- .replace(/\((\w+):\s*\w+\)/g, '($1)')
7
- .replace(/\((\w+):\s*any\)/g, '($1)')
8
- .replace(/Promise<void>\[\]/g, 'Promise[]')
9
- .replace(/Promise<void>/g, 'Promise')
10
- .replace(/:\s*TransitionEvent/g, ''));
11
- }
12
- const COMMAND_IMPLEMENTATIONS_TS = {
13
- toggle: `
14
- case 'toggle': {
15
- const raw = getClassName(cmd.args[0]) || String(await evaluate(cmd.args[0], ctx));
16
- const targets = await getTarget();
17
- if (raw.startsWith('@')) {
18
- const attr = raw.slice(1);
19
- for (const el of targets) {
20
- if (el.hasAttribute(attr)) el.removeAttribute(attr);
21
- else el.setAttribute(attr, '');
22
- }
23
- } else {
24
- for (const el of targets) el.classList.toggle(raw);
25
- }
26
- ctx.it = targets.length === 1 ? targets[0] : targets;
27
- return ctx.it;
28
- }`,
29
- add: `
30
- case 'add': {
31
- const raw = getClassName(cmd.args[0]) || String(await evaluate(cmd.args[0], ctx));
32
- const targets = await getTarget();
33
- if (raw.startsWith('@')) {
34
- const attr = raw.slice(1);
35
- for (const el of targets) el.setAttribute(attr, '');
36
- } else {
37
- for (const el of targets) el.classList.add(raw);
38
- }
39
- ctx.it = targets.length === 1 ? targets[0] : targets;
40
- return ctx.it;
41
- }`,
42
- remove: `
43
- case 'remove': {
44
- const targets = await getTarget();
45
- for (const el of targets) el.remove();
46
- return null;
47
- }`,
48
- removeClass: `
49
- case 'removeClass': {
50
- const raw = getClassName(cmd.args[0]) || String(await evaluate(cmd.args[0], ctx));
51
- const targets = await getTarget();
52
- if (raw.startsWith('@')) {
53
- const attr = raw.slice(1);
54
- for (const el of targets) el.removeAttribute(attr);
55
- } else {
56
- for (const el of targets) el.classList.remove(raw);
57
- }
58
- return targets;
59
- }`,
60
- show: `
61
- case 'show': {
62
- const targets = await getTarget();
63
- for (const el of targets) {
64
- (el as HTMLElement).style.display = '';
65
- el.classList.remove('hidden');
66
- }
67
- return targets;
68
- }`,
69
- hide: `
70
- case 'hide': {
71
- const targets = await getTarget();
72
- for (const el of targets) (el as HTMLElement).style.display = 'none';
73
- return targets;
74
- }`,
75
- set: `
76
- case 'set': {
77
- const target = cmd.args[0];
78
- const value = await evaluate(cmd.args[1], ctx);
79
-
80
- if (target.type === 'variable') {
81
- const varName = target.name.slice(1);
82
- const map = target.scope === 'local' ? elemScope(ctx.me) : globalVars;
83
- map.set(varName, value);
84
- ctx.it = value;
85
- return value;
86
- }
87
-
88
- if (target.type === 'possessive' || target.type === 'member') {
89
- const obj = await evaluate(target.object, ctx);
90
- if (obj) {
91
- if (obj instanceof Element && isStyleProp(target.property)) {
92
- setStyleProp(obj, target.property, value);
93
- } else {
94
- (obj as any)[target.property] = value;
95
- }
96
- ctx.it = value;
97
- return value;
98
- }
99
- }
100
-
101
- ctx.it = value;
102
- return value;
103
- }`,
104
- get: `
105
- case 'get': {
106
- const value = await evaluate(cmd.args[0], ctx);
107
- ctx.it = value;
108
- return value;
109
- }`,
110
- wait: `
111
- case 'wait': {
112
- const duration = await evaluate(cmd.args[0], ctx);
113
- const ms = typeof duration === 'number' ? duration : parseInt(String(duration));
114
- await new Promise(resolve => setTimeout(resolve, ms));
115
- return ms;
116
- }
117
-
118
- case 'waitFor': {
119
- const eventName = await evaluate(cmd.args[0], ctx);
120
- const targets = await getTarget();
121
- const target = targets[0] || ctx.me;
122
- return new Promise(resolve => {
123
- target.addEventListener(
124
- String(eventName),
125
- e => {
126
- ctx.it = e;
127
- resolve(e);
128
- },
129
- { once: true }
130
- );
131
- });
132
- }`,
133
- transition: `
134
- case 'transition': {
135
- const property = String(await evaluate(cmd.args[0], ctx)).replace(/^\\*/, '');
136
- const toValue = await evaluate(cmd.args[1], ctx);
137
- const durationVal = await evaluate(cmd.args[2], ctx);
138
- const duration = typeof durationVal === 'number' ? durationVal :
139
- String(durationVal).endsWith('ms') ? parseInt(String(durationVal)) :
140
- String(durationVal).endsWith('s') ? parseFloat(String(durationVal)) * 1000 :
141
- parseInt(String(durationVal)) || 300;
142
-
143
- const targets = await getTarget();
144
- const promises: Promise<void>[] = [];
145
-
146
- for (const el of targets) {
147
- const htmlEl = el as HTMLElement;
148
- const kebabProp = property.replace(/([A-Z])/g, '-$1').toLowerCase();
149
-
150
- const oldTransition = htmlEl.style.transition;
151
- htmlEl.style.transition = \`\${kebabProp} \${duration}ms ease\`;
152
- htmlEl.style.setProperty(kebabProp, String(toValue));
153
-
154
- promises.push(new Promise<void>(resolve => {
155
- const cleanup = () => {
156
- htmlEl.style.transition = oldTransition;
157
- resolve();
158
- };
159
-
160
- const onEnd = (e: TransitionEvent) => {
161
- if (e.propertyName === kebabProp) {
162
- htmlEl.removeEventListener('transitionend', onEnd);
163
- cleanup();
164
- }
165
- };
166
-
167
- htmlEl.addEventListener('transitionend', onEnd);
168
- setTimeout(cleanup, duration + 50);
169
- }));
170
- }
171
-
172
- await Promise.all(promises);
173
- ctx.it = targets.length === 1 ? targets[0] : targets;
174
- return ctx.it;
175
- }`,
176
- go: `
177
- case 'go': {
178
- const dest = await evaluate(cmd.args[0], ctx);
179
- const d = String(dest).toLowerCase();
180
- if (d === 'back') history.back();
181
- else if (d === 'forward') history.forward();
182
- else if (d === 'bottom') ctx.me.scrollIntoView({ block: 'end', behavior: 'smooth' });
183
- else if (d === 'top') ctx.me.scrollIntoView({ block: 'start', behavior: 'smooth' });
184
- else window.location.href = String(dest);
185
- return null;
186
- }`,
187
- call: `
188
- case 'call': {
189
- const result = await evaluate(cmd.args[0], ctx);
190
- ctx.it = result;
191
- return result;
192
- }`,
193
- log: `
194
- case 'log': {
195
- const values = await Promise.all(cmd.args.map((a: any) => evaluate(a, ctx)));
196
- console.log(...values);
197
- return values[0];
198
- }`,
199
- send: `
200
- case 'send': {
201
- const eventName = await evaluate(cmd.args[0], ctx);
202
- const targets = await getTarget();
203
- const event = new CustomEvent(String(eventName), { bubbles: true, detail: ctx.it });
204
- for (const el of targets) el.dispatchEvent(event);
205
- ctx.it = event;
206
- return event;
207
- }`,
208
- put: `
209
- case 'put': {
210
- const content = await evaluate(cmd.args[0], ctx);
211
- const modifier = cmd.modifier || 'into';
212
-
213
- if (cmd.target?.type === 'possessive' && isStyleProp(cmd.target.property)) {
214
- const obj = await evaluate(cmd.target.object, ctx);
215
- const elements = toElementArray(obj);
216
- for (const el of elements) {
217
- setStyleProp(el, cmd.target.property, content);
218
- }
219
- ctx.it = content;
220
- return content;
221
- }
222
-
223
- const targets = await getTarget();
224
- for (const el of targets) {
225
- const html = String(content);
226
- if (modifier === 'into') el.innerHTML = html;
227
- else if (modifier === 'before') el.insertAdjacentHTML('beforebegin', html);
228
- else if (modifier === 'after') el.insertAdjacentHTML('afterend', html);
229
- else if (modifier === 'at start of') el.insertAdjacentHTML('afterbegin', html);
230
- else if (modifier === 'at end of') el.insertAdjacentHTML('beforeend', html);
231
- }
232
- ctx.it = content;
233
- return content;
234
- }`,
235
- append: `
236
- case 'append': {
237
- const content = await evaluate(cmd.args[0], ctx);
238
- const targets = await getTarget();
239
- for (const el of targets) el.insertAdjacentHTML('beforeend', String(content));
240
- ctx.it = content;
241
- return content;
242
- }`,
243
- prepend: `
244
- case 'prepend': {
245
- const content = await evaluate(cmd.args[0], ctx);
246
- const targets = await getTarget();
247
- for (const el of targets) el.insertAdjacentHTML('afterbegin', String(content));
248
- ctx.it = content;
249
- return content;
250
- }`,
251
- morph: `
252
- case 'morph': {
253
- const targets = await getTarget();
254
- const content = await evaluate(cmd.args[0], ctx);
255
- const contentStr = String(content);
256
- const isOuter = cmd.modifier === 'over';
257
-
258
- for (const target of targets) {
259
- try {
260
- if (isOuter) {
261
- morphlexMorph(target, contentStr);
262
- } else {
263
- // Upstream's morph MERGES a lone root element that has the
264
- // target's tag (attributes and children); anything else morphs the
265
- // children \u2014 the full runtime's 'morphMerge' (lib/swap-executor.ts).
266
- const template = document.createElement('template');
267
- template.innerHTML = contentStr;
268
- const root = template.content.firstElementChild;
269
- if (root && !root.nextElementSibling && root.tagName === target.tagName) {
270
- morphlexMorph(target, root);
271
- } else {
272
- // morphlex's morphInner takes an ELEMENT, not a string \u2014 the same
273
- // wrapping src/lib/morph-adapter.ts does. Passing the string threw
274
- // straight into the fallback below, so inner morph never actually
275
- // morphed (it silently degraded to innerHTML on every call).
276
- const wrapper = document.createElement(target.tagName);
277
- wrapper.innerHTML = contentStr;
278
- morphlexMorphInner(target, wrapper);
279
- }
280
- }
281
- } catch (error) {
282
- // Fallback to innerHTML/outerHTML if morph fails
283
- console.warn('[LokaScript] Morph failed, falling back:', error);
284
- if (isOuter) {
285
- target.outerHTML = contentStr;
286
- } else {
287
- target.innerHTML = contentStr;
288
- }
289
- }
290
- }
291
- ctx.it = targets.length === 1 ? targets[0] : targets;
292
- return ctx.it;
293
- }`,
294
- take: `
295
- case 'take': {
296
- // getClassName reads a NODE (as toggle/add/removeClass all do). Passing the
297
- // EVALUATED value handed it a NodeList, which yielded '' and then threw
298
- // 'Invalid selector .' \u2014 a command the parse-level reachability check
299
- // certified while every generated bundle carrying it crashed.
300
- const className = getClassName(cmd.args[0]);
301
- const from = cmd.target ? await getTarget() : [ctx.me.parentElement!];
302
- for (const container of from) {
303
- const siblings = container.querySelectorAll('.' + className);
304
- siblings.forEach(el => el.classList.remove(className));
305
- }
306
- ctx.me.classList.add(className);
307
- return ctx.me;
308
- }`,
309
- increment: `
310
- case 'increment': {
311
- const target = cmd.args[0];
312
- const amount = cmd.args[1] ? await evaluate(cmd.args[1], ctx) : 1;
313
-
314
- if (target.type === 'variable') {
315
- const varName = target.name.slice(1);
316
- const map = target.scope === 'local' ? elemScope(ctx.me) : globalVars;
317
- const current = map.get(varName) || 0;
318
- const newVal = current + amount;
319
- map.set(varName, newVal);
320
- ctx.it = newVal;
321
- return newVal;
322
- }
323
-
324
- if (target.type === 'possessive') {
325
- const style = isStyleProp(target.property);
326
- const obj = await evaluate(target.object, ctx);
327
- const elements = toElementArray(obj);
328
- for (const el of elements) {
329
- const was = style ? getStyleProp(el, target.property) : Reflect.get(el, target.property);
330
- const newVal = (parseFloat(was || '0') || 0) + amount;
331
- if (style) setStyleProp(el, target.property, newVal);
332
- else Reflect.set(el, target.property, newVal);
333
- ctx.it = newVal;
334
- }
335
- return ctx.it;
336
- }
337
-
338
- const elements = toElementArray(await evaluate(target, ctx));
339
- for (const el of elements) {
340
- const current = parseFloat(el.textContent || '0') || 0;
341
- const newVal = current + amount;
342
- el.textContent = String(newVal);
343
- ctx.it = newVal;
344
- }
345
- return ctx.it;
346
- }`,
347
- decrement: `
348
- case 'decrement': {
349
- const target = cmd.args[0];
350
- const amount = cmd.args[1] ? await evaluate(cmd.args[1], ctx) : 1;
351
-
352
- if (target.type === 'variable') {
353
- const varName = target.name.slice(1);
354
- const map = target.scope === 'local' ? elemScope(ctx.me) : globalVars;
355
- const current = map.get(varName) || 0;
356
- const newVal = current - amount;
357
- map.set(varName, newVal);
358
- ctx.it = newVal;
359
- return newVal;
360
- }
361
-
362
- if (target.type === 'possessive') {
363
- const style = isStyleProp(target.property);
364
- const obj = await evaluate(target.object, ctx);
365
- const elements = toElementArray(obj);
366
- for (const el of elements) {
367
- const was = style ? getStyleProp(el, target.property) : Reflect.get(el, target.property);
368
- const newVal = (parseFloat(was || '0') || 0) - amount;
369
- if (style) setStyleProp(el, target.property, newVal);
370
- else Reflect.set(el, target.property, newVal);
371
- ctx.it = newVal;
372
- }
373
- return ctx.it;
374
- }
375
-
376
- const elements = toElementArray(await evaluate(target, ctx));
377
- for (const el of elements) {
378
- const current = parseFloat(el.textContent || '0') || 0;
379
- const newVal = current - amount;
380
- el.textContent = String(newVal);
381
- ctx.it = newVal;
382
- }
383
- return ctx.it;
384
- }`,
385
- focus: `
386
- case 'focus': {
387
- const targets = await getTarget();
388
- for (const el of targets) (el as HTMLElement).focus();
389
- return targets;
390
- }`,
391
- blur: `
392
- case 'blur': {
393
- const targets = await getTarget();
394
- for (const el of targets) (el as HTMLElement).blur();
395
- return targets;
396
- }`,
397
- empty: `
398
- case 'empty': {
399
- const targets = await getTarget();
400
- for (const el of targets) (el as HTMLElement).innerHTML = '';
401
- return targets;
402
- }`,
403
- return: `
404
- case 'return': {
405
- const value = cmd.args[0] ? await evaluate(cmd.args[0], ctx) : ctx.it;
406
- throw { type: 'return', value };
407
- }`,
408
- break: `
409
- case 'break': {
410
- throw { type: 'break' };
411
- }`,
412
- continue: `
413
- case 'continue': {
414
- throw { type: 'continue' };
415
- }`,
416
- halt: `
417
- case 'halt': {
418
- // Check for "halt the event" pattern
419
- const firstArg = cmd.args[0];
420
- let targetEvent = ctx.event;
421
- if (firstArg?.type === 'identifier' && firstArg.name === 'the' && cmd.args[1]?.name === 'event') {
422
- targetEvent = ctx.event;
423
- } else if (firstArg) {
424
- const evaluated = await evaluate(firstArg, ctx);
425
- if (evaluated?.preventDefault) targetEvent = evaluated;
426
- }
427
-
428
- if (targetEvent && typeof targetEvent.preventDefault === 'function') {
429
- targetEvent.preventDefault();
430
- targetEvent.stopPropagation();
431
- return { halted: true, eventHalted: true };
432
- }
433
-
434
- // Regular halt - stop execution
435
- const haltError = new Error('HALT_EXECUTION');
436
- (haltError as any).isHalt = true;
437
- throw haltError;
438
- }`,
439
- exit: `
440
- case 'exit': {
441
- const exitError = new Error('EXIT_COMMAND');
442
- (exitError as any).isExit = true;
443
- throw exitError;
444
- }`,
445
- throw: `
446
- case 'throw': {
447
- const message = cmd.args[0] ? await evaluate(cmd.args[0], ctx) : 'Error';
448
- const errorToThrow = message instanceof Error ? message : new Error(String(message));
449
- throw errorToThrow;
450
- }`,
451
- beep: `
452
- case 'beep': {
453
- const values = await Promise.all(cmd.args.map((a: any) => evaluate(a, ctx)));
454
- const displayValues = values.length > 0 ? values : [ctx.it];
455
-
456
- for (const val of displayValues) {
457
- const typeInfo = val === null ? 'null' :
458
- val === undefined ? 'undefined' :
459
- Array.isArray(val) ? \`Array[\${val.length}]\` :
460
- val instanceof Element ? \`Element<\${val.tagName.toLowerCase()}>\` :
461
- typeof val;
462
- console.log('[beep]', typeInfo + ':', val);
463
- }
464
- return displayValues[0];
465
- }`,
466
- js: `
467
- case 'js': {
468
- const codeArg = cmd.args[0];
469
- let jsCode = '';
470
-
471
- if (codeArg.type === 'string') {
472
- jsCode = codeArg.value;
473
- } else if (codeArg.type === 'template') {
474
- jsCode = await evaluate(codeArg, ctx);
475
- } else {
476
- jsCode = String(await evaluate(codeArg, ctx));
477
- }
478
-
479
- // Build context object for the Function
480
- //
481
- // \`target\` is \`ctx.me\` outright, not \`ctx.target || ctx.me\`. No Context
482
- // in any bundle declares a \`target\` field and no executor assigns one, so
483
- // the left operand was always \`undefined\` and the expression always
484
- // yielded \`ctx.me\` \u2014 same value, and a type error the moment the template
485
- // lands in a file that is actually typechecked (Arc E step 4, where it
486
- // did). Generated bundles are written, imported and executed but never
487
- // \`tsc\`'d, which is how a phantom property survived here.
488
- const jsContext = {
489
- me: ctx.me,
490
- it: ctx.it,
491
- event: ctx.event,
492
- target: ctx.me,
493
- locals: Object.fromEntries(ctx.locals),
494
- globals: Object.fromEntries(globalVars),
495
- document: typeof document !== 'undefined' ? document : undefined,
496
- window: typeof window !== 'undefined' ? window : undefined,
497
- };
498
-
499
- try {
500
- const fn = new Function('ctx', \`with(ctx) { return (async () => { \${jsCode} })(); }\`);
501
- const result = await fn(jsContext);
502
- ctx.it = result;
503
- return result;
504
- } catch (error) {
505
- console.error('[js] Execution error:', error);
506
- throw error;
507
- }
508
- }`,
509
- copy: `
510
- case 'copy': {
511
- const source = await evaluate(cmd.args[0], ctx);
512
- let textToCopy = '';
513
-
514
- if (typeof source === 'string') {
515
- textToCopy = source;
516
- } else if (source instanceof Element) {
517
- textToCopy = source.textContent || '';
518
- } else {
519
- textToCopy = String(source);
520
- }
521
-
522
- try {
523
- if (navigator.clipboard) {
524
- await navigator.clipboard.writeText(textToCopy);
525
- } else {
526
- // Fallback for older browsers
527
- const textarea = document.createElement('textarea');
528
- textarea.value = textToCopy;
529
- textarea.style.cssText = 'position:fixed;top:0;left:-9999px';
530
- document.body.appendChild(textarea);
531
- textarea.select();
532
- document.execCommand('copy');
533
- document.body.removeChild(textarea);
534
- }
535
-
536
- if (ctx.me instanceof Element) {
537
- ctx.me.dispatchEvent(new CustomEvent('copy:success', {
538
- bubbles: true,
539
- detail: { text: textToCopy }
540
- }));
541
- }
542
- ctx.it = textToCopy;
543
- return textToCopy;
544
- } catch (error) {
545
- if (ctx.me instanceof Element) {
546
- ctx.me.dispatchEvent(new CustomEvent('copy:error', {
547
- bubbles: true,
548
- detail: { error }
549
- }));
550
- }
551
- throw error;
552
- }
553
- }`,
554
- push: `
555
- case 'push': {
556
- const url = String(await evaluate(cmd.args[0], ctx));
557
- let title = '';
558
-
559
- // Check for "with title" modifier
560
- if (cmd.modifiers?.title) {
561
- title = String(await evaluate(cmd.modifiers.title, ctx));
562
- }
563
-
564
- window.history.pushState(null, '', url);
565
- if (title) document.title = title;
566
-
567
- window.dispatchEvent(new CustomEvent('lokascript:pushurl', {
568
- detail: { url, title }
569
- }));
570
-
571
- return { url, title, mode: 'push' };
572
- }`,
573
- replace: `
574
- case 'replace': {
575
- const url = String(await evaluate(cmd.args[0], ctx));
576
- let title = '';
577
-
578
- // Check for "with title" modifier
579
- if (cmd.modifiers?.title) {
580
- title = String(await evaluate(cmd.modifiers.title, ctx));
581
- }
582
-
583
- window.history.replaceState(null, '', url);
584
- if (title) document.title = title;
585
-
586
- window.dispatchEvent(new CustomEvent('lokascript:replaceurl', {
587
- detail: { url, title }
588
- }));
589
-
590
- return { url, title, mode: 'replace' };
591
- }`,
592
- };
593
- const BLOCK_IMPLEMENTATIONS_TS = {
594
- if: `
595
- case 'if': {
596
- const condition = await evaluate(block.condition!, ctx);
597
- if (condition) {
598
- return executeSequenceWithBlocks(block.body, ctx);
599
- } else if (block.elseBody) {
600
- return executeSequenceWithBlocks(block.elseBody, ctx);
601
- }
602
- return null;
603
- }`,
604
- repeat: `
605
- case 'repeat': {
606
- const count = await evaluate(block.condition!, ctx);
607
- // A count reads as upstream's \`index < times\` does, and core's loopCount:
608
- // "6.5" loops 7 times, "6abc" none (parseInt read 6 for both), true once.
609
- const n = Number(count) || 0;
610
- for (let i = 0; i < n && i < MAX_LOOP_ITERATIONS; i++) {
611
- ctx.locals.set('__loop_index__', i);
612
- ctx.locals.set('__loop_count__', i + 1);
613
- try {
614
- await executeSequenceWithBlocks(block.body, ctx);
615
- } catch (e: any) {
616
- if (e?.type === 'break') break;
617
- if (e?.type === 'continue') continue;
618
- throw e;
619
- }
620
- }
621
- return null;
622
- }`,
623
- for: `
624
- case 'for': {
625
- const { variable, iterable } = block.condition as any;
626
- const items = await evaluate(iterable, ctx);
627
- const arr = Array.isArray(items) ? items : items instanceof NodeList ? Array.from(items) : [items];
628
- const varName = variable.startsWith(':') ? variable.slice(1) : variable;
629
- for (let i = 0; i < arr.length && i < MAX_LOOP_ITERATIONS; i++) {
630
- ctx.locals.set(varName, arr[i]);
631
- ctx.locals.set('__loop_index__', i);
632
- ctx.locals.set('__loop_count__', i + 1);
633
- try {
634
- await executeSequenceWithBlocks(block.body, ctx);
635
- } catch (e: any) {
636
- if (e?.type === 'break') break;
637
- if (e?.type === 'continue') continue;
638
- throw e;
639
- }
640
- }
641
- return null;
642
- }`,
643
- while: `
644
- case 'while': {
645
- let iterations = 0;
646
- while (await evaluate(block.condition!, ctx) && iterations < MAX_LOOP_ITERATIONS) {
647
- ctx.locals.set('__loop_index__', iterations);
648
- try {
649
- await executeSequenceWithBlocks(block.body, ctx);
650
- } catch (e: any) {
651
- if (e?.type === 'break') break;
652
- if (e?.type === 'continue') { iterations++; continue; }
653
- throw e;
654
- }
655
- iterations++;
656
- }
657
- return null;
658
- }`,
659
- fetch: `
660
- case 'fetch': {
661
- const { url, responseType, options, method } = block.condition as any;
662
- try {
663
- const urlVal = await evaluate(url, ctx);
664
- const fetchInit = {} as RequestInit;
665
-
666
- if (method) {
667
- const methodVal = await evaluate(method, ctx);
668
- fetchInit.method = String(methodVal).toUpperCase();
669
- }
670
-
671
- if (options) {
672
- const optionsVal = await evaluate(options, ctx);
673
- if (optionsVal instanceof FormData) {
674
- fetchInit.body = optionsVal;
675
- } else if (optionsVal && typeof optionsVal === 'object' && !(optionsVal instanceof Element)) {
676
- Object.assign(fetchInit, optionsVal);
677
- }
678
- }
679
-
680
- const response = await fetch(String(urlVal), fetchInit);
681
- if (!response.ok) throw new Error(\`HTTP \${response.status}\`);
682
-
683
- const resType = await evaluate(responseType, ctx);
684
- let data: any;
685
- if (resType === 'json') data = await response.json();
686
- else if (resType === 'html') {
687
- const text = await response.text();
688
- const doc = new DOMParser().parseFromString(text, 'text/html');
689
- data = doc.body.innerHTML;
690
- } else data = await response.text();
691
-
692
- ctx.it = data;
693
- ctx.locals.set('it', data);
694
- ctx.locals.set('result', data);
695
- ctx.locals.set('response', response);
696
-
697
- await executeSequenceWithBlocks(block.body, ctx);
698
- } catch (error: any) {
699
- if (error?.type === 'return') throw error;
700
- ctx.locals.set('error', error);
701
- console.error('Fetch error:', error);
702
- }
703
- return null;
704
- }`,
705
- };
706
- const STYLE_COMMANDS = ['set', 'put', 'increment', 'decrement'];
707
- const STYLE_READ_COMMANDS = ['increment', 'decrement'];
708
- const ELEMENT_ARRAY_COMMANDS = ['put', 'increment', 'decrement'];
709
- const MORPH_COMMANDS = ['morph'];
710
- function getCommandImplementations(format = 'ts') {
711
- const result = {};
712
- for (const [name, code] of Object.entries(COMMAND_IMPLEMENTATIONS_TS)) {
713
- result[name] = stripTypes(code, format);
714
- }
715
- return result;
716
- }
717
- function getBlockImplementations(format = 'ts') {
718
- const result = {};
719
- for (const [name, code] of Object.entries(BLOCK_IMPLEMENTATIONS_TS)) {
720
- result[name] = stripTypes(code, format);
721
- }
722
- return result;
723
- }
724
- function getAvailableCommands() {
725
- return Object.keys(COMMAND_IMPLEMENTATIONS_TS);
726
- }
727
- function getAvailableBlocks() {
728
- return Object.keys(BLOCK_IMPLEMENTATIONS_TS);
729
- }
730
- const COMMAND_IMPLEMENTATIONS = COMMAND_IMPLEMENTATIONS_TS;
731
- const BLOCK_IMPLEMENTATIONS = BLOCK_IMPLEMENTATIONS_TS;
732
-
733
- const AVAILABLE_COMMANDS = [
734
- 'toggle',
735
- 'add',
736
- 'remove',
737
- 'removeClass',
738
- 'show',
739
- 'hide',
740
- 'put',
741
- 'append',
742
- 'prepend',
743
- 'take',
744
- 'empty',
745
- 'set',
746
- 'get',
747
- 'increment',
748
- 'decrement',
749
- 'wait',
750
- 'transition',
751
- 'send',
752
- 'trigger',
753
- 'log',
754
- 'call',
755
- 'copy',
756
- 'beep',
757
- 'go',
758
- 'push',
759
- 'push-url',
760
- 'replace',
761
- 'replace-url',
762
- 'focus',
763
- 'blur',
764
- 'return',
765
- 'break',
766
- 'continue',
767
- 'halt',
768
- 'exit',
769
- 'throw',
770
- 'js',
771
- 'morph',
772
- ];
773
- const AVAILABLE_BLOCKS = ['if', 'repeat', 'for', 'while', 'fetch'];
774
- const FULL_RUNTIME_ONLY_COMMANDS = [
775
- 'make',
776
- 'swap',
777
- 'process',
778
- 'default',
779
- 'tell',
780
- 'pick',
781
- 'unless',
782
- 'settle',
783
- 'measure',
784
- 'install',
785
- 'breakpoint',
786
- 'clear',
787
- 'close',
788
- 'open',
789
- 'pseudo-command',
790
- 'render',
791
- 'reset',
792
- 'scroll',
793
- 'select',
794
- 'start',
795
- ];
796
- const COMMAND_ALIASES = {
797
- 'push-url': 'push',
798
- 'replace-url': 'replace',
799
- trigger: 'send',
800
- };
801
- function resolveCommandKey(command) {
802
- return COMMAND_ALIASES[command] ?? command;
803
- }
804
- function isAvailableCommand(command) {
805
- return AVAILABLE_COMMANDS.includes(command);
806
- }
807
- function isAvailableBlock(block) {
808
- return AVAILABLE_BLOCKS.includes(block);
809
- }
810
- function requiresFullRuntime(command) {
811
- return FULL_RUNTIME_ONLY_COMMANDS.includes(command);
812
- }
813
-
814
- function emitCommandCases(commands, format = 'ts') {
815
- const impls = getCommandImplementations(format);
816
- return [...new Set(commands.map(resolveCommandKey))]
817
- .filter(key => impls[key])
818
- .map(key => impls[key])
819
- .join('\n');
820
- }
821
- function emitBlockCases(blocks, format = 'ts') {
822
- const impls = getBlockImplementations(format);
823
- return blocks
824
- .filter(key => impls[key])
825
- .map(key => impls[key])
826
- .join('\n');
827
- }
828
-
829
- function generateBundleCode(config) {
830
- const { name, commands, blocks = [], htmxIntegration = false, globalName = 'hyperfixi', positionalExpressions = false, parserImportPath = '../parser/hybrid', autoInit = true, esModule = true, format = 'ts', maxLoopIterations = 1000, } = config;
831
- const needsStyleHelpers = commands.some(cmd => STYLE_COMMANDS.includes(cmd));
832
- const needsStyleReadHelper = commands.some(cmd => STYLE_READ_COMMANDS.includes(cmd));
833
- const needsElementArrayHelper = commands.some(cmd => ELEMENT_ARRAY_COMMANDS.includes(cmd));
834
- const needsMorphlex = commands.some(cmd => MORPH_COMMANDS.includes(cmd));
835
- const hasBlocks = blocks.length > 0;
836
- const hasReturn = commands.includes('return');
837
- const commandCases = emitCommandCases(commands, format);
838
- const blockCases = emitBlockCases(blocks, format);
839
- return `/**
840
- * HyperFixi ${name} Bundle (Auto-Generated)
841
- *
842
- * Generated by: @hyperfixi/core bundle-generator
843
- * Commands: ${commands.join(', ')}${blocks.length > 0 ? `\n * Blocks: ${blocks.join(', ')}` : ''}${positionalExpressions ? '\n * Positional expressions: enabled' : ''}
844
- *
845
- * DO NOT EDIT - Regenerate with the build script.
846
- */
847
-
848
- // =============================================================================
849
- // MODULAR PARSER IMPORTS
850
- // =============================================================================
851
-
852
- import { HybridParser } from '${parserImportPath}/parser-core';
853
- import type { ASTNode, CommandNode, EventNode${hasBlocks ? ', BlockNode' : ''} } from '${parserImportPath}/ast-types';
854
- ${needsMorphlex ? "import { morph as morphlexMorph, morphInner as morphlexMorphInner } from 'morphlex';" : ''}
855
-
856
- // =============================================================================
857
- // RUNTIME
858
- // =============================================================================
859
-
860
- interface Context {
861
- me: Element;
862
- event?: Event;
863
- it?: any;
864
- you?: Element;
865
- locals: Map<string, any>;
866
- }
867
-
868
- const globalVars = new Map<string, any>();
869
- // Per-element store for \`:name\` variables (scope 'local' from the mini-parser).
870
- // Persists per-element across event firings, isolated per element.
871
- const elementVars = new WeakMap<Element, Map<string, any>>();
872
- function elemScope(el: Element): Map<string, any> {
873
- let m = elementVars.get(el);
874
- if (!m) { m = new Map<string, any>(); elementVars.set(el, m); }
875
- return m;
876
- }
877
- ${hasBlocks ? `const MAX_LOOP_ITERATIONS = ${maxLoopIterations};` : ''}
878
-
879
- async function evaluate(node: ASTNode, ctx: Context): Promise<any> {
880
- switch (node.type) {
881
- case 'literal': return node.value;
882
-
883
- case 'identifier':
884
- if (node.value === 'me' || node.value === 'my') return ctx.me;
885
- if (node.value === 'it') return ctx.it;
886
- if (node.value === 'you') return ctx.you;
887
- if (node.value === 'event') return ctx.event;
888
- if (node.value === 'body') return document.body;
889
- if (node.value === 'document') return document;
890
- if (node.value === 'window') return window;
891
- if (ctx.locals.has(node.value)) return ctx.locals.get(node.value);
892
- if (node.value in (ctx.me as any)) return (ctx.me as any)[node.value];
893
- return node.value;
894
-
895
- case 'variable':
896
- if (node.scope === 'local') return elemScope(ctx.me).get(node.name.slice(1));
897
- const gName = node.name.slice(1);
898
- if (globalVars.has(gName)) return globalVars.get(gName);
899
- return (window as any)[node.name];
900
-
901
- case 'selector':
902
- const elements = document.querySelectorAll(node.value);
903
- return elements.length === 1 ? elements[0] : Array.from(elements);
904
-
905
- case 'binary':
906
- return evaluateBinary(node, ctx);
907
-
908
- case 'possessive':
909
- case 'member':
910
- const obj = await evaluate(node.object, ctx);
911
- if (obj == null) return undefined;
912
- const prop = node.computed ? await evaluate(node.property, ctx) : node.property;
913
- if (prop === 'values' && obj instanceof Element) {
914
- if (obj instanceof HTMLFormElement) return new FormData(obj);
915
- const fd = new FormData();
916
- obj.querySelectorAll('input, select, textarea').forEach(input => {
917
- const name = input.getAttribute('name');
918
- if (name && 'value' in input) fd.append(name, (input as HTMLInputElement).value);
919
- });
920
- return fd;
921
- }
922
- return obj[prop];
923
-
924
- case 'call': {
925
- let callContext: any = null;
926
- let callee: any;
927
-
928
- if (node.callee.type === 'member' || node.callee.type === 'possessive') {
929
- callContext = await evaluate(node.callee.object, ctx);
930
- const p = node.callee.computed
931
- ? await evaluate(node.callee.property, ctx)
932
- : node.callee.property;
933
- callee = callContext?.[p];
934
- } else {
935
- callee = await evaluate(node.callee, ctx);
936
- }
937
-
938
- const args = await Promise.all(node.args.map((a: ASTNode) => evaluate(a, ctx)));
939
- if (typeof callee === 'function') return callee.apply(callContext, args);
940
- return undefined;
941
- }
942
- ${positionalExpressions
943
- ? `
944
- case 'positional':
945
- return evaluatePositional(node, ctx);
946
- `
947
- : ''}
948
- default: return undefined;
949
- }
950
- }
951
-
952
- async function evaluateBinary(node: ASTNode, ctx: Context): Promise<any> {
953
- if (node.operator === 'has') {
954
- const left = await evaluate(node.left, ctx);
955
- if (left instanceof Element && node.right.type === 'selector' && node.right.value.startsWith('.')) {
956
- return left.classList.contains(node.right.value.slice(1));
957
- }
958
- return false;
959
- }
960
-
961
- const left = await evaluate(node.left, ctx);
962
- const right = await evaluate(node.right, ctx);
963
-
964
- switch (node.operator) {
965
- case '+': return left + right;
966
- case '-': return left - right;
967
- case '*': return left * right;
968
- case '/': return left / right;
969
- case '%': return left % right;
970
- case '==': case 'is': return left == right;
971
- case '!=': case 'is not': return left != right;
972
- case '<': return left < right;
973
- case '>': return left > right;
974
- case '<=': return left <= right;
975
- case '>=': return left >= right;
976
- case 'and': case '&&': return left && right;
977
- case 'or': case '||': return left || right;
978
- case 'contains': case 'includes':
979
- if (typeof left === 'string') return left.includes(right);
980
- if (Array.isArray(left)) return left.includes(right);
981
- if (left instanceof Element) return left.contains(right);
982
- return false;
983
- case 'matches':
984
- if (left instanceof Element) return left.matches(right);
985
- if (typeof left === 'string') return new RegExp(right).test(left);
986
- return false;
987
- default: return undefined;
988
- }
989
- }
990
- ${positionalExpressions
991
- ? `
992
- function evaluatePositional(node: ASTNode, ctx: Context): Element | null {
993
- const target = node.target;
994
- let elements: Element[] = [];
995
-
996
- let selector: string | null = null;
997
- if (target.type === 'selector') {
998
- selector = target.value;
999
- } else if (target.type === 'identifier') {
1000
- selector = target.value;
1001
- } else if (target.type === 'htmlSelector') {
1002
- selector = target.value;
1003
- }
1004
- if (selector) {
1005
- elements = Array.from(document.querySelectorAll(selector));
1006
- }
1007
-
1008
- switch (node.position) {
1009
- case 'first': return elements[0] || null;
1010
- case 'last': return elements[elements.length - 1] || null;
1011
- case 'next': {
1012
- if (selector) {
1013
- let el = ctx.me.nextElementSibling;
1014
- while (el) { if (el.matches(selector)) return el; el = el.nextElementSibling; }
1015
- return null;
1016
- }
1017
- return ctx.me.nextElementSibling;
1018
- }
1019
- case 'previous': {
1020
- if (selector) {
1021
- let el = ctx.me.previousElementSibling;
1022
- while (el) { if (el.matches(selector)) return el; el = el.previousElementSibling; }
1023
- return null;
1024
- }
1025
- return ctx.me.previousElementSibling;
1026
- }
1027
- case 'closest': return selector ? ctx.me.closest(selector) : null;
1028
- case 'parent': {
1029
- if (selector) {
1030
- let el = ctx.me.parentElement;
1031
- while (el) { if (el.matches(selector)) return el; el = el.parentElement; }
1032
- return null;
1033
- }
1034
- return ctx.me.parentElement;
1035
- }
1036
- default: return elements[0] || null;
1037
- }
1038
- }
1039
- `
1040
- : ''}
1041
- // =============================================================================
1042
- // COMMAND EXECUTOR
1043
- // =============================================================================
1044
-
1045
- ${needsStyleHelpers
1046
- ? `
1047
- const isStyleProp = (prop: string) => prop?.startsWith('*');
1048
- const getStyleName = (prop: string) => prop.substring(1);
1049
- const setStyleProp = (el: Element, prop: string, value: any): boolean => {
1050
- if (!isStyleProp(prop)) return false;
1051
- (el as HTMLElement).style.setProperty(getStyleName(prop), String(value));
1052
- return true;
1053
- };
1054
- ${needsStyleReadHelper
1055
- ? `const getStyleProp = (el: Element, prop: string): string | undefined => {
1056
- if (!isStyleProp(prop)) return undefined;
1057
- return getComputedStyle(el as HTMLElement).getPropertyValue(getStyleName(prop));
1058
- };
1059
- `
1060
- : ''}`
1061
- : ''}
1062
-
1063
- ${needsElementArrayHelper
1064
- ? `
1065
- const toElementArray = (val: any): Element[] => {
1066
- if (Array.isArray(val)) return val.filter(e => e instanceof Element);
1067
- if (val instanceof Element) return [val];
1068
- if (typeof val === 'string') return Array.from(document.querySelectorAll(val));
1069
- return [];
1070
- };
1071
- `
1072
- : ''}
1073
-
1074
- async function executeCommand(cmd: CommandNode, ctx: Context): Promise<any> {
1075
- const getTarget = async (): Promise<Element[]> => {
1076
- if (!cmd.target) return [ctx.me];
1077
- const t = await evaluate(cmd.target, ctx);
1078
- if (Array.isArray(t)) return t;
1079
- if (t instanceof Element) return [t];
1080
- if (typeof t === 'string') return Array.from(document.querySelectorAll(t));
1081
- return [ctx.me];
1082
- };
1083
-
1084
- const getClassName = (node: any): string => {
1085
- if (!node) return '';
1086
- if (node.type === 'selector') {
1087
- // \`@attr\` passes through unsliced; .class / #id lose their prefix.
1088
- if (node.value.startsWith('@')) return node.value;
1089
- return node.value.slice(1);
1090
- }
1091
- if (node.type === 'string' || node.type === 'literal') {
1092
- const val = node.value;
1093
- return typeof val === 'string' && val.startsWith('.') ? val.slice(1) : String(val);
1094
- }
1095
- if (node.type === 'identifier') return node.value;
1096
- return '';
1097
- };
1098
-
1099
- switch (cmd.name) {
1100
- ${commandCases}
1101
-
1102
- default:
1103
- console.warn(\`${name} bundle: Unknown command '\${cmd.name}'\`);
1104
- return null;
1105
- }
1106
- }
1107
- ${hasBlocks
1108
- ? `
1109
- // =============================================================================
1110
- // BLOCK EXECUTOR
1111
- // =============================================================================
1112
-
1113
- async function executeBlock(block: BlockNode, ctx: Context): Promise<any> {
1114
- switch (block.type) {
1115
- ${blockCases}
1116
-
1117
- default:
1118
- console.warn(\`${name} bundle: Unknown block '\${block.type}'\`);
1119
- return null;
1120
- }
1121
- }
1122
- `
1123
- : ''}
1124
- // =============================================================================
1125
- // SEQUENCE EXECUTOR
1126
- // =============================================================================
1127
-
1128
- async function executeSequence(nodes: ASTNode[], ctx: Context): Promise<any> {
1129
- let result: any;
1130
- for (const node of nodes) {
1131
- if (node.type === 'command') {
1132
- result = await executeCommand(node as CommandNode, ctx);
1133
- }${hasBlocks
1134
- ? ` else if (['if', 'repeat', 'for', 'while', 'fetch'].includes(node.type)) {
1135
- result = await executeBlock(node as BlockNode, ctx);
1136
- }`
1137
- : ''}
1138
- }
1139
- return result;
1140
- }
1141
- ${hasBlocks
1142
- ? `
1143
- async function executeSequenceWithBlocks(nodes: ASTNode[], ctx: Context): Promise<any> {
1144
- try {
1145
- return await executeSequence(nodes, ctx);
1146
- } catch (e: any) {
1147
- if (e?.type === 'return') throw e;
1148
- throw e;
1149
- }
1150
- }
1151
- `
1152
- : ''}
1153
- async function executeAST(ast: ASTNode, me: Element, event?: Event): Promise<any> {
1154
- const ctx: Context = { me, event, locals: new Map() };
1155
-
1156
- if (ast.type === 'sequence') {
1157
- ${hasReturn || hasBlocks ? "try { return await executeSequence(ast.commands, ctx); } catch (e: any) { if (e?.type === 'return') return e.value; throw e; }" : 'return executeSequence(ast.commands, ctx);'}
1158
- }
1159
-
1160
- if (ast.type === 'event') {
1161
- const eventNode = ast as EventNode;
1162
- const eventName = eventNode.event;
1163
-
1164
- if (eventName === 'init') {
1165
- ${hasReturn || hasBlocks ? "try { await executeSequence(eventNode.body, ctx); } catch (e: any) { if (e?.type !== 'return') throw e; }" : 'await executeSequence(eventNode.body, ctx);'}
1166
- return;
1167
- }
1168
-
1169
- const target = eventNode.filter ? await evaluate(eventNode.filter, ctx) : me;
1170
- const targetEl = target instanceof Element ? target : me;
1171
- const mods = eventNode.modifiers;
1172
-
1173
- let handler = async (e: Event) => {
1174
- if (mods.prevent) e.preventDefault();
1175
- if (mods.stop) e.stopPropagation();
1176
-
1177
- const handlerCtx: Context = {
1178
- me, event: e,
1179
- you: e.target instanceof Element ? e.target : undefined,
1180
- locals: new Map(),
1181
- };
1182
- ${hasReturn || hasBlocks ? "try { await executeSequence(eventNode.body, handlerCtx); } catch (err: any) { if (err?.type !== 'return') throw err; }" : 'await executeSequence(eventNode.body, handlerCtx);'}
1183
- };
1184
-
1185
- if (mods.debounce) {
1186
- let timeout: any;
1187
- const orig = handler;
1188
- handler = async (e: Event) => {
1189
- clearTimeout(timeout);
1190
- timeout = setTimeout(() => orig(e), mods.debounce);
1191
- };
1192
- }
1193
-
1194
- if (mods.throttle) {
1195
- let lastCall = 0;
1196
- const orig = handler;
1197
- handler = async (e: Event) => {
1198
- const now = Date.now();
1199
- if (now - lastCall >= mods.throttle!) {
1200
- lastCall = now;
1201
- await orig(e);
1202
- }
1203
- };
1204
- }
1205
-
1206
- targetEl.addEventListener(eventName, handler, { once: !!mods.once });
1207
- return;
1208
- }
1209
-
1210
- return null;
1211
- }
1212
-
1213
- // =============================================================================
1214
- // DOM PROCESSOR
1215
- // =============================================================================
1216
-
1217
- function processElement(el: Element): void {
1218
- const code = el.getAttribute('_');
1219
- if (!code) return;
1220
-
1221
- try {
1222
- const parser = new HybridParser(code);
1223
- const ast = parser.parse();
1224
- executeAST(ast, el);
1225
- } catch (err) {
1226
- console.error('HyperFixi ${name} error:', err, 'Code:', code);
1227
- }
1228
- }
1229
-
1230
- function processElements(root: Element | Document = document): void {
1231
- const elements = root.querySelectorAll('[_]');
1232
- elements.forEach(processElement);
1233
- }
1234
-
1235
- // =============================================================================
1236
- // PUBLIC API
1237
- // =============================================================================
1238
- // Shape mirrors \`compatibility/bundle-shell.ts\` (BundleShellApi). The two are
1239
- // separate copies on purpose \u2014 a generated bundle is self-contained and must
1240
- // not import from @hyperfixi/core \u2014 so \`bundle-shell.test.ts\` asserts the
1241
- // emitted key set matches the handwritten one, the way Oracle 2 pins the two
1242
- // cmdMaps. \`run\`/\`eval\`/\`parserName\` are generated-only extras; see the
1243
- // witnessed-extras table in bundle-shell.ts for why they stay here and are not
1244
- // added to the shipped handwritten bundles.
1245
-
1246
- const api = {
1247
- version: '1.0.0-${name.toLowerCase().replace(/\s+/g, '-')}',
1248
-
1249
- parse(code: string): ASTNode {
1250
- const parser = new HybridParser(code);
1251
- return parser.parse();
1252
- },
1253
-
1254
- async execute(code: string, element?: Element): Promise<any> {
1255
- const me = element || document.body;
1256
- const parser = new HybridParser(code);
1257
- const ast = parser.parse();
1258
- return executeAST(ast, me);
1259
- },
1260
-
1261
- run: async (code: string, element?: Element) => api.execute(code, element),
1262
- eval: async (code: string, element?: Element) => api.execute(code, element),
1263
-
1264
- init: processElements,
1265
- process: processElements,
1266
-
1267
- commands: ${JSON.stringify(commands)},
1268
- ${blocks.length > 0 ? `blocks: ${JSON.stringify(blocks)},` : ''}
1269
- parserName: 'hybrid',
1270
- };
1271
-
1272
- // =============================================================================
1273
- // AUTO-INITIALIZE
1274
- // =============================================================================
1275
- ${autoInit
1276
- ? `
1277
- if (typeof window !== 'undefined') {
1278
- (window as any).${globalName} = api;
1279
-
1280
- if (document.readyState === 'loading') {
1281
- document.addEventListener('DOMContentLoaded', () => processElements());
1282
- } else {
1283
- processElements();
1284
- }
1285
- ${htmxIntegration
1286
- ? `
1287
- // HTMX integration
1288
- document.addEventListener('htmx:afterSettle', (e: Event) => {
1289
- const target = (e as CustomEvent).detail?.target;
1290
- if (target) processElements(target);
1291
- });
1292
- `
1293
- : ''}
1294
- }
1295
- `
1296
- : ''}
1297
- ${esModule
1298
- ? `
1299
- export default api;
1300
- export { api, processElements };
1301
- `
1302
- : ''}`;
1303
- }
1304
- function generateBundle(config) {
1305
- const warnings = [];
1306
- const errors = [];
1307
- const strict = config.validation?.strict ?? false;
1308
- const unknownCommands = config.commands.filter(cmd => !COMMAND_IMPLEMENTATIONS[resolveCommandKey(cmd)]);
1309
- for (const cmd of unknownCommands) {
1310
- const error = {
1311
- type: 'unknown-command',
1312
- message: `Unknown command '${cmd}' will not be included`,
1313
- name: cmd,
1314
- };
1315
- errors.push(error);
1316
- warnings.push(error.message);
1317
- }
1318
- const unknownBlocks = (config.blocks || []).filter(block => !BLOCK_IMPLEMENTATIONS[block]);
1319
- for (const block of unknownBlocks) {
1320
- const error = {
1321
- type: 'unknown-block',
1322
- message: `Unknown block '${block}' will not be included`,
1323
- name: block,
1324
- };
1325
- errors.push(error);
1326
- warnings.push(error.message);
1327
- }
1328
- if (strict && errors.length > 0) {
1329
- const errorMessages = errors.map(e => e.message).join('; ');
1330
- throw new Error(`Bundle generation failed (strict mode): ${errorMessages}`);
1331
- }
1332
- const code = generateBundleCode(config);
1333
- return {
1334
- code,
1335
- commands: config.commands.filter(cmd => COMMAND_IMPLEMENTATIONS[resolveCommandKey(cmd)]),
1336
- blocks: (config.blocks || []).filter(block => BLOCK_IMPLEMENTATIONS[block]),
1337
- positional: config.positionalExpressions || false,
1338
- warnings,
1339
- errors,
1340
- };
1341
- }
1342
-
1343
- const LITE_PARSER_TEMPLATE = `
1344
- // Lite Parser - Regex-based for minimal bundle size
1345
-
1346
- function parseLite(code) {
1347
- const trimmed = code.trim();
1348
-
1349
- // Handle event handlers: "on click toggle .active"
1350
- const onMatch = trimmed.match(/^on\\s+(\\w+)(?:\\s+from\\s+([^\\s]+))?\\s+(.+)$/i);
1351
- if (onMatch) {
1352
- return {
1353
- type: 'event',
1354
- event: onMatch[1],
1355
- filter: onMatch[2] ? { type: 'selector', value: onMatch[2] } : undefined,
1356
- modifiers: {},
1357
- body: parseCommands(onMatch[3]),
1358
- };
1359
- }
1360
-
1361
- // Handle "every Nms" event pattern
1362
- const everyMatch = trimmed.match(/^every\\s+(\\d+)(ms|s)?\\s+(.+)$/i);
1363
- if (everyMatch) {
1364
- const ms = everyMatch[2] === 's' ? parseInt(everyMatch[1]) * 1000 : parseInt(everyMatch[1]);
1365
- return {
1366
- type: 'event',
1367
- event: 'interval:' + ms,
1368
- modifiers: {},
1369
- body: parseCommands(everyMatch[3]),
1370
- };
1371
- }
1372
-
1373
- // Handle "init" pattern
1374
- const initMatch = trimmed.match(/^init\\s+(.+)$/i);
1375
- if (initMatch) {
1376
- return {
1377
- type: 'event',
1378
- event: 'init',
1379
- modifiers: {},
1380
- body: parseCommands(initMatch[1]),
1381
- };
1382
- }
1383
-
1384
- return { type: 'sequence', commands: parseCommands(trimmed) };
1385
- }
1386
-
1387
- function parseCommands(code) {
1388
- const parts = code.split(/\\s+(?:then|and)\\s+/i);
1389
- return parts.map(parseCommand).filter(Boolean);
1390
- }
1391
-
1392
- function parseCommand(code) {
1393
- const trimmed = code.trim();
1394
- if (!trimmed) return null;
1395
-
1396
- let match;
1397
-
1398
- // toggle .class [on target]
1399
- match = trimmed.match(/^toggle\\s+(\\.\\w+|\\w+)(?:\\s+on\\s+(.+))?$/i);
1400
- if (match) {
1401
- return {
1402
- type: 'command',
1403
- name: 'toggle',
1404
- args: [{ type: 'selector', value: match[1] }],
1405
- target: match[2] ? parseTarget(match[2]) : undefined,
1406
- };
1407
- }
1408
-
1409
- // add .class [to target]
1410
- match = trimmed.match(/^add\\s+(\\.\\w+|\\w+)(?:\\s+to\\s+(.+))?$/i);
1411
- if (match) {
1412
- return {
1413
- type: 'command',
1414
- name: 'add',
1415
- args: [{ type: 'selector', value: match[1] }],
1416
- target: match[2] ? parseTarget(match[2]) : undefined,
1417
- };
1418
- }
1419
-
1420
- // remove .class [from target] | remove [target]
1421
- match = trimmed.match(/^remove\\s+(\\.\\w+)(?:\\s+from\\s+(.+))?$/i);
1422
- if (match) {
1423
- return {
1424
- type: 'command',
1425
- name: 'removeClass',
1426
- args: [{ type: 'selector', value: match[1] }],
1427
- target: match[2] ? parseTarget(match[2]) : undefined,
1428
- };
1429
- }
1430
- match = trimmed.match(/^remove\\s+(.+)$/i);
1431
- if (match) {
1432
- return {
1433
- type: 'command',
1434
- name: 'remove',
1435
- args: [],
1436
- target: parseTarget(match[1]),
1437
- };
1438
- }
1439
-
1440
- // put "content" into target
1441
- match = trimmed.match(/^put\\s+(?:"([^"]+)"|'([^']+)'|(\\S+))\\s+(into|before|after)\\s+(.+)$/i);
1442
- if (match) {
1443
- const content = match[1] || match[2] || match[3];
1444
- return {
1445
- type: 'command',
1446
- name: 'put',
1447
- args: [{ type: 'literal', value: content }],
1448
- modifier: match[4],
1449
- target: parseTarget(match[5]),
1450
- };
1451
- }
1452
-
1453
- // set target to value | set :var to value
1454
- match = trimmed.match(/^set\\s+(.+?)\\s+to\\s+(.+)$/i);
1455
- if (match) {
1456
- return {
1457
- type: 'command',
1458
- name: 'set',
1459
- args: [parseTarget(match[1]), parseLiteValue(match[2])],
1460
- };
1461
- }
1462
-
1463
- // log message
1464
- match = trimmed.match(/^log\\s+(.+)$/i);
1465
- if (match) {
1466
- return {
1467
- type: 'command',
1468
- name: 'log',
1469
- args: [parseLiteValue(match[1])],
1470
- };
1471
- }
1472
-
1473
- // send event [to target]
1474
- match = trimmed.match(/^send\\s+(\\w+)(?:\\s+to\\s+(.+))?$/i);
1475
- if (match) {
1476
- return {
1477
- type: 'command',
1478
- name: 'send',
1479
- args: [{ type: 'literal', value: match[1] }],
1480
- target: match[2] ? parseTarget(match[2]) : undefined,
1481
- };
1482
- }
1483
-
1484
- // wait Nms | wait Ns
1485
- match = trimmed.match(/^wait\\s+(\\d+)(ms|s)?$/i);
1486
- if (match) {
1487
- const ms = match[2] === 's' ? parseInt(match[1]) * 1000 : parseInt(match[1]);
1488
- return {
1489
- type: 'command',
1490
- name: 'wait',
1491
- args: [{ type: 'literal', value: ms }],
1492
- };
1493
- }
1494
-
1495
- // show/hide shortcuts
1496
- match = trimmed.match(/^(show|hide)(?:\\s+(.+))?$/i);
1497
- if (match) {
1498
- return {
1499
- type: 'command',
1500
- name: match[1].toLowerCase(),
1501
- args: [],
1502
- target: match[2] ? parseTarget(match[2]) : undefined,
1503
- };
1504
- }
1505
-
1506
- // Unknown command - try generic parsing
1507
- const parts = trimmed.split(/\\s+/);
1508
- if (parts.length > 0) {
1509
- return {
1510
- type: 'command',
1511
- name: parts[0],
1512
- args: parts.slice(1).map(p => ({ type: 'literal', value: p })),
1513
- };
1514
- }
1515
-
1516
- return null;
1517
- }
1518
-
1519
- function parseTarget(str) {
1520
- const s = str.trim();
1521
- if (s === 'me') return { type: 'identifier', value: 'me' };
1522
- if (s === 'body') return { type: 'identifier', value: 'body' };
1523
- if (s.startsWith('#') || s.startsWith('.') || s.startsWith('[')) {
1524
- return { type: 'selector', value: s };
1525
- }
1526
- if (s.startsWith(':')) {
1527
- return { type: 'variable', name: s, scope: 'local' };
1528
- }
1529
- return { type: 'identifier', value: s };
1530
- }
1531
-
1532
- function parseLiteValue(str) {
1533
- const s = str.trim();
1534
- if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
1535
- return { type: 'literal', value: s.slice(1, -1) };
1536
- }
1537
- if (/^-?\\d+(\\.\\d+)?$/.test(s)) {
1538
- return { type: 'literal', value: parseFloat(s) };
1539
- }
1540
- if (s === 'true') return { type: 'literal', value: true };
1541
- if (s === 'false') return { type: 'literal', value: false };
1542
- if (s === 'null') return { type: 'literal', value: null };
1543
- if (s.startsWith(':')) return { type: 'variable', name: s, scope: 'local' };
1544
- if (s === 'me') return { type: 'identifier', value: 'me' };
1545
- return { type: 'identifier', value: s };
1546
- }
1547
- `;
1548
- const HYBRID_PARSER_TEMPLATE = `
1549
- // #region generated:hybrid-parser \u2014 DO NOT EDIT (npm run generate:bundles)
1550
- // Hybrid Parser \u2014 generated from parser/hybrid/{aliases,tokenizer,parser-core}.ts
1551
-
1552
- const COMMAND_ALIASES = {
1553
- flip: "toggle",
1554
- switch: "toggle",
1555
- display: "show",
1556
- reveal: "show",
1557
- conceal: "hide",
1558
- increase: "increment",
1559
- decrease: "decrement",
1560
- fire: "trigger",
1561
- dispatch: "send",
1562
- navigate: "go",
1563
- goto: "go"
1564
- };
1565
- const EVENT_ALIASES = {
1566
- clicked: "click",
1567
- pressed: "keydown",
1568
- changed: "change",
1569
- submitted: "submit",
1570
- loaded: "load"
1571
- };
1572
- function normalizeCommand(name) {
1573
- const lower = name.toLowerCase();
1574
- return COMMAND_ALIASES[lower] || lower;
1575
- }
1576
- function normalizeEvent(name) {
1577
- const lower = name.toLowerCase();
1578
- return EVENT_ALIASES[lower] || lower;
1579
- }
1580
- function addCommandAliases(aliases) {
1581
- Object.assign(COMMAND_ALIASES, aliases);
1582
- }
1583
- function addEventAliases(aliases) {
1584
- Object.assign(EVENT_ALIASES, aliases);
1585
- }
1586
-
1587
- const KEYWORDS = /* @__PURE__ */ new Set([
1588
- "on",
1589
- "from",
1590
- "to",
1591
- "into",
1592
- "before",
1593
- "after",
1594
- "in",
1595
- "of",
1596
- "at",
1597
- "with",
1598
- "if",
1599
- "else",
1600
- "unless",
1601
- "end",
1602
- "then",
1603
- "and",
1604
- "or",
1605
- "not",
1606
- "repeat",
1607
- "times",
1608
- "for",
1609
- "each",
1610
- "while",
1611
- "until",
1612
- "toggle",
1613
- "add",
1614
- "remove",
1615
- "put",
1616
- "set",
1617
- "get",
1618
- "call",
1619
- "return",
1620
- "append",
1621
- "prepend",
1622
- "log",
1623
- "send",
1624
- "trigger",
1625
- "wait",
1626
- "settle",
1627
- "fetch",
1628
- "as",
1629
- "show",
1630
- "hide",
1631
- "take",
1632
- "increment",
1633
- "decrement",
1634
- "focus",
1635
- "blur",
1636
- "go",
1637
- "transition",
1638
- "over",
1639
- "the",
1640
- "a",
1641
- "an",
1642
- "my",
1643
- "its",
1644
- "me",
1645
- "it",
1646
- "you",
1647
- "first",
1648
- "last",
1649
- "next",
1650
- "previous",
1651
- "closest",
1652
- "parent",
1653
- "true",
1654
- "false",
1655
- "null",
1656
- "undefined",
1657
- "is",
1658
- "matches",
1659
- "contains",
1660
- "includes",
1661
- "exists",
1662
- "has",
1663
- "init",
1664
- "every",
1665
- "by",
1666
- "halt",
1667
- "via",
1668
- "values",
1669
- "default",
1670
- "event"
1671
- ]);
1672
- function tokenize(code) {
1673
- const tokens = [];
1674
- let pos = 0;
1675
- while (pos < code.length) {
1676
- if (/\\s/.test(code[pos])) {
1677
- pos++;
1678
- continue;
1679
- }
1680
- if (code.slice(pos, pos + 2) === "--") {
1681
- while (pos < code.length && code[pos] !== "\\n") pos++;
1682
- continue;
1683
- }
1684
- const start = pos;
1685
- if (code[pos] === "<" && /[a-zA-Z]/.test(code[pos + 1] || "")) {
1686
- pos++;
1687
- while (pos < code.length && code[pos] !== ">") pos++;
1688
- if (code[pos] === ">") pos++;
1689
- const val = code.slice(start, pos);
1690
- if (val.endsWith("/>") || val.endsWith(">")) {
1691
- const normalized = val.slice(1).replace(/\\/?>$/, "");
1692
- tokens.push({ type: "selector", value: normalized, pos: start });
1693
- continue;
1694
- }
1695
- }
1696
- if (code.slice(pos, pos + 2) === "'s" && !/[a-zA-Z]/.test(code[pos + 2] || "")) {
1697
- tokens.push({ type: "operator", value: "'s", pos: start });
1698
- pos += 2;
1699
- continue;
1700
- }
1701
- if (code[pos] === '"' || code[pos] === "'") {
1702
- const quote = code[pos++];
1703
- while (pos < code.length && code[pos] !== quote) {
1704
- if (code[pos] === "\\\\") pos++;
1705
- pos++;
1706
- }
1707
- pos++;
1708
- tokens.push({ type: "string", value: code.slice(start, pos), pos: start });
1709
- continue;
1710
- }
1711
- if (/\\d/.test(code[pos]) || code[pos] === "-" && /\\d/.test(code[pos + 1] || "")) {
1712
- if (code[pos] === "-") pos++;
1713
- while (pos < code.length && /[\\d.]/.test(code[pos])) pos++;
1714
- if (code.slice(pos, pos + 2) === "ms") pos += 2;
1715
- else if (code[pos] === "s" && !/[a-zA-Z]/.test(code[pos + 1] || "")) pos++;
1716
- else if (code.slice(pos, pos + 2) === "px") pos += 2;
1717
- tokens.push({ type: "number", value: code.slice(start, pos), pos: start });
1718
- continue;
1719
- }
1720
- if (code[pos] === ":") {
1721
- pos++;
1722
- while (pos < code.length && /[\\w]/.test(code[pos])) pos++;
1723
- tokens.push({ type: "localVar", value: code.slice(start, pos), pos: start });
1724
- continue;
1725
- }
1726
- if (code[pos] === "$") {
1727
- pos++;
1728
- while (pos < code.length && /[\\w]/.test(code[pos])) pos++;
1729
- tokens.push({ type: "globalVar", value: code.slice(start, pos), pos: start });
1730
- continue;
1731
- }
1732
- if (code[pos] === "@") {
1733
- pos++;
1734
- while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
1735
- tokens.push({ type: "selector", value: code.slice(start, pos), pos: start });
1736
- continue;
1737
- }
1738
- if (code[pos] === "#" || code[pos] === ".") {
1739
- if (code[pos] === ".") {
1740
- const afterDot = code.slice(pos + 1).match(/^(once|prevent|stop|debounce|throttle)\\b/i);
1741
- if (afterDot) {
1742
- tokens.push({ type: "symbol", value: ".", pos: start });
1743
- pos++;
1744
- continue;
1745
- }
1746
- }
1747
- pos++;
1748
- while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
1749
- tokens.push({ type: "selector", value: code.slice(start, pos), pos: start });
1750
- continue;
1751
- }
1752
- if (code[pos] === "[") {
1753
- let lookahead = pos + 1;
1754
- while (lookahead < code.length && /\\s/.test(code[lookahead])) lookahead++;
1755
- const nextChar = code[lookahead] || "";
1756
- const isArrayLiteral = /['"\\d\\[\\]:\\$\\-]/.test(nextChar) || nextChar === "";
1757
- if (isArrayLiteral) {
1758
- tokens.push({ type: "symbol", value: "[", pos: start });
1759
- pos++;
1760
- continue;
1761
- } else {
1762
- pos++;
1763
- let depth = 1;
1764
- while (pos < code.length && depth > 0) {
1765
- if (code[pos] === "[") depth++;
1766
- if (code[pos] === "]") depth--;
1767
- pos++;
1768
- }
1769
- tokens.push({ type: "selector", value: code.slice(start, pos), pos: start });
1770
- continue;
1771
- }
1772
- }
1773
- if (code[pos] === "]") {
1774
- tokens.push({ type: "symbol", value: "]", pos: start });
1775
- pos++;
1776
- continue;
1777
- }
1778
- if (code.slice(pos, pos + 2) === "'s") {
1779
- tokens.push({ type: "operator", value: "'s", pos: start });
1780
- pos += 2;
1781
- continue;
1782
- }
1783
- const twoChar = code.slice(pos, pos + 2);
1784
- if (["==", "!=", "<=", ">=", "&&", "||"].includes(twoChar)) {
1785
- tokens.push({ type: "operator", value: twoChar, pos: start });
1786
- pos += 2;
1787
- continue;
1788
- }
1789
- if (code[pos] === "*" && /[a-zA-Z]/.test(code[pos + 1] || "")) {
1790
- pos++;
1791
- while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
1792
- tokens.push({ type: "styleProperty", value: code.slice(start, pos), pos: start });
1793
- continue;
1794
- }
1795
- if ("+-*/%<>!".includes(code[pos])) {
1796
- tokens.push({ type: "operator", value: code[pos], pos: start });
1797
- pos++;
1798
- continue;
1799
- }
1800
- if ("()[]{},.".includes(code[pos])) {
1801
- tokens.push({ type: "symbol", value: code[pos], pos: start });
1802
- pos++;
1803
- continue;
1804
- }
1805
- if (/[a-zA-Z_]/.test(code[pos])) {
1806
- while (pos < code.length && /[\\w-]/.test(code[pos])) pos++;
1807
- const value = code.slice(start, pos);
1808
- const type = KEYWORDS.has(value.toLowerCase()) ? "keyword" : "identifier";
1809
- tokens.push({ type, value, pos: start });
1810
- continue;
1811
- }
1812
- pos++;
1813
- }
1814
- tokens.push({ type: "eof", value: "", pos: code.length });
1815
- return tokens;
1816
- }
1817
-
1818
- var __defProp = Object.defineProperty;
1819
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1820
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1821
- class HybridParser {
1822
- constructor(code) {
1823
- __publicField(this, "tokens");
1824
- __publicField(this, "pos", 0);
1825
- /**
1826
- * The raw source. Kept because \`js \u2026 end\` must be sliced from it verbatim \u2014
1827
- * the tokenizer reads a JS body as hyperscript and mangles regexes, template
1828
- * literals and single quotes. Same approach as the full parser's
1829
- * \`parseJsCommand\`, which slices between token offsets for the same reason.
1830
- */
1831
- __publicField(this, "source");
1832
- /**
1833
- * Command keyword \u2192 parse rule. Built once per parse rather than once per
1834
- * command, and the single place the parser's command set is written down:
1835
- * \`isCommandKeyword()\` reads these keys instead of carrying its own copy.
1836
- *
1837
- * MUST stay in sync with \`bundle-generator/parser-templates.ts\`'s
1838
- * \`HYBRID_PARSER_TEMPLATE\` \u2014 core's \`generateBundle()\` imports this file
1839
- * while the vite-plugin's generator embeds that template, so a name in only
1840
- * one of them makes the reachable command set depend on which generator the
1841
- * user went through. Gated by \`capability-emission.test.ts\` \u00a73.
1842
- */
1843
- __publicField(this, "cmdMap", {
1844
- toggle: () => this.parseToggle(),
1845
- add: () => this.parseAdd(),
1846
- remove: () => this.parseRemove(),
1847
- put: () => this.parsePut(),
1848
- append: () => this.parseInsertion("append"),
1849
- prepend: () => this.parseInsertion("prepend"),
1850
- set: () => this.parseSet(),
1851
- get: () => this.parseGet(),
1852
- call: () => this.parseCall(),
1853
- log: () => this.parseLog(),
1854
- send: () => this.parseSend("to"),
1855
- // \`trigger <event> on <target>\` \u2014 same node as \`send\`, per the runtime,
1856
- // where \`trigger\` is a consolidation alias sharing \`send\`'s implementation.
1857
- // The target marker differs, which is why it is a parameter and not a
1858
- // second entry pointing at the same rule (that dropped the target).
1859
- trigger: () => this.parseSend("on"),
1860
- wait: () => this.parseWait(),
1861
- show: () => this.parseShow(),
1862
- hide: () => this.parseHide(),
1863
- take: () => this.parseTake(),
1864
- empty: () => this.parseEmpty(),
1865
- increment: () => this.parseIncDec("increment"),
1866
- decrement: () => this.parseIncDec("decrement"),
1867
- focus: () => this.parseFocusBlur("focus"),
1868
- blur: () => this.parseFocusBlur("blur"),
1869
- go: () => this.parseGo(),
1870
- return: () => this.parseReturn(),
1871
- transition: () => this.parseTransition(),
1872
- halt: () => this.parseHalt(),
1873
- copy: () => this.parseCopy(),
1874
- beep: () => this.parseBeep(),
1875
- push: () => this.parseUrlCommand("push"),
1876
- replace: () => this.parseUrlCommand("replace"),
1877
- morph: () => this.parseMorph(),
1878
- js: () => this.parseJs(),
1879
- throw: () => this.parseThrow(),
1880
- break: () => this.parseBare("break"),
1881
- continue: () => this.parseBare("continue"),
1882
- exit: () => this.parseBare("exit")
1883
- });
1884
- this.source = code;
1885
- this.tokens = tokenize(code);
1886
- }
1887
- peek(offset = 0) {
1888
- return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)];
1889
- }
1890
- advance() {
1891
- return this.tokens[this.pos++];
1892
- }
1893
- match(...values) {
1894
- const token = this.peek();
1895
- return values.some((v) => token.value.toLowerCase() === v.toLowerCase());
1896
- }
1897
- matchType(...types) {
1898
- return types.includes(this.peek().type);
1899
- }
1900
- expect(value) {
1901
- if (!this.match(value) && normalizeCommand(this.peek().value) !== value) {
1902
- throw new Error(\`Expected '\${value}', got '\${this.peek().value}'\`);
1903
- }
1904
- return this.advance();
1905
- }
1906
- isAtEnd() {
1907
- return this.peek().type === "eof";
1908
- }
1909
- parse() {
1910
- if (this.match("on")) return this.parseEventHandler();
1911
- if (this.match("init")) {
1912
- this.advance();
1913
- return { type: "event", event: "init", modifiers: {}, body: this.parseCommandSequence() };
1914
- }
1915
- if (this.match("every")) return this.parseEveryHandler();
1916
- return { type: "sequence", commands: this.parseCommandSequence() };
1917
- }
1918
- parseEventHandler() {
1919
- this.expect("on");
1920
- const eventName = this.advance().value;
1921
- const modifiers = {};
1922
- let filter;
1923
- while (this.peek().value === ".") {
1924
- this.advance();
1925
- const mod = this.advance().value.toLowerCase();
1926
- if (mod === "once") modifiers.once = true;
1927
- else if (mod === "prevent") modifiers.prevent = true;
1928
- else if (mod === "stop") modifiers.stop = true;
1929
- else if (mod === "debounce" || mod === "throttle") {
1930
- if (this.peek().value === "(") {
1931
- this.advance();
1932
- const num = this.advance().value;
1933
- this.expect(")");
1934
- if (mod === "debounce") modifiers.debounce = parseInt(num) || 100;
1935
- else modifiers.throttle = parseInt(num) || 100;
1936
- }
1937
- }
1938
- }
1939
- if (this.match("from")) {
1940
- this.advance();
1941
- filter = this.parseExpression();
1942
- }
1943
- return {
1944
- type: "event",
1945
- event: normalizeEvent(eventName),
1946
- filter,
1947
- modifiers,
1948
- body: this.parseCommandSequence()
1949
- };
1950
- }
1951
- parseEveryHandler() {
1952
- this.expect("every");
1953
- const interval = this.advance().value;
1954
- return {
1955
- type: "event",
1956
- event: \`interval:\${interval}\`,
1957
- modifiers: {},
1958
- body: this.parseCommandSequence()
1959
- };
1960
- }
1961
- parseCommandSequence() {
1962
- const commands = [];
1963
- while (!this.isAtEnd() && !this.match("end", "else")) {
1964
- const cmd = this.parseCommand();
1965
- if (cmd) commands.push(cmd);
1966
- if (this.match("then", "and")) this.advance();
1967
- }
1968
- return commands;
1969
- }
1970
- parseCommand() {
1971
- if (this.match("if", "unless")) return this.parseIf();
1972
- if (this.match("repeat")) return this.parseRepeat();
1973
- if (this.match("for")) return this.parseFor();
1974
- if (this.match("while")) return this.parseWhile();
1975
- if (this.match("fetch")) return this.parseFetchBlock();
1976
- const normalized = normalizeCommand(this.peek().value);
1977
- if (this.cmdMap[normalized]) {
1978
- return this.cmdMap[normalized]();
1979
- }
1980
- if (this.match("catch", "finally")) {
1981
- throw new Error(\`'\${this.peek().value}' needs the full parser (use hyperfixi.js)\`);
1982
- }
1983
- const stray = this.peek();
1984
- if (!this.isAtEnd() && (stray.type === "identifier" || stray.type === "keyword") && !this.match("then", "and", "end", "else")) {
1985
- throw new Error(\`'\${stray.value}' needs the full parser (use hyperfixi.js)\`);
1986
- }
1987
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
1988
- this.advance();
1989
- }
1990
- return null;
1991
- }
1992
- // Control flow parsing
1993
- parseIf() {
1994
- const isUnless = this.match("unless");
1995
- this.advance();
1996
- const condition = this.parseExpression();
1997
- const body = this.parseCommandSequence();
1998
- let elseBody;
1999
- if (this.match("else")) {
2000
- this.advance();
2001
- elseBody = this.parseCommandSequence();
2002
- }
2003
- if (this.match("end")) this.advance();
2004
- return {
2005
- type: "if",
2006
- condition: isUnless ? { type: "unary", operator: "not", operand: condition } : condition,
2007
- body,
2008
- elseBody
2009
- };
2010
- }
2011
- parseRepeat() {
2012
- this.expect("repeat");
2013
- let count;
2014
- if (!this.match("until", "while", "forever")) {
2015
- count = this.parseExpression();
2016
- if (this.match("times")) this.advance();
2017
- }
2018
- const body = this.parseCommandSequence();
2019
- if (this.match("end")) this.advance();
2020
- return { type: "repeat", condition: count, body };
2021
- }
2022
- parseFor() {
2023
- this.expect("for");
2024
- if (this.match("each")) this.advance();
2025
- const variable = this.advance().value;
2026
- this.expect("in");
2027
- const iterable = this.parseExpression();
2028
- const body = this.parseCommandSequence();
2029
- if (this.match("end")) this.advance();
2030
- return { type: "for", condition: { type: "forCondition", variable, iterable }, body };
2031
- }
2032
- parseWhile() {
2033
- this.expect("while");
2034
- const condition = this.parseExpression();
2035
- const body = this.parseCommandSequence();
2036
- if (this.match("end")) this.advance();
2037
- return { type: "while", condition, body };
2038
- }
2039
- /**
2040
- * A naked URL \u2014 \`fetch /api/data \u2026\`, \`fetch https://x/y \u2026\` \u2014 the way upstream
2041
- * reads one: everything up to the next whitespace, verbatim. The tokenizer
2042
- * splits \`/api/data\` into \`/\`, \`api\`, \`/\`, \`data\`, and \`parseExpression\` used
2043
- * to return the first \`/\` as the URL; the skip fallback then dropped the rest
2044
- * silently, so every unquoted \`fetch /path\` in a hybrid bundle fetched \`/\`.
2045
- * Measured 2026-09-04 when the fallback stopped being silent.
2046
- */
2047
- parseNakedUrl() {
2048
- const tok = this.peek();
2049
- const isSlash = tok.type === "operator" && tok.value === "/";
2050
- const isScheme = (tok.value === "http" || tok.value === "https") && this.source.slice(tok.pos + tok.value.length, tok.pos + tok.value.length + 3) === "://";
2051
- if (!isSlash && !isScheme) return null;
2052
- let end = tok.pos;
2053
- while (end < this.source.length && !/\\s/.test(this.source[end])) end++;
2054
- while (!this.isAtEnd() && this.peek().pos < end) this.advance();
2055
- return { type: "literal", value: this.source.slice(tok.pos, end) };
2056
- }
2057
- parseFetchBlock() {
2058
- this.expect("fetch");
2059
- const url = this.parseNakedUrl() ?? this.parseExpression();
2060
- let responseType = { type: "literal", value: "text" };
2061
- let options;
2062
- let method;
2063
- if (this.match("{")) {
2064
- this.pos--;
2065
- options = this.parseExpression();
2066
- }
2067
- for (let i = 0; i < 3; i++) {
2068
- if (this.match("via") && !method) {
2069
- this.advance();
2070
- method = this.parseExpression();
2071
- continue;
2072
- }
2073
- if (this.match("as")) {
2074
- this.advance();
2075
- if (this.match("a") || this.match("an")) this.advance();
2076
- responseType = this.parseExpression();
2077
- continue;
2078
- }
2079
- if (this.match("with") && !options) {
2080
- this.advance();
2081
- options = this.parseExpression();
2082
- continue;
2083
- }
2084
- break;
2085
- }
2086
- if (this.match("then")) this.advance();
2087
- const body = this.parseCommandSequence();
2088
- return {
2089
- type: "fetch",
2090
- condition: { type: "fetchConfig", url, responseType, options, method },
2091
- body
2092
- };
2093
- }
2094
- // Command parsing
2095
- parseToggle() {
2096
- this.expect("toggle");
2097
- const what = this.parseExpression();
2098
- let target;
2099
- if (this.match("on")) {
2100
- this.advance();
2101
- target = this.parseExpression();
2102
- }
2103
- return { type: "command", name: "toggle", args: [what], target };
2104
- }
2105
- parseAdd() {
2106
- this.expect("add");
2107
- const what = this.parseExpression();
2108
- let target;
2109
- if (this.match("to")) {
2110
- this.advance();
2111
- target = this.parseExpression();
2112
- }
2113
- return { type: "command", name: "add", args: [what], target };
2114
- }
2115
- parseRemove() {
2116
- this.expect("remove");
2117
- if (this.matchType("selector") && /^[.@]/.test(this.peek().value)) {
2118
- const what = this.parseExpression();
2119
- let target2;
2120
- if (this.match("from")) {
2121
- this.advance();
2122
- target2 = this.parseExpression();
2123
- }
2124
- return { type: "command", name: "removeClass", args: [what], target: target2 };
2125
- }
2126
- const target = this.parseExpression();
2127
- return { type: "command", name: "remove", args: [], target };
2128
- }
2129
- parsePut() {
2130
- this.expect("put");
2131
- const content = this.parseExpression();
2132
- let modifier = "into";
2133
- if (this.match("into", "before", "after", "at")) {
2134
- modifier = this.advance().value;
2135
- if (modifier === "at") {
2136
- const pos = this.advance().value;
2137
- this.expect("of");
2138
- modifier = \`at \${pos} of\`;
2139
- }
2140
- }
2141
- const target = this.parseExpression();
2142
- return { type: "command", name: "put", args: [content], target, modifier };
2143
- }
2144
- /** \`append\`/\`prepend <content> [to <target>]\` \u2014 identical shape, both ends. */
2145
- parseInsertion(name) {
2146
- this.expect(name);
2147
- const content = this.parseExpression();
2148
- let target;
2149
- if (this.match("to")) {
2150
- this.advance();
2151
- target = this.parseExpression();
2152
- }
2153
- return { type: "command", name, args: [content], target };
2154
- }
2155
- parseSet() {
2156
- this.expect("set");
2157
- const target = this.parseExpression();
2158
- if (this.match("to")) {
2159
- this.advance();
2160
- const value = this.parseExpression();
2161
- return { type: "command", name: "set", args: [target, value] };
2162
- }
2163
- return { type: "command", name: "set", args: [target] };
2164
- }
2165
- parseGet() {
2166
- this.expect("get");
2167
- return { type: "command", name: "get", args: [this.parseExpression()] };
2168
- }
2169
- parseCall() {
2170
- this.expect("call");
2171
- return { type: "command", name: "call", args: [this.parseExpression()] };
2172
- }
2173
- parseLog() {
2174
- this.expect("log");
2175
- const args = [];
2176
- while (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
2177
- args.push(this.parseExpression());
2178
- if (this.match(",")) this.advance();
2179
- else break;
2180
- }
2181
- return { type: "command", name: "log", args };
2182
- }
2183
- /**
2184
- * \`send <event> to <target>\` / \`trigger <event> on <target>\`.
2185
- *
2186
- * Both emit a \`send\` node \u2014 the runtime registers \`trigger\` as a
2187
- * consolidation alias sharing \`send\`'s implementation, so the bundle
2188
- * generator carries one template for both. The marker is a parameter
2189
- * because it is the ONLY difference: \`trigger\` used to reuse this rule with
2190
- * \`to\` hardcoded, which parsed the event name and then silently abandoned
2191
- * \`on #target\`, leaving the dispatch to land on \`me\`.
2192
- */
2193
- parseSend(marker) {
2194
- this.advance();
2195
- const first = this.advance();
2196
- let event = first.value;
2197
- let end = first.pos + first.value.length;
2198
- while (!this.isAtEnd() && this.peek().type === "localVar" && this.peek().pos === end) {
2199
- const piece = this.advance();
2200
- event += piece.value;
2201
- end = piece.pos + piece.value.length;
2202
- }
2203
- let target;
2204
- if (this.match(marker)) {
2205
- this.advance();
2206
- target = this.parseExpression();
2207
- }
2208
- return { type: "command", name: "send", args: [{ type: "literal", value: event }], target };
2209
- }
2210
- parseWait() {
2211
- this.expect("wait");
2212
- if (this.match("for")) {
2213
- this.advance();
2214
- const event = this.advance().value;
2215
- let target;
2216
- if (this.match("from")) {
2217
- this.advance();
2218
- target = this.parseExpression();
2219
- }
2220
- return {
2221
- type: "command",
2222
- name: "waitFor",
2223
- args: [{ type: "literal", value: event }],
2224
- target
2225
- };
2226
- }
2227
- return { type: "command", name: "wait", args: [this.parseExpression()] };
2228
- }
2229
- parseShow() {
2230
- this.expect("show");
2231
- let target;
2232
- const modifiers = {};
2233
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else", "when", "where")) {
2234
- target = this.parseExpression();
2235
- }
2236
- if (!this.isAtEnd() && this.match("when", "where")) {
2237
- const keyword = this.advance().value;
2238
- modifiers[keyword] = this.parseExpression();
2239
- }
2240
- return { type: "command", name: "show", args: [], target, modifiers };
2241
- }
2242
- parseHide() {
2243
- this.expect("hide");
2244
- let target;
2245
- const modifiers = {};
2246
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else", "when", "where")) {
2247
- target = this.parseExpression();
2248
- }
2249
- if (!this.isAtEnd() && this.match("when", "where")) {
2250
- const keyword = this.advance().value;
2251
- modifiers[keyword] = this.parseExpression();
2252
- }
2253
- return { type: "command", name: "hide", args: [], target, modifiers };
2254
- }
2255
- parseTake() {
2256
- this.expect("take");
2257
- const what = this.parseExpression();
2258
- let from;
2259
- if (this.match("from")) {
2260
- this.advance();
2261
- from = this.parseExpression();
2262
- }
2263
- return { type: "command", name: "take", args: [what], target: from };
2264
- }
2265
- parseIncDec(name) {
2266
- this.advance();
2267
- const target = this.parseExpression();
2268
- let amount = { type: "literal", value: 1 };
2269
- if (this.match("by")) {
2270
- this.advance();
2271
- amount = this.parseExpression();
2272
- }
2273
- return { type: "command", name, args: [target, amount] };
2274
- }
2275
- parseFocusBlur(name) {
2276
- this.advance();
2277
- let target;
2278
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
2279
- target = this.parseExpression();
2280
- }
2281
- return { type: "command", name, args: [], target };
2282
- }
2283
- parseGo() {
2284
- this.expect("go");
2285
- if (this.match("to")) this.advance();
2286
- if (this.match("url")) this.advance();
2287
- const dest = this.parseExpression();
2288
- return { type: "command", name: "go", args: [dest] };
2289
- }
2290
- parseReturn() {
2291
- this.expect("return");
2292
- let value;
2293
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
2294
- value = this.parseExpression();
2295
- }
2296
- return { type: "command", name: "return", args: value ? [value] : [] };
2297
- }
2298
- // ---------------------------------------------------------------------------
2299
- // Rules restoring the commands the capability list advertised but this parser
2300
- // could not reach (Finding 13). Every one already had a working template in
2301
- // \`bundle-generator/templates.ts\`; only the parse rule was missing, so the
2302
- // emitted \`case\` label was dead and the user's source silently no-opped.
2303
- // ---------------------------------------------------------------------------
2304
- /** \`empty [<target>]\` \u2014 clears children. Defaults to \`me\`. */
2305
- parseEmpty() {
2306
- this.expect("empty");
2307
- let target;
2308
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
2309
- target = this.parseExpression();
2310
- }
2311
- return { type: "command", name: "empty", args: [], target };
2312
- }
2313
- /** \`copy <value>\` \u2014 clipboard write. */
2314
- parseCopy() {
2315
- this.expect("copy");
2316
- return { type: "command", name: "copy", args: [this.parseExpression()] };
2317
- }
2318
- /**
2319
- * \`beep[!] [<value>, \u2026]\` \u2014 debug echo.
2320
- *
2321
- * Upstream spells it \`beep!\`; hyperfixi accepts both (see the tier list's
2322
- * note on the same nuance). The \`!\` is consumed here because the tokenizer
2323
- * emits it as a separate operator, and \`parseUnary\` would otherwise read it
2324
- * as logical negation of the first argument.
2325
- */
2326
- parseBeep() {
2327
- this.advance();
2328
- if (this.match("!")) this.advance();
2329
- const args = [];
2330
- while (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
2331
- args.push(this.parseExpression());
2332
- if (this.match(",")) this.advance();
2333
- else break;
2334
- }
2335
- return { type: "command", name: "beep", args };
2336
- }
2337
- /**
2338
- * \`push|replace url <url> [with title <title>]\` \u2014 History API navigation.
2339
- *
2340
- * The \`url\` keyword is consumed here rather than left for the executor, the
2341
- * way \`parseGo\` already does it. Note \`push-url\` / \`replace-url\` are NOT
2342
- * source spellings \u2014 the full parser rejects both \u2014 they exist only as
2343
- * bundle-config aliases resolving to these templates.
2344
- */
2345
- parseUrlCommand(name) {
2346
- this.advance();
2347
- if (this.match("url")) this.advance();
2348
- const url = this.parseExpression();
2349
- const modifiers = {};
2350
- if (this.match("with")) {
2351
- this.advance();
2352
- if (this.match("title")) {
2353
- this.advance();
2354
- modifiers.title = this.parseExpression();
2355
- }
2356
- }
2357
- return { type: "command", name, args: [url], modifiers };
2358
- }
2359
- /** \`morph [over] <target> to|with|into <content>\` \u2014 upstream spells it \`to\`; the full parser also takes \`with\`; \`into\` is this parser's own. */
2360
- parseMorph() {
2361
- this.expect("morph");
2362
- let modifier;
2363
- if (this.match("over")) {
2364
- this.advance();
2365
- modifier = "over";
2366
- }
2367
- const target = this.parseExpression();
2368
- if (this.match("with", "to", "into")) this.advance();
2369
- const content = this.parseExpression();
2370
- return { type: "command", name: "morph", args: [content], target, modifier };
2371
- }
2372
- /**
2373
- * \`js[(<params>)] <raw JavaScript> end\`.
2374
- *
2375
- * The body is sliced from the ORIGINAL SOURCE between token offsets, never
2376
- * reassembled from tokens \u2014 the tokenizer reads it as hyperscript, which
2377
- * mangles regexes, template literals and possessive-looking quotes. This
2378
- * mirrors the full parser's \`parseJsCommand\`.
2379
- *
2380
- * Known limit: the terminator scan matches the \`end\` TOKEN, so \`end\` inside a
2381
- * JS *string* is safe (the tokenizer keeps a string as one token, quotes
2382
- * included) but a bare JS identifier named \`end\` would cut the body early.
2383
- * The full parser's \`findJsEndBoundary\` handles that; replicating it is not
2384
- * worth the bytes in a bundle this size.
2385
- */
2386
- parseJs() {
2387
- this.advance();
2388
- if (this.match("(")) {
2389
- while (!this.isAtEnd() && !this.match(")")) this.advance();
2390
- if (this.match(")")) this.advance();
2391
- }
2392
- const start = this.peek().pos;
2393
- while (!this.isAtEnd() && !this.match("end")) this.advance();
2394
- const stop = this.peek().pos;
2395
- if (this.match("end")) this.advance();
2396
- const code = this.source.slice(start, stop).trim();
2397
- return { type: "command", name: "js", args: [{ type: "literal", value: code }] };
2398
- }
2399
- /** \`throw <value>\` */
2400
- parseThrow() {
2401
- this.expect("throw");
2402
- let value;
2403
- if (!this.isAtEnd() && !this.match("then", "and", "end", "else")) {
2404
- value = this.parseExpression();
2405
- }
2406
- return { type: "command", name: "throw", args: value ? [value] : [] };
2407
- }
2408
- /** \`break\` / \`continue\` / \`exit\` \u2014 bare control-flow signals, no arguments. */
2409
- parseBare(name) {
2410
- this.advance();
2411
- return { type: "command", name, args: [] };
2412
- }
2413
- parseHalt() {
2414
- this.expect("halt");
2415
- if (this.match("the")) this.advance();
2416
- if (this.match("event", "default")) this.advance();
2417
- return { type: "command", name: "halt", args: [] };
2418
- }
2419
- // transition <property> to <value> [over <duration>]
2420
- parseTransition() {
2421
- this.expect("transition");
2422
- let target;
2423
- if (this.match("my", "its")) {
2424
- const ref = this.advance().value;
2425
- target = { type: "identifier", value: ref === "my" ? "me" : "it" };
2426
- } else if (this.matchType("selector")) {
2427
- const expr = this.parseExpression();
2428
- if (expr.type === "possessive") {
2429
- return this.parseTransitionRest(expr.object, expr.property);
2430
- }
2431
- target = expr;
2432
- }
2433
- const propToken = this.peek();
2434
- let property;
2435
- if (propToken.type === "styleProperty") {
2436
- property = this.advance().value;
2437
- } else if (propToken.type === "identifier" || propToken.type === "keyword") {
2438
- property = this.advance().value;
2439
- } else {
2440
- property = "opacity";
2441
- }
2442
- return this.parseTransitionRest(target, property);
2443
- }
2444
- parseTransitionRest(target, property) {
2445
- let toValue = { type: "literal", value: 1 };
2446
- if (this.match("to")) {
2447
- this.advance();
2448
- toValue = this.parseExpression();
2449
- }
2450
- let duration = { type: "literal", value: 300 };
2451
- if (this.match("over")) {
2452
- this.advance();
2453
- duration = this.parseExpression();
2454
- }
2455
- return {
2456
- type: "command",
2457
- name: "transition",
2458
- args: [{ type: "literal", value: property }, toValue, duration],
2459
- target
2460
- };
2461
- }
2462
- // Expression parsing with operator precedence
2463
- parseExpression() {
2464
- return this.parseOr();
2465
- }
2466
- parseOr() {
2467
- let left = this.parseAnd();
2468
- while (this.match("or", "||")) {
2469
- this.advance();
2470
- left = { type: "binary", operator: "or", left, right: this.parseAnd() };
2471
- }
2472
- return left;
2473
- }
2474
- parseAnd() {
2475
- let left = this.parseEquality();
2476
- while (this.match("and", "&&") && !this.isCommandKeyword(this.peek(1))) {
2477
- this.advance();
2478
- left = { type: "binary", operator: "and", left, right: this.parseEquality() };
2479
- }
2480
- return left;
2481
- }
2482
- /**
2483
- * Does this token start a command rather than continue an expression?
2484
- *
2485
- * Used in two places with different stakes: terminating an \`and\` chain
2486
- * (\`toggle .x and add .y\`), and refusing to read a command name as a
2487
- * possessive property (\`my show\`).
2488
- *
2489
- * This is a deliberate SUBSET of \`cmdMap\`'s keys, not a second copy of it \u2014
2490
- * asserted as a subset in \`capability-emission.test.ts\` \u00a74 so it cannot
2491
- * name something the parser does not dispatch. It is not the full set
2492
- * because several of the newer keys are ordinary English or JS words
2493
- * (\`copy\`, \`empty\`, \`push\`, \`replace\`, \`break\`) that appear as property
2494
- * names and operands; promoting them here would change expression parsing,
2495
- * which is a separate decision from command reachability. The cost is that
2496
- * \`\u2026 and break\` reads \`break\` as an operand; \`then\` is the canonical
2497
- * separator and is handled by \`parseCommandSequence\` directly.
2498
- */
2499
- isCommandKeyword(token) {
2500
- const cmds = [
2501
- "toggle",
2502
- "add",
2503
- "remove",
2504
- "set",
2505
- "put",
2506
- "log",
2507
- "send",
2508
- "wait",
2509
- "show",
2510
- "hide",
2511
- "increment",
2512
- "decrement",
2513
- "focus",
2514
- "blur",
2515
- "go"
2516
- ];
2517
- return cmds.includes(normalizeCommand(token.value));
2518
- }
2519
- parseEquality() {
2520
- let left = this.parseComparison();
2521
- while (this.match("==", "!=", "is", "matches", "contains", "includes", "has")) {
2522
- const op = this.advance().value;
2523
- if (op.toLowerCase() === "is" && this.match("not")) {
2524
- this.advance();
2525
- left = { type: "binary", operator: "is not", left, right: this.parseComparison() };
2526
- } else {
2527
- left = { type: "binary", operator: op, left, right: this.parseComparison() };
2528
- }
2529
- }
2530
- return left;
2531
- }
2532
- parseComparison() {
2533
- let left = this.parseAdditive();
2534
- while (this.match("<", ">", "<=", ">=")) {
2535
- const op = this.advance().value;
2536
- left = { type: "binary", operator: op, left, right: this.parseAdditive() };
2537
- }
2538
- return left;
2539
- }
2540
- parseAdditive() {
2541
- let left = this.parseMultiplicative();
2542
- while (this.match("+", "-")) {
2543
- const op = this.advance().value;
2544
- left = { type: "binary", operator: op, left, right: this.parseMultiplicative() };
2545
- }
2546
- return left;
2547
- }
2548
- parseMultiplicative() {
2549
- let left = this.parseUnary();
2550
- while (this.match("*", "/", "%")) {
2551
- const op = this.advance().value;
2552
- left = { type: "binary", operator: op, left, right: this.parseUnary() };
2553
- }
2554
- return left;
2555
- }
2556
- parseUnary() {
2557
- if (this.match("beep") && this.peek(1).value === "!") {
2558
- throw new Error(\`'beep!' needs the full parser (use hyperfixi.js)\`);
2559
- }
2560
- if (this.match("not", "!")) {
2561
- this.advance();
2562
- return { type: "unary", operator: "not", operand: this.parseUnary() };
2563
- }
2564
- if (this.match("-") && this.peek(1).type === "number") {
2565
- this.advance();
2566
- const num = this.advance();
2567
- return { type: "literal", value: -parseFloat(num.value) };
2568
- }
2569
- return this.parsePostfix();
2570
- }
2571
- parsePostfix() {
2572
- let left = this.parsePrimary();
2573
- while (true) {
2574
- if (this.match("'s")) {
2575
- this.advance();
2576
- const next = this.peek();
2577
- const prop = next.type === "styleProperty" ? this.advance().value : this.advance().value;
2578
- left = { type: "possessive", object: left, property: prop };
2579
- } else if (this.peek().type === "styleProperty") {
2580
- const prop = this.advance().value;
2581
- left = { type: "possessive", object: left, property: prop };
2582
- } else if (this.peek().value === ".") {
2583
- this.advance();
2584
- const prop = this.advance().value;
2585
- left = { type: "member", object: left, property: prop };
2586
- } else if (this.peek().type === "selector" && this.peek().value.startsWith(".")) {
2587
- const prop = this.advance().value.slice(1);
2588
- left = { type: "member", object: left, property: prop };
2589
- } else if (this.peek().value === "(") {
2590
- this.advance();
2591
- const args = [];
2592
- while (!this.match(")")) {
2593
- args.push(this.parseExpression());
2594
- if (this.match(",")) this.advance();
2595
- }
2596
- this.expect(")");
2597
- left = { type: "call", callee: left, args };
2598
- } else if (this.peek().value === "[" && left.type !== "selector") {
2599
- this.advance();
2600
- const index = this.parseExpression();
2601
- this.expect("]");
2602
- left = { type: "member", object: left, property: index, computed: true };
2603
- } else {
2604
- break;
2605
- }
2606
- }
2607
- return left;
2608
- }
2609
- parsePrimary() {
2610
- const token = this.peek();
2611
- if (token.value === "(") {
2612
- this.advance();
2613
- const expr = this.parseExpression();
2614
- this.expect(")");
2615
- return expr;
2616
- }
2617
- if (token.value === "{") return this.parseObjectLiteral();
2618
- if (token.value === "[") return this.parseArrayLiteral();
2619
- if (token.type === "number") {
2620
- this.advance();
2621
- const val = token.value;
2622
- if (val.endsWith("ms")) return { type: "literal", value: parseInt(val), unit: "ms" };
2623
- if (val.endsWith("s")) return { type: "literal", value: parseFloat(val) * 1e3, unit: "ms" };
2624
- return { type: "literal", value: parseFloat(val) };
2625
- }
2626
- if (token.type === "string") {
2627
- this.advance();
2628
- return { type: "literal", value: token.value.slice(1, -1) };
2629
- }
2630
- if (this.match("true")) {
2631
- this.advance();
2632
- return { type: "literal", value: true };
2633
- }
2634
- if (this.match("false")) {
2635
- this.advance();
2636
- return { type: "literal", value: false };
2637
- }
2638
- if (this.match("null")) {
2639
- this.advance();
2640
- return { type: "literal", value: null };
2641
- }
2642
- if (this.match("undefined")) {
2643
- this.advance();
2644
- return { type: "literal", value: void 0 };
2645
- }
2646
- if (token.type === "localVar") {
2647
- this.advance();
2648
- return { type: "variable", name: token.value, scope: "local" };
2649
- }
2650
- if (token.type === "globalVar") {
2651
- this.advance();
2652
- return { type: "variable", name: token.value, scope: "global" };
2653
- }
2654
- if (token.type === "selector") {
2655
- this.advance();
2656
- return { type: "selector", value: token.value };
2657
- }
2658
- if (this.match("my")) {
2659
- this.advance();
2660
- const next = this.peek();
2661
- if ((next.type === "identifier" || next.type === "keyword") && !this.isCommandKeyword(next)) {
2662
- const prop = this.advance().value;
2663
- return { type: "possessive", object: { type: "identifier", value: "me" }, property: prop };
2664
- }
2665
- return { type: "identifier", value: "me" };
2666
- }
2667
- if (this.match("its")) {
2668
- this.advance();
2669
- const next = this.peek();
2670
- if ((next.type === "identifier" || next.type === "keyword") && !this.isCommandKeyword(next)) {
2671
- const prop = this.advance().value;
2672
- return { type: "possessive", object: { type: "identifier", value: "it" }, property: prop };
2673
- }
2674
- return { type: "identifier", value: "it" };
2675
- }
2676
- if (this.match("me")) {
2677
- this.advance();
2678
- return { type: "identifier", value: "me" };
2679
- }
2680
- if (this.match("it")) {
2681
- this.advance();
2682
- return { type: "identifier", value: "it" };
2683
- }
2684
- if (this.match("you")) {
2685
- this.advance();
2686
- return { type: "identifier", value: "you" };
2687
- }
2688
- if (this.match("the", "a", "an")) {
2689
- this.advance();
2690
- if (this.match("first", "last", "next", "previous", "closest", "parent")) {
2691
- const position = this.advance().value;
2692
- const target = this.parsePositionalTarget();
2693
- return { type: "positional", position, target };
2694
- }
2695
- return this.parsePrimary();
2696
- }
2697
- if (this.match("first", "last", "next", "previous", "closest", "parent")) {
2698
- const position = this.advance().value;
2699
- const target = this.parsePositionalTarget();
2700
- return { type: "positional", position, target };
2701
- }
2702
- if (this.match("values")) {
2703
- this.advance();
2704
- if (this.match("of")) {
2705
- this.advance();
2706
- const target = this.parseExpression();
2707
- return { type: "valuesOf", target };
2708
- }
2709
- return { type: "identifier", value: token.value };
2710
- }
2711
- if (token.type === "identifier" || token.type === "keyword") {
2712
- this.advance();
2713
- return { type: "identifier", value: token.value };
2714
- }
2715
- this.advance();
2716
- return { type: "identifier", value: token.value };
2717
- }
2718
- parseObjectLiteral() {
2719
- this.expect("{");
2720
- const properties = [];
2721
- while (!this.match("}")) {
2722
- const key = this.advance().value;
2723
- this.expect(":");
2724
- const value = this.parseExpression();
2725
- properties.push({ key, value });
2726
- if (this.match(",")) this.advance();
2727
- }
2728
- this.expect("}");
2729
- return { type: "object", properties };
2730
- }
2731
- parseArrayLiteral() {
2732
- this.expect("[");
2733
- const elements = [];
2734
- while (!this.match("]")) {
2735
- elements.push(this.parseExpression());
2736
- if (this.match(",")) this.advance();
2737
- }
2738
- this.expect("]");
2739
- return { type: "array", elements };
2740
- }
2741
- parsePositionalTarget() {
2742
- const token = this.peek();
2743
- if (token.type === "selector") {
2744
- return { type: "selector", value: this.advance().value };
2745
- }
2746
- if (token.type === "identifier" || token.type === "keyword") {
2747
- return { type: "identifier", value: this.advance().value };
2748
- }
2749
- return this.parseExpression();
2750
- }
2751
- }
2752
- // #endregion generated:hybrid-parser
2753
- `;
2754
- function getParserTemplate(type) {
2755
- return type === 'lite' ? LITE_PARSER_TEMPLATE : HYBRID_PARSER_TEMPLATE;
2756
- }
2757
- const LITE_PARSER_COMMANDS = [
2758
- 'toggle',
2759
- 'add',
2760
- 'remove',
2761
- 'put',
2762
- 'set',
2763
- 'log',
2764
- 'send',
2765
- 'wait',
2766
- 'show',
2767
- 'hide',
2768
- ];
2769
- function canUseLiteParser(commands, blocks, positional) {
2770
- if (blocks.length > 0)
2771
- return false;
2772
- if (positional)
2773
- return false;
2774
- const liteCommands = new Set(LITE_PARSER_COMMANDS);
2775
- return commands.every(cmd => liteCommands.has(cmd));
2776
- }
2777
-
2778
- export { AVAILABLE_BLOCKS, AVAILABLE_COMMANDS, BLOCK_IMPLEMENTATIONS, COMMAND_ALIASES, COMMAND_IMPLEMENTATIONS, ELEMENT_ARRAY_COMMANDS, FULL_RUNTIME_ONLY_COMMANDS, HYBRID_PARSER_TEMPLATE, LITE_PARSER_COMMANDS, LITE_PARSER_TEMPLATE, MORPH_COMMANDS, STYLE_COMMANDS, canUseLiteParser, generateBundle, generateBundleCode, getAvailableBlocks, getAvailableCommands, getBlockImplementations, getCommandImplementations, getParserTemplate, isAvailableBlock, isAvailableCommand, requiresFullRuntime, resolveCommandKey };
2779
- //# sourceMappingURL=index.mjs.map