@lokascript/semantic 1.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 (435) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +686 -0
  3. package/dist/browser-ar.ar.global.js +2 -0
  4. package/dist/browser-core.core.global.js +2 -0
  5. package/dist/browser-de.de.global.js +2 -0
  6. package/dist/browser-east-asian.east-asian.global.js +2 -0
  7. package/dist/browser-en-tr.en-tr.global.js +2 -0
  8. package/dist/browser-en.en.global.js +2 -0
  9. package/dist/browser-es-en.es-en.global.js +2 -0
  10. package/dist/browser-es.es.global.js +2 -0
  11. package/dist/browser-fr.fr.global.js +2 -0
  12. package/dist/browser-id.id.global.js +2 -0
  13. package/dist/browser-ja.ja.global.js +2 -0
  14. package/dist/browser-ko.ko.global.js +2 -0
  15. package/dist/browser-lazy.lazy.global.js +2 -0
  16. package/dist/browser-priority.priority.global.js +2 -0
  17. package/dist/browser-pt.pt.global.js +2 -0
  18. package/dist/browser-qu.qu.global.js +2 -0
  19. package/dist/browser-sw.sw.global.js +2 -0
  20. package/dist/browser-tr.tr.global.js +2 -0
  21. package/dist/browser-western.western.global.js +2 -0
  22. package/dist/browser-zh.zh.global.js +2 -0
  23. package/dist/browser.global.js +3 -0
  24. package/dist/browser.global.js.map +1 -0
  25. package/dist/index.cjs +35051 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +3426 -0
  28. package/dist/index.d.ts +3426 -0
  29. package/dist/index.js +34890 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/languages/ar.d.ts +78 -0
  32. package/dist/languages/ar.js +1622 -0
  33. package/dist/languages/ar.js.map +1 -0
  34. package/dist/languages/de.d.ts +38 -0
  35. package/dist/languages/de.js +1168 -0
  36. package/dist/languages/de.js.map +1 -0
  37. package/dist/languages/en.d.ts +44 -0
  38. package/dist/languages/en.js +3491 -0
  39. package/dist/languages/en.js.map +1 -0
  40. package/dist/languages/es.d.ts +52 -0
  41. package/dist/languages/es.js +1493 -0
  42. package/dist/languages/es.js.map +1 -0
  43. package/dist/languages/fr.d.ts +37 -0
  44. package/dist/languages/fr.js +1159 -0
  45. package/dist/languages/fr.js.map +1 -0
  46. package/dist/languages/id.d.ts +35 -0
  47. package/dist/languages/id.js +1152 -0
  48. package/dist/languages/id.js.map +1 -0
  49. package/dist/languages/ja.d.ts +53 -0
  50. package/dist/languages/ja.js +1430 -0
  51. package/dist/languages/ja.js.map +1 -0
  52. package/dist/languages/ko.d.ts +51 -0
  53. package/dist/languages/ko.js +1729 -0
  54. package/dist/languages/ko.js.map +1 -0
  55. package/dist/languages/pt.d.ts +37 -0
  56. package/dist/languages/pt.js +1127 -0
  57. package/dist/languages/pt.js.map +1 -0
  58. package/dist/languages/qu.d.ts +36 -0
  59. package/dist/languages/qu.js +1143 -0
  60. package/dist/languages/qu.js.map +1 -0
  61. package/dist/languages/sw.d.ts +35 -0
  62. package/dist/languages/sw.js +1147 -0
  63. package/dist/languages/sw.js.map +1 -0
  64. package/dist/languages/tr.d.ts +45 -0
  65. package/dist/languages/tr.js +1529 -0
  66. package/dist/languages/tr.js.map +1 -0
  67. package/dist/languages/zh.d.ts +58 -0
  68. package/dist/languages/zh.js +1257 -0
  69. package/dist/languages/zh.js.map +1 -0
  70. package/dist/types-C4dcj53L.d.ts +600 -0
  71. package/package.json +202 -0
  72. package/src/__test-utils__/index.ts +7 -0
  73. package/src/__test-utils__/test-helpers.ts +8 -0
  74. package/src/__types__/test-helpers.ts +122 -0
  75. package/src/analysis/index.ts +479 -0
  76. package/src/ast-builder/command-mappers.ts +1133 -0
  77. package/src/ast-builder/expression-parser/index.ts +41 -0
  78. package/src/ast-builder/expression-parser/parser.ts +563 -0
  79. package/src/ast-builder/expression-parser/tokenizer.ts +394 -0
  80. package/src/ast-builder/expression-parser/types.ts +208 -0
  81. package/src/ast-builder/index.ts +536 -0
  82. package/src/ast-builder/value-converters.ts +172 -0
  83. package/src/bridge.ts +275 -0
  84. package/src/browser-ar.ts +162 -0
  85. package/src/browser-core.ts +231 -0
  86. package/src/browser-de.ts +162 -0
  87. package/src/browser-east-asian.ts +173 -0
  88. package/src/browser-en-tr.ts +165 -0
  89. package/src/browser-en.ts +157 -0
  90. package/src/browser-es-en.ts +200 -0
  91. package/src/browser-es.ts +170 -0
  92. package/src/browser-fr.ts +162 -0
  93. package/src/browser-id.ts +162 -0
  94. package/src/browser-ja.ts +162 -0
  95. package/src/browser-ko.ts +162 -0
  96. package/src/browser-lazy.ts +189 -0
  97. package/src/browser-priority.ts +214 -0
  98. package/src/browser-pt.ts +162 -0
  99. package/src/browser-qu.ts +162 -0
  100. package/src/browser-sw.ts +162 -0
  101. package/src/browser-tr.ts +162 -0
  102. package/src/browser-western.ts +181 -0
  103. package/src/browser-zh.ts +162 -0
  104. package/src/browser.ts +268 -0
  105. package/src/cache/index.ts +14 -0
  106. package/src/cache/semantic-cache.ts +344 -0
  107. package/src/core-bridge.ts +372 -0
  108. package/src/explicit/converter.ts +258 -0
  109. package/src/explicit/index.ts +18 -0
  110. package/src/explicit/parser.ts +236 -0
  111. package/src/explicit/renderer.ts +424 -0
  112. package/src/generators/command-schemas.ts +1636 -0
  113. package/src/generators/event-handler-generator.ts +109 -0
  114. package/src/generators/index.ts +117 -0
  115. package/src/generators/language-profiles.ts +139 -0
  116. package/src/generators/pattern-generator.ts +537 -0
  117. package/src/generators/profiles/arabic.ts +131 -0
  118. package/src/generators/profiles/bengali.ts +132 -0
  119. package/src/generators/profiles/chinese.ts +124 -0
  120. package/src/generators/profiles/english.ts +113 -0
  121. package/src/generators/profiles/french.ts +125 -0
  122. package/src/generators/profiles/german.ts +126 -0
  123. package/src/generators/profiles/hindi.ts +146 -0
  124. package/src/generators/profiles/index.ts +46 -0
  125. package/src/generators/profiles/indonesian.ts +125 -0
  126. package/src/generators/profiles/italian.ts +139 -0
  127. package/src/generators/profiles/japanese.ts +149 -0
  128. package/src/generators/profiles/korean.ts +127 -0
  129. package/src/generators/profiles/marker-templates.ts +288 -0
  130. package/src/generators/profiles/ms.ts +130 -0
  131. package/src/generators/profiles/polish.ts +249 -0
  132. package/src/generators/profiles/portuguese.ts +115 -0
  133. package/src/generators/profiles/quechua.ts +113 -0
  134. package/src/generators/profiles/russian.ts +260 -0
  135. package/src/generators/profiles/spanish.ts +130 -0
  136. package/src/generators/profiles/swahili.ts +129 -0
  137. package/src/generators/profiles/thai.ts +132 -0
  138. package/src/generators/profiles/tl.ts +128 -0
  139. package/src/generators/profiles/turkish.ts +124 -0
  140. package/src/generators/profiles/types.ts +165 -0
  141. package/src/generators/profiles/ukrainian.ts +270 -0
  142. package/src/generators/profiles/vietnamese.ts +133 -0
  143. package/src/generators/schema-error-codes.ts +160 -0
  144. package/src/generators/schema-validator.ts +391 -0
  145. package/src/index.ts +429 -0
  146. package/src/language-building-schema.ts +3170 -0
  147. package/src/language-loader.ts +394 -0
  148. package/src/languages/_all.ts +65 -0
  149. package/src/languages/ar.ts +15 -0
  150. package/src/languages/bn.ts +16 -0
  151. package/src/languages/de.ts +15 -0
  152. package/src/languages/en.ts +29 -0
  153. package/src/languages/es.ts +15 -0
  154. package/src/languages/fr.ts +15 -0
  155. package/src/languages/hi.ts +26 -0
  156. package/src/languages/id.ts +15 -0
  157. package/src/languages/index.ts +18 -0
  158. package/src/languages/it.ts +15 -0
  159. package/src/languages/ja.ts +15 -0
  160. package/src/languages/ko.ts +15 -0
  161. package/src/languages/ms.ts +16 -0
  162. package/src/languages/pl.ts +18 -0
  163. package/src/languages/pt.ts +15 -0
  164. package/src/languages/qu.ts +15 -0
  165. package/src/languages/ru.ts +26 -0
  166. package/src/languages/sw.ts +15 -0
  167. package/src/languages/th.ts +16 -0
  168. package/src/languages/tl.ts +16 -0
  169. package/src/languages/tr.ts +15 -0
  170. package/src/languages/uk.ts +26 -0
  171. package/src/languages/vi.ts +16 -0
  172. package/src/languages/zh.ts +15 -0
  173. package/src/parser/index.ts +15 -0
  174. package/src/parser/pattern-matcher.ts +1181 -0
  175. package/src/parser/semantic-parser.ts +573 -0
  176. package/src/parser/utils/index.ts +35 -0
  177. package/src/parser/utils/marker-resolution.ts +111 -0
  178. package/src/parser/utils/possessive-keywords.ts +43 -0
  179. package/src/parser/utils/role-positioning.ts +70 -0
  180. package/src/parser/utils/type-validation.ts +134 -0
  181. package/src/patterns/add/ar.ts +71 -0
  182. package/src/patterns/add/bn.ts +70 -0
  183. package/src/patterns/add/hi.ts +69 -0
  184. package/src/patterns/add/index.ts +87 -0
  185. package/src/patterns/add/it.ts +61 -0
  186. package/src/patterns/add/ja.ts +93 -0
  187. package/src/patterns/add/ko.ts +74 -0
  188. package/src/patterns/add/ms.ts +30 -0
  189. package/src/patterns/add/pl.ts +62 -0
  190. package/src/patterns/add/ru.ts +62 -0
  191. package/src/patterns/add/th.ts +49 -0
  192. package/src/patterns/add/tl.ts +30 -0
  193. package/src/patterns/add/tr.ts +71 -0
  194. package/src/patterns/add/uk.ts +62 -0
  195. package/src/patterns/add/vi.ts +61 -0
  196. package/src/patterns/add/zh.ts +71 -0
  197. package/src/patterns/builders.ts +207 -0
  198. package/src/patterns/decrement/bn.ts +70 -0
  199. package/src/patterns/decrement/de.ts +42 -0
  200. package/src/patterns/decrement/hi.ts +68 -0
  201. package/src/patterns/decrement/index.ts +79 -0
  202. package/src/patterns/decrement/it.ts +69 -0
  203. package/src/patterns/decrement/ms.ts +30 -0
  204. package/src/patterns/decrement/pl.ts +58 -0
  205. package/src/patterns/decrement/ru.ts +58 -0
  206. package/src/patterns/decrement/th.ts +49 -0
  207. package/src/patterns/decrement/tl.ts +30 -0
  208. package/src/patterns/decrement/tr.ts +48 -0
  209. package/src/patterns/decrement/uk.ts +58 -0
  210. package/src/patterns/decrement/vi.ts +61 -0
  211. package/src/patterns/decrement/zh.ts +32 -0
  212. package/src/patterns/en.ts +302 -0
  213. package/src/patterns/event-handler/ar.ts +151 -0
  214. package/src/patterns/event-handler/bn.ts +72 -0
  215. package/src/patterns/event-handler/de.ts +117 -0
  216. package/src/patterns/event-handler/en.ts +117 -0
  217. package/src/patterns/event-handler/es.ts +136 -0
  218. package/src/patterns/event-handler/fr.ts +117 -0
  219. package/src/patterns/event-handler/hi.ts +64 -0
  220. package/src/patterns/event-handler/id.ts +117 -0
  221. package/src/patterns/event-handler/index.ts +119 -0
  222. package/src/patterns/event-handler/it.ts +54 -0
  223. package/src/patterns/event-handler/ja.ts +118 -0
  224. package/src/patterns/event-handler/ko.ts +133 -0
  225. package/src/patterns/event-handler/ms.ts +30 -0
  226. package/src/patterns/event-handler/pl.ts +62 -0
  227. package/src/patterns/event-handler/pt.ts +117 -0
  228. package/src/patterns/event-handler/qu.ts +66 -0
  229. package/src/patterns/event-handler/ru.ts +62 -0
  230. package/src/patterns/event-handler/shared.ts +270 -0
  231. package/src/patterns/event-handler/sw.ts +117 -0
  232. package/src/patterns/event-handler/th.ts +53 -0
  233. package/src/patterns/event-handler/tl.ts +30 -0
  234. package/src/patterns/event-handler/tr.ts +170 -0
  235. package/src/patterns/event-handler/uk.ts +62 -0
  236. package/src/patterns/event-handler/vi.ts +61 -0
  237. package/src/patterns/event-handler/zh.ts +150 -0
  238. package/src/patterns/get/ar.ts +49 -0
  239. package/src/patterns/get/bn.ts +47 -0
  240. package/src/patterns/get/de.ts +32 -0
  241. package/src/patterns/get/hi.ts +52 -0
  242. package/src/patterns/get/index.ts +83 -0
  243. package/src/patterns/get/it.ts +56 -0
  244. package/src/patterns/get/ja.ts +53 -0
  245. package/src/patterns/get/ko.ts +53 -0
  246. package/src/patterns/get/ms.ts +30 -0
  247. package/src/patterns/get/pl.ts +57 -0
  248. package/src/patterns/get/ru.ts +57 -0
  249. package/src/patterns/get/th.ts +29 -0
  250. package/src/patterns/get/tl.ts +30 -0
  251. package/src/patterns/get/uk.ts +57 -0
  252. package/src/patterns/get/vi.ts +48 -0
  253. package/src/patterns/grammar-transformed/index.ts +39 -0
  254. package/src/patterns/grammar-transformed/ja.ts +1713 -0
  255. package/src/patterns/grammar-transformed/ko.ts +1311 -0
  256. package/src/patterns/grammar-transformed/tr.ts +1067 -0
  257. package/src/patterns/hide/ar.ts +67 -0
  258. package/src/patterns/hide/bn.ts +47 -0
  259. package/src/patterns/hide/de.ts +36 -0
  260. package/src/patterns/hide/hi.ts +61 -0
  261. package/src/patterns/hide/index.ts +91 -0
  262. package/src/patterns/hide/it.ts +56 -0
  263. package/src/patterns/hide/ja.ts +69 -0
  264. package/src/patterns/hide/ko.ts +69 -0
  265. package/src/patterns/hide/ms.ts +30 -0
  266. package/src/patterns/hide/pl.ts +57 -0
  267. package/src/patterns/hide/ru.ts +57 -0
  268. package/src/patterns/hide/th.ts +29 -0
  269. package/src/patterns/hide/tl.ts +30 -0
  270. package/src/patterns/hide/tr.ts +65 -0
  271. package/src/patterns/hide/uk.ts +57 -0
  272. package/src/patterns/hide/vi.ts +56 -0
  273. package/src/patterns/hide/zh.ts +68 -0
  274. package/src/patterns/increment/bn.ts +70 -0
  275. package/src/patterns/increment/de.ts +36 -0
  276. package/src/patterns/increment/hi.ts +68 -0
  277. package/src/patterns/increment/index.ts +79 -0
  278. package/src/patterns/increment/it.ts +69 -0
  279. package/src/patterns/increment/ms.ts +30 -0
  280. package/src/patterns/increment/pl.ts +58 -0
  281. package/src/patterns/increment/ru.ts +58 -0
  282. package/src/patterns/increment/th.ts +49 -0
  283. package/src/patterns/increment/tl.ts +30 -0
  284. package/src/patterns/increment/tr.ts +52 -0
  285. package/src/patterns/increment/uk.ts +58 -0
  286. package/src/patterns/increment/vi.ts +61 -0
  287. package/src/patterns/increment/zh.ts +32 -0
  288. package/src/patterns/index.ts +84 -0
  289. package/src/patterns/languages/en/control-flow.ts +93 -0
  290. package/src/patterns/languages/en/fetch.ts +62 -0
  291. package/src/patterns/languages/en/index.ts +42 -0
  292. package/src/patterns/languages/en/repeat.ts +67 -0
  293. package/src/patterns/languages/en/set.ts +48 -0
  294. package/src/patterns/languages/en/swap.ts +38 -0
  295. package/src/patterns/languages/en/temporal.ts +57 -0
  296. package/src/patterns/put/ar.ts +74 -0
  297. package/src/patterns/put/bn.ts +53 -0
  298. package/src/patterns/put/en.ts +74 -0
  299. package/src/patterns/put/es.ts +74 -0
  300. package/src/patterns/put/hi.ts +69 -0
  301. package/src/patterns/put/id.ts +96 -0
  302. package/src/patterns/put/index.ts +99 -0
  303. package/src/patterns/put/it.ts +56 -0
  304. package/src/patterns/put/ja.ts +75 -0
  305. package/src/patterns/put/ko.ts +67 -0
  306. package/src/patterns/put/ms.ts +30 -0
  307. package/src/patterns/put/pl.ts +81 -0
  308. package/src/patterns/put/ru.ts +85 -0
  309. package/src/patterns/put/th.ts +32 -0
  310. package/src/patterns/put/tl.ts +30 -0
  311. package/src/patterns/put/tr.ts +67 -0
  312. package/src/patterns/put/uk.ts +85 -0
  313. package/src/patterns/put/vi.ts +72 -0
  314. package/src/patterns/put/zh.ts +62 -0
  315. package/src/patterns/registry.ts +163 -0
  316. package/src/patterns/remove/ar.ts +71 -0
  317. package/src/patterns/remove/bn.ts +68 -0
  318. package/src/patterns/remove/hi.ts +69 -0
  319. package/src/patterns/remove/index.ts +87 -0
  320. package/src/patterns/remove/it.ts +69 -0
  321. package/src/patterns/remove/ja.ts +74 -0
  322. package/src/patterns/remove/ko.ts +78 -0
  323. package/src/patterns/remove/ms.ts +30 -0
  324. package/src/patterns/remove/pl.ts +62 -0
  325. package/src/patterns/remove/ru.ts +62 -0
  326. package/src/patterns/remove/th.ts +49 -0
  327. package/src/patterns/remove/tl.ts +30 -0
  328. package/src/patterns/remove/tr.ts +78 -0
  329. package/src/patterns/remove/uk.ts +62 -0
  330. package/src/patterns/remove/vi.ts +61 -0
  331. package/src/patterns/remove/zh.ts +72 -0
  332. package/src/patterns/set/ar.ts +84 -0
  333. package/src/patterns/set/bn.ts +53 -0
  334. package/src/patterns/set/de.ts +84 -0
  335. package/src/patterns/set/es.ts +92 -0
  336. package/src/patterns/set/fr.ts +88 -0
  337. package/src/patterns/set/hi.ts +56 -0
  338. package/src/patterns/set/id.ts +84 -0
  339. package/src/patterns/set/index.ts +107 -0
  340. package/src/patterns/set/it.ts +56 -0
  341. package/src/patterns/set/ja.ts +86 -0
  342. package/src/patterns/set/ko.ts +85 -0
  343. package/src/patterns/set/ms.ts +30 -0
  344. package/src/patterns/set/pl.ts +57 -0
  345. package/src/patterns/set/pt.ts +84 -0
  346. package/src/patterns/set/ru.ts +57 -0
  347. package/src/patterns/set/th.ts +31 -0
  348. package/src/patterns/set/tl.ts +30 -0
  349. package/src/patterns/set/tr.ts +107 -0
  350. package/src/patterns/set/uk.ts +57 -0
  351. package/src/patterns/set/vi.ts +53 -0
  352. package/src/patterns/set/zh.ts +84 -0
  353. package/src/patterns/show/ar.ts +67 -0
  354. package/src/patterns/show/bn.ts +47 -0
  355. package/src/patterns/show/de.ts +32 -0
  356. package/src/patterns/show/fr.ts +32 -0
  357. package/src/patterns/show/hi.ts +61 -0
  358. package/src/patterns/show/index.ts +95 -0
  359. package/src/patterns/show/it.ts +56 -0
  360. package/src/patterns/show/ja.ts +69 -0
  361. package/src/patterns/show/ko.ts +73 -0
  362. package/src/patterns/show/ms.ts +30 -0
  363. package/src/patterns/show/pl.ts +57 -0
  364. package/src/patterns/show/ru.ts +57 -0
  365. package/src/patterns/show/th.ts +29 -0
  366. package/src/patterns/show/tl.ts +30 -0
  367. package/src/patterns/show/tr.ts +65 -0
  368. package/src/patterns/show/uk.ts +57 -0
  369. package/src/patterns/show/vi.ts +56 -0
  370. package/src/patterns/show/zh.ts +68 -0
  371. package/src/patterns/take/ar.ts +51 -0
  372. package/src/patterns/take/index.ts +31 -0
  373. package/src/patterns/toggle/ar.ts +61 -0
  374. package/src/patterns/toggle/bn.ts +70 -0
  375. package/src/patterns/toggle/en.ts +61 -0
  376. package/src/patterns/toggle/es.ts +61 -0
  377. package/src/patterns/toggle/hi.ts +80 -0
  378. package/src/patterns/toggle/index.ts +95 -0
  379. package/src/patterns/toggle/it.ts +69 -0
  380. package/src/patterns/toggle/ja.ts +156 -0
  381. package/src/patterns/toggle/ko.ts +113 -0
  382. package/src/patterns/toggle/ms.ts +30 -0
  383. package/src/patterns/toggle/pl.ts +62 -0
  384. package/src/patterns/toggle/ru.ts +62 -0
  385. package/src/patterns/toggle/th.ts +50 -0
  386. package/src/patterns/toggle/tl.ts +30 -0
  387. package/src/patterns/toggle/tr.ts +88 -0
  388. package/src/patterns/toggle/uk.ts +62 -0
  389. package/src/patterns/toggle/vi.ts +61 -0
  390. package/src/patterns/toggle/zh.ts +99 -0
  391. package/src/public-api.ts +286 -0
  392. package/src/registry.ts +441 -0
  393. package/src/tokenizers/arabic.ts +723 -0
  394. package/src/tokenizers/base.ts +1300 -0
  395. package/src/tokenizers/bengali.ts +289 -0
  396. package/src/tokenizers/chinese.ts +481 -0
  397. package/src/tokenizers/english.ts +416 -0
  398. package/src/tokenizers/french.ts +326 -0
  399. package/src/tokenizers/german.ts +324 -0
  400. package/src/tokenizers/hindi.ts +319 -0
  401. package/src/tokenizers/index.ts +127 -0
  402. package/src/tokenizers/indonesian.ts +306 -0
  403. package/src/tokenizers/italian.ts +458 -0
  404. package/src/tokenizers/japanese.ts +447 -0
  405. package/src/tokenizers/korean.ts +642 -0
  406. package/src/tokenizers/morphology/arabic-normalizer.ts +242 -0
  407. package/src/tokenizers/morphology/french-normalizer.ts +268 -0
  408. package/src/tokenizers/morphology/german-normalizer.ts +256 -0
  409. package/src/tokenizers/morphology/index.ts +46 -0
  410. package/src/tokenizers/morphology/italian-normalizer.ts +329 -0
  411. package/src/tokenizers/morphology/japanese-normalizer.ts +288 -0
  412. package/src/tokenizers/morphology/korean-normalizer.ts +428 -0
  413. package/src/tokenizers/morphology/polish-normalizer.ts +264 -0
  414. package/src/tokenizers/morphology/portuguese-normalizer.ts +310 -0
  415. package/src/tokenizers/morphology/spanish-normalizer.ts +327 -0
  416. package/src/tokenizers/morphology/turkish-normalizer.ts +412 -0
  417. package/src/tokenizers/morphology/types.ts +211 -0
  418. package/src/tokenizers/ms.ts +198 -0
  419. package/src/tokenizers/polish.ts +354 -0
  420. package/src/tokenizers/portuguese.ts +304 -0
  421. package/src/tokenizers/quechua.ts +339 -0
  422. package/src/tokenizers/russian.ts +375 -0
  423. package/src/tokenizers/spanish.ts +403 -0
  424. package/src/tokenizers/swahili.ts +303 -0
  425. package/src/tokenizers/thai.ts +236 -0
  426. package/src/tokenizers/tl.ts +198 -0
  427. package/src/tokenizers/turkish.ts +411 -0
  428. package/src/tokenizers/ukrainian.ts +369 -0
  429. package/src/tokenizers/vietnamese.ts +410 -0
  430. package/src/types/grammar-types.ts +617 -0
  431. package/src/types/unified-profile.ts +267 -0
  432. package/src/types.ts +709 -0
  433. package/src/utils/confidence-calculator.ts +147 -0
  434. package/src/validators/command-validator.ts +380 -0
  435. package/src/validators/index.ts +15 -0
@@ -0,0 +1,1636 @@
1
+ /**
2
+ * Command Schemas
3
+ *
4
+ * Defines the semantic structure of each hyperscript command.
5
+ * Used by the pattern generator to create language-specific patterns.
6
+ */
7
+
8
+ import type { SemanticRole, ActionType, SemanticValue } from '../types';
9
+
10
+ // =============================================================================
11
+ // Command Schema Types
12
+ // =============================================================================
13
+
14
+ /**
15
+ * A role specification in a command schema.
16
+ */
17
+ export interface RoleSpec {
18
+ /** The semantic role */
19
+ readonly role: SemanticRole;
20
+ /** Description of what this role represents */
21
+ readonly description: string;
22
+ /** Whether this role is required */
23
+ readonly required: boolean;
24
+ /** Expected value types */
25
+ readonly expectedTypes: Array<'selector' | 'literal' | 'reference' | 'expression'>;
26
+ /** Default value if not provided */
27
+ readonly default?: SemanticValue;
28
+ /** Position hint for SVO languages (higher = earlier) */
29
+ readonly svoPosition?: number;
30
+ /** Position hint for SOV languages (higher = earlier) */
31
+ readonly sovPosition?: number;
32
+ /**
33
+ * Override the default role marker for this command.
34
+ * Maps language code to the marker to use (e.g., { en: 'to', es: 'a' }).
35
+ * If not specified, uses the language profile's default roleMarker.
36
+ */
37
+ readonly markerOverride?: Record<string, string>;
38
+ }
39
+
40
+ /**
41
+ * A precondition that must be met before command execution.
42
+ * Used for runtime error documentation.
43
+ */
44
+ export interface CommandPrecondition {
45
+ /** Human-readable condition description */
46
+ readonly condition: string;
47
+ /** Error code thrown when precondition fails */
48
+ readonly errorCode: string;
49
+ /** Error message template */
50
+ readonly message: string;
51
+ }
52
+
53
+ /**
54
+ * A command schema defines the semantic structure of a command.
55
+ */
56
+ export interface CommandSchema {
57
+ /** The action type (command name) */
58
+ readonly action: ActionType;
59
+ /** Human-readable description */
60
+ readonly description: string;
61
+ /** Roles this command accepts */
62
+ readonly roles: RoleSpec[];
63
+ /** The primary role (what the command acts on) */
64
+ readonly primaryRole: SemanticRole;
65
+ /** Category for grouping */
66
+ readonly category: CommandCategory;
67
+ /** Whether this command typically has a body (like event handlers) */
68
+ readonly hasBody?: boolean;
69
+ /** Notes about special handling */
70
+ readonly notes?: string;
71
+
72
+ // Runtime error documentation (optional for backward compatibility)
73
+
74
+ /** Possible runtime error codes this command can throw */
75
+ readonly errorCodes?: readonly string[];
76
+ /** Preconditions that must be met before execution */
77
+ readonly preconditions?: readonly CommandPrecondition[];
78
+ /** Recovery hints mapping error code to suggestion */
79
+ readonly recoveryHints?: Readonly<Record<string, string>>;
80
+ }
81
+
82
+ /**
83
+ * Command categories for organization.
84
+ */
85
+ export type CommandCategory =
86
+ | 'dom-class' // Class/attribute manipulation
87
+ | 'dom-content' // Content manipulation
88
+ | 'dom-visibility' // Show/hide
89
+ | 'variable' // Variable operations
90
+ | 'event' // Event handling
91
+ | 'async' // Async operations
92
+ | 'navigation' // URL/navigation
93
+ | 'control-flow'; // Control flow
94
+
95
+ // =============================================================================
96
+ // Command Schema Definitions
97
+ // =============================================================================
98
+
99
+ /**
100
+ * Toggle command: adds class/attribute if absent, removes if present.
101
+ *
102
+ * Patterns:
103
+ * - EN: toggle .active on #button
104
+ * - JA: #button の .active を 切り替え
105
+ * - AR: بدّل .active على #button
106
+ */
107
+ export const toggleSchema: CommandSchema = {
108
+ action: 'toggle',
109
+ description: 'Toggle a class or attribute on/off',
110
+ category: 'dom-class',
111
+ primaryRole: 'patient',
112
+ roles: [
113
+ {
114
+ role: 'patient',
115
+ description: 'The class or attribute to toggle',
116
+ required: true,
117
+ expectedTypes: ['selector'],
118
+ svoPosition: 1,
119
+ sovPosition: 2,
120
+ },
121
+ {
122
+ role: 'destination',
123
+ description: 'The target element (defaults to me)',
124
+ required: false,
125
+ expectedTypes: ['selector', 'reference'],
126
+ default: { type: 'reference', value: 'me' },
127
+ svoPosition: 2,
128
+ sovPosition: 1,
129
+ },
130
+ ],
131
+ // Runtime error documentation
132
+ errorCodes: ['MISSING_ARGUMENT', 'NO_VALID_CLASS_NAMES', 'INVALID_CSS_PROPERTY'],
133
+ preconditions: [
134
+ {
135
+ condition: 'Command has at least one argument',
136
+ errorCode: 'MISSING_ARGUMENT',
137
+ message: 'toggle command requires an argument',
138
+ },
139
+ {
140
+ condition: 'Class names are valid CSS identifiers',
141
+ errorCode: 'NO_VALID_CLASS_NAMES',
142
+ message: 'toggle command: no valid class names found',
143
+ },
144
+ ],
145
+ recoveryHints: {
146
+ MISSING_ARGUMENT: 'Add a class selector (.classname) or attribute to toggle',
147
+ NO_VALID_CLASS_NAMES: 'Ensure class names start with a dot (.) and are valid CSS identifiers',
148
+ INVALID_CSS_PROPERTY: 'Check CSS property name syntax (use kebab-case)',
149
+ },
150
+ };
151
+
152
+ /**
153
+ * Add command: adds a class or attribute.
154
+ */
155
+ export const addSchema: CommandSchema = {
156
+ action: 'add',
157
+ description: 'Add a class or attribute to an element',
158
+ category: 'dom-class',
159
+ primaryRole: 'patient',
160
+ roles: [
161
+ {
162
+ role: 'patient',
163
+ description: 'The class or attribute to add',
164
+ required: true,
165
+ expectedTypes: ['selector'],
166
+ svoPosition: 1,
167
+ sovPosition: 2,
168
+ },
169
+ {
170
+ role: 'destination',
171
+ description: 'The target element (defaults to me)',
172
+ required: false,
173
+ expectedTypes: ['selector', 'reference'],
174
+ default: { type: 'reference', value: 'me' },
175
+ svoPosition: 2,
176
+ sovPosition: 1,
177
+ },
178
+ ],
179
+ // Runtime error documentation
180
+ errorCodes: ['MISSING_ARGUMENT', 'NO_VALID_CLASS_NAMES', 'PROPERTY_REQUIRES_VALUE'],
181
+ preconditions: [
182
+ {
183
+ condition: 'Command has at least one argument',
184
+ errorCode: 'MISSING_ARGUMENT',
185
+ message: 'add command requires an argument',
186
+ },
187
+ ],
188
+ recoveryHints: {
189
+ MISSING_ARGUMENT: 'Add a class selector (.classname) or attribute to add',
190
+ NO_VALID_CLASS_NAMES: 'Ensure class names start with a dot (.) and are valid CSS identifiers',
191
+ PROPERTY_REQUIRES_VALUE: 'When adding a property (*prop), provide a value argument',
192
+ },
193
+ };
194
+
195
+ /**
196
+ * Remove command: removes a class or attribute.
197
+ */
198
+ export const removeSchema: CommandSchema = {
199
+ action: 'remove',
200
+ description: 'Remove a class or attribute from an element',
201
+ category: 'dom-class',
202
+ primaryRole: 'patient',
203
+ roles: [
204
+ {
205
+ role: 'patient',
206
+ description: 'The class or attribute to remove',
207
+ required: true,
208
+ expectedTypes: ['selector'],
209
+ svoPosition: 1,
210
+ sovPosition: 2,
211
+ },
212
+ {
213
+ role: 'source',
214
+ description: 'The element to remove from (defaults to me)',
215
+ required: false,
216
+ expectedTypes: ['selector', 'reference'],
217
+ default: { type: 'reference', value: 'me' },
218
+ svoPosition: 2,
219
+ sovPosition: 1,
220
+ },
221
+ ],
222
+ // Runtime error documentation
223
+ errorCodes: ['MISSING_ARGUMENT', 'NO_VALID_CLASS_NAMES'],
224
+ preconditions: [
225
+ {
226
+ condition: 'Command has at least one argument',
227
+ errorCode: 'MISSING_ARGUMENT',
228
+ message: 'remove command requires an argument',
229
+ },
230
+ ],
231
+ recoveryHints: {
232
+ MISSING_ARGUMENT: 'Add a class selector (.classname) or attribute to remove',
233
+ NO_VALID_CLASS_NAMES: 'Ensure class names start with a dot (.) and are valid CSS identifiers',
234
+ },
235
+ };
236
+
237
+ /**
238
+ * Put command: puts content into a target.
239
+ *
240
+ * Patterns:
241
+ * - EN: put "hello" into #output
242
+ * - JA: #output に "hello" を 置く
243
+ * - AR: ضع "hello" في #output
244
+ */
245
+ export const putSchema: CommandSchema = {
246
+ action: 'put',
247
+ description: 'Put content into a target element or variable',
248
+ category: 'dom-content',
249
+ primaryRole: 'patient',
250
+ roles: [
251
+ {
252
+ role: 'patient',
253
+ description: 'The content to put',
254
+ required: true,
255
+ expectedTypes: ['literal', 'selector', 'reference', 'expression'],
256
+ svoPosition: 1,
257
+ sovPosition: 2,
258
+ },
259
+ {
260
+ role: 'destination',
261
+ description: 'Where to put the content',
262
+ required: true,
263
+ expectedTypes: ['selector', 'reference'],
264
+ svoPosition: 2,
265
+ sovPosition: 1,
266
+ },
267
+ ],
268
+ // Runtime error documentation
269
+ errorCodes: [
270
+ 'MISSING_ARGUMENTS',
271
+ 'MISSING_CONTENT',
272
+ 'MISSING_POSITION',
273
+ 'INVALID_POSITION',
274
+ 'NO_TARGET',
275
+ 'NO_ELEMENTS',
276
+ ],
277
+ preconditions: [
278
+ {
279
+ condition: 'Command has content and position arguments',
280
+ errorCode: 'MISSING_ARGUMENTS',
281
+ message: 'put requires arguments',
282
+ },
283
+ {
284
+ condition: 'Content to put is specified',
285
+ errorCode: 'MISSING_CONTENT',
286
+ message: 'put requires content',
287
+ },
288
+ {
289
+ condition: 'Position keyword is specified (into, before, after, etc.)',
290
+ errorCode: 'MISSING_POSITION',
291
+ message: 'put requires position keyword',
292
+ },
293
+ ],
294
+ recoveryHints: {
295
+ MISSING_ARGUMENTS: 'Use syntax: put <content> into/before/after <target>',
296
+ MISSING_CONTENT: 'Add content to put (string, element, or expression)',
297
+ MISSING_POSITION: 'Add position keyword: into, before, after, at start of, at end of',
298
+ INVALID_POSITION: 'Valid positions: into, before, after, at start of, at end of',
299
+ NO_TARGET: 'Ensure target element exists or use "me" reference',
300
+ NO_ELEMENTS: 'Check that the selector matches existing elements',
301
+ },
302
+ };
303
+
304
+ /**
305
+ * Set command: sets a property or variable.
306
+ *
307
+ * Patterns:
308
+ * - EN: set :count to 10
309
+ * - ES: establecer :count a 10
310
+ * - JA: :count を 10 に 設定
311
+ * - KO: :x 에 5 을 설정 (uses default markers)
312
+ * - TR: :x e 5 i ayarla (uses default markers)
313
+ *
314
+ * Note: Only override markers for SVO languages where patient has no default marker.
315
+ * SOV languages (Korean, Japanese, Turkish) already have correct object markers.
316
+ */
317
+ export const setSchema: CommandSchema = {
318
+ action: 'set',
319
+ description: 'Set a property or variable to a value',
320
+ category: 'variable',
321
+ primaryRole: 'destination',
322
+ roles: [
323
+ {
324
+ role: 'destination',
325
+ description: 'The property or variable to set',
326
+ required: true,
327
+ expectedTypes: ['selector', 'reference'],
328
+ svoPosition: 1,
329
+ sovPosition: 1,
330
+ // Override destination marker for English (remove 'on', use no marker)
331
+ // Other languages keep their default destination markers
332
+ markerOverride: {
333
+ en: '', // No marker before destination in English: "set :x to 5"
334
+ },
335
+ },
336
+ {
337
+ role: 'patient',
338
+ description: 'The value to set',
339
+ required: true,
340
+ expectedTypes: ['literal', 'expression', 'reference'],
341
+ svoPosition: 2,
342
+ sovPosition: 2,
343
+ // Override patient marker for SVO languages with their native prepositions
344
+ // SOV languages (Korean, Japanese, Turkish) use their default object markers
345
+ markerOverride: {
346
+ en: 'to', // "set :x to 5"
347
+ es: 'a', // "establecer x a 10"
348
+ pt: 'para', // "definir x para 10"
349
+ fr: 'à', // "définir x à 10"
350
+ de: 'auf', // "setze x auf 10"
351
+ id: 'ke', // "atur x ke 10"
352
+ },
353
+ },
354
+ ],
355
+ // Runtime error documentation
356
+ errorCodes: ['MISSING_TARGET', 'INVALID_TARGET', 'MISSING_VALUE', 'INVALID_SYNTAX'],
357
+ preconditions: [
358
+ {
359
+ condition: 'Command has a target variable or property',
360
+ errorCode: 'MISSING_TARGET',
361
+ message: 'set command requires a target',
362
+ },
363
+ {
364
+ condition: 'Target is a valid variable or property reference',
365
+ errorCode: 'INVALID_TARGET',
366
+ message: 'set command target must be a string or object literal',
367
+ },
368
+ {
369
+ condition: 'Value is specified with "to" keyword',
370
+ errorCode: 'MISSING_VALUE',
371
+ message: 'set command requires a value (use "to" keyword)',
372
+ },
373
+ ],
374
+ recoveryHints: {
375
+ MISSING_TARGET: 'Add a target: set :variable to value OR set element.property to value',
376
+ INVALID_TARGET:
377
+ 'Use local variable (:name), element property (el.prop), or "the X of Y" syntax',
378
+ MISSING_VALUE: 'Add "to <value>" to specify what to set',
379
+ INVALID_SYNTAX: 'Use syntax: set <target> to <value>',
380
+ },
381
+ };
382
+
383
+ /**
384
+ * Show command: makes an element visible.
385
+ */
386
+ export const showSchema: CommandSchema = {
387
+ action: 'show',
388
+ description: 'Make an element visible',
389
+ category: 'dom-visibility',
390
+ primaryRole: 'patient',
391
+ roles: [
392
+ {
393
+ role: 'patient',
394
+ description: 'The element to show',
395
+ required: true, // Changed from false - patient is primary role
396
+ expectedTypes: ['selector', 'reference'],
397
+ default: { type: 'reference', value: 'me' },
398
+ svoPosition: 1,
399
+ sovPosition: 1,
400
+ },
401
+ {
402
+ role: 'style',
403
+ description: 'Animation style (fade, slide, etc.)',
404
+ required: false,
405
+ expectedTypes: ['literal'],
406
+ svoPosition: 2,
407
+ sovPosition: 2,
408
+ },
409
+ ],
410
+ };
411
+
412
+ /**
413
+ * Hide command: makes an element invisible.
414
+ */
415
+ export const hideSchema: CommandSchema = {
416
+ action: 'hide',
417
+ description: 'Make an element invisible',
418
+ category: 'dom-visibility',
419
+ primaryRole: 'patient',
420
+ roles: [
421
+ {
422
+ role: 'patient',
423
+ description: 'The element to hide',
424
+ required: true, // Changed from false - patient is primary role
425
+ expectedTypes: ['selector', 'reference'],
426
+ default: { type: 'reference', value: 'me' },
427
+ svoPosition: 1,
428
+ sovPosition: 1,
429
+ },
430
+ {
431
+ role: 'style',
432
+ description: 'Animation style (fade, slide, etc.)',
433
+ required: false,
434
+ expectedTypes: ['literal'],
435
+ svoPosition: 2,
436
+ sovPosition: 2,
437
+ },
438
+ ],
439
+ };
440
+
441
+ /**
442
+ * On command: event handler.
443
+ */
444
+ export const onSchema: CommandSchema = {
445
+ action: 'on',
446
+ description: 'Handle an event',
447
+ category: 'event',
448
+ primaryRole: 'event',
449
+ hasBody: true,
450
+ roles: [
451
+ {
452
+ role: 'event',
453
+ description: 'The event to handle',
454
+ required: true,
455
+ expectedTypes: ['literal'],
456
+ svoPosition: 1,
457
+ sovPosition: 2,
458
+ },
459
+ {
460
+ role: 'source',
461
+ description: 'The element to listen on (defaults to me)',
462
+ required: false,
463
+ expectedTypes: ['selector', 'reference'],
464
+ default: { type: 'reference', value: 'me' },
465
+ svoPosition: 2,
466
+ sovPosition: 1,
467
+ },
468
+ ],
469
+ };
470
+
471
+ /**
472
+ * Trigger command: dispatches an event.
473
+ * Supports namespaced events like "draggable:start".
474
+ */
475
+ export const triggerSchema: CommandSchema = {
476
+ action: 'trigger',
477
+ description: 'Trigger/dispatch an event',
478
+ category: 'event',
479
+ primaryRole: 'event',
480
+ roles: [
481
+ {
482
+ role: 'event',
483
+ description: 'The event to trigger (supports namespaced events like draggable:start)',
484
+ required: true,
485
+ expectedTypes: ['literal', 'expression'], // expression for custom/namespaced event names
486
+ svoPosition: 1,
487
+ sovPosition: 2,
488
+ },
489
+ {
490
+ role: 'destination',
491
+ description: 'The target element (defaults to me)',
492
+ required: false,
493
+ expectedTypes: ['selector', 'reference'],
494
+ default: { type: 'reference', value: 'me' },
495
+ svoPosition: 2,
496
+ sovPosition: 1,
497
+ },
498
+ ],
499
+ };
500
+
501
+ /**
502
+ * Wait command: pauses execution.
503
+ */
504
+ export const waitSchema: CommandSchema = {
505
+ action: 'wait',
506
+ description: 'Wait for a duration or event',
507
+ category: 'async',
508
+ primaryRole: 'patient',
509
+ roles: [
510
+ {
511
+ role: 'patient',
512
+ description: 'Duration or event to wait for',
513
+ required: true,
514
+ expectedTypes: ['literal', 'expression'],
515
+ svoPosition: 1,
516
+ sovPosition: 1,
517
+ },
518
+ ],
519
+ };
520
+
521
+ /**
522
+ * Fetch command: makes HTTP request.
523
+ */
524
+ export const fetchSchema: CommandSchema = {
525
+ action: 'fetch',
526
+ description: 'Fetch data from a URL',
527
+ category: 'async',
528
+ primaryRole: 'source',
529
+ roles: [
530
+ {
531
+ role: 'source',
532
+ description: 'The URL to fetch from',
533
+ required: true,
534
+ expectedTypes: ['literal', 'expression'],
535
+ svoPosition: 1,
536
+ sovPosition: 1,
537
+ },
538
+ {
539
+ role: 'responseType',
540
+ description: 'Response format (json, text, html, blob, etc.)',
541
+ required: false,
542
+ expectedTypes: ['literal', 'expression'], // json/text/html are identifiers → expression type
543
+ svoPosition: 2,
544
+ sovPosition: 2,
545
+ },
546
+ {
547
+ role: 'method',
548
+ description: 'HTTP method (GET, POST, etc.)',
549
+ required: false,
550
+ expectedTypes: ['literal'],
551
+ svoPosition: 3,
552
+ sovPosition: 3,
553
+ },
554
+ {
555
+ role: 'destination',
556
+ description: 'Where to store the result',
557
+ required: false,
558
+ expectedTypes: ['selector', 'reference'],
559
+ svoPosition: 4,
560
+ sovPosition: 4,
561
+ },
562
+ ],
563
+ };
564
+
565
+ /**
566
+ * Increment command: increases a numeric value.
567
+ */
568
+ export const incrementSchema: CommandSchema = {
569
+ action: 'increment',
570
+ description: 'Increment a numeric value',
571
+ category: 'variable',
572
+ primaryRole: 'patient',
573
+ roles: [
574
+ {
575
+ role: 'patient',
576
+ description: 'The value to increment',
577
+ required: true,
578
+ expectedTypes: ['selector', 'reference', 'expression'],
579
+ svoPosition: 1,
580
+ sovPosition: 1,
581
+ },
582
+ {
583
+ role: 'quantity',
584
+ description: 'Amount to increment by (defaults to 1)',
585
+ required: false,
586
+ expectedTypes: ['literal'],
587
+ default: { type: 'literal', value: 1, dataType: 'number' },
588
+ svoPosition: 2,
589
+ sovPosition: 2,
590
+ },
591
+ ],
592
+ };
593
+
594
+ /**
595
+ * Decrement command: decreases a numeric value.
596
+ */
597
+ export const decrementSchema: CommandSchema = {
598
+ action: 'decrement',
599
+ description: 'Decrement a numeric value',
600
+ category: 'variable',
601
+ primaryRole: 'patient',
602
+ roles: [
603
+ {
604
+ role: 'patient',
605
+ description: 'The value to decrement',
606
+ required: true,
607
+ expectedTypes: ['selector', 'reference', 'expression'],
608
+ svoPosition: 1,
609
+ sovPosition: 1,
610
+ },
611
+ {
612
+ role: 'quantity',
613
+ description: 'Amount to decrement by (defaults to 1)',
614
+ required: false,
615
+ expectedTypes: ['literal'],
616
+ default: { type: 'literal', value: 1, dataType: 'number' },
617
+ svoPosition: 2,
618
+ sovPosition: 2,
619
+ },
620
+ ],
621
+ };
622
+
623
+ /**
624
+ * Append command: appends content to an element.
625
+ */
626
+ export const appendSchema: CommandSchema = {
627
+ action: 'append',
628
+ description: 'Append content to an element',
629
+ category: 'dom-content',
630
+ primaryRole: 'patient',
631
+ roles: [
632
+ {
633
+ role: 'patient',
634
+ description: 'The content to append',
635
+ required: true,
636
+ expectedTypes: ['literal', 'selector', 'expression'],
637
+ svoPosition: 1,
638
+ sovPosition: 2,
639
+ },
640
+ {
641
+ role: 'destination',
642
+ description: 'The element to append to',
643
+ required: true,
644
+ expectedTypes: ['selector', 'reference'],
645
+ svoPosition: 2,
646
+ sovPosition: 1,
647
+ },
648
+ ],
649
+ };
650
+
651
+ /**
652
+ * Prepend command: prepends content to an element.
653
+ */
654
+ export const prependSchema: CommandSchema = {
655
+ action: 'prepend',
656
+ description: 'Prepend content to an element',
657
+ category: 'dom-content',
658
+ primaryRole: 'patient',
659
+ roles: [
660
+ {
661
+ role: 'patient',
662
+ description: 'The content to prepend',
663
+ required: true,
664
+ expectedTypes: ['literal', 'selector', 'expression'],
665
+ svoPosition: 1,
666
+ sovPosition: 2,
667
+ },
668
+ {
669
+ role: 'destination',
670
+ description: 'The element to prepend to',
671
+ required: true,
672
+ expectedTypes: ['selector', 'reference'],
673
+ svoPosition: 2,
674
+ sovPosition: 1,
675
+ },
676
+ ],
677
+ };
678
+
679
+ // =============================================================================
680
+ // Batch 1 - Simple Commands
681
+ // =============================================================================
682
+
683
+ /**
684
+ * Log command: logs a value to console.
685
+ */
686
+ export const logSchema: CommandSchema = {
687
+ action: 'log',
688
+ description: 'Log a value to the console',
689
+ category: 'variable',
690
+ primaryRole: 'patient',
691
+ roles: [
692
+ {
693
+ role: 'patient',
694
+ description: 'The value to log',
695
+ required: true,
696
+ expectedTypes: ['literal', 'selector', 'reference', 'expression'],
697
+ svoPosition: 1,
698
+ sovPosition: 1,
699
+ },
700
+ ],
701
+ };
702
+
703
+ /**
704
+ * Get command: retrieves a value.
705
+ */
706
+ export const getCommandSchema: CommandSchema = {
707
+ action: 'get',
708
+ description: 'Get a value from a source',
709
+ category: 'variable',
710
+ primaryRole: 'source',
711
+ roles: [
712
+ {
713
+ role: 'source',
714
+ description: 'The source to get from',
715
+ required: true,
716
+ expectedTypes: ['selector', 'reference', 'expression'],
717
+ svoPosition: 1,
718
+ sovPosition: 2,
719
+ // No marker before source for simple GET pattern: "get #element" not "get from #element"
720
+ markerOverride: {
721
+ en: '',
722
+ es: '',
723
+ pt: '',
724
+ fr: '',
725
+ de: '',
726
+ ja: '',
727
+ zh: '',
728
+ ko: '',
729
+ ar: '',
730
+ tr: '',
731
+ id: '',
732
+ },
733
+ },
734
+ {
735
+ role: 'destination',
736
+ description: 'Where to store the result (optional)',
737
+ required: false,
738
+ expectedTypes: ['reference'],
739
+ svoPosition: 2,
740
+ sovPosition: 1,
741
+ },
742
+ ],
743
+ };
744
+
745
+ /**
746
+ * Take command: takes/removes content from a source.
747
+ */
748
+ export const takeSchema: CommandSchema = {
749
+ action: 'take',
750
+ description: 'Take content from a source element',
751
+ category: 'dom-content',
752
+ primaryRole: 'patient',
753
+ roles: [
754
+ {
755
+ role: 'patient',
756
+ description: 'The class or element to take',
757
+ required: true,
758
+ expectedTypes: ['selector'],
759
+ svoPosition: 1,
760
+ sovPosition: 2,
761
+ },
762
+ {
763
+ role: 'source',
764
+ description: 'The element to take from (defaults to me)',
765
+ required: false,
766
+ expectedTypes: ['selector', 'reference'],
767
+ default: { type: 'reference', value: 'me' },
768
+ svoPosition: 2,
769
+ sovPosition: 1,
770
+ },
771
+ ],
772
+ };
773
+
774
+ /**
775
+ * Make command: creates a new element.
776
+ */
777
+ export const makeSchema: CommandSchema = {
778
+ action: 'make',
779
+ description: 'Create a new element',
780
+ category: 'dom-content',
781
+ primaryRole: 'patient',
782
+ roles: [
783
+ {
784
+ role: 'patient',
785
+ description: 'The element type or selector to create',
786
+ required: true,
787
+ expectedTypes: ['literal', 'selector'],
788
+ svoPosition: 1,
789
+ sovPosition: 1,
790
+ },
791
+ ],
792
+ };
793
+
794
+ /**
795
+ * Halt command: stops execution or event propagation.
796
+ * Supports: halt, halt the event, halt default, halt the bubbling
797
+ */
798
+ export const haltSchema: CommandSchema = {
799
+ action: 'halt',
800
+ description: 'Halt/stop execution or event propagation',
801
+ category: 'control-flow',
802
+ primaryRole: 'patient',
803
+ roles: [
804
+ {
805
+ role: 'patient',
806
+ description: 'What to halt (event, default, bubbling, etc.)',
807
+ required: false, // Plain "halt" is valid
808
+ expectedTypes: ['literal', 'reference', 'expression'],
809
+ svoPosition: 1,
810
+ sovPosition: 1,
811
+ },
812
+ ],
813
+ };
814
+
815
+ /**
816
+ * Settle command: waits for animations to complete.
817
+ */
818
+ export const settleSchema: CommandSchema = {
819
+ action: 'settle',
820
+ description: 'Wait for animations/transitions to settle',
821
+ category: 'async',
822
+ primaryRole: 'patient',
823
+ roles: [
824
+ {
825
+ role: 'patient',
826
+ description: 'The element to settle (defaults to me)',
827
+ required: false,
828
+ expectedTypes: ['selector', 'reference'],
829
+ default: { type: 'reference', value: 'me' },
830
+ svoPosition: 1,
831
+ sovPosition: 1,
832
+ },
833
+ ],
834
+ };
835
+
836
+ /**
837
+ * Throw command: throws an error/exception.
838
+ */
839
+ export const throwSchema: CommandSchema = {
840
+ action: 'throw',
841
+ description: 'Throw an error',
842
+ category: 'control-flow',
843
+ primaryRole: 'patient',
844
+ roles: [
845
+ {
846
+ role: 'patient',
847
+ description: 'The error message or object to throw',
848
+ required: true,
849
+ expectedTypes: ['literal', 'expression'],
850
+ svoPosition: 1,
851
+ sovPosition: 1,
852
+ },
853
+ ],
854
+ };
855
+
856
+ /**
857
+ * Send command: sends/dispatches an event.
858
+ */
859
+ export const sendSchema: CommandSchema = {
860
+ action: 'send',
861
+ description: 'Send an event to an element',
862
+ category: 'event',
863
+ primaryRole: 'event',
864
+ roles: [
865
+ {
866
+ role: 'event',
867
+ description: 'The event to send',
868
+ required: true,
869
+ expectedTypes: ['literal', 'expression'], // identifiers tokenize as expression
870
+ svoPosition: 1,
871
+ sovPosition: 2,
872
+ },
873
+ {
874
+ role: 'destination',
875
+ description: 'The target element (defaults to me)',
876
+ required: false,
877
+ expectedTypes: ['selector', 'reference'],
878
+ default: { type: 'reference', value: 'me' },
879
+ svoPosition: 2,
880
+ sovPosition: 1,
881
+ // send uses "to" not "on" for destination: send foo to #target
882
+ markerOverride: {
883
+ en: 'to',
884
+ ja: 'に',
885
+ ar: 'إلى',
886
+ es: 'a',
887
+ ko: '에게',
888
+ zh: '到',
889
+ tr: '-e',
890
+ pt: 'para',
891
+ fr: 'à',
892
+ de: 'an',
893
+ id: 'ke',
894
+ qu: '-man',
895
+ sw: 'kwa',
896
+ },
897
+ },
898
+ ],
899
+ };
900
+
901
+ // =============================================================================
902
+ // Batch 2 - Control Flow Commands
903
+ // =============================================================================
904
+
905
+ /**
906
+ * If command: conditional execution.
907
+ */
908
+ export const ifSchema: CommandSchema = {
909
+ action: 'if',
910
+ description: 'Conditional execution',
911
+ category: 'control-flow',
912
+ primaryRole: 'condition',
913
+ hasBody: true,
914
+ roles: [
915
+ {
916
+ role: 'condition',
917
+ description: 'The condition to evaluate',
918
+ required: true,
919
+ expectedTypes: ['expression'],
920
+ svoPosition: 1,
921
+ sovPosition: 1,
922
+ },
923
+ ],
924
+ };
925
+
926
+ /**
927
+ * Unless command: negated conditional execution.
928
+ * Executes body when condition is false.
929
+ */
930
+ export const unlessSchema: CommandSchema = {
931
+ action: 'unless',
932
+ description: 'Negated conditional execution (executes when condition is false)',
933
+ category: 'control-flow',
934
+ primaryRole: 'condition',
935
+ hasBody: true,
936
+ roles: [
937
+ {
938
+ role: 'condition',
939
+ description: 'The condition to evaluate (body executes when false)',
940
+ required: true,
941
+ expectedTypes: ['expression'],
942
+ svoPosition: 1,
943
+ sovPosition: 1,
944
+ },
945
+ ],
946
+ };
947
+
948
+ /**
949
+ * Else command: alternative branch.
950
+ */
951
+ export const elseSchema: CommandSchema = {
952
+ action: 'else',
953
+ description: 'Else branch of conditional',
954
+ category: 'control-flow',
955
+ primaryRole: 'patient',
956
+ hasBody: true,
957
+ roles: [], // No roles - follows an if
958
+ };
959
+
960
+ /**
961
+ * Repeat command: loop execution.
962
+ */
963
+ export const repeatSchema: CommandSchema = {
964
+ action: 'repeat',
965
+ description: 'Repeat a block of commands',
966
+ category: 'control-flow',
967
+ primaryRole: 'loopType',
968
+ hasBody: true,
969
+ roles: [
970
+ {
971
+ role: 'loopType',
972
+ description: 'Loop variant: forever, times, for, while, until, until-event',
973
+ required: true,
974
+ expectedTypes: ['literal'],
975
+ svoPosition: 0,
976
+ sovPosition: 0,
977
+ },
978
+ {
979
+ role: 'quantity',
980
+ description: 'Number of times to repeat',
981
+ required: false,
982
+ expectedTypes: ['literal', 'expression'],
983
+ svoPosition: 1,
984
+ sovPosition: 1,
985
+ },
986
+ {
987
+ role: 'event',
988
+ description: 'Event to wait for (terminates loop)',
989
+ required: false,
990
+ expectedTypes: ['literal', 'expression'],
991
+ svoPosition: 2,
992
+ sovPosition: 2,
993
+ },
994
+ {
995
+ role: 'source',
996
+ description: 'Element to listen for event on',
997
+ required: false,
998
+ expectedTypes: ['selector', 'reference'],
999
+ svoPosition: 3,
1000
+ sovPosition: 3,
1001
+ },
1002
+ ],
1003
+ notes:
1004
+ 'Can also use "repeat forever", "repeat until condition", or "repeat until event X from Y"',
1005
+ };
1006
+
1007
+ /**
1008
+ * For command: iteration over collection.
1009
+ */
1010
+ export const forSchema: CommandSchema = {
1011
+ action: 'for',
1012
+ description: 'Iterate over a collection',
1013
+ category: 'control-flow',
1014
+ primaryRole: 'patient',
1015
+ hasBody: true,
1016
+ roles: [
1017
+ {
1018
+ role: 'patient',
1019
+ description: 'The iteration variable',
1020
+ required: true,
1021
+ expectedTypes: ['reference'],
1022
+ svoPosition: 1,
1023
+ sovPosition: 2,
1024
+ },
1025
+ {
1026
+ role: 'source',
1027
+ description: 'The collection to iterate over',
1028
+ required: true,
1029
+ expectedTypes: ['selector', 'reference', 'expression'],
1030
+ svoPosition: 2,
1031
+ sovPosition: 1,
1032
+ },
1033
+ ],
1034
+ };
1035
+
1036
+ /**
1037
+ * While command: conditional loop.
1038
+ */
1039
+ export const whileSchema: CommandSchema = {
1040
+ action: 'while',
1041
+ description: 'Loop while condition is true',
1042
+ category: 'control-flow',
1043
+ primaryRole: 'condition',
1044
+ hasBody: true,
1045
+ roles: [
1046
+ {
1047
+ role: 'condition',
1048
+ description: 'The condition to check',
1049
+ required: true,
1050
+ expectedTypes: ['expression'],
1051
+ svoPosition: 1,
1052
+ sovPosition: 1,
1053
+ },
1054
+ ],
1055
+ };
1056
+
1057
+ /**
1058
+ * Continue command: skip to next iteration.
1059
+ */
1060
+ export const continueSchema: CommandSchema = {
1061
+ action: 'continue',
1062
+ description: 'Continue to next loop iteration',
1063
+ category: 'control-flow',
1064
+ primaryRole: 'patient',
1065
+ roles: [], // No roles
1066
+ };
1067
+
1068
+ // =============================================================================
1069
+ // Batch 3 - DOM & Navigation Commands
1070
+ // =============================================================================
1071
+
1072
+ /**
1073
+ * Go command: navigates to a URL.
1074
+ */
1075
+ export const goSchema: CommandSchema = {
1076
+ action: 'go',
1077
+ description: 'Navigate to a URL',
1078
+ category: 'navigation',
1079
+ primaryRole: 'destination',
1080
+ roles: [
1081
+ {
1082
+ role: 'destination',
1083
+ description: 'The URL to navigate to',
1084
+ required: true,
1085
+ expectedTypes: ['literal', 'expression'],
1086
+ svoPosition: 1,
1087
+ sovPosition: 1,
1088
+ },
1089
+ ],
1090
+ };
1091
+
1092
+ /**
1093
+ * Transition command: animates element changes.
1094
+ */
1095
+ export const transitionSchema: CommandSchema = {
1096
+ action: 'transition',
1097
+ description: 'Transition an element with animation',
1098
+ category: 'dom-visibility',
1099
+ primaryRole: 'patient',
1100
+ roles: [
1101
+ {
1102
+ role: 'patient',
1103
+ description: 'The property to transition (opacity, *background-color, etc.)',
1104
+ required: true,
1105
+ expectedTypes: ['literal'], // Only literal - CSS properties are strings, not selectors
1106
+ svoPosition: 1,
1107
+ sovPosition: 2,
1108
+ },
1109
+ {
1110
+ role: 'goal',
1111
+ description: 'The target value to transition to',
1112
+ required: true,
1113
+ expectedTypes: ['literal', 'expression'],
1114
+ svoPosition: 2,
1115
+ sovPosition: 3,
1116
+ },
1117
+ {
1118
+ role: 'destination',
1119
+ description: 'The target element (defaults to me)',
1120
+ required: false,
1121
+ expectedTypes: ['selector', 'reference'],
1122
+ default: { type: 'reference', value: 'me' },
1123
+ svoPosition: 3,
1124
+ sovPosition: 1,
1125
+ },
1126
+ {
1127
+ role: 'duration',
1128
+ description: 'Transition duration (over 500ms, for 2 seconds)',
1129
+ required: false,
1130
+ expectedTypes: ['literal'],
1131
+ svoPosition: 4,
1132
+ sovPosition: 4,
1133
+ },
1134
+ {
1135
+ role: 'style',
1136
+ description: 'Easing function (ease-in, linear, etc.)',
1137
+ required: false,
1138
+ expectedTypes: ['literal'],
1139
+ svoPosition: 5,
1140
+ sovPosition: 5,
1141
+ },
1142
+ ],
1143
+ };
1144
+
1145
+ /**
1146
+ * Clone command: clones an element.
1147
+ */
1148
+ export const cloneSchema: CommandSchema = {
1149
+ action: 'clone',
1150
+ description: 'Clone an element',
1151
+ category: 'dom-content',
1152
+ primaryRole: 'patient',
1153
+ roles: [
1154
+ {
1155
+ role: 'patient',
1156
+ description: 'The element to clone',
1157
+ required: true,
1158
+ expectedTypes: ['selector', 'reference'],
1159
+ svoPosition: 1,
1160
+ sovPosition: 2,
1161
+ },
1162
+ {
1163
+ role: 'destination',
1164
+ description: 'Where to put the clone',
1165
+ required: false,
1166
+ expectedTypes: ['selector', 'reference'],
1167
+ svoPosition: 2,
1168
+ sovPosition: 1,
1169
+ },
1170
+ ],
1171
+ };
1172
+
1173
+ /**
1174
+ * Focus command: focuses an element.
1175
+ */
1176
+ export const focusSchema: CommandSchema = {
1177
+ action: 'focus',
1178
+ description: 'Focus an element',
1179
+ category: 'dom-content',
1180
+ primaryRole: 'patient',
1181
+ roles: [
1182
+ {
1183
+ role: 'patient',
1184
+ description: 'The element to focus (defaults to me)',
1185
+ required: false,
1186
+ expectedTypes: ['selector', 'reference'],
1187
+ default: { type: 'reference', value: 'me' },
1188
+ svoPosition: 1,
1189
+ sovPosition: 1,
1190
+ },
1191
+ ],
1192
+ };
1193
+
1194
+ /**
1195
+ * Blur command: removes focus from an element.
1196
+ */
1197
+ export const blurSchema: CommandSchema = {
1198
+ action: 'blur',
1199
+ description: 'Remove focus from an element',
1200
+ category: 'dom-content',
1201
+ primaryRole: 'patient',
1202
+ roles: [
1203
+ {
1204
+ role: 'patient',
1205
+ description: 'The element to blur (defaults to me)',
1206
+ required: false,
1207
+ expectedTypes: ['selector', 'reference'],
1208
+ default: { type: 'reference', value: 'me' },
1209
+ svoPosition: 1,
1210
+ sovPosition: 1,
1211
+ },
1212
+ ],
1213
+ };
1214
+
1215
+ // =============================================================================
1216
+ // Batch 4 - Advanced Commands
1217
+ // =============================================================================
1218
+
1219
+ /**
1220
+ * Call command: calls a function.
1221
+ */
1222
+ export const callSchema: CommandSchema = {
1223
+ action: 'call',
1224
+ description: 'Call a function',
1225
+ category: 'control-flow',
1226
+ primaryRole: 'patient',
1227
+ roles: [
1228
+ {
1229
+ role: 'patient',
1230
+ description: 'The function to call',
1231
+ required: true,
1232
+ expectedTypes: ['expression', 'reference'],
1233
+ svoPosition: 1,
1234
+ sovPosition: 1,
1235
+ },
1236
+ ],
1237
+ };
1238
+
1239
+ /**
1240
+ * Return command: returns a value.
1241
+ */
1242
+ export const returnSchema: CommandSchema = {
1243
+ action: 'return',
1244
+ description: 'Return a value from a function',
1245
+ category: 'control-flow',
1246
+ primaryRole: 'patient',
1247
+ roles: [
1248
+ {
1249
+ role: 'patient',
1250
+ description: 'The value to return',
1251
+ required: false,
1252
+ expectedTypes: ['literal', 'expression', 'reference'],
1253
+ svoPosition: 1,
1254
+ sovPosition: 1,
1255
+ },
1256
+ ],
1257
+ };
1258
+
1259
+ /**
1260
+ * JS command: executes raw JavaScript.
1261
+ */
1262
+ export const jsSchema: CommandSchema = {
1263
+ action: 'js',
1264
+ description: 'Execute raw JavaScript code',
1265
+ category: 'control-flow',
1266
+ primaryRole: 'patient',
1267
+ hasBody: true,
1268
+ roles: [
1269
+ {
1270
+ role: 'patient',
1271
+ description: 'The JavaScript code to execute',
1272
+ required: false,
1273
+ expectedTypes: ['expression'],
1274
+ svoPosition: 1,
1275
+ sovPosition: 1,
1276
+ },
1277
+ ],
1278
+ };
1279
+
1280
+ /**
1281
+ * Async command: runs commands asynchronously.
1282
+ */
1283
+ export const asyncSchema: CommandSchema = {
1284
+ action: 'async',
1285
+ description: 'Execute commands asynchronously',
1286
+ category: 'async',
1287
+ primaryRole: 'patient',
1288
+ hasBody: true,
1289
+ roles: [],
1290
+ };
1291
+
1292
+ /**
1293
+ * Tell command: sends commands to another element.
1294
+ */
1295
+ export const tellSchema: CommandSchema = {
1296
+ action: 'tell',
1297
+ description: 'Execute commands in context of another element',
1298
+ category: 'control-flow',
1299
+ primaryRole: 'destination',
1300
+ hasBody: true,
1301
+ roles: [
1302
+ {
1303
+ role: 'destination',
1304
+ description: 'The element to tell',
1305
+ required: true,
1306
+ expectedTypes: ['selector', 'reference'],
1307
+ svoPosition: 1,
1308
+ sovPosition: 1,
1309
+ },
1310
+ ],
1311
+ };
1312
+
1313
+ /**
1314
+ * Default command: sets default values.
1315
+ */
1316
+ export const defaultSchema: CommandSchema = {
1317
+ action: 'default',
1318
+ description: 'Set a default value for a variable',
1319
+ category: 'variable',
1320
+ primaryRole: 'destination',
1321
+ roles: [
1322
+ {
1323
+ role: 'destination',
1324
+ description: 'The variable to set default for',
1325
+ required: true,
1326
+ expectedTypes: ['reference'],
1327
+ svoPosition: 1,
1328
+ sovPosition: 1,
1329
+ },
1330
+ {
1331
+ role: 'patient',
1332
+ description: 'The default value',
1333
+ required: true,
1334
+ expectedTypes: ['literal', 'expression'],
1335
+ svoPosition: 2,
1336
+ sovPosition: 2,
1337
+ },
1338
+ ],
1339
+ };
1340
+
1341
+ /**
1342
+ * Init command: initialization block.
1343
+ */
1344
+ export const initSchema: CommandSchema = {
1345
+ action: 'init',
1346
+ description: 'Initialization block that runs once',
1347
+ category: 'control-flow',
1348
+ primaryRole: 'patient',
1349
+ hasBody: true,
1350
+ roles: [],
1351
+ };
1352
+
1353
+ /**
1354
+ * Behavior command: defines reusable behavior.
1355
+ * Patterns:
1356
+ * - EN: behavior Draggable
1357
+ * - EN: behavior Draggable(dragHandle)
1358
+ */
1359
+ export const behaviorSchema: CommandSchema = {
1360
+ action: 'behavior',
1361
+ description: 'Define a reusable behavior',
1362
+ category: 'control-flow',
1363
+ primaryRole: 'patient',
1364
+ hasBody: true,
1365
+ roles: [
1366
+ {
1367
+ role: 'patient',
1368
+ description: 'The behavior name (PascalCase identifier)',
1369
+ required: true,
1370
+ expectedTypes: ['literal', 'reference', 'expression'], // expression for PascalCase identifiers
1371
+ svoPosition: 1,
1372
+ sovPosition: 1,
1373
+ },
1374
+ ],
1375
+ };
1376
+
1377
+ /**
1378
+ * Install command: installs a behavior on an element.
1379
+ * Patterns:
1380
+ * - EN: install Draggable
1381
+ * - EN: install Draggable(dragHandle: .titlebar)
1382
+ * - EN: install Draggable on #element
1383
+ */
1384
+ export const installSchema: CommandSchema = {
1385
+ action: 'install',
1386
+ description: 'Install a behavior on an element',
1387
+ category: 'control-flow',
1388
+ primaryRole: 'patient',
1389
+ roles: [
1390
+ {
1391
+ role: 'patient',
1392
+ description: 'The behavior name to install',
1393
+ required: true,
1394
+ expectedTypes: ['literal', 'reference', 'expression'],
1395
+ svoPosition: 1,
1396
+ sovPosition: 2,
1397
+ },
1398
+ {
1399
+ role: 'destination',
1400
+ description: 'Element to install on (defaults to me)',
1401
+ required: false,
1402
+ expectedTypes: ['selector', 'reference'],
1403
+ default: { type: 'reference', value: 'me' },
1404
+ svoPosition: 2,
1405
+ sovPosition: 1,
1406
+ },
1407
+ ],
1408
+ };
1409
+
1410
+ /**
1411
+ * Measure command: measures element dimensions or position.
1412
+ * Patterns:
1413
+ * - EN: measure x
1414
+ * - EN: measure width
1415
+ * - EN: measure width of #element
1416
+ */
1417
+ export const measureSchema: CommandSchema = {
1418
+ action: 'measure',
1419
+ description: 'Measure element dimensions (x, y, width, height, etc.)',
1420
+ category: 'dom-content',
1421
+ primaryRole: 'patient',
1422
+ roles: [
1423
+ {
1424
+ role: 'patient',
1425
+ description: 'Property to measure (x, y, width, height, top, left, etc.)',
1426
+ required: false, // Plain "measure" is valid, defaults to bounds
1427
+ expectedTypes: ['literal', 'expression'],
1428
+ svoPosition: 1,
1429
+ sovPosition: 1,
1430
+ },
1431
+ {
1432
+ role: 'source',
1433
+ description: 'Element to measure (defaults to me)',
1434
+ required: false,
1435
+ expectedTypes: ['selector', 'reference'],
1436
+ default: { type: 'reference', value: 'me' },
1437
+ svoPosition: 2,
1438
+ sovPosition: 2,
1439
+ },
1440
+ ],
1441
+ };
1442
+
1443
+ // =============================================================================
1444
+ // Batch 5 - DOM Content Manipulation
1445
+ // =============================================================================
1446
+
1447
+ /**
1448
+ * Swap command: swaps DOM content using various strategies.
1449
+ *
1450
+ * Patterns:
1451
+ * - EN: swap innerHTML of #target
1452
+ * - EN: swap delete #target
1453
+ * - EN: swap beforebegin #target with <html>
1454
+ */
1455
+ export const swapSchema: CommandSchema = {
1456
+ action: 'swap',
1457
+ description: 'Swap DOM content using various strategies (innerHTML, outerHTML, delete, etc.)',
1458
+ category: 'dom-content',
1459
+ primaryRole: 'destination',
1460
+ roles: [
1461
+ {
1462
+ role: 'method',
1463
+ description: 'The swap strategy (innerHTML, outerHTML, beforebegin, afterend, delete)',
1464
+ required: false,
1465
+ expectedTypes: ['literal'],
1466
+ svoPosition: 1,
1467
+ sovPosition: 3,
1468
+ },
1469
+ {
1470
+ role: 'destination',
1471
+ description: 'The element to swap content in/for',
1472
+ required: true,
1473
+ expectedTypes: ['selector', 'reference'],
1474
+ svoPosition: 2,
1475
+ sovPosition: 1,
1476
+ },
1477
+ {
1478
+ role: 'patient',
1479
+ description: 'The content to swap in (optional for delete)',
1480
+ required: false,
1481
+ expectedTypes: ['literal', 'expression', 'selector'],
1482
+ svoPosition: 3,
1483
+ sovPosition: 2,
1484
+ },
1485
+ ],
1486
+ };
1487
+
1488
+ /**
1489
+ * Morph command: morphs one element into another using DOM diffing.
1490
+ *
1491
+ * Patterns:
1492
+ * - EN: morph #target to <html>
1493
+ * - EN: morph me into #template
1494
+ */
1495
+ export const morphSchema: CommandSchema = {
1496
+ action: 'morph',
1497
+ description: 'Morph an element into another using DOM diffing',
1498
+ category: 'dom-content',
1499
+ primaryRole: 'destination',
1500
+ roles: [
1501
+ {
1502
+ role: 'destination',
1503
+ description: 'The element to morph',
1504
+ required: true,
1505
+ expectedTypes: ['selector', 'reference'],
1506
+ svoPosition: 1,
1507
+ sovPosition: 1,
1508
+ },
1509
+ {
1510
+ role: 'patient',
1511
+ description: 'The target content/element to morph into',
1512
+ required: true,
1513
+ expectedTypes: ['literal', 'expression', 'selector'],
1514
+ svoPosition: 2,
1515
+ sovPosition: 2,
1516
+ },
1517
+ ],
1518
+ };
1519
+
1520
+ // =============================================================================
1521
+ // Schema Registry
1522
+ // =============================================================================
1523
+
1524
+ /**
1525
+ * All available command schemas.
1526
+ */
1527
+ export const commandSchemas: Record<ActionType, CommandSchema> = {
1528
+ // Original schemas
1529
+ toggle: toggleSchema,
1530
+ add: addSchema,
1531
+ remove: removeSchema,
1532
+ put: putSchema,
1533
+ set: setSchema,
1534
+ show: showSchema,
1535
+ hide: hideSchema,
1536
+ on: onSchema,
1537
+ trigger: triggerSchema,
1538
+ wait: waitSchema,
1539
+ fetch: fetchSchema,
1540
+ increment: incrementSchema,
1541
+ decrement: decrementSchema,
1542
+ append: appendSchema,
1543
+ prepend: prependSchema,
1544
+ // Batch 1 - Simple Commands
1545
+ log: logSchema,
1546
+ get: getCommandSchema,
1547
+ take: takeSchema,
1548
+ make: makeSchema,
1549
+ halt: haltSchema,
1550
+ settle: settleSchema,
1551
+ throw: throwSchema,
1552
+ send: sendSchema,
1553
+ // Batch 2 - Control Flow
1554
+ if: ifSchema,
1555
+ unless: unlessSchema,
1556
+ else: elseSchema,
1557
+ repeat: repeatSchema,
1558
+ for: forSchema,
1559
+ while: whileSchema,
1560
+ continue: continueSchema,
1561
+ // Batch 3 - DOM & Navigation
1562
+ go: goSchema,
1563
+ transition: transitionSchema,
1564
+ clone: cloneSchema,
1565
+ focus: focusSchema,
1566
+ blur: blurSchema,
1567
+ // Batch 4 - Advanced
1568
+ call: callSchema,
1569
+ return: returnSchema,
1570
+ js: jsSchema,
1571
+ async: asyncSchema,
1572
+ tell: tellSchema,
1573
+ default: defaultSchema,
1574
+ init: initSchema,
1575
+ behavior: behaviorSchema,
1576
+ install: installSchema,
1577
+ measure: measureSchema,
1578
+ // Batch 5 - DOM Content Manipulation
1579
+ swap: swapSchema,
1580
+ morph: morphSchema,
1581
+ // Meta commands (for compound structures)
1582
+ compound: {
1583
+ action: 'compound',
1584
+ description: 'A compound node representing chained statements',
1585
+ primaryRole: 'patient', // Compound nodes don't have a traditional primary role
1586
+ category: 'control-flow',
1587
+ hasBody: true,
1588
+ roles: [],
1589
+ },
1590
+ };
1591
+
1592
+ /**
1593
+ * Get a command schema by action type.
1594
+ */
1595
+ export function getSchema(action: ActionType): CommandSchema | undefined {
1596
+ return commandSchemas[action];
1597
+ }
1598
+
1599
+ /**
1600
+ * Get all schemas for a category.
1601
+ */
1602
+ export function getSchemasByCategory(category: CommandCategory): CommandSchema[] {
1603
+ return Object.values(commandSchemas).filter(s => s.category === category);
1604
+ }
1605
+
1606
+ /**
1607
+ * Get all fully-defined schemas (with roles).
1608
+ */
1609
+ export function getDefinedSchemas(): CommandSchema[] {
1610
+ return Object.values(commandSchemas).filter(s => s.roles.length > 0);
1611
+ }
1612
+
1613
+ // =============================================================================
1614
+ // Schema Validation (Development Only)
1615
+ // =============================================================================
1616
+
1617
+ // Run schema validation at module load time in development builds
1618
+ // This is tree-shaken out in production builds
1619
+ if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') {
1620
+ // Dynamic import to avoid bundling in production
1621
+ import('./schema-validator')
1622
+ .then(({ validateAllSchemas, formatValidationResults }) => {
1623
+ const validations = validateAllSchemas(commandSchemas);
1624
+
1625
+ if (validations.size > 0) {
1626
+ console.warn('[SCHEMA VALIDATION] Found issues in command schemas:');
1627
+ console.warn(formatValidationResults(validations));
1628
+ console.warn('\nThese warnings help identify potential schema design issues.');
1629
+ console.warn('Fix them to improve type inference and avoid runtime bugs.');
1630
+ }
1631
+ })
1632
+ .catch(err => {
1633
+ // Silently ignore if schema validator is not available
1634
+ console.debug('Schema validation skipped:', err);
1635
+ });
1636
+ }