@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.
- package/LICENSE +21 -0
- package/README.md +686 -0
- package/dist/browser-ar.ar.global.js +2 -0
- package/dist/browser-core.core.global.js +2 -0
- package/dist/browser-de.de.global.js +2 -0
- package/dist/browser-east-asian.east-asian.global.js +2 -0
- package/dist/browser-en-tr.en-tr.global.js +2 -0
- package/dist/browser-en.en.global.js +2 -0
- package/dist/browser-es-en.es-en.global.js +2 -0
- package/dist/browser-es.es.global.js +2 -0
- package/dist/browser-fr.fr.global.js +2 -0
- package/dist/browser-id.id.global.js +2 -0
- package/dist/browser-ja.ja.global.js +2 -0
- package/dist/browser-ko.ko.global.js +2 -0
- package/dist/browser-lazy.lazy.global.js +2 -0
- package/dist/browser-priority.priority.global.js +2 -0
- package/dist/browser-pt.pt.global.js +2 -0
- package/dist/browser-qu.qu.global.js +2 -0
- package/dist/browser-sw.sw.global.js +2 -0
- package/dist/browser-tr.tr.global.js +2 -0
- package/dist/browser-western.western.global.js +2 -0
- package/dist/browser-zh.zh.global.js +2 -0
- package/dist/browser.global.js +3 -0
- package/dist/browser.global.js.map +1 -0
- package/dist/index.cjs +35051 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3426 -0
- package/dist/index.d.ts +3426 -0
- package/dist/index.js +34890 -0
- package/dist/index.js.map +1 -0
- package/dist/languages/ar.d.ts +78 -0
- package/dist/languages/ar.js +1622 -0
- package/dist/languages/ar.js.map +1 -0
- package/dist/languages/de.d.ts +38 -0
- package/dist/languages/de.js +1168 -0
- package/dist/languages/de.js.map +1 -0
- package/dist/languages/en.d.ts +44 -0
- package/dist/languages/en.js +3491 -0
- package/dist/languages/en.js.map +1 -0
- package/dist/languages/es.d.ts +52 -0
- package/dist/languages/es.js +1493 -0
- package/dist/languages/es.js.map +1 -0
- package/dist/languages/fr.d.ts +37 -0
- package/dist/languages/fr.js +1159 -0
- package/dist/languages/fr.js.map +1 -0
- package/dist/languages/id.d.ts +35 -0
- package/dist/languages/id.js +1152 -0
- package/dist/languages/id.js.map +1 -0
- package/dist/languages/ja.d.ts +53 -0
- package/dist/languages/ja.js +1430 -0
- package/dist/languages/ja.js.map +1 -0
- package/dist/languages/ko.d.ts +51 -0
- package/dist/languages/ko.js +1729 -0
- package/dist/languages/ko.js.map +1 -0
- package/dist/languages/pt.d.ts +37 -0
- package/dist/languages/pt.js +1127 -0
- package/dist/languages/pt.js.map +1 -0
- package/dist/languages/qu.d.ts +36 -0
- package/dist/languages/qu.js +1143 -0
- package/dist/languages/qu.js.map +1 -0
- package/dist/languages/sw.d.ts +35 -0
- package/dist/languages/sw.js +1147 -0
- package/dist/languages/sw.js.map +1 -0
- package/dist/languages/tr.d.ts +45 -0
- package/dist/languages/tr.js +1529 -0
- package/dist/languages/tr.js.map +1 -0
- package/dist/languages/zh.d.ts +58 -0
- package/dist/languages/zh.js +1257 -0
- package/dist/languages/zh.js.map +1 -0
- package/dist/types-C4dcj53L.d.ts +600 -0
- package/package.json +202 -0
- package/src/__test-utils__/index.ts +7 -0
- package/src/__test-utils__/test-helpers.ts +8 -0
- package/src/__types__/test-helpers.ts +122 -0
- package/src/analysis/index.ts +479 -0
- package/src/ast-builder/command-mappers.ts +1133 -0
- package/src/ast-builder/expression-parser/index.ts +41 -0
- package/src/ast-builder/expression-parser/parser.ts +563 -0
- package/src/ast-builder/expression-parser/tokenizer.ts +394 -0
- package/src/ast-builder/expression-parser/types.ts +208 -0
- package/src/ast-builder/index.ts +536 -0
- package/src/ast-builder/value-converters.ts +172 -0
- package/src/bridge.ts +275 -0
- package/src/browser-ar.ts +162 -0
- package/src/browser-core.ts +231 -0
- package/src/browser-de.ts +162 -0
- package/src/browser-east-asian.ts +173 -0
- package/src/browser-en-tr.ts +165 -0
- package/src/browser-en.ts +157 -0
- package/src/browser-es-en.ts +200 -0
- package/src/browser-es.ts +170 -0
- package/src/browser-fr.ts +162 -0
- package/src/browser-id.ts +162 -0
- package/src/browser-ja.ts +162 -0
- package/src/browser-ko.ts +162 -0
- package/src/browser-lazy.ts +189 -0
- package/src/browser-priority.ts +214 -0
- package/src/browser-pt.ts +162 -0
- package/src/browser-qu.ts +162 -0
- package/src/browser-sw.ts +162 -0
- package/src/browser-tr.ts +162 -0
- package/src/browser-western.ts +181 -0
- package/src/browser-zh.ts +162 -0
- package/src/browser.ts +268 -0
- package/src/cache/index.ts +14 -0
- package/src/cache/semantic-cache.ts +344 -0
- package/src/core-bridge.ts +372 -0
- package/src/explicit/converter.ts +258 -0
- package/src/explicit/index.ts +18 -0
- package/src/explicit/parser.ts +236 -0
- package/src/explicit/renderer.ts +424 -0
- package/src/generators/command-schemas.ts +1636 -0
- package/src/generators/event-handler-generator.ts +109 -0
- package/src/generators/index.ts +117 -0
- package/src/generators/language-profiles.ts +139 -0
- package/src/generators/pattern-generator.ts +537 -0
- package/src/generators/profiles/arabic.ts +131 -0
- package/src/generators/profiles/bengali.ts +132 -0
- package/src/generators/profiles/chinese.ts +124 -0
- package/src/generators/profiles/english.ts +113 -0
- package/src/generators/profiles/french.ts +125 -0
- package/src/generators/profiles/german.ts +126 -0
- package/src/generators/profiles/hindi.ts +146 -0
- package/src/generators/profiles/index.ts +46 -0
- package/src/generators/profiles/indonesian.ts +125 -0
- package/src/generators/profiles/italian.ts +139 -0
- package/src/generators/profiles/japanese.ts +149 -0
- package/src/generators/profiles/korean.ts +127 -0
- package/src/generators/profiles/marker-templates.ts +288 -0
- package/src/generators/profiles/ms.ts +130 -0
- package/src/generators/profiles/polish.ts +249 -0
- package/src/generators/profiles/portuguese.ts +115 -0
- package/src/generators/profiles/quechua.ts +113 -0
- package/src/generators/profiles/russian.ts +260 -0
- package/src/generators/profiles/spanish.ts +130 -0
- package/src/generators/profiles/swahili.ts +129 -0
- package/src/generators/profiles/thai.ts +132 -0
- package/src/generators/profiles/tl.ts +128 -0
- package/src/generators/profiles/turkish.ts +124 -0
- package/src/generators/profiles/types.ts +165 -0
- package/src/generators/profiles/ukrainian.ts +270 -0
- package/src/generators/profiles/vietnamese.ts +133 -0
- package/src/generators/schema-error-codes.ts +160 -0
- package/src/generators/schema-validator.ts +391 -0
- package/src/index.ts +429 -0
- package/src/language-building-schema.ts +3170 -0
- package/src/language-loader.ts +394 -0
- package/src/languages/_all.ts +65 -0
- package/src/languages/ar.ts +15 -0
- package/src/languages/bn.ts +16 -0
- package/src/languages/de.ts +15 -0
- package/src/languages/en.ts +29 -0
- package/src/languages/es.ts +15 -0
- package/src/languages/fr.ts +15 -0
- package/src/languages/hi.ts +26 -0
- package/src/languages/id.ts +15 -0
- package/src/languages/index.ts +18 -0
- package/src/languages/it.ts +15 -0
- package/src/languages/ja.ts +15 -0
- package/src/languages/ko.ts +15 -0
- package/src/languages/ms.ts +16 -0
- package/src/languages/pl.ts +18 -0
- package/src/languages/pt.ts +15 -0
- package/src/languages/qu.ts +15 -0
- package/src/languages/ru.ts +26 -0
- package/src/languages/sw.ts +15 -0
- package/src/languages/th.ts +16 -0
- package/src/languages/tl.ts +16 -0
- package/src/languages/tr.ts +15 -0
- package/src/languages/uk.ts +26 -0
- package/src/languages/vi.ts +16 -0
- package/src/languages/zh.ts +15 -0
- package/src/parser/index.ts +15 -0
- package/src/parser/pattern-matcher.ts +1181 -0
- package/src/parser/semantic-parser.ts +573 -0
- package/src/parser/utils/index.ts +35 -0
- package/src/parser/utils/marker-resolution.ts +111 -0
- package/src/parser/utils/possessive-keywords.ts +43 -0
- package/src/parser/utils/role-positioning.ts +70 -0
- package/src/parser/utils/type-validation.ts +134 -0
- package/src/patterns/add/ar.ts +71 -0
- package/src/patterns/add/bn.ts +70 -0
- package/src/patterns/add/hi.ts +69 -0
- package/src/patterns/add/index.ts +87 -0
- package/src/patterns/add/it.ts +61 -0
- package/src/patterns/add/ja.ts +93 -0
- package/src/patterns/add/ko.ts +74 -0
- package/src/patterns/add/ms.ts +30 -0
- package/src/patterns/add/pl.ts +62 -0
- package/src/patterns/add/ru.ts +62 -0
- package/src/patterns/add/th.ts +49 -0
- package/src/patterns/add/tl.ts +30 -0
- package/src/patterns/add/tr.ts +71 -0
- package/src/patterns/add/uk.ts +62 -0
- package/src/patterns/add/vi.ts +61 -0
- package/src/patterns/add/zh.ts +71 -0
- package/src/patterns/builders.ts +207 -0
- package/src/patterns/decrement/bn.ts +70 -0
- package/src/patterns/decrement/de.ts +42 -0
- package/src/patterns/decrement/hi.ts +68 -0
- package/src/patterns/decrement/index.ts +79 -0
- package/src/patterns/decrement/it.ts +69 -0
- package/src/patterns/decrement/ms.ts +30 -0
- package/src/patterns/decrement/pl.ts +58 -0
- package/src/patterns/decrement/ru.ts +58 -0
- package/src/patterns/decrement/th.ts +49 -0
- package/src/patterns/decrement/tl.ts +30 -0
- package/src/patterns/decrement/tr.ts +48 -0
- package/src/patterns/decrement/uk.ts +58 -0
- package/src/patterns/decrement/vi.ts +61 -0
- package/src/patterns/decrement/zh.ts +32 -0
- package/src/patterns/en.ts +302 -0
- package/src/patterns/event-handler/ar.ts +151 -0
- package/src/patterns/event-handler/bn.ts +72 -0
- package/src/patterns/event-handler/de.ts +117 -0
- package/src/patterns/event-handler/en.ts +117 -0
- package/src/patterns/event-handler/es.ts +136 -0
- package/src/patterns/event-handler/fr.ts +117 -0
- package/src/patterns/event-handler/hi.ts +64 -0
- package/src/patterns/event-handler/id.ts +117 -0
- package/src/patterns/event-handler/index.ts +119 -0
- package/src/patterns/event-handler/it.ts +54 -0
- package/src/patterns/event-handler/ja.ts +118 -0
- package/src/patterns/event-handler/ko.ts +133 -0
- package/src/patterns/event-handler/ms.ts +30 -0
- package/src/patterns/event-handler/pl.ts +62 -0
- package/src/patterns/event-handler/pt.ts +117 -0
- package/src/patterns/event-handler/qu.ts +66 -0
- package/src/patterns/event-handler/ru.ts +62 -0
- package/src/patterns/event-handler/shared.ts +270 -0
- package/src/patterns/event-handler/sw.ts +117 -0
- package/src/patterns/event-handler/th.ts +53 -0
- package/src/patterns/event-handler/tl.ts +30 -0
- package/src/patterns/event-handler/tr.ts +170 -0
- package/src/patterns/event-handler/uk.ts +62 -0
- package/src/patterns/event-handler/vi.ts +61 -0
- package/src/patterns/event-handler/zh.ts +150 -0
- package/src/patterns/get/ar.ts +49 -0
- package/src/patterns/get/bn.ts +47 -0
- package/src/patterns/get/de.ts +32 -0
- package/src/patterns/get/hi.ts +52 -0
- package/src/patterns/get/index.ts +83 -0
- package/src/patterns/get/it.ts +56 -0
- package/src/patterns/get/ja.ts +53 -0
- package/src/patterns/get/ko.ts +53 -0
- package/src/patterns/get/ms.ts +30 -0
- package/src/patterns/get/pl.ts +57 -0
- package/src/patterns/get/ru.ts +57 -0
- package/src/patterns/get/th.ts +29 -0
- package/src/patterns/get/tl.ts +30 -0
- package/src/patterns/get/uk.ts +57 -0
- package/src/patterns/get/vi.ts +48 -0
- package/src/patterns/grammar-transformed/index.ts +39 -0
- package/src/patterns/grammar-transformed/ja.ts +1713 -0
- package/src/patterns/grammar-transformed/ko.ts +1311 -0
- package/src/patterns/grammar-transformed/tr.ts +1067 -0
- package/src/patterns/hide/ar.ts +67 -0
- package/src/patterns/hide/bn.ts +47 -0
- package/src/patterns/hide/de.ts +36 -0
- package/src/patterns/hide/hi.ts +61 -0
- package/src/patterns/hide/index.ts +91 -0
- package/src/patterns/hide/it.ts +56 -0
- package/src/patterns/hide/ja.ts +69 -0
- package/src/patterns/hide/ko.ts +69 -0
- package/src/patterns/hide/ms.ts +30 -0
- package/src/patterns/hide/pl.ts +57 -0
- package/src/patterns/hide/ru.ts +57 -0
- package/src/patterns/hide/th.ts +29 -0
- package/src/patterns/hide/tl.ts +30 -0
- package/src/patterns/hide/tr.ts +65 -0
- package/src/patterns/hide/uk.ts +57 -0
- package/src/patterns/hide/vi.ts +56 -0
- package/src/patterns/hide/zh.ts +68 -0
- package/src/patterns/increment/bn.ts +70 -0
- package/src/patterns/increment/de.ts +36 -0
- package/src/patterns/increment/hi.ts +68 -0
- package/src/patterns/increment/index.ts +79 -0
- package/src/patterns/increment/it.ts +69 -0
- package/src/patterns/increment/ms.ts +30 -0
- package/src/patterns/increment/pl.ts +58 -0
- package/src/patterns/increment/ru.ts +58 -0
- package/src/patterns/increment/th.ts +49 -0
- package/src/patterns/increment/tl.ts +30 -0
- package/src/patterns/increment/tr.ts +52 -0
- package/src/patterns/increment/uk.ts +58 -0
- package/src/patterns/increment/vi.ts +61 -0
- package/src/patterns/increment/zh.ts +32 -0
- package/src/patterns/index.ts +84 -0
- package/src/patterns/languages/en/control-flow.ts +93 -0
- package/src/patterns/languages/en/fetch.ts +62 -0
- package/src/patterns/languages/en/index.ts +42 -0
- package/src/patterns/languages/en/repeat.ts +67 -0
- package/src/patterns/languages/en/set.ts +48 -0
- package/src/patterns/languages/en/swap.ts +38 -0
- package/src/patterns/languages/en/temporal.ts +57 -0
- package/src/patterns/put/ar.ts +74 -0
- package/src/patterns/put/bn.ts +53 -0
- package/src/patterns/put/en.ts +74 -0
- package/src/patterns/put/es.ts +74 -0
- package/src/patterns/put/hi.ts +69 -0
- package/src/patterns/put/id.ts +96 -0
- package/src/patterns/put/index.ts +99 -0
- package/src/patterns/put/it.ts +56 -0
- package/src/patterns/put/ja.ts +75 -0
- package/src/patterns/put/ko.ts +67 -0
- package/src/patterns/put/ms.ts +30 -0
- package/src/patterns/put/pl.ts +81 -0
- package/src/patterns/put/ru.ts +85 -0
- package/src/patterns/put/th.ts +32 -0
- package/src/patterns/put/tl.ts +30 -0
- package/src/patterns/put/tr.ts +67 -0
- package/src/patterns/put/uk.ts +85 -0
- package/src/patterns/put/vi.ts +72 -0
- package/src/patterns/put/zh.ts +62 -0
- package/src/patterns/registry.ts +163 -0
- package/src/patterns/remove/ar.ts +71 -0
- package/src/patterns/remove/bn.ts +68 -0
- package/src/patterns/remove/hi.ts +69 -0
- package/src/patterns/remove/index.ts +87 -0
- package/src/patterns/remove/it.ts +69 -0
- package/src/patterns/remove/ja.ts +74 -0
- package/src/patterns/remove/ko.ts +78 -0
- package/src/patterns/remove/ms.ts +30 -0
- package/src/patterns/remove/pl.ts +62 -0
- package/src/patterns/remove/ru.ts +62 -0
- package/src/patterns/remove/th.ts +49 -0
- package/src/patterns/remove/tl.ts +30 -0
- package/src/patterns/remove/tr.ts +78 -0
- package/src/patterns/remove/uk.ts +62 -0
- package/src/patterns/remove/vi.ts +61 -0
- package/src/patterns/remove/zh.ts +72 -0
- package/src/patterns/set/ar.ts +84 -0
- package/src/patterns/set/bn.ts +53 -0
- package/src/patterns/set/de.ts +84 -0
- package/src/patterns/set/es.ts +92 -0
- package/src/patterns/set/fr.ts +88 -0
- package/src/patterns/set/hi.ts +56 -0
- package/src/patterns/set/id.ts +84 -0
- package/src/patterns/set/index.ts +107 -0
- package/src/patterns/set/it.ts +56 -0
- package/src/patterns/set/ja.ts +86 -0
- package/src/patterns/set/ko.ts +85 -0
- package/src/patterns/set/ms.ts +30 -0
- package/src/patterns/set/pl.ts +57 -0
- package/src/patterns/set/pt.ts +84 -0
- package/src/patterns/set/ru.ts +57 -0
- package/src/patterns/set/th.ts +31 -0
- package/src/patterns/set/tl.ts +30 -0
- package/src/patterns/set/tr.ts +107 -0
- package/src/patterns/set/uk.ts +57 -0
- package/src/patterns/set/vi.ts +53 -0
- package/src/patterns/set/zh.ts +84 -0
- package/src/patterns/show/ar.ts +67 -0
- package/src/patterns/show/bn.ts +47 -0
- package/src/patterns/show/de.ts +32 -0
- package/src/patterns/show/fr.ts +32 -0
- package/src/patterns/show/hi.ts +61 -0
- package/src/patterns/show/index.ts +95 -0
- package/src/patterns/show/it.ts +56 -0
- package/src/patterns/show/ja.ts +69 -0
- package/src/patterns/show/ko.ts +73 -0
- package/src/patterns/show/ms.ts +30 -0
- package/src/patterns/show/pl.ts +57 -0
- package/src/patterns/show/ru.ts +57 -0
- package/src/patterns/show/th.ts +29 -0
- package/src/patterns/show/tl.ts +30 -0
- package/src/patterns/show/tr.ts +65 -0
- package/src/patterns/show/uk.ts +57 -0
- package/src/patterns/show/vi.ts +56 -0
- package/src/patterns/show/zh.ts +68 -0
- package/src/patterns/take/ar.ts +51 -0
- package/src/patterns/take/index.ts +31 -0
- package/src/patterns/toggle/ar.ts +61 -0
- package/src/patterns/toggle/bn.ts +70 -0
- package/src/patterns/toggle/en.ts +61 -0
- package/src/patterns/toggle/es.ts +61 -0
- package/src/patterns/toggle/hi.ts +80 -0
- package/src/patterns/toggle/index.ts +95 -0
- package/src/patterns/toggle/it.ts +69 -0
- package/src/patterns/toggle/ja.ts +156 -0
- package/src/patterns/toggle/ko.ts +113 -0
- package/src/patterns/toggle/ms.ts +30 -0
- package/src/patterns/toggle/pl.ts +62 -0
- package/src/patterns/toggle/ru.ts +62 -0
- package/src/patterns/toggle/th.ts +50 -0
- package/src/patterns/toggle/tl.ts +30 -0
- package/src/patterns/toggle/tr.ts +88 -0
- package/src/patterns/toggle/uk.ts +62 -0
- package/src/patterns/toggle/vi.ts +61 -0
- package/src/patterns/toggle/zh.ts +99 -0
- package/src/public-api.ts +286 -0
- package/src/registry.ts +441 -0
- package/src/tokenizers/arabic.ts +723 -0
- package/src/tokenizers/base.ts +1300 -0
- package/src/tokenizers/bengali.ts +289 -0
- package/src/tokenizers/chinese.ts +481 -0
- package/src/tokenizers/english.ts +416 -0
- package/src/tokenizers/french.ts +326 -0
- package/src/tokenizers/german.ts +324 -0
- package/src/tokenizers/hindi.ts +319 -0
- package/src/tokenizers/index.ts +127 -0
- package/src/tokenizers/indonesian.ts +306 -0
- package/src/tokenizers/italian.ts +458 -0
- package/src/tokenizers/japanese.ts +447 -0
- package/src/tokenizers/korean.ts +642 -0
- package/src/tokenizers/morphology/arabic-normalizer.ts +242 -0
- package/src/tokenizers/morphology/french-normalizer.ts +268 -0
- package/src/tokenizers/morphology/german-normalizer.ts +256 -0
- package/src/tokenizers/morphology/index.ts +46 -0
- package/src/tokenizers/morphology/italian-normalizer.ts +329 -0
- package/src/tokenizers/morphology/japanese-normalizer.ts +288 -0
- package/src/tokenizers/morphology/korean-normalizer.ts +428 -0
- package/src/tokenizers/morphology/polish-normalizer.ts +264 -0
- package/src/tokenizers/morphology/portuguese-normalizer.ts +310 -0
- package/src/tokenizers/morphology/spanish-normalizer.ts +327 -0
- package/src/tokenizers/morphology/turkish-normalizer.ts +412 -0
- package/src/tokenizers/morphology/types.ts +211 -0
- package/src/tokenizers/ms.ts +198 -0
- package/src/tokenizers/polish.ts +354 -0
- package/src/tokenizers/portuguese.ts +304 -0
- package/src/tokenizers/quechua.ts +339 -0
- package/src/tokenizers/russian.ts +375 -0
- package/src/tokenizers/spanish.ts +403 -0
- package/src/tokenizers/swahili.ts +303 -0
- package/src/tokenizers/thai.ts +236 -0
- package/src/tokenizers/tl.ts +198 -0
- package/src/tokenizers/turkish.ts +411 -0
- package/src/tokenizers/ukrainian.ts +369 -0
- package/src/tokenizers/vietnamese.ts +410 -0
- package/src/types/grammar-types.ts +617 -0
- package/src/types/unified-profile.ts +267 -0
- package/src/types.ts +709 -0
- package/src/utils/confidence-calculator.ts +147 -0
- package/src/validators/command-validator.ts +380 -0
- package/src/validators/index.ts +15 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var LokaScriptSemanticAr=(()=>{var fe=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=(r,e)=>{for(var t in e)fe(r,t,{get:e[t],enumerable:!0})},st=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of it(e))!ot.call(r,i)&&i!==t&&fe(r,i,{get:()=>e[i],enumerable:!(n=rt(e,i))||n.enumerable});return r};var ct=r=>st(fe({},"__esModule",{value:!0}),r);var zn={};at(zn,{ASTBuilder:()=>Y,DEFAULT_CONFIDENCE_THRESHOLD:()=>Le,HIGH_CONFIDENCE_THRESHOLD:()=>Je,SemanticAnalyzerImpl:()=>J,VERSION:()=>wn,arabicProfile:()=>I,arabicTokenizer:()=>ce,buildAST:()=>Qe,canParse:()=>be,createCommandNode:()=>V,createEventHandler:()=>$,createLiteral:()=>E,createPropertyPath:()=>W,createReference:()=>P,createSelector:()=>A,createSemanticAnalyzer:()=>Ye,fromExplicit:()=>Ne,getCommandMapper:()=>Q,getPatternsForLanguage:()=>nt,getPatternsForLanguageAndCommand:()=>Ln,getProfile:()=>he,getSupportedLanguages:()=>Cn,getTokenizer:()=>ge,isExplicitSyntax:()=>U,isLanguageSupported:()=>Ve,parse:()=>F,parseAny:()=>we,parseExplicit:()=>B,registerCommandMapper:()=>Ce,render:()=>X,renderExplicit:()=>Z,shouldUseSemanticResult:()=>et,toExplicit:()=>ke,tokenize:()=>Rn,tryGetProfile:()=>L});var K=new Map,te=new Map,ee=new Map;var ze=null;function Me(r,e,t){K.set(r,e),te.set(r,t),ee.delete(r)}var lt=new Map;function ge(r){let e=K.get(r);if(!e){let t=Array.from(K.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function he(r){let e=te.get(r);if(!e){let t=Array.from(te.keys()).join(", ");throw new Error(`Language profile '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function Ae(r){return K.get(r)}function L(r){return te.get(r)}function ne(){return Array.from(K.keys())}function Ve(r){return K.has(r)}function Oe(r,e){return ge(e).tokenize(r)}function N(r){let e=ee.get(r);if(e)return e;let t=lt.get(r);if(t)return ee.set(r,t),t;if(!ze)throw new Error(`No patterns registered for language '${r}'. Either import the language module or set a pattern generator.`);let n=he(r),i=ze(n);return ee.set(r,i),i}function Ie(r,e){return N(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}var O=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function S(r,e){return{start:r,end:e}}function v(r,e,t,n){if(typeof n=="string")return{value:r,kind:e,position:t,normalized:n};if(n){let{normalized:i,stem:o,stemConfidence:s}=n,a={value:r,kind:e,position:t};return i!==void 0&&(a.normalized=i),o!==void 0&&(a.stem=o,s!==void 0&&(a.stemConfidence=s)),a}return{value:r,kind:e,position:t}}function z(r){return/\s/.test(r)}function ie(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function oe(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function w(r){return/\d/.test(r)}function _e(r){return/[a-zA-Z]/.test(r)}function b(r){return/[a-zA-Z0-9_-]/.test(r)}function ye(r){return e=>{let t=e.charCodeAt(0);return r.some(([n,i])=>t>=n&&t<=i)}}function Be(r,e){if(e>=r.length)return null;let t=r[e];if(!ie(t))return null;let n=e,i="";if(t==="#"||t==="."){for(i+=r[n++];n<r.length&&b(r[n]);)i+=r[n++];if(i.length<=1)return null;if(n<r.length&&r[n]==="."&&t==="#"){let s=n+1;for(;s<r.length&&b(r[s]);)s++;if(s<r.length&&r[s]==="(")return i}}else if(t==="["){let o=1,s=!1,a=null,c=!1;for(i+=r[n++];n<r.length&&o>0;){let l=r[n];i+=l,c?c=!1:l==="\\"?c=!0:s?l===a&&(s=!1,a=null):l==='"'||l==="'"||l==="`"?(s=!0,a=l):l==="["?o++:l==="]"&&o--,n++}if(o!==0)return null}else if(t==="@"){for(i+=r[n++];n<r.length&&b(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="*"){for(i+=r[n++];n<r.length&&b(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="<"){if(i+=r[n++],n>=r.length||!_e(r[n]))return null;for(;n<r.length&&b(r[n]);)i+=r[n++];for(;n<r.length;){let o=r[n];if(o==="."){if(i+=r[n++],n>=r.length||!b(r[n]))return null;for(;n<r.length&&b(r[n]);)i+=r[n++]}else if(o==="#"){if(i+=r[n++],n>=r.length||!b(r[n]))return null;for(;n<r.length&&b(r[n]);)i+=r[n++]}else if(o==="["){let s=1,a=!1,c=null,l=!1;for(i+=r[n++];n<r.length&&s>0;){let p=r[n];i+=p,l?l=!1:p==="\\"?l=!0:a?p===c&&(a=!1,c=null):p==='"'||p==="'"||p==="`"?(a=!0,c=p):p==="["?s++:p==="]"&&s--,n++}if(s!==0)return null}else break}for(;n<r.length&&z(r[n]);)i+=r[n++];if(n<r.length&&r[n]==="/")for(i+=r[n++];n<r.length&&z(r[n]);)i+=r[n++];if(n>=r.length||r[n]!==">")return null;i+=r[n++]}return i||null}function dt(r,e){if(e>=r.length||r[e]!=="'"||e+1>=r.length||r[e+1].toLowerCase()!=="s")return!1;if(e+2>=r.length)return!0;let n=r[e+2];return z(n)||n==="*"||!b(n)}function je(r,e){if(e>=r.length)return null;let t=r[e];if(!oe(t)||t==="'"&&dt(r,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,s=t,a=!1;for(;o<r.length;){let c=r[o];if(s+=c,a)a=!1;else if(c==="\\")a=!0;else if(c===i)return s;o++}return s}function ae(r,e){if(e>=r.length)return!1;let t=r[e],n=r[e+1]||"",i=r[e+2]||"";if(t==="/"&&n!=="/"&&/[a-zA-Z0-9._-]/.test(n)||t==="/"&&n==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(n==="/"||n==="."&&i==="/"))return!0;let o=r.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function Ke(r,e){if(!ae(r,e))return null;let t=e,n="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<r.length;){let o=r[t];if(o==="#"){if(n.length>0&&/[a-zA-Z0-9/.]$/.test(n))for(n+=o,t++;t<r.length&&/[a-zA-Z0-9_-]/.test(r[t]);)n+=r[t++];break}if(i.test(o))n+=o,t++;else break}return n.length<2?null:n}function We(r,e){if(e>=r.length)return null;let t=r[e];if(!w(t)&&t!=="-"&&t!=="+")return null;let n=e,i="";if((r[n]==="-"||r[n]==="+")&&(i+=r[n++]),n>=r.length||!w(r[n]))return null;for(;n<r.length&&w(r[n]);)i+=r[n++];if(n<r.length&&r[n]===".")for(i+=r[n++];n<r.length&&w(r[n]);)i+=r[n++];return n<r.length&&(r.slice(n,n+2)==="ms"?i+="ms":(r[n]==="s"||r[n]==="m"||r[n]==="h")&&(i+=r[n])),i}var re=class re{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let n=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(n.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let s of o.alternatives)n.set(s,{native:s,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))n.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&n.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let s of o.alternatives)n.set(s,{native:s,normalized:i})}for(let i of t)n.set(i.native,i);this.profileKeywords=Array.from(n.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let n of this.profileKeywords)if(e.slice(t).startsWith(n.native))return v(n.native,"keyword",S(t,t+n.native.length),n.normalized);return null}isKeywordStart(e,t){let n=e.slice(t);return this.profileKeywords.some(i=>n.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,n){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let s={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return v(e,"keyword",S(t,n),s)}trySelector(e,t){let n=Be(e,t);return n?v(n,"selector",S(t,t+n.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let n=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!n)return null;let i=n[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],s=n[1];return{...v(i,"event-modifier",S(t,t+i.length)),metadata:{modifierName:o,value:s?o==="queue"?s:parseInt(s,10):void 0}}}tryString(e,t){let n=je(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryNumber(e,t){let n=We(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,i=!1){let o=t;if(i)for(;o<e.length&&z(e[o]);)o++;let s=e.slice(o);for(let a of n){let c=s.slice(0,a.length);if(a.caseInsensitive?c.toLowerCase()===a.pattern.toLowerCase():c===a.pattern){if(a.notFollowedBy&&(s[a.length]||"")===a.notFollowedBy)continue;if(a.checkBoundary){let p=s[a.length]||"";if(b(p))continue}return{suffix:a.suffix,endPos:o+a.length}}}return null}parseBaseNumber(e,t,n=!0){let i=t,o="";if(n&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!w(e[i]))return null;for(;i<e.length&&w(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&w(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,n,i={}){let{allowSign:o=!0,skipWhitespace:s=!1}=i,a=this.parseBaseNumber(e,t,o);if(!a)return null;let{number:c,endPos:l}=a,p=[...n,...re.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,l,p,s);return x&&(c+=x.suffix,l=x.endPos),v(c,"literal",S(t,l))}tryUrl(e,t){let n=Ke(e,t);return n?v(n,"url",S(t,t+n.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!b(e[t+1]))return null;let n=t+1;for(;n<e.length&&b(e[n]);)n++;let i=e.slice(t,n);return v(i,"identifier",S(t,n))}tryOperator(e,t){let n=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(n))return v(n,"operator",S(t,t+2));let i=e[t];return["<",">","!","+","-","*","/","="].includes(i)?v(i,"operator",S(t,t+1)):["(",")","{","}",",",";",":"].includes(i)?v(i,"punctuation",S(t,t+1)):null}tryMultiCharParticle(e,t,n){for(let i of n)if(e.slice(t,t+i.length)===i)return v(i,"particle",S(t,t+i.length));return null}};re.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var q=re;function $e(r){return{stem:r,confidence:1}}function Ue(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}function ut(r){let e=r.charCodeAt(0);return e>=1536&&e<=1791||e>=1872&&e<=1919||e>=2208&&e<=2303||e>=64336&&e<=65023||e>=65136&&e<=65279}function pt(r){for(let e of r)if(ut(e))return!0;return!1}function mt(r){return r.replace(/[\u064B-\u0652\u0670]/g,"")}var ft=[{pattern:"\u0648\u0627\u0644",confidencePenalty:.15,prefixType:"conjunction"},{pattern:"\u0641\u0627\u0644",confidencePenalty:.15,prefixType:"conjunction"},{pattern:"\u0628\u0627\u0644",confidencePenalty:.15,prefixType:"preposition"},{pattern:"\u0643\u0627\u0644",confidencePenalty:.15,prefixType:"preposition"},{pattern:"\u0644\u0644",confidencePenalty:.12,prefixType:"preposition"}],gt=[{pattern:"\u0627\u0644",confidencePenalty:.08,prefixType:"article",minRemaining:2},{pattern:"\u0648",confidencePenalty:.08,prefixType:"conjunction",minRemaining:3},{pattern:"\u0641",confidencePenalty:.08,prefixType:"conjunction",minRemaining:3},{pattern:"\u0628",confidencePenalty:.1,prefixType:"preposition",minRemaining:3},{pattern:"\u0644",confidencePenalty:.1,prefixType:"preposition",minRemaining:3},{pattern:"\u0643",confidencePenalty:.1,prefixType:"preposition",minRemaining:3}],ht=[{pattern:"\u064A",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u062A",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0646",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0623",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0627",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3}],yt=[{pattern:"\u0648\u0646",confidencePenalty:.1,type:"masculine-plural"},{pattern:"\u064A\u0646",confidencePenalty:.1,type:"masculine-plural-accusative"},{pattern:"\u0627\u062A",confidencePenalty:.1,type:"feminine-plural"},{pattern:"\u0627\u0646",confidencePenalty:.1,type:"dual-nominative"},{pattern:"\u064A\u0646",confidencePenalty:.1,type:"dual-accusative"},{pattern:"\u0647\u0627",confidencePenalty:.1,type:"pronoun-her"},{pattern:"\u0647\u0645",confidencePenalty:.1,type:"pronoun-them"},{pattern:"\u0647\u0646",confidencePenalty:.1,type:"pronoun-them-f"},{pattern:"\u0646\u0627",confidencePenalty:.1,type:"pronoun-us"},{pattern:"\u0643\u0645",confidencePenalty:.1,type:"pronoun-you-pl"},{pattern:"\u0643",confidencePenalty:.08,type:"pronoun-you"},{pattern:"\u0647",confidencePenalty:.08,type:"pronoun-him"},{pattern:"\u064A",confidencePenalty:.08,type:"pronoun-me"},{pattern:"\u0629",confidencePenalty:.08,type:"feminine"}],H=class{constructor(){this.language="ar"}isNormalizable(e){return!(!pt(e)||e.length<2)}normalize(e){let t=mt(e),n=1,i=[],o=[];for(let a of ft)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length);if(c.length>=2){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}if(i.length===0){for(let a of gt)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length),l=a.minRemaining??2;if(c.length>=l){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}}if(!(t.endsWith("\u0627\u062A")||t.endsWith("\u0629")||t.endsWith("\u0648\u0646")||t.endsWith("\u064A\u0646")||t.endsWith("\u0647\u0627")||t.endsWith("\u0647\u0645")||t.endsWith("\u0647\u0646")||t.endsWith("\u0646\u0627")||t.endsWith("\u0643\u0645"))&&(i.length===0||i[0]==="\u0648"||i[0]==="\u0641")){for(let a of ht)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length),l=a.minRemaining??3;if(c.length>=l){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}}for(let a of yt)if(t.endsWith(a.pattern)){let c=t.slice(0,-a.pattern.length);c.length>=2&&(t=c,n-=a.confidencePenalty,o.push(a.pattern))}return n=Math.max(.5,n),i.length===0&&o.length===0?$e(e):Ue(t,n,{removedPrefixes:i,removedSuffixes:o})}},_n=new H;var I={code:"ar",name:"Arabic",nativeName:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",direction:"rtl",wordOrder:"VSO",markingStrategy:"preposition",usesSpaces:!0,verb:{position:"start",subjectDrop:!0},references:{me:"\u0623\u0646\u0627",it:"\u0647\u0648",you:"\u0623\u0646\u062A",result:"\u0627\u0644\u0646\u062A\u064A\u062C\u0629",event:"\u0627\u0644\u062D\u062F\u062B",target:"\u0627\u0644\u0647\u062F\u0641",body:"\u0627\u0644\u062C\u0633\u0645"},possessive:{marker:"",markerPosition:"after-object",usePossessiveAdjectives:!0,specialForms:{me:"\u0644\u064A",it:"\u0644\u0647",you:"\u0644\u0643"},keywords:{\u0644\u064A:"me",\u0644\u0643:"you",\u0644\u0647:"it",\u0644\u0647\u0627:"it"}},roleMarkers:{destination:{primary:"\u0639\u0644\u0649",alternatives:["\u0641\u064A","\u0625\u0644\u0649","\u0628"],position:"before"},source:{primary:"\u0645\u0646",position:"before"},patient:{primary:"",position:"before"},style:{primary:"\u0628\u0640",alternatives:["\u0628\u0627\u0633\u062A\u062E\u062F\u0627\u0645"],position:"before"}},keywords:{toggle:{primary:"\u0628\u062F\u0651\u0644",alternatives:["\u0628\u062F\u0644","\u063A\u064A\u0651\u0631","\u063A\u064A\u0631"],normalized:"toggle"},add:{primary:"\u0623\u0636\u0641",alternatives:["\u0627\u0636\u0641","\u0632\u0650\u062F"],normalized:"add"},remove:{primary:"\u0627\u062D\u0630\u0641",alternatives:["\u0623\u0632\u0644","\u0627\u0645\u0633\u062D"],normalized:"remove"},put:{primary:"\u0636\u0639",alternatives:["\u0627\u062C\u0639\u0644"],normalized:"put"},append:{primary:"\u0623\u0644\u062D\u0642",normalized:"append"},prepend:{primary:"\u0633\u0628\u0642",normalized:"prepend"},take:{primary:"\u062E\u0630",alternatives:["\u0627\u062D\u0635\u0644"],normalized:"take"},make:{primary:"\u0627\u0635\u0646\u0639",alternatives:["\u0623\u0646\u0634\u0626"],normalized:"make"},clone:{primary:"\u0627\u0633\u062A\u0646\u0633\u062E",alternatives:["\u0627\u0646\u0633\u062E"],normalized:"clone"},swap:{primary:"\u0627\u0633\u062A\u0628\u062F\u0644",alternatives:["\u062A\u0628\u0627\u062F\u0644"],normalized:"swap"},morph:{primary:"\u062D\u0648\u0651\u0644",alternatives:["\u063A\u064A\u0651\u0631"],normalized:"morph"},set:{primary:"\u0627\u0636\u0628\u0637",alternatives:["\u0639\u064A\u0651\u0646","\u062D\u062F\u062F"],normalized:"set"},get:{primary:"\u0627\u062D\u0635\u0644",alternatives:["\u062E\u0630"],normalized:"get"},increment:{primary:"\u0632\u0650\u062F",alternatives:["\u0632\u062F","\u0627\u0631\u0641\u0639"],normalized:"increment"},decrement:{primary:"\u0623\u0646\u0642\u0635",alternatives:["\u0627\u0646\u0642\u0635","\u0642\u0644\u0644"],normalized:"decrement"},log:{primary:"\u0633\u062C\u0644",normalized:"log"},show:{primary:"\u0627\u0638\u0647\u0631",alternatives:["\u0623\u0638\u0647\u0631","\u0627\u0639\u0631\u0636"],normalized:"show"},hide:{primary:"\u0627\u062E\u0641",alternatives:["\u0623\u062E\u0641\u0650","\u0627\u062E\u0641\u064A"],normalized:"hide"},transition:{primary:"\u0627\u0646\u062A\u0642\u0627\u0644",alternatives:["\u0627\u0646\u062A\u0642\u0644"],normalized:"transition"},on:{primary:"\u0639\u0644\u0649",alternatives:["\u0639\u0646\u062F","\u0644\u062F\u0649","\u062D\u064A\u0646"],normalized:"on"},trigger:{primary:"\u062A\u0634\u063A\u064A\u0644",alternatives:["\u0623\u0637\u0644\u0642","\u0641\u0639\u0651\u0644"],normalized:"trigger"},send:{primary:"\u0623\u0631\u0633\u0644",normalized:"send"},focus:{primary:"\u062A\u0631\u0643\u064A\u0632",alternatives:["\u0631\u0643\u0632"],normalized:"focus"},blur:{primary:"\u0636\u0628\u0627\u0628\u064A\u0629",alternatives:["\u0634\u0648\u0634"],normalized:"blur"},go:{primary:"\u0627\u0630\u0647\u0628",alternatives:["\u0627\u0646\u062A\u0642\u0644"],normalized:"go"},wait:{primary:"\u0627\u0646\u062A\u0638\u0631",normalized:"wait"},fetch:{primary:"\u0627\u062D\u0636\u0631",alternatives:["\u062C\u0644\u0628"],normalized:"fetch"},settle:{primary:"\u0627\u0633\u062A\u0642\u0631",normalized:"settle"},if:{primary:"\u0625\u0630\u0627",normalized:"if"},when:{primary:"\u0639\u0646\u062F\u0645\u0627",normalized:"when"},where:{primary:"\u0623\u064A\u0646",normalized:"where"},else:{primary:"\u0648\u0625\u0644\u0627",alternatives:["\u062E\u0644\u0627\u0641 \u0630\u0644\u0643"],normalized:"else"},repeat:{primary:"\u0643\u0631\u0631",normalized:"repeat"},for:{primary:"\u0644\u0643\u0644",normalized:"for"},while:{primary:"\u0628\u064A\u0646\u0645\u0627",normalized:"while"},continue:{primary:"\u0648\u0627\u0635\u0644",normalized:"continue"},halt:{primary:"\u0623\u0648\u0642\u0641",alternatives:["\u062A\u0648\u0642\u0641"],normalized:"halt"},throw:{primary:"\u0627\u0631\u0645",alternatives:["\u0627\u0631\u0645\u0650"],normalized:"throw"},call:{primary:"\u0627\u0633\u062A\u062F\u0639",alternatives:["\u0646\u0627\u062F\u0650"],normalized:"call"},return:{primary:"\u0627\u0631\u062C\u0639",alternatives:["\u0639\u064F\u062F"],normalized:"return"},then:{primary:"\u062B\u0645",alternatives:["\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"],normalized:"then"},and:{primary:"\u0648\u0623\u064A\u0636\u0627\u064B",alternatives:["\u0623\u064A\u0636\u0627\u064B"],normalized:"and"},end:{primary:"\u0646\u0647\u0627\u064A\u0629",alternatives:["\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"],normalized:"end"},js:{primary:"\u062C\u0627\u0641\u0627\u0633\u0643\u0631\u0628\u062A",alternatives:["js"],normalized:"js"},async:{primary:"\u0645\u062A\u0632\u0627\u0645\u0646",normalized:"async"},tell:{primary:"\u0623\u062E\u0628\u0631",normalized:"tell"},default:{primary:"\u0627\u0641\u062A\u0631\u0627\u0636\u064A",normalized:"default"},init:{primary:"\u062A\u0647\u064A\u0626\u0629",alternatives:["\u0628\u062F\u0621"],normalized:"init"},behavior:{primary:"\u0633\u0644\u0648\u0643",normalized:"behavior"},install:{primary:"\u062A\u062B\u0628\u064A\u062A",alternatives:["\u062B\u0628\u0651\u062A"],normalized:"install"},measure:{primary:"\u0642\u064A\u0627\u0633",alternatives:["\u0642\u0650\u0633"],normalized:"measure"},into:{primary:"\u0641\u064A",alternatives:["\u0625\u0644\u0649"],normalized:"into"},before:{primary:"\u0642\u0628\u0644",normalized:"before"},after:{primary:"\u0628\u0639\u062F",normalized:"after"},until:{primary:"\u062D\u062A\u0649",normalized:"until"},event:{primary:"\u062D\u062F\u062B",normalized:"event"},from:{primary:"\u0645\u0646",normalized:"from"}},tokenization:{prefixes:["\u0627\u0644","\u0648","\u0641","\u0628","\u0643","\u0644"]}};var M=ye([[1536,1791],[1872,1919],[2208,2303],[64336,65023],[65136,65279]]),xt=new Set(["\u0628\u0640","\u0644\u0640","\u0643\u0640","\u0648\u0640"]),xe=new Map([["\u0648",{normalized:"and",type:"conjunction"}],["\u0641",{normalized:"then",type:"conjunction"}],["\u0628",{normalized:"with",type:"preposition"}],["\u0644",{normalized:"to",type:"preposition"}],["\u0643",{normalized:"like",type:"preposition"}],["\u0648\u0644",{normalized:"and-to",type:"conjunction"}],["\u0648\u0628",{normalized:"and-with",type:"conjunction"}],["\u0648\u0643",{normalized:"and-like",type:"conjunction"}],["\u0641\u0644",{normalized:"then-to",type:"conjunction"}],["\u0641\u0628",{normalized:"then-with",type:"conjunction"}],["\u0641\u0643",{normalized:"then-like",type:"conjunction"}]]),Fe=new Map([["\u0639\u0646\u062F\u0645\u0627",{normalized:"on",formality:"formal",confidence:.95,description:"when (formal MSA)"}],["\u062D\u064A\u0646\u0645\u0627",{normalized:"on",formality:"formal",confidence:.93,description:"when/whenever (formal)"}],["\u0639\u0646\u062F",{normalized:"on",formality:"neutral",confidence:.88,description:"at/when (neutral)"}],["\u062D\u064A\u0646",{normalized:"on",formality:"neutral",confidence:.85,description:"when/time (neutral)"}],["\u0644\u0645\u0651\u0627",{normalized:"on",formality:"dialectal",confidence:.7,description:"when (dialectal, with shadda)"}],["\u0644\u0645\u0627",{normalized:"on",formality:"dialectal",confidence:.68,description:"when (dialectal, no diacritic)"}],["\u0644\u062F\u0649",{normalized:"on",formality:"neutral",confidence:.82,description:"at/with (temporal)"}]]),se=new Set(["\u0641\u064A","\u0639\u0644\u0649","\u0645\u0646","\u0625\u0644\u0649","\u0627\u0644\u0649","\u0645\u0639","\u0639\u0646","\u0642\u0628\u0644","\u0628\u0639\u062F","\u0628\u064A\u0646"]),St=[{native:"\u0635\u062D\u064A\u062D",normalized:"true"},{native:"\u062E\u0637\u0623",normalized:"false"},{native:"null",normalized:"null"},{native:"\u0641\u0627\u0631\u063A",normalized:"null"},{native:"\u063A\u064A\u0631 \u0645\u0639\u0631\u0641",normalized:"undefined"},{native:"\u0627\u0644\u0623\u0648\u0644",normalized:"first"},{native:"\u0623\u0648\u0644",normalized:"first"},{native:"\u0627\u0644\u0623\u062E\u064A\u0631",normalized:"last"},{native:"\u0622\u062E\u0631",normalized:"last"},{native:"\u0627\u0644\u062A\u0627\u0644\u064A",normalized:"next"},{native:"\u0627\u0644\u0633\u0627\u0628\u0642",normalized:"previous"},{native:"\u0627\u0644\u0623\u0642\u0631\u0628",normalized:"closest"},{native:"\u0627\u0644\u0623\u0628",normalized:"parent"},{native:"\u0627\u0644\u0646\u0642\u0631",normalized:"click"},{native:"\u0646\u0642\u0631",normalized:"click"},{native:"\u0627\u0644\u0625\u062F\u062E\u0627\u0644",normalized:"input"},{native:"\u0625\u062F\u062E\u0627\u0644",normalized:"input"},{native:"\u0627\u0644\u062A\u063A\u064A\u064A\u0631",normalized:"change"},{native:"\u062A\u063A\u064A\u064A\u0631",normalized:"change"},{native:"\u0627\u0644\u0625\u0631\u0633\u0627\u0644",normalized:"submit"},{native:"\u0625\u0631\u0633\u0627\u0644",normalized:"submit"},{native:"\u0627\u0644\u062A\u0631\u0643\u064A\u0632",normalized:"focus"},{native:"\u0641\u0642\u062F\u0627\u0646 \u0627\u0644\u062A\u0631\u0643\u064A\u0632",normalized:"blur"},{native:"\u0636\u063A\u0637",normalized:"keydown"},{native:"\u0631\u0641\u0639",normalized:"keyup"},{native:"\u062A\u0645\u0631\u064A\u0631 \u0627\u0644\u0641\u0623\u0631\u0629",normalized:"mouseover"},{native:"\u0645\u063A\u0627\u062F\u0631\u0629 \u0627\u0644\u0641\u0623\u0631\u0629",normalized:"mouseout"},{native:"\u062A\u062D\u0645\u064A\u0644",normalized:"load"},{native:"\u062A\u0645\u0631\u064A\u0631",normalized:"scroll"},{native:"\u0623\u0646\u0627",normalized:"me"},{native:"\u0647\u0648",normalized:"it"},{native:"\u0647\u064A",normalized:"it"},{native:"\u0627\u0644\u0646\u062A\u064A\u062C\u0629",normalized:"result"},{native:"\u0627\u0644\u062D\u062F\u062B",normalized:"event"},{native:"\u0627\u0644\u0647\u062F\u0641",normalized:"target"},{native:"\u062B\u0627\u0646\u064A\u0629",normalized:"s"},{native:"\u062B\u0648\u0627\u0646\u064A",normalized:"s"},{native:"\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629",normalized:"ms"},{native:"\u062F\u0642\u064A\u0642\u0629",normalized:"m"},{native:"\u062F\u0642\u0627\u0626\u0642",normalized:"m"},{native:"\u0633\u0627\u0639\u0629",normalized:"h"},{native:"\u0633\u0627\u0639\u0627\u062A",normalized:"h"},{native:"\u0628\u062F\u0644",normalized:"toggle"},{native:"\u063A\u064A\u0631",normalized:"toggle"},{native:"\u0627\u0636\u0641",normalized:"add"},{native:"\u0627\u0632\u0644",normalized:"remove"},{native:"\u0627\u0636\u0639",normalized:"put"},{native:"\u064A\u0636\u0639",normalized:"put"},{native:"\u0627\u062C\u0639\u0644",normalized:"put"},{native:"\u0639\u064A\u0646",normalized:"set"},{native:"\u0632\u062F",normalized:"increment"},{native:"\u0627\u0631\u0641\u0639",normalized:"increment"},{native:"\u0627\u0646\u0642\u0635",normalized:"decrement"},{native:"\u0642\u0644\u0644",normalized:"decrement"},{native:"\u0633\u062C\u0644",normalized:"log"},{native:"\u0627\u0638\u0647\u0631",normalized:"show"},{native:"\u0627\u0639\u0631\u0636",normalized:"show"},{native:"\u0627\u062E\u0641",normalized:"hide"},{native:"\u0627\u062E\u0641\u064A",normalized:"hide"},{native:"\u0634\u063A\u0644",normalized:"trigger"},{native:"\u0627\u0631\u0633\u0644",normalized:"send"},{native:"\u0631\u0643\u0632",normalized:"focus"},{native:"\u0634\u0648\u0634",normalized:"blur"},{native:"\u0627\u0630\u0627",normalized:"if"},{native:"\u0644\u0648",normalized:"if"},{native:"\u0648\u0627\u0644\u0627",normalized:"else"},{native:"\u062A\u0648\u0642\u0641",normalized:"halt"},{native:"\u0627\u0646\u0633\u062E",normalized:"clone"},{native:"\u0625\u0630\u0646",normalized:"then"},{native:"\u0641\u0625\u0646",normalized:"then"},{native:"\u0646\u0647\u0627\u064A\u0629",normalized:"end"},{native:"\u0642\u0628\u0644",normalized:"before"},{native:"\u0628\u0639\u062F",normalized:"after"}],vt=[{pattern:"\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629",suffix:"ms",length:9,caseInsensitive:!1},{pattern:"\u0645\u0644\u064A_\u062B\u0627\u0646\u064A\u0629",suffix:"ms",length:8,caseInsensitive:!1},{pattern:"\u062F\u0642\u0627\u0626\u0642",suffix:"m",length:5,caseInsensitive:!1},{pattern:"\u062F\u0642\u064A\u0642\u0629",suffix:"m",length:5,caseInsensitive:!1},{pattern:"\u062B\u0648\u0627\u0646\u064A",suffix:"s",length:5,caseInsensitive:!1},{pattern:"\u062B\u0627\u0646\u064A\u0629",suffix:"s",length:5,caseInsensitive:!1},{pattern:"\u0633\u0627\u0639\u0627\u062A",suffix:"h",length:5,caseInsensitive:!1},{pattern:"\u0633\u0627\u0639\u0629",suffix:"h",length:4,caseInsensitive:!1}],Se=class extends q{constructor(){super();this.language="ar";this.direction="rtl";this.initializeKeywordsFromProfile(I,St),this.normalizer=new H}tokenize(t){let n=[],i=0;for(;i<t.length;){if(z(t[i])){i++;continue}if(ie(t[i])){let a=this.tryEventModifier(t,i);if(a){n.push(a),i=a.position.end;continue}let c=this.trySelector(t,i);if(c){n.push(c),i=c.position.end;continue}}if(oe(t[i])){let a=this.tryString(t,i);if(a){n.push(a),i=a.position.end;continue}}if(ae(t,i)){let a=this.tryUrl(t,i);if(a){n.push(a),i=a.position.end;continue}}if(w(t[i])){let a=this.extractArabicNumber(t,i);if(a){n.push(a),i=a.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){n.push(o),i=o.position.end;continue}let s=this.tryPreposition(t,i);if(s){n.push(s),i=s.position.end;continue}if(M(t[i])){let a=this.tryProclitic(t,i);if(a){n.push(a.conjunction),i=a.conjunction.position.end;continue}let c=this.extractArabicWord(t,i);if(c){n.push(c),i=c.position.end;continue}}if(b(t[i])){let a=this.extractAsciiWord(t,i);if(a){n.push(a),i=a.position.end;continue}}i++}return new O(n,"ar")}classifyToken(t){return se.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||/^\d/.test(t)?"literal":"identifier"}tryPreposition(t,n){let i=Array.from(se).sort((o,s)=>s.length-o.length);for(let o of i)if(t.slice(n,n+o.length)===o){let s=n+o.length;if(s>=t.length||z(t[s])||!M(t[s]))return{...v(o,"particle",S(n,s)),metadata:{prepositionValue:o}}}return null}tryProclitic(t,n){let i=n;for(;i<t.length&&(M(t[i])||t[i]==="\u0640");)i++;let o=t.slice(n,i);if(this.lookupKeyword(o)||Fe.has(o)||se.has(o))return null;if(n+2<=t.length){let y=t.slice(n,n+2),g=xe.get(y);if(g){let u=n+2;if(u<t.length&&M(t[u])){let m=0,h=u;for(;h<t.length&&M(t[h]);)m++,h++;if(m>=2)if(xe.get(t[n])){let R=t.slice(n+1,i);if(!this.lookupKeyword(R)){let D=g.type==="conjunction"?"conjunction":"particle";return{conjunction:v(y,D,S(n,u),g.normalized)}}}else{let R=g.type==="conjunction"?"conjunction":"particle";return{conjunction:v(y,R,S(n,u),g.normalized)}}}}}let s=t[n],a=xe.get(s);if(!a)return null;let c=n+1;if(c>=t.length||!M(t[c]))return null;let l=0,p=c;for(;p<t.length&&M(t[p]);)l++,p++;if(l<2)return null;let x=a.type==="conjunction"?"conjunction":"particle";return{conjunction:v(s,x,S(n,c),a.normalized)}}extractArabicWord(t,n){let i=n,o="";for(let l of xt){let p=l.replace("\u0640","");t.slice(i,i+p.length)}for(;i<t.length&&(M(t[i])||t[i]==="\u0640");)o+=t[i++];if(!o)return null;let s=Fe.get(o);if(s)return{...v(o,"keyword",S(n,i),s.normalized),metadata:{temporalFormality:s.formality,temporalConfidence:s.confidence}};let a=this.lookupKeyword(o);if(a)return v(o,"keyword",S(n,i),a.normalized);if(se.has(o))return{...v(o,"particle",S(n,i)),metadata:{prepositionValue:o}};let c=this.tryMorphKeywordMatch(o,n,i);return c||v(o,"identifier",S(n,i))}extractAsciiWord(t,n){let i=n,o="";for(;i<t.length&&b(t[i]);)o+=t[i++];return o?v(o,"identifier",S(n,i)):null}extractArabicNumber(t,n){return this.tryNumberWithTimeUnits(t,n,vt,{allowSign:!1,skipWhitespace:!0})}},ce=new Se;Me("ar",ce,I);function De(r){return Ae(r)}function le(r,e){return Oe(r,e)}function de(){return ne()}function A(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function E(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function P(r){return{type:"reference",value:r}}function W(r,e){return{type:"property-path",object:r,property:e}}function V(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function $(r,e,t,n,i){let o=new Map;o.set("event",r);let s={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(s.eventModifiers=t),n!==void 0&&(s.metadata=n),i!==void 0&&i.length>0&&(s.parameterNames=i),s}function qe(r,e="then",t){let n={kind:"compound",action:"compound",roles:new Map,statements:r,chainType:e};return t!==void 0&&(n.metadata=t),n}function ve(r,e){return!e||e.length===0||e.includes(r)||e.includes("expression")?!0:r==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function He(r,e){return r.possessive?.keywords?.[e]}var C=class C{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let n=e.mark(),i=new Map;if(this.currentProfile=L(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(n),null;let s=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-n.position,confidence:s}}matchBest(e,t){let n=[];for(let o of t){let s=e.mark(),a=this.matchPattern(e,o);a&&n.push(a),e.reset(s)}if(n.length===0)return null;n.sort((o,s)=>{let a=s.pattern.priority-o.pattern.priority;return a!==0?a:s.confidence-o.confidence});let i=n[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,n){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let i of t)if(!this.matchPatternToken(e,i,n)){if(this.isOptional(i))continue;return!1}return!0}matchPatternToken(e,t,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,n);case"group":return this.matchGroupToken(e,t,n);default:return!1}}matchLiteralToken(e,t){let n=e.peek();if(!n)return!1;let i=this.getMatchType(n,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let s=this.getMatchType(n,o);if(s!=="none")return this.totalKeywordMatches++,s==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,o),!0);let s=this.tryMatchMethodCallExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(s.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,s),!0);let a=this.tryMatchPossessiveSelectorExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!ve(a.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,a),!0);let c=this.tryMatchPropertyAccessExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,c),!0);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!ve(l.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,l),!0);let p=this.tokenToSemanticValue(i);return!p||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(p.type)?t.optional||!1:(n.set(t.role,p),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let n=(t.normalized||t.value).toLowerCase(),i=He(this.currentProfile,n);if(!i)return null;let o=e.mark();e.advance();let s=e.peek();return s&&(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)||s.kind==="selector"&&s.value.startsWith("*"))?(e.advance(),W(P(i),s.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let s=e.peek();if(!s||s.kind!=="punctuation"||s.value!=="(")return e.reset(n),null;e.advance();let a=[];for(;!e.isAtEnd()&&a.length<C.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}a.push(l.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${a.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let s=`${t.value}.${o.value}`,a=1;for(;!e.isAtEnd()&&a<C.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),s+=`.${p.value}`,a++}let c=e.peek();if(c&&c.kind==="punctuation"&&c.value==="("){e.advance();let l=[],p=0;for(;!e.isAtEnd()&&l.length<C.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(p===0){e.advance();break}p--}if(y.kind==="punctuation"&&y.value==="("&&p++,y.kind==="punctuation"&&y.value===","){e.advance();continue}l.push(y.value),e.advance()}return{type:"expression",raw:`${s}(${l.join(", ")})`}}return{type:"expression",raw:s}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(n),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(n),null):(e.advance(),W(A(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(n),null;let o=e.peek(1);o&&o.kind,e.advance();let s=i.value.slice(1);return W(A(t.value),s)}matchGroupToken(e,t,n){let i=e.mark(),o=new Set(n.keys());if(!this.matchTokenSequence(e,t.tokens,n)){e.reset(i);for(let a of n.keys())o.has(a)||n.delete(a);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return A(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?P(t):E(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return P(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?P(n):{type:"expression",raw:e.value};case"url":return E(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let i=e.slice(1,-1);return E(i,"string")}if(e==="true")return E(!0,"boolean");if(e==="false")return E(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let i=parseFloat(t[1]);return t[2]?E(e,"duration"):E(i,"number")}let n=parseFloat(e);return isNaN(n)?E(e,"string"):E(n,"number")}applyExtractionRules(e,t){for(let[n,i]of Object.entries(e.extraction))!t.has(n)&&i.default&&t.set(n,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let n=0,i=0,o=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")i+=1,t.has(l.role)&&(n+=1);else if(l.type==="group"){for(let p of l.tokens)if(p.type==="role"){let x=o(p.role),y=.8;i+=y,t.has(p.role)?n+=y:x&&(n+=y*.6)}}let s=i>0?n/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let l=this.stemMatchCount/this.totalKeywordMatches*.15;s=Math.max(.5,s-l)}let a=this.calculateVSOConfidenceBoost(e);s=Math.min(1,s+a);let c=this.arabicPrepositionDisambiguation(e,t);return s=Math.max(0,Math.min(1,s+c)),s}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let n=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(n.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(n.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let n=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,s]of t.entries()){let a=i[o];if(!a||a.length===0)continue;let c=s.metadata;if(c&&typeof c.prepositionValue=="string"){let l=c.prepositionValue;a.includes(l)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){let t=e.peek();if(!t)return;let n=t.value.toLowerCase();if(C.ENGLISH_NOISE_WORDS.has(n)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return n?t:void 0}};C.MAX_PROPERTY_DEPTH=10,C.MAX_METHOD_ARGS=20,C.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var G=C,_=new G;var ue=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=Ie(t,e.action);if(n.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,n);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return n.join(` ${i} `)}getChainWord(e,t){let n=L(t);return n?.keywords?n.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let n=e;return n.statements.map(o=>this.renderExplicit(o)).join(` ${n.chainType} `)}let t=[e.action];for(let[n,i]of e.roles)t.push(`${n}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let n=e;if(n.body&&n.body.length>0){let i=n.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return de()}findBestPattern(e,t){let n=t.map(i=>{let o=i.priority;for(let s of i.template.tokens)s.type==="role"&&(e.roles.has(s.role)?o+=10:s.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return n.sort((i,o)=>o.score-i.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let n=[],i=t.language;for(let o of t.template.tokens){let s=this.renderPatternToken(o,e,i);s!==null&&n.push(s)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let s=o.body.map(a=>this.render(a,i));n.push(s.join(" "))}}return n.join(" ")}renderPatternToken(e,t,n){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,n):(e.optional,null)}case"group":{if(!e.tokens.filter(s=>s.type==="role"&&!s.optional).every(s=>t.roles.has(s.role))&&e.optional)return null;if(e.optional&&e.tokens.find(a=>a.type==="role"&&a.role==="destination")){let a=t.roles.get("destination");if(a?.type==="reference"&&a.value==="me")return null}let o=[];for(let s of e.tokens){let a=this.renderPatternToken(s,t,n);a!==null&&o.push(a)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let n=L(t);return n?.references?n.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let n=L(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(n?.possessive?.specialForms&&o){let a=n.possessive.specialForms[o];if(a){let{markerPosition:c,usePossessiveAdjectives:l}=n.possessive;return l&&c==="after-object"?`${i} ${a}`:`${a} ${i}`}}let s=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:a,markerPosition:c,usePossessiveAdjectives:l}=n.possessive;if(l&&o&&c==="after-object")return`${i} ${s}`;if(a)switch(c){case"between":return n.usesSpaces?`${s}${a} ${i}`:`${s}${a}${i}`;case"after-object":return`${s}${a} ${i}`;case"before-property":return`${s} ${a} ${i}`}}return t==="en"||!n?.possessive?s==="me"?`my ${i}`:s==="it"?`its ${i}`:`${s}'s ${i}`:`${s} ${i}`}},Ee=new ue;function X(r,e){return Ee.render(r,e)}function Z(r){return Ee.renderExplicit(r)}function B(r){let e=r.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let n=Et(t);if(n.length===0)throw new Error("No command specified in explicit statement");let i=n[0].toLowerCase(),o=new Map;for(let a=1;a<n.length;a++){let c=n[a],l=c.indexOf(":");if(l===-1)throw new Error(`Invalid role format: "${c}". Expected role:value`);let p=c.slice(0,l),x=c.slice(l+1);if(p==="body"&&x.startsWith("[")){let g=bt(c,l+1),u=c.slice(l+1,g+1);o.set(p,{type:"expression",raw:u});continue}let y=Tt(x);o.set(p,y)}if(i==="on"){let a=o.get("event");if(!a)throw new Error("Event handler requires event role: [on event:click ...]");let c=o.get("body"),l=[];return c&&c.type==="expression"&&l.push(B(c.raw)),o.delete("body"),$(a,l,void 0,{sourceLanguage:"explicit"})}let s={};for(let[a,c]of o)s[a]=c;return V(i,s,{sourceLanguage:"explicit"})}function Et(r){let e=[],t="",n=!1,i="",o=0;for(let s=0;s<r.length;s++){let a=r[s];if(n){t+=a,a===i&&r[s-1]!=="\\"&&(n=!1);continue}if(a==='"'||a==="'"){n=!0,i=a,t+=a;continue}if(a==="["){o++,t+=a;continue}if(a==="]"){o--,t+=a;continue}if(a===" "&&o===0){t&&(e.push(t),t="");continue}t+=a}return t&&e.push(t),e}function Tt(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return A(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return E(t,"string")}if(r==="true")return E(!0,"boolean");if(r==="false")return E(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(r.toLowerCase()))return P(r.toLowerCase());let e=r.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?E(r,"duration"):E(t,"number")}return E(r,"string")}function bt(r,e){let t=0;for(let n=e;n<r.length;n++)if(r[n]==="[")t++;else if(r[n]==="]"&&(t--,t===0))return n;return r.length-1}function U(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var pe=class{parse(e,t){let n=le(e,t),i=N(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((p,x)=>x.priority-p.priority),s=o.filter(p=>p.command==="on"),a=_.matchBest(n,s);if(a)return this.buildEventHandler(a,n,t);let c=o.filter(p=>p.command!=="on"),l=_.matchBest(n,c);if(l)return this.buildCommand(l,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return de()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let n={};for(let[i,o]of e.captured)n[i]=o;return V(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=_.extractEventModifiers(t),s,a=e.captured.get("action");if(a&&a.type==="literal"){let c=a.value,l={};for(let[y,g]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(l[y]=g);let p=V(c,l,{sourceLanguage:n,patternId:e.pattern.id}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=N(n).filter(m=>m.command!=="on").sort((m,h)=>h.priority-m.priority),g=N(n).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,h)=>h.priority-m.priority),u=this.parseBodyWithGrammarPatterns(t,y,g,n);u.length>0?s=[p,...u]:s=[p]}else s=[p]}else{let c=N(n).filter(l=>l.command!=="on").sort((l,p)=>p.priority-l.priority);s=this.parseBodyWithClauses(t,c,n)}return $(i,s,o,{sourceLanguage:n,patternId:e.pattern.id})}parseBodyWithClauses(e,t,n){let i=[],o=[];for(;!e.isAtEnd();){let s=e.peek();if(!s)break;let a=s.kind==="conjunction"||s.kind==="keyword"&&this.isThenKeyword(s.value,n),c=s.kind==="keyword"&&this.isEndKeyword(s.value,n);if(a){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l),o.length=0}e.advance();continue}if(c){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l)}e.advance();break}o.push(s),e.advance()}if(o.length>0){let s=this.parseClause(o,t,n);i.push(...s)}return i.length>1?[qe(i,"then",{sourceLanguage:n})]:i}parseClause(e,t,n){if(e.length===0)return[];let i=new O(e,n),o=[];for(;!i.isAtEnd();){let s=_.matchBest(i,t);s?o.push(this.buildCommand(s,n)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,n,i){let o=[];for(;!e.isAtEnd();){let s=e.peek();if(s&&this.isThenKeyword(s.value,i)){e.advance();continue}if(s&&this.isEndKeyword(s.value,i)){e.advance();break}let a=!1;if(n.length>0){let c=_.matchBest(e,n);if(c){let l=c.pattern.command,p={};for(let[g,u]of c.captured)g!=="event"&&g!=="action"&&g!=="continues"&&(p[g]=u);let x=V(l,p,{sourceLanguage:i,patternId:c.pattern.id});o.push(x),a=!0;let y=c.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!a){let c=_.matchBest(e,t);c&&(o.push(this.buildCommand(c,i)),a=!0)}a||e.advance()}return o}isThenKeyword(e,t){let n={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(n[t]||n.en).has(e.toLowerCase())}isEndKeyword(e,t){let n={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(n[t]||n.en).has(e.toLowerCase())}},Te=new pe;function F(r,e){return Te.parse(r,e)}function be(r,e){return Te.canParse(r,e)}function ke(r,e){if(U(r))return r;let t=F(r,e);return Z(t)}function Ne(r,e){let t=B(r);return X(t,e)}function we(r,e){return U(r)?B(r):F(r,e)}var kt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Nt=new Set(["and","or","not","no"]),wt=new Set(["true","false","null","undefined"]),Pt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ge(r){let e=[],t=0,n=1,i=1;function o(){if(e.length===0)return!0;let u=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(u.type)}function s(u=0){return r[t+u]??""}function a(){let u=r[t];return t++,u===`
|
|
2
|
+
`?(n++,i=1):i++,u}function c(){for(;t<r.length&&/\s/.test(r[t]);)a()}function l(u){let m="";for(;t<r.length&&u(r[t]);)m+=a();return m}function p(u){let m=u;for(a();t<r.length&&r[t]!==u;)r[t]==="\\"&&t+1<r.length&&(m+=a()),m+=a();return t<r.length&&(m+=a()),m}function x(){let u="`";for(a();t<r.length&&r[t]!=="`";)r[t]==="\\"&&t+1<r.length&&(u+=a()),u+=a();return t<r.length&&(u+=a()),u}function y(){let u="<";for(a();t<r.length&&(u+=a(),!u.endsWith("/>")););return u}function g(u,m,h){return{type:u,value:m,start:h,end:t,line:n,column:i-m.length}}for(;t<r.length&&(c(),!(t>=r.length));){let u=t,m=s();if(m==="'"&&s(1)==="s"&&!/\w/.test(s(2))){a(),a(),e.push(g("POSSESSIVE","'s",u));continue}if(m==='"'||m==="'"){let h=p(m);e.push(g("STRING",h,u));continue}if(m==="`"){let h=x();e.push(g("TEMPLATE_LITERAL",h,u));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(s(1))){let h=y();e.push(g("QUERY_SELECTOR",h,u));continue}if(m==="#"&&o()){a();let h=l(T=>/[\w-]/.test(T));e.push(g("ID_SELECTOR","#"+h,u));continue}if(m==="."&&/[a-zA-Z_-]/.test(s(1))&&o()){a();let h=l(T=>/[\w-]/.test(T));e.push(g("CLASS_SELECTOR","."+h,u));continue}if(m==="["&&o()){let h=s(1);if(h==="@"||/[a-zA-Z]/.test(h)){let T="";for(T+=a();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?T+=p(r[t]):T+=a();t<r.length&&(T+=a()),e.push(g("ATTRIBUTE_SELECTOR",T,u));continue}}if(m==="["){a(),e.push(g("LBRACKET","[",u));continue}if(m==="]"){a(),e.push(g("RBRACKET","]",u));continue}if(/\d/.test(m)){let h=l(D=>/[\d.]/.test(D)),T=t,R=l(D=>/[a-zA-Z]/.test(D));Pt.has(R)?e.push(g("TIME_EXPRESSION",h+R,u)):(t=T,e.push(g("NUMBER",h,u)));continue}if(m==="("){a(),e.push(g("LPAREN","(",u));continue}if(m===")"){a(),e.push(g("RPAREN",")",u));continue}if(m==="{"){a(),e.push(g("LBRACE","{",u));continue}if(m==="}"){a(),e.push(g("RBRACE","}",u));continue}if(m===","){a(),e.push(g("COMMA",",",u));continue}if(m===":"){a(),e.push(g("COLON",":",u));continue}if(m==="."){a(),e.push(g("DOT",".",u));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){a(),e.push(g("OPERATOR",m,u));continue}if(m==="="||m==="!"||m==="<"||m===">"){let h=a();s()==="="&&(h+=a()),e.push(g("COMPARISON",h,u));continue}if(/[a-zA-Z_$]/.test(m)){let h=l(R=>/[\w$]/.test(R)),T=h.toLowerCase();kt.has(T)?e.push(g("CONTEXT_VAR",h,u)):Nt.has(T)?e.push(g("LOGICAL",h,u)):wt.has(T)?e.push(g("BOOLEAN",h,u)):e.push(g("IDENTIFIER",h,u));continue}a()}return e.push(g("EOF","",t)),e}var me=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ge(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,n=this.parseAnd();e=this.createBinaryExpression(t,e,n)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,n=this.parseEquality();e=this.createBinaryExpression(t,e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,n=this.parseComparison();e=this.createBinaryExpression(t,e,n)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,n=this.parseAddition();e=this.createBinaryExpression(t,e,n)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,n=this.parseMultiplication();e=this.createBinaryExpression(t,e,n)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,n=this.parseUnary();e=this.createBinaryExpression(t,e,n)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let n;if(this.check("STRING"))n=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))n=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:n,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(n=>({type:"objectProperty",key:n.key,value:n.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let n=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:n,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,n){return{type:"literal",value:e,dataType:t,raw:n.value,start:n.start,end:n.end,line:n.line,column:n.column}}createSelector(e,t,n){return{type:"selector",value:e,selector:e,selectorType:t,start:n.start,end:n.end,line:n.line,column:n.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,n){return{type:"binaryExpression",operator:e,left:t,right:n,start:t.start,end:n.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Pe(r){return new me().parse(r)}function k(r,e){switch(r.type){case"literal":return Ct(r);case"selector":return Rt(r,e);case"reference":return Lt(r);case"property-path":return zt(r,e);case"expression":return Mt(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function Ct(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function Rt(r,e){return e&&r.value.startsWith("*")&&/^[a-zA-Z-]/.test(r.value.slice(1))&&e.push(`Converted '${r.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:r.value,selector:r.value,selectorType:r.selectorKind}}function Lt(r){return{type:"contextReference",contextType:r.value,name:r.value}}function zt(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function Mt(r){let e=Pe(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function Xe(r,e){return r.roles.get(e)}function d(r,e,t){let n=Xe(r,e);return n?k(n,t):void 0}function f(r,e=[],t,n={}){let i={type:"command",name:r,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),n.isBlocking&&(i.isBlocking=n.isBlocking),n.implicitTarget&&(i.implicitTarget=n.implicitTarget),i}var At={action:"toggle",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"duration"),o=t?[t]:[],s={};return n&&(s.on=n),i&&(s.for=i),f("toggle",o,s)}},Vt={action:"add",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("add",i,o)}},Ot={action:"remove",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("remove",i,o)}},It={action:"set",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("set",i,o)}},_t={action:"show",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.with=i),f("show",o,s)}},Bt={action:"hide",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.with=i),f("hide",o,s)}},jt={action:"increment",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.by=i),f("increment",o,s)}},Kt={action:"decrement",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.by=i),f("decrement",o,s)}},Wt={action:"wait",toAST(r,e){let t=d(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},$t={action:"log",toAST(r,e){let t=d(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},Ut={action:"put",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=Xe(r,"method"),o=t?[t]:[],s={};if(n){let a=i?.type==="literal"?String(i.value):"into";s[a]=n}return f("put",o,s)}},Ft={action:"fetch",toAST(r,e){let t=d(r,"source"),n=d(r,"method"),i=d(r,"responseType"),o=d(r,"patient"),s=t?[t]:[],a={};return n&&(a.with=n),i&&(a.as=i),o&&(a.body=o),f("fetch",s,a,{isBlocking:!0})}},Dt={action:"append",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("append",i,o)}},qt={action:"prepend",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("prepend",i,o)}},Ht={action:"trigger",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("trigger",i,o)}},Gt={action:"send",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=d(r,"patient"),o=t?[t]:[],s={};return n&&(s.to=n),i&&(s.detail=i),f("send",o,s)}},Xt={action:"go",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("go",i,o)}},Zt={action:"transition",toAST(r,e){let t=d(r,"patient"),n=d(r,"goal"),i=d(r,"duration"),o=d(r,"destination"),s=t?[t]:[],a={};return n&&(a.to=n),i&&(a.over=i),o&&(a.on=o),f("transition",s,a)}},Qt={action:"focus",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={},s=t??n;return s&&i.push(s),f("focus",i,o)}},Yt={action:"blur",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("blur",i)}},Jt={action:"get",toAST(r,e){let t=d(r,"source"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("get",i)}},en={action:"take",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("take",i,o)}},tn={action:"call",toAST(r,e){let t=d(r,"patient");return f("call",t?[t]:[])}},nn={action:"return",toAST(r,e){let t=d(r,"patient");return f("return",t?[t]:[])}},rn={action:"halt",toAST(r,e){return f("halt",[])}},on={action:"throw",toAST(r,e){let t=d(r,"patient");return f("throw",t?[t]:[])}},an={action:"settle",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},sn={action:"swap",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=d(r,"destination"),o=d(r,"style"),s=[],a={};return t&&s.push(t),n&&s.push(n),i&&(a.on=i),o&&(a.with=o),f("swap",s,a)}},cn={action:"morph",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],s={},a=t??i;return a&&o.push(a),n&&(s.on=n),f("morph",o,s)}},ln={action:"clone",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],s={},a=t??i;return a&&o.push(a),n&&(s.into=n),f("clone",o,s)}},dn={action:"make",toAST(r,e){let t=d(r,"patient");return f("make",t?[t]:[])}},un={action:"measure",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"source"),o=[],s={};t&&o.push(t);let a=n??i;return a&&(s.of=a),f("measure",o,s)}},pn={action:"tell",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("tell",i)}},mn={action:"js",toAST(r,e){let t=d(r,"patient");return f("js",t?[t]:[])}},fn={action:"async",toAST(r,e){return f("async",[])}},gn={action:"if",toAST(r,e){let t=d(r,"condition");return f("if",t?[t]:[])}},hn={action:"unless",toAST(r,e){let t=d(r,"condition");return f("unless",t?[t]:[])}},yn={action:"repeat",toAST(r,e){let t=d(r,"quantity"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("repeat",i)}},xn={action:"for",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.in=n),f("for",i,o)}},Sn={action:"while",toAST(r,e){let t=d(r,"condition");return f("while",t?[t]:[])}},vn={action:"continue",toAST(r,e){return f("continue",[])}},En={action:"default",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.to=n),f("default",i,o)}},Tn={action:"init",toAST(r,e){return f("init",[])}},bn={action:"behavior",toAST(r,e){let t=d(r,"patient");return f("behavior",t?[t]:[])}},kn={action:"install",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("install",i,o)}},Nn={action:"on",toAST(r,e){let t=d(r,"event"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("on",i,o)}},Ze=new Map([["toggle",At],["add",Vt],["remove",Ot],["set",It],["show",_t],["hide",Bt],["increment",jt],["decrement",Kt],["wait",Wt],["log",$t],["put",Ut],["fetch",Ft],["append",Dt],["prepend",qt],["get",Jt],["take",en],["trigger",Ht],["send",Gt],["on",Nn],["go",Xt],["transition",Zt],["focus",Qt],["blur",Yt],["call",tn],["return",nn],["halt",rn],["throw",on],["settle",an],["swap",sn],["morph",cn],["clone",ln],["measure",un],["make",dn],["tell",pn],["default",En],["js",mn],["async",fn],["if",gn],["unless",hn],["repeat",yn],["for",xn],["while",Sn],["continue",vn],["init",Tn],["behavior",bn],["install",kn]]);function Q(r){return Ze.get(r)}function Ce(r){Ze.set(r.action,r)}var Y=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=Q(e.action);if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let i=n;return this.warnings.push(...i.warnings),i.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let a of i){let c=e.roles.get(a);c&&t.push(k(c))}for(let a of o){let c=e.roles.get(a);if(c){let l=this.roleToModifierKey(a);n[l]=k(c)}}let s={type:"command",name:e.action,args:t};return Object.keys(n).length>0?{...s,modifiers:n}:s}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),n,i;if(t?.type==="literal"){let h=String(t.value);h.includes("|")||h.includes(" or ")?(i=h.split(/\s+or\s+|\|/).map(T=>T.trim()),n=i[0]):n=h}else t?.type==="reference"?n=t.value:n="click";let o=e.body.map(h=>this.build(h)),s=e.roles.get("source"),a,c;s?.type==="selector"?(a=s.value,c=s.value):s?.type==="reference"?c=s.value:s?.type==="literal"&&(c=String(s.value));let l=e.roles.get("condition"),p=l?k(l):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,g=e.eventModifiers,u=a;if(g?.from){let h=g.from;h.type==="selector"&&!a&&(u=h.value)}let m=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:n,commands:o,...i&&i.length>1?{events:i}:{},...u?{selector:u}:{},...c?{target:c}:{},...p?{condition:p}:{},...y?{watchTarget:y}:{},...m&&m.length>0?{args:m,params:m}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let n=k(t),i=e.thenBranch.map(a=>this.build(a)),o=e.elseBranch?.map(a=>this.build(a)),s=[n,{type:"block",commands:i}];return o&&o.length>0&&s.push({type:"block",commands:o}),{type:"command",name:"if",args:s}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),n=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&n.push(k(i));break}case"for":{e.loopVariable&&n.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&n.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&n.push(k(i));break}case"forever":break}return n.push({type:"block",commands:t}),{type:"command",name:"repeat",args:n}}buildBlock(e){return{type:"block",commands:e.map(n=>this.build(n))}}};function Qe(r){let e=new Y;return{ast:e.build(r),warnings:e.warnings}}var j=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),i=this.cache.get(n);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),i.lastAccessed=Date.now(),this.cache.set(n,i),this.stats.hits++,i.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:n,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),i=this.cache.get(n);return i?this.isExpired(i)?(this.cache.delete(n),this.stats.expirations++,!1):!0:!1}delete(e,t){let n=this.makeKey(e,t);return this.cache.delete(n)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Re=new j;var J=class{constructor(e={}){this.patternMatcher=new G,this.languages=new Set(ne()),e.cache===!1?this.cache=new j({enabled:!1}):this.cache=e.cache?new j(e.cache):Re}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let n=this.cache.get(e,t);if(n)return n;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let n=De(t);if(!n)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=n.tokenize(e),o=N(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let s=this.patternMatcher.matchBest(i,o);if(!s)return{confidence:0,errors:["No pattern matched the input"]};let a=this.buildSemanticNode(s);return{confidence:s.confidence,command:{name:s.pattern.command,roles:s.captured},node:a,tokensConsumed:s.consumedTokens}}catch(n){return{confidence:0,errors:[n instanceof Error?n.message:String(n)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function Ye(r){return new J(r)}var Le=.5,Je=.8;function et(r,e=Le){return r.confidence>=e&&r.command!==void 0}var wn="1.0.0-ar",Pn=["ar"];function Cn(){return[...Pn]}function tt(r){if(r!=="ar")throw new Error(`Language not supported in this bundle: ${r}. Supported: ar`)}function Rn(r,e){return tt(e),[...le(r,e).tokens]}function nt(r){return tt(r),N(r)}function Ln(r,e){return nt(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return ct(zn);})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var LokaScriptSemanticCore=(()=>{var ce=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ze=Object.prototype.hasOwnProperty;var Qe=(n,e)=>{for(var t in e)ce(n,t,{get:e[t],enumerable:!0})},Ye=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xe(e))!Ze.call(n,o)&&o!==t&&ce(n,o,{get:()=>e[o],enumerable:!(r=Ge(e,o))||r.enumerable});return n};var Je=n=>Ye(ce({},"__esModule",{value:!0}),n);var lr={};Qe(lr,{ASTBuilder:()=>Q,DEFAULT_CONFIDENCE_THRESHOLD:()=>be,HIGH_CONFIDENCE_THRESHOLD:()=>qe,SemanticAnalyzerImpl:()=>Y,VERSION:()=>ir,buildAST:()=>De,canParse:()=>he,createCommandNode:()=>M,createEventHandler:()=>K,createLiteral:()=>S,createPropertyPath:()=>B,createReference:()=>C,createSelector:()=>P,createSemanticAnalyzer:()=>Fe,fromExplicit:()=>xe,getCommandMapper:()=>Z,getPatternsForLanguage:()=>k,getProfile:()=>de,getRegisteredLanguages:()=>I,getTokenizer:()=>ue,isExplicitSyntax:()=>$,isLanguageRegistered:()=>_,isLanguageSupported:()=>we,loadLanguageFromUrl:()=>sr,parse:()=>W,parseAny:()=>Se,parseExplicit:()=>z,registerCommandMapper:()=>ve,registerLanguage:()=>ee,registerLanguageModule:()=>cr,registerPatterns:()=>D,render:()=>G,renderExplicit:()=>X,setPatternGenerator:()=>Ne,shouldUseSemanticResult:()=>He,toExplicit:()=>ye,tokenize:()=>ar,tryGetProfile:()=>R});var A=new Map,U=new Map,j=new Map;var le=null;function ee(n,e,t){A.set(n,e),U.set(n,t),j.delete(n)}function Ne(n){le=n}var ke=new Map;function D(n,e){ke.set(n,e),j.delete(n)}function ue(n){let e=A.get(n);if(!e){let t=Array.from(A.keys()).join(", ");throw new Error(`Language '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function de(n){let e=U.get(n);if(!e){let t=Array.from(U.keys()).join(", ");throw new Error(`Language profile '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function Ce(n){return A.get(n)}function R(n){return U.get(n)}function I(){return Array.from(A.keys())}function _(n){return A.has(n)&&U.has(n)}function we(n){return A.has(n)}function Re(n,e){return ue(e).tokenize(n)}function k(n){let e=j.get(n);if(e)return e;let t=ke.get(n);if(t)return j.set(n,t),t;if(!le)throw new Error(`No patterns registered for language '${n}'. Either import the language module or set a pattern generator.`);let r=de(n),o=le(r);return j.set(n,o),o}function Le(n,e){return k(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}var F=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function v(n,e){return{start:n,end:e}}function T(n,e,t,r){if(typeof r=="string")return{value:n,kind:e,position:t,normalized:r};if(r){let{normalized:o,stem:i,stemConfidence:a}=r,s={value:n,kind:e,position:t};return o!==void 0&&(s.normalized=o),i!==void 0&&(s.stem=i,a!==void 0&&(s.stemConfidence=a)),s}return{value:n,kind:e,position:t}}function q(n){return/\s/.test(n)}function Pe(n){return n==="#"||n==="."||n==="["||n==="@"||n==="*"||n==="<"}function Me(n){return n==='"'||n==="'"||n==="`"||n==="\u300C"||n==="\u300D"}function L(n){return/\d/.test(n)}function Ae(n){return/[a-zA-Z]/.test(n)}function b(n){return/[a-zA-Z0-9_-]/.test(n)}function Ve(n,e){if(e>=n.length)return null;let t=n[e];if(!Pe(t))return null;let r=e,o="";if(t==="#"||t==="."){for(o+=n[r++];r<n.length&&b(n[r]);)o+=n[r++];if(o.length<=1)return null;if(r<n.length&&n[r]==="."&&t==="#"){let a=r+1;for(;a<n.length&&b(n[a]);)a++;if(a<n.length&&n[a]==="(")return o}}else if(t==="["){let i=1,a=!1,s=null,u=!1;for(o+=n[r++];r<n.length&&i>0;){let c=n[r];o+=c,u?u=!1:c==="\\"?u=!0:a?c===s&&(a=!1,s=null):c==='"'||c==="'"||c==="`"?(a=!0,s=c):c==="["?i++:c==="]"&&i--,r++}if(i!==0)return null}else if(t==="@"){for(o+=n[r++];r<n.length&&b(n[r]);)o+=n[r++];if(o.length<=1)return null}else if(t==="*"){for(o+=n[r++];r<n.length&&b(n[r]);)o+=n[r++];if(o.length<=1)return null}else if(t==="<"){if(o+=n[r++],r>=n.length||!Ae(n[r]))return null;for(;r<n.length&&b(n[r]);)o+=n[r++];for(;r<n.length;){let i=n[r];if(i==="."){if(o+=n[r++],r>=n.length||!b(n[r]))return null;for(;r<n.length&&b(n[r]);)o+=n[r++]}else if(i==="#"){if(o+=n[r++],r>=n.length||!b(n[r]))return null;for(;r<n.length&&b(n[r]);)o+=n[r++]}else if(i==="["){let a=1,s=!1,u=null,c=!1;for(o+=n[r++];r<n.length&&a>0;){let m=n[r];o+=m,c?c=!1:m==="\\"?c=!0:s?m===u&&(s=!1,u=null):m==='"'||m==="'"||m==="`"?(s=!0,u=m):m==="["?a++:m==="]"&&a--,r++}if(a!==0)return null}else break}for(;r<n.length&&q(n[r]);)o+=n[r++];if(r<n.length&&n[r]==="/")for(o+=n[r++];r<n.length&&q(n[r]);)o+=n[r++];if(r>=n.length||n[r]!==">")return null;o+=n[r++]}return o||null}function et(n,e){if(e>=n.length||n[e]!=="'"||e+1>=n.length||n[e+1].toLowerCase()!=="s")return!1;if(e+2>=n.length)return!0;let r=n[e+2];return q(r)||r==="*"||!b(r)}function ze(n,e){if(e>=n.length)return null;let t=n[e];if(!Me(t)||t==="'"&&et(n,e))return null;let o={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!o)return null;let i=e+1,a=t,s=!1;for(;i<n.length;){let u=n[i];if(a+=u,s)s=!1;else if(u==="\\")s=!0;else if(u===o)return a;i++}return a}function Oe(n,e){if(e>=n.length)return!1;let t=n[e],r=n[e+1]||"",o=n[e+2]||"";if(t==="/"&&r!=="/"&&/[a-zA-Z0-9._-]/.test(r)||t==="/"&&r==="/"&&/[a-zA-Z]/.test(o)||t==="."&&(r==="/"||r==="."&&o==="/"))return!0;let i=n.slice(e,e+8).toLowerCase();return!!(i.startsWith("http://")||i.startsWith("https://"))}function Ie(n,e){if(!Oe(n,e))return null;let t=e,r="",o=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<n.length;){let i=n[t];if(i==="#"){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=i,t++;t<n.length&&/[a-zA-Z0-9_-]/.test(n[t]);)r+=n[t++];break}if(o.test(i))r+=i,t++;else break}return r.length<2?null:r}function _e(n,e){if(e>=n.length)return null;let t=n[e];if(!L(t)&&t!=="-"&&t!=="+")return null;let r=e,o="";if((n[r]==="-"||n[r]==="+")&&(o+=n[r++]),r>=n.length||!L(n[r]))return null;for(;r<n.length&&L(n[r]);)o+=n[r++];if(r<n.length&&n[r]===".")for(o+=n[r++];r<n.length&&L(n[r]);)o+=n[r++];return r<n.length&&(n.slice(r,r+2)==="ms"?o+="ms":(n[r]==="s"||n[r]==="m"||n[r]==="h")&&(o+=n[r])),o}var te=class te{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let r=new Map;if(e.keywords){for(let[o,i]of Object.entries(e.keywords))if(r.set(i.primary,{native:i.primary,normalized:i.normalized||o}),i.alternatives)for(let a of i.alternatives)r.set(a,{native:a,normalized:i.normalized||o})}if(e.references)for(let[o,i]of Object.entries(e.references))r.set(i,{native:i,normalized:o});if(e.roleMarkers){for(let[o,i]of Object.entries(e.roleMarkers))if(i.primary&&r.set(i.primary,{native:i.primary,normalized:o}),i.alternatives)for(let a of i.alternatives)r.set(a,{native:a,normalized:o})}for(let o of t)r.set(o.native,o);this.profileKeywords=Array.from(r.values()).sort((o,i)=>i.native.length-o.native.length),this.profileKeywordMap=new Map;for(let o of this.profileKeywords){this.profileKeywordMap.set(o.native.toLowerCase(),o);let i=this.removeDiacritics(o.native);i!==o.native&&!this.profileKeywordMap.has(i.toLowerCase())&&this.profileKeywordMap.set(i.toLowerCase(),o)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let r of this.profileKeywords)if(e.slice(t).startsWith(r.native))return T(r.native,"keyword",v(t,t+r.native.length),r.normalized);return null}isKeywordStart(e,t){let r=e.slice(t);return this.profileKeywords.some(o=>r.startsWith(o.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,r){let o=this.tryNormalize(e);if(!o)return null;let i=this.lookupKeyword(o.stem);if(!i)return null;let a={normalized:i.normalized,stem:o.stem,stemConfidence:o.confidence};return T(e,"keyword",v(t,r),a)}trySelector(e,t){let r=Ve(e,t);return r?T(r,"selector",v(t,t+r.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let r=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!r)return null;let o=r[0].replace(/(\s|\.)$/,""),i=o.slice(1).split("(")[0],a=r[1];return{...T(o,"event-modifier",v(t,t+o.length)),metadata:{modifierName:i,value:a?i==="queue"?a:parseInt(a,10):void 0}}}tryString(e,t){let r=ze(e,t);return r?T(r,"literal",v(t,t+r.length)):null}tryNumber(e,t){let r=_e(e,t);return r?T(r,"literal",v(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,o=!1){let i=t;if(o)for(;i<e.length&&q(e[i]);)i++;let a=e.slice(i);for(let s of r){let u=a.slice(0,s.length);if(s.caseInsensitive?u.toLowerCase()===s.pattern.toLowerCase():u===s.pattern){if(s.notFollowedBy&&(a[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let m=a[s.length]||"";if(b(m))continue}return{suffix:s.suffix,endPos:i+s.length}}}return null}parseBaseNumber(e,t,r=!0){let o=t,i="";if(r&&(e[o]==="-"||e[o]==="+")&&(i+=e[o++]),o>=e.length||!L(e[o]))return null;for(;o<e.length&&L(e[o]);)i+=e[o++];if(o<e.length&&e[o]===".")for(i+=e[o++];o<e.length&&L(e[o]);)i+=e[o++];return!i||i==="-"||i==="+"?null:{number:i,endPos:o}}tryNumberWithTimeUnits(e,t,r,o={}){let{allowSign:i=!0,skipWhitespace:a=!1}=o,s=this.parseBaseNumber(e,t,i);if(!s)return null;let{number:u,endPos:c}=s,m=[...r,...te.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,c,m,a);return x&&(u+=x.suffix,c=x.endPos),T(u,"literal",v(t,c))}tryUrl(e,t){let r=Ie(e,t);return r?T(r,"url",v(t,t+r.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!b(e[t+1]))return null;let r=t+1;for(;r<e.length&&b(e[r]);)r++;let o=e.slice(t,r);return T(o,"identifier",v(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return T(r,"operator",v(t,t+2));let o=e[t];return["<",">","!","+","-","*","/","="].includes(o)?T(o,"operator",v(t,t+1)):["(",")","{","}",",",";",":"].includes(o)?T(o,"punctuation",v(t,t+1)):null}tryMultiCharParticle(e,t,r){for(let o of r)if(e.slice(t,t+o.length)===o)return T(o,"particle",v(t,t+o.length));return null}};te.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var pe=te;function Be(n){return Ce(n)}function re(n,e){return Re(n,e)}function ne(){return I()}function P(n){let e="complex";return n.startsWith("#")&&!n.includes(" ")?e="id":n.startsWith(".")&&!n.includes(" ")?e="class":n.startsWith("[")&&n.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(n)&&(e="element"),{type:"selector",value:n,selectorKind:e}}function S(n,e){let t={type:"literal",value:n};return e!==void 0?{type:"literal",value:n,dataType:e}:t}function C(n){return{type:"reference",value:n}}function B(n,e){return{type:"property-path",object:n,property:e}}function M(n,e,t){let r={kind:"command",action:n,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function K(n,e,t,r,o){let i=new Map;i.set("event",n);let a={kind:"event-handler",action:"on",roles:i,body:e};return t!==void 0&&(a.eventModifiers=t),r!==void 0&&(a.metadata=r),o!==void 0&&o.length>0&&(a.parameterNames=o),a}function Ke(n,e="then",t){let r={kind:"compound",action:"compound",roles:new Map,statements:n,chainType:e};return t!==void 0&&(r.metadata=t),r}function me(n,e){return!e||e.length===0||e.includes(n)||e.includes("expression")?!0:n==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function $e(n,e){return n.possessive?.keywords?.[e]}var w=class w{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let r=e.mark(),o=new Map;if(this.currentProfile=R(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,o))return e.reset(r),null;let a=this.calculateConfidence(t,o);return this.applyExtractionRules(t,o),{pattern:t,captured:o,consumedTokens:e.position()-r.position,confidence:a}}matchBest(e,t){let r=[];for(let i of t){let a=e.mark(),s=this.matchPattern(e,i);s&&r.push(s),e.reset(a)}if(r.length===0)return null;r.sort((i,a)=>{let s=a.pattern.priority-i.pattern.priority;return s!==0?s:a.confidence-i.confidence});let o=r[0];return this.matchPattern(e,o.pattern),o}matchTokenSequence(e,t,r){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let o of t)if(!this.matchPatternToken(e,o,r)){if(this.isOptional(o))continue;return!1}return!0}matchPatternToken(e,t,r){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r);case"group":return this.matchGroupToken(e,t,r);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(!r)return!1;let o=this.getMatchType(r,t.value);if(o!=="none")return this.totalKeywordMatches++,o==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let i of t.alternatives){let a=this.getMatchType(r,i);if(a!=="none")return this.totalKeywordMatches++,a==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,r){this.skipNoiseWords(e);let o=e.peek();if(!o)return t.optional||!1;let i=this.tryMatchPossessiveExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(i.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,i),!0);let a=this.tryMatchMethodCallExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(a.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,a),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!me(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);let u=this.tryMatchPropertyAccessExpression(e);if(u)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(u.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,u),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!me(c.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,c),!0);let m=this.tokenToSemanticValue(o);return!m||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(m.type)?t.optional||!1:(r.set(t.role,m),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=(t.normalized||t.value).toLowerCase(),o=$e(this.currentProfile,r);if(!o)return null;let i=e.mark();e.advance();let a=e.peek();return a&&(a.kind==="identifier"||a.kind==="keyword"&&!this.isStructuralKeyword(a.value)||a.kind==="selector"&&a.value.startsWith("*"))?(e.advance(),B(C(o),a.value)):(e.reset(i),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let o=e.peek();if(!o||o.kind!=="operator"||o.value!==".")return e.reset(r),null;e.advance();let i=e.peek();if(!i||i.kind!=="identifier")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="punctuation"||a.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<w.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${i.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let r=e.mark();e.advance();let o=e.peek();if(!o||o.kind!=="operator"||o.value!==".")return e.reset(r),null;e.advance();let i=e.peek();if(!i||i.kind!=="identifier")return e.reset(r),null;e.advance();let a=`${t.value}.${i.value}`,s=1;for(;!e.isAtEnd()&&s<w.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let m=e.peek();if(!m||m.kind!=="identifier")break;e.advance(),a+=`.${m.value}`,s++}let u=e.peek();if(u&&u.kind==="punctuation"&&u.value==="("){e.advance();let c=[],m=0;for(;!e.isAtEnd()&&c.length<w.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(m===0){e.advance();break}m--}if(y.kind==="punctuation"&&y.value==="("&&m++,y.kind==="punctuation"&&y.value===","){e.advance();continue}c.push(y.value),e.advance()}return{type:"expression",raw:`${a}(${c.join(", ")})`}}return{type:"expression",raw:a}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let o=e.peek();if(!o||o.kind!=="punctuation"||o.value!=="'s")return e.reset(r),null;e.advance();let i=e.peek();return!i||i.kind!=="selector"&&i.kind!=="identifier"?(e.reset(r),null):(e.advance(),B(P(t.value),i.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let o=e.peek();if(!o||o.kind!=="selector"||!o.value.startsWith("."))return e.reset(r),null;let i=e.peek(1);i&&i.kind,e.advance();let a=o.value.slice(1);return B(P(t.value),a)}matchGroupToken(e,t,r){let o=e.mark(),i=new Set(r.keys());if(!this.matchTokenSequence(e,t.tokens,r)){e.reset(o);for(let s of r.keys())i.has(s)||r.delete(s);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return P(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?C(t):S(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return C(e.value);let r=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(r)?C(r):{type:"expression",raw:e.value};case"url":return S(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let o=e.slice(1,-1);return S(o,"string")}if(e==="true")return S(!0,"boolean");if(e==="false")return S(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let o=parseFloat(t[1]);return t[2]?S(e,"duration"):S(o,"number")}let r=parseFloat(e);return isNaN(r)?S(e,"string"):S(r,"number")}applyExtractionRules(e,t){for(let[r,o]of Object.entries(e.extraction))!t.has(r)&&o.default&&t.set(r,o.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let r=0,o=0,i=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")o+=1,t.has(c.role)&&(r+=1);else if(c.type==="group"){for(let m of c.tokens)if(m.type==="role"){let x=i(m.role),y=.8;o+=y,t.has(m.role)?r+=y:x&&(r+=y*.6)}}let a=o>0?r/o:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let c=this.stemMatchCount/this.totalKeywordMatches*.15;a=Math.max(.5,a-c)}let s=this.calculateVSOConfidenceBoost(e);a=Math.min(1,a+s);let u=this.arabicPrepositionDisambiguation(e,t);return a=Math.max(0,Math.min(1,a+u)),a}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let r=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(r.has(t.value))return .15;if(t.alternatives){for(let o of t.alternatives)if(r.has(o))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let r=0,o={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[i,a]of t.entries()){let s=o[i];if(!s||s.length===0)continue;let u=a.metadata;if(u&&typeof u.prepositionValue=="string"){let c=u.prepositionValue;s.includes(c)?r+=.1:r-=.1}}return Math.max(-.1,Math.min(.1,r))}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=t.value.toLowerCase();if(w.ENGLISH_NOISE_WORDS.has(r)){let o=e.mark();e.advance();let i=e.peek();if(i&&i.kind==="selector")return;e.reset(o)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let o=e.peek();if(!o||o.kind!=="event-modifier")break;let i=o.metadata;if(!i)break;switch(r=!0,i.modifierName){case"once":t.once=!0;break;case"debounce":typeof i.value=="number"&&(t.debounce=i.value);break;case"throttle":typeof i.value=="number"&&(t.throttle=i.value);break;case"queue":(i.value==="first"||i.value==="last"||i.value==="all"||i.value==="none")&&(t.queue=i.value);break}e.advance()}return r?t:void 0}};w.MAX_PROPERTY_DEPTH=10,w.MAX_METHOD_ARGS=20,w.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var H=w,V=new H;var oe=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let r=Le(t,e.action);if(r.length===0)return this.renderExplicit(e);let o=this.findBestPattern(e,r);return o?this.renderWithPattern(e,o):this.renderExplicit(e)}renderCompound(e,t){let r=e.statements.map(i=>this.render(i,t)),o=this.getChainWord(e.chainType,t);return r.join(` ${o} `)}getChainWord(e,t){let r=R(t);return r?.keywords?r.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let r=e;return r.statements.map(i=>this.renderExplicit(i)).join(` ${r.chainType} `)}let t=[e.action];for(let[r,o]of e.roles)t.push(`${r}:${this.valueToString(o)}`);if(e.kind==="event-handler"){let r=e;if(r.body&&r.body.length>0){let o=r.body.map(i=>this.renderExplicit(i));t.push(`body:${o.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return ne()}findBestPattern(e,t){let r=t.map(o=>{let i=o.priority;for(let a of o.template.tokens)a.type==="role"&&(e.roles.has(a.role)?i+=10:a.optional||(i-=50));return o.language==="en"&&((o.id.includes("standard")||o.id.includes("en-source"))&&(i+=20),(o.id.includes("-when")||o.id.includes("-if")||o.id.includes("-upon"))&&(i-=15)),{pattern:o,score:i}});return r.sort((o,i)=>i.score-o.score),r.length>0?r[0].pattern:null}renderWithPattern(e,t){let r=[],o=t.language;for(let i of t.template.tokens){let a=this.renderPatternToken(i,e,o);a!==null&&r.push(a)}if(e.kind==="event-handler"){let i=e;if(i.body&&i.body.length>0){let a=i.body.map(s=>this.render(s,o));r.push(a.join(" "))}}return r.join(" ")}renderPatternToken(e,t,r){switch(e.type){case"literal":return e.value;case"role":{let o=t.roles.get(e.role);return o?this.valueToNaturalString(o,r):(e.optional,null)}case"group":{if(!e.tokens.filter(a=>a.type==="role"&&!a.optional).every(a=>t.roles.has(a.role))&&e.optional)return null;if(e.optional&&e.tokens.find(s=>s.type==="role"&&s.role==="destination")){let s=t.roles.get("destination");if(s?.type==="reference"&&s.value==="me")return null}let i=[];for(let a of e.tokens){let s=this.renderPatternToken(a,t,r);s!==null&&i.push(s)}return i.length>0?i.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let r=R(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=R(t),o=e.property,i=e.object.type==="reference"?e.object.value:null;if(r?.possessive?.specialForms&&i){let s=r.possessive.specialForms[i];if(s){let{markerPosition:u,usePossessiveAdjectives:c}=r.possessive;return c&&u==="after-object"?`${o} ${s}`:`${s} ${o}`}}let a=this.valueToNaturalString(e.object,t);if(r?.possessive){let{marker:s,markerPosition:u,usePossessiveAdjectives:c}=r.possessive;if(c&&i&&u==="after-object")return`${o} ${a}`;if(s)switch(u){case"between":return r.usesSpaces?`${a}${s} ${o}`:`${a}${s}${o}`;case"after-object":return`${a}${s} ${o}`;case"before-property":return`${a} ${s} ${o}`}}return t==="en"||!r?.possessive?a==="me"?`my ${o}`:a==="it"?`its ${o}`:`${a}'s ${o}`:`${a} ${o}`}},fe=new oe;function G(n,e){return fe.render(n,e)}function X(n){return fe.renderExplicit(n)}function z(n){let e=n.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let r=tt(t);if(r.length===0)throw new Error("No command specified in explicit statement");let o=r[0].toLowerCase(),i=new Map;for(let s=1;s<r.length;s++){let u=r[s],c=u.indexOf(":");if(c===-1)throw new Error(`Invalid role format: "${u}". Expected role:value`);let m=u.slice(0,c),x=u.slice(c+1);if(m==="body"&&x.startsWith("[")){let h=nt(u,c+1),d=u.slice(c+1,h+1);i.set(m,{type:"expression",raw:d});continue}let y=rt(x);i.set(m,y)}if(o==="on"){let s=i.get("event");if(!s)throw new Error("Event handler requires event role: [on event:click ...]");let u=i.get("body"),c=[];return u&&u.type==="expression"&&c.push(z(u.raw)),i.delete("body"),K(s,c,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,u]of i)a[s]=u;return M(o,a,{sourceLanguage:"explicit"})}function tt(n){let e=[],t="",r=!1,o="",i=0;for(let a=0;a<n.length;a++){let s=n[a];if(r){t+=s,s===o&&n[a-1]!=="\\"&&(r=!1);continue}if(s==='"'||s==="'"){r=!0,o=s,t+=s;continue}if(s==="["){i++,t+=s;continue}if(s==="]"){i--,t+=s;continue}if(s===" "&&i===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function rt(n){if(n.startsWith("#")||n.startsWith(".")||n.startsWith("[")||n.startsWith("@")||n.startsWith("*"))return P(n);if(n.startsWith('"')||n.startsWith("'")){let t=n.slice(1,-1);return S(t,"string")}if(n==="true")return S(!0,"boolean");if(n==="false")return S(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(n.toLowerCase()))return C(n.toLowerCase());let e=n.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?S(n,"duration"):S(t,"number")}return S(n,"string")}function nt(n,e){let t=0;for(let r=e;r<n.length;r++)if(n[r]==="[")t++;else if(n[r]==="]"&&(t--,t===0))return r;return n.length-1}function $(n){let e=n.trim();return e.startsWith("[")&&e.endsWith("]")}var ie=class{parse(e,t){let r=re(e,t),o=k(t);if(o.length===0)throw new Error(`No patterns available for language: ${t}`);let i=[...o].sort((m,x)=>x.priority-m.priority),a=i.filter(m=>m.command==="on"),s=V.matchBest(r,a);if(s)return this.buildEventHandler(s,r,t);let u=i.filter(m=>m.command!=="on"),c=V.matchBest(r,u);if(c)return this.buildCommand(c,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return ne()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let r={};for(let[o,i]of e.captured)r[o]=i;return M(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,r){if(!e)throw new Error("No match to build event handler from");let o=e.captured.get("event");if(!o)throw new Error("Event handler pattern matched but no event captured");let i=V.extractEventModifiers(t),a,s=e.captured.get("action");if(s&&s.type==="literal"){let u=s.value,c={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(c[y]=h);let m=M(u,c,{sourceLanguage:r,patternId:e.pattern.id}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=k(r).filter(p=>p.command!=="on").sort((p,g)=>g.priority-p.priority),h=k(r).filter(p=>p.id.startsWith("grammar-")&&p.id.includes("-continuation")).sort((p,g)=>g.priority-p.priority),d=this.parseBodyWithGrammarPatterns(t,y,h,r);d.length>0?a=[m,...d]:a=[m]}else a=[m]}else{let u=k(r).filter(c=>c.command!=="on").sort((c,m)=>m.priority-c.priority);a=this.parseBodyWithClauses(t,u,r)}return K(o,a,i,{sourceLanguage:r,patternId:e.pattern.id})}parseBodyWithClauses(e,t,r){let o=[],i=[];for(;!e.isAtEnd();){let a=e.peek();if(!a)break;let s=a.kind==="conjunction"||a.kind==="keyword"&&this.isThenKeyword(a.value,r),u=a.kind==="keyword"&&this.isEndKeyword(a.value,r);if(s){if(i.length>0){let c=this.parseClause(i,t,r);o.push(...c),i.length=0}e.advance();continue}if(u){if(i.length>0){let c=this.parseClause(i,t,r);o.push(...c)}e.advance();break}i.push(a),e.advance()}if(i.length>0){let a=this.parseClause(i,t,r);o.push(...a)}return o.length>1?[Ke(o,"then",{sourceLanguage:r})]:o}parseClause(e,t,r){if(e.length===0)return[];let o=new F(e,r),i=[];for(;!o.isAtEnd();){let a=V.matchBest(o,t);a?i.push(this.buildCommand(a,r)):o.advance()}return i}parseBodyWithGrammarPatterns(e,t,r,o){let i=[];for(;!e.isAtEnd();){let a=e.peek();if(a&&this.isThenKeyword(a.value,o)){e.advance();continue}if(a&&this.isEndKeyword(a.value,o)){e.advance();break}let s=!1;if(r.length>0){let u=V.matchBest(e,r);if(u){let c=u.pattern.command,m={};for(let[h,d]of u.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(m[h]=d);let x=M(c,m,{sourceLanguage:o,patternId:u.pattern.id});i.push(x),s=!0;let y=u.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!s){let u=V.matchBest(e,t);u&&(i.push(this.buildCommand(u,o)),s=!0)}s||e.advance()}return i}isThenKeyword(e,t){let r={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(r[t]||r.en).has(e.toLowerCase())}isEndKeyword(e,t){let r={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(r[t]||r.en).has(e.toLowerCase())}},ge=new ie;function W(n,e){return ge.parse(n,e)}function he(n,e){return ge.canParse(n,e)}function ye(n,e){if($(n))return n;let t=W(n,e);return X(t)}function xe(n,e){let t=z(n);return G(t,e)}function Se(n,e){return $(n)?z(n):W(n,e)}var ot=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),it=new Set(["and","or","not","no"]),at=new Set(["true","false","null","undefined"]),st=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function We(n){let e=[],t=0,r=1,o=1;function i(){if(e.length===0)return!0;let d=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(d.type)}function a(d=0){return n[t+d]??""}function s(){let d=n[t];return t++,d===`
|
|
2
|
+
`?(r++,o=1):o++,d}function u(){for(;t<n.length&&/\s/.test(n[t]);)s()}function c(d){let p="";for(;t<n.length&&d(n[t]);)p+=s();return p}function m(d){let p=d;for(s();t<n.length&&n[t]!==d;)n[t]==="\\"&&t+1<n.length&&(p+=s()),p+=s();return t<n.length&&(p+=s()),p}function x(){let d="`";for(s();t<n.length&&n[t]!=="`";)n[t]==="\\"&&t+1<n.length&&(d+=s()),d+=s();return t<n.length&&(d+=s()),d}function y(){let d="<";for(s();t<n.length&&(d+=s(),!d.endsWith("/>")););return d}function h(d,p,g){return{type:d,value:p,start:g,end:t,line:r,column:o-p.length}}for(;t<n.length&&(u(),!(t>=n.length));){let d=t,p=a();if(p==="'"&&a(1)==="s"&&!/\w/.test(a(2))){s(),s(),e.push(h("POSSESSIVE","'s",d));continue}if(p==='"'||p==="'"){let g=m(p);e.push(h("STRING",g,d));continue}if(p==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,d));continue}if(p==="<"&&/[a-zA-Z.#\[]/.test(a(1))){let g=y();e.push(h("QUERY_SELECTOR",g,d));continue}if(p==="#"&&i()){s();let g=c(E=>/[\w-]/.test(E));e.push(h("ID_SELECTOR","#"+g,d));continue}if(p==="."&&/[a-zA-Z_-]/.test(a(1))&&i()){s();let g=c(E=>/[\w-]/.test(E));e.push(h("CLASS_SELECTOR","."+g,d));continue}if(p==="["&&i()){let g=a(1);if(g==="@"||/[a-zA-Z]/.test(g)){let E="";for(E+=s();t<n.length&&n[t]!=="]";)n[t]==='"'||n[t]==="'"?E+=m(n[t]):E+=s();t<n.length&&(E+=s()),e.push(h("ATTRIBUTE_SELECTOR",E,d));continue}}if(p==="["){s(),e.push(h("LBRACKET","[",d));continue}if(p==="]"){s(),e.push(h("RBRACKET","]",d));continue}if(/\d/.test(p)){let g=c(se=>/[\d.]/.test(se)),E=t,J=c(se=>/[a-zA-Z]/.test(se));st.has(J)?e.push(h("TIME_EXPRESSION",g+J,d)):(t=E,e.push(h("NUMBER",g,d)));continue}if(p==="("){s(),e.push(h("LPAREN","(",d));continue}if(p===")"){s(),e.push(h("RPAREN",")",d));continue}if(p==="{"){s(),e.push(h("LBRACE","{",d));continue}if(p==="}"){s(),e.push(h("RBRACE","}",d));continue}if(p===","){s(),e.push(h("COMMA",",",d));continue}if(p===":"){s(),e.push(h("COLON",":",d));continue}if(p==="."){s(),e.push(h("DOT",".",d));continue}if(p==="+"||p==="-"||p==="*"||p==="/"||p==="%"){s(),e.push(h("OPERATOR",p,d));continue}if(p==="="||p==="!"||p==="<"||p===">"){let g=s();a()==="="&&(g+=s()),e.push(h("COMPARISON",g,d));continue}if(/[a-zA-Z_$]/.test(p)){let g=c(J=>/[\w$]/.test(J)),E=g.toLowerCase();ot.has(E)?e.push(h("CONTEXT_VAR",g,d)):it.has(E)?e.push(h("LOGICAL",g,d)):at.has(E)?e.push(h("BOOLEAN",g,d)):e.push(h("IDENTIFIER",g,d));continue}s()}return e.push(h("EOF","",t)),e}var ae=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=We(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,r=this.parseAnd();e=this.createBinaryExpression(t,e,r)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,r=this.parseEquality();e=this.createBinaryExpression(t,e,r)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,r=this.parseComparison();e=this.createBinaryExpression(t,e,r)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,r=this.parseAddition();e=this.createBinaryExpression(t,e,r)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,r=this.parseMultiplication();e=this.createBinaryExpression(t,e,r)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,r=this.parseUnary();e=this.createBinaryExpression(t,e,r)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let r;if(this.check("STRING"))r=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))r=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let o=this.parseExpression();e.push({key:r,value:o})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(r=>({type:"objectProperty",key:r.key,value:r.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let r=parseFloat(t[1]),o=t[2].toLowerCase();return{type:"timeExpression",value:r,unit:o,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,r){return{type:"literal",value:e,dataType:t,raw:r.value,start:r.start,end:r.end,line:r.line,column:r.column}}createSelector(e,t,r){return{type:"selector",value:e,selector:e,selectorType:t,start:r.start,end:r.end,line:r.line,column:r.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,r){return{type:"binaryExpression",operator:e,left:t,right:r,start:t.start,end:r.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Ee(n){return new ae().parse(n)}function N(n,e){switch(n.type){case"literal":return ct(n);case"selector":return lt(n,e);case"reference":return ut(n);case"property-path":return dt(n,e);case"expression":return pt(n);default:let t=n;throw new Error(`Unknown semantic value type: ${t.type}`)}}function ct(n){let e={type:"literal",value:n.value};return n.dataType?{...e,dataType:n.dataType}:e}function lt(n,e){return e&&n.value.startsWith("*")&&/^[a-zA-Z-]/.test(n.value.slice(1))&&e.push(`Converted '${n.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:n.value,selector:n.value,selectorType:n.selectorKind}}function ut(n){return{type:"contextReference",contextType:n.value,name:n.value}}function dt(n,e){return{type:"propertyAccess",object:N(n.object,e),property:n.property}}function pt(n){let e=Ee(n.raw);return!e.success||!e.node?{type:"identifier",name:n.raw}:e.node}function je(n,e){return n.roles.get(e)}function l(n,e,t){let r=je(n,e);return r?N(r,t):void 0}function f(n,e=[],t,r={}){let o={type:"command",name:n,args:e};return t&&Object.keys(t).length>0&&(o.modifiers=t),r.isBlocking&&(o.isBlocking=r.isBlocking),r.implicitTarget&&(o.implicitTarget=r.implicitTarget),o}var mt={action:"toggle",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=l(n,"duration"),i=t?[t]:[],a={};return r&&(a.on=r),o&&(a.for=o),f("toggle",i,a)}},ft={action:"add",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=t?[t]:[],i={};return r&&(i.to=r),f("add",o,i)}},gt={action:"remove",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),o=t?[t]:[],i={};return r&&(i.from=r),f("remove",o,i)}},ht={action:"set",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=[],i={};return t&&o.push(t),r&&(i.to=r),f("set",o,i)}},yt={action:"show",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=l(n,"duration"),i=[],a={},s=t??r;return s&&i.push(s),o&&(a.with=o),f("show",i,a)}},xt={action:"hide",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=l(n,"duration"),i=[],a={},s=t??r;return s&&i.push(s),o&&(a.with=o),f("hide",i,a)}},St={action:"increment",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=l(n,"quantity"),i=[],a={},s=t??r;return s&&i.push(s),o&&(a.by=o),f("increment",i,a)}},Et={action:"decrement",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=l(n,"quantity"),i=[],a={},s=t??r;return s&&i.push(s),o&&(a.by=o),f("decrement",i,a)}},vt={action:"wait",toAST(n,e){let t=l(n,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Tt={action:"log",toAST(n,e){let t=l(n,"patient"),r=[];return t&&r.push(t),f("log",r)}},bt={action:"put",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=je(n,"method"),i=t?[t]:[],a={};if(r){let s=o?.type==="literal"?String(o.value):"into";a[s]=r}return f("put",i,a)}},Nt={action:"fetch",toAST(n,e){let t=l(n,"source"),r=l(n,"method"),o=l(n,"responseType"),i=l(n,"patient"),a=t?[t]:[],s={};return r&&(s.with=r),o&&(s.as=o),i&&(s.body=i),f("fetch",a,s,{isBlocking:!0})}},kt={action:"append",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=t?[t]:[],i={};return r&&(i.to=r),f("append",o,i)}},Ct={action:"prepend",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=t?[t]:[],i={};return r&&(i.to=r),f("prepend",o,i)}},wt={action:"trigger",toAST(n,e){let t=l(n,"event"),r=l(n,"destination"),o=t?[t]:[],i={};return r&&(i.on=r),f("trigger",o,i)}},Rt={action:"send",toAST(n,e){let t=l(n,"event"),r=l(n,"destination"),o=l(n,"patient"),i=t?[t]:[],a={};return r&&(a.to=r),o&&(a.detail=o),f("send",i,a)}},Lt={action:"go",toAST(n,e){let t=l(n,"source"),r=l(n,"destination"),o=[],i={};return t&&o.push(t),r&&(i.to=r),f("go",o,i)}},Pt={action:"transition",toAST(n,e){let t=l(n,"patient"),r=l(n,"goal"),o=l(n,"duration"),i=l(n,"destination"),a=t?[t]:[],s={};return r&&(s.to=r),o&&(s.over=o),i&&(s.on=i),f("transition",a,s)}},Mt={action:"focus",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=[],i={},a=t??r;return a&&o.push(a),f("focus",o,i)}},At={action:"blur",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=[],i=t??r;return i&&o.push(i),f("blur",o)}},Vt={action:"get",toAST(n,e){let t=l(n,"source"),r=l(n,"patient"),o=[],i=t??r;return i&&o.push(i),f("get",o)}},zt={action:"take",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),o=t?[t]:[],i={};return r&&(i.from=r),f("take",o,i)}},Ot={action:"call",toAST(n,e){let t=l(n,"patient");return f("call",t?[t]:[])}},It={action:"return",toAST(n,e){let t=l(n,"patient");return f("return",t?[t]:[])}},_t={action:"halt",toAST(n,e){return f("halt",[])}},Bt={action:"throw",toAST(n,e){let t=l(n,"patient");return f("throw",t?[t]:[])}},Kt={action:"settle",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=[],i=t??r;return i&&o.push(i),f("settle",o,void 0,{isBlocking:!0})}},$t={action:"swap",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),o=l(n,"destination"),i=l(n,"style"),a=[],s={};return t&&a.push(t),r&&a.push(r),o&&(s.on=o),i&&(s.with=i),f("swap",a,s)}},Wt={action:"morph",toAST(n,e){let t=l(n,"source"),r=l(n,"destination"),o=l(n,"patient"),i=[],a={},s=t??o;return s&&i.push(s),r&&(a.on=r),f("morph",i,a)}},jt={action:"clone",toAST(n,e){let t=l(n,"source"),r=l(n,"destination"),o=l(n,"patient"),i=[],a={},s=t??o;return s&&i.push(s),r&&(a.into=r),f("clone",i,a)}},Ut={action:"make",toAST(n,e){let t=l(n,"patient");return f("make",t?[t]:[])}},Dt={action:"measure",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=l(n,"source"),i=[],a={};t&&i.push(t);let s=r??o;return s&&(a.of=s),f("measure",i,a)}},Ft={action:"tell",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),o=[],i=t??r;return i&&o.push(i),f("tell",o)}},qt={action:"js",toAST(n,e){let t=l(n,"patient");return f("js",t?[t]:[])}},Ht={action:"async",toAST(n,e){return f("async",[])}},Gt={action:"if",toAST(n,e){let t=l(n,"condition");return f("if",t?[t]:[])}},Xt={action:"unless",toAST(n,e){let t=l(n,"condition");return f("unless",t?[t]:[])}},Zt={action:"repeat",toAST(n,e){let t=l(n,"quantity"),r=l(n,"patient"),o=[],i=t??r;return i&&o.push(i),f("repeat",o)}},Qt={action:"for",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),o=t?[t]:[],i={};return r&&(i.in=r),f("for",o,i)}},Yt={action:"while",toAST(n,e){let t=l(n,"condition");return f("while",t?[t]:[])}},Jt={action:"continue",toAST(n,e){return f("continue",[])}},er={action:"default",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),o=t?[t]:[],i={};return r&&(i.to=r),f("default",o,i)}},tr={action:"init",toAST(n,e){return f("init",[])}},rr={action:"behavior",toAST(n,e){let t=l(n,"patient");return f("behavior",t?[t]:[])}},nr={action:"install",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=t?[t]:[],i={};return r&&(i.on=r),f("install",o,i)}},or={action:"on",toAST(n,e){let t=l(n,"event"),r=l(n,"source"),o=t?[t]:[],i={};return r&&(i.from=r),f("on",o,i)}},Ue=new Map([["toggle",mt],["add",ft],["remove",gt],["set",ht],["show",yt],["hide",xt],["increment",St],["decrement",Et],["wait",vt],["log",Tt],["put",bt],["fetch",Nt],["append",kt],["prepend",Ct],["get",Vt],["take",zt],["trigger",wt],["send",Rt],["on",or],["go",Lt],["transition",Pt],["focus",Mt],["blur",At],["call",Ot],["return",It],["halt",_t],["throw",Bt],["settle",Kt],["swap",$t],["morph",Wt],["clone",jt],["measure",Dt],["make",Ut],["tell",Ft],["default",er],["js",qt],["async",Ht],["if",Gt],["unless",Xt],["repeat",Zt],["for",Qt],["while",Yt],["continue",Jt],["init",tr],["behavior",rr],["install",nr]]);function Z(n){return Ue.get(n)}function ve(n){Ue.set(n.action,n)}var Q=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=Z(e.action);if(t){let r=t.toAST(e,this);if("ast"in r&&"warnings"in r){let o=r;return this.warnings.push(...o.warnings),o.ast}else return r}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],r={},o=["patient","source","quantity"],i=["destination","duration","method","style"];for(let s of o){let u=e.roles.get(s);u&&t.push(N(u))}for(let s of i){let u=e.roles.get(s);if(u){let c=this.roleToModifierKey(s);r[c]=N(u)}}let a={type:"command",name:e.action,args:t};return Object.keys(r).length>0?{...a,modifiers:r}:a}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),r,o;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(o=g.split(/\s+or\s+|\|/).map(E=>E.trim()),r=o[0]):r=g}else t?.type==="reference"?r=t.value:r="click";let i=e.body.map(g=>this.build(g)),a=e.roles.get("source"),s,u;a?.type==="selector"?(s=a.value,u=a.value):a?.type==="reference"?u=a.value:a?.type==="literal"&&(u=String(a.value));let c=e.roles.get("condition"),m=c?N(c):void 0,x=e.roles.get("destination"),y=x?N(x):void 0,h=e.eventModifiers,d=s;if(h?.from){let g=h.from;g.type==="selector"&&!s&&(d=g.value)}let p=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:r,commands:i,...o&&o.length>1?{events:o}:{},...d?{selector:d}:{},...u?{target:u}:{},...m?{condition:m}:{},...y?{watchTarget:y}:{},...p&&p.length>0?{args:p,params:p}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let r=N(t),o=e.thenBranch.map(s=>this.build(s)),i=e.elseBranch?.map(s=>this.build(s)),a=[r,{type:"block",commands:o}];return i&&i.length>0&&a.push({type:"block",commands:i}),{type:"command",name:"if",args:a}}buildCompound(e){let t=e.statements.map(o=>this.build(o));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(o=>this.build(o)),r=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let o=e.roles.get("quantity");o&&r.push(N(o));break}case"for":{e.loopVariable&&r.push({type:"string",value:e.loopVariable});let o=e.roles.get("source");o&&r.push(N(o));break}case"while":case"until":{let o=e.roles.get("condition");o&&r.push(N(o));break}case"forever":break}return r.push({type:"block",commands:t}),{type:"command",name:"repeat",args:r}}buildBlock(e){return{type:"block",commands:e.map(r=>this.build(r))}}};function De(n){let e=new Q;return{ast:e.build(n),warnings:e.warnings}}var O=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let r=this.makeKey(e,t),o=this.cache.get(r);if(!o){this.stats.misses++;return}if(this.isExpired(o)){this.cache.delete(r),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(r),o.lastAccessed=Date.now(),this.cache.set(r,o),this.stats.hits++,o.result}set(e,t,r){if(!this.config.enabled||r.confidence===0)return;let o=this.makeKey(e,t),i=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(o,{result:r,createdAt:i,lastAccessed:i})}has(e,t){if(!this.config.enabled)return!1;let r=this.makeKey(e,t),o=this.cache.get(r);return o?this.isExpired(o)?(this.cache.delete(r),this.stats.expirations++,!1):!0:!1}delete(e,t){let r=this.makeKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Te=new O;var Y=class{constructor(e={}){this.patternMatcher=new H,this.languages=new Set(I()),e.cache===!1?this.cache=new O({enabled:!1}):this.cache=e.cache?new O(e.cache):Te}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let r=this.cache.get(e,t);if(r)return r;let o=this.analyzeUncached(e,t);return this.cache.set(e,t,o),o}analyzeUncached(e,t){try{let r=Be(t);if(!r)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let o=r.tokenize(e),i=k(t);if(i.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let a=this.patternMatcher.matchBest(o,i);if(!a)return{confidence:0,errors:["No pattern matched the input"]};let s=this.buildSemanticNode(a);return{confidence:a.confidence,command:{name:a.pattern.command,roles:a.captured},node:s,tokensConsumed:a.consumedTokens}}catch(r){return{confidence:0,errors:[r instanceof Error?r.message:String(r)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function Fe(n){return new Y(n)}var be=.5,qe=.8;function He(n,e=be){return n.confidence>=e&&n.command!==void 0}var ir="1.0.0-core";function ar(n,e){if(!_(e))throw new Error(`Language '${e}' is not loaded. Load it via script tag or loadLanguageFromUrl().`);return[...re(n,e).tokens]}async function sr(n,e){try{let t=await fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);let r=await t.text(),o=document.createElement("script");return o.textContent=r,document.head.appendChild(o),document.head.removeChild(o),_(n)?{loaded:!0}:{loaded:!1,error:`Script loaded but language '${n}' was not registered`}}catch(t){return{loaded:!1,error:t instanceof Error?t.message:String(t)}}}function cr(n,e){ee(n,e.tokenizer,e.profile),e.patterns?D(n,e.patterns):e.buildPatterns&&D(n,e.buildPatterns())}return Je(lr);})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var LokaScriptSemanticDe=(()=>{var de=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var et=(n,e)=>{for(var t in e)de(n,t,{get:e[t],enumerable:!0})},tt=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ye(e))!Je.call(n,i)&&i!==t&&de(n,i,{get:()=>e[i],enumerable:!(r=Qe(e,i))||r.enumerable});return n};var rt=n=>tt(de({},"__esModule",{value:!0}),n);var xr={};et(xr,{ASTBuilder:()=>G,DEFAULT_CONFIDENCE_THRESHOLD:()=>we,HIGH_CONFIDENCE_THRESHOLD:()=>He,SemanticAnalyzerImpl:()=>X,VERSION:()=>mr,buildAST:()=>De,canParse:()=>Se,createCommandNode:()=>M,createEventHandler:()=>$,createLiteral:()=>S,createPropertyPath:()=>K,createReference:()=>C,createSelector:()=>L,createSemanticAnalyzer:()=>qe,fromExplicit:()=>Ee,germanProfile:()=>V,germanTokenizer:()=>ie,getCommandMapper:()=>H,getPatternsForLanguage:()=>Ze,getPatternsForLanguageAndCommand:()=>yr,getProfile:()=>me,getSupportedLanguages:()=>gr,getTokenizer:()=>pe,isExplicitSyntax:()=>W,isLanguageSupported:()=>Le,parse:()=>j,parseAny:()=>be,parseExplicit:()=>I,registerCommandMapper:()=>ke,render:()=>D,renderExplicit:()=>q,shouldUseSemanticResult:()=>Ge,toExplicit:()=>ve,tokenize:()=>hr,tryGetProfile:()=>P});var B=new Map,Y=new Map,Q=new Map;var Ce=null;function Re(n,e,t){B.set(n,e),Y.set(n,t),Q.delete(n)}var nt=new Map;function pe(n){let e=B.get(n);if(!e){let t=Array.from(B.keys()).join(", ");throw new Error(`Language '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function me(n){let e=Y.get(n);if(!e){let t=Array.from(Y.keys()).join(", ");throw new Error(`Language profile '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function Pe(n){return B.get(n)}function P(n){return Y.get(n)}function J(){return Array.from(B.keys())}function Le(n){return B.has(n)}function Me(n,e){return pe(e).tokenize(n)}function w(n){let e=Q.get(n);if(e)return e;let t=nt.get(n);if(t)return Q.set(n,t),t;if(!Ce)throw new Error(`No patterns registered for language '${n}'. Either import the language module or set a pattern generator.`);let r=me(n),i=Ce(r);return Q.set(n,i),i}function Ae(n,e){return w(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}var A=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function v(n,e){return{start:n,end:e}}function E(n,e,t,r){if(typeof r=="string")return{value:n,kind:e,position:t,normalized:r};if(r){let{normalized:i,stem:o,stemConfidence:a}=r,s={value:n,kind:e,position:t};return i!==void 0&&(s.normalized=i),o!==void 0&&(s.stem=o,a!==void 0&&(s.stemConfidence=a)),s}return{value:n,kind:e,position:t}}function z(n){return/\s/.test(n)}function te(n){return n==="#"||n==="."||n==="["||n==="@"||n==="*"||n==="<"}function re(n){return n==='"'||n==="'"||n==="`"||n==="\u300C"||n==="\u300D"}function N(n){return/\d/.test(n)}function ze(n){return/[a-zA-Z]/.test(n)}function T(n){return/[a-zA-Z0-9_-]/.test(n)}function fe(n){let e=r=>n.test(r);return{isLetter:e,isIdentifierChar:r=>e(r)||/[0-9_-]/.test(r)}}function Ve(n,e){if(e>=n.length)return null;let t=n[e];if(!te(t))return null;let r=e,i="";if(t==="#"||t==="."){for(i+=n[r++];r<n.length&&T(n[r]);)i+=n[r++];if(i.length<=1)return null;if(r<n.length&&n[r]==="."&&t==="#"){let a=r+1;for(;a<n.length&&T(n[a]);)a++;if(a<n.length&&n[a]==="(")return i}}else if(t==="["){let o=1,a=!1,s=null,u=!1;for(i+=n[r++];r<n.length&&o>0;){let c=n[r];i+=c,u?u=!1:c==="\\"?u=!0:a?c===s&&(a=!1,s=null):c==='"'||c==="'"||c==="`"?(a=!0,s=c):c==="["?o++:c==="]"&&o--,r++}if(o!==0)return null}else if(t==="@"){for(i+=n[r++];r<n.length&&T(n[r]);)i+=n[r++];if(i.length<=1)return null}else if(t==="*"){for(i+=n[r++];r<n.length&&T(n[r]);)i+=n[r++];if(i.length<=1)return null}else if(t==="<"){if(i+=n[r++],r>=n.length||!ze(n[r]))return null;for(;r<n.length&&T(n[r]);)i+=n[r++];for(;r<n.length;){let o=n[r];if(o==="."){if(i+=n[r++],r>=n.length||!T(n[r]))return null;for(;r<n.length&&T(n[r]);)i+=n[r++]}else if(o==="#"){if(i+=n[r++],r>=n.length||!T(n[r]))return null;for(;r<n.length&&T(n[r]);)i+=n[r++]}else if(o==="["){let a=1,s=!1,u=null,c=!1;for(i+=n[r++];r<n.length&&a>0;){let m=n[r];i+=m,c?c=!1:m==="\\"?c=!0:s?m===u&&(s=!1,u=null):m==='"'||m==="'"||m==="`"?(s=!0,u=m):m==="["?a++:m==="]"&&a--,r++}if(a!==0)return null}else break}for(;r<n.length&&z(n[r]);)i+=n[r++];if(r<n.length&&n[r]==="/")for(i+=n[r++];r<n.length&&z(n[r]);)i+=n[r++];if(r>=n.length||n[r]!==">")return null;i+=n[r++]}return i||null}function it(n,e){if(e>=n.length||n[e]!=="'"||e+1>=n.length||n[e+1].toLowerCase()!=="s")return!1;if(e+2>=n.length)return!0;let r=n[e+2];return z(r)||r==="*"||!T(r)}function Oe(n,e){if(e>=n.length)return null;let t=n[e];if(!re(t)||t==="'"&&it(n,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,a=t,s=!1;for(;o<n.length;){let u=n[o];if(a+=u,s)s=!1;else if(u==="\\")s=!0;else if(u===i)return a;o++}return a}function ne(n,e){if(e>=n.length)return!1;let t=n[e],r=n[e+1]||"",i=n[e+2]||"";if(t==="/"&&r!=="/"&&/[a-zA-Z0-9._-]/.test(r)||t==="/"&&r==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(r==="/"||r==="."&&i==="/"))return!0;let o=n.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function Ie(n,e){if(!ne(n,e))return null;let t=e,r="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<n.length;){let o=n[t];if(o==="#"){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=o,t++;t<n.length&&/[a-zA-Z0-9_-]/.test(n[t]);)r+=n[t++];break}if(i.test(o))r+=o,t++;else break}return r.length<2?null:r}function _e(n,e){if(e>=n.length)return null;let t=n[e];if(!N(t)&&t!=="-"&&t!=="+")return null;let r=e,i="";if((n[r]==="-"||n[r]==="+")&&(i+=n[r++]),r>=n.length||!N(n[r]))return null;for(;r<n.length&&N(n[r]);)i+=n[r++];if(r<n.length&&n[r]===".")for(i+=n[r++];r<n.length&&N(n[r]);)i+=n[r++];return r<n.length&&(n.slice(r,r+2)==="ms"?i+="ms":(n[r]==="s"||n[r]==="m"||n[r]==="h")&&(i+=n[r])),i}var ee=class ee{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let r=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(r.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let a of o.alternatives)r.set(a,{native:a,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))r.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&r.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let a of o.alternatives)r.set(a,{native:a,normalized:i})}for(let i of t)r.set(i.native,i);this.profileKeywords=Array.from(r.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let r of this.profileKeywords)if(e.slice(t).startsWith(r.native))return E(r.native,"keyword",v(t,t+r.native.length),r.normalized);return null}isKeywordStart(e,t){let r=e.slice(t);return this.profileKeywords.some(i=>r.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,r){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let a={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return E(e,"keyword",v(t,r),a)}trySelector(e,t){let r=Ve(e,t);return r?E(r,"selector",v(t,t+r.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let r=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!r)return null;let i=r[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],a=r[1];return{...E(i,"event-modifier",v(t,t+i.length)),metadata:{modifierName:o,value:a?o==="queue"?a:parseInt(a,10):void 0}}}tryString(e,t){let r=Oe(e,t);return r?E(r,"literal",v(t,t+r.length)):null}tryNumber(e,t){let r=_e(e,t);return r?E(r,"literal",v(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,i=!1){let o=t;if(i)for(;o<e.length&&z(e[o]);)o++;let a=e.slice(o);for(let s of r){let u=a.slice(0,s.length);if(s.caseInsensitive?u.toLowerCase()===s.pattern.toLowerCase():u===s.pattern){if(s.notFollowedBy&&(a[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let m=a[s.length]||"";if(T(m))continue}return{suffix:s.suffix,endPos:o+s.length}}}return null}parseBaseNumber(e,t,r=!0){let i=t,o="";if(r&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!N(e[i]))return null;for(;i<e.length&&N(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&N(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,r,i={}){let{allowSign:o=!0,skipWhitespace:a=!1}=i,s=this.parseBaseNumber(e,t,o);if(!s)return null;let{number:u,endPos:c}=s,m=[...r,...ee.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,c,m,a);return x&&(u+=x.suffix,c=x.endPos),E(u,"literal",v(t,c))}tryUrl(e,t){let r=Ie(e,t);return r?E(r,"url",v(t,t+r.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!T(e[t+1]))return null;let r=t+1;for(;r<e.length&&T(e[r]);)r++;let i=e.slice(t,r);return E(i,"identifier",v(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return E(r,"operator",v(t,t+2));let i=e[t];return["<",">","!","+","-","*","/","="].includes(i)?E(i,"operator",v(t,t+1)):["(",")","{","}",",",";",":"].includes(i)?E(i,"punctuation",v(t,t+1)):null}tryMultiCharParticle(e,t,r){for(let i of r)if(e.slice(t,t+i.length)===i)return E(i,"particle",v(t,t+i.length));return null}};ee.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var U=ee;var V={code:"de",name:"German",nativeName:"Deutsch",direction:"ltr",wordOrder:"SVO",markingStrategy:"preposition",usesSpaces:!0,defaultVerbForm:"infinitive",verb:{position:"start",subjectDrop:!1},references:{me:"ich",it:"es",you:"du",result:"Ergebnis",event:"Ereignis",target:"Ziel",body:"K\xF6rper"},possessive:{marker:"",markerPosition:"before-property",usePossessiveAdjectives:!0,specialForms:{me:"mein",it:"sein",you:"dein"},keywords:{mein:"me",meine:"me",meinen:"me",dein:"you",deine:"you",deinen:"you",sein:"it",seine:"it",seinen:"it"}},roleMarkers:{destination:{primary:"auf",alternatives:["zu","in"],position:"before"},source:{primary:"von",alternatives:["aus"],position:"before"},patient:{primary:"",position:"before"},style:{primary:"mit",position:"before"}},keywords:{toggle:{primary:"umschalten",alternatives:["wechseln"],normalized:"toggle"},add:{primary:"hinzuf\xFCgen",normalized:"add"},remove:{primary:"entfernen",alternatives:["l\xF6schen"],normalized:"remove"},put:{primary:"setzen",alternatives:["stellen","platzieren"],normalized:"put"},append:{primary:"anh\xE4ngen",normalized:"append"},prepend:{primary:"voranstellen",normalized:"prepend"},take:{primary:"nehmen",normalized:"take"},make:{primary:"machen",alternatives:["erstellen","erzeugen"],normalized:"make"},clone:{primary:"klonen",alternatives:["kopieren"],normalized:"clone"},swap:{primary:"austauschen",alternatives:["tauschen","wechseln"],normalized:"swap"},morph:{primary:"verwandeln",alternatives:["transformieren"],normalized:"morph"},set:{primary:"festlegen",alternatives:["definieren"],normalized:"set"},get:{primary:"holen",alternatives:["bekommen"],normalized:"get"},increment:{primary:"erh\xF6hen",normalized:"increment"},decrement:{primary:"verringern",alternatives:["vermindern"],normalized:"decrement"},log:{primary:"protokollieren",alternatives:["ausgeben"],normalized:"log"},show:{primary:"zeigen",alternatives:["anzeigen"],normalized:"show"},hide:{primary:"verbergen",alternatives:["verstecken"],normalized:"hide"},transition:{primary:"\xFCbergang",alternatives:["animieren"],normalized:"transition"},on:{primary:"bei",alternatives:["wenn","auf"],normalized:"on"},trigger:{primary:"ausl\xF6sen",normalized:"trigger"},send:{primary:"senden",alternatives:["schicken"],normalized:"send"},focus:{primary:"fokussieren",normalized:"focus"},blur:{primary:"defokussieren",alternatives:["entfokussieren"],normalized:"blur"},go:{primary:"gehen",alternatives:["navigieren"],normalized:"go"},wait:{primary:"warten",normalized:"wait"},fetch:{primary:"abrufen",alternatives:["laden"],normalized:"fetch"},settle:{primary:"stabilisieren",normalized:"settle"},if:{primary:"wenn",alternatives:["falls"],normalized:"if"},when:{primary:"wenn",normalized:"when"},where:{primary:"wo",normalized:"where"},else:{primary:"sonst",alternatives:["ansonsten"],normalized:"else"},repeat:{primary:"wiederholen",normalized:"repeat"},for:{primary:"f\xFCr",normalized:"for"},while:{primary:"solange",alternatives:["w\xE4hrend"],normalized:"while"},continue:{primary:"fortfahren",alternatives:["weiter"],normalized:"continue"},halt:{primary:"anhalten",alternatives:["stoppen"],normalized:"halt"},throw:{primary:"werfen",normalized:"throw"},call:{primary:"aufrufen",normalized:"call"},return:{primary:"zur\xFCckgeben",normalized:"return"},then:{primary:"dann",alternatives:["danach","anschlie\xDFend"],normalized:"then"},and:{primary:"und",alternatives:["sowie","auch"],normalized:"and"},end:{primary:"ende",alternatives:["beenden","fertig"],normalized:"end"},js:{primary:"js",alternatives:["javascript"],normalized:"js"},async:{primary:"asynchron",normalized:"async"},tell:{primary:"sagen",normalized:"tell"},default:{primary:"standard",normalized:"default"},init:{primary:"initialisieren",normalized:"init"},behavior:{primary:"verhalten",normalized:"behavior"},install:{primary:"installieren",normalized:"install"},measure:{primary:"messen",normalized:"measure"},into:{primary:"hinein",normalized:"into"},before:{primary:"vor",normalized:"before"},after:{primary:"nach",normalized:"after"},until:{primary:"bis",normalized:"until"},event:{primary:"Ereignis",alternatives:["Event"],normalized:"event"},from:{primary:"von",alternatives:["aus"],normalized:"from"}},eventHandler:{keyword:{primary:"bei",alternatives:["auf"]},sourceMarker:{primary:"von",alternatives:["aus"],position:"before"},conditionalKeyword:{primary:"wenn",alternatives:["falls"]}}};var{isLetter:ot,isIdentifierChar:at}=fe(/[a-zA-ZäöüÄÖÜß]/),Be=new Set(["an","auf","aus","bei","durch","f\xFCr","fur","gegen","in","mit","nach","ohne","seit","\xFCber","uber","um","unter","von","vor","zu","zwischen","bis","gegen\xFCber","gegenuber","w\xE4hrend","wahrend","wegen","trotz","statt","innerhalb","au\xDFerhalb","ausserhalb"]),st=[{native:"wahr",normalized:"true"},{native:"falsch",normalized:"false"},{native:"null",normalized:"null"},{native:"undefiniert",normalized:"undefined"},{native:"erste",normalized:"first"},{native:"erster",normalized:"first"},{native:"erstes",normalized:"first"},{native:"letzte",normalized:"last"},{native:"letzter",normalized:"last"},{native:"letztes",normalized:"last"},{native:"n\xE4chste",normalized:"next"},{native:"nachste",normalized:"next"},{native:"vorherige",normalized:"previous"},{native:"n\xE4chste",normalized:"closest"},{native:"eltern",normalized:"parent"},{native:"klick",normalized:"click"},{native:"click",normalized:"click"},{native:"eingabe",normalized:"input"},{native:"\xE4nderung",normalized:"change"},{native:"anderung",normalized:"change"},{native:"absenden",normalized:"submit"},{native:"taste unten",normalized:"keydown"},{native:"taste oben",normalized:"keyup"},{native:"maus dr\xFCber",normalized:"mouseover"},{native:"maus druber",normalized:"mouseover"},{native:"maus weg",normalized:"mouseout"},{native:"fokus",normalized:"focus"},{native:"unsch\xE4rfe",normalized:"blur"},{native:"unscharfe",normalized:"blur"},{native:"scrollen",normalized:"scroll"},{native:"meine",normalized:"my"},{native:"meinen",normalized:"my"},{native:"ergebnis",normalized:"result"},{native:"ziel",normalized:"target"},{native:"sekunde",normalized:"s"},{native:"sekunden",normalized:"s"},{native:"millisekunde",normalized:"ms"},{native:"millisekunden",normalized:"ms"},{native:"minute",normalized:"m"},{native:"minuten",normalized:"m"},{native:"stunde",normalized:"h"},{native:"stunden",normalized:"h"},{native:"hinzufugen",normalized:"add"},{native:"hinzufgen",normalized:"add"},{native:"loschen",normalized:"remove"},{native:"anhangen",normalized:"append"},{native:"erhohen",normalized:"increment"},{native:"ubergang",normalized:"transition"},{native:"auslosen",normalized:"trigger"},{native:"zuruckgeben",normalized:"return"},{native:"anschliessend",normalized:"then"},{native:"erh\xF6he",normalized:"increment"},{native:"erhohe",normalized:"increment"},{native:"verringere",normalized:"decrement"}],ct=[{pattern:"millisekunden",suffix:"ms",length:13,caseInsensitive:!0},{pattern:"millisekunde",suffix:"ms",length:12,caseInsensitive:!0},{pattern:"sekunden",suffix:"s",length:8,caseInsensitive:!0},{pattern:"sekunde",suffix:"s",length:7,caseInsensitive:!0},{pattern:"minuten",suffix:"m",length:7,caseInsensitive:!0},{pattern:"minute",suffix:"m",length:6,caseInsensitive:!0},{pattern:"stunden",suffix:"h",length:7,caseInsensitive:!0},{pattern:"stunde",suffix:"h",length:6,caseInsensitive:!0}],ge=class extends U{constructor(){super();this.language="de";this.direction="ltr";this.initializeKeywordsFromProfile(V,st)}tokenize(t){let r=[],i=0;for(;i<t.length;){if(z(t[i])){i++;continue}if(te(t[i])){let s=this.tryEventModifier(t,i);if(s){r.push(s),i=s.position.end;continue}let u=this.trySelector(t,i);if(u){r.push(u),i=u.position.end;continue}}if(re(t[i])){let s=this.tryString(t,i);if(s){r.push(s),i=s.position.end;continue}}if(ne(t,i)){let s=this.tryUrl(t,i);if(s){r.push(s),i=s.position.end;continue}}if(N(t[i])||t[i]==="-"&&i+1<t.length&&N(t[i+1])){let s=this.extractNumber(t,i);if(s){r.push(s),i=s.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){r.push(o),i=o.position.end;continue}if(ot(t[i])){let s=this.extractWord(t,i);if(s){r.push(s),i=s.position.end;continue}}let a=this.tryOperator(t,i);if(a){r.push(a),i=a.position.end;continue}i++}return new A(r,"de")}classifyToken(t){let r=t.toLowerCase();return Be.has(r)?"particle":this.isKeyword(r)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||/^\d/.test(t)?"literal":"identifier"}extractWord(t,r){let i=r,o="";for(;i<t.length&&at(t[i]);)o+=t[i++];if(!o)return null;let a=o.toLowerCase(),s=this.lookupKeyword(a);return s?E(o,"keyword",v(r,i),s.normalized):Be.has(a)?E(o,"particle",v(r,i)):E(o,"identifier",v(r,i))}extractNumber(t,r){return this.tryNumberWithTimeUnits(t,r,ct,{allowSign:!0,skipWhitespace:!0})}},ie=new ge;Re("de",ie,V);function Ke(n){return Pe(n)}function oe(n,e){return Me(n,e)}function ae(){return J()}function L(n){let e="complex";return n.startsWith("#")&&!n.includes(" ")?e="id":n.startsWith(".")&&!n.includes(" ")?e="class":n.startsWith("[")&&n.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(n)&&(e="element"),{type:"selector",value:n,selectorKind:e}}function S(n,e){let t={type:"literal",value:n};return e!==void 0?{type:"literal",value:n,dataType:e}:t}function C(n){return{type:"reference",value:n}}function K(n,e){return{type:"property-path",object:n,property:e}}function M(n,e,t){let r={kind:"command",action:n,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function $(n,e,t,r,i){let o=new Map;o.set("event",n);let a={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(a.eventModifiers=t),r!==void 0&&(a.metadata=r),i!==void 0&&i.length>0&&(a.parameterNames=i),a}function $e(n,e="then",t){let r={kind:"compound",action:"compound",roles:new Map,statements:n,chainType:e};return t!==void 0&&(r.metadata=t),r}function he(n,e){return!e||e.length===0||e.includes(n)||e.includes("expression")?!0:n==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function We(n,e){return n.possessive?.keywords?.[e]}var R=class R{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let r=e.mark(),i=new Map;if(this.currentProfile=P(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(r),null;let a=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-r.position,confidence:a}}matchBest(e,t){let r=[];for(let o of t){let a=e.mark(),s=this.matchPattern(e,o);s&&r.push(s),e.reset(a)}if(r.length===0)return null;r.sort((o,a)=>{let s=a.pattern.priority-o.pattern.priority;return s!==0?s:a.confidence-o.confidence});let i=r[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,r){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let i of t)if(!this.matchPatternToken(e,i,r)){if(this.isOptional(i))continue;return!1}return!0}matchPatternToken(e,t,r){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r);case"group":return this.matchGroupToken(e,t,r);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(!r)return!1;let i=this.getMatchType(r,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let a=this.getMatchType(r,o);if(a!=="none")return this.totalKeywordMatches++,a==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,r){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,o),!0);let a=this.tryMatchMethodCallExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(a.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,a),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!he(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);let u=this.tryMatchPropertyAccessExpression(e);if(u)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(u.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,u),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!he(c.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,c),!0);let m=this.tokenToSemanticValue(i);return!m||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(m.type)?t.optional||!1:(r.set(t.role,m),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=(t.normalized||t.value).toLowerCase(),i=We(this.currentProfile,r);if(!i)return null;let o=e.mark();e.advance();let a=e.peek();return a&&(a.kind==="identifier"||a.kind==="keyword"&&!this.isStructuralKeyword(a.value)||a.kind==="selector"&&a.value.startsWith("*"))?(e.advance(),K(C(i),a.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(r),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="punctuation"||a.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<R.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(r),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(r),null;e.advance();let a=`${t.value}.${o.value}`,s=1;for(;!e.isAtEnd()&&s<R.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let m=e.peek();if(!m||m.kind!=="identifier")break;e.advance(),a+=`.${m.value}`,s++}let u=e.peek();if(u&&u.kind==="punctuation"&&u.value==="("){e.advance();let c=[],m=0;for(;!e.isAtEnd()&&c.length<R.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(m===0){e.advance();break}m--}if(y.kind==="punctuation"&&y.value==="("&&m++,y.kind==="punctuation"&&y.value===","){e.advance();continue}c.push(y.value),e.advance()}return{type:"expression",raw:`${a}(${c.join(", ")})`}}return{type:"expression",raw:a}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(r),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(r),null):(e.advance(),K(L(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(r),null;let o=e.peek(1);o&&o.kind,e.advance();let a=i.value.slice(1);return K(L(t.value),a)}matchGroupToken(e,t,r){let i=e.mark(),o=new Set(r.keys());if(!this.matchTokenSequence(e,t.tokens,r)){e.reset(i);for(let s of r.keys())o.has(s)||r.delete(s);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return L(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?C(t):S(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return C(e.value);let r=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(r)?C(r):{type:"expression",raw:e.value};case"url":return S(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let i=e.slice(1,-1);return S(i,"string")}if(e==="true")return S(!0,"boolean");if(e==="false")return S(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let i=parseFloat(t[1]);return t[2]?S(e,"duration"):S(i,"number")}let r=parseFloat(e);return isNaN(r)?S(e,"string"):S(r,"number")}applyExtractionRules(e,t){for(let[r,i]of Object.entries(e.extraction))!t.has(r)&&i.default&&t.set(r,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let r=0,i=0,o=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")i+=1,t.has(c.role)&&(r+=1);else if(c.type==="group"){for(let m of c.tokens)if(m.type==="role"){let x=o(m.role),y=.8;i+=y,t.has(m.role)?r+=y:x&&(r+=y*.6)}}let a=i>0?r/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let c=this.stemMatchCount/this.totalKeywordMatches*.15;a=Math.max(.5,a-c)}let s=this.calculateVSOConfidenceBoost(e);a=Math.min(1,a+s);let u=this.arabicPrepositionDisambiguation(e,t);return a=Math.max(0,Math.min(1,a+u)),a}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let r=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(r.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(r.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let r=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,a]of t.entries()){let s=i[o];if(!s||s.length===0)continue;let u=a.metadata;if(u&&typeof u.prepositionValue=="string"){let c=u.prepositionValue;s.includes(c)?r+=.1:r-=.1}}return Math.max(-.1,Math.min(.1,r))}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=t.value.toLowerCase();if(R.ENGLISH_NOISE_WORDS.has(r)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(r=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return r?t:void 0}};R.MAX_PROPERTY_DEPTH=10,R.MAX_METHOD_ARGS=20,R.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var F=R,O=new F;var se=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let r=Ae(t,e.action);if(r.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,r);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let r=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return r.join(` ${i} `)}getChainWord(e,t){let r=P(t);return r?.keywords?r.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let r=e;return r.statements.map(o=>this.renderExplicit(o)).join(` ${r.chainType} `)}let t=[e.action];for(let[r,i]of e.roles)t.push(`${r}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let r=e;if(r.body&&r.body.length>0){let i=r.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return ae()}findBestPattern(e,t){let r=t.map(i=>{let o=i.priority;for(let a of i.template.tokens)a.type==="role"&&(e.roles.has(a.role)?o+=10:a.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return r.sort((i,o)=>o.score-i.score),r.length>0?r[0].pattern:null}renderWithPattern(e,t){let r=[],i=t.language;for(let o of t.template.tokens){let a=this.renderPatternToken(o,e,i);a!==null&&r.push(a)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let a=o.body.map(s=>this.render(s,i));r.push(a.join(" "))}}return r.join(" ")}renderPatternToken(e,t,r){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,r):(e.optional,null)}case"group":{if(!e.tokens.filter(a=>a.type==="role"&&!a.optional).every(a=>t.roles.has(a.role))&&e.optional)return null;if(e.optional&&e.tokens.find(s=>s.type==="role"&&s.role==="destination")){let s=t.roles.get("destination");if(s?.type==="reference"&&s.value==="me")return null}let o=[];for(let a of e.tokens){let s=this.renderPatternToken(a,t,r);s!==null&&o.push(s)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let r=P(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=P(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(r?.possessive?.specialForms&&o){let s=r.possessive.specialForms[o];if(s){let{markerPosition:u,usePossessiveAdjectives:c}=r.possessive;return c&&u==="after-object"?`${i} ${s}`:`${s} ${i}`}}let a=this.valueToNaturalString(e.object,t);if(r?.possessive){let{marker:s,markerPosition:u,usePossessiveAdjectives:c}=r.possessive;if(c&&o&&u==="after-object")return`${i} ${a}`;if(s)switch(u){case"between":return r.usesSpaces?`${a}${s} ${i}`:`${a}${s}${i}`;case"after-object":return`${a}${s} ${i}`;case"before-property":return`${a} ${s} ${i}`}}return t==="en"||!r?.possessive?a==="me"?`my ${i}`:a==="it"?`its ${i}`:`${a}'s ${i}`:`${a} ${i}`}},ye=new se;function D(n,e){return ye.render(n,e)}function q(n){return ye.renderExplicit(n)}function I(n){let e=n.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let r=lt(t);if(r.length===0)throw new Error("No command specified in explicit statement");let i=r[0].toLowerCase(),o=new Map;for(let s=1;s<r.length;s++){let u=r[s],c=u.indexOf(":");if(c===-1)throw new Error(`Invalid role format: "${u}". Expected role:value`);let m=u.slice(0,c),x=u.slice(c+1);if(m==="body"&&x.startsWith("[")){let h=dt(u,c+1),d=u.slice(c+1,h+1);o.set(m,{type:"expression",raw:d});continue}let y=ut(x);o.set(m,y)}if(i==="on"){let s=o.get("event");if(!s)throw new Error("Event handler requires event role: [on event:click ...]");let u=o.get("body"),c=[];return u&&u.type==="expression"&&c.push(I(u.raw)),o.delete("body"),$(s,c,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,u]of o)a[s]=u;return M(i,a,{sourceLanguage:"explicit"})}function lt(n){let e=[],t="",r=!1,i="",o=0;for(let a=0;a<n.length;a++){let s=n[a];if(r){t+=s,s===i&&n[a-1]!=="\\"&&(r=!1);continue}if(s==='"'||s==="'"){r=!0,i=s,t+=s;continue}if(s==="["){o++,t+=s;continue}if(s==="]"){o--,t+=s;continue}if(s===" "&&o===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function ut(n){if(n.startsWith("#")||n.startsWith(".")||n.startsWith("[")||n.startsWith("@")||n.startsWith("*"))return L(n);if(n.startsWith('"')||n.startsWith("'")){let t=n.slice(1,-1);return S(t,"string")}if(n==="true")return S(!0,"boolean");if(n==="false")return S(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(n.toLowerCase()))return C(n.toLowerCase());let e=n.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?S(n,"duration"):S(t,"number")}return S(n,"string")}function dt(n,e){let t=0;for(let r=e;r<n.length;r++)if(n[r]==="[")t++;else if(n[r]==="]"&&(t--,t===0))return r;return n.length-1}function W(n){let e=n.trim();return e.startsWith("[")&&e.endsWith("]")}var ce=class{parse(e,t){let r=oe(e,t),i=w(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((m,x)=>x.priority-m.priority),a=o.filter(m=>m.command==="on"),s=O.matchBest(r,a);if(s)return this.buildEventHandler(s,r,t);let u=o.filter(m=>m.command!=="on"),c=O.matchBest(r,u);if(c)return this.buildCommand(c,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return ae()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let r={};for(let[i,o]of e.captured)r[i]=o;return M(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,r){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=O.extractEventModifiers(t),a,s=e.captured.get("action");if(s&&s.type==="literal"){let u=s.value,c={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(c[y]=h);let m=M(u,c,{sourceLanguage:r,patternId:e.pattern.id}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=w(r).filter(p=>p.command!=="on").sort((p,g)=>g.priority-p.priority),h=w(r).filter(p=>p.id.startsWith("grammar-")&&p.id.includes("-continuation")).sort((p,g)=>g.priority-p.priority),d=this.parseBodyWithGrammarPatterns(t,y,h,r);d.length>0?a=[m,...d]:a=[m]}else a=[m]}else{let u=w(r).filter(c=>c.command!=="on").sort((c,m)=>m.priority-c.priority);a=this.parseBodyWithClauses(t,u,r)}return $(i,a,o,{sourceLanguage:r,patternId:e.pattern.id})}parseBodyWithClauses(e,t,r){let i=[],o=[];for(;!e.isAtEnd();){let a=e.peek();if(!a)break;let s=a.kind==="conjunction"||a.kind==="keyword"&&this.isThenKeyword(a.value,r),u=a.kind==="keyword"&&this.isEndKeyword(a.value,r);if(s){if(o.length>0){let c=this.parseClause(o,t,r);i.push(...c),o.length=0}e.advance();continue}if(u){if(o.length>0){let c=this.parseClause(o,t,r);i.push(...c)}e.advance();break}o.push(a),e.advance()}if(o.length>0){let a=this.parseClause(o,t,r);i.push(...a)}return i.length>1?[$e(i,"then",{sourceLanguage:r})]:i}parseClause(e,t,r){if(e.length===0)return[];let i=new A(e,r),o=[];for(;!i.isAtEnd();){let a=O.matchBest(i,t);a?o.push(this.buildCommand(a,r)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,r,i){let o=[];for(;!e.isAtEnd();){let a=e.peek();if(a&&this.isThenKeyword(a.value,i)){e.advance();continue}if(a&&this.isEndKeyword(a.value,i)){e.advance();break}let s=!1;if(r.length>0){let u=O.matchBest(e,r);if(u){let c=u.pattern.command,m={};for(let[h,d]of u.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(m[h]=d);let x=M(c,m,{sourceLanguage:i,patternId:u.pattern.id});o.push(x),s=!0;let y=u.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!s){let u=O.matchBest(e,t);u&&(o.push(this.buildCommand(u,i)),s=!0)}s||e.advance()}return o}isThenKeyword(e,t){let r={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(r[t]||r.en).has(e.toLowerCase())}isEndKeyword(e,t){let r={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(r[t]||r.en).has(e.toLowerCase())}},xe=new ce;function j(n,e){return xe.parse(n,e)}function Se(n,e){return xe.canParse(n,e)}function ve(n,e){if(W(n))return n;let t=j(n,e);return q(t)}function Ee(n,e){let t=I(n);return D(t,e)}function be(n,e){return W(n)?I(n):j(n,e)}var pt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),mt=new Set(["and","or","not","no"]),ft=new Set(["true","false","null","undefined"]),gt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function je(n){let e=[],t=0,r=1,i=1;function o(){if(e.length===0)return!0;let d=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(d.type)}function a(d=0){return n[t+d]??""}function s(){let d=n[t];return t++,d===`
|
|
2
|
+
`?(r++,i=1):i++,d}function u(){for(;t<n.length&&/\s/.test(n[t]);)s()}function c(d){let p="";for(;t<n.length&&d(n[t]);)p+=s();return p}function m(d){let p=d;for(s();t<n.length&&n[t]!==d;)n[t]==="\\"&&t+1<n.length&&(p+=s()),p+=s();return t<n.length&&(p+=s()),p}function x(){let d="`";for(s();t<n.length&&n[t]!=="`";)n[t]==="\\"&&t+1<n.length&&(d+=s()),d+=s();return t<n.length&&(d+=s()),d}function y(){let d="<";for(s();t<n.length&&(d+=s(),!d.endsWith("/>")););return d}function h(d,p,g){return{type:d,value:p,start:g,end:t,line:r,column:i-p.length}}for(;t<n.length&&(u(),!(t>=n.length));){let d=t,p=a();if(p==="'"&&a(1)==="s"&&!/\w/.test(a(2))){s(),s(),e.push(h("POSSESSIVE","'s",d));continue}if(p==='"'||p==="'"){let g=m(p);e.push(h("STRING",g,d));continue}if(p==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,d));continue}if(p==="<"&&/[a-zA-Z.#\[]/.test(a(1))){let g=y();e.push(h("QUERY_SELECTOR",g,d));continue}if(p==="#"&&o()){s();let g=c(b=>/[\w-]/.test(b));e.push(h("ID_SELECTOR","#"+g,d));continue}if(p==="."&&/[a-zA-Z_-]/.test(a(1))&&o()){s();let g=c(b=>/[\w-]/.test(b));e.push(h("CLASS_SELECTOR","."+g,d));continue}if(p==="["&&o()){let g=a(1);if(g==="@"||/[a-zA-Z]/.test(g)){let b="";for(b+=s();t<n.length&&n[t]!=="]";)n[t]==='"'||n[t]==="'"?b+=m(n[t]):b+=s();t<n.length&&(b+=s()),e.push(h("ATTRIBUTE_SELECTOR",b,d));continue}}if(p==="["){s(),e.push(h("LBRACKET","[",d));continue}if(p==="]"){s(),e.push(h("RBRACKET","]",d));continue}if(/\d/.test(p)){let g=c(ue=>/[\d.]/.test(ue)),b=t,Z=c(ue=>/[a-zA-Z]/.test(ue));gt.has(Z)?e.push(h("TIME_EXPRESSION",g+Z,d)):(t=b,e.push(h("NUMBER",g,d)));continue}if(p==="("){s(),e.push(h("LPAREN","(",d));continue}if(p===")"){s(),e.push(h("RPAREN",")",d));continue}if(p==="{"){s(),e.push(h("LBRACE","{",d));continue}if(p==="}"){s(),e.push(h("RBRACE","}",d));continue}if(p===","){s(),e.push(h("COMMA",",",d));continue}if(p===":"){s(),e.push(h("COLON",":",d));continue}if(p==="."){s(),e.push(h("DOT",".",d));continue}if(p==="+"||p==="-"||p==="*"||p==="/"||p==="%"){s(),e.push(h("OPERATOR",p,d));continue}if(p==="="||p==="!"||p==="<"||p===">"){let g=s();a()==="="&&(g+=s()),e.push(h("COMPARISON",g,d));continue}if(/[a-zA-Z_$]/.test(p)){let g=c(Z=>/[\w$]/.test(Z)),b=g.toLowerCase();pt.has(b)?e.push(h("CONTEXT_VAR",g,d)):mt.has(b)?e.push(h("LOGICAL",g,d)):ft.has(b)?e.push(h("BOOLEAN",g,d)):e.push(h("IDENTIFIER",g,d));continue}s()}return e.push(h("EOF","",t)),e}var le=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=je(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,r=this.parseAnd();e=this.createBinaryExpression(t,e,r)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,r=this.parseEquality();e=this.createBinaryExpression(t,e,r)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,r=this.parseComparison();e=this.createBinaryExpression(t,e,r)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,r=this.parseAddition();e=this.createBinaryExpression(t,e,r)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,r=this.parseMultiplication();e=this.createBinaryExpression(t,e,r)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,r=this.parseUnary();e=this.createBinaryExpression(t,e,r)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let r;if(this.check("STRING"))r=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))r=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:r,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(r=>({type:"objectProperty",key:r.key,value:r.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let r=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:r,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,r){return{type:"literal",value:e,dataType:t,raw:r.value,start:r.start,end:r.end,line:r.line,column:r.column}}createSelector(e,t,r){return{type:"selector",value:e,selector:e,selectorType:t,start:r.start,end:r.end,line:r.line,column:r.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,r){return{type:"binaryExpression",operator:e,left:t,right:r,start:t.start,end:r.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Te(n){return new le().parse(n)}function k(n,e){switch(n.type){case"literal":return ht(n);case"selector":return yt(n,e);case"reference":return xt(n);case"property-path":return St(n,e);case"expression":return vt(n);default:let t=n;throw new Error(`Unknown semantic value type: ${t.type}`)}}function ht(n){let e={type:"literal",value:n.value};return n.dataType?{...e,dataType:n.dataType}:e}function yt(n,e){return e&&n.value.startsWith("*")&&/^[a-zA-Z-]/.test(n.value.slice(1))&&e.push(`Converted '${n.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:n.value,selector:n.value,selectorType:n.selectorKind}}function xt(n){return{type:"contextReference",contextType:n.value,name:n.value}}function St(n,e){return{type:"propertyAccess",object:k(n.object,e),property:n.property}}function vt(n){let e=Te(n.raw);return!e.success||!e.node?{type:"identifier",name:n.raw}:e.node}function Ue(n,e){return n.roles.get(e)}function l(n,e,t){let r=Ue(n,e);return r?k(r,t):void 0}function f(n,e=[],t,r={}){let i={type:"command",name:n,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),r.isBlocking&&(i.isBlocking=r.isBlocking),r.implicitTarget&&(i.implicitTarget=r.implicitTarget),i}var Et={action:"toggle",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=l(n,"duration"),o=t?[t]:[],a={};return r&&(a.on=r),i&&(a.for=i),f("toggle",o,a)}},bt={action:"add",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("add",i,o)}},Tt={action:"remove",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("remove",i,o)}},kt={action:"set",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=[],o={};return t&&i.push(t),r&&(o.to=r),f("set",i,o)}},Nt={action:"show",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=l(n,"duration"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.with=i),f("show",o,a)}},wt={action:"hide",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=l(n,"duration"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.with=i),f("hide",o,a)}},Ct={action:"increment",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=l(n,"quantity"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.by=i),f("increment",o,a)}},Rt={action:"decrement",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=l(n,"quantity"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.by=i),f("decrement",o,a)}},Pt={action:"wait",toAST(n,e){let t=l(n,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Lt={action:"log",toAST(n,e){let t=l(n,"patient"),r=[];return t&&r.push(t),f("log",r)}},Mt={action:"put",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=Ue(n,"method"),o=t?[t]:[],a={};if(r){let s=i?.type==="literal"?String(i.value):"into";a[s]=r}return f("put",o,a)}},At={action:"fetch",toAST(n,e){let t=l(n,"source"),r=l(n,"method"),i=l(n,"responseType"),o=l(n,"patient"),a=t?[t]:[],s={};return r&&(s.with=r),i&&(s.as=i),o&&(s.body=o),f("fetch",a,s,{isBlocking:!0})}},zt={action:"append",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("append",i,o)}},Vt={action:"prepend",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("prepend",i,o)}},Ot={action:"trigger",toAST(n,e){let t=l(n,"event"),r=l(n,"destination"),i=t?[t]:[],o={};return r&&(o.on=r),f("trigger",i,o)}},It={action:"send",toAST(n,e){let t=l(n,"event"),r=l(n,"destination"),i=l(n,"patient"),o=t?[t]:[],a={};return r&&(a.to=r),i&&(a.detail=i),f("send",o,a)}},_t={action:"go",toAST(n,e){let t=l(n,"source"),r=l(n,"destination"),i=[],o={};return t&&i.push(t),r&&(o.to=r),f("go",i,o)}},Bt={action:"transition",toAST(n,e){let t=l(n,"patient"),r=l(n,"goal"),i=l(n,"duration"),o=l(n,"destination"),a=t?[t]:[],s={};return r&&(s.to=r),i&&(s.over=i),o&&(s.on=o),f("transition",a,s)}},Kt={action:"focus",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=[],o={},a=t??r;return a&&i.push(a),f("focus",i,o)}},$t={action:"blur",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("blur",i)}},Wt={action:"get",toAST(n,e){let t=l(n,"source"),r=l(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("get",i)}},jt={action:"take",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("take",i,o)}},Ut={action:"call",toAST(n,e){let t=l(n,"patient");return f("call",t?[t]:[])}},Ft={action:"return",toAST(n,e){let t=l(n,"patient");return f("return",t?[t]:[])}},Dt={action:"halt",toAST(n,e){return f("halt",[])}},qt={action:"throw",toAST(n,e){let t=l(n,"patient");return f("throw",t?[t]:[])}},Ht={action:"settle",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},Gt={action:"swap",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),i=l(n,"destination"),o=l(n,"style"),a=[],s={};return t&&a.push(t),r&&a.push(r),i&&(s.on=i),o&&(s.with=o),f("swap",a,s)}},Xt={action:"morph",toAST(n,e){let t=l(n,"source"),r=l(n,"destination"),i=l(n,"patient"),o=[],a={},s=t??i;return s&&o.push(s),r&&(a.on=r),f("morph",o,a)}},Zt={action:"clone",toAST(n,e){let t=l(n,"source"),r=l(n,"destination"),i=l(n,"patient"),o=[],a={},s=t??i;return s&&o.push(s),r&&(a.into=r),f("clone",o,a)}},Qt={action:"make",toAST(n,e){let t=l(n,"patient");return f("make",t?[t]:[])}},Yt={action:"measure",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=l(n,"source"),o=[],a={};t&&o.push(t);let s=r??i;return s&&(a.of=s),f("measure",o,a)}},Jt={action:"tell",toAST(n,e){let t=l(n,"destination"),r=l(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("tell",i)}},er={action:"js",toAST(n,e){let t=l(n,"patient");return f("js",t?[t]:[])}},tr={action:"async",toAST(n,e){return f("async",[])}},rr={action:"if",toAST(n,e){let t=l(n,"condition");return f("if",t?[t]:[])}},nr={action:"unless",toAST(n,e){let t=l(n,"condition");return f("unless",t?[t]:[])}},ir={action:"repeat",toAST(n,e){let t=l(n,"quantity"),r=l(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("repeat",i)}},or={action:"for",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),i=t?[t]:[],o={};return r&&(o.in=r),f("for",i,o)}},ar={action:"while",toAST(n,e){let t=l(n,"condition");return f("while",t?[t]:[])}},sr={action:"continue",toAST(n,e){return f("continue",[])}},cr={action:"default",toAST(n,e){let t=l(n,"patient"),r=l(n,"source"),i=t?[t]:[],o={};return r&&(o.to=r),f("default",i,o)}},lr={action:"init",toAST(n,e){return f("init",[])}},ur={action:"behavior",toAST(n,e){let t=l(n,"patient");return f("behavior",t?[t]:[])}},dr={action:"install",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),i=t?[t]:[],o={};return r&&(o.on=r),f("install",i,o)}},pr={action:"on",toAST(n,e){let t=l(n,"event"),r=l(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("on",i,o)}},Fe=new Map([["toggle",Et],["add",bt],["remove",Tt],["set",kt],["show",Nt],["hide",wt],["increment",Ct],["decrement",Rt],["wait",Pt],["log",Lt],["put",Mt],["fetch",At],["append",zt],["prepend",Vt],["get",Wt],["take",jt],["trigger",Ot],["send",It],["on",pr],["go",_t],["transition",Bt],["focus",Kt],["blur",$t],["call",Ut],["return",Ft],["halt",Dt],["throw",qt],["settle",Ht],["swap",Gt],["morph",Xt],["clone",Zt],["measure",Yt],["make",Qt],["tell",Jt],["default",cr],["js",er],["async",tr],["if",rr],["unless",nr],["repeat",ir],["for",or],["while",ar],["continue",sr],["init",lr],["behavior",ur],["install",dr]]);function H(n){return Fe.get(n)}function ke(n){Fe.set(n.action,n)}var G=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=H(e.action);if(t){let r=t.toAST(e,this);if("ast"in r&&"warnings"in r){let i=r;return this.warnings.push(...i.warnings),i.ast}else return r}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],r={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let s of i){let u=e.roles.get(s);u&&t.push(k(u))}for(let s of o){let u=e.roles.get(s);if(u){let c=this.roleToModifierKey(s);r[c]=k(u)}}let a={type:"command",name:e.action,args:t};return Object.keys(r).length>0?{...a,modifiers:r}:a}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),r,i;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(i=g.split(/\s+or\s+|\|/).map(b=>b.trim()),r=i[0]):r=g}else t?.type==="reference"?r=t.value:r="click";let o=e.body.map(g=>this.build(g)),a=e.roles.get("source"),s,u;a?.type==="selector"?(s=a.value,u=a.value):a?.type==="reference"?u=a.value:a?.type==="literal"&&(u=String(a.value));let c=e.roles.get("condition"),m=c?k(c):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,h=e.eventModifiers,d=s;if(h?.from){let g=h.from;g.type==="selector"&&!s&&(d=g.value)}let p=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:r,commands:o,...i&&i.length>1?{events:i}:{},...d?{selector:d}:{},...u?{target:u}:{},...m?{condition:m}:{},...y?{watchTarget:y}:{},...p&&p.length>0?{args:p,params:p}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let r=k(t),i=e.thenBranch.map(s=>this.build(s)),o=e.elseBranch?.map(s=>this.build(s)),a=[r,{type:"block",commands:i}];return o&&o.length>0&&a.push({type:"block",commands:o}),{type:"command",name:"if",args:a}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),r=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&r.push(k(i));break}case"for":{e.loopVariable&&r.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&r.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&r.push(k(i));break}case"forever":break}return r.push({type:"block",commands:t}),{type:"command",name:"repeat",args:r}}buildBlock(e){return{type:"block",commands:e.map(r=>this.build(r))}}};function De(n){let e=new G;return{ast:e.build(n),warnings:e.warnings}}var _=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let r=this.makeKey(e,t),i=this.cache.get(r);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(r),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(r),i.lastAccessed=Date.now(),this.cache.set(r,i),this.stats.hits++,i.result}set(e,t,r){if(!this.config.enabled||r.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:r,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let r=this.makeKey(e,t),i=this.cache.get(r);return i?this.isExpired(i)?(this.cache.delete(r),this.stats.expirations++,!1):!0:!1}delete(e,t){let r=this.makeKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Ne=new _;var X=class{constructor(e={}){this.patternMatcher=new F,this.languages=new Set(J()),e.cache===!1?this.cache=new _({enabled:!1}):this.cache=e.cache?new _(e.cache):Ne}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let r=this.cache.get(e,t);if(r)return r;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let r=Ke(t);if(!r)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=r.tokenize(e),o=w(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let a=this.patternMatcher.matchBest(i,o);if(!a)return{confidence:0,errors:["No pattern matched the input"]};let s=this.buildSemanticNode(a);return{confidence:a.confidence,command:{name:a.pattern.command,roles:a.captured},node:s,tokensConsumed:a.consumedTokens}}catch(r){return{confidence:0,errors:[r instanceof Error?r.message:String(r)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function qe(n){return new X(n)}var we=.5,He=.8;function Ge(n,e=we){return n.confidence>=e&&n.command!==void 0}var mr="1.0.0-de",fr=["de"];function gr(){return[...fr]}function Xe(n){if(n!=="de")throw new Error(`Language not supported in this bundle: ${n}. Supported: de`)}function hr(n,e){return Xe(e),[...oe(n,e).tokens]}function Ze(n){return Xe(n),w(n)}function yr(n,e){return Ze(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}return rt(xr);})();
|