@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 LokaScriptSemanticEs=(()=>{var fe=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=(r,e)=>{for(var t in e)fe(r,t,{get:e[t],enumerable:!0})},st=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of it(e))!ot.call(r,i)&&i!==t&&fe(r,i,{get:()=>e[i],enumerable:!(n=rt(e,i))||n.enumerable});return r};var ct=r=>st(fe({},"__esModule",{value:!0}),r);var Pn={};at(Pn,{ASTBuilder:()=>X,DEFAULT_CONFIDENCE_THRESHOLD:()=>Le,HIGH_CONFIDENCE_THRESHOLD:()=>Je,SemanticAnalyzerImpl:()=>Z,VERSION:()=>Nn,buildAST:()=>Qe,canParse:()=>Te,createCommandNode:()=>M,createEventHandler:()=>j,createLiteral:()=>E,createPropertyPath:()=>W,createReference:()=>w,createSelector:()=>L,createSemanticAnalyzer:()=>Ye,fromExplicit:()=>Ne,getCommandMapper:()=>G,getPatternsForLanguage:()=>nt,getPatternsForLanguageAndCommand:()=>Rn,getProfile:()=>he,getSupportedLanguages:()=>Cn,getTokenizer:()=>ge,isExplicitSyntax:()=>K,isLanguageSupported:()=>Ve,parse:()=>$,parseAny:()=>Ce,parseExplicit:()=>O,registerCommandMapper:()=>Re,render:()=>q,renderExplicit:()=>H,shouldUseSemanticResult:()=>et,spanishProfile:()=>A,spanishTokenizer:()=>ae,toExplicit:()=>ke,tokenize:()=>wn});var _=new Map,J=new Map,Y=new Map;var Me=null;function ze(r,e,t){_.set(r,e),J.set(r,t),Y.delete(r)}var lt=new Map;function ge(r){let e=_.get(r);if(!e){let t=Array.from(_.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function he(r){let e=J.get(r);if(!e){let t=Array.from(J.keys()).join(", ");throw new Error(`Language profile '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function Ae(r){return _.get(r)}function B(r){return J.get(r)}function ee(){return Array.from(_.keys())}function Ve(r){return _.has(r)}function Oe(r,e){return ge(e).tokenize(r)}function C(r){let e=Y.get(r);if(e)return e;let t=lt.get(r);if(t)return Y.set(r,t),t;if(!Me)throw new Error(`No patterns registered for language '${r}'. Either import the language module or set a pattern generator.`);let n=he(r),i=Me(n);return Y.set(r,i),i}function Ie(r,e){return C(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}var z=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function S(r,e){return{start:r,end:e}}function v(r,e,t,n){if(typeof n=="string")return{value:r,kind:e,position:t,normalized:n};if(n){let{normalized:i,stem:o,stemConfidence:a}=n,s={value:r,kind:e,position:t};return i!==void 0&&(s.normalized=i),o!==void 0&&(s.stem=o,a!==void 0&&(s.stemConfidence=a)),s}return{value:r,kind:e,position:t}}function P(r){return/\s/.test(r)}function ne(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function re(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function N(r){return/\d/.test(r)}function _e(r){return/[a-zA-Z]/.test(r)}function T(r){return/[a-zA-Z0-9_-]/.test(r)}function ye(r){let e=n=>r.test(n);return{isLetter:e,isIdentifierChar:n=>e(n)||/[0-9_-]/.test(n)}}function Be(r,e){if(e>=r.length)return null;let t=r[e];if(!ne(t))return null;let n=e,i="";if(t==="#"||t==="."){for(i+=r[n++];n<r.length&&T(r[n]);)i+=r[n++];if(i.length<=1)return null;if(n<r.length&&r[n]==="."&&t==="#"){let a=n+1;for(;a<r.length&&T(r[a]);)a++;if(a<r.length&&r[a]==="(")return i}}else if(t==="["){let o=1,a=!1,s=null,c=!1;for(i+=r[n++];n<r.length&&o>0;){let l=r[n];i+=l,c?c=!1:l==="\\"?c=!0:a?l===s&&(a=!1,s=null):l==='"'||l==="'"||l==="`"?(a=!0,s=l):l==="["?o++:l==="]"&&o--,n++}if(o!==0)return null}else if(t==="@"){for(i+=r[n++];n<r.length&&T(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="*"){for(i+=r[n++];n<r.length&&T(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="<"){if(i+=r[n++],n>=r.length||!_e(r[n]))return null;for(;n<r.length&&T(r[n]);)i+=r[n++];for(;n<r.length;){let o=r[n];if(o==="."){if(i+=r[n++],n>=r.length||!T(r[n]))return null;for(;n<r.length&&T(r[n]);)i+=r[n++]}else if(o==="#"){if(i+=r[n++],n>=r.length||!T(r[n]))return null;for(;n<r.length&&T(r[n]);)i+=r[n++]}else if(o==="["){let a=1,s=!1,c=null,l=!1;for(i+=r[n++];n<r.length&&a>0;){let m=r[n];i+=m,l?l=!1:m==="\\"?l=!0:s?m===c&&(s=!1,c=null):m==='"'||m==="'"||m==="`"?(s=!0,c=m):m==="["?a++:m==="]"&&a--,n++}if(a!==0)return null}else break}for(;n<r.length&&P(r[n]);)i+=r[n++];if(n<r.length&&r[n]==="/")for(i+=r[n++];n<r.length&&P(r[n]);)i+=r[n++];if(n>=r.length||r[n]!==">")return null;i+=r[n++]}return i||null}function dt(r,e){if(e>=r.length||r[e]!=="'"||e+1>=r.length||r[e+1].toLowerCase()!=="s")return!1;if(e+2>=r.length)return!0;let n=r[e+2];return P(n)||n==="*"||!T(n)}function We(r,e){if(e>=r.length)return null;let t=r[e];if(!re(t)||t==="'"&&dt(r,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,a=t,s=!1;for(;o<r.length;){let c=r[o];if(a+=c,s)s=!1;else if(c==="\\")s=!0;else if(c===i)return a;o++}return a}function ie(r,e){if(e>=r.length)return!1;let t=r[e],n=r[e+1]||"",i=r[e+2]||"";if(t==="/"&&n!=="/"&&/[a-zA-Z0-9._-]/.test(n)||t==="/"&&n==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(n==="/"||n==="."&&i==="/"))return!0;let o=r.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function je(r,e){if(!ie(r,e))return null;let t=e,n="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<r.length;){let o=r[t];if(o==="#"){if(n.length>0&&/[a-zA-Z0-9/.]$/.test(n))for(n+=o,t++;t<r.length&&/[a-zA-Z0-9_-]/.test(r[t]);)n+=r[t++];break}if(i.test(o))n+=o,t++;else break}return n.length<2?null:n}function Ke(r,e){if(e>=r.length)return null;let t=r[e];if(!N(t)&&t!=="-"&&t!=="+")return null;let n=e,i="";if((r[n]==="-"||r[n]==="+")&&(i+=r[n++]),n>=r.length||!N(r[n]))return null;for(;n<r.length&&N(r[n]);)i+=r[n++];if(n<r.length&&r[n]===".")for(i+=r[n++];n<r.length&&N(r[n]);)i+=r[n++];return n<r.length&&(r.slice(n,n+2)==="ms"?i+="ms":(r[n]==="s"||r[n]==="m"||r[n]==="h")&&(i+=r[n])),i}var te=class te{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let n=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(n.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let a of o.alternatives)n.set(a,{native:a,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))n.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&n.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let a of o.alternatives)n.set(a,{native:a,normalized:i})}for(let i of t)n.set(i.native,i);this.profileKeywords=Array.from(n.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let n of this.profileKeywords)if(e.slice(t).startsWith(n.native))return v(n.native,"keyword",S(t,t+n.native.length),n.normalized);return null}isKeywordStart(e,t){let n=e.slice(t);return this.profileKeywords.some(i=>n.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,n){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let a={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return v(e,"keyword",S(t,n),a)}trySelector(e,t){let n=Be(e,t);return n?v(n,"selector",S(t,t+n.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let n=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!n)return null;let i=n[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],a=n[1];return{...v(i,"event-modifier",S(t,t+i.length)),metadata:{modifierName:o,value:a?o==="queue"?a:parseInt(a,10):void 0}}}tryString(e,t){let n=We(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryNumber(e,t){let n=Ke(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,i=!1){let o=t;if(i)for(;o<e.length&&P(e[o]);)o++;let a=e.slice(o);for(let s of n){let c=a.slice(0,s.length);if(s.caseInsensitive?c.toLowerCase()===s.pattern.toLowerCase():c===s.pattern){if(s.notFollowedBy&&(a[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let m=a[s.length]||"";if(T(m))continue}return{suffix:s.suffix,endPos:o+s.length}}}return null}parseBaseNumber(e,t,n=!0){let i=t,o="";if(n&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!N(e[i]))return null;for(;i<e.length&&N(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&N(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,n,i={}){let{allowSign:o=!0,skipWhitespace:a=!1}=i,s=this.parseBaseNumber(e,t,o);if(!s)return null;let{number:c,endPos:l}=s,m=[...n,...te.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,l,m,a);return x&&(c+=x.suffix,l=x.endPos),v(c,"literal",S(t,l))}tryUrl(e,t){let n=je(e,t);return n?v(n,"url",S(t,t+n.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!T(e[t+1]))return null;let n=t+1;for(;n<e.length&&T(e[n]);)n++;let i=e.slice(t,n);return v(i,"identifier",S(t,n))}tryOperator(e,t){let n=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(n))return v(n,"operator",S(t,t+2));let i=e[t];return["<",">","!","+","-","*","/","="].includes(i)?v(i,"operator",S(t,t+1)):["(",")","{","}",",",";",":"].includes(i)?v(i,"punctuation",S(t,t+1)):null}tryMultiCharParticle(e,t,n){for(let i of n)if(e.slice(t,t+i.length)===i)return v(i,"particle",S(t,t+i.length));return null}};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 U=te;function xe(r){return{stem:r,confidence:1}}function oe(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}function pt(r){return/[áéíóúüñÁÉÍÓÚÜÑ]/.test(r)}function ut(r){let e=r.toLowerCase();if(e.endsWith("ar")||e.endsWith("er")||e.endsWith("ir")||e.endsWith("ando")||e.endsWith("iendo")||e.endsWith("ado")||e.endsWith("ido")||e.endsWith("arse")||e.endsWith("erse")||e.endsWith("irse"))return!0;for(let t of r)if(pt(t))return!0;return!1}var $e=["se","me","te","nos","os"],mt=[{ending:"ando",stem:"ar",confidence:.88,type:"gerund"},{ending:"ado",stem:"ar",confidence:.88,type:"participle"},{ending:"ada",stem:"ar",confidence:.88,type:"participle"},{ending:"ados",stem:"ar",confidence:.88,type:"participle"},{ending:"adas",stem:"ar",confidence:.88,type:"participle"},{ending:"o",stem:"ar",confidence:.75,type:"present"},{ending:"as",stem:"ar",confidence:.82,type:"present"},{ending:"a",stem:"ar",confidence:.75,type:"present"},{ending:"amos",stem:"ar",confidence:.85,type:"present"},{ending:"\xE1is",stem:"ar",confidence:.85,type:"present"},{ending:"ais",stem:"ar",confidence:.82,type:"present"},{ending:"an",stem:"ar",confidence:.8,type:"present"},{ending:"\xE9",stem:"ar",confidence:.85,type:"past"},{ending:"aste",stem:"ar",confidence:.88,type:"past"},{ending:"\xF3",stem:"ar",confidence:.82,type:"past"},{ending:"amos",stem:"ar",confidence:.85,type:"past"},{ending:"asteis",stem:"ar",confidence:.88,type:"past"},{ending:"aron",stem:"ar",confidence:.88,type:"past"},{ending:"aba",stem:"ar",confidence:.88,type:"past"},{ending:"abas",stem:"ar",confidence:.88,type:"past"},{ending:"\xE1bamos",stem:"ar",confidence:.88,type:"past"},{ending:"abamos",stem:"ar",confidence:.85,type:"past"},{ending:"abais",stem:"ar",confidence:.88,type:"past"},{ending:"aban",stem:"ar",confidence:.88,type:"past"},{ending:"e",stem:"ar",confidence:.72,type:"subjunctive"},{ending:"es",stem:"ar",confidence:.78,type:"subjunctive"},{ending:"emos",stem:"ar",confidence:.82,type:"subjunctive"},{ending:"\xE9is",stem:"ar",confidence:.85,type:"subjunctive"},{ending:"eis",stem:"ar",confidence:.82,type:"subjunctive"},{ending:"en",stem:"ar",confidence:.78,type:"subjunctive"},{ending:"a",stem:"ar",confidence:.75,type:"imperative"},{ending:"ad",stem:"ar",confidence:.85,type:"imperative"},{ending:"ar",stem:"ar",confidence:.92,type:"dictionary"}],ft=[{ending:"iendo",stem:"er",confidence:.88,type:"gerund"},{ending:"ido",stem:"er",confidence:.85,type:"participle"},{ending:"ida",stem:"er",confidence:.85,type:"participle"},{ending:"idos",stem:"er",confidence:.85,type:"participle"},{ending:"idas",stem:"er",confidence:.85,type:"participle"},{ending:"o",stem:"er",confidence:.72,type:"present"},{ending:"es",stem:"er",confidence:.78,type:"present"},{ending:"e",stem:"er",confidence:.72,type:"present"},{ending:"emos",stem:"er",confidence:.85,type:"present"},{ending:"\xE9is",stem:"er",confidence:.85,type:"present"},{ending:"eis",stem:"er",confidence:.82,type:"present"},{ending:"en",stem:"er",confidence:.78,type:"present"},{ending:"\xED",stem:"er",confidence:.85,type:"past"},{ending:"iste",stem:"er",confidence:.88,type:"past"},{ending:"i\xF3",stem:"er",confidence:.85,type:"past"},{ending:"io",stem:"er",confidence:.82,type:"past"},{ending:"imos",stem:"er",confidence:.85,type:"past"},{ending:"isteis",stem:"er",confidence:.88,type:"past"},{ending:"ieron",stem:"er",confidence:.88,type:"past"},{ending:"\xEDa",stem:"er",confidence:.88,type:"past"},{ending:"ia",stem:"er",confidence:.85,type:"past"},{ending:"\xEDas",stem:"er",confidence:.88,type:"past"},{ending:"ias",stem:"er",confidence:.85,type:"past"},{ending:"\xEDamos",stem:"er",confidence:.88,type:"past"},{ending:"iamos",stem:"er",confidence:.85,type:"past"},{ending:"\xEDais",stem:"er",confidence:.88,type:"past"},{ending:"iais",stem:"er",confidence:.85,type:"past"},{ending:"\xEDan",stem:"er",confidence:.88,type:"past"},{ending:"ian",stem:"er",confidence:.85,type:"past"},{ending:"er",stem:"er",confidence:.92,type:"dictionary"}],gt=[{ending:"iendo",stem:"ir",confidence:.88,type:"gerund"},{ending:"ido",stem:"ir",confidence:.85,type:"participle"},{ending:"ida",stem:"ir",confidence:.85,type:"participle"},{ending:"idos",stem:"ir",confidence:.85,type:"participle"},{ending:"idas",stem:"ir",confidence:.85,type:"participle"},{ending:"o",stem:"ir",confidence:.72,type:"present"},{ending:"es",stem:"ir",confidence:.78,type:"present"},{ending:"e",stem:"ir",confidence:.72,type:"present"},{ending:"imos",stem:"ir",confidence:.85,type:"present"},{ending:"\xEDs",stem:"ir",confidence:.85,type:"present"},{ending:"is",stem:"ir",confidence:.82,type:"present"},{ending:"en",stem:"ir",confidence:.78,type:"present"},{ending:"\xED",stem:"ir",confidence:.85,type:"past"},{ending:"iste",stem:"ir",confidence:.88,type:"past"},{ending:"i\xF3",stem:"ir",confidence:.85,type:"past"},{ending:"io",stem:"ir",confidence:.82,type:"past"},{ending:"imos",stem:"ir",confidence:.85,type:"past"},{ending:"isteis",stem:"ir",confidence:.88,type:"past"},{ending:"ieron",stem:"ir",confidence:.88,type:"past"},{ending:"\xEDa",stem:"ir",confidence:.88,type:"past"},{ending:"ia",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDas",stem:"ir",confidence:.88,type:"past"},{ending:"ias",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDamos",stem:"ir",confidence:.88,type:"past"},{ending:"iamos",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDais",stem:"ir",confidence:.88,type:"past"},{ending:"iais",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDan",stem:"ir",confidence:.88,type:"past"},{ending:"ian",stem:"ir",confidence:.85,type:"past"},{ending:"ir",stem:"ir",confidence:.92,type:"dictionary"}],ht=[...mt,...ft,...gt].sort((r,e)=>e.ending.length-r.ending.length),F=class{constructor(){this.language="es"}isNormalizable(e){return e.length<3?!1:ut(e)}normalize(e){let t=e.toLowerCase();if((t.endsWith("ar")||t.endsWith("er")||t.endsWith("ir"))&&!$e.some(o=>t.endsWith(o+"ar")||t.endsWith(o+"er")||t.endsWith(o+"ir")))return xe(e);let n=this.tryReflexiveNormalization(t);if(n)return n;let i=this.tryConjugationNormalization(t);return i||xe(e)}tryReflexiveNormalization(e){for(let t of $e)if(e.endsWith(t)){let n=e.slice(0,-t.length);if(n.endsWith("ar")||n.endsWith("er")||n.endsWith("ir"))return oe(n,.88,{removedSuffixes:[t],conjugationType:"reflexive"});let i=this.tryConjugationNormalization(n);if(i&&i.stem!==n)return oe(i.stem,i.confidence*.95,{removedSuffixes:[t,...i.metadata?.removedSuffixes||[]],conjugationType:"reflexive"})}return null}tryConjugationNormalization(e){for(let t of ht)if(e.endsWith(t.ending)){let n=e.slice(0,-t.ending.length);if(n.length<2)continue;let i=n+t.stem;return oe(i,t.confidence,{removedSuffixes:[t.ending],conjugationType:t.type})}return null}},On=new F;var A={code:"es",name:"Spanish",nativeName:"Espa\xF1ol",direction:"ltr",wordOrder:"SVO",markingStrategy:"preposition",usesSpaces:!0,defaultVerbForm:"infinitive",verb:{position:"start",subjectDrop:!0},references:{me:"yo",it:"ello",you:"t\xFA",result:"resultado",event:"evento",target:"objetivo",body:"cuerpo"},possessive:{marker:"de",markerPosition:"before-property",usePossessiveAdjectives:!0,specialForms:{me:"mi",it:"su",you:"tu"},keywords:{mi:"me",tu:"you",su:"it"}},roleMarkers:{destination:{primary:"en",alternatives:["sobre","a"],position:"before"},source:{primary:"de",alternatives:["desde"],position:"before"},patient:{primary:"",position:"before"},style:{primary:"con",position:"before"}},keywords:{toggle:{primary:"alternar",alternatives:["cambiar","conmutar"],normalized:"toggle"},add:{primary:"agregar",alternatives:["a\xF1adir"],normalized:"add"},remove:{primary:"quitar",alternatives:["eliminar","remover","sacar"],normalized:"remove"},put:{primary:"poner",alternatives:["colocar"],normalized:"put"},append:{primary:"a\xF1adir",normalized:"append"},prepend:{primary:"anteponer",normalized:"prepend"},take:{primary:"tomar",normalized:"take"},make:{primary:"hacer",alternatives:["crear"],normalized:"make"},clone:{primary:"clonar",alternatives:["copiar"],normalized:"clone"},swap:{primary:"intercambiar",alternatives:["cambiar"],normalized:"swap"},morph:{primary:"transformar",alternatives:["convertir"],normalized:"morph"},set:{primary:"establecer",alternatives:["fijar","definir"],normalized:"set"},get:{primary:"obtener",alternatives:["conseguir"],normalized:"get"},increment:{primary:"incrementar",alternatives:["aumentar"],normalized:"increment"},decrement:{primary:"decrementar",alternatives:["disminuir"],normalized:"decrement"},log:{primary:"registrar",alternatives:["imprimir"],normalized:"log"},show:{primary:"mostrar",alternatives:["ense\xF1ar"],normalized:"show"},hide:{primary:"ocultar",alternatives:["esconder"],normalized:"hide"},transition:{primary:"transici\xF3n",alternatives:["animar"],normalized:"transition"},on:{primary:"en",alternatives:["cuando","al"],normalized:"on"},trigger:{primary:"disparar",alternatives:["activar"],normalized:"trigger"},send:{primary:"enviar",normalized:"send"},focus:{primary:"enfocar",normalized:"focus"},blur:{primary:"desenfocar",normalized:"blur"},go:{primary:"ir",alternatives:["navegar"],normalized:"go"},wait:{primary:"esperar",normalized:"wait"},fetch:{primary:"buscar",alternatives:["obtener"],normalized:"fetch"},settle:{primary:"estabilizar",normalized:"settle"},if:{primary:"si",normalized:"if"},when:{primary:"cuando",normalized:"when"},where:{primary:"donde",normalized:"where"},else:{primary:"sino",alternatives:["de lo contrario"],normalized:"else"},repeat:{primary:"repetir",normalized:"repeat"},for:{primary:"para",normalized:"for"},while:{primary:"mientras",normalized:"while"},continue:{primary:"continuar",normalized:"continue"},halt:{primary:"detener",alternatives:["parar"],normalized:"halt"},throw:{primary:"lanzar",alternatives:["arrojar"],normalized:"throw"},call:{primary:"llamar",normalized:"call"},return:{primary:"retornar",alternatives:["devolver"],normalized:"return"},then:{primary:"entonces",alternatives:["luego","despu\xE9s"],normalized:"then"},and:{primary:"y",alternatives:["adem\xE1s","tambi\xE9n"],normalized:"and"},end:{primary:"fin",alternatives:["final","terminar"],normalized:"end"},js:{primary:"js",normalized:"js"},async:{primary:"as\xEDncrono",normalized:"async"},tell:{primary:"decir",normalized:"tell"},default:{primary:"predeterminar",alternatives:["por defecto"],normalized:"default"},init:{primary:"iniciar",alternatives:["inicializar"],normalized:"init"},behavior:{primary:"comportamiento",normalized:"behavior"},install:{primary:"instalar",normalized:"install"},measure:{primary:"medir",normalized:"measure"},into:{primary:"en",alternatives:["dentro de"],normalized:"into"},before:{primary:"antes",normalized:"before"},after:{primary:"despu\xE9s",normalized:"after"},until:{primary:"hasta",normalized:"until"},event:{primary:"evento",normalized:"event"},from:{primary:"de",alternatives:["desde"],normalized:"from"}}};var{isLetter:Ue,isIdentifierChar:yt}=ye(/[a-zA-ZáéíóúüñÁÉÍÓÚÜÑ]/),xt=[{pattern:"milisegundos",suffix:"ms",length:12,caseInsensitive:!0},{pattern:"milisegundo",suffix:"ms",length:11,caseInsensitive:!0},{pattern:"segundos",suffix:"s",length:8,caseInsensitive:!0},{pattern:"segundo",suffix:"s",length:7,caseInsensitive:!0},{pattern:"minutos",suffix:"m",length:7,caseInsensitive:!0},{pattern:"minuto",suffix:"m",length:6,caseInsensitive:!0},{pattern:"horas",suffix:"h",length:5,caseInsensitive:!0},{pattern:"hora",suffix:"h",length:4,caseInsensitive:!0}],Fe=new Set(["en","a","de","desde","hasta","con","sin","por","para","sobre","entre","antes","despu\xE9s","despues","dentro","fuera","al","del"]),St=[{native:"verdadero",normalized:"true"},{native:"falso",normalized:"false"},{native:"nulo",normalized:"null"},{native:"indefinido",normalized:"undefined"},{native:"primero",normalized:"first"},{native:"primera",normalized:"first"},{native:"\xFAltimo",normalized:"last"},{native:"ultima",normalized:"last"},{native:"siguiente",normalized:"next"},{native:"anterior",normalized:"previous"},{native:"cercano",normalized:"closest"},{native:"padre",normalized:"parent"},{native:"clic",normalized:"click"},{native:"click",normalized:"click"},{native:"hacer clic",normalized:"click"},{native:"entrada",normalized:"input"},{native:"cambio",normalized:"change"},{native:"env\xEDo",normalized:"submit"},{native:"envio",normalized:"submit"},{native:"tecla abajo",normalized:"keydown"},{native:"tecla arriba",normalized:"keyup"},{native:"rat\xF3n encima",normalized:"mouseover"},{native:"raton encima",normalized:"mouseover"},{native:"rat\xF3n fuera",normalized:"mouseout"},{native:"raton fuera",normalized:"mouseout"},{native:"enfoque",normalized:"focus"},{native:"desenfoque",normalized:"blur"},{native:"carga",normalized:"load"},{native:"desplazamiento",normalized:"scroll"},{native:"yo",normalized:"me"},{native:"m\xED",normalized:"me"},{native:"mi",normalized:"me"},{native:"ello",normalized:"it"},{native:"resultado",normalized:"result"},{native:"objetivo",normalized:"target"},{native:"destino",normalized:"target"},{native:"segundo",normalized:"s"},{native:"segundos",normalized:"s"},{native:"milisegundo",normalized:"ms"},{native:"milisegundos",normalized:"ms"},{native:"minuto",normalized:"m"},{native:"minutos",normalized:"m"},{native:"hora",normalized:"h"},{native:"horas",normalized:"h"},{native:"de lo contrario",normalized:"else"},{native:"hasta que",normalized:"until"},{native:"antes de",normalized:"before"},{native:"despu\xE9s de",normalized:"after"},{native:"despues de",normalized:"after"},{native:"dentro de",normalized:"into"},{native:"fuera de",normalized:"out"},{native:"asincrono",normalized:"async"},{native:"despues",normalized:"after"},{native:"a\xF1adir",normalized:"add"},{native:"toggle",normalized:"toggle"},{native:"borrar",normalized:"remove"},{native:"pon",normalized:"put"},{native:"crear",normalized:"make"},{native:"y",normalized:"and"},{native:"o",normalized:"or"},{native:"no",normalized:"not"},{native:"es",normalized:"is"},{native:"existe",normalized:"exists"},{native:"vac\xEDo",normalized:"empty"},{native:"vacio",normalized:"empty"}],Se=class extends U{constructor(){super();this.language="es";this.direction="ltr";this.initializeKeywordsFromProfile(A,St),this.normalizer=new F}tokenize(t){let n=[],i=0;for(;i<t.length;){if(P(t[i])){i++;continue}if(ne(t[i])){let c=this.tryEventModifier(t,i);if(c){n.push(c),i=c.position.end;continue}let l=this.trySelector(t,i);if(l){n.push(l),i=l.position.end;continue}}if(re(t[i])){let c=this.tryString(t,i);if(c){n.push(c),i=c.position.end;continue}}if(ie(t,i)){let c=this.tryUrl(t,i);if(c){n.push(c),i=c.position.end;continue}}if(N(t[i])||t[i]==="-"&&i+1<t.length&&N(t[i+1])){let c=this.extractSpanishNumber(t,i);if(c){n.push(c),i=c.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){n.push(o),i=o.position.end;continue}let a=this.tryMultiWordPhrase(t,i);if(a){n.push(a),i=a.position.end;continue}if(Ue(t[i])){let c=this.extractSpanishWord(t,i);if(c){n.push(c),i=c.position.end;continue}}let s=this.tryOperator(t,i);if(s){n.push(s),i=s.position.end;continue}i++}return new z(n,"es")}classifyToken(t){let n=t.toLowerCase();return Fe.has(n)?"particle":this.isKeyword(n)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||/^\d/.test(t)?"literal":["==","!=","<=",">=","<",">","&&","||","!"].includes(t)?"operator":"identifier"}tryMultiWordPhrase(t,n){for(let i of this.profileKeywords){if(!i.native.includes(" "))continue;let o=i.native;if(t.slice(n,n+o.length).toLowerCase()===o.toLowerCase()){let s=n+o.length;if(s>=t.length||P(t[s])||!Ue(t[s]))return v(t.slice(n,n+o.length),"keyword",S(n,s),i.normalized)}}return null}extractSpanishWord(t,n){let i=n,o="";for(;i<t.length&&yt(t[i]);)o+=t[i++];if(!o)return null;let a=o.toLowerCase();if(Fe.has(a))return v(o,"particle",S(n,i));let s=this.lookupKeyword(a);if(s)return v(o,"keyword",S(n,i),s.normalized);let c=this.tryMorphKeywordMatch(a,n,i);return c||v(o,"identifier",S(n,i))}extractSpanishNumber(t,n){return this.tryNumberWithTimeUnits(t,n,xt,{allowSign:!0,skipWhitespace:!0})}},ae=new Se;ze("es",ae,A);function De(r){return Ae(r)}function se(r,e){return Oe(r,e)}function ce(){return ee()}function L(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function E(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function w(r){return{type:"reference",value:r}}function W(r,e){return{type:"property-path",object:r,property:e}}function M(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function j(r,e,t,n,i){let o=new Map;o.set("event",r);let a={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(a.eventModifiers=t),n!==void 0&&(a.metadata=n),i!==void 0&&i.length>0&&(a.parameterNames=i),a}function qe(r,e="then",t){let n={kind:"compound",action:"compound",roles:new Map,statements:r,chainType:e};return t!==void 0&&(n.metadata=t),n}function ve(r,e){return!e||e.length===0||e.includes(r)||e.includes("expression")?!0:r==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function He(r,e){return r.possessive?.keywords?.[e]}var R=class R{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let n=e.mark(),i=new Map;if(this.currentProfile=B(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(n),null;let a=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-n.position,confidence:a}}matchBest(e,t){let n=[];for(let o of t){let a=e.mark(),s=this.matchPattern(e,o);s&&n.push(s),e.reset(a)}if(n.length===0)return null;n.sort((o,a)=>{let s=a.pattern.priority-o.pattern.priority;return s!==0?s:a.confidence-o.confidence});let i=n[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,n){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let i of t)if(!this.matchPatternToken(e,i,n)){if(this.isOptional(i))continue;return!1}return!0}matchPatternToken(e,t,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,n);case"group":return this.matchGroupToken(e,t,n);default:return!1}}matchLiteralToken(e,t){let n=e.peek();if(!n)return!1;let i=this.getMatchType(n,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let a=this.getMatchType(n,o);if(a!=="none")return this.totalKeywordMatches++,a==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,o),!0);let 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:(n.set(t.role,a),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!ve(s.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,s),!0);let c=this.tryMatchPropertyAccessExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,c),!0);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!ve(l.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,l),!0);let m=this.tokenToSemanticValue(i);return!m||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(m.type)?t.optional||!1:(n.set(t.role,m),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let n=(t.normalized||t.value).toLowerCase(),i=He(this.currentProfile,n);if(!i)return null;let o=e.mark();e.advance();let a=e.peek();return a&&(a.kind==="identifier"||a.kind==="keyword"&&!this.isStructuralKeyword(a.value)||a.kind==="selector"&&a.value.startsWith("*"))?(e.advance(),W(w(i),a.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let a=e.peek();if(!a||a.kind!=="punctuation"||a.value!=="(")return e.reset(n),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<R.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}s.push(l.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let a=`${t.value}.${o.value}`,s=1;for(;!e.isAtEnd()&&s<R.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let m=e.peek();if(!m||m.kind!=="identifier")break;e.advance(),a+=`.${m.value}`,s++}let c=e.peek();if(c&&c.kind==="punctuation"&&c.value==="("){e.advance();let l=[],m=0;for(;!e.isAtEnd()&&l.length<R.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(m===0){e.advance();break}m--}if(y.kind==="punctuation"&&y.value==="("&&m++,y.kind==="punctuation"&&y.value===","){e.advance();continue}l.push(y.value),e.advance()}return{type:"expression",raw:`${a}(${l.join(", ")})`}}return{type:"expression",raw:a}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(n),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(n),null):(e.advance(),W(L(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(n),null;let o=e.peek(1);o&&o.kind,e.advance();let a=i.value.slice(1);return W(L(t.value),a)}matchGroupToken(e,t,n){let i=e.mark(),o=new Set(n.keys());if(!this.matchTokenSequence(e,t.tokens,n)){e.reset(i);for(let s of n.keys())o.has(s)||n.delete(s);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return L(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?w(t):E(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return w(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?w(n):{type:"expression",raw:e.value};case"url":return E(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let i=e.slice(1,-1);return E(i,"string")}if(e==="true")return E(!0,"boolean");if(e==="false")return E(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let i=parseFloat(t[1]);return t[2]?E(e,"duration"):E(i,"number")}let n=parseFloat(e);return isNaN(n)?E(e,"string"):E(n,"number")}applyExtractionRules(e,t){for(let[n,i]of Object.entries(e.extraction))!t.has(n)&&i.default&&t.set(n,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let n=0,i=0,o=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")i+=1,t.has(l.role)&&(n+=1);else if(l.type==="group"){for(let m of l.tokens)if(m.type==="role"){let x=o(m.role),y=.8;i+=y,t.has(m.role)?n+=y:x&&(n+=y*.6)}}let a=i>0?n/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let l=this.stemMatchCount/this.totalKeywordMatches*.15;a=Math.max(.5,a-l)}let s=this.calculateVSOConfidenceBoost(e);a=Math.min(1,a+s);let c=this.arabicPrepositionDisambiguation(e,t);return a=Math.max(0,Math.min(1,a+c)),a}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let n=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(n.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(n.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let n=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,a]of t.entries()){let s=i[o];if(!s||s.length===0)continue;let c=a.metadata;if(c&&typeof c.prepositionValue=="string"){let l=c.prepositionValue;s.includes(l)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){let t=e.peek();if(!t)return;let n=t.value.toLowerCase();if(R.ENGLISH_NOISE_WORDS.has(n)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return n?t:void 0}};R.MAX_PROPERTY_DEPTH=10,R.MAX_METHOD_ARGS=20,R.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var D=R,V=new D;var le=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=Ie(t,e.action);if(n.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,n);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return n.join(` ${i} `)}getChainWord(e,t){let n=B(t);return n?.keywords?n.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let n=e;return n.statements.map(o=>this.renderExplicit(o)).join(` ${n.chainType} `)}let t=[e.action];for(let[n,i]of e.roles)t.push(`${n}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let n=e;if(n.body&&n.body.length>0){let i=n.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return ce()}findBestPattern(e,t){let n=t.map(i=>{let o=i.priority;for(let a of i.template.tokens)a.type==="role"&&(e.roles.has(a.role)?o+=10:a.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return n.sort((i,o)=>o.score-i.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let n=[],i=t.language;for(let o of t.template.tokens){let a=this.renderPatternToken(o,e,i);a!==null&&n.push(a)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let a=o.body.map(s=>this.render(s,i));n.push(a.join(" "))}}return n.join(" ")}renderPatternToken(e,t,n){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,n):(e.optional,null)}case"group":{if(!e.tokens.filter(a=>a.type==="role"&&!a.optional).every(a=>t.roles.has(a.role))&&e.optional)return null;if(e.optional&&e.tokens.find(s=>s.type==="role"&&s.role==="destination")){let s=t.roles.get("destination");if(s?.type==="reference"&&s.value==="me")return null}let o=[];for(let a of e.tokens){let s=this.renderPatternToken(a,t,n);s!==null&&o.push(s)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let n=B(t);return n?.references?n.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let n=B(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(n?.possessive?.specialForms&&o){let s=n.possessive.specialForms[o];if(s){let{markerPosition:c,usePossessiveAdjectives:l}=n.possessive;return l&&c==="after-object"?`${i} ${s}`:`${s} ${i}`}}let a=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:s,markerPosition:c,usePossessiveAdjectives:l}=n.possessive;if(l&&o&&c==="after-object")return`${i} ${a}`;if(s)switch(c){case"between":return n.usesSpaces?`${a}${s} ${i}`:`${a}${s}${i}`;case"after-object":return`${a}${s} ${i}`;case"before-property":return`${a} ${s} ${i}`}}return t==="en"||!n?.possessive?a==="me"?`my ${i}`:a==="it"?`its ${i}`:`${a}'s ${i}`:`${a} ${i}`}},Ee=new le;function q(r,e){return Ee.render(r,e)}function H(r){return Ee.renderExplicit(r)}function O(r){let e=r.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let n=vt(t);if(n.length===0)throw new Error("No command specified in explicit statement");let i=n[0].toLowerCase(),o=new Map;for(let s=1;s<n.length;s++){let c=n[s],l=c.indexOf(":");if(l===-1)throw new Error(`Invalid role format: "${c}". Expected role:value`);let m=c.slice(0,l),x=c.slice(l+1);if(m==="body"&&x.startsWith("[")){let h=bt(c,l+1),p=c.slice(l+1,h+1);o.set(m,{type:"expression",raw:p});continue}let y=Et(x);o.set(m,y)}if(i==="on"){let s=o.get("event");if(!s)throw new Error("Event handler requires event role: [on event:click ...]");let c=o.get("body"),l=[];return c&&c.type==="expression"&&l.push(O(c.raw)),o.delete("body"),j(s,l,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,c]of o)a[s]=c;return M(i,a,{sourceLanguage:"explicit"})}function vt(r){let e=[],t="",n=!1,i="",o=0;for(let a=0;a<r.length;a++){let s=r[a];if(n){t+=s,s===i&&r[a-1]!=="\\"&&(n=!1);continue}if(s==='"'||s==="'"){n=!0,i=s,t+=s;continue}if(s==="["){o++,t+=s;continue}if(s==="]"){o--,t+=s;continue}if(s===" "&&o===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function Et(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return L(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return E(t,"string")}if(r==="true")return E(!0,"boolean");if(r==="false")return E(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(r.toLowerCase()))return w(r.toLowerCase());let e=r.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?E(r,"duration"):E(t,"number")}return E(r,"string")}function bt(r,e){let t=0;for(let n=e;n<r.length;n++)if(r[n]==="[")t++;else if(r[n]==="]"&&(t--,t===0))return n;return r.length-1}function K(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var de=class{parse(e,t){let n=se(e,t),i=C(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((m,x)=>x.priority-m.priority),a=o.filter(m=>m.command==="on"),s=V.matchBest(n,a);if(s)return this.buildEventHandler(s,n,t);let c=o.filter(m=>m.command!=="on"),l=V.matchBest(n,c);if(l)return this.buildCommand(l,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return ce()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let n={};for(let[i,o]of e.captured)n[i]=o;return M(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=V.extractEventModifiers(t),a,s=e.captured.get("action");if(s&&s.type==="literal"){let c=s.value,l={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(l[y]=h);let m=M(c,l,{sourceLanguage:n,patternId:e.pattern.id}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=C(n).filter(u=>u.command!=="on").sort((u,g)=>g.priority-u.priority),h=C(n).filter(u=>u.id.startsWith("grammar-")&&u.id.includes("-continuation")).sort((u,g)=>g.priority-u.priority),p=this.parseBodyWithGrammarPatterns(t,y,h,n);p.length>0?a=[m,...p]:a=[m]}else a=[m]}else{let c=C(n).filter(l=>l.command!=="on").sort((l,m)=>m.priority-l.priority);a=this.parseBodyWithClauses(t,c,n)}return j(i,a,o,{sourceLanguage:n,patternId:e.pattern.id})}parseBodyWithClauses(e,t,n){let i=[],o=[];for(;!e.isAtEnd();){let a=e.peek();if(!a)break;let s=a.kind==="conjunction"||a.kind==="keyword"&&this.isThenKeyword(a.value,n),c=a.kind==="keyword"&&this.isEndKeyword(a.value,n);if(s){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l),o.length=0}e.advance();continue}if(c){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l)}e.advance();break}o.push(a),e.advance()}if(o.length>0){let a=this.parseClause(o,t,n);i.push(...a)}return i.length>1?[qe(i,"then",{sourceLanguage:n})]:i}parseClause(e,t,n){if(e.length===0)return[];let i=new z(e,n),o=[];for(;!i.isAtEnd();){let a=V.matchBest(i,t);a?o.push(this.buildCommand(a,n)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,n,i){let o=[];for(;!e.isAtEnd();){let a=e.peek();if(a&&this.isThenKeyword(a.value,i)){e.advance();continue}if(a&&this.isEndKeyword(a.value,i)){e.advance();break}let s=!1;if(n.length>0){let c=V.matchBest(e,n);if(c){let l=c.pattern.command,m={};for(let[h,p]of c.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(m[h]=p);let x=M(l,m,{sourceLanguage:i,patternId:c.pattern.id});o.push(x),s=!0;let y=c.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!s){let c=V.matchBest(e,t);c&&(o.push(this.buildCommand(c,i)),s=!0)}s||e.advance()}return o}isThenKeyword(e,t){let n={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(n[t]||n.en).has(e.toLowerCase())}isEndKeyword(e,t){let n={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(n[t]||n.en).has(e.toLowerCase())}},be=new de;function $(r,e){return be.parse(r,e)}function Te(r,e){return be.canParse(r,e)}function ke(r,e){if(K(r))return r;let t=$(r,e);return H(t)}function Ne(r,e){let t=O(r);return q(t,e)}function Ce(r,e){return K(r)?O(r):$(r,e)}var Tt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),kt=new Set(["and","or","not","no"]),Nt=new Set(["true","false","null","undefined"]),Ct=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ge(r){let e=[],t=0,n=1,i=1;function o(){if(e.length===0)return!0;let p=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(p.type)}function a(p=0){return r[t+p]??""}function s(){let p=r[t];return t++,p===`
|
|
2
|
-
`?(n++,i=1):i++,p}function c(){for(;t<r.length&&/\s/.test(r[t]);)s()}function l(p){let u="";for(;t<r.length&&p(r[t]);)u+=s();return u}function m(p){let u=p;for(s();t<r.length&&r[t]!==p;)r[t]==="\\"&&t+1<r.length&&(u+=s()),u+=s();return t<r.length&&(u+=s()),u}function x(){let p="`";for(s();t<r.length&&r[t]!=="`";)r[t]==="\\"&&t+1<r.length&&(p+=s()),p+=s();return t<r.length&&(p+=s()),p}function y(){let p="<";for(s();t<r.length&&(p+=s(),!p.endsWith("/>")););return p}function h(p,u,g){return{type:p,value:u,start:g,end:t,line:n,column:i-u.length}}for(;t<r.length&&(c(),!(t>=r.length));){let p=t,u=a();if(u==="'"&&a(1)==="s"&&!/\w/.test(a(2))){s(),s(),e.push(h("POSSESSIVE","'s",p));continue}if(u==='"'||u==="'"){let g=m(u);e.push(h("STRING",g,p));continue}if(u==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,p));continue}if(u==="<"&&/[a-zA-Z.#\[]/.test(a(1))){let g=y();e.push(h("QUERY_SELECTOR",g,p));continue}if(u==="#"&&o()){s();let g=l(b=>/[\w-]/.test(b));e.push(h("ID_SELECTOR","#"+g,p));continue}if(u==="."&&/[a-zA-Z_-]/.test(a(1))&&o()){s();let g=l(b=>/[\w-]/.test(b));e.push(h("CLASS_SELECTOR","."+g,p));continue}if(u==="["&&o()){let g=a(1);if(g==="@"||/[a-zA-Z]/.test(g)){let b="";for(b+=s();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?b+=m(r[t]):b+=s();t<r.length&&(b+=s()),e.push(h("ATTRIBUTE_SELECTOR",b,p));continue}}if(u==="["){s(),e.push(h("LBRACKET","[",p));continue}if(u==="]"){s(),e.push(h("RBRACKET","]",p));continue}if(/\d/.test(u)){let g=l(me=>/[\d.]/.test(me)),b=t,Q=l(me=>/[a-zA-Z]/.test(me));Ct.has(Q)?e.push(h("TIME_EXPRESSION",g+Q,p)):(t=b,e.push(h("NUMBER",g,p)));continue}if(u==="("){s(),e.push(h("LPAREN","(",p));continue}if(u===")"){s(),e.push(h("RPAREN",")",p));continue}if(u==="{"){s(),e.push(h("LBRACE","{",p));continue}if(u==="}"){s(),e.push(h("RBRACE","}",p));continue}if(u===","){s(),e.push(h("COMMA",",",p));continue}if(u===":"){s(),e.push(h("COLON",":",p));continue}if(u==="."){s(),e.push(h("DOT",".",p));continue}if(u==="+"||u==="-"||u==="*"||u==="/"||u==="%"){s(),e.push(h("OPERATOR",u,p));continue}if(u==="="||u==="!"||u==="<"||u===">"){let g=s();a()==="="&&(g+=s()),e.push(h("COMPARISON",g,p));continue}if(/[a-zA-Z_$]/.test(u)){let g=l(Q=>/[\w$]/.test(Q)),b=g.toLowerCase();Tt.has(b)?e.push(h("CONTEXT_VAR",g,p)):kt.has(b)?e.push(h("LOGICAL",g,p)):Nt.has(b)?e.push(h("BOOLEAN",g,p)):e.push(h("IDENTIFIER",g,p));continue}s()}return e.push(h("EOF","",t)),e}var pe=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ge(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,n=this.parseAnd();e=this.createBinaryExpression(t,e,n)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,n=this.parseEquality();e=this.createBinaryExpression(t,e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,n=this.parseComparison();e=this.createBinaryExpression(t,e,n)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,n=this.parseAddition();e=this.createBinaryExpression(t,e,n)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,n=this.parseMultiplication();e=this.createBinaryExpression(t,e,n)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,n=this.parseUnary();e=this.createBinaryExpression(t,e,n)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let n;if(this.check("STRING"))n=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))n=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:n,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(n=>({type:"objectProperty",key:n.key,value:n.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let n=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:n,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,n){return{type:"literal",value:e,dataType:t,raw:n.value,start:n.start,end:n.end,line:n.line,column:n.column}}createSelector(e,t,n){return{type:"selector",value:e,selector:e,selectorType:t,start:n.start,end:n.end,line:n.line,column:n.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,n){return{type:"binaryExpression",operator:e,left:t,right:n,start:t.start,end:n.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function we(r){return new pe().parse(r)}function k(r,e){switch(r.type){case"literal":return wt(r);case"selector":return Rt(r,e);case"reference":return Pt(r);case"property-path":return Lt(r,e);case"expression":return Mt(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function wt(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function Rt(r,e){return e&&r.value.startsWith("*")&&/^[a-zA-Z-]/.test(r.value.slice(1))&&e.push(`Converted '${r.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:r.value,selector:r.value,selectorType:r.selectorKind}}function Pt(r){return{type:"contextReference",contextType:r.value,name:r.value}}function Lt(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function Mt(r){let e=we(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function Xe(r,e){return r.roles.get(e)}function d(r,e,t){let n=Xe(r,e);return n?k(n,t):void 0}function f(r,e=[],t,n={}){let i={type:"command",name:r,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),n.isBlocking&&(i.isBlocking=n.isBlocking),n.implicitTarget&&(i.implicitTarget=n.implicitTarget),i}var zt={action:"toggle",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"duration"),o=t?[t]:[],a={};return n&&(a.on=n),i&&(a.for=i),f("toggle",o,a)}},At={action:"add",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("add",i,o)}},Vt={action:"remove",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("remove",i,o)}},Ot={action:"set",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("set",i,o)}},It={action:"show",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.with=i),f("show",o,a)}},_t={action:"hide",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.with=i),f("hide",o,a)}},Bt={action:"increment",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.by=i),f("increment",o,a)}},Wt={action:"decrement",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.by=i),f("decrement",o,a)}},jt={action:"wait",toAST(r,e){let t=d(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Kt={action:"log",toAST(r,e){let t=d(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},$t={action:"put",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=Xe(r,"method"),o=t?[t]:[],a={};if(n){let s=i?.type==="literal"?String(i.value):"into";a[s]=n}return f("put",o,a)}},Ut={action:"fetch",toAST(r,e){let t=d(r,"source"),n=d(r,"method"),i=d(r,"responseType"),o=d(r,"patient"),a=t?[t]:[],s={};return n&&(s.with=n),i&&(s.as=i),o&&(s.body=o),f("fetch",a,s,{isBlocking:!0})}},Ft={action:"append",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("append",i,o)}},Dt={action:"prepend",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("prepend",i,o)}},qt={action:"trigger",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("trigger",i,o)}},Ht={action:"send",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=d(r,"patient"),o=t?[t]:[],a={};return n&&(a.to=n),i&&(a.detail=i),f("send",o,a)}},Gt={action:"go",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("go",i,o)}},Xt={action:"transition",toAST(r,e){let t=d(r,"patient"),n=d(r,"goal"),i=d(r,"duration"),o=d(r,"destination"),a=t?[t]:[],s={};return n&&(s.to=n),i&&(s.over=i),o&&(s.on=o),f("transition",a,s)}},Zt={action:"focus",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={},a=t??n;return a&&i.push(a),f("focus",i,o)}},Qt={action:"blur",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("blur",i)}},Yt={action:"get",toAST(r,e){let t=d(r,"source"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("get",i)}},Jt={action:"take",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("take",i,o)}},en={action:"call",toAST(r,e){let t=d(r,"patient");return f("call",t?[t]:[])}},tn={action:"return",toAST(r,e){let t=d(r,"patient");return f("return",t?[t]:[])}},nn={action:"halt",toAST(r,e){return f("halt",[])}},rn={action:"throw",toAST(r,e){let t=d(r,"patient");return f("throw",t?[t]:[])}},on={action:"settle",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},an={action:"swap",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=d(r,"destination"),o=d(r,"style"),a=[],s={};return t&&a.push(t),n&&a.push(n),i&&(s.on=i),o&&(s.with=o),f("swap",a,s)}},sn={action:"morph",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],a={},s=t??i;return s&&o.push(s),n&&(a.on=n),f("morph",o,a)}},cn={action:"clone",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],a={},s=t??i;return s&&o.push(s),n&&(a.into=n),f("clone",o,a)}},ln={action:"make",toAST(r,e){let t=d(r,"patient");return f("make",t?[t]:[])}},dn={action:"measure",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"source"),o=[],a={};t&&o.push(t);let s=n??i;return s&&(a.of=s),f("measure",o,a)}},pn={action:"tell",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("tell",i)}},un={action:"js",toAST(r,e){let t=d(r,"patient");return f("js",t?[t]:[])}},mn={action:"async",toAST(r,e){return f("async",[])}},fn={action:"if",toAST(r,e){let t=d(r,"condition");return f("if",t?[t]:[])}},gn={action:"unless",toAST(r,e){let t=d(r,"condition");return f("unless",t?[t]:[])}},hn={action:"repeat",toAST(r,e){let t=d(r,"quantity"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("repeat",i)}},yn={action:"for",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.in=n),f("for",i,o)}},xn={action:"while",toAST(r,e){let t=d(r,"condition");return f("while",t?[t]:[])}},Sn={action:"continue",toAST(r,e){return f("continue",[])}},vn={action:"default",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.to=n),f("default",i,o)}},En={action:"init",toAST(r,e){return f("init",[])}},bn={action:"behavior",toAST(r,e){let t=d(r,"patient");return f("behavior",t?[t]:[])}},Tn={action:"install",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("install",i,o)}},kn={action:"on",toAST(r,e){let t=d(r,"event"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("on",i,o)}},Ze=new Map([["toggle",zt],["add",At],["remove",Vt],["set",Ot],["show",It],["hide",_t],["increment",Bt],["decrement",Wt],["wait",jt],["log",Kt],["put",$t],["fetch",Ut],["append",Ft],["prepend",Dt],["get",Yt],["take",Jt],["trigger",qt],["send",Ht],["on",kn],["go",Gt],["transition",Xt],["focus",Zt],["blur",Qt],["call",en],["return",tn],["halt",nn],["throw",rn],["settle",on],["swap",an],["morph",sn],["clone",cn],["measure",dn],["make",ln],["tell",pn],["default",vn],["js",un],["async",mn],["if",fn],["unless",gn],["repeat",hn],["for",yn],["while",xn],["continue",Sn],["init",En],["behavior",bn],["install",Tn]]);function G(r){return Ze.get(r)}function Re(r){Ze.set(r.action,r)}var X=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=G(e.action);if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let i=n;return this.warnings.push(...i.warnings),i.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let s of i){let c=e.roles.get(s);c&&t.push(k(c))}for(let s of o){let c=e.roles.get(s);if(c){let l=this.roleToModifierKey(s);n[l]=k(c)}}let a={type:"command",name:e.action,args:t};return Object.keys(n).length>0?{...a,modifiers:n}: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"),n,i;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(i=g.split(/\s+or\s+|\|/).map(b=>b.trim()),n=i[0]):n=g}else t?.type==="reference"?n=t.value:n="click";let o=e.body.map(g=>this.build(g)),a=e.roles.get("source"),s,c;a?.type==="selector"?(s=a.value,c=a.value):a?.type==="reference"?c=a.value:a?.type==="literal"&&(c=String(a.value));let l=e.roles.get("condition"),m=l?k(l):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,h=e.eventModifiers,p=s;if(h?.from){let g=h.from;g.type==="selector"&&!s&&(p=g.value)}let u=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:n,commands:o,...i&&i.length>1?{events:i}:{},...p?{selector:p}:{},...c?{target:c}:{},...m?{condition:m}:{},...y?{watchTarget:y}:{},...u&&u.length>0?{args:u,params:u}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let n=k(t),i=e.thenBranch.map(s=>this.build(s)),o=e.elseBranch?.map(s=>this.build(s)),a=[n,{type:"block",commands:i}];return o&&o.length>0&&a.push({type:"block",commands:o}),{type:"command",name:"if",args:a}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),n=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&n.push(k(i));break}case"for":{e.loopVariable&&n.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&n.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&n.push(k(i));break}case"forever":break}return n.push({type:"block",commands:t}),{type:"command",name:"repeat",args:n}}buildBlock(e){return{type:"block",commands:e.map(n=>this.build(n))}}};function Qe(r){let e=new X;return{ast:e.build(r),warnings:e.warnings}}var I=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),i=this.cache.get(n);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),i.lastAccessed=Date.now(),this.cache.set(n,i),this.stats.hits++,i.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:n,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),i=this.cache.get(n);return i?this.isExpired(i)?(this.cache.delete(n),this.stats.expirations++,!1):!0:!1}delete(e,t){let n=this.makeKey(e,t);return this.cache.delete(n)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Pe=new I;var Z=class{constructor(e={}){this.patternMatcher=new D,this.languages=new Set(ee()),e.cache===!1?this.cache=new I({enabled:!1}):this.cache=e.cache?new I(e.cache):Pe}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let n=this.cache.get(e,t);if(n)return n;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let n=De(t);if(!n)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=n.tokenize(e),o=C(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let a=this.patternMatcher.matchBest(i,o);if(!a)return{confidence:0,errors:["No pattern matched the input"]};let s=this.buildSemanticNode(a);return{confidence:a.confidence,command:{name:a.pattern.command,roles:a.captured},node:s,tokensConsumed:a.consumedTokens}}catch(n){return{confidence:0,errors:[n instanceof Error?n.message:String(n)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function Ye(r){return new Z(r)}var Le=.5,Je=.8;function et(r,e=Le){return r.confidence>=e&&r.command!==void 0}var Nn="1.0.0-es",ue="es";function Cn(){return[ue]}function tt(r){if(r!==ue)throw new Error(`Idioma no soportado en este paquete: ${r}. Este paquete solo soporta: ${ue}. (Language not supported: ${r}. This bundle only supports: ${ue})`)}function wn(r,e){return tt(e),[...se(r,e).tokens]}function nt(r){return tt(r),C(r)}function Rn(r,e){return nt(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return ct(Pn);})();
|
|
1
|
+
"use strict";var LokaScriptSemanticEs=(()=>{var he=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var dt=Object.prototype.hasOwnProperty;var ut=(r,e)=>{for(var t in e)he(r,t,{get:e[t],enumerable:!0})},pt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of lt(e))!dt.call(r,i)&&i!==t&&he(r,i,{get:()=>e[i],enumerable:!(n=ct(e,i))||n.enumerable});return r};var mt=r=>pt(he({},"__esModule",{value:!0}),r);var Vn={};ut(Vn,{ASTBuilder:()=>J,DEFAULT_CONFIDENCE_THRESHOLD:()=>Ae,HIGH_CONFIDENCE_THRESHOLD:()=>it,SemanticAnalyzerImpl:()=>ee,VERSION:()=>Ln,buildAST:()=>nt,canParse:()=>Ce,createCommandNode:()=>z,createEventHandler:()=>U,createLiteral:()=>b,createPropertyPath:()=>$,createReference:()=>R,createSelector:()=>M,createSemanticAnalyzer:()=>rt,fromExplicit:()=>Re,getCommandMapper:()=>Y,getPatternsForLanguage:()=>st,getPatternsForLanguageAndCommand:()=>An,getProfile:()=>ve,getSupportedLanguages:()=>Mn,getTokenizer:()=>xe,isExplicitSyntax:()=>F,isLanguageSupported:()=>je,parse:()=>D,parseAny:()=>Pe,parseExplicit:()=>j,registerCommandMapper:()=>Me,render:()=>Z,renderExplicit:()=>Q,shouldUseSemanticResult:()=>ot,spanishProfile:()=>_,spanishTokenizer:()=>ce,toExplicit:()=>we,tokenize:()=>zn});var w=new Map,A=new Map,q=new Map;var Ve=null;function Ie(r,e){let t={...r};for(let n of Object.keys(e)){let i=e[n],o=r[n];i!==void 0&&(typeof i=="object"&&i!==null&&!Array.isArray(i)&&typeof o=="object"&&o!==null&&!Array.isArray(o)?t[n]=Ie(o,i):t[n]=i)}return t}function ft(r,e){return Ie(r,e)}function ye(r){if(!r.extends)return r;let e=A.get(r.extends);if(!e)return console.warn(`[Registry] Profile '${r.code}' extends '${r.extends}' but base is not registered. Make sure to import the base language before the variant.`),r;let t=ye(e);return ft(t,r)}function _e(r,e,t){w.set(r,e),A.set(r,t),q.delete(r)}var Oe=new Map;function V(r){return r.split("-")[0]}function O(r){return r.includes("-")}function xe(r){let e=w.get(r);if(!e&&O(r)){let t=V(r);e=w.get(t)}if(!e){let t=Array.from(w.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function ve(r){let e=A.get(r);if(!e&&O(r)){let t=V(r);e=A.get(t)}if(!e){let t=Array.from(A.keys()).join(", ");throw new Error(`Language profile '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return ye(e)}function Be(r){let e=w.get(r);return!e&&O(r)&&(e=w.get(V(r))),e}function K(r){let e=A.get(r);return!e&&O(r)&&(e=A.get(V(r))),e?ye(e):void 0}function ne(){return Array.from(w.keys())}function je(r){return w.has(r)?!0:O(r)?w.has(V(r)):!1}function We(r,e){return xe(e).tokenize(r)}function C(r){let e=q.get(r);if(!e&&O(r)&&(e=q.get(V(r))),e)return e;let t=Oe.get(r);if(!t&&O(r)&&(t=Oe.get(V(r))),t)return q.set(r,t),t;if(!Ve)throw new Error(`No patterns registered for language '${r}'. Either import the language module or set a pattern generator.`);let n=ve(r),i=Ve(n);return q.set(r,i),i}function Ke(r,e){return C(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}var I=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(r,e){return{start:r,end:e}}function S(r,e,t,n){if(typeof n=="string")return{value:r,kind:e,position:t,normalized:n};if(n){let{normalized:i,stem:o,stemConfidence:a}=n,s={value:r,kind:e,position:t};return i!==void 0&&(s.normalized=i),o!==void 0&&(s.stem=o,a!==void 0&&(s.stemConfidence=a)),s}return{value:r,kind:e,position:t}}function L(r){return/\s/.test(r)}function ie(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function oe(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function N(r){return/\d/.test(r)}function $e(r){return/[a-zA-Z]/.test(r)}function T(r){return/[a-zA-Z0-9_-]/.test(r)}function Se(r){let e=n=>r.test(n);return{isLetter:e,isIdentifierChar:n=>e(n)||/[0-9_-]/.test(n)}}function Ue(r,e){if(e>=r.length)return null;let t=r[e];if(!ie(t))return null;let n=e,i="";if(t==="#"||t==="."){for(i+=r[n++];n<r.length&&T(r[n]);)i+=r[n++];if(i.length<=1)return null;if(n<r.length&&r[n]==="."&&t==="#"){let a=n+1;for(;a<r.length&&T(r[a]);)a++;if(a<r.length&&r[a]==="(")return i}}else if(t==="["){let o=1,a=!1,s=null,c=!1;for(i+=r[n++];n<r.length&&o>0;){let l=r[n];i+=l,c?c=!1:l==="\\"?c=!0:a?l===s&&(a=!1,s=null):l==='"'||l==="'"||l==="`"?(a=!0,s=l):l==="["?o++:l==="]"&&o--,n++}if(o!==0)return null}else if(t==="@"){for(i+=r[n++];n<r.length&&T(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="*"){for(i+=r[n++];n<r.length&&T(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="<"){if(i+=r[n++],n>=r.length||!$e(r[n]))return null;for(;n<r.length&&T(r[n]);)i+=r[n++];for(;n<r.length;){let o=r[n];if(o==="."){if(i+=r[n++],n>=r.length||!T(r[n]))return null;for(;n<r.length&&T(r[n]);)i+=r[n++]}else if(o==="#"){if(i+=r[n++],n>=r.length||!T(r[n]))return null;for(;n<r.length&&T(r[n]);)i+=r[n++]}else if(o==="["){let a=1,s=!1,c=null,l=!1;for(i+=r[n++];n<r.length&&a>0;){let m=r[n];i+=m,l?l=!1:m==="\\"?l=!0:s?m===c&&(s=!1,c=null):m==='"'||m==="'"||m==="`"?(s=!0,c=m):m==="["?a++:m==="]"&&a--,n++}if(a!==0)return null}else break}for(;n<r.length&&L(r[n]);)i+=r[n++];if(n<r.length&&r[n]==="/")for(i+=r[n++];n<r.length&&L(r[n]);)i+=r[n++];if(n>=r.length||r[n]!==">")return null;i+=r[n++]}return i||null}function gt(r,e){if(e>=r.length||r[e]!=="'"||e+1>=r.length||r[e+1].toLowerCase()!=="s")return!1;if(e+2>=r.length)return!0;let n=r[e+2];return L(n)||n==="*"||!T(n)}function Fe(r,e){if(e>=r.length)return null;let t=r[e];if(!oe(t)||t==="'"&>(r,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,a=t,s=!1;for(;o<r.length;){let c=r[o];if(a+=c,s)s=!1;else if(c==="\\")s=!0;else if(c===i)return a;o++}return a}function ae(r,e){if(e>=r.length)return!1;let t=r[e],n=r[e+1]||"",i=r[e+2]||"";if(t==="/"&&n!=="/"&&/[a-zA-Z0-9._-]/.test(n)||t==="/"&&n==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(n==="/"||n==="."&&i==="/"))return!0;let o=r.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function De(r,e){if(!ae(r,e))return null;let t=e,n="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<r.length;){let o=r[t];if(o==="#"){if(n.length>0&&/[a-zA-Z0-9/.]$/.test(n))for(n+=o,t++;t<r.length&&/[a-zA-Z0-9_-]/.test(r[t]);)n+=r[t++];break}if(i.test(o))n+=o,t++;else break}return n.length<2?null:n}function qe(r,e){if(e>=r.length)return null;let t=r[e];if(!N(t)&&t!=="-"&&t!=="+")return null;let n=e,i="";if((r[n]==="-"||r[n]==="+")&&(i+=r[n++]),n>=r.length||!N(r[n]))return null;for(;n<r.length&&N(r[n]);)i+=r[n++];if(n<r.length&&r[n]===".")for(i+=r[n++];n<r.length&&N(r[n]);)i+=r[n++];return n<r.length&&(r.slice(n,n+2)==="ms"?i+="ms":(r[n]==="s"||r[n]==="m"||r[n]==="h")&&(i+=r[n])),i}var re=class re{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let n=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(n.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let a of o.alternatives)n.set(a,{native:a,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))n.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&n.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let a of o.alternatives)n.set(a,{native:a,normalized:i})}for(let i of t)n.set(i.native,i);this.profileKeywords=Array.from(n.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let n of this.profileKeywords)if(e.slice(t).startsWith(n.native))return S(n.native,"keyword",v(t,t+n.native.length),n.normalized);return null}isKeywordStart(e,t){let n=e.slice(t);return this.profileKeywords.some(i=>n.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,n){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let a={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return S(e,"keyword",v(t,n),a)}trySelector(e,t){let n=Ue(e,t);return n?S(n,"selector",v(t,t+n.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let n=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!n)return null;let i=n[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],a=n[1];return{...S(i,"event-modifier",v(t,t+i.length)),metadata:{modifierName:o,value:a?o==="queue"?a:parseInt(a,10):void 0}}}tryString(e,t){let n=Fe(e,t);return n?S(n,"literal",v(t,t+n.length)):null}tryNumber(e,t){let n=qe(e,t);return n?S(n,"literal",v(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,i=!1){let o=t;if(i)for(;o<e.length&&L(e[o]);)o++;let a=e.slice(o);for(let s of n){let c=a.slice(0,s.length);if(s.caseInsensitive?c.toLowerCase()===s.pattern.toLowerCase():c===s.pattern){if(s.notFollowedBy&&(a[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let m=a[s.length]||"";if(T(m))continue}return{suffix:s.suffix,endPos:o+s.length}}}return null}parseBaseNumber(e,t,n=!0){let i=t,o="";if(n&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!N(e[i]))return null;for(;i<e.length&&N(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&N(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,n,i={}){let{allowSign:o=!0,skipWhitespace:a=!1}=i,s=this.parseBaseNumber(e,t,o);if(!s)return null;let{number:c,endPos:l}=s,m=[...n,...re.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,l,m,a);return x&&(c+=x.suffix,l=x.endPos),S(c,"literal",v(t,l))}tryUrl(e,t){let n=De(e,t);return n?S(n,"url",v(t,t+n.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!T(e[t+1]))return null;let n=t+1;for(;n<e.length&&T(e[n]);)n++;let i=e.slice(t,n);return S(i,"identifier",v(t,n))}tryOperator(e,t){let n=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(n))return S(n,"operator",v(t,t+2));let i=e[t];return["<",">","!","+","-","*","/","="].includes(i)?S(i,"operator",v(t,t+1)):["(",")","{","}",",",";",":"].includes(i)?S(i,"punctuation",v(t,t+1)):null}tryMultiCharParticle(e,t,n){for(let i of n)if(e.slice(t,t+i.length)===i)return S(i,"particle",v(t,t+i.length));return null}};re.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var H=re;function be(r){return{stem:r,confidence:1}}function se(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}function ht(r){return/[áéíóúüñÁÉÍÓÚÜÑ]/.test(r)}function yt(r){let e=r.toLowerCase();if(e.endsWith("ar")||e.endsWith("er")||e.endsWith("ir")||e.endsWith("ando")||e.endsWith("iendo")||e.endsWith("ado")||e.endsWith("ido")||e.endsWith("arse")||e.endsWith("erse")||e.endsWith("irse"))return!0;for(let t of r)if(ht(t))return!0;return!1}var He=["se","me","te","nos","os"],xt=[{ending:"ando",stem:"ar",confidence:.88,type:"gerund"},{ending:"ado",stem:"ar",confidence:.88,type:"participle"},{ending:"ada",stem:"ar",confidence:.88,type:"participle"},{ending:"ados",stem:"ar",confidence:.88,type:"participle"},{ending:"adas",stem:"ar",confidence:.88,type:"participle"},{ending:"o",stem:"ar",confidence:.75,type:"present"},{ending:"as",stem:"ar",confidence:.82,type:"present"},{ending:"a",stem:"ar",confidence:.75,type:"present"},{ending:"amos",stem:"ar",confidence:.85,type:"present"},{ending:"\xE1is",stem:"ar",confidence:.85,type:"present"},{ending:"ais",stem:"ar",confidence:.82,type:"present"},{ending:"an",stem:"ar",confidence:.8,type:"present"},{ending:"\xE9",stem:"ar",confidence:.85,type:"past"},{ending:"aste",stem:"ar",confidence:.88,type:"past"},{ending:"\xF3",stem:"ar",confidence:.82,type:"past"},{ending:"amos",stem:"ar",confidence:.85,type:"past"},{ending:"asteis",stem:"ar",confidence:.88,type:"past"},{ending:"aron",stem:"ar",confidence:.88,type:"past"},{ending:"aba",stem:"ar",confidence:.88,type:"past"},{ending:"abas",stem:"ar",confidence:.88,type:"past"},{ending:"\xE1bamos",stem:"ar",confidence:.88,type:"past"},{ending:"abamos",stem:"ar",confidence:.85,type:"past"},{ending:"abais",stem:"ar",confidence:.88,type:"past"},{ending:"aban",stem:"ar",confidence:.88,type:"past"},{ending:"e",stem:"ar",confidence:.72,type:"subjunctive"},{ending:"es",stem:"ar",confidence:.78,type:"subjunctive"},{ending:"emos",stem:"ar",confidence:.82,type:"subjunctive"},{ending:"\xE9is",stem:"ar",confidence:.85,type:"subjunctive"},{ending:"eis",stem:"ar",confidence:.82,type:"subjunctive"},{ending:"en",stem:"ar",confidence:.78,type:"subjunctive"},{ending:"a",stem:"ar",confidence:.75,type:"imperative"},{ending:"ad",stem:"ar",confidence:.85,type:"imperative"},{ending:"ar",stem:"ar",confidence:.92,type:"dictionary"}],vt=[{ending:"iendo",stem:"er",confidence:.88,type:"gerund"},{ending:"ido",stem:"er",confidence:.85,type:"participle"},{ending:"ida",stem:"er",confidence:.85,type:"participle"},{ending:"idos",stem:"er",confidence:.85,type:"participle"},{ending:"idas",stem:"er",confidence:.85,type:"participle"},{ending:"o",stem:"er",confidence:.72,type:"present"},{ending:"es",stem:"er",confidence:.78,type:"present"},{ending:"e",stem:"er",confidence:.72,type:"present"},{ending:"emos",stem:"er",confidence:.85,type:"present"},{ending:"\xE9is",stem:"er",confidence:.85,type:"present"},{ending:"eis",stem:"er",confidence:.82,type:"present"},{ending:"en",stem:"er",confidence:.78,type:"present"},{ending:"\xED",stem:"er",confidence:.85,type:"past"},{ending:"iste",stem:"er",confidence:.88,type:"past"},{ending:"i\xF3",stem:"er",confidence:.85,type:"past"},{ending:"io",stem:"er",confidence:.82,type:"past"},{ending:"imos",stem:"er",confidence:.85,type:"past"},{ending:"isteis",stem:"er",confidence:.88,type:"past"},{ending:"ieron",stem:"er",confidence:.88,type:"past"},{ending:"\xEDa",stem:"er",confidence:.88,type:"past"},{ending:"ia",stem:"er",confidence:.85,type:"past"},{ending:"\xEDas",stem:"er",confidence:.88,type:"past"},{ending:"ias",stem:"er",confidence:.85,type:"past"},{ending:"\xEDamos",stem:"er",confidence:.88,type:"past"},{ending:"iamos",stem:"er",confidence:.85,type:"past"},{ending:"\xEDais",stem:"er",confidence:.88,type:"past"},{ending:"iais",stem:"er",confidence:.85,type:"past"},{ending:"\xEDan",stem:"er",confidence:.88,type:"past"},{ending:"ian",stem:"er",confidence:.85,type:"past"},{ending:"er",stem:"er",confidence:.92,type:"dictionary"}],St=[{ending:"iendo",stem:"ir",confidence:.88,type:"gerund"},{ending:"ido",stem:"ir",confidence:.85,type:"participle"},{ending:"ida",stem:"ir",confidence:.85,type:"participle"},{ending:"idos",stem:"ir",confidence:.85,type:"participle"},{ending:"idas",stem:"ir",confidence:.85,type:"participle"},{ending:"o",stem:"ir",confidence:.72,type:"present"},{ending:"es",stem:"ir",confidence:.78,type:"present"},{ending:"e",stem:"ir",confidence:.72,type:"present"},{ending:"imos",stem:"ir",confidence:.85,type:"present"},{ending:"\xEDs",stem:"ir",confidence:.85,type:"present"},{ending:"is",stem:"ir",confidence:.82,type:"present"},{ending:"en",stem:"ir",confidence:.78,type:"present"},{ending:"\xED",stem:"ir",confidence:.85,type:"past"},{ending:"iste",stem:"ir",confidence:.88,type:"past"},{ending:"i\xF3",stem:"ir",confidence:.85,type:"past"},{ending:"io",stem:"ir",confidence:.82,type:"past"},{ending:"imos",stem:"ir",confidence:.85,type:"past"},{ending:"isteis",stem:"ir",confidence:.88,type:"past"},{ending:"ieron",stem:"ir",confidence:.88,type:"past"},{ending:"\xEDa",stem:"ir",confidence:.88,type:"past"},{ending:"ia",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDas",stem:"ir",confidence:.88,type:"past"},{ending:"ias",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDamos",stem:"ir",confidence:.88,type:"past"},{ending:"iamos",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDais",stem:"ir",confidence:.88,type:"past"},{ending:"iais",stem:"ir",confidence:.85,type:"past"},{ending:"\xEDan",stem:"ir",confidence:.88,type:"past"},{ending:"ian",stem:"ir",confidence:.85,type:"past"},{ending:"ir",stem:"ir",confidence:.92,type:"dictionary"}],bt=[...xt,...vt,...St].sort((r,e)=>e.ending.length-r.ending.length),G=class{constructor(){this.language="es"}isNormalizable(e){return e.length<3?!1:yt(e)}normalize(e){let t=e.toLowerCase();if((t.endsWith("ar")||t.endsWith("er")||t.endsWith("ir"))&&!He.some(o=>t.endsWith(o+"ar")||t.endsWith(o+"er")||t.endsWith(o+"ir")))return be(e);let n=this.tryReflexiveNormalization(t);if(n)return n;let i=this.tryConjugationNormalization(t);return i||be(e)}tryReflexiveNormalization(e){for(let t of He)if(e.endsWith(t)){let n=e.slice(0,-t.length);if(n.endsWith("ar")||n.endsWith("er")||n.endsWith("ir"))return se(n,.88,{removedSuffixes:[t],conjugationType:"reflexive"});let i=this.tryConjugationNormalization(n);if(i&&i.stem!==n)return se(i.stem,i.confidence*.95,{removedSuffixes:[t,...i.metadata?.removedSuffixes||[]],conjugationType:"reflexive"})}return null}tryConjugationNormalization(e){for(let t of bt)if(e.endsWith(t.ending)){let n=e.slice(0,-t.ending.length);if(n.length<2)continue;let i=n+t.stem;return se(i,t.confidence,{removedSuffixes:[t.ending],conjugationType:t.type})}return null}},Wn=new G;var _={code:"es",name:"Spanish",nativeName:"Espa\xF1ol",direction:"ltr",wordOrder:"SVO",markingStrategy:"preposition",usesSpaces:!0,defaultVerbForm:"infinitive",verb:{position:"start",subjectDrop:!0},references:{me:"yo",it:"ello",you:"t\xFA",result:"resultado",event:"evento",target:"objetivo",body:"cuerpo"},possessive:{marker:"de",markerPosition:"before-property",usePossessiveAdjectives:!0,specialForms:{me:"mi",it:"su",you:"tu"},keywords:{mi:"me",tu:"you",su:"it"}},roleMarkers:{destination:{primary:"en",alternatives:["sobre","a"],position:"before"},source:{primary:"de",alternatives:["desde"],position:"before"},patient:{primary:"",position:"before"},style:{primary:"con",position:"before"}},keywords:{toggle:{primary:"alternar",alternatives:["cambiar","conmutar"],normalized:"toggle"},add:{primary:"agregar",alternatives:["a\xF1adir"],normalized:"add"},remove:{primary:"quitar",alternatives:["eliminar","remover","sacar"],normalized:"remove"},put:{primary:"poner",alternatives:["colocar"],normalized:"put"},append:{primary:"a\xF1adir",normalized:"append"},prepend:{primary:"anteponer",normalized:"prepend"},take:{primary:"tomar",normalized:"take"},make:{primary:"hacer",alternatives:["crear"],normalized:"make"},clone:{primary:"clonar",alternatives:["copiar"],normalized:"clone"},swap:{primary:"intercambiar",alternatives:["cambiar"],normalized:"swap"},morph:{primary:"transformar",alternatives:["convertir"],normalized:"morph"},set:{primary:"establecer",alternatives:["fijar","definir"],normalized:"set"},get:{primary:"obtener",alternatives:["conseguir"],normalized:"get"},increment:{primary:"incrementar",alternatives:["aumentar"],normalized:"increment"},decrement:{primary:"decrementar",alternatives:["disminuir"],normalized:"decrement"},log:{primary:"registrar",alternatives:["imprimir"],normalized:"log"},show:{primary:"mostrar",alternatives:["ense\xF1ar"],normalized:"show"},hide:{primary:"ocultar",alternatives:["esconder"],normalized:"hide"},transition:{primary:"transici\xF3n",alternatives:["animar"],normalized:"transition"},on:{primary:"en",alternatives:["cuando","al"],normalized:"on"},trigger:{primary:"disparar",alternatives:["activar"],normalized:"trigger"},send:{primary:"enviar",normalized:"send"},focus:{primary:"enfocar",normalized:"focus"},blur:{primary:"desenfocar",normalized:"blur"},click:{primary:"clic",alternatives:["hacer clic"],normalized:"click"},hover:{primary:"sobrevolar",alternatives:["pasar por encima"],normalized:"hover"},submit:{primary:"env\xEDo",alternatives:["enviar"],normalized:"submit"},input:{primary:"entrada",alternatives:["introducir"],normalized:"input"},change:{primary:"cambio",alternatives:["cambiar"],normalized:"change"},go:{primary:"ir",alternatives:["navegar"],normalized:"go"},wait:{primary:"esperar",normalized:"wait"},fetch:{primary:"buscar",alternatives:["obtener"],normalized:"fetch"},settle:{primary:"estabilizar",normalized:"settle"},if:{primary:"si",normalized:"if"},when:{primary:"cuando",normalized:"when"},where:{primary:"donde",normalized:"where"},else:{primary:"sino",alternatives:["de lo contrario"],normalized:"else"},repeat:{primary:"repetir",normalized:"repeat"},for:{primary:"para",normalized:"for"},while:{primary:"mientras",normalized:"while"},continue:{primary:"continuar",normalized:"continue"},halt:{primary:"detener",alternatives:["parar"],normalized:"halt"},throw:{primary:"lanzar",alternatives:["arrojar"],normalized:"throw"},call:{primary:"llamar",normalized:"call"},return:{primary:"retornar",alternatives:["devolver"],normalized:"return"},then:{primary:"entonces",alternatives:["luego","despu\xE9s"],normalized:"then"},and:{primary:"y",alternatives:["adem\xE1s","tambi\xE9n"],normalized:"and"},end:{primary:"fin",alternatives:["final","terminar"],normalized:"end"},js:{primary:"js",normalized:"js"},async:{primary:"as\xEDncrono",normalized:"async"},tell:{primary:"decir",normalized:"tell"},default:{primary:"predeterminar",alternatives:["por defecto"],normalized:"default"},init:{primary:"iniciar",alternatives:["inicializar"],normalized:"init"},behavior:{primary:"comportamiento",normalized:"behavior"},install:{primary:"instalar",normalized:"install"},measure:{primary:"medir",normalized:"measure"},into:{primary:"en",alternatives:["dentro de"],normalized:"into"},before:{primary:"antes",normalized:"before"},after:{primary:"despu\xE9s",normalized:"after"},until:{primary:"hasta",normalized:"until"},event:{primary:"evento",normalized:"event"},from:{primary:"de",alternatives:["desde"],normalized:"from"}},eventHandler:{keyword:{primary:"al",alternatives:["cuando","en"],normalized:"on"},sourceMarker:{primary:"de",alternatives:["desde"],position:"before"},eventMarker:{primary:"al",alternatives:["cuando"],position:"before"},temporalMarkers:["cuando","al"]}};var{isLetter:Ge,isIdentifierChar:Et}=Se(/[a-zA-ZáéíóúüñÁÉÍÓÚÜÑ]/),Tt=[{pattern:"milisegundos",suffix:"ms",length:12,caseInsensitive:!0},{pattern:"milisegundo",suffix:"ms",length:11,caseInsensitive:!0},{pattern:"segundos",suffix:"s",length:8,caseInsensitive:!0},{pattern:"segundo",suffix:"s",length:7,caseInsensitive:!0},{pattern:"minutos",suffix:"m",length:7,caseInsensitive:!0},{pattern:"minuto",suffix:"m",length:6,caseInsensitive:!0},{pattern:"horas",suffix:"h",length:5,caseInsensitive:!0},{pattern:"hora",suffix:"h",length:4,caseInsensitive:!0}],Xe=new Set(["en","a","de","desde","hasta","con","sin","por","para","sobre","entre","antes","despu\xE9s","despues","dentro","fuera","al","del"]),kt=[{native:"verdadero",normalized:"true"},{native:"falso",normalized:"false"},{native:"nulo",normalized:"null"},{native:"indefinido",normalized:"undefined"},{native:"primero",normalized:"first"},{native:"primera",normalized:"first"},{native:"\xFAltimo",normalized:"last"},{native:"ultima",normalized:"last"},{native:"siguiente",normalized:"next"},{native:"anterior",normalized:"previous"},{native:"cercano",normalized:"closest"},{native:"padre",normalized:"parent"},{native:"clic",normalized:"click"},{native:"click",normalized:"click"},{native:"hacer clic",normalized:"click"},{native:"entrada",normalized:"input"},{native:"cambio",normalized:"change"},{native:"env\xEDo",normalized:"submit"},{native:"envio",normalized:"submit"},{native:"tecla abajo",normalized:"keydown"},{native:"tecla arriba",normalized:"keyup"},{native:"rat\xF3n encima",normalized:"mouseover"},{native:"raton encima",normalized:"mouseover"},{native:"rat\xF3n fuera",normalized:"mouseout"},{native:"raton fuera",normalized:"mouseout"},{native:"enfoque",normalized:"focus"},{native:"desenfoque",normalized:"blur"},{native:"carga",normalized:"load"},{native:"desplazamiento",normalized:"scroll"},{native:"yo",normalized:"me"},{native:"m\xED",normalized:"me"},{native:"mi",normalized:"me"},{native:"ello",normalized:"it"},{native:"resultado",normalized:"result"},{native:"objetivo",normalized:"target"},{native:"destino",normalized:"target"},{native:"segundo",normalized:"s"},{native:"segundos",normalized:"s"},{native:"milisegundo",normalized:"ms"},{native:"milisegundos",normalized:"ms"},{native:"minuto",normalized:"m"},{native:"minutos",normalized:"m"},{native:"hora",normalized:"h"},{native:"horas",normalized:"h"},{native:"de lo contrario",normalized:"else"},{native:"hasta que",normalized:"until"},{native:"antes de",normalized:"before"},{native:"despu\xE9s de",normalized:"after"},{native:"despues de",normalized:"after"},{native:"dentro de",normalized:"into"},{native:"fuera de",normalized:"out"},{native:"asincrono",normalized:"async"},{native:"despues",normalized:"after"},{native:"a\xF1adir",normalized:"add"},{native:"toggle",normalized:"toggle"},{native:"borrar",normalized:"remove"},{native:"pon",normalized:"put"},{native:"crear",normalized:"make"},{native:"y",normalized:"and"},{native:"o",normalized:"or"},{native:"no",normalized:"not"},{native:"es",normalized:"is"},{native:"existe",normalized:"exists"},{native:"vac\xEDo",normalized:"empty"},{native:"vacio",normalized:"empty"}],Ee=class extends H{constructor(){super();this.language="es";this.direction="ltr";this.initializeKeywordsFromProfile(_,kt),this.normalizer=new G}tokenize(t){let n=[],i=0;for(;i<t.length;){if(L(t[i])){i++;continue}if(ie(t[i])){let c=this.tryEventModifier(t,i);if(c){n.push(c),i=c.position.end;continue}let l=this.trySelector(t,i);if(l){n.push(l),i=l.position.end;continue}}if(oe(t[i])){let c=this.tryString(t,i);if(c){n.push(c),i=c.position.end;continue}}if(ae(t,i)){let c=this.tryUrl(t,i);if(c){n.push(c),i=c.position.end;continue}}if(N(t[i])||t[i]==="-"&&i+1<t.length&&N(t[i+1])){let c=this.extractSpanishNumber(t,i);if(c){n.push(c),i=c.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){n.push(o),i=o.position.end;continue}let a=this.tryMultiWordPhrase(t,i);if(a){n.push(a),i=a.position.end;continue}if(Ge(t[i])){let c=this.extractSpanishWord(t,i);if(c){n.push(c),i=c.position.end;continue}}let s=this.tryOperator(t,i);if(s){n.push(s),i=s.position.end;continue}i++}return new I(n,"es")}classifyToken(t){let n=t.toLowerCase();return Xe.has(n)?"particle":this.isKeyword(n)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||/^\d/.test(t)?"literal":["==","!=","<=",">=","<",">","&&","||","!"].includes(t)?"operator":"identifier"}tryMultiWordPhrase(t,n){for(let i of this.profileKeywords){if(!i.native.includes(" "))continue;let o=i.native;if(t.slice(n,n+o.length).toLowerCase()===o.toLowerCase()){let s=n+o.length;if(s>=t.length||L(t[s])||!Ge(t[s]))return S(t.slice(n,n+o.length),"keyword",v(n,s),i.normalized)}}return null}extractSpanishWord(t,n){let i=n,o="";for(;i<t.length&&Et(t[i]);)o+=t[i++];if(!o)return null;let a=o.toLowerCase();if(Xe.has(a))return S(o,"particle",v(n,i));let s=this.lookupKeyword(a);if(s)return S(o,"keyword",v(n,i),s.normalized);let c=this.tryMorphKeywordMatch(a,n,i);return c||S(o,"identifier",v(n,i))}extractSpanishNumber(t,n){return this.tryNumberWithTimeUnits(t,n,Tt,{allowSign:!0,skipWhitespace:!0})}},ce=new Ee;_e("es",ce,_);function Ze(r){return Be(r)}function le(r,e){return We(r,e)}function de(){return ne()}function M(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function b(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function R(r){return{type:"reference",value:r}}function $(r,e){return{type:"property-path",object:r,property:e}}function z(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function U(r,e,t,n,i){let o=new Map;o.set("event",r);let a={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(a.eventModifiers=t),n!==void 0&&(a.metadata=n),i!==void 0&&i.length>0&&(a.parameterNames=i),a}function Qe(r,e="then",t){let n={kind:"compound",action:"compound",roles:new Map,statements:r,chainType:e};return t!==void 0&&(n.metadata=t),n}function Te(r,e){return!e||e.length===0||e.includes(r)||e.includes("expression")?!0:r==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function Ye(r,e){return r.possessive?.keywords?.[e]}var P=class P{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let n=e.mark(),i=new Map;if(this.currentProfile=K(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(n),null;let a=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-n.position,confidence:a}}matchBest(e,t){let n=[];for(let o of t){let a=e.mark(),s=this.matchPattern(e,o);s&&n.push(s),e.reset(a)}if(n.length===0)return null;n.sort((o,a)=>{let s=a.pattern.priority-o.pattern.priority;return s!==0?s:a.confidence-o.confidence});let i=n[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,n){let i=t[0],o=i?.type==="literal"&&(i.value==="and"||i.value==="then"||i.alternatives?.includes("and")||i.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!o)for(;e.peek()?.kind==="conjunction";)e.advance();for(let a of t)if(!this.matchPatternToken(e,a,n)){if(this.isOptional(a))continue;return!1}return!0}matchPatternToken(e,t,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,n);case"group":return this.matchGroupToken(e,t,n);default:return!1}}matchLiteralToken(e,t){let n=e.peek();if(!n)return!1;let i=this.getMatchType(n,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let a=this.getMatchType(n,o);if(a!=="none")return this.totalKeywordMatches++,a==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,o),!0);let 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:(n.set(t.role,a),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!Te(s.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,s),!0);let c=this.tryMatchPropertyAccessExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,c),!0);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!Te(l.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,l),!0);let m=this.tokenToSemanticValue(i);return!m||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(m.type)?t.optional||!1:(n.set(t.role,m),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let n=(t.normalized||t.value).toLowerCase(),i=Ye(this.currentProfile,n);if(!i)return null;let o=e.mark();e.advance();let a=e.peek();return a&&(a.kind==="identifier"||a.kind==="keyword"&&!this.isStructuralKeyword(a.value)||a.kind==="selector"&&a.value.startsWith("*"))?(e.advance(),$(R(i),a.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let a=e.peek();if(!a||a.kind!=="punctuation"||a.value!=="(")return e.reset(n),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<P.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}s.push(l.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let a=`${t.value}.${o.value}`,s=1;for(;!e.isAtEnd()&&s<P.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let m=e.peek();if(!m||m.kind!=="identifier")break;e.advance(),a+=`.${m.value}`,s++}let c=e.peek();if(c&&c.kind==="punctuation"&&c.value==="("){e.advance();let l=[],m=0;for(;!e.isAtEnd()&&l.length<P.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}l.push(y.value),e.advance()}return{type:"expression",raw:`${a}(${l.join(", ")})`}}return{type:"expression",raw:a}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(n),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(n),null):(e.advance(),$(M(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(n),null;let o=e.peek(1);o&&o.kind,e.advance();let a=i.value.slice(1);return $(M(t.value),a)}matchGroupToken(e,t,n){let i=e.mark(),o=new Set(n.keys());if(!this.matchTokenSequence(e,t.tokens,n)){e.reset(i);for(let s of n.keys())o.has(s)||n.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 M(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):b(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return R(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?R(n):{type:"expression",raw:e.value};case"url":return b(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let i=e.slice(1,-1);return b(i,"string")}if(e==="true")return b(!0,"boolean");if(e==="false")return b(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let i=parseFloat(t[1]);return t[2]?b(e,"duration"):b(i,"number")}let n=parseFloat(e);return isNaN(n)?b(e,"string"):b(n,"number")}applyExtractionRules(e,t){for(let[n,i]of Object.entries(e.extraction))!t.has(n)&&i.default&&t.set(n,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let n=0,i=0,o=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")i+=1,t.has(l.role)&&(n+=1);else if(l.type==="group"){for(let m of l.tokens)if(m.type==="role"){let x=o(m.role),y=.8;i+=y,t.has(m.role)?n+=y:x&&(n+=y*.6)}}let a=i>0?n/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let l=this.stemMatchCount/this.totalKeywordMatches*.15;a=Math.max(.5,a-l)}let s=this.calculateVSOConfidenceBoost(e);a=Math.min(1,a+s);let c=this.arabicPrepositionDisambiguation(e,t);return a=Math.max(0,Math.min(1,a+c)),a}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let n=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(n.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(n.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let n=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,a]of t.entries()){let s=i[o];if(!s||s.length===0)continue;let c=a.metadata;if(c&&typeof c.prepositionValue=="string"){let l=c.prepositionValue;s.includes(l)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){let t=e.peek();if(!t)return;let n=t.value.toLowerCase();if(P.ENGLISH_NOISE_WORDS.has(n)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return n?t:void 0}};P.MAX_PROPERTY_DEPTH=10,P.MAX_METHOD_ARGS=20,P.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var X=P,B=new X;var ue=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=Ke(t,e.action);if(n.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,n);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return n.join(` ${i} `)}getChainWord(e,t){let n=K(t);return n?.keywords?n.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let n=e;return n.statements.map(o=>this.renderExplicit(o)).join(` ${n.chainType} `)}let t=[e.action];for(let[n,i]of e.roles)t.push(`${n}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let n=e;if(n.body&&n.body.length>0){let i=n.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return de()}findBestPattern(e,t){let n=t.map(i=>{let o=i.priority;for(let a of i.template.tokens)a.type==="role"&&(e.roles.has(a.role)?o+=10:a.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return n.sort((i,o)=>o.score-i.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let n=[],i=t.language;for(let o of t.template.tokens){let a=this.renderPatternToken(o,e,i);a!==null&&n.push(a)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let a=o.body.map(s=>this.render(s,i));n.push(a.join(" "))}}return n.join(" ")}renderPatternToken(e,t,n){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,n):(e.optional,null)}case"group":{if(!e.tokens.filter(a=>a.type==="role"&&!a.optional).every(a=>t.roles.has(a.role))&&e.optional)return null;if(e.optional&&e.tokens.find(s=>s.type==="role"&&s.role==="destination")){let s=t.roles.get("destination");if(s?.type==="reference"&&s.value==="me")return null}let o=[];for(let a of e.tokens){let s=this.renderPatternToken(a,t,n);s!==null&&o.push(s)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let n=K(t);return n?.references?n.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let n=K(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(n?.possessive?.specialForms&&o){let s=n.possessive.specialForms[o];if(s){let{markerPosition:c,usePossessiveAdjectives:l}=n.possessive;return l&&c==="after-object"?`${i} ${s}`:`${s} ${i}`}}let a=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:s,markerPosition:c,usePossessiveAdjectives:l}=n.possessive;if(l&&o&&c==="after-object")return`${i} ${a}`;if(s)switch(c){case"between":return n.usesSpaces?`${a}${s} ${i}`:`${a}${s}${i}`;case"after-object":return`${a}${s} ${i}`;case"before-property":return`${a} ${s} ${i}`}}return t==="en"||!n?.possessive?a==="me"?`my ${i}`:a==="it"?`its ${i}`:`${a}'s ${i}`:`${a} ${i}`}},ke=new ue;function Z(r,e){return ke.render(r,e)}function Q(r){return ke.renderExplicit(r)}function j(r){let e=r.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let n=Nt(t);if(n.length===0)throw new Error("No command specified in explicit statement");let i=n[0].toLowerCase(),o=new Map;for(let s=1;s<n.length;s++){let c=n[s],l=c.indexOf(":");if(l===-1)throw new Error(`Invalid role format: "${c}". Expected role:value`);let m=c.slice(0,l),x=c.slice(l+1);if(m==="body"&&x.startsWith("[")){let h=wt(c,l+1),u=c.slice(l+1,h+1);o.set(m,{type:"expression",raw:u});continue}let y=Ct(x);o.set(m,y)}if(i==="on"){let s=o.get("event");if(!s)throw new Error("Event handler requires event role: [on event:click ...]");let c=o.get("body"),l=[];return c&&c.type==="expression"&&l.push(j(c.raw)),o.delete("body"),U(s,l,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,c]of o)a[s]=c;return z(i,a,{sourceLanguage:"explicit"})}function Nt(r){let e=[],t="",n=!1,i="",o=0;for(let a=0;a<r.length;a++){let s=r[a];if(n){t+=s,s===i&&r[a-1]!=="\\"&&(n=!1);continue}if(s==='"'||s==="'"){n=!0,i=s,t+=s;continue}if(s==="["){o++,t+=s;continue}if(s==="]"){o--,t+=s;continue}if(s===" "&&o===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function Ct(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return M(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return b(t,"string")}if(r==="true")return b(!0,"boolean");if(r==="false")return b(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(r.toLowerCase()))return R(r.toLowerCase());let e=r.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?b(r,"duration"):b(t,"number")}return b(r,"string")}function wt(r,e){let t=0;for(let n=e;n<r.length;n++)if(r[n]==="[")t++;else if(r[n]==="]"&&(t--,t===0))return n;return r.length-1}function F(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var pe=class{parse(e,t){let n=le(e,t),i=C(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((m,x)=>x.priority-m.priority),a=o.filter(m=>m.command==="on"),s=B.matchBest(n,a);if(s)return this.buildEventHandler(s,n,t);let c=o.filter(m=>m.command!=="on"),l=B.matchBest(n,c);if(l)return this.buildCommand(l,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return de()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let n={};for(let[i,o]of e.captured)n[i]=o;return z(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=B.extractEventModifiers(t),a,s=e.captured.get("action");if(s&&s.type==="literal"){let c=s.value,l={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(l[y]=h);let m=z(c,l,{sourceLanguage:n,patternId:e.pattern.id,confidence:e.confidence}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=C(n).filter(p=>p.command!=="on").sort((p,g)=>g.priority-p.priority),h=C(n).filter(p=>p.id.startsWith("grammar-")&&p.id.includes("-continuation")).sort((p,g)=>g.priority-p.priority),u=this.parseBodyWithGrammarPatterns(t,y,h,n);u.length>0?a=[m,...u]:a=[m]}else a=[m]}else{let c=C(n).filter(l=>l.command!=="on").sort((l,m)=>m.priority-l.priority);a=this.parseBodyWithClauses(t,c,n)}return U(i,a,o,{sourceLanguage:n,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,t,n){let i=[],o=[];for(;!e.isAtEnd();){let a=e.peek();if(!a)break;let s=a.kind==="conjunction"||a.kind==="keyword"&&this.isThenKeyword(a.value,n),c=a.kind==="keyword"&&this.isEndKeyword(a.value,n);if(s){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l),o.length=0}e.advance();continue}if(c){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l)}e.advance();break}o.push(a),e.advance()}if(o.length>0){let a=this.parseClause(o,t,n);i.push(...a)}return i.length>1?[Qe(i,"then",{sourceLanguage:n})]:i}parseClause(e,t,n){if(e.length===0)return[];let i=new I(e,n),o=[];for(;!i.isAtEnd();){let a=B.matchBest(i,t);a?o.push(this.buildCommand(a,n)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,n,i){let o=[];for(;!e.isAtEnd();){let a=e.peek();if(a&&this.isThenKeyword(a.value,i)){e.advance();continue}if(a&&this.isEndKeyword(a.value,i)){e.advance();break}let s=!1;if(n.length>0){let c=B.matchBest(e,n);if(c){let l=c.pattern.command,m={};for(let[h,u]of c.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(m[h]=u);let x=z(l,m,{sourceLanguage:i,patternId:c.pattern.id});o.push(x),s=!0;let y=c.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!s){let c=B.matchBest(e,t);c&&(o.push(this.buildCommand(c,i)),s=!0)}s||e.advance()}return o}isThenKeyword(e,t){let n={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(n[t]||n.en).has(e.toLowerCase())}isEndKeyword(e,t){let n={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(n[t]||n.en).has(e.toLowerCase())}},Ne=new pe;function D(r,e){return Ne.parse(r,e)}function Ce(r,e){return Ne.canParse(r,e)}function we(r,e){if(F(r))return r;let t=D(r,e);return Q(t)}function Re(r,e){let t=j(r);return Z(t,e)}function Pe(r,e){return F(r)?j(r):D(r,e)}var Rt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Pt=new Set(["and","or","not","no"]),Lt=new Set(["true","false","null","undefined"]),Mt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Je(r){let e=[],t=0,n=1,i=1;function o(){if(e.length===0)return!0;let u=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(u.type)}function a(u=0){return r[t+u]??""}function s(){let u=r[t];return t++,u===`
|
|
2
|
+
`?(n++,i=1):i++,u}function c(){for(;t<r.length&&/\s/.test(r[t]);)s()}function l(u){let p="";for(;t<r.length&&u(r[t]);)p+=s();return p}function m(u){let p=u;for(s();t<r.length&&r[t]!==u;)r[t]==="\\"&&t+1<r.length&&(p+=s()),p+=s();return t<r.length&&(p+=s()),p}function x(){let u="`";for(s();t<r.length&&r[t]!=="`";)r[t]==="\\"&&t+1<r.length&&(u+=s()),u+=s();return t<r.length&&(u+=s()),u}function y(){let u="<";for(s();t<r.length&&(u+=s(),!u.endsWith("/>")););return u}function h(u,p,g){return{type:u,value:p,start:g,end:t,line:n,column:i-p.length}}for(;t<r.length&&(c(),!(t>=r.length));){let u=t,p=a();if(p==="'"&&a(1)==="s"&&!/\w/.test(a(2))){s(),s(),e.push(h("POSSESSIVE","'s",u));continue}if(p==='"'||p==="'"){let g=m(p);e.push(h("STRING",g,u));continue}if(p==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,u));continue}if(p==="<"&&/[a-zA-Z.#\[]/.test(a(1))){let g=y();e.push(h("QUERY_SELECTOR",g,u));continue}if(p==="#"&&o()){s();let g=l(E=>/[\w-]/.test(E));e.push(h("ID_SELECTOR","#"+g,u));continue}if(p==="."&&/[a-zA-Z_-]/.test(a(1))&&o()){s();let g=l(E=>/[\w-]/.test(E));e.push(h("CLASS_SELECTOR","."+g,u));continue}if(p==="["&&o()){let g=a(1);if(g==="@"||/[a-zA-Z]/.test(g)){let E="";for(E+=s();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?E+=m(r[t]):E+=s();t<r.length&&(E+=s()),e.push(h("ATTRIBUTE_SELECTOR",E,u));continue}}if(p==="["){s(),e.push(h("LBRACKET","[",u));continue}if(p==="]"){s(),e.push(h("RBRACKET","]",u));continue}if(/\d/.test(p)){let g=l(ge=>/[\d.]/.test(ge)),E=t,te=l(ge=>/[a-zA-Z]/.test(ge));Mt.has(te)?e.push(h("TIME_EXPRESSION",g+te,u)):(t=E,e.push(h("NUMBER",g,u)));continue}if(p==="("){s(),e.push(h("LPAREN","(",u));continue}if(p===")"){s(),e.push(h("RPAREN",")",u));continue}if(p==="{"){s(),e.push(h("LBRACE","{",u));continue}if(p==="}"){s(),e.push(h("RBRACE","}",u));continue}if(p===","){s(),e.push(h("COMMA",",",u));continue}if(p===":"){s(),e.push(h("COLON",":",u));continue}if(p==="."){s(),e.push(h("DOT",".",u));continue}if(p==="+"||p==="-"||p==="*"||p==="/"||p==="%"){s(),e.push(h("OPERATOR",p,u));continue}if(p==="="||p==="!"||p==="<"||p===">"){let g=s();a()==="="&&(g+=s()),e.push(h("COMPARISON",g,u));continue}if(/[a-zA-Z_$]/.test(p)){let g=l(te=>/[\w$]/.test(te)),E=g.toLowerCase();Rt.has(E)?e.push(h("CONTEXT_VAR",g,u)):Pt.has(E)?e.push(h("LOGICAL",g,u)):Lt.has(E)?e.push(h("BOOLEAN",g,u)):e.push(h("IDENTIFIER",g,u));continue}s()}return e.push(h("EOF","",t)),e}var me=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Je(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,n=this.parseAnd();e=this.createBinaryExpression(t,e,n)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,n=this.parseEquality();e=this.createBinaryExpression(t,e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,n=this.parseComparison();e=this.createBinaryExpression(t,e,n)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,n=this.parseAddition();e=this.createBinaryExpression(t,e,n)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,n=this.parseMultiplication();e=this.createBinaryExpression(t,e,n)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,n=this.parseUnary();e=this.createBinaryExpression(t,e,n)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let n;if(this.check("STRING"))n=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))n=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:n,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(n=>({type:"objectProperty",key:n.key,value:n.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let n=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:n,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,n){return{type:"literal",value:e,dataType:t,raw:n.value,start:n.start,end:n.end,line:n.line,column:n.column}}createSelector(e,t,n){return{type:"selector",value:e,selector:e,selectorType:t,start:n.start,end:n.end,line:n.line,column:n.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,n){return{type:"binaryExpression",operator:e,left:t,right:n,start:t.start,end:n.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Le(r){return new me().parse(r)}function k(r,e){switch(r.type){case"literal":return zt(r);case"selector":return At(r,e);case"reference":return Vt(r);case"property-path":return Ot(r,e);case"expression":return It(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function zt(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function At(r,e){return e&&r.value.startsWith("*")&&/^[a-zA-Z-]/.test(r.value.slice(1))&&e.push(`Converted '${r.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:r.value,selector:r.value,selectorType:r.selectorKind}}function Vt(r){return{type:"contextReference",contextType:r.value,name:r.value}}function Ot(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function It(r){let e=Le(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function et(r,e){return r.roles.get(e)}function d(r,e,t){let n=et(r,e);return n?k(n,t):void 0}function f(r,e=[],t,n={}){let i={type:"command",name:r,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),n.isBlocking&&(i.isBlocking=n.isBlocking),n.implicitTarget&&(i.implicitTarget=n.implicitTarget),i}var _t={action:"toggle",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"duration"),o=t?[t]:[],a={};return n&&(a.on=n),i&&(a.for=i),f("toggle",o,a)}},Bt={action:"add",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("add",i,o)}},jt={action:"remove",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("remove",i,o)}},Wt={action:"set",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("set",i,o)}},Kt={action:"show",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.with=i),f("show",o,a)}},$t={action:"hide",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.with=i),f("hide",o,a)}},Ut={action:"increment",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.by=i),f("increment",o,a)}},Ft={action:"decrement",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],a={},s=t??n;return s&&o.push(s),i&&(a.by=i),f("decrement",o,a)}},Dt={action:"wait",toAST(r,e){let t=d(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},qt={action:"log",toAST(r,e){let t=d(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},Ht={action:"put",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=et(r,"method"),o=t?[t]:[],a={};if(n){let s=i?.type==="literal"?String(i.value):"into";a[s]=n}return f("put",o,a)}},Gt={action:"fetch",toAST(r,e){let t=d(r,"source"),n=d(r,"method"),i=d(r,"responseType"),o=d(r,"patient"),a=t?[t]:[],s={};return n&&(s.with=n),i&&(s.as=i),o&&(s.body=o),f("fetch",a,s,{isBlocking:!0})}},Xt={action:"append",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("append",i,o)}},Zt={action:"prepend",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("prepend",i,o)}},Qt={action:"trigger",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("trigger",i,o)}},Yt={action:"send",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=d(r,"patient"),o=t?[t]:[],a={};return n&&(a.to=n),i&&(a.detail=i),f("send",o,a)}},Jt={action:"go",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("go",i,o)}},en={action:"transition",toAST(r,e){let t=d(r,"patient"),n=d(r,"goal"),i=d(r,"duration"),o=d(r,"destination"),a=t?[t]:[],s={};return n&&(s.to=n),i&&(s.over=i),o&&(s.on=o),f("transition",a,s)}},tn={action:"focus",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={},a=t??n;return a&&i.push(a),f("focus",i,o)}},nn={action:"blur",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("blur",i)}},rn={action:"get",toAST(r,e){let t=d(r,"source"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("get",i)}},on={action:"take",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("take",i,o)}},an={action:"call",toAST(r,e){let t=d(r,"patient");return f("call",t?[t]:[])}},sn={action:"return",toAST(r,e){let t=d(r,"patient");return f("return",t?[t]:[])}},cn={action:"halt",toAST(r,e){return f("halt",[])}},ln={action:"throw",toAST(r,e){let t=d(r,"patient");return f("throw",t?[t]:[])}},dn={action:"settle",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},un={action:"swap",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=d(r,"destination"),o=d(r,"style"),a=[],s={};return t&&a.push(t),n&&a.push(n),i&&(s.on=i),o&&(s.with=o),f("swap",a,s)}},pn={action:"morph",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],a={},s=t??i;return s&&o.push(s),n&&(a.on=n),f("morph",o,a)}},mn={action:"clone",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],a={},s=t??i;return s&&o.push(s),n&&(a.into=n),f("clone",o,a)}},fn={action:"make",toAST(r,e){let t=d(r,"patient");return f("make",t?[t]:[])}},gn={action:"measure",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"source"),o=[],a={};t&&o.push(t);let s=n??i;return s&&(a.of=s),f("measure",o,a)}},hn={action:"tell",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("tell",i)}},yn={action:"js",toAST(r,e){let t=d(r,"patient");return f("js",t?[t]:[])}},xn={action:"async",toAST(r,e){return f("async",[])}},vn={action:"if",toAST(r,e){let t=d(r,"condition");return f("if",t?[t]:[])}},Sn={action:"unless",toAST(r,e){let t=d(r,"condition");return f("unless",t?[t]:[])}},bn={action:"repeat",toAST(r,e){let t=d(r,"quantity"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("repeat",i)}},En={action:"for",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.in=n),f("for",i,o)}},Tn={action:"while",toAST(r,e){let t=d(r,"condition");return f("while",t?[t]:[])}},kn={action:"continue",toAST(r,e){return f("continue",[])}},Nn={action:"default",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.to=n),f("default",i,o)}},Cn={action:"init",toAST(r,e){return f("init",[])}},wn={action:"behavior",toAST(r,e){let t=d(r,"patient");return f("behavior",t?[t]:[])}},Rn={action:"install",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("install",i,o)}},Pn={action:"on",toAST(r,e){let t=d(r,"event"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("on",i,o)}},tt=new Map([["toggle",_t],["add",Bt],["remove",jt],["set",Wt],["show",Kt],["hide",$t],["increment",Ut],["decrement",Ft],["wait",Dt],["log",qt],["put",Ht],["fetch",Gt],["append",Xt],["prepend",Zt],["get",rn],["take",on],["trigger",Qt],["send",Yt],["on",Pn],["go",Jt],["transition",en],["focus",tn],["blur",nn],["call",an],["return",sn],["halt",cn],["throw",ln],["settle",dn],["swap",un],["morph",pn],["clone",mn],["measure",gn],["make",fn],["tell",hn],["default",Nn],["js",yn],["async",xn],["if",vn],["unless",Sn],["repeat",bn],["for",En],["while",Tn],["continue",kn],["init",Cn],["behavior",wn],["install",Rn]]);function Y(r){return tt.get(r)}function Me(r){tt.set(r.action,r)}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 n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let i=n;return this.warnings.push(...i.warnings),i.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let s of i){let c=e.roles.get(s);c&&t.push(k(c))}for(let s of o){let c=e.roles.get(s);if(c){let l=this.roleToModifierKey(s);n[l]=k(c)}}let a={type:"command",name:e.action,args:t};return Object.keys(n).length>0?{...a,modifiers:n}: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"),n,i;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(i=g.split(/\s+or\s+|\|/).map(E=>E.trim()),n=i[0]):n=g}else t?.type==="reference"?n=t.value:n="click";let o=e.body.map(g=>this.build(g)),a=e.roles.get("source"),s,c;a?.type==="selector"?(s=a.value,c=a.value):a?.type==="reference"?c=a.value:a?.type==="literal"&&(c=String(a.value));let l=e.roles.get("condition"),m=l?k(l):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,h=e.eventModifiers,u=s;if(h?.from){let g=h.from;g.type==="selector"&&!s&&(u=g.value)}let p=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:n,commands:o,...i&&i.length>1?{events:i}:{},...u?{selector:u}:{},...c?{target:c}:{},...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 n=k(t),i=e.thenBranch.map(s=>this.build(s)),o=e.elseBranch?.map(s=>this.build(s)),a=[n,{type:"block",commands:i}];return o&&o.length>0&&a.push({type:"block",commands:o}),{type:"command",name:"if",args:a}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),n=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&n.push(k(i));break}case"for":{e.loopVariable&&n.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&n.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&n.push(k(i));break}case"forever":break}return n.push({type:"block",commands:t}),{type:"command",name:"repeat",args:n}}buildBlock(e){return{type:"block",commands:e.map(n=>this.build(n))}}};function nt(r){let e=new J;return{ast:e.build(r),warnings:e.warnings}}var W=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),i=this.cache.get(n);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),i.lastAccessed=Date.now(),this.cache.set(n,i),this.stats.hits++,i.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:n,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),i=this.cache.get(n);return i?this.isExpired(i)?(this.cache.delete(n),this.stats.expirations++,!1):!0:!1}delete(e,t){let n=this.makeKey(e,t);return this.cache.delete(n)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},ze=new W;var ee=class{constructor(e={}){this.patternMatcher=new X,this.languages=new Set(ne()),e.cache===!1?this.cache=new W({enabled:!1}):this.cache=e.cache?new W(e.cache):ze}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let n=this.cache.get(e,t);if(n)return n;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let n=Ze(t);if(!n)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=n.tokenize(e),o=C(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let a=this.patternMatcher.matchBest(i,o);if(!a)return{confidence:0,errors:["No pattern matched the input"]};let s=this.buildSemanticNode(a);return{confidence:a.confidence,command:{name:a.pattern.command,roles:a.captured},node:s,tokensConsumed:a.consumedTokens}}catch(n){return{confidence:0,errors:[n instanceof Error?n.message:String(n)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function rt(r){return new ee(r)}var Ae=.5,it=.8;function ot(r,e=Ae){return r.confidence>=e&&r.command!==void 0}var Ln="1.0.0-es",fe="es";function Mn(){return[fe]}function at(r){if(r!==fe)throw new Error(`Idioma no soportado en este paquete: ${r}. Este paquete solo soporta: ${fe}. (Language not supported: ${r}. This bundle only supports: ${fe})`)}function zn(r,e){return at(e),[...le(r,e).tokens]}function st(r){return at(r),C(r)}function An(r,e){return st(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return mt(Vn);})();
|