@lokascript/semantic 1.0.0 → 1.1.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/dist/browser-ar.ar.global.js +2 -2
- package/dist/browser-core.core.global.js +2 -2
- package/dist/browser-de.de.global.js +2 -2
- package/dist/browser-east-asian.east-asian.global.js +2 -2
- package/dist/browser-en-tr.en-tr.global.js +2 -2
- package/dist/browser-en.en.global.js +2 -2
- package/dist/browser-es-en.es-en.global.js +2 -2
- package/dist/browser-es.es.global.js +2 -2
- package/dist/browser-fr.fr.global.js +2 -2
- package/dist/browser-id.id.global.js +2 -2
- package/dist/browser-ja.ja.global.js +2 -2
- package/dist/browser-ko.ko.global.js +2 -2
- package/dist/browser-lazy.lazy.global.js +2 -2
- package/dist/browser-priority.priority.global.js +2 -2
- package/dist/browser-pt.pt.global.js +2 -2
- package/dist/browser-qu.qu.global.js +2 -2
- package/dist/browser-sw.sw.global.js +2 -2
- package/dist/browser-tr.tr.global.js +2 -2
- package/dist/browser-western.western.global.js +2 -2
- package/dist/browser-zh.zh.global.js +2 -2
- package/dist/browser.global.js +2 -2
- package/dist/browser.global.js.map +1 -1
- package/dist/index.cjs +13042 -17462
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -5
- package/dist/index.d.ts +49 -5
- package/dist/index.js +14044 -18464
- package/dist/index.js.map +1 -1
- package/dist/languages/ar.d.ts +1 -1
- package/dist/languages/ar.js +31 -44
- package/dist/languages/ar.js.map +1 -1
- package/dist/languages/de.d.ts +1 -1
- package/dist/languages/de.js +14 -2
- package/dist/languages/de.js.map +1 -1
- package/dist/languages/en.d.ts +1 -1
- package/dist/languages/en.js +558 -12
- package/dist/languages/en.js.map +1 -1
- package/dist/languages/es.d.ts +1 -1
- package/dist/languages/es.js +16 -0
- package/dist/languages/es.js.map +1 -1
- package/dist/languages/fr.d.ts +1 -1
- package/dist/languages/fr.js +14 -2
- package/dist/languages/fr.js.map +1 -1
- package/dist/languages/id.d.ts +1 -1
- package/dist/languages/id.js +14 -2
- package/dist/languages/id.js.map +1 -1
- package/dist/languages/ja.d.ts +1 -1
- package/dist/languages/ja.js +18 -3
- package/dist/languages/ja.js.map +1 -1
- package/dist/languages/ko.d.ts +8 -1
- package/dist/languages/ko.js +75 -43
- package/dist/languages/ko.js.map +1 -1
- package/dist/languages/pt.d.ts +1 -1
- package/dist/languages/pt.js +17 -0
- package/dist/languages/pt.js.map +1 -1
- package/dist/languages/qu.d.ts +12 -1
- package/dist/languages/qu.js +77 -2
- package/dist/languages/qu.js.map +1 -1
- package/dist/languages/sw.d.ts +1 -1
- package/dist/languages/sw.js.map +1 -1
- package/dist/languages/tr.d.ts +9 -1
- package/dist/languages/tr.js +96 -72
- package/dist/languages/tr.js.map +1 -1
- package/dist/languages/zh.d.ts +1 -1
- package/dist/languages/zh.js +16 -0
- package/dist/languages/zh.js.map +1 -1
- package/dist/{types-C4dcj53L.d.ts → types-BY3Id07j.d.ts} +20 -5
- package/package.json +20 -29
- package/src/generators/command-schemas.ts +21 -10
- package/src/generators/event-handler-generator.ts +50 -44
- package/src/generators/language-profiles.ts +6 -0
- package/src/generators/pattern-generator.ts +883 -1
- package/src/generators/profiles/arabic.ts +19 -3
- package/src/generators/profiles/bengali.ts +12 -1
- package/src/generators/profiles/chinese.ts +15 -0
- package/src/generators/profiles/french.ts +12 -1
- package/src/generators/profiles/german.ts +12 -1
- package/src/generators/profiles/hebrew.ts +148 -0
- package/src/generators/profiles/hindi.ts +12 -1
- package/src/generators/profiles/index.ts +2 -0
- package/src/generators/profiles/indonesian.ts +12 -1
- package/src/generators/profiles/italian.ts +16 -0
- package/src/generators/profiles/japanese.ts +11 -2
- package/src/generators/profiles/korean.ts +15 -1
- package/src/generators/profiles/polish.ts +12 -0
- package/src/generators/profiles/portuguese.ts +16 -0
- package/src/generators/profiles/russian.ts +11 -0
- package/src/generators/profiles/spanish.ts +15 -0
- package/src/generators/profiles/spanishMexico.ts +176 -0
- package/src/generators/profiles/thai.ts +11 -0
- package/src/generators/profiles/turkish.ts +49 -7
- package/src/generators/profiles/types.ts +21 -5
- package/src/generators/profiles/ukrainian.ts +11 -0
- package/src/generators/profiles/vietnamese.ts +11 -0
- package/src/language-building-schema.ts +111 -0
- package/src/languages/_all.ts +5 -1
- package/src/languages/es-MX.ts +32 -0
- package/src/languages/he.ts +15 -0
- package/src/parser/pattern-matcher.ts +10 -1
- package/src/parser/semantic-parser.ts +3 -0
- package/src/patterns/add/ar.ts +3 -59
- package/src/patterns/add/index.ts +5 -1
- package/src/patterns/add/ja.ts +3 -81
- package/src/patterns/add/ko.ts +3 -62
- package/src/patterns/add/qu.ts +69 -0
- package/src/patterns/add/tr.ts +3 -59
- package/src/patterns/builders.ts +1 -0
- package/src/patterns/decrement/tr.ts +3 -36
- package/src/patterns/event-handler/ar.ts +3 -139
- package/src/patterns/event-handler/he.ts +15 -0
- package/src/patterns/event-handler/index.ts +5 -1
- package/src/patterns/event-handler/ja.ts +3 -106
- package/src/patterns/event-handler/ko.ts +3 -121
- package/src/patterns/event-handler/ms.ts +45 -20
- package/src/patterns/event-handler/tr.ts +3 -158
- package/src/patterns/get/ar.ts +3 -37
- package/src/patterns/get/ja.ts +3 -41
- package/src/patterns/get/ko.ts +3 -41
- package/src/patterns/grammar-transformed/ja.ts +3 -1701
- package/src/patterns/grammar-transformed/ko.ts +3 -1299
- package/src/patterns/grammar-transformed/tr.ts +3 -1055
- package/src/patterns/hide/ar.ts +3 -55
- package/src/patterns/hide/ja.ts +3 -57
- package/src/patterns/hide/ko.ts +3 -57
- package/src/patterns/hide/tr.ts +3 -53
- package/src/patterns/increment/tr.ts +3 -40
- package/src/patterns/put/ar.ts +3 -62
- package/src/patterns/put/ja.ts +3 -63
- package/src/patterns/put/ko.ts +3 -55
- package/src/patterns/put/tr.ts +3 -55
- package/src/patterns/remove/ar.ts +3 -59
- package/src/patterns/remove/index.ts +5 -1
- package/src/patterns/remove/ja.ts +3 -62
- package/src/patterns/remove/ko.ts +3 -66
- package/src/patterns/remove/qu.ts +69 -0
- package/src/patterns/remove/tr.ts +3 -66
- package/src/patterns/set/ar.ts +3 -72
- package/src/patterns/set/ja.ts +3 -74
- package/src/patterns/set/ko.ts +3 -73
- package/src/patterns/set/tr.ts +3 -95
- package/src/patterns/show/ar.ts +3 -55
- package/src/patterns/show/ja.ts +3 -57
- package/src/patterns/show/ko.ts +3 -61
- package/src/patterns/show/tr.ts +3 -53
- package/src/patterns/take/ar.ts +3 -39
- package/src/patterns/toggle/ar.ts +3 -49
- package/src/patterns/toggle/index.ts +5 -1
- package/src/patterns/toggle/ja.ts +3 -144
- package/src/patterns/toggle/ko.ts +3 -101
- package/src/patterns/toggle/qu.ts +90 -0
- package/src/patterns/toggle/tr.ts +3 -76
- package/src/registry.ts +179 -15
- package/src/tokenizers/arabic.ts +13 -46
- package/src/tokenizers/bengali.ts +2 -16
- package/src/tokenizers/he.ts +542 -0
- package/src/tokenizers/index.ts +1 -0
- package/src/tokenizers/japanese.ts +3 -1
- package/src/tokenizers/korean.ts +104 -48
- package/src/tokenizers/ms.ts +3 -0
- package/src/tokenizers/quechua.ts +101 -2
- package/src/tokenizers/turkish.ts +64 -69
- package/src/types.ts +13 -0
|
@@ -1,2 +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);})();
|
|
1
|
+
"use strict";var LokaScriptSemanticCore=(()=>{var ue=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(n,e)=>{for(var t in e)ue(n,t,{get:e[t],enumerable:!0})},rt=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Je(e))!et.call(n,o)&&o!==t&&ue(n,o,{get:()=>e[o],enumerable:!(r=Ye(e,o))||r.enumerable});return n};var nt=n=>rt(ue({},"__esModule",{value:!0}),n);var fr={};tt(fr,{ASTBuilder:()=>J,DEFAULT_CONFIDENCE_THRESHOLD:()=>we,HIGH_CONFIDENCE_THRESHOLD:()=>Ze,SemanticAnalyzerImpl:()=>ee,VERSION:()=>ur,buildAST:()=>Ge,canParse:()=>Ee,createCommandNode:()=>O,createEventHandler:()=>U,createLiteral:()=>S,createPropertyPath:()=>W,createReference:()=>R,createSelector:()=>z,createSemanticAnalyzer:()=>Xe,fromExplicit:()=>ve,getCommandMapper:()=>Y,getPatternsForLanguage:()=>C,getProfile:()=>ge,getRegisteredLanguages:()=>K,getTokenizer:()=>fe,isExplicitSyntax:()=>D,isLanguageRegistered:()=>j,isLanguageSupported:()=>Me,loadLanguageFromUrl:()=>pr,parse:()=>F,parseAny:()=>be,parseExplicit:()=>_,registerCommandMapper:()=>ke,registerLanguage:()=>re,registerLanguageModule:()=>mr,registerPatterns:()=>q,render:()=>Z,renderExplicit:()=>Q,setPatternGenerator:()=>Le,shouldUseSemanticResult:()=>Qe,toExplicit:()=>Te,tokenize:()=>dr,tryGetProfile:()=>A});var k=new Map,w=new Map,$=new Map;var de=null;function Re(n,e){let t={...n};for(let r of Object.keys(e)){let o=e[r],i=n[r];o!==void 0&&(typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof i=="object"&&i!==null&&!Array.isArray(i)?t[r]=Re(i,o):t[r]=o)}return t}function ot(n,e){return Re(n,e)}function me(n){if(!n.extends)return n;let e=w.get(n.extends);if(!e)return console.warn(`[Registry] Profile '${n.code}' extends '${n.extends}' but base is not registered. Make sure to import the base language before the variant.`),n;let t=me(e);return ot(t,n)}function re(n,e,t){k.set(n,e),w.set(n,t),$.delete(n)}function Le(n){de=n}var pe=new Map;function q(n,e){pe.set(n,e),$.delete(n)}function P(n){return n.split("-")[0]}function M(n){return n.includes("-")}function fe(n){let e=k.get(n);if(!e&&M(n)){let t=P(n);e=k.get(t)}if(!e){let t=Array.from(k.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 ge(n){let e=w.get(n);if(!e&&M(n)){let t=P(n);e=w.get(t)}if(!e){let t=Array.from(w.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 me(e)}function Pe(n){let e=k.get(n);return!e&&M(n)&&(e=k.get(P(n))),e}function A(n){let e=w.get(n);return!e&&M(n)&&(e=w.get(P(n))),e?me(e):void 0}function K(){return Array.from(k.keys())}function j(n){if(k.has(n)&&w.has(n))return!0;if(M(n)){let e=P(n);return k.has(e)&&w.has(e)}return!1}function Me(n){return k.has(n)?!0:M(n)?k.has(P(n)):!1}function Ae(n,e){return fe(e).tokenize(n)}function C(n){let e=$.get(n);if(!e&&M(n)&&(e=$.get(P(n))),e)return e;let t=pe.get(n);if(!t&&M(n)&&(t=pe.get(P(n))),t)return $.set(n,t),t;if(!de)throw new Error(`No patterns registered for language '${n}'. Either import the language module or set a pattern generator.`);let r=ge(n),o=de(r);return $.set(n,o),o}function Ve(n,e){return C(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}var H=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 T(n,e){return{start:n,end:e}}function v(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 G(n){return/\s/.test(n)}function ze(n){return n==="#"||n==="."||n==="["||n==="@"||n==="*"||n==="<"}function Oe(n){return n==='"'||n==="'"||n==="`"||n==="\u300C"||n==="\u300D"}function V(n){return/\d/.test(n)}function Ie(n){return/[a-zA-Z]/.test(n)}function b(n){return/[a-zA-Z0-9_-]/.test(n)}function _e(n,e){if(e>=n.length)return null;let t=n[e];if(!ze(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||!Ie(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&&G(n[r]);)o+=n[r++];if(r<n.length&&n[r]==="/")for(o+=n[r++];r<n.length&&G(n[r]);)o+=n[r++];if(r>=n.length||n[r]!==">")return null;o+=n[r++]}return o||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 G(r)||r==="*"||!b(r)}function Be(n,e){if(e>=n.length)return null;let t=n[e];if(!Oe(t)||t==="'"&&it(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 $e(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 Ke(n,e){if(!$e(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 je(n,e){if(e>=n.length)return null;let t=n[e];if(!V(t)&&t!=="-"&&t!=="+")return null;let r=e,o="";if((n[r]==="-"||n[r]==="+")&&(o+=n[r++]),r>=n.length||!V(n[r]))return null;for(;r<n.length&&V(n[r]);)o+=n[r++];if(r<n.length&&n[r]===".")for(o+=n[r++];r<n.length&&V(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 ne=class ne{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 v(r.native,"keyword",T(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 v(e,"keyword",T(t,r),a)}trySelector(e,t){let r=_e(e,t);return r?v(r,"selector",T(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{...v(o,"event-modifier",T(t,t+o.length)),metadata:{modifierName:i,value:a?i==="queue"?a:parseInt(a,10):void 0}}}tryString(e,t){let r=Be(e,t);return r?v(r,"literal",T(t,t+r.length)):null}tryNumber(e,t){let r=je(e,t);return r?v(r,"literal",T(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,o=!1){let i=t;if(o)for(;i<e.length&&G(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||!V(e[o]))return null;for(;o<e.length&&V(e[o]);)i+=e[o++];if(o<e.length&&e[o]===".")for(i+=e[o++];o<e.length&&V(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,...ne.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,c,m,a);return x&&(u+=x.suffix,c=x.endPos),v(u,"literal",T(t,c))}tryUrl(e,t){let r=Ke(e,t);return r?v(r,"url",T(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 v(o,"identifier",T(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return v(r,"operator",T(t,t+2));let o=e[t];return["<",">","!","+","-","*","/","="].includes(o)?v(o,"operator",T(t,t+1)):["(",")","{","}",",",";",":"].includes(o)?v(o,"punctuation",T(t,t+1)):null}tryMultiCharParticle(e,t,r){for(let o of r)if(e.slice(t,t+o.length)===o)return v(o,"particle",T(t,t+o.length));return null}};ne.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 he=ne;function We(n){return Pe(n)}function oe(n,e){return Ae(n,e)}function ie(){return K()}function z(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 R(n){return{type:"reference",value:n}}function W(n,e){return{type:"property-path",object:n,property:e}}function O(n,e,t){let r={kind:"command",action:n,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function U(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 Ue(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 ye(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 De(n,e){return n.possessive?.keywords?.[e]}var L=class L{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let r=e.mark(),o=new Map;if(this.currentProfile=A(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){let o=t[0],i=o?.type==="literal"&&(o.value==="and"||o.value==="then"||o.alternatives?.includes("and")||o.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!i)for(;e.peek()?.kind==="conjunction";)e.advance();for(let a of t)if(!this.matchPatternToken(e,a,r)){if(this.isOptional(a))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&&!ye(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&&!ye(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=De(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(),W(R(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<L.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<L.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<L.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(),W(z(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 W(z(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 z(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)?R(t):S(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return R(e.value);let r=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(r)?R(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(L.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}};L.MAX_PROPERTY_DEPTH=10,L.MAX_METHOD_ARGS=20,L.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var X=L,I=new X;var ae=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let r=Ve(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=A(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 ie()}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=A(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=A(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}`}},xe=new ae;function Z(n,e){return xe.render(n,e)}function Q(n){return xe.renderExplicit(n)}function _(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=at(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=ct(u,c+1),d=u.slice(c+1,h+1);i.set(m,{type:"expression",raw:d});continue}let y=st(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(_(u.raw)),i.delete("body"),U(s,c,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,u]of i)a[s]=u;return O(o,a,{sourceLanguage:"explicit"})}function at(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 st(n){if(n.startsWith("#")||n.startsWith(".")||n.startsWith("[")||n.startsWith("@")||n.startsWith("*"))return z(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 R(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 ct(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 D(n){let e=n.trim();return e.startsWith("[")&&e.endsWith("]")}var se=class{parse(e,t){let r=oe(e,t),o=C(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=I.matchBest(r,a);if(s)return this.buildEventHandler(s,r,t);let u=i.filter(m=>m.command!=="on"),c=I.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 ie()}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 O(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}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=I.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=O(u,c,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=C(r).filter(p=>p.command!=="on").sort((p,g)=>g.priority-p.priority),h=C(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=C(r).filter(c=>c.command!=="on").sort((c,m)=>m.priority-c.priority);a=this.parseBodyWithClauses(t,u,r)}return U(o,a,i,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence})}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?[Ue(o,"then",{sourceLanguage:r})]:o}parseClause(e,t,r){if(e.length===0)return[];let o=new H(e,r),i=[];for(;!o.isAtEnd();){let a=I.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=I.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=O(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=I.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())}},Se=new se;function F(n,e){return Se.parse(n,e)}function Ee(n,e){return Se.canParse(n,e)}function Te(n,e){if(D(n))return n;let t=F(n,e);return Q(t)}function ve(n,e){let t=_(n);return Z(t,e)}function be(n,e){return D(n)?_(n):F(n,e)}var lt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),ut=new Set(["and","or","not","no"]),dt=new Set(["true","false","null","undefined"]),pt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Fe(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(le=>/[\d.]/.test(le)),E=t,te=c(le=>/[a-zA-Z]/.test(le));pt.has(te)?e.push(h("TIME_EXPRESSION",g+te,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(te=>/[\w$]/.test(te)),E=g.toLowerCase();lt.has(E)?e.push(h("CONTEXT_VAR",g,d)):ut.has(E)?e.push(h("LOGICAL",g,d)):dt.has(E)?e.push(h("BOOLEAN",g,d)):e.push(h("IDENTIFIER",g,d));continue}s()}return e.push(h("EOF","",t)),e}var ce=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Fe(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 Ne(n){return new ce().parse(n)}function N(n,e){switch(n.type){case"literal":return mt(n);case"selector":return ft(n,e);case"reference":return gt(n);case"property-path":return ht(n,e);case"expression":return yt(n);default:let t=n;throw new Error(`Unknown semantic value type: ${t.type}`)}}function mt(n){let e={type:"literal",value:n.value};return n.dataType?{...e,dataType:n.dataType}:e}function ft(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 gt(n){return{type:"contextReference",contextType:n.value,name:n.value}}function ht(n,e){return{type:"propertyAccess",object:N(n.object,e),property:n.property}}function yt(n){let e=Ne(n.raw);return!e.success||!e.node?{type:"identifier",name:n.raw}:e.node}function qe(n,e){return n.roles.get(e)}function l(n,e,t){let r=qe(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 xt={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)}},St={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)}},Et={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)}},Tt={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)}},vt={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)}},bt={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)}},Nt={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)}},kt={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)}},Ct={action:"wait",toAST(n,e){let t=l(n,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},wt={action:"log",toAST(n,e){let t=l(n,"patient"),r=[];return t&&r.push(t),f("log",r)}},Rt={action:"put",toAST(n,e){let t=l(n,"patient"),r=l(n,"destination"),o=qe(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)}},Lt={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})}},Pt={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)}},Mt={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)}},At={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)}},Vt={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)}},zt={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)}},Ot={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)}},It={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)}},_t={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)}},Bt={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)}},$t={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)}},Kt={action:"call",toAST(n,e){let t=l(n,"patient");return f("call",t?[t]:[])}},jt={action:"return",toAST(n,e){let t=l(n,"patient");return f("return",t?[t]:[])}},Wt={action:"halt",toAST(n,e){return f("halt",[])}},Ut={action:"throw",toAST(n,e){let t=l(n,"patient");return f("throw",t?[t]:[])}},Dt={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})}},Ft={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)}},qt={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)}},Ht={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)}},Gt={action:"make",toAST(n,e){let t=l(n,"patient");return f("make",t?[t]:[])}},Xt={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)}},Zt={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]:[])}},Yt={action:"async",toAST(n,e){return f("async",[])}},Jt={action:"if",toAST(n,e){let t=l(n,"condition");return f("if",t?[t]:[])}},er={action:"unless",toAST(n,e){let t=l(n,"condition");return f("unless",t?[t]:[])}},tr={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)}},rr={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)}},nr={action:"while",toAST(n,e){let t=l(n,"condition");return f("while",t?[t]:[])}},or={action:"continue",toAST(n,e){return f("continue",[])}},ir={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)}},ar={action:"init",toAST(n,e){return f("init",[])}},sr={action:"behavior",toAST(n,e){let t=l(n,"patient");return f("behavior",t?[t]:[])}},cr={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)}},lr={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)}},He=new Map([["toggle",xt],["add",St],["remove",Et],["set",Tt],["show",vt],["hide",bt],["increment",Nt],["decrement",kt],["wait",Ct],["log",wt],["put",Rt],["fetch",Lt],["append",Pt],["prepend",Mt],["get",Bt],["take",$t],["trigger",At],["send",Vt],["on",lr],["go",zt],["transition",Ot],["focus",It],["blur",_t],["call",Kt],["return",jt],["halt",Wt],["throw",Ut],["settle",Dt],["swap",Ft],["morph",qt],["clone",Ht],["measure",Xt],["make",Gt],["tell",Zt],["default",ir],["js",Qt],["async",Yt],["if",Jt],["unless",er],["repeat",tr],["for",rr],["while",nr],["continue",or],["init",ar],["behavior",sr],["install",cr]]);function Y(n){return He.get(n)}function ke(n){He.set(n.action,n)}var J=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=Y(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 Ge(n){let e=new J;return{ast:e.build(n),warnings:e.warnings}}var B=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}}},Ce=new B;var ee=class{constructor(e={}){this.patternMatcher=new X,this.languages=new Set(K()),e.cache===!1?this.cache=new B({enabled:!1}):this.cache=e.cache?new B(e.cache):Ce}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=We(t);if(!r)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let o=r.tokenize(e),i=C(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 Xe(n){return new ee(n)}var we=.5,Ze=.8;function Qe(n,e=we){return n.confidence>=e&&n.command!==void 0}var ur="1.0.0-core";function dr(n,e){if(!j(e))throw new Error(`Language '${e}' is not loaded. Load it via script tag or loadLanguageFromUrl().`);return[...oe(n,e).tokens]}async function pr(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),j(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 mr(n,e){re(n,e.tokenizer,e.profile),e.patterns?q(n,e.patterns):e.buildPatterns&&q(n,e.buildPatterns())}return nt(fr);})();
|