@hyperfixi/core 3.2.0 → 4.0.0

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