@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 LokaScriptSemanticZh=(()=>{var de=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(n,e)=>{for(var t in e)de(n,t,{get:e[t],enumerable:!0})},rt=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Je(e))!et.call(n,i)&&i!==t&&de(n,i,{get:()=>e[i],enumerable:!(r=Ye(e,i))||r.enumerable});return n};var nt=n=>rt(de({},"__esModule",{value:!0}),n);var xr={};tt(xr,{ASTBuilder:()=>G,DEFAULT_CONFIDENCE_THRESHOLD:()=>Re,HIGH_CONFIDENCE_THRESHOLD:()=>Ge,SemanticAnalyzerImpl:()=>X,VERSION:()=>mr,buildAST:()=>qe,canParse:()=>Ee,chineseProfile:()=>V,chineseTokenizer:()=>ie,createCommandNode:()=>M,createEventHandler:()=>W,createLiteral:()=>E,createPropertyPath:()=>K,createReference:()=>w,createSelector:()=>L,createSemanticAnalyzer:()=>He,fromExplicit:()=>be,getCommandMapper:()=>H,getPatternsForLanguage:()=>Qe,getPatternsForLanguageAndCommand:()=>yr,getProfile:()=>me,getSupportedLanguages:()=>gr,getTokenizer:()=>pe,isExplicitSyntax:()=>$,isLanguageSupported:()=>Ae,parse:()=>j,parseAny:()=>ke,parseExplicit:()=>I,registerCommandMapper:()=>Ce,render:()=>F,renderExplicit:()=>q,shouldUseSemanticResult:()=>Xe,toExplicit:()=>Te,tokenize:()=>hr,tryGetProfile:()=>P});var B=new Map,Y=new Map,Q=new Map;var Pe=null;function Le(n,e,t){B.set(n,e),Y.set(n,t),Q.delete(n)}var it=new Map;function pe(n){let e=B.get(n);if(!e){let t=Array.from(B.keys()).join(", ");throw new Error(`Language '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function me(n){let e=Y.get(n);if(!e){let t=Array.from(Y.keys()).join(", ");throw new Error(`Language profile '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function Me(n){return B.get(n)}function P(n){return Y.get(n)}function J(){return Array.from(B.keys())}function Ae(n){return B.has(n)}function ze(n,e){return pe(e).tokenize(n)}function N(n){let e=Q.get(n);if(e)return e;let t=it.get(n);if(t)return Q.set(n,t),t;if(!Pe)throw new Error(`No patterns registered for language '${n}'. Either import the language module or set a pattern generator.`);let r=me(n),i=Pe(r);return Q.set(n,i),i}function Ve(n,e){return N(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}var A=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function S(n,e){return{start:n,end:e}}function v(n,e,t,r){if(typeof r=="string")return{value:n,kind:e,position:t,normalized:r};if(r){let{normalized:i,stem:o,stemConfidence:a}=r,s={value:n,kind:e,position:t};return i!==void 0&&(s.normalized=i),o!==void 0&&(s.stem=o,a!==void 0&&(s.stemConfidence=a)),s}return{value:n,kind:e,position:t}}function z(n){return/\s/.test(n)}function te(n){return n==="#"||n==="."||n==="["||n==="@"||n==="*"||n==="<"}function re(n){return n==='"'||n==="'"||n==="`"||n==="\u300C"||n==="\u300D"}function C(n){return/\d/.test(n)}function Oe(n){return/[a-zA-Z]/.test(n)}function b(n){return/[a-zA-Z0-9_-]/.test(n)}function fe(n){return e=>{let t=e.charCodeAt(0);return n.some(([r,i])=>t>=r&&t<=i)}}function Ie(n,e){if(e>=n.length)return null;let t=n[e];if(!te(t))return null;let r=e,i="";if(t==="#"||t==="."){for(i+=n[r++];r<n.length&&b(n[r]);)i+=n[r++];if(i.length<=1)return null;if(r<n.length&&n[r]==="."&&t==="#"){let a=r+1;for(;a<n.length&&b(n[a]);)a++;if(a<n.length&&n[a]==="(")return i}}else if(t==="["){let o=1,a=!1,s=null,l=!1;for(i+=n[r++];r<n.length&&o>0;){let c=n[r];i+=c,l?l=!1:c==="\\"?l=!0:a?c===s&&(a=!1,s=null):c==='"'||c==="'"||c==="`"?(a=!0,s=c):c==="["?o++:c==="]"&&o--,r++}if(o!==0)return null}else if(t==="@"){for(i+=n[r++];r<n.length&&b(n[r]);)i+=n[r++];if(i.length<=1)return null}else if(t==="*"){for(i+=n[r++];r<n.length&&b(n[r]);)i+=n[r++];if(i.length<=1)return null}else if(t==="<"){if(i+=n[r++],r>=n.length||!Oe(n[r]))return null;for(;r<n.length&&b(n[r]);)i+=n[r++];for(;r<n.length;){let o=n[r];if(o==="."){if(i+=n[r++],r>=n.length||!b(n[r]))return null;for(;r<n.length&&b(n[r]);)i+=n[r++]}else if(o==="#"){if(i+=n[r++],r>=n.length||!b(n[r]))return null;for(;r<n.length&&b(n[r]);)i+=n[r++]}else if(o==="["){let a=1,s=!1,l=null,c=!1;for(i+=n[r++];r<n.length&&a>0;){let d=n[r];i+=d,c?c=!1:d==="\\"?c=!0:s?d===l&&(s=!1,l=null):d==='"'||d==="'"||d==="`"?(s=!0,l=d):d==="["?a++:d==="]"&&a--,r++}if(a!==0)return null}else break}for(;r<n.length&&z(n[r]);)i+=n[r++];if(r<n.length&&n[r]==="/")for(i+=n[r++];r<n.length&&z(n[r]);)i+=n[r++];if(r>=n.length||n[r]!==">")return null;i+=n[r++]}return i||null}function ot(n,e){if(e>=n.length||n[e]!=="'"||e+1>=n.length||n[e+1].toLowerCase()!=="s")return!1;if(e+2>=n.length)return!0;let r=n[e+2];return z(r)||r==="*"||!b(r)}function _e(n,e){if(e>=n.length)return null;let t=n[e];if(!re(t)||t==="'"&&ot(n,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,a=t,s=!1;for(;o<n.length;){let l=n[o];if(a+=l,s)s=!1;else if(l==="\\")s=!0;else if(l===i)return a;o++}return a}function ne(n,e){if(e>=n.length)return!1;let t=n[e],r=n[e+1]||"",i=n[e+2]||"";if(t==="/"&&r!=="/"&&/[a-zA-Z0-9._-]/.test(r)||t==="/"&&r==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(r==="/"||r==="."&&i==="/"))return!0;let o=n.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function Be(n,e){if(!ne(n,e))return null;let t=e,r="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<n.length;){let o=n[t];if(o==="#"){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=o,t++;t<n.length&&/[a-zA-Z0-9_-]/.test(n[t]);)r+=n[t++];break}if(i.test(o))r+=o,t++;else break}return r.length<2?null:r}function Ke(n,e){if(e>=n.length)return null;let t=n[e];if(!C(t)&&t!=="-"&&t!=="+")return null;let r=e,i="";if((n[r]==="-"||n[r]==="+")&&(i+=n[r++]),r>=n.length||!C(n[r]))return null;for(;r<n.length&&C(n[r]);)i+=n[r++];if(r<n.length&&n[r]===".")for(i+=n[r++];r<n.length&&C(n[r]);)i+=n[r++];return r<n.length&&(n.slice(r,r+2)==="ms"?i+="ms":(n[r]==="s"||n[r]==="m"||n[r]==="h")&&(i+=n[r])),i}var ee=class ee{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let r=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(r.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let a of o.alternatives)r.set(a,{native:a,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))r.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&r.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let a of o.alternatives)r.set(a,{native:a,normalized:i})}for(let i of t)r.set(i.native,i);this.profileKeywords=Array.from(r.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let r of this.profileKeywords)if(e.slice(t).startsWith(r.native))return v(r.native,"keyword",S(t,t+r.native.length),r.normalized);return null}isKeywordStart(e,t){let r=e.slice(t);return this.profileKeywords.some(i=>r.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,r){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let a={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return v(e,"keyword",S(t,r),a)}trySelector(e,t){let r=Ie(e,t);return r?v(r,"selector",S(t,t+r.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let r=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!r)return null;let i=r[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],a=r[1];return{...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 r=_e(e,t);return r?v(r,"literal",S(t,t+r.length)):null}tryNumber(e,t){let r=Ke(e,t);return r?v(r,"literal",S(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,i=!1){let o=t;if(i)for(;o<e.length&&z(e[o]);)o++;let a=e.slice(o);for(let s of r){let l=a.slice(0,s.length);if(s.caseInsensitive?l.toLowerCase()===s.pattern.toLowerCase():l===s.pattern){if(s.notFollowedBy&&(a[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let d=a[s.length]||"";if(b(d))continue}return{suffix:s.suffix,endPos:o+s.length}}}return null}parseBaseNumber(e,t,r=!0){let i=t,o="";if(r&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!C(e[i]))return null;for(;i<e.length&&C(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&C(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,r,i={}){let{allowSign:o=!0,skipWhitespace:a=!1}=i,s=this.parseBaseNumber(e,t,o);if(!s)return null;let{number:l,endPos:c}=s,d=[...r,...ee.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,c,d,a);return x&&(l+=x.suffix,c=x.endPos),v(l,"literal",S(t,c))}tryUrl(e,t){let r=Be(e,t);return r?v(r,"url",S(t,t+r.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!b(e[t+1]))return null;let r=t+1;for(;r<e.length&&b(e[r]);)r++;let i=e.slice(t,r);return v(i,"identifier",S(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return v(r,"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,r){for(let i of r)if(e.slice(t,t+i.length)===i)return v(i,"particle",S(t,t+i.length));return null}};ee.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var U=ee;var V={code:"zh",name:"Chinese",nativeName:"\u4E2D\u6587",direction:"ltr",wordOrder:"SVO",markingStrategy:"preposition",usesSpaces:!1,verb:{position:"second",subjectDrop:!0},references:{me:"\u6211",it:"\u5B83",you:"\u4F60",result:"\u7ED3\u679C",event:"\u4E8B\u4EF6",target:"\u76EE\u6807",body:"\u4E3B\u4F53"},possessive:{marker:"\u7684",markerPosition:"between",keywords:{\u6211\u7684:"me",\u4F60\u7684:"you",\u5B83\u7684:"it",\u4ED6\u7684:"it",\u5979\u7684:"it"}},roleMarkers:{destination:{primary:"\u5728",alternatives:["\u5230","\u4E8E"],position:"before"},source:{primary:"\u4ECE",alternatives:["\u7531"],position:"before"},patient:{primary:"\u628A",position:"before"},style:{primary:"\u7528",alternatives:["\u4EE5"],position:"before"}},keywords:{toggle:{primary:"\u5207\u6362",normalized:"toggle"},add:{primary:"\u6DFB\u52A0",alternatives:["\u52A0"],normalized:"add"},remove:{primary:"\u79FB\u9664",alternatives:["\u5220\u9664","\u53BB\u6389"],normalized:"remove"},put:{primary:"\u653E\u7F6E",alternatives:["\u653E","\u653E\u5165"],normalized:"put"},append:{primary:"\u8FFD\u52A0",alternatives:["\u9644\u52A0"],normalized:"append"},prepend:{primary:"\u524D\u7F6E",alternatives:["\u9884\u7F6E"],normalized:"prepend"},take:{primary:"\u83B7\u53D6",normalized:"take"},make:{primary:"\u5236\u4F5C",normalized:"make"},clone:{primary:"\u590D\u5236",normalized:"clone"},swap:{primary:"\u4EA4\u6362",normalized:"swap"},morph:{primary:"\u53D8\u5F62",alternatives:["\u8F6C\u6362"],normalized:"morph"},set:{primary:"\u8BBE\u7F6E",alternatives:["\u8BBE\u5B9A"],normalized:"set"},get:{primary:"\u83B7\u5F97",alternatives:["\u83B7\u53D6","\u53D6\u5F97"],normalized:"get"},increment:{primary:"\u589E\u52A0",normalized:"increment"},decrement:{primary:"\u51CF\u5C11",normalized:"decrement"},log:{primary:"\u65E5\u5FD7",normalized:"log"},show:{primary:"\u663E\u793A",alternatives:["\u5C55\u793A"],normalized:"show"},hide:{primary:"\u9690\u85CF",normalized:"hide"},transition:{primary:"\u8FC7\u6E21",normalized:"transition"},on:{primary:"\u5F53",alternatives:["\u5728...\u65F6"],normalized:"on"},trigger:{primary:"\u89E6\u53D1",normalized:"trigger"},send:{primary:"\u53D1\u9001",normalized:"send"},focus:{primary:"\u805A\u7126",normalized:"focus"},blur:{primary:"\u5931\u7126",normalized:"blur"},go:{primary:"\u524D\u5F80",normalized:"go"},wait:{primary:"\u7B49\u5F85",normalized:"wait"},fetch:{primary:"\u83B7\u53D6",normalized:"fetch"},settle:{primary:"\u7A33\u5B9A",normalized:"settle"},if:{primary:"\u5982\u679C",normalized:"if"},when:{primary:"\u5F53",normalized:"when"},where:{primary:"\u54EA\u91CC",normalized:"where"},else:{primary:"\u5426\u5219",normalized:"else"},repeat:{primary:"\u91CD\u590D",normalized:"repeat"},for:{primary:"\u4E3A",normalized:"for"},while:{primary:"\u5F53",normalized:"while"},continue:{primary:"\u7EE7\u7EED",normalized:"continue"},halt:{primary:"\u505C\u6B62",normalized:"halt"},throw:{primary:"\u629B\u51FA",normalized:"throw"},call:{primary:"\u8C03\u7528",normalized:"call"},return:{primary:"\u8FD4\u56DE",normalized:"return"},then:{primary:"\u7136\u540E",alternatives:["\u63A5\u7740","\u4E4B\u540E"],normalized:"then"},and:{primary:"\u5E76\u4E14",alternatives:["\u548C","\u800C\u4E14"],normalized:"and"},end:{primary:"\u7ED3\u675F",alternatives:["\u7EC8\u6B62","\u5B8C"],normalized:"end"},js:{primary:"JS\u6267\u884C",alternatives:["js"],normalized:"js"},async:{primary:"\u5F02\u6B65",normalized:"async"},tell:{primary:"\u544A\u8BC9",normalized:"tell"},default:{primary:"\u9ED8\u8BA4",normalized:"default"},init:{primary:"\u521D\u59CB\u5316",normalized:"init"},behavior:{primary:"\u884C\u4E3A",normalized:"behavior"},install:{primary:"\u5B89\u88C5",normalized:"install"},measure:{primary:"\u6D4B\u91CF",normalized:"measure"},into:{primary:"\u8FDB\u5165",normalized:"into"},before:{primary:"\u4E4B\u524D",normalized:"before"},after:{primary:"\u4E4B\u540E",normalized:"after"},until:{primary:"\u76F4\u5230",normalized:"until"},event:{primary:"\u4E8B\u4EF6",normalized:"event"},from:{primary:"\u4ECE",normalized:"from"}},tokenization:{boundaryStrategy:"character"}};var ge=fe([[19968,40959],[13312,19903],[131072,173791],[63744,64255],[194560,195103]]),he=new Set(["\u628A","\u5728","\u4ECE","\u5230","\u5411","\u7ED9","\u5BF9","\u7528","\u88AB","\u8BA9","\u7684","\u5730","\u5F97","\u4E86","\u7740","\u8FC7","\u5417","\u5462","\u5427"]),at=["\u7136\u540E","\u63A5\u7740","\u5E76\u4E14","\u6216\u8005","\u5982\u679C","\u90A3\u4E48","\u5426\u5219"],st=[{native:"\u771F",normalized:"true"},{native:"\u5047",normalized:"false"},{native:"\u7A7A",normalized:"null"},{native:"\u672A\u5B9A\u4E49",normalized:"undefined"},{native:"\u7B2C\u4E00\u4E2A",normalized:"first"},{native:"\u9996\u4E2A",normalized:"first"},{native:"\u6700\u540E\u4E00\u4E2A",normalized:"last"},{native:"\u672B\u4E2A",normalized:"last"},{native:"\u4E0B\u4E00\u4E2A",normalized:"next"},{native:"\u4E0A\u4E00\u4E2A",normalized:"previous"},{native:"\u6700\u8FD1\u7684",normalized:"closest"},{native:"\u7236\u7EA7",normalized:"parent"},{native:"\u70B9\u51FB",normalized:"click"},{native:"\u53CC\u51FB",normalized:"dblclick"},{native:"\u8F93\u5165",normalized:"input"},{native:"\u53D8\u66F4",normalized:"change"},{native:"\u6539\u53D8",normalized:"change"},{native:"\u63D0\u4EA4",normalized:"submit"},{native:"\u6309\u952E",normalized:"keydown"},{native:"\u91CA\u653E\u952E",normalized:"keyup"},{native:"\u9F20\u6807\u79FB\u5165",normalized:"mouseover"},{native:"\u9F20\u6807\u79FB\u51FA",normalized:"mouseout"},{native:"\u83B7\u5F97\u7126\u70B9",normalized:"focus"},{native:"\u5931\u53BB\u7126\u70B9",normalized:"blur"},{native:"\u52A0\u8F7D",normalized:"load"},{native:"\u6EDA\u52A8",normalized:"scroll"},{native:"\u6211\u7684",normalized:"my"},{native:"\u5B83\u7684",normalized:"its"},{native:"\u79D2",normalized:"s"},{native:"\u6BEB\u79D2",normalized:"ms"},{native:"\u5206\u949F",normalized:"m"},{native:"\u5C0F\u65F6",normalized:"h"},{native:"\u548C",normalized:"and"},{native:"\u6216\u8005",normalized:"or"},{native:"\u6216",normalized:"or"},{native:"\u4E0D",normalized:"not"},{native:"\u975E",normalized:"not"},{native:"\u662F",normalized:"is"},{native:"\u82E5",normalized:"if"},{native:"\u4E0D\u7136",normalized:"else"},{native:"\u5FAA\u73AF",normalized:"repeat"},{native:"\u904D\u5386",normalized:"for"},{native:"\u6BCF\u4E2A",normalized:"for"},{native:"\u4E3A\u6BCF",normalized:"for"},{native:"\u4E2D\u6B62",normalized:"halt"},{native:"\u629B",normalized:"throw"},{native:"\u547C\u53EB",normalized:"call"},{native:"\u56DE",normalized:"return"},{native:"\u811A\u672C",normalized:"js"},{native:"\u901A\u77E5",normalized:"tell"},{native:"\u7F3A\u7701",normalized:"default"},{native:"\u521D\u59CB",normalized:"init"},{native:"\u52A8\u4F5C",normalized:"behavior"},{native:"\u6FC0\u53D1",normalized:"trigger"},{native:"\u5BF9\u7126",normalized:"focus"},{native:"\u6A21\u7CCA",normalized:"blur"},{native:"\u8DF3\u8F6C",normalized:"go"},{native:"\u5BFC\u822A",normalized:"go"},{native:"\u6293\u53D6",normalized:"fetch"},{native:"\u83B7\u53D6\u6570\u636E",normalized:"fetch"},{native:"\u5B89\u5B9A",normalized:"settle"},{native:"\u62FF\u53D6",normalized:"take"},{native:"\u53D6",normalized:"take"},{native:"\u521B\u5EFA",normalized:"make"},{native:"\u514B\u9686",normalized:"clone"},{native:"\u8BB0\u5F55",normalized:"log"},{native:"\u6253\u5370",normalized:"log"},{native:"\u52A8\u753B",normalized:"transition"},{native:"\u5230\u91CC\u9762",normalized:"into"},{native:"\u91CC",normalized:"into"},{native:"\u524D",normalized:"before"},{native:"\u540E",normalized:"after"},{native:"\u90A3\u4E48",normalized:"then"},{native:"\u5B8C",normalized:"end"}],ct=[{pattern:"\u6BEB\u79D2",suffix:"ms",length:2},{pattern:"\u5206\u949F",suffix:"m",length:2},{pattern:"\u5C0F\u65F6",suffix:"h",length:2},{pattern:"\u79D2",suffix:"s",length:1},{pattern:"\u5206",suffix:"m",length:1}],ye=class extends U{constructor(){super();this.language="zh";this.direction="ltr";this.initializeKeywordsFromProfile(V,st)}tokenize(t){let r=[],i=0;for(;i<t.length;){if(z(t[i])){i++;continue}if(te(t[i])){let s=this.tryEventModifier(t,i);if(s){r.push(s),i=s.position.end;continue}let l=this.trySelector(t,i);if(l){r.push(l),i=l.position.end;continue}}if(re(t[i])||t[i]==="\u201C"||t[i]==="\u201D"||t[i]==="\u2018"||t[i]==="\u2019"){let s=this.tryChineseString(t,i);if(s){r.push(s),i=s.position.end;continue}}if(ne(t,i)){let s=this.tryUrl(t,i);if(s){r.push(s),i=s.position.end;continue}}if(C(t[i])){let s=this.extractChineseNumber(t,i);if(s){r.push(s),i=s.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){r.push(o),i=o.position.end;continue}let a=this.tryMultiCharParticle(t,i,at);if(a){r.push(a),i=a.position.end;continue}if(ge(t[i])){let s=this.extractChineseWord(t,i);if(s){r.push(s),i=s.position.end;continue}}if(b(t[i])){let s=this.extractAsciiWord(t,i);if(s){r.push(s),i=s.position.end;continue}}i++}return new A(r,"zh")}classifyToken(t){return he.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")||t.startsWith("<")?"selector":t.startsWith('"')||t.startsWith("'")||t.startsWith("\u201C")||t.startsWith("\u2018")||/^\d/.test(t)?"literal":"identifier"}extractChineseWord(t,r){for(let a of this.profileKeywords){let s=a.native,l=t.slice(r,r+s.length);if(l===s){let c=!0;for(let d=0;d<s.length;d++)if(!ge(s[d])){c=!1;break}if(c)return v(l,"keyword",S(r,r+s.length),a.normalized)}}let i=r,o="";for(;i<t.length;){let a=t[i];if(he.has(a)&&o.length>0)break;if(ge(a))o+=a,i++;else break}return o?he.has(o)?v(o,"particle",S(r,i)):v(o,"identifier",S(r,i)):null}extractAsciiWord(t,r){let i=r,o="";for(;i<t.length&&b(t[i]);)o+=t[i++];return o?v(o,"identifier",S(r,i)):null}tryChineseString(t,r){let i=t[r];if(i==='"'||i==="'"||i==="`")return this.tryString(t,r);if(i==="\u201C"){let o=r+1;for(;o<t.length&&t[o]!=="\u201D";)o++;if(o>=t.length)return null;let a=t.slice(r,o+1);return v(a,"literal",S(r,o+1))}if(i==="\u2018"){let o=r+1;for(;o<t.length&&t[o]!=="\u2019";)o++;if(o>=t.length)return null;let a=t.slice(r,o+1);return v(a,"literal",S(r,o+1))}return null}extractChineseNumber(t,r){return this.tryNumberWithTimeUnits(t,r,ct,{allowSign:!1,skipWhitespace:!1})}},ie=new ye;Le("zh",ie,V);function We(n){return Me(n)}function oe(n,e){return ze(n,e)}function ae(){return J()}function L(n){let e="complex";return n.startsWith("#")&&!n.includes(" ")?e="id":n.startsWith(".")&&!n.includes(" ")?e="class":n.startsWith("[")&&n.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(n)&&(e="element"),{type:"selector",value:n,selectorKind:e}}function E(n,e){let t={type:"literal",value:n};return e!==void 0?{type:"literal",value:n,dataType:e}:t}function w(n){return{type:"reference",value:n}}function K(n,e){return{type:"property-path",object:n,property:e}}function M(n,e,t){let r={kind:"command",action:n,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function W(n,e,t,r,i){let o=new Map;o.set("event",n);let a={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(a.eventModifiers=t),r!==void 0&&(a.metadata=r),i!==void 0&&i.length>0&&(a.parameterNames=i),a}function $e(n,e="then",t){let r={kind:"compound",action:"compound",roles:new Map,statements:n,chainType:e};return t!==void 0&&(r.metadata=t),r}function xe(n,e){return!e||e.length===0||e.includes(n)||e.includes("expression")?!0:n==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function je(n,e){return n.possessive?.keywords?.[e]}var R=class R{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let r=e.mark(),i=new Map;if(this.currentProfile=P(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(r),null;let a=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-r.position,confidence:a}}matchBest(e,t){let r=[];for(let o of t){let a=e.mark(),s=this.matchPattern(e,o);s&&r.push(s),e.reset(a)}if(r.length===0)return null;r.sort((o,a)=>{let s=a.pattern.priority-o.pattern.priority;return s!==0?s:a.confidence-o.confidence});let i=r[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,r){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let i of t)if(!this.matchPatternToken(e,i,r)){if(this.isOptional(i))continue;return!1}return!0}matchPatternToken(e,t,r){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r);case"group":return this.matchGroupToken(e,t,r);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(!r)return!1;let i=this.getMatchType(r,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let a=this.getMatchType(r,o);if(a!=="none")return this.totalKeywordMatches++,a==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,r){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,o),!0);let a=this.tryMatchMethodCallExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(a.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,a),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!xe(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);let l=this.tryMatchPropertyAccessExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(l.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,l),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!xe(c.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,c),!0);let d=this.tokenToSemanticValue(i);return!d||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(d.type)?t.optional||!1:(r.set(t.role,d),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=(t.normalized||t.value).toLowerCase(),i=je(this.currentProfile,r);if(!i)return null;let o=e.mark();e.advance();let a=e.peek();return a&&(a.kind==="identifier"||a.kind==="keyword"&&!this.isStructuralKeyword(a.value)||a.kind==="selector"&&a.value.startsWith("*"))?(e.advance(),K(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 r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(r),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="punctuation"||a.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<R.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(r),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(r),null;e.advance();let a=`${t.value}.${o.value}`,s=1;for(;!e.isAtEnd()&&s<R.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let d=e.peek();if(!d||d.kind!=="identifier")break;e.advance(),a+=`.${d.value}`,s++}let l=e.peek();if(l&&l.kind==="punctuation"&&l.value==="("){e.advance();let c=[],d=0;for(;!e.isAtEnd()&&c.length<R.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(d===0){e.advance();break}d--}if(y.kind==="punctuation"&&y.value==="("&&d++,y.kind==="punctuation"&&y.value===","){e.advance();continue}c.push(y.value),e.advance()}return{type:"expression",raw:`${a}(${c.join(", ")})`}}return{type:"expression",raw:a}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(r),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(r),null):(e.advance(),K(L(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(r),null;let o=e.peek(1);o&&o.kind,e.advance();let a=i.value.slice(1);return K(L(t.value),a)}matchGroupToken(e,t,r){let i=e.mark(),o=new Set(r.keys());if(!this.matchTokenSequence(e,t.tokens,r)){e.reset(i);for(let s of r.keys())o.has(s)||r.delete(s);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return L(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?w(t):E(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return w(e.value);let r=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(r)?w(r):{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 r=parseFloat(e);return isNaN(r)?E(e,"string"):E(r,"number")}applyExtractionRules(e,t){for(let[r,i]of Object.entries(e.extraction))!t.has(r)&&i.default&&t.set(r,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let r=0,i=0,o=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")i+=1,t.has(c.role)&&(r+=1);else if(c.type==="group"){for(let d of c.tokens)if(d.type==="role"){let x=o(d.role),y=.8;i+=y,t.has(d.role)?r+=y:x&&(r+=y*.6)}}let a=i>0?r/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let c=this.stemMatchCount/this.totalKeywordMatches*.15;a=Math.max(.5,a-c)}let s=this.calculateVSOConfidenceBoost(e);a=Math.min(1,a+s);let l=this.arabicPrepositionDisambiguation(e,t);return a=Math.max(0,Math.min(1,a+l)),a}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let r=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(r.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(r.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let r=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,a]of t.entries()){let s=i[o];if(!s||s.length===0)continue;let l=a.metadata;if(l&&typeof l.prepositionValue=="string"){let c=l.prepositionValue;s.includes(c)?r+=.1:r-=.1}}return Math.max(-.1,Math.min(.1,r))}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=t.value.toLowerCase();if(R.ENGLISH_NOISE_WORDS.has(r)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(r=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return r?t:void 0}};R.MAX_PROPERTY_DEPTH=10,R.MAX_METHOD_ARGS=20,R.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var D=R,O=new D;var se=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let r=Ve(t,e.action);if(r.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,r);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let r=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return r.join(` ${i} `)}getChainWord(e,t){let r=P(t);return r?.keywords?r.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let r=e;return r.statements.map(o=>this.renderExplicit(o)).join(` ${r.chainType} `)}let t=[e.action];for(let[r,i]of e.roles)t.push(`${r}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let r=e;if(r.body&&r.body.length>0){let i=r.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return ae()}findBestPattern(e,t){let r=t.map(i=>{let o=i.priority;for(let a of i.template.tokens)a.type==="role"&&(e.roles.has(a.role)?o+=10:a.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return r.sort((i,o)=>o.score-i.score),r.length>0?r[0].pattern:null}renderWithPattern(e,t){let r=[],i=t.language;for(let o of t.template.tokens){let a=this.renderPatternToken(o,e,i);a!==null&&r.push(a)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let a=o.body.map(s=>this.render(s,i));r.push(a.join(" "))}}return r.join(" ")}renderPatternToken(e,t,r){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,r):(e.optional,null)}case"group":{if(!e.tokens.filter(a=>a.type==="role"&&!a.optional).every(a=>t.roles.has(a.role))&&e.optional)return null;if(e.optional&&e.tokens.find(s=>s.type==="role"&&s.role==="destination")){let s=t.roles.get("destination");if(s?.type==="reference"&&s.value==="me")return null}let o=[];for(let a of e.tokens){let s=this.renderPatternToken(a,t,r);s!==null&&o.push(s)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let r=P(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=P(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(r?.possessive?.specialForms&&o){let s=r.possessive.specialForms[o];if(s){let{markerPosition:l,usePossessiveAdjectives:c}=r.possessive;return c&&l==="after-object"?`${i} ${s}`:`${s} ${i}`}}let a=this.valueToNaturalString(e.object,t);if(r?.possessive){let{marker:s,markerPosition:l,usePossessiveAdjectives:c}=r.possessive;if(c&&o&&l==="after-object")return`${i} ${a}`;if(s)switch(l){case"between":return r.usesSpaces?`${a}${s} ${i}`:`${a}${s}${i}`;case"after-object":return`${a}${s} ${i}`;case"before-property":return`${a} ${s} ${i}`}}return t==="en"||!r?.possessive?a==="me"?`my ${i}`:a==="it"?`its ${i}`:`${a}'s ${i}`:`${a} ${i}`}},Se=new se;function F(n,e){return Se.render(n,e)}function q(n){return Se.renderExplicit(n)}function I(n){let e=n.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let r=lt(t);if(r.length===0)throw new Error("No command specified in explicit statement");let i=r[0].toLowerCase(),o=new Map;for(let s=1;s<r.length;s++){let l=r[s],c=l.indexOf(":");if(c===-1)throw new Error(`Invalid role format: "${l}". Expected role:value`);let d=l.slice(0,c),x=l.slice(c+1);if(d==="body"&&x.startsWith("[")){let h=dt(l,c+1),p=l.slice(c+1,h+1);o.set(d,{type:"expression",raw:p});continue}let y=ut(x);o.set(d,y)}if(i==="on"){let s=o.get("event");if(!s)throw new Error("Event handler requires event role: [on event:click ...]");let l=o.get("body"),c=[];return l&&l.type==="expression"&&c.push(I(l.raw)),o.delete("body"),W(s,c,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,l]of o)a[s]=l;return M(i,a,{sourceLanguage:"explicit"})}function lt(n){let e=[],t="",r=!1,i="",o=0;for(let a=0;a<n.length;a++){let s=n[a];if(r){t+=s,s===i&&n[a-1]!=="\\"&&(r=!1);continue}if(s==='"'||s==="'"){r=!0,i=s,t+=s;continue}if(s==="["){o++,t+=s;continue}if(s==="]"){o--,t+=s;continue}if(s===" "&&o===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function ut(n){if(n.startsWith("#")||n.startsWith(".")||n.startsWith("[")||n.startsWith("@")||n.startsWith("*"))return L(n);if(n.startsWith('"')||n.startsWith("'")){let t=n.slice(1,-1);return E(t,"string")}if(n==="true")return E(!0,"boolean");if(n==="false")return E(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(n.toLowerCase()))return w(n.toLowerCase());let e=n.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?E(n,"duration"):E(t,"number")}return E(n,"string")}function dt(n,e){let t=0;for(let r=e;r<n.length;r++)if(n[r]==="[")t++;else if(n[r]==="]"&&(t--,t===0))return r;return n.length-1}function $(n){let e=n.trim();return e.startsWith("[")&&e.endsWith("]")}var ce=class{parse(e,t){let r=oe(e,t),i=N(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((d,x)=>x.priority-d.priority),a=o.filter(d=>d.command==="on"),s=O.matchBest(r,a);if(s)return this.buildEventHandler(s,r,t);let l=o.filter(d=>d.command!=="on"),c=O.matchBest(r,l);if(c)return this.buildCommand(c,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return ae()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let r={};for(let[i,o]of e.captured)r[i]=o;return M(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,r){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=O.extractEventModifiers(t),a,s=e.captured.get("action");if(s&&s.type==="literal"){let l=s.value,c={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(c[y]=h);let d=M(l,c,{sourceLanguage:r,patternId:e.pattern.id}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=N(r).filter(m=>m.command!=="on").sort((m,g)=>g.priority-m.priority),h=N(r).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,g)=>g.priority-m.priority),p=this.parseBodyWithGrammarPatterns(t,y,h,r);p.length>0?a=[d,...p]:a=[d]}else a=[d]}else{let l=N(r).filter(c=>c.command!=="on").sort((c,d)=>d.priority-c.priority);a=this.parseBodyWithClauses(t,l,r)}return W(i,a,o,{sourceLanguage:r,patternId:e.pattern.id})}parseBodyWithClauses(e,t,r){let i=[],o=[];for(;!e.isAtEnd();){let a=e.peek();if(!a)break;let s=a.kind==="conjunction"||a.kind==="keyword"&&this.isThenKeyword(a.value,r),l=a.kind==="keyword"&&this.isEndKeyword(a.value,r);if(s){if(o.length>0){let c=this.parseClause(o,t,r);i.push(...c),o.length=0}e.advance();continue}if(l){if(o.length>0){let c=this.parseClause(o,t,r);i.push(...c)}e.advance();break}o.push(a),e.advance()}if(o.length>0){let a=this.parseClause(o,t,r);i.push(...a)}return i.length>1?[$e(i,"then",{sourceLanguage:r})]:i}parseClause(e,t,r){if(e.length===0)return[];let i=new A(e,r),o=[];for(;!i.isAtEnd();){let a=O.matchBest(i,t);a?o.push(this.buildCommand(a,r)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,r,i){let o=[];for(;!e.isAtEnd();){let a=e.peek();if(a&&this.isThenKeyword(a.value,i)){e.advance();continue}if(a&&this.isEndKeyword(a.value,i)){e.advance();break}let s=!1;if(r.length>0){let l=O.matchBest(e,r);if(l){let c=l.pattern.command,d={};for(let[h,p]of l.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(d[h]=p);let x=M(c,d,{sourceLanguage:i,patternId:l.pattern.id});o.push(x),s=!0;let y=l.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!s){let l=O.matchBest(e,t);l&&(o.push(this.buildCommand(l,i)),s=!0)}s||e.advance()}return o}isThenKeyword(e,t){let r={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(r[t]||r.en).has(e.toLowerCase())}isEndKeyword(e,t){let r={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(r[t]||r.en).has(e.toLowerCase())}},ve=new ce;function j(n,e){return ve.parse(n,e)}function Ee(n,e){return ve.canParse(n,e)}function Te(n,e){if($(n))return n;let t=j(n,e);return q(t)}function be(n,e){let t=I(n);return F(t,e)}function ke(n,e){return $(n)?I(n):j(n,e)}var pt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),mt=new Set(["and","or","not","no"]),ft=new Set(["true","false","null","undefined"]),gt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ue(n){let e=[],t=0,r=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 n[t+p]??""}function s(){let p=n[t];return t++,p===`
|
|
2
|
-
`?(r++,i=1):i++,p}function l(){for(;t<n.length&&/\s/.test(n[t]);)s()}function c(p){let m="";for(;t<n.length&&p(n[t]);)m+=s();return m}function d(p){let m=p;for(s();t<n.length&&n[t]!==p;)n[t]==="\\"&&t+1<n.length&&(m+=s()),m+=s();return t<n.length&&(m+=s()),m}function x(){let p="`";for(s();t<n.length&&n[t]!=="`";)n[t]==="\\"&&t+1<n.length&&(p+=s()),p+=s();return t<n.length&&(p+=s()),p}function y(){let p="<";for(s();t<n.length&&(p+=s(),!p.endsWith("/>")););return p}function h(p,m,g){return{type:p,value:m,start:g,end:t,line:r,column:i-m.length}}for(;t<n.length&&(l(),!(t>=n.length));){let p=t,m=a();if(m==="'"&&a(1)==="s"&&!/\w/.test(a(2))){s(),s(),e.push(h("POSSESSIVE","'s",p));continue}if(m==='"'||m==="'"){let g=d(m);e.push(h("STRING",g,p));continue}if(m==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,p));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(a(1))){let g=y();e.push(h("QUERY_SELECTOR",g,p));continue}if(m==="#"&&o()){s();let g=c(T=>/[\w-]/.test(T));e.push(h("ID_SELECTOR","#"+g,p));continue}if(m==="."&&/[a-zA-Z_-]/.test(a(1))&&o()){s();let g=c(T=>/[\w-]/.test(T));e.push(h("CLASS_SELECTOR","."+g,p));continue}if(m==="["&&o()){let g=a(1);if(g==="@"||/[a-zA-Z]/.test(g)){let T="";for(T+=s();t<n.length&&n[t]!=="]";)n[t]==='"'||n[t]==="'"?T+=d(n[t]):T+=s();t<n.length&&(T+=s()),e.push(h("ATTRIBUTE_SELECTOR",T,p));continue}}if(m==="["){s(),e.push(h("LBRACKET","[",p));continue}if(m==="]"){s(),e.push(h("RBRACKET","]",p));continue}if(/\d/.test(m)){let g=c(ue=>/[\d.]/.test(ue)),T=t,Z=c(ue=>/[a-zA-Z]/.test(ue));gt.has(Z)?e.push(h("TIME_EXPRESSION",g+Z,p)):(t=T,e.push(h("NUMBER",g,p)));continue}if(m==="("){s(),e.push(h("LPAREN","(",p));continue}if(m===")"){s(),e.push(h("RPAREN",")",p));continue}if(m==="{"){s(),e.push(h("LBRACE","{",p));continue}if(m==="}"){s(),e.push(h("RBRACE","}",p));continue}if(m===","){s(),e.push(h("COMMA",",",p));continue}if(m===":"){s(),e.push(h("COLON",":",p));continue}if(m==="."){s(),e.push(h("DOT",".",p));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){s(),e.push(h("OPERATOR",m,p));continue}if(m==="="||m==="!"||m==="<"||m===">"){let g=s();a()==="="&&(g+=s()),e.push(h("COMPARISON",g,p));continue}if(/[a-zA-Z_$]/.test(m)){let g=c(Z=>/[\w$]/.test(Z)),T=g.toLowerCase();pt.has(T)?e.push(h("CONTEXT_VAR",g,p)):mt.has(T)?e.push(h("LOGICAL",g,p)):ft.has(T)?e.push(h("BOOLEAN",g,p)):e.push(h("IDENTIFIER",g,p));continue}s()}return e.push(h("EOF","",t)),e}var le=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ue(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,r=this.parseAnd();e=this.createBinaryExpression(t,e,r)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,r=this.parseEquality();e=this.createBinaryExpression(t,e,r)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,r=this.parseComparison();e=this.createBinaryExpression(t,e,r)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,r=this.parseAddition();e=this.createBinaryExpression(t,e,r)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,r=this.parseMultiplication();e=this.createBinaryExpression(t,e,r)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,r=this.parseUnary();e=this.createBinaryExpression(t,e,r)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let r;if(this.check("STRING"))r=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))r=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:r,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(r=>({type:"objectProperty",key:r.key,value:r.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let r=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:r,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,r){return{type:"literal",value:e,dataType:t,raw:r.value,start:r.start,end:r.end,line:r.line,column:r.column}}createSelector(e,t,r){return{type:"selector",value:e,selector:e,selectorType:t,start:r.start,end:r.end,line:r.line,column:r.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,r){return{type:"binaryExpression",operator:e,left:t,right:r,start:t.start,end:r.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Ne(n){return new le().parse(n)}function k(n,e){switch(n.type){case"literal":return ht(n);case"selector":return yt(n,e);case"reference":return xt(n);case"property-path":return St(n,e);case"expression":return vt(n);default:let t=n;throw new Error(`Unknown semantic value type: ${t.type}`)}}function ht(n){let e={type:"literal",value:n.value};return n.dataType?{...e,dataType:n.dataType}:e}function yt(n,e){return e&&n.value.startsWith("*")&&/^[a-zA-Z-]/.test(n.value.slice(1))&&e.push(`Converted '${n.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:n.value,selector:n.value,selectorType:n.selectorKind}}function xt(n){return{type:"contextReference",contextType:n.value,name:n.value}}function St(n,e){return{type:"propertyAccess",object:k(n.object,e),property:n.property}}function vt(n){let e=Ne(n.raw);return!e.success||!e.node?{type:"identifier",name:n.raw}:e.node}function De(n,e){return n.roles.get(e)}function u(n,e,t){let r=De(n,e);return r?k(r,t):void 0}function f(n,e=[],t,r={}){let i={type:"command",name:n,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),r.isBlocking&&(i.isBlocking=r.isBlocking),r.implicitTarget&&(i.implicitTarget=r.implicitTarget),i}var Et={action:"toggle",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=u(n,"duration"),o=t?[t]:[],a={};return r&&(a.on=r),i&&(a.for=i),f("toggle",o,a)}},Tt={action:"add",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("add",i,o)}},bt={action:"remove",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("remove",i,o)}},kt={action:"set",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o={};return t&&i.push(t),r&&(o.to=r),f("set",i,o)}},Nt={action:"show",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"duration"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.with=i),f("show",o,a)}},Ct={action:"hide",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"duration"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.with=i),f("hide",o,a)}},wt={action:"increment",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"quantity"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.by=i),f("increment",o,a)}},Rt={action:"decrement",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"quantity"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.by=i),f("decrement",o,a)}},Pt={action:"wait",toAST(n,e){let t=u(n,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Lt={action:"log",toAST(n,e){let t=u(n,"patient"),r=[];return t&&r.push(t),f("log",r)}},Mt={action:"put",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=De(n,"method"),o=t?[t]:[],a={};if(r){let s=i?.type==="literal"?String(i.value):"into";a[s]=r}return f("put",o,a)}},At={action:"fetch",toAST(n,e){let t=u(n,"source"),r=u(n,"method"),i=u(n,"responseType"),o=u(n,"patient"),a=t?[t]:[],s={};return r&&(s.with=r),i&&(s.as=i),o&&(s.body=o),f("fetch",a,s,{isBlocking:!0})}},zt={action:"append",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("append",i,o)}},Vt={action:"prepend",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("prepend",i,o)}},Ot={action:"trigger",toAST(n,e){let t=u(n,"event"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.on=r),f("trigger",i,o)}},It={action:"send",toAST(n,e){let t=u(n,"event"),r=u(n,"destination"),i=u(n,"patient"),o=t?[t]:[],a={};return r&&(a.to=r),i&&(a.detail=i),f("send",o,a)}},_t={action:"go",toAST(n,e){let t=u(n,"source"),r=u(n,"destination"),i=[],o={};return t&&i.push(t),r&&(o.to=r),f("go",i,o)}},Bt={action:"transition",toAST(n,e){let t=u(n,"patient"),r=u(n,"goal"),i=u(n,"duration"),o=u(n,"destination"),a=t?[t]:[],s={};return r&&(s.to=r),i&&(s.over=i),o&&(s.on=o),f("transition",a,s)}},Kt={action:"focus",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o={},a=t??r;return a&&i.push(a),f("focus",i,o)}},Wt={action:"blur",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("blur",i)}},$t={action:"get",toAST(n,e){let t=u(n,"source"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("get",i)}},jt={action:"take",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("take",i,o)}},Ut={action:"call",toAST(n,e){let t=u(n,"patient");return f("call",t?[t]:[])}},Dt={action:"return",toAST(n,e){let t=u(n,"patient");return f("return",t?[t]:[])}},Ft={action:"halt",toAST(n,e){return f("halt",[])}},qt={action:"throw",toAST(n,e){let t=u(n,"patient");return f("throw",t?[t]:[])}},Ht={action:"settle",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},Gt={action:"swap",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=u(n,"destination"),o=u(n,"style"),a=[],s={};return t&&a.push(t),r&&a.push(r),i&&(s.on=i),o&&(s.with=o),f("swap",a,s)}},Xt={action:"morph",toAST(n,e){let t=u(n,"source"),r=u(n,"destination"),i=u(n,"patient"),o=[],a={},s=t??i;return s&&o.push(s),r&&(a.on=r),f("morph",o,a)}},Zt={action:"clone",toAST(n,e){let t=u(n,"source"),r=u(n,"destination"),i=u(n,"patient"),o=[],a={},s=t??i;return s&&o.push(s),r&&(a.into=r),f("clone",o,a)}},Qt={action:"make",toAST(n,e){let t=u(n,"patient");return f("make",t?[t]:[])}},Yt={action:"measure",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=u(n,"source"),o=[],a={};t&&o.push(t);let s=r??i;return s&&(a.of=s),f("measure",o,a)}},Jt={action:"tell",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("tell",i)}},er={action:"js",toAST(n,e){let t=u(n,"patient");return f("js",t?[t]:[])}},tr={action:"async",toAST(n,e){return f("async",[])}},rr={action:"if",toAST(n,e){let t=u(n,"condition");return f("if",t?[t]:[])}},nr={action:"unless",toAST(n,e){let t=u(n,"condition");return f("unless",t?[t]:[])}},ir={action:"repeat",toAST(n,e){let t=u(n,"quantity"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("repeat",i)}},or={action:"for",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.in=r),f("for",i,o)}},ar={action:"while",toAST(n,e){let t=u(n,"condition");return f("while",t?[t]:[])}},sr={action:"continue",toAST(n,e){return f("continue",[])}},cr={action:"default",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.to=r),f("default",i,o)}},lr={action:"init",toAST(n,e){return f("init",[])}},ur={action:"behavior",toAST(n,e){let t=u(n,"patient");return f("behavior",t?[t]:[])}},dr={action:"install",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.on=r),f("install",i,o)}},pr={action:"on",toAST(n,e){let t=u(n,"event"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("on",i,o)}},Fe=new Map([["toggle",Et],["add",Tt],["remove",bt],["set",kt],["show",Nt],["hide",Ct],["increment",wt],["decrement",Rt],["wait",Pt],["log",Lt],["put",Mt],["fetch",At],["append",zt],["prepend",Vt],["get",$t],["take",jt],["trigger",Ot],["send",It],["on",pr],["go",_t],["transition",Bt],["focus",Kt],["blur",Wt],["call",Ut],["return",Dt],["halt",Ft],["throw",qt],["settle",Ht],["swap",Gt],["morph",Xt],["clone",Zt],["measure",Yt],["make",Qt],["tell",Jt],["default",cr],["js",er],["async",tr],["if",rr],["unless",nr],["repeat",ir],["for",or],["while",ar],["continue",sr],["init",lr],["behavior",ur],["install",dr]]);function H(n){return Fe.get(n)}function Ce(n){Fe.set(n.action,n)}var G=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=H(e.action);if(t){let r=t.toAST(e,this);if("ast"in r&&"warnings"in r){let i=r;return this.warnings.push(...i.warnings),i.ast}else return r}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],r={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let s of i){let l=e.roles.get(s);l&&t.push(k(l))}for(let s of o){let l=e.roles.get(s);if(l){let c=this.roleToModifierKey(s);r[c]=k(l)}}let a={type:"command",name:e.action,args:t};return Object.keys(r).length>0?{...a,modifiers:r}:a}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),r,i;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(i=g.split(/\s+or\s+|\|/).map(T=>T.trim()),r=i[0]):r=g}else t?.type==="reference"?r=t.value:r="click";let o=e.body.map(g=>this.build(g)),a=e.roles.get("source"),s,l;a?.type==="selector"?(s=a.value,l=a.value):a?.type==="reference"?l=a.value:a?.type==="literal"&&(l=String(a.value));let c=e.roles.get("condition"),d=c?k(c):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 m=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:r,commands:o,...i&&i.length>1?{events:i}:{},...p?{selector:p}:{},...l?{target:l}:{},...d?{condition:d}:{},...y?{watchTarget:y}:{},...m&&m.length>0?{args:m,params:m}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let r=k(t),i=e.thenBranch.map(s=>this.build(s)),o=e.elseBranch?.map(s=>this.build(s)),a=[r,{type:"block",commands:i}];return o&&o.length>0&&a.push({type:"block",commands:o}),{type:"command",name:"if",args:a}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),r=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&r.push(k(i));break}case"for":{e.loopVariable&&r.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&r.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&r.push(k(i));break}case"forever":break}return r.push({type:"block",commands:t}),{type:"command",name:"repeat",args:r}}buildBlock(e){return{type:"block",commands:e.map(r=>this.build(r))}}};function qe(n){let e=new G;return{ast:e.build(n),warnings:e.warnings}}var _=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let r=this.makeKey(e,t),i=this.cache.get(r);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(r),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(r),i.lastAccessed=Date.now(),this.cache.set(r,i),this.stats.hits++,i.result}set(e,t,r){if(!this.config.enabled||r.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:r,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let r=this.makeKey(e,t),i=this.cache.get(r);return i?this.isExpired(i)?(this.cache.delete(r),this.stats.expirations++,!1):!0:!1}delete(e,t){let r=this.makeKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},we=new _;var X=class{constructor(e={}){this.patternMatcher=new D,this.languages=new Set(J()),e.cache===!1?this.cache=new _({enabled:!1}):this.cache=e.cache?new _(e.cache):we}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let r=this.cache.get(e,t);if(r)return r;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let r=We(t);if(!r)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=r.tokenize(e),o=N(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let a=this.patternMatcher.matchBest(i,o);if(!a)return{confidence:0,errors:["No pattern matched the input"]};let s=this.buildSemanticNode(a);return{confidence:a.confidence,command:{name:a.pattern.command,roles:a.captured},node:s,tokensConsumed:a.consumedTokens}}catch(r){return{confidence:0,errors:[r instanceof Error?r.message:String(r)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function He(n){return new X(n)}var Re=.5,Ge=.8;function Xe(n,e=Re){return n.confidence>=e&&n.command!==void 0}var mr="1.0.0-zh",fr=["zh"];function gr(){return[...fr]}function Ze(n){if(n!=="zh")throw new Error(`Language not supported in this bundle: ${n}. Supported: zh`)}function hr(n,e){return Ze(e),[...oe(n,e).tokens]}function Qe(n){return Ze(n),N(n)}function yr(n,e){return Qe(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}return nt(xr);})();
|
|
1
|
+
"use strict";var LokaScriptSemanticZh=(()=>{var me=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=(n,e)=>{for(var t in e)me(n,t,{get:e[t],enumerable:!0})},st=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of it(e))!ot.call(n,i)&&i!==t&&me(n,i,{get:()=>e[i],enumerable:!(r=nt(e,i))||r.enumerable});return n};var lt=n=>st(me({},"__esModule",{value:!0}),n);var br={};at(br,{ASTBuilder:()=>Y,DEFAULT_CONFIDENCE_THRESHOLD:()=>Me,HIGH_CONFIDENCE_THRESHOLD:()=>Je,SemanticAnalyzerImpl:()=>J,VERSION:()=>xr,buildAST:()=>Qe,canParse:()=>ke,chineseProfile:()=>B,chineseTokenizer:()=>ae,createCommandNode:()=>A,createEventHandler:()=>U,createLiteral:()=>E,createPropertyPath:()=>j,createReference:()=>P,createSelector:()=>M,createSemanticAnalyzer:()=>Ye,fromExplicit:()=>Ce,getCommandMapper:()=>Q,getPatternsForLanguage:()=>rt,getPatternsForLanguageAndCommand:()=>Tr,getProfile:()=>he,getSupportedLanguages:()=>vr,getTokenizer:()=>ge,isExplicitSyntax:()=>D,isLanguageSupported:()=>_e,parse:()=>F,parseAny:()=>we,parseExplicit:()=>$,registerCommandMapper:()=>Re,render:()=>X,renderExplicit:()=>Z,shouldUseSemanticResult:()=>et,toExplicit:()=>Ne,tokenize:()=>Er,tryGetProfile:()=>L});var w=new Map,z=new Map,q=new Map;var Ae=null;function Ve(n,e){let t={...n};for(let r of Object.keys(e)){let i=e[r],o=n[r];i!==void 0&&(typeof i=="object"&&i!==null&&!Array.isArray(i)&&typeof o=="object"&&o!==null&&!Array.isArray(o)?t[r]=Ve(o,i):t[r]=i)}return t}function ct(n,e){return Ve(n,e)}function fe(n){if(!n.extends)return n;let e=z.get(n.extends);if(!e)return console.warn(`[Registry] Profile '${n.code}' extends '${n.extends}' but base is not registered. Make sure to import the base language before the variant.`),n;let t=fe(e);return ct(t,n)}function Oe(n,e,t){w.set(n,e),z.set(n,t),q.delete(n)}var ze=new Map;function V(n){return n.split("-")[0]}function O(n){return n.includes("-")}function ge(n){let e=w.get(n);if(!e&&O(n)){let t=V(n);e=w.get(t)}if(!e){let t=Array.from(w.keys()).join(", ");throw new Error(`Language '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return e}function he(n){let e=z.get(n);if(!e&&O(n)){let t=V(n);e=z.get(t)}if(!e){let t=Array.from(z.keys()).join(", ");throw new Error(`Language profile '${n}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${n}';`)}return fe(e)}function Ie(n){let e=w.get(n);return!e&&O(n)&&(e=w.get(V(n))),e}function L(n){let e=z.get(n);return!e&&O(n)&&(e=z.get(V(n))),e?fe(e):void 0}function te(){return Array.from(w.keys())}function _e(n){return w.has(n)?!0:O(n)?w.has(V(n)):!1}function Be(n,e){return ge(e).tokenize(n)}function N(n){let e=q.get(n);if(!e&&O(n)&&(e=q.get(V(n))),e)return e;let t=ze.get(n);if(!t&&O(n)&&(t=ze.get(V(n))),t)return q.set(n,t),t;if(!Ae)throw new Error(`No patterns registered for language '${n}'. Either import the language module or set a pattern generator.`);let r=he(n),i=Ae(r);return q.set(n,i),i}function Ke(n,e){return N(n).filter(t=>t.command===e).sort((t,r)=>r.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 S(n,e){return{start:n,end:e}}function v(n,e,t,r){if(typeof r=="string")return{value:n,kind:e,position:t,normalized:r};if(r){let{normalized:i,stem:o,stemConfidence:a}=r,s={value:n,kind:e,position:t};return i!==void 0&&(s.normalized=i),o!==void 0&&(s.stem=o,a!==void 0&&(s.stemConfidence=a)),s}return{value:n,kind:e,position:t}}function _(n){return/\s/.test(n)}function ne(n){return n==="#"||n==="."||n==="["||n==="@"||n==="*"||n==="<"}function ie(n){return n==='"'||n==="'"||n==="`"||n==="\u300C"||n==="\u300D"}function C(n){return/\d/.test(n)}function $e(n){return/[a-zA-Z]/.test(n)}function b(n){return/[a-zA-Z0-9_-]/.test(n)}function ye(n){return e=>{let t=e.charCodeAt(0);return n.some(([r,i])=>t>=r&&t<=i)}}function We(n,e){if(e>=n.length)return null;let t=n[e];if(!ne(t))return null;let r=e,i="";if(t==="#"||t==="."){for(i+=n[r++];r<n.length&&b(n[r]);)i+=n[r++];if(i.length<=1)return null;if(r<n.length&&n[r]==="."&&t==="#"){let a=r+1;for(;a<n.length&&b(n[a]);)a++;if(a<n.length&&n[a]==="(")return i}}else if(t==="["){let o=1,a=!1,s=null,c=!1;for(i+=n[r++];r<n.length&&o>0;){let l=n[r];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--,r++}if(o!==0)return null}else if(t==="@"){for(i+=n[r++];r<n.length&&b(n[r]);)i+=n[r++];if(i.length<=1)return null}else if(t==="*"){for(i+=n[r++];r<n.length&&b(n[r]);)i+=n[r++];if(i.length<=1)return null}else if(t==="<"){if(i+=n[r++],r>=n.length||!$e(n[r]))return null;for(;r<n.length&&b(n[r]);)i+=n[r++];for(;r<n.length;){let o=n[r];if(o==="."){if(i+=n[r++],r>=n.length||!b(n[r]))return null;for(;r<n.length&&b(n[r]);)i+=n[r++]}else if(o==="#"){if(i+=n[r++],r>=n.length||!b(n[r]))return null;for(;r<n.length&&b(n[r]);)i+=n[r++]}else if(o==="["){let a=1,s=!1,c=null,l=!1;for(i+=n[r++];r<n.length&&a>0;){let d=n[r];i+=d,l?l=!1:d==="\\"?l=!0:s?d===c&&(s=!1,c=null):d==='"'||d==="'"||d==="`"?(s=!0,c=d):d==="["?a++:d==="]"&&a--,r++}if(a!==0)return null}else break}for(;r<n.length&&_(n[r]);)i+=n[r++];if(r<n.length&&n[r]==="/")for(i+=n[r++];r<n.length&&_(n[r]);)i+=n[r++];if(r>=n.length||n[r]!==">")return null;i+=n[r++]}return i||null}function ut(n,e){if(e>=n.length||n[e]!=="'"||e+1>=n.length||n[e+1].toLowerCase()!=="s")return!1;if(e+2>=n.length)return!0;let r=n[e+2];return _(r)||r==="*"||!b(r)}function je(n,e){if(e>=n.length)return null;let t=n[e];if(!ie(t)||t==="'"&&ut(n,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,a=t,s=!1;for(;o<n.length;){let c=n[o];if(a+=c,s)s=!1;else if(c==="\\")s=!0;else if(c===i)return a;o++}return a}function oe(n,e){if(e>=n.length)return!1;let t=n[e],r=n[e+1]||"",i=n[e+2]||"";if(t==="/"&&r!=="/"&&/[a-zA-Z0-9._-]/.test(r)||t==="/"&&r==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(r==="/"||r==="."&&i==="/"))return!0;let o=n.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function Ue(n,e){if(!oe(n,e))return null;let t=e,r="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<n.length;){let o=n[t];if(o==="#"){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=o,t++;t<n.length&&/[a-zA-Z0-9_-]/.test(n[t]);)r+=n[t++];break}if(i.test(o))r+=o,t++;else break}return r.length<2?null:r}function De(n,e){if(e>=n.length)return null;let t=n[e];if(!C(t)&&t!=="-"&&t!=="+")return null;let r=e,i="";if((n[r]==="-"||n[r]==="+")&&(i+=n[r++]),r>=n.length||!C(n[r]))return null;for(;r<n.length&&C(n[r]);)i+=n[r++];if(r<n.length&&n[r]===".")for(i+=n[r++];r<n.length&&C(n[r]);)i+=n[r++];return r<n.length&&(n.slice(r,r+2)==="ms"?i+="ms":(n[r]==="s"||n[r]==="m"||n[r]==="h")&&(i+=n[r])),i}var re=class re{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let r=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(r.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let a of o.alternatives)r.set(a,{native:a,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))r.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&r.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let a of o.alternatives)r.set(a,{native:a,normalized:i})}for(let i of t)r.set(i.native,i);this.profileKeywords=Array.from(r.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let r of this.profileKeywords)if(e.slice(t).startsWith(r.native))return v(r.native,"keyword",S(t,t+r.native.length),r.normalized);return null}isKeywordStart(e,t){let r=e.slice(t);return this.profileKeywords.some(i=>r.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,r){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let a={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return v(e,"keyword",S(t,r),a)}trySelector(e,t){let r=We(e,t);return r?v(r,"selector",S(t,t+r.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let r=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!r)return null;let i=r[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],a=r[1];return{...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 r=je(e,t);return r?v(r,"literal",S(t,t+r.length)):null}tryNumber(e,t){let r=De(e,t);return r?v(r,"literal",S(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,i=!1){let o=t;if(i)for(;o<e.length&&_(e[o]);)o++;let a=e.slice(o);for(let s of r){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 d=a[s.length]||"";if(b(d))continue}return{suffix:s.suffix,endPos:o+s.length}}}return null}parseBaseNumber(e,t,r=!0){let i=t,o="";if(r&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!C(e[i]))return null;for(;i<e.length&&C(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&C(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,r,i={}){let{allowSign:o=!0,skipWhitespace:a=!1}=i,s=this.parseBaseNumber(e,t,o);if(!s)return null;let{number:c,endPos:l}=s,d=[...r,...re.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,l,d,a);return x&&(c+=x.suffix,l=x.endPos),v(c,"literal",S(t,l))}tryUrl(e,t){let r=Ue(e,t);return r?v(r,"url",S(t,t+r.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!b(e[t+1]))return null;let r=t+1;for(;r<e.length&&b(e[r]);)r++;let i=e.slice(t,r);return v(i,"identifier",S(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return v(r,"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,r){for(let i of r)if(e.slice(t,t+i.length)===i)return v(i,"particle",S(t,t+i.length));return null}};re.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var H=re;var B={code:"zh",name:"Chinese",nativeName:"\u4E2D\u6587",direction:"ltr",wordOrder:"SVO",markingStrategy:"preposition",usesSpaces:!1,verb:{position:"second",subjectDrop:!0},references:{me:"\u6211",it:"\u5B83",you:"\u4F60",result:"\u7ED3\u679C",event:"\u4E8B\u4EF6",target:"\u76EE\u6807",body:"\u4E3B\u4F53"},possessive:{marker:"\u7684",markerPosition:"between",keywords:{\u6211\u7684:"me",\u4F60\u7684:"you",\u5B83\u7684:"it",\u4ED6\u7684:"it",\u5979\u7684:"it"}},roleMarkers:{destination:{primary:"\u5728",alternatives:["\u5230","\u4E8E"],position:"before"},source:{primary:"\u4ECE",alternatives:["\u7531"],position:"before"},patient:{primary:"\u628A",position:"before"},style:{primary:"\u7528",alternatives:["\u4EE5"],position:"before"}},keywords:{toggle:{primary:"\u5207\u6362",normalized:"toggle"},add:{primary:"\u6DFB\u52A0",alternatives:["\u52A0"],normalized:"add"},remove:{primary:"\u79FB\u9664",alternatives:["\u5220\u9664","\u53BB\u6389"],normalized:"remove"},put:{primary:"\u653E\u7F6E",alternatives:["\u653E","\u653E\u5165"],normalized:"put"},append:{primary:"\u8FFD\u52A0",alternatives:["\u9644\u52A0"],normalized:"append"},prepend:{primary:"\u524D\u7F6E",alternatives:["\u9884\u7F6E"],normalized:"prepend"},take:{primary:"\u83B7\u53D6",normalized:"take"},make:{primary:"\u5236\u4F5C",normalized:"make"},clone:{primary:"\u590D\u5236",normalized:"clone"},swap:{primary:"\u4EA4\u6362",normalized:"swap"},morph:{primary:"\u53D8\u5F62",alternatives:["\u8F6C\u6362"],normalized:"morph"},set:{primary:"\u8BBE\u7F6E",alternatives:["\u8BBE\u5B9A"],normalized:"set"},get:{primary:"\u83B7\u5F97",alternatives:["\u83B7\u53D6","\u53D6\u5F97"],normalized:"get"},increment:{primary:"\u589E\u52A0",normalized:"increment"},decrement:{primary:"\u51CF\u5C11",normalized:"decrement"},log:{primary:"\u65E5\u5FD7",normalized:"log"},show:{primary:"\u663E\u793A",alternatives:["\u5C55\u793A"],normalized:"show"},hide:{primary:"\u9690\u85CF",normalized:"hide"},transition:{primary:"\u8FC7\u6E21",normalized:"transition"},on:{primary:"\u5F53",alternatives:["\u5728...\u65F6"],normalized:"on"},trigger:{primary:"\u89E6\u53D1",normalized:"trigger"},send:{primary:"\u53D1\u9001",normalized:"send"},focus:{primary:"\u805A\u7126",normalized:"focus"},blur:{primary:"\u5931\u7126",normalized:"blur"},click:{primary:"\u70B9\u51FB",normalized:"click"},hover:{primary:"\u60AC\u505C",alternatives:["\u60AC\u6D6E"],normalized:"hover"},submit:{primary:"\u63D0\u4EA4",normalized:"submit"},input:{primary:"\u8F93\u5165",normalized:"input"},change:{primary:"\u6539\u53D8",alternatives:["\u53D8\u5316"],normalized:"change"},go:{primary:"\u524D\u5F80",normalized:"go"},wait:{primary:"\u7B49\u5F85",normalized:"wait"},fetch:{primary:"\u83B7\u53D6",normalized:"fetch"},settle:{primary:"\u7A33\u5B9A",normalized:"settle"},if:{primary:"\u5982\u679C",normalized:"if"},when:{primary:"\u5F53",normalized:"when"},where:{primary:"\u54EA\u91CC",normalized:"where"},else:{primary:"\u5426\u5219",normalized:"else"},repeat:{primary:"\u91CD\u590D",normalized:"repeat"},for:{primary:"\u4E3A",normalized:"for"},while:{primary:"\u5F53",normalized:"while"},continue:{primary:"\u7EE7\u7EED",normalized:"continue"},halt:{primary:"\u505C\u6B62",normalized:"halt"},throw:{primary:"\u629B\u51FA",normalized:"throw"},call:{primary:"\u8C03\u7528",normalized:"call"},return:{primary:"\u8FD4\u56DE",normalized:"return"},then:{primary:"\u7136\u540E",alternatives:["\u63A5\u7740","\u4E4B\u540E"],normalized:"then"},and:{primary:"\u5E76\u4E14",alternatives:["\u548C","\u800C\u4E14"],normalized:"and"},end:{primary:"\u7ED3\u675F",alternatives:["\u7EC8\u6B62","\u5B8C"],normalized:"end"},js:{primary:"JS\u6267\u884C",alternatives:["js"],normalized:"js"},async:{primary:"\u5F02\u6B65",normalized:"async"},tell:{primary:"\u544A\u8BC9",normalized:"tell"},default:{primary:"\u9ED8\u8BA4",normalized:"default"},init:{primary:"\u521D\u59CB\u5316",normalized:"init"},behavior:{primary:"\u884C\u4E3A",normalized:"behavior"},install:{primary:"\u5B89\u88C5",normalized:"install"},measure:{primary:"\u6D4B\u91CF",normalized:"measure"},into:{primary:"\u8FDB\u5165",normalized:"into"},before:{primary:"\u4E4B\u524D",normalized:"before"},after:{primary:"\u4E4B\u540E",normalized:"after"},until:{primary:"\u76F4\u5230",normalized:"until"},event:{primary:"\u4E8B\u4EF6",normalized:"event"},from:{primary:"\u4ECE",normalized:"from"}},tokenization:{boundaryStrategy:"character"},eventHandler:{keyword:{primary:"\u5F53",alternatives:["\u5728...\u65F6"],normalized:"on"},sourceMarker:{primary:"\u4ECE",position:"before"},eventMarker:{primary:"\u5F53",alternatives:["\u5728"],position:"before"},temporalMarkers:["\u5F53","\u5728...\u65F6"]}};var xe=ye([[19968,40959],[13312,19903],[131072,173791],[63744,64255],[194560,195103]]),Se=new Set(["\u628A","\u5728","\u4ECE","\u5230","\u5411","\u7ED9","\u5BF9","\u7528","\u88AB","\u8BA9","\u7684","\u5730","\u5F97","\u4E86","\u7740","\u8FC7","\u5417","\u5462","\u5427"]),dt=["\u7136\u540E","\u63A5\u7740","\u5E76\u4E14","\u6216\u8005","\u5982\u679C","\u90A3\u4E48","\u5426\u5219"],pt=[{native:"\u771F",normalized:"true"},{native:"\u5047",normalized:"false"},{native:"\u7A7A",normalized:"null"},{native:"\u672A\u5B9A\u4E49",normalized:"undefined"},{native:"\u7B2C\u4E00\u4E2A",normalized:"first"},{native:"\u9996\u4E2A",normalized:"first"},{native:"\u6700\u540E\u4E00\u4E2A",normalized:"last"},{native:"\u672B\u4E2A",normalized:"last"},{native:"\u4E0B\u4E00\u4E2A",normalized:"next"},{native:"\u4E0A\u4E00\u4E2A",normalized:"previous"},{native:"\u6700\u8FD1\u7684",normalized:"closest"},{native:"\u7236\u7EA7",normalized:"parent"},{native:"\u70B9\u51FB",normalized:"click"},{native:"\u53CC\u51FB",normalized:"dblclick"},{native:"\u8F93\u5165",normalized:"input"},{native:"\u53D8\u66F4",normalized:"change"},{native:"\u6539\u53D8",normalized:"change"},{native:"\u63D0\u4EA4",normalized:"submit"},{native:"\u6309\u952E",normalized:"keydown"},{native:"\u91CA\u653E\u952E",normalized:"keyup"},{native:"\u9F20\u6807\u79FB\u5165",normalized:"mouseover"},{native:"\u9F20\u6807\u79FB\u51FA",normalized:"mouseout"},{native:"\u83B7\u5F97\u7126\u70B9",normalized:"focus"},{native:"\u5931\u53BB\u7126\u70B9",normalized:"blur"},{native:"\u52A0\u8F7D",normalized:"load"},{native:"\u6EDA\u52A8",normalized:"scroll"},{native:"\u6211\u7684",normalized:"my"},{native:"\u5B83\u7684",normalized:"its"},{native:"\u79D2",normalized:"s"},{native:"\u6BEB\u79D2",normalized:"ms"},{native:"\u5206\u949F",normalized:"m"},{native:"\u5C0F\u65F6",normalized:"h"},{native:"\u548C",normalized:"and"},{native:"\u6216\u8005",normalized:"or"},{native:"\u6216",normalized:"or"},{native:"\u4E0D",normalized:"not"},{native:"\u975E",normalized:"not"},{native:"\u662F",normalized:"is"},{native:"\u82E5",normalized:"if"},{native:"\u4E0D\u7136",normalized:"else"},{native:"\u5FAA\u73AF",normalized:"repeat"},{native:"\u904D\u5386",normalized:"for"},{native:"\u6BCF\u4E2A",normalized:"for"},{native:"\u4E3A\u6BCF",normalized:"for"},{native:"\u4E2D\u6B62",normalized:"halt"},{native:"\u629B",normalized:"throw"},{native:"\u547C\u53EB",normalized:"call"},{native:"\u56DE",normalized:"return"},{native:"\u811A\u672C",normalized:"js"},{native:"\u901A\u77E5",normalized:"tell"},{native:"\u7F3A\u7701",normalized:"default"},{native:"\u521D\u59CB",normalized:"init"},{native:"\u52A8\u4F5C",normalized:"behavior"},{native:"\u6FC0\u53D1",normalized:"trigger"},{native:"\u5BF9\u7126",normalized:"focus"},{native:"\u6A21\u7CCA",normalized:"blur"},{native:"\u8DF3\u8F6C",normalized:"go"},{native:"\u5BFC\u822A",normalized:"go"},{native:"\u6293\u53D6",normalized:"fetch"},{native:"\u83B7\u53D6\u6570\u636E",normalized:"fetch"},{native:"\u5B89\u5B9A",normalized:"settle"},{native:"\u62FF\u53D6",normalized:"take"},{native:"\u53D6",normalized:"take"},{native:"\u521B\u5EFA",normalized:"make"},{native:"\u514B\u9686",normalized:"clone"},{native:"\u8BB0\u5F55",normalized:"log"},{native:"\u6253\u5370",normalized:"log"},{native:"\u52A8\u753B",normalized:"transition"},{native:"\u5230\u91CC\u9762",normalized:"into"},{native:"\u91CC",normalized:"into"},{native:"\u524D",normalized:"before"},{native:"\u540E",normalized:"after"},{native:"\u90A3\u4E48",normalized:"then"},{native:"\u5B8C",normalized:"end"}],mt=[{pattern:"\u6BEB\u79D2",suffix:"ms",length:2},{pattern:"\u5206\u949F",suffix:"m",length:2},{pattern:"\u5C0F\u65F6",suffix:"h",length:2},{pattern:"\u79D2",suffix:"s",length:1},{pattern:"\u5206",suffix:"m",length:1}],ve=class extends H{constructor(){super();this.language="zh";this.direction="ltr";this.initializeKeywordsFromProfile(B,pt)}tokenize(t){let r=[],i=0;for(;i<t.length;){if(_(t[i])){i++;continue}if(ne(t[i])){let s=this.tryEventModifier(t,i);if(s){r.push(s),i=s.position.end;continue}let c=this.trySelector(t,i);if(c){r.push(c),i=c.position.end;continue}}if(ie(t[i])||t[i]==="\u201C"||t[i]==="\u201D"||t[i]==="\u2018"||t[i]==="\u2019"){let s=this.tryChineseString(t,i);if(s){r.push(s),i=s.position.end;continue}}if(oe(t,i)){let s=this.tryUrl(t,i);if(s){r.push(s),i=s.position.end;continue}}if(C(t[i])){let s=this.extractChineseNumber(t,i);if(s){r.push(s),i=s.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){r.push(o),i=o.position.end;continue}let a=this.tryMultiCharParticle(t,i,dt);if(a){r.push(a),i=a.position.end;continue}if(xe(t[i])){let s=this.extractChineseWord(t,i);if(s){r.push(s),i=s.position.end;continue}}if(b(t[i])){let s=this.extractAsciiWord(t,i);if(s){r.push(s),i=s.position.end;continue}}i++}return new I(r,"zh")}classifyToken(t){return Se.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")||t.startsWith("<")?"selector":t.startsWith('"')||t.startsWith("'")||t.startsWith("\u201C")||t.startsWith("\u2018")||/^\d/.test(t)?"literal":"identifier"}extractChineseWord(t,r){for(let a of this.profileKeywords){let s=a.native,c=t.slice(r,r+s.length);if(c===s){let l=!0;for(let d=0;d<s.length;d++)if(!xe(s[d])){l=!1;break}if(l)return v(c,"keyword",S(r,r+s.length),a.normalized)}}let i=r,o="";for(;i<t.length;){let a=t[i];if(Se.has(a)&&o.length>0)break;if(xe(a))o+=a,i++;else break}return o?Se.has(o)?v(o,"particle",S(r,i)):v(o,"identifier",S(r,i)):null}extractAsciiWord(t,r){let i=r,o="";for(;i<t.length&&b(t[i]);)o+=t[i++];return o?v(o,"identifier",S(r,i)):null}tryChineseString(t,r){let i=t[r];if(i==='"'||i==="'"||i==="`")return this.tryString(t,r);if(i==="\u201C"){let o=r+1;for(;o<t.length&&t[o]!=="\u201D";)o++;if(o>=t.length)return null;let a=t.slice(r,o+1);return v(a,"literal",S(r,o+1))}if(i==="\u2018"){let o=r+1;for(;o<t.length&&t[o]!=="\u2019";)o++;if(o>=t.length)return null;let a=t.slice(r,o+1);return v(a,"literal",S(r,o+1))}return null}extractChineseNumber(t,r){return this.tryNumberWithTimeUnits(t,r,mt,{allowSign:!1,skipWhitespace:!1})}},ae=new ve;Oe("zh",ae,B);function Fe(n){return Ie(n)}function se(n,e){return Be(n,e)}function le(){return te()}function M(n){let e="complex";return n.startsWith("#")&&!n.includes(" ")?e="id":n.startsWith(".")&&!n.includes(" ")?e="class":n.startsWith("[")&&n.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(n)&&(e="element"),{type:"selector",value:n,selectorKind:e}}function E(n,e){let t={type:"literal",value:n};return e!==void 0?{type:"literal",value:n,dataType:e}:t}function P(n){return{type:"reference",value:n}}function j(n,e){return{type:"property-path",object:n,property:e}}function A(n,e,t){let r={kind:"command",action:n,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function U(n,e,t,r,i){let o=new Map;o.set("event",n);let a={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(a.eventModifiers=t),r!==void 0&&(a.metadata=r),i!==void 0&&i.length>0&&(a.parameterNames=i),a}function qe(n,e="then",t){let r={kind:"compound",action:"compound",roles:new Map,statements:n,chainType:e};return t!==void 0&&(r.metadata=t),r}function Ee(n,e){return!e||e.length===0||e.includes(n)||e.includes("expression")?!0:n==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function He(n,e){return n.possessive?.keywords?.[e]}var R=class R{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let r=e.mark(),i=new Map;if(this.currentProfile=L(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(r),null;let a=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-r.position,confidence:a}}matchBest(e,t){let r=[];for(let o of t){let a=e.mark(),s=this.matchPattern(e,o);s&&r.push(s),e.reset(a)}if(r.length===0)return null;r.sort((o,a)=>{let s=a.pattern.priority-o.pattern.priority;return s!==0?s:a.confidence-o.confidence});let i=r[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,r){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,r)){if(this.isOptional(a))continue;return!1}return!0}matchPatternToken(e,t,r){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r);case"group":return this.matchGroupToken(e,t,r);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(!r)return!1;let i=this.getMatchType(r,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let a=this.getMatchType(r,o);if(a!=="none")return this.totalKeywordMatches++,a==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,r){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,o),!0);let a=this.tryMatchMethodCallExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(a.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,a),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(s.type,t.expectedTypes)?t.optional||!1:(r.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:(r.set(t.role,c),!0);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(l.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,l),!0);let d=this.tokenToSemanticValue(i);return!d||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(d.type)?t.optional||!1:(r.set(t.role,d),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=(t.normalized||t.value).toLowerCase(),i=He(this.currentProfile,r);if(!i)return null;let o=e.mark();e.advance();let a=e.peek();return a&&(a.kind==="identifier"||a.kind==="keyword"&&!this.isStructuralKeyword(a.value)||a.kind==="selector"&&a.value.startsWith("*"))?(e.advance(),j(P(i),a.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(r),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="punctuation"||a.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<R.MAX_METHOD_ARGS;){let 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 r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(r),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(r),null;e.advance();let a=`${t.value}.${o.value}`,s=1;for(;!e.isAtEnd()&&s<R.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let d=e.peek();if(!d||d.kind!=="identifier")break;e.advance(),a+=`.${d.value}`,s++}let c=e.peek();if(c&&c.kind==="punctuation"&&c.value==="("){e.advance();let l=[],d=0;for(;!e.isAtEnd()&&l.length<R.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(d===0){e.advance();break}d--}if(y.kind==="punctuation"&&y.value==="("&&d++,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 r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(r),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(r),null):(e.advance(),j(M(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(r),null;let o=e.peek(1);o&&o.kind,e.advance();let a=i.value.slice(1);return j(M(t.value),a)}matchGroupToken(e,t,r){let i=e.mark(),o=new Set(r.keys());if(!this.matchTokenSequence(e,t.tokens,r)){e.reset(i);for(let s of r.keys())o.has(s)||r.delete(s);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return 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)?P(t):E(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return P(e.value);let r=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(r)?P(r):{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 r=parseFloat(e);return isNaN(r)?E(e,"string"):E(r,"number")}applyExtractionRules(e,t){for(let[r,i]of Object.entries(e.extraction))!t.has(r)&&i.default&&t.set(r,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let r=0,i=0,o=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")i+=1,t.has(l.role)&&(r+=1);else if(l.type==="group"){for(let d of l.tokens)if(d.type==="role"){let x=o(d.role),y=.8;i+=y,t.has(d.role)?r+=y:x&&(r+=y*.6)}}let a=i>0?r/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 r=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(r.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(r.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let r=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,a]of t.entries()){let s=i[o];if(!s||s.length===0)continue;let c=a.metadata;if(c&&typeof c.prepositionValue=="string"){let l=c.prepositionValue;s.includes(l)?r+=.1:r-=.1}}return Math.max(-.1,Math.min(.1,r))}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=t.value.toLowerCase();if(R.ENGLISH_NOISE_WORDS.has(r)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(r=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return r?t:void 0}};R.MAX_PROPERTY_DEPTH=10,R.MAX_METHOD_ARGS=20,R.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var G=R,K=new G;var ce=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let r=Ke(t,e.action);if(r.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,r);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let r=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return r.join(` ${i} `)}getChainWord(e,t){let r=L(t);return r?.keywords?r.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let r=e;return r.statements.map(o=>this.renderExplicit(o)).join(` ${r.chainType} `)}let t=[e.action];for(let[r,i]of e.roles)t.push(`${r}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let r=e;if(r.body&&r.body.length>0){let i=r.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return le()}findBestPattern(e,t){let r=t.map(i=>{let o=i.priority;for(let a of i.template.tokens)a.type==="role"&&(e.roles.has(a.role)?o+=10:a.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return r.sort((i,o)=>o.score-i.score),r.length>0?r[0].pattern:null}renderWithPattern(e,t){let r=[],i=t.language;for(let o of t.template.tokens){let a=this.renderPatternToken(o,e,i);a!==null&&r.push(a)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let a=o.body.map(s=>this.render(s,i));r.push(a.join(" "))}}return r.join(" ")}renderPatternToken(e,t,r){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,r):(e.optional,null)}case"group":{if(!e.tokens.filter(a=>a.type==="role"&&!a.optional).every(a=>t.roles.has(a.role))&&e.optional)return null;if(e.optional&&e.tokens.find(s=>s.type==="role"&&s.role==="destination")){let s=t.roles.get("destination");if(s?.type==="reference"&&s.value==="me")return null}let o=[];for(let a of e.tokens){let s=this.renderPatternToken(a,t,r);s!==null&&o.push(s)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let r=L(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=L(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(r?.possessive?.specialForms&&o){let s=r.possessive.specialForms[o];if(s){let{markerPosition:c,usePossessiveAdjectives:l}=r.possessive;return l&&c==="after-object"?`${i} ${s}`:`${s} ${i}`}}let a=this.valueToNaturalString(e.object,t);if(r?.possessive){let{marker:s,markerPosition:c,usePossessiveAdjectives:l}=r.possessive;if(l&&o&&c==="after-object")return`${i} ${a}`;if(s)switch(c){case"between":return r.usesSpaces?`${a}${s} ${i}`:`${a}${s}${i}`;case"after-object":return`${a}${s} ${i}`;case"before-property":return`${a} ${s} ${i}`}}return t==="en"||!r?.possessive?a==="me"?`my ${i}`:a==="it"?`its ${i}`:`${a}'s ${i}`:`${a} ${i}`}},Te=new ce;function X(n,e){return Te.render(n,e)}function Z(n){return Te.renderExplicit(n)}function $(n){let e=n.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let r=ft(t);if(r.length===0)throw new Error("No command specified in explicit statement");let i=r[0].toLowerCase(),o=new Map;for(let s=1;s<r.length;s++){let c=r[s],l=c.indexOf(":");if(l===-1)throw new Error(`Invalid role format: "${c}". Expected role:value`);let d=c.slice(0,l),x=c.slice(l+1);if(d==="body"&&x.startsWith("[")){let h=ht(c,l+1),p=c.slice(l+1,h+1);o.set(d,{type:"expression",raw:p});continue}let y=gt(x);o.set(d,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($(c.raw)),o.delete("body"),U(s,l,void 0,{sourceLanguage:"explicit"})}let a={};for(let[s,c]of o)a[s]=c;return A(i,a,{sourceLanguage:"explicit"})}function ft(n){let e=[],t="",r=!1,i="",o=0;for(let a=0;a<n.length;a++){let s=n[a];if(r){t+=s,s===i&&n[a-1]!=="\\"&&(r=!1);continue}if(s==='"'||s==="'"){r=!0,i=s,t+=s;continue}if(s==="["){o++,t+=s;continue}if(s==="]"){o--,t+=s;continue}if(s===" "&&o===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function gt(n){if(n.startsWith("#")||n.startsWith(".")||n.startsWith("[")||n.startsWith("@")||n.startsWith("*"))return M(n);if(n.startsWith('"')||n.startsWith("'")){let t=n.slice(1,-1);return E(t,"string")}if(n==="true")return E(!0,"boolean");if(n==="false")return E(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(n.toLowerCase()))return P(n.toLowerCase());let e=n.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?E(n,"duration"):E(t,"number")}return E(n,"string")}function ht(n,e){let t=0;for(let r=e;r<n.length;r++)if(n[r]==="[")t++;else if(n[r]==="]"&&(t--,t===0))return r;return n.length-1}function D(n){let e=n.trim();return e.startsWith("[")&&e.endsWith("]")}var ue=class{parse(e,t){let r=se(e,t),i=N(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((d,x)=>x.priority-d.priority),a=o.filter(d=>d.command==="on"),s=K.matchBest(r,a);if(s)return this.buildEventHandler(s,r,t);let c=o.filter(d=>d.command!=="on"),l=K.matchBest(r,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 le()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let r={};for(let[i,o]of e.captured)r[i]=o;return A(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}buildEventHandler(e,t,r){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=K.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 d=A(c,l,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=N(r).filter(m=>m.command!=="on").sort((m,g)=>g.priority-m.priority),h=N(r).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,g)=>g.priority-m.priority),p=this.parseBodyWithGrammarPatterns(t,y,h,r);p.length>0?a=[d,...p]:a=[d]}else a=[d]}else{let c=N(r).filter(l=>l.command!=="on").sort((l,d)=>d.priority-l.priority);a=this.parseBodyWithClauses(t,c,r)}return U(i,a,o,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,t,r){let i=[],o=[];for(;!e.isAtEnd();){let a=e.peek();if(!a)break;let s=a.kind==="conjunction"||a.kind==="keyword"&&this.isThenKeyword(a.value,r),c=a.kind==="keyword"&&this.isEndKeyword(a.value,r);if(s){if(o.length>0){let l=this.parseClause(o,t,r);i.push(...l),o.length=0}e.advance();continue}if(c){if(o.length>0){let l=this.parseClause(o,t,r);i.push(...l)}e.advance();break}o.push(a),e.advance()}if(o.length>0){let a=this.parseClause(o,t,r);i.push(...a)}return i.length>1?[qe(i,"then",{sourceLanguage:r})]:i}parseClause(e,t,r){if(e.length===0)return[];let i=new I(e,r),o=[];for(;!i.isAtEnd();){let a=K.matchBest(i,t);a?o.push(this.buildCommand(a,r)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,r,i){let o=[];for(;!e.isAtEnd();){let a=e.peek();if(a&&this.isThenKeyword(a.value,i)){e.advance();continue}if(a&&this.isEndKeyword(a.value,i)){e.advance();break}let s=!1;if(r.length>0){let c=K.matchBest(e,r);if(c){let l=c.pattern.command,d={};for(let[h,p]of c.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(d[h]=p);let x=A(l,d,{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=K.matchBest(e,t);c&&(o.push(this.buildCommand(c,i)),s=!0)}s||e.advance()}return o}isThenKeyword(e,t){let r={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(r[t]||r.en).has(e.toLowerCase())}isEndKeyword(e,t){let r={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(r[t]||r.en).has(e.toLowerCase())}},be=new ue;function F(n,e){return be.parse(n,e)}function ke(n,e){return be.canParse(n,e)}function Ne(n,e){if(D(n))return n;let t=F(n,e);return Z(t)}function Ce(n,e){let t=$(n);return X(t,e)}function we(n,e){return D(n)?$(n):F(n,e)}var yt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),xt=new Set(["and","or","not","no"]),St=new Set(["true","false","null","undefined"]),vt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ge(n){let e=[],t=0,r=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 n[t+p]??""}function s(){let p=n[t];return t++,p===`
|
|
2
|
+
`?(r++,i=1):i++,p}function c(){for(;t<n.length&&/\s/.test(n[t]);)s()}function l(p){let m="";for(;t<n.length&&p(n[t]);)m+=s();return m}function d(p){let m=p;for(s();t<n.length&&n[t]!==p;)n[t]==="\\"&&t+1<n.length&&(m+=s()),m+=s();return t<n.length&&(m+=s()),m}function x(){let p="`";for(s();t<n.length&&n[t]!=="`";)n[t]==="\\"&&t+1<n.length&&(p+=s()),p+=s();return t<n.length&&(p+=s()),p}function y(){let p="<";for(s();t<n.length&&(p+=s(),!p.endsWith("/>")););return p}function h(p,m,g){return{type:p,value:m,start:g,end:t,line:r,column:i-m.length}}for(;t<n.length&&(c(),!(t>=n.length));){let p=t,m=a();if(m==="'"&&a(1)==="s"&&!/\w/.test(a(2))){s(),s(),e.push(h("POSSESSIVE","'s",p));continue}if(m==='"'||m==="'"){let g=d(m);e.push(h("STRING",g,p));continue}if(m==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,p));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(a(1))){let g=y();e.push(h("QUERY_SELECTOR",g,p));continue}if(m==="#"&&o()){s();let g=l(T=>/[\w-]/.test(T));e.push(h("ID_SELECTOR","#"+g,p));continue}if(m==="."&&/[a-zA-Z_-]/.test(a(1))&&o()){s();let g=l(T=>/[\w-]/.test(T));e.push(h("CLASS_SELECTOR","."+g,p));continue}if(m==="["&&o()){let g=a(1);if(g==="@"||/[a-zA-Z]/.test(g)){let T="";for(T+=s();t<n.length&&n[t]!=="]";)n[t]==='"'||n[t]==="'"?T+=d(n[t]):T+=s();t<n.length&&(T+=s()),e.push(h("ATTRIBUTE_SELECTOR",T,p));continue}}if(m==="["){s(),e.push(h("LBRACKET","[",p));continue}if(m==="]"){s(),e.push(h("RBRACKET","]",p));continue}if(/\d/.test(m)){let g=l(pe=>/[\d.]/.test(pe)),T=t,ee=l(pe=>/[a-zA-Z]/.test(pe));vt.has(ee)?e.push(h("TIME_EXPRESSION",g+ee,p)):(t=T,e.push(h("NUMBER",g,p)));continue}if(m==="("){s(),e.push(h("LPAREN","(",p));continue}if(m===")"){s(),e.push(h("RPAREN",")",p));continue}if(m==="{"){s(),e.push(h("LBRACE","{",p));continue}if(m==="}"){s(),e.push(h("RBRACE","}",p));continue}if(m===","){s(),e.push(h("COMMA",",",p));continue}if(m===":"){s(),e.push(h("COLON",":",p));continue}if(m==="."){s(),e.push(h("DOT",".",p));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){s(),e.push(h("OPERATOR",m,p));continue}if(m==="="||m==="!"||m==="<"||m===">"){let g=s();a()==="="&&(g+=s()),e.push(h("COMPARISON",g,p));continue}if(/[a-zA-Z_$]/.test(m)){let g=l(ee=>/[\w$]/.test(ee)),T=g.toLowerCase();yt.has(T)?e.push(h("CONTEXT_VAR",g,p)):xt.has(T)?e.push(h("LOGICAL",g,p)):St.has(T)?e.push(h("BOOLEAN",g,p)):e.push(h("IDENTIFIER",g,p));continue}s()}return e.push(h("EOF","",t)),e}var de=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,r=this.parseAnd();e=this.createBinaryExpression(t,e,r)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,r=this.parseEquality();e=this.createBinaryExpression(t,e,r)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,r=this.parseComparison();e=this.createBinaryExpression(t,e,r)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,r=this.parseAddition();e=this.createBinaryExpression(t,e,r)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,r=this.parseMultiplication();e=this.createBinaryExpression(t,e,r)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,r=this.parseUnary();e=this.createBinaryExpression(t,e,r)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let r;if(this.check("STRING"))r=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))r=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:r,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(r=>({type:"objectProperty",key:r.key,value:r.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let r=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:r,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,r){return{type:"literal",value:e,dataType:t,raw:r.value,start:r.start,end:r.end,line:r.line,column:r.column}}createSelector(e,t,r){return{type:"selector",value:e,selector:e,selectorType:t,start:r.start,end:r.end,line:r.line,column:r.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,r){return{type:"binaryExpression",operator:e,left:t,right:r,start:t.start,end:r.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Pe(n){return new de().parse(n)}function k(n,e){switch(n.type){case"literal":return Et(n);case"selector":return Tt(n,e);case"reference":return bt(n);case"property-path":return kt(n,e);case"expression":return Nt(n);default:let t=n;throw new Error(`Unknown semantic value type: ${t.type}`)}}function Et(n){let e={type:"literal",value:n.value};return n.dataType?{...e,dataType:n.dataType}:e}function Tt(n,e){return e&&n.value.startsWith("*")&&/^[a-zA-Z-]/.test(n.value.slice(1))&&e.push(`Converted '${n.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:n.value,selector:n.value,selectorType:n.selectorKind}}function bt(n){return{type:"contextReference",contextType:n.value,name:n.value}}function kt(n,e){return{type:"propertyAccess",object:k(n.object,e),property:n.property}}function Nt(n){let e=Pe(n.raw);return!e.success||!e.node?{type:"identifier",name:n.raw}:e.node}function Xe(n,e){return n.roles.get(e)}function u(n,e,t){let r=Xe(n,e);return r?k(r,t):void 0}function f(n,e=[],t,r={}){let i={type:"command",name:n,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),r.isBlocking&&(i.isBlocking=r.isBlocking),r.implicitTarget&&(i.implicitTarget=r.implicitTarget),i}var Ct={action:"toggle",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=u(n,"duration"),o=t?[t]:[],a={};return r&&(a.on=r),i&&(a.for=i),f("toggle",o,a)}},wt={action:"add",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("add",i,o)}},Pt={action:"remove",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("remove",i,o)}},Rt={action:"set",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o={};return t&&i.push(t),r&&(o.to=r),f("set",i,o)}},Lt={action:"show",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"duration"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.with=i),f("show",o,a)}},Mt={action:"hide",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"duration"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.with=i),f("hide",o,a)}},At={action:"increment",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"quantity"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.by=i),f("increment",o,a)}},zt={action:"decrement",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=u(n,"quantity"),o=[],a={},s=t??r;return s&&o.push(s),i&&(a.by=i),f("decrement",o,a)}},Vt={action:"wait",toAST(n,e){let t=u(n,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Ot={action:"log",toAST(n,e){let t=u(n,"patient"),r=[];return t&&r.push(t),f("log",r)}},It={action:"put",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=Xe(n,"method"),o=t?[t]:[],a={};if(r){let s=i?.type==="literal"?String(i.value):"into";a[s]=r}return f("put",o,a)}},_t={action:"fetch",toAST(n,e){let t=u(n,"source"),r=u(n,"method"),i=u(n,"responseType"),o=u(n,"patient"),a=t?[t]:[],s={};return r&&(s.with=r),i&&(s.as=i),o&&(s.body=o),f("fetch",a,s,{isBlocking:!0})}},Bt={action:"append",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("append",i,o)}},Kt={action:"prepend",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.to=r),f("prepend",i,o)}},$t={action:"trigger",toAST(n,e){let t=u(n,"event"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.on=r),f("trigger",i,o)}},Wt={action:"send",toAST(n,e){let t=u(n,"event"),r=u(n,"destination"),i=u(n,"patient"),o=t?[t]:[],a={};return r&&(a.to=r),i&&(a.detail=i),f("send",o,a)}},jt={action:"go",toAST(n,e){let t=u(n,"source"),r=u(n,"destination"),i=[],o={};return t&&i.push(t),r&&(o.to=r),f("go",i,o)}},Ut={action:"transition",toAST(n,e){let t=u(n,"patient"),r=u(n,"goal"),i=u(n,"duration"),o=u(n,"destination"),a=t?[t]:[],s={};return r&&(s.to=r),i&&(s.over=i),o&&(s.on=o),f("transition",a,s)}},Dt={action:"focus",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o={},a=t??r;return a&&i.push(a),f("focus",i,o)}},Ft={action:"blur",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("blur",i)}},qt={action:"get",toAST(n,e){let t=u(n,"source"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("get",i)}},Ht={action:"take",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("take",i,o)}},Gt={action:"call",toAST(n,e){let t=u(n,"patient");return f("call",t?[t]:[])}},Xt={action:"return",toAST(n,e){let t=u(n,"patient");return f("return",t?[t]:[])}},Zt={action:"halt",toAST(n,e){return f("halt",[])}},Qt={action:"throw",toAST(n,e){let t=u(n,"patient");return f("throw",t?[t]:[])}},Yt={action:"settle",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},Jt={action:"swap",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=u(n,"destination"),o=u(n,"style"),a=[],s={};return t&&a.push(t),r&&a.push(r),i&&(s.on=i),o&&(s.with=o),f("swap",a,s)}},er={action:"morph",toAST(n,e){let t=u(n,"source"),r=u(n,"destination"),i=u(n,"patient"),o=[],a={},s=t??i;return s&&o.push(s),r&&(a.on=r),f("morph",o,a)}},tr={action:"clone",toAST(n,e){let t=u(n,"source"),r=u(n,"destination"),i=u(n,"patient"),o=[],a={},s=t??i;return s&&o.push(s),r&&(a.into=r),f("clone",o,a)}},rr={action:"make",toAST(n,e){let t=u(n,"patient");return f("make",t?[t]:[])}},nr={action:"measure",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=u(n,"source"),o=[],a={};t&&o.push(t);let s=r??i;return s&&(a.of=s),f("measure",o,a)}},ir={action:"tell",toAST(n,e){let t=u(n,"destination"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("tell",i)}},or={action:"js",toAST(n,e){let t=u(n,"patient");return f("js",t?[t]:[])}},ar={action:"async",toAST(n,e){return f("async",[])}},sr={action:"if",toAST(n,e){let t=u(n,"condition");return f("if",t?[t]:[])}},lr={action:"unless",toAST(n,e){let t=u(n,"condition");return f("unless",t?[t]:[])}},cr={action:"repeat",toAST(n,e){let t=u(n,"quantity"),r=u(n,"patient"),i=[],o=t??r;return o&&i.push(o),f("repeat",i)}},ur={action:"for",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.in=r),f("for",i,o)}},dr={action:"while",toAST(n,e){let t=u(n,"condition");return f("while",t?[t]:[])}},pr={action:"continue",toAST(n,e){return f("continue",[])}},mr={action:"default",toAST(n,e){let t=u(n,"patient"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.to=r),f("default",i,o)}},fr={action:"init",toAST(n,e){return f("init",[])}},gr={action:"behavior",toAST(n,e){let t=u(n,"patient");return f("behavior",t?[t]:[])}},hr={action:"install",toAST(n,e){let t=u(n,"patient"),r=u(n,"destination"),i=t?[t]:[],o={};return r&&(o.on=r),f("install",i,o)}},yr={action:"on",toAST(n,e){let t=u(n,"event"),r=u(n,"source"),i=t?[t]:[],o={};return r&&(o.from=r),f("on",i,o)}},Ze=new Map([["toggle",Ct],["add",wt],["remove",Pt],["set",Rt],["show",Lt],["hide",Mt],["increment",At],["decrement",zt],["wait",Vt],["log",Ot],["put",It],["fetch",_t],["append",Bt],["prepend",Kt],["get",qt],["take",Ht],["trigger",$t],["send",Wt],["on",yr],["go",jt],["transition",Ut],["focus",Dt],["blur",Ft],["call",Gt],["return",Xt],["halt",Zt],["throw",Qt],["settle",Yt],["swap",Jt],["morph",er],["clone",tr],["measure",nr],["make",rr],["tell",ir],["default",mr],["js",or],["async",ar],["if",sr],["unless",lr],["repeat",cr],["for",ur],["while",dr],["continue",pr],["init",fr],["behavior",gr],["install",hr]]);function Q(n){return Ze.get(n)}function Re(n){Ze.set(n.action,n)}var Y=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=Q(e.action);if(t){let r=t.toAST(e,this);if("ast"in r&&"warnings"in r){let i=r;return this.warnings.push(...i.warnings),i.ast}else return r}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],r={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let s of i){let 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);r[l]=k(c)}}let a={type:"command",name:e.action,args:t};return Object.keys(r).length>0?{...a,modifiers:r}:a}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),r,i;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(i=g.split(/\s+or\s+|\|/).map(T=>T.trim()),r=i[0]):r=g}else t?.type==="reference"?r=t.value:r="click";let o=e.body.map(g=>this.build(g)),a=e.roles.get("source"),s,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"),d=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 m=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:r,commands:o,...i&&i.length>1?{events:i}:{},...p?{selector:p}:{},...c?{target:c}:{},...d?{condition:d}:{},...y?{watchTarget:y}:{},...m&&m.length>0?{args:m,params:m}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let r=k(t),i=e.thenBranch.map(s=>this.build(s)),o=e.elseBranch?.map(s=>this.build(s)),a=[r,{type:"block",commands:i}];return o&&o.length>0&&a.push({type:"block",commands:o}),{type:"command",name:"if",args:a}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),r=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&r.push(k(i));break}case"for":{e.loopVariable&&r.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&r.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&r.push(k(i));break}case"forever":break}return r.push({type:"block",commands:t}),{type:"command",name:"repeat",args:r}}buildBlock(e){return{type:"block",commands:e.map(r=>this.build(r))}}};function Qe(n){let e=new Y;return{ast:e.build(n),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 r=this.makeKey(e,t),i=this.cache.get(r);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(r),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(r),i.lastAccessed=Date.now(),this.cache.set(r,i),this.stats.hits++,i.result}set(e,t,r){if(!this.config.enabled||r.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:r,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let r=this.makeKey(e,t),i=this.cache.get(r);return i?this.isExpired(i)?(this.cache.delete(r),this.stats.expirations++,!1):!0:!1}delete(e,t){let r=this.makeKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Le=new W;var J=class{constructor(e={}){this.patternMatcher=new G,this.languages=new Set(te()),e.cache===!1?this.cache=new W({enabled:!1}):this.cache=e.cache?new W(e.cache):Le}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let r=this.cache.get(e,t);if(r)return r;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let r=Fe(t);if(!r)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=r.tokenize(e),o=N(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let a=this.patternMatcher.matchBest(i,o);if(!a)return{confidence:0,errors:["No pattern matched the input"]};let s=this.buildSemanticNode(a);return{confidence:a.confidence,command:{name:a.pattern.command,roles:a.captured},node:s,tokensConsumed:a.consumedTokens}}catch(r){return{confidence:0,errors:[r instanceof Error?r.message:String(r)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function Ye(n){return new J(n)}var Me=.5,Je=.8;function et(n,e=Me){return n.confidence>=e&&n.command!==void 0}var xr="1.0.0-zh",Sr=["zh"];function vr(){return[...Sr]}function tt(n){if(n!=="zh")throw new Error(`Language not supported in this bundle: ${n}. Supported: zh`)}function Er(n,e){return tt(e),[...se(n,e).tokens]}function rt(n){return tt(n),N(n)}function Tr(n,e){return rt(n).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}return lt(br);})();
|