@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.
Files changed (162) hide show
  1. package/dist/browser-ar.ar.global.js +2 -2
  2. package/dist/browser-core.core.global.js +2 -2
  3. package/dist/browser-de.de.global.js +2 -2
  4. package/dist/browser-east-asian.east-asian.global.js +2 -2
  5. package/dist/browser-en-tr.en-tr.global.js +2 -2
  6. package/dist/browser-en.en.global.js +2 -2
  7. package/dist/browser-es-en.es-en.global.js +2 -2
  8. package/dist/browser-es.es.global.js +2 -2
  9. package/dist/browser-fr.fr.global.js +2 -2
  10. package/dist/browser-id.id.global.js +2 -2
  11. package/dist/browser-ja.ja.global.js +2 -2
  12. package/dist/browser-ko.ko.global.js +2 -2
  13. package/dist/browser-lazy.lazy.global.js +2 -2
  14. package/dist/browser-priority.priority.global.js +2 -2
  15. package/dist/browser-pt.pt.global.js +2 -2
  16. package/dist/browser-qu.qu.global.js +2 -2
  17. package/dist/browser-sw.sw.global.js +2 -2
  18. package/dist/browser-tr.tr.global.js +2 -2
  19. package/dist/browser-western.western.global.js +2 -2
  20. package/dist/browser-zh.zh.global.js +2 -2
  21. package/dist/browser.global.js +2 -2
  22. package/dist/browser.global.js.map +1 -1
  23. package/dist/index.cjs +13042 -17462
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +49 -5
  26. package/dist/index.d.ts +49 -5
  27. package/dist/index.js +14044 -18464
  28. package/dist/index.js.map +1 -1
  29. package/dist/languages/ar.d.ts +1 -1
  30. package/dist/languages/ar.js +31 -44
  31. package/dist/languages/ar.js.map +1 -1
  32. package/dist/languages/de.d.ts +1 -1
  33. package/dist/languages/de.js +14 -2
  34. package/dist/languages/de.js.map +1 -1
  35. package/dist/languages/en.d.ts +1 -1
  36. package/dist/languages/en.js +558 -12
  37. package/dist/languages/en.js.map +1 -1
  38. package/dist/languages/es.d.ts +1 -1
  39. package/dist/languages/es.js +16 -0
  40. package/dist/languages/es.js.map +1 -1
  41. package/dist/languages/fr.d.ts +1 -1
  42. package/dist/languages/fr.js +14 -2
  43. package/dist/languages/fr.js.map +1 -1
  44. package/dist/languages/id.d.ts +1 -1
  45. package/dist/languages/id.js +14 -2
  46. package/dist/languages/id.js.map +1 -1
  47. package/dist/languages/ja.d.ts +1 -1
  48. package/dist/languages/ja.js +18 -3
  49. package/dist/languages/ja.js.map +1 -1
  50. package/dist/languages/ko.d.ts +8 -1
  51. package/dist/languages/ko.js +75 -43
  52. package/dist/languages/ko.js.map +1 -1
  53. package/dist/languages/pt.d.ts +1 -1
  54. package/dist/languages/pt.js +17 -0
  55. package/dist/languages/pt.js.map +1 -1
  56. package/dist/languages/qu.d.ts +12 -1
  57. package/dist/languages/qu.js +77 -2
  58. package/dist/languages/qu.js.map +1 -1
  59. package/dist/languages/sw.d.ts +1 -1
  60. package/dist/languages/sw.js.map +1 -1
  61. package/dist/languages/tr.d.ts +9 -1
  62. package/dist/languages/tr.js +96 -72
  63. package/dist/languages/tr.js.map +1 -1
  64. package/dist/languages/zh.d.ts +1 -1
  65. package/dist/languages/zh.js +16 -0
  66. package/dist/languages/zh.js.map +1 -1
  67. package/dist/{types-C4dcj53L.d.ts → types-BY3Id07j.d.ts} +20 -5
  68. package/package.json +20 -29
  69. package/src/generators/command-schemas.ts +21 -10
  70. package/src/generators/event-handler-generator.ts +50 -44
  71. package/src/generators/language-profiles.ts +6 -0
  72. package/src/generators/pattern-generator.ts +883 -1
  73. package/src/generators/profiles/arabic.ts +19 -3
  74. package/src/generators/profiles/bengali.ts +12 -1
  75. package/src/generators/profiles/chinese.ts +15 -0
  76. package/src/generators/profiles/french.ts +12 -1
  77. package/src/generators/profiles/german.ts +12 -1
  78. package/src/generators/profiles/hebrew.ts +148 -0
  79. package/src/generators/profiles/hindi.ts +12 -1
  80. package/src/generators/profiles/index.ts +2 -0
  81. package/src/generators/profiles/indonesian.ts +12 -1
  82. package/src/generators/profiles/italian.ts +16 -0
  83. package/src/generators/profiles/japanese.ts +11 -2
  84. package/src/generators/profiles/korean.ts +15 -1
  85. package/src/generators/profiles/polish.ts +12 -0
  86. package/src/generators/profiles/portuguese.ts +16 -0
  87. package/src/generators/profiles/russian.ts +11 -0
  88. package/src/generators/profiles/spanish.ts +15 -0
  89. package/src/generators/profiles/spanishMexico.ts +176 -0
  90. package/src/generators/profiles/thai.ts +11 -0
  91. package/src/generators/profiles/turkish.ts +49 -7
  92. package/src/generators/profiles/types.ts +21 -5
  93. package/src/generators/profiles/ukrainian.ts +11 -0
  94. package/src/generators/profiles/vietnamese.ts +11 -0
  95. package/src/language-building-schema.ts +111 -0
  96. package/src/languages/_all.ts +5 -1
  97. package/src/languages/es-MX.ts +32 -0
  98. package/src/languages/he.ts +15 -0
  99. package/src/parser/pattern-matcher.ts +10 -1
  100. package/src/parser/semantic-parser.ts +3 -0
  101. package/src/patterns/add/ar.ts +3 -59
  102. package/src/patterns/add/index.ts +5 -1
  103. package/src/patterns/add/ja.ts +3 -81
  104. package/src/patterns/add/ko.ts +3 -62
  105. package/src/patterns/add/qu.ts +69 -0
  106. package/src/patterns/add/tr.ts +3 -59
  107. package/src/patterns/builders.ts +1 -0
  108. package/src/patterns/decrement/tr.ts +3 -36
  109. package/src/patterns/event-handler/ar.ts +3 -139
  110. package/src/patterns/event-handler/he.ts +15 -0
  111. package/src/patterns/event-handler/index.ts +5 -1
  112. package/src/patterns/event-handler/ja.ts +3 -106
  113. package/src/patterns/event-handler/ko.ts +3 -121
  114. package/src/patterns/event-handler/ms.ts +45 -20
  115. package/src/patterns/event-handler/tr.ts +3 -158
  116. package/src/patterns/get/ar.ts +3 -37
  117. package/src/patterns/get/ja.ts +3 -41
  118. package/src/patterns/get/ko.ts +3 -41
  119. package/src/patterns/grammar-transformed/ja.ts +3 -1701
  120. package/src/patterns/grammar-transformed/ko.ts +3 -1299
  121. package/src/patterns/grammar-transformed/tr.ts +3 -1055
  122. package/src/patterns/hide/ar.ts +3 -55
  123. package/src/patterns/hide/ja.ts +3 -57
  124. package/src/patterns/hide/ko.ts +3 -57
  125. package/src/patterns/hide/tr.ts +3 -53
  126. package/src/patterns/increment/tr.ts +3 -40
  127. package/src/patterns/put/ar.ts +3 -62
  128. package/src/patterns/put/ja.ts +3 -63
  129. package/src/patterns/put/ko.ts +3 -55
  130. package/src/patterns/put/tr.ts +3 -55
  131. package/src/patterns/remove/ar.ts +3 -59
  132. package/src/patterns/remove/index.ts +5 -1
  133. package/src/patterns/remove/ja.ts +3 -62
  134. package/src/patterns/remove/ko.ts +3 -66
  135. package/src/patterns/remove/qu.ts +69 -0
  136. package/src/patterns/remove/tr.ts +3 -66
  137. package/src/patterns/set/ar.ts +3 -72
  138. package/src/patterns/set/ja.ts +3 -74
  139. package/src/patterns/set/ko.ts +3 -73
  140. package/src/patterns/set/tr.ts +3 -95
  141. package/src/patterns/show/ar.ts +3 -55
  142. package/src/patterns/show/ja.ts +3 -57
  143. package/src/patterns/show/ko.ts +3 -61
  144. package/src/patterns/show/tr.ts +3 -53
  145. package/src/patterns/take/ar.ts +3 -39
  146. package/src/patterns/toggle/ar.ts +3 -49
  147. package/src/patterns/toggle/index.ts +5 -1
  148. package/src/patterns/toggle/ja.ts +3 -144
  149. package/src/patterns/toggle/ko.ts +3 -101
  150. package/src/patterns/toggle/qu.ts +90 -0
  151. package/src/patterns/toggle/tr.ts +3 -76
  152. package/src/registry.ts +179 -15
  153. package/src/tokenizers/arabic.ts +13 -46
  154. package/src/tokenizers/bengali.ts +2 -16
  155. package/src/tokenizers/he.ts +542 -0
  156. package/src/tokenizers/index.ts +1 -0
  157. package/src/tokenizers/japanese.ts +3 -1
  158. package/src/tokenizers/korean.ts +104 -48
  159. package/src/tokenizers/ms.ts +3 -0
  160. package/src/tokenizers/quechua.ts +101 -2
  161. package/src/tokenizers/turkish.ts +64 -69
  162. package/src/types.ts +13 -0
@@ -1,2 +1,2 @@
1
- "use strict";var LokaScriptSemanticJa=(()=>{var fe=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var ct=(r,e)=>{for(var t in e)fe(r,t,{get:e[t],enumerable:!0})},lt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of at(e))!st.call(r,o)&&o!==t&&fe(r,o,{get:()=>e[o],enumerable:!(n=it(e,o))||n.enumerable});return r};var ut=r=>lt(fe({},"__esModule",{value:!0}),r);var Vn={};ct(Vn,{ASTBuilder:()=>Z,DEFAULT_CONFIDENCE_THRESHOLD:()=>Pe,HIGH_CONFIDENCE_THRESHOLD:()=>tt,SemanticAnalyzerImpl:()=>Q,VERSION:()=>Pn,buildAST:()=>Ye,canParse:()=>Ee,createCommandNode:()=>M,createEventHandler:()=>K,createLiteral:()=>T,createPropertyPath:()=>B,createReference:()=>w,createSelector:()=>L,createSemanticAnalyzer:()=>et,fromExplicit:()=>ke,getCommandMapper:()=>X,getPatternsForLanguage:()=>ot,getPatternsForLanguageAndCommand:()=>zn,getProfile:()=>he,getSupportedLanguages:()=>Mn,getTokenizer:()=>ge,isExplicitSyntax:()=>W,isLanguageSupported:()=>ze,japaneseProfile:()=>V,japaneseTokenizer:()=>se,parse:()=>$,parseAny:()=>Ne,parseExplicit:()=>j,registerCommandMapper:()=>we,render:()=>H,renderExplicit:()=>G,shouldUseSemanticResult:()=>nt,toExplicit:()=>be,tokenize:()=>An,tryGetProfile:()=>P});var _=new Map,ee=new Map,Y=new Map;var Le=null;function Me(r,e,t){_.set(r,e),ee.set(r,t),Y.delete(r)}var dt=new Map;function ge(r){let e=_.get(r);if(!e){let t=Array.from(_.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function he(r){let e=ee.get(r);if(!e){let t=Array.from(ee.keys()).join(", ");throw new Error(`Language profile '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function Ae(r){return _.get(r)}function P(r){return ee.get(r)}function te(){return Array.from(_.keys())}function ze(r){return _.has(r)}function Ve(r,e){return ge(e).tokenize(r)}function N(r){let e=Y.get(r);if(e)return e;let t=dt.get(r);if(t)return Y.set(r,t),t;if(!Le)throw new Error(`No patterns registered for language '${r}'. Either import the language module or set a pattern generator.`);let n=he(r),o=Le(n);return Y.set(r,o),o}function Oe(r,e){return N(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}var A=class{constructor(e,t){this.pos=0;this.tokens=e,this.language=t}peek(e=0){let t=this.pos+e;return t<0||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw new Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){let t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function S(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:o,stem:i,stemConfidence:s}=n,a={value:r,kind:e,position:t};return o!==void 0&&(a.normalized=o),i!==void 0&&(a.stem=i,s!==void 0&&(a.stemConfidence=s)),a}return{value:r,kind:e,position:t}}function z(r){return/\s/.test(r)}function re(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function oe(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function C(r){return/\d/.test(r)}function je(r){return/[a-zA-Z]/.test(r)}function b(r){return/[a-zA-Z0-9_-]/.test(r)}function F(r){return e=>{let t=e.charCodeAt(0);return r.some(([n,o])=>t>=n&&t<=o)}}function ye(...r){return e=>r.some(t=>t(e))}function Ie(r,e){if(e>=r.length)return null;let t=r[e];if(!re(t))return null;let n=e,o="";if(t==="#"||t==="."){for(o+=r[n++];n<r.length&&b(r[n]);)o+=r[n++];if(o.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 o}}else if(t==="["){let i=1,s=!1,a=null,l=!1;for(o+=r[n++];n<r.length&&i>0;){let c=r[n];o+=c,l?l=!1:c==="\\"?l=!0:s?c===a&&(s=!1,a=null):c==='"'||c==="'"||c==="`"?(s=!0,a=c):c==="["?i++:c==="]"&&i--,n++}if(i!==0)return null}else if(t==="@"){for(o+=r[n++];n<r.length&&b(r[n]);)o+=r[n++];if(o.length<=1)return null}else if(t==="*"){for(o+=r[n++];n<r.length&&b(r[n]);)o+=r[n++];if(o.length<=1)return null}else if(t==="<"){if(o+=r[n++],n>=r.length||!je(r[n]))return null;for(;n<r.length&&b(r[n]);)o+=r[n++];for(;n<r.length;){let i=r[n];if(i==="."){if(o+=r[n++],n>=r.length||!b(r[n]))return null;for(;n<r.length&&b(r[n]);)o+=r[n++]}else if(i==="#"){if(o+=r[n++],n>=r.length||!b(r[n]))return null;for(;n<r.length&&b(r[n]);)o+=r[n++]}else if(i==="["){let s=1,a=!1,l=null,c=!1;for(o+=r[n++];n<r.length&&s>0;){let p=r[n];o+=p,c?c=!1:p==="\\"?c=!0:a?p===l&&(a=!1,l=null):p==='"'||p==="'"||p==="`"?(a=!0,l=p):p==="["?s++:p==="]"&&s--,n++}if(s!==0)return null}else break}for(;n<r.length&&z(r[n]);)o+=r[n++];if(n<r.length&&r[n]==="/")for(o+=r[n++];n<r.length&&z(r[n]);)o+=r[n++];if(n>=r.length||r[n]!==">")return null;o+=r[n++]}return o||null}function pt(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 _e(r,e){if(e>=r.length)return null;let t=r[e];if(!oe(t)||t==="'"&&pt(r,e))return null;let o={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!o)return null;let i=e+1,s=t,a=!1;for(;i<r.length;){let l=r[i];if(s+=l,a)a=!1;else if(l==="\\")a=!0;else if(l===o)return s;i++}return s}function ie(r,e){if(e>=r.length)return!1;let t=r[e],n=r[e+1]||"",o=r[e+2]||"";if(t==="/"&&n!=="/"&&/[a-zA-Z0-9._-]/.test(n)||t==="/"&&n==="/"&&/[a-zA-Z]/.test(o)||t==="."&&(n==="/"||n==="."&&o==="/"))return!0;let i=r.slice(e,e+8).toLowerCase();return!!(i.startsWith("http://")||i.startsWith("https://"))}function Be(r,e){if(!ie(r,e))return null;let t=e,n="",o=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<r.length;){let i=r[t];if(i==="#"){if(n.length>0&&/[a-zA-Z0-9/.]$/.test(n))for(n+=i,t++;t<r.length&&/[a-zA-Z0-9_-]/.test(r[t]);)n+=r[t++];break}if(o.test(i))n+=i,t++;else break}return n.length<2?null:n}function Ke(r,e){if(e>=r.length)return null;let t=r[e];if(!C(t)&&t!=="-"&&t!=="+")return null;let n=e,o="";if((r[n]==="-"||r[n]==="+")&&(o+=r[n++]),n>=r.length||!C(r[n]))return null;for(;n<r.length&&C(r[n]);)o+=r[n++];if(n<r.length&&r[n]===".")for(o+=r[n++];n<r.length&&C(r[n]);)o+=r[n++];return n<r.length&&(r.slice(n,n+2)==="ms"?o+="ms":(r[n]==="s"||r[n]==="m"||r[n]==="h")&&(o+=r[n])),o}var ne=class ne{constructor(){this.profileKeywords=[];this.profileKeywordMap=new Map}initializeKeywordsFromProfile(e,t=[]){let n=new Map;if(e.keywords){for(let[o,i]of Object.entries(e.keywords))if(n.set(i.primary,{native:i.primary,normalized:i.normalized||o}),i.alternatives)for(let s of i.alternatives)n.set(s,{native:s,normalized:i.normalized||o})}if(e.references)for(let[o,i]of Object.entries(e.references))n.set(i,{native:i,normalized:o});if(e.roleMarkers){for(let[o,i]of Object.entries(e.roleMarkers))if(i.primary&&n.set(i.primary,{native:i.primary,normalized:o}),i.alternatives)for(let s of i.alternatives)n.set(s,{native:s,normalized:o})}for(let o of t)n.set(o.native,o);this.profileKeywords=Array.from(n.values()).sort((o,i)=>i.native.length-o.native.length),this.profileKeywordMap=new Map;for(let o of this.profileKeywords){this.profileKeywordMap.set(o.native.toLowerCase(),o);let i=this.removeDiacritics(o.native);i!==o.native&&!this.profileKeywordMap.has(i.toLowerCase())&&this.profileKeywordMap.set(i.toLowerCase(),o)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let 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(o=>n.startsWith(o.native))}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,n){let o=this.tryNormalize(e);if(!o)return null;let i=this.lookupKeyword(o.stem);if(!i)return null;let s={normalized:i.normalized,stem:o.stem,stemConfidence:o.confidence};return v(e,"keyword",S(t,n),s)}trySelector(e,t){let n=Ie(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 o=n[0].replace(/(\s|\.)$/,""),i=o.slice(1).split("(")[0],s=n[1];return{...v(o,"event-modifier",S(t,t+o.length)),metadata:{modifierName:i,value:s?i==="queue"?s:parseInt(s,10):void 0}}}tryString(e,t){let n=_e(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryNumber(e,t){let n=Ke(e,t);return n?v(n,"literal",S(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,o=!1){let i=t;if(o)for(;i<e.length&&z(e[i]);)i++;let s=e.slice(i);for(let a of n){let l=s.slice(0,a.length);if(a.caseInsensitive?l.toLowerCase()===a.pattern.toLowerCase():l===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:i+a.length}}}return null}parseBaseNumber(e,t,n=!0){let o=t,i="";if(n&&(e[o]==="-"||e[o]==="+")&&(i+=e[o++]),o>=e.length||!C(e[o]))return null;for(;o<e.length&&C(e[o]);)i+=e[o++];if(o<e.length&&e[o]===".")for(i+=e[o++];o<e.length&&C(e[o]);)i+=e[o++];return!i||i==="-"||i==="+"?null:{number:i,endPos:o}}tryNumberWithTimeUnits(e,t,n,o={}){let{allowSign:i=!0,skipWhitespace:s=!1}=o,a=this.parseBaseNumber(e,t,i);if(!a)return null;let{number:l,endPos:c}=a,p=[...n,...ne.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,c,p,s);return x&&(l+=x.suffix,c=x.endPos),v(l,"literal",S(t,c))}tryUrl(e,t){let n=Be(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 o=e.slice(t,n);return v(o,"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 o=e[t];return["<",">","!","+","-","*","/","="].includes(o)?v(o,"operator",S(t,t+1)):["(",")","{","}",",",";",":"].includes(o)?v(o,"punctuation",S(t,t+1)):null}tryMultiCharParticle(e,t,n){for(let o of n)if(e.slice(t,t+o.length)===o)return v(o,"particle",S(t,t+o.length));return null}};ne.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var U=ne;function We(r){return{stem:r,confidence:1}}function ae(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}var mt=[{pattern:"\u3057\u305F\u3089",confidence:.88,conjugationType:"conditional-tara",minStemLength:2},{pattern:"\u3059\u308B\u3068",confidence:.88,conjugationType:"conditional-to",minStemLength:2},{pattern:"\u3059\u308C\u3070",confidence:.85,conjugationType:"conditional-ba",minStemLength:2},{pattern:"\u305F\u3089",confidence:.85,conjugationType:"conditional-tara",minStemLength:2},{pattern:"\u308C\u3070",confidence:.82,conjugationType:"conditional-ba",minStemLength:2},{pattern:"\u3066\u3044\u307E\u3057\u305F",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\u3066\u3044\u307E\u3059",confidence:.85,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u304F\u3060\u3055\u3044",confidence:.85,conjugationType:"request",minStemLength:2},{pattern:"\u3067\u304F\u3060\u3055\u3044",confidence:.85,conjugationType:"request",minStemLength:2},{pattern:"\u3066\u3044\u308B",confidence:.85,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u304A\u304F",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u307F\u308B",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u3042\u308B",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u304F\u308C",confidence:.8,conjugationType:"casual-request",minStemLength:2},{pattern:"\u3067\u304F\u308C",confidence:.8,conjugationType:"casual-request",minStemLength:2},{pattern:"\u3061\u3083\u3063\u305F",confidence:.82,conjugationType:"contracted-past",minStemLength:2},{pattern:"\u3058\u3083\u3063\u305F",confidence:.82,conjugationType:"contracted-past",minStemLength:2},{pattern:"\u3061\u3083\u3046",confidence:.82,conjugationType:"contracted",minStemLength:2},{pattern:"\u3058\u3083\u3046",confidence:.82,conjugationType:"contracted",minStemLength:2},{pattern:"\u307E\u3057\u305F",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"\u307E\u305B\u3093",confidence:.85,conjugationType:"negative",minStemLength:2},{pattern:"\u307E\u3059",confidence:.85,conjugationType:"polite",minStemLength:2},{pattern:"\u3066",confidence:.85,conjugationType:"te-form",minStemLength:2},{pattern:"\u305F",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"\u306A\u3044",confidence:.82,conjugationType:"negative",minStemLength:2},{pattern:"\u306A\u304B\u3063\u305F",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\u3089\u308C\u308B",confidence:.8,conjugationType:"potential",minStemLength:2},{pattern:"\u308C\u308B",confidence:.78,conjugationType:"potential",minStemLength:2},{pattern:"\u3089\u308C\u305F",confidence:.8,conjugationType:"passive",minStemLength:2},{pattern:"\u3055\u305B\u308B",confidence:.8,conjugationType:"causative",minStemLength:2},{pattern:"\u305B\u308B",confidence:.78,conjugationType:"causative",minStemLength:2},{pattern:"\u3088\u3046",confidence:.8,conjugationType:"volitional",minStemLength:2},{pattern:"\u308B",confidence:.75,conjugationType:"dictionary",minStemLength:3}],ft=[{pattern:"\u3057\u305F\u3089",confidence:.88,conjugationType:"conditional-tara"},{pattern:"\u3059\u308B\u3068",confidence:.88,conjugationType:"conditional-to"},{pattern:"\u3059\u308C\u3070",confidence:.85,conjugationType:"conditional-ba"},{pattern:"\u3057\u3066\u3044\u307E\u3059",confidence:.85,conjugationType:"progressive"},{pattern:"\u3057\u3066\u3044\u308B",confidence:.85,conjugationType:"progressive"},{pattern:"\u3057\u307E\u3057\u305F",confidence:.85,conjugationType:"past"},{pattern:"\u3057\u307E\u3059",confidence:.85,conjugationType:"polite"},{pattern:"\u3057\u306A\u3044",confidence:.82,conjugationType:"negative"},{pattern:"\u3057\u3066",confidence:.85,conjugationType:"te-form"},{pattern:"\u3057\u305F",confidence:.85,conjugationType:"past"},{pattern:"\u3059\u308B",confidence:.88,conjugationType:"dictionary"}];function $e(r){let e=r.charCodeAt(0);return e>=12352&&e<=12447}function gt(r){let e=r.charCodeAt(0);return e>=12448&&e<=12543}function ht(r){let e=r.charCodeAt(0);return e>=19968&&e<=40959||e>=13312&&e<=19903}function yt(r){for(let e of r)if($e(e)||gt(e)||ht(e))return!0;return!1}var q=class{constructor(){this.language="ja"}isNormalizable(e){if(!yt(e)||e.length<2)return!1;let t=e[e.length-1];return $e(t)}normalize(e){let t=this.normalizeCompound(e);if(t)return t;let n=this.trySuruNormalization(e);if(n)return n;for(let o of mt)if(e.endsWith(o.pattern)){let i=e.slice(0,-o.pattern.length),s=o.minStemLength??2;if(i.length<s)continue;let a={removedSuffixes:[o.pattern]};return o.conjugationType&&(a.conjugationType=o.conjugationType),ae(i,o.confidence,a)}return We(e)}trySuruNormalization(e){for(let t of ft)if(e.endsWith(t.pattern)){let n=e.slice(0,-t.pattern.length);if(n.length<1)continue;return ae(n,t.confidence,{removedSuffixes:[t.pattern],conjugationType:t.conjugationType,originalForm:"suru-verb"})}return null}normalizeCompound(e){let t=[{pattern:"\u3066\u3044\u306A\u304B\u3063\u305F",suffixes:["\u3066","\u3044","\u306A\u304B\u3063\u305F"],confidence:.8,minStemLength:2},{pattern:"\u3067\u3044\u306A\u304B\u3063\u305F",suffixes:["\u3067","\u3044","\u306A\u304B\u3063\u305F"],confidence:.8,minStemLength:2},{pattern:"\u3066\u3044\u306A\u3044",suffixes:["\u3066","\u3044","\u306A\u3044"],confidence:.82,minStemLength:2},{pattern:"\u3067\u3044\u306A\u3044",suffixes:["\u3067","\u3044","\u306A\u3044"],confidence:.82,minStemLength:2},{pattern:"\u3066\u3044\u305F",suffixes:["\u3066","\u3044","\u305F"],confidence:.85,minStemLength:2},{pattern:"\u3067\u3044\u305F",suffixes:["\u3067","\u3044","\u305F"],confidence:.85,minStemLength:2}];for(let{pattern:n,suffixes:o,confidence:i,minStemLength:s}of t)if(e.endsWith(n)){let a=e.slice(0,-n.length);if(a.length<s)continue;return ae(a,i,{removedSuffixes:o,conjugationType:"compound"})}return null}},Kn=new q;var V={code:"ja",name:"Japanese",nativeName:"\u65E5\u672C\u8A9E",direction:"ltr",wordOrder:"SOV",markingStrategy:"particle",usesSpaces:!1,defaultVerbForm:"base",verb:{position:"end",suffixes:["\u308B","\u3066","\u305F","\u307E\u3059","\u306A\u3044"],subjectDrop:!0},references:{me:"\u81EA\u5206",it:"\u305D\u308C",you:"\u3042\u306A\u305F",result:"\u7D50\u679C",event:"\u30A4\u30D9\u30F3\u30C8",target:"\u30BF\u30FC\u30B2\u30C3\u30C8",body:"\u30DC\u30C7\u30A3"},possessive:{marker:"\u306E",markerPosition:"between",keywords:{\u79C1\u306E:"me",\u3042\u306A\u305F\u306E:"you",\u305D\u306E:"it"}},roleMarkers:{patient:{primary:"\u3092",position:"after"},destination:{primary:"\u306B",alternatives:["\u3078","\u3067"],position:"after"},source:{primary:"\u304B\u3089",position:"after"},style:{primary:"\u3067",position:"after"},event:{primary:"\u3092",position:"after"}},keywords:{toggle:{primary:"\u5207\u308A\u66FF\u3048",alternatives:["\u5207\u308A\u66FF\u3048\u308B","\u30C8\u30B0\u30EB","\u30C8\u30B0\u30EB\u3059\u308B"],normalized:"toggle"},add:{primary:"\u8FFD\u52A0",alternatives:["\u8FFD\u52A0\u3059\u308B","\u52A0\u3048\u308B"],normalized:"add"},remove:{primary:"\u524A\u9664",alternatives:["\u524A\u9664\u3059\u308B","\u53D6\u308A\u9664\u304F"],normalized:"remove"},put:{primary:"\u7F6E\u304F",alternatives:["\u5165\u308C\u308B","\u30BB\u30C3\u30C8"],normalized:"put"},append:{primary:"\u672B\u5C3E\u8FFD\u52A0",alternatives:["\u672B\u5C3E\u306B\u8FFD\u52A0","\u30A2\u30DA\u30F3\u30C9"],normalized:"append"},prepend:{primary:"\u5148\u982D\u8FFD\u52A0",alternatives:["\u5148\u982D\u306B\u8FFD\u52A0","\u30D7\u30EA\u30DA\u30F3\u30C9"],normalized:"prepend"},take:{primary:"\u53D6\u308B",alternatives:["\u53D6\u5F97"],normalized:"take"},make:{primary:"\u4F5C\u308B",alternatives:["\u4F5C\u6210"],normalized:"make"},clone:{primary:"\u8907\u88FD",alternatives:["\u30AF\u30ED\u30FC\u30F3"],normalized:"clone"},swap:{primary:"\u4EA4\u63DB",alternatives:["\u30B9\u30EF\u30C3\u30D7","\u5165\u308C\u66FF\u3048"],normalized:"swap"},morph:{primary:"\u5909\u5F62",alternatives:["\u30E2\u30FC\u30D5","\u5909\u63DB"],normalized:"morph"},set:{primary:"\u8A2D\u5B9A",alternatives:["\u8A2D\u5B9A\u3059\u308B","\u30BB\u30C3\u30C8"],normalized:"set"},get:{primary:"\u53D6\u5F97",alternatives:["\u53D6\u5F97\u3059\u308B","\u30B2\u30C3\u30C8"],normalized:"get"},increment:{primary:"\u5897\u52A0",alternatives:["\u5897\u3084\u3059","\u30A4\u30F3\u30AF\u30EA\u30E1\u30F3\u30C8"],normalized:"increment"},decrement:{primary:"\u6E1B\u5C11",alternatives:["\u6E1B\u3089\u3059","\u30C7\u30AF\u30EA\u30E1\u30F3\u30C8"],normalized:"decrement"},log:{primary:"\u8A18\u9332",alternatives:["\u30ED\u30B0","\u51FA\u529B"],normalized:"log"},show:{primary:"\u8868\u793A",alternatives:["\u8868\u793A\u3059\u308B","\u898B\u305B\u308B"],normalized:"show"},hide:{primary:"\u96A0\u3059",alternatives:["\u975E\u8868\u793A","\u975E\u8868\u793A\u306B\u3059\u308B"],normalized:"hide"},transition:{primary:"\u9077\u79FB",alternatives:["\u30C8\u30E9\u30F3\u30B8\u30B7\u30E7\u30F3","\u30A2\u30CB\u30E1\u30FC\u30B7\u30E7\u30F3"],normalized:"transition"},on:{primary:"\u3067",alternatives:["\u6642","\u3068\u304D"],normalized:"on"},trigger:{primary:"\u5F15\u304D\u91D1",alternatives:["\u767A\u706B","\u30C8\u30EA\u30AC\u30FC"],normalized:"trigger"},send:{primary:"\u9001\u308B",alternatives:["\u9001\u4FE1"],normalized:"send"},focus:{primary:"\u30D5\u30A9\u30FC\u30AB\u30B9",alternatives:["\u96C6\u4E2D"],normalized:"focus"},blur:{primary:"\u307C\u304B\u3057",alternatives:["\u30D5\u30A9\u30FC\u30AB\u30B9\u89E3\u9664"],normalized:"blur"},go:{primary:"\u79FB\u52D5",alternatives:["\u884C\u304F","\u30CA\u30D3\u30B2\u30FC\u30C8"],normalized:"go"},wait:{primary:"\u5F85\u3064",alternatives:["\u5F85\u6A5F"],normalized:"wait"},fetch:{primary:"\u53D6\u5F97",alternatives:["\u30D5\u30A7\u30C3\u30C1"],normalized:"fetch"},settle:{primary:"\u5B89\u5B9A",alternatives:["\u843D\u3061\u7740\u304F"],normalized:"settle"},if:{primary:"\u3082\u3057",alternatives:["\u6761\u4EF6"],normalized:"if"},when:{primary:"\u3068\u304D",normalized:"when"},where:{primary:"\u3069\u3053",normalized:"where"},else:{primary:"\u305D\u3046\u3067\u306A\u3051\u308C\u3070",alternatives:["\u305D\u308C\u4EE5\u5916"],normalized:"else"},repeat:{primary:"\u7E70\u308A\u8FD4\u3057",alternatives:["\u7E70\u308A\u8FD4\u3059","\u30EA\u30D4\u30FC\u30C8"],normalized:"repeat"},for:{primary:"\u305F\u3081\u306B",alternatives:["\u5404"],normalized:"for"},while:{primary:"\u306E\u9593",alternatives:["\u9593"],normalized:"while"},continue:{primary:"\u7D9A\u3051\u308B",alternatives:["\u7D99\u7D9A"],normalized:"continue"},halt:{primary:"\u505C\u6B62",alternatives:["\u6B62\u3081\u308B","\u30CF\u30EB\u30C8"],normalized:"halt"},throw:{primary:"\u6295\u3052\u308B",alternatives:["\u30B9\u30ED\u30FC"],normalized:"throw"},call:{primary:"\u547C\u3073\u51FA\u3057",alternatives:["\u30B3\u30FC\u30EB","\u547C\u3076"],normalized:"call"},return:{primary:"\u623B\u308B",alternatives:["\u8FD4\u3059","\u30EA\u30BF\u30FC\u30F3"],normalized:"return"},then:{primary:"\u305D\u308C\u304B\u3089",alternatives:["\u6B21\u306B","\u305D\u3057\u3066"],normalized:"then"},and:{primary:"\u305D\u3057\u3066",alternatives:["\u3068","\u307E\u305F"],normalized:"and"},end:{primary:"\u7D42\u308F\u308A",alternatives:["\u7D42\u4E86","\u304A\u308F\u308A"],normalized:"end"},js:{primary:"JS\u5B9F\u884C",alternatives:["js"],normalized:"js"},async:{primary:"\u975E\u540C\u671F",alternatives:["\u30A2\u30B7\u30F3\u30AF"],normalized:"async"},tell:{primary:"\u4F1D\u3048\u308B",alternatives:["\u30C6\u30EB"],normalized:"tell"},default:{primary:"\u65E2\u5B9A",alternatives:["\u30C7\u30D5\u30A9\u30EB\u30C8"],normalized:"default"},init:{primary:"\u521D\u671F\u5316",alternatives:["\u30A4\u30CB\u30C3\u30C8"],normalized:"init"},behavior:{primary:"\u632F\u308B\u821E\u3044",alternatives:["\u30D3\u30D8\u30A4\u30D3\u30A2"],normalized:"behavior"},install:{primary:"\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB",alternatives:["\u5C0E\u5165"],normalized:"install"},measure:{primary:"\u6E2C\u5B9A",alternatives:["\u8A08\u6E2C","\u30E1\u30B8\u30E3\u30FC"],normalized:"measure"},into:{primary:"\u3078",alternatives:["\u306B"],normalized:"into"},before:{primary:"\u524D\u306B",alternatives:["\u524D"],normalized:"before"},after:{primary:"\u5F8C\u306B",alternatives:["\u5F8C"],normalized:"after"},until:{primary:"\u307E\u3067",alternatives:["\u8FC4"],normalized:"until"},event:{primary:"\u30A4\u30D9\u30F3\u30C8",alternatives:["\u4E8B\u8C61"],normalized:"event"},from:{primary:"\u304B\u3089",normalized:"from"}},tokenization:{particles:["\u3092","\u306B","\u3067","\u304B\u3089","\u306E","\u304C","\u306F","\u3082","\u3078","\u3068"],boundaryStrategy:"particle"}};var xt=F([[12352,12447]]),St=F([[12448,12543]]),vt=F([[19968,40959],[13312,19903]]),Ue=ye(xt,St,vt),Tt=new Set(["\u3092","\u306B","\u3067","\u304B\u3089","\u307E\u3067","\u3078","\u3068","\u306E","\u304C","\u306F","\u3082","\u3088\u308A"]),Fe=new Set(["\u3092","\u306B","\u3067","\u3078","\u3068","\u306E","\u304C","\u306F","\u3082"]),qe=["\u304B\u3089","\u307E\u3067","\u3088\u308A"],De=new Map([["\u3092",{role:"patient",confidence:.95,description:"object marker"}],["\u306B",{role:"destination",confidence:.85,description:"destination/time marker"}],["\u3067",{role:"manner",confidence:.88,description:"means/location marker"}],["\u304B\u3089",{role:"source",confidence:.9,description:"from/source marker"}],["\u307E\u3067",{role:"destination",confidence:.75,description:"until/boundary marker"}],["\u3078",{role:"destination",confidence:.9,description:"direction marker"}],["\u3068",{role:"style",confidence:.7,description:"with/and marker"}],["\u306E",{role:"patient",confidence:.6,description:"possessive marker"}],["\u304C",{role:"agent",confidence:.85,description:"subject marker"}],["\u306F",{role:"agent",confidence:.75,description:"topic marker"}],["\u3082",{role:"patient",confidence:.65,description:"also/too marker"}],["\u3088\u308A",{role:"source",confidence:.85,description:"from/than marker"}]]),Et=[{native:"\u771F",normalized:"true"},{native:"\u507D",normalized:"false"},{native:"\u30CC\u30EB",normalized:"null"},{native:"\u672A\u5B9A\u7FA9",normalized:"undefined"},{native:"\u6700\u521D",normalized:"first"},{native:"\u6700\u5F8C",normalized:"last"},{native:"\u6B21",normalized:"next"},{native:"\u524D",normalized:"previous"},{native:"\u6700\u3082\u8FD1\u3044",normalized:"closest"},{native:"\u89AA",normalized:"parent"},{native:"\u30AF\u30EA\u30C3\u30AF",normalized:"click"},{native:"\u5909\u66F4",normalized:"change"},{native:"\u9001\u4FE1",normalized:"submit"},{native:"\u5165\u529B",normalized:"input"},{native:"\u30ED\u30FC\u30C9",normalized:"load"},{native:"\u30B9\u30AF\u30ED\u30FC\u30EB",normalized:"scroll"},{native:"\u30AD\u30FC\u30C0\u30A6\u30F3",normalized:"keydown"},{native:"\u30AD\u30FC\u30A2\u30C3\u30D7",normalized:"keyup"},{native:"\u30DE\u30A6\u30B9\u30AA\u30FC\u30D0\u30FC",normalized:"mouseover"},{native:"\u30DE\u30A6\u30B9\u30A2\u30A6\u30C8",normalized:"mouseout"},{native:"\u30D6\u30E9\u30FC",normalized:"blur"},{native:"\u79C1",normalized:"me"},{native:"\u79C1\u306E",normalized:"my"},{native:"\u305D\u306E",normalized:"its"},{native:"\u3057\u305F\u3089",normalized:"on"},{native:"\u3059\u308B\u3068",normalized:"on"},{native:"\u6642\u306B",normalized:"on"},{native:"\u3082\u3057",normalized:"if"},{native:"\u306A\u3089\u3070",normalized:"then"},{native:"\u306A\u3089",normalized:"then"},{native:"\u79D2",normalized:"s"},{native:"\u30DF\u30EA\u79D2",normalized:"ms"},{native:"\u5206",normalized:"m"},{native:"\u6642\u9593",normalized:"h"}],bt=[{pattern:"\u30DF\u30EA\u79D2",suffix:"ms",length:3},{pattern:"\u6642\u9593",suffix:"h",length:2},{pattern:"\u79D2",suffix:"s",length:1},{pattern:"\u5206",suffix:"m",length:1}],xe=class extends U{constructor(){super();this.language="ja";this.direction="ltr";this.initializeKeywordsFromProfile(V,Et),this.normalizer=new q}tokenize(t){let n=[],o=0;for(;o<t.length;){if(z(t[o])){o++;continue}if(re(t[o])){let a=this.tryEventModifier(t,o);if(a){n.push(a),o=a.position.end;continue}let l=this.trySelector(t,o);if(l){n.push(l),o=l.position.end;continue}}if(oe(t[o])){let a=this.tryString(t,o);if(a){n.push(a),o=a.position.end;continue}}if(ie(t,o)){let a=this.tryUrl(t,o);if(a){n.push(a),o=a.position.end;continue}}if(C(t[o])){let a=this.extractJapaneseNumber(t,o);if(a){n.push(a),o=a.position.end;continue}}let i=this.tryVariableRef(t,o);if(i){n.push(i),o=i.position.end;continue}let s=this.tryMultiCharParticle(t,o,qe);if(s){let a=De.get(s.value);a?n.push({...s,metadata:{particleRole:a.role,particleConfidence:a.confidence}}):n.push(s),o=s.position.end;continue}if(Fe.has(t[o])){let a=this.tryProfileKeyword(t,o);if(a&&a.value.length>1){n.push(a),o=a.position.end;continue}let l=t[o],c=De.get(l);c?n.push({...v(l,"particle",S(o,o+1)),metadata:{particleRole:c.role,particleConfidence:c.confidence}}):n.push(v(l,"particle",S(o,o+1))),o++;continue}if(Ue(t[o])){let a=this.extractJapaneseWord(t,o);if(a){n.push(a),o=a.position.end;continue}}if(b(t[o])){let a=this.extractAsciiWord(t,o);if(a){n.push(a),o=a.position.end;continue}}o++}return new A(n,"ja")}classifyToken(t){return Tt.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||t.startsWith("\u300C")||/^\d/.test(t)?"literal":"identifier"}extractJapaneseWord(t,n){let o=n,i="";for(;o<t.length;){let l=t[o];if(Fe.has(l)&&i.length>0)break;let c=!1;for(let p of qe)if(t.slice(o,o+p.length)===p&&i.length>0){c=!0;break}if(c)break;if(Ue(l))i+=l,o++;else break}if(!i)return null;let s=this.lookupKeyword(i);if(s)return v(i,"keyword",S(n,o),s.normalized);let a=this.tryMorphKeywordMatch(i,n,o);return a||v(i,"identifier",S(n,o))}extractAsciiWord(t,n){let o=n,i="";for(;o<t.length&&b(t[o]);)i+=t[o++];return i?v(i,"identifier",S(n,o)):null}extractJapaneseNumber(t,n){return this.tryNumberWithTimeUnits(t,n,bt,{allowSign:!1,skipWhitespace:!1})}},se=new xe;Me("ja",se,V);function He(r){return Ae(r)}function ce(r,e){return Ve(r,e)}function le(){return te()}function L(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function T(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function w(r){return{type:"reference",value:r}}function B(r,e){return{type:"property-path",object:r,property:e}}function M(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function K(r,e,t,n,o){let i=new Map;i.set("event",r);let s={kind:"event-handler",action:"on",roles:i,body:e};return t!==void 0&&(s.eventModifiers=t),n!==void 0&&(s.metadata=n),o!==void 0&&o.length>0&&(s.parameterNames=o),s}function Ge(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 Se(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 Xe(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(),o=new Map;if(this.currentProfile=P(t.language),this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,o))return e.reset(n),null;let s=this.calculateConfidence(t,o);return this.applyExtractionRules(t,o),{pattern:t,captured:o,consumedTokens:e.position()-n.position,confidence:s}}matchBest(e,t){let n=[];for(let i of t){let s=e.mark(),a=this.matchPattern(e,i);a&&n.push(a),e.reset(s)}if(n.length===0)return null;n.sort((i,s)=>{let a=s.pattern.priority-i.pattern.priority;return a!==0?a:s.confidence-i.confidence});let o=n[0];return this.matchPattern(e,o.pattern),o}matchTokenSequence(e,t,n){if(this.currentProfile?.code==="ar")for(;e.peek()?.kind==="conjunction";)e.advance();for(let o of t)if(!this.matchPatternToken(e,o,n)){if(this.isOptional(o))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 o=this.getMatchType(n,t.value);if(o!=="none")return this.totalKeywordMatches++,o==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let i of t.alternatives){let s=this.getMatchType(n,i);if(s!=="none")return this.totalKeywordMatches++,s==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.skipNoiseWords(e);let o=e.peek();if(!o)return t.optional||!1;let i=this.tryMatchPossessiveExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(i.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,i),!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&&!Se(a.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,a),!0);let l=this.tryMatchPropertyAccessExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(l.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,l),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!Se(c.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,c),!0);let p=this.tokenToSemanticValue(o);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(),o=Xe(this.currentProfile,n);if(!o)return null;let i=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(),B(w(o),s.value)):(e.reset(i),null)}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let n=e.mark();e.advance();let o=e.peek();if(!o||o.kind!=="operator"||o.value!==".")return e.reset(n),null;e.advance();let i=e.peek();if(!i||i.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 c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}a.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${i.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 o=e.peek();if(!o||o.kind!=="operator"||o.value!==".")return e.reset(n),null;e.advance();let i=e.peek();if(!i||i.kind!=="identifier")return e.reset(n),null;e.advance();let s=`${t.value}.${i.value}`,a=1;for(;!e.isAtEnd()&&a<R.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),s+=`.${p.value}`,a++}let l=e.peek();if(l&&l.kind==="punctuation"&&l.value==="("){e.advance();let c=[],p=0;for(;!e.isAtEnd()&&c.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}c.push(y.value),e.advance()}return{type:"expression",raw:`${s}(${c.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 o=e.peek();if(!o||o.kind!=="punctuation"||o.value!=="'s")return e.reset(n),null;e.advance();let i=e.peek();return!i||i.kind!=="selector"&&i.kind!=="identifier"?(e.reset(n),null):(e.advance(),B(L(t.value),i.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let o=e.peek();if(!o||o.kind!=="selector"||!o.value.startsWith("."))return e.reset(n),null;let i=e.peek(1);i&&i.kind,e.advance();let s=o.value.slice(1);return B(L(t.value),s)}matchGroupToken(e,t,n){let o=e.mark(),i=new Set(n.keys());if(!this.matchTokenSequence(e,t.tokens,n)){e.reset(o);for(let a of n.keys())i.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 L(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?w(t):T(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return w(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?w(n):{type:"expression",raw:e.value};case"url":return T(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let o=e.slice(1,-1);return T(o,"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 o=parseFloat(t[1]);return t[2]?T(e,"duration"):T(o,"number")}let n=parseFloat(e);return isNaN(n)?T(e,"string"):T(n,"number")}applyExtractionRules(e,t){for(let[n,o]of Object.entries(e.extraction))!t.has(n)&&o.default&&t.set(n,o.default)}isOptional(e){return e.optional===!0}calculateConfidence(e,t){let n=0,o=0,i=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")o+=1,t.has(c.role)&&(n+=1);else if(c.type==="group"){for(let p of c.tokens)if(p.type==="role"){let x=i(p.role),y=.8;o+=y,t.has(p.role)?n+=y:x&&(n+=y*.6)}}let s=o>0?n/o:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let c=this.stemMatchCount/this.totalKeywordMatches*.15;s=Math.max(.5,s-c)}let a=this.calculateVSOConfidenceBoost(e);s=Math.min(1,s+a);let l=this.arabicPrepositionDisambiguation(e,t);return s=Math.max(0,Math.min(1,s+l)),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 o of t.alternatives)if(n.has(o))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let n=0,o={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(let[i,s]of t.entries()){let a=o[i];if(!a||a.length===0)continue;let l=s.metadata;if(l&&typeof l.prepositionValue=="string"){let c=l.prepositionValue;a.includes(c)?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 o=e.mark();e.advance();let i=e.peek();if(i&&i.kind==="selector")return;e.reset(o)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let o=e.peek();if(!o||o.kind!=="event-modifier")break;let i=o.metadata;if(!i)break;switch(n=!0,i.modifierName){case"once":t.once=!0;break;case"debounce":typeof i.value=="number"&&(t.debounce=i.value);break;case"throttle":typeof i.value=="number"&&(t.throttle=i.value);break;case"queue":(i.value==="first"||i.value==="last"||i.value==="all"||i.value==="none")&&(t.queue=i.value);break}e.advance()}return n?t:void 0}};R.MAX_PROPERTY_DEPTH=10,R.MAX_METHOD_ARGS=20,R.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var D=R,O=new D;var ue=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=Oe(t,e.action);if(n.length===0)return this.renderExplicit(e);let o=this.findBestPattern(e,n);return o?this.renderWithPattern(e,o):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(i=>this.render(i,t)),o=this.getChainWord(e.chainType,t);return n.join(` ${o} `)}getChainWord(e,t){let n=P(t);return n?.keywords?n.keywords[e]?.primary??e:e}renderExplicit(e){if(e.kind==="compound"){let n=e;return n.statements.map(i=>this.renderExplicit(i)).join(` ${n.chainType} `)}let t=[e.action];for(let[n,o]of e.roles)t.push(`${n}:${this.valueToString(o)}`);if(e.kind==="event-handler"){let n=e;if(n.body&&n.body.length>0){let o=n.body.map(i=>this.renderExplicit(i));t.push(`body:${o.join(" ")}`)}}return`[${t.join(" ")}]`}supportedLanguages(){return le()}findBestPattern(e,t){let n=t.map(o=>{let i=o.priority;for(let s of o.template.tokens)s.type==="role"&&(e.roles.has(s.role)?i+=10:s.optional||(i-=50));return o.language==="en"&&((o.id.includes("standard")||o.id.includes("en-source"))&&(i+=20),(o.id.includes("-when")||o.id.includes("-if")||o.id.includes("-upon"))&&(i-=15)),{pattern:o,score:i}});return n.sort((o,i)=>i.score-o.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let n=[],o=t.language;for(let i of t.template.tokens){let s=this.renderPatternToken(i,e,o);s!==null&&n.push(s)}if(e.kind==="event-handler"){let i=e;if(i.body&&i.body.length>0){let s=i.body.map(a=>this.render(a,o));n.push(s.join(" "))}}return n.join(" ")}renderPatternToken(e,t,n){switch(e.type){case"literal":return e.value;case"role":{let o=t.roles.get(e.role);return o?this.valueToNaturalString(o,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 i=[];for(let s of e.tokens){let a=this.renderPatternToken(s,t,n);a!==null&&i.push(a)}return i.length>0?i.join(" "):null}default:return null}}valueToString(e){switch(e.type){case"literal":return typeof e.value=="string"?e.dataType==="string"||/\s/.test(e.value)?`"${e.value}"`:e.value:String(e.value);case"selector":return e.value;case"reference":return e.value;case"property-path":return`${this.valueToString(e.object)}'s ${e.property}`;case"expression":return e.raw}}valueToNaturalString(e,t="en"){switch(e.type){case"literal":return typeof e.value=="string"&&e.dataType==="string"?`"${e.value}"`:String(e.value);case"selector":return e.value;case"reference":return this.renderReference(e,t);case"property-path":return this.renderPropertyPath(e,t);case"expression":return e.raw}}renderReference(e,t){let n=P(t);return n?.references?n.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let n=P(t),o=e.property,i=e.object.type==="reference"?e.object.value:null;if(n?.possessive?.specialForms&&i){let a=n.possessive.specialForms[i];if(a){let{markerPosition:l,usePossessiveAdjectives:c}=n.possessive;return c&&l==="after-object"?`${o} ${a}`:`${a} ${o}`}}let s=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:a,markerPosition:l,usePossessiveAdjectives:c}=n.possessive;if(c&&i&&l==="after-object")return`${o} ${s}`;if(a)switch(l){case"between":return n.usesSpaces?`${s}${a} ${o}`:`${s}${a}${o}`;case"after-object":return`${s}${a} ${o}`;case"before-property":return`${s} ${a} ${o}`}}return t==="en"||!n?.possessive?s==="me"?`my ${o}`:s==="it"?`its ${o}`:`${s}'s ${o}`:`${s} ${o}`}},ve=new ue;function H(r,e){return ve.render(r,e)}function G(r){return ve.renderExplicit(r)}function j(r){let e=r.trim();if(!e.startsWith("[")||!e.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let t=e.slice(1,-1).trim();if(!t)throw new Error("Empty explicit statement");let n=kt(t);if(n.length===0)throw new Error("No command specified in explicit statement");let o=n[0].toLowerCase(),i=new Map;for(let a=1;a<n.length;a++){let l=n[a],c=l.indexOf(":");if(c===-1)throw new Error(`Invalid role format: "${l}". Expected role:value`);let p=l.slice(0,c),x=l.slice(c+1);if(p==="body"&&x.startsWith("[")){let h=Ct(l,c+1),d=l.slice(c+1,h+1);i.set(p,{type:"expression",raw:d});continue}let y=Nt(x);i.set(p,y)}if(o==="on"){let a=i.get("event");if(!a)throw new Error("Event handler requires event role: [on event:click ...]");let l=i.get("body"),c=[];return l&&l.type==="expression"&&c.push(j(l.raw)),i.delete("body"),K(a,c,void 0,{sourceLanguage:"explicit"})}let s={};for(let[a,l]of i)s[a]=l;return M(o,s,{sourceLanguage:"explicit"})}function kt(r){let e=[],t="",n=!1,o="",i=0;for(let s=0;s<r.length;s++){let a=r[s];if(n){t+=a,a===o&&r[s-1]!=="\\"&&(n=!1);continue}if(a==='"'||a==="'"){n=!0,o=a,t+=a;continue}if(a==="["){i++,t+=a;continue}if(a==="]"){i--,t+=a;continue}if(a===" "&&i===0){t&&(e.push(t),t="");continue}t+=a}return t&&e.push(t),e}function Nt(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return L(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return 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 w(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 W(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var de=class{parse(e,t){let n=ce(e,t),o=N(t);if(o.length===0)throw new Error(`No patterns available for language: ${t}`);let i=[...o].sort((p,x)=>x.priority-p.priority),s=i.filter(p=>p.command==="on"),a=O.matchBest(n,s);if(a)return this.buildEventHandler(a,n,t);let l=i.filter(p=>p.command!=="on"),c=O.matchBest(n,l);if(c)return this.buildCommand(c,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return le()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let n={};for(let[o,i]of e.captured)n[o]=i;return M(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let o=e.captured.get("event");if(!o)throw new Error("Event handler pattern matched but no event captured");let i=O.extractEventModifiers(t),s,a=e.captured.get("action");if(a&&a.type==="literal"){let l=a.value,c={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(c[y]=h);let p=M(l,c,{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,g)=>g.priority-m.priority),h=N(n).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,g)=>g.priority-m.priority),d=this.parseBodyWithGrammarPatterns(t,y,h,n);d.length>0?s=[p,...d]:s=[p]}else s=[p]}else{let l=N(n).filter(c=>c.command!=="on").sort((c,p)=>p.priority-c.priority);s=this.parseBodyWithClauses(t,l,n)}return K(o,s,i,{sourceLanguage:n,patternId:e.pattern.id})}parseBodyWithClauses(e,t,n){let o=[],i=[];for(;!e.isAtEnd();){let s=e.peek();if(!s)break;let a=s.kind==="conjunction"||s.kind==="keyword"&&this.isThenKeyword(s.value,n),l=s.kind==="keyword"&&this.isEndKeyword(s.value,n);if(a){if(i.length>0){let c=this.parseClause(i,t,n);o.push(...c),i.length=0}e.advance();continue}if(l){if(i.length>0){let c=this.parseClause(i,t,n);o.push(...c)}e.advance();break}i.push(s),e.advance()}if(i.length>0){let s=this.parseClause(i,t,n);o.push(...s)}return o.length>1?[Ge(o,"then",{sourceLanguage:n})]:o}parseClause(e,t,n){if(e.length===0)return[];let o=new A(e,n),i=[];for(;!o.isAtEnd();){let s=O.matchBest(o,t);s?i.push(this.buildCommand(s,n)):o.advance()}return i}parseBodyWithGrammarPatterns(e,t,n,o){let i=[];for(;!e.isAtEnd();){let s=e.peek();if(s&&this.isThenKeyword(s.value,o)){e.advance();continue}if(s&&this.isEndKeyword(s.value,o)){e.advance();break}let a=!1;if(n.length>0){let l=O.matchBest(e,n);if(l){let c=l.pattern.command,p={};for(let[h,d]of l.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(p[h]=d);let x=M(c,p,{sourceLanguage:o,patternId:l.pattern.id});i.push(x),a=!0;let y=l.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!a){let l=O.matchBest(e,t);l&&(i.push(this.buildCommand(l,o)),a=!0)}a||e.advance()}return i}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 de;function $(r,e){return Te.parse(r,e)}function Ee(r,e){return Te.canParse(r,e)}function be(r,e){if(W(r))return r;let t=$(r,e);return G(t)}function ke(r,e){let t=j(r);return H(t,e)}function Ne(r,e){return W(r)?j(r):$(r,e)}var wt=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Rt=new Set(["and","or","not","no"]),Pt=new Set(["true","false","null","undefined"]),Lt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ze(r){let e=[],t=0,n=1,o=1;function i(){if(e.length===0)return!0;let d=e[e.length-1];return["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(d.type)}function s(d=0){return r[t+d]??""}function a(){let d=r[t];return t++,d===`
2
- `?(n++,o=1):o++,d}function l(){for(;t<r.length&&/\s/.test(r[t]);)a()}function c(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 h(d,m,g){return{type:d,value:m,start:g,end:t,line:n,column:o-m.length}}for(;t<r.length&&(l(),!(t>=r.length));){let d=t,m=s();if(m==="'"&&s(1)==="s"&&!/\w/.test(s(2))){a(),a(),e.push(h("POSSESSIVE","'s",d));continue}if(m==='"'||m==="'"){let g=p(m);e.push(h("STRING",g,d));continue}if(m==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,d));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(s(1))){let g=y();e.push(h("QUERY_SELECTOR",g,d));continue}if(m==="#"&&i()){a();let g=c(E=>/[\w-]/.test(E));e.push(h("ID_SELECTOR","#"+g,d));continue}if(m==="."&&/[a-zA-Z_-]/.test(s(1))&&i()){a();let g=c(E=>/[\w-]/.test(E));e.push(h("CLASS_SELECTOR","."+g,d));continue}if(m==="["&&i()){let g=s(1);if(g==="@"||/[a-zA-Z]/.test(g)){let E="";for(E+=a();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?E+=p(r[t]):E+=a();t<r.length&&(E+=a()),e.push(h("ATTRIBUTE_SELECTOR",E,d));continue}}if(m==="["){a(),e.push(h("LBRACKET","[",d));continue}if(m==="]"){a(),e.push(h("RBRACKET","]",d));continue}if(/\d/.test(m)){let g=c(me=>/[\d.]/.test(me)),E=t,J=c(me=>/[a-zA-Z]/.test(me));Lt.has(J)?e.push(h("TIME_EXPRESSION",g+J,d)):(t=E,e.push(h("NUMBER",g,d)));continue}if(m==="("){a(),e.push(h("LPAREN","(",d));continue}if(m===")"){a(),e.push(h("RPAREN",")",d));continue}if(m==="{"){a(),e.push(h("LBRACE","{",d));continue}if(m==="}"){a(),e.push(h("RBRACE","}",d));continue}if(m===","){a(),e.push(h("COMMA",",",d));continue}if(m===":"){a(),e.push(h("COLON",":",d));continue}if(m==="."){a(),e.push(h("DOT",".",d));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){a(),e.push(h("OPERATOR",m,d));continue}if(m==="="||m==="!"||m==="<"||m===">"){let g=a();s()==="="&&(g+=a()),e.push(h("COMPARISON",g,d));continue}if(/[a-zA-Z_$]/.test(m)){let g=c(J=>/[\w$]/.test(J)),E=g.toLowerCase();wt.has(E)?e.push(h("CONTEXT_VAR",g,d)):Rt.has(E)?e.push(h("LOGICAL",g,d)):Pt.has(E)?e.push(h("BOOLEAN",g,d)):e.push(h("IDENTIFIER",g,d));continue}a()}return e.push(h("EOF","",t)),e}var pe=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ze(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 o=this.parseExpression();e.push({key:n,value:o})}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]),o=t[2].toLowerCase();return{type:"timeExpression",value:n,unit:o,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 Ce(r){return new pe().parse(r)}function k(r,e){switch(r.type){case"literal":return Mt(r);case"selector":return At(r,e);case"reference":return zt(r);case"property-path":return Vt(r,e);case"expression":return Ot(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function Mt(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function At(r,e){return e&&r.value.startsWith("*")&&/^[a-zA-Z-]/.test(r.value.slice(1))&&e.push(`Converted '${r.value}' to a CSS selector, but it looks like a CSS property name. CSS properties in commands like 'transition' should be literal strings, not selectors. Consider using expectedTypes: ['literal'] instead of ['literal', 'selector'] in the command schema.`),{type:"selector",value:r.value,selector:r.value,selectorType:r.selectorKind}}function zt(r){return{type:"contextReference",contextType:r.value,name:r.value}}function Vt(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function Ot(r){let e=Ce(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function Qe(r,e){return r.roles.get(e)}function u(r,e,t){let n=Qe(r,e);return n?k(n,t):void 0}function f(r,e=[],t,n={}){let o={type:"command",name:r,args:e};return t&&Object.keys(t).length>0&&(o.modifiers=t),n.isBlocking&&(o.isBlocking=n.isBlocking),n.implicitTarget&&(o.implicitTarget=n.implicitTarget),o}var jt={action:"toggle",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=u(r,"duration"),i=t?[t]:[],s={};return n&&(s.on=n),o&&(s.for=o),f("toggle",i,s)}},It={action:"add",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=t?[t]:[],i={};return n&&(i.to=n),f("add",o,i)}},_t={action:"remove",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),o=t?[t]:[],i={};return n&&(i.from=n),f("remove",o,i)}},Bt={action:"set",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=[],i={};return t&&o.push(t),n&&(i.to=n),f("set",o,i)}},Kt={action:"show",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=u(r,"duration"),i=[],s={},a=t??n;return a&&i.push(a),o&&(s.with=o),f("show",i,s)}},Wt={action:"hide",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=u(r,"duration"),i=[],s={},a=t??n;return a&&i.push(a),o&&(s.with=o),f("hide",i,s)}},$t={action:"increment",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=u(r,"quantity"),i=[],s={},a=t??n;return a&&i.push(a),o&&(s.by=o),f("increment",i,s)}},Ut={action:"decrement",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=u(r,"quantity"),i=[],s={},a=t??n;return a&&i.push(a),o&&(s.by=o),f("decrement",i,s)}},Ft={action:"wait",toAST(r,e){let t=u(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},qt={action:"log",toAST(r,e){let t=u(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},Dt={action:"put",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=Qe(r,"method"),i=t?[t]:[],s={};if(n){let a=o?.type==="literal"?String(o.value):"into";s[a]=n}return f("put",i,s)}},Ht={action:"fetch",toAST(r,e){let t=u(r,"source"),n=u(r,"method"),o=u(r,"responseType"),i=u(r,"patient"),s=t?[t]:[],a={};return n&&(a.with=n),o&&(a.as=o),i&&(a.body=i),f("fetch",s,a,{isBlocking:!0})}},Gt={action:"append",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=t?[t]:[],i={};return n&&(i.to=n),f("append",o,i)}},Xt={action:"prepend",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=t?[t]:[],i={};return n&&(i.to=n),f("prepend",o,i)}},Zt={action:"trigger",toAST(r,e){let t=u(r,"event"),n=u(r,"destination"),o=t?[t]:[],i={};return n&&(i.on=n),f("trigger",o,i)}},Qt={action:"send",toAST(r,e){let t=u(r,"event"),n=u(r,"destination"),o=u(r,"patient"),i=t?[t]:[],s={};return n&&(s.to=n),o&&(s.detail=o),f("send",i,s)}},Jt={action:"go",toAST(r,e){let t=u(r,"source"),n=u(r,"destination"),o=[],i={};return t&&o.push(t),n&&(i.to=n),f("go",o,i)}},Yt={action:"transition",toAST(r,e){let t=u(r,"patient"),n=u(r,"goal"),o=u(r,"duration"),i=u(r,"destination"),s=t?[t]:[],a={};return n&&(a.to=n),o&&(a.over=o),i&&(a.on=i),f("transition",s,a)}},en={action:"focus",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=[],i={},s=t??n;return s&&o.push(s),f("focus",o,i)}},tn={action:"blur",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=[],i=t??n;return i&&o.push(i),f("blur",o)}},nn={action:"get",toAST(r,e){let t=u(r,"source"),n=u(r,"patient"),o=[],i=t??n;return i&&o.push(i),f("get",o)}},rn={action:"take",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),o=t?[t]:[],i={};return n&&(i.from=n),f("take",o,i)}},on={action:"call",toAST(r,e){let t=u(r,"patient");return f("call",t?[t]:[])}},an={action:"return",toAST(r,e){let t=u(r,"patient");return f("return",t?[t]:[])}},sn={action:"halt",toAST(r,e){return f("halt",[])}},cn={action:"throw",toAST(r,e){let t=u(r,"patient");return f("throw",t?[t]:[])}},ln={action:"settle",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=[],i=t??n;return i&&o.push(i),f("settle",o,void 0,{isBlocking:!0})}},un={action:"swap",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),o=u(r,"destination"),i=u(r,"style"),s=[],a={};return t&&s.push(t),n&&s.push(n),o&&(a.on=o),i&&(a.with=i),f("swap",s,a)}},dn={action:"morph",toAST(r,e){let t=u(r,"source"),n=u(r,"destination"),o=u(r,"patient"),i=[],s={},a=t??o;return a&&i.push(a),n&&(s.on=n),f("morph",i,s)}},pn={action:"clone",toAST(r,e){let t=u(r,"source"),n=u(r,"destination"),o=u(r,"patient"),i=[],s={},a=t??o;return a&&i.push(a),n&&(s.into=n),f("clone",i,s)}},mn={action:"make",toAST(r,e){let t=u(r,"patient");return f("make",t?[t]:[])}},fn={action:"measure",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=u(r,"source"),i=[],s={};t&&i.push(t);let a=n??o;return a&&(s.of=a),f("measure",i,s)}},gn={action:"tell",toAST(r,e){let t=u(r,"destination"),n=u(r,"patient"),o=[],i=t??n;return i&&o.push(i),f("tell",o)}},hn={action:"js",toAST(r,e){let t=u(r,"patient");return f("js",t?[t]:[])}},yn={action:"async",toAST(r,e){return f("async",[])}},xn={action:"if",toAST(r,e){let t=u(r,"condition");return f("if",t?[t]:[])}},Sn={action:"unless",toAST(r,e){let t=u(r,"condition");return f("unless",t?[t]:[])}},vn={action:"repeat",toAST(r,e){let t=u(r,"quantity"),n=u(r,"patient"),o=[],i=t??n;return i&&o.push(i),f("repeat",o)}},Tn={action:"for",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),o=t?[t]:[],i={};return n&&(i.in=n),f("for",o,i)}},En={action:"while",toAST(r,e){let t=u(r,"condition");return f("while",t?[t]:[])}},bn={action:"continue",toAST(r,e){return f("continue",[])}},kn={action:"default",toAST(r,e){let t=u(r,"patient"),n=u(r,"source"),o=t?[t]:[],i={};return n&&(i.to=n),f("default",o,i)}},Nn={action:"init",toAST(r,e){return f("init",[])}},Cn={action:"behavior",toAST(r,e){let t=u(r,"patient");return f("behavior",t?[t]:[])}},wn={action:"install",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),o=t?[t]:[],i={};return n&&(i.on=n),f("install",o,i)}},Rn={action:"on",toAST(r,e){let t=u(r,"event"),n=u(r,"source"),o=t?[t]:[],i={};return n&&(i.from=n),f("on",o,i)}},Je=new Map([["toggle",jt],["add",It],["remove",_t],["set",Bt],["show",Kt],["hide",Wt],["increment",$t],["decrement",Ut],["wait",Ft],["log",qt],["put",Dt],["fetch",Ht],["append",Gt],["prepend",Xt],["get",nn],["take",rn],["trigger",Zt],["send",Qt],["on",Rn],["go",Jt],["transition",Yt],["focus",en],["blur",tn],["call",on],["return",an],["halt",sn],["throw",cn],["settle",ln],["swap",un],["morph",dn],["clone",pn],["measure",fn],["make",mn],["tell",gn],["default",kn],["js",hn],["async",yn],["if",xn],["unless",Sn],["repeat",vn],["for",Tn],["while",En],["continue",bn],["init",Nn],["behavior",Cn],["install",wn]]);function X(r){return Je.get(r)}function we(r){Je.set(r.action,r)}var Z=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=X(e.action);if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let o=n;return this.warnings.push(...o.warnings),o.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},o=["patient","source","quantity"],i=["destination","duration","method","style"];for(let a of o){let l=e.roles.get(a);l&&t.push(k(l))}for(let a of i){let l=e.roles.get(a);if(l){let c=this.roleToModifierKey(a);n[c]=k(l)}}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,o;if(t?.type==="literal"){let g=String(t.value);g.includes("|")||g.includes(" or ")?(o=g.split(/\s+or\s+|\|/).map(E=>E.trim()),n=o[0]):n=g}else t?.type==="reference"?n=t.value:n="click";let i=e.body.map(g=>this.build(g)),s=e.roles.get("source"),a,l;s?.type==="selector"?(a=s.value,l=s.value):s?.type==="reference"?l=s.value:s?.type==="literal"&&(l=String(s.value));let c=e.roles.get("condition"),p=c?k(c):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,h=e.eventModifiers,d=a;if(h?.from){let g=h.from;g.type==="selector"&&!a&&(d=g.value)}let m=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:n,commands:i,...o&&o.length>1?{events:o}:{},...d?{selector:d}:{},...l?{target:l}:{},...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),o=e.thenBranch.map(a=>this.build(a)),i=e.elseBranch?.map(a=>this.build(a)),s=[n,{type:"block",commands:o}];return i&&i.length>0&&s.push({type:"block",commands:i}),{type:"command",name:"if",args:s}}buildCompound(e){let t=e.statements.map(o=>this.build(o));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(o=>this.build(o)),n=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let o=e.roles.get("quantity");o&&n.push(k(o));break}case"for":{e.loopVariable&&n.push({type:"string",value:e.loopVariable});let o=e.roles.get("source");o&&n.push(k(o));break}case"while":case"until":{let o=e.roles.get("condition");o&&n.push(k(o));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 Ye(r){let e=new Z;return{ast:e.build(r),warnings:e.warnings}}var I=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),o=this.cache.get(n);if(!o){this.stats.misses++;return}if(this.isExpired(o)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),o.lastAccessed=Date.now(),this.cache.set(n,o),this.stats.hits++,o.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let o=this.makeKey(e,t),i=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(o,{result:n,createdAt:i,lastAccessed:i})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),o=this.cache.get(n);return o?this.isExpired(o)?(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 I;var Q=class{constructor(e={}){this.patternMatcher=new D,this.languages=new Set(te()),e.cache===!1?this.cache=new I({enabled:!1}):this.cache=e.cache?new I(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 o=this.analyzeUncached(e,t);return this.cache.set(e,t,o),o}analyzeUncached(e,t){try{let n=He(t);if(!n)return{confidence:0,errors:[`No tokenizer available for language '${t}'`]};let o=n.tokenize(e),i=N(t);if(i.length===0)return{confidence:0,errors:[`No patterns available for language '${t}'`]};let s=this.patternMatcher.matchBest(o,i);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 et(r){return new Q(r)}var Pe=.5,tt=.8;function nt(r,e=Pe){return r.confidence>=e&&r.command!==void 0}var Pn="1.0.0-ja",Ln=["ja"];function Mn(){return[...Ln]}function rt(r){if(r!=="ja")throw new Error(`Language not supported in this bundle: ${r}. Supported: ja`)}function An(r,e){return rt(e),[...ce(r,e).tokens]}function ot(r){return rt(r),N(r)}function zn(r,e){return ot(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return ut(Vn);})();
1
+ "use strict";var LokaScriptSemanticJa=(()=>{var he=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var pt=Object.prototype.hasOwnProperty;var mt=(r,e)=>{for(var t in e)he(r,t,{get:e[t],enumerable:!0})},ft=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of dt(e))!pt.call(r,i)&&i!==t&&he(r,i,{get:()=>e[i],enumerable:!(n=ut(e,i))||n.enumerable});return r};var gt=r=>ft(he({},"__esModule",{value:!0}),r);var Bn={};mt(Bn,{ASTBuilder:()=>ee,DEFAULT_CONFIDENCE_THRESHOLD:()=>Ae,HIGH_CONFIDENCE_THRESHOLD:()=>at,SemanticAnalyzerImpl:()=>te,VERSION:()=>Vn,buildAST:()=>it,canParse:()=>Ne,createCommandNode:()=>A,createEventHandler:()=>U,createLiteral:()=>T,createPropertyPath:()=>$,createReference:()=>R,createSelector:()=>M,createSemanticAnalyzer:()=>ot,fromExplicit:()=>we,getCommandMapper:()=>Y,getPatternsForLanguage:()=>lt,getPatternsForLanguageAndCommand:()=>_n,getProfile:()=>Se,getSupportedLanguages:()=>On,getTokenizer:()=>xe,isExplicitSyntax:()=>F,isLanguageSupported:()=>_e,japaneseProfile:()=>_,japaneseTokenizer:()=>le,parse:()=>q,parseAny:()=>Re,parseExplicit:()=>K,registerCommandMapper:()=>Le,render:()=>Q,renderExplicit:()=>J,shouldUseSemanticResult:()=>st,toExplicit:()=>Ce,tokenize:()=>In,tryGetProfile:()=>L});var w=new Map,z=new Map,D=new Map;var ze=null;function je(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]=je(o,i):t[n]=i)}return t}function ht(r,e){return je(r,e)}function ye(r){if(!r.extends)return r;let e=z.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 ht(t,r)}function Oe(r,e,t){w.set(r,e),z.set(r,t),D.delete(r)}var Ve=new Map;function V(r){return r.split("-")[0]}function j(r){return r.includes("-")}function xe(r){let e=w.get(r);if(!e&&j(r)){let t=V(r);e=w.get(t)}if(!e){let t=Array.from(w.keys()).join(", ");throw new Error(`Language '${r}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${r}';`)}return e}function Se(r){let e=z.get(r);if(!e&&j(r)){let t=V(r);e=z.get(t)}if(!e){let t=Array.from(z.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 Ie(r){let e=w.get(r);return!e&&j(r)&&(e=w.get(V(r))),e}function L(r){let e=z.get(r);return!e&&j(r)&&(e=z.get(V(r))),e?ye(e):void 0}function re(){return Array.from(w.keys())}function _e(r){return w.has(r)?!0:j(r)?w.has(V(r)):!1}function Be(r,e){return xe(e).tokenize(r)}function N(r){let e=D.get(r);if(!e&&j(r)&&(e=D.get(V(r))),e)return e;let t=Ve.get(r);if(!t&&j(r)&&(t=Ve.get(V(r))),t)return D.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=Se(r),i=ze(n);return D.set(r,i),i}function Ke(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 I(r){return/\s/.test(r)}function oe(r){return r==="#"||r==="."||r==="["||r==="@"||r==="*"||r==="<"}function ae(r){return r==='"'||r==="'"||r==="`"||r==="\u300C"||r==="\u300D"}function C(r){return/\d/.test(r)}function We(r){return/[a-zA-Z]/.test(r)}function b(r){return/[a-zA-Z0-9_-]/.test(r)}function G(r){return e=>{let t=e.charCodeAt(0);return r.some(([n,i])=>t>=n&&t<=i)}}function ve(...r){return e=>r.some(t=>t(e))}function $e(r,e){if(e>=r.length)return null;let t=r[e];if(!oe(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,l=!1;for(i+=r[n++];n<r.length&&o>0;){let c=r[n];i+=c,l?l=!1:c==="\\"?l=!0:s?c===a&&(s=!1,a=null):c==='"'||c==="'"||c==="`"?(s=!0,a=c):c==="["?o++:c==="]"&&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||!We(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,l=null,c=!1;for(i+=r[n++];n<r.length&&s>0;){let p=r[n];i+=p,c?c=!1:p==="\\"?c=!0:a?p===l&&(a=!1,l=null):p==='"'||p==="'"||p==="`"?(a=!0,l=p):p==="["?s++:p==="]"&&s--,n++}if(s!==0)return null}else break}for(;n<r.length&&I(r[n]);)i+=r[n++];if(n<r.length&&r[n]==="/")for(i+=r[n++];n<r.length&&I(r[n]);)i+=r[n++];if(n>=r.length||r[n]!==">")return null;i+=r[n++]}return i||null}function yt(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 I(n)||n==="*"||!b(n)}function Ue(r,e){if(e>=r.length)return null;let t=r[e];if(!ae(t)||t==="'"&&yt(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 l=r[o];if(s+=l,a)a=!1;else if(l==="\\")a=!0;else if(l===i)return s;o++}return s}function se(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 Fe(r,e){if(!se(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(!C(t)&&t!=="-"&&t!=="+")return null;let n=e,i="";if((r[n]==="-"||r[n]==="+")&&(i+=r[n++]),n>=r.length||!C(r[n]))return null;for(;n<r.length&&C(r[n]);)i+=r[n++];if(n<r.length&&r[n]===".")for(i+=r[n++];n<r.length&&C(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 ie=class ie{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=$e(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=Ue(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&&I(e[o]);)o++;let s=e.slice(o);for(let a of n){let l=s.slice(0,a.length);if(a.caseInsensitive?l.toLowerCase()===a.pattern.toLowerCase():l===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||!C(e[i]))return null;for(;i<e.length&&C(e[i]);)o+=e[i++];if(i<e.length&&e[i]===".")for(o+=e[i++];i<e.length&&C(e[i]);)o+=e[i++];return!o||o==="-"||o==="+"?null:{number:o,endPos:i}}tryNumberWithTimeUnits(e,t,n,i={}){let{allowSign:o=!0,skipWhitespace:s=!1}=i,a=this.parseBaseNumber(e,t,o);if(!a)return null;let{number:l,endPos:c}=a,p=[...n,...ie.STANDARD_TIME_UNITS],x=this.tryMatchTimeUnit(e,c,p,s);return x&&(l+=x.suffix,c=x.endPos),v(l,"literal",S(t,c))}tryUrl(e,t){let n=Fe(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}};ie.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var H=ie;function De(r){return{stem:r,confidence:1}}function ce(r,e,t){return t?{stem:r,confidence:e,metadata:t}:{stem:r,confidence:e}}var xt=[{pattern:"\u3057\u305F\u3089",confidence:.88,conjugationType:"conditional-tara",minStemLength:2},{pattern:"\u3059\u308B\u3068",confidence:.88,conjugationType:"conditional-to",minStemLength:2},{pattern:"\u3059\u308C\u3070",confidence:.85,conjugationType:"conditional-ba",minStemLength:2},{pattern:"\u305F\u3089",confidence:.85,conjugationType:"conditional-tara",minStemLength:2},{pattern:"\u308C\u3070",confidence:.82,conjugationType:"conditional-ba",minStemLength:2},{pattern:"\u3066\u3044\u307E\u3057\u305F",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\u3066\u3044\u307E\u3059",confidence:.85,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u304F\u3060\u3055\u3044",confidence:.85,conjugationType:"request",minStemLength:2},{pattern:"\u3067\u304F\u3060\u3055\u3044",confidence:.85,conjugationType:"request",minStemLength:2},{pattern:"\u3066\u3044\u308B",confidence:.85,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u304A\u304F",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u307F\u308B",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u3042\u308B",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"\u3066\u304F\u308C",confidence:.8,conjugationType:"casual-request",minStemLength:2},{pattern:"\u3067\u304F\u308C",confidence:.8,conjugationType:"casual-request",minStemLength:2},{pattern:"\u3061\u3083\u3063\u305F",confidence:.82,conjugationType:"contracted-past",minStemLength:2},{pattern:"\u3058\u3083\u3063\u305F",confidence:.82,conjugationType:"contracted-past",minStemLength:2},{pattern:"\u3061\u3083\u3046",confidence:.82,conjugationType:"contracted",minStemLength:2},{pattern:"\u3058\u3083\u3046",confidence:.82,conjugationType:"contracted",minStemLength:2},{pattern:"\u307E\u3057\u305F",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"\u307E\u305B\u3093",confidence:.85,conjugationType:"negative",minStemLength:2},{pattern:"\u307E\u3059",confidence:.85,conjugationType:"polite",minStemLength:2},{pattern:"\u3066",confidence:.85,conjugationType:"te-form",minStemLength:2},{pattern:"\u305F",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"\u306A\u3044",confidence:.82,conjugationType:"negative",minStemLength:2},{pattern:"\u306A\u304B\u3063\u305F",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\u3089\u308C\u308B",confidence:.8,conjugationType:"potential",minStemLength:2},{pattern:"\u308C\u308B",confidence:.78,conjugationType:"potential",minStemLength:2},{pattern:"\u3089\u308C\u305F",confidence:.8,conjugationType:"passive",minStemLength:2},{pattern:"\u3055\u305B\u308B",confidence:.8,conjugationType:"causative",minStemLength:2},{pattern:"\u305B\u308B",confidence:.78,conjugationType:"causative",minStemLength:2},{pattern:"\u3088\u3046",confidence:.8,conjugationType:"volitional",minStemLength:2},{pattern:"\u308B",confidence:.75,conjugationType:"dictionary",minStemLength:3}],St=[{pattern:"\u3057\u305F\u3089",confidence:.88,conjugationType:"conditional-tara"},{pattern:"\u3059\u308B\u3068",confidence:.88,conjugationType:"conditional-to"},{pattern:"\u3059\u308C\u3070",confidence:.85,conjugationType:"conditional-ba"},{pattern:"\u3057\u3066\u3044\u307E\u3059",confidence:.85,conjugationType:"progressive"},{pattern:"\u3057\u3066\u3044\u308B",confidence:.85,conjugationType:"progressive"},{pattern:"\u3057\u307E\u3057\u305F",confidence:.85,conjugationType:"past"},{pattern:"\u3057\u307E\u3059",confidence:.85,conjugationType:"polite"},{pattern:"\u3057\u306A\u3044",confidence:.82,conjugationType:"negative"},{pattern:"\u3057\u3066",confidence:.85,conjugationType:"te-form"},{pattern:"\u3057\u305F",confidence:.85,conjugationType:"past"},{pattern:"\u3059\u308B",confidence:.88,conjugationType:"dictionary"}];function He(r){let e=r.charCodeAt(0);return e>=12352&&e<=12447}function vt(r){let e=r.charCodeAt(0);return e>=12448&&e<=12543}function Tt(r){let e=r.charCodeAt(0);return e>=19968&&e<=40959||e>=13312&&e<=19903}function Et(r){for(let e of r)if(He(e)||vt(e)||Tt(e))return!0;return!1}var X=class{constructor(){this.language="ja"}isNormalizable(e){if(!Et(e)||e.length<2)return!1;let t=e[e.length-1];return He(t)}normalize(e){let t=this.normalizeCompound(e);if(t)return t;let n=this.trySuruNormalization(e);if(n)return n;for(let i of xt)if(e.endsWith(i.pattern)){let o=e.slice(0,-i.pattern.length),s=i.minStemLength??2;if(o.length<s)continue;let a={removedSuffixes:[i.pattern]};return i.conjugationType&&(a.conjugationType=i.conjugationType),ce(o,i.confidence,a)}return De(e)}trySuruNormalization(e){for(let t of St)if(e.endsWith(t.pattern)){let n=e.slice(0,-t.pattern.length);if(n.length<1)continue;return ce(n,t.confidence,{removedSuffixes:[t.pattern],conjugationType:t.conjugationType,originalForm:"suru-verb"})}return null}normalizeCompound(e){let t=[{pattern:"\u3066\u3044\u306A\u304B\u3063\u305F",suffixes:["\u3066","\u3044","\u306A\u304B\u3063\u305F"],confidence:.8,minStemLength:2},{pattern:"\u3067\u3044\u306A\u304B\u3063\u305F",suffixes:["\u3067","\u3044","\u306A\u304B\u3063\u305F"],confidence:.8,minStemLength:2},{pattern:"\u3066\u3044\u306A\u3044",suffixes:["\u3066","\u3044","\u306A\u3044"],confidence:.82,minStemLength:2},{pattern:"\u3067\u3044\u306A\u3044",suffixes:["\u3067","\u3044","\u306A\u3044"],confidence:.82,minStemLength:2},{pattern:"\u3066\u3044\u305F",suffixes:["\u3066","\u3044","\u305F"],confidence:.85,minStemLength:2},{pattern:"\u3067\u3044\u305F",suffixes:["\u3067","\u3044","\u305F"],confidence:.85,minStemLength:2}];for(let{pattern:n,suffixes:i,confidence:o,minStemLength:s}of t)if(e.endsWith(n)){let a=e.slice(0,-n.length);if(a.length<s)continue;return ce(a,o,{removedSuffixes:i,conjugationType:"compound"})}return null}},qn=new X;var _={code:"ja",name:"Japanese",nativeName:"\u65E5\u672C\u8A9E",direction:"ltr",wordOrder:"SOV",markingStrategy:"particle",usesSpaces:!1,defaultVerbForm:"base",verb:{position:"end",suffixes:["\u308B","\u3066","\u305F","\u307E\u3059","\u306A\u3044"],subjectDrop:!0},references:{me:"\u81EA\u5206",it:"\u305D\u308C",you:"\u3042\u306A\u305F",result:"\u7D50\u679C",event:"\u30A4\u30D9\u30F3\u30C8",target:"\u30BF\u30FC\u30B2\u30C3\u30C8",body:"\u30DC\u30C7\u30A3"},possessive:{marker:"\u306E",markerPosition:"between",keywords:{\u79C1\u306E:"me",\u3042\u306A\u305F\u306E:"you",\u305D\u306E:"it"}},roleMarkers:{patient:{primary:"\u3092",position:"after"},destination:{primary:"\u306B",alternatives:["\u3078","\u3067","\u306E"],position:"after"},source:{primary:"\u304B\u3089",position:"after"},style:{primary:"\u3067",position:"after"},event:{primary:"\u3092",position:"after"}},keywords:{toggle:{primary:"\u5207\u308A\u66FF\u3048",alternatives:["\u5207\u308A\u66FF\u3048\u308B","\u30C8\u30B0\u30EB","\u30C8\u30B0\u30EB\u3059\u308B"],normalized:"toggle"},add:{primary:"\u8FFD\u52A0",alternatives:["\u8FFD\u52A0\u3059\u308B","\u52A0\u3048\u308B"],normalized:"add"},remove:{primary:"\u524A\u9664",alternatives:["\u524A\u9664\u3059\u308B","\u53D6\u308A\u9664\u304F"],normalized:"remove"},put:{primary:"\u7F6E\u304F",alternatives:["\u5165\u308C\u308B","\u30BB\u30C3\u30C8"],normalized:"put"},append:{primary:"\u672B\u5C3E\u8FFD\u52A0",alternatives:["\u672B\u5C3E\u306B\u8FFD\u52A0","\u30A2\u30DA\u30F3\u30C9"],normalized:"append"},prepend:{primary:"\u5148\u982D\u8FFD\u52A0",alternatives:["\u5148\u982D\u306B\u8FFD\u52A0","\u30D7\u30EA\u30DA\u30F3\u30C9"],normalized:"prepend"},take:{primary:"\u53D6\u308B",normalized:"take"},make:{primary:"\u4F5C\u308B",alternatives:["\u4F5C\u6210"],normalized:"make"},clone:{primary:"\u8907\u88FD",alternatives:["\u30AF\u30ED\u30FC\u30F3"],normalized:"clone"},swap:{primary:"\u4EA4\u63DB",alternatives:["\u30B9\u30EF\u30C3\u30D7","\u5165\u308C\u66FF\u3048"],normalized:"swap"},morph:{primary:"\u5909\u5F62",alternatives:["\u30E2\u30FC\u30D5","\u5909\u63DB"],normalized:"morph"},set:{primary:"\u8A2D\u5B9A",alternatives:["\u8A2D\u5B9A\u3059\u308B","\u30BB\u30C3\u30C8"],normalized:"set"},get:{primary:"\u53D6\u5F97",alternatives:["\u53D6\u5F97\u3059\u308B","\u30B2\u30C3\u30C8"],normalized:"get"},increment:{primary:"\u5897\u52A0",alternatives:["\u5897\u3084\u3059","\u30A4\u30F3\u30AF\u30EA\u30E1\u30F3\u30C8"],normalized:"increment"},decrement:{primary:"\u6E1B\u5C11",alternatives:["\u6E1B\u3089\u3059","\u30C7\u30AF\u30EA\u30E1\u30F3\u30C8"],normalized:"decrement"},log:{primary:"\u8A18\u9332",alternatives:["\u30ED\u30B0","\u51FA\u529B"],normalized:"log"},show:{primary:"\u8868\u793A",alternatives:["\u8868\u793A\u3059\u308B","\u898B\u305B\u308B"],normalized:"show"},hide:{primary:"\u96A0\u3059",alternatives:["\u975E\u8868\u793A","\u975E\u8868\u793A\u306B\u3059\u308B"],normalized:"hide"},transition:{primary:"\u9077\u79FB",alternatives:["\u30C8\u30E9\u30F3\u30B8\u30B7\u30E7\u30F3","\u30A2\u30CB\u30E1\u30FC\u30B7\u30E7\u30F3"],normalized:"transition"},on:{primary:"\u3067",alternatives:["\u6642","\u3068\u304D"],normalized:"on"},trigger:{primary:"\u5F15\u304D\u91D1",alternatives:["\u767A\u706B","\u30C8\u30EA\u30AC\u30FC"],normalized:"trigger"},send:{primary:"\u9001\u308B",alternatives:["\u9001\u4FE1"],normalized:"send"},focus:{primary:"\u30D5\u30A9\u30FC\u30AB\u30B9",alternatives:["\u96C6\u4E2D"],normalized:"focus"},blur:{primary:"\u307C\u304B\u3057",alternatives:["\u30D5\u30A9\u30FC\u30AB\u30B9\u89E3\u9664"],normalized:"blur"},go:{primary:"\u79FB\u52D5",alternatives:["\u884C\u304F","\u30CA\u30D3\u30B2\u30FC\u30C8"],normalized:"go"},wait:{primary:"\u5F85\u3064",alternatives:["\u5F85\u6A5F"],normalized:"wait"},fetch:{primary:"\u53D6\u5F97",alternatives:["\u30D5\u30A7\u30C3\u30C1"],normalized:"fetch"},settle:{primary:"\u5B89\u5B9A",alternatives:["\u843D\u3061\u7740\u304F"],normalized:"settle"},if:{primary:"\u3082\u3057",alternatives:["\u6761\u4EF6"],normalized:"if"},when:{primary:"\u3068\u304D",normalized:"when"},where:{primary:"\u3069\u3053",normalized:"where"},else:{primary:"\u305D\u3046\u3067\u306A\u3051\u308C\u3070",alternatives:["\u305D\u308C\u4EE5\u5916"],normalized:"else"},repeat:{primary:"\u7E70\u308A\u8FD4\u3057",alternatives:["\u7E70\u308A\u8FD4\u3059","\u30EA\u30D4\u30FC\u30C8"],normalized:"repeat"},for:{primary:"\u305F\u3081\u306B",alternatives:["\u5404"],normalized:"for"},while:{primary:"\u306E\u9593",alternatives:["\u9593"],normalized:"while"},continue:{primary:"\u7D9A\u3051\u308B",alternatives:["\u7D99\u7D9A"],normalized:"continue"},halt:{primary:"\u505C\u6B62",alternatives:["\u6B62\u3081\u308B","\u30CF\u30EB\u30C8"],normalized:"halt"},throw:{primary:"\u6295\u3052\u308B",alternatives:["\u30B9\u30ED\u30FC"],normalized:"throw"},call:{primary:"\u547C\u3073\u51FA\u3057",alternatives:["\u30B3\u30FC\u30EB","\u547C\u3076"],normalized:"call"},return:{primary:"\u623B\u308B",alternatives:["\u8FD4\u3059","\u30EA\u30BF\u30FC\u30F3"],normalized:"return"},then:{primary:"\u305D\u308C\u304B\u3089",alternatives:["\u6B21\u306B","\u305D\u3057\u3066"],normalized:"then"},and:{primary:"\u305D\u3057\u3066",alternatives:["\u3068","\u307E\u305F"],normalized:"and"},end:{primary:"\u7D42\u308F\u308A",alternatives:["\u7D42\u4E86","\u304A\u308F\u308A"],normalized:"end"},js:{primary:"JS\u5B9F\u884C",alternatives:["js"],normalized:"js"},async:{primary:"\u975E\u540C\u671F",alternatives:["\u30A2\u30B7\u30F3\u30AF"],normalized:"async"},tell:{primary:"\u4F1D\u3048\u308B",alternatives:["\u30C6\u30EB"],normalized:"tell"},default:{primary:"\u65E2\u5B9A",alternatives:["\u30C7\u30D5\u30A9\u30EB\u30C8"],normalized:"default"},init:{primary:"\u521D\u671F\u5316",alternatives:["\u30A4\u30CB\u30C3\u30C8"],normalized:"init"},behavior:{primary:"\u632F\u308B\u821E\u3044",alternatives:["\u30D3\u30D8\u30A4\u30D3\u30A2"],normalized:"behavior"},install:{primary:"\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB",alternatives:["\u5C0E\u5165"],normalized:"install"},measure:{primary:"\u6E2C\u5B9A",alternatives:["\u8A08\u6E2C","\u30E1\u30B8\u30E3\u30FC"],normalized:"measure"},into:{primary:"\u3078",alternatives:["\u306B"],normalized:"into"},before:{primary:"\u524D\u306B",alternatives:["\u524D"],normalized:"before"},after:{primary:"\u5F8C\u306B",alternatives:["\u5F8C"],normalized:"after"},until:{primary:"\u307E\u3067",alternatives:["\u8FC4"],normalized:"until"},event:{primary:"\u30A4\u30D9\u30F3\u30C8",alternatives:["\u4E8B\u8C61"],normalized:"event"},from:{primary:"\u304B\u3089",normalized:"from"}},tokenization:{particles:["\u3092","\u306B","\u3067","\u304B\u3089","\u306E","\u304C","\u306F","\u3082","\u3078","\u3068"],boundaryStrategy:"particle"},eventHandler:{eventMarker:{primary:"\u3067",position:"after"},temporalMarkers:["\u6642","\u3068\u304D"]}};var bt=G([[12352,12447]]),kt=G([[12448,12543]]),Nt=G([[19968,40959],[13312,19903]]),Ge=ve(bt,kt,Nt),Ct=new Set(["\u3092","\u306B","\u3067","\u304B\u3089","\u307E\u3067","\u3078","\u3068","\u306E","\u304C","\u306F","\u3082","\u3088\u308A"]),Xe=new Set(["\u3092","\u306B","\u3067","\u3078","\u3068","\u306E","\u304C","\u306F","\u3082"]),Ze=["\u304B\u3089","\u307E\u3067","\u3088\u308A"],Qe=new Map([["\u3092",{role:"patient",confidence:.95,description:"object marker"}],["\u306B",{role:"destination",confidence:.85,description:"destination/time marker"}],["\u3067",{role:"manner",confidence:.88,description:"means/location marker"}],["\u304B\u3089",{role:"source",confidence:.9,description:"from/source marker"}],["\u307E\u3067",{role:"destination",confidence:.75,description:"until/boundary marker"}],["\u3078",{role:"destination",confidence:.9,description:"direction marker"}],["\u3068",{role:"style",confidence:.7,description:"with/and marker"}],["\u306E",{role:"destination",confidence:.75,description:"possessive/destination marker"}],["\u304C",{role:"agent",confidence:.85,description:"subject marker"}],["\u306F",{role:"agent",confidence:.75,description:"topic marker"}],["\u3082",{role:"patient",confidence:.65,description:"also/too marker"}],["\u3088\u308A",{role:"source",confidence:.85,description:"from/than marker"}]]),wt=[{native:"\u771F",normalized:"true"},{native:"\u507D",normalized:"false"},{native:"\u30CC\u30EB",normalized:"null"},{native:"\u672A\u5B9A\u7FA9",normalized:"undefined"},{native:"\u6700\u521D",normalized:"first"},{native:"\u6700\u5F8C",normalized:"last"},{native:"\u6B21",normalized:"next"},{native:"\u524D",normalized:"previous"},{native:"\u6700\u3082\u8FD1\u3044",normalized:"closest"},{native:"\u89AA",normalized:"parent"},{native:"\u30AF\u30EA\u30C3\u30AF",normalized:"click"},{native:"\u5909\u66F4",normalized:"change"},{native:"\u9001\u4FE1",normalized:"submit"},{native:"\u5165\u529B",normalized:"input"},{native:"\u30ED\u30FC\u30C9",normalized:"load"},{native:"\u30B9\u30AF\u30ED\u30FC\u30EB",normalized:"scroll"},{native:"\u30AD\u30FC\u30C0\u30A6\u30F3",normalized:"keydown"},{native:"\u30AD\u30FC\u30A2\u30C3\u30D7",normalized:"keyup"},{native:"\u30DE\u30A6\u30B9\u30AA\u30FC\u30D0\u30FC",normalized:"mouseover"},{native:"\u30DE\u30A6\u30B9\u30A2\u30A6\u30C8",normalized:"mouseout"},{native:"\u30D6\u30E9\u30FC",normalized:"blur"},{native:"\u79C1",normalized:"me"},{native:"\u79C1\u306E",normalized:"my"},{native:"\u305D\u306E",normalized:"its"},{native:"\u3057\u305F\u3089",normalized:"on"},{native:"\u3059\u308B\u3068",normalized:"on"},{native:"\u6642\u306B",normalized:"on"},{native:"\u3082\u3057",normalized:"if"},{native:"\u306A\u3089\u3070",normalized:"then"},{native:"\u306A\u3089",normalized:"then"},{native:"\u305D\u308C\u304B\u3089",normalized:"then"},{native:"\u305D\u3057\u3066",normalized:"and"},{native:"\u79D2",normalized:"s"},{native:"\u30DF\u30EA\u79D2",normalized:"ms"},{native:"\u5206",normalized:"m"},{native:"\u6642\u9593",normalized:"h"}],Rt=[{pattern:"\u30DF\u30EA\u79D2",suffix:"ms",length:3},{pattern:"\u6642\u9593",suffix:"h",length:2},{pattern:"\u79D2",suffix:"s",length:1},{pattern:"\u5206",suffix:"m",length:1}],Te=class extends H{constructor(){super();this.language="ja";this.direction="ltr";this.initializeKeywordsFromProfile(_,wt),this.normalizer=new X}tokenize(t){let n=[],i=0;for(;i<t.length;){if(I(t[i])){i++;continue}if(oe(t[i])){let a=this.tryEventModifier(t,i);if(a){n.push(a),i=a.position.end;continue}let l=this.trySelector(t,i);if(l){n.push(l),i=l.position.end;continue}}if(ae(t[i])){let a=this.tryString(t,i);if(a){n.push(a),i=a.position.end;continue}}if(se(t,i)){let a=this.tryUrl(t,i);if(a){n.push(a),i=a.position.end;continue}}if(C(t[i])){let a=this.extractJapaneseNumber(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.tryMultiCharParticle(t,i,Ze);if(s){let a=Qe.get(s.value);a?n.push({...s,metadata:{particleRole:a.role,particleConfidence:a.confidence}}):n.push(s),i=s.position.end;continue}if(Xe.has(t[i])){let a=this.tryProfileKeyword(t,i);if(a&&a.value.length>1){n.push(a),i=a.position.end;continue}let l=t[i],c=Qe.get(l);c?n.push({...v(l,"particle",S(i,i+1)),metadata:{particleRole:c.role,particleConfidence:c.confidence}}):n.push(v(l,"particle",S(i,i+1))),i++;continue}if(Ge(t[i])){let a=this.extractJapaneseWord(t,i);if(a){n.push(a),i=a.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,"ja")}classifyToken(t){return Ct.has(t)?"particle":this.isKeyword(t)?"keyword":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")?"selector":t.startsWith('"')||t.startsWith("'")||t.startsWith("\u300C")||/^\d/.test(t)?"literal":"identifier"}extractJapaneseWord(t,n){let i=n,o="";for(;i<t.length;){let l=t[i];if(Xe.has(l)&&o.length>0)break;let c=!1;for(let p of Ze)if(t.slice(i,i+p.length)===p&&o.length>0){c=!0;break}if(c)break;if(Ge(l))o+=l,i++;else break}if(!o)return null;let s=this.lookupKeyword(o);if(s)return v(o,"keyword",S(n,i),s.normalized);let a=this.tryMorphKeywordMatch(o,n,i);return a||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}extractJapaneseNumber(t,n){return this.tryNumberWithTimeUnits(t,n,Rt,{allowSign:!1,skipWhitespace:!1})}},le=new Te;Oe("ja",le,_);function Je(r){return Ie(r)}function ue(r,e){return Be(r,e)}function de(){return re()}function M(r){let e="complex";return r.startsWith("#")&&!r.includes(" ")?e="id":r.startsWith(".")&&!r.includes(" ")?e="class":r.startsWith("[")&&r.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(r)&&(e="element"),{type:"selector",value:r,selectorKind:e}}function T(r,e){let t={type:"literal",value:r};return e!==void 0?{type:"literal",value:r,dataType:e}:t}function R(r){return{type:"reference",value:r}}function $(r,e){return{type:"property-path",object:r,property:e}}function A(r,e,t){let n={kind:"command",action:r,roles:new Map(Object.entries(e))};return t!==void 0?{...n,metadata:t}:n}function U(r,e,t,n,i){let o=new Map;o.set("event",r);let 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 Ye(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 et(r,e){return r.possessive?.keywords?.[e]}var P=class P{constructor(){this.stemMatchCount=0;this.totalKeywordMatches=0}matchPattern(e,t){let n=e.mark(),i=new Map;if(this.currentProfile=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){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 l=this.tryMatchPropertyAccessExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(l.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(n.set(t.role,l),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(c.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,c),!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=et(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(),$(R(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<P.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}a.push(c.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<P.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),s+=`.${p.value}`,a++}let l=e.peek();if(l&&l.kind==="punctuation"&&l.value==="("){e.advance();let c=[],p=0;for(;!e.isAtEnd()&&c.length<P.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}c.push(y.value),e.advance()}return{type:"expression",raw:`${s}(${c.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(),$(M(t.value),o.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let n=e.mark();e.advance();let i=e.peek();if(!i||i.kind!=="selector"||!i.value.startsWith("."))return e.reset(n),null;let o=e.peek(1);o&&o.kind,e.advance();let s=i.value.slice(1);return $(M(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 M(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return["me","you","it","result","event","target","body"].includes(t)?R(t):T(e.normalized||e.value);case"identifier":if(e.value.startsWith(":"))return R(e.value);let n=e.value.toLowerCase();return["me","you","it","result","event","target","body"].includes(n)?R(n):{type:"expression",raw:e.value};case"url":return 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=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")i+=1,t.has(c.role)&&(n+=1);else if(c.type==="group"){for(let p of c.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 c=this.stemMatchCount/this.totalKeywordMatches*.15;s=Math.max(.5,s-c)}let a=this.calculateVSOConfidenceBoost(e);s=Math.min(1,s+a);let l=this.arabicPrepositionDisambiguation(e,t);return s=Math.max(0,Math.min(1,s+l)),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 l=s.metadata;if(l&&typeof l.prepositionValue=="string"){let c=l.prepositionValue;a.includes(c)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){let t=e.peek();if(!t)return;let n=t.value.toLowerCase();if(P.ENGLISH_NOISE_WORDS.has(n)){let i=e.mark();e.advance();let o=e.peek();if(o&&o.kind==="selector")return;e.reset(i)}n==="class"&&e.advance()}extractEventModifiers(e){let t={},n=!1;for(;!e.isAtEnd();){let i=e.peek();if(!i||i.kind!=="event-modifier")break;let o=i.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":typeof o.value=="number"&&(t.debounce=o.value);break;case"throttle":typeof o.value=="number"&&(t.throttle=o.value);break;case"queue":(o.value==="first"||o.value==="last"||o.value==="all"||o.value==="none")&&(t.queue=o.value);break}e.advance()}return n?t:void 0}};P.MAX_PROPERTY_DEPTH=10,P.MAX_METHOD_ARGS=20,P.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Z=P,B=new Z;var pe=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);let n=Ke(t,e.action);if(n.length===0)return this.renderExplicit(e);let i=this.findBestPattern(e,n);return i?this.renderWithPattern(e,i):this.renderExplicit(e)}renderCompound(e,t){let n=e.statements.map(o=>this.render(o,t)),i=this.getChainWord(e.chainType,t);return n.join(` ${i} `)}getChainWord(e,t){let n=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:l,usePossessiveAdjectives:c}=n.possessive;return c&&l==="after-object"?`${i} ${a}`:`${a} ${i}`}}let s=this.valueToNaturalString(e.object,t);if(n?.possessive){let{marker:a,markerPosition:l,usePossessiveAdjectives:c}=n.possessive;if(c&&o&&l==="after-object")return`${i} ${s}`;if(a)switch(l){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}`}},be=new pe;function Q(r,e){return be.render(r,e)}function J(r){return be.renderExplicit(r)}function K(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 l=n[a],c=l.indexOf(":");if(c===-1)throw new Error(`Invalid role format: "${l}". Expected role:value`);let p=l.slice(0,c),x=l.slice(c+1);if(p==="body"&&x.startsWith("[")){let h=Mt(l,c+1),d=l.slice(c+1,h+1);o.set(p,{type:"expression",raw:d});continue}let y=Lt(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 l=o.get("body"),c=[];return l&&l.type==="expression"&&c.push(K(l.raw)),o.delete("body"),U(a,c,void 0,{sourceLanguage:"explicit"})}let s={};for(let[a,l]of o)s[a]=l;return A(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 Lt(r){if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return M(r);if(r.startsWith('"')||r.startsWith("'")){let t=r.slice(1,-1);return 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 R(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 Mt(r,e){let t=0;for(let n=e;n<r.length;n++)if(r[n]==="[")t++;else if(r[n]==="]"&&(t--,t===0))return n;return r.length-1}function F(r){let e=r.trim();return e.startsWith("[")&&e.endsWith("]")}var me=class{parse(e,t){let n=ue(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=B.matchBest(n,s);if(a)return this.buildEventHandler(a,n,t);let l=o.filter(p=>p.command!=="on"),c=B.matchBest(n,l);if(c)return this.buildCommand(c,t);throw new Error(`Could not parse input in ${t}: ${e}`)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return 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 A(e.pattern.command,n,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}buildEventHandler(e,t,n){if(!e)throw new Error("No match to build event handler from");let i=e.captured.get("event");if(!i)throw new Error("Event handler pattern matched but no event captured");let o=B.extractEventModifiers(t),s,a=e.captured.get("action");if(a&&a.type==="literal"){let l=a.value,c={};for(let[y,h]of e.captured)y!=="event"&&y!=="action"&&y!=="continues"&&(c[y]=h);let p=A(l,c,{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,g)=>g.priority-m.priority),h=N(n).filter(m=>m.id.startsWith("grammar-")&&m.id.includes("-continuation")).sort((m,g)=>g.priority-m.priority),d=this.parseBodyWithGrammarPatterns(t,y,h,n);d.length>0?s=[p,...d]:s=[p]}else s=[p]}else{let l=N(n).filter(c=>c.command!=="on").sort((c,p)=>p.priority-c.priority);s=this.parseBodyWithClauses(t,l,n)}return U(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),l=s.kind==="keyword"&&this.isEndKeyword(s.value,n);if(a){if(o.length>0){let c=this.parseClause(o,t,n);i.push(...c),o.length=0}e.advance();continue}if(l){if(o.length>0){let c=this.parseClause(o,t,n);i.push(...c)}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?[Ye(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=B.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 l=B.matchBest(e,n);if(l){let c=l.pattern.command,p={};for(let[h,d]of l.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(p[h]=d);let x=A(c,p,{sourceLanguage:i,patternId:l.pattern.id});o.push(x),a=!0;let y=l.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!a){let l=B.matchBest(e,t);l&&(o.push(this.buildCommand(l,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())}},ke=new me;function q(r,e){return ke.parse(r,e)}function Ne(r,e){return ke.canParse(r,e)}function Ce(r,e){if(F(r))return r;let t=q(r,e);return J(t)}function we(r,e){let t=K(r);return Q(t,e)}function Re(r,e){return F(r)?K(r):q(r,e)}var At=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),zt=new Set(["and","or","not","no"]),Vt=new Set(["true","false","null","undefined"]),jt=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function tt(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 l(){for(;t<r.length&&/\s/.test(r[t]);)a()}function c(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 h(d,m,g){return{type:d,value:m,start:g,end:t,line:n,column:i-m.length}}for(;t<r.length&&(l(),!(t>=r.length));){let d=t,m=s();if(m==="'"&&s(1)==="s"&&!/\w/.test(s(2))){a(),a(),e.push(h("POSSESSIVE","'s",d));continue}if(m==='"'||m==="'"){let g=p(m);e.push(h("STRING",g,d));continue}if(m==="`"){let g=x();e.push(h("TEMPLATE_LITERAL",g,d));continue}if(m==="<"&&/[a-zA-Z.#\[]/.test(s(1))){let g=y();e.push(h("QUERY_SELECTOR",g,d));continue}if(m==="#"&&o()){a();let g=c(E=>/[\w-]/.test(E));e.push(h("ID_SELECTOR","#"+g,d));continue}if(m==="."&&/[a-zA-Z_-]/.test(s(1))&&o()){a();let g=c(E=>/[\w-]/.test(E));e.push(h("CLASS_SELECTOR","."+g,d));continue}if(m==="["&&o()){let g=s(1);if(g==="@"||/[a-zA-Z]/.test(g)){let E="";for(E+=a();t<r.length&&r[t]!=="]";)r[t]==='"'||r[t]==="'"?E+=p(r[t]):E+=a();t<r.length&&(E+=a()),e.push(h("ATTRIBUTE_SELECTOR",E,d));continue}}if(m==="["){a(),e.push(h("LBRACKET","[",d));continue}if(m==="]"){a(),e.push(h("RBRACKET","]",d));continue}if(/\d/.test(m)){let g=c(ge=>/[\d.]/.test(ge)),E=t,ne=c(ge=>/[a-zA-Z]/.test(ge));jt.has(ne)?e.push(h("TIME_EXPRESSION",g+ne,d)):(t=E,e.push(h("NUMBER",g,d)));continue}if(m==="("){a(),e.push(h("LPAREN","(",d));continue}if(m===")"){a(),e.push(h("RPAREN",")",d));continue}if(m==="{"){a(),e.push(h("LBRACE","{",d));continue}if(m==="}"){a(),e.push(h("RBRACE","}",d));continue}if(m===","){a(),e.push(h("COMMA",",",d));continue}if(m===":"){a(),e.push(h("COLON",":",d));continue}if(m==="."){a(),e.push(h("DOT",".",d));continue}if(m==="+"||m==="-"||m==="*"||m==="/"||m==="%"){a(),e.push(h("OPERATOR",m,d));continue}if(m==="="||m==="!"||m==="<"||m===">"){let g=a();s()==="="&&(g+=a()),e.push(h("COMPARISON",g,d));continue}if(/[a-zA-Z_$]/.test(m)){let g=c(ne=>/[\w$]/.test(ne)),E=g.toLowerCase();At.has(E)?e.push(h("CONTEXT_VAR",g,d)):zt.has(E)?e.push(h("LOGICAL",g,d)):Vt.has(E)?e.push(h("BOOLEAN",g,d)):e.push(h("IDENTIFIER",g,d));continue}a()}return e.push(h("EOF","",t)),e}var fe=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=tt(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 fe().parse(r)}function k(r,e){switch(r.type){case"literal":return Ot(r);case"selector":return It(r,e);case"reference":return _t(r);case"property-path":return Bt(r,e);case"expression":return Kt(r);default:let t=r;throw new Error(`Unknown semantic value type: ${t.type}`)}}function Ot(r){let e={type:"literal",value:r.value};return r.dataType?{...e,dataType:r.dataType}:e}function It(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 _t(r){return{type:"contextReference",contextType:r.value,name:r.value}}function Bt(r,e){return{type:"propertyAccess",object:k(r.object,e),property:r.property}}function Kt(r){let e=Pe(r.raw);return!e.success||!e.node?{type:"identifier",name:r.raw}:e.node}function nt(r,e){return r.roles.get(e)}function u(r,e,t){let n=nt(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 Wt={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)}},$t={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)}},Ut={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)}},Ft={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)}},qt={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)}},Dt={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)}},Ht={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)}},Gt={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)}},Xt={action:"wait",toAST(r,e){let t=u(r,"duration");return f("wait",t?[t]:[],void 0,{isBlocking:!0})}},Zt={action:"log",toAST(r,e){let t=u(r,"patient"),n=[];return t&&n.push(t),f("log",n)}},Qt={action:"put",toAST(r,e){let t=u(r,"patient"),n=u(r,"destination"),i=nt(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)}},Jt={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})}},Yt={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)}},en={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)}},tn={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)}},nn={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)}},rn={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)}},on={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)}},an={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)}},sn={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)}},cn={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)}},ln={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)}},un={action:"call",toAST(r,e){let t=u(r,"patient");return f("call",t?[t]:[])}},dn={action:"return",toAST(r,e){let t=u(r,"patient");return f("return",t?[t]:[])}},pn={action:"halt",toAST(r,e){return f("halt",[])}},mn={action:"throw",toAST(r,e){let t=u(r,"patient");return f("throw",t?[t]:[])}},fn={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})}},gn={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)}},hn={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)}},yn={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)}},xn={action:"make",toAST(r,e){let t=u(r,"patient");return f("make",t?[t]:[])}},Sn={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)}},vn={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)}},Tn={action:"js",toAST(r,e){let t=u(r,"patient");return f("js",t?[t]:[])}},En={action:"async",toAST(r,e){return f("async",[])}},bn={action:"if",toAST(r,e){let t=u(r,"condition");return f("if",t?[t]:[])}},kn={action:"unless",toAST(r,e){let t=u(r,"condition");return f("unless",t?[t]:[])}},Nn={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)}},Cn={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)}},wn={action:"while",toAST(r,e){let t=u(r,"condition");return f("while",t?[t]:[])}},Rn={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)}},Ln={action:"init",toAST(r,e){return f("init",[])}},Mn={action:"behavior",toAST(r,e){let t=u(r,"patient");return f("behavior",t?[t]:[])}},An={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)}},zn={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)}},rt=new Map([["toggle",Wt],["add",$t],["remove",Ut],["set",Ft],["show",qt],["hide",Dt],["increment",Ht],["decrement",Gt],["wait",Xt],["log",Zt],["put",Qt],["fetch",Jt],["append",Yt],["prepend",en],["get",cn],["take",ln],["trigger",tn],["send",nn],["on",zn],["go",rn],["transition",on],["focus",an],["blur",sn],["call",un],["return",dn],["halt",pn],["throw",mn],["settle",fn],["swap",gn],["morph",hn],["clone",yn],["measure",Sn],["make",xn],["tell",vn],["default",Pn],["js",Tn],["async",En],["if",bn],["unless",kn],["repeat",Nn],["for",Cn],["while",wn],["continue",Rn],["init",Ln],["behavior",Mn],["install",An]]);function Y(r){return rt.get(r)}function Le(r){rt.set(r.action,r)}var ee=class{constructor(e={}){this.warnings=[]}build(e){switch(e.kind){case"command":return this.buildCommand(e);case"event-handler":return this.buildEventHandler(e);case"conditional":return this.buildConditional(e);case"compound":return this.buildCompound(e);case"loop":return this.buildLoop(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildCommand(e){let t=Y(e.action);if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let i=n;return this.warnings.push(...i.warnings),i.ast}else return n}return this.buildGenericCommand(e)}buildGenericCommand(e){let t=[],n={},i=["patient","source","quantity"],o=["destination","duration","method","style"];for(let a of i){let l=e.roles.get(a);l&&t.push(k(l))}for(let a of o){let l=e.roles.get(a);if(l){let c=this.roleToModifierKey(a);n[c]=k(l)}}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 g=String(t.value);g.includes("|")||g.includes(" or ")?(i=g.split(/\s+or\s+|\|/).map(E=>E.trim()),n=i[0]):n=g}else t?.type==="reference"?n=t.value:n="click";let o=e.body.map(g=>this.build(g)),s=e.roles.get("source"),a,l;s?.type==="selector"?(a=s.value,l=s.value):s?.type==="reference"?l=s.value:s?.type==="literal"&&(l=String(s.value));let c=e.roles.get("condition"),p=c?k(c):void 0,x=e.roles.get("destination"),y=x?k(x):void 0,h=e.eventModifiers,d=a;if(h?.from){let g=h.from;g.type==="selector"&&!a&&(d=g.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}:{},...l?{target:l}:{},...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 it(r){let e=new ee;return{ast:e.build(r),warnings:e.warnings}}var W=class{constructor(e={}){this.cache=new Map,this.config={maxSize:e.maxSize??1e3,ttlMs:e.ttlMs??0,enabled:e.enabled??!0},this.stats={hits:0,misses:0,evictions:0,expirations:0}}makeKey(e,t){return`${t}:${e}`}isExpired(e){return this.config.ttlMs===0?!1:Date.now()-e.createdAt>this.config.ttlMs}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}get(e,t){if(!this.config.enabled){this.stats.misses++;return}let n=this.makeKey(e,t),i=this.cache.get(n);if(!i){this.stats.misses++;return}if(this.isExpired(i)){this.cache.delete(n),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(n),i.lastAccessed=Date.now(),this.cache.set(n,i),this.stats.hits++,i.result}set(e,t,n){if(!this.config.enabled||n.confidence===0)return;let i=this.makeKey(e,t),o=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(i,{result:n,createdAt:o,lastAccessed:o})}has(e,t){if(!this.config.enabled)return!1;let n=this.makeKey(e,t),i=this.cache.get(n);return i?this.isExpired(i)?(this.cache.delete(n),this.stats.expirations++,!1):!0:!1}delete(e,t){let n=this.makeKey(e,t);return this.cache.delete(n)}clear(){this.cache.clear()}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0}}getStats(){let e=this.stats.hits+this.stats.misses;return{hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:e>0?this.stats.hits/e:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(e){if(e.maxSize!==void 0)for(this.config.maxSize=e.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();e.ttlMs!==void 0&&(this.config.ttlMs=e.ttlMs),e.enabled!==void 0&&(this.config.enabled=e.enabled)}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}getConfig(){return{...this.config}}},Me=new W;var te=class{constructor(e={}){this.patternMatcher=new Z,this.languages=new Set(re()),e.cache===!1?this.cache=new W({enabled:!1}):this.cache=e.cache?new W(e.cache):Me}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=Je(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 ot(r){return new te(r)}var Ae=.5,at=.8;function st(r,e=Ae){return r.confidence>=e&&r.command!==void 0}var Vn="1.0.0-ja",jn=["ja"];function On(){return[...jn]}function ct(r){if(r!=="ja")throw new Error(`Language not supported in this bundle: ${r}. Supported: ja`)}function In(r,e){return ct(e),[...ue(r,e).tokens]}function lt(r){return ct(r),N(r)}function _n(r,e){return lt(r).filter(t=>t.command===e).sort((t,n)=>n.priority-t.priority)}return gt(Bn);})();