@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 LokaScriptSemanticAr=(()=>{var fe=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=(r,e)=>{for(var t in e)fe(r,t,{get:e[t],enumerable:!0})},st=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of it(e))!ot.call(r,i)&&i!==t&&fe(r,i,{get:()=>e[i],enumerable:!(n=rt(e,i))||n.enumerable});return r};var ct=r=>st(fe({},"__esModule",{value:!0}),r);var zn={};at(zn,{ASTBuilder:()=>Y,DEFAULT_CONFIDENCE_THRESHOLD:()=>Le,HIGH_CONFIDENCE_THRESHOLD:()=>Je,SemanticAnalyzerImpl:()=>J,VERSION:()=>wn,arabicProfile:()=>I,arabicTokenizer:()=>ce,buildAST:()=>Qe,canParse:()=>be,createCommandNode:()=>V,createEventHandler:()=>$,createLiteral:()=>E,createPropertyPath:()=>W,createReference:()=>P,createSelector:()=>A,createSemanticAnalyzer:()=>Ye,fromExplicit:()=>Ne,getCommandMapper:()=>Q,getPatternsForLanguage:()=>nt,getPatternsForLanguageAndCommand:()=>Ln,getProfile:()=>he,getSupportedLanguages:()=>Cn,getTokenizer:()=>ge,isExplicitSyntax:()=>U,isLanguageSupported:()=>Ve,parse:()=>F,parseAny:()=>we,parseExplicit:()=>B,registerCommandMapper:()=>Ce,render:()=>X,renderExplicit:()=>Z,shouldUseSemanticResult:()=>et,toExplicit:()=>ke,tokenize:()=>Rn,tryGetProfile:()=>L});var K=new Map,te=new Map,ee=new Map;var ze=null;function Me(r,e,t){K.set(r,e),te.set(r,t),ee.delete(r)}var lt=new Map;function ge(r){let e=K.get(r);if(!e){let t=Array.from(K.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function he(r){let e=te.get(r);if(!e){let t=Array.from(te.keys()).join(", ");throw new Error(`Language profile '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function Ae(r){return K.get(r)}function L(r){return te.get(r)}function ne(){return Array.from(K.keys())}function Ve(r){return K.has(r)}function Oe(r,e){return ge(e).tokenize(r)}function N(r){let e=ee.get(r);if(e)return e;let t=lt.get(r);if(t)return ee.set(r,t),t;if(!ze)throw new Error(`No patterns registered for language '${r}'. Either import the language module or set a pattern generator.`);let n=he(r),i=ze(n);return ee.set(r,i),i}function Ie(r,e){return N(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}var O=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function S(r,e){return{start:r,end:e}}function v(r,e,t,n){if(typeof n=="string")return{value:r,kind:e,position:t,normalized:n};if(n){let{normalized:i,stem:o,stemConfidence:s}=n,a={value:r,kind:e,position:t};return i!==void 0&&(a.normalized=i),o!==void 0&&(a.stem=o,s!==void 0&&(a.stemConfidence=s)),a}return{value:r,kind:e,position:t}}function z(r){return/\s/.test(r)}function ie(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function oe(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function w(r){return/\d/.test(r)}function _e(r){return/[a-zA-Z]/.test(r)}function b(r){return/[a-zA-Z0-9_-]/.test(r)}function ye(r){return e=>{let t=e.charCodeAt(0);return r.some(([n,i])=>t>=n&&t<=i)}}function Be(r,e){if(e>=r.length)return null;let t=r[e];if(!ie(t))return null;let n=e,i="";if(t==="#"||t==="."){for(i+=r[n++];n<r.length&&b(r[n]);)i+=r[n++];if(i.length<=1)return null;if(n<r.length&&r[n]==="."&&t==="#"){let s=n+1;for(;s<r.length&&b(r[s]);)s++;if(s<r.length&&r[s]==="(")return i}}else if(t==="["){let o=1,s=!1,a=null,c=!1;for(i+=r[n++];n<r.length&&o>0;){let l=r[n];i+=l,c?c=!1:l==="\\"?c=!0:s?l===a&&(s=!1,a=null):l==='"'||l==="'"||l==="`"?(s=!0,a=l):l==="["?o++:l==="]"&&o--,n++}if(o!==0)return null}else if(t==="@"){for(i+=r[n++];n<r.length&&b(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="*"){for(i+=r[n++];n<r.length&&b(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="<"){if(i+=r[n++],n>=r.length||!_e(r[n]))return null;for(;n<r.length&&b(r[n]);)i+=r[n++];for(;n<r.length;){let o=r[n];if(o==="."){if(i+=r[n++],n>=r.length||!b(r[n]))return null;for(;n<r.length&&b(r[n]);)i+=r[n++]}else if(o==="#"){if(i+=r[n++],n>=r.length||!b(r[n]))return null;for(;n<r.length&&b(r[n]);)i+=r[n++]}else if(o==="["){let s=1,a=!1,c=null,l=!1;for(i+=r[n++];n<r.length&&s>0;){let p=r[n];i+=p,l?l=!1:p==="\\"?l=!0:a?p===c&&(a=!1,c=null):p==='"'||p==="'"||p==="`"?(a=!0,c=p):p==="["?s++:p==="]"&&s--,n++}if(s!==0)return null}else break}for(;n<r.length&&z(r[n]);)i+=r[n++];if(n<r.length&&r[n]==="/")for(i+=r[n++];n<r.length&&z(r[n]);)i+=r[n++];if(n>=r.length||r[n]!==">")return null;i+=r[n++]}return i||null}function dt(r,e){if(e>=r.length||r[e]!=="'"||e+1>=r.length||r[e+1].toLowerCase()!=="s")return!1;if(e+2>=r.length)return!0;let n=r[e+2];return z(n)||n==="*"||!b(n)}function je(r,e){if(e>=r.length)return null;let t=r[e];if(!oe(t)||t==="'"&&dt(r,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,s=t,a=!1;for(;o<r.length;){let c=r[o];if(s+=c,a)a=!1;else if(c==="\\")a=!0;else if(c===i)return s;o++}return s}function ae(r,e){if(e>=r.length)return!1;let t=r[e],n=r[e+1]||"",i=r[e+2]||"";if(t==="/"&&n!=="/"&&/[a-zA-Z0-9._-]/.test(n)||t==="/"&&n==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(n==="/"||n==="."&&i==="/"))return!0;let o=r.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function Ke(r,e){if(!ae(r,e))return null;let t=e,n="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<r.length;){let o=r[t];if(o==="#"){if(n.length>0&&/[a-zA-Z0-9/.]$/.test(n))for(n+=o,t++;t<r.length&&/[a-zA-Z0-9_-]/.test(r[t]);)n+=r[t++];break}if(i.test(o))n+=o,t++;else break}return n.length<2?null:n}function We(r,e){if(e>=r.length)return null;let t=r[e];if(!w(t)&&t!=="-"&&t!=="+")return null;let n=e,i="";if((r[n]==="-"||r[n]==="+")&&(i+=r[n++]),n>=r.length||!w(r[n]))return null;for(;n<r.length&&w(r[n]);)i+=r[n++];if(n<r.length&&r[n]===".")for(i+=r[n++];n<r.length&&w(r[n]);)i+=r[n++];return n<r.length&&(r.slice(n,n+2)==="ms"?i+="ms":(r[n]==="s"||r[n]==="m"||r[n]==="h")&&(i+=r[n])),i}var re=class re{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let n=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(n.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let s of o.alternatives)n.set(s,{native:s,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))n.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&n.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let s of o.alternatives)n.set(s,{native:s,normalized:i})}for(let i of t)n.set(i.native,i);this.profileKeywords=Array.from(n.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let n of this.profileKeywords)if(e.slice(t).startsWith(n.native))return v(n.native,"keyword",S(t,t+n.native.length),n.normalized);return null}isKeywordStart(e,t){let n=e.slice(t);return this.profileKeywords.some(i=>n.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,n){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let s={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return v(e,"keyword",S(t,n),s)}trySelector(e,t){let n=Be(e,t);return n?v(n,"selector",S(t,t+n.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let n=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!n)return null;let i=n[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],s=n[1];return{...v(i,"event-modifier",S(t,t+i.length)),metadata:{modifierName:o,value:s?o==="queue"?s:parseInt(s,10):void 0}}}tryString(e,t){let n=je(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryNumber(e,t){let n=We(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,i=!1){let o=t;if(i)for(;o<e.length&&z(e[o]);)o++;let s=e.slice(o);for(let a of n){let c=s.slice(0,a.length);if(a.caseInsensitive?c.toLowerCase()===a.pattern.toLowerCase():c===a.pattern){if(a.notFollowedBy&&(s[a.length]||"")===a.notFollowedBy)continue;if(a.checkBoundary){let p=s[a.length]||"";if(b(p))continue}return{suffix:a.suffix,endPos:o+a.length}}}return null}parseBaseNumber(e,t,n=!0){let i=t,o="";if(n&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!w(e[i]))return null;for(;i<e.length&&w(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&w(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,n,i={}){let{allowSign:o=!0,skipWhitespace:s=!1}=i,a=this.parseBaseNumber(e,t,o);if(!a)return null;let{number:c,endPos:l}=a,p=[...n,...re.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,l,p,s);return x&&(c+=x.suffix,l=x.endPos),v(c,"literal",S(t,l))}tryUrl(e,t){let n=Ke(e,t);return n?v(n,"url",S(t,t+n.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!b(e[t+1]))return null;let n=t+1;for(;n<e.length&&b(e[n]);)n++;let i=e.slice(t,n);return v(i,"identifier",S(t,n))}tryOperator(e,t){let n=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(n))return v(n,"operator",S(t,t+2));let i=e[t];return["<",">","!","+","-","*","/","="].includes(i)?v(i,"operator",S(t,t+1)):["(",")","{","}",",",";",":"].includes(i)?v(i,"punctuation",S(t,t+1)):null}tryMultiCharParticle(e,t,n){for(let i of n)if(e.slice(t,t+i.length)===i)return v(i,"particle",S(t,t+i.length));return null}};re.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var q=re;function $e(r){return{stem:r,confidence:1}}function Ue(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}function ut(r){let e=r.charCodeAt(0);return e>=1536&&e<=1791||e>=1872&&e<=1919||e>=2208&&e<=2303||e>=64336&&e<=65023||e>=65136&&e<=65279}function pt(r){for(let e of r)if(ut(e))return!0;return!1}function mt(r){return r.replace(/[\u064B-\u0652\u0670]/g,"")}var ft=[{pattern:"\u0648\u0627\u0644",confidencePenalty:.15,prefixType:"conjunction"},{pattern:"\u0641\u0627\u0644",confidencePenalty:.15,prefixType:"conjunction"},{pattern:"\u0628\u0627\u0644",confidencePenalty:.15,prefixType:"preposition"},{pattern:"\u0643\u0627\u0644",confidencePenalty:.15,prefixType:"preposition"},{pattern:"\u0644\u0644",confidencePenalty:.12,prefixType:"preposition"}],gt=[{pattern:"\u0627\u0644",confidencePenalty:.08,prefixType:"article",minRemaining:2},{pattern:"\u0648",confidencePenalty:.08,prefixType:"conjunction",minRemaining:3},{pattern:"\u0641",confidencePenalty:.08,prefixType:"conjunction",minRemaining:3},{pattern:"\u0628",confidencePenalty:.1,prefixType:"preposition",minRemaining:3},{pattern:"\u0644",confidencePenalty:.1,prefixType:"preposition",minRemaining:3},{pattern:"\u0643",confidencePenalty:.1,prefixType:"preposition",minRemaining:3}],ht=[{pattern:"\u064A",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u062A",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0646",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0623",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0627",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3}],yt=[{pattern:"\u0648\u0646",confidencePenalty:.1,type:"masculine-plural"},{pattern:"\u064A\u0646",confidencePenalty:.1,type:"masculine-plural-accusative"},{pattern:"\u0627\u062A",confidencePenalty:.1,type:"feminine-plural"},{pattern:"\u0627\u0646",confidencePenalty:.1,type:"dual-nominative"},{pattern:"\u064A\u0646",confidencePenalty:.1,type:"dual-accusative"},{pattern:"\u0647\u0627",confidencePenalty:.1,type:"pronoun-her"},{pattern:"\u0647\u0645",confidencePenalty:.1,type:"pronoun-them"},{pattern:"\u0647\u0646",confidencePenalty:.1,type:"pronoun-them-f"},{pattern:"\u0646\u0627",confidencePenalty:.1,type:"pronoun-us"},{pattern:"\u0643\u0645",confidencePenalty:.1,type:"pronoun-you-pl"},{pattern:"\u0643",confidencePenalty:.08,type:"pronoun-you"},{pattern:"\u0647",confidencePenalty:.08,type:"pronoun-him"},{pattern:"\u064A",confidencePenalty:.08,type:"pronoun-me"},{pattern:"\u0629",confidencePenalty:.08,type:"feminine"}],H=class{constructor(){this.language="ar"}isNormalizable(e){return!(!pt(e)||e.length<2)}normalize(e){let t=mt(e),n=1,i=[],o=[];for(let a of ft)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length);if(c.length>=2){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}if(i.length===0){for(let a of gt)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length),l=a.minRemaining??2;if(c.length>=l){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}}if(!(t.endsWith("\u0627\u062A")||t.endsWith("\u0629")||t.endsWith("\u0648\u0646")||t.endsWith("\u064A\u0646")||t.endsWith("\u0647\u0627")||t.endsWith("\u0647\u0645")||t.endsWith("\u0647\u0646")||t.endsWith("\u0646\u0627")||t.endsWith("\u0643\u0645"))&&(i.length===0||i[0]==="\u0648"||i[0]==="\u0641")){for(let a of ht)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length),l=a.minRemaining??3;if(c.length>=l){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}}for(let a of yt)if(t.endsWith(a.pattern)){let c=t.slice(0,-a.pattern.length);c.length>=2&&(t=c,n-=a.confidencePenalty,o.push(a.pattern))}return n=Math.max(.5,n),i.length===0&&o.length===0?$e(e):Ue(t,n,{removedPrefixes:i,removedSuffixes:o})}},_n=new H;var I={code:"ar",name:"Arabic",nativeName:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",direction:"rtl",wordOrder:"VSO",markingStrategy:"preposition",usesSpaces:!0,verb:{position:"start",subjectDrop:!0},references:{me:"\u0623\u0646\u0627",it:"\u0647\u0648",you:"\u0623\u0646\u062A",result:"\u0627\u0644\u0646\u062A\u064A\u062C\u0629",event:"\u0627\u0644\u062D\u062F\u062B",target:"\u0627\u0644\u0647\u062F\u0641",body:"\u0627\u0644\u062C\u0633\u0645"},possessive:{marker:"",markerPosition:"after-object",usePossessiveAdjectives:!0,specialForms:{me:"\u0644\u064A",it:"\u0644\u0647",you:"\u0644\u0643"},keywords:{\u0644\u064A:"me",\u0644\u0643:"you",\u0644\u0647:"it",\u0644\u0647\u0627:"it"}},roleMarkers:{destination:{primary:"\u0639\u0644\u0649",alternatives:["\u0641\u064A","\u0625\u0644\u0649","\u0628"],position:"before"},source:{primary:"\u0645\u0646",position:"before"},patient:{primary:"",position:"before"},style:{primary:"\u0628\u0640",alternatives:["\u0628\u0627\u0633\u062A\u062E\u062F\u0627\u0645"],position:"before"}},keywords:{toggle:{primary:"\u0628\u062F\u0651\u0644",alternatives:["\u0628\u062F\u0644","\u063A\u064A\u0651\u0631","\u063A\u064A\u0631"],normalized:"toggle"},add:{primary:"\u0623\u0636\u0641",alternatives:["\u0627\u0636\u0641","\u0632\u0650\u062F"],normalized:"add"},remove:{primary:"\u0627\u062D\u0630\u0641",alternatives:["\u0623\u0632\u0644","\u0627\u0645\u0633\u062D"],normalized:"remove"},put:{primary:"\u0636\u0639",alternatives:["\u0627\u062C\u0639\u0644"],normalized:"put"},append:{primary:"\u0623\u0644\u062D\u0642",normalized:"append"},prepend:{primary:"\u0633\u0628\u0642",normalized:"prepend"},take:{primary:"\u062E\u0630",alternatives:["\u0627\u062D\u0635\u0644"],normalized:"take"},make:{primary:"\u0627\u0635\u0646\u0639",alternatives:["\u0623\u0646\u0634\u0626"],normalized:"make"},clone:{primary:"\u0627\u0633\u062A\u0646\u0633\u062E",alternatives:["\u0627\u0646\u0633\u062E"],normalized:"clone"},swap:{primary:"\u0627\u0633\u062A\u0628\u062F\u0644",alternatives:["\u062A\u0628\u0627\u062F\u0644"],normalized:"swap"},morph:{primary:"\u062D\u0648\u0651\u0644",alternatives:["\u063A\u064A\u0651\u0631"],normalized:"morph"},set:{primary:"\u0627\u0636\u0628\u0637",alternatives:["\u0639\u064A\u0651\u0646","\u062D\u062F\u062F"],normalized:"set"},get:{primary:"\u0627\u062D\u0635\u0644",alternatives:["\u062E\u0630"],normalized:"get"},increment:{primary:"\u0632\u0650\u062F",alternatives:["\u0632\u062F","\u0627\u0631\u0641\u0639"],normalized:"increment"},decrement:{primary:"\u0623\u0646\u0642\u0635",alternatives:["\u0627\u0646\u0642\u0635","\u0642\u0644\u0644"],normalized:"decrement"},log:{primary:"\u0633\u062C\u0644",normalized:"log"},show:{primary:"\u0627\u0638\u0647\u0631",alternatives:["\u0623\u0638\u0647\u0631","\u0627\u0639\u0631\u0636"],normalized:"show"},hide:{primary:"\u0627\u062E\u0641",alternatives:["\u0623\u062E\u0641\u0650","\u0627\u062E\u0641\u064A"],normalized:"hide"},transition:{primary:"\u0627\u0646\u062A\u0642\u0627\u0644",alternatives:["\u0627\u0646\u062A\u0642\u0644"],normalized:"transition"},on:{primary:"\u0639\u0644\u0649",alternatives:["\u0639\u0646\u062F","\u0644\u062F\u0649","\u062D\u064A\u0646"],normalized:"on"},trigger:{primary:"\u062A\u0634\u063A\u064A\u0644",alternatives:["\u0623\u0637\u0644\u0642","\u0641\u0639\u0651\u0644"],normalized:"trigger"},send:{primary:"\u0623\u0631\u0633\u0644",normalized:"send"},focus:{primary:"\u062A\u0631\u0643\u064A\u0632",alternatives:["\u0631\u0643\u0632"],normalized:"focus"},blur:{primary:"\u0636\u0628\u0627\u0628\u064A\u0629",alternatives:["\u0634\u0648\u0634"],normalized:"blur"},go:{primary:"\u0627\u0630\u0647\u0628",alternatives:["\u0627\u0646\u062A\u0642\u0644"],normalized:"go"},wait:{primary:"\u0627\u0646\u062A\u0638\u0631",normalized:"wait"},fetch:{primary:"\u0627\u062D\u0636\u0631",alternatives:["\u062C\u0644\u0628"],normalized:"fetch"},settle:{primary:"\u0627\u0633\u062A\u0642\u0631",normalized:"settle"},if:{primary:"\u0625\u0630\u0627",normalized:"if"},when:{primary:"\u0639\u0646\u062F\u0645\u0627",normalized:"when"},where:{primary:"\u0623\u064A\u0646",normalized:"where"},else:{primary:"\u0648\u0625\u0644\u0627",alternatives:["\u062E\u0644\u0627\u0641 \u0630\u0644\u0643"],normalized:"else"},repeat:{primary:"\u0643\u0631\u0631",normalized:"repeat"},for:{primary:"\u0644\u0643\u0644",normalized:"for"},while:{primary:"\u0628\u064A\u0646\u0645\u0627",normalized:"while"},continue:{primary:"\u0648\u0627\u0635\u0644",normalized:"continue"},halt:{primary:"\u0623\u0648\u0642\u0641",alternatives:["\u062A\u0648\u0642\u0641"],normalized:"halt"},throw:{primary:"\u0627\u0631\u0645",alternatives:["\u0627\u0631\u0645\u0650"],normalized:"throw"},call:{primary:"\u0627\u0633\u062A\u062F\u0639",alternatives:["\u0646\u0627\u062F\u0650"],normalized:"call"},return:{primary:"\u0627\u0631\u062C\u0639",alternatives:["\u0639\u064F\u062F"],normalized:"return"},then:{primary:"\u062B\u0645",alternatives:["\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"],normalized:"then"},and:{primary:"\u0648\u0623\u064A\u0636\u0627\u064B",alternatives:["\u0623\u064A\u0636\u0627\u064B"],normalized:"and"},end:{primary:"\u0646\u0647\u0627\u064A\u0629",alternatives:["\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"],normalized:"end"},js:{primary:"\u062C\u0627\u0641\u0627\u0633\u0643\u0631\u0628\u062A",alternatives:["js"],normalized:"js"},async:{primary:"\u0645\u062A\u0632\u0627\u0645\u0646",normalized:"async"},tell:{primary:"\u0623\u062E\u0628\u0631",normalized:"tell"},default:{primary:"\u0627\u0641\u062A\u0631\u0627\u0636\u064A",normalized:"default"},init:{primary:"\u062A\u0647\u064A\u0626\u0629",alternatives:["\u0628\u062F\u0621"],normalized:"init"},behavior:{primary:"\u0633\u0644\u0648\u0643",normalized:"behavior"},install:{primary:"\u062A\u062B\u0628\u064A\u062A",alternatives:["\u062B\u0628\u0651\u062A"],normalized:"install"},measure:{primary:"\u0642\u064A\u0627\u0633",alternatives:["\u0642\u0650\u0633"],normalized:"measure"},into:{primary:"\u0641\u064A",alternatives:["\u0625\u0644\u0649"],normalized:"into"},before:{primary:"\u0642\u0628\u0644",normalized:"before"},after:{primary:"\u0628\u0639\u062F",normalized:"after"},until:{primary:"\u062D\u062A\u0649",normalized:"until"},event:{primary:"\u062D\u062F\u062B",normalized:"event"},from:{primary:"\u0645\u0646",normalized:"from"}},tokenization:{prefixes:["\u0627\u0644","\u0648","\u0641","\u0628","\u0643","\u0644"]}};var M=ye([[1536,1791],[1872,1919],[2208,2303],[64336,65023],[65136,65279]]),xt=new Set(["\u0628\u0640","\u0644\u0640","\u0643\u0640","\u0648\u0640"]),xe=new Map([["\u0648",{normalized:"and",type:"conjunction"}],["\u0641",{normalized:"then",type:"conjunction"}],["\u0628",{normalized:"with",type:"preposition"}],["\u0644",{normalized:"to",type:"preposition"}],["\u0643",{normalized:"like",type:"preposition"}],["\u0648\u0644",{normalized:"and-to",type:"conjunction"}],["\u0648\u0628",{normalized:"and-with",type:"conjunction"}],["\u0648\u0643",{normalized:"and-like",type:"conjunction"}],["\u0641\u0644",{normalized:"then-to",type:"conjunction"}],["\u0641\u0628",{normalized:"then-with",type:"conjunction"}],["\u0641\u0643",{normalized:"then-like",type:"conjunction"}]]),Fe=new Map([["\u0639\u0646\u062F\u0645\u0627",{normalized:"on",formality:"formal",confidence:.95,description:"when (formal MSA)"}],["\u062D\u064A\u0646\u0645\u0627",{normalized:"on",formality:"formal",confidence:.93,description:"when/whenever (formal)"}],["\u0639\u0646\u062F",{normalized:"on",formality:"neutral",confidence:.88,description:"at/when (neutral)"}],["\u062D\u064A\u0646",{normalized:"on",formality:"neutral",confidence:.85,description:"when/time (neutral)"}],["\u0644\u0645\u0651\u0627",{normalized:"on",formality:"dialectal",confidence:.7,description:"when (dialectal, with shadda)"}],["\u0644\u0645\u0627",{normalized:"on",formality:"dialectal",confidence:.68,description:"when (dialectal, no diacritic)"}],["\u0644\u062F\u0649",{normalized:"on",formality:"neutral",confidence:.82,description:"at/with (temporal)"}]]),se=new Set(["\u0641\u064A","\u0639\u0644\u0649","\u0645\u0646","\u0625\u0644\u0649","\u0627\u0644\u0649","\u0645\u0639","\u0639\u0646","\u0642\u0628\u0644","\u0628\u0639\u062F","\u0628\u064A\u0646"]),St=[{native:"\u0635\u062D\u064A\u062D",normalized:"true"},{native:"\u062E\u0637\u0623",normalized:"false"},{native:"null",normalized:"null"},{native:"\u0641\u0627\u0631\u063A",normalized:"null"},{native:"\u063A\u064A\u0631 \u0645\u0639\u0631\u0641",normalized:"undefined"},{native:"\u0627\u0644\u0623\u0648\u0644",normalized:"first"},{native:"\u0623\u0648\u0644",normalized:"first"},{native:"\u0627\u0644\u0623\u062E\u064A\u0631",normalized:"last"},{native:"\u0622\u062E\u0631",normalized:"last"},{native:"\u0627\u0644\u062A\u0627\u0644\u064A",normalized:"next"},{native:"\u0627\u0644\u0633\u0627\u0628\u0642",normalized:"previous"},{native:"\u0627\u0644\u0623\u0642\u0631\u0628",normalized:"closest"},{native:"\u0627\u0644\u0623\u0628",normalized:"parent"},{native:"\u0627\u0644\u0646\u0642\u0631",normalized:"click"},{native:"\u0646\u0642\u0631",normalized:"click"},{native:"\u0627\u0644\u0625\u062F\u062E\u0627\u0644",normalized:"input"},{native:"\u0625\u062F\u062E\u0627\u0644",normalized:"input"},{native:"\u0627\u0644\u062A\u063A\u064A\u064A\u0631",normalized:"change"},{native:"\u062A\u063A\u064A\u064A\u0631",normalized:"change"},{native:"\u0627\u0644\u0625\u0631\u0633\u0627\u0644",normalized:"submit"},{native:"\u0625\u0631\u0633\u0627\u0644",normalized:"submit"},{native:"\u0627\u0644\u062A\u0631\u0643\u064A\u0632",normalized:"focus"},{native:"\u0641\u0642\u062F\u0627\u0646 \u0627\u0644\u062A\u0631\u0643\u064A\u0632",normalized:"blur"},{native:"\u0636\u063A\u0637",normalized:"keydown"},{native:"\u0631\u0641\u0639",normalized:"keyup"},{native:"\u062A\u0645\u0631\u064A\u0631 \u0627\u0644\u0641\u0623\u0631\u0629",normalized:"mouseover"},{native:"\u0645\u063A\u0627\u062F\u0631\u0629 \u0627\u0644\u0641\u0623\u0631\u0629",normalized:"mouseout"},{native:"\u062A\u062D\u0645\u064A\u0644",normalized:"load"},{native:"\u062A\u0645\u0631\u064A\u0631",normalized:"scroll"},{native:"\u0623\u0646\u0627",normalized:"me"},{native:"\u0647\u0648",normalized:"it"},{native:"\u0647\u064A",normalized:"it"},{native:"\u0627\u0644\u0646\u062A\u064A\u062C\u0629",normalized:"result"},{native:"\u0627\u0644\u062D\u062F\u062B",normalized:"event"},{native:"\u0627\u0644\u0647\u062F\u0641",normalized:"target"},{native:"\u062B\u0627\u0646\u064A\u0629",normalized:"s"},{native:"\u062B\u0648\u0627\u0646\u064A",normalized:"s"},{native:"\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629",normalized:"ms"},{native:"\u062F\u0642\u064A\u0642\u0629",normalized:"m"},{native:"\u062F\u0642\u0627\u0626\u0642",normalized:"m"},{native:"\u0633\u0627\u0639\u0629",normalized:"h"},{native:"\u0633\u0627\u0639\u0627\u062A",normalized:"h"},{native:"\u0628\u062F\u0644",normalized:"toggle"},{native:"\u063A\u064A\u0631",normalized:"toggle"},{native:"\u0627\u0636\u0641",normalized:"add"},{native:"\u0627\u0632\u0644",normalized:"remove"},{native:"\u0627\u0636\u0639",normalized:"put"},{native:"\u064A\u0636\u0639",normalized:"put"},{native:"\u0627\u062C\u0639\u0644",normalized:"put"},{native:"\u0639\u064A\u0646",normalized:"set"},{native:"\u0632\u062F",normalized:"increment"},{native:"\u0627\u0631\u0641\u0639",normalized:"increment"},{native:"\u0627\u0646\u0642\u0635",normalized:"decrement"},{native:"\u0642\u0644\u0644",normalized:"decrement"},{native:"\u0633\u062C\u0644",normalized:"log"},{native:"\u0627\u0638\u0647\u0631",normalized:"show"},{native:"\u0627\u0639\u0631\u0636",normalized:"show"},{native:"\u0627\u062E\u0641",normalized:"hide"},{native:"\u0627\u062E\u0641\u064A",normalized:"hide"},{native:"\u0634\u063A\u0644",normalized:"trigger"},{native:"\u0627\u0631\u0633\u0644",normalized:"send"},{native:"\u0631\u0643\u0632",normalized:"focus"},{native:"\u0634\u0648\u0634",normalized:"blur"},{native:"\u0627\u0630\u0627",normalized:"if"},{native:"\u0644\u0648",normalized:"if"},{native:"\u0648\u0627\u0644\u0627",normalized:"else"},{native:"\u062A\u0648\u0642\u0641",normalized:"halt"},{native:"\u0627\u0646\u0633\u062E",normalized:"clone"},{native:"\u0625\u0630\u0646",normalized:"then"},{native:"\u0641\u0625\u0646",normalized:"then"},{native:"\u0646\u0647\u0627\u064A\u0629",normalized:"end"},{native:"\u0642\u0628\u0644",normalized:"before"},{native:"\u0628\u0639\u062F",normalized:"after"}],vt=[{pattern:"\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629",suffix:"ms",length:9,caseInsensitive:!1},{pattern:"\u0645\u0644\u064A_\u062B\u0627\u0646\u064A\u0629",suffix:"ms",length:8,caseInsensitive:!1},{pattern:"\u062F\u0642\u0627\u0626\u0642",suffix:"m",length:5,caseInsensitive:!1},{pattern:"\u062F\u0642\u064A\u0642\u0629",suffix:"m",length:5,caseInsensitive:!1},{pattern:"\u062B\u0648\u0627\u0646\u064A",suffix:"s",length:5,caseInsensitive:!1},{pattern:"\u062B\u0627\u0646\u064A\u0629",suffix:"s",length:5,caseInsensitive:!1},{pattern:"\u0633\u0627\u0639\u0627\u062A",suffix:"h",length:5,caseInsensitive:!1},{pattern:"\u0633\u0627\u0639\u0629",suffix:"h",length:4,caseInsensitive:!1}],Se=class extends q{constructor(){super();this.language="ar";this.direction="rtl";this.initializeKeywordsFromProfile(I,St),this.normalizer=new H}tokenize(t){let n=[],i=0;for(;i<t.length;){if(z(t[i])){i++;continue}if(ie(t[i])){let a=this.tryEventModifier(t,i);if(a){n.push(a),i=a.position.end;continue}let c=this.trySelector(t,i);if(c){n.push(c),i=c.position.end;continue}}if(oe(t[i])){let a=this.tryString(t,i);if(a){n.push(a),i=a.position.end;continue}}if(ae(t,i)){let a=this.tryUrl(t,i);if(a){n.push(a),i=a.position.end;continue}}if(w(t[i])){let a=this.extractArabicNumber(t,i);if(a){n.push(a),i=a.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){n.push(o),i=o.position.end;continue}let s=this.tryPreposition(t,i);if(s){n.push(s),i=s.position.end;continue}if(M(t[i])){let a=this.tryProclitic(t,i);if(a){n.push(a.conjunction),i=a.conjunction.position.end;continue}let c=this.extractArabicWord(t,i);if(c){n.push(c),i=c.position.end;continue}}if(b(t[i])){let a=this.extractAsciiWord(t,i);if(a){n.push(a),i=a.position.end;continue}}i++}return new O(n,"ar")}classifyToken(t){return se.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||/^\d/.test(t)?"literal":"identifier"}tryPreposition(t,n){let i=Array.from(se).sort((o,s)=>s.length-o.length);for(let o of i)if(t.slice(n,n+o.length)===o){let s=n+o.length;if(s>=t.length||z(t[s])||!M(t[s]))return{...v(o,"particle",S(n,s)),metadata:{prepositionValue:o}}}return null}tryProclitic(t,n){let i=n;for(;i<t.length&&(M(t[i])||t[i]==="\u0640");)i++;let o=t.slice(n,i);if(this.lookupKeyword(o)||Fe.has(o)||se.has(o))return null;if(n+2<=t.length){let y=t.slice(n,n+2),g=xe.get(y);if(g){let u=n+2;if(u<t.length&&M(t[u])){let m=0,h=u;for(;h<t.length&&M(t[h]);)m++,h++;if(m>=2)if(xe.get(t[n])){let R=t.slice(n+1,i);if(!this.lookupKeyword(R)){let D=g.type==="conjunction"?"conjunction":"particle";return{conjunction:v(y,D,S(n,u),g.normalized)}}}else{let R=g.type==="conjunction"?"conjunction":"particle";return{conjunction:v(y,R,S(n,u),g.normalized)}}}}}let s=t[n],a=xe.get(s);if(!a)return null;let c=n+1;if(c>=t.length||!M(t[c]))return null;let l=0,p=c;for(;p<t.length&&M(t[p]);)l++,p++;if(l<2)return null;let x=a.type==="conjunction"?"conjunction":"particle";return{conjunction:v(s,x,S(n,c),a.normalized)}}extractArabicWord(t,n){let i=n,o="";for(let l of xt){let p=l.replace("\u0640","");t.slice(i,i+p.length)}for(;i<t.length&&(M(t[i])||t[i]==="\u0640");)o+=t[i++];if(!o)return null;let s=Fe.get(o);if(s)return{...v(o,"keyword",S(n,i),s.normalized),metadata:{temporalFormality:s.formality,temporalConfidence:s.confidence}};let a=this.lookupKeyword(o);if(a)return v(o,"keyword",S(n,i),a.normalized);if(se.has(o))return{...v(o,"particle",S(n,i)),metadata:{prepositionValue:o}};let c=this.tryMorphKeywordMatch(o,n,i);return c||v(o,"identifier",S(n,i))}extractAsciiWord(t,n){let i=n,o="";for(;i<t.length&&b(t[i]);)o+=t[i++];return o?v(o,"identifier",S(n,i)):null}extractArabicNumber(t,n){return this.tryNumberWithTimeUnits(t,n,vt,{allowSign:!1,skipWhitespace:!0})}},ce=new Se;Me("ar",ce,I);function De(r){return Ae(r)}function le(r,e){return Oe(r,e)}function de(){return ne()}function A(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function E(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function P(r){return{type:"reference",value:r}}function W(r,e){return{type:"property-path",object:r,property:e}}function V(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function $(r,e,t,n,i){let o=new Map;o.set("event",r);let s={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(s.eventModifiers=t),n!==void 0&&(s.metadata=n),i!==void 0&&i.length>0&&(s.parameterNames=i),s}function qe(r,e="then",t){let n={kind:"compound",action:"compound",roles:new Map,statements:r,chainType:e};return t!==void 0&&(n.metadata=t),n}function ve(r,e){return!e||e.length===0||e.includes(r)||e.includes("expression")?!0:r==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function He(r,e){return r.possessive?.keywords?.[e]}var C=class C{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let n=e.mark(),i=new Map;if(this.currentProfile=L(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(n),null;let s=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-n.position,confidence:s}}matchBest(e,t){let n=[];for(let o of t){let s=e.mark(),a=this.matchPattern(e,o);a&&n.push(a),e.reset(s)}if(n.length===0)return null;n.sort((o,s)=>{let a=s.pattern.priority-o.pattern.priority;return a!==0?a:s.confidence-o.confidence});let i=n[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,n){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let i of t)if(!this.matchPatternToken(e,i,n)){if(this.isOptional(i))continue;return!1}return!0}matchPatternToken(e,t,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,n);case"group":return this.matchGroupToken(e,t,n);default:return!1}}matchLiteralToken(e,t){let n=e.peek();if(!n)return!1;let i=this.getMatchType(n,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let s=this.getMatchType(n,o);if(s!=="none")return this.totalKeywordMatches++,s==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,o),!0);let s=this.tryMatchMethodCallExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(s.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,s),!0);let a=this.tryMatchPossessiveSelectorExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!ve(a.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,a),!0);let c=this.tryMatchPropertyAccessExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,c),!0);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!ve(l.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,l),!0);let p=this.tokenToSemanticValue(i);return!p||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(p.type)?t.optional||!1:(n.set(t.role,p),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let n=(t.normalized||t.value).toLowerCase(),i=He(this.currentProfile,n);if(!i)return null;let o=e.mark();e.advance();let s=e.peek();return s&&(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)||s.kind==="selector"&&s.value.startsWith("*"))?(e.advance(),W(P(i),s.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let s=e.peek();if(!s||s.kind!=="punctuation"||s.value!=="(")return e.reset(n),null;e.advance();let a=[];for(;!e.isAtEnd()&&a.length<C.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}a.push(l.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${a.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let s=`${t.value}.${o.value}`,a=1;for(;!e.isAtEnd()&&a<C.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),s+=`.${p.value}`,a++}let c=e.peek();if(c&&c.kind==="punctuation"&&c.value==="("){e.advance();let l=[],p=0;for(;!e.isAtEnd()&&l.length<C.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(p===0){e.advance();break}p--}if(y.kind==="punctuation"&&y.value==="("&&p++,y.kind==="punctuation"&&y.value===","){e.advance();continue}l.push(y.value),e.advance()}return{type:"expression",raw:`${s}(${l.join(", ")})`}}return{type:"expression",raw:s}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(n),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(n),null):(e.advance(),W(A(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(n),null;let o=e.peek(1);o&&o.kind,e.advance();let s=i.value.slice(1);return W(A(t.value),s)}matchGroupToken(e,t,n){let i=e.mark(),o=new Set(n.keys());if(!this.matchTokenSequence(e,t.tokens,n)){e.reset(i);for(let a of n.keys())o.has(a)||n.delete(a);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return A(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?P(t):E(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return P(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?P(n):{type:"expression",raw:e.value};case"url":return E(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let i=e.slice(1,-1);return E(i,"string")}if(e==="true")return E(!0,"boolean");if(e==="false")return E(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let i=parseFloat(t[1]);return t[2]?E(e,"duration"):E(i,"number")}let n=parseFloat(e);return isNaN(n)?E(e,"string"):E(n,"number")}applyExtractionRules(e,t){for(let[n,i]of Object.entries(e.extraction))!t.has(n)&&i.default&&t.set(n,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let n=0,i=0,o=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")i+=1,t.has(l.role)&&(n+=1);else if(l.type==="group"){for(let p of l.tokens)if(p.type==="role"){let x=o(p.role),y=.8;i+=y,t.has(p.role)?n+=y:x&&(n+=y*.6)}}let s=i>0?n/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let l=this.stemMatchCount/this.totalKeywordMatches*.15;s=Math.max(.5,s-l)}let a=this.calculateVSOConfidenceBoost(e);s=Math.min(1,s+a);let c=this.arabicPrepositionDisambiguation(e,t);return s=Math.max(0,Math.min(1,s+c)),s}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let n=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(n.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(n.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let n=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,s]of t.entries()){let a=i[o];if(!a||a.length===0)continue;let c=s.metadata;if(c&&typeof c.prepositionValue=="string"){let l=c.prepositionValue;a.includes(l)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){let t=e.peek();if(!t)return;let n=t.value.toLowerCase();if(C.ENGLISH_NOISE_WORDS.has(n)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return n?t:void 0}};C.MAX_PROPERTY_DEPTH=10,C.MAX_METHOD_ARGS=20,C.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var G=C,_=new G;var ue=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=Ie(t,e.action);if(n.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,n);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return n.join(` ${i} `)}getChainWord(e,t){let n=L(t);return n?.keywords?n.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let n=e;return n.statements.map(o=>this.renderExplicit(o)).join(` ${n.chainType} `)}let t=[e.action];for(let[n,i]of e.roles)t.push(`${n}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let n=e;if(n.body&&n.body.length>0){let i=n.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return de()}findBestPattern(e,t){let n=t.map(i=>{let o=i.priority;for(let s of i.template.tokens)s.type==="role"&&(e.roles.has(s.role)?o+=10:s.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return n.sort((i,o)=>o.score-i.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let n=[],i=t.language;for(let o of t.template.tokens){let s=this.renderPatternToken(o,e,i);s!==null&&n.push(s)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let s=o.body.map(a=>this.render(a,i));n.push(s.join(" "))}}return n.join(" ")}renderPatternToken(e,t,n){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,n):(e.optional,null)}case"group":{if(!e.tokens.filter(s=>s.type==="role"&&!s.optional).every(s=>t.roles.has(s.role))&&e.optional)return null;if(e.optional&&e.tokens.find(a=>a.type==="role"&&a.role==="destination")){let a=t.roles.get("destination");if(a?.type==="reference"&&a.value==="me")return null}let o=[];for(let s of e.tokens){let a=this.renderPatternToken(s,t,n);a!==null&&o.push(a)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let n=L(t);return n?.references?n.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let n=L(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(n?.possessive?.specialForms&&o){let a=n.possessive.specialForms[o];if(a){let{markerPosition:c,usePossessiveAdjectives:l}=n.possessive;return l&&c==="after-object"?`${i} ${a}`:`${a} ${i}`}}let s=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:a,markerPosition:c,usePossessiveAdjectives:l}=n.possessive;if(l&&o&&c==="after-object")return`${i} ${s}`;if(a)switch(c){case"between":return n.usesSpaces?`${s}${a} ${i}`:`${s}${a}${i}`;case"after-object":return`${s}${a} ${i}`;case"before-property":return`${s} ${a} ${i}`}}return t==="en"||!n?.possessive?s==="me"?`my ${i}`:s==="it"?`its ${i}`:`${s}'s ${i}`:`${s} ${i}`}},Ee=new ue;function X(r,e){return Ee.render(r,e)}function Z(r){return Ee.renderExplicit(r)}function B(r){let e=r.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let n=Et(t);if(n.length===0)throw new Error("No command specified in explicit statement");let i=n[0].toLowerCase(),o=new Map;for(let a=1;a<n.length;a++){let c=n[a],l=c.indexOf(":");if(l===-1)throw new Error(`Invalid role format: "${c}". Expected role:value`);let p=c.slice(0,l),x=c.slice(l+1);if(p==="body"&&x.startsWith("[")){let g=bt(c,l+1),u=c.slice(l+1,g+1);o.set(p,{type:"expression",raw:u});continue}let y=Tt(x);o.set(p,y)}if(i==="on"){let a=o.get("event");if(!a)throw new Error("Event handler requires event role: [on event:click ...]");let c=o.get("body"),l=[];return c&&c.type==="expression"&&l.push(B(c.raw)),o.delete("body"),$(a,l,void 0,{sourceLanguage:"explicit"})}let s={};for(let[a,c]of o)s[a]=c;return V(i,s,{sourceLanguage:"explicit"})}function Et(r){let e=[],t="",n=!1,i="",o=0;for(let s=0;s<r.length;s++){let a=r[s];if(n){t+=a,a===i&&r[s-1]!=="\\"&&(n=!1);continue}if(a==='"'||a==="'"){n=!0,i=a,t+=a;continue}if(a==="["){o++,t+=a;continue}if(a==="]"){o--,t+=a;continue}if(a===" "&&o===0){t&&(e.push(t),t="");continue}t+=a}return t&&e.push(t),e}function Tt(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return A(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return E(t,"string")}if(r==="true")return E(!0,"boolean");if(r==="false")return E(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(r.toLowerCase()))return P(r.toLowerCase());let e=r.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?E(r,"duration"):E(t,"number")}return E(r,"string")}function bt(r,e){let t=0;for(let n=e;n<r.length;n++)if(r[n]==="[")t++;else if(r[n]==="]"&&(t--,t===0))return n;return r.length-1}function U(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var pe=class{parse(e,t){let n=le(e,t),i=N(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((p,x)=>x.priority-p.priority),s=o.filter(p=>p.command==="on"),a=_.matchBest(n,s);if(a)return this.buildEventHandler(a,n,t);let c=o.filter(p=>p.command!=="on"),l=_.matchBest(n,c);if(l)return this.buildCommand(l,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return de()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let n={};for(let[i,o]of e.captured)n[i]=o;return V(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=_.extractEventModifiers(t),s,a=e.captured.get("action");if(a&&a.type==="literal"){let c=a.value,l={};for(let[y,g]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(l[y]=g);let p=V(c,l,{sourceLanguage:n,patternId:e.pattern.id}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=N(n).filter(m=>m.command!=="on").sort((m,h)=>h.priority-m.priority),g=N(n).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,h)=>h.priority-m.priority),u=this.parseBodyWithGrammarPatterns(t,y,g,n);u.length>0?s=[p,...u]:s=[p]}else s=[p]}else{let c=N(n).filter(l=>l.command!=="on").sort((l,p)=>p.priority-l.priority);s=this.parseBodyWithClauses(t,c,n)}return $(i,s,o,{sourceLanguage:n,patternId:e.pattern.id})}parseBodyWithClauses(e,t,n){let i=[],o=[];for(;!e.isAtEnd();){let s=e.peek();if(!s)break;let a=s.kind==="conjunction"||s.kind==="keyword"&&this.isThenKeyword(s.value,n),c=s.kind==="keyword"&&this.isEndKeyword(s.value,n);if(a){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l),o.length=0}e.advance();continue}if(c){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l)}e.advance();break}o.push(s),e.advance()}if(o.length>0){let s=this.parseClause(o,t,n);i.push(...s)}return i.length>1?[qe(i,"then",{sourceLanguage:n})]:i}parseClause(e,t,n){if(e.length===0)return[];let i=new O(e,n),o=[];for(;!i.isAtEnd();){let s=_.matchBest(i,t);s?o.push(this.buildCommand(s,n)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,n,i){let o=[];for(;!e.isAtEnd();){let s=e.peek();if(s&&this.isThenKeyword(s.value,i)){e.advance();continue}if(s&&this.isEndKeyword(s.value,i)){e.advance();break}let a=!1;if(n.length>0){let c=_.matchBest(e,n);if(c){let l=c.pattern.command,p={};for(let[g,u]of c.captured)g!=="event"&&g!=="action"&&g!=="continues"&&(p[g]=u);let x=V(l,p,{sourceLanguage:i,patternId:c.pattern.id});o.push(x),a=!0;let y=c.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!a){let c=_.matchBest(e,t);c&&(o.push(this.buildCommand(c,i)),a=!0)}a||e.advance()}return o}isThenKeyword(e,t){let n={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(n[t]||n.en).has(e.toLowerCase())}isEndKeyword(e,t){let n={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(n[t]||n.en).has(e.toLowerCase())}},Te=new pe;function F(r,e){return Te.parse(r,e)}function be(r,e){return Te.canParse(r,e)}function ke(r,e){if(U(r))return r;let t=F(r,e);return Z(t)}function Ne(r,e){let t=B(r);return X(t,e)}function we(r,e){return U(r)?B(r):F(r,e)}var kt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Nt=new Set(["and","or","not","no"]),wt=new Set(["true","false","null","undefined"]),Pt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ge(r){let e=[],t=0,n=1,i=1;function o(){if(e.length===0)return!0;let u=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(u.type)}function s(u=0){return r[t+u]??""}function a(){let u=r[t];return t++,u===`
|
|
2
|
-
`?(n++,i=1):i++,u}function c(){for(;t<r.length&&/\s/.test(r[t]);)a()}function l(u){let m="";for(;t<r.length&&u(r[t]);)m+=a();return m}function p(u){let m=u;for(a();t<r.length&&r[t]!==u;)r[t]==="\\"&&t+1<r.length&&(m+=a()),m+=a();return t<r.length&&(m+=a()),m}function x(){let u="`";for(a();t<r.length&&r[t]!=="`";)r[t]==="\\"&&t+1<r.length&&(u+=a()),u+=a();return t<r.length&&(u+=a()),u}function y(){let u="<";for(a();t<r.length&&(u+=a(),!u.endsWith("/>")););return u}function g(u,m,h){return{type:u,value:m,start:h,end:t,line:n,column:i-m.length}}for(;t<r.length&&(c(),!(t>=r.length));){let u=t,m=s();if(m==="'"&&s(1)==="s"&&!/\w/.test(s(2))){a(),a(),e.push(g("POSSESSIVE","'s",u));continue}if(m==='"'||m==="'"){let h=p(m);e.push(g("STRING",h,u));continue}if(m==="`"){let h=x();e.push(g("TEMPLATE_LITERAL",h,u));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(s(1))){let h=y();e.push(g("QUERY_SELECTOR",h,u));continue}if(m==="#"&&o()){a();let h=l(T=>/[\w-]/.test(T));e.push(g("ID_SELECTOR","#"+h,u));continue}if(m==="."&&/[a-zA-Z_-]/.test(s(1))&&o()){a();let h=l(T=>/[\w-]/.test(T));e.push(g("CLASS_SELECTOR","."+h,u));continue}if(m==="["&&o()){let h=s(1);if(h==="@"||/[a-zA-Z]/.test(h)){let T="";for(T+=a();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?T+=p(r[t]):T+=a();t<r.length&&(T+=a()),e.push(g("ATTRIBUTE_SELECTOR",T,u));continue}}if(m==="["){a(),e.push(g("LBRACKET","[",u));continue}if(m==="]"){a(),e.push(g("RBRACKET","]",u));continue}if(/\d/.test(m)){let h=l(D=>/[\d.]/.test(D)),T=t,R=l(D=>/[a-zA-Z]/.test(D));Pt.has(R)?e.push(g("TIME_EXPRESSION",h+R,u)):(t=T,e.push(g("NUMBER",h,u)));continue}if(m==="("){a(),e.push(g("LPAREN","(",u));continue}if(m===")"){a(),e.push(g("RPAREN",")",u));continue}if(m==="{"){a(),e.push(g("LBRACE","{",u));continue}if(m==="}"){a(),e.push(g("RBRACE","}",u));continue}if(m===","){a(),e.push(g("COMMA",",",u));continue}if(m===":"){a(),e.push(g("COLON",":",u));continue}if(m==="."){a(),e.push(g("DOT",".",u));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){a(),e.push(g("OPERATOR",m,u));continue}if(m==="="||m==="!"||m==="<"||m===">"){let h=a();s()==="="&&(h+=a()),e.push(g("COMPARISON",h,u));continue}if(/[a-zA-Z_$]/.test(m)){let h=l(R=>/[\w$]/.test(R)),T=h.toLowerCase();kt.has(T)?e.push(g("CONTEXT_VAR",h,u)):Nt.has(T)?e.push(g("LOGICAL",h,u)):wt.has(T)?e.push(g("BOOLEAN",h,u)):e.push(g("IDENTIFIER",h,u));continue}a()}return e.push(g("EOF","",t)),e}var me=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ge(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,n=this.parseAnd();e=this.createBinaryExpression(t,e,n)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,n=this.parseEquality();e=this.createBinaryExpression(t,e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,n=this.parseComparison();e=this.createBinaryExpression(t,e,n)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,n=this.parseAddition();e=this.createBinaryExpression(t,e,n)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,n=this.parseMultiplication();e=this.createBinaryExpression(t,e,n)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,n=this.parseUnary();e=this.createBinaryExpression(t,e,n)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let n;if(this.check("STRING"))n=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))n=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:n,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(n=>({type:"objectProperty",key:n.key,value:n.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let n=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:n,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,n){return{type:"literal",value:e,dataType:t,raw:n.value,start:n.start,end:n.end,line:n.line,column:n.column}}createSelector(e,t,n){return{type:"selector",value:e,selector:e,selectorType:t,start:n.start,end:n.end,line:n.line,column:n.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,n){return{type:"binaryExpression",operator:e,left:t,right:n,start:t.start,end:n.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Pe(r){return new me().parse(r)}function k(r,e){switch(r.type){case"literal":return Ct(r);case"selector":return Rt(r,e);case"reference":return Lt(r);case"property-path":return zt(r,e);case"expression":return Mt(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function Ct(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function Rt(r,e){return e&&r.value.startsWith("*")&&/^[a-zA-Z-]/.test(r.value.slice(1))&&e.push(`Converted '${r.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:r.value,selector:r.value,selectorType:r.selectorKind}}function Lt(r){return{type:"contextReference",contextType:r.value,name:r.value}}function zt(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function Mt(r){let e=Pe(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function Xe(r,e){return r.roles.get(e)}function d(r,e,t){let n=Xe(r,e);return n?k(n,t):void 0}function f(r,e=[],t,n={}){let i={type:"command",name:r,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),n.isBlocking&&(i.isBlocking=n.isBlocking),n.implicitTarget&&(i.implicitTarget=n.implicitTarget),i}var At={action:"toggle",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"duration"),o=t?[t]:[],s={};return n&&(s.on=n),i&&(s.for=i),f("toggle",o,s)}},Vt={action:"add",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("add",i,o)}},Ot={action:"remove",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("remove",i,o)}},It={action:"set",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("set",i,o)}},_t={action:"show",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.with=i),f("show",o,s)}},Bt={action:"hide",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"duration"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.with=i),f("hide",o,s)}},jt={action:"increment",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.by=i),f("increment",o,s)}},Kt={action:"decrement",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=d(r,"quantity"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.by=i),f("decrement",o,s)}},Wt={action:"wait",toAST(r,e){let t=d(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},$t={action:"log",toAST(r,e){let t=d(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},Ut={action:"put",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=Xe(r,"method"),o=t?[t]:[],s={};if(n){let a=i?.type==="literal"?String(i.value):"into";s[a]=n}return f("put",o,s)}},Ft={action:"fetch",toAST(r,e){let t=d(r,"source"),n=d(r,"method"),i=d(r,"responseType"),o=d(r,"patient"),s=t?[t]:[],a={};return n&&(a.with=n),i&&(a.as=i),o&&(a.body=o),f("fetch",s,a,{isBlocking:!0})}},Dt={action:"append",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("append",i,o)}},qt={action:"prepend",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("prepend",i,o)}},Ht={action:"trigger",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("trigger",i,o)}},Gt={action:"send",toAST(r,e){let t=d(r,"event"),n=d(r,"destination"),i=d(r,"patient"),o=t?[t]:[],s={};return n&&(s.to=n),i&&(s.detail=i),f("send",o,s)}},Xt={action:"go",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("go",i,o)}},Zt={action:"transition",toAST(r,e){let t=d(r,"patient"),n=d(r,"goal"),i=d(r,"duration"),o=d(r,"destination"),s=t?[t]:[],a={};return n&&(a.to=n),i&&(a.over=i),o&&(a.on=o),f("transition",s,a)}},Qt={action:"focus",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o={},s=t??n;return s&&i.push(s),f("focus",i,o)}},Yt={action:"blur",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("blur",i)}},Jt={action:"get",toAST(r,e){let t=d(r,"source"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("get",i)}},en={action:"take",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("take",i,o)}},tn={action:"call",toAST(r,e){let t=d(r,"patient");return f("call",t?[t]:[])}},nn={action:"return",toAST(r,e){let t=d(r,"patient");return f("return",t?[t]:[])}},rn={action:"halt",toAST(r,e){return f("halt",[])}},on={action:"throw",toAST(r,e){let t=d(r,"patient");return f("throw",t?[t]:[])}},an={action:"settle",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},sn={action:"swap",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=d(r,"destination"),o=d(r,"style"),s=[],a={};return t&&s.push(t),n&&s.push(n),i&&(a.on=i),o&&(a.with=o),f("swap",s,a)}},cn={action:"morph",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],s={},a=t??i;return a&&o.push(a),n&&(s.on=n),f("morph",o,s)}},ln={action:"clone",toAST(r,e){let t=d(r,"source"),n=d(r,"destination"),i=d(r,"patient"),o=[],s={},a=t??i;return a&&o.push(a),n&&(s.into=n),f("clone",o,s)}},dn={action:"make",toAST(r,e){let t=d(r,"patient");return f("make",t?[t]:[])}},un={action:"measure",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=d(r,"source"),o=[],s={};t&&o.push(t);let a=n??i;return a&&(s.of=a),f("measure",o,s)}},pn={action:"tell",toAST(r,e){let t=d(r,"destination"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("tell",i)}},mn={action:"js",toAST(r,e){let t=d(r,"patient");return f("js",t?[t]:[])}},fn={action:"async",toAST(r,e){return f("async",[])}},gn={action:"if",toAST(r,e){let t=d(r,"condition");return f("if",t?[t]:[])}},hn={action:"unless",toAST(r,e){let t=d(r,"condition");return f("unless",t?[t]:[])}},yn={action:"repeat",toAST(r,e){let t=d(r,"quantity"),n=d(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("repeat",i)}},xn={action:"for",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.in=n),f("for",i,o)}},Sn={action:"while",toAST(r,e){let t=d(r,"condition");return f("while",t?[t]:[])}},vn={action:"continue",toAST(r,e){return f("continue",[])}},En={action:"default",toAST(r,e){let t=d(r,"patient"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.to=n),f("default",i,o)}},Tn={action:"init",toAST(r,e){return f("init",[])}},bn={action:"behavior",toAST(r,e){let t=d(r,"patient");return f("behavior",t?[t]:[])}},kn={action:"install",toAST(r,e){let t=d(r,"patient"),n=d(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("install",i,o)}},Nn={action:"on",toAST(r,e){let t=d(r,"event"),n=d(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("on",i,o)}},Ze=new Map([["toggle",At],["add",Vt],["remove",Ot],["set",It],["show",_t],["hide",Bt],["increment",jt],["decrement",Kt],["wait",Wt],["log",$t],["put",Ut],["fetch",Ft],["append",Dt],["prepend",qt],["get",Jt],["take",en],["trigger",Ht],["send",Gt],["on",Nn],["go",Xt],["transition",Zt],["focus",Qt],["blur",Yt],["call",tn],["return",nn],["halt",rn],["throw",on],["settle",an],["swap",sn],["morph",cn],["clone",ln],["measure",un],["make",dn],["tell",pn],["default",En],["js",mn],["async",fn],["if",gn],["unless",hn],["repeat",yn],["for",xn],["while",Sn],["continue",vn],["init",Tn],["behavior",bn],["install",kn]]);function Q(r){return Ze.get(r)}function Ce(r){Ze.set(r.action,r)}var Y=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=Q(e.action);if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let i=n;return this.warnings.push(...i.warnings),i.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let a of i){let c=e.roles.get(a);c&&t.push(k(c))}for(let a of o){let c=e.roles.get(a);if(c){let l=this.roleToModifierKey(a);n[l]=k(c)}}let s={type:"command",name:e.action,args:t};return Object.keys(n).length>0?{...s,modifiers:n}:s}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),n,i;if(t?.type==="literal"){let h=String(t.value);h.includes("|")||h.includes(" or ")?(i=h.split(/\s+or\s+|\|/).map(T=>T.trim()),n=i[0]):n=h}else t?.type==="reference"?n=t.value:n="click";let o=e.body.map(h=>this.build(h)),s=e.roles.get("source"),a,c;s?.type==="selector"?(a=s.value,c=s.value):s?.type==="reference"?c=s.value:s?.type==="literal"&&(c=String(s.value));let l=e.roles.get("condition"),p=l?k(l):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,g=e.eventModifiers,u=a;if(g?.from){let h=g.from;h.type==="selector"&&!a&&(u=h.value)}let m=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:n,commands:o,...i&&i.length>1?{events:i}:{},...u?{selector:u}:{},...c?{target:c}:{},...p?{condition:p}:{},...y?{watchTarget:y}:{},...m&&m.length>0?{args:m,params:m}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let n=k(t),i=e.thenBranch.map(a=>this.build(a)),o=e.elseBranch?.map(a=>this.build(a)),s=[n,{type:"block",commands:i}];return o&&o.length>0&&s.push({type:"block",commands:o}),{type:"command",name:"if",args:s}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),n=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&n.push(k(i));break}case"for":{e.loopVariable&&n.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&n.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&n.push(k(i));break}case"forever":break}return n.push({type:"block",commands:t}),{type:"command",name:"repeat",args:n}}buildBlock(e){return{type:"block",commands:e.map(n=>this.build(n))}}};function Qe(r){let e=new Y;return{ast:e.build(r),warnings:e.warnings}}var j=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),i=this.cache.get(n);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),i.lastAccessed=Date.now(),this.cache.set(n,i),this.stats.hits++,i.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:n,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),i=this.cache.get(n);return i?this.isExpired(i)?(this.cache.delete(n),this.stats.expirations++,!1):!0:!1}delete(e,t){let n=this.makeKey(e,t);return this.cache.delete(n)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Re=new j;var J=class{constructor(e={}){this.patternMatcher=new G,this.languages=new Set(ne()),e.cache===!1?this.cache=new j({enabled:!1}):this.cache=e.cache?new j(e.cache):Re}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let n=this.cache.get(e,t);if(n)return n;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let n=De(t);if(!n)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=n.tokenize(e),o=N(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let s=this.patternMatcher.matchBest(i,o);if(!s)return{confidence:0,errors:["No pattern matched the input"]};let a=this.buildSemanticNode(s);return{confidence:s.confidence,command:{name:s.pattern.command,roles:s.captured},node:a,tokensConsumed:s.consumedTokens}}catch(n){return{confidence:0,errors:[n instanceof Error?n.message:String(n)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function Ye(r){return new J(r)}var Le=.5,Je=.8;function et(r,e=Le){return r.confidence>=e&&r.command!==void 0}var wn="1.0.0-ar",Pn=["ar"];function Cn(){return[...Pn]}function tt(r){if(r!=="ar")throw new Error(`Language not supported in this bundle: ${r}. Supported: ar`)}function Rn(r,e){return tt(e),[...le(r,e).tokens]}function nt(r){return tt(r),N(r)}function Ln(r,e){return nt(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return ct(zn);})();
|
|
1
|
+
"use strict";var LokaScriptSemanticAr=(()=>{var he=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var dt=(r,e)=>{for(var t in e)he(r,t,{get:e[t],enumerable:!0})},pt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of lt(e))!ut.call(r,i)&&i!==t&&he(r,i,{get:()=>e[i],enumerable:!(n=ct(e,i))||n.enumerable});return r};var mt=r=>pt(he({},"__esModule",{value:!0}),r);var In={};dt(In,{ASTBuilder:()=>ne,DEFAULT_CONFIDENCE_THRESHOLD:()=>ze,HIGH_CONFIDENCE_THRESHOLD:()=>it,SemanticAnalyzerImpl:()=>re,VERSION:()=>Mn,arabicProfile:()=>K,arabicTokenizer:()=>ue,buildAST:()=>nt,canParse:()=>Pe,createCommandNode:()=>O,createEventHandler:()=>D,createLiteral:()=>T,createPropertyPath:()=>F,createReference:()=>C,createSelector:()=>V,createSemanticAnalyzer:()=>rt,fromExplicit:()=>Ce,getCommandMapper:()=>te,getPatternsForLanguage:()=>st,getPatternsForLanguageAndCommand:()=>On,getProfile:()=>Se,getSupportedLanguages:()=>zn,getTokenizer:()=>xe,isExplicitSyntax:()=>q,isLanguageSupported:()=>je,parse:()=>H,parseAny:()=>Re,parseExplicit:()=>$,registerCommandMapper:()=>Me,render:()=>J,renderExplicit:()=>ee,shouldUseSemanticResult:()=>ot,toExplicit:()=>we,tokenize:()=>Vn,tryGetProfile:()=>M});var w=new Map,I=new Map,X=new Map;var Ve=null;function Ie(r,e){let t={...r};for(let n of Object.keys(e)){let i=e[n],o=r[n];i!==void 0&&(typeof i=="object"&&i!==null&&!Array.isArray(i)&&typeof o=="object"&&o!==null&&!Array.isArray(o)?t[n]=Ie(o,i):t[n]=i)}return t}function ft(r,e){return Ie(r,e)}function ye(r){if(!r.extends)return r;let e=I.get(r.extends);if(!e)return console.warn(`[Registry] Profile '${r.code}' extends '${r.extends}' but base is not registered. Make sure to import the base language before the variant.`),r;let t=ye(e);return ft(t,r)}function _e(r,e,t){w.set(r,e),I.set(r,t),X.delete(r)}var Oe=new Map;function _(r){return r.split("-")[0]}function B(r){return r.includes("-")}function xe(r){let e=w.get(r);if(!e&&B(r)){let t=_(r);e=w.get(t)}if(!e){let t=Array.from(w.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function Se(r){let e=I.get(r);if(!e&&B(r)){let t=_(r);e=I.get(t)}if(!e){let t=Array.from(I.keys()).join(", ");throw new Error(`Language profile '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return ye(e)}function Be(r){let e=w.get(r);return!e&&B(r)&&(e=w.get(_(r))),e}function M(r){let e=I.get(r);return!e&&B(r)&&(e=I.get(_(r))),e?ye(e):void 0}function ie(){return Array.from(w.keys())}function je(r){return w.has(r)?!0:B(r)?w.has(_(r)):!1}function Ke(r,e){return xe(e).tokenize(r)}function N(r){let e=X.get(r);if(!e&&B(r)&&(e=X.get(_(r))),e)return e;let t=Oe.get(r);if(!t&&B(r)&&(t=Oe.get(_(r))),t)return X.set(r,t),t;if(!Ve)throw new Error(`No patterns registered for language '${r}'. Either import the language module or set a pattern generator.`);let n=Se(r),i=Ve(n);return X.set(r,i),i}function We(r,e){return N(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}var j=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function S(r,e){return{start:r,end:e}}function v(r,e,t,n){if(typeof n=="string")return{value:r,kind:e,position:t,normalized:n};if(n){let{normalized:i,stem:o,stemConfidence:s}=n,a={value:r,kind:e,position:t};return i!==void 0&&(a.normalized=i),o!==void 0&&(a.stem=o,s!==void 0&&(a.stemConfidence=s)),a}return{value:r,kind:e,position:t}}function A(r){return/\s/.test(r)}function ae(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function se(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function P(r){return/\d/.test(r)}function $e(r){return/[a-zA-Z]/.test(r)}function E(r){return/[a-zA-Z0-9_-]/.test(r)}function ve(r){return e=>{let t=e.charCodeAt(0);return r.some(([n,i])=>t>=n&&t<=i)}}function Ue(r,e){if(e>=r.length)return null;let t=r[e];if(!ae(t))return null;let n=e,i="";if(t==="#"||t==="."){for(i+=r[n++];n<r.length&&E(r[n]);)i+=r[n++];if(i.length<=1)return null;if(n<r.length&&r[n]==="."&&t==="#"){let s=n+1;for(;s<r.length&&E(r[s]);)s++;if(s<r.length&&r[s]==="(")return i}}else if(t==="["){let o=1,s=!1,a=null,c=!1;for(i+=r[n++];n<r.length&&o>0;){let l=r[n];i+=l,c?c=!1:l==="\\"?c=!0:s?l===a&&(s=!1,a=null):l==='"'||l==="'"||l==="`"?(s=!0,a=l):l==="["?o++:l==="]"&&o--,n++}if(o!==0)return null}else if(t==="@"){for(i+=r[n++];n<r.length&&E(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="*"){for(i+=r[n++];n<r.length&&E(r[n]);)i+=r[n++];if(i.length<=1)return null}else if(t==="<"){if(i+=r[n++],n>=r.length||!$e(r[n]))return null;for(;n<r.length&&E(r[n]);)i+=r[n++];for(;n<r.length;){let o=r[n];if(o==="."){if(i+=r[n++],n>=r.length||!E(r[n]))return null;for(;n<r.length&&E(r[n]);)i+=r[n++]}else if(o==="#"){if(i+=r[n++],n>=r.length||!E(r[n]))return null;for(;n<r.length&&E(r[n]);)i+=r[n++]}else if(o==="["){let s=1,a=!1,c=null,l=!1;for(i+=r[n++];n<r.length&&s>0;){let p=r[n];i+=p,l?l=!1:p==="\\"?l=!0:a?p===c&&(a=!1,c=null):p==='"'||p==="'"||p==="`"?(a=!0,c=p):p==="["?s++:p==="]"&&s--,n++}if(s!==0)return null}else break}for(;n<r.length&&A(r[n]);)i+=r[n++];if(n<r.length&&r[n]==="/")for(i+=r[n++];n<r.length&&A(r[n]);)i+=r[n++];if(n>=r.length||r[n]!==">")return null;i+=r[n++]}return i||null}function gt(r,e){if(e>=r.length||r[e]!=="'"||e+1>=r.length||r[e+1].toLowerCase()!=="s")return!1;if(e+2>=r.length)return!0;let n=r[e+2];return A(n)||n==="*"||!E(n)}function Fe(r,e){if(e>=r.length)return null;let t=r[e];if(!se(t)||t==="'"&>(r,e))return null;let i={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!i)return null;let o=e+1,s=t,a=!1;for(;o<r.length;){let c=r[o];if(s+=c,a)a=!1;else if(c==="\\")a=!0;else if(c===i)return s;o++}return s}function ce(r,e){if(e>=r.length)return!1;let t=r[e],n=r[e+1]||"",i=r[e+2]||"";if(t==="/"&&n!=="/"&&/[a-zA-Z0-9._-]/.test(n)||t==="/"&&n==="/"&&/[a-zA-Z]/.test(i)||t==="."&&(n==="/"||n==="."&&i==="/"))return!0;let o=r.slice(e,e+8).toLowerCase();return!!(o.startsWith("http://")||o.startsWith("https://"))}function De(r,e){if(!ce(r,e))return null;let t=e,n="",i=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<r.length;){let o=r[t];if(o==="#"){if(n.length>0&&/[a-zA-Z0-9/.]$/.test(n))for(n+=o,t++;t<r.length&&/[a-zA-Z0-9_-]/.test(r[t]);)n+=r[t++];break}if(i.test(o))n+=o,t++;else break}return n.length<2?null:n}function qe(r,e){if(e>=r.length)return null;let t=r[e];if(!P(t)&&t!=="-"&&t!=="+")return null;let n=e,i="";if((r[n]==="-"||r[n]==="+")&&(i+=r[n++]),n>=r.length||!P(r[n]))return null;for(;n<r.length&&P(r[n]);)i+=r[n++];if(n<r.length&&r[n]===".")for(i+=r[n++];n<r.length&&P(r[n]);)i+=r[n++];return n<r.length&&(r.slice(n,n+2)==="ms"?i+="ms":(r[n]==="s"||r[n]==="m"||r[n]==="h")&&(i+=r[n])),i}var oe=class oe{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let n=new Map;if(e.keywords){for(let[i,o]of Object.entries(e.keywords))if(n.set(o.primary,{native:o.primary,normalized:o.normalized||i}),o.alternatives)for(let s of o.alternatives)n.set(s,{native:s,normalized:o.normalized||i})}if(e.references)for(let[i,o]of Object.entries(e.references))n.set(o,{native:o,normalized:i});if(e.roleMarkers){for(let[i,o]of Object.entries(e.roleMarkers))if(o.primary&&n.set(o.primary,{native:o.primary,normalized:i}),o.alternatives)for(let s of o.alternatives)n.set(s,{native:s,normalized:i})}for(let i of t)n.set(i.native,i);this.profileKeywords=Array.from(n.values()).sort((i,o)=>o.native.length-i.native.length),this.profileKeywordMap=new Map;for(let i of this.profileKeywords){this.profileKeywordMap.set(i.native.toLowerCase(),i);let o=this.removeDiacritics(i.native);o!==i.native&&!this.profileKeywordMap.has(o.toLowerCase())&&this.profileKeywordMap.set(o.toLowerCase(),i)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let n of this.profileKeywords)if(e.slice(t).startsWith(n.native))return v(n.native,"keyword",S(t,t+n.native.length),n.normalized);return null}isKeywordStart(e,t){let n=e.slice(t);return this.profileKeywords.some(i=>n.startsWith(i.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,n){let i=this.tryNormalize(e);if(!i)return null;let o=this.lookupKeyword(i.stem);if(!o)return null;let s={normalized:o.normalized,stem:i.stem,stemConfidence:i.confidence};return v(e,"keyword",S(t,n),s)}trySelector(e,t){let n=Ue(e,t);return n?v(n,"selector",S(t,t+n.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let n=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!n)return null;let i=n[0].replace(/(\s|\.)$/,""),o=i.slice(1).split("(")[0],s=n[1];return{...v(i,"event-modifier",S(t,t+i.length)),metadata:{modifierName:o,value:s?o==="queue"?s:parseInt(s,10):void 0}}}tryString(e,t){let n=Fe(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryNumber(e,t){let n=qe(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,i=!1){let o=t;if(i)for(;o<e.length&&A(e[o]);)o++;let s=e.slice(o);for(let a of n){let c=s.slice(0,a.length);if(a.caseInsensitive?c.toLowerCase()===a.pattern.toLowerCase():c===a.pattern){if(a.notFollowedBy&&(s[a.length]||"")===a.notFollowedBy)continue;if(a.checkBoundary){let p=s[a.length]||"";if(E(p))continue}return{suffix:a.suffix,endPos:o+a.length}}}return null}parseBaseNumber(e,t,n=!0){let i=t,o="";if(n&&(e[i]==="-"||e[i]==="+")&&(o+=e[i++]),i>=e.length||!P(e[i]))return null;for(;i<e.length&&P(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&P(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,n,i={}){let{allowSign:o=!0,skipWhitespace:s=!1}=i,a=this.parseBaseNumber(e,t,o);if(!a)return null;let{number:c,endPos:l}=a,p=[...n,...oe.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,l,p,s);return x&&(c+=x.suffix,l=x.endPos),v(c,"literal",S(t,l))}tryUrl(e,t){let n=De(e,t);return n?v(n,"url",S(t,t+n.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!E(e[t+1]))return null;let n=t+1;for(;n<e.length&&E(e[n]);)n++;let i=e.slice(t,n);return v(i,"identifier",S(t,n))}tryOperator(e,t){let n=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(n))return v(n,"operator",S(t,t+2));let i=e[t];return["<",">","!","+","-","*","/","="].includes(i)?v(i,"operator",S(t,t+1)):["(",")","{","}",",",";",":"].includes(i)?v(i,"punctuation",S(t,t+1)):null}tryMultiCharParticle(e,t,n){for(let i of n)if(e.slice(t,t+i.length)===i)return v(i,"particle",S(t,t+i.length));return null}};oe.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 Z=oe;function He(r){return{stem:r,confidence:1}}function Ge(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}function ht(r){let e=r.charCodeAt(0);return e>=1536&&e<=1791||e>=1872&&e<=1919||e>=2208&&e<=2303||e>=64336&&e<=65023||e>=65136&&e<=65279}function yt(r){for(let e of r)if(ht(e))return!0;return!1}function xt(r){return r.replace(/[\u064B-\u0652\u0670]/g,"")}var St=[{pattern:"\u0648\u0627\u0644",confidencePenalty:.15,prefixType:"conjunction"},{pattern:"\u0641\u0627\u0644",confidencePenalty:.15,prefixType:"conjunction"},{pattern:"\u0628\u0627\u0644",confidencePenalty:.15,prefixType:"preposition"},{pattern:"\u0643\u0627\u0644",confidencePenalty:.15,prefixType:"preposition"},{pattern:"\u0644\u0644",confidencePenalty:.12,prefixType:"preposition"}],vt=[{pattern:"\u0627\u0644",confidencePenalty:.08,prefixType:"article",minRemaining:2},{pattern:"\u0648",confidencePenalty:.08,prefixType:"conjunction",minRemaining:3},{pattern:"\u0641",confidencePenalty:.08,prefixType:"conjunction",minRemaining:3},{pattern:"\u0628",confidencePenalty:.1,prefixType:"preposition",minRemaining:3},{pattern:"\u0644",confidencePenalty:.1,prefixType:"preposition",minRemaining:3},{pattern:"\u0643",confidencePenalty:.1,prefixType:"preposition",minRemaining:3}],Tt=[{pattern:"\u064A",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u062A",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0646",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0623",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3},{pattern:"\u0627",confidencePenalty:.12,prefixType:"verb-marker",minRemaining:3}],bt=[{pattern:"\u0648\u0646",confidencePenalty:.1,type:"masculine-plural"},{pattern:"\u064A\u0646",confidencePenalty:.1,type:"masculine-plural-accusative"},{pattern:"\u0627\u062A",confidencePenalty:.1,type:"feminine-plural"},{pattern:"\u0627\u0646",confidencePenalty:.1,type:"dual-nominative"},{pattern:"\u064A\u0646",confidencePenalty:.1,type:"dual-accusative"},{pattern:"\u0647\u0627",confidencePenalty:.1,type:"pronoun-her"},{pattern:"\u0647\u0645",confidencePenalty:.1,type:"pronoun-them"},{pattern:"\u0647\u0646",confidencePenalty:.1,type:"pronoun-them-f"},{pattern:"\u0646\u0627",confidencePenalty:.1,type:"pronoun-us"},{pattern:"\u0643\u0645",confidencePenalty:.1,type:"pronoun-you-pl"},{pattern:"\u0643",confidencePenalty:.08,type:"pronoun-you"},{pattern:"\u0647",confidencePenalty:.08,type:"pronoun-him"},{pattern:"\u064A",confidencePenalty:.08,type:"pronoun-me"},{pattern:"\u0629",confidencePenalty:.08,type:"feminine"}],Q=class{constructor(){this.language="ar"}isNormalizable(e){return!(!yt(e)||e.length<2)}normalize(e){let t=xt(e),n=1,i=[],o=[];for(let a of St)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length);if(c.length>=2){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}if(i.length===0){for(let a of vt)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length),l=a.minRemaining??2;if(c.length>=l){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}}if(!(t.endsWith("\u0627\u062A")||t.endsWith("\u0629")||t.endsWith("\u0648\u0646")||t.endsWith("\u064A\u0646")||t.endsWith("\u0647\u0627")||t.endsWith("\u0647\u0645")||t.endsWith("\u0647\u0646")||t.endsWith("\u0646\u0627")||t.endsWith("\u0643\u0645"))&&(i.length===0||i[0]==="\u0648"||i[0]==="\u0641")){for(let a of Tt)if(t.startsWith(a.pattern)){let c=t.slice(a.pattern.length),l=a.minRemaining??3;if(c.length>=l){t=c,n-=a.confidencePenalty,i.push(a.pattern);break}}}for(let a of bt)if(t.endsWith(a.pattern)){let c=t.slice(0,-a.pattern.length);c.length>=2&&(t=c,n-=a.confidencePenalty,o.push(a.pattern))}return n=Math.max(.5,n),i.length===0&&o.length===0?He(e):Ge(t,n,{removedPrefixes:i,removedSuffixes:o})}},$n=new Q;var K={code:"ar",name:"Arabic",nativeName:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",direction:"rtl",wordOrder:"VSO",markingStrategy:"preposition",usesSpaces:!0,verb:{position:"start",subjectDrop:!0},references:{me:"\u0623\u0646\u0627",it:"\u0647\u0648",you:"\u0623\u0646\u062A",result:"\u0627\u0644\u0646\u062A\u064A\u062C\u0629",event:"\u0627\u0644\u062D\u062F\u062B",target:"\u0627\u0644\u0647\u062F\u0641",body:"\u0627\u0644\u062C\u0633\u0645"},possessive:{marker:"",markerPosition:"after-object",usePossessiveAdjectives:!0,specialForms:{me:"\u0644\u064A",it:"\u0644\u0647",you:"\u0644\u0643"},keywords:{\u0644\u064A:"me",\u0644\u0643:"you",\u0644\u0647:"it",\u0644\u0647\u0627:"it"}},roleMarkers:{destination:{primary:"\u0639\u0644\u0649",alternatives:["\u0641\u064A","\u0625\u0644\u0649","\u0628"],position:"before"},source:{primary:"\u0645\u0646",position:"before"},patient:{primary:"",position:"before"},style:{primary:"\u0628\u0640",alternatives:["\u0628\u0627\u0633\u062A\u062E\u062F\u0627\u0645"],position:"before"}},keywords:{toggle:{primary:"\u0628\u062F\u0651\u0644",alternatives:["\u0628\u062F\u0644","\u063A\u064A\u0651\u0631","\u063A\u064A\u0631"],normalized:"toggle"},add:{primary:"\u0623\u0636\u0641",alternatives:["\u0627\u0636\u0641","\u0632\u0650\u062F"],normalized:"add"},remove:{primary:"\u0627\u062D\u0630\u0641",alternatives:["\u0623\u0632\u0644","\u0627\u0645\u0633\u062D"],normalized:"remove"},put:{primary:"\u0636\u0639",alternatives:["\u0627\u062C\u0639\u0644"],normalized:"put"},append:{primary:"\u0623\u0644\u062D\u0642",normalized:"append"},prepend:{primary:"\u0633\u0628\u0642",normalized:"prepend"},take:{primary:"\u062E\u0630",normalized:"take"},make:{primary:"\u0627\u0635\u0646\u0639",alternatives:["\u0623\u0646\u0634\u0626"],normalized:"make"},clone:{primary:"\u0627\u0633\u062A\u0646\u0633\u062E",alternatives:["\u0627\u0646\u0633\u062E"],normalized:"clone"},swap:{primary:"\u0627\u0633\u062A\u0628\u062F\u0644",alternatives:["\u062A\u0628\u0627\u062F\u0644"],normalized:"swap"},morph:{primary:"\u062D\u0648\u0651\u0644",alternatives:["\u063A\u064A\u0651\u0631"],normalized:"morph"},set:{primary:"\u0627\u0636\u0628\u0637",alternatives:["\u0639\u064A\u0651\u0646","\u062D\u062F\u062F"],normalized:"set"},get:{primary:"\u0627\u062D\u0635\u0644",normalized:"get"},increment:{primary:"\u0632\u0650\u062F",alternatives:["\u0632\u062F","\u0627\u0631\u0641\u0639"],normalized:"increment"},decrement:{primary:"\u0623\u0646\u0642\u0635",alternatives:["\u0627\u0646\u0642\u0635","\u0642\u0644\u0644"],normalized:"decrement"},log:{primary:"\u0633\u062C\u0644",normalized:"log"},show:{primary:"\u0627\u0638\u0647\u0631",alternatives:["\u0623\u0638\u0647\u0631","\u0627\u0639\u0631\u0636"],normalized:"show"},hide:{primary:"\u0627\u062E\u0641",alternatives:["\u0623\u062E\u0641\u0650","\u0627\u062E\u0641\u064A","\u0623\u062E\u0641"],normalized:"hide"},transition:{primary:"\u0627\u0646\u062A\u0642\u0627\u0644",alternatives:["\u0627\u0646\u062A\u0642\u0644"],normalized:"transition"},on:{primary:"\u0639\u0644\u0649",alternatives:["\u0639\u0646\u062F","\u0644\u062F\u0649","\u062D\u064A\u0646"],normalized:"on"},trigger:{primary:"\u062A\u0634\u063A\u064A\u0644",alternatives:["\u0623\u0637\u0644\u0642","\u0641\u0639\u0651\u0644"],normalized:"trigger"},send:{primary:"\u0623\u0631\u0633\u0644",normalized:"send"},focus:{primary:"\u062A\u0631\u0643\u064A\u0632",alternatives:["\u0631\u0643\u0632"],normalized:"focus"},blur:{primary:"\u0636\u0628\u0627\u0628\u064A\u0629",alternatives:["\u0634\u0648\u0634"],normalized:"blur"},go:{primary:"\u0627\u0630\u0647\u0628",alternatives:["\u0627\u0646\u062A\u0642\u0644"],normalized:"go"},wait:{primary:"\u0627\u0646\u062A\u0638\u0631",normalized:"wait"},fetch:{primary:"\u0627\u062D\u0636\u0631",alternatives:["\u062C\u0644\u0628"],normalized:"fetch"},settle:{primary:"\u0627\u0633\u062A\u0642\u0631",normalized:"settle"},if:{primary:"\u0625\u0630\u0627",normalized:"if"},when:{primary:"\u0639\u0646\u062F\u0645\u0627",normalized:"when"},where:{primary:"\u0623\u064A\u0646",normalized:"where"},else:{primary:"\u0648\u0625\u0644\u0627",alternatives:["\u062E\u0644\u0627\u0641 \u0630\u0644\u0643"],normalized:"else"},repeat:{primary:"\u0643\u0631\u0631",normalized:"repeat"},for:{primary:"\u0644\u0643\u0644",normalized:"for"},while:{primary:"\u0628\u064A\u0646\u0645\u0627",normalized:"while"},continue:{primary:"\u0648\u0627\u0635\u0644",normalized:"continue"},halt:{primary:"\u0623\u0648\u0642\u0641",alternatives:["\u062A\u0648\u0642\u0641"],normalized:"halt"},throw:{primary:"\u0627\u0631\u0645",alternatives:["\u0627\u0631\u0645\u0650"],normalized:"throw"},call:{primary:"\u0627\u0633\u062A\u062F\u0639",alternatives:["\u0646\u0627\u062F\u0650"],normalized:"call"},return:{primary:"\u0627\u0631\u062C\u0639",alternatives:["\u0639\u064F\u062F"],normalized:"return"},then:{primary:"\u062B\u0645",alternatives:["\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"],normalized:"then"},and:{primary:"\u0648\u0623\u064A\u0636\u0627\u064B",alternatives:["\u0623\u064A\u0636\u0627\u064B"],normalized:"and"},end:{primary:"\u0646\u0647\u0627\u064A\u0629",alternatives:["\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"],normalized:"end"},js:{primary:"\u062C\u0627\u0641\u0627\u0633\u0643\u0631\u0628\u062A",alternatives:["js"],normalized:"js"},async:{primary:"\u0645\u062A\u0632\u0627\u0645\u0646",normalized:"async"},tell:{primary:"\u0623\u062E\u0628\u0631",normalized:"tell"},default:{primary:"\u0627\u0641\u062A\u0631\u0627\u0636\u064A",normalized:"default"},init:{primary:"\u062A\u0647\u064A\u0626\u0629",alternatives:["\u0628\u062F\u0621"],normalized:"init"},behavior:{primary:"\u0633\u0644\u0648\u0643",normalized:"behavior"},install:{primary:"\u062A\u062B\u0628\u064A\u062A",alternatives:["\u062B\u0628\u0651\u062A"],normalized:"install"},measure:{primary:"\u0642\u064A\u0627\u0633",alternatives:["\u0642\u0650\u0633"],normalized:"measure"},into:{primary:"\u0641\u064A",alternatives:["\u0625\u0644\u0649"],normalized:"into"},before:{primary:"\u0642\u0628\u0644",normalized:"before"},after:{primary:"\u0628\u0639\u062F",normalized:"after"},until:{primary:"\u062D\u062A\u0649",normalized:"until"},event:{primary:"\u062D\u062F\u062B",normalized:"event"},from:{primary:"\u0645\u0646",normalized:"from"}},tokenization:{prefixes:["\u0627\u0644","\u0648","\u0641","\u0628","\u0643","\u0644"]},eventHandler:{eventMarker:{primary:"\u0639\u0646\u062F",alternatives:["\u0641\u064A","\u0644\u062F\u0649","\u0639\u0646\u062F\u0645\u0627","\u062D\u064A\u0646","\u062D\u064A\u0646\u0645\u0627","\u0644\u0645\u0651\u0627","\u0644\u0645\u0627"],position:"before"},temporalMarkers:["\u0639\u0646\u062F\u0645\u0627","\u062D\u064A\u0646","\u0644\u0645\u0651\u0627"],negationMarker:{primary:"\u0639\u062F\u0645",alternatives:["\u0639\u062F\u0645"],position:"before"}}};var z=ve([[1536,1791],[1872,1919],[2208,2303],[64336,65023],[65136,65279]]),Et=new Set(["\u0628\u0640","\u0644\u0640","\u0643\u0640","\u0648\u0640"]),Te=new Map([["\u0648",{normalized:"and",type:"conjunction"}],["\u0641",{normalized:"then",type:"conjunction"}],["\u0628",{normalized:"with",type:"preposition"}],["\u0644",{normalized:"to",type:"preposition"}],["\u0643",{normalized:"like",type:"preposition"}],["\u0648\u0644",{normalized:"and-to",type:"conjunction"}],["\u0648\u0628",{normalized:"and-with",type:"conjunction"}],["\u0648\u0643",{normalized:"and-like",type:"conjunction"}],["\u0641\u0644",{normalized:"then-to",type:"conjunction"}],["\u0641\u0628",{normalized:"then-with",type:"conjunction"}],["\u0641\u0643",{normalized:"then-like",type:"conjunction"}]]),Xe=new Map([["\u0639\u0646\u062F\u0645\u0627",{normalized:"on",formality:"formal",confidence:.95,description:"when (formal MSA)"}],["\u062D\u064A\u0646\u0645\u0627",{normalized:"on",formality:"formal",confidence:.93,description:"when/whenever (formal)"}],["\u0639\u0646\u062F",{normalized:"on",formality:"neutral",confidence:.88,description:"at/when (neutral)"}],["\u062D\u064A\u0646",{normalized:"on",formality:"neutral",confidence:.85,description:"when/time (neutral)"}],["\u0644\u0645\u0651\u0627",{normalized:"on",formality:"dialectal",confidence:.7,description:"when (dialectal, with shadda)"}],["\u0644\u0645\u0627",{normalized:"on",formality:"dialectal",confidence:.68,description:"when (dialectal, no diacritic)"}],["\u0644\u062F\u0649",{normalized:"on",formality:"neutral",confidence:.82,description:"at/with (temporal)"}]]),le=new Set(["\u0641\u064A","\u0639\u0644\u0649","\u0645\u0646","\u0625\u0644\u0649","\u0627\u0644\u0649","\u0645\u0639","\u0639\u0646","\u0642\u0628\u0644","\u0628\u0639\u062F","\u0628\u064A\u0646"]),kt=[{native:"\u0635\u062D\u064A\u062D",normalized:"true"},{native:"\u062E\u0637\u0623",normalized:"false"},{native:"null",normalized:"null"},{native:"\u0641\u0627\u0631\u063A",normalized:"null"},{native:"\u063A\u064A\u0631 \u0645\u0639\u0631\u0641",normalized:"undefined"},{native:"\u0627\u0644\u0623\u0648\u0644",normalized:"first"},{native:"\u0623\u0648\u0644",normalized:"first"},{native:"\u0627\u0644\u0623\u062E\u064A\u0631",normalized:"last"},{native:"\u0622\u062E\u0631",normalized:"last"},{native:"\u0627\u0644\u062A\u0627\u0644\u064A",normalized:"next"},{native:"\u0627\u0644\u0633\u0627\u0628\u0642",normalized:"previous"},{native:"\u0627\u0644\u0623\u0642\u0631\u0628",normalized:"closest"},{native:"\u0627\u0644\u0623\u0628",normalized:"parent"},{native:"\u0627\u0644\u0646\u0642\u0631",normalized:"click"},{native:"\u0646\u0642\u0631",normalized:"click"},{native:"\u0627\u0644\u0625\u062F\u062E\u0627\u0644",normalized:"input"},{native:"\u0625\u062F\u062E\u0627\u0644",normalized:"input"},{native:"\u0627\u0644\u062A\u063A\u064A\u064A\u0631",normalized:"change"},{native:"\u062A\u063A\u064A\u064A\u0631",normalized:"change"},{native:"\u0627\u0644\u0625\u0631\u0633\u0627\u0644",normalized:"submit"},{native:"\u0625\u0631\u0633\u0627\u0644",normalized:"submit"},{native:"\u0627\u0644\u062A\u0631\u0643\u064A\u0632",normalized:"focus"},{native:"\u0641\u0642\u062F\u0627\u0646 \u0627\u0644\u062A\u0631\u0643\u064A\u0632",normalized:"blur"},{native:"\u0636\u063A\u0637",normalized:"keydown"},{native:"\u0631\u0641\u0639",normalized:"keyup"},{native:"\u062A\u0645\u0631\u064A\u0631 \u0627\u0644\u0641\u0623\u0631\u0629",normalized:"mouseover"},{native:"\u0645\u063A\u0627\u062F\u0631\u0629 \u0627\u0644\u0641\u0623\u0631\u0629",normalized:"mouseout"},{native:"\u062A\u062D\u0645\u064A\u0644",normalized:"load"},{native:"\u062A\u0645\u0631\u064A\u0631",normalized:"scroll"},{native:"\u0647\u064A",normalized:"it"},{native:"\u062B\u0627\u0646\u064A\u0629",normalized:"s"},{native:"\u062B\u0648\u0627\u0646\u064A",normalized:"s"},{native:"\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629",normalized:"ms"},{native:"\u062F\u0642\u064A\u0642\u0629",normalized:"m"},{native:"\u062F\u0642\u0627\u0626\u0642",normalized:"m"},{native:"\u0633\u0627\u0639\u0629",normalized:"h"},{native:"\u0633\u0627\u0639\u0627\u062A",normalized:"h"}],Nt=[{pattern:"\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629",suffix:"ms",length:9,caseInsensitive:!1},{pattern:"\u0645\u0644\u064A_\u062B\u0627\u0646\u064A\u0629",suffix:"ms",length:8,caseInsensitive:!1},{pattern:"\u062F\u0642\u0627\u0626\u0642",suffix:"m",length:5,caseInsensitive:!1},{pattern:"\u062F\u0642\u064A\u0642\u0629",suffix:"m",length:5,caseInsensitive:!1},{pattern:"\u062B\u0648\u0627\u0646\u064A",suffix:"s",length:5,caseInsensitive:!1},{pattern:"\u062B\u0627\u0646\u064A\u0629",suffix:"s",length:5,caseInsensitive:!1},{pattern:"\u0633\u0627\u0639\u0627\u062A",suffix:"h",length:5,caseInsensitive:!1},{pattern:"\u0633\u0627\u0639\u0629",suffix:"h",length:4,caseInsensitive:!1}],be=class extends Z{constructor(){super();this.language="ar";this.direction="rtl";this.initializeKeywordsFromProfile(K,kt),this.normalizer=new Q}tokenize(t){let n=[],i=0;for(;i<t.length;){if(A(t[i])){i++;continue}if(ae(t[i])){let a=this.tryEventModifier(t,i);if(a){n.push(a),i=a.position.end;continue}let c=this.trySelector(t,i);if(c){n.push(c),i=c.position.end;continue}}if(se(t[i])){let a=this.tryString(t,i);if(a){n.push(a),i=a.position.end;continue}}if(ce(t,i)){let a=this.tryUrl(t,i);if(a){n.push(a),i=a.position.end;continue}}if(P(t[i])){let a=this.extractArabicNumber(t,i);if(a){n.push(a),i=a.position.end;continue}}let o=this.tryVariableRef(t,i);if(o){n.push(o),i=o.position.end;continue}let s=this.tryPreposition(t,i);if(s){n.push(s),i=s.position.end;continue}if(z(t[i])){let a=this.tryProclitic(t,i);if(a){n.push(a.conjunction),i=a.conjunction.position.end;continue}let c=this.extractArabicWord(t,i);if(c){n.push(c),i=c.position.end;continue}}if(E(t[i])){let a=this.extractAsciiWord(t,i);if(a){n.push(a),i=a.position.end;continue}}i++}return new j(n,"ar")}classifyToken(t){return le.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||/^\d/.test(t)?"literal":"identifier"}tryPreposition(t,n){let i=Array.from(le).sort((o,s)=>s.length-o.length);for(let o of i)if(t.slice(n,n+o.length)===o){let s=n+o.length;if(s>=t.length||A(t[s])||!z(t[s]))return{...v(o,"particle",S(n,s)),metadata:{prepositionValue:o}}}return null}tryProclitic(t,n){let i=n;for(;i<t.length&&(z(t[i])||t[i]==="\u0640");)i++;let o=t.slice(n,i);if(this.lookupKeyword(o)||Xe.has(o)||le.has(o))return null;if(n+2<=t.length){let y=t.slice(n,n+2),g=Te.get(y);if(g){let d=n+2;if(d<t.length&&z(t[d])){let m=0,h=d;for(;h<t.length&&z(t[h]);)m++,h++;if(m>=2)if(Te.get(t[n])){let L=t.slice(n+1,i);if(!this.lookupKeyword(L)){let G=g.type==="conjunction"?"conjunction":"particle";return{conjunction:v(y,G,S(n,d),g.normalized)}}}else{let L=g.type==="conjunction"?"conjunction":"particle";return{conjunction:v(y,L,S(n,d),g.normalized)}}}}}let s=t[n],a=Te.get(s);if(!a)return null;let c=n+1;if(c>=t.length||!z(t[c]))return null;let l=0,p=c;for(;p<t.length&&z(t[p]);)l++,p++;if(l<2)return null;let x=a.type==="conjunction"?"conjunction":"particle";return{conjunction:v(s,x,S(n,c),a.normalized)}}extractArabicWord(t,n){let i=n,o="";for(let l of Et){let p=l.replace("\u0640","");t.slice(i,i+p.length)}for(;i<t.length&&(z(t[i])||t[i]==="\u0640");)o+=t[i++];if(!o)return null;let s=Xe.get(o);if(s)return{...v(o,"keyword",S(n,i),s.normalized),metadata:{temporalFormality:s.formality,temporalConfidence:s.confidence}};let a=this.lookupKeyword(o);if(a)return v(o,"keyword",S(n,i),a.normalized);if(le.has(o))return{...v(o,"particle",S(n,i)),metadata:{prepositionValue:o}};let c=this.tryMorphKeywordMatch(o,n,i);return c||v(o,"identifier",S(n,i))}extractAsciiWord(t,n){let i=n,o="";for(;i<t.length&&E(t[i]);)o+=t[i++];return o?v(o,"identifier",S(n,i)):null}extractArabicNumber(t,n){return this.tryNumberWithTimeUnits(t,n,Nt,{allowSign:!1,skipWhitespace:!0})}},ue=new be;_e("ar",ue,K);function Ze(r){return Be(r)}function de(r,e){return Ke(r,e)}function pe(){return ie()}function V(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function T(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function C(r){return{type:"reference",value:r}}function F(r,e){return{type:"property-path",object:r,property:e}}function O(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function D(r,e,t,n,i){let o=new Map;o.set("event",r);let s={kind:"event-handler",action:"on",roles:o,body:e};return t!==void 0&&(s.eventModifiers=t),n!==void 0&&(s.metadata=n),i!==void 0&&i.length>0&&(s.parameterNames=i),s}function Qe(r,e="then",t){let n={kind:"compound",action:"compound",roles:new Map,statements:r,chainType:e};return t!==void 0&&(n.metadata=t),n}function Ee(r,e){return!e||e.length===0||e.includes(r)||e.includes("expression")?!0:r==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function Ye(r,e){return r.possessive?.keywords?.[e]}var R=class R{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let n=e.mark(),i=new Map;if(this.currentProfile=M(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,i))return e.reset(n),null;let s=this.calculateConfidence(t,i);return this.applyExtractionRules(t,i),{pattern:t,captured:i,consumedTokens:e.position()-n.position,confidence:s}}matchBest(e,t){let n=[];for(let o of t){let s=e.mark(),a=this.matchPattern(e,o);a&&n.push(a),e.reset(s)}if(n.length===0)return null;n.sort((o,s)=>{let a=s.pattern.priority-o.pattern.priority;return a!==0?a:s.confidence-o.confidence});let i=n[0];return this.matchPattern(e,i.pattern),i}matchTokenSequence(e,t,n){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 s of t)if(!this.matchPatternToken(e,s,n)){if(this.isOptional(s))continue;return!1}return!0}matchPatternToken(e,t,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,n);case"group":return this.matchGroupToken(e,t,n);default:return!1}}matchLiteralToken(e,t){let n=e.peek();if(!n)return!1;let i=this.getMatchType(n,t.value);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let o of t.alternatives){let s=this.getMatchType(n,o);if(s!=="none")return this.totalKeywordMatches++,s==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.skipNoiseWords(e);let i=e.peek();if(!i)return t.optional||!1;let o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(o.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,o),!0);let s=this.tryMatchMethodCallExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(s.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,s),!0);let a=this.tryMatchPossessiveSelectorExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(a.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,a),!0);let c=this.tryMatchPropertyAccessExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,c),!0);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(l.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,l),!0);let p=this.tokenToSemanticValue(i);return!p||t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(p.type)?t.optional||!1:(n.set(t.role,p),e.advance(),!0)}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let n=(t.normalized||t.value).toLowerCase(),i=Ye(this.currentProfile,n);if(!i)return null;let o=e.mark();e.advance();let s=e.peek();return s&&(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)||s.kind==="selector"&&s.value.startsWith("*"))?(e.advance(),F(C(i),s.value)):(e.reset(o),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let s=e.peek();if(!s||s.kind!=="punctuation"||s.value!=="(")return e.reset(n),null;e.advance();let a=[];for(;!e.isAtEnd()&&a.length<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}a.push(l.value),e.advance()}return{type:"expression",raw:`${t.value}.${o.value}(${a.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="operator"||i.value!==".")return e.reset(n),null;e.advance();let o=e.peek();if(!o||o.kind!=="identifier")return e.reset(n),null;e.advance();let s=`${t.value}.${o.value}`,a=1;for(;!e.isAtEnd()&&a<R.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),s+=`.${p.value}`,a++}let c=e.peek();if(c&&c.kind==="punctuation"&&c.value==="("){e.advance();let l=[],p=0;for(;!e.isAtEnd()&&l.length<R.MAX_METHOD_ARGS;){let y=e.peek();if(!y)break;if(y.kind==="punctuation"&&y.value===")"){if(p===0){e.advance();break}p--}if(y.kind==="punctuation"&&y.value==="("&&p++,y.kind==="punctuation"&&y.value===","){e.advance();continue}l.push(y.value),e.advance()}return{type:"expression",raw:`${s}(${l.join(", ")})`}}return{type:"expression",raw:s}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="'s")return e.reset(n),null;e.advance();let o=e.peek();return!o||o.kind!=="selector"&&o.kind!=="identifier"?(e.reset(n),null):(e.advance(),F(V(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(n),null;let o=e.peek(1);o&&o.kind,e.advance();let s=i.value.slice(1);return F(V(t.value),s)}matchGroupToken(e,t,n){let i=e.mark(),o=new Set(n.keys());if(!this.matchTokenSequence(e,t.tokens,n)){e.reset(i);for(let a of n.keys())o.has(a)||n.delete(a);return t.optional||!1}return!0}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem===t&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&e.value.toLowerCase()===t.toLowerCase()?"case-insensitive":"none"}tokenToSemanticValue(e){switch(e.kind){case"selector":return V(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?C(t):T(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return C(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?C(n):{type:"expression",raw:e.value};case"url":return T(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 T(i,"string")}if(e==="true")return T(!0,"boolean");if(e==="false")return T(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let i=parseFloat(t[1]);return t[2]?T(e,"duration"):T(i,"number")}let n=parseFloat(e);return isNaN(n)?T(e,"string"):T(n,"number")}applyExtractionRules(e,t){for(let[n,i]of Object.entries(e.extraction))!t.has(n)&&i.default&&t.set(n,i.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let n=0,i=0,o=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")i+=1,t.has(l.role)&&(n+=1);else if(l.type==="group"){for(let p of l.tokens)if(p.type==="role"){let x=o(p.role),y=.8;i+=y,t.has(p.role)?n+=y:x&&(n+=y*.6)}}let s=i>0?n/i:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let l=this.stemMatchCount/this.totalKeywordMatches*.15;s=Math.max(.5,s-l)}let a=this.calculateVSOConfidenceBoost(e);s=Math.min(1,s+a);let c=this.arabicPrepositionDisambiguation(e,t);return s=Math.max(0,Math.min(1,s+c)),s}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let n=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(n.has(t.value))return .15;if(t.alternatives){for(let i of t.alternatives)if(n.has(i))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let n=0,i={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[o,s]of t.entries()){let a=i[o];if(!a||a.length===0)continue;let c=s.metadata;if(c&&typeof c.prepositionValue=="string"){let l=c.prepositionValue;a.includes(l)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){let t=e.peek();if(!t)return;let n=t.value.toLowerCase();if(R.ENGLISH_NOISE_WORDS.has(n)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return n?t:void 0}};R.MAX_PROPERTY_DEPTH=10,R.MAX_METHOD_ARGS=20,R.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Y=R,W=new Y;var me=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=We(t,e.action);if(n.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,n);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return n.join(` ${i} `)}getChainWord(e,t){let n=M(t);return n?.keywords?n.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let n=e;return n.statements.map(o=>this.renderExplicit(o)).join(` ${n.chainType} `)}let t=[e.action];for(let[n,i]of e.roles)t.push(`${n}:${this.valueToString(i)}`);if(e.kind==="event-handler"){let n=e;if(n.body&&n.body.length>0){let i=n.body.map(o=>this.renderExplicit(o));t.push(`body:${i.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return pe()}findBestPattern(e,t){let n=t.map(i=>{let o=i.priority;for(let s of i.template.tokens)s.type==="role"&&(e.roles.has(s.role)?o+=10:s.optional||(o-=50));return i.language==="en"&&((i.id.includes("standard")||i.id.includes("en-source"))&&(o+=20),(i.id.includes("-when")||i.id.includes("-if")||i.id.includes("-upon"))&&(o-=15)),{pattern:i,score:o}});return n.sort((i,o)=>o.score-i.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let n=[],i=t.language;for(let o of t.template.tokens){let s=this.renderPatternToken(o,e,i);s!==null&&n.push(s)}if(e.kind==="event-handler"){let o=e;if(o.body&&o.body.length>0){let s=o.body.map(a=>this.render(a,i));n.push(s.join(" "))}}return n.join(" ")}renderPatternToken(e,t,n){switch(e.type){case"literal":return e.value;case"role":{let i=t.roles.get(e.role);return i?this.valueToNaturalString(i,n):(e.optional,null)}case"group":{if(!e.tokens.filter(s=>s.type==="role"&&!s.optional).every(s=>t.roles.has(s.role))&&e.optional)return null;if(e.optional&&e.tokens.find(a=>a.type==="role"&&a.role==="destination")){let a=t.roles.get("destination");if(a?.type==="reference"&&a.value==="me")return null}let o=[];for(let s of e.tokens){let a=this.renderPatternToken(s,t,n);a!==null&&o.push(a)}return o.length>0?o.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let n=M(t);return n?.references?n.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let n=M(t),i=e.property,o=e.object.type==="reference"?e.object.value:null;if(n?.possessive?.specialForms&&o){let a=n.possessive.specialForms[o];if(a){let{markerPosition:c,usePossessiveAdjectives:l}=n.possessive;return l&&c==="after-object"?`${i} ${a}`:`${a} ${i}`}}let s=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:a,markerPosition:c,usePossessiveAdjectives:l}=n.possessive;if(l&&o&&c==="after-object")return`${i} ${s}`;if(a)switch(c){case"between":return n.usesSpaces?`${s}${a} ${i}`:`${s}${a}${i}`;case"after-object":return`${s}${a} ${i}`;case"before-property":return`${s} ${a} ${i}`}}return t==="en"||!n?.possessive?s==="me"?`my ${i}`:s==="it"?`its ${i}`:`${s}'s ${i}`:`${s} ${i}`}},ke=new me;function J(r,e){return ke.render(r,e)}function ee(r){return ke.renderExplicit(r)}function $(r){let e=r.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let n=Pt(t);if(n.length===0)throw new Error("No command specified in explicit statement");let i=n[0].toLowerCase(),o=new Map;for(let a=1;a<n.length;a++){let c=n[a],l=c.indexOf(":");if(l===-1)throw new Error(`Invalid role format: "${c}". Expected role:value`);let p=c.slice(0,l),x=c.slice(l+1);if(p==="body"&&x.startsWith("[")){let g=Ct(c,l+1),d=c.slice(l+1,g+1);o.set(p,{type:"expression",raw:d});continue}let y=wt(x);o.set(p,y)}if(i==="on"){let a=o.get("event");if(!a)throw new Error("Event handler requires event role: [on event:click ...]");let c=o.get("body"),l=[];return c&&c.type==="expression"&&l.push($(c.raw)),o.delete("body"),D(a,l,void 0,{sourceLanguage:"explicit"})}let s={};for(let[a,c]of o)s[a]=c;return O(i,s,{sourceLanguage:"explicit"})}function Pt(r){let e=[],t="",n=!1,i="",o=0;for(let s=0;s<r.length;s++){let a=r[s];if(n){t+=a,a===i&&r[s-1]!=="\\"&&(n=!1);continue}if(a==='"'||a==="'"){n=!0,i=a,t+=a;continue}if(a==="["){o++,t+=a;continue}if(a==="]"){o--,t+=a;continue}if(a===" "&&o===0){t&&(e.push(t),t="");continue}t+=a}return t&&e.push(t),e}function wt(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return V(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return T(t,"string")}if(r==="true")return T(!0,"boolean");if(r==="false")return T(!1,"boolean");if(["me","you","it","result","event","target","body"].includes(r.toLowerCase()))return C(r.toLowerCase());let e=r.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(e){let t=parseFloat(e[1]);return e[2]?T(r,"duration"):T(t,"number")}return T(r,"string")}function Ct(r,e){let t=0;for(let n=e;n<r.length;n++)if(r[n]==="[")t++;else if(r[n]==="]"&&(t--,t===0))return n;return r.length-1}function q(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var fe=class{parse(e,t){let n=de(e,t),i=N(t);if(i.length===0)throw new Error(`No patterns available for language: ${t}`);let o=[...i].sort((p,x)=>x.priority-p.priority),s=o.filter(p=>p.command==="on"),a=W.matchBest(n,s);if(a)return this.buildEventHandler(a,n,t);let c=o.filter(p=>p.command!=="on"),l=W.matchBest(n,c);if(l)return this.buildCommand(l,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return pe()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let n={};for(let[i,o]of e.captured)n[i]=o;return O(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=W.extractEventModifiers(t),s,a=e.captured.get("action");if(a&&a.type==="literal"){let c=a.value,l={};for(let[y,g]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(l[y]=g);let p=O(c,l,{sourceLanguage:n,patternId:e.pattern.id,confidence:e.confidence}),x=e.captured.get("continues");if(x&&x.type==="literal"&&x.value==="then"){let y=N(n).filter(m=>m.command!=="on").sort((m,h)=>h.priority-m.priority),g=N(n).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,h)=>h.priority-m.priority),d=this.parseBodyWithGrammarPatterns(t,y,g,n);d.length>0?s=[p,...d]:s=[p]}else s=[p]}else{let c=N(n).filter(l=>l.command!=="on").sort((l,p)=>p.priority-l.priority);s=this.parseBodyWithClauses(t,c,n)}return D(i,s,o,{sourceLanguage:n,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,t,n){let i=[],o=[];for(;!e.isAtEnd();){let s=e.peek();if(!s)break;let a=s.kind==="conjunction"||s.kind==="keyword"&&this.isThenKeyword(s.value,n),c=s.kind==="keyword"&&this.isEndKeyword(s.value,n);if(a){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l),o.length=0}e.advance();continue}if(c){if(o.length>0){let l=this.parseClause(o,t,n);i.push(...l)}e.advance();break}o.push(s),e.advance()}if(o.length>0){let s=this.parseClause(o,t,n);i.push(...s)}return i.length>1?[Qe(i,"then",{sourceLanguage:n})]:i}parseClause(e,t,n){if(e.length===0)return[];let i=new j(e,n),o=[];for(;!i.isAtEnd();){let s=W.matchBest(i,t);s?o.push(this.buildCommand(s,n)):i.advance()}return o}parseBodyWithGrammarPatterns(e,t,n,i){let o=[];for(;!e.isAtEnd();){let s=e.peek();if(s&&this.isThenKeyword(s.value,i)){e.advance();continue}if(s&&this.isEndKeyword(s.value,i)){e.advance();break}let a=!1;if(n.length>0){let c=W.matchBest(e,n);if(c){let l=c.pattern.command,p={};for(let[g,d]of c.captured)g!=="event"&&g!=="action"&&g!=="continues"&&(p[g]=d);let x=O(l,p,{sourceLanguage:i,patternId:c.pattern.id});o.push(x),a=!0;let y=c.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!a){let c=W.matchBest(e,t);c&&(o.push(this.buildCommand(c,i)),a=!0)}a||e.advance()}return o}isThenKeyword(e,t){let n={en:new Set(["then"]),ja:new Set(["\u305D\u308C\u304B\u3089","\u6B21\u306B","\u305D\u3057\u3066"]),ar:new Set(["\u062B\u0645","\u0628\u0639\u062F\u0647\u0627","\u062B\u0645\u0651"]),es:new Set(["entonces","luego","despu\xE9s"]),ko:new Set(["\uADF8\uB2E4\uC74C","\uADF8\uB9AC\uACE0","\uADF8\uB7F0\uD6C4"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u4E4B\u540E"]),tr:new Set(["sonra","ard\u0131ndan","daha sonra"]),pt:new Set(["ent\xE3o","depois","logo"]),fr:new Set(["puis","ensuite","alors"]),de:new Set(["dann","danach","anschlie\xDFend"]),id:new Set(["lalu","kemudian","setelah itu"]),qu:new Set(["chaymantataq","hinaspa","chaymanta"]),sw:new Set(["kisha","halafu","baadaye"])};return(n[t]||n.en).has(e.toLowerCase())}isEndKeyword(e,t){let n={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u7D42\u4E86","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0622\u062E\u0631"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\uC885\uB8CC","\uB9C8\uCE68"]),zh:new Set(["\u7ED3\u675F","\u7EC8\u6B62","\u5B8C"]),tr:new Set(["son","biti\u015F","bitti"]),pt:new Set(["fim","final","t\xE9rmino"]),fr:new Set(["fin","terminer","finir"]),de:new Set(["ende","beenden","fertig"]),id:new Set(["selesai","akhir","tamat"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])};return(n[t]||n.en).has(e.toLowerCase())}},Ne=new fe;function H(r,e){return Ne.parse(r,e)}function Pe(r,e){return Ne.canParse(r,e)}function we(r,e){if(q(r))return r;let t=H(r,e);return ee(t)}function Ce(r,e){let t=$(r);return J(t,e)}function Re(r,e){return q(r)?$(r):H(r,e)}var Rt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Lt=new Set(["and","or","not","no"]),Mt=new Set(["true","false","null","undefined"]),At=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Je(r){let e=[],t=0,n=1,i=1;function o(){if(e.length===0)return!0;let d=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(d.type)}function s(d=0){return r[t+d]??""}function a(){let d=r[t];return t++,d===`
|
|
2
|
+
`?(n++,i=1):i++,d}function c(){for(;t<r.length&&/\s/.test(r[t]);)a()}function l(d){let m="";for(;t<r.length&&d(r[t]);)m+=a();return m}function p(d){let m=d;for(a();t<r.length&&r[t]!==d;)r[t]==="\\"&&t+1<r.length&&(m+=a()),m+=a();return t<r.length&&(m+=a()),m}function x(){let d="`";for(a();t<r.length&&r[t]!=="`";)r[t]==="\\"&&t+1<r.length&&(d+=a()),d+=a();return t<r.length&&(d+=a()),d}function y(){let d="<";for(a();t<r.length&&(d+=a(),!d.endsWith("/>")););return d}function g(d,m,h){return{type:d,value:m,start:h,end:t,line:n,column:i-m.length}}for(;t<r.length&&(c(),!(t>=r.length));){let d=t,m=s();if(m==="'"&&s(1)==="s"&&!/\w/.test(s(2))){a(),a(),e.push(g("POSSESSIVE","'s",d));continue}if(m==='"'||m==="'"){let h=p(m);e.push(g("STRING",h,d));continue}if(m==="`"){let h=x();e.push(g("TEMPLATE_LITERAL",h,d));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(s(1))){let h=y();e.push(g("QUERY_SELECTOR",h,d));continue}if(m==="#"&&o()){a();let h=l(b=>/[\w-]/.test(b));e.push(g("ID_SELECTOR","#"+h,d));continue}if(m==="."&&/[a-zA-Z_-]/.test(s(1))&&o()){a();let h=l(b=>/[\w-]/.test(b));e.push(g("CLASS_SELECTOR","."+h,d));continue}if(m==="["&&o()){let h=s(1);if(h==="@"||/[a-zA-Z]/.test(h)){let b="";for(b+=a();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?b+=p(r[t]):b+=a();t<r.length&&(b+=a()),e.push(g("ATTRIBUTE_SELECTOR",b,d));continue}}if(m==="["){a(),e.push(g("LBRACKET","[",d));continue}if(m==="]"){a(),e.push(g("RBRACKET","]",d));continue}if(/\d/.test(m)){let h=l(G=>/[\d.]/.test(G)),b=t,L=l(G=>/[a-zA-Z]/.test(G));At.has(L)?e.push(g("TIME_EXPRESSION",h+L,d)):(t=b,e.push(g("NUMBER",h,d)));continue}if(m==="("){a(),e.push(g("LPAREN","(",d));continue}if(m===")"){a(),e.push(g("RPAREN",")",d));continue}if(m==="{"){a(),e.push(g("LBRACE","{",d));continue}if(m==="}"){a(),e.push(g("RBRACE","}",d));continue}if(m===","){a(),e.push(g("COMMA",",",d));continue}if(m===":"){a(),e.push(g("COLON",":",d));continue}if(m==="."){a(),e.push(g("DOT",".",d));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){a(),e.push(g("OPERATOR",m,d));continue}if(m==="="||m==="!"||m==="<"||m===">"){let h=a();s()==="="&&(h+=a()),e.push(g("COMPARISON",h,d));continue}if(/[a-zA-Z_$]/.test(m)){let h=l(L=>/[\w$]/.test(L)),b=h.toLowerCase();Rt.has(b)?e.push(g("CONTEXT_VAR",h,d)):Lt.has(b)?e.push(g("LOGICAL",h,d)):Mt.has(b)?e.push(g("BOOLEAN",h,d)):e.push(g("IDENTIFIER",h,d));continue}a()}return e.push(g("EOF","",t)),e}var ge=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Je(e),this.current=0,this.isAtEnd()?{success:!1,error:"Empty expression"}:{success:!0,node:this.parseExpression(),consumed:this.current}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Parse error"}}}peek(){return this.tokens[this.current]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,n=this.parseAnd();e=this.createBinaryExpression(t,e,n)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,n=this.parseEquality();e=this.createBinaryExpression(t,e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.match("COMPARISON")||this.checkValue("is")||this.checkValue("matches")||this.checkValue("contains")||this.checkValue("in");){let t=this.previous().value,n=this.parseComparison();e=this.createBinaryExpression(t,e,n)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,n=this.parseAddition();e=this.createBinaryExpression(t,e,n)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,n=this.parseMultiplication();e=this.createBinaryExpression(t,e,n)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,n=this.parseUnary();e=this.createBinaryExpression(t,e,n)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else break;return e}parsePrimary(){let e=this.peek();if(this.match("NUMBER"))return this.createLiteral(parseFloat(e.value),"number",e);if(this.match("STRING")){let t=e.value.slice(1,-1);return this.createLiteral(t,"string",e)}if(this.match("BOOLEAN")){let t=e.value==="true"?!0:e.value==="false"?!1:e.value==="null"?null:void 0;return this.createLiteral(t,e.value,e)}if(this.match("TEMPLATE_LITERAL"))return{type:"templateLiteral",value:e.value,start:e.start,end:e.end,line:e.line,column:e.column};if(this.match("TIME_EXPRESSION"))return this.parseTimeExpression(e);if(this.match("ID_SELECTOR"))return this.createSelector(e.value,"id",e);if(this.match("CLASS_SELECTOR"))return this.createSelector(e.value,"class",e);if(this.match("ATTRIBUTE_SELECTOR"))return this.createSelector(e.value,"attribute",e);if(this.match("QUERY_SELECTOR")){let t=e.value.slice(1,-2);return this.createSelector(t,"query",e)}if(this.match("CONTEXT_VAR"))return this.createContextReference(e.value,e);if(this.match("IDENTIFIER"))return this.createIdentifier(e.value,e);if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let n;if(this.check("STRING"))n=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))n=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let i=this.parseExpression();e.push({key:n,value:i})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(n=>({type:"objectProperty",key:n.key,value:n.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let n=parseFloat(t[1]),i=t[2].toLowerCase();return{type:"timeExpression",value:n,unit:i,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,n){return{type:"literal",value:e,dataType:t,raw:n.value,start:n.start,end:n.end,line:n.line,column:n.column}}createSelector(e,t,n){return{type:"selector",value:e,selector:e,selectorType:t,start:n.start,end:n.end,line:n.line,column:n.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.name??"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,n){return{type:"binaryExpression",operator:e,left:t,right:n,start:t.start,end:n.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function Le(r){return new ge().parse(r)}function k(r,e){switch(r.type){case"literal":return zt(r);case"selector":return Vt(r,e);case"reference":return Ot(r);case"property-path":return It(r,e);case"expression":return _t(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function zt(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function Vt(r,e){return e&&r.value.startsWith("*")&&/^[a-zA-Z-]/.test(r.value.slice(1))&&e.push(`Converted '${r.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:r.value,selector:r.value,selectorType:r.selectorKind}}function Ot(r){return{type:"contextReference",contextType:r.value,name:r.value}}function It(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function _t(r){let e=Le(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function et(r,e){return r.roles.get(e)}function u(r,e,t){let n=et(r,e);return n?k(n,t):void 0}function f(r,e=[],t,n={}){let i={type:"command",name:r,args:e};return t&&Object.keys(t).length>0&&(i.modifiers=t),n.isBlocking&&(i.isBlocking=n.isBlocking),n.implicitTarget&&(i.implicitTarget=n.implicitTarget),i}var Bt={action:"toggle",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=u(r,"duration"),o=t?[t]:[],s={};return n&&(s.on=n),i&&(s.for=i),f("toggle",o,s)}},jt={action:"add",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("add",i,o)}},Kt={action:"remove",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("remove",i,o)}},Wt={action:"set",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("set",i,o)}},$t={action:"show",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=u(r,"duration"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.with=i),f("show",o,s)}},Ut={action:"hide",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=u(r,"duration"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.with=i),f("hide",o,s)}},Ft={action:"increment",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=u(r,"quantity"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.by=i),f("increment",o,s)}},Dt={action:"decrement",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=u(r,"quantity"),o=[],s={},a=t??n;return a&&o.push(a),i&&(s.by=i),f("decrement",o,s)}},qt={action:"wait",toAST(r,e){let t=u(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Ht={action:"log",toAST(r,e){let t=u(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},Gt={action:"put",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=et(r,"method"),o=t?[t]:[],s={};if(n){let a=i?.type==="literal"?String(i.value):"into";s[a]=n}return f("put",o,s)}},Xt={action:"fetch",toAST(r,e){let t=u(r,"source"),n=u(r,"method"),i=u(r,"responseType"),o=u(r,"patient"),s=t?[t]:[],a={};return n&&(a.with=n),i&&(a.as=i),o&&(a.body=o),f("fetch",s,a,{isBlocking:!0})}},Zt={action:"append",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("append",i,o)}},Qt={action:"prepend",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=t?[t]:[],o={};return n&&(o.to=n),f("prepend",i,o)}},Yt={action:"trigger",toAST(r,e){let t=u(r,"event"),n=u(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("trigger",i,o)}},Jt={action:"send",toAST(r,e){let t=u(r,"event"),n=u(r,"destination"),i=u(r,"patient"),o=t?[t]:[],s={};return n&&(s.to=n),i&&(s.detail=i),f("send",o,s)}},en={action:"go",toAST(r,e){let t=u(r,"source"),n=u(r,"destination"),i=[],o={};return t&&i.push(t),n&&(o.to=n),f("go",i,o)}},tn={action:"transition",toAST(r,e){let t=u(r,"patient"),n=u(r,"goal"),i=u(r,"duration"),o=u(r,"destination"),s=t?[t]:[],a={};return n&&(a.to=n),i&&(a.over=i),o&&(a.on=o),f("transition",s,a)}},nn={action:"focus",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=[],o={},s=t??n;return s&&i.push(s),f("focus",i,o)}},rn={action:"blur",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("blur",i)}},on={action:"get",toAST(r,e){let t=u(r,"source"),n=u(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("get",i)}},an={action:"take",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("take",i,o)}},sn={action:"call",toAST(r,e){let t=u(r,"patient");return f("call",t?[t]:[])}},cn={action:"return",toAST(r,e){let t=u(r,"patient");return f("return",t?[t]:[])}},ln={action:"halt",toAST(r,e){return f("halt",[])}},un={action:"throw",toAST(r,e){let t=u(r,"patient");return f("throw",t?[t]:[])}},dn={action:"settle",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("settle",i,void 0,{isBlocking:!0})}},pn={action:"swap",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),i=u(r,"destination"),o=u(r,"style"),s=[],a={};return t&&s.push(t),n&&s.push(n),i&&(a.on=i),o&&(a.with=o),f("swap",s,a)}},mn={action:"morph",toAST(r,e){let t=u(r,"source"),n=u(r,"destination"),i=u(r,"patient"),o=[],s={},a=t??i;return a&&o.push(a),n&&(s.on=n),f("morph",o,s)}},fn={action:"clone",toAST(r,e){let t=u(r,"source"),n=u(r,"destination"),i=u(r,"patient"),o=[],s={},a=t??i;return a&&o.push(a),n&&(s.into=n),f("clone",o,s)}},gn={action:"make",toAST(r,e){let t=u(r,"patient");return f("make",t?[t]:[])}},hn={action:"measure",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=u(r,"source"),o=[],s={};t&&o.push(t);let a=n??i;return a&&(s.of=a),f("measure",o,s)}},yn={action:"tell",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("tell",i)}},xn={action:"js",toAST(r,e){let t=u(r,"patient");return f("js",t?[t]:[])}},Sn={action:"async",toAST(r,e){return f("async",[])}},vn={action:"if",toAST(r,e){let t=u(r,"condition");return f("if",t?[t]:[])}},Tn={action:"unless",toAST(r,e){let t=u(r,"condition");return f("unless",t?[t]:[])}},bn={action:"repeat",toAST(r,e){let t=u(r,"quantity"),n=u(r,"patient"),i=[],o=t??n;return o&&i.push(o),f("repeat",i)}},En={action:"for",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),i=t?[t]:[],o={};return n&&(o.in=n),f("for",i,o)}},kn={action:"while",toAST(r,e){let t=u(r,"condition");return f("while",t?[t]:[])}},Nn={action:"continue",toAST(r,e){return f("continue",[])}},Pn={action:"default",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),i=t?[t]:[],o={};return n&&(o.to=n),f("default",i,o)}},wn={action:"init",toAST(r,e){return f("init",[])}},Cn={action:"behavior",toAST(r,e){let t=u(r,"patient");return f("behavior",t?[t]:[])}},Rn={action:"install",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=t?[t]:[],o={};return n&&(o.on=n),f("install",i,o)}},Ln={action:"on",toAST(r,e){let t=u(r,"event"),n=u(r,"source"),i=t?[t]:[],o={};return n&&(o.from=n),f("on",i,o)}},tt=new Map([["toggle",Bt],["add",jt],["remove",Kt],["set",Wt],["show",$t],["hide",Ut],["increment",Ft],["decrement",Dt],["wait",qt],["log",Ht],["put",Gt],["fetch",Xt],["append",Zt],["prepend",Qt],["get",on],["take",an],["trigger",Yt],["send",Jt],["on",Ln],["go",en],["transition",tn],["focus",nn],["blur",rn],["call",sn],["return",cn],["halt",ln],["throw",un],["settle",dn],["swap",pn],["morph",mn],["clone",fn],["measure",hn],["make",gn],["tell",yn],["default",Pn],["js",xn],["async",Sn],["if",vn],["unless",Tn],["repeat",bn],["for",En],["while",kn],["continue",Nn],["init",wn],["behavior",Cn],["install",Rn]]);function te(r){return tt.get(r)}function Me(r){tt.set(r.action,r)}var ne=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=te(e.action);if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let i=n;return this.warnings.push(...i.warnings),i.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let a of i){let c=e.roles.get(a);c&&t.push(k(c))}for(let a of o){let c=e.roles.get(a);if(c){let l=this.roleToModifierKey(a);n[l]=k(c)}}let s={type:"command",name:e.action,args:t};return Object.keys(n).length>0?{...s,modifiers:n}:s}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),n,i;if(t?.type==="literal"){let h=String(t.value);h.includes("|")||h.includes(" or ")?(i=h.split(/\s+or\s+|\|/).map(b=>b.trim()),n=i[0]):n=h}else t?.type==="reference"?n=t.value:n="click";let o=e.body.map(h=>this.build(h)),s=e.roles.get("source"),a,c;s?.type==="selector"?(a=s.value,c=s.value):s?.type==="reference"?c=s.value:s?.type==="literal"&&(c=String(s.value));let l=e.roles.get("condition"),p=l?k(l):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,g=e.eventModifiers,d=a;if(g?.from){let h=g.from;h.type==="selector"&&!a&&(d=h.value)}let m=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:n,commands:o,...i&&i.length>1?{events:i}:{},...d?{selector:d}:{},...c?{target:c}:{},...p?{condition:p}:{},...y?{watchTarget:y}:{},...m&&m.length>0?{args:m,params:m}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let n=k(t),i=e.thenBranch.map(a=>this.build(a)),o=e.elseBranch?.map(a=>this.build(a)),s=[n,{type:"block",commands:i}];return o&&o.length>0&&s.push({type:"block",commands:o}),{type:"command",name:"if",args:s}}buildCompound(e){let t=e.statements.map(i=>this.build(i));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(i=>this.build(i)),n=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let i=e.roles.get("quantity");i&&n.push(k(i));break}case"for":{e.loopVariable&&n.push({type:"string",value:e.loopVariable});let i=e.roles.get("source");i&&n.push(k(i));break}case"while":case"until":{let i=e.roles.get("condition");i&&n.push(k(i));break}case"forever":break}return n.push({type:"block",commands:t}),{type:"command",name:"repeat",args:n}}buildBlock(e){return{type:"block",commands:e.map(n=>this.build(n))}}};function nt(r){let e=new ne;return{ast:e.build(r),warnings:e.warnings}}var U=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),i=this.cache.get(n);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),i.lastAccessed=Date.now(),this.cache.set(n,i),this.stats.hits++,i.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:n,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),i=this.cache.get(n);return i?this.isExpired(i)?(this.cache.delete(n),this.stats.expirations++,!1):!0:!1}delete(e,t){let n=this.makeKey(e,t);return this.cache.delete(n)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Ae=new U;var re=class{constructor(e={}){this.patternMatcher=new Y,this.languages=new Set(ie()),e.cache===!1?this.cache=new U({enabled:!1}):this.cache=e.cache?new U(e.cache):Ae}analyze(e,t){if(!this.supportsLanguage(t))return{confidence:0,errors:[`Language '${t}' is not supported for semantic parsing`]};let n=this.cache.get(e,t);if(n)return n;let i=this.analyzeUncached(e,t);return this.cache.set(e,t,i),i}analyzeUncached(e,t){try{let n=Ze(t);if(!n)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let i=n.tokenize(e),o=N(t);if(o.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let s=this.patternMatcher.matchBest(i,o);if(!s)return{confidence:0,errors:["No pattern matched the input"]};let a=this.buildSemanticNode(s);return{confidence:s.confidence,command:{name:s.pattern.command,roles:s.captured},node:a,tokensConsumed:s.consumedTokens}}catch(n){return{confidence:0,errors:[n instanceof Error?n.message:String(n)]}}}supportsLanguage(e){return this.languages.has(e)}supportedLanguages(){return Array.from(this.languages)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}configureCache(e){this.cache.configure(e)}buildSemanticNode(e){return{kind:"command",action:e.pattern.command,roles:e.captured,metadata:{patternId:e.pattern.id}}}};function rt(r){return new re(r)}var ze=.5,it=.8;function ot(r,e=ze){return r.confidence>=e&&r.command!==void 0}var Mn="1.0.0-ar",An=["ar"];function zn(){return[...An]}function at(r){if(r!=="ar")throw new Error(`Language not supported in this bundle: ${r}. Supported: ar`)}function Vn(r,e){return at(e),[...de(r,e).tokens]}function st(r){return at(r),N(r)}function On(r,e){return st(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return mt(In);})();
|