@lokascript/semantic 2.6.0 → 2.7.1

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 (40) hide show
  1. package/dist/browser-ar.ar.global.js +5 -5
  2. package/dist/browser-bn.bn.global.js +4 -4
  3. package/dist/browser-de.de.global.js +4 -4
  4. package/dist/browser-east-asian.east-asian.global.js +3 -3
  5. package/dist/browser-en-tr.en-tr.global.js +4 -4
  6. package/dist/browser-es.es.global.js +4 -4
  7. package/dist/browser-fr.fr.global.js +3 -3
  8. package/dist/browser-hi.hi.global.js +3 -3
  9. package/dist/browser-id.id.global.js +4 -4
  10. package/dist/browser-it.it.global.js +3 -3
  11. package/dist/browser-ja.ja.global.js +4 -4
  12. package/dist/browser-ko.ko.global.js +5 -5
  13. package/dist/browser-lazy.lazy.global.js +1 -1
  14. package/dist/browser-ms.ms.global.js +4 -4
  15. package/dist/browser-pl.pl.global.js +4 -4
  16. package/dist/browser-priority.priority.global.js +1 -1
  17. package/dist/browser-qu.qu.global.js +5 -5
  18. package/dist/browser-ru.ru.global.js +5 -5
  19. package/dist/browser-sw.sw.global.js +4 -4
  20. package/dist/browser-th.th.global.js +3 -3
  21. package/dist/browser-tl.tl.global.js +4 -4
  22. package/dist/browser-tr.tr.global.js +4 -4
  23. package/dist/browser-uk.uk.global.js +5 -5
  24. package/dist/browser-vi.vi.global.js +3 -3
  25. package/dist/browser.global.js +22 -22
  26. package/dist/browser.global.js.map +1 -1
  27. package/dist/generators/index.d.ts +1 -0
  28. package/dist/generators/index.d.ts.map +1 -1
  29. package/dist/generators/profile-queries.d.ts +32 -0
  30. package/dist/generators/profile-queries.d.ts.map +1 -0
  31. package/dist/index.cjs +19 -0
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +17 -0
  36. package/dist/index.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/generators/index.ts +3 -0
  39. package/src/generators/profile-queries.ts +53 -0
  40. package/src/index.ts +4 -0
@@ -1,6 +1,6 @@
1
- "use strict";var LokaScriptSemanticQu=(()=>{var mt=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var jr=Object.getOwnPropertyNames;var Wr=Object.prototype.hasOwnProperty;var Kr=(o,e)=>{for(var t in e)mt(o,t,{get:e[t],enumerable:!0})},Ur=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of jr(e))!Wr.call(o,n)&&n!==t&&mt(o,n,{get:()=>e[n],enumerable:!(r=Dr(e,n))||r.enumerable});return o};var Fr=o=>Ur(mt({},"__esModule",{value:!0}),o);var si={};Kr(si,{ASTBuilder:()=>Oe,DEFAULT_CONFIDENCE_THRESHOLD:()=>Ut,HIGH_CONFIDENCE_THRESHOLD:()=>Ft,VERSION:()=>ri,buildAST:()=>Yt,canParse:()=>Dt,createCommandNode:()=>H,createEventHandler:()=>me,createLiteral:()=>q,createPropertyPath:()=>ie,createReference:()=>Z,createSelector:()=>re,fromExplicit:()=>Wt,getCommandMapper:()=>Me,getPatternsForLanguage:()=>Br,getPatternsForLanguageAndCommand:()=>ii,getProfile:()=>Ze,getSupportedLanguages:()=>oi,getTokenizer:()=>Ye,isExplicitSyntax:()=>de,isLanguageSupported:()=>St,parse:()=>Ae,parseAny:()=>Kt,parseExplicit:()=>Pe,quechuaProfile:()=>ve,quechuaTokenizer:()=>it,registerCommandMapper:()=>yt,render:()=>Ue,renderExplicit:()=>Fe,toExplicit:()=>jt,tokenize:()=>ai,tryGetProfile:()=>z});var Ut=.5,Ft=.8;var Hr=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Gr=new Set(["and","or","not","no"]),Yr=new Set(["true","false","null","undefined"]),Zr=new Set(["is","matches","match","contains","in"]),Jr=new Set(["next","previous","closest","first","last"]),Xr=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ht(o){let e=[],t=0,r=1,n=1;function a(){if(e.length===0)return!0;let p=e[e.length-1];return p.type==="IDENTIFIER"&&Zr.has(p.value.toLowerCase())||p.type==="IDENTIFIER"&&Jr.has(p.value.toLowerCase())?!0:["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(p.type)}function i(p=0){return o[t+p]??""}function s(){let p=o[t];return t++,p===`
2
- `?(r++,n=1):n++,p}function l(){for(;t<o.length&&/\s/.test(o[t]);)s()}function c(p){let h="";for(;t<o.length&&p(o[t]);)h+=s();return h}function d(p){let h=p;for(s();t<o.length&&o[t]!==p;)o[t]==="\\"&&t+1<o.length&&(h+=s()),h+=s();return t<o.length&&(h+=s()),h}function u(){let p="`";for(s();t<o.length&&o[t]!=="`";)o[t]==="\\"&&t+1<o.length&&(p+=s()),p+=s();return t<o.length&&(p+=s()),p}function f(){let p="<";for(s();t<o.length&&(p+=s(),!p.endsWith("/>")););return p}function m(p,h,y){return{type:p,value:h,start:y,end:t,line:r,column:n-h.length}}for(;t<o.length&&(l(),!(t>=o.length));){let p=t,h=i();if(h==="'"&&i(1)==="s"&&!/\w/.test(i(2))){s(),s(),e.push(m("POSSESSIVE","'s",p));continue}if(h==='"'||h==="'"){let y=d(h);e.push(m("STRING",y,p));continue}if(h==="`"){let y=u();e.push(m("TEMPLATE_LITERAL",y,p));continue}if(h==="<"&&/[a-zA-Z.#\[]/.test(i(1))){let y=f();e.push(m("QUERY_SELECTOR",y,p));continue}if(h==="#"&&a()){s();let y=c(g=>/[\w-]/.test(g));e.push(m("ID_SELECTOR","#"+y,p));continue}if(h==="."&&/[a-zA-Z_-]/.test(i(1))&&a()){s();let y=c(g=>/[\w-]/.test(g));e.push(m("CLASS_SELECTOR","."+y,p));continue}if(h==="@"&&/[a-zA-Z_]/.test(i(1))){s();let y=c(g=>/[\w-]/.test(g));e.push(m("ATTRIBUTE_REF","@"+y,p));continue}if(h==="["&&a()){let y=i(1);if(y==="@"||/[a-zA-Z]/.test(y)){let g="";for(g+=s();t<o.length&&o[t]!=="]";)o[t]==='"'||o[t]==="'"?g+=d(o[t]):g+=s();t<o.length&&(g+=s()),e.push(m("ATTRIBUTE_SELECTOR",g,p));continue}}if(h==="["){s(),e.push(m("LBRACKET","[",p));continue}if(h==="]"){s(),e.push(m("RBRACKET","]",p));continue}if(/\d/.test(h)){let y=c(T=>/[\d.]/.test(T)),g=t,x=c(T=>/[a-zA-Z]/.test(T));Xr.has(x)?e.push(m("TIME_EXPRESSION",y+x,p)):(t=g,e.push(m("NUMBER",y,p)));continue}if(h==="("){s(),e.push(m("LPAREN","(",p));continue}if(h===")"){s(),e.push(m("RPAREN",")",p));continue}if(h==="{"){s(),e.push(m("LBRACE","{",p));continue}if(h==="}"){s(),e.push(m("RBRACE","}",p));continue}if(h===","){s(),e.push(m("COMMA",",",p));continue}if(h===":"){s(),e.push(m("COLON",":",p));continue}if(h==="."){s(),e.push(m("DOT",".",p));continue}if(h==="+"||h==="-"||h==="*"||h==="/"||h==="%"){s(),e.push(m("OPERATOR",h,p));continue}if(h==="="||h==="!"||h==="<"||h===">"){let y=s();i()==="="&&(y+=s()),e.push(m("COMPARISON",y,p));continue}if(/[a-zA-Z_$]/.test(h)){let y=c(x=>/[\w$]/.test(x)),g=y.toLowerCase();Hr.has(g)?e.push(m("CONTEXT_VAR",y,p)):Gr.has(g)?e.push(m("LOGICAL",y,p)):Yr.has(g)?e.push(m("BOOLEAN",y,p)):e.push(m("IDENTIFIER",y,p));continue}s()}return e.push(m("EOF","",t)),e}var Qr=new Set(["my","its","your"]),en=new Set(["is","matches","match","contains","in","exists","does"]),tn=new Set(["next","previous","closest","first","last"]),Ge=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ht(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}}peekAt(e){return this.tokens[this.current+e]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,r=this.parseAnd();e=this.createBinaryExpression(t,e,r)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,r=this.parseEquality();e=this.createBinaryExpression(t,e,r)}return e}parseEquality(){let e=this.parseComparison();for(;;){let t;if(this.match("COMPARISON"))t=this.previous().value;else if(this.checkValue("is")||this.checkValue("matches")||this.checkValue("match")||this.checkValue("contains")||this.checkValue("in")){let n=this.advance().value;t=n.toLowerCase()==="match"?"matches":n}else break;if(t.toLowerCase()==="is"){if(this.checkValue("empty")){this.advance(),e=this.createPostfixUnary("is empty",e);continue}if(this.checkValue("not")&&this.peekAt(1).value.toLowerCase()==="empty"){this.advance(),this.advance(),e=this.createPostfixUnary("is not empty",e);continue}}let r=this.parseComparison();e=this.createBinaryExpression(t,e,r)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,r=this.parseAddition();e=this.createBinaryExpression(t,e,r)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,r=this.parseMultiplication();e=this.createBinaryExpression(t,e,r)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,r=this.parseUnary();e=this.createBinaryExpression(t,e,r)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else if(e.type==="contextReference"&&Qr.has(e.contextType??"")&&this.check("IDENTIFIER")&&!en.has(this.peek().value.toLowerCase())){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else if(this.checkValue("exists")&&this.peekAt(1).type!=="LPAREN")this.advance(),e=this.createPostfixUnary("exists",e);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,r={true:"boolean",false:"boolean",null:"null",undefined:"undefined"};return this.createLiteral(t,r[e.value]??"string",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("ATTRIBUTE_REF"))return{type:"attributeAccess",attributeName:e.value.slice(1),start:e.start,end:e.end};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")){if(tn.has(e.value.toLowerCase())&&(this.check("CLASS_SELECTOR")||this.check("ID_SELECTOR")||this.check("QUERY_SELECTOR"))){let t=this.advance(),r=t.type==="QUERY_SELECTOR"?t.value.slice(1,-2):t.value,n=t.type==="CLASS_SELECTOR"?"class":t.type==="ID_SELECTOR"?"id":"query";return{type:"callExpression",callee:this.createIdentifier(e.value,e),arguments:[this.createSelector(r,n,t)],start:e.start,end:t.end}}return this.createIdentifier(e.value,e)}if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let r;if(this.check("STRING"))r=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))r=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let n=this.parseExpression();e.push({key:r,value:n})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(r=>({type:"objectProperty",key:r.key,value:r.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let r=parseFloat(t[1]),n=t[2].toLowerCase();return{type:"timeExpression",value:r,unit:n,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,r){return{type:"literal",value:e,dataType:t,raw:r.value,start:r.start,end:r.end,line:r.line,column:r.column}}createSelector(e,t,r){return{type:"selector",value:e,selector:e,selectorType:t,start:r.start,end:r.end,line:r.line,column:r.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.type==="identifier"?t.name:"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,r){return{type:"binaryExpression",operator:e,left:t,right:r,start:t.start,end:r.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createPostfixUnary(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!1,start:t.start,end:this.previous().end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function ft(o){return new Ge().parse(o)}function Y(o,e){switch(o.type){case"literal":return rn(o);case"selector":return nn(o,e);case"reference":return on(o);case"property-path":return an(o,e);case"expression":return sn(o);case"flag":return{type:"literal",value:o.enabled};default:let t=o;throw new Error(`Unknown semantic value type: ${t.type}`)}}function rn(o){let e={type:"literal",value:o.value};return o.dataType?{...e,dataType:o.dataType}:e}function nn(o,e){return o.value.startsWith("@")&&/^[a-zA-Z_]/.test(o.value.slice(1))?{type:"attributeAccess",attributeName:o.value.slice(1)}:(e&&o.value.startsWith("*")&&/^[a-zA-Z-]/.test(o.value.slice(1))&&e.push(`Converted '${o.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.`),o.value.startsWith("<")?{type:"selector",value:o.value,selector:o.value,selectorType:o.selectorKind,raw:o.value}:{type:"selector",value:o.value,selector:o.value,selectorType:o.selectorKind})}function on(o){return{type:"contextReference",contextType:o.value,name:o.value}}function an(o,e){return{type:"propertyAccess",object:Y(o.object,e),property:o.property}}function sn(o){let e=ft(o.raw);return!e.success||!e.node?{type:"identifier",name:o.raw}:e.node}function ht(o,e){return o.roles.get(e)}function w(o,e,t){let r=ht(o,e);return r?Y(r,t):void 0}function L(o,e=[],t,r={}){let n={type:"command",name:o,args:e};return t&&Object.keys(t).length>0&&(n.modifiers=t),r.isBlocking&&(n.isBlocking=r.isBlocking),r.implicitTarget&&(n.implicitTarget=r.implicitTarget),r.semanticRoles&&Object.keys(r.semanticRoles).length>0&&(n.semanticRoles=r.semanticRoles),n}var ln={action:"toggle",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=w(o,"duration"),a=t?[t]:[],i={};return r&&(i.on=r),n&&(i.for=n),L("toggle",a,i)}},cn={action:"add",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.to=r),L("add",n,a)}},un={action:"remove",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.from=r),L("remove",n,a)}},dn={action:"set",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"scope"),a=[],i={};return t&&a.push(t),r&&(i.to=r),n&&(i.on=n),L("set",a,i)}},pn={action:"show",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"duration"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.with=n),L("show",a,i)}},mn={action:"hide",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"duration"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.with=n),L("hide",a,i)}},fn={action:"increment",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"quantity"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.by=n),L("increment",a,i)}},hn={action:"decrement",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"quantity"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.by=n),L("decrement",a,i)}},yn={action:"wait",toAST(o,e){let t=w(o,"event");if(t){let a={for:t},i=w(o,"source");return i&&(a.from=i),L("wait",[],a,{isBlocking:!0})}let r=w(o,"duration");return L("wait",r?[r]:[],void 0,{isBlocking:!0})}},gn={action:"log",toAST(o,e){let t=w(o,"patient"),r=[];return t&&r.push(t),L("log",r)}},vn={action:"put",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=ht(o,"manner")??ht(o,"method"),a=t?[t]:[],i={};if(r){let s=n?.type==="literal"?String(n.value):"into";i[s]=r}return L("put",a,i)}},kn={action:"fetch",toAST(o,e){let t=w(o,"source"),r=w(o,"method"),n=w(o,"responseType"),a=w(o,"patient"),i=t?[t]:[],s={};return r&&(s.with=r),n&&(s.as=n),a&&(s.body=a),L("fetch",i,s,{isBlocking:!0})}},Sn={action:"append",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.to=r),L("append",n,a)}},xn={action:"prepend",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.to=r),L("prepend",n,a)}},bn={action:"trigger",toAST(o,e){let t=w(o,"event"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.on=r),L("trigger",n,a)}},wn={action:"send",toAST(o,e){let t=w(o,"event"),r=w(o,"destination"),n=w(o,"patient"),a=t?[t]:[],i={};return r&&(i.to=r),n&&(i.detail=n),L("send",a,i)}},Tn={action:"go",toAST(o,e){let t=w(o,"source"),r=w(o,"destination"),n=[],a={};return t&&n.push(t),r&&(a.to=r),L("go",n,a)}},En={action:"transition",toAST(o,e){let t=w(o,"patient"),r=w(o,"goal"),n=w(o,"duration"),a=w(o,"destination"),i=t?[t]:[],s={};return r&&(s.to=r),n&&(s.over=n),a&&(s.on=a),L("transition",i,s)}},Cn={action:"focus",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a={},i=t??r;return i&&n.push(i),L("focus",n,a)}},Nn={action:"blur",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("blur",n)}},Pn={action:"get",toAST(o,e){let t=w(o,"source"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("get",n)}},Ln={action:"take",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.from=r),L("take",n,a)}},Rn={action:"call",toAST(o,e){let t=w(o,"patient");return L("call",t?[t]:[])}},An={action:"return",toAST(o,e){let t=w(o,"patient");return L("return",t?[t]:[])}},Mn={action:"halt",toAST(o,e){let t=o.roles.get("patient");return t?L("halt",[Y(t)]):L("halt",[])}},On={action:"throw",toAST(o,e){let t=w(o,"patient");return L("throw",t?[t]:[])}},Vn={action:"settle",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("settle",n,void 0,{isBlocking:!0})}},zn={action:"swap",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=w(o,"destination"),a=w(o,"style"),i=[],s={};return t&&i.push(t),r&&i.push(r),n&&(s.on=n),a&&(s.with=a),L("swap",i,s)}},In={action:"morph",toAST(o,e){let t=w(o,"source"),r=w(o,"destination"),n=w(o,"patient"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.on=n),L("morph",a,i)}},_n={action:"clone",toAST(o,e){let t=w(o,"source"),r=w(o,"destination"),n=w(o,"patient"),a=[],i={},s=t??n;return s&&a.push(s),r&&(i.into=r),L("clone",a,i)}},qn={action:"make",toAST(o,e){let t=w(o,"patient");return L("make",t?[t]:[])}},Bn={action:"measure",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=w(o,"source"),a=[],i={};t&&a.push(t);let s=r??n;return s&&(i.of=s),L("measure",a,i)}},$n={action:"tell",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("tell",n)}},Dn={action:"js",toAST(o,e){let t=w(o,"patient");return L("js",t?[t]:[])}},jn={action:"async",toAST(o,e){return L("async",[])}},Wn={action:"if",toAST(o,e){let t=w(o,"condition");return L("if",t?[t]:[])}},Kn={action:"unless",toAST(o,e){let t=w(o,"condition");return L("unless",t?[t]:[])}},Un={action:"repeat",toAST(o,e){let t=w(o,"quantity"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("repeat",n)}},Fn={action:"for",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.in=r),L("for",n,a)}},Hn={action:"while",toAST(o,e){let t=w(o,"condition");return L("while",t?[t]:[])}},Gn={action:"continue",toAST(o,e){return L("continue",[])}},Yn={action:"default",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.to=r),L("default",n,a)}},Zn={action:"init",toAST(o,e){return L("init",[])}},Jn={action:"behavior",toAST(o,e){let t=w(o,"patient");return L("behavior",t?[t]:[])}},Xn={action:"install",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.on=r),L("install",n,a)}},Qn={action:"on",toAST(o,e){let t=w(o,"event"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.from=r),L("on",n,a)}},Gt=new Map([["toggle",ln],["add",cn],["remove",un],["set",dn],["show",pn],["hide",mn],["increment",fn],["decrement",hn],["wait",yn],["log",gn],["put",vn],["fetch",kn],["append",Sn],["prepend",xn],["get",Pn],["take",Ln],["trigger",bn],["send",wn],["on",Qn],["go",Tn],["transition",En],["focus",Cn],["blur",Nn],["call",Rn],["return",An],["halt",Mn],["throw",On],["settle",Vn],["swap",zn],["morph",In],["clone",_n],["measure",Bn],["make",qn],["tell",$n],["default",Yn],["js",Dn],["async",jn],["if",Wn],["unless",Kn],["repeat",Un],["for",Fn],["while",Hn],["continue",Gn],["init",Zn],["behavior",Jn],["install",Xn]]);function Me(o){return Gt.get(o)}function yt(o){Gt.set(o.action,o)}var Oe=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);case"behavior":return this.buildBehavior(e);case"def":return this.buildDef(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildBehavior(e){let t=e.eventHandlers.map(n=>this.buildEventHandler(n)),r={type:"behavior",name:e.name,parameters:[...e.parameters],eventHandlers:t};return e.initBlock&&e.initBlock.length>0&&(r.initBlock={type:"initBlock",commands:e.initBlock.map(n=>this.build(n))}),r}buildDef(e){return{type:"def",name:e.name,params:[...e.parameters],body:e.body.map(t=>this.build(t))}}buildCommand(e){let t=Me(e.action),r;if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let a=n;this.warnings.push(...a.warnings),r=a.ast}else r=n}else r=this.buildGenericCommand(e);if(e.roles&&e.roles.size>0){let n={};for(let[a,i]of e.roles)n[a]=Y(i);Object.keys(n).length>0&&(r.semanticRoles=n)}return r}buildGenericCommand(e){let t=[],r={},n=["patient","source","quantity"],a=["destination","duration","method","style"];for(let s of n){let l=e.roles.get(s);l&&t.push(Y(l))}for(let s of a){let l=e.roles.get(s);if(l){let c=this.roleToModifierKey(s);r[c]=Y(l)}}let i={type:"command",name:e.action,args:t};return Object.keys(r).length>0?{...i,modifiers:r}:i}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),r="click",n,a=t?.type==="literal"?String(t.value):t?.type==="expression"?t.raw:t?.type==="reference"?t.value:void 0;a!==void 0&&(a.includes("|")||a.includes(" or ")?(n=a.split(/\s+or\s+|\|/).map(g=>g.trim()),r=n[0]):r=a);let i=e.body.map(g=>this.build(g)),s=e.roles.get("source"),l,c;s?.type==="selector"?(l=s.value,c=s.value):s?.type==="reference"?c=s.value:s?.type==="literal"&&(c=String(s.value));let d=e.roles.get("condition"),u=d?Y(d):void 0,f=e.roles.get("destination"),m=f?Y(f):void 0,p=e.eventModifiers,h=l;if(p?.from){let g=p.from;g.type==="selector"&&!l&&(h=g.value)}let y=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:r,commands:i,...n&&n.length>1?{events:n}:{},...h?{selector:h}:{},...c?{target:c}:{},...u?{condition:u}:{},...m?{watchTarget:m}:{},...y&&y.length>0?{args:y,params:y}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let r=Y(t),n=e.thenBranch.map(s=>this.build(s)),a=e.elseBranch?.map(s=>this.build(s)),i=[r,{type:"block",commands:n}];return a&&a.length>0&&i.push({type:"block",commands:a}),{type:"command",name:"if",args:i}}buildCompound(e){let t=e.statements.map(n=>this.build(n));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:t.every(n=>n.type==="eventHandler")?{type:"Program",statements:t}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(n=>this.build(n)),r=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let n=e.roles.get("quantity");n&&r.push(Y(n));break}case"for":{e.loopVariable&&r.push({type:"string",value:e.loopVariable});let n=e.roles.get("source");n&&r.push(Y(n));break}case"while":case"until":{let n=e.roles.get("condition");n&&r.push(Y(n));break}case"forever":break}return r.push({type:"block",commands:t}),{type:"command",name:"repeat",args:r}}buildBlock(e){return{type:"block",commands:e.map(r=>this.build(r))}}};function Yt(o){let e=new Oe;return{ast:e.build(o),warnings:e.warnings}}var ye=new Map,ge=new Map,Ve=new Map;var Zt=null;function Xt(o,e){let t={...o};for(let r of Object.keys(e)){let n=e[r],a=o[r];n!==void 0&&(typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof a=="object"&&a!==null&&!Array.isArray(a)?t[r]=Xt(a,n):t[r]=n)}return t}function Qt(o,e){return Xt(o,e)}function gt(o){if(!o.extends)return o;let e=ge.get(o.extends);if(!e)return console.warn(`[Registry] Profile '${o.code}' extends '${o.extends}' but base is not registered. Make sure to import the base language before the variant.`),o;let t=gt(e);return Qt(t,o)}function vt(o,e,t){ye.set(o,e),ge.set(o,t),Ve.delete(o)}var Jt=new Map;function be(o){return o.split("-")[0]}function we(o){return o.includes("-")}function Ye(o){let e=ye.get(o);if(!e&&we(o)){let t=be(o);e=ye.get(t)}if(!e){let t=Array.from(ye.keys()).join(", ");throw new Error(`Language '${o}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${o}';`)}return e}function Ze(o){let e=ge.get(o);if(!e&&we(o)){let t=be(o);e=ge.get(t)}if(!e){let t=Array.from(ge.keys()).join(", ");throw new Error(`Language profile '${o}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${o}';`)}return gt(e)}function z(o){let e=ge.get(o);return!e&&we(o)&&(e=ge.get(be(o))),e?gt(e):void 0}function kt(){return Array.from(ye.keys())}function St(o){return ye.has(o)?!0:we(o)?ye.has(be(o)):!1}function er(o,e){return Ye(e).tokenize(o)}function Q(o){let e=Ve.get(o);if(!e&&we(o)&&(e=Ve.get(be(o))),e)return e;let t=Jt.get(o);if(!t&&we(o)&&(t=Jt.get(be(o))),t)return Ve.set(o,t),t;if(!Zt)throw new Error(`No patterns registered for language '${o}'. Either import the language module or set a pattern generator.`);let r=Ze(o),n=Zt(r);return Ve.set(o,n),n}function xt(o,e){return Q(o).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}var ve={code:"qu",name:"Quechua",nativeName:"Runasimi",direction:"ltr",script:"latin",wordOrder:"SOV",markingStrategy:"postposition",usesSpaces:!0,verb:{position:"end",subjectDrop:!0},references:{me:"noqa",it:"chay",you:"qam",result:"rurasqa",event:"ruwakuq",target:"punta",body:"kurku"},possessive:{marker:"-pa",markerPosition:"after-object",keywords:{\u00F1uqapa:"me",\u00F1uqaypa:"me",noqaq:"me",qampa:"you",paypa:"it",chay:"it"},connectors:["paq","pa"]},roleMarkers:{patient:{primary:"ta",position:"after"},destination:{primary:"man",alternatives:["pa"],position:"after"},source:{primary:"manta",position:"after"},style:{primary:"wan",position:"after"},event:{primary:"pi",position:"after"}},keywords:{toggle:{primary:"t'ikray",alternatives:["tikray"],normalized:"toggle"},add:{primary:"yapay",alternatives:["yapaykuy"],normalized:"add"},remove:{primary:"qichuy",alternatives:["hurquy","anchuchiy"],normalized:"remove"},put:{primary:"churay",alternatives:["tiyachiy"],normalized:"put"},append:{primary:"qatichiy",alternatives:["qhipaman_yapay"],normalized:"append"},prepend:{primary:"\xF1awpachiy",normalized:"prepend"},take:{primary:"hapiy",normalized:"take"},make:{primary:"ruray",alternatives:["kamay"],normalized:"make"},clone:{primary:"kikinchay",alternatives:[],normalized:"clone"},swap:{primary:"t'inkuy",alternatives:["rantikunakuy","rantin_tikray"],normalized:"swap"},morph:{primary:"tukunay",alternatives:[],normalized:"morph"},set:{primary:"churanay",alternatives:["kamaykuy"],normalized:"set"},get:{primary:"taripay",normalized:"get"},increment:{primary:"yapachiy",normalized:"increment"},decrement:{primary:"pisiyachiy",normalized:"decrement"},log:{primary:"qillqakuy",alternatives:["willakuy"],normalized:"log"},show:{primary:"rikuchiy",alternatives:["qawachiy"],normalized:"show"},hide:{primary:"pakay",alternatives:["pakakuy"],normalized:"hide"},transition:{primary:"pasay",alternatives:[],normalized:"transition"},on:{primary:"chaypim",alternatives:["kaypi"],normalized:"on"},trigger:{primary:"kuyuchiy",alternatives:["kichay"],normalized:"trigger"},send:{primary:"kachay",alternatives:["apachiy"],normalized:"send"},focus:{primary:"qhawachiy",alternatives:["qhaway"],normalized:"focus"},blur:{primary:"paqariy",alternatives:["mana qhawachiy"],normalized:"blur"},empty:{primary:"ch'usaq",normalized:"empty"},open:{primary:"paskay",normalized:"open"},close:{primary:"wichqay",normalized:"close"},select:{primary:"marcay",normalized:"select"},clear:{primary:"pichay",normalized:"clear"},reset:{primary:"musuqchay",normalized:"reset"},breakpoint:{primary:"sayachinay",normalized:"breakpoint"},go:{primary:"riy",alternatives:["puriy"],normalized:"go"},scroll:{primary:"kunray",alternatives:[],normalized:"scroll"},push:{primary:"tanqay",normalized:"push"},replace:{primary:"tikray_url",alternatives:[],normalized:"replace"},process:{primary:"rurariy",normalized:"process"},wait:{primary:"suyay",normalized:"wait"},fetch:{primary:"apamuy",alternatives:["taripakaramuy"],normalized:"fetch"},settle:{primary:"tiyakuy",normalized:"settle"},if:{primary:"sichus",normalized:"if"},unless:{primary:"mana sichus",normalized:"unless"},when:{primary:"maykama",normalized:"when"},where:{primary:"maypi",normalized:"where"},else:{primary:"manachus",alternatives:["hukniraq"],normalized:"else"},repeat:{primary:"kutipay",alternatives:["muyu"],normalized:"repeat"},for:{primary:"sapankaq",normalized:"for"},while:{primary:"kaykamaqa",normalized:"while"},forever:{primary:"forever",normalized:"forever"},continue:{primary:"qatipay",normalized:"continue"},halt:{primary:"sayay",alternatives:[],normalized:"halt"},throw:{primary:"chanqay",normalized:"throw"},call:{primary:"waqyay",alternatives:["qayay"],normalized:"call"},return:{primary:"kutichiy",alternatives:["kutimuy"],normalized:"return"},then:{primary:"chaymantataq",alternatives:["hinaspa","chaymanta"],normalized:"then"},and:{primary:"hinallataq",alternatives:["ima","chaymantawan"],normalized:"and"},end:{primary:"tukukuy",alternatives:["tukuy","puchukay"],normalized:"end"},js:{primary:"js",normalized:"js"},async:{primary:"mana waqtalla",normalized:"async"},tell:{primary:"niy",alternatives:[],normalized:"tell"},default:{primary:"\xF1awpaq_kaq",alternatives:["qallariy"],normalized:"default"},init:{primary:"qallarichiy",normalized:"init"},behavior:{primary:"ruwana",normalized:"behavior"},install:{primary:"tarpuy",normalized:"install"},measure:{primary:"tupuy",normalized:"measure"},beep:{primary:"waqay",normalized:"beep"},break:{primary:"p'akiy",normalized:"break"},copy:{primary:"qillqay",normalized:"copy"},exit:{primary:"lluqsiy",normalized:"exit"},pick:{primary:"akllay",normalized:"pick"},render:{primary:"rikurichiy",normalized:"render"},into:{primary:"ukuman",normalized:"into"},before:{primary:"\xF1awpaq",normalized:"before"},after:{primary:"qhipa",normalized:"after"},until:{primary:"kama",alternatives:["-kama"],normalized:"until"},event:{primary:"ruwakuq",alternatives:["imayna"],normalized:"event"},from:{primary:"manta",alternatives:["-manta"],normalized:"from"},click:{primary:"\xF1itiy",normalized:"click"},load:{primary:"apakuy",normalized:"load"},submit:{primary:"apaykachay",normalized:"submit"},hover:{primary:"hawachiy",normalized:"hover"},input:{primary:"yaykuchiy",normalized:"input"},change:{primary:"kambiay",normalized:"change"},connect:{primary:"tinkiy",alternatives:["watay","hukllachay"],normalized:"connect"},stream:{primary:"phawachiy",alternatives:["sururichiy","ch'uquchiy"],normalized:"stream"},live:{primary:"kawsachkaq",alternatives:["kunan-pacha","kawsay"],normalized:"live"},socket:{primary:"tinkina",alternatives:["t'oqo","tinkiy-tinkina"],normalized:"socket"},bind:{primary:"bind",alternatives:["watachiy"],normalized:"bind"},intercept:{primary:"hark'ay",alternatives:["intercept"],normalized:"intercept"},worker:{primary:"llamk'aq",alternatives:["worker"],normalized:"worker"},eventsource:{primary:"eventsource",alternatives:["kawsay-pukyu"],normalized:"eventsource"}},eventHandler:{keyword:{primary:"pi",alternatives:["kaqtin"]},sourceMarker:{primary:"manta",position:"after"},eventMarker:{primary:"pi",alternatives:["kaqtin","kaqpi"],position:"after"}}};function U(o,e){return e?{type:"literal",value:o,dataType:e}:{type:"literal",value:o}}function ze(o,e){return e?{type:"selector",value:o,selectorKind:e}:{type:"selector",value:o}}function Te(o){return{type:"reference",value:o}}function Xe(o,e){return{type:"property-path",object:o,property:e}}function bt(o,e=!0){return{type:"flag",name:o,enabled:e}}function rr(o,e,t){let r=e instanceof Map?e:new Map(Object.entries(e)),n={kind:"command",action:o,roles:r};return t?{...n,metadata:t}:n}function wt(o,e,t,r,n){let a=e instanceof Map?e:new Map(Object.entries(e));return{kind:"event-handler",action:o,roles:a,body:t,...n&&{eventModifiers:n},...r&&{metadata:r}}}function nr(o,e,t,r,n){let a=e instanceof Map?e:new Map(Object.entries(e));return{kind:"conditional",action:o,roles:a,thenBranch:t,...r&&{elseBranch:r},...n&&{metadata:n}}}function or(o,e,t,r,n,a,i){let s=e instanceof Map?e:new Map(Object.entries(e));return{kind:"loop",action:o,roles:s,loopVariant:t,body:r,...n&&{loopVariable:n},...a&&{indexVariable:a},...i&&{metadata:i}}}var Tt=new Set(["me","you","it","result","event","target","body"]);function Qe(o,e=Tt){return e.has(o)}var tr=new Set(["body","then","else","condition","loop-body","variable","catch","finally"]);function eo(o){let e=o.slice(1,-1),t=0;for(let r of e)if(r==="[")t++;else if(r==="]")t--;else if(t===0&&(r===" "||r===":"))return!0;return!1}function et(o,e={}){let t=o.trim(),r=e.collectDiagnostics===!0,n=[];if(!t.startsWith("[")||!t.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let a=t.slice(1,-1).trim();if(!a)throw new Error("Empty explicit statement");let i=ro(a);if(i.length===0)throw new Error("No command specified in explicit statement");let s=i[0].toLowerCase(),l=new Map,c=e.referenceSet??Tt,d=e.schemaLookup?.getSchema(s),u=d?new Set(d.roles.map(m=>m.role)):null;for(let m=1;m<i.length;m++){let p=i[m];if(p.startsWith("+")||p.startsWith("~")){let C=p.startsWith("+"),S=p.slice(1);if(!S){if(r){n.push({severity:"error",code:"EMPTY_FLAG",message:`Empty flag name: "${p}"`,source:"schema"});continue}throw new Error(`Empty flag name: "${p}"`)}if(u&&!u.has(S)){if(r){n.push({severity:"error",code:"UNKNOWN_FLAG",message:`Unknown flag "${S}" for command "${s}"`,source:"schema",suggestions:[...u].map(k=>`+${k}`)}),l.set(S,bt(S,C));continue}throw new Error(`Unknown flag "${S}" for command "${s}". Valid roles: ${[...u].join(", ")}`)}l.set(S,bt(S,C));continue}let h=p.indexOf(":");if(h===-1){if(r){n.push({severity:"error",code:"INVALID_ROLE_FORMAT",message:`Invalid role format: "${p}". Expected role:value or +flag`,source:"schema"});continue}throw new Error(`Invalid role format: "${p}". Expected role:value or +flag`)}let y=p.slice(0,h);if(u&&!tr.has(y)&&!u.has(y))if(r)n.push({severity:"error",code:"UNKNOWN_ROLE",message:`Unknown role "${y}" for command "${s}"`,source:"schema",suggestions:[...u]});else throw new Error(`Unknown role "${y}" for command "${s}". Valid roles: ${[...u].join(", ")}`);let g=y,x=p.slice(h+1);if(tr.has(y)&&x.startsWith("[")&&eo(x)){let C=oo(p,h+1),S=p.slice(h+1,C+1);l.set(g,{type:"expression",raw:S});continue}let T=no(x,c);l.set(g,T)}if(d&&s!=="on"){for(let m of d.roles)if(m.required&&!l.has(m.role)&&!m.default)if(r)n.push({severity:"error",code:"MISSING_REQUIRED_ROLE",message:`Missing required role "${m.role}" for command "${s}": ${m.description}`,source:"schema"});else throw new Error(`Missing required role "${m.role}" for command "${s}": ${m.description}`)}let f=m=>n.length===0?m:{...m,diagnostics:n};switch(s){case"on":{if(!l.get("event")){if(r)return n.push({severity:"error",code:"MISSING_EVENT_ROLE",message:"Event handler requires event role: [on event:click ...]",source:"schema"}),f(wt("on",l,[],{sourceLanguage:"explicit"}));throw new Error("Event handler requires event role: [on event:click ...]")}let p=Je(l,"body",e);return l.delete("body"),f(wt("on",l,p,{sourceLanguage:"explicit"}))}case"if":{let m=Je(l,"then",e),p=Je(l,"else",e);return l.delete("then"),l.delete("else"),f(nr(s,l,m,p.length>0?p:void 0,{sourceLanguage:"explicit"}))}case"repeat":{let m=Je(l,"loop-body",e),p=l.get("loop-variant"),h=l.get("variable"),y=l.get("index-variable");l.delete("loop-body"),l.delete("loop-variant"),l.delete("variable"),l.delete("index-variable");let g;p&&p.type==="literal"&&typeof p.value=="string"?g=p.value:l.has("quantity")?g="times":l.has("source")?g="for":l.has("condition")?g="while":g="forever";let x=h?.type==="literal"&&typeof h.value=="string"?h.value:h?.type==="expression"?h.raw:void 0,T=y?.type==="literal"&&typeof y.value=="string"?y.value:void 0;return f(or(s,l,g,m,x,T,{sourceLanguage:"explicit"}))}default:return f(rr(s,l,{sourceLanguage:"explicit"}))}}function de(o){let e=o.trim();return e.startsWith("[")&&e.endsWith("]")}function Je(o,e,t){let r=o.get(e);return r?r.type==="expression"?[et(r.raw,t)]:[]:[]}function to(o){if(o){if(o.startsWith("#"))return"id";if(o.startsWith("."))return"class";if(o.startsWith("["))return"attribute";if(o.startsWith("<")||o.startsWith("*"))return"element";if(/[>+~ ]/.test(o)&&o.length>1)return"complex"}}function ro(o){let e=[],t="",r=!1,n="",a=0;for(let i=0;i<o.length;i++){let s=o[i];if(r){t+=s,s===n&&o[i-1]!=="\\"&&(r=!1);continue}if(s==='"'||s==="'"){r=!0,n=s,t+=s;continue}if(s==="["){a++,t+=s;continue}if(s==="]"){a--,t+=s;continue}if(s===" "&&a===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function no(o,e){if(o.startsWith("#")||o.startsWith(".")||o.startsWith("[")||o.startsWith("@")||o.startsWith("*"))return ze(o,to(o));if(o.startsWith('"')||o.startsWith("'"))return U(o.slice(1,-1),"string");if(o==="true")return U(!0,"boolean");if(o==="false")return U(!1,"boolean");let t=o.toLowerCase();if(Qe(t,e))return Te(t);let r=o.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(r){let n=parseFloat(r[1]);return r[2]?U(o,"duration"):U(n,"number")}return U(o)}function oo(o,e){let t=0;for(let r=e;r<o.length;r++)if(o[r]==="[")t++;else if(o[r]==="]"&&(t--,t===0))return r;return o.length-1}function ee(o){let e;if(o.kind==="compound"){let t=o;e=t.statements.map(r=>ee(r)).join(` ${t.chainType} `)}else e=ao(o);return o.annotations&&o.annotations.length>0?o.annotations.map(r=>r.value!==void 0?`@${r.name}(${r.value})`:`@${r.name}`).join(" ")+" "+e:e}function ao(o){let e=[o.action];for(let[t,r]of o.roles)r.type==="flag"?e.push(r.enabled?`+${r.name}`:`~${r.name}`):e.push(`${t}:${ar(r)}`);if(o.kind==="event-handler"){let t=o;t.body&&t.body.length>0&&e.push(`body:${t.body.map(r=>ee(r)).join(" ")}`)}if(o.kind==="conditional"){let t=o;t.thenBranch&&t.thenBranch.length>0&&e.push(`then:${t.thenBranch.map(r=>ee(r)).join(" ")}`),t.elseBranch&&t.elseBranch.length>0&&e.push(`else:${t.elseBranch.map(r=>ee(r)).join(" ")}`)}if(o.kind==="loop"){let t=o;t.loopVariant&&e.push(`loop-variant:${t.loopVariant}`),t.loopVariable&&e.push(`variable:${t.loopVariable}`),t.indexVariable&&e.push(`index-variable:${t.indexVariable}`),t.body&&t.body.length>0&&e.push(`loop-body:${t.body.map(r=>ee(r)).join(" ")}`)}if(o.kind==="command"){let t=o;t.body&&t.body.length>0&&e.push(`body:${t.body.map(r=>ee(r)).join(" ")}`),t.catchBranch&&t.catchBranch.length>0&&e.push(`catch:${t.catchBranch.map(r=>ee(r)).join(" ")}`),t.finallyBranch&&t.finallyBranch.length>0&&e.push(`finally:${t.finallyBranch.map(r=>ee(r)).join(" ")}`),t.asyncVariant&&e.push(`async-variant:${t.asyncVariant}`),t.asyncBody&&t.asyncBody.length>0&&e.push(`async-body:${t.asyncBody.map(r=>ee(r)).join(" ")}`)}return`[${e.join(" ")}]`}function ar(o){switch(o.type){case"literal":return typeof o.value=="string"?o.dataType==="string"||/\s/.test(o.value)?`"${o.value}"`:o.value:String(o.value);case"selector":return o.value;case"reference":return o.value;case"property-path":return`${ar(o.object)}'s ${o.property}`;case"expression":return o.raw;case"flag":return o.name}}var io=class{constructor(o){this.namespace=o,this.enabled=this.checkEnabled()}checkEnabled(){if(typeof process<"u"&&process.env){let o=process.env.DEBUG||"";return o==="*"||o.includes("framework:*")||o.includes(`framework:${this.namespace}`)}return!1}log(o,e,...t){if(!this.enabled)return;let r=`[framework:${this.namespace}]`,n=new Date().toISOString();switch(o){case"debug":console.debug(`${n} ${r} DEBUG:`,e,...t);break;case"info":console.info(`${n} ${r} INFO:`,e,...t);break;case"warn":console.warn(`${n} ${r} WARN:`,e,...t);break;case"error":console.error(`${n} ${r} ERROR:`,e,...t);break}}debug(o,...e){this.log("debug",o,...e)}info(o,...e){this.log("info",o,...e)}warn(o,...e){this.log("warn",o,...e)}error(o,...e){this.log("error",o,...e)}isEnabled(){return this.enabled}enable(){this.enabled=!0}disable(){this.enabled=!1}};function so(o){return new io(o)}function Ee(o,e){return!e||e.length===0||e.includes(o)||e.includes("expression")?!0:o==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function lo(o,e){return o?.possessive?.keywords?.[e]}function ir(o){return!1}var Ie=class Ce{constructor(){this.logger=so("pattern-matcher"),this.stemMatchCount=0,this.totalKeywordMatches=0}safeToLowerCase(e){return typeof e=="string"?e.toLowerCase():e==null?"":String(e).toLowerCase()}matchPattern(e,t,r){let n=e.mark(),a=new Map;if(this.logger.debug("========================================"),this.logger.debug("matchPattern ENTRY"),this.logger.debug("Pattern ID:",t.id),this.logger.debug("Pattern command:",t.command),this.logger.debug("Pattern language:",t.language),this.logger.debug("Pattern template:",JSON.stringify(t.template,null,2)),this.logger.isEnabled()){let l=[];for(let c=0;c<10;c++){let d=e.peek(c);if(d)l.push({type:d.type,value:d.value,kind:d.kind});else break}this.logger.debug("Input tokens (first 10):",l),this.logger.debug("Profile code:",r?.code)}this.currentProfile=r,this.stemMatchCount=0,this.totalKeywordMatches=0,this.logger.debug("--- Calling matchTokenSequence ---"),this.logger.debug("Pattern tokens to match:",JSON.stringify(t.template.tokens,null,2));let i=this.matchTokenSequence(e,t.template.tokens,a);if(this.logger.debug("matchTokenSequence returned:",i),this.logger.debug("Captured roles:",Array.from(a.entries()).map(([l,c])=>[l,JSON.stringify(c)])),!i)return this.logger.debug(">>> MATCH FAILED - resetting token position"),e.reset(n),null;let s=this.calculateConfidence(t,a);return this.applyExtractionRules(t,a),{pattern:t,captured:a,consumedTokens:e.position()-n.position,confidence:s}}matchBest(e,t,r){let n=[];for(let i of t){let s=e.mark(),l=this.matchPattern(e,i,r);l&&n.push(l),e.reset(s)}if(n.length===0)return null;n.sort((i,s)=>{let l=s.pattern.priority-i.pattern.priority;if(l!==0)return l;let c=s.confidence-i.confidence;return Math.abs(c)>.001?c:s.consumedTokens-i.consumedTokens});let a=n[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,t,r,n){let a=t[0],i=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!i)for(;e.peek()?.kind==="conjunction";)e.advance();let s=null,l=null;for(let c=0;c<t.length;c++){let d=t[c];this.logger.debug(" >> Matching pattern token:",JSON.stringify(d,null,2));let u=e.peek();if(this.logger.debug(" >> Current input token:",u?JSON.stringify({type:u.type,value:u.value,kind:u.kind}):"EOF"),d.type==="role"&&d.greedy){let y=this.collectStopMarkers(t,c+1);if(n)for(let x of n)y.add(x);let g=[];for(;!e.isAtEnd();){let x=e.peek();if(!x||this.isStopMarker(x,y))break;g.push(x.value),e.advance()}if(g.length>0){r.set(d.role,{type:"expression",raw:g.join(" ")}),s=null,l=null;continue}else{if(d.optional)continue;return!1}}if(d.type==="group"){let y=this.collectStopMarkers(t,c+1);if(n)for(let x of n)y.add(x);if(this.matchGroupToken(e,d,r,y)){s=null,l=null;continue}if(this.isOptional(d))continue;return!1}let f=d.type==="role"&&d.optional===!0,m=f?e.mark():null;if(d.type==="role"&&!f){let y=c+1<t.length?t[c+1]:null;if(y?.type==="literal"){let g=e.peek();if(g&&this.getMatchType(g,y.value)!=="none"){if(this.logger.debug(" >> MARKER-STEAL GUARD: current token matches next literal, skipping role"),this.logger.debug(" >> Token match FAILED"),this.isOptional(d))continue;if(s&&l){this.logger.debug(" >> BACKTRACKING: undoing optional role",l),e.reset(s),r.delete(l),s=null,l=null;let x=this.matchPatternToken(e,d,r);if(this.logger.debug(" >> Backtrack retry result:",x),x)continue}return!1}}}let h=this.matchPatternToken(e,d,r);if(this.logger.debug(" >> Match result:",h),h){f?(s=m,l=d.role):(s=null,l=null);continue}if(this.logger.debug(" >> Token match FAILED"),!this.isOptional(d)){if(s&&l){this.logger.debug(" >> BACKTRACKING: undoing optional role",l),e.reset(s),r.delete(l),s=null,l=null;let y=this.matchPatternToken(e,d,r);if(this.logger.debug(" >> Backtrack retry result:",y),y)continue}return!1}}return!0}matchPatternToken(e,t,r){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r);case"group":return this.matchGroupToken(e,t,r);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(this.logger.debug(" >>> matchLiteralToken: expecting",t.value),this.logger.debug(" >>> matchLiteralToken: got token",r?JSON.stringify({type:r.type,value:r.value,kind:r.kind}):"null"),!r)return this.logger.debug(" >>> matchLiteralToken: FAIL - no token"),!1;let n=this.getMatchType(r,t.value);if(this.logger.debug(" >>> matchType for",r.value,"vs",t.value,":",n),n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let a of t.alternatives){let i=this.getMatchType(r,a);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,r){this.logger.debug(" >>> matchRoleToken ENTRY: capturing role",t.role),this.logger.debug(" >>> matchRoleToken: expected types",t.expectedTypes),this.logger.debug(" >>> matchRoleToken: optional?",t.optional),this.skipNoiseWords(e);let n=e.peek();if(this.logger.debug(" >>> After skipNoiseWords, current token:",n?JSON.stringify({value:n.value,kind:n.kind}):"null"),!n)return t.optional||!1;let a=this.tryMatchPossessiveExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(a.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,a),!0);let i=this.tryMatchMethodCallExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(i.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,i),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);let l=this.tryMatchPropertyAccessExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(l.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,l),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(c.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,c),!0);this.logger.debug(" >>> Trying tokenToSemanticValue for token:",n?JSON.stringify({value:n.value,kind:n.kind}):"null");let d=this.tokenToSemanticValue(n);return this.logger.debug(" >>> tokenToSemanticValue returned:",d?JSON.stringify(d):"null"),d?(this.logger.debug(" >>> Validating type:",d.type,"against expected:",t.expectedTypes),t.expectedTypes&&t.expectedTypes.length>0&&!Ee(d.type,t.expectedTypes)?(this.logger.debug(" >>> TYPE MISMATCH - returning",t.optional||!1),t.optional||!1):(this.logger.debug(" >>> Type validation PASSED"),r.set(t.role,d),e.advance(),!0)):t.optional||!1}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=t.normalized||t.value,n=this.safeToLowerCase(r),a=lo(this.currentProfile,n);if(!a)return null;let i=e.mark();e.advance();let s=e.peek();if(!s)return e.reset(i),null;if(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)||s.kind==="selector"&&s.value.startsWith("*")||s.kind==="selector"&&s.value.startsWith("@")||s.kind==="selector"&&s.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s.value)){e.advance();let l=s.value;s.kind==="selector"&&l.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(l)&&(l=l.substring(1));let c=l;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)c+=e.peek().value,e.advance();let d=e.peek();return d?.kind==="literal"&&d.value.startsWith("(")&&(c+=d.value,e.advance()),Xe(Te(a),c)}return e.reset(i),null}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(r),null;e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<Ce.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${a.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(r),null;e.advance();let i=`${t.value}.${a.value}`,s=1;for(;!e.isAtEnd()&&s<Ce.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let d=e.peek();if(!d||d.kind!=="identifier")break;e.advance(),i+=`.${d.value}`,s++}let l=e.peek();if(l&&l.kind==="punctuation"&&l.value==="("){e.advance();let c=[],d=0;for(;!e.isAtEnd()&&c.length<Ce.MAX_METHOD_ARGS;){let f=e.peek();if(!f)break;if(f.kind==="punctuation"&&f.value===")"){if(d===0){e.advance();break}d--}if(f.kind==="punctuation"&&f.value==="("&&d++,f.kind==="punctuation"&&f.value===","){e.advance();continue}c.push(f.value),e.advance()}return{type:"expression",raw:`${i}(${c.join(", ")})`}}return{type:"expression",raw:i}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="punctuation"||n.value!=="'s")return e.reset(r),null;e.advance();let a=e.peek();return!a||a.kind!=="selector"&&a.kind!=="identifier"?(e.reset(r),null):(e.advance(),Xe(ze(t.value),a.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||typeof t.value!="string"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(r),null;let a=e.peek(1);a&&a.kind,e.advance();let i=n.value.slice(1);return Xe(ze(t.value),i)}matchGroupToken(e,t,r,n){let a=e.mark(),i=new Set(r.keys());if(this.matchTokenSequence(e,t.tokens,r,n))return!0;e.reset(a);for(let c of r.keys())i.has(c)||r.delete(c);if(!t.optional)return!1;let l=this.getGroupLeadingMarker(t);if(l)for(let c=1;c<=Ce.MAX_MARKER_SCAN;c++){let d=e.peek(c);if(!d)break;if((d.normalized||d.value).toLowerCase()===l){this.logger.debug(" >> MARKER SCAN: found",l,"at offset",c,"- skipping intervening tokens");for(let m=0;m<c;m++)e.advance();if(this.matchTokenSequence(e,t.tokens,r,n))return!0;e.reset(a);for(let m of r.keys())i.has(m)||r.delete(m);break}}return!0}getGroupLeadingMarker(e){let t=e.tokens[0];return t?.type==="literal"?t.value.toLowerCase():null}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"&&this.safeToLowerCase(e.value)===t.toLowerCase()?"case-insensitive":"none"}collectStopMarkers(e,t){let r=new Set;for(let n=t;n<e.length;n++){let a=e[n];if(a.type==="literal"){if(r.add(a.value.toLowerCase()),a.alternatives)for(let i of a.alternatives)r.add(i.toLowerCase());break}if(a.type==="group"){for(let i of a.tokens)if(i.type==="literal"){if(r.add(i.value.toLowerCase()),i.alternatives)for(let s of i.alternatives)r.add(s.toLowerCase());break}if(!a.optional)break}}return r}isStopMarker(e,t){return t.size===0?!1:!!(t.has(e.value.toLowerCase())||e.normalized&&t.has(e.normalized.toLowerCase()))}tokenToSemanticValue(e){switch(e.kind){case"selector":return ze(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=e.normalized||e.value,r=this.safeToLowerCase(t);return ir(r)?Te(r):U(e.normalized||e.value);case"identifier":if(typeof e.value=="string"&&e.value.startsWith(":"))return Te(e.value);let n=this.safeToLowerCase(e.value);return ir(n)?Te(n):{type:"expression",raw:e.value};case"url":return U(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let n=e.slice(1,-1);return U(n,"string")}if(e==="true")return U(!0,"boolean");if(e==="false")return U(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let n=parseFloat(t[1]);return t[2]?U(e,"duration"):U(n,"number")}let r=parseFloat(e);return isNaN(r)?U(e,"string"):U(r,"number")}applyExtractionRules(e,t){for(let[r,n]of Object.entries(e.extraction))t.has(r)||(n.value!==void 0?t.set(r,{type:"literal",value:n.value}):n.default&&t.set(r,n.default))}isOptional(e){return e.type!=="literal"&&e.optional===!0}calculateConfidence(e,t){let r=0,n=0,a=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")n+=1,t.has(c.role)&&(r+=1);else if(c.type==="group"){for(let d of c.tokens)if(d.type==="role"){let u=a(d.role),f=.8;n+=f,t.has(d.role)?r+=f:u&&(r+=f*.6)}}let i=n>0?r/n:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let c=this.stemMatchCount/this.totalKeywordMatches*.15;i=Math.max(.5,i-c)}let s=this.calculateVSOConfidenceBoost(e);i=Math.min(1,i+s);let l=this.arabicPrepositionDisambiguation(e,t);return i=Math.max(0,Math.min(1,i+l)),i}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let r=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(r.has(t.value))return .15;if(t.alternatives){for(let n of t.alternatives)if(r.has(n))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let r=0,n={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[a,i]of t.entries()){let s=n[a];if(!s||s.length===0)continue;let l="metadata"in i?i.metadata:void 0;if(l&&typeof l.prepositionValue=="string"){let c=l.prepositionValue;s.includes(c)?r+=.1:r-=.1}}return Math.max(-.1,Math.min(.1,r))}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=this.safeToLowerCase(t.value);if(Ce.ENGLISH_NOISE_WORDS.has(r)){let n=e.mark();e.advance();let a=e.peek();if(a&&a.kind==="selector")return;e.reset(n)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(r=!0,a.modifierName){case"once":t.once=!0;break;case"debounce":typeof a.value=="number"&&(t.debounce=a.value);break;case"throttle":typeof a.value=="number"&&(t.throttle=a.value);break;case"queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(t.queue=a.value);break}e.advance()}return r?t:void 0}};Ie.MAX_MARKER_SCAN=3;Ie.MAX_PROPERTY_DEPTH=10;Ie.MAX_METHOD_ARGS=20;Ie.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var co=Ie,Wi=new co;var Et=class{constructor(){this.name="number"}canExtract(o,e){return/\d/.test(o[e])}extract(o,e){let t=0,r=!1;for(;e+t<o.length;){let i=o[e+t];if(/\d/.test(i))t++;else if(i==="."&&!r)r=!0,t++;else break}if(t===0)return null;let n=o.substring(e,e+t),a=e+t;if(a<o.length){let i=o.slice(a),s=[{pattern:"\u6BEB\u79D2",suffix:"ms"},{pattern:"\u5206\u949F",suffix:"m"},{pattern:"\u5C0F\u65F6",suffix:"h"},{pattern:"\u30DF\u30EA\u79D2",suffix:"ms"},{pattern:"\u6642\u9593",suffix:"h"}];for(let c of s)if(i.startsWith(c.pattern))return{value:n+c.suffix,length:t+c.pattern.length,metadata:{hasTimeUnit:!0}};if(i.startsWith("ms"))return{value:n+"ms",length:t+2,metadata:{hasTimeUnit:!0}};let l=[{pattern:"\u79D2",suffix:"s"},{pattern:"\u5206",suffix:"m"}];for(let c of l)if(i.startsWith(c.pattern))return{value:n+c.suffix,length:t+1,metadata:{hasTimeUnit:!0}};if(/^[smh](?![a-zA-Z])/.test(i))return{value:n+i[0],length:t+1,metadata:{hasTimeUnit:!0}}}return{value:n,length:t}}};function uo(o){return"setContext"in o&&typeof o.setContext=="function"}function po(o){let e={language:o.language,direction:o.direction,lookupKeyword:o.lookupKeyword.bind(o),isKeyword:o.isKeyword.bind(o),isKeywordStart:o.isKeywordStart.bind(o),...o.isKeywordStartAtBoundary?{isKeywordStartAtBoundary:o.isKeywordStartAtBoundary.bind(o)}:{}};return o.normalizer?{...e,normalizer:o.normalizer}:e}var X=class{constructor(o,e){this.pos=0,this.tokens=o,this.language=e}peek(o=0){let e=this.pos+o;return e<0||e>=this.tokens.length?null:this.tokens[e]}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(o){this.pos=o.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(o){let e=[];for(;!this.isAtEnd()&&o(this.peek());)e.push(this.advance());return e}skipWhile(o){for(;!this.isAtEnd()&&o(this.peek());)this.advance()}};function B(o,e){return{start:o,end:e}}function $(o,e,t,r){if(typeof o=="object"){let{value:a,kind:i,position:s,normalized:l,stem:c,stemConfidence:d,metadata:u}=o;return{value:a,kind:i,position:s,...l!==void 0&&{normalized:l},...c!==void 0&&{stem:c},...d!==void 0&&{stemConfidence:d},...u!==void 0&&{metadata:u}}}let n=o;if(!e||!t)throw new Error("createToken requires kind and position parameters");if(typeof r=="string")return{value:n,kind:e,position:t,normalized:r};if(r){let{normalized:a,stem:i,stemConfidence:s,metadata:l}=r;return{value:n,kind:e,position:t,...a!==void 0&&{normalized:a},...i!==void 0&&{stem:i},...s!==void 0&&{stemConfidence:s},...l!==void 0&&{metadata:l}}}return{value:n,kind:e,position:t}}function pe(o){return/\s/.test(o)}function tt(o){return o==="#"||o==="."||o==="["||o==="@"||o==="*"||o==="<"}function rt(o){return o==='"'||o==="'"||o==="`"||o==="\u300C"||o==="\u300D"}function ae(o){return/\d/.test(o)}function nt(o){return/[a-zA-Z]/.test(o)}function W(o){return/[a-zA-Z0-9_-]/.test(o)}function sr(o,e){if(e>=o.length)return null;let t=o[e];if(!tt(t))return null;let r=e,n="";if(t==="#"||t==="."){for(n+=o[r++];r<o.length&&W(o[r]);)n+=o[r++];if(n.length<=1)return null;if(r<o.length&&o[r]==="."&&t==="#"){let i=r+1;for(;i<o.length&&W(o[i]);)i++;if(i<o.length&&o[i]==="(")return n}}else if(t==="["){let a=1,i=!1,s=null,l=!1;for(n+=o[r++];r<o.length&&a>0;){let c=o[r];n+=c,l?l=!1:c==="\\"?l=!0:i?c===s&&(i=!1,s=null):c==='"'||c==="'"||c==="`"?(i=!0,s=c):c==="["?a++:c==="]"&&a--,r++}if(a!==0)return null}else if(t==="@"){for(n+=o[r++];r<o.length&&W(o[r]);)n+=o[r++];if(n.length<=1)return null}else if(t==="*"){for(n+=o[r++];r<o.length&&W(o[r]);)n+=o[r++];if(n.length<=1)return null}else if(t==="<"){if(n+=o[r++],r>=o.length||!nt(o[r]))return null;for(;r<o.length&&W(o[r]);)n+=o[r++];for(;r<o.length;){let a=o[r];if(a==="."){if(n+=o[r++],r>=o.length||!W(o[r]))return null;for(;r<o.length&&W(o[r]);)n+=o[r++]}else if(a==="#"){if(n+=o[r++],r>=o.length||!W(o[r]))return null;for(;r<o.length&&W(o[r]);)n+=o[r++]}else if(a==="["){let i=1,s=!1,l=null,c=!1;for(n+=o[r++];r<o.length&&i>0;){let d=o[r];n+=d,c?c=!1:d==="\\"?c=!0:s?d===l&&(s=!1,l=null):d==='"'||d==="'"||d==="`"?(s=!0,l=d):d==="["?i++:d==="]"&&i--,r++}if(i!==0)return null}else break}for(;r<o.length&&pe(o[r]);)n+=o[r++];if(r<o.length&&o[r]==="/")for(n+=o[r++];r<o.length&&pe(o[r]);)n+=o[r++];if(r>=o.length||o[r]!==">")return null;n+=o[r++]}return n||null}function mo(o,e){if(e>=o.length||o[e]!=="'"||e+1>=o.length||o[e+1].toLowerCase()!=="s")return!1;if(e+2>=o.length)return!0;let r=o[e+2];return pe(r)||r==="*"||!W(r)}function lr(o,e){if(e>=o.length)return null;let t=o[e];if(!rt(t)||t==="'"&&mo(o,e))return null;let n={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!n)return null;let a=e+1,i=t,s=!1;for(;a<o.length;){let l=o[a];if(i+=l,s)s=!1;else if(l==="\\")s=!0;else if(l===n)return i;a++}return i}function cr(o,e){if(e>=o.length)return!1;let t=o[e],r=o[e+1]||"",n=o[e+2]||"";if(t==="/"&&r!=="/"&&/[a-zA-Z0-9._-]/.test(r)||t==="/"&&r==="/"&&/[a-zA-Z]/.test(n)||t==="."&&(r==="/"||r==="."&&n==="/"))return!0;let a=o.slice(e,e+8).toLowerCase();return!!(a.startsWith("http://")||a.startsWith("https://"))}function ur(o,e){if(!cr(o,e))return null;let t=e,r="",n=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<o.length;){let a=o[t];if(a==="#"){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=a,t++;t<o.length&&/[a-zA-Z0-9_-]/.test(o[t]);)r+=o[t++];break}if(n.test(a))r+=a,t++;else break}return r.length<2?null:r}function dr(o,e){if(e>=o.length)return null;let t=o[e];if(!ae(t)&&t!=="-"&&t!=="+")return null;let r=e,n="";if((o[r]==="-"||o[r]==="+")&&(n+=o[r++]),r>=o.length||!ae(o[r]))return null;for(;r<o.length&&ae(o[r]);)n+=o[r++];if(r<o.length&&o[r]===".")for(n+=o[r++];r<o.length&&ae(o[r]);)n+=o[r++];return r<o.length&&(o.slice(r,r+2)==="ms"?n+="ms":(o[r]==="s"||o[r]==="m"||o[r]==="h")&&(n+=o[r])),n}var fo=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"];var Gi=new Set(fo),ho=new Set(["patient","destination","source","style","event","eventMarker","agent","goal","manner","into","from","to","with","at","of","as","by","in","on","over","under","between","through","without"]),yo=["click","dblclick","input","change","submit","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave","mousemove","pointerdown","pointerup","pointermove","focus","blur","load","resize","scroll"],pr=class mr{constructor(){this.profileKeywords=[],this.multiWordKeywords=[],this.profileKeywordMap=new Map,this.rawExtraEntries=[],this.extractors=[]}getExtraKeywordEntries(){return this.rawExtraEntries}tokenize(e){if(this.isUsingExtractors())return this.tokenizeWithExtractors(e);throw new Error(`${this.constructor.name}: tokenize() not implemented and no extractors registered. Either register extractors or override tokenize() method.`)}registerExtractor(e){uo(e)&&e.setContext(po(this)),this.extractors.push(e)}registerExtractors(e){for(let t of e)this.registerExtractor(t)}clearExtractors(){this.extractors=[]}isUsingExtractors(){return this.extractors.length>0}tokenizeWithExtractors(e){let t=[],r=0;for(;r<e.length;){for(;r<e.length&&pe(e[r]);)r++;if(r>=e.length)break;let n=this.tryMultiWordKeyword(e,r);if(n){t.push(n),r=n.position.end;continue}let a=!1;for(let i of this.extractors)if(i.canExtract(e,r)){let s=i.extract(e,r);if(s){let l=s.metadata?.normalized,c=s.metadata?.stem,d=s.metadata?.stemConfidence,u={};if(s.metadata)for(let[m,p]of Object.entries(s.metadata))m!=="normalized"&&m!=="stem"&&m!=="stemConfidence"&&(u[m]=p);let f={};l&&(f.normalized=l),c&&(f.stem=c),d!==void 0&&(f.stemConfidence=d),Object.keys(u).length>0&&(f.metadata=u),t.push($(s.value,this.classifyToken(s.value),B(r,r+s.length),Object.keys(f).length>0?f:void 0)),r+=s.length,a=!0;break}}if(!a){let i=e[r],s=this.classifyUnknownChar(i);t.push($(i,s,B(r,r+1))),r++}}return new X(t,this.language)}classifyUnknownChar(e){return"()[]{},:;".includes(e)?"punctuation":"+-*/<>=!&|".includes(e)?"operator":"identifier"}tryPropertyAccess(e,t,r){if(e[t]!==".")return!1;let n=r[r.length-1],a=n&&n.position.end<t;if(n&&!a&&(n.kind==="identifier"||n.kind==="keyword"||n.kind==="selector"))return r.push($(".","operator",B(t,t+1))),!0;let l=t+1;for(;l<e.length&&W(e[l]);)l++;return l<e.length&&e[l]==="("?(r.push($(".","operator",B(t,t+1))),!0):!1}initializeKeywordsFromProfile(e,t=[]){let r=new Map;if(this.rawExtraEntries=t,e.keywords){for(let[n,a]of Object.entries(e.keywords))if(r.set(a.primary,{native:a.primary,normalized:a.normalized||n}),a.alternatives)for(let i of a.alternatives)r.set(i,{native:i,normalized:a.normalized||n})}if(e.references){for(let[n,a]of Object.entries(e.references))r.set(a,{native:a,normalized:n});for(let n of Object.keys(e.references))r.has(n)||r.set(n,{native:n,normalized:n})}if(e.roleMarkers){for(let[n,a]of Object.entries(e.roleMarkers))if(a.primary&&r.set(a.primary,{native:a.primary,normalized:n}),a.alternatives)for(let i of a.alternatives)r.set(i,{native:i,normalized:n})}if(e.possessive?.keywords)for(let[n,a]of Object.entries(e.possessive.keywords))r.set(n,{native:n,normalized:a});for(let n of yo)r.has(n)||r.set(n,{native:n,normalized:n});for(let n of t)r.set(n.native,n);this.profileKeywords=Array.from(r.values()).sort((n,a)=>a.native.length-n.native.length),this.multiWordKeywords=this.profileKeywords.filter(n=>n.native.includes(" ")&&!ho.has(n.normalized)),this.profileKeywordMap=new Map;for(let n of this.profileKeywords){this.profileKeywordMap.set(n.native.toLowerCase(),n);let a=this.removeDiacritics(n.native);a!==n.native&&!this.profileKeywordMap.has(a.toLowerCase())&&this.profileKeywordMap.set(a.toLowerCase(),n)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let r of this.profileKeywords)if(e.slice(t).startsWith(r.native))return $(r.native,"keyword",B(t,t+r.native.length),r.normalized);return null}tryMultiWordKeyword(e,t,r=n=>/[\p{L}\p{N}_]/u.test(n)){if(this.multiWordKeywords.length===0)return null;let n=e.slice(t);for(let a of this.multiWordKeywords){if(!n.startsWith(a.native))continue;let i=e[t+a.native.length];if(!(i!==void 0&&r(i)))return $(a.native,"keyword",B(t,t+a.native.length),a.normalized)}return null}isKeywordStart(e,t){let r=e.slice(t);return this.profileKeywords.some(n=>r.startsWith(n.native))}isKeywordStartAtBoundary(e,t,r=n=>/[\p{L}\p{N}_]/u.test(n)){let n=e.slice(t);return this.profileKeywords.some(a=>{if(!n.startsWith(a.native))return!1;let i=e[t+a.native.length];return i===void 0||!r(i)})}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,r){let n=this.tryNormalize(e);if(!n)return null;let a=this.lookupKeyword(n.stem);if(!a)return null;let i={normalized:a.normalized,stem:n.stem,stemConfidence:n.confidence};return $(e,"keyword",B(t,r),i)}trySelector(e,t){let r=sr(e,t);return r?$(r,"selector",B(t,t+r.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let r=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!r)return null;let n=r[0].replace(/(\s|\.)$/,""),a=n.slice(1).split("(")[0],i=r[1];return{...$(n,"event-modifier",B(t,t+n.length)),metadata:{modifierName:a,value:i?a==="queue"?i:parseInt(i,10):void 0}}}tryString(e,t){let r=lr(e,t);return r?$(r,"literal",B(t,t+r.length)):null}tryNumber(e,t){let r=dr(e,t);return r?$(r,"literal",B(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,n=!1){let a=t;if(n)for(;a<e.length&&pe(e[a]);)a++;let i=e.slice(a);for(let s of r){let l=i.slice(0,s.length);if(s.caseInsensitive?l.toLowerCase()===s.pattern.toLowerCase():l===s.pattern){if(s.notFollowedBy&&(i[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let d=i[s.length]||"";if(W(d))continue}return{suffix:s.suffix,endPos:a+s.length}}}return null}parseBaseNumber(e,t,r=!0){let n=t,a="";if(r&&(e[n]==="-"||e[n]==="+")&&(a+=e[n++]),n>=e.length||!ae(e[n]))return null;for(;n<e.length&&ae(e[n]);)a+=e[n++];if(n<e.length&&e[n]===".")for(a+=e[n++];n<e.length&&ae(e[n]);)a+=e[n++];return!a||a==="-"||a==="+"?null:{number:a,endPos:n}}tryNumberWithTimeUnits(e,t,r,n={}){let{allowSign:a=!0,skipWhitespace:i=!1}=n,s=this.parseBaseNumber(e,t,a);if(!s)return null;let{number:l,endPos:c}=s,d=[...r,...mr.STANDARD_TIME_UNITS],u=this.tryMatchTimeUnit(e,c,d,i);return u&&(l+=u.suffix,c=u.endPos),$(l,"literal",B(t,c))}tryUrl(e,t){let r=ur(e,t);return r?$(r,"url",B(t,t+r.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!W(e[t+1]))return null;let r=t+1;for(;r<e.length&&W(e[r]);)r++;let n=e.slice(t,r);return $(n,"identifier",B(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return $(r,"operator",B(t,t+2));let n=e[t];return["<",">","!","+","-","*","/","="].includes(n)?$(n,"operator",B(t,t+1)):["(",")","{","}",",",";",":"].includes(n)?$(n,"punctuation",B(t,t+1)):null}tryMultiCharParticle(e,t,r){for(let n of r)if(e.slice(t,t+n.length)===n)return $(n,"particle",B(t,t+n.length));return null}};pr.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 _e=pr;function Ct(o){return{stem:o,confidence:1}}function Nt(o,e,t){return t?{stem:o,confidence:e,metadata:t}:{stem:o,confidence:e}}function re(o){let e="complex";return o.startsWith("#")&&!o.includes(" ")?e="id":o.startsWith(".")&&!o.includes(" ")?e="class":o.startsWith("[")&&o.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(o)&&(e="element"),{type:"selector",value:o,selectorKind:e}}function q(o,e){let t={type:"literal",value:o};return e!==void 0?{type:"literal",value:o,dataType:e}:t}function ke(o){return Qe(o)}function Z(o){return{type:"reference",value:o}}function ie(o,e){return{type:"property-path",object:o,property:e}}function H(o,e,t){let r={kind:"command",action:o,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function me(o,e,t,r,n,a){let i=new Map;i.set("event",o);let s={kind:"event-handler",action:"on",roles:i,body:e};return t!==void 0&&(s.eventModifiers=t),r!==void 0&&(s.metadata=r),n!==void 0&&n.length>0&&(s.parameterNames=n),a!==void 0&&a.length>0&&(s.additionalEvents=a),s}function fr(o,e,t,r,n){let a={kind:"behavior",action:"behavior",roles:new Map,name:o,parameters:e,eventHandlers:t};return r!==void 0&&r.length>0&&(a.initBlock=r),n!==void 0&&(a.metadata=n),a}function hr(o,e,t,r){let n={kind:"def",action:"def",roles:new Map,name:o,parameters:e,body:t};return r!==void 0&&(n.metadata=r),n}function qe(o,e="then",t){let r={kind:"compound",action:"compound",roles:new Map,statements:o,chainType:e};return t!==void 0&&(r.metadata=t),r}function yr(o,e,t,r){let n=new Map;n.set("condition",o);let a={kind:"conditional",action:"if",roles:n,thenBranch:e};return t!==void 0&&(a.elseBranch=t),r!==void 0&&(a.metadata=r),a}function Be(o,e){return!e||e.length===0||e.includes(o)||e.includes("expression")?!0:o==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):o==="expression"?e.some(t=>["selector","reference","expression"].includes(t)):!1}var go={action:"toggle",description:"Toggle a class or attribute on/off",category:"dom-class",primaryRole:"patient",roles:[{role:"patient",description:"The class or attribute to toggle",required:!0,expectedTypes:["selector"],selectorKinds:["class","attribute"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerVariants:{ko:["\uC5D0\uC11C"]}}],errorCodes:["MISSING_ARGUMENT","NO_VALID_CLASS_NAMES","INVALID_CSS_PROPERTY"],preconditions:[{condition:"Command has at least one argument",errorCode:"MISSING_ARGUMENT",message:"toggle command requires an argument"},{condition:"Class names are valid CSS identifiers",errorCode:"NO_VALID_CLASS_NAMES",message:"toggle command: no valid class names found"}],recoveryHints:{MISSING_ARGUMENT:"Add a class selector (.classname) or attribute to toggle",NO_VALID_CLASS_NAMES:"Ensure class names start with a dot (.) and are valid CSS identifiers",INVALID_CSS_PROPERTY:"Check CSS property name syntax (use kebab-case)"}},vo={action:"add",description:"Add a class or attribute to an element",category:"dom-class",primaryRole:"patient",roles:[{role:"patient",description:"The class or attribute to add",required:!0,expectedTypes:["selector","literal"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}],errorCodes:["MISSING_ARGUMENT","NO_VALID_CLASS_NAMES","PROPERTY_REQUIRES_VALUE"],preconditions:[{condition:"Command has at least one argument",errorCode:"MISSING_ARGUMENT",message:"add command requires an argument"}],recoveryHints:{MISSING_ARGUMENT:"Add a class selector (.classname) or attribute to add",NO_VALID_CLASS_NAMES:"Ensure class names start with a dot (.) and are valid CSS identifiers",PROPERTY_REQUIRES_VALUE:"When adding a property (*prop), provide a value argument"}},ko={action:"remove",description:"Remove a class or attribute from an element",category:"dom-class",primaryRole:"patient",targetRole:"source",roles:[{role:"patient",description:"The class/attribute to remove, or the element to remove",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to remove from (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}],errorCodes:["MISSING_ARGUMENT","NO_VALID_CLASS_NAMES"],preconditions:[{condition:"Command has at least one argument",errorCode:"MISSING_ARGUMENT",message:"remove command requires an argument"}],recoveryHints:{MISSING_ARGUMENT:"Add a class selector (.classname) or attribute to remove",NO_VALID_CLASS_NAMES:"Ensure class names start with a dot (.) and are valid CSS identifiers"}},So={action:"put",description:"Put content into a target element or variable",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The content to put",required:!0,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"destination",description:"Where to put the content",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"into"},markerVariants:{en:["before","after"]},methodCarrier:"method"}],errorCodes:["MISSING_ARGUMENTS","MISSING_CONTENT","MISSING_POSITION","INVALID_POSITION","NO_TARGET","NO_ELEMENTS"],preconditions:[{condition:"Command has content and position arguments",errorCode:"MISSING_ARGUMENTS",message:"put requires arguments"},{condition:"Content to put is specified",errorCode:"MISSING_CONTENT",message:"put requires content"},{condition:"Position keyword is specified (into, before, after, etc.)",errorCode:"MISSING_POSITION",message:"put requires position keyword"}],recoveryHints:{MISSING_ARGUMENTS:"Use syntax: put <content> into/before/after <target>",MISSING_CONTENT:"Add content to put (string, element, or expression)",MISSING_POSITION:"Add position keyword: into, before, after, at start of, at end of",INVALID_POSITION:"Valid positions: into, before, after, at start of, at end of",NO_TARGET:'Ensure target element exists or use "me" reference',NO_ELEMENTS:"Check that the selector matches existing elements"}},xo={action:"set",description:"Set a property or variable to a value",category:"variable",primaryRole:"destination",roles:[{role:"destination",description:"The property or variable to set",required:!0,expectedTypes:["selector","reference","expression","property-path"],svoPosition:1,sovPosition:1,markerOverride:{en:"",ja:"\u3092",ko:"\uB97C",tr:"i",ar:"",sw:"",tl:"",bn:"\u0995\u09C7",qu:"ta",hi:"\u0915\u094B"}},{role:"patient",description:"The value to set",required:!0,expectedTypes:["literal","expression","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"to",es:"a",pt:"para",fr:"\xE0",de:"auf",id:"ke",ja:"\u306B",ko:"\uC5D0",tr:"e",ar:"\u0625\u0644\u0649",sw:"kwenye",tl:"sa",bn:"\u09A4\u09C7",qu:"man",hi:"\u092E\u0947\u0902"},markerVariants:{tr:["e","a","ye","ya"]}},{role:"scope",description:"The element(s) the attribute/property is set on (defaults to me)",required:!1,expectedTypes:["selector","reference"],svoPosition:3,sovPosition:3,markerOverride:{en:"on",es:"on",pt:"on",fr:"on",de:"on",it:"on",id:"on",ms:"on",sw:"on",tl:"on",zh:"on",vi:"on",ru:"on",uk:"on",pl:"on",th:"on",he:"on",ar:"on",ja:"on",ko:"on",tr:"on",hi:"on",bn:"on",qu:"on"}}],errorCodes:["MISSING_TARGET","INVALID_TARGET","MISSING_VALUE","INVALID_SYNTAX"],preconditions:[{condition:"Command has a target variable or property",errorCode:"MISSING_TARGET",message:"set command requires a target"},{condition:"Target is a valid variable or property reference",errorCode:"INVALID_TARGET",message:"set command target must be a string or object literal"},{condition:'Value is specified with "to" keyword',errorCode:"MISSING_VALUE",message:'set command requires a value (use "to" keyword)'}],recoveryHints:{MISSING_TARGET:"Add a target: set :variable to value OR set element.property to value",INVALID_TARGET:'Use local variable (:name), element property (el.prop), or "the X of Y" syntax',MISSING_VALUE:'Add "to <value>" to specify what to set',INVALID_SYNTAX:"Use syntax: set <target> to <value>"}},bo={action:"bind",description:"Reactively bind a variable to an element or property value",category:"variable",primaryRole:"destination",roles:[{role:"destination",description:"The variable to bind",required:!0,expectedTypes:["reference","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"",es:"",pt:"",fr:"",de:"",it:"",id:"",ms:"",vi:"",ru:"",uk:"",pl:"",th:"",zh:"",he:"",ar:"",sw:"",tl:"",ja:"\u3092",ko:"\uB97C",tr:"i",bn:"\u0995\u09C7",qu:"ta",hi:"\u0915\u094B"}},{role:"source",description:"The element or property to bind to",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:2,markerOverride:{en:"to",es:"a",pt:"para",fr:"\xE0",de:"zu",it:"in",id:"ke",ms:"ke",vi:"v\xE0o",ru:"\u0432",uk:"\u0432",pl:"do",ja:"\u306B",ko:"\uC5D0",tr:"e",ar:"\u0625\u0644\u0649",zh:"\u5230",he:"\u05DC",sw:"kwa",th:"\u0E43\u0E19",tl:"sa",bn:"\u09A4\u09C7",qu:"man",hi:"\u092E\u0947\u0902"}}],errorCodes:["MISSING_TARGET","MISSING_VALUE","INVALID_SYNTAX"],recoveryHints:{MISSING_TARGET:"Add a variable to bind: bind $name to #input",MISSING_VALUE:'Add "to <element>" to specify the binding source',INVALID_SYNTAX:"Use syntax: bind <variable> to <element>"}},wo={action:"live",description:"Reactive block: re-run the body when its dependencies change",category:"control-flow",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},To={action:"eventsource",description:"Open a Server-Sent Events stream and handle its events",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},Eo={action:"socket",description:"Open a WebSocket and handle its messages",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},Co={action:"worker",description:"Define a Web Worker with inline methods",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},No={action:"intercept",description:"Service-worker fetch interception / caching strategies",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},Po={action:"show",description:"Make an element visible",category:"dom-visibility",primaryRole:"patient",roles:[{role:"patient",description:"The element to show",required:!0,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:!1,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},Lo={action:"hide",description:"Make an element invisible",category:"dom-visibility",primaryRole:"patient",roles:[{role:"patient",description:"The element to hide",required:!0,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:!1,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},Ro={action:"on",description:"Handle an event",category:"event",primaryRole:"event",hasBody:!0,roles:[{role:"event",description:"The event to handle",required:!0,expectedTypes:["literal"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to listen on (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Ao={action:"trigger",description:"Trigger/dispatch an event",category:"event",primaryRole:"event",roles:[{role:"event",description:"The event to trigger (supports namespaced events like draggable:start)",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Mo={action:"wait",description:"Wait for a duration or event",category:"async",primaryRole:"duration",roles:[{role:"duration",description:"Duration or event to wait for",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},Oo={action:"fetch",description:"Fetch data from a URL",category:"async",primaryRole:"source",roles:[{role:"source",description:"The URL to fetch from",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,renderOverride:{en:""}},{role:"responseType",description:"Response format (json, text, html, blob, etc.)",required:!1,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2,markerOverride:{en:"as"}},{role:"method",description:"HTTP method (GET, POST, etc.)",required:!1,expectedTypes:["literal"],svoPosition:3,sovPosition:3},{role:"destination",description:"Where to store the result",required:!1,expectedTypes:["selector","reference"],svoPosition:4,sovPosition:4}]},Vo={action:"increment",description:"Increment a numeric value",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The value to increment",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to increment by (defaults to 1)",required:!1,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},zo={action:"decrement",description:"Decrement a numeric value",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The value to decrement",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to decrement by (defaults to 1)",required:!1,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Io={action:"append",description:"Append content to an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The content to append",required:!0,expectedTypes:["literal","selector","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to append to",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},_o={action:"prepend",description:"Prepend content to an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The content to prepend",required:!0,expectedTypes:["literal","selector","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to prepend to",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},qo={action:"log",description:"Log a value to the console",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The value to log",required:!0,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Bo={action:"get",description:"Get a value from a source",category:"variable",primaryRole:"source",roles:[{role:"source",description:"The source to get from",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:2,markerOverride:{en:"",es:"",pt:"",fr:"",de:"",ja:"\u3092",zh:"",ko:"\uB97C",ar:"\u0639\u0644\u0649",tr:"i",id:"",he:"\u05D0\u05EA",sw:"",tl:"",bn:"\u0995\u09C7",qu:"ta"}},{role:"destination",description:"Where to store the result (optional)",required:!1,expectedTypes:["reference"],svoPosition:2,sovPosition:1}]},$o={action:"take",description:"Take content from a source element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The class or element to take",required:!0,expectedTypes:["selector"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to take from (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Do={action:"make",description:"Create a new element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element type or selector to create",required:!0,expectedTypes:["literal","selector"],svoPosition:1,sovPosition:1}]},jo={action:"halt",description:"Halt/stop execution or event propagation",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"What to halt (event, default, bubbling, etc.)",required:!1,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},Wo={action:"settle",description:"Wait for animations/transitions to settle",category:"async",primaryRole:"patient",roles:[{role:"patient",description:"The element to settle (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},Ko={action:"throw",description:"Throw an error",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The error message or object to throw",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},Uo={action:"send",description:"Send an event to an element",category:"event",primaryRole:"event",roles:[{role:"event",description:"The event to send",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerOverride:{en:"to",ja:"\u306B",ar:"\u0625\u0644\u0649",es:"a",ko:"\uC5D0\uAC8C",zh:"\u5230",tr:"-e",pt:"para",fr:"\xE0",de:"an",id:"ke",qu:"-man",sw:"kwa"}}]},Fo={action:"if",description:"Conditional execution",category:"control-flow",primaryRole:"condition",hasBody:!0,roles:[{role:"condition",description:"The condition to evaluate",required:!0,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},Ho={action:"unless",description:"Negated conditional execution (executes when condition is false)",category:"control-flow",primaryRole:"condition",hasBody:!0,roles:[{role:"condition",description:"The condition to evaluate (body executes when false)",required:!0,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},Go={action:"else",description:"Else branch of conditional",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[]},Yo={action:"repeat",description:"Repeat a block of commands",category:"control-flow",primaryRole:"loopType",hasBody:!0,roles:[{role:"loopType",description:"Loop variant: forever, times, for, while, until, until-event",required:!0,expectedTypes:["literal"],svoPosition:0,sovPosition:0},{role:"quantity",description:"Number of times to repeat",required:!1,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"event",description:"Event to wait for (terminates loop)",required:!1,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2},{role:"source",description:"Element to listen for event on",required:!1,expectedTypes:["selector","reference"],svoPosition:3,sovPosition:3}],notes:'Can also use "repeat forever", "repeat until condition", or "repeat until event X from Y"'},Zo={action:"for",description:"Iterate over a collection",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[{role:"patient",description:"The iteration variable",required:!0,expectedTypes:["reference","expression"],svoPosition:1,sovPosition:2},{role:"source",description:"The collection to iterate over",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"in",es:"en",fr:"en",de:"in",it:"in",pt:"dentro",id:"dalam",ms:"dalam",pl:"w",ru:"\u0432",uk:"\u0443",sw:"ndani",th:"\u0E43\u0E19",vi:"trong",ar:"\u0641\u064A",tl:"sa_loob",he:"in",zh:"\u5728"}}]},Jo={action:"while",description:"Loop while condition is true",category:"control-flow",primaryRole:"condition",hasBody:!0,roles:[{role:"condition",description:"The condition to check",required:!0,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},Xo={action:"continue",description:"Continue to next loop iteration",category:"control-flow",primaryRole:"patient",roles:[]},Qo={action:"go",description:"Navigate to a URL",category:"navigation",primaryRole:"destination",roles:[{role:"destination",description:"The URL to navigate to",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to"},renderOverride:{en:""},markerOptional:{en:!0},markerVariants:{he:["\u05D0\u05EA"],zh:["\u628A"]}}]},ea={action:"transition",description:"Transition an element with animation",category:"dom-visibility",primaryRole:"patient",omitRoleVariants:["goal"],roles:[{role:"patient",description:"The property to transition (opacity, *background-color, etc.)",required:!0,expectedTypes:["literal","expression","selector"],svoPosition:1,sovPosition:2,markerOverride:{en:"",ar:"",tl:"",sw:""}},{role:"goal",description:"The target value to transition to",required:!0,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:3,markerOverride:{en:"to",ar:"\u0625\u0644\u0649",tl:"sa",sw:"kwa",bn:"\u09A4\u09C7",qu:"man",es:"a",pt:"para",fr:"\xE0",de:"zu",he:"\u05E2\u05DC",it:"in",ja:"\u306B",ko:"\uC5D0",ms:"ke",pl:"do",ru:"\u0432",th:"\u0E43\u0E19",tr:"e",uk:"\u0432",vi:"v\xE0o",zh:"\u5230",id:"ke"}},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:3,sovPosition:1},{role:"duration",description:"Transition duration (over 500ms, for 2 seconds)",required:!1,expectedTypes:["literal"],svoPosition:4,sovPosition:4,markerOverride:{en:"over"}},{role:"style",description:"Easing function (ease-in, linear, etc.)",required:!1,expectedTypes:["literal"],svoPosition:5,sovPosition:5}]},ta={action:"clone",description:"Clone an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to clone",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"destination",description:"Where to put the clone",required:!1,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"into"}}]},ra={action:"focus",description:"Focus an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to focus (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},na={action:"blur",description:"Remove focus from an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to blur (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},oa={action:"empty",description:"Remove all children from an element (sets innerHTML to empty)",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to empty (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},aa={action:"open",description:"Open a dialog, details element, or popover",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to open (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:2},{role:"style",description:"Open-mode variant (modal / non-modal) for <dialog>",required:!1,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"as"}}]},ia={action:"close",description:"Close a dialog, details element, or popover",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to close (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},sa={action:"select",description:"Select the contents of a text field or DOM element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element whose contents to select (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},la={action:"clear",description:"Clear a variable, local, or input element",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The variable or element to clear (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ca={action:"reset",description:"Reset a <form> element to its default values",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The form element to reset (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ua={action:"breakpoint",description:"Drop into the debugger",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:!0},da={action:"call",description:"Call a function",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The function to call",required:!0,expectedTypes:["expression","reference"],markerOptional:{he:!0,zh:!0},svoPosition:1,sovPosition:1}]},pa={action:"return",description:"Return a value from a function",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The value to return",required:!1,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1}]},ma={action:"js",description:"Execute raw JavaScript code",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[{role:"patient",description:"The JavaScript code to execute",required:!1,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},fa={action:"async",description:"Execute commands asynchronously",category:"async",primaryRole:"patient",hasBody:!0,roles:[]},ha={action:"tell",description:"Execute commands in context of another element",category:"control-flow",primaryRole:"destination",hasBody:!0,roles:[{role:"destination",description:"The element to tell",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:"",he:"\u05D0\u05EA",zh:"\u628A"}}]},ya={action:"default",description:"Set a default value for a variable",category:"variable",primaryRole:"destination",roles:[{role:"destination",description:"The variable to set default for",required:!0,expectedTypes:["selector","reference","expression","property-path"],svoPosition:1,sovPosition:1,markerOverride:{en:"",ar:"",tl:"",sw:"",bn:"\u0995\u09C7",qu:"ta",ja:"\u3092",ko:"\uB97C",tr:"i",hi:"\u0915\u094B",de:"",es:"",fr:"",it:"",pt:"",pl:"",ru:"",uk:"",vi:"",id:"",ms:"",th:"",zh:"\u628A",he:"\u05D0\u05EA"}},{role:"patient",description:"The default value",required:!0,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2,markerOverride:{en:"to",ar:"\u0625\u0644\u0649",tl:"sa",sw:"kwa",bn:"\u09A4\u09C7",qu:"man",ja:"\u306B",ko:"\uC5D0",tr:"e",hi:"\u092E\u0947\u0902",de:"zu",es:"a",fr:"\xE0",it:"in",pt:"para",pl:"do",ru:"\u0432",uk:"\u0432",vi:"v\xE0o",id:"ke",ms:"ke",th:"\u0E43\u0E19",zh:"\u5230",he:"\u05E2\u05DC"}}]},ga={action:"init",description:"Initialization block that runs once",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[]},va={action:"behavior",description:"Define a reusable behavior",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[{role:"patient",description:"The behavior name (PascalCase identifier)",required:!0,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},ka={action:"install",description:"Install a behavior on an element",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The behavior name to install",required:!0,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"Element to install on (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Sa={action:"measure",description:"Measure element dimensions (x, y, width, height, etc.)",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"Property to measure (x, y, width, height, top, left, etc.)",required:!1,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"source",description:"Element to measure (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:2,markerOverride:{en:"of"}}]},xa={action:"swap",description:"Swap DOM content using various strategies (innerHTML, outerHTML, delete, etc.)",category:"dom-content",primaryRole:"destination",roles:[{role:"method",description:"The swap strategy (innerHTML, outerHTML, beforebegin, afterend, delete)",required:!1,expectedTypes:["literal"],svoPosition:1,sovPosition:3,markerOverride:{en:""}},{role:"destination",description:"The element to swap content in/for",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"of",es:"",fr:"",pt:"",it:"",de:"",pl:"",ru:"",uk:"",id:"",ms:"",sw:"",th:"",vi:"",he:"\u05D0\u05EA",zh:"\u628A"}},{role:"patient",description:"The content to swap in (optional for delete)",required:!1,expectedTypes:["literal","expression","selector"],svoPosition:3,sovPosition:2,markerOverride:{en:"with",es:"con",fr:"avec",pt:"com",it:"con",de:"mit",pl:"z",ru:"\u0441",uk:"\u0437",id:"dengan",ms:"dengan",sw:"na",th:"\u0E14\u0E49\u0E27\u0E22",vi:"v\u1EDBi",he:"\u05E2\u05DD",zh:"\u7528"}}]},ba={action:"morph",description:"Morph an element into another using DOM diffing",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to morph",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:""}},{role:"destination",description:"The target content/element to morph into",required:!0,expectedTypes:["literal","expression","selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"to"}}]},wa={action:"beep",description:"Debug output for expressions with type information",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The expression(s) to debug",required:!1,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ta={action:"break",description:"Exit from the current loop",category:"control-flow",primaryRole:"patient",roles:[]},Ea={action:"copy",description:"Copy text or element content to the clipboard",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The text or element to copy",required:!0,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ca={action:"exit",description:"Exit from the current event handler",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:!0},Na={action:"pick",description:"Select a random element from a collection",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The items to pick from",required:!0,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1},{role:"source",description:'The array to pick from (with "from" keyword)',required:!1,expectedTypes:["reference","expression"],svoPosition:2,sovPosition:2}]},Pa={action:"scroll",description:"Scroll the viewport to a target element",category:"navigation",primaryRole:"destination",argSkipTokens:["of","the","top","bottom","middle","center","nearest","left","right","smoothly","instantly"],roles:[{role:"destination",description:"The element to scroll to",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to"}}]},gr={en:"url",es:"url",pt:"url",fr:"url",de:"url",it:"url",ja:"url",ko:"url",zh:"url",ar:"url",he:"url",hi:"url",bn:"url",tr:"url",ru:"url",uk:"url",pl:"url",id:"url",vi:"url",th:"url",ms:"url",tl:"url",sw:"url",qu:"url"},La={en:"partials in",es:"partials in",pt:"partials in",fr:"partials in",de:"partials in",it:"partials in",ja:"partials in",ko:"partials in",zh:"partials in",ar:"partials in",he:"partials in",hi:"partials in",bn:"partials in",tr:"partials in",ru:"partials in",uk:"partials in",pl:"partials in",id:"partials in",vi:"partials in",th:"partials in",ms:"partials in",tl:"partials in",sw:"partials in",qu:"partials in"},Ra={action:"push",description:"Push a URL onto the browser history",category:"navigation",primaryRole:"patient",roles:[{role:"patient",description:"The URL to push (after the `url` keyword)",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:gr}]},Aa={action:"replace",description:"Replace the current browser history entry with a URL",category:"navigation",primaryRole:"patient",roles:[{role:"patient",description:"The URL to replace with (after the `url` keyword)",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:gr}]},Ma={action:"process",description:"Process hx-partial markup in HTML content",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The HTML content (string, element, or response) to process",required:!0,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:La}]},Oa={action:"render",description:"Render a template with optional variables",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The template to render",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"style",description:"Variables to pass to the template (with keyword)",required:!1,expectedTypes:["expression","reference"],svoPosition:2,sovPosition:1}]},Ne={toggle:go,add:vo,remove:ko,put:So,set:xo,show:Po,hide:Lo,on:Ro,trigger:Ao,wait:Mo,fetch:Oo,increment:Vo,decrement:zo,append:Io,prepend:_o,log:qo,get:Bo,take:$o,make:Do,halt:jo,settle:Wo,throw:Ko,send:Uo,if:Fo,unless:Ho,else:Go,repeat:Yo,for:Zo,while:Jo,continue:Xo,go:Qo,scroll:Pa,push:Ra,replace:Aa,process:Ma,transition:ea,clone:ta,focus:ra,blur:na,empty:oa,open:aa,close:ia,select:sa,clear:la,reset:ca,breakpoint:ua,call:da,return:pa,js:ma,async:fa,tell:ha,default:ya,init:ga,behavior:va,install:ka,measure:Sa,swap:xa,morph:ba,beep:wa,break:Ta,copy:Ea,exit:Ca,pick:Na,render:Oa,bind:bo,live:wo,eventsource:To,socket:Eo,worker:Co,intercept:No,compound:{action:"compound",description:"A compound node representing chained statements",primaryRole:"patient",category:"control-flow",hasBody:!0,roles:[]}};function ne(o){return Ne[o]}function ce(o,e){let t=o.possessive?.keywords?.[e];if(t)return t;let r=o.possessive?.specialForms;if(r){for(let[n,a]of Object.entries(r))if(a===e)return n}}var vr=[{lang:"es",verb:"poner",verbAlts:["pon","colocar","put"],at:"en",end:"fin",of:"de"},{lang:"fr",verb:"mettre",at:"\xE0",end:"fin",of:"de"},{lang:"pt",verb:"colocar",at:"em",end:"fim",of:"de"},{lang:"it",verb:"mettere",at:"a",end:"fine",of:"di"},{lang:"de",verb:"setzen",at:"bei",end:"ende",of:"von"},{lang:"sw",verb:"weka",at:"katika",end:"mwisho",of:"ya"},{lang:"id",verb:"taruh",verbAlts:["letakkan","masukkan","tempatkan"],at:"di",end:"akhir",of:"dari"},{lang:"ms",verb:"letak",at:"di",end:"tamat",of:"daripada"},{lang:"vi",verb:"\u0111\u1EB7t",at:"t\u1EA1i",end:"k\u1EBFt th\xFAc",of:"c\u1EE7a"},{lang:"pl",verb:"umie\u015B\u0107",at:"przy",end:"koniec",of:"z"},{lang:"ru",verb:"\u043F\u043E\u043B\u043E\u0436\u0438\u0442\u044C",at:"\u0443",end:"\u043A\u043E\u043D\u0435\u0446",of:"\u0438\u0437"},{lang:"uk",verb:"\u043F\u043E\u043A\u043B\u0430\u0441\u0442\u0438",at:"\u0432",end:"\u043A\u0456\u043D\u0435\u0446\u044C",of:"\u0437"},{lang:"th",verb:"\u0E43\u0E2A\u0E48",at:"\u0E17\u0E35\u0E48",end:"\u0E08\u0E1A",of:"\u0E02\u0E2D\u0E07"},{lang:"tl",verb:"ilagay",at:"sa",end:"wakas",of:"ng"},{lang:"ar",verb:"\u0636\u0639",at:"\u0639\u0646\u062F",end:"\u0627\u0644\u0646\u0647\u0627\u064A\u0629",of:"\u0645\u0646"},{lang:"zh",verb:"\u653E\u7F6E",verbAlts:["\u653E","\u653E\u5165"],patientPrefix:"\u628A",at:"\u5728",end:"\u7ED3\u675F",of:"\u7684"},{lang:"he",verb:"\u05E9\u05D9\u05DD",patientPrefix:"\u05D0\u05EA",at:"at",end:"\u05E1\u05D5\u05E3",of:"of"},{lang:"tr",verb:"koy",sov:!0,objMarker:"i",at:"de",end:"son",of:"nin"},{lang:"ja",verb:"\u7F6E\u304F",sov:!0,objMarker:"\u3092",at:"\u3067",end:"\u7D42\u308F\u308A",of:"\u306E"},{lang:"ko",verb:"\uB123\uB2E4",sov:!0,objMarker:"\uB97C",at:"\uC5D0",end:"\uB05D",of:"\uC758"},{lang:"hi",verb:"\u0930\u0916\u0947\u0902",verbAlts:["\u0930\u0916","\u0921\u093E\u0932\u0947\u0902","\u0921\u093E\u0932"],sov:!0,objMarker:"\u0915\u094B",at:"\u092A\u0930",end:"\u0938\u092E\u093E\u092A\u094D\u0924",of:"\u0915\u093E"},{lang:"bn",verb:"\u09B0\u09BE\u0996\u09C1\u09A8",verbAlts:["\u09B0\u09BE\u0996"],sov:!0,objMarker:"\u0995\u09C7",at:"\u098F",end:"\u09B6\u09C7\u09B7",of:"\u09B0"},{lang:"qu",verb:"churay",sov:!0,objMarker:"ta",at:"pi",end:"tukuy",of:"pa"}];function Pt(o,e,t,r){let n=vr.find(i=>i.lang===o);if(!n)return!1;let a=(i,s)=>(i??"").toLowerCase()===s.toLowerCase();return a(e,n.end)&&a(t,n.at)&&a(r,n.of)}function kr(o,e){let t=vr.find(n=>n.lang===o);if(!t)return!1;let r=e.toLowerCase();return r===t.at.toLowerCase()||r===t.of.toLowerCase()||r===t.end.toLowerCase()}var Sr=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"]),Va={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"]},Lt=class{calculate(e){return this.calculateWithBreakdown(e).final}calculateWithBreakdown(e){let t=this.scoreRoleCoverage(e),r=this.scoreStemPenalty(e),n=this.scoreLanguageBoost(e),a=this.scoreLanguageAdjustment(e),i=t;return i=Math.max(.5,i+r),i=Math.min(1,i+n),i=Math.max(0,Math.min(1,i+a)),{roleCoverage:t,stemPenalty:r,languageBoost:n,languageAdjustment:a,final:i}}scoreRoleCoverage(e){let{pattern:t,captured:r}=e,n=0,a=0,i=s=>t.extraction?.[s]?.default!==void 0;for(let s of t.template.tokens)if(s.type==="role")a+=1,r.has(s.role)&&(n+=1);else if(s.type==="group")for(let l of s.tokens)l.type==="role"&&(a+=.8,r.has(l.role)?n+=.8:i(l.role)&&(n+=.8*.6));return a>0?n/a:1}scoreStemPenalty(e){let{stemMatchCount:t,totalKeywordMatches:r}=e;return t<=0||r<=0?0:-(t/r)*.15}scoreLanguageBoost(e){let{pattern:t}=e;if(t.language!=="ar")return 0;let r=t.template.tokens[0];return!r||r.type!=="literal"?0:Sr.has(r.value)||r.alternatives?.some(n=>Sr.has(n))?.15:0}scoreLanguageAdjustment(e){let{pattern:t,captured:r}=e;if(t.language!=="ar")return 0;let n=0;for(let[a,i]of r.entries()){let s=Va[a];if(!s||s.length===0)continue;let l="metadata"in i?i.metadata:void 0;l&&typeof l.prepositionValue=="string"&&(s.includes(l.prepositionValue)?n+=.1:n-=.1)}return Math.max(-.1,Math.min(.1,n))}},xr=new Lt;var za=new Set(Object.values(Ne).filter(o=>o.bareKeyword===!0).map(o=>o.action)),A=class A{constructor(e){this.matchCache=new Map;this.stemMatchCount=0;this.totalKeywordMatches=0;this.confidenceModel=e??xr}matchPattern(e,t){let r=e.mark(),n=new Map;if(this.currentProfile=z(t.language),this.currentPatternCommand=t.command,this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,n))return e.reset(r),null;let i=this.confidenceModel.calculate({pattern:t,captured:n,stemMatchCount:this.stemMatchCount,totalKeywordMatches:this.totalKeywordMatches});return this.applyExtractionRules(t,n),{pattern:t,captured:n,consumedTokens:e.position()-r.position,confidence:i}}matchBest(e,t){this.matchCache.clear();let r=[],n=e.position();for(let i of t){let s=e.mark(),l=`${n}:${i.id}`,c;this.matchCache.has(l)?c=this.matchCache.get(l):(c=this.matchPattern(e,i),this.matchCache.set(l,c)),c&&r.push(c),e.reset(s)}if(r.length===0)return null;r.sort((i,s)=>{let l=s.pattern.priority-i.pattern.priority;return l!==0?l:s.confidence-i.confidence});let a=r[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,t,r,n){let a=t[0],i=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!i)for(;e.peek()?.kind==="conjunction";)e.advance();let s=0;for(let l=0;l<t.length;l++){let c=t[l];s>0&&c.type==="literal"&&this.tryConsumeEventSourceClause(e,r,c);let d=this.matchPatternToken(e,c,r,t[l+1]??n);if(s=c.type==="role"&&c.role==="event"?2:Math.max(0,s-1),!d){if(this.isOptional(c))continue;return!1}}return!0}tryConsumeEventSourceClause(e,t,r){if(t.has("source"))return;let n=e.peek(),a=e.peek(1);if(!n||!a||this.patternTokenWouldMatch(r,n))return;let i=this.currentProfile?.roleMarkers?.source,s=c=>{if(c.kind!=="particle"&&c.kind!=="keyword")return!1;if((c.normalized??"").toLowerCase()==="source")return!0;if(!i)return!1;let d=c.value.toLowerCase();return i.primary?.toLowerCase()===d?!0:!!i.alternatives?.some(u=>u.toLowerCase()===d)},l=i?.position;if(l!=="after"&&s(n)&&a.kind==="selector"){e.advance();let c=this.tokenToSemanticValue(e.advance());c&&t.set("source",c);return}if(l==="after"&&n.kind==="selector"&&s(a)){let c=this.tokenToSemanticValue(n);e.advance(),e.advance(),c&&t.set("source",c)}}matchPatternToken(e,t,r,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r,n);case"group":return this.matchGroupToken(e,t,r,n);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(!r)return!1;let n=this.getMatchType(r,t.value);if(n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let a of t.alternatives){let i=this.getMatchType(r,a);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0}for(let a of[t.value,...t.alternatives??[]])for(let i of["-","_"])if(a.includes(i)&&this.tryMatchShatteredCompound(e,a,i))return this.totalKeywordMatches++,!0;return!1}tryFoldHyphenActionKeyword(e){let t=this.currentProfile;if(!t)return null;let r=e.mark(),n=[];for(;;){let i=e.peek();if(!i||i.kind!=="identifier"&&i.kind!=="keyword")break;n.push(i.value),e.advance();let s=e.peek();if(!s||s.value!=="-")break;e.advance(),n.push("-")}if(n.length<3||n[n.length-1]==="-")return e.reset(r),null;let a=n.join("").toLowerCase();for(let[i,s]of Object.entries(t.keywords))if(s.primary.toLowerCase()===a||s.alternatives?.some(l=>l.toLowerCase()===a))return q(i);return e.reset(r),null}tryMatchShatteredCompound(e,t,r){let n=t.split(r);if(n.length<2||n.some(i=>i.length===0))return!1;let a=e.mark();for(let i=0;i<n.length;i++){if(i>0){let l=e.peek();if(!l||l.value!==r)return e.reset(a),!1;e.advance()}let s=e.peek();if(!s||s.kind!=="identifier"&&s.kind!=="keyword"&&s.kind!=="particle"||s.value.toLowerCase()!==n[i].toLowerCase())return e.reset(a),!1;e.advance()}return!0}matchRoleToken(e,t,r,n){this.skipNoiseWords(e);let a=e.peek();if(!a)return t.optional||!1;if(t.role==="action"&&this.currentProfile&&e.peek(1)?.value==="-"){let g=this.tryFoldHyphenActionKeyword(e);if(g)return r.set(t.role,g),!0}if(t.role==="event"&&this.currentPatternCommand==="on"){if(!A.tokenLooksLikeEvent(a))return t.optional||!1;let g=(a.normalized??a.value).toLowerCase();if(A.POSITIONAL_OR_SCOPE_KEYWORDS.has(g)||this.currentProfile&&(ce(this.currentProfile,a.value)??ce(this.currentProfile,g))!==void 0||a.value.includes("?."))return t.optional||!1}if(t.role==="event"){let g=(a.normalized??a.value).toLowerCase();if(A.STRUCTURAL_NEVER_EVENT.has(g))return t.optional||!1}if(t.role==="duration"){let g=(a.normalized??a.value).toLowerCase();if(A.POSITIONAL_OR_SCOPE_KEYWORDS.has(g))return t.optional||!1}if(t.optional&&n===void 0&&t.role!=="event"&&t.role!=="action"&&a.kind==="keyword"&&(a.normalized??a.value).toLowerCase()in Ne)return!0;let i=this.tryMatchPositionalExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(i.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,i),!0);let s=this.tryMatchCaretScopeExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);if(t.role!=="event"&&(!t.expectedTypes||t.expectedTypes.includes("expression"))){let g=this.tryMatchOperatorRunExpression(e);if(g)return r.set(t.role,g),!0}if(t.expectedTypes?.includes("property-path")){let g=this.tryMatchOfPossessiveExpression(e);if(g)return r.set(t.role,g),!0;let x=this.tryMatchPostNominalPossessiveExpression(e);if(x)return r.set(t.role,x),!0}let l=this.tryMatchPossessiveExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(l.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,l),!0);let c=this.tryMatchMethodCallExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,c),!0);let u=t.role==="event"&&this.currentPatternCommand==="on"||A.DECLARATION_COMMANDS.has(this.currentPatternCommand??"")?null:this.tryMatchBareCallExpression(e);if(u)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(u.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,u),!0);let f=this.tryMatchPossessiveSelectorExpression(e);if(f)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(f.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,f),!0);let m=t.role!=="condition",p=this.tryMatchPropertyAccessExpression(e,m);if(p)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(p.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,p),!0);let h=this.tryMatchSelectorPropertyExpression(e);if(h)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(h.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,h),!0);if(a.kind==="identifier"&&a.value==="{"&&(!t.expectedTypes?.length||t.expectedTypes.includes("literal"))){let g=this.tryMatchBraceRunLiteral(e);if(g)return r.set(t.role,g),!0}let y=this.tokenToSemanticValue(a);if(!y)return t.optional||!1;if(t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(y.type)){let g=y.type==="selector"&&String(y.value).startsWith("@"),x=t.expectedTypes.some(T=>T==="expression"||T==="reference");if(!(g&&x))return t.optional||!1}if(r.set(t.role,y),e.advance(),t.role==="event"){let g=e.peek();g&&g.kind==="selector"&&g.value.startsWith("[")&&"value"in y&&(r.set(t.role,q(`${String(y.value)}${g.value}`)),e.advance());let x=e.peek();if(x&&(x.kind==="particle"||x.kind==="keyword")&&(x.normalized??"").toLowerCase()==="source"&&!this.patternTokenWouldMatch(n,x)){let T=e.peek(1);if(T&&(T.kind==="selector"||T.kind==="identifier")){e.advance();let C=this.tokenToSemanticValue(e.advance());C&&!r.has("source")&&r.set("source",C)}}}return!0}patternTokenWouldMatch(e,t){return e?e.type==="literal"?this.getMatchType(t,e.value)!=="none"?!0:!!e.alternatives?.some(r=>this.getMatchType(t,r)!=="none"):e.type==="group"?this.patternTokenWouldMatch(e.tokens?.[0],t):!1:!1}tryMatchPositionalExpression(e){let t=e.peek();if(!t)return null;let r=(t.normalized??t.value).toLowerCase();if(!A.POSITIONAL_KEYWORDS.has(r)&&!A.POSITIONAL_KEYWORDS.has(t.value.toLowerCase()))return null;let n=e.mark(),a=[t.normalized??t.value];e.advance();let i=e.peek();if(!i||i.kind!=="selector")return e.reset(n),null;a.push(i.value),e.advance();let s=0;for(;s++<8;){let d=e.peek();if(d&&d.kind==="selector"&&d.value.startsWith("."))a.push(d.value),e.advance();else break}let l=e.peek(),c=e.peek(1);return l&&c&&c.kind==="selector"&&(l.kind==="keyword"||l.kind==="particle"||l.kind==="identifier")&&!A.POSITIONAL_KEYWORDS.has((l.normalized??l.value).toLowerCase())&&!A.COMMAND_ACTION_KEYWORDS.has((l.normalized??l.value).toLowerCase())&&(a.push(l.normalized??l.value,c.value),e.advance(),e.advance()),{type:"expression",raw:a.join(" ")}}tryMatchCaretScopeExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"||!t.value.startsWith("^"))return null;let r=e.peek(1),n=e.peek(2),a=(r?.normalized??"").toLowerCase(),i=!!r&&(r.value.toLowerCase()==="on"||a==="destination"||a==="on");return!r||!n||n.kind!=="selector"||!i?null:(e.advance(),e.advance(),e.advance(),{type:"expression",raw:`${t.value} on ${n.value}`})}isOfPossessiveMarker(e){let t=e.value.toLowerCase(),r=(e.normalized??"").toLowerCase();if(t==="of"||t==="ng"||r==="of"||r==="source")return!0;let n=this.currentProfile?.code?A.OF_POSSESSIVE_MARKERS[this.currentProfile.code]:void 0;return!!n&&n.has(t)}tryMatchOperatorRunExpression(e){let t=e.mark(),r=e.position();if(!this.tryConsumeRunOperand(e))return e.reset(t),null;let n=1;for(;;){let i=e.peek();if(!i||!A.RUN_OPERATORS.has(i.value))break;let s=e.mark();if(e.advance(),!this.tryConsumeRunOperand(e)){e.reset(s);break}n++}if(n<2)return e.reset(t),null;let a=e.tokens.slice(r,e.position()).map(i=>i.value).join(" ");return{type:"expression",raw:a,value:a}}tryConsumeRunOperand(e){let t=e.peek();if(!t)return!1;if(t.value==="("){let r=e.mark(),n=0;for(;!e.isAtEnd();){let a=e.advance();if(a.value==="(")n++;else if(a.value===")"&&(n--,n===0))return!0}return e.reset(r),!1}return this.tryMatchPossessiveExpression(e)?!0:(t.kind==="literal"||t.kind==="identifier"||t.kind==="selector"||t.kind==="keyword")&&!A.RUN_OPERATORS.has(t.value)&&t.value!==")"?(e.advance(),!0):!1}tryMatchOfPossessiveExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||!this.isOfPossessiveMarker(n))return e.reset(r),null;e.advance();let a=e.peek();return!a||a.kind!=="selector"?(e.reset(r),null):(e.advance(),ie(re(a.value),t.value))}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=[t.value,t.normalized].filter(Boolean),n;for(let l of r)if(n=ce(this.currentProfile,l)??ce(this.currentProfile,l.toLowerCase()),n)break;if(!n)return null;let a=e.mark();e.advance();let i=this.currentProfile.possessive?.connectors;if(i&&i.length>0){let l=e.peek();if(l){let c=l.value.toLowerCase(),d=(l.normalized??"").toLowerCase();i.some(u=>u.toLowerCase()===c||u.toLowerCase()===d)&&e.advance()}}let s=e.peek();if(!s||kr(this.currentProfile.code,s.value))return e.reset(a),null;if(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)&&!(s.normalized&&this.isStructuralKeyword(s.normalized))&&!(s.normalized&&this.isRoleMarkerConcept(s.normalized))||s.kind==="selector"&&s.value.startsWith("*")||s.kind==="selector"&&s.value.startsWith("@")||s.kind==="selector"&&s.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s.value)){e.advance();let l=s.value;s.kind==="selector"&&l.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(l)&&(l=l.substring(1));let c=l;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)c+=e.peek().value,e.advance();let d=e.peek();if(d&&d.value.startsWith("(")){let u="",f=0,m=0;for(;!e.isAtEnd()&&m++<A.MAX_METHOD_ARGS+2;){let p=e.peek();if(!p)break;u+=p.value,e.advance();for(let h of p.value)h==="("?f++:h===")"&&f--;if(f<=0)break}c+=u}return ie(Z(n),c)}return e.reset(a),null}tryMatchPostNominalPossessiveExpression(e){if(!this.currentProfile||this.currentProfile.possessive?.markerPosition!=="after-object")return null;let t=u=>{for(let f of[u.value,u.normalized].filter(Boolean))if(ce(this.currentProfile,f)??ce(this.currentProfile,f.toLowerCase()))return!0;return!1},r=e.peek();if(!r)return null;let n=r.kind==="selector"&&r.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(r.value);if(!(r.kind==="identifier"&&!this.isStructuralKeyword(r.value)&&!(r.normalized&&this.isStructuralKeyword(r.normalized))&&!(r.normalized&&this.isRoleMarkerConcept(r.normalized))||r.kind==="selector"&&(r.value.startsWith("*")||r.value.startsWith("@"))||n)||t(r))return null;let i=e.mark(),s=r.value;n&&(s=s.substring(1)),e.advance();let l=s;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)l+=e.peek().value,e.advance();let c=e.peek();if(!c)return e.reset(i),null;let d;for(let u of[c.value,c.normalized].filter(Boolean))if(d=ce(this.currentProfile,u)??ce(this.currentProfile,u.toLowerCase()),d)break;return d?(e.advance(),ie(Z(d),l)):(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())}isRoleMarkerConcept(e){return new Set(["destination","source","patient","object","event","eventmarker","manner","instrument"]).has(e.toLowerCase())}static tokenLooksLikeEvent(e){if(e.kind==="selector"||e.kind==="url"||e.kind==="literal")return!1;let t=e.value;if(/[/#@*]/.test(t)||t.startsWith('"')||t.startsWith("'")||t.startsWith("`"))return!1;let r=e.normalized?.toLowerCase();return!(r&&za.has(r))}tryMatchBraceRunLiteral(e){let t=e.peek();if(!t||t.kind!=="identifier"||t.value!=="{")return null;let r=e.mark();e.advance();let n=["{"],a=1,i=0;for(;!e.isAtEnd()&&i++<A.MAX_BRACE_RUN_TOKENS;){let s=e.advance();if(!s)break;if(s.value==="{")a++;else if(s.value==="}"&&(a--,a===0))return n.push("}"),q(n.join(" "));n.push(s.value)}return e.reset(r),null}tryMatchBareCallExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"||!/^[A-Za-z_][\w$]*$/.test(t.value))return null;let r=e.peek(1);if(!r||r.value!=="(")return null;let n=e.mark();e.advance(),e.advance();let a=[],i=!1,s=0;for(;!e.isAtEnd()&&s++<A.MAX_METHOD_ARGS+2;){let l=e.peek();if(!l)break;if(l.value===")"){e.advance(),i=!0;break}if(l.value===","){e.advance();continue}a.push(l.value),e.advance()}return i?{type:"expression",raw:`${t.value}(${a.join(", ")})`}:(e.reset(n),null)}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(r),null;e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<A.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${a.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e,t=!0){let r=e.peek();if(!r||r.kind!=="identifier"&&r.kind!=="keyword")return null;let n=e.mark();e.advance();let a=r.value.toLowerCase(),i=e.peek();if((r.kind==="identifier"||A.PROPERTY_ACCESS_BASES.has(a))&&i&&i.kind==="selector"&&/^\.[a-zA-Z_]/.test(i.value)){let m=r.value,p=[],h=0;for(;h<A.MAX_PROPERTY_DEPTH;){let x=e.peek();if(x&&x.kind==="selector"&&/^\.[a-zA-Z_]/.test(x.value))m+=`.${x.value.slice(1)}`,p.push(x.value.slice(1)),e.advance(),h++;else break}let y=e.peek(),g=!!y&&y.value.startsWith("(");if(t&&!g&&p.length>0&&ke(a))return ie(Z(a),p.join("."));if(g){let x=e.mark(),T=[],C=0,S=!1;for(;!e.isAtEnd();){let k=e.peek();if(!k)break;if(k.value==="(")C++;else if(k.value===")"){if(T.push(k.value),e.advance(),C--,C===0&&(S=!0),S)break;continue}T.push(k.value),e.advance()}S?m+=T.join(""):e.reset(x)}return{type:"expression",raw:m}}let s=e.peek();if(!s||s.kind!=="operator"||s.value!==".")return e.reset(n),null;e.advance();let l=e.peek();if(!l||l.kind!=="identifier")return e.reset(n),null;e.advance();let c=`${r.value}.${l.value}`,d=1;for(;!e.isAtEnd()&&d<A.MAX_PROPERTY_DEPTH;){let m=e.peek();if(!m||m.kind!=="operator"||m.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),c+=`.${p.value}`,d++}let u=e.peek();if(u&&u.kind==="punctuation"&&u.value==="("){e.advance();let m=[],p=0;for(;!e.isAtEnd()&&m.length<A.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}m.push(y.value),e.advance()}return{type:"expression",raw:`${c}(${m.join(", ")})`}}let f=r.value.toLowerCase();if(t&&ke(f)){let m=c.split(".").slice(1).join(".");return ie(Z(f),m)}return{type:"expression",raw:c}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek(),a=this.currentProfile?.possessive?.marker?.replace(/^-/,""),i=!!n&&n.kind==="punctuation"&&n.value==="'s",s=!!n&&n.value==="'"&&(e.peek(1)?.value??"").toLowerCase()==="s",l=(()=>{if(!this.currentPatternCommand||(n?.normalized??"").toLowerCase()!=="source")return!1;let f=Ne[this.currentPatternCommand];return!!f&&f.roles.some(m=>m.role==="source")})(),c=!!n&&!!a&&a!=="'s"&&n.value===a&&(n.kind==="particle"||n.kind==="punctuation")&&!l;if(!i&&!c&&!s)return e.reset(r),null;e.advance(),s&&e.advance();let d=e.peek();return!d||!(d.kind==="identifier"||(i||s)&&(d.kind==="selector"||d.kind==="keyword"))?(e.reset(r),null):(e.advance(),ie(re(t.value),d.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(r),null;let a=e.peek(1);a&&a.kind,e.advance();let i=n.value.slice(1);return ie(re(t.value),i)}matchGroupToken(e,t,r,n){let a=e.mark(),i=new Set(r.keys());if(!this.matchTokenSequence(e,t.tokens,r,n)){e.reset(a);for(let l of r.keys())i.has(l)||r.delete(l);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 re(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return ke(t)?Z(t):q(e.normalized||e.value);case"identifier":if(e.value.startsWith("@"))return re(e.value);if(e.value.startsWith(":")||e.value.startsWith("$"))return Z(e.value);let r=e.value.toLowerCase();return ke(r)?Z(r):{type:"expression",raw:e.value};case"url":return q(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let n=e.slice(1,-1);return q(n,"string")}if(e==="true")return q(!0,"boolean");if(e==="false")return q(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let n=parseFloat(t[1]);return t[2]?q(e,"duration"):q(n,"number")}let r=parseFloat(e);return isNaN(r)?q(e,"string"):q(r,"number")}applyExtractionRules(e,t){for(let[r,n]of Object.entries(e.extraction))t.has(r)||(n.value!==void 0?t.set(r,{type:"literal",value:n.value}):n.default&&t.set(r,n.default))}isOptional(e){return e.type!=="literal"&&e.optional===!0}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=t.value.toLowerCase();if(A.ENGLISH_NOISE_WORDS.has(r)){let n=e.mark();e.advance();let a=e.peek();if(a&&(a.kind==="selector"||a.kind==="identifier"))return;let i=e.peek(1);if(a&&a.kind==="keyword"&&i&&i.kind==="selector"&&/^\.[a-zA-Z_]/.test(i.value))return;let s=a?(a.normalized??a.value).toLowerCase():"";if(a&&A.POSITIONAL_OR_SCOPE_KEYWORDS.has(s))return;let l=e.peek(1),c=l?(l.normalized??l.value).toLowerCase():"",d=this.currentProfile?.wordOrder!=="SOV"&&A.COMMAND_ACTION_KEYWORDS.has(c),u=!l||l.kind==="particle"||A.CLAUSE_BOUNDARY_KEYWORDS.has(c)||d;if(a&&a.kind==="keyword"&&this.currentProfile?.code!=="en"&&ke(s)&&u||a&&a.kind==="keyword"&&this.currentProfile?.code==="en"&&ke(s))return;e.reset(n)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(r=!0,a.modifierName){case"once":t.once=!0;break;case"debounce":typeof a.value=="number"&&(t.debounce=a.value);break;case"throttle":typeof a.value=="number"&&(t.throttle=a.value);break;case"queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(t.queue=a.value);break}e.advance()}return r?t:void 0}};A.POSITIONAL_KEYWORDS=new Set(["first","last","next","previous","random","closest"]),A.POSITIONAL_OR_SCOPE_KEYWORDS=new Set(["first","last","next","previous","random","closest","parent"]),A.STRUCTURAL_NEVER_EVENT=new Set(["if","unless","else","end","then"]),A.PROPERTY_ACCESS_BASES=new Set(["it","me","you","my","its","your","event","result","target","detail","body","window","document","self","this"]),A.COMMAND_ACTION_KEYWORDS=new Set(Object.keys(Ne).map(e=>e.toLowerCase())),A.CLAUSE_BOUNDARY_KEYWORDS=new Set(["then","and","or","end","else"]),A.OF_POSSESSIVE_MARKERS={ms:new Set(["daripada"]),sw:new Set(["ya"]),vi:new Set(["c\u1EE7a"]),zh:new Set(["\u7684"]),it:new Set(["di"]),pl:new Set(["z"]),uk:new Set(["\u0437"]),th:new Set(["\u0E02\u0E2D\u0E07"]),ja:new Set(["\u306E"]),ko:new Set(["\uC758"]),bn:new Set(["\u09B0"]),hi:new Set(["\u0915\u093E"]),qu:new Set(["pa"]),tr:new Set(["nin"])},A.RUN_OPERATORS=new Set(["+","-","*","/"]),A.MAX_BRACE_RUN_TOKENS=64,A.MAX_PROPERTY_DEPTH=10,A.MAX_METHOD_ARGS=20,A.DECLARATION_COMMANDS=new Set(["behavior","def","install"]),A.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Rt=A,se=new Rt;var Ia=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"],ot=class{constructor(e=Ia){this.name="operator";this.operators=[...e].sort((t,r)=>r.length-t.length)}canExtract(e,t){return this.operators.some(r=>e.startsWith(r,t))}extract(e,t){for(let r of this.operators)if(e.startsWith(r,t))return{value:r,length:r.length};return null}},_a="()[]{},:;",at=class{constructor(e=_a){this.punctuation=e;this.name="punctuation"}canExtract(e,t){return this.punctuation.includes(e[t])}extract(e,t){let r=e[t];return this.punctuation.includes(r)?{value:r,length:1}:null}};function At(o,e){let t=o[e];if(t==="#"){let r=o.slice(e).match(/^#[a-zA-Z_][\w-]*/);return r?r[0]:null}if(t==="."){let r=o.slice(e).match(/^\.\{[a-zA-Z_$][\w$]*\}/);if(r)return r[0];let n=o.slice(e).match(/^\.[a-zA-Z_][\w-]*/);return n?n[0]:null}if(t==="@"){let r=o.slice(e).match(/^@[a-zA-Z_][\w-]*/);return r?r[0]:null}if(t==="*"){let r=o.slice(e).match(/^\*(?:--)?[a-zA-Z_][\w-]*/);return r?r[0]:null}if(t==="["){let r=0,n=e;for(;n<o.length;){if(o[n]==="["&&r++,o[n]==="]"&&(r--,r===0))return o.slice(e,n+1);n++}return null}if(t==="<"){let r=o.slice(e).match(/^<(?=[\w.#[])[\w-]*(?:[#.][\w-]+|\[[^\]]+\])*\s*\/>/);return r?r[0]:null}return null}var $e=class{constructor(){this.name="css-selector"}canExtract(e,t){let r=e[t];return r==="#"||r==="."||r==="["||r==="<"?!0:r==="@"||r==="*"?At(e,t)!==null:!1}extract(e,t){let r=At(e,t);return r?{value:r,length:r.length,metadata:{type:"css-selector"}}:null}};var De=class{constructor(){this.name="event-modifier"}canExtract(e,t){if(e[t]!==".")return!1;let r=e.slice(t);return/^\.(once|prevent|stop|debounce|throttle|queue)/.test(r)}extract(e,t){let r=e.slice(t).match(/^\.(?:once|prevent|stop|debounce|throttle|queue)(?:\(([^)]+)\))?/);if(!r)return null;let n=r[0],a=n.slice(1).split("(")[0],i=r[1];return{value:n,length:n.length,metadata:{modifierName:a,value:i?a==="queue"?i:parseInt(i,10):void 0}}}};function br(o,e){let t=o.slice(e);if(t.startsWith("http://")||t.startsWith("https://")){let r=t.match(/^https?:\/\/[^\s]*/);return r?r[0]:null}if(t.startsWith("//")){let r=t.match(/^\/\/[^\s]*/);return r?r[0]:null}if(t.startsWith("./")||t.startsWith("../")){let r=t.match(/^\.\.?\/[^\s]*/);return r?r[0]:null}if(t.startsWith("/")){let r=t.match(/^\/[^\s]*/);return r?r[0]:null}return null}var je=class{constructor(){this.name="url"}canExtract(e,t){let r=e.slice(t);return r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||r.startsWith("./")||r.startsWith("../")||r.startsWith("/")}extract(e,t){let r=br(e,t);return r?{value:r,length:r.length,metadata:{type:"url"}}:null}};var We=class{constructor(){this.name="variable-ref"}canExtract(e,t){let r=e[t];return(r===":"||r==="$"||r==="^")&&t+1<e.length&&/[a-zA-Z_]/.test(e[t+1])}extract(e,t){if(!this.canExtract(e,t))return null;let r=1;for(;t+r<e.length&&/[a-zA-Z0-9_]/.test(e[t+r]);)r++;return{value:e.substring(t,t+r),length:r,metadata:{type:"variable-reference"}}}};function Ke(o){let e=o.charCodeAt(0);return e>=65&&e<=90||e>=97&&e<=122?!0:o==="\xF1"||o==="\xD1"||o==="'"||o==="\u2019"}var Mt=new Set(["-ta","-man","-manta","-pi","-wan","-paq","-kama","-rayku","-hina","ta","man","manta","pi","wan","paq","kama","hina","pa"]),wr=new Set(["kama","hina","rayku","paq"]),qa=new Set([...Mt,...wr].map(o=>o.startsWith("-")?o.slice(1):o));function Ba(o,e){let t=o.slice(e);for(let r of qa){if(!t.startsWith(r))continue;let n=o[e+r.length];if(n===void 0||!Ke(n))return!0}return!1}var Ot=class{constructor(){this.name="quechua-keyword"}setContext(e){this.context=e}canExtract(e,t){return Ke(e[t])?!0:this.isHyphenatedSuffix(e,t)!==null}isHyphenatedSuffix(e,t){if(e[t]!=="-")return null;let r=e.slice(t).match(/^-([a-zñ'’]+)/i);return r&&Mt.has(`-${r[1].toLowerCase()}`)?r[1]:null}extract(e,t){if(!this.context)throw new Error("QuechuaKeywordExtractor: context not set");let r=t,n=this.isHyphenatedSuffix(e,t);if(n!==null)return{value:n,length:n.length+1,metadata:{suffixValue:n.toLowerCase()}};let a=12;for(let u=Math.min(a,e.length-r);u>=2;u--){let f=e.slice(r,r+u),m=e[r+u];if(m!==void 0&&Ke(m))continue;let p=!0;for(let y=0;y<f.length;y++)if(!Ke(f[y])){p=!1;break}if(!p)continue;let h=this.context.lookupKeyword(f);if(h)return{value:f,length:u,metadata:{normalized:h.normalized!==h.native?h.normalized:void 0}};if(this.context.normalizer){let y=this.context.normalizer.normalize(f);if(y.stem!==f&&y.confidence>=.7){let g=this.context.lookupKeyword(y.stem);if(g)return{value:f,length:u,metadata:{normalized:g.normalized}}}}}let i="",s=t;for(;s<e.length&&Ke(e[s])&&!(i.length>0&&Ba(e,s));)i+=e[s],s++;if(!i)return null;if(Mt.has(i.toLowerCase()))return{value:i,length:s-r,metadata:{suffixValue:i.toLowerCase()}};if(wr.has(i.toLowerCase()))return{value:i,length:s-r,metadata:{postpositionValue:i.toLowerCase()}};let l=this.context.lookupKeyword(i),c=l&&l.normalized!==l.native?l.normalized:void 0,d;if(!l&&this.context.normalizer){let u=this.context.normalizer.normalize(i);if(u.stem!==i&&u.confidence>=.7){let f=this.context.lookupKeyword(u.stem);f&&(d=f.normalized)}}return{value:i,length:s-r,metadata:{normalized:c||d}}}};function Tr(){return new Ot}function Er(){return[new je,new De,new We,new $e]}function $a(o){let e=o.charCodeAt(0);return e>=65&&e<=90||e>=97&&e<=122?!0:o==="\xF1"||o==="\xD1"||o==="'"||o==="'"}function Da(o){for(let e of o)if($a(e))return!0;return!1}var ja=[{pattern:"shankichik",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"shaniku",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"shanki",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shani",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shanchik",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shanku",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shan",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"rqankichik",confidence:.8,conjugationType:"past",minStemLength:2},{pattern:"rqaniku",confidence:.8,conjugationType:"past",minStemLength:2},{pattern:"rqanki",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqani",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqanchik",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqanku",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqan",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"nqankichik",confidence:.8,conjugationType:"future",minStemLength:2},{pattern:"nqaniku",confidence:.8,conjugationType:"future",minStemLength:2},{pattern:"nqanki",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqani",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqanchik",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqanku",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqa",confidence:.85,conjugationType:"future",minStemLength:2},{pattern:"chikuy",confidence:.8,conjugationType:"compound",minStemLength:2},{pattern:"chiku",confidence:.82,conjugationType:"compound",minStemLength:2},{pattern:"chiy",confidence:.85,conjugationType:"causative",minStemLength:2,replacement:"y"},{pattern:"chiq",confidence:.85,conjugationType:"causative",minStemLength:2,replacement:"y"},{pattern:"chi",confidence:.82,conjugationType:"causative",minStemLength:2},{pattern:"kuy",confidence:.82,conjugationType:"reflexive",minStemLength:2},{pattern:"rqa",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"rqan",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"sha",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"na",confidence:.85,conjugationType:"obligation",minStemLength:2},{pattern:"manmi",confidence:.8,conjugationType:"potential",minStemLength:2},{pattern:"man",confidence:.8,conjugationType:"potential",minStemLength:2},{pattern:"nkichik",confidence:.8,conjugationType:"present",minStemLength:2},{pattern:"niku",confidence:.8,conjugationType:"present",minStemLength:2},{pattern:"nki",confidence:.82,conjugationType:"present",minStemLength:2},{pattern:"nchik",confidence:.82,conjugationType:"present",minStemLength:2},{pattern:"nku",confidence:.82,conjugationType:"present",minStemLength:2},{pattern:"ni",confidence:.85,conjugationType:"present",minStemLength:2},{pattern:"ku",confidence:.82,conjugationType:"reflexive",minStemLength:2},{pattern:"ychik",confidence:.82,conjugationType:"imperative",minStemLength:2},{pattern:"y",confidence:.9,conjugationType:"dictionary",minStemLength:2},{pattern:"sqa",confidence:.82,conjugationType:"passive",minStemLength:2},{pattern:"ska",confidence:.82,conjugationType:"passive",minStemLength:2},{pattern:"kama",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"manta",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"man",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"wan",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"pi",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"ta",confidence:.7,conjugationType:"dictionary",minStemLength:2}],Vt=class{constructor(){this.language="qu"}isNormalizable(e){return!(!Da(e)||e.length<3||!/[aiu]/.test(e.toLowerCase()))}normalize(e){let t=e.toLowerCase();for(let r of ja)if(t.endsWith(r.pattern)){let n=t.slice(0,-r.pattern.length);r.replacement&&!n.endsWith(r.replacement)&&(n=n+r.replacement);let a=r.minStemLength??2;if(n.length<a||!this.isValidStem(n))continue;let i={removedSuffixes:[r.pattern]};return r.conjugationType&&(i.conjugationType=r.conjugationType),Nt(n,r.confidence,i)}return Ct(e)}isValidStem(e){return!(e.length<2||!/[aeiou]/.test(e)||new Set(["ta","man","pi","wan","pa","kama","hina"]).has(e))}},Cr=new Vt;var zt=class{constructor(){this.name="quechua-string-literal"}canExtract(e,t){return e[t]==='"'||e[t]==="'"}extract(e,t){let r=e[t],n=r,a=t+1;for(;a<e.length;){let i=e[a];if(i===r)return n+=i,{value:n,length:n.length};i==="\\"&&a+1<e.length?(n+=i+e[a+1],a+=2):(n+=i,a++)}return null}},Wa=new Set(["-ta","-man","-manta","-pi","-wan","-paq","-kama","-rayku","-hina","ta","man","manta","pi","wan","paq","kama","hina","pa"]),Ka=[{native:"cheqaq",normalized:"true"},{native:"ar\xED",normalized:"true"},{native:"ari",normalized:"true"},{native:"manan",normalized:"false"},{native:"mana",normalized:"false"},{native:"ch'usaq",normalized:"null"},{native:"chusaq",normalized:"null"},{native:"mana riqsisqa",normalized:"undefined"},{native:"\xF1awpaqpi",normalized:"before"},{native:"nawpaqpi",normalized:"before"},{native:"qhepapi",normalized:"after"},{native:"qhipapi",normalized:"after"},{native:"\xF1awpaq",normalized:"first"},{native:"nawpaq",normalized:"first"},{native:"qhipa",normalized:"last"},{native:"hamuq",normalized:"next"},{native:"qhipantin",normalized:"next"},{native:"\xF1awpaqnin",normalized:"previous"},{native:"\xF1awpaq kaq",normalized:"previous"},{native:"\xF1awpaq_kaq",normalized:"previous"},{native:"kaylla",normalized:"closest"},{native:"qaylla",normalized:"closest"},{native:"tayta",normalized:"parent"},{native:"llikllay",normalized:"click"},{native:"\xF1itiy",normalized:"click"},{native:"\xF1it'iy",normalized:"click"},{native:"click",normalized:"click"},{native:"yaykuy",normalized:"input"},{native:"llave uray",normalized:"keydown"},{native:"llave hawa",normalized:"keyup"},{native:"mausiri yayku",normalized:"mouseover"},{native:"mausiri lluqsi",normalized:"mouseout"},{native:"rat\xF1itiy",normalized:"mousedown"},{native:"rathuqariy",normalized:"mouseup"},{native:"qhaway",normalized:"focus"},{native:"mana qhaway",normalized:"blur"},{native:"kargay",normalized:"load"},{native:"muyuy",normalized:"scroll"},{native:"\xF1uqa",normalized:"me"},{native:"nuqa",normalized:"me"},{native:"\xF1uqap",normalized:"my"},{native:"nuqap",normalized:"my"},{native:"chay",normalized:"it"},{native:"chaymi",normalized:"it"},{native:"lluqsiy",normalized:"result"},{native:"ruway",normalized:"event"},{native:"maypi",normalized:"target"},{native:"sikundu",normalized:"s"},{native:"segundu",normalized:"s"},{native:"waranqa sikundu",normalized:"ms"},{native:"minutu",normalized:"m"},{native:"ura",normalized:"h"},{native:"hora",normalized:"h"},{native:"chaypim",normalized:"on"},{native:"kaypi",normalized:"on"},{native:"chayqa",normalized:"then"},{native:"chaymanta",normalized:"then"},{native:"chaymantataq",normalized:"then"},{native:"hinaspa",normalized:"then"},{native:"tukukuy",normalized:"end"},{native:"puchukay",normalized:"end"},{native:"kaykama",normalized:"until"},{native:"yapay",normalized:"add"},{native:"t'ikray",normalized:"toggle"},{native:"tikray",normalized:"toggle"},{native:"qhawachiy",normalized:"focus"},{native:"mana qhawachiy",normalized:"blur"},{native:"-manta",normalized:"from"}],It=class extends _e{constructor(){super();this.language="qu";this.direction="ltr";this.initializeKeywordsFromProfile(ve,Ka),this.setNormalizer(Cr),this.registerExtractors(Er()),this.registerExtractor(new zt),this.registerExtractor(new Et),this.registerExtractor(Tr()),this.registerExtractor(new ot),this.registerExtractor(new at)}classifyToken(t){let r=t.toLowerCase();return Wa.has(r)?"particle":this.isKeyword(r)?"keyword":t.startsWith("/")||t.startsWith("./")||t.startsWith("../")||t.startsWith("http")?"url":/^\.(once|prevent|stop|debounce|throttle|queue)(\(.*\))?$/.test(t)?"event-modifier":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")||t.startsWith("*")||t.startsWith("<")?"selector":t.startsWith('"')||/^\d/.test(t)?"literal":["==","!=","<=",">=","<",">","&&","||","!"].includes(t)?"operator":"identifier"}},it=new It;function G(o,e){return er(o,e)}function st(){return kt()}var ct=["if","unless","repeat","for","while"];function le(o,e){let t=new Set([e]),n=z(o)?.keywords?.[e];if(n){n.primary&&t.add(n.primary.toLowerCase());for(let a of n.alternatives??[])t.add(a.toLowerCase())}return t}function te(o,e){return e.has(o.value.toLowerCase())?!0:o.normalized?e.has(o.normalized.toLowerCase()):!1}var Fa=new Set(ct);function qt(o,e){let t=o.normalized?.toLowerCase();return t?Fa.has(t):e.some(r=>te(o,r))}var Nr=new Set(["me","it","you","the","body","window","document","its","event","result","target","self","this","them","parent","next","previous","closest","first","last"]),Ha=new Set(["destination","source","style","patient","on","from","to"]);function Ga(o){if(!o||o.kind==="selector")return!1;let e=(o.normalized??o.value).toLowerCase(),t=o.value.toLowerCase();return!(Nr.has(e)||Nr.has(t)||Ha.has(e))}var Pr=new Set(["ja","ko"]);function _t(o){let e=new Set;o?.primary&&e.add(o.primary.toLowerCase());for(let t of o?.alternatives??[])e.add(t.toLowerCase());return e}function Rr(o,e){let t=[],r=e.position.end,n=o.slice(e.position.end).match(/^\s*\(([^)]*)\)/);if(n){r=e.position.end+n[0].length;for(let a of n[1].split(/[,،、]/)){let i=a.trim();i&&t.push(i)}}return{parameters:t,headerEnd:r}}function Ar(o,e,t){let r=e+1;if(r>=o.length)return-1;let n=_t(z(t)?.roleMarkers?.patient);return n.size>0&&te(o[r],n)&&r++,r<o.length?r:-1}function Mr(o,e,t){if(!z(e))return null;let r=le(e,"behavior"),n=le(e,"def"),a=o.toLowerCase(),i=[...r].some(d=>a.includes(d)),s=/\bdef\b/.test(a)||[...n].some(d=>d!=="def"&&a.includes(d));if(!i&&!s)return null;let l=G(o,e).tokens;if(l.length<2)return null;if(te(l[0],r))return Lr(o,e,l,t,0);let c=l.findIndex((d,u)=>u>0&&te(d,r));return c>0&&/^[A-Z][A-Za-z0-9_]*$/.test(l[0].value)?Lr(o,e,l,t,c):te(l[0],n)?Ya(o,e,l,t):null}function Or(o,e,t){let r=z(e);if(!r)return null;let n=r.wordOrder!=="SOV",a=Pr.has(e)?_t(r.roleMarkers?.event):new Set,i=Pr.has(e)?_t(r.keywords?.on):new Set,s=a.size>0&&i.size>0,l=le(e,"end"),c=le(e,"on"),d=o.toLowerCase(),u=[...l].some(k=>d.includes(k)),f=(n||s)&&(()=>{let k=0;for(let E of c)if(E){for(let v=d.indexOf(E);v>=0;v=d.indexOf(E,v+E.length))if(++k>=2)return!0}return!1})();if(!u&&!f)return null;let m=G(o,e).tokens;if(m.length<2)return null;let p=ct.map(k=>le(e,k)),h=k=>qt(k,p),y=k=>te(k,l),g=[],x=0,T=0;for(let k=0;k<m.length;k++){let E=m[k];if(y(E)){if(x>0){x--;continue}let v=o.slice(m[T].position.start,E.position.start).trim();v&&g.push(v),T=k+1}else if(h(E))x++;else if(n&&x===0&&k>T&&te(E,c)&&Ga(m[k+1])){let v=o.slice(m[T].position.start,E.position.start).trim();v&&g.push(v),T=k}else if(s&&x===0&&k-1>T&&te(E,a)&&m[k+1]!==void 0&&te(m[k+1],i)){let v=m[k-1],b=o.slice(m[T].position.start,v.position.start).trim();b&&g.push(b),T=k-1}}if(T<m.length){let k=o.slice(m[T].position.start).trim();k&&g.push(k)}if(g.length<2)return null;let C=[],S=[];for(let k of g){let E;try{E=t.statement(k,e)}catch{return null}if(!E||E.kind!=="event-handler")return null;let v=E;C.push(v);let b=!v.body||v.body.length===0;S.push(b?.2:v.metadata?.confidence??.75)}return qe(C,"then",{sourceLanguage:e,confidence:lt(S),sourceText:o})}function lt(o){return o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0}function Vr(o){let e=[];for(let t of o){let r=t.statements;t.kind==="compound"&&Array.isArray(r)?e.push(...r):e.push(t)}return e}function Lr(o,e,t,r,n){let a=n>0,i=a?0:Ar(t,n,e);if(i<0)return null;let s=t[i],l=s.value;if(!/^[A-Z][A-Za-z0-9_]*$/.test(l))return null;let{parameters:c,headerEnd:d}=Rr(o,s),u=a?n+1:t.findIndex(v=>v.position.start>=d);u<=i&&(u=i+1);let f=le(e,"init"),m=le(e,"end"),p=ct.map(v=>le(e,v)),h=v=>qt(v,p),y=v=>te(v,m),g=[],x=[],T=[],C=!1,S=0,k=u;for(let v=u;v<t.length;v++){let b=t[v];if(y(b)){if(S>0){S--;continue}if(v===k){C=!0;break}if(te(t[k],f)){let P=o.slice(t[k].position.end,b.position.start).trim();if(P)try{let N=Vr(r.body(P,e));x.push(...N),T.push(lt(N.map(V=>V.metadata?.confidence??.75)))}catch{T.push(0)}}else{let P=o.slice(t[k].position.start,b.position.start).trim();try{let N=r.statement(P,e);if(N&&N.kind==="event-handler"){let V=N;g.push(V);let M=!V.body||V.body.length===0;T.push(M?.2:V.metadata?.confidence??.75)}else T.push(0)}catch{T.push(0)}}k=v+1}else h(b)&&S++}if(g.length===0&&x.length===0)return null;let E=(C?1:.8)*lt(T);return fr(l,c,g,x.length>0?x:void 0,{sourceLanguage:e,confidence:E,sourceText:o})}function Ya(o,e,t,r){let n=Ar(t,0,e);if(n<0)return null;let a=t[n],i=a.value;if(!/^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*$/.test(i))return null;let{parameters:s,headerEnd:l}=Rr(o,a),c=t.findIndex(S=>S.position.start>=l);c<=n&&(c=n+1);let d=le(e,"end"),u=ct.map(S=>le(e,S)),f=S=>qt(S,u),m=S=>te(S,d),p=0,h=-1;for(let S=c;S<t.length;S++)if(m(t[S])){if(p===0){h=S;break}p--}else f(t[S])&&p++;let y=t[c]?.position.start??l,g=h>=0?t[h].position.start:o.length,x=o.slice(y,g).trim();if(!x)return null;let T;try{T=Vr(r.body(x,e))}catch{return null}if(T.length===0)return null;let C=lt(T.map(S=>S.metadata?.confidence??.75));return h<0&&(C*=.8),hr(i,s,T,{sourceLanguage:e,confidence:C,sourceText:o})}var Se={ko:{\uD074\uB9AD:"click",\uC785\uB825:"input",\uBCC0\uACBD:"change",\uC81C\uCD9C:"submit",\uD0A4\uB2E4\uC6B4:"keydown",\uD0A4\uC5C5:"keyup",\uB9C8\uC6B0\uC2A4\uC624\uBC84:"mouseover",\uB9C8\uC6B0\uC2A4\uC544\uC6C3:"mouseout",\uB9C8\uC6B0\uC2A4\uB2E4\uC6B4:"mousedown",\uB9C8\uC6B0\uC2A4\uC5C5:"mouseup",\uD3EC\uCEE4\uC2A4:"focus",\uBE14\uB7EC:"blur",\uB85C\uB4DC:"load",\uB9AC\uC0AC\uC774\uC988:"resize",\uC2A4\uD06C\uB864:"scroll"},ja:{\u30AF\u30EA\u30C3\u30AF:"click",\u5165\u529B:"input",\u5909\u66F4:"change",\u9001\u4FE1:"submit",\u30AD\u30FC\u30C0\u30A6\u30F3:"keydown",\u30AD\u30FC\u30A2\u30C3\u30D7:"keyup",\u30AD\u30FC\u30D7\u30EC\u30B9:"keypress",\u30DE\u30A6\u30B9\u30AA\u30FC\u30D0\u30FC:"mouseover",\u30DE\u30A6\u30B9\u30A2\u30A6\u30C8:"mouseout",\u30DE\u30A6\u30B9\u62BC\u4E0B:"mousedown",\u30DE\u30A6\u30B9\u89E3\u653E:"mouseup",\u30D5\u30A9\u30FC\u30AB\u30B9:"focus",\u30D6\u30E9\u30FC:"blur",\u30ED\u30FC\u30C9:"load",\u8AAD\u307F\u8FBC\u307F:"load",\u30B5\u30A4\u30BA\u5909\u66F4:"resize",\u30B9\u30AF\u30ED\u30FC\u30EB:"scroll"},ar:{\u0627\u0644\u0646\u0642\u0631:"click",\u0646\u0642\u0631:"click",\u0627\u0644\u0625\u062F\u062E\u0627\u0644:"input",\u0625\u062F\u062E\u0627\u0644:"input",\u0627\u0644\u062A\u063A\u064A\u064A\u0631:"change",\u062A\u063A\u064A\u064A\u0631:"change",\u0627\u0644\u0625\u0631\u0633\u0627\u0644:"submit",\u0625\u0631\u0633\u0627\u0644:"submit","\u0636\u063A\u0637 \u0627\u0644\u0645\u0641\u062A\u0627\u062D":"keydown","\u0631\u0641\u0639 \u0627\u0644\u0645\u0641\u062A\u0627\u062D":"keyup","\u062A\u0645\u0631\u064A\u0631 \u0627\u0644\u0645\u0627\u0648\u0633":"mouseover",\u0627\u0644\u062A\u0631\u0643\u064A\u0632:"focus",\u062A\u062D\u0645\u064A\u0644:"load",\u062A\u0645\u0631\u064A\u0631:"scroll"},es:{clic:"click",click:"click",entrada:"input",cambio:"change",env\u00EDo:"submit",enviar:"submit","tecla abajo":"keydown","tecla arriba":"keyup","rat\xF3n encima":"mouseover","rat\xF3n fuera":"mouseout",enfoque:"focus",desenfoque:"blur",carga:"load",desplazamiento:"scroll"},tr:{t\u0131klama:"click",t\u0131kla:"click",t\u0131k:"click",giri\u015F:"input",girdi:"input",de\u011Fi\u015Fiklik:"change",de\u011Fi\u015Fim:"change",g\u00F6nderme:"submit",g\u00F6nder:"submit",tu\u015Fbasma:"keydown",tu\u015Fb\u0131rakma:"keyup",fare_bas:"mousedown",fare_b\u0131rak:"mouseup",farei\u00E7inde:"mouseover",fared\u0131\u015F\u0131nda:"mouseout",odaklanma:"focus",odak:"focus",bulan\u0131kl\u0131k:"blur",y\u00FCkleme:"load",y\u00FCkle:"load",boyutland\u0131rma:"resize",boyutland\u0131r:"resize",kayd\u0131rma:"scroll"},pt:{clique:"click",clicar:"click",click:"click",entrada:"input",inserir:"input",mudan\u00E7a:"change",mudanca:"change",alterar:"change",envio:"submit",enviar:"submit","tecla baixo":"keydown","tecla cima":"keyup","pressionar tecla":"keydown","soltar tecla":"keyup","mouse sobre":"mouseover","mouse fora":"mouseout",foco:"focus",focar:"focus",desfoque:"blur",desfocar:"blur",carregar:"load",carregamento:"load",rolagem:"scroll",rolar:"scroll"},zh:{\u70B9\u51FB:"click",\u5355\u51FB:"click",\u53CC\u51FB:"dblclick",\u8F93\u5165:"input",\u6539\u53D8:"change",\u53D8\u5316:"change",\u53D8\u66F4:"change",\u63D0\u4EA4:"submit",\u53D1\u9001:"submit",\u6309\u952E:"keydown",\u952E\u5165:"keydown",\u677E\u952E:"keyup",\u9F20\u6807\u8FDB\u5165:"mouseover",\u9F20\u6807\u79FB\u5165:"mouseover",\u9F20\u6807\u79BB\u5F00:"mouseout",\u9F20\u6807\u79FB\u51FA:"mouseout",\u7126\u70B9:"focus",\u805A\u7126:"focus",\u5931\u7126:"blur",\u6A21\u7CCA:"blur",\u52A0\u8F7D:"load",\u8F7D\u5165:"load",\u6EDA\u52A8:"scroll"},fr:{clic:"click",cliquer:"click",click:"click",saisie:"input",entr\u00E9e:"input",changement:"change",changer:"change",soumettre:"submit",soumission:"submit",envoi:"submit","touche bas":"keydown","touche haut":"keyup","souris dessus":"mouseover","souris dehors":"mouseout",focus:"focus",focaliser:"focus",d\u00E9focus:"blur",d\u00E9focaliser:"blur",chargement:"load",charger:"load",d\u00E9filement:"scroll",d\u00E9filer:"scroll"},de:{klick:"click",klicken:"click",click:"click",eingabe:"input",eingeben:"input",\u00E4nderung:"change",\u00E4ndern:"change",absenden:"submit",einreichen:"submit","taste runter":"keydown","taste hoch":"keyup","maus \xFCber":"mouseover","maus raus":"mouseout",fokus:"focus",fokussieren:"focus",defokussieren:"blur",unsch\u00E4rfe:"blur",laden:"load",ladung:"load",scrollen:"scroll",bl\u00E4ttern:"scroll"},id:{klik:"click",click:"click",masukan:"input",input:"input",ubah:"change",perubahan:"change",kirim:"submit","tekan tombol":"keydown","lepas tombol":"keyup","mouse masuk":"mouseover","mouse keluar":"mouseout",fokus:"focus",blur:"blur",muat:"load",memuat:"load",gulir:"scroll",menggulir:"scroll"},bn:{\u0995\u09CD\u09B2\u09BF\u0995:"click",\u0987\u09A8\u09AA\u09C1\u099F:"input",\u099C\u09AE\u09BE:"submit",\u09B2\u09CB\u09A1:"load",\u09B8\u09CD\u0995\u09CD\u09B0\u09CB\u09B2:"scroll",\u09B0\u09BF\u09B8\u09BE\u0987\u099C:"resize",\u099D\u09BE\u09AA\u09B8\u09BE:"blur",\u09AB\u09CB\u0995\u09BE\u09B8:"focus",\u09AA\u09B0\u09BF\u09AC\u09B0\u09CD\u09A4\u09A8:"change"},qu:{click:"click","\xF1it'iy":"click",\u00F1itiy:"click",yaykuchiy:"input",yaykuy:"input",tikray:"change","t'ikray":"change",apachiy:"submit",kachay:"submit","llave uray":"keydown","llave hawa":"keyup","q'away":"focus",qhaway:"focus",paqariy:"blur","mana q'away":"blur",cargay:"load",apakuy:"load",apamuy:"load",kunray:"scroll",muyuy:"scroll",hatun_kay:"resize"},sw:{bofya:"click",click:"click",kubofya:"click",ingiza:"input",kubadilisha:"change",mabadiliko:"change",tuma:"submit",kutuma:"submit","bonyeza chini":"keydown","bonyeza juu":"keyup","panya juu":"mouseover","panya nje":"mouseout",lenga:"focus",kulenga:"focus",blur:"blur",pakia:"load",kupakia:"load",sogeza:"scroll",kusogeza:"scroll"}};var Za=Object.fromEntries(Object.entries(Se).map(([o,e])=>{let t={};for(let[r,n]of Object.entries(e))n in t||(t[n]=r);return[o,t]})),Ja={ar:new Set(["mouseover"]),bn:new Set(["resize"]),de:new Set(["keydown","keyup","load","mouseout","mouseover"]),fr:new Set(["blur"]),id:new Set(["input","keyup","mouseout","mouseover"]),ja:new Set(["keypress","mousedown","mouseup","resize"]),qu:new Set(["change","focus","load","resize","submit"]),sw:new Set(["change","click","input","keydown","keyup","mouseout","mouseover","submit"]),tr:new Set(["keydown","keyup","load","mousedown","mouseout","mouseover","mouseup","resize","scroll"]),zh:new Set(["focus","keyup","mouseout","mouseover"])};function zr(o,e){return Ja[e]?.has(o)?o:Za[e]?.[o]??o}var ut=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);if(e.kind==="behavior")return this.renderBehavior(e,t);if(e.kind==="def")return this.renderDef(e,t);let r=xt(t,e.action);if(r.length===0)return this.renderExplicit(e);let n=this.findBestPattern(e,r);return n?this.renderWithPattern(e,n):this.renderExplicit(e)}renderCompound(e,t){if(e.statements.length>1&&e.statements.every(a=>a.kind==="event-handler")){let a=this.keyword(t,"end"),i=[];for(let s of e.statements)i.push(this.render(s,t),a);return i.join(`
3
- `)}let r=e.statements.map(a=>this.render(a,t)),n=this.getChainWord(e.chainType,t);return r.join(` ${n} `)}keyword(e,t){return z(e)?.keywords?.[t]?.primary??t}renderBlockHeader(e,t,r){return r.length>0?`${e} ${t}(${r.join(", ")})`:`${e} ${t}`}renderBehavior(e,t){let r=this.keyword(t,"end"),n=[this.renderBlockHeader(this.keyword(t,"behavior"),e.name,e.parameters)];for(let a of e.eventHandlers)n.push(` ${this.render(a,t)}`,` ${r}`);if(e.initBlock&&e.initBlock.length>0){n.push(` ${this.keyword(t,"init")}`);for(let a of e.initBlock)n.push(` ${this.render(a,t)}`);n.push(` ${r}`)}return n.push(r),n.join(`
1
+ "use strict";var LokaScriptSemanticQu=(()=>{var mt=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var jr=Object.getOwnPropertyNames;var Wr=Object.prototype.hasOwnProperty;var Kr=(o,e)=>{for(var t in e)mt(o,t,{get:e[t],enumerable:!0})},Ur=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of jr(e))!Wr.call(o,n)&&n!==t&&mt(o,n,{get:()=>e[n],enumerable:!(r=Dr(e,n))||r.enumerable});return o};var Fr=o=>Ur(mt({},"__esModule",{value:!0}),o);var si={};Kr(si,{ASTBuilder:()=>Oe,DEFAULT_CONFIDENCE_THRESHOLD:()=>Ut,HIGH_CONFIDENCE_THRESHOLD:()=>Ft,VERSION:()=>ri,buildAST:()=>Yt,canParse:()=>Dt,createCommandNode:()=>H,createEventHandler:()=>me,createLiteral:()=>q,createPropertyPath:()=>ie,createReference:()=>Z,createSelector:()=>re,fromExplicit:()=>Wt,getCommandMapper:()=>Me,getPatternsForLanguage:()=>Br,getPatternsForLanguageAndCommand:()=>ii,getProfile:()=>Ze,getSupportedLanguages:()=>oi,getTokenizer:()=>Ye,isExplicitSyntax:()=>de,isLanguageSupported:()=>St,parse:()=>Ae,parseAny:()=>Kt,parseExplicit:()=>Pe,quechuaProfile:()=>ve,quechuaTokenizer:()=>it,registerCommandMapper:()=>yt,render:()=>Ue,renderExplicit:()=>Fe,toExplicit:()=>jt,tokenize:()=>ai,tryGetProfile:()=>V});var Ut=.5,Ft=.8;var Hr=new Set(["me","my","myself","you","your","yourself","it","its","result","event","target","body","detail","window","document"]),Gr=new Set(["and","or","not","no"]),Yr=new Set(["true","false","null","undefined"]),Zr=new Set(["is","matches","match","contains","in"]),Jr=new Set(["next","previous","closest","first","last"]),Xr=new Set(["ms","s","seconds","second","milliseconds","millisecond","minutes","minute","hours","hour"]);function Ht(o){let e=[],t=0,r=1,n=1;function a(){if(e.length===0)return!0;let p=e[e.length-1];return p.type==="IDENTIFIER"&&Zr.has(p.value.toLowerCase())||p.type==="IDENTIFIER"&&Jr.has(p.value.toLowerCase())?!0:["OPERATOR","COMPARISON","LOGICAL","LPAREN","LBRACKET","LBRACE","COMMA","COLON"].includes(p.type)}function i(p=0){return o[t+p]??""}function s(){let p=o[t];return t++,p===`
2
+ `?(r++,n=1):n++,p}function l(){for(;t<o.length&&/\s/.test(o[t]);)s()}function c(p){let h="";for(;t<o.length&&p(o[t]);)h+=s();return h}function d(p){let h=p;for(s();t<o.length&&o[t]!==p;)o[t]==="\\"&&t+1<o.length&&(h+=s()),h+=s();return t<o.length&&(h+=s()),h}function u(){let p="`";for(s();t<o.length&&o[t]!=="`";)o[t]==="\\"&&t+1<o.length&&(p+=s()),p+=s();return t<o.length&&(p+=s()),p}function f(){let p="<";for(s();t<o.length&&(p+=s(),!p.endsWith("/>")););return p}function m(p,h,y){return{type:p,value:h,start:y,end:t,line:r,column:n-h.length}}for(;t<o.length&&(l(),!(t>=o.length));){let p=t,h=i();if(h==="'"&&i(1)==="s"&&!/\w/.test(i(2))){s(),s(),e.push(m("POSSESSIVE","'s",p));continue}if(h==='"'||h==="'"){let y=d(h);e.push(m("STRING",y,p));continue}if(h==="`"){let y=u();e.push(m("TEMPLATE_LITERAL",y,p));continue}if(h==="<"&&/[a-zA-Z.#\[]/.test(i(1))){let y=f();e.push(m("QUERY_SELECTOR",y,p));continue}if(h==="#"&&a()){s();let y=c(g=>/[\w-]/.test(g));e.push(m("ID_SELECTOR","#"+y,p));continue}if(h==="."&&/[a-zA-Z_-]/.test(i(1))&&a()){s();let y=c(g=>/[\w-]/.test(g));e.push(m("CLASS_SELECTOR","."+y,p));continue}if(h==="@"&&/[a-zA-Z_]/.test(i(1))){s();let y=c(g=>/[\w-]/.test(g));e.push(m("ATTRIBUTE_REF","@"+y,p));continue}if(h==="["&&a()){let y=i(1);if(y==="@"||/[a-zA-Z]/.test(y)){let g="";for(g+=s();t<o.length&&o[t]!=="]";)o[t]==='"'||o[t]==="'"?g+=d(o[t]):g+=s();t<o.length&&(g+=s()),e.push(m("ATTRIBUTE_SELECTOR",g,p));continue}}if(h==="["){s(),e.push(m("LBRACKET","[",p));continue}if(h==="]"){s(),e.push(m("RBRACKET","]",p));continue}if(/\d/.test(h)){let y=c(T=>/[\d.]/.test(T)),g=t,x=c(T=>/[a-zA-Z]/.test(T));Xr.has(x)?e.push(m("TIME_EXPRESSION",y+x,p)):(t=g,e.push(m("NUMBER",y,p)));continue}if(h==="("){s(),e.push(m("LPAREN","(",p));continue}if(h===")"){s(),e.push(m("RPAREN",")",p));continue}if(h==="{"){s(),e.push(m("LBRACE","{",p));continue}if(h==="}"){s(),e.push(m("RBRACE","}",p));continue}if(h===","){s(),e.push(m("COMMA",",",p));continue}if(h===":"){s(),e.push(m("COLON",":",p));continue}if(h==="."){s(),e.push(m("DOT",".",p));continue}if(h==="+"||h==="-"||h==="*"||h==="/"||h==="%"){s(),e.push(m("OPERATOR",h,p));continue}if(h==="="||h==="!"||h==="<"||h===">"){let y=s();i()==="="&&(y+=s()),e.push(m("COMPARISON",y,p));continue}if(/[a-zA-Z_$]/.test(h)){let y=c(x=>/[\w$]/.test(x)),g=y.toLowerCase();Hr.has(g)?e.push(m("CONTEXT_VAR",y,p)):Gr.has(g)?e.push(m("LOGICAL",y,p)):Yr.has(g)?e.push(m("BOOLEAN",y,p)):e.push(m("IDENTIFIER",y,p));continue}s()}return e.push(m("EOF","",t)),e}var Qr=new Set(["my","its","your"]),en=new Set(["is","matches","match","contains","in","exists","does"]),tn=new Set(["next","previous","closest","first","last"]),Ge=class{constructor(){this.tokens=[];this.current=0}parse(e){try{return this.tokens=Ht(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}}peekAt(e){return this.tokens[this.current+e]??{type:"EOF",value:"",start:0,end:0}}previous(){return this.tokens[this.current-1]??{type:"EOF",value:"",start:0,end:0}}isAtEnd(){return this.peek().type==="EOF"}advance(){return this.isAtEnd()||this.current++,this.previous()}check(e){return this.peek().type===e}checkValue(e){return this.peek().value.toLowerCase()===e.toLowerCase()}match(...e){for(let t of e)if(this.check(t))return this.advance(),!0;return!1}parseExpression(){return this.parseOr()}parseOr(){let e=this.parseAnd();for(;this.checkValue("or");){let t=this.advance().value,r=this.parseAnd();e=this.createBinaryExpression(t,e,r)}return e}parseAnd(){let e=this.parseEquality();for(;this.checkValue("and");){let t=this.advance().value,r=this.parseEquality();e=this.createBinaryExpression(t,e,r)}return e}parseEquality(){let e=this.parseComparison();for(;;){let t;if(this.match("COMPARISON"))t=this.previous().value;else if(this.checkValue("is")||this.checkValue("matches")||this.checkValue("match")||this.checkValue("contains")||this.checkValue("in")){let n=this.advance().value;t=n.toLowerCase()==="match"?"matches":n}else break;if(t.toLowerCase()==="is"){if(this.checkValue("empty")){this.advance(),e=this.createPostfixUnary("is empty",e);continue}if(this.checkValue("not")&&this.peekAt(1).value.toLowerCase()==="empty"){this.advance(),this.advance(),e=this.createPostfixUnary("is not empty",e);continue}}let r=this.parseComparison();e=this.createBinaryExpression(t,e,r)}return e}parseComparison(){let e=this.parseAddition();for(;this.check("COMPARISON");){let t=this.advance().value,r=this.parseAddition();e=this.createBinaryExpression(t,e,r)}return e}parseAddition(){let e=this.parseMultiplication();for(;this.peek().value==="+"||this.peek().value==="-";){let t=this.advance().value,r=this.parseMultiplication();e=this.createBinaryExpression(t,e,r)}return e}parseMultiplication(){let e=this.parseUnary();for(;this.peek().value==="*"||this.peek().value==="/"||this.peek().value==="%";){let t=this.advance().value,r=this.parseUnary();e=this.createBinaryExpression(t,e,r)}return e}parseUnary(){if(this.checkValue("not")||this.checkValue("no")||this.peek().value==="-"){let e=this.advance().value,t=this.parseUnary();return this.createUnaryExpression(e,t)}return this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("DOT"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else break;else if(this.match("POSSESSIVE"))if(this.check("IDENTIFIER")||this.check("CONTEXT_VAR")){let t=this.advance().value;e=this.createPossessiveExpression(e,t)}else break;else if(this.match("LPAREN")){let t=this.parseArguments();e=this.createCallExpression(e,t)}else if(this.match("LBRACKET")){let t=this.parseExpression();if(!this.match("RBRACKET"))throw new Error("Expected ] after index");e=this.createPropertyAccess(e,t)}else if(e.type==="contextReference"&&Qr.has(e.contextType??"")&&this.check("IDENTIFIER")&&!en.has(this.peek().value.toLowerCase())){let t=this.advance().value;e=this.createPropertyAccess(e,t)}else if(this.checkValue("exists")&&this.peekAt(1).type!=="LPAREN")this.advance(),e=this.createPostfixUnary("exists",e);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,r={true:"boolean",false:"boolean",null:"null",undefined:"undefined"};return this.createLiteral(t,r[e.value]??"string",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("ATTRIBUTE_REF"))return{type:"attributeAccess",attributeName:e.value.slice(1),start:e.start,end:e.end};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")){if(tn.has(e.value.toLowerCase())&&(this.check("CLASS_SELECTOR")||this.check("ID_SELECTOR")||this.check("QUERY_SELECTOR"))){let t=this.advance(),r=t.type==="QUERY_SELECTOR"?t.value.slice(1,-2):t.value,n=t.type==="CLASS_SELECTOR"?"class":t.type==="ID_SELECTOR"?"id":"query";return{type:"callExpression",callee:this.createIdentifier(e.value,e),arguments:[this.createSelector(r,n,t)],start:e.start,end:t.end}}return this.createIdentifier(e.value,e)}if(this.match("LPAREN")){let t=this.parseExpression();if(!this.match("RPAREN"))throw new Error("Expected ) after expression");return t}if(this.match("LBRACKET"))return this.parseArrayLiteral();if(this.match("LBRACE"))return this.parseObjectLiteral();throw new Error(`Unexpected token: ${e.value}`)}parseArguments(){let e=[];if(!this.check("RPAREN"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RPAREN"))throw new Error("Expected ) after arguments");return e}parseArrayLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACKET"))do e.push(this.parseExpression());while(this.match("COMMA"));if(!this.match("RBRACKET"))throw new Error("Expected ] after array elements");return{type:"arrayLiteral",elements:e,start:t,end:this.previous().end}}parseObjectLiteral(){let e=[],t=this.previous().start;if(!this.check("RBRACE"))do{let r;if(this.check("STRING"))r=this.advance().value.slice(1,-1);else if(this.check("IDENTIFIER"))r=this.advance().value;else throw new Error("Expected property name");if(!this.match("COLON"))throw new Error("Expected : after property name");let n=this.parseExpression();e.push({key:r,value:n})}while(this.match("COMMA"));if(!this.match("RBRACE"))throw new Error("Expected } after object properties");return{type:"objectLiteral",properties:e.map(r=>({type:"objectProperty",key:r.key,value:r.value})),start:t,end:this.previous().end}}parseTimeExpression(e){let t=e.value.match(/^(\d+(?:\.\d+)?)(ms|s|seconds?|milliseconds?|minutes?|hours?)$/i);if(!t)throw new Error(`Invalid time expression: ${e.value}`);let r=parseFloat(t[1]),n=t[2].toLowerCase();return{type:"timeExpression",value:r,unit:n,raw:e.value,start:e.start,end:e.end,line:e.line,column:e.column}}createLiteral(e,t,r){return{type:"literal",value:e,dataType:t,raw:r.value,start:r.start,end:r.end,line:r.line,column:r.column}}createSelector(e,t,r){return{type:"selector",value:e,selector:e,selectorType:t,start:r.start,end:r.end,line:r.line,column:r.column}}createContextReference(e,t){return{type:"contextReference",contextType:e,name:t.value,start:t.start,end:t.end,line:t.line,column:t.column}}createIdentifier(e,t){return{type:"identifier",name:e,start:t.start,end:t.end,line:t.line,column:t.column}}createPropertyAccess(e,t){return{type:"propertyAccess",object:e,property:typeof t=="string"?t:t.type==="identifier"?t.name:"",start:e.start,end:this.previous().end}}createPossessiveExpression(e,t){return{type:"possessiveExpression",object:e,property:t,start:e.start,end:this.previous().end}}createBinaryExpression(e,t,r){return{type:"binaryExpression",operator:e,left:t,right:r,start:t.start,end:r.end}}createUnaryExpression(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!0,start:this.previous().start,end:t.end}}createPostfixUnary(e,t){return{type:"unaryExpression",operator:e,operand:t,prefix:!1,start:t.start,end:this.previous().end}}createCallExpression(e,t){return{type:"callExpression",callee:e,arguments:t,start:e.start,end:this.previous().end}}};function ft(o){return new Ge().parse(o)}function Y(o,e){switch(o.type){case"literal":return rn(o);case"selector":return nn(o,e);case"reference":return on(o);case"property-path":return an(o,e);case"expression":return sn(o);case"flag":return{type:"literal",value:o.enabled};default:let t=o;throw new Error(`Unknown semantic value type: ${t.type}`)}}function rn(o){let e={type:"literal",value:o.value};return o.dataType?{...e,dataType:o.dataType}:e}function nn(o,e){return o.value.startsWith("@")&&/^[a-zA-Z_]/.test(o.value.slice(1))?{type:"attributeAccess",attributeName:o.value.slice(1)}:(e&&o.value.startsWith("*")&&/^[a-zA-Z-]/.test(o.value.slice(1))&&e.push(`Converted '${o.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.`),o.value.startsWith("<")?{type:"selector",value:o.value,selector:o.value,selectorType:o.selectorKind,raw:o.value}:{type:"selector",value:o.value,selector:o.value,selectorType:o.selectorKind})}function on(o){return{type:"contextReference",contextType:o.value,name:o.value}}function an(o,e){return{type:"propertyAccess",object:Y(o.object,e),property:o.property}}function sn(o){let e=ft(o.raw);return!e.success||!e.node?{type:"identifier",name:o.raw}:e.node}function ht(o,e){return o.roles.get(e)}function w(o,e,t){let r=ht(o,e);return r?Y(r,t):void 0}function L(o,e=[],t,r={}){let n={type:"command",name:o,args:e};return t&&Object.keys(t).length>0&&(n.modifiers=t),r.isBlocking&&(n.isBlocking=r.isBlocking),r.implicitTarget&&(n.implicitTarget=r.implicitTarget),r.semanticRoles&&Object.keys(r.semanticRoles).length>0&&(n.semanticRoles=r.semanticRoles),n}var ln={action:"toggle",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=w(o,"duration"),a=t?[t]:[],i={};return r&&(i.on=r),n&&(i.for=n),L("toggle",a,i)}},cn={action:"add",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.to=r),L("add",n,a)}},un={action:"remove",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.from=r),L("remove",n,a)}},dn={action:"set",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"scope"),a=[],i={};return t&&a.push(t),r&&(i.to=r),n&&(i.on=n),L("set",a,i)}},pn={action:"show",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"duration"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.with=n),L("show",a,i)}},mn={action:"hide",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"duration"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.with=n),L("hide",a,i)}},fn={action:"increment",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"quantity"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.by=n),L("increment",a,i)}},hn={action:"decrement",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=w(o,"quantity"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.by=n),L("decrement",a,i)}},yn={action:"wait",toAST(o,e){let t=w(o,"event");if(t){let a={for:t},i=w(o,"source");return i&&(a.from=i),L("wait",[],a,{isBlocking:!0})}let r=w(o,"duration");return L("wait",r?[r]:[],void 0,{isBlocking:!0})}},gn={action:"log",toAST(o,e){let t=w(o,"patient"),r=[];return t&&r.push(t),L("log",r)}},vn={action:"put",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=ht(o,"manner")??ht(o,"method"),a=t?[t]:[],i={};if(r){let s=n?.type==="literal"?String(n.value):"into";i[s]=r}return L("put",a,i)}},kn={action:"fetch",toAST(o,e){let t=w(o,"source"),r=w(o,"method"),n=w(o,"responseType"),a=w(o,"patient"),i=t?[t]:[],s={};return r&&(s.with=r),n&&(s.as=n),a&&(s.body=a),L("fetch",i,s,{isBlocking:!0})}},Sn={action:"append",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.to=r),L("append",n,a)}},xn={action:"prepend",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.to=r),L("prepend",n,a)}},bn={action:"trigger",toAST(o,e){let t=w(o,"event"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.on=r),L("trigger",n,a)}},wn={action:"send",toAST(o,e){let t=w(o,"event"),r=w(o,"destination"),n=w(o,"patient"),a=t?[t]:[],i={};return r&&(i.to=r),n&&(i.detail=n),L("send",a,i)}},Tn={action:"go",toAST(o,e){let t=w(o,"source"),r=w(o,"destination"),n=[],a={};return t&&n.push(t),r&&(a.to=r),L("go",n,a)}},En={action:"transition",toAST(o,e){let t=w(o,"patient"),r=w(o,"goal"),n=w(o,"duration"),a=w(o,"destination"),i=t?[t]:[],s={};return r&&(s.to=r),n&&(s.over=n),a&&(s.on=a),L("transition",i,s)}},Cn={action:"focus",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a={},i=t??r;return i&&n.push(i),L("focus",n,a)}},Nn={action:"blur",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("blur",n)}},Pn={action:"get",toAST(o,e){let t=w(o,"source"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("get",n)}},Ln={action:"take",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.from=r),L("take",n,a)}},Rn={action:"call",toAST(o,e){let t=w(o,"patient");return L("call",t?[t]:[])}},An={action:"return",toAST(o,e){let t=w(o,"patient");return L("return",t?[t]:[])}},Mn={action:"halt",toAST(o,e){let t=o.roles.get("patient");return t?L("halt",[Y(t)]):L("halt",[])}},On={action:"throw",toAST(o,e){let t=w(o,"patient");return L("throw",t?[t]:[])}},zn={action:"settle",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("settle",n,void 0,{isBlocking:!0})}},Vn={action:"swap",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=w(o,"destination"),a=w(o,"style"),i=[],s={};return t&&i.push(t),r&&i.push(r),n&&(s.on=n),a&&(s.with=a),L("swap",i,s)}},In={action:"morph",toAST(o,e){let t=w(o,"source"),r=w(o,"destination"),n=w(o,"patient"),a=[],i={},s=t??r;return s&&a.push(s),n&&(i.on=n),L("morph",a,i)}},_n={action:"clone",toAST(o,e){let t=w(o,"source"),r=w(o,"destination"),n=w(o,"patient"),a=[],i={},s=t??n;return s&&a.push(s),r&&(i.into=r),L("clone",a,i)}},qn={action:"make",toAST(o,e){let t=w(o,"patient");return L("make",t?[t]:[])}},Bn={action:"measure",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=w(o,"source"),a=[],i={};t&&a.push(t);let s=r??n;return s&&(i.of=s),L("measure",a,i)}},$n={action:"tell",toAST(o,e){let t=w(o,"destination"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("tell",n)}},Dn={action:"js",toAST(o,e){let t=w(o,"patient");return L("js",t?[t]:[])}},jn={action:"async",toAST(o,e){return L("async",[])}},Wn={action:"if",toAST(o,e){let t=w(o,"condition");return L("if",t?[t]:[])}},Kn={action:"unless",toAST(o,e){let t=w(o,"condition");return L("unless",t?[t]:[])}},Un={action:"repeat",toAST(o,e){let t=w(o,"quantity"),r=w(o,"patient"),n=[],a=t??r;return a&&n.push(a),L("repeat",n)}},Fn={action:"for",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.in=r),L("for",n,a)}},Hn={action:"while",toAST(o,e){let t=w(o,"condition");return L("while",t?[t]:[])}},Gn={action:"continue",toAST(o,e){return L("continue",[])}},Yn={action:"default",toAST(o,e){let t=w(o,"patient"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.to=r),L("default",n,a)}},Zn={action:"init",toAST(o,e){return L("init",[])}},Jn={action:"behavior",toAST(o,e){let t=w(o,"patient");return L("behavior",t?[t]:[])}},Xn={action:"install",toAST(o,e){let t=w(o,"patient"),r=w(o,"destination"),n=t?[t]:[],a={};return r&&(a.on=r),L("install",n,a)}},Qn={action:"on",toAST(o,e){let t=w(o,"event"),r=w(o,"source"),n=t?[t]:[],a={};return r&&(a.from=r),L("on",n,a)}},Gt=new Map([["toggle",ln],["add",cn],["remove",un],["set",dn],["show",pn],["hide",mn],["increment",fn],["decrement",hn],["wait",yn],["log",gn],["put",vn],["fetch",kn],["append",Sn],["prepend",xn],["get",Pn],["take",Ln],["trigger",bn],["send",wn],["on",Qn],["go",Tn],["transition",En],["focus",Cn],["blur",Nn],["call",Rn],["return",An],["halt",Mn],["throw",On],["settle",zn],["swap",Vn],["morph",In],["clone",_n],["measure",Bn],["make",qn],["tell",$n],["default",Yn],["js",Dn],["async",jn],["if",Wn],["unless",Kn],["repeat",Un],["for",Fn],["while",Hn],["continue",Gn],["init",Zn],["behavior",Jn],["install",Xn]]);function Me(o){return Gt.get(o)}function yt(o){Gt.set(o.action,o)}var Oe=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);case"behavior":return this.buildBehavior(e);case"def":return this.buildDef(e);default:throw new Error(`Unknown semantic node kind: ${e.kind}`)}}buildBehavior(e){let t=e.eventHandlers.map(n=>this.buildEventHandler(n)),r={type:"behavior",name:e.name,parameters:[...e.parameters],eventHandlers:t};return e.initBlock&&e.initBlock.length>0&&(r.initBlock={type:"initBlock",commands:e.initBlock.map(n=>this.build(n))}),r}buildDef(e){return{type:"def",name:e.name,params:[...e.parameters],body:e.body.map(t=>this.build(t))}}buildCommand(e){let t=Me(e.action),r;if(t){let n=t.toAST(e,this);if("ast"in n&&"warnings"in n){let a=n;this.warnings.push(...a.warnings),r=a.ast}else r=n}else r=this.buildGenericCommand(e);if(e.roles&&e.roles.size>0){let n={};for(let[a,i]of e.roles)n[a]=Y(i);Object.keys(n).length>0&&(r.semanticRoles=n)}return r}buildGenericCommand(e){let t=[],r={},n=["patient","source","quantity"],a=["destination","duration","method","style"];for(let s of n){let l=e.roles.get(s);l&&t.push(Y(l))}for(let s of a){let l=e.roles.get(s);if(l){let c=this.roleToModifierKey(s);r[c]=Y(l)}}let i={type:"command",name:e.action,args:t};return Object.keys(r).length>0?{...i,modifiers:r}:i}roleToModifierKey(e){return{destination:"on",duration:"for",source:"from",condition:"if",method:"via",style:"with"}[e]??e}buildEventHandler(e){let t=e.roles.get("event"),r="click",n,a=t?.type==="literal"?String(t.value):t?.type==="expression"?t.raw:t?.type==="reference"?t.value:void 0;a!==void 0&&(a.includes("|")||a.includes(" or ")?(n=a.split(/\s+or\s+|\|/).map(g=>g.trim()),r=n[0]):r=a);let i=e.body.map(g=>this.build(g)),s=e.roles.get("source"),l,c;s?.type==="selector"?(l=s.value,c=s.value):s?.type==="reference"?c=s.value:s?.type==="literal"&&(c=String(s.value));let d=e.roles.get("condition"),u=d?Y(d):void 0,f=e.roles.get("destination"),m=f?Y(f):void 0,p=e.eventModifiers,h=l;if(p?.from){let g=p.from;g.type==="selector"&&!l&&(h=g.value)}let y=e.parameterNames?[...e.parameterNames]:void 0;return{type:"eventHandler",event:r,commands:i,...n&&n.length>1?{events:n}:{},...h?{selector:h}:{},...c?{target:c}:{},...u?{condition:u}:{},...m?{watchTarget:m}:{},...y&&y.length>0?{args:y,params:y}:{}}}buildConditional(e){let t=e.roles.get("condition");if(!t)throw new Error("Conditional node missing condition");let r=Y(t),n=e.thenBranch.map(s=>this.build(s)),a=e.elseBranch?.map(s=>this.build(s)),i=[r,{type:"block",commands:n}];return a&&a.length>0&&i.push({type:"block",commands:a}),{type:"command",name:"if",args:i}}buildCompound(e){let t=e.statements.map(n=>this.build(n));return t.length===1?t[0]:t.length===0?{type:"block",commands:[]}:t.every(n=>n.type==="eventHandler")?{type:"Program",statements:t}:{type:"CommandSequence",commands:t}}buildLoop(e){let t=e.body.map(n=>this.build(n)),r=[{type:"identifier",name:e.loopVariant}];switch(e.loopVariant){case"times":{let n=e.roles.get("quantity");n&&r.push(Y(n));break}case"for":{e.loopVariable&&r.push({type:"string",value:e.loopVariable});let n=e.roles.get("source");n&&r.push(Y(n));break}case"while":case"until":{let n=e.roles.get("condition");n&&r.push(Y(n));break}case"forever":break}return r.push({type:"block",commands:t}),{type:"command",name:"repeat",args:r}}buildBlock(e){return{type:"block",commands:e.map(r=>this.build(r))}}};function Yt(o){let e=new Oe;return{ast:e.build(o),warnings:e.warnings}}var ye=new Map,ge=new Map,ze=new Map;var Zt=null;function Xt(o,e){let t={...o};for(let r of Object.keys(e)){let n=e[r],a=o[r];n!==void 0&&(typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof a=="object"&&a!==null&&!Array.isArray(a)?t[r]=Xt(a,n):t[r]=n)}return t}function Qt(o,e){return Xt(o,e)}function gt(o){if(!o.extends)return o;let e=ge.get(o.extends);if(!e)return console.warn(`[Registry] Profile '${o.code}' extends '${o.extends}' but base is not registered. Make sure to import the base language before the variant.`),o;let t=gt(e);return Qt(t,o)}function vt(o,e,t){ye.set(o,e),ge.set(o,t),ze.delete(o)}var Jt=new Map;function be(o){return o.split("-")[0]}function we(o){return o.includes("-")}function Ye(o){let e=ye.get(o);if(!e&&we(o)){let t=be(o);e=ye.get(t)}if(!e){let t=Array.from(ye.keys()).join(", ");throw new Error(`Language '${o}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${o}';`)}return e}function Ze(o){let e=ge.get(o);if(!e&&we(o)){let t=be(o);e=ge.get(t)}if(!e){let t=Array.from(ge.keys()).join(", ");throw new Error(`Language profile '${o}' is not registered. Registered languages: ${t||"none"}. Import the language module first: import '@lokascript/semantic/languages/${o}';`)}return gt(e)}function V(o){let e=ge.get(o);return!e&&we(o)&&(e=ge.get(be(o))),e?gt(e):void 0}function kt(){return Array.from(ye.keys())}function St(o){return ye.has(o)?!0:we(o)?ye.has(be(o)):!1}function er(o,e){return Ye(e).tokenize(o)}function Q(o){let e=ze.get(o);if(!e&&we(o)&&(e=ze.get(be(o))),e)return e;let t=Jt.get(o);if(!t&&we(o)&&(t=Jt.get(be(o))),t)return ze.set(o,t),t;if(!Zt)throw new Error(`No patterns registered for language '${o}'. Either import the language module or set a pattern generator.`);let r=Ze(o),n=Zt(r);return ze.set(o,n),n}function xt(o,e){return Q(o).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}var ve={code:"qu",name:"Quechua",nativeName:"Runasimi",direction:"ltr",script:"latin",wordOrder:"SOV",markingStrategy:"postposition",usesSpaces:!0,verb:{position:"end",subjectDrop:!0},references:{me:"noqa",it:"chay",you:"qam",result:"rurasqa",event:"ruwakuq",target:"punta",body:"kurku"},possessive:{marker:"-pa",markerPosition:"after-object",keywords:{\u00F1uqapa:"me",\u00F1uqaypa:"me",noqaq:"me",qampa:"you",paypa:"it",chay:"it"},connectors:["paq","pa"]},roleMarkers:{patient:{primary:"ta",position:"after"},destination:{primary:"man",alternatives:["pa"],position:"after"},source:{primary:"manta",position:"after"},style:{primary:"wan",position:"after"},event:{primary:"pi",position:"after"}},keywords:{toggle:{primary:"t'ikray",alternatives:["tikray"],normalized:"toggle"},add:{primary:"yapay",alternatives:["yapaykuy"],normalized:"add"},remove:{primary:"qichuy",alternatives:["hurquy","anchuchiy"],normalized:"remove"},put:{primary:"churay",alternatives:["tiyachiy"],normalized:"put"},append:{primary:"qatichiy",alternatives:["qhipaman_yapay"],normalized:"append"},prepend:{primary:"\xF1awpachiy",normalized:"prepend"},take:{primary:"hapiy",normalized:"take"},make:{primary:"ruray",alternatives:["kamay"],normalized:"make"},clone:{primary:"kikinchay",alternatives:[],normalized:"clone"},swap:{primary:"t'inkuy",alternatives:["rantikunakuy","rantin_tikray"],normalized:"swap"},morph:{primary:"tukunay",alternatives:[],normalized:"morph"},set:{primary:"churanay",alternatives:["kamaykuy"],normalized:"set"},get:{primary:"taripay",normalized:"get"},increment:{primary:"yapachiy",normalized:"increment"},decrement:{primary:"pisiyachiy",normalized:"decrement"},log:{primary:"qillqakuy",alternatives:["willakuy"],normalized:"log"},show:{primary:"rikuchiy",alternatives:["qawachiy"],normalized:"show"},hide:{primary:"pakay",alternatives:["pakakuy"],normalized:"hide"},transition:{primary:"pasay",alternatives:[],normalized:"transition"},on:{primary:"chaypim",alternatives:["kaypi"],normalized:"on"},trigger:{primary:"kuyuchiy",alternatives:["kichay"],normalized:"trigger"},send:{primary:"kachay",alternatives:["apachiy"],normalized:"send"},focus:{primary:"qhawachiy",alternatives:["qhaway"],normalized:"focus"},blur:{primary:"paqariy",alternatives:["mana qhawachiy"],normalized:"blur"},empty:{primary:"ch'usaq",normalized:"empty"},open:{primary:"paskay",normalized:"open"},close:{primary:"wichqay",normalized:"close"},select:{primary:"marcay",normalized:"select"},clear:{primary:"pichay",normalized:"clear"},reset:{primary:"musuqchay",normalized:"reset"},breakpoint:{primary:"sayachinay",normalized:"breakpoint"},go:{primary:"riy",alternatives:["puriy"],normalized:"go"},scroll:{primary:"kunray",alternatives:[],normalized:"scroll"},push:{primary:"tanqay",normalized:"push"},replace:{primary:"tikray_url",alternatives:[],normalized:"replace"},process:{primary:"rurariy",normalized:"process"},wait:{primary:"suyay",normalized:"wait"},fetch:{primary:"apamuy",alternatives:["taripakaramuy"],normalized:"fetch"},settle:{primary:"tiyakuy",normalized:"settle"},if:{primary:"sichus",normalized:"if"},unless:{primary:"mana sichus",normalized:"unless"},when:{primary:"maykama",normalized:"when"},where:{primary:"maypi",normalized:"where"},else:{primary:"manachus",alternatives:["hukniraq"],normalized:"else"},repeat:{primary:"kutipay",alternatives:["muyu"],normalized:"repeat"},for:{primary:"sapankaq",normalized:"for"},while:{primary:"kaykamaqa",normalized:"while"},forever:{primary:"forever",normalized:"forever"},continue:{primary:"qatipay",normalized:"continue"},halt:{primary:"sayay",alternatives:[],normalized:"halt"},throw:{primary:"chanqay",normalized:"throw"},call:{primary:"waqyay",alternatives:["qayay"],normalized:"call"},return:{primary:"kutichiy",alternatives:["kutimuy"],normalized:"return"},then:{primary:"chaymantataq",alternatives:["hinaspa","chaymanta"],normalized:"then"},and:{primary:"hinallataq",alternatives:["ima","chaymantawan"],normalized:"and"},end:{primary:"tukukuy",alternatives:["tukuy","puchukay"],normalized:"end"},js:{primary:"js",normalized:"js"},async:{primary:"mana waqtalla",normalized:"async"},tell:{primary:"niy",alternatives:[],normalized:"tell"},default:{primary:"\xF1awpaq_kaq",alternatives:["qallariy"],normalized:"default"},init:{primary:"qallarichiy",normalized:"init"},behavior:{primary:"ruwana",normalized:"behavior"},install:{primary:"tarpuy",normalized:"install"},measure:{primary:"tupuy",normalized:"measure"},beep:{primary:"waqay",normalized:"beep"},break:{primary:"p'akiy",normalized:"break"},copy:{primary:"qillqay",normalized:"copy"},exit:{primary:"lluqsiy",normalized:"exit"},pick:{primary:"akllay",normalized:"pick"},render:{primary:"rikurichiy",normalized:"render"},into:{primary:"ukuman",normalized:"into"},before:{primary:"\xF1awpaq",normalized:"before"},after:{primary:"qhipa",normalized:"after"},until:{primary:"kama",alternatives:["-kama"],normalized:"until"},event:{primary:"ruwakuq",alternatives:["imayna"],normalized:"event"},from:{primary:"manta",alternatives:["-manta"],normalized:"from"},click:{primary:"\xF1itiy",normalized:"click"},load:{primary:"apakuy",normalized:"load"},submit:{primary:"apaykachay",normalized:"submit"},hover:{primary:"hawachiy",normalized:"hover"},input:{primary:"yaykuchiy",normalized:"input"},change:{primary:"kambiay",normalized:"change"},connect:{primary:"tinkiy",alternatives:["watay","hukllachay"],normalized:"connect"},stream:{primary:"phawachiy",alternatives:["sururichiy","ch'uquchiy"],normalized:"stream"},live:{primary:"kawsachkaq",alternatives:["kunan-pacha","kawsay"],normalized:"live"},socket:{primary:"tinkina",alternatives:["t'oqo","tinkiy-tinkina"],normalized:"socket"},bind:{primary:"bind",alternatives:["watachiy"],normalized:"bind"},intercept:{primary:"hark'ay",alternatives:["intercept"],normalized:"intercept"},worker:{primary:"llamk'aq",alternatives:["worker"],normalized:"worker"},eventsource:{primary:"eventsource",alternatives:["kawsay-pukyu"],normalized:"eventsource"}},eventHandler:{keyword:{primary:"pi",alternatives:["kaqtin"]},sourceMarker:{primary:"manta",position:"after"},eventMarker:{primary:"pi",alternatives:["kaqtin","kaqpi"],position:"after"}}};function U(o,e){return e?{type:"literal",value:o,dataType:e}:{type:"literal",value:o}}function Ve(o,e){return e?{type:"selector",value:o,selectorKind:e}:{type:"selector",value:o}}function Te(o){return{type:"reference",value:o}}function Xe(o,e){return{type:"property-path",object:o,property:e}}function bt(o,e=!0){return{type:"flag",name:o,enabled:e}}function rr(o,e,t){let r=e instanceof Map?e:new Map(Object.entries(e)),n={kind:"command",action:o,roles:r};return t?{...n,metadata:t}:n}function wt(o,e,t,r,n){let a=e instanceof Map?e:new Map(Object.entries(e));return{kind:"event-handler",action:o,roles:a,body:t,...n&&{eventModifiers:n},...r&&{metadata:r}}}function nr(o,e,t,r,n){let a=e instanceof Map?e:new Map(Object.entries(e));return{kind:"conditional",action:o,roles:a,thenBranch:t,...r&&{elseBranch:r},...n&&{metadata:n}}}function or(o,e,t,r,n,a,i){let s=e instanceof Map?e:new Map(Object.entries(e));return{kind:"loop",action:o,roles:s,loopVariant:t,body:r,...n&&{loopVariable:n},...a&&{indexVariable:a},...i&&{metadata:i}}}var Tt=new Set(["me","you","it","result","event","target","body"]);function Qe(o,e=Tt){return e.has(o)}var tr=new Set(["body","then","else","condition","loop-body","variable","catch","finally"]);function eo(o){let e=o.slice(1,-1),t=0;for(let r of e)if(r==="[")t++;else if(r==="]")t--;else if(t===0&&(r===" "||r===":"))return!0;return!1}function et(o,e={}){let t=o.trim(),r=e.collectDiagnostics===!0,n=[];if(!t.startsWith("[")||!t.endsWith("]"))throw new Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");let a=t.slice(1,-1).trim();if(!a)throw new Error("Empty explicit statement");let i=ro(a);if(i.length===0)throw new Error("No command specified in explicit statement");let s=i[0].toLowerCase(),l=new Map,c=e.referenceSet??Tt,d=e.schemaLookup?.getSchema(s),u=d?new Set(d.roles.map(m=>m.role)):null;for(let m=1;m<i.length;m++){let p=i[m];if(p.startsWith("+")||p.startsWith("~")){let C=p.startsWith("+"),S=p.slice(1);if(!S){if(r){n.push({severity:"error",code:"EMPTY_FLAG",message:`Empty flag name: "${p}"`,source:"schema"});continue}throw new Error(`Empty flag name: "${p}"`)}if(u&&!u.has(S)){if(r){n.push({severity:"error",code:"UNKNOWN_FLAG",message:`Unknown flag "${S}" for command "${s}"`,source:"schema",suggestions:[...u].map(k=>`+${k}`)}),l.set(S,bt(S,C));continue}throw new Error(`Unknown flag "${S}" for command "${s}". Valid roles: ${[...u].join(", ")}`)}l.set(S,bt(S,C));continue}let h=p.indexOf(":");if(h===-1){if(r){n.push({severity:"error",code:"INVALID_ROLE_FORMAT",message:`Invalid role format: "${p}". Expected role:value or +flag`,source:"schema"});continue}throw new Error(`Invalid role format: "${p}". Expected role:value or +flag`)}let y=p.slice(0,h);if(u&&!tr.has(y)&&!u.has(y))if(r)n.push({severity:"error",code:"UNKNOWN_ROLE",message:`Unknown role "${y}" for command "${s}"`,source:"schema",suggestions:[...u]});else throw new Error(`Unknown role "${y}" for command "${s}". Valid roles: ${[...u].join(", ")}`);let g=y,x=p.slice(h+1);if(tr.has(y)&&x.startsWith("[")&&eo(x)){let C=oo(p,h+1),S=p.slice(h+1,C+1);l.set(g,{type:"expression",raw:S});continue}let T=no(x,c);l.set(g,T)}if(d&&s!=="on"){for(let m of d.roles)if(m.required&&!l.has(m.role)&&!m.default)if(r)n.push({severity:"error",code:"MISSING_REQUIRED_ROLE",message:`Missing required role "${m.role}" for command "${s}": ${m.description}`,source:"schema"});else throw new Error(`Missing required role "${m.role}" for command "${s}": ${m.description}`)}let f=m=>n.length===0?m:{...m,diagnostics:n};switch(s){case"on":{if(!l.get("event")){if(r)return n.push({severity:"error",code:"MISSING_EVENT_ROLE",message:"Event handler requires event role: [on event:click ...]",source:"schema"}),f(wt("on",l,[],{sourceLanguage:"explicit"}));throw new Error("Event handler requires event role: [on event:click ...]")}let p=Je(l,"body",e);return l.delete("body"),f(wt("on",l,p,{sourceLanguage:"explicit"}))}case"if":{let m=Je(l,"then",e),p=Je(l,"else",e);return l.delete("then"),l.delete("else"),f(nr(s,l,m,p.length>0?p:void 0,{sourceLanguage:"explicit"}))}case"repeat":{let m=Je(l,"loop-body",e),p=l.get("loop-variant"),h=l.get("variable"),y=l.get("index-variable");l.delete("loop-body"),l.delete("loop-variant"),l.delete("variable"),l.delete("index-variable");let g;p&&p.type==="literal"&&typeof p.value=="string"?g=p.value:l.has("quantity")?g="times":l.has("source")?g="for":l.has("condition")?g="while":g="forever";let x=h?.type==="literal"&&typeof h.value=="string"?h.value:h?.type==="expression"?h.raw:void 0,T=y?.type==="literal"&&typeof y.value=="string"?y.value:void 0;return f(or(s,l,g,m,x,T,{sourceLanguage:"explicit"}))}default:return f(rr(s,l,{sourceLanguage:"explicit"}))}}function de(o){let e=o.trim();return e.startsWith("[")&&e.endsWith("]")}function Je(o,e,t){let r=o.get(e);return r?r.type==="expression"?[et(r.raw,t)]:[]:[]}function to(o){if(o){if(o.startsWith("#"))return"id";if(o.startsWith("."))return"class";if(o.startsWith("["))return"attribute";if(o.startsWith("<")||o.startsWith("*"))return"element";if(/[>+~ ]/.test(o)&&o.length>1)return"complex"}}function ro(o){let e=[],t="",r=!1,n="",a=0;for(let i=0;i<o.length;i++){let s=o[i];if(r){t+=s,s===n&&o[i-1]!=="\\"&&(r=!1);continue}if(s==='"'||s==="'"){r=!0,n=s,t+=s;continue}if(s==="["){a++,t+=s;continue}if(s==="]"){a--,t+=s;continue}if(s===" "&&a===0){t&&(e.push(t),t="");continue}t+=s}return t&&e.push(t),e}function no(o,e){if(o.startsWith("#")||o.startsWith(".")||o.startsWith("[")||o.startsWith("@")||o.startsWith("*"))return Ve(o,to(o));if(o.startsWith('"')||o.startsWith("'"))return U(o.slice(1,-1),"string");if(o==="true")return U(!0,"boolean");if(o==="false")return U(!1,"boolean");let t=o.toLowerCase();if(Qe(t,e))return Te(t);let r=o.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(r){let n=parseFloat(r[1]);return r[2]?U(o,"duration"):U(n,"number")}return U(o)}function oo(o,e){let t=0;for(let r=e;r<o.length;r++)if(o[r]==="[")t++;else if(o[r]==="]"&&(t--,t===0))return r;return o.length-1}function ee(o){let e;if(o.kind==="compound"){let t=o;e=t.statements.map(r=>ee(r)).join(` ${t.chainType} `)}else e=ao(o);return o.annotations&&o.annotations.length>0?o.annotations.map(r=>r.value!==void 0?`@${r.name}(${r.value})`:`@${r.name}`).join(" ")+" "+e:e}function ao(o){let e=[o.action];for(let[t,r]of o.roles)r.type==="flag"?e.push(r.enabled?`+${r.name}`:`~${r.name}`):e.push(`${t}:${ar(r)}`);if(o.kind==="event-handler"){let t=o;t.body&&t.body.length>0&&e.push(`body:${t.body.map(r=>ee(r)).join(" ")}`)}if(o.kind==="conditional"){let t=o;t.thenBranch&&t.thenBranch.length>0&&e.push(`then:${t.thenBranch.map(r=>ee(r)).join(" ")}`),t.elseBranch&&t.elseBranch.length>0&&e.push(`else:${t.elseBranch.map(r=>ee(r)).join(" ")}`)}if(o.kind==="loop"){let t=o;t.loopVariant&&e.push(`loop-variant:${t.loopVariant}`),t.loopVariable&&e.push(`variable:${t.loopVariable}`),t.indexVariable&&e.push(`index-variable:${t.indexVariable}`),t.body&&t.body.length>0&&e.push(`loop-body:${t.body.map(r=>ee(r)).join(" ")}`)}if(o.kind==="command"){let t=o;t.body&&t.body.length>0&&e.push(`body:${t.body.map(r=>ee(r)).join(" ")}`),t.catchBranch&&t.catchBranch.length>0&&e.push(`catch:${t.catchBranch.map(r=>ee(r)).join(" ")}`),t.finallyBranch&&t.finallyBranch.length>0&&e.push(`finally:${t.finallyBranch.map(r=>ee(r)).join(" ")}`),t.asyncVariant&&e.push(`async-variant:${t.asyncVariant}`),t.asyncBody&&t.asyncBody.length>0&&e.push(`async-body:${t.asyncBody.map(r=>ee(r)).join(" ")}`)}return`[${e.join(" ")}]`}function ar(o){switch(o.type){case"literal":return typeof o.value=="string"?o.dataType==="string"||/\s/.test(o.value)?`"${o.value}"`:o.value:String(o.value);case"selector":return o.value;case"reference":return o.value;case"property-path":return`${ar(o.object)}'s ${o.property}`;case"expression":return o.raw;case"flag":return o.name}}var io=class{constructor(o){this.namespace=o,this.enabled=this.checkEnabled()}checkEnabled(){if(typeof process<"u"&&process.env){let o=process.env.DEBUG||"";return o==="*"||o.includes("framework:*")||o.includes(`framework:${this.namespace}`)}return!1}log(o,e,...t){if(!this.enabled)return;let r=`[framework:${this.namespace}]`,n=new Date().toISOString();switch(o){case"debug":console.debug(`${n} ${r} DEBUG:`,e,...t);break;case"info":console.info(`${n} ${r} INFO:`,e,...t);break;case"warn":console.warn(`${n} ${r} WARN:`,e,...t);break;case"error":console.error(`${n} ${r} ERROR:`,e,...t);break}}debug(o,...e){this.log("debug",o,...e)}info(o,...e){this.log("info",o,...e)}warn(o,...e){this.log("warn",o,...e)}error(o,...e){this.log("error",o,...e)}isEnabled(){return this.enabled}enable(){this.enabled=!0}disable(){this.enabled=!1}};function so(o){return new io(o)}function Ee(o,e){return!e||e.length===0||e.includes(o)||e.includes("expression")?!0:o==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):!1}function lo(o,e){return o?.possessive?.keywords?.[e]}function ir(o){return!1}var Ie=class Ce{constructor(){this.logger=so("pattern-matcher"),this.stemMatchCount=0,this.totalKeywordMatches=0}safeToLowerCase(e){return typeof e=="string"?e.toLowerCase():e==null?"":String(e).toLowerCase()}matchPattern(e,t,r){let n=e.mark(),a=new Map;if(this.logger.debug("========================================"),this.logger.debug("matchPattern ENTRY"),this.logger.debug("Pattern ID:",t.id),this.logger.debug("Pattern command:",t.command),this.logger.debug("Pattern language:",t.language),this.logger.debug("Pattern template:",JSON.stringify(t.template,null,2)),this.logger.isEnabled()){let l=[];for(let c=0;c<10;c++){let d=e.peek(c);if(d)l.push({type:d.type,value:d.value,kind:d.kind});else break}this.logger.debug("Input tokens (first 10):",l),this.logger.debug("Profile code:",r?.code)}this.currentProfile=r,this.stemMatchCount=0,this.totalKeywordMatches=0,this.logger.debug("--- Calling matchTokenSequence ---"),this.logger.debug("Pattern tokens to match:",JSON.stringify(t.template.tokens,null,2));let i=this.matchTokenSequence(e,t.template.tokens,a);if(this.logger.debug("matchTokenSequence returned:",i),this.logger.debug("Captured roles:",Array.from(a.entries()).map(([l,c])=>[l,JSON.stringify(c)])),!i)return this.logger.debug(">>> MATCH FAILED - resetting token position"),e.reset(n),null;let s=this.calculateConfidence(t,a);return this.applyExtractionRules(t,a),{pattern:t,captured:a,consumedTokens:e.position()-n.position,confidence:s}}matchBest(e,t,r){let n=[];for(let i of t){let s=e.mark(),l=this.matchPattern(e,i,r);l&&n.push(l),e.reset(s)}if(n.length===0)return null;n.sort((i,s)=>{let l=s.pattern.priority-i.pattern.priority;if(l!==0)return l;let c=s.confidence-i.confidence;return Math.abs(c)>.001?c:s.consumedTokens-i.consumedTokens});let a=n[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,t,r,n){let a=t[0],i=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!i)for(;e.peek()?.kind==="conjunction";)e.advance();let s=null,l=null;for(let c=0;c<t.length;c++){let d=t[c];this.logger.debug(" >> Matching pattern token:",JSON.stringify(d,null,2));let u=e.peek();if(this.logger.debug(" >> Current input token:",u?JSON.stringify({type:u.type,value:u.value,kind:u.kind}):"EOF"),d.type==="role"&&d.greedy){let y=this.collectStopMarkers(t,c+1);if(n)for(let x of n)y.add(x);let g=[];for(;!e.isAtEnd();){let x=e.peek();if(!x||this.isStopMarker(x,y))break;g.push(x.value),e.advance()}if(g.length>0){r.set(d.role,{type:"expression",raw:g.join(" ")}),s=null,l=null;continue}else{if(d.optional)continue;return!1}}if(d.type==="group"){let y=this.collectStopMarkers(t,c+1);if(n)for(let x of n)y.add(x);if(this.matchGroupToken(e,d,r,y)){s=null,l=null;continue}if(this.isOptional(d))continue;return!1}let f=d.type==="role"&&d.optional===!0,m=f?e.mark():null;if(d.type==="role"&&!f){let y=c+1<t.length?t[c+1]:null;if(y?.type==="literal"){let g=e.peek();if(g&&this.getMatchType(g,y.value)!=="none"){if(this.logger.debug(" >> MARKER-STEAL GUARD: current token matches next literal, skipping role"),this.logger.debug(" >> Token match FAILED"),this.isOptional(d))continue;if(s&&l){this.logger.debug(" >> BACKTRACKING: undoing optional role",l),e.reset(s),r.delete(l),s=null,l=null;let x=this.matchPatternToken(e,d,r);if(this.logger.debug(" >> Backtrack retry result:",x),x)continue}return!1}}}let h=this.matchPatternToken(e,d,r);if(this.logger.debug(" >> Match result:",h),h){f?(s=m,l=d.role):(s=null,l=null);continue}if(this.logger.debug(" >> Token match FAILED"),!this.isOptional(d)){if(s&&l){this.logger.debug(" >> BACKTRACKING: undoing optional role",l),e.reset(s),r.delete(l),s=null,l=null;let y=this.matchPatternToken(e,d,r);if(this.logger.debug(" >> Backtrack retry result:",y),y)continue}return!1}}return!0}matchPatternToken(e,t,r){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r);case"group":return this.matchGroupToken(e,t,r);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(this.logger.debug(" >>> matchLiteralToken: expecting",t.value),this.logger.debug(" >>> matchLiteralToken: got token",r?JSON.stringify({type:r.type,value:r.value,kind:r.kind}):"null"),!r)return this.logger.debug(" >>> matchLiteralToken: FAIL - no token"),!1;let n=this.getMatchType(r,t.value);if(this.logger.debug(" >>> matchType for",r.value,"vs",t.value,":",n),n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let a of t.alternatives){let i=this.getMatchType(r,a);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,r){this.logger.debug(" >>> matchRoleToken ENTRY: capturing role",t.role),this.logger.debug(" >>> matchRoleToken: expected types",t.expectedTypes),this.logger.debug(" >>> matchRoleToken: optional?",t.optional),this.skipNoiseWords(e);let n=e.peek();if(this.logger.debug(" >>> After skipNoiseWords, current token:",n?JSON.stringify({value:n.value,kind:n.kind}):"null"),!n)return t.optional||!1;let a=this.tryMatchPossessiveExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(a.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,a),!0);let i=this.tryMatchMethodCallExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(i.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,i),!0);let s=this.tryMatchPossessiveSelectorExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);let l=this.tryMatchPropertyAccessExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(l.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,l),!0);let c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!Ee(c.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,c),!0);this.logger.debug(" >>> Trying tokenToSemanticValue for token:",n?JSON.stringify({value:n.value,kind:n.kind}):"null");let d=this.tokenToSemanticValue(n);return this.logger.debug(" >>> tokenToSemanticValue returned:",d?JSON.stringify(d):"null"),d?(this.logger.debug(" >>> Validating type:",d.type,"against expected:",t.expectedTypes),t.expectedTypes&&t.expectedTypes.length>0&&!Ee(d.type,t.expectedTypes)?(this.logger.debug(" >>> TYPE MISMATCH - returning",t.optional||!1),t.optional||!1):(this.logger.debug(" >>> Type validation PASSED"),r.set(t.role,d),e.advance(),!0)):t.optional||!1}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=t.normalized||t.value,n=this.safeToLowerCase(r),a=lo(this.currentProfile,n);if(!a)return null;let i=e.mark();e.advance();let s=e.peek();if(!s)return e.reset(i),null;if(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)||s.kind==="selector"&&s.value.startsWith("*")||s.kind==="selector"&&s.value.startsWith("@")||s.kind==="selector"&&s.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s.value)){e.advance();let l=s.value;s.kind==="selector"&&l.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(l)&&(l=l.substring(1));let c=l;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)c+=e.peek().value,e.advance();let d=e.peek();return d?.kind==="literal"&&d.value.startsWith("(")&&(c+=d.value,e.advance()),Xe(Te(a),c)}return e.reset(i),null}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(r),null;e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<Ce.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${a.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(r),null;e.advance();let i=`${t.value}.${a.value}`,s=1;for(;!e.isAtEnd()&&s<Ce.MAX_PROPERTY_DEPTH;){let c=e.peek();if(!c||c.kind!=="operator"||c.value!==".")break;e.advance();let d=e.peek();if(!d||d.kind!=="identifier")break;e.advance(),i+=`.${d.value}`,s++}let l=e.peek();if(l&&l.kind==="punctuation"&&l.value==="("){e.advance();let c=[],d=0;for(;!e.isAtEnd()&&c.length<Ce.MAX_METHOD_ARGS;){let f=e.peek();if(!f)break;if(f.kind==="punctuation"&&f.value===")"){if(d===0){e.advance();break}d--}if(f.kind==="punctuation"&&f.value==="("&&d++,f.kind==="punctuation"&&f.value===","){e.advance();continue}c.push(f.value),e.advance()}return{type:"expression",raw:`${i}(${c.join(", ")})`}}return{type:"expression",raw:i}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="punctuation"||n.value!=="'s")return e.reset(r),null;e.advance();let a=e.peek();return!a||a.kind!=="selector"&&a.kind!=="identifier"?(e.reset(r),null):(e.advance(),Xe(Ve(t.value),a.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||typeof t.value!="string"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(r),null;let a=e.peek(1);a&&a.kind,e.advance();let i=n.value.slice(1);return Xe(Ve(t.value),i)}matchGroupToken(e,t,r,n){let a=e.mark(),i=new Set(r.keys());if(this.matchTokenSequence(e,t.tokens,r,n))return!0;e.reset(a);for(let c of r.keys())i.has(c)||r.delete(c);if(!t.optional)return!1;let l=this.getGroupLeadingMarker(t);if(l)for(let c=1;c<=Ce.MAX_MARKER_SCAN;c++){let d=e.peek(c);if(!d)break;if((d.normalized||d.value).toLowerCase()===l){this.logger.debug(" >> MARKER SCAN: found",l,"at offset",c,"- skipping intervening tokens");for(let m=0;m<c;m++)e.advance();if(this.matchTokenSequence(e,t.tokens,r,n))return!0;e.reset(a);for(let m of r.keys())i.has(m)||r.delete(m);break}}return!0}getGroupLeadingMarker(e){let t=e.tokens[0];return t?.type==="literal"?t.value.toLowerCase():null}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"&&this.safeToLowerCase(e.value)===t.toLowerCase()?"case-insensitive":"none"}collectStopMarkers(e,t){let r=new Set;for(let n=t;n<e.length;n++){let a=e[n];if(a.type==="literal"){if(r.add(a.value.toLowerCase()),a.alternatives)for(let i of a.alternatives)r.add(i.toLowerCase());break}if(a.type==="group"){for(let i of a.tokens)if(i.type==="literal"){if(r.add(i.value.toLowerCase()),i.alternatives)for(let s of i.alternatives)r.add(s.toLowerCase());break}if(!a.optional)break}}return r}isStopMarker(e,t){return t.size===0?!1:!!(t.has(e.value.toLowerCase())||e.normalized&&t.has(e.normalized.toLowerCase()))}tokenToSemanticValue(e){switch(e.kind){case"selector":return Ve(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=e.normalized||e.value,r=this.safeToLowerCase(t);return ir(r)?Te(r):U(e.normalized||e.value);case"identifier":if(typeof e.value=="string"&&e.value.startsWith(":"))return Te(e.value);let n=this.safeToLowerCase(e.value);return ir(n)?Te(n):{type:"expression",raw:e.value};case"url":return U(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let n=e.slice(1,-1);return U(n,"string")}if(e==="true")return U(!0,"boolean");if(e==="false")return U(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let n=parseFloat(t[1]);return t[2]?U(e,"duration"):U(n,"number")}let r=parseFloat(e);return isNaN(r)?U(e,"string"):U(r,"number")}applyExtractionRules(e,t){for(let[r,n]of Object.entries(e.extraction))t.has(r)||(n.value!==void 0?t.set(r,{type:"literal",value:n.value}):n.default&&t.set(r,n.default))}isOptional(e){return e.type!=="literal"&&e.optional===!0}calculateConfidence(e,t){let r=0,n=0,a=c=>e.extraction?.[c]?.default!==void 0;for(let c of e.template.tokens)if(c.type==="role")n+=1,t.has(c.role)&&(r+=1);else if(c.type==="group"){for(let d of c.tokens)if(d.type==="role"){let u=a(d.role),f=.8;n+=f,t.has(d.role)?r+=f:u&&(r+=f*.6)}}let i=n>0?r/n:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let c=this.stemMatchCount/this.totalKeywordMatches*.15;i=Math.max(.5,i-c)}let s=this.calculateVSOConfidenceBoost(e);i=Math.min(1,i+s);let l=this.arabicPrepositionDisambiguation(e,t);return i=Math.max(0,Math.min(1,i+l)),i}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let t=e.template.tokens[0];if(!t||t.type!=="literal")return 0;let r=new Set(["\u0628\u062F\u0644","\u063A\u064A\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062C\u0639\u0644","\u0639\u064A\u0646","\u0632\u062F","\u0627\u0646\u0642\u0635","\u0633\u062C\u0644","\u0623\u0638\u0647\u0631","\u0623\u062E\u0641","\u0634\u063A\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062A\u0648\u0642\u0641","\u0627\u0646\u0633\u062E","\u0627\u062D\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062A\u0638\u0631","\u0627\u0646\u062A\u0642\u0627\u0644","\u0623\u0648"]);if(r.has(t.value))return .15;if(t.alternatives){for(let n of t.alternatives)if(r.has(n))return .15}return 0}arabicPrepositionDisambiguation(e,t){if(e.language!=="ar")return 0;let r=0,n={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[a,i]of t.entries()){let s=n[a];if(!s||s.length===0)continue;let l="metadata"in i?i.metadata:void 0;if(l&&typeof l.prepositionValue=="string"){let c=l.prepositionValue;s.includes(c)?r+=.1:r-=.1}}return Math.max(-.1,Math.min(.1,r))}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=this.safeToLowerCase(t.value);if(Ce.ENGLISH_NOISE_WORDS.has(r)){let n=e.mark();e.advance();let a=e.peek();if(a&&a.kind==="selector")return;e.reset(n)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(r=!0,a.modifierName){case"once":t.once=!0;break;case"debounce":typeof a.value=="number"&&(t.debounce=a.value);break;case"throttle":typeof a.value=="number"&&(t.throttle=a.value);break;case"queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(t.queue=a.value);break}e.advance()}return r?t:void 0}};Ie.MAX_MARKER_SCAN=3;Ie.MAX_PROPERTY_DEPTH=10;Ie.MAX_METHOD_ARGS=20;Ie.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var co=Ie,Wi=new co;var Et=class{constructor(){this.name="number"}canExtract(o,e){return/\d/.test(o[e])}extract(o,e){let t=0,r=!1;for(;e+t<o.length;){let i=o[e+t];if(/\d/.test(i))t++;else if(i==="."&&!r)r=!0,t++;else break}if(t===0)return null;let n=o.substring(e,e+t),a=e+t;if(a<o.length){let i=o.slice(a),s=[{pattern:"\u6BEB\u79D2",suffix:"ms"},{pattern:"\u5206\u949F",suffix:"m"},{pattern:"\u5C0F\u65F6",suffix:"h"},{pattern:"\u30DF\u30EA\u79D2",suffix:"ms"},{pattern:"\u6642\u9593",suffix:"h"}];for(let c of s)if(i.startsWith(c.pattern))return{value:n+c.suffix,length:t+c.pattern.length,metadata:{hasTimeUnit:!0}};if(i.startsWith("ms"))return{value:n+"ms",length:t+2,metadata:{hasTimeUnit:!0}};let l=[{pattern:"\u79D2",suffix:"s"},{pattern:"\u5206",suffix:"m"}];for(let c of l)if(i.startsWith(c.pattern))return{value:n+c.suffix,length:t+1,metadata:{hasTimeUnit:!0}};if(/^[smh](?![a-zA-Z])/.test(i))return{value:n+i[0],length:t+1,metadata:{hasTimeUnit:!0}}}return{value:n,length:t}}};function uo(o){return"setContext"in o&&typeof o.setContext=="function"}function po(o){let e={language:o.language,direction:o.direction,lookupKeyword:o.lookupKeyword.bind(o),isKeyword:o.isKeyword.bind(o),isKeywordStart:o.isKeywordStart.bind(o),...o.isKeywordStartAtBoundary?{isKeywordStartAtBoundary:o.isKeywordStartAtBoundary.bind(o)}:{}};return o.normalizer?{...e,normalizer:o.normalizer}:e}var X=class{constructor(o,e){this.pos=0,this.tokens=o,this.language=e}peek(o=0){let e=this.pos+o;return e<0||e>=this.tokens.length?null:this.tokens[e]}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(o){this.pos=o.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(o){let e=[];for(;!this.isAtEnd()&&o(this.peek());)e.push(this.advance());return e}skipWhile(o){for(;!this.isAtEnd()&&o(this.peek());)this.advance()}};function B(o,e){return{start:o,end:e}}function $(o,e,t,r){if(typeof o=="object"){let{value:a,kind:i,position:s,normalized:l,stem:c,stemConfidence:d,metadata:u}=o;return{value:a,kind:i,position:s,...l!==void 0&&{normalized:l},...c!==void 0&&{stem:c},...d!==void 0&&{stemConfidence:d},...u!==void 0&&{metadata:u}}}let n=o;if(!e||!t)throw new Error("createToken requires kind and position parameters");if(typeof r=="string")return{value:n,kind:e,position:t,normalized:r};if(r){let{normalized:a,stem:i,stemConfidence:s,metadata:l}=r;return{value:n,kind:e,position:t,...a!==void 0&&{normalized:a},...i!==void 0&&{stem:i},...s!==void 0&&{stemConfidence:s},...l!==void 0&&{metadata:l}}}return{value:n,kind:e,position:t}}function pe(o){return/\s/.test(o)}function tt(o){return o==="#"||o==="."||o==="["||o==="@"||o==="*"||o==="<"}function rt(o){return o==='"'||o==="'"||o==="`"||o==="\u300C"||o==="\u300D"}function ae(o){return/\d/.test(o)}function nt(o){return/[a-zA-Z]/.test(o)}function W(o){return/[a-zA-Z0-9_-]/.test(o)}function sr(o,e){if(e>=o.length)return null;let t=o[e];if(!tt(t))return null;let r=e,n="";if(t==="#"||t==="."){for(n+=o[r++];r<o.length&&W(o[r]);)n+=o[r++];if(n.length<=1)return null;if(r<o.length&&o[r]==="."&&t==="#"){let i=r+1;for(;i<o.length&&W(o[i]);)i++;if(i<o.length&&o[i]==="(")return n}}else if(t==="["){let a=1,i=!1,s=null,l=!1;for(n+=o[r++];r<o.length&&a>0;){let c=o[r];n+=c,l?l=!1:c==="\\"?l=!0:i?c===s&&(i=!1,s=null):c==='"'||c==="'"||c==="`"?(i=!0,s=c):c==="["?a++:c==="]"&&a--,r++}if(a!==0)return null}else if(t==="@"){for(n+=o[r++];r<o.length&&W(o[r]);)n+=o[r++];if(n.length<=1)return null}else if(t==="*"){for(n+=o[r++];r<o.length&&W(o[r]);)n+=o[r++];if(n.length<=1)return null}else if(t==="<"){if(n+=o[r++],r>=o.length||!nt(o[r]))return null;for(;r<o.length&&W(o[r]);)n+=o[r++];for(;r<o.length;){let a=o[r];if(a==="."){if(n+=o[r++],r>=o.length||!W(o[r]))return null;for(;r<o.length&&W(o[r]);)n+=o[r++]}else if(a==="#"){if(n+=o[r++],r>=o.length||!W(o[r]))return null;for(;r<o.length&&W(o[r]);)n+=o[r++]}else if(a==="["){let i=1,s=!1,l=null,c=!1;for(n+=o[r++];r<o.length&&i>0;){let d=o[r];n+=d,c?c=!1:d==="\\"?c=!0:s?d===l&&(s=!1,l=null):d==='"'||d==="'"||d==="`"?(s=!0,l=d):d==="["?i++:d==="]"&&i--,r++}if(i!==0)return null}else break}for(;r<o.length&&pe(o[r]);)n+=o[r++];if(r<o.length&&o[r]==="/")for(n+=o[r++];r<o.length&&pe(o[r]);)n+=o[r++];if(r>=o.length||o[r]!==">")return null;n+=o[r++]}return n||null}function mo(o,e){if(e>=o.length||o[e]!=="'"||e+1>=o.length||o[e+1].toLowerCase()!=="s")return!1;if(e+2>=o.length)return!0;let r=o[e+2];return pe(r)||r==="*"||!W(r)}function lr(o,e){if(e>=o.length)return null;let t=o[e];if(!rt(t)||t==="'"&&mo(o,e))return null;let n={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[t];if(!n)return null;let a=e+1,i=t,s=!1;for(;a<o.length;){let l=o[a];if(i+=l,s)s=!1;else if(l==="\\")s=!0;else if(l===n)return i;a++}return i}function cr(o,e){if(e>=o.length)return!1;let t=o[e],r=o[e+1]||"",n=o[e+2]||"";if(t==="/"&&r!=="/"&&/[a-zA-Z0-9._-]/.test(r)||t==="/"&&r==="/"&&/[a-zA-Z]/.test(n)||t==="."&&(r==="/"||r==="."&&n==="/"))return!0;let a=o.slice(e,e+8).toLowerCase();return!!(a.startsWith("http://")||a.startsWith("https://"))}function ur(o,e){if(!cr(o,e))return null;let t=e,r="",n=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;t<o.length;){let a=o[t];if(a==="#"){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=a,t++;t<o.length&&/[a-zA-Z0-9_-]/.test(o[t]);)r+=o[t++];break}if(n.test(a))r+=a,t++;else break}return r.length<2?null:r}function dr(o,e){if(e>=o.length)return null;let t=o[e];if(!ae(t)&&t!=="-"&&t!=="+")return null;let r=e,n="";if((o[r]==="-"||o[r]==="+")&&(n+=o[r++]),r>=o.length||!ae(o[r]))return null;for(;r<o.length&&ae(o[r]);)n+=o[r++];if(r<o.length&&o[r]===".")for(n+=o[r++];r<o.length&&ae(o[r]);)n+=o[r++];return r<o.length&&(o.slice(r,r+2)==="ms"?n+="ms":(o[r]==="s"||o[r]==="m"||o[r]==="h")&&(n+=o[r])),n}var fo=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"];var Gi=new Set(fo),ho=new Set(["patient","destination","source","style","event","eventMarker","agent","goal","manner","into","from","to","with","at","of","as","by","in","on","over","under","between","through","without"]),yo=["click","dblclick","input","change","submit","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave","mousemove","pointerdown","pointerup","pointermove","focus","blur","load","resize","scroll"],pr=class mr{constructor(){this.profileKeywords=[],this.multiWordKeywords=[],this.profileKeywordMap=new Map,this.rawExtraEntries=[],this.extractors=[]}getExtraKeywordEntries(){return this.rawExtraEntries}tokenize(e){if(this.isUsingExtractors())return this.tokenizeWithExtractors(e);throw new Error(`${this.constructor.name}: tokenize() not implemented and no extractors registered. Either register extractors or override tokenize() method.`)}registerExtractor(e){uo(e)&&e.setContext(po(this)),this.extractors.push(e)}registerExtractors(e){for(let t of e)this.registerExtractor(t)}clearExtractors(){this.extractors=[]}isUsingExtractors(){return this.extractors.length>0}tokenizeWithExtractors(e){let t=[],r=0;for(;r<e.length;){for(;r<e.length&&pe(e[r]);)r++;if(r>=e.length)break;let n=this.tryMultiWordKeyword(e,r);if(n){t.push(n),r=n.position.end;continue}let a=!1;for(let i of this.extractors)if(i.canExtract(e,r)){let s=i.extract(e,r);if(s){let l=s.metadata?.normalized,c=s.metadata?.stem,d=s.metadata?.stemConfidence,u={};if(s.metadata)for(let[m,p]of Object.entries(s.metadata))m!=="normalized"&&m!=="stem"&&m!=="stemConfidence"&&(u[m]=p);let f={};l&&(f.normalized=l),c&&(f.stem=c),d!==void 0&&(f.stemConfidence=d),Object.keys(u).length>0&&(f.metadata=u),t.push($(s.value,this.classifyToken(s.value),B(r,r+s.length),Object.keys(f).length>0?f:void 0)),r+=s.length,a=!0;break}}if(!a){let i=e[r],s=this.classifyUnknownChar(i);t.push($(i,s,B(r,r+1))),r++}}return new X(t,this.language)}classifyUnknownChar(e){return"()[]{},:;".includes(e)?"punctuation":"+-*/<>=!&|".includes(e)?"operator":"identifier"}tryPropertyAccess(e,t,r){if(e[t]!==".")return!1;let n=r[r.length-1],a=n&&n.position.end<t;if(n&&!a&&(n.kind==="identifier"||n.kind==="keyword"||n.kind==="selector"))return r.push($(".","operator",B(t,t+1))),!0;let l=t+1;for(;l<e.length&&W(e[l]);)l++;return l<e.length&&e[l]==="("?(r.push($(".","operator",B(t,t+1))),!0):!1}initializeKeywordsFromProfile(e,t=[]){let r=new Map;if(this.rawExtraEntries=t,e.keywords){for(let[n,a]of Object.entries(e.keywords))if(r.set(a.primary,{native:a.primary,normalized:a.normalized||n}),a.alternatives)for(let i of a.alternatives)r.set(i,{native:i,normalized:a.normalized||n})}if(e.references){for(let[n,a]of Object.entries(e.references))r.set(a,{native:a,normalized:n});for(let n of Object.keys(e.references))r.has(n)||r.set(n,{native:n,normalized:n})}if(e.roleMarkers){for(let[n,a]of Object.entries(e.roleMarkers))if(a.primary&&r.set(a.primary,{native:a.primary,normalized:n}),a.alternatives)for(let i of a.alternatives)r.set(i,{native:i,normalized:n})}if(e.possessive?.keywords)for(let[n,a]of Object.entries(e.possessive.keywords))r.set(n,{native:n,normalized:a});for(let n of yo)r.has(n)||r.set(n,{native:n,normalized:n});for(let n of t)r.set(n.native,n);this.profileKeywords=Array.from(r.values()).sort((n,a)=>a.native.length-n.native.length),this.multiWordKeywords=this.profileKeywords.filter(n=>n.native.includes(" ")&&!ho.has(n.normalized)),this.profileKeywordMap=new Map;for(let n of this.profileKeywords){this.profileKeywordMap.set(n.native.toLowerCase(),n);let a=this.removeDiacritics(n.native);a!==n.native&&!this.profileKeywordMap.has(a.toLowerCase())&&this.profileKeywordMap.set(a.toLowerCase(),n)}}removeDiacritics(e){return e.replace(/[\u064B-\u0652\u0670]/g,"")}tryProfileKeyword(e,t){for(let r of this.profileKeywords)if(e.slice(t).startsWith(r.native))return $(r.native,"keyword",B(t,t+r.native.length),r.normalized);return null}tryMultiWordKeyword(e,t,r=n=>/[\p{L}\p{N}_]/u.test(n)){if(this.multiWordKeywords.length===0)return null;let n=e.slice(t);for(let a of this.multiWordKeywords){if(!n.startsWith(a.native))continue;let i=e[t+a.native.length];if(!(i!==void 0&&r(i)))return $(a.native,"keyword",B(t,t+a.native.length),a.normalized)}return null}isKeywordStart(e,t){let r=e.slice(t);return this.profileKeywords.some(n=>r.startsWith(n.native))}isKeywordStartAtBoundary(e,t,r=n=>/[\p{L}\p{N}_]/u.test(n)){let n=e.slice(t);return this.profileKeywords.some(a=>{if(!n.startsWith(a.native))return!1;let i=e[t+a.native.length];return i===void 0||!r(i)})}lookupKeyword(e){return this.profileKeywordMap.get(e.toLowerCase())}isKeyword(e){return this.profileKeywordMap.has(e.toLowerCase())}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;let t=this.normalizer.normalize(e);return t.stem!==e&&t.confidence>=.7?t:null}tryMorphKeywordMatch(e,t,r){let n=this.tryNormalize(e);if(!n)return null;let a=this.lookupKeyword(n.stem);if(!a)return null;let i={normalized:a.normalized,stem:n.stem,stemConfidence:n.confidence};return $(e,"keyword",B(t,r),i)}trySelector(e,t){let r=sr(e,t);return r?$(r,"selector",B(t,t+r.length)):null}tryEventModifier(e,t){if(e[t]!==".")return null;let r=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!r)return null;let n=r[0].replace(/(\s|\.)$/,""),a=n.slice(1).split("(")[0],i=r[1];return{...$(n,"event-modifier",B(t,t+n.length)),metadata:{modifierName:a,value:i?a==="queue"?i:parseInt(i,10):void 0}}}tryString(e,t){let r=lr(e,t);return r?$(r,"literal",B(t,t+r.length)):null}tryNumber(e,t){let r=dr(e,t);return r?$(r,"literal",B(t,t+r.length)):null}tryMatchTimeUnit(e,t,r,n=!1){let a=t;if(n)for(;a<e.length&&pe(e[a]);)a++;let i=e.slice(a);for(let s of r){let l=i.slice(0,s.length);if(s.caseInsensitive?l.toLowerCase()===s.pattern.toLowerCase():l===s.pattern){if(s.notFollowedBy&&(i[s.length]||"")===s.notFollowedBy)continue;if(s.checkBoundary){let d=i[s.length]||"";if(W(d))continue}return{suffix:s.suffix,endPos:a+s.length}}}return null}parseBaseNumber(e,t,r=!0){let n=t,a="";if(r&&(e[n]==="-"||e[n]==="+")&&(a+=e[n++]),n>=e.length||!ae(e[n]))return null;for(;n<e.length&&ae(e[n]);)a+=e[n++];if(n<e.length&&e[n]===".")for(a+=e[n++];n<e.length&&ae(e[n]);)a+=e[n++];return!a||a==="-"||a==="+"?null:{number:a,endPos:n}}tryNumberWithTimeUnits(e,t,r,n={}){let{allowSign:a=!0,skipWhitespace:i=!1}=n,s=this.parseBaseNumber(e,t,a);if(!s)return null;let{number:l,endPos:c}=s,d=[...r,...mr.STANDARD_TIME_UNITS],u=this.tryMatchTimeUnit(e,c,d,i);return u&&(l+=u.suffix,c=u.endPos),$(l,"literal",B(t,c))}tryUrl(e,t){let r=ur(e,t);return r?$(r,"url",B(t,t+r.length)):null}tryVariableRef(e,t){if(e[t]!==":"||t+1>=e.length||!W(e[t+1]))return null;let r=t+1;for(;r<e.length&&W(e[r]);)r++;let n=e.slice(t,r);return $(n,"identifier",B(t,r))}tryOperator(e,t){let r=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(r))return $(r,"operator",B(t,t+2));let n=e[t];return["<",">","!","+","-","*","/","="].includes(n)?$(n,"operator",B(t,t+1)):["(",")","{","}",",",";",":"].includes(n)?$(n,"punctuation",B(t,t+1)):null}tryMultiCharParticle(e,t,r){for(let n of r)if(e.slice(t,t+n.length)===n)return $(n,"particle",B(t,t+n.length));return null}};pr.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 _e=pr;function Ct(o){return{stem:o,confidence:1}}function Nt(o,e,t){return t?{stem:o,confidence:e,metadata:t}:{stem:o,confidence:e}}function re(o){let e="complex";return o.startsWith("#")&&!o.includes(" ")?e="id":o.startsWith(".")&&!o.includes(" ")?e="class":o.startsWith("[")&&o.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(o)&&(e="element"),{type:"selector",value:o,selectorKind:e}}function q(o,e){let t={type:"literal",value:o};return e!==void 0?{type:"literal",value:o,dataType:e}:t}function ke(o){return Qe(o)}function Z(o){return{type:"reference",value:o}}function ie(o,e){return{type:"property-path",object:o,property:e}}function H(o,e,t){let r={kind:"command",action:o,roles:new Map(Object.entries(e))};return t!==void 0?{...r,metadata:t}:r}function me(o,e,t,r,n,a){let i=new Map;i.set("event",o);let s={kind:"event-handler",action:"on",roles:i,body:e};return t!==void 0&&(s.eventModifiers=t),r!==void 0&&(s.metadata=r),n!==void 0&&n.length>0&&(s.parameterNames=n),a!==void 0&&a.length>0&&(s.additionalEvents=a),s}function fr(o,e,t,r,n){let a={kind:"behavior",action:"behavior",roles:new Map,name:o,parameters:e,eventHandlers:t};return r!==void 0&&r.length>0&&(a.initBlock=r),n!==void 0&&(a.metadata=n),a}function hr(o,e,t,r){let n={kind:"def",action:"def",roles:new Map,name:o,parameters:e,body:t};return r!==void 0&&(n.metadata=r),n}function qe(o,e="then",t){let r={kind:"compound",action:"compound",roles:new Map,statements:o,chainType:e};return t!==void 0&&(r.metadata=t),r}function yr(o,e,t,r){let n=new Map;n.set("condition",o);let a={kind:"conditional",action:"if",roles:n,thenBranch:e};return t!==void 0&&(a.elseBranch=t),r!==void 0&&(a.metadata=r),a}function Be(o,e){return!e||e.length===0||e.includes(o)||e.includes("expression")?!0:o==="property-path"?e.some(t=>["selector","reference","expression"].includes(t)):o==="expression"?e.some(t=>["selector","reference","expression"].includes(t)):!1}var go={action:"toggle",description:"Toggle a class or attribute on/off",category:"dom-class",primaryRole:"patient",roles:[{role:"patient",description:"The class or attribute to toggle",required:!0,expectedTypes:["selector"],selectorKinds:["class","attribute"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerVariants:{ko:["\uC5D0\uC11C"]}}],errorCodes:["MISSING_ARGUMENT","NO_VALID_CLASS_NAMES","INVALID_CSS_PROPERTY"],preconditions:[{condition:"Command has at least one argument",errorCode:"MISSING_ARGUMENT",message:"toggle command requires an argument"},{condition:"Class names are valid CSS identifiers",errorCode:"NO_VALID_CLASS_NAMES",message:"toggle command: no valid class names found"}],recoveryHints:{MISSING_ARGUMENT:"Add a class selector (.classname) or attribute to toggle",NO_VALID_CLASS_NAMES:"Ensure class names start with a dot (.) and are valid CSS identifiers",INVALID_CSS_PROPERTY:"Check CSS property name syntax (use kebab-case)"}},vo={action:"add",description:"Add a class or attribute to an element",category:"dom-class",primaryRole:"patient",roles:[{role:"patient",description:"The class or attribute to add",required:!0,expectedTypes:["selector","literal"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}],errorCodes:["MISSING_ARGUMENT","NO_VALID_CLASS_NAMES","PROPERTY_REQUIRES_VALUE"],preconditions:[{condition:"Command has at least one argument",errorCode:"MISSING_ARGUMENT",message:"add command requires an argument"}],recoveryHints:{MISSING_ARGUMENT:"Add a class selector (.classname) or attribute to add",NO_VALID_CLASS_NAMES:"Ensure class names start with a dot (.) and are valid CSS identifiers",PROPERTY_REQUIRES_VALUE:"When adding a property (*prop), provide a value argument"}},ko={action:"remove",description:"Remove a class or attribute from an element",category:"dom-class",primaryRole:"patient",targetRole:"source",roles:[{role:"patient",description:"The class/attribute to remove, or the element to remove",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to remove from (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}],errorCodes:["MISSING_ARGUMENT","NO_VALID_CLASS_NAMES"],preconditions:[{condition:"Command has at least one argument",errorCode:"MISSING_ARGUMENT",message:"remove command requires an argument"}],recoveryHints:{MISSING_ARGUMENT:"Add a class selector (.classname) or attribute to remove",NO_VALID_CLASS_NAMES:"Ensure class names start with a dot (.) and are valid CSS identifiers"}},So={action:"put",description:"Put content into a target element or variable",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The content to put",required:!0,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"destination",description:"Where to put the content",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"into"},markerVariants:{en:["before","after"]},methodCarrier:"method"}],errorCodes:["MISSING_ARGUMENTS","MISSING_CONTENT","MISSING_POSITION","INVALID_POSITION","NO_TARGET","NO_ELEMENTS"],preconditions:[{condition:"Command has content and position arguments",errorCode:"MISSING_ARGUMENTS",message:"put requires arguments"},{condition:"Content to put is specified",errorCode:"MISSING_CONTENT",message:"put requires content"},{condition:"Position keyword is specified (into, before, after, etc.)",errorCode:"MISSING_POSITION",message:"put requires position keyword"}],recoveryHints:{MISSING_ARGUMENTS:"Use syntax: put <content> into/before/after <target>",MISSING_CONTENT:"Add content to put (string, element, or expression)",MISSING_POSITION:"Add position keyword: into, before, after, at start of, at end of",INVALID_POSITION:"Valid positions: into, before, after, at start of, at end of",NO_TARGET:'Ensure target element exists or use "me" reference',NO_ELEMENTS:"Check that the selector matches existing elements"}},xo={action:"set",description:"Set a property or variable to a value",category:"variable",primaryRole:"destination",roles:[{role:"destination",description:"The property or variable to set",required:!0,expectedTypes:["selector","reference","expression","property-path"],svoPosition:1,sovPosition:1,markerOverride:{en:"",ja:"\u3092",ko:"\uB97C",tr:"i",ar:"",sw:"",tl:"",bn:"\u0995\u09C7",qu:"ta",hi:"\u0915\u094B"}},{role:"patient",description:"The value to set",required:!0,expectedTypes:["literal","expression","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"to",es:"a",pt:"para",fr:"\xE0",de:"auf",id:"ke",ja:"\u306B",ko:"\uC5D0",tr:"e",ar:"\u0625\u0644\u0649",sw:"kwenye",tl:"sa",bn:"\u09A4\u09C7",qu:"man",hi:"\u092E\u0947\u0902"},markerVariants:{tr:["e","a","ye","ya"]}},{role:"scope",description:"The element(s) the attribute/property is set on (defaults to me)",required:!1,expectedTypes:["selector","reference"],svoPosition:3,sovPosition:3,markerOverride:{en:"on",es:"on",pt:"on",fr:"on",de:"on",it:"on",id:"on",ms:"on",sw:"on",tl:"on",zh:"on",vi:"on",ru:"on",uk:"on",pl:"on",th:"on",he:"on",ar:"on",ja:"on",ko:"on",tr:"on",hi:"on",bn:"on",qu:"on"}}],errorCodes:["MISSING_TARGET","INVALID_TARGET","MISSING_VALUE","INVALID_SYNTAX"],preconditions:[{condition:"Command has a target variable or property",errorCode:"MISSING_TARGET",message:"set command requires a target"},{condition:"Target is a valid variable or property reference",errorCode:"INVALID_TARGET",message:"set command target must be a string or object literal"},{condition:'Value is specified with "to" keyword',errorCode:"MISSING_VALUE",message:'set command requires a value (use "to" keyword)'}],recoveryHints:{MISSING_TARGET:"Add a target: set :variable to value OR set element.property to value",INVALID_TARGET:'Use local variable (:name), element property (el.prop), or "the X of Y" syntax',MISSING_VALUE:'Add "to <value>" to specify what to set',INVALID_SYNTAX:"Use syntax: set <target> to <value>"}},bo={action:"bind",description:"Reactively bind a variable to an element or property value",category:"variable",primaryRole:"destination",roles:[{role:"destination",description:"The variable to bind",required:!0,expectedTypes:["reference","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"",es:"",pt:"",fr:"",de:"",it:"",id:"",ms:"",vi:"",ru:"",uk:"",pl:"",th:"",zh:"",he:"",ar:"",sw:"",tl:"",ja:"\u3092",ko:"\uB97C",tr:"i",bn:"\u0995\u09C7",qu:"ta",hi:"\u0915\u094B"}},{role:"source",description:"The element or property to bind to",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:2,markerOverride:{en:"to",es:"a",pt:"para",fr:"\xE0",de:"zu",it:"in",id:"ke",ms:"ke",vi:"v\xE0o",ru:"\u0432",uk:"\u0432",pl:"do",ja:"\u306B",ko:"\uC5D0",tr:"e",ar:"\u0625\u0644\u0649",zh:"\u5230",he:"\u05DC",sw:"kwa",th:"\u0E43\u0E19",tl:"sa",bn:"\u09A4\u09C7",qu:"man",hi:"\u092E\u0947\u0902"}}],errorCodes:["MISSING_TARGET","MISSING_VALUE","INVALID_SYNTAX"],recoveryHints:{MISSING_TARGET:"Add a variable to bind: bind $name to #input",MISSING_VALUE:'Add "to <element>" to specify the binding source',INVALID_SYNTAX:"Use syntax: bind <variable> to <element>"}},wo={action:"live",description:"Reactive block: re-run the body when its dependencies change",category:"control-flow",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},To={action:"eventsource",description:"Open a Server-Sent Events stream and handle its events",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},Eo={action:"socket",description:"Open a WebSocket and handle its messages",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},Co={action:"worker",description:"Define a Web Worker with inline methods",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},No={action:"intercept",description:"Service-worker fetch interception / caching strategies",category:"async",primaryRole:"patient",hasBody:!0,bareKeyword:!0,roles:[]},Po={action:"show",description:"Make an element visible",category:"dom-visibility",primaryRole:"patient",roles:[{role:"patient",description:"The element to show",required:!0,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:!1,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},Lo={action:"hide",description:"Make an element invisible",category:"dom-visibility",primaryRole:"patient",roles:[{role:"patient",description:"The element to hide",required:!0,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:!1,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},Ro={action:"on",description:"Handle an event",category:"event",primaryRole:"event",hasBody:!0,roles:[{role:"event",description:"The event to handle",required:!0,expectedTypes:["literal"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to listen on (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Ao={action:"trigger",description:"Trigger/dispatch an event",category:"event",primaryRole:"event",roles:[{role:"event",description:"The event to trigger (supports namespaced events like draggable:start)",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Mo={action:"wait",description:"Wait for a duration or event",category:"async",primaryRole:"duration",roles:[{role:"duration",description:"Duration or event to wait for",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},Oo={action:"fetch",description:"Fetch data from a URL",category:"async",primaryRole:"source",roles:[{role:"source",description:"The URL to fetch from",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,renderOverride:{en:""}},{role:"responseType",description:"Response format (json, text, html, blob, etc.)",required:!1,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2,markerOverride:{en:"as"}},{role:"method",description:"HTTP method (GET, POST, etc.)",required:!1,expectedTypes:["literal"],svoPosition:3,sovPosition:3},{role:"destination",description:"Where to store the result",required:!1,expectedTypes:["selector","reference"],svoPosition:4,sovPosition:4}]},zo={action:"increment",description:"Increment a numeric value",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The value to increment",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to increment by (defaults to 1)",required:!1,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Vo={action:"decrement",description:"Decrement a numeric value",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The value to decrement",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to decrement by (defaults to 1)",required:!1,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Io={action:"append",description:"Append content to an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The content to append",required:!0,expectedTypes:["literal","selector","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to append to",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},_o={action:"prepend",description:"Prepend content to an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The content to prepend",required:!0,expectedTypes:["literal","selector","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to prepend to",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},qo={action:"log",description:"Log a value to the console",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The value to log",required:!0,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Bo={action:"get",description:"Get a value from a source",category:"variable",primaryRole:"source",roles:[{role:"source",description:"The source to get from",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:2,markerOverride:{en:"",es:"",pt:"",fr:"",de:"",ja:"\u3092",zh:"",ko:"\uB97C",ar:"\u0639\u0644\u0649",tr:"i",id:"",he:"\u05D0\u05EA",sw:"",tl:"",bn:"\u0995\u09C7",qu:"ta"}},{role:"destination",description:"Where to store the result (optional)",required:!1,expectedTypes:["reference"],svoPosition:2,sovPosition:1}]},$o={action:"take",description:"Take content from a source element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The class or element to take",required:!0,expectedTypes:["selector"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to take from (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Do={action:"make",description:"Create a new element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element type or selector to create",required:!0,expectedTypes:["literal","selector"],svoPosition:1,sovPosition:1}]},jo={action:"halt",description:"Halt/stop execution or event propagation",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"What to halt (event, default, bubbling, etc.)",required:!1,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},Wo={action:"settle",description:"Wait for animations/transitions to settle",category:"async",primaryRole:"patient",roles:[{role:"patient",description:"The element to settle (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},Ko={action:"throw",description:"Throw an error",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The error message or object to throw",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},Uo={action:"send",description:"Send an event to an element",category:"event",primaryRole:"event",roles:[{role:"event",description:"The event to send",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerOverride:{en:"to",ja:"\u306B",ar:"\u0625\u0644\u0649",es:"a",ko:"\uC5D0\uAC8C",zh:"\u5230",tr:"-e",pt:"para",fr:"\xE0",de:"an",id:"ke",qu:"-man",sw:"kwa"}}]},Fo={action:"if",description:"Conditional execution",category:"control-flow",primaryRole:"condition",hasBody:!0,roles:[{role:"condition",description:"The condition to evaluate",required:!0,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},Ho={action:"unless",description:"Negated conditional execution (executes when condition is false)",category:"control-flow",primaryRole:"condition",hasBody:!0,roles:[{role:"condition",description:"The condition to evaluate (body executes when false)",required:!0,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},Go={action:"else",description:"Else branch of conditional",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[]},Yo={action:"repeat",description:"Repeat a block of commands",category:"control-flow",primaryRole:"loopType",hasBody:!0,roles:[{role:"loopType",description:"Loop variant: forever, times, for, while, until, until-event",required:!0,expectedTypes:["literal"],svoPosition:0,sovPosition:0},{role:"quantity",description:"Number of times to repeat",required:!1,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"event",description:"Event to wait for (terminates loop)",required:!1,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2},{role:"source",description:"Element to listen for event on",required:!1,expectedTypes:["selector","reference"],svoPosition:3,sovPosition:3}],notes:'Can also use "repeat forever", "repeat until condition", or "repeat until event X from Y"'},Zo={action:"for",description:"Iterate over a collection",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[{role:"patient",description:"The iteration variable",required:!0,expectedTypes:["reference","expression"],svoPosition:1,sovPosition:2},{role:"source",description:"The collection to iterate over",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"in",es:"en",fr:"en",de:"in",it:"in",pt:"dentro",id:"dalam",ms:"dalam",pl:"w",ru:"\u0432",uk:"\u0443",sw:"ndani",th:"\u0E43\u0E19",vi:"trong",ar:"\u0641\u064A",tl:"sa_loob",he:"in",zh:"\u5728"}}]},Jo={action:"while",description:"Loop while condition is true",category:"control-flow",primaryRole:"condition",hasBody:!0,roles:[{role:"condition",description:"The condition to check",required:!0,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},Xo={action:"continue",description:"Continue to next loop iteration",category:"control-flow",primaryRole:"patient",roles:[]},Qo={action:"go",description:"Navigate to a URL",category:"navigation",primaryRole:"destination",roles:[{role:"destination",description:"The URL to navigate to",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to"},renderOverride:{en:""},markerOptional:{en:!0},markerVariants:{he:["\u05D0\u05EA"],zh:["\u628A"]}}]},ea={action:"transition",description:"Transition an element with animation",category:"dom-visibility",primaryRole:"patient",omitRoleVariants:["goal"],roles:[{role:"patient",description:"The property to transition (opacity, *background-color, etc.)",required:!0,expectedTypes:["literal","expression","selector"],svoPosition:1,sovPosition:2,markerOverride:{en:"",ar:"",tl:"",sw:""}},{role:"goal",description:"The target value to transition to",required:!0,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:3,markerOverride:{en:"to",ar:"\u0625\u0644\u0649",tl:"sa",sw:"kwa",bn:"\u09A4\u09C7",qu:"man",es:"a",pt:"para",fr:"\xE0",de:"zu",he:"\u05E2\u05DC",it:"in",ja:"\u306B",ko:"\uC5D0",ms:"ke",pl:"do",ru:"\u0432",th:"\u0E43\u0E19",tr:"e",uk:"\u0432",vi:"v\xE0o",zh:"\u5230",id:"ke"}},{role:"destination",description:"The target element (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:3,sovPosition:1},{role:"duration",description:"Transition duration (over 500ms, for 2 seconds)",required:!1,expectedTypes:["literal"],svoPosition:4,sovPosition:4,markerOverride:{en:"over"}},{role:"style",description:"Easing function (ease-in, linear, etc.)",required:!1,expectedTypes:["literal"],svoPosition:5,sovPosition:5}]},ta={action:"clone",description:"Clone an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to clone",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"destination",description:"Where to put the clone",required:!1,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"into"}}]},ra={action:"focus",description:"Focus an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to focus (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},na={action:"blur",description:"Remove focus from an element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to blur (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},oa={action:"empty",description:"Remove all children from an element (sets innerHTML to empty)",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to empty (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},aa={action:"open",description:"Open a dialog, details element, or popover",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to open (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:2},{role:"style",description:"Open-mode variant (modal / non-modal) for <dialog>",required:!1,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"as"}}]},ia={action:"close",description:"Close a dialog, details element, or popover",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to close (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},sa={action:"select",description:"Select the contents of a text field or DOM element",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element whose contents to select (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},la={action:"clear",description:"Clear a variable, local, or input element",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The variable or element to clear (defaults to me)",required:!1,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ca={action:"reset",description:"Reset a <form> element to its default values",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The form element to reset (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ua={action:"breakpoint",description:"Drop into the debugger",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:!0},da={action:"call",description:"Call a function",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The function to call",required:!0,expectedTypes:["expression","reference"],markerOptional:{he:!0,zh:!0},svoPosition:1,sovPosition:1}]},pa={action:"return",description:"Return a value from a function",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The value to return",required:!1,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1}]},ma={action:"js",description:"Execute raw JavaScript code",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[{role:"patient",description:"The JavaScript code to execute",required:!1,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},fa={action:"async",description:"Execute commands asynchronously",category:"async",primaryRole:"patient",hasBody:!0,roles:[]},ha={action:"tell",description:"Execute commands in context of another element",category:"control-flow",primaryRole:"destination",hasBody:!0,roles:[{role:"destination",description:"The element to tell",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:"",he:"\u05D0\u05EA",zh:"\u628A"}}]},ya={action:"default",description:"Set a default value for a variable",category:"variable",primaryRole:"destination",roles:[{role:"destination",description:"The variable to set default for",required:!0,expectedTypes:["selector","reference","expression","property-path"],svoPosition:1,sovPosition:1,markerOverride:{en:"",ar:"",tl:"",sw:"",bn:"\u0995\u09C7",qu:"ta",ja:"\u3092",ko:"\uB97C",tr:"i",hi:"\u0915\u094B",de:"",es:"",fr:"",it:"",pt:"",pl:"",ru:"",uk:"",vi:"",id:"",ms:"",th:"",zh:"\u628A",he:"\u05D0\u05EA"}},{role:"patient",description:"The default value",required:!0,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2,markerOverride:{en:"to",ar:"\u0625\u0644\u0649",tl:"sa",sw:"kwa",bn:"\u09A4\u09C7",qu:"man",ja:"\u306B",ko:"\uC5D0",tr:"e",hi:"\u092E\u0947\u0902",de:"zu",es:"a",fr:"\xE0",it:"in",pt:"para",pl:"do",ru:"\u0432",uk:"\u0432",vi:"v\xE0o",id:"ke",ms:"ke",th:"\u0E43\u0E19",zh:"\u5230",he:"\u05E2\u05DC"}}]},ga={action:"init",description:"Initialization block that runs once",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[]},va={action:"behavior",description:"Define a reusable behavior",category:"control-flow",primaryRole:"patient",hasBody:!0,roles:[{role:"patient",description:"The behavior name (PascalCase identifier)",required:!0,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},ka={action:"install",description:"Install a behavior on an element",category:"control-flow",primaryRole:"patient",roles:[{role:"patient",description:"The behavior name to install",required:!0,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"Element to install on (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Sa={action:"measure",description:"Measure element dimensions (x, y, width, height, etc.)",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"Property to measure (x, y, width, height, top, left, etc.)",required:!1,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"source",description:"Element to measure (defaults to me)",required:!1,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:2,markerOverride:{en:"of"}}]},xa={action:"swap",description:"Swap DOM content using various strategies (innerHTML, outerHTML, delete, etc.)",category:"dom-content",primaryRole:"destination",roles:[{role:"method",description:"The swap strategy (innerHTML, outerHTML, beforebegin, afterend, delete)",required:!1,expectedTypes:["literal"],svoPosition:1,sovPosition:3,markerOverride:{en:""}},{role:"destination",description:"The element to swap content in/for",required:!0,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"of",es:"",fr:"",pt:"",it:"",de:"",pl:"",ru:"",uk:"",id:"",ms:"",sw:"",th:"",vi:"",he:"\u05D0\u05EA",zh:"\u628A"}},{role:"patient",description:"The content to swap in (optional for delete)",required:!1,expectedTypes:["literal","expression","selector"],svoPosition:3,sovPosition:2,markerOverride:{en:"with",es:"con",fr:"avec",pt:"com",it:"con",de:"mit",pl:"z",ru:"\u0441",uk:"\u0437",id:"dengan",ms:"dengan",sw:"na",th:"\u0E14\u0E49\u0E27\u0E22",vi:"v\u1EDBi",he:"\u05E2\u05DD",zh:"\u7528"}}]},ba={action:"morph",description:"Morph an element into another using DOM diffing",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The element to morph",required:!0,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:""}},{role:"destination",description:"The target content/element to morph into",required:!0,expectedTypes:["literal","expression","selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"to"}}]},wa={action:"beep",description:"Debug output for expressions with type information",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The expression(s) to debug",required:!1,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ta={action:"break",description:"Exit from the current loop",category:"control-flow",primaryRole:"patient",roles:[]},Ea={action:"copy",description:"Copy text or element content to the clipboard",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The text or element to copy",required:!0,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ca={action:"exit",description:"Exit from the current event handler",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:!0},Na={action:"pick",description:"Select a random element from a collection",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The items to pick from",required:!0,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1},{role:"source",description:'The array to pick from (with "from" keyword)',required:!1,expectedTypes:["reference","expression"],svoPosition:2,sovPosition:2}]},Pa={action:"scroll",description:"Scroll the viewport to a target element",category:"navigation",primaryRole:"destination",argSkipTokens:["of","the","top","bottom","middle","center","nearest","left","right","smoothly","instantly"],roles:[{role:"destination",description:"The element to scroll to",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to"}}]},gr={en:"url",es:"url",pt:"url",fr:"url",de:"url",it:"url",ja:"url",ko:"url",zh:"url",ar:"url",he:"url",hi:"url",bn:"url",tr:"url",ru:"url",uk:"url",pl:"url",id:"url",vi:"url",th:"url",ms:"url",tl:"url",sw:"url",qu:"url"},La={en:"partials in",es:"partials in",pt:"partials in",fr:"partials in",de:"partials in",it:"partials in",ja:"partials in",ko:"partials in",zh:"partials in",ar:"partials in",he:"partials in",hi:"partials in",bn:"partials in",tr:"partials in",ru:"partials in",uk:"partials in",pl:"partials in",id:"partials in",vi:"partials in",th:"partials in",ms:"partials in",tl:"partials in",sw:"partials in",qu:"partials in"},Ra={action:"push",description:"Push a URL onto the browser history",category:"navigation",primaryRole:"patient",roles:[{role:"patient",description:"The URL to push (after the `url` keyword)",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:gr}]},Aa={action:"replace",description:"Replace the current browser history entry with a URL",category:"navigation",primaryRole:"patient",roles:[{role:"patient",description:"The URL to replace with (after the `url` keyword)",required:!0,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:gr}]},Ma={action:"process",description:"Process hx-partial markup in HTML content",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The HTML content (string, element, or response) to process",required:!0,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:La}]},Oa={action:"render",description:"Render a template with optional variables",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The template to render",required:!0,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"style",description:"Variables to pass to the template (with keyword)",required:!1,expectedTypes:["expression","reference"],svoPosition:2,sovPosition:1}]},Ne={toggle:go,add:vo,remove:ko,put:So,set:xo,show:Po,hide:Lo,on:Ro,trigger:Ao,wait:Mo,fetch:Oo,increment:zo,decrement:Vo,append:Io,prepend:_o,log:qo,get:Bo,take:$o,make:Do,halt:jo,settle:Wo,throw:Ko,send:Uo,if:Fo,unless:Ho,else:Go,repeat:Yo,for:Zo,while:Jo,continue:Xo,go:Qo,scroll:Pa,push:Ra,replace:Aa,process:Ma,transition:ea,clone:ta,focus:ra,blur:na,empty:oa,open:aa,close:ia,select:sa,clear:la,reset:ca,breakpoint:ua,call:da,return:pa,js:ma,async:fa,tell:ha,default:ya,init:ga,behavior:va,install:ka,measure:Sa,swap:xa,morph:ba,beep:wa,break:Ta,copy:Ea,exit:Ca,pick:Na,render:Oa,bind:bo,live:wo,eventsource:To,socket:Eo,worker:Co,intercept:No,compound:{action:"compound",description:"A compound node representing chained statements",primaryRole:"patient",category:"control-flow",hasBody:!0,roles:[]}};function ne(o){return Ne[o]}function ce(o,e){let t=o.possessive?.keywords?.[e];if(t)return t;let r=o.possessive?.specialForms;if(r){for(let[n,a]of Object.entries(r))if(a===e)return n}}var vr=[{lang:"es",verb:"poner",verbAlts:["pon","colocar","put"],at:"en",end:"fin",of:"de"},{lang:"fr",verb:"mettre",at:"\xE0",end:"fin",of:"de"},{lang:"pt",verb:"colocar",at:"em",end:"fim",of:"de"},{lang:"it",verb:"mettere",at:"a",end:"fine",of:"di"},{lang:"de",verb:"setzen",at:"bei",end:"ende",of:"von"},{lang:"sw",verb:"weka",at:"katika",end:"mwisho",of:"ya"},{lang:"id",verb:"taruh",verbAlts:["letakkan","masukkan","tempatkan"],at:"di",end:"akhir",of:"dari"},{lang:"ms",verb:"letak",at:"di",end:"tamat",of:"daripada"},{lang:"vi",verb:"\u0111\u1EB7t",at:"t\u1EA1i",end:"k\u1EBFt th\xFAc",of:"c\u1EE7a"},{lang:"pl",verb:"umie\u015B\u0107",at:"przy",end:"koniec",of:"z"},{lang:"ru",verb:"\u043F\u043E\u043B\u043E\u0436\u0438\u0442\u044C",at:"\u0443",end:"\u043A\u043E\u043D\u0435\u0446",of:"\u0438\u0437"},{lang:"uk",verb:"\u043F\u043E\u043A\u043B\u0430\u0441\u0442\u0438",at:"\u0432",end:"\u043A\u0456\u043D\u0435\u0446\u044C",of:"\u0437"},{lang:"th",verb:"\u0E43\u0E2A\u0E48",at:"\u0E17\u0E35\u0E48",end:"\u0E08\u0E1A",of:"\u0E02\u0E2D\u0E07"},{lang:"tl",verb:"ilagay",at:"sa",end:"wakas",of:"ng"},{lang:"ar",verb:"\u0636\u0639",at:"\u0639\u0646\u062F",end:"\u0627\u0644\u0646\u0647\u0627\u064A\u0629",of:"\u0645\u0646"},{lang:"zh",verb:"\u653E\u7F6E",verbAlts:["\u653E","\u653E\u5165"],patientPrefix:"\u628A",at:"\u5728",end:"\u7ED3\u675F",of:"\u7684"},{lang:"he",verb:"\u05E9\u05D9\u05DD",patientPrefix:"\u05D0\u05EA",at:"at",end:"\u05E1\u05D5\u05E3",of:"of"},{lang:"tr",verb:"koy",sov:!0,objMarker:"i",at:"de",end:"son",of:"nin"},{lang:"ja",verb:"\u7F6E\u304F",sov:!0,objMarker:"\u3092",at:"\u3067",end:"\u7D42\u308F\u308A",of:"\u306E"},{lang:"ko",verb:"\uB123\uB2E4",sov:!0,objMarker:"\uB97C",at:"\uC5D0",end:"\uB05D",of:"\uC758"},{lang:"hi",verb:"\u0930\u0916\u0947\u0902",verbAlts:["\u0930\u0916","\u0921\u093E\u0932\u0947\u0902","\u0921\u093E\u0932"],sov:!0,objMarker:"\u0915\u094B",at:"\u092A\u0930",end:"\u0938\u092E\u093E\u092A\u094D\u0924",of:"\u0915\u093E"},{lang:"bn",verb:"\u09B0\u09BE\u0996\u09C1\u09A8",verbAlts:["\u09B0\u09BE\u0996"],sov:!0,objMarker:"\u0995\u09C7",at:"\u098F",end:"\u09B6\u09C7\u09B7",of:"\u09B0"},{lang:"qu",verb:"churay",sov:!0,objMarker:"ta",at:"pi",end:"tukuy",of:"pa"}];function Pt(o,e,t,r){let n=vr.find(i=>i.lang===o);if(!n)return!1;let a=(i,s)=>(i??"").toLowerCase()===s.toLowerCase();return a(e,n.end)&&a(t,n.at)&&a(r,n.of)}function kr(o,e){let t=vr.find(n=>n.lang===o);if(!t)return!1;let r=e.toLowerCase();return r===t.at.toLowerCase()||r===t.of.toLowerCase()||r===t.end.toLowerCase()}var Sr=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"]),za={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"]},Lt=class{calculate(e){return this.calculateWithBreakdown(e).final}calculateWithBreakdown(e){let t=this.scoreRoleCoverage(e),r=this.scoreStemPenalty(e),n=this.scoreLanguageBoost(e),a=this.scoreLanguageAdjustment(e),i=t;return i=Math.max(.5,i+r),i=Math.min(1,i+n),i=Math.max(0,Math.min(1,i+a)),{roleCoverage:t,stemPenalty:r,languageBoost:n,languageAdjustment:a,final:i}}scoreRoleCoverage(e){let{pattern:t,captured:r}=e,n=0,a=0,i=s=>t.extraction?.[s]?.default!==void 0;for(let s of t.template.tokens)if(s.type==="role")a+=1,r.has(s.role)&&(n+=1);else if(s.type==="group")for(let l of s.tokens)l.type==="role"&&(a+=.8,r.has(l.role)?n+=.8:i(l.role)&&(n+=.8*.6));return a>0?n/a:1}scoreStemPenalty(e){let{stemMatchCount:t,totalKeywordMatches:r}=e;return t<=0||r<=0?0:-(t/r)*.15}scoreLanguageBoost(e){let{pattern:t}=e;if(t.language!=="ar")return 0;let r=t.template.tokens[0];return!r||r.type!=="literal"?0:Sr.has(r.value)||r.alternatives?.some(n=>Sr.has(n))?.15:0}scoreLanguageAdjustment(e){let{pattern:t,captured:r}=e;if(t.language!=="ar")return 0;let n=0;for(let[a,i]of r.entries()){let s=za[a];if(!s||s.length===0)continue;let l="metadata"in i?i.metadata:void 0;l&&typeof l.prepositionValue=="string"&&(s.includes(l.prepositionValue)?n+=.1:n-=.1)}return Math.max(-.1,Math.min(.1,n))}},xr=new Lt;var Va=new Set(Object.values(Ne).filter(o=>o.bareKeyword===!0).map(o=>o.action)),A=class A{constructor(e){this.matchCache=new Map;this.stemMatchCount=0;this.totalKeywordMatches=0;this.confidenceModel=e??xr}matchPattern(e,t){let r=e.mark(),n=new Map;if(this.currentProfile=V(t.language),this.currentPatternCommand=t.command,this.stemMatchCount=0,this.totalKeywordMatches=0,!this.matchTokenSequence(e,t.template.tokens,n))return e.reset(r),null;let i=this.confidenceModel.calculate({pattern:t,captured:n,stemMatchCount:this.stemMatchCount,totalKeywordMatches:this.totalKeywordMatches});return this.applyExtractionRules(t,n),{pattern:t,captured:n,consumedTokens:e.position()-r.position,confidence:i}}matchBest(e,t){this.matchCache.clear();let r=[],n=e.position();for(let i of t){let s=e.mark(),l=`${n}:${i.id}`,c;this.matchCache.has(l)?c=this.matchCache.get(l):(c=this.matchPattern(e,i),this.matchCache.set(l,c)),c&&r.push(c),e.reset(s)}if(r.length===0)return null;r.sort((i,s)=>{let l=s.pattern.priority-i.pattern.priority;return l!==0?l:s.confidence-i.confidence});let a=r[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,t,r,n){let a=t[0],i=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!i)for(;e.peek()?.kind==="conjunction";)e.advance();let s=0;for(let l=0;l<t.length;l++){let c=t[l];s>0&&c.type==="literal"&&this.tryConsumeEventSourceClause(e,r,c);let d=this.matchPatternToken(e,c,r,t[l+1]??n);if(s=c.type==="role"&&c.role==="event"?2:Math.max(0,s-1),!d){if(this.isOptional(c))continue;return!1}}return!0}tryConsumeEventSourceClause(e,t,r){if(t.has("source"))return;let n=e.peek(),a=e.peek(1);if(!n||!a||this.patternTokenWouldMatch(r,n))return;let i=this.currentProfile?.roleMarkers?.source,s=c=>{if(c.kind!=="particle"&&c.kind!=="keyword")return!1;if((c.normalized??"").toLowerCase()==="source")return!0;if(!i)return!1;let d=c.value.toLowerCase();return i.primary?.toLowerCase()===d?!0:!!i.alternatives?.some(u=>u.toLowerCase()===d)},l=i?.position;if(l!=="after"&&s(n)&&a.kind==="selector"){e.advance();let c=this.tokenToSemanticValue(e.advance());c&&t.set("source",c);return}if(l==="after"&&n.kind==="selector"&&s(a)){let c=this.tokenToSemanticValue(n);e.advance(),e.advance(),c&&t.set("source",c)}}matchPatternToken(e,t,r,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,r,n);case"group":return this.matchGroupToken(e,t,r,n);default:return!1}}matchLiteralToken(e,t){let r=e.peek();if(!r)return!1;let n=this.getMatchType(r,t.value);if(n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(let a of t.alternatives){let i=this.getMatchType(r,a);if(i!=="none")return this.totalKeywordMatches++,i==="stem"&&this.stemMatchCount++,e.advance(),!0}for(let a of[t.value,...t.alternatives??[]])for(let i of["-","_"])if(a.includes(i)&&this.tryMatchShatteredCompound(e,a,i))return this.totalKeywordMatches++,!0;return!1}tryFoldHyphenActionKeyword(e){let t=this.currentProfile;if(!t)return null;let r=e.mark(),n=[];for(;;){let i=e.peek();if(!i||i.kind!=="identifier"&&i.kind!=="keyword")break;n.push(i.value),e.advance();let s=e.peek();if(!s||s.value!=="-")break;e.advance(),n.push("-")}if(n.length<3||n[n.length-1]==="-")return e.reset(r),null;let a=n.join("").toLowerCase();for(let[i,s]of Object.entries(t.keywords))if(s.primary.toLowerCase()===a||s.alternatives?.some(l=>l.toLowerCase()===a))return q(i);return e.reset(r),null}tryMatchShatteredCompound(e,t,r){let n=t.split(r);if(n.length<2||n.some(i=>i.length===0))return!1;let a=e.mark();for(let i=0;i<n.length;i++){if(i>0){let l=e.peek();if(!l||l.value!==r)return e.reset(a),!1;e.advance()}let s=e.peek();if(!s||s.kind!=="identifier"&&s.kind!=="keyword"&&s.kind!=="particle"||s.value.toLowerCase()!==n[i].toLowerCase())return e.reset(a),!1;e.advance()}return!0}matchRoleToken(e,t,r,n){this.skipNoiseWords(e);let a=e.peek();if(!a)return t.optional||!1;if(t.role==="action"&&this.currentProfile&&e.peek(1)?.value==="-"){let g=this.tryFoldHyphenActionKeyword(e);if(g)return r.set(t.role,g),!0}if(t.role==="event"&&this.currentPatternCommand==="on"){if(!A.tokenLooksLikeEvent(a))return t.optional||!1;let g=(a.normalized??a.value).toLowerCase();if(A.POSITIONAL_OR_SCOPE_KEYWORDS.has(g)||this.currentProfile&&(ce(this.currentProfile,a.value)??ce(this.currentProfile,g))!==void 0||a.value.includes("?."))return t.optional||!1}if(t.role==="event"){let g=(a.normalized??a.value).toLowerCase();if(A.STRUCTURAL_NEVER_EVENT.has(g))return t.optional||!1}if(t.role==="duration"){let g=(a.normalized??a.value).toLowerCase();if(A.POSITIONAL_OR_SCOPE_KEYWORDS.has(g))return t.optional||!1}if(t.optional&&n===void 0&&t.role!=="event"&&t.role!=="action"&&a.kind==="keyword"&&(a.normalized??a.value).toLowerCase()in Ne)return!0;let i=this.tryMatchPositionalExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(i.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,i),!0);let s=this.tryMatchCaretScopeExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(s.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,s),!0);if(t.role!=="event"&&(!t.expectedTypes||t.expectedTypes.includes("expression"))){let g=this.tryMatchOperatorRunExpression(e);if(g)return r.set(t.role,g),!0}if(t.expectedTypes?.includes("property-path")){let g=this.tryMatchOfPossessiveExpression(e);if(g)return r.set(t.role,g),!0;let x=this.tryMatchPostNominalPossessiveExpression(e);if(x)return r.set(t.role,x),!0}let l=this.tryMatchPossessiveExpression(e);if(l)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(l.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,l),!0);let c=this.tryMatchMethodCallExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(c.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,c),!0);let u=t.role==="event"&&this.currentPatternCommand==="on"||A.DECLARATION_COMMANDS.has(this.currentPatternCommand??"")?null:this.tryMatchBareCallExpression(e);if(u)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(u.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,u),!0);let f=this.tryMatchPossessiveSelectorExpression(e);if(f)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(f.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,f),!0);let m=t.role!=="condition",p=this.tryMatchPropertyAccessExpression(e,m);if(p)return t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(p.type)&&!t.expectedTypes.includes("expression")?t.optional||!1:(r.set(t.role,p),!0);let h=this.tryMatchSelectorPropertyExpression(e);if(h)return t.expectedTypes&&t.expectedTypes.length>0&&!Be(h.type,t.expectedTypes)?t.optional||!1:(r.set(t.role,h),!0);if(a.kind==="identifier"&&a.value==="{"&&(!t.expectedTypes?.length||t.expectedTypes.includes("literal"))){let g=this.tryMatchBraceRunLiteral(e);if(g)return r.set(t.role,g),!0}let y=this.tokenToSemanticValue(a);if(!y)return t.optional||!1;if(t.expectedTypes&&t.expectedTypes.length>0&&!t.expectedTypes.includes(y.type)){let g=y.type==="selector"&&String(y.value).startsWith("@"),x=t.expectedTypes.some(T=>T==="expression"||T==="reference");if(!(g&&x))return t.optional||!1}if(r.set(t.role,y),e.advance(),t.role==="event"){let g=e.peek();g&&g.kind==="selector"&&g.value.startsWith("[")&&"value"in y&&(r.set(t.role,q(`${String(y.value)}${g.value}`)),e.advance());let x=e.peek();if(x&&(x.kind==="particle"||x.kind==="keyword")&&(x.normalized??"").toLowerCase()==="source"&&!this.patternTokenWouldMatch(n,x)){let T=e.peek(1);if(T&&(T.kind==="selector"||T.kind==="identifier")){e.advance();let C=this.tokenToSemanticValue(e.advance());C&&!r.has("source")&&r.set("source",C)}}}return!0}patternTokenWouldMatch(e,t){return e?e.type==="literal"?this.getMatchType(t,e.value)!=="none"?!0:!!e.alternatives?.some(r=>this.getMatchType(t,r)!=="none"):e.type==="group"?this.patternTokenWouldMatch(e.tokens?.[0],t):!1:!1}tryMatchPositionalExpression(e){let t=e.peek();if(!t)return null;let r=(t.normalized??t.value).toLowerCase();if(!A.POSITIONAL_KEYWORDS.has(r)&&!A.POSITIONAL_KEYWORDS.has(t.value.toLowerCase()))return null;let n=e.mark(),a=[t.normalized??t.value];e.advance();let i=e.peek();if(!i||i.kind!=="selector")return e.reset(n),null;a.push(i.value),e.advance();let s=0;for(;s++<8;){let d=e.peek();if(d&&d.kind==="selector"&&d.value.startsWith("."))a.push(d.value),e.advance();else break}let l=e.peek(),c=e.peek(1);return l&&c&&c.kind==="selector"&&(l.kind==="keyword"||l.kind==="particle"||l.kind==="identifier")&&!A.POSITIONAL_KEYWORDS.has((l.normalized??l.value).toLowerCase())&&!A.COMMAND_ACTION_KEYWORDS.has((l.normalized??l.value).toLowerCase())&&(a.push(l.normalized??l.value,c.value),e.advance(),e.advance()),{type:"expression",raw:a.join(" ")}}tryMatchCaretScopeExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"||!t.value.startsWith("^"))return null;let r=e.peek(1),n=e.peek(2),a=(r?.normalized??"").toLowerCase(),i=!!r&&(r.value.toLowerCase()==="on"||a==="destination"||a==="on");return!r||!n||n.kind!=="selector"||!i?null:(e.advance(),e.advance(),e.advance(),{type:"expression",raw:`${t.value} on ${n.value}`})}isOfPossessiveMarker(e){let t=e.value.toLowerCase(),r=(e.normalized??"").toLowerCase();if(t==="of"||t==="ng"||r==="of"||r==="source")return!0;let n=this.currentProfile?.code?A.OF_POSSESSIVE_MARKERS[this.currentProfile.code]:void 0;return!!n&&n.has(t)}tryMatchOperatorRunExpression(e){let t=e.mark(),r=e.position();if(!this.tryConsumeRunOperand(e))return e.reset(t),null;let n=1;for(;;){let i=e.peek();if(!i||!A.RUN_OPERATORS.has(i.value))break;let s=e.mark();if(e.advance(),!this.tryConsumeRunOperand(e)){e.reset(s);break}n++}if(n<2)return e.reset(t),null;let a=e.tokens.slice(r,e.position()).map(i=>i.value).join(" ");return{type:"expression",raw:a,value:a}}tryConsumeRunOperand(e){let t=e.peek();if(!t)return!1;if(t.value==="("){let r=e.mark(),n=0;for(;!e.isAtEnd();){let a=e.advance();if(a.value==="(")n++;else if(a.value===")"&&(n--,n===0))return!0}return e.reset(r),!1}return this.tryMatchPossessiveExpression(e)?!0:(t.kind==="literal"||t.kind==="identifier"||t.kind==="selector"||t.kind==="keyword")&&!A.RUN_OPERATORS.has(t.value)&&t.value!==")"?(e.advance(),!0):!1}tryMatchOfPossessiveExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||!this.isOfPossessiveMarker(n))return e.reset(r),null;e.advance();let a=e.peek();return!a||a.kind!=="selector"?(e.reset(r),null):(e.advance(),ie(re(a.value),t.value))}tryMatchPossessiveExpression(e){let t=e.peek();if(!t||!this.currentProfile)return null;let r=[t.value,t.normalized].filter(Boolean),n;for(let l of r)if(n=ce(this.currentProfile,l)??ce(this.currentProfile,l.toLowerCase()),n)break;if(!n)return null;let a=e.mark();e.advance();let i=this.currentProfile.possessive?.connectors;if(i&&i.length>0){let l=e.peek();if(l){let c=l.value.toLowerCase(),d=(l.normalized??"").toLowerCase();i.some(u=>u.toLowerCase()===c||u.toLowerCase()===d)&&e.advance()}}let s=e.peek();if(!s||kr(this.currentProfile.code,s.value))return e.reset(a),null;if(s.kind==="identifier"||s.kind==="keyword"&&!this.isStructuralKeyword(s.value)&&!(s.normalized&&this.isStructuralKeyword(s.normalized))&&!(s.normalized&&this.isRoleMarkerConcept(s.normalized))||s.kind==="selector"&&s.value.startsWith("*")||s.kind==="selector"&&s.value.startsWith("@")||s.kind==="selector"&&s.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s.value)){e.advance();let l=s.value;s.kind==="selector"&&l.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(l)&&(l=l.substring(1));let c=l;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)c+=e.peek().value,e.advance();let d=e.peek();if(d&&d.value.startsWith("(")){let u="",f=0,m=0;for(;!e.isAtEnd()&&m++<A.MAX_METHOD_ARGS+2;){let p=e.peek();if(!p)break;u+=p.value,e.advance();for(let h of p.value)h==="("?f++:h===")"&&f--;if(f<=0)break}c+=u}return ie(Z(n),c)}return e.reset(a),null}tryMatchPostNominalPossessiveExpression(e){if(!this.currentProfile||this.currentProfile.possessive?.markerPosition!=="after-object")return null;let t=u=>{for(let f of[u.value,u.normalized].filter(Boolean))if(ce(this.currentProfile,f)??ce(this.currentProfile,f.toLowerCase()))return!0;return!1},r=e.peek();if(!r)return null;let n=r.kind==="selector"&&r.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(r.value);if(!(r.kind==="identifier"&&!this.isStructuralKeyword(r.value)&&!(r.normalized&&this.isStructuralKeyword(r.normalized))&&!(r.normalized&&this.isRoleMarkerConcept(r.normalized))||r.kind==="selector"&&(r.value.startsWith("*")||r.value.startsWith("@"))||n)||t(r))return null;let i=e.mark(),s=r.value;n&&(s=s.substring(1)),e.advance();let l=s;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)l+=e.peek().value,e.advance();let c=e.peek();if(!c)return e.reset(i),null;let d;for(let u of[c.value,c.normalized].filter(Boolean))if(d=ce(this.currentProfile,u)??ce(this.currentProfile,u.toLowerCase()),d)break;return d?(e.advance(),ie(Z(d),l)):(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())}isRoleMarkerConcept(e){return new Set(["destination","source","patient","object","event","eventmarker","manner","instrument"]).has(e.toLowerCase())}static tokenLooksLikeEvent(e){if(e.kind==="selector"||e.kind==="url"||e.kind==="literal")return!1;let t=e.value;if(/[/#@*]/.test(t)||t.startsWith('"')||t.startsWith("'")||t.startsWith("`"))return!1;let r=e.normalized?.toLowerCase();return!(r&&Va.has(r))}tryMatchBraceRunLiteral(e){let t=e.peek();if(!t||t.kind!=="identifier"||t.value!=="{")return null;let r=e.mark();e.advance();let n=["{"],a=1,i=0;for(;!e.isAtEnd()&&i++<A.MAX_BRACE_RUN_TOKENS;){let s=e.advance();if(!s)break;if(s.value==="{")a++;else if(s.value==="}"&&(a--,a===0))return n.push("}"),q(n.join(" "));n.push(s.value)}return e.reset(r),null}tryMatchBareCallExpression(e){let t=e.peek();if(!t||t.kind!=="identifier"||!/^[A-Za-z_][\w$]*$/.test(t.value))return null;let r=e.peek(1);if(!r||r.value!=="(")return null;let n=e.mark();e.advance(),e.advance();let a=[],i=!1,s=0;for(;!e.isAtEnd()&&s++<A.MAX_METHOD_ARGS+2;){let l=e.peek();if(!l)break;if(l.value===")"){e.advance(),i=!0;break}if(l.value===","){e.advance();continue}a.push(l.value),e.advance()}return i?{type:"expression",raw:`${t.value}(${a.join(", ")})`}:(e.reset(n),null)}tryMatchMethodCallExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(r),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(r),null;e.advance();let i=e.peek();if(!i||i.kind!=="punctuation"||i.value!=="(")return e.reset(r),null;e.advance();let s=[];for(;!e.isAtEnd()&&s.length<A.MAX_METHOD_ARGS;){let c=e.peek();if(!c)break;if(c.kind==="punctuation"&&c.value===")"){e.advance();break}if(c.kind==="punctuation"&&c.value===","){e.advance();continue}s.push(c.value),e.advance()}return{type:"expression",raw:`${t.value}.${a.value}(${s.join(", ")})`}}tryMatchPropertyAccessExpression(e,t=!0){let r=e.peek();if(!r||r.kind!=="identifier"&&r.kind!=="keyword")return null;let n=e.mark();e.advance();let a=r.value.toLowerCase(),i=e.peek();if((r.kind==="identifier"||A.PROPERTY_ACCESS_BASES.has(a))&&i&&i.kind==="selector"&&/^\.[a-zA-Z_]/.test(i.value)){let m=r.value,p=[],h=0;for(;h<A.MAX_PROPERTY_DEPTH;){let x=e.peek();if(x&&x.kind==="selector"&&/^\.[a-zA-Z_]/.test(x.value))m+=`.${x.value.slice(1)}`,p.push(x.value.slice(1)),e.advance(),h++;else break}let y=e.peek(),g=!!y&&y.value.startsWith("(");if(t&&!g&&p.length>0&&ke(a))return ie(Z(a),p.join("."));if(g){let x=e.mark(),T=[],C=0,S=!1;for(;!e.isAtEnd();){let k=e.peek();if(!k)break;if(k.value==="(")C++;else if(k.value===")"){if(T.push(k.value),e.advance(),C--,C===0&&(S=!0),S)break;continue}T.push(k.value),e.advance()}S?m+=T.join(""):e.reset(x)}return{type:"expression",raw:m}}let s=e.peek();if(!s||s.kind!=="operator"||s.value!==".")return e.reset(n),null;e.advance();let l=e.peek();if(!l||l.kind!=="identifier")return e.reset(n),null;e.advance();let c=`${r.value}.${l.value}`,d=1;for(;!e.isAtEnd()&&d<A.MAX_PROPERTY_DEPTH;){let m=e.peek();if(!m||m.kind!=="operator"||m.value!==".")break;e.advance();let p=e.peek();if(!p||p.kind!=="identifier")break;e.advance(),c+=`.${p.value}`,d++}let u=e.peek();if(u&&u.kind==="punctuation"&&u.value==="("){e.advance();let m=[],p=0;for(;!e.isAtEnd()&&m.length<A.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}m.push(y.value),e.advance()}return{type:"expression",raw:`${c}(${m.join(", ")})`}}let f=r.value.toLowerCase();if(t&&ke(f)){let m=c.split(".").slice(1).join(".");return ie(Z(f),m)}return{type:"expression",raw:c}}tryMatchPossessiveSelectorExpression(e){let t=e.peek();if(!t||t.kind!=="selector")return null;let r=e.mark();e.advance();let n=e.peek(),a=this.currentProfile?.possessive?.marker?.replace(/^-/,""),i=!!n&&n.kind==="punctuation"&&n.value==="'s",s=!!n&&n.value==="'"&&(e.peek(1)?.value??"").toLowerCase()==="s",l=(()=>{if(!this.currentPatternCommand||(n?.normalized??"").toLowerCase()!=="source")return!1;let f=Ne[this.currentPatternCommand];return!!f&&f.roles.some(m=>m.role==="source")})(),c=!!n&&!!a&&a!=="'s"&&n.value===a&&(n.kind==="particle"||n.kind==="punctuation")&&!l;if(!i&&!c&&!s)return e.reset(r),null;e.advance(),s&&e.advance();let d=e.peek();return!d||!(d.kind==="identifier"||(i||s)&&(d.kind==="selector"||d.kind==="keyword"))?(e.reset(r),null):(e.advance(),ie(re(t.value),d.value))}tryMatchSelectorPropertyExpression(e){let t=e.peek();if(!t||t.kind!=="selector"||!t.value.startsWith("#"))return null;let r=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(r),null;let a=e.peek(1);a&&a.kind,e.advance();let i=n.value.slice(1);return ie(re(t.value),i)}matchGroupToken(e,t,r,n){let a=e.mark(),i=new Set(r.keys());if(!this.matchTokenSequence(e,t.tokens,r,n)){e.reset(a);for(let l of r.keys())i.has(l)||r.delete(l);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 re(e.value);case"literal":return this.parseLiteralValue(e.value);case"keyword":let t=(e.normalized||e.value).toLowerCase();return ke(t)?Z(t):q(e.normalized||e.value);case"identifier":if(e.value.startsWith("@"))return re(e.value);if(e.value.startsWith(":")||e.value.startsWith("$"))return Z(e.value);let r=e.value.toLowerCase();return ke(r)?Z(r):{type:"expression",raw:e.value};case"url":return q(e.value,"string");default:return null}}parseLiteralValue(e){if(e.startsWith('"')||e.startsWith("'")||e.startsWith("`")||e.startsWith("\u300C")){let n=e.slice(1,-1);return q(n,"string")}if(e==="true")return q(!0,"boolean");if(e==="false")return q(!1,"boolean");let t=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(t){let n=parseFloat(t[1]);return t[2]?q(e,"duration"):q(n,"number")}let r=parseFloat(e);return isNaN(r)?q(e,"string"):q(r,"number")}applyExtractionRules(e,t){for(let[r,n]of Object.entries(e.extraction))t.has(r)||(n.value!==void 0?t.set(r,{type:"literal",value:n.value}):n.default&&t.set(r,n.default))}isOptional(e){return e.type!=="literal"&&e.optional===!0}skipNoiseWords(e){let t=e.peek();if(!t)return;let r=t.value.toLowerCase();if(A.ENGLISH_NOISE_WORDS.has(r)){let n=e.mark();e.advance();let a=e.peek();if(a&&(a.kind==="selector"||a.kind==="identifier"))return;let i=e.peek(1);if(a&&a.kind==="keyword"&&i&&i.kind==="selector"&&/^\.[a-zA-Z_]/.test(i.value))return;let s=a?(a.normalized??a.value).toLowerCase():"";if(a&&A.POSITIONAL_OR_SCOPE_KEYWORDS.has(s))return;let l=e.peek(1),c=l?(l.normalized??l.value).toLowerCase():"",d=this.currentProfile?.wordOrder!=="SOV"&&A.COMMAND_ACTION_KEYWORDS.has(c),u=!l||l.kind==="particle"||A.CLAUSE_BOUNDARY_KEYWORDS.has(c)||d;if(a&&a.kind==="keyword"&&this.currentProfile?.code!=="en"&&ke(s)&&u||a&&a.kind==="keyword"&&this.currentProfile?.code==="en"&&ke(s))return;e.reset(n)}r==="class"&&e.advance()}extractEventModifiers(e){let t={},r=!1;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(r=!0,a.modifierName){case"once":t.once=!0;break;case"debounce":typeof a.value=="number"&&(t.debounce=a.value);break;case"throttle":typeof a.value=="number"&&(t.throttle=a.value);break;case"queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(t.queue=a.value);break}e.advance()}return r?t:void 0}};A.POSITIONAL_KEYWORDS=new Set(["first","last","next","previous","random","closest"]),A.POSITIONAL_OR_SCOPE_KEYWORDS=new Set(["first","last","next","previous","random","closest","parent"]),A.STRUCTURAL_NEVER_EVENT=new Set(["if","unless","else","end","then"]),A.PROPERTY_ACCESS_BASES=new Set(["it","me","you","my","its","your","event","result","target","detail","body","window","document","self","this"]),A.COMMAND_ACTION_KEYWORDS=new Set(Object.keys(Ne).map(e=>e.toLowerCase())),A.CLAUSE_BOUNDARY_KEYWORDS=new Set(["then","and","or","end","else"]),A.OF_POSSESSIVE_MARKERS={ms:new Set(["daripada"]),sw:new Set(["ya"]),vi:new Set(["c\u1EE7a"]),zh:new Set(["\u7684"]),it:new Set(["di"]),pl:new Set(["z"]),uk:new Set(["\u0437"]),th:new Set(["\u0E02\u0E2D\u0E07"]),ja:new Set(["\u306E"]),ko:new Set(["\uC758"]),bn:new Set(["\u09B0"]),hi:new Set(["\u0915\u093E"]),qu:new Set(["pa"]),tr:new Set(["nin"])},A.RUN_OPERATORS=new Set(["+","-","*","/"]),A.MAX_BRACE_RUN_TOKENS=64,A.MAX_PROPERTY_DEPTH=10,A.MAX_METHOD_ARGS=20,A.DECLARATION_COMMANDS=new Set(["behavior","def","install"]),A.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Rt=A,se=new Rt;var Ia=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"],ot=class{constructor(e=Ia){this.name="operator";this.operators=[...e].sort((t,r)=>r.length-t.length)}canExtract(e,t){return this.operators.some(r=>e.startsWith(r,t))}extract(e,t){for(let r of this.operators)if(e.startsWith(r,t))return{value:r,length:r.length};return null}},_a="()[]{},:;",at=class{constructor(e=_a){this.punctuation=e;this.name="punctuation"}canExtract(e,t){return this.punctuation.includes(e[t])}extract(e,t){let r=e[t];return this.punctuation.includes(r)?{value:r,length:1}:null}};function At(o,e){let t=o[e];if(t==="#"){let r=o.slice(e).match(/^#[a-zA-Z_][\w-]*/);return r?r[0]:null}if(t==="."){let r=o.slice(e).match(/^\.\{[a-zA-Z_$][\w$]*\}/);if(r)return r[0];let n=o.slice(e).match(/^\.[a-zA-Z_][\w-]*/);return n?n[0]:null}if(t==="@"){let r=o.slice(e).match(/^@[a-zA-Z_][\w-]*/);return r?r[0]:null}if(t==="*"){let r=o.slice(e).match(/^\*(?:--)?[a-zA-Z_][\w-]*/);return r?r[0]:null}if(t==="["){let r=0,n=e;for(;n<o.length;){if(o[n]==="["&&r++,o[n]==="]"&&(r--,r===0))return o.slice(e,n+1);n++}return null}if(t==="<"){let r=o.slice(e).match(/^<(?=[\w.#[])[\w-]*(?:[#.][\w-]+|\[[^\]]+\])*\s*\/>/);return r?r[0]:null}return null}var $e=class{constructor(){this.name="css-selector"}canExtract(e,t){let r=e[t];return r==="#"||r==="."||r==="["||r==="<"?!0:r==="@"||r==="*"?At(e,t)!==null:!1}extract(e,t){let r=At(e,t);return r?{value:r,length:r.length,metadata:{type:"css-selector"}}:null}};var De=class{constructor(){this.name="event-modifier"}canExtract(e,t){if(e[t]!==".")return!1;let r=e.slice(t);return/^\.(once|prevent|stop|debounce|throttle|queue)/.test(r)}extract(e,t){let r=e.slice(t).match(/^\.(?:once|prevent|stop|debounce|throttle|queue)(?:\(([^)]+)\))?/);if(!r)return null;let n=r[0],a=n.slice(1).split("(")[0],i=r[1];return{value:n,length:n.length,metadata:{modifierName:a,value:i?a==="queue"?i:parseInt(i,10):void 0}}}};function br(o,e){let t=o.slice(e);if(t.startsWith("http://")||t.startsWith("https://")){let r=t.match(/^https?:\/\/[^\s]*/);return r?r[0]:null}if(t.startsWith("//")){let r=t.match(/^\/\/[^\s]*/);return r?r[0]:null}if(t.startsWith("./")||t.startsWith("../")){let r=t.match(/^\.\.?\/[^\s]*/);return r?r[0]:null}if(t.startsWith("/")){let r=t.match(/^\/[^\s]*/);return r?r[0]:null}return null}var je=class{constructor(){this.name="url"}canExtract(e,t){let r=e.slice(t);return r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||r.startsWith("./")||r.startsWith("../")||r.startsWith("/")}extract(e,t){let r=br(e,t);return r?{value:r,length:r.length,metadata:{type:"url"}}:null}};var We=class{constructor(){this.name="variable-ref"}canExtract(e,t){let r=e[t];return(r===":"||r==="$"||r==="^")&&t+1<e.length&&/[a-zA-Z_]/.test(e[t+1])}extract(e,t){if(!this.canExtract(e,t))return null;let r=1;for(;t+r<e.length&&/[a-zA-Z0-9_]/.test(e[t+r]);)r++;return{value:e.substring(t,t+r),length:r,metadata:{type:"variable-reference"}}}};function Ke(o){let e=o.charCodeAt(0);return e>=65&&e<=90||e>=97&&e<=122?!0:o==="\xF1"||o==="\xD1"||o==="'"||o==="\u2019"}var Mt=new Set(["-ta","-man","-manta","-pi","-wan","-paq","-kama","-rayku","-hina","ta","man","manta","pi","wan","paq","kama","hina","pa"]),wr=new Set(["kama","hina","rayku","paq"]),qa=new Set([...Mt,...wr].map(o=>o.startsWith("-")?o.slice(1):o));function Ba(o,e){let t=o.slice(e);for(let r of qa){if(!t.startsWith(r))continue;let n=o[e+r.length];if(n===void 0||!Ke(n))return!0}return!1}var Ot=class{constructor(){this.name="quechua-keyword"}setContext(e){this.context=e}canExtract(e,t){return Ke(e[t])?!0:this.isHyphenatedSuffix(e,t)!==null}isHyphenatedSuffix(e,t){if(e[t]!=="-")return null;let r=e.slice(t).match(/^-([a-zñ'’]+)/i);return r&&Mt.has(`-${r[1].toLowerCase()}`)?r[1]:null}extract(e,t){if(!this.context)throw new Error("QuechuaKeywordExtractor: context not set");let r=t,n=this.isHyphenatedSuffix(e,t);if(n!==null)return{value:n,length:n.length+1,metadata:{suffixValue:n.toLowerCase()}};let a=12;for(let u=Math.min(a,e.length-r);u>=2;u--){let f=e.slice(r,r+u),m=e[r+u];if(m!==void 0&&Ke(m))continue;let p=!0;for(let y=0;y<f.length;y++)if(!Ke(f[y])){p=!1;break}if(!p)continue;let h=this.context.lookupKeyword(f);if(h)return{value:f,length:u,metadata:{normalized:h.normalized!==h.native?h.normalized:void 0}};if(this.context.normalizer){let y=this.context.normalizer.normalize(f);if(y.stem!==f&&y.confidence>=.7){let g=this.context.lookupKeyword(y.stem);if(g)return{value:f,length:u,metadata:{normalized:g.normalized}}}}}let i="",s=t;for(;s<e.length&&Ke(e[s])&&!(i.length>0&&Ba(e,s));)i+=e[s],s++;if(!i)return null;if(Mt.has(i.toLowerCase()))return{value:i,length:s-r,metadata:{suffixValue:i.toLowerCase()}};if(wr.has(i.toLowerCase()))return{value:i,length:s-r,metadata:{postpositionValue:i.toLowerCase()}};let l=this.context.lookupKeyword(i),c=l&&l.normalized!==l.native?l.normalized:void 0,d;if(!l&&this.context.normalizer){let u=this.context.normalizer.normalize(i);if(u.stem!==i&&u.confidence>=.7){let f=this.context.lookupKeyword(u.stem);f&&(d=f.normalized)}}return{value:i,length:s-r,metadata:{normalized:c||d}}}};function Tr(){return new Ot}function Er(){return[new je,new De,new We,new $e]}function $a(o){let e=o.charCodeAt(0);return e>=65&&e<=90||e>=97&&e<=122?!0:o==="\xF1"||o==="\xD1"||o==="'"||o==="'"}function Da(o){for(let e of o)if($a(e))return!0;return!1}var ja=[{pattern:"shankichik",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"shaniku",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"shanki",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shani",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shanchik",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shanku",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"shan",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"rqankichik",confidence:.8,conjugationType:"past",minStemLength:2},{pattern:"rqaniku",confidence:.8,conjugationType:"past",minStemLength:2},{pattern:"rqanki",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqani",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqanchik",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqanku",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"rqan",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"nqankichik",confidence:.8,conjugationType:"future",minStemLength:2},{pattern:"nqaniku",confidence:.8,conjugationType:"future",minStemLength:2},{pattern:"nqanki",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqani",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqanchik",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqanku",confidence:.82,conjugationType:"future",minStemLength:2},{pattern:"nqa",confidence:.85,conjugationType:"future",minStemLength:2},{pattern:"chikuy",confidence:.8,conjugationType:"compound",minStemLength:2},{pattern:"chiku",confidence:.82,conjugationType:"compound",minStemLength:2},{pattern:"chiy",confidence:.85,conjugationType:"causative",minStemLength:2,replacement:"y"},{pattern:"chiq",confidence:.85,conjugationType:"causative",minStemLength:2,replacement:"y"},{pattern:"chi",confidence:.82,conjugationType:"causative",minStemLength:2},{pattern:"kuy",confidence:.82,conjugationType:"reflexive",minStemLength:2},{pattern:"rqa",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"rqan",confidence:.85,conjugationType:"past",minStemLength:2},{pattern:"sha",confidence:.82,conjugationType:"progressive",minStemLength:2},{pattern:"na",confidence:.85,conjugationType:"obligation",minStemLength:2},{pattern:"manmi",confidence:.8,conjugationType:"potential",minStemLength:2},{pattern:"man",confidence:.8,conjugationType:"potential",minStemLength:2},{pattern:"nkichik",confidence:.8,conjugationType:"present",minStemLength:2},{pattern:"niku",confidence:.8,conjugationType:"present",minStemLength:2},{pattern:"nki",confidence:.82,conjugationType:"present",minStemLength:2},{pattern:"nchik",confidence:.82,conjugationType:"present",minStemLength:2},{pattern:"nku",confidence:.82,conjugationType:"present",minStemLength:2},{pattern:"ni",confidence:.85,conjugationType:"present",minStemLength:2},{pattern:"ku",confidence:.82,conjugationType:"reflexive",minStemLength:2},{pattern:"ychik",confidence:.82,conjugationType:"imperative",minStemLength:2},{pattern:"y",confidence:.9,conjugationType:"dictionary",minStemLength:2},{pattern:"sqa",confidence:.82,conjugationType:"passive",minStemLength:2},{pattern:"ska",confidence:.82,conjugationType:"passive",minStemLength:2},{pattern:"kama",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"manta",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"man",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"wan",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"pi",confidence:.7,conjugationType:"dictionary",minStemLength:2},{pattern:"ta",confidence:.7,conjugationType:"dictionary",minStemLength:2}],zt=class{constructor(){this.language="qu"}isNormalizable(e){return!(!Da(e)||e.length<3||!/[aiu]/.test(e.toLowerCase()))}normalize(e){let t=e.toLowerCase();for(let r of ja)if(t.endsWith(r.pattern)){let n=t.slice(0,-r.pattern.length);r.replacement&&!n.endsWith(r.replacement)&&(n=n+r.replacement);let a=r.minStemLength??2;if(n.length<a||!this.isValidStem(n))continue;let i={removedSuffixes:[r.pattern]};return r.conjugationType&&(i.conjugationType=r.conjugationType),Nt(n,r.confidence,i)}return Ct(e)}isValidStem(e){return!(e.length<2||!/[aeiou]/.test(e)||new Set(["ta","man","pi","wan","pa","kama","hina"]).has(e))}},Cr=new zt;var Vt=class{constructor(){this.name="quechua-string-literal"}canExtract(e,t){return e[t]==='"'||e[t]==="'"}extract(e,t){let r=e[t],n=r,a=t+1;for(;a<e.length;){let i=e[a];if(i===r)return n+=i,{value:n,length:n.length};i==="\\"&&a+1<e.length?(n+=i+e[a+1],a+=2):(n+=i,a++)}return null}},Wa=new Set(["-ta","-man","-manta","-pi","-wan","-paq","-kama","-rayku","-hina","ta","man","manta","pi","wan","paq","kama","hina","pa"]),Ka=[{native:"cheqaq",normalized:"true"},{native:"ar\xED",normalized:"true"},{native:"ari",normalized:"true"},{native:"manan",normalized:"false"},{native:"mana",normalized:"false"},{native:"ch'usaq",normalized:"null"},{native:"chusaq",normalized:"null"},{native:"mana riqsisqa",normalized:"undefined"},{native:"\xF1awpaqpi",normalized:"before"},{native:"nawpaqpi",normalized:"before"},{native:"qhepapi",normalized:"after"},{native:"qhipapi",normalized:"after"},{native:"\xF1awpaq",normalized:"first"},{native:"nawpaq",normalized:"first"},{native:"qhipa",normalized:"last"},{native:"hamuq",normalized:"next"},{native:"qhipantin",normalized:"next"},{native:"\xF1awpaqnin",normalized:"previous"},{native:"\xF1awpaq kaq",normalized:"previous"},{native:"\xF1awpaq_kaq",normalized:"previous"},{native:"kaylla",normalized:"closest"},{native:"qaylla",normalized:"closest"},{native:"tayta",normalized:"parent"},{native:"llikllay",normalized:"click"},{native:"\xF1itiy",normalized:"click"},{native:"\xF1it'iy",normalized:"click"},{native:"click",normalized:"click"},{native:"yaykuy",normalized:"input"},{native:"llave uray",normalized:"keydown"},{native:"llave hawa",normalized:"keyup"},{native:"mausiri yayku",normalized:"mouseover"},{native:"mausiri lluqsi",normalized:"mouseout"},{native:"rat\xF1itiy",normalized:"mousedown"},{native:"rathuqariy",normalized:"mouseup"},{native:"qhaway",normalized:"focus"},{native:"mana qhaway",normalized:"blur"},{native:"kargay",normalized:"load"},{native:"muyuy",normalized:"scroll"},{native:"\xF1uqa",normalized:"me"},{native:"nuqa",normalized:"me"},{native:"\xF1uqap",normalized:"my"},{native:"nuqap",normalized:"my"},{native:"chay",normalized:"it"},{native:"chaymi",normalized:"it"},{native:"lluqsiy",normalized:"result"},{native:"ruway",normalized:"event"},{native:"maypi",normalized:"target"},{native:"sikundu",normalized:"s"},{native:"segundu",normalized:"s"},{native:"waranqa sikundu",normalized:"ms"},{native:"minutu",normalized:"m"},{native:"ura",normalized:"h"},{native:"hora",normalized:"h"},{native:"chaypim",normalized:"on"},{native:"kaypi",normalized:"on"},{native:"chayqa",normalized:"then"},{native:"chaymanta",normalized:"then"},{native:"chaymantataq",normalized:"then"},{native:"hinaspa",normalized:"then"},{native:"tukukuy",normalized:"end"},{native:"puchukay",normalized:"end"},{native:"kaykama",normalized:"until"},{native:"yapay",normalized:"add"},{native:"t'ikray",normalized:"toggle"},{native:"tikray",normalized:"toggle"},{native:"qhawachiy",normalized:"focus"},{native:"mana qhawachiy",normalized:"blur"},{native:"-manta",normalized:"from"}],It=class extends _e{constructor(){super();this.language="qu";this.direction="ltr";this.initializeKeywordsFromProfile(ve,Ka),this.setNormalizer(Cr),this.registerExtractors(Er()),this.registerExtractor(new Vt),this.registerExtractor(new Et),this.registerExtractor(Tr()),this.registerExtractor(new ot),this.registerExtractor(new at)}classifyToken(t){let r=t.toLowerCase();return Wa.has(r)?"particle":this.isKeyword(r)?"keyword":t.startsWith("/")||t.startsWith("./")||t.startsWith("../")||t.startsWith("http")?"url":/^\.(once|prevent|stop|debounce|throttle|queue)(\(.*\))?$/.test(t)?"event-modifier":t.startsWith("#")||t.startsWith(".")||t.startsWith("[")||t.startsWith("*")||t.startsWith("<")?"selector":t.startsWith('"')||/^\d/.test(t)?"literal":["==","!=","<=",">=","<",">","&&","||","!"].includes(t)?"operator":"identifier"}},it=new It;function G(o,e){return er(o,e)}function st(){return kt()}var ct=["if","unless","repeat","for","while"];function le(o,e){let t=new Set([e]),n=V(o)?.keywords?.[e];if(n){n.primary&&t.add(n.primary.toLowerCase());for(let a of n.alternatives??[])t.add(a.toLowerCase())}return t}function te(o,e){return e.has(o.value.toLowerCase())?!0:o.normalized?e.has(o.normalized.toLowerCase()):!1}var Fa=new Set(ct);function qt(o,e){let t=o.normalized?.toLowerCase();return t?Fa.has(t):e.some(r=>te(o,r))}var Nr=new Set(["me","it","you","the","body","window","document","its","event","result","target","self","this","them","parent","next","previous","closest","first","last"]),Ha=new Set(["destination","source","style","patient","on","from","to"]);function Ga(o){if(!o||o.kind==="selector")return!1;let e=(o.normalized??o.value).toLowerCase(),t=o.value.toLowerCase();return!(Nr.has(e)||Nr.has(t)||Ha.has(e))}var Pr=new Set(["ja","ko"]);function _t(o){let e=new Set;o?.primary&&e.add(o.primary.toLowerCase());for(let t of o?.alternatives??[])e.add(t.toLowerCase());return e}function Rr(o,e){let t=[],r=e.position.end,n=o.slice(e.position.end).match(/^\s*\(([^)]*)\)/);if(n){r=e.position.end+n[0].length;for(let a of n[1].split(/[,،、]/)){let i=a.trim();i&&t.push(i)}}return{parameters:t,headerEnd:r}}function Ar(o,e,t){let r=e+1;if(r>=o.length)return-1;let n=_t(V(t)?.roleMarkers?.patient);return n.size>0&&te(o[r],n)&&r++,r<o.length?r:-1}function Mr(o,e,t){if(!V(e))return null;let r=le(e,"behavior"),n=le(e,"def"),a=o.toLowerCase(),i=[...r].some(d=>a.includes(d)),s=/\bdef\b/.test(a)||[...n].some(d=>d!=="def"&&a.includes(d));if(!i&&!s)return null;let l=G(o,e).tokens;if(l.length<2)return null;if(te(l[0],r))return Lr(o,e,l,t,0);let c=l.findIndex((d,u)=>u>0&&te(d,r));return c>0&&/^[A-Z][A-Za-z0-9_]*$/.test(l[0].value)?Lr(o,e,l,t,c):te(l[0],n)?Ya(o,e,l,t):null}function Or(o,e,t){let r=V(e);if(!r)return null;let n=r.wordOrder!=="SOV",a=Pr.has(e)?_t(r.roleMarkers?.event):new Set,i=Pr.has(e)?_t(r.keywords?.on):new Set,s=a.size>0&&i.size>0,l=le(e,"end"),c=le(e,"on"),d=o.toLowerCase(),u=[...l].some(k=>d.includes(k)),f=(n||s)&&(()=>{let k=0;for(let E of c)if(E){for(let v=d.indexOf(E);v>=0;v=d.indexOf(E,v+E.length))if(++k>=2)return!0}return!1})();if(!u&&!f)return null;let m=G(o,e).tokens;if(m.length<2)return null;let p=ct.map(k=>le(e,k)),h=k=>qt(k,p),y=k=>te(k,l),g=[],x=0,T=0;for(let k=0;k<m.length;k++){let E=m[k];if(y(E)){if(x>0){x--;continue}let v=o.slice(m[T].position.start,E.position.start).trim();v&&g.push(v),T=k+1}else if(h(E))x++;else if(n&&x===0&&k>T&&te(E,c)&&Ga(m[k+1])){let v=o.slice(m[T].position.start,E.position.start).trim();v&&g.push(v),T=k}else if(s&&x===0&&k-1>T&&te(E,a)&&m[k+1]!==void 0&&te(m[k+1],i)){let v=m[k-1],b=o.slice(m[T].position.start,v.position.start).trim();b&&g.push(b),T=k-1}}if(T<m.length){let k=o.slice(m[T].position.start).trim();k&&g.push(k)}if(g.length<2)return null;let C=[],S=[];for(let k of g){let E;try{E=t.statement(k,e)}catch{return null}if(!E||E.kind!=="event-handler")return null;let v=E;C.push(v);let b=!v.body||v.body.length===0;S.push(b?.2:v.metadata?.confidence??.75)}return qe(C,"then",{sourceLanguage:e,confidence:lt(S),sourceText:o})}function lt(o){return o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0}function zr(o){let e=[];for(let t of o){let r=t.statements;t.kind==="compound"&&Array.isArray(r)?e.push(...r):e.push(t)}return e}function Lr(o,e,t,r,n){let a=n>0,i=a?0:Ar(t,n,e);if(i<0)return null;let s=t[i],l=s.value;if(!/^[A-Z][A-Za-z0-9_]*$/.test(l))return null;let{parameters:c,headerEnd:d}=Rr(o,s),u=a?n+1:t.findIndex(v=>v.position.start>=d);u<=i&&(u=i+1);let f=le(e,"init"),m=le(e,"end"),p=ct.map(v=>le(e,v)),h=v=>qt(v,p),y=v=>te(v,m),g=[],x=[],T=[],C=!1,S=0,k=u;for(let v=u;v<t.length;v++){let b=t[v];if(y(b)){if(S>0){S--;continue}if(v===k){C=!0;break}if(te(t[k],f)){let P=o.slice(t[k].position.end,b.position.start).trim();if(P)try{let N=zr(r.body(P,e));x.push(...N),T.push(lt(N.map(z=>z.metadata?.confidence??.75)))}catch{T.push(0)}}else{let P=o.slice(t[k].position.start,b.position.start).trim();try{let N=r.statement(P,e);if(N&&N.kind==="event-handler"){let z=N;g.push(z);let M=!z.body||z.body.length===0;T.push(M?.2:z.metadata?.confidence??.75)}else T.push(0)}catch{T.push(0)}}k=v+1}else h(b)&&S++}if(g.length===0&&x.length===0)return null;let E=(C?1:.8)*lt(T);return fr(l,c,g,x.length>0?x:void 0,{sourceLanguage:e,confidence:E,sourceText:o})}function Ya(o,e,t,r){let n=Ar(t,0,e);if(n<0)return null;let a=t[n],i=a.value;if(!/^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*$/.test(i))return null;let{parameters:s,headerEnd:l}=Rr(o,a),c=t.findIndex(S=>S.position.start>=l);c<=n&&(c=n+1);let d=le(e,"end"),u=ct.map(S=>le(e,S)),f=S=>qt(S,u),m=S=>te(S,d),p=0,h=-1;for(let S=c;S<t.length;S++)if(m(t[S])){if(p===0){h=S;break}p--}else f(t[S])&&p++;let y=t[c]?.position.start??l,g=h>=0?t[h].position.start:o.length,x=o.slice(y,g).trim();if(!x)return null;let T;try{T=zr(r.body(x,e))}catch{return null}if(T.length===0)return null;let C=lt(T.map(S=>S.metadata?.confidence??.75));return h<0&&(C*=.8),hr(i,s,T,{sourceLanguage:e,confidence:C,sourceText:o})}var Se={ko:{\uD074\uB9AD:"click",\uC785\uB825:"input",\uBCC0\uACBD:"change",\uC81C\uCD9C:"submit",\uD0A4\uB2E4\uC6B4:"keydown",\uD0A4\uC5C5:"keyup",\uB9C8\uC6B0\uC2A4\uC624\uBC84:"mouseover",\uB9C8\uC6B0\uC2A4\uC544\uC6C3:"mouseout",\uB9C8\uC6B0\uC2A4\uB2E4\uC6B4:"mousedown",\uB9C8\uC6B0\uC2A4\uC5C5:"mouseup",\uD3EC\uCEE4\uC2A4:"focus",\uBE14\uB7EC:"blur",\uB85C\uB4DC:"load",\uB9AC\uC0AC\uC774\uC988:"resize",\uC2A4\uD06C\uB864:"scroll"},ja:{\u30AF\u30EA\u30C3\u30AF:"click",\u5165\u529B:"input",\u5909\u66F4:"change",\u9001\u4FE1:"submit",\u30AD\u30FC\u30C0\u30A6\u30F3:"keydown",\u30AD\u30FC\u30A2\u30C3\u30D7:"keyup",\u30AD\u30FC\u30D7\u30EC\u30B9:"keypress",\u30DE\u30A6\u30B9\u30AA\u30FC\u30D0\u30FC:"mouseover",\u30DE\u30A6\u30B9\u30A2\u30A6\u30C8:"mouseout",\u30DE\u30A6\u30B9\u62BC\u4E0B:"mousedown",\u30DE\u30A6\u30B9\u89E3\u653E:"mouseup",\u30D5\u30A9\u30FC\u30AB\u30B9:"focus",\u30D6\u30E9\u30FC:"blur",\u30ED\u30FC\u30C9:"load",\u8AAD\u307F\u8FBC\u307F:"load",\u30B5\u30A4\u30BA\u5909\u66F4:"resize",\u30B9\u30AF\u30ED\u30FC\u30EB:"scroll"},ar:{\u0627\u0644\u0646\u0642\u0631:"click",\u0646\u0642\u0631:"click",\u0627\u0644\u0625\u062F\u062E\u0627\u0644:"input",\u0625\u062F\u062E\u0627\u0644:"input",\u0627\u0644\u062A\u063A\u064A\u064A\u0631:"change",\u062A\u063A\u064A\u064A\u0631:"change",\u0627\u0644\u0625\u0631\u0633\u0627\u0644:"submit",\u0625\u0631\u0633\u0627\u0644:"submit","\u0636\u063A\u0637 \u0627\u0644\u0645\u0641\u062A\u0627\u062D":"keydown","\u0631\u0641\u0639 \u0627\u0644\u0645\u0641\u062A\u0627\u062D":"keyup","\u062A\u0645\u0631\u064A\u0631 \u0627\u0644\u0645\u0627\u0648\u0633":"mouseover",\u0627\u0644\u062A\u0631\u0643\u064A\u0632:"focus",\u062A\u062D\u0645\u064A\u0644:"load",\u062A\u0645\u0631\u064A\u0631:"scroll"},es:{clic:"click",click:"click",entrada:"input",cambio:"change",env\u00EDo:"submit",enviar:"submit","tecla abajo":"keydown","tecla arriba":"keyup","rat\xF3n encima":"mouseover","rat\xF3n fuera":"mouseout",enfoque:"focus",desenfoque:"blur",carga:"load",desplazamiento:"scroll"},tr:{t\u0131klama:"click",t\u0131kla:"click",t\u0131k:"click",giri\u015F:"input",girdi:"input",de\u011Fi\u015Fiklik:"change",de\u011Fi\u015Fim:"change",g\u00F6nderme:"submit",g\u00F6nder:"submit",tu\u015Fbasma:"keydown",tu\u015Fb\u0131rakma:"keyup",fare_bas:"mousedown",fare_b\u0131rak:"mouseup",farei\u00E7inde:"mouseover",fared\u0131\u015F\u0131nda:"mouseout",odaklanma:"focus",odak:"focus",bulan\u0131kl\u0131k:"blur",y\u00FCkleme:"load",y\u00FCkle:"load",boyutland\u0131rma:"resize",boyutland\u0131r:"resize",kayd\u0131rma:"scroll"},pt:{clique:"click",clicar:"click",click:"click",entrada:"input",inserir:"input",mudan\u00E7a:"change",mudanca:"change",alterar:"change",envio:"submit",enviar:"submit","tecla baixo":"keydown","tecla cima":"keyup","pressionar tecla":"keydown","soltar tecla":"keyup","mouse sobre":"mouseover","mouse fora":"mouseout",foco:"focus",focar:"focus",desfoque:"blur",desfocar:"blur",carregar:"load",carregamento:"load",rolagem:"scroll",rolar:"scroll"},zh:{\u70B9\u51FB:"click",\u5355\u51FB:"click",\u53CC\u51FB:"dblclick",\u8F93\u5165:"input",\u6539\u53D8:"change",\u53D8\u5316:"change",\u53D8\u66F4:"change",\u63D0\u4EA4:"submit",\u53D1\u9001:"submit",\u6309\u952E:"keydown",\u952E\u5165:"keydown",\u677E\u952E:"keyup",\u9F20\u6807\u8FDB\u5165:"mouseover",\u9F20\u6807\u79FB\u5165:"mouseover",\u9F20\u6807\u79BB\u5F00:"mouseout",\u9F20\u6807\u79FB\u51FA:"mouseout",\u7126\u70B9:"focus",\u805A\u7126:"focus",\u5931\u7126:"blur",\u6A21\u7CCA:"blur",\u52A0\u8F7D:"load",\u8F7D\u5165:"load",\u6EDA\u52A8:"scroll"},fr:{clic:"click",cliquer:"click",click:"click",saisie:"input",entr\u00E9e:"input",changement:"change",changer:"change",soumettre:"submit",soumission:"submit",envoi:"submit","touche bas":"keydown","touche haut":"keyup","souris dessus":"mouseover","souris dehors":"mouseout",focus:"focus",focaliser:"focus",d\u00E9focus:"blur",d\u00E9focaliser:"blur",chargement:"load",charger:"load",d\u00E9filement:"scroll",d\u00E9filer:"scroll"},de:{klick:"click",klicken:"click",click:"click",eingabe:"input",eingeben:"input",\u00E4nderung:"change",\u00E4ndern:"change",absenden:"submit",einreichen:"submit","taste runter":"keydown","taste hoch":"keyup","maus \xFCber":"mouseover","maus raus":"mouseout",fokus:"focus",fokussieren:"focus",defokussieren:"blur",unsch\u00E4rfe:"blur",laden:"load",ladung:"load",scrollen:"scroll",bl\u00E4ttern:"scroll"},id:{klik:"click",click:"click",masukan:"input",input:"input",ubah:"change",perubahan:"change",kirim:"submit","tekan tombol":"keydown","lepas tombol":"keyup","mouse masuk":"mouseover","mouse keluar":"mouseout",fokus:"focus",blur:"blur",muat:"load",memuat:"load",gulir:"scroll",menggulir:"scroll"},bn:{\u0995\u09CD\u09B2\u09BF\u0995:"click",\u0987\u09A8\u09AA\u09C1\u099F:"input",\u099C\u09AE\u09BE:"submit",\u09B2\u09CB\u09A1:"load",\u09B8\u09CD\u0995\u09CD\u09B0\u09CB\u09B2:"scroll",\u09B0\u09BF\u09B8\u09BE\u0987\u099C:"resize",\u099D\u09BE\u09AA\u09B8\u09BE:"blur",\u09AB\u09CB\u0995\u09BE\u09B8:"focus",\u09AA\u09B0\u09BF\u09AC\u09B0\u09CD\u09A4\u09A8:"change"},qu:{click:"click","\xF1it'iy":"click",\u00F1itiy:"click",yaykuchiy:"input",yaykuy:"input",tikray:"change","t'ikray":"change",apachiy:"submit",kachay:"submit","llave uray":"keydown","llave hawa":"keyup","q'away":"focus",qhaway:"focus",paqariy:"blur","mana q'away":"blur",cargay:"load",apakuy:"load",apamuy:"load",kunray:"scroll",muyuy:"scroll",hatun_kay:"resize"},sw:{bofya:"click",click:"click",kubofya:"click",ingiza:"input",kubadilisha:"change",mabadiliko:"change",tuma:"submit",kutuma:"submit","bonyeza chini":"keydown","bonyeza juu":"keyup","panya juu":"mouseover","panya nje":"mouseout",lenga:"focus",kulenga:"focus",blur:"blur",pakia:"load",kupakia:"load",sogeza:"scroll",kusogeza:"scroll"}};var Za=Object.fromEntries(Object.entries(Se).map(([o,e])=>{let t={};for(let[r,n]of Object.entries(e))n in t||(t[n]=r);return[o,t]})),Ja={ar:new Set(["mouseover"]),bn:new Set(["resize"]),de:new Set(["keydown","keyup","load","mouseout","mouseover"]),fr:new Set(["blur"]),id:new Set(["input","keyup","mouseout","mouseover"]),ja:new Set(["keypress","mousedown","mouseup","resize"]),qu:new Set(["change","focus","load","resize","submit"]),sw:new Set(["change","click","input","keydown","keyup","mouseout","mouseover","submit"]),tr:new Set(["keydown","keyup","load","mousedown","mouseout","mouseover","mouseup","resize","scroll"]),zh:new Set(["focus","keyup","mouseout","mouseover"])};function Vr(o,e){return Ja[e]?.has(o)?o:Za[e]?.[o]??o}var ut=class{render(e,t){if(e.kind==="compound")return this.renderCompound(e,t);if(e.kind==="behavior")return this.renderBehavior(e,t);if(e.kind==="def")return this.renderDef(e,t);let r=xt(t,e.action);if(r.length===0)return this.renderExplicit(e);let n=this.findBestPattern(e,r);return n?this.renderWithPattern(e,n):this.renderExplicit(e)}renderCompound(e,t){if(e.statements.length>1&&e.statements.every(a=>a.kind==="event-handler")){let a=this.keyword(t,"end"),i=[];for(let s of e.statements)i.push(this.render(s,t),a);return i.join(`
3
+ `)}let r=e.statements.map(a=>this.render(a,t)),n=this.getChainWord(e.chainType,t);return r.join(` ${n} `)}keyword(e,t){return V(e)?.keywords?.[t]?.primary??t}renderBlockHeader(e,t,r){return r.length>0?`${e} ${t}(${r.join(", ")})`:`${e} ${t}`}renderBehavior(e,t){let r=this.keyword(t,"end"),n=[this.renderBlockHeader(this.keyword(t,"behavior"),e.name,e.parameters)];for(let a of e.eventHandlers)n.push(` ${this.render(a,t)}`,` ${r}`);if(e.initBlock&&e.initBlock.length>0){n.push(` ${this.keyword(t,"init")}`);for(let a of e.initBlock)n.push(` ${this.render(a,t)}`);n.push(` ${r}`)}return n.push(r),n.join(`
4
4
  `)}renderDef(e,t){let r=[this.renderBlockHeader(this.keyword(t,"def"),e.name,e.parameters)];for(let n of e.body)r.push(` ${this.render(n,t)}`);return r.push(this.keyword(t,"end")),r.join(`
5
- `)}getChainWord(e,t){let r=z(t);return r?.keywords?r.keywords[e]?.primary??e:e}renderExplicit(e){return ee(e)}supportedLanguages(){return st()}findBestPattern(e,t){let r=t;if(e.kind==="event-handler"){let a=t.filter(i=>!/-event-/i.test(i.id));a.length>0&&(r=a)}let n=r.map(a=>{let i=a.priority;for(let s of a.template.tokens)s.type==="role"&&(e.roles.has(s.role)?i+=10:s.optional||(i-=50));return/-at-end|-at-start|-before$|-after$/i.test(a.id)&&(i-=30),a.language==="en"&&((a.id.includes("standard")||a.id.includes("en-source"))&&(i+=20),(a.id.includes("-when")||a.id.includes("-if")||a.id.includes("-upon"))&&(i-=15)),{pattern:a,score:i}});return n.sort((a,i)=>i.score-a.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let r=[],n=t.language;for(let a of t.template.tokens){let i=this.renderPatternToken(a,e,n);i!==null&&r.push(i)}if(e.kind==="event-handler"){let a=e;if(a.body&&a.body.length>0){let i=a.body.map(s=>this.render(s,n));r.push(i.join(" "))}}return r.join(" ")}renderPatternToken(e,t,r){switch(e.type){case"literal":return e.value;case"role":{let n=t.roles.get(e.role);return n?e.role==="event"&&t.kind==="event-handler"?this.renderEventName(n,r):this.valueToNaturalString(n,r):(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(l=>l.type==="role"&&l.role==="destination")){let l=t.roles.get("destination");if(l?.type==="reference"&&l.value==="me")return null}if(e.optional&&e.tokens.find(l=>l.type==="role"&&l.role==="quantity")){let l=t.roles.get("quantity");if(l?.type==="literal"&&Number(l.value)===1)return null}let a=[],i=!1;for(let s of e.tokens){let l=this.renderPatternToken(s,t,r);l!==null&&(a.push(l),s.type==="role"&&(i=!0))}return e.optional&&!i?null:a.length>0?a.join(" "):null}default:return null}}renderEventName(e,t){if(e.type!=="literal"||typeof e.value!="string")return this.valueToNaturalString(e,t);let r=e.value,n=a=>a.includes(":")?a:zr(a,t);return r.includes(" or ")?r.split(" or ").map(a=>n(a.trim())).join(" or "):n(r)}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;case"flag":return e.name}}renderReference(e,t){let r=z(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=z(t),n=e.property,a=e.object.type==="reference"?e.object.value:null;if(r?.possessive?.specialForms&&a){let s=r.possessive.specialForms[a];if(s){let{markerPosition:l,usePossessiveAdjectives:c}=r.possessive;return c&&l==="after-object"?`${n} ${s}`:`${s} ${n}`}}let i=this.valueToNaturalString(e.object,t);if(r?.possessive){let{marker:s,markerPosition:l,usePossessiveAdjectives:c}=r.possessive;if(c&&a&&l==="after-object")return`${n} ${i}`;if(s)switch(l){case"between":return r.usesSpaces?`${i}${s} ${n}`:`${i}${s}${n}`;case"after-object":return`${i}${s} ${n}`;case"before-property":return`${i} ${s} ${n}`}}return t==="en"||!r?.possessive?i==="me"?`my ${n}`:i==="it"?`its ${n}`:`${i}'s ${n}`:`${i} ${n}`}},Bt=new ut;function Ue(o,e){return Bt.render(o,e)}function Fe(o){return Bt.renderExplicit(o)}var Xa={getSchema:ne};function Pe(o){return et(o,{schemaLookup:Xa})}var Le=new Set(["if","unless","while","repeat","for"]),Qa=new Set(["then","end","else","if","unless","while","for","repeat","and"]),ei=new Set(["first","last","next","previous","random","closest"]),Re=new Set(["click","dblclick","input","change","submit","keydown","keyup","keypress","mouseover","mouseout","mousedown","mouseup","focus","blur","load","scroll","resize","contextmenu","transitionend","transitionstart","transitionrun","transitioncancel","animationend","animationstart","animationiteration","animationcancel","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","pointerover","pointerout","touchstart","touchend","touchmove","touchcancel","mousemove","mouseenter","mouseleave","wheel","dragstart","dragend","dragover","dragenter","dragleave","drop","drag","loadend","loadstart","error","abort","close","open","message","popstate","hashchange","storage","online","offline","visibilitychange"]),He=class extends Error{constructor(e,t,r,n){super(e),this.name="SemanticParseError",this.language=t,this.input=r,this.diagnostics=n}};function D(o,e,t){return{message:o,severity:e,source:"semantic-parser",...t&&{code:t}}}function J(o,e){return e.length===0?o:{...o,diagnostics:e}}function Ir(o){if(o.length>=2){let e=o[0];if((e==='"'||e==="'")&&o.endsWith(e))return o.slice(1,-1)}return o}var ti=["body","statements","thenBranch","elseBranch","eventHandlers","initBlock"];function _r(o,e){if(!o||typeof o!="object")return o;if(o.action&&o.roles instanceof Map){let r=ne(o.action),n=r?.primaryRole;if(r&&n&&n!=="patient"&&!r.roles.some(a=>a.role==="patient")&&o.roles.has("patient")&&!o.roles.has(n)){let a=o.roles,i=a.get("patient");i!==void 0&&(a.delete("patient"),a.set(n,i))}if(o.action==="tell"){let a=o.roles,i=a.get("patient"),s=a.get("destination");i&&(i.type==="selector"||i.type==="reference")&&(!s||s.type==="literal")&&(a.delete("patient"),a.set("destination",i))}if(o.action==="transition"){let a=o.roles,i=a.get("destination");i&&i.type==="literal"&&!a.has("goal")&&(a.delete("destination"),a.set("goal",i));let s=a.get("patient");s&&s.type==="literal"&&typeof s.value=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*$/.test(s.value)&&a.set("patient",{type:"expression",raw:s.value})}if(o.action==="morph"){let a=o.roles,i=a.get("patient");i&&i.type==="literal"&&typeof i.value=="string"&&/<[a-zA-Z][^>]*\/?>/.test(i.value)&&a.set("patient",{type:"expression",raw:i.value})}if(o.action==="wait"){let a=o.roles;if(!a.has("event")){let i=a.get("duration"),s=i?.type==="expression"?i.raw:i?.type==="literal"?i.value:void 0;typeof s=="string"&&Re.has(s.toLowerCase())&&(a.delete("duration"),a.set("event",{type:"literal",value:s,dataType:"string"}))}}if(o.kind==="command"&&o.action!=="on"){let a=o.roles,i=a.get("event");if(i&&i.type==="expression"){let s=i.raw;typeof s=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*(:[A-Za-z0-9_-]+)?$/.test(s)&&a.set("event",{type:"literal",value:s,dataType:"string"})}}if(e?.size){let a=o.roles;for(let i of["destination","source"]){let s=a.get(i);s&&s.type==="literal"&&typeof s.value=="string"&&e.has(s.value)&&a.set(i,{type:"expression",raw:s.value})}}}let t=o;for(let r of ti){let n=t[r];if(Array.isArray(n))for(let a of n)_r(a,e)}return o}var R=class R{constructor(){this.parseDepth=0;this.boundIdentifiers=new Set}parse(e,t){this.parseDepth===0&&this.boundIdentifiers.clear(),this.parseDepth++;try{return _r(this.parseInternal(e,t),this.boundIdentifiers)}finally{this.parseDepth--}}registerBoundIdentifiers(e){let t=e.action==="repeat"||e.action==="for"?"patient":e.action==="set"?"destination":null;if(!t)return;let r=e.roles.get(t);r?.type==="expression"&&typeof r.raw=="string"&&/^[A-Za-z_]\w*$/.test(r.raw)&&this.boundIdentifiers.add(r.raw)}parseInternal(e,t){let r=Mr(e,t,{statement:(v,b)=>this.parse(v,b),body:(v,b)=>this.parseStatements(v,b)});if(r)return r;let n=Or(e,t,{statement:(v,b)=>this.parse(v,b),body:(v,b)=>this.parseStatements(v,b)});if(n)return n;let{modifiers:a,remainingInput:i}=this.extractStandaloneModifiers(e,t),s=i||e,c=this.stripAsyncModifier(s,t).remainingInput??s,u=this.stripDoNotThrowModifier(c,t).remainingInput??c,f=[],m=G(u,t),p=Q(t);if(p.length===0)throw new He(`No patterns available for language: ${t}`,t,u,[D(`No patterns registered for language '${t}'`,"error","no-patterns")]);let h=[...p].sort((v,b)=>b.priority-v.priority);{let v=m.tokens;if(z(t)?.wordOrder==="VSO"&&v.length>=4&&v[0]?.normalized==="source"){let b=v.findIndex(P=>P.normalized==="on");if(b>=2&&b+1<v.length){let P=u.slice(v[0].position.start,v[b].position.start).trim(),N=v[b+1].position.end,V=u.slice(v[b].position.start,N)+" "+P+u.slice(N);if(V!==u)try{let M=this.parse(V,t);if(M&&M.kind==="event-handler"){let O=a?this.applyModifiers(M,a):M;return J(O,f)}}catch{}}}}{let v=m.tokens;for(let b=1;b<v.length-1;b++){let P=v[b],N=P.value,V=(P.normalized??P.value).toLowerCase();if(!(V==="or"||R.OR_KEYWORDS.has(N)||R.OR_KEYWORDS.has(V)))continue;let O=v[b+1],_=(O.normalized??O.value).toLowerCase();if(!R.KNOWN_EVENTS.has(_))break;let I=b+1,K=v[b+2];K&&K.kind==="selector"&&K.value.startsWith("[")&&(I=b+2);let F=v[b].position.start,fe=v[I].position.end,oe=(u.slice(0,F).trimEnd()+" "+u.slice(fe).trimStart()).trim();if(oe&&oe!==u)try{let he=this.parse(oe,t);if(he&&he.kind==="event-handler"){he.additionalEvents=[{type:"literal",value:_}];let pt=a?this.applyModifiers(he,a):he;return J(pt,f)}}catch{}break}}let y=h.filter(v=>v.command==="on"),g=m.mark(),x=se.matchBest(m,y);if(x){f.push(D(`event pattern matched: ${x.pattern.id} (confidence: ${x.confidence.toFixed(2)})`,"info","pattern-match"));let v=!1;if(/^event-[a-z]+-bare$/.test(x.pattern.id)){let b=x.captured.get("event"),P=(b?.raw??b?.value??"").toString().toLowerCase(),N=Se[t],V=R.KNOWN_EVENTS.has(P)||!!N&&Object.keys(N).some(M=>M.toLowerCase()===P);if(P&&!V){let M=this.trySOVEventExtraction(u,t,h);if(M){f.push(D(`bare-event mis-anchor on "${P}" rejected; SOV extraction preferred`,"info","stage-bare-event-guard"));let O=a?this.applyModifiers(M,a):M;return J(O,f)}if(b?.type==="reference"||b?.type==="expression"){m.reset(g);let O=h.filter(I=>I.command!=="on"),_=se.matchBest(m,O);m.reset(g),_&&_.pattern.command!=="on"?(v=!0,f.push(D(`bare-event mis-anchor on reference "${P}" rejected; command ${_.pattern.command} preferred`,"info","stage-bare-event-guard"))):se.matchBest(m,y)}}}if(!v){let b=this.buildEventHandler(x,m,t),P=a?this.applyModifiers(b,a):b;return J(P,f)}}f.push(D(`event patterns: ${y.length} tried, no match`,"info","stage-event"));let T=this.tryTrailingEventExtraction(u,t,h);if(T){f.push(D("trailing event extraction succeeded","info","stage-trailing-event"));let v=a?this.applyModifiers(T,a):T;return J(v,f)}let C=h.filter(v=>v.command!=="on"),S=se.matchBest(m,C);if(S){if(Le.has(S.pattern.command)){let v=this.trySOVEventExtraction(u,t,h);if(v){f.push(D(`SOV event extraction preferred over bare ${S.pattern.command} command`,"info","stage-sov-loop"));let P=a?this.applyModifiers(v,a):v;return J(P,f)}let b=this.tryMidStreamEventExtraction(u,t,h);if(b){f.push(D(`mid-stream event extraction preferred over bare ${S.pattern.command} command`,"info","stage-midstream-loop"));let P=a?this.applyModifiers(b,a):b;return J(P,f)}}else if(R.KNOWN_EVENTS.has(S.pattern.command)&&this.hasSOVEventMarkerHead(u,t)){let v=this.trySOVEventExtraction(u,t,h);if(v){f.push(D(`SOV event extraction preferred over command-homonym event ${S.pattern.command}`,"info","stage-sov-homonym"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}else if(z(t)?.wordOrder==="VSO"){let v=this.tryMidStreamEventExtraction(u,t,h);if(v){f.push(D(`mid-stream event extraction preferred over bare ${S.pattern.command} command`,"info","stage-midstream-cmd"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}if(S.consumedTokens<m.tokens.length&&z(t)?.wordOrder==="SOV"){let v=this.trySOVEventExtraction(u,t,h);if(v){f.push(D(`SOV event extraction preferred over partial ${S.pattern.command} command (trailing remainder)`,"info","stage-sov-trailing"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}return f.push(D(`command pattern matched: ${S.pattern.id} (confidence: ${S.confidence.toFixed(2)})`,"info","pattern-match")),J(this.buildCommand(S,t),f)}if(f.push(D(`command patterns: ${C.length} tried, no match`,"info","stage-command")),!u.includes(`
6
- `)&&z(t)?.wordOrder==="VSO"){let v=this.tryMidStreamEventExtraction(u,t,h);if(v){f.push(D("mid-stream event extraction succeeded with no leading command match","info","stage-midstream-nocmd"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}let k=this.trySOVEventExtraction(u,t,h);if(k){f.push(D("SOV event extraction succeeded","info","stage-sov"));let v=a?this.applyModifiers(k,a):k;return J(v,f)}f.push(D("SOV event extraction: no event keyword found","info","stage-sov"));let E=this.tryCompoundCommandParsing(m,C,t);if(E)return f.push(D("compound command parsing succeeded","info","stage-compound")),J(E,f);throw f.push(D("compound parsing: no then-keywords or no command matches","info","stage-compound")),f.push(D(`all parse stages exhausted for "${u}"`,"error","parse-failed")),new He(`Could not parse input in ${t}: ${u}`,t,u,f)}parseStatements(e,t){let r=G(e,t),n=Q(t).filter(a=>a.command!=="on").sort((a,i)=>i.priority-a.priority);return this.parseBodyWithClauses(r,n,t)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return st()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let r={};for(let[a,i]of e.captured)r[a]=i;let n=H(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence});return this.registerBoundIdentifiers(n),n}buildEventHandler(e,t,r){if(!e)throw new Error("No match to build event handler from");let n=e.captured.get("event");if(!n)throw new Error("Event handler pattern matched but no event captured");let a=se.extractEventModifiers(t),i=this.extractOrConjunctionEvents(t,r),s=n;i.length>0&&n.type==="literal"&&(s={type:"literal",value:[String(n.value),...i.map(u=>String("value"in u?u.value:""))].join(" or ")});let l,c=e.captured.get("action");if(c&&c.type==="literal"&&c.value==="if"){let d=t.tokens,u=-1;for(let f=t.position()-1;f>=0;f--){let m=d[f],p=(m.normalized??m.value).toLowerCase();if(this.isIfKeyword(p,r)){u=f;break}}if(u>=0){let f=Q(r).filter(y=>y.command!=="on").sort((y,g)=>g.priority-y.priority),m=new X(d.slice(u),r),p=this.parseBodyWithClauses(m,f,r);if(p.some(y=>y.kind==="conditional")||p.length===1&&p[0]?.kind==="compound"&&p[0].statements.some(y=>y.kind==="conditional")){for(;!t.isAtEnd();)t.advance();return me(s,p,a,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence})}}}if(c&&c.type==="literal"){let d=c.value,u={};for(let[C,S]of e.captured)C!=="event"&&C!=="action"&&C!=="continues"&&(u[C]=S);if(d==="repeat"){let C=t.peek(),S=E=>(E.normalized??E.value).toLowerCase();if(C&&C.kind==="keyword"&&S(C)==="forever")u.loopType={type:"literal",value:"forever"},delete u.patient,t.advance();else if(C&&C.kind==="keyword"&&S(C)==="event"){t.advance();let E=t.peek();if(E)for(u.event={type:"literal",value:S(E)},u.loopType={type:"literal",value:"until-event"},delete u.patient;!t.isAtEnd();){let v=t.peek();if(!v||v.kind==="conjunction"||v.kind==="keyword"&&(this.isThenKeyword(v.value,r)||this.isEndKeyword(v.value,r)))break;t.advance()}}let k=u.patient;k&&k.type==="reference"&&k.value==="me"&&delete u.patient}let f=H(d,u,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence});if(this.registerBoundIdentifiers(f),!Le.has(d)||d==="repeat"){let C=e.pattern.id.includes("verb-first"),S=t.tokens,k=t.position(),E=b=>b.kind==="conjunction"||b.kind==="keyword"&&(this.isThenKeyword(b.value,r)||this.isEndKeyword(b.value,r)),v=-1;for(let b=k-1;b>=0;b--){let P=S[b];if(E(P))break;if((P.normalized??P.value).toLowerCase()===d){v=b;break}}if(v>=0){let b=k;for(;b<S.length&&!E(S[b]);)b++;let P=S.slice(v,b),N=P;if(C){let V=String(n.value??"").toLowerCase(),M=P.findIndex(O=>(O.normalized??O.value).toLowerCase()===V);if(M<0)N=null;else{let O=P[M-1],_=O&&O.kind==="keyword"&&O.normalized?.toLowerCase()==="on"?M-1:M;N=[...P.slice(0,_),...P.slice(M+1)]}}if(N&&N.length>1){let V=Q(r).filter(j=>j.command!=="on").sort((j,ue)=>ue.priority-j.priority),M=this.parseClause(N,V,r),O=M[0],_=j=>j!==null&&typeof j=="object"&&typeof j.type=="string"?j.type:typeof j,I=ne(d),K=I?.primaryRole,F=j=>j==="patient"&&K&&K!=="patient"&&!I?.roles.some(ue=>ue.role==="patient")?K:j,fe=(j,ue)=>{if(!Le.has(d)||!I)return!1;let xe=I.roles.find($r=>$r.role===F(j));return xe?xe.expectedTypes.length>0&&!xe.expectedTypes.includes(_(ue)):!0},oe=!!O&&O.kind==="command"&&Object.entries(u).every(([j,ue])=>{if(fe(j,ue))return!0;let xe=O.roles.get(F(j));return xe!==void 0&&_(xe)===_(ue)}),he=O?.metadata?.patternId??"",pt=!Le.has(d)||/^repeat-.*-(times|for-in|while-head|until-head)$/.test(he);if(M.length===1&&O&&O.kind==="command"&&O.action===d&&oe&&pt&&O.roles.size>Object.keys(u).length)for(f=O;t.position()<b;)t.advance()}}}if(!Le.has(d)){let C=f;if(ne(d)?.roles.some(N=>N.role==="quantity"&&!N.required)&&!C.roles.has("quantity")){let N=t.peek();N&&/^-?\d+(\.\d+)?$/.test(N.value)&&(f=H(d,{...Object.fromEntries(C.roles),quantity:{type:"literal",value:parseFloat(N.value),dataType:"number"}},C.metadata),t.advance())}let k=f;if(ne(d)?.roles.some(N=>N.role==="duration"&&!N.required)&&!k.roles.has("duration")){let N=t.peek();N&&/^\d+(\.\d+)?(ms|s)$/i.test(N.value)&&(f=H(d,{...Object.fromEntries(k.roles),duration:{type:"literal",value:N.value,dataType:"string"}},k.metadata),t.advance(),this.consumeForPostposition(t,r))}let v=f,b=ne(d);if(b?.roles.find(N=>N.role==="responseType"&&!N.required)&&!v.roles.has("responseType")){let N=I=>typeof I=="string"&&R.RESPONSE_TYPE_WORDS.has(I.toLowerCase()),V=(I,K)=>{let F=Object.fromEntries(v.roles);K&&delete F.destination,F.responseType={type:"expression",raw:I},f=H(d,F,v.metadata)},M=v.roles.get("destination"),O=b?.roles.find(I=>I.role==="destination"),_=M?.raw??M?.value;if(M&&O&&!O.expectedTypes.includes(M.type)&&N(_))V(_,!0);else{let I=t.peek();I&&N(I.value)&&(V(I.value,!1),t.advance())}}if(d==="wait"){let N=f;if(!N.roles.has("event")){let V=t.peek();if(V&&Re.has(V.value.toLowerCase())){let M=Object.fromEntries(N.roles),O=M.duration;O&&O.type!=="literal"&&O.type!=="expression"&&delete M.duration;let _=M.patient;_&&_.type==="reference"&&_.value==="me"&&delete M.patient,M.event={type:"literal",value:V.value,dataType:"string"},f=H(d,M,N.metadata),t.advance(),this.consumeForPostposition(t,r)}}}}let m=e.captured.get("continues"),p=m?.type==="literal"&&m.value==="then",h=t.peek(),y=!!h&&this.isThenKeyword(h.value,r),x=Le.has(d)&&!!h&&!this.isEndKeyword(h.value,r),T=!!h&&!this.isEndKeyword(h.value,r);if(p||y||x||T){let C=Q(r).filter(E=>E.command!=="on").sort((E,v)=>v.priority-E.priority),S=Q(r).filter(E=>E.id.startsWith("grammar-")&&E.id.includes("-continuation")).sort((E,v)=>v.priority-E.priority),k=this.parseBodyWithGrammarPatterns(t,C,S,r);k.length>0?l=[f,...k]:l=[f]}else l=[f]}else{let d=Q(r).filter(u=>u.command!=="on").sort((u,f)=>f.priority-u.priority);l=this.parseBodyWithClauses(t,d,r)}return me(s,l,a,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,t,r){let n=[],a=[],i=0,s=[];for(;!e.isAtEnd();){let l=e.peek();if(!l)break;if(a.length===0){let p=this.consumeJsBlock(e,r);if(p){n.push(p);continue}let h=this.tryParseConditionalBlock(e,t,r);if(h){n.push(h);continue}}let c=l.kind==="conjunction"||l.kind==="keyword"&&this.isThenKeyword(l.value,r),d=a[a.length-1],u=e.peek(1),f=d?.value.toLowerCase()==="at"&&u?.value.toLowerCase()==="of"||Pt(r,l.value,d?.value,u?.value),m=l.kind==="keyword"&&this.isEndKeyword(l.value,r)&&!f;if(m&&i>0){i--,s.pop(),a.push(l),e.advance();continue}if(c&&s.includes("if")){a.push(l),e.advance();continue}if(c){if(a.length>0){let p=this.parseClause(a,t,r);n.push(...p),a.length=0,i=p.filter(h=>{let y=h;return(y.action==="for"||y.action==="repeat"||y.action==="while")&&(!Array.isArray(y.body)||y.body.length===0)}).length,s.length=0;for(let h=0;h<i;h++)s.push("other")}e.advance();continue}if(m){e.advance();let p=[];for(;!e.isAtEnd();){let h=e.peek();if(!h||h.kind==="conjunction"||h.kind==="keyword"&&(this.isThenKeyword(h.value,r)||this.isEndKeyword(h.value,r)))break;p.push(h),e.advance()}if(p.length>0){let h=a.length>0?this.parseClause(a,t,r):[];h.length===0&&a.length>0?n.push(...this.parseClause([...a,...p],t,r)):(n.push(...h),n.push(...this.parseClause(p,t,r)))}else if(a.length>0){let h=this.parseClause(a,t,r);n.push(...h)}a.length=0;break}if(l.kind==="keyword"){let p=(l.normalized??l.value).toLowerCase();(this.isIfKeyword(p,r)||this.isUnlessKeyword(p,r)||p==="while"||p==="for"||p==="repeat")&&(i++,s.push(this.isIfKeyword(p,r)?"if":"other"))}a.push(l),e.advance()}if(a.length>0){let l=this.parseClause(a,t,r);n.push(...l)}this.foldFrontedWhileIntoRepeat(n,r);for(let l=n.length-1;l>=0;l--){let c=n[l];c.kind==="command"&&c.action==="for"&&(!(c.roles instanceof Map)||c.roles.size===0)&&(!Array.isArray(c.body)||c.body.length===0)&&n.splice(l,1)}return n.length>1?[qe(n,"then",{sourceLanguage:r})]:n}foldFrontedWhileIntoRepeat(e,t){for(let r=0;r+1<e.length;r++){let n=e[r],a=e[r+1];if(n.kind!=="command"||n.action!=="while"||a.kind!=="command"||a.action!=="repeat")continue;let i=n.roles.get("condition");if(!i||a.roles.has("condition")||Array.isArray(n.body)||Array.isArray(a.body))continue;let s=new Map(a.roles);s.set("condition",i),s.set("loopType",{type:"literal",value:"while",dataType:"string"}),e.splice(r,2,{...a,roles:s,metadata:{...a.metadata,sourceLanguage:t,patternId:`repeat-${t}-fronted-while-fold`,confidence:Math.max(a.metadata?.confidence??0,n.metadata?.confidence??0)}})}}parseClause(e,t,r){if(e.length===0)return[];let n=null,a=e,i=e[e.length-1];if(i&&e.length>=2){let y=(i.normalized??i.value).toLowerCase();this.isUnlessKeyword(y,r)&&(n="unless",a=e.slice(0,-1))}let s=null;if(n&&a.length>=3){let y=z(r),g=y?R.buildVerbLookup(y):null;if(g)for(let x=1;x<a.length-1;x++){let T=a[x],C=g.get(T.value.toLowerCase())??(T.normalized?g.get(T.normalized.toLowerCase()):void 0);if(C&&!R.CONDITION_OPERATORS.has(C)){s=a.slice(0,x),a=a.slice(x);break}}}let l=new X(a,r),c=[],d=0,u=[],f=s,m=()=>{if(u.length===0)return;let y=u.slice();if(u.length=0,n&&c.length===0&&f===null){f=y;return}let g=y[0];if(g&&(g.kind==="identifier"||g.kind==="selector"||g.kind==="literal"||g.kind==="reference"))for(let T of this.parseSOVClauseByVerbAnchoring(y,r)){let C=T.action,S=T.roles;C&&ne(C)&&S instanceof Map&&S.size>0&&c.push(T)}};for(;!l.isAtEnd();){let y=l.peek(),g=!!y&&y.normalized?.toLowerCase()==="repeat",x=l.mark(),T=se.matchBest(l,t);if(g&&T&&T.pattern.command!=="repeat"){l.reset(x),m(),c.push(H("repeat",{},{sourceLanguage:r,confidence:.6})),d++,l.advance();continue}if(T&&T.pattern.command==="if"){let C=l.mark(),S=u.length;for(l.reset(x);!l.isAtEnd();){let E=l.peek();if(!E||this.isIfKeyword((E.normalized??E.value).toLowerCase(),r))break;u.push(E),l.advance()}let k=this.tryParseConditionalBlock(l,t,r);if(k){m(),c.push(k),d++;continue}u.length=S,l.reset(C)}if(T){m();let C=this.buildCommand(T,r);c.push(C),d++,this.tryAttachTrailingRole(l,C,r)}else{let C=l.peek();C&&C.normalized?.toLowerCase()==="repeat"?(m(),c.push(H("repeat",{},{sourceLanguage:r,confidence:.6})),d++):C&&u.push(C),l.advance()}}m();let p=c;if(d===0){let y=this.parseSOVClauseByVerbAnchoring(a,r);y.length>0&&(p=y)}let h=f;return n&&p.length>0&&h&&h.length>0?[H(n,{condition:{type:"expression",raw:this.joinTokenText(h)}},{sourceLanguage:r,patternId:`${n}-${r}-trailing-guard`,confidence:.85}),...p]:p}tryAttachTrailingRole(e,t,r){let n=ne(t.action);if(!n)return;let a=z(r);if(!a)return;let i=t.roles,s=(c,d)=>{if(!c)return!1;if(c.kind==="selector")return!0;let u=(c.normalized??c.value).toLowerCase();return Qa.has(u)?!1:u==="body"||u==="it"||u==="you"||u==="result"||u==="document"||u==="window"||this.boundIdentifiers.has(c.value)?!0:d?!1:c.kind==="identifier"||c.kind==="reference"},l=[{role:"source",strict:!1},{role:"destination",strict:!0}];for(let{role:c,strict:d}of l){if(!n.roles.some(y=>y.role===c))continue;let u=a.roleMarkers?.[c];if(!u)continue;let f=i.get(c);if(f&&!(f.type==="reference"&&f.value==="me"))continue;let m=y=>{if(!y||y.kind!=="particle"&&y.kind!=="keyword")return!1;let g=y.value.toLowerCase();return u.primary?.toLowerCase()===g?!0:d?!1:(y.normalized??"").toLowerCase()===c?!0:!!u.alternatives?.some(x=>x.toLowerCase()===g)},p=e.peek(),h=e.peek(1);if(!p||!h)return;if(d&&u.position==="after"){let y=e.peek(2),g=(p.normalized??p.value).toLowerCase();if(ei.has(g)&&h.kind==="selector"&&m(y)){i.set(c,{type:"expression",raw:`${g} ${h.value}`}),e.advance(),e.advance(),e.advance();return}}if(u.position==="after"){if(s(p,d)&&m(h)){let y=this.tokenToSemanticValue(p);e.advance(),e.advance(),y&&i.set(c,y);return}}else if(m(p)&&s(h,d)){e.advance();let y=this.tokenToSemanticValue(e.advance());y&&i.set(c,y);return}}}static buildVerbLookup(e){let t=new Map;for(let[r,n]of Object.entries(e.keywords))if(!["on","if","else","when","where","while","end","then","and"].includes(r)&&(t.set(n.primary.toLowerCase(),r),n.alternatives))for(let a of n.alternatives)t.set(a.toLowerCase(),r);return t}static buildMarkerToRoleLookup(e){let t=new Map;for(let[r,n]of Object.entries(e.roleMarkers)){if(!n)continue;if((r!=="event"||!t.has(n.primary))&&t.set(n.primary,r),n.alternatives)for(let i of n.alternatives)t.has(i)||t.set(i,r)}return t}parseSOVClauseByVerbAnchoring(e,t){let r=z(t);if(!r||r.wordOrder!=="SOV")return[];let n=R.buildVerbLookup(r),a=R.buildMarkerToRoleLookup(r),i=[],s=0;for(;s<e.length;){let l=-1,c="";for(let p=s;p<e.length;p++){let h=e[p];if(a.has(h.value))continue;let y=n.get(h.value.toLowerCase()),g=h.normalized?n.get(h.normalized.toLowerCase()):void 0,x=y||g;if(x){l=p,c=x;break}}if(l===-1)break;let d=e.slice(s,l),u=e.length;for(let p=l+1;p<e.length;p++){let h=e[p];if(h.kind==="conjunction"||this.isThenKeyword(h.value,t)){u=p;break}if(p>l+1&&!a.has(h.value)&&(n.get(h.value.toLowerCase())||(h.normalized?n.get(h.normalized.toLowerCase()):void 0))){u=p;break}}let f=e.slice(l+1,u),m=this.extractRolesFromMarkedTokens(d,f,a,c,t);if(i.push(H(c,m,{sourceLanguage:t,confidence:.7})),s=u,s<e.length){let p=e[s];(p.kind==="conjunction"||this.isThenKeyword(p.value,t))&&s++}}return i}extractRolesFromMarkedTokens(e,t,r,n,a){let i={},s=l=>{let c=[];for(let d of l){let u=r.get(d.value);if(u&&d.kind==="particle"&&c.length>0){let f=this.tokensToSemanticValue(c);if(f){let m=this.mapRoleForCommand(u,n,i);m&&(i[m]=f)}c=[]}else c.push(d)}if(c.length>0)if(c.length===1&&/^\d+(\.\d+)?(ms|s)$/i.test(c[0].value)&&!i.duration&&ne(n)?.roles.some(u=>u.role==="duration"))i.duration={type:"literal",value:c[0].value,dataType:"string"};else{let u=this.tokensToSemanticValue(c);u&&(i.patient?i.destination||(i.destination=u):i.patient=u)}};return s(e),s(t),i}mapRoleForCommand(e,t,r){return r[e]?e==="patient"&&!r.destination?"destination":e==="destination"&&!r.patient?"patient":e==="source"&&!r.source?"source":null:e}tokensToSemanticValue(e){if(e.length===0)return null;let t=e.filter(a=>a.kind!=="whitespace");if(t.length===0)return null;if(t.length===1)return this.tokenToSemanticValue(t[0]);let r=t.map(a=>a.value).join(""),n=t[0];return n.kind==="selector"||n.value.startsWith("#")||n.value.startsWith(".")||n.value.startsWith("@")||n.value.startsWith("*")?re(r):n.kind==="literal"||n.value.startsWith('"')||n.value.startsWith("'")?q(Ir(r),"string"):n.kind==="reference"?Z(r):q(r)}tokenToSemanticValue(e){let t=e.value;if(e.kind==="selector"||t.startsWith("#")||t.startsWith(".")||t.startsWith("@")||t.startsWith("*"))return re(t);if(t.startsWith('"')||t.startsWith("'"))return q(Ir(t),"string");if(/^-?\d+(\.\d+)?$/.test(t))return q(parseFloat(t));if(t==="true"||t==="\u771F"||t==="\uCC38"||t==="do\u011Fru")return q(!0);if(t==="false"||t==="\u507D"||t==="\uAC70\uC9D3"||t==="yanl\u0131\u015F")return q(!1);let r=e.normalized?.toLowerCase();return r==="me"||r==="it"||r==="you"||r==="result"||r==="body"?Z(r):e.kind==="reference"?Z(e.normalized||"me"):q(t)}parseBodyWithGrammarPatterns(e,t,r,n){let a=[],i=[],s=!1,l=()=>{!s&&i.length>0&&a.push(...this.parseSOVClauseByVerbAnchoring(i,n)),i=[],s=!1},c=0,d=()=>{let u=0;for(let f of a){let m=f;(m.action==="for"||m.action==="repeat"||m.action==="while")&&(!Array.isArray(m.body)||m.body.length===0)&&u++}return u-c};for(;!e.isAtEnd();){let u=e.peek();if(u&&this.isThenKeyword(u.value,n)){l(),e.advance();continue}if(u&&this.isEndKeyword(u.value,n)){let m=e.peek(-1),p=e.peek(1);if(!Pt(n,u.value,m?.value,p?.value)){if(l(),d()>0){c++,e.advance();continue}e.advance();break}}if(u&&!s&&this.isIfKeyword((u.normalized??u.value).toLowerCase(),n)){l();let m=this.tryParseConditionalBlock(e,t,n);if(m){a.push(m),s=!0;continue}}let f=!1;if(r.length>0){let m=se.matchBest(e,r);if(m){let p=m.pattern.command,h={};for(let[x,T]of m.captured)x!=="event"&&x!=="action"&&x!=="continues"&&(h[x]=T);let y=H(p,h,{sourceLanguage:n,patternId:m.pattern.id});a.push(y),f=!0,s=!0;let g=m.captured.get("continues");if(g&&g.type==="literal"&&g.value==="then")continue}}if(!f){let m=e.mark(),p=se.matchBest(e,t);if(p){if(p.pattern.command==="if"){let y=e.mark();for(e.reset(m);!e.isAtEnd();){let x=e.peek();if(!x||this.isIfKeyword((x.normalized??x.value).toLowerCase(),n))break;e.advance()}let g=this.tryParseConditionalBlock(e,t,n);if(g){l(),a.push(g),s=!0;continue}e.reset(y)}let h=this.buildCommand(p,n);a.push(h),this.tryAttachTrailingRole(e,h,n),f=!0,s=!0}}f||(u&&i.push(u),e.advance())}l();for(let u=a.length-1;u>=0;u--){let f=a[u];f.kind==="command"&&f.action==="for"&&(!(f.roles instanceof Map)||f.roles.size===0)&&(!Array.isArray(f.body)||f.body.length===0)&&a.splice(u,1)}return a}tryCompoundCommandParsing(e,t,r){let n=e.tokens,a=n.some(c=>c.kind==="conjunction"||c.kind==="keyword"&&this.isThenKeyword(c.value,r)),i=n.some(c=>this.isElseKeyword(c.value,r));if(!a&&!i)return null;let s=new X(n,r),l=this.parseBodyWithClauses(s,t,r);return l.length===0?null:l.length===1?l[0]:qe(l,"then",{sourceLanguage:r,confidence:.65})}matchEventMarkerPhrase(e,t,r){let n=R.SOV_EVENT_MARKER_PHRASES[r];if(!n)return 0;for(let a of n)if(a.every((i,s)=>e[t+s]?.value===i))return a.length;return 0}hasSOVEventMarkerHead(e,t){let r=R.SOV_EVENT_MARKERS[t];if(r===void 0)return!1;let{tokens:n}=G(e,t),a=Se[t],i=new Set;if(a)for(let s of Object.keys(a))i.add(s.toLowerCase());for(let s=0;s<n.length;s++){let l=n[s],c=l.value.toLowerCase(),d=l.normalized?.toLowerCase();if(!(!!d&&(R.KNOWN_EVENTS.has(d)||Re.has(d))||R.KNOWN_EVENTS.has(c)||Re.has(c)||i.has(c)))continue;let f=this.matchEventParamPhrase(n,s+1).len,m=n[s+1+f];if(m&&(m.kind==="particle"||m.kind==="keyword")&&r.has(m.value)||this.matchEventMarkerPhrase(n,s+1+f,t)>0)return!0}return!1}matchEventParamPhrase(e,t){if(e[t]?.value!=="(")return{len:0,names:[]};let r=[];for(let n=t+1;n<e.length;n++){let a=e[n].value;if(a===")")return{len:n-t+1,names:r};if(a!==","){if(e[n].kind!=="identifier")break;r.push(a)}}return{len:0,names:[]}}isStrippableSourceRef(e,t){if(!e)return!1;let r=e.normalized?.toLowerCase();if(e.kind==="keyword"&&(r==="me"||r==="i"||r==="it"))return!0;let n=e.value.toLowerCase();return t.has(n)||!!r&&t.has(r)}tryTrailingEventExtraction(e,t,r){let n=G(e,t).tokens;if(n.length<3)return null;let a=Se[t],i=new Set;if(a)for(let T of Object.keys(a))i.add(T.toLowerCase());let s=n.length-2,l=n[s];if(!(l.kind==="keyword"&&l.normalized?.toLowerCase()==="on"))return null;let d=n[n.length-1],u=d.value.toLowerCase(),f=d.normalized?.toLowerCase();if(!(!!f&&R.KNOWN_EVENTS.has(f)||R.KNOWN_EVENTS.has(u)||i.has(u)))return null;let p=f&&R.KNOWN_EVENTS.has(f)?f:a?.[u]??u,h=n.slice(0,s);if(h.length===0)return null;let y=r.filter(T=>T.command!=="on"),g=new X(h,t),x=this.parseBodyWithClauses(g,y,t);return x.length===0?null:me({type:"literal",value:p},x,void 0,{sourceLanguage:t,confidence:.75})}tryMidStreamEventExtraction(e,t,r){let n=G(e,t).tokens;if(n.length<3)return null;let a=Se[t],i=new Set;if(a)for(let s of Object.keys(a))i.add(s.toLowerCase());for(let s=0;s<n.length-1;s++){let l=n[s];if(!(l.kind==="keyword"&&l.normalized?.toLowerCase()==="on"))continue;let d=n[s+1],u=d.value.toLowerCase(),f=d.normalized?.toLowerCase();if(!(!!f&&R.KNOWN_EVENTS.has(f)||R.KNOWN_EVENTS.has(u)||i.has(u)))continue;let p=f&&R.KNOWN_EVENTS.has(f)?f:a?.[u]??u,h=n.filter((T,C)=>C!==s&&C!==s+1);if(h.length===0)return null;let y=r.filter(T=>T.command!=="on"),g=new X(h,t),x=this.parseBodyWithClauses(g,y,t);return x.length===0?null:me({type:"literal",value:p},x,void 0,{sourceLanguage:t,confidence:.75})}return null}trySOVEventExtraction(e,t,r){let n=R.SOV_EVENT_MARKERS[t];if(!n)return null;let i=G(e,t).tokens,s=Se[t],l=new Set;if(s)for(let S of Object.keys(s))l.add(S.toLowerCase());let c=R.SOV_SOURCE_MARKERS[t],d=-1,u="",f="",m=1,p=[];for(let S=0;S<i.length;S++){let k=i[S],E=k.value.toLowerCase(),v=E,b="",P=E.indexOf("[");P>0&&(v=E.slice(0,P),b=k.value.slice(P));let N=k.normalized?.toLowerCase(),V=N&&(R.KNOWN_EVENTS.has(N)||Re.has(N)),M=l.has(E)||l.has(v),O=R.KNOWN_EVENTS.has(v)||Re.has(v);if(V||M||O){let _=i[S-1];if(_&&(_.normalized??_.value).toLowerCase()==="event")continue;let I;V?I=N:M?I=s?.[E]??s?.[v]??v:I=v;let K=this.matchEventParamPhrase(i,S+1);if(n.size>0){let F=1+K.len,fe=i[S+F];fe&&fe.kind==="selector"&&fe.value.startsWith("[")&&(F+=1);let oe=i[S+F];if(oe&&(oe.kind==="particle"||oe.kind==="keyword")&&n.has(oe.value)){d=S,u=I,f=b||(F===K.len+2?i[S+F-1].value:""),m=F+1,p=K.names;break}}else{d=S,u=I,f=b,m=1+K.len+this.matchEventMarkerPhrase(i,S+1+K.len,t),p=K.names;break}}}if(d===-1){let S=new Set(r.filter(k=>k.command!=="on").map(k=>k.command));for(let k=0;k<i.length;k++){let E=i[k];if(E.kind==="identifier")if(n.size>0){let v=1,b=i[k+1];b&&b.kind==="selector"&&b.value.startsWith("[")&&(v=2);let P=i[k+v];if(P&&(P.kind==="particle"||P.kind==="keyword")&&n.has(P.value)){d=k,u=E.value,f=v===2?i[k+1].value:"",m=v+1;break}}else{let v=this.matchEventMarkerPhrase(i,k+1,t);if(v>0){d=k,u=E.value,f="",m=1+v;break}let b=i[k+1];if(b&&b.kind==="keyword"&&b.normalized!=null&&S.has(b.normalized)){d=k,u=E.value,f="",m=1;break}}}}if(d===-1)return null;let h=new Set;for(let S=d;S<d+m;S++)h.add(S);if(c){let S=d+m;if(S<i.length){let k=i[S];if((k.kind==="particle"||k.kind==="keyword")&&c.markers.has(k.value))h.add(S);else if(this.isStrippableSourceRef(k,c.windowTokens)){let E=i[S+1];E&&(E.kind==="particle"||E.kind==="keyword")&&c.markers.has(E.value)&&(h.add(S),h.add(S+1))}}if(d>=2){let k=i[d-1];(k.kind==="particle"||k.kind==="keyword")&&c.markers.has(k.value)&&this.isStrippableSourceRef(i[d-2],c.windowTokens)&&(h.add(d-2),h.add(d-1))}for(let k=0;k<d;k++){let E=i[k],v=E.value.toLowerCase(),b=E.normalized?.toLowerCase();if(c.windowTokens.has(v)||b&&c.windowTokens.has(b)){h.add(k);break}}}let y=i.filter((S,k)=>!h.has(k));if(y.length===0)return null;let g=r.filter(S=>S.command!=="on"),x=new X(y,t),T=this.parseBodyWithClauses(x,g,t);if(T.length===0)return null;let C={sourceLanguage:t,confidence:.75};return f&&(C.keyFilter=f),me({type:"literal",value:u},T,void 0,C,p)}profileKeywordMatches(e,t,r){let n=z(e)?.keywords?.[t];return n?n.primary?.toLowerCase()===r?!0:!!n.alternatives?.some(a=>a.toLowerCase()===r):!1}consumeForPostposition(e,t){let r=e.peek();if(!r)return;let n=(r.normalized??"").toLowerCase(),a=z(t)?.keywords?.for;(n==="for"||r.value===a?.primary||(a?.alternatives??[]).includes(r.value))&&e.advance()}isThenKeyword(e,t){let r=e.toLowerCase(),a={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","\uADF8\uB7EC\uBA74"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u90A3\u4E48"]),tr:new Set(["ard\u0131ndan","daha sonra","ardindan"]),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"]),tl:new Set(["pagkatapos","tapos"]),bn:new Set(["\u09A4\u09BE\u09B0\u09AA\u09B0"]),qu:new Set(["chaymantataq","hinaspa","chaymanta","chayqa"]),sw:new Set(["kisha","halafu","baadaye"])}[t];return a?a.has(r):r==="then"||this.profileKeywordMatches(t,"then",r)}isElseKeyword(e,t){let r=e.toLowerCase();return r==="else"?!0:this.profileKeywordMatches(t,"else",r)}isEndKeyword(e,t){let r=e.toLowerCase(),a={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0627\u0644\u0646\u0647\u0627\u064A\u0629"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\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","fertig"]),id:new Set(["selesai","akhir","tamat"]),tl:new Set(["wakas","tapos"]),bn:new Set(["\u09B8\u09AE\u09BE\u09AA\u09CD\u09A4"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])}[t];return a?r==="end"||a.has(r):r==="end"||this.profileKeywordMatches(t,"end",r)}isJsKeyword(e){let t=(e.normalized??e.value).toLowerCase();return t==="js"||this.profileKeywordMatches("en","js",t)}consumeJsBlock(e,t){let r=e.peek();if(!r||!this.isJsKeyword(r))return null;let n=e.mark(),a=[];e.advance();let i=!1;for(;!e.isAtEnd();){let l=e.peek();if(!l)break;if(e.advance(),this.isEndKeyword(l.value,t)){i=!0;break}a.push(l)}if(!i)return e.reset(n),null;let s=a.map(l=>l.value).join(" ").trim();return H("js",{patient:{type:"expression",raw:s||"()"}},{sourceLanguage:t,patternId:`js-opaque-${t}`,confidence:1})}isIfKeyword(e,t){let r=e.toLowerCase();return r==="if"?!0:this.profileKeywordMatches(t,"if",r)}isUnlessKeyword(e,t){let r=e.toLowerCase();return r==="unless"?!0:this.profileKeywordMatches(t,"unless",r)}isBlockEndToken(e,t,r){return this.isEndKeyword(e.value,r)?!0:e.kind!=="keyword"||(e.normalized??"").toLowerCase()!=="end"?!1:!(t&&t.kind==="selector")}tryParseConditionalBlock(e,t,r){let n=e.peek();if(!n)return null;let a=(n.normalized??n.value).toLowerCase();if(!this.isIfKeyword(a,r))return null;let i=e.mark();e.advance();let s=[],l=0;for(;!e.isAtEnd();){let k=e.peek();if(!k)break;let E=(k.normalized??k.value).toLowerCase();if(this.isIfKeyword(E,r)||this.isUnlessKeyword(E,r)){l++,s.push(k),e.advance();continue}if(this.isBlockEndToken(k,e.peek(1)??void 0,r)){if(l===0){e.advance();break}l--,s.push(k),e.advance();continue}s.push(k),e.advance()}if(s.length===0)return e.reset(i),null;let c=z(r),d=c?.wordOrder==="SOV"?R.buildVerbLookup(c):null,u=0,f=0,m=[],p=!1;for(;u<s.length;u++){let k=s[u],E=(k.normalized??k.value).toLowerCase();if(this.isIfKeyword(E,r)||this.isUnlessKeyword(E,r)?f++:this.isBlockEndToken(k,s[u+1],r)&&f--,f===0&&this.isThenKeyword(k.value,r)){p=!0,u++;break}if(f===0&&m.length>0){let v=(s[u-1].normalized??s[u-1].value).toLowerCase(),b=s[u-1].value.toLowerCase(),P=(k.normalized??k.value).toLowerCase(),N=R.CONDITION_COPULAS.has(v)||R.CONDITION_COPULAS_SURFACE.has(b)&&R.CONDITION_PREDICATES.has(P),V=d!==null&&d.has(k.value.toLowerCase())&&!R.CONDITION_PREDICATES.has(P);if(!R.CONDITION_OPERATORS.has(P)&&(!N||V)&&(this.tokensBeginCommand(s.slice(u),t,r)||this.sovCommandStartsAt(s.slice(u),d)))break}m.push(k)}if(m.length===0)return e.reset(i),null;let h=[],y=[],g=!1,x=0;for(;u<s.length;u++){let k=s[u],E=(k.normalized??k.value).toLowerCase();if(this.isIfKeyword(E,r)||this.isUnlessKeyword(E,r)?x++:this.isBlockEndToken(k,s[u+1],r)&&x--,x===0&&!g&&this.isElseKeyword(k.value,r)){g=!0;continue}(g?y:h).push(k)}let T={type:"expression",raw:this.joinTokenText(m)},C=this.parseBranch(h,t,r),S=y.length>0?this.parseBranch(y,t,r):void 0;return C.length===0&&(!S||S.length===0)?(e.reset(i),null):yr(T,C,S,{sourceLanguage:r,patternId:`conditional-${r}-folded`,confidence:1})}joinTokenText(e){return e.map(t=>t.kind==="keyword"?t.normalized??t.value:t.value).join(" ").trim()}tokensBeginCommand(e,t,r){if(e.length===0)return!1;let n=new X(e,r);return se.matchBest(n,t)!==null}sovCommandStartsAt(e,t){if(!t)return!1;let r=s=>t.has(s.value.toLowerCase())||!!s.normalized&&t.has(s.normalized.toLowerCase()),n=s=>s.kind==="identifier"||s.kind==="selector"||s.kind==="literal"||s.kind==="reference",a=0,i=0;for(;a+1<e.length;){let s=e[a],l=e[a+1];if(!n(s)||l.kind!=="particle")break;i+=1,a+=2;let c=e[a];if(i>=1&&c&&r(c))return!0}return!1}parseBranch(e,t,r){if(e.length===0)return[];let n=new X(e,r),a=this.parseBodyWithClauses(n,t,r);return a.length===1&&a[0]?.kind==="compound"?a[0].statements:a}extractStandaloneModifiers(e,t){let n=G(e,t).tokens;if(n.length===0)return{modifiers:null,remainingInput:null};let i=n[0].value.toLowerCase(),s=R.STANDALONE_MODIFIERS[i];if(!s)return{modifiers:null,remainingInput:null};let l={},c=1;if(s==="once")l.once=!0;else{let m=1;if(m<n.length){let p=n[m];(p.kind==="keyword"||p.kind==="particle")&&(m++,c++)}if(m<n.length){let p=n[m];if(p.kind==="literal"){let h=p.value.match(/^(\d+)(ms|s|m)?$/);if(h){let y=parseInt(h[1],10),g=h[2]||"ms";g==="s"?y*=1e3:g==="m"&&(y*=6e4),l[s]=y,c=m+1}}}l[s]||(l[s]=s==="debounce"?300:100)}let d=n.slice(c);if(d.length===0)return{modifiers:null,remainingInput:null};let u=d[0].position.start,f=e.slice(u);return{modifiers:l,remainingInput:f}}stripAsyncModifier(e,t){let r=z(t)?.keywords?.async,n=new Set(["async"]);r?.primary&&n.add(r.primary.toLowerCase()),r?.alternatives?.forEach(c=>n.add(c.toLowerCase()));let a=G(e,t).tokens,i=a.findIndex(c=>n.has(c.value.toLowerCase()));if(i===-1)return{remainingInput:null};let s=a[i],l=(e.slice(0,s.position.start)+e.slice(s.position.end)).replace(/\s{2,}/g," ").trim();return l.length===0?{remainingInput:null}:{remainingInput:l}}stripDoNotThrowModifier(e,t){let r=G(e,t).tokens;for(let n=0;n<r.length-1;n++){if(r[n].value.toLowerCase()!=="do")continue;let a=-1;for(let c=n+1;c<=n+5&&c<r.length;c++){let d=r[c];if(d.normalized?.toLowerCase()==="throw"){a=c;break}let u=d.kind;if(u==="selector"||u==="literal"||u==="reference"||u==="conjunction")break}if(a===-1)continue;let i=r[n].position.start,s=r[a].position.end,l=(e.slice(0,i)+e.slice(s)).replace(/\s{2,}/g," ").trim();return l.length===0?{remainingInput:null}:{remainingInput:l}}return{remainingInput:null}}applyModifiers(e,t){return{...e,eventModifiers:{...e.eventModifiers,...t}}}extractOrConjunctionEvents(e,t){let r=[];for(;;){let n=e.mark(),a=e.peek();if(!a)break;let i=(a.normalized||a.value).toLowerCase();if(!R.OR_KEYWORDS.has(i)){e.reset(n);break}e.advance();let s=e.peek();if(!s){e.reset(n);break}let l=(s.normalized||s.value).toLowerCase();e.advance(),r.push({type:"literal",value:l})}return r}};R.KNOWN_EVENTS=new Set(["click","dblclick","input","change","submit","keydown","keyup","keypress","mouseover","mouseout","mousedown","mouseup","focus","blur","load","scroll","resize","contextmenu"]),R.RESPONSE_TYPE_WORDS=new Set(["json","text","html","xml","blob","arraybuffer","formdata","response"]),R.SOV_EVENT_MARKERS={ja:new Set(["\u3067"]),ko:new Set,tr:new Set(["de","da","te","ta"]),bn:new Set(["\u098F"]),qu:new Set(["pi"]),hi:new Set(["\u092A\u0930"])},R.SOV_EVENT_MARKER_PHRASES={ko:[["\uD560","\uB54C"],["\uD560\uB54C"]]},R.SOV_SOURCE_MARKERS={ja:{markers:new Set(["\u304B\u3089"]),windowTokens:new Set(["\u30A6\u30A3\u30F3\u30C9\u30A6","\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8","window","document"])},ko:{markers:new Set(["\uC5D0\uC11C"]),windowTokens:new Set(["\uCC3D","\uC708\uB3C4\uC6B0","\uBB38\uC11C","window","document"])},tr:{markers:new Set(["den","dan","ten","tan"]),windowTokens:new Set(["pencere","belge","window","document"])},bn:{markers:new Set(["\u09A5\u09C7\u0995\u09C7","\u09AE\u09A7\u09CD\u09AF\u09C7"]),windowTokens:new Set(["\u0989\u0987\u09A8\u09CD\u09A1\u09CB","\u09A1\u0995\u09C1\u09AE\u09C7\u09A8\u09CD\u099F","window","document"])},qu:{markers:new Set(["manta"]),windowTokens:new Set(["k_iri","ventana","window","document"])},hi:{markers:new Set(["\u0938\u0947"]),windowTokens:new Set(["\u0935\u093F\u0902\u0921\u094B","\u0926\u0938\u094D\u0924\u093E\u0935\u0947\u091C\u093C","window","document"])}},R.CONDITION_COPULAS=new Set(["is","am","are","be","was","were","not","no"]),R.CONDITION_COPULAS_SURFACE=new Set(["est","\u0435\u0441\u0442\u044C","\u0454","\xE9","ay","\u0647\u0648","adalah","\u0E40\u0E1B\u0E47\u0E19","\u09B9\u09AF\u09BC","\u0939\u0948","dir","kanqa"]),R.CONDITION_PREDICATES=new Set(["empty","null","undefined"]),R.CONDITION_OPERATORS=new Set(["matches","match","contains","exists","has","have","equals","includes"]),R.STANDALONE_MODIFIERS={once:"once",debounced:"debounce",debounce:"debounce",throttled:"throttle",throttle:"throttle"},R.OR_KEYWORDS=new Set(["or","\u0623\u0648","o","ou","oder","atau","atau","\u6216","\u307E\u305F\u306F","\uB610\uB294","veya","\u0985\u09A5\u09AC\u09BE","utaq","au","\u0430\u0431\u043E","\u0438\u043B\u0438","ho\u1EB7c","lub","\u05D0\u05D5","\u0E2B\u0E23\u0E37\u0E2D","o","\u092F\u093E","\u0985\u09A5\u09AC\u09BE"]);var dt=R,$t=new dt;function Ae(o,e){return $t.parse(o,e)}function Dt(o,e){return $t.canParse(o,e)}function jt(o,e){if(de(o))return o;let t=Ae(o,e);return Fe(t)}function Wt(o,e){let t=Pe(o);return Ue(t,e)}function Kt(o,e){return de(o)?Pe(o):Ae(o,e)}vt("qu",it,ve);var ri="1.0.0-qu",ni=["qu"];function oi(){return[...ni]}function qr(o){if(o!=="qu")throw new Error(`Language not supported in this bundle: ${o}. Supported: qu`)}function ai(o,e){return qr(e),[...G(o,e).tokens]}function Br(o){return qr(o),Q(o)}function ii(o,e){return Br(o).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}return Fr(si);})();
5
+ `)}getChainWord(e,t){let r=V(t);return r?.keywords?r.keywords[e]?.primary??e:e}renderExplicit(e){return ee(e)}supportedLanguages(){return st()}findBestPattern(e,t){let r=t;if(e.kind==="event-handler"){let a=t.filter(i=>!/-event-/i.test(i.id));a.length>0&&(r=a)}let n=r.map(a=>{let i=a.priority;for(let s of a.template.tokens)s.type==="role"&&(e.roles.has(s.role)?i+=10:s.optional||(i-=50));return/-at-end|-at-start|-before$|-after$/i.test(a.id)&&(i-=30),a.language==="en"&&((a.id.includes("standard")||a.id.includes("en-source"))&&(i+=20),(a.id.includes("-when")||a.id.includes("-if")||a.id.includes("-upon"))&&(i-=15)),{pattern:a,score:i}});return n.sort((a,i)=>i.score-a.score),n.length>0?n[0].pattern:null}renderWithPattern(e,t){let r=[],n=t.language;for(let a of t.template.tokens){let i=this.renderPatternToken(a,e,n);i!==null&&r.push(i)}if(e.kind==="event-handler"){let a=e;if(a.body&&a.body.length>0){let i=a.body.map(s=>this.render(s,n));r.push(i.join(" "))}}return r.join(" ")}renderPatternToken(e,t,r){switch(e.type){case"literal":return e.value;case"role":{let n=t.roles.get(e.role);return n?e.role==="event"&&t.kind==="event-handler"?this.renderEventName(n,r):this.valueToNaturalString(n,r):(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(l=>l.type==="role"&&l.role==="destination")){let l=t.roles.get("destination");if(l?.type==="reference"&&l.value==="me")return null}if(e.optional&&e.tokens.find(l=>l.type==="role"&&l.role==="quantity")){let l=t.roles.get("quantity");if(l?.type==="literal"&&Number(l.value)===1)return null}let a=[],i=!1;for(let s of e.tokens){let l=this.renderPatternToken(s,t,r);l!==null&&(a.push(l),s.type==="role"&&(i=!0))}return e.optional&&!i?null:a.length>0?a.join(" "):null}default:return null}}renderEventName(e,t){if(e.type!=="literal"||typeof e.value!="string")return this.valueToNaturalString(e,t);let r=e.value,n=a=>a.includes(":")?a:Vr(a,t);return r.includes(" or ")?r.split(" or ").map(a=>n(a.trim())).join(" or "):n(r)}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;case"flag":return e.name}}renderReference(e,t){let r=V(t);return r?.references?r.references[e.value]??e.value:e.value}renderPropertyPath(e,t){let r=V(t),n=e.property,a=e.object.type==="reference"?e.object.value:null;if(r?.possessive?.specialForms&&a){let s=r.possessive.specialForms[a];if(s){let{markerPosition:l,usePossessiveAdjectives:c}=r.possessive;return c&&l==="after-object"?`${n} ${s}`:`${s} ${n}`}}let i=this.valueToNaturalString(e.object,t);if(r?.possessive){let{marker:s,markerPosition:l,usePossessiveAdjectives:c}=r.possessive;if(c&&a&&l==="after-object")return`${n} ${i}`;if(s)switch(l){case"between":return r.usesSpaces?`${i}${s} ${n}`:`${i}${s}${n}`;case"after-object":return`${i}${s} ${n}`;case"before-property":return`${i} ${s} ${n}`}}return t==="en"||!r?.possessive?i==="me"?`my ${n}`:i==="it"?`its ${n}`:`${i}'s ${n}`:`${i} ${n}`}},Bt=new ut;function Ue(o,e){return Bt.render(o,e)}function Fe(o){return Bt.renderExplicit(o)}var Xa={getSchema:ne};function Pe(o){return et(o,{schemaLookup:Xa})}var Le=new Set(["if","unless","while","repeat","for"]),Qa=new Set(["then","end","else","if","unless","while","for","repeat","and"]),ei=new Set(["first","last","next","previous","random","closest"]),Re=new Set(["click","dblclick","input","change","submit","keydown","keyup","keypress","mouseover","mouseout","mousedown","mouseup","focus","blur","load","scroll","resize","contextmenu","transitionend","transitionstart","transitionrun","transitioncancel","animationend","animationstart","animationiteration","animationcancel","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","pointerover","pointerout","touchstart","touchend","touchmove","touchcancel","mousemove","mouseenter","mouseleave","wheel","dragstart","dragend","dragover","dragenter","dragleave","drop","drag","loadend","loadstart","error","abort","close","open","message","popstate","hashchange","storage","online","offline","visibilitychange"]),He=class extends Error{constructor(e,t,r,n){super(e),this.name="SemanticParseError",this.language=t,this.input=r,this.diagnostics=n}};function D(o,e,t){return{message:o,severity:e,source:"semantic-parser",...t&&{code:t}}}function J(o,e){return e.length===0?o:{...o,diagnostics:e}}function Ir(o){if(o.length>=2){let e=o[0];if((e==='"'||e==="'")&&o.endsWith(e))return o.slice(1,-1)}return o}var ti=["body","statements","thenBranch","elseBranch","eventHandlers","initBlock"];function _r(o,e){if(!o||typeof o!="object")return o;if(o.action&&o.roles instanceof Map){let r=ne(o.action),n=r?.primaryRole;if(r&&n&&n!=="patient"&&!r.roles.some(a=>a.role==="patient")&&o.roles.has("patient")&&!o.roles.has(n)){let a=o.roles,i=a.get("patient");i!==void 0&&(a.delete("patient"),a.set(n,i))}if(o.action==="tell"){let a=o.roles,i=a.get("patient"),s=a.get("destination");i&&(i.type==="selector"||i.type==="reference")&&(!s||s.type==="literal")&&(a.delete("patient"),a.set("destination",i))}if(o.action==="transition"){let a=o.roles,i=a.get("destination");i&&i.type==="literal"&&!a.has("goal")&&(a.delete("destination"),a.set("goal",i));let s=a.get("patient");s&&s.type==="literal"&&typeof s.value=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*$/.test(s.value)&&a.set("patient",{type:"expression",raw:s.value})}if(o.action==="morph"){let a=o.roles,i=a.get("patient");i&&i.type==="literal"&&typeof i.value=="string"&&/<[a-zA-Z][^>]*\/?>/.test(i.value)&&a.set("patient",{type:"expression",raw:i.value})}if(o.action==="wait"){let a=o.roles;if(!a.has("event")){let i=a.get("duration"),s=i?.type==="expression"?i.raw:i?.type==="literal"?i.value:void 0;typeof s=="string"&&Re.has(s.toLowerCase())&&(a.delete("duration"),a.set("event",{type:"literal",value:s,dataType:"string"}))}}if(o.kind==="command"&&o.action!=="on"){let a=o.roles,i=a.get("event");if(i&&i.type==="expression"){let s=i.raw;typeof s=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*(:[A-Za-z0-9_-]+)?$/.test(s)&&a.set("event",{type:"literal",value:s,dataType:"string"})}}if(e?.size){let a=o.roles;for(let i of["destination","source"]){let s=a.get(i);s&&s.type==="literal"&&typeof s.value=="string"&&e.has(s.value)&&a.set(i,{type:"expression",raw:s.value})}}}let t=o;for(let r of ti){let n=t[r];if(Array.isArray(n))for(let a of n)_r(a,e)}return o}var R=class R{constructor(){this.parseDepth=0;this.boundIdentifiers=new Set}parse(e,t){this.parseDepth===0&&this.boundIdentifiers.clear(),this.parseDepth++;try{return _r(this.parseInternal(e,t),this.boundIdentifiers)}finally{this.parseDepth--}}registerBoundIdentifiers(e){let t=e.action==="repeat"||e.action==="for"?"patient":e.action==="set"?"destination":null;if(!t)return;let r=e.roles.get(t);r?.type==="expression"&&typeof r.raw=="string"&&/^[A-Za-z_]\w*$/.test(r.raw)&&this.boundIdentifiers.add(r.raw)}parseInternal(e,t){let r=Mr(e,t,{statement:(v,b)=>this.parse(v,b),body:(v,b)=>this.parseStatements(v,b)});if(r)return r;let n=Or(e,t,{statement:(v,b)=>this.parse(v,b),body:(v,b)=>this.parseStatements(v,b)});if(n)return n;let{modifiers:a,remainingInput:i}=this.extractStandaloneModifiers(e,t),s=i||e,c=this.stripAsyncModifier(s,t).remainingInput??s,u=this.stripDoNotThrowModifier(c,t).remainingInput??c,f=[],m=G(u,t),p=Q(t);if(p.length===0)throw new He(`No patterns available for language: ${t}`,t,u,[D(`No patterns registered for language '${t}'`,"error","no-patterns")]);let h=[...p].sort((v,b)=>b.priority-v.priority);{let v=m.tokens;if(V(t)?.wordOrder==="VSO"&&v.length>=4&&v[0]?.normalized==="source"){let b=v.findIndex(P=>P.normalized==="on");if(b>=2&&b+1<v.length){let P=u.slice(v[0].position.start,v[b].position.start).trim(),N=v[b+1].position.end,z=u.slice(v[b].position.start,N)+" "+P+u.slice(N);if(z!==u)try{let M=this.parse(z,t);if(M&&M.kind==="event-handler"){let O=a?this.applyModifiers(M,a):M;return J(O,f)}}catch{}}}}{let v=m.tokens;for(let b=1;b<v.length-1;b++){let P=v[b],N=P.value,z=(P.normalized??P.value).toLowerCase();if(!(z==="or"||R.OR_KEYWORDS.has(N)||R.OR_KEYWORDS.has(z)))continue;let O=v[b+1],_=(O.normalized??O.value).toLowerCase();if(!R.KNOWN_EVENTS.has(_))break;let I=b+1,K=v[b+2];K&&K.kind==="selector"&&K.value.startsWith("[")&&(I=b+2);let F=v[b].position.start,fe=v[I].position.end,oe=(u.slice(0,F).trimEnd()+" "+u.slice(fe).trimStart()).trim();if(oe&&oe!==u)try{let he=this.parse(oe,t);if(he&&he.kind==="event-handler"){he.additionalEvents=[{type:"literal",value:_}];let pt=a?this.applyModifiers(he,a):he;return J(pt,f)}}catch{}break}}let y=h.filter(v=>v.command==="on"),g=m.mark(),x=se.matchBest(m,y);if(x){f.push(D(`event pattern matched: ${x.pattern.id} (confidence: ${x.confidence.toFixed(2)})`,"info","pattern-match"));let v=!1;if(/^event-[a-z]+-bare$/.test(x.pattern.id)){let b=x.captured.get("event"),P=(b?.raw??b?.value??"").toString().toLowerCase(),N=Se[t],z=R.KNOWN_EVENTS.has(P)||!!N&&Object.keys(N).some(M=>M.toLowerCase()===P);if(P&&!z){let M=this.trySOVEventExtraction(u,t,h);if(M){f.push(D(`bare-event mis-anchor on "${P}" rejected; SOV extraction preferred`,"info","stage-bare-event-guard"));let O=a?this.applyModifiers(M,a):M;return J(O,f)}if(b?.type==="reference"||b?.type==="expression"){m.reset(g);let O=h.filter(I=>I.command!=="on"),_=se.matchBest(m,O);m.reset(g),_&&_.pattern.command!=="on"?(v=!0,f.push(D(`bare-event mis-anchor on reference "${P}" rejected; command ${_.pattern.command} preferred`,"info","stage-bare-event-guard"))):se.matchBest(m,y)}}}if(!v){let b=this.buildEventHandler(x,m,t),P=a?this.applyModifiers(b,a):b;return J(P,f)}}f.push(D(`event patterns: ${y.length} tried, no match`,"info","stage-event"));let T=this.tryTrailingEventExtraction(u,t,h);if(T){f.push(D("trailing event extraction succeeded","info","stage-trailing-event"));let v=a?this.applyModifiers(T,a):T;return J(v,f)}let C=h.filter(v=>v.command!=="on"),S=se.matchBest(m,C);if(S){if(Le.has(S.pattern.command)){let v=this.trySOVEventExtraction(u,t,h);if(v){f.push(D(`SOV event extraction preferred over bare ${S.pattern.command} command`,"info","stage-sov-loop"));let P=a?this.applyModifiers(v,a):v;return J(P,f)}let b=this.tryMidStreamEventExtraction(u,t,h);if(b){f.push(D(`mid-stream event extraction preferred over bare ${S.pattern.command} command`,"info","stage-midstream-loop"));let P=a?this.applyModifiers(b,a):b;return J(P,f)}}else if(R.KNOWN_EVENTS.has(S.pattern.command)&&this.hasSOVEventMarkerHead(u,t)){let v=this.trySOVEventExtraction(u,t,h);if(v){f.push(D(`SOV event extraction preferred over command-homonym event ${S.pattern.command}`,"info","stage-sov-homonym"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}else if(V(t)?.wordOrder==="VSO"){let v=this.tryMidStreamEventExtraction(u,t,h);if(v){f.push(D(`mid-stream event extraction preferred over bare ${S.pattern.command} command`,"info","stage-midstream-cmd"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}if(S.consumedTokens<m.tokens.length&&V(t)?.wordOrder==="SOV"){let v=this.trySOVEventExtraction(u,t,h);if(v){f.push(D(`SOV event extraction preferred over partial ${S.pattern.command} command (trailing remainder)`,"info","stage-sov-trailing"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}return f.push(D(`command pattern matched: ${S.pattern.id} (confidence: ${S.confidence.toFixed(2)})`,"info","pattern-match")),J(this.buildCommand(S,t),f)}if(f.push(D(`command patterns: ${C.length} tried, no match`,"info","stage-command")),!u.includes(`
6
+ `)&&V(t)?.wordOrder==="VSO"){let v=this.tryMidStreamEventExtraction(u,t,h);if(v){f.push(D("mid-stream event extraction succeeded with no leading command match","info","stage-midstream-nocmd"));let b=a?this.applyModifiers(v,a):v;return J(b,f)}}let k=this.trySOVEventExtraction(u,t,h);if(k){f.push(D("SOV event extraction succeeded","info","stage-sov"));let v=a?this.applyModifiers(k,a):k;return J(v,f)}f.push(D("SOV event extraction: no event keyword found","info","stage-sov"));let E=this.tryCompoundCommandParsing(m,C,t);if(E)return f.push(D("compound command parsing succeeded","info","stage-compound")),J(E,f);throw f.push(D("compound parsing: no then-keywords or no command matches","info","stage-compound")),f.push(D(`all parse stages exhausted for "${u}"`,"error","parse-failed")),new He(`Could not parse input in ${t}: ${u}`,t,u,f)}parseStatements(e,t){let r=G(e,t),n=Q(t).filter(a=>a.command!=="on").sort((a,i)=>i.priority-a.priority);return this.parseBodyWithClauses(r,n,t)}canParse(e,t){try{return this.parse(e,t),!0}catch{return!1}}supportedLanguages(){return st()}buildCommand(e,t){if(!e)throw new Error("No match to build command from");let r={};for(let[a,i]of e.captured)r[a]=i;let n=H(e.pattern.command,r,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence});return this.registerBoundIdentifiers(n),n}buildEventHandler(e,t,r){if(!e)throw new Error("No match to build event handler from");let n=e.captured.get("event");if(!n)throw new Error("Event handler pattern matched but no event captured");let a=se.extractEventModifiers(t),i=this.extractOrConjunctionEvents(t,r),s=n;i.length>0&&n.type==="literal"&&(s={type:"literal",value:[String(n.value),...i.map(u=>String("value"in u?u.value:""))].join(" or ")});let l,c=e.captured.get("action");if(c&&c.type==="literal"&&c.value==="if"){let d=t.tokens,u=-1;for(let f=t.position()-1;f>=0;f--){let m=d[f],p=(m.normalized??m.value).toLowerCase();if(this.isIfKeyword(p,r)){u=f;break}}if(u>=0){let f=Q(r).filter(y=>y.command!=="on").sort((y,g)=>g.priority-y.priority),m=new X(d.slice(u),r),p=this.parseBodyWithClauses(m,f,r);if(p.some(y=>y.kind==="conditional")||p.length===1&&p[0]?.kind==="compound"&&p[0].statements.some(y=>y.kind==="conditional")){for(;!t.isAtEnd();)t.advance();return me(s,p,a,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence})}}}if(c&&c.type==="literal"){let d=c.value,u={};for(let[C,S]of e.captured)C!=="event"&&C!=="action"&&C!=="continues"&&(u[C]=S);if(d==="repeat"){let C=t.peek(),S=E=>(E.normalized??E.value).toLowerCase();if(C&&C.kind==="keyword"&&S(C)==="forever")u.loopType={type:"literal",value:"forever"},delete u.patient,t.advance();else if(C&&C.kind==="keyword"&&S(C)==="event"){t.advance();let E=t.peek();if(E)for(u.event={type:"literal",value:S(E)},u.loopType={type:"literal",value:"until-event"},delete u.patient;!t.isAtEnd();){let v=t.peek();if(!v||v.kind==="conjunction"||v.kind==="keyword"&&(this.isThenKeyword(v.value,r)||this.isEndKeyword(v.value,r)))break;t.advance()}}let k=u.patient;k&&k.type==="reference"&&k.value==="me"&&delete u.patient}let f=H(d,u,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence});if(this.registerBoundIdentifiers(f),!Le.has(d)||d==="repeat"){let C=e.pattern.id.includes("verb-first"),S=t.tokens,k=t.position(),E=b=>b.kind==="conjunction"||b.kind==="keyword"&&(this.isThenKeyword(b.value,r)||this.isEndKeyword(b.value,r)),v=-1;for(let b=k-1;b>=0;b--){let P=S[b];if(E(P))break;if((P.normalized??P.value).toLowerCase()===d){v=b;break}}if(v>=0){let b=k;for(;b<S.length&&!E(S[b]);)b++;let P=S.slice(v,b),N=P;if(C){let z=String(n.value??"").toLowerCase(),M=P.findIndex(O=>(O.normalized??O.value).toLowerCase()===z);if(M<0)N=null;else{let O=P[M-1],_=O&&O.kind==="keyword"&&O.normalized?.toLowerCase()==="on"?M-1:M;N=[...P.slice(0,_),...P.slice(M+1)]}}if(N&&N.length>1){let z=Q(r).filter(j=>j.command!=="on").sort((j,ue)=>ue.priority-j.priority),M=this.parseClause(N,z,r),O=M[0],_=j=>j!==null&&typeof j=="object"&&typeof j.type=="string"?j.type:typeof j,I=ne(d),K=I?.primaryRole,F=j=>j==="patient"&&K&&K!=="patient"&&!I?.roles.some(ue=>ue.role==="patient")?K:j,fe=(j,ue)=>{if(!Le.has(d)||!I)return!1;let xe=I.roles.find($r=>$r.role===F(j));return xe?xe.expectedTypes.length>0&&!xe.expectedTypes.includes(_(ue)):!0},oe=!!O&&O.kind==="command"&&Object.entries(u).every(([j,ue])=>{if(fe(j,ue))return!0;let xe=O.roles.get(F(j));return xe!==void 0&&_(xe)===_(ue)}),he=O?.metadata?.patternId??"",pt=!Le.has(d)||/^repeat-.*-(times|for-in|while-head|until-head)$/.test(he);if(M.length===1&&O&&O.kind==="command"&&O.action===d&&oe&&pt&&O.roles.size>Object.keys(u).length)for(f=O;t.position()<b;)t.advance()}}}if(!Le.has(d)){let C=f;if(ne(d)?.roles.some(N=>N.role==="quantity"&&!N.required)&&!C.roles.has("quantity")){let N=t.peek();N&&/^-?\d+(\.\d+)?$/.test(N.value)&&(f=H(d,{...Object.fromEntries(C.roles),quantity:{type:"literal",value:parseFloat(N.value),dataType:"number"}},C.metadata),t.advance())}let k=f;if(ne(d)?.roles.some(N=>N.role==="duration"&&!N.required)&&!k.roles.has("duration")){let N=t.peek();N&&/^\d+(\.\d+)?(ms|s)$/i.test(N.value)&&(f=H(d,{...Object.fromEntries(k.roles),duration:{type:"literal",value:N.value,dataType:"string"}},k.metadata),t.advance(),this.consumeForPostposition(t,r))}let v=f,b=ne(d);if(b?.roles.find(N=>N.role==="responseType"&&!N.required)&&!v.roles.has("responseType")){let N=I=>typeof I=="string"&&R.RESPONSE_TYPE_WORDS.has(I.toLowerCase()),z=(I,K)=>{let F=Object.fromEntries(v.roles);K&&delete F.destination,F.responseType={type:"expression",raw:I},f=H(d,F,v.metadata)},M=v.roles.get("destination"),O=b?.roles.find(I=>I.role==="destination"),_=M?.raw??M?.value;if(M&&O&&!O.expectedTypes.includes(M.type)&&N(_))z(_,!0);else{let I=t.peek();I&&N(I.value)&&(z(I.value,!1),t.advance())}}if(d==="wait"){let N=f;if(!N.roles.has("event")){let z=t.peek();if(z&&Re.has(z.value.toLowerCase())){let M=Object.fromEntries(N.roles),O=M.duration;O&&O.type!=="literal"&&O.type!=="expression"&&delete M.duration;let _=M.patient;_&&_.type==="reference"&&_.value==="me"&&delete M.patient,M.event={type:"literal",value:z.value,dataType:"string"},f=H(d,M,N.metadata),t.advance(),this.consumeForPostposition(t,r)}}}}let m=e.captured.get("continues"),p=m?.type==="literal"&&m.value==="then",h=t.peek(),y=!!h&&this.isThenKeyword(h.value,r),x=Le.has(d)&&!!h&&!this.isEndKeyword(h.value,r),T=!!h&&!this.isEndKeyword(h.value,r);if(p||y||x||T){let C=Q(r).filter(E=>E.command!=="on").sort((E,v)=>v.priority-E.priority),S=Q(r).filter(E=>E.id.startsWith("grammar-")&&E.id.includes("-continuation")).sort((E,v)=>v.priority-E.priority),k=this.parseBodyWithGrammarPatterns(t,C,S,r);k.length>0?l=[f,...k]:l=[f]}else l=[f]}else{let d=Q(r).filter(u=>u.command!=="on").sort((u,f)=>f.priority-u.priority);l=this.parseBodyWithClauses(t,d,r)}return me(s,l,a,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,t,r){let n=[],a=[],i=0,s=[];for(;!e.isAtEnd();){let l=e.peek();if(!l)break;if(a.length===0){let p=this.consumeJsBlock(e,r);if(p){n.push(p);continue}let h=this.tryParseConditionalBlock(e,t,r);if(h){n.push(h);continue}}let c=l.kind==="conjunction"||l.kind==="keyword"&&this.isThenKeyword(l.value,r),d=a[a.length-1],u=e.peek(1),f=d?.value.toLowerCase()==="at"&&u?.value.toLowerCase()==="of"||Pt(r,l.value,d?.value,u?.value),m=l.kind==="keyword"&&this.isEndKeyword(l.value,r)&&!f;if(m&&i>0){i--,s.pop(),a.push(l),e.advance();continue}if(c&&s.includes("if")){a.push(l),e.advance();continue}if(c){if(a.length>0){let p=this.parseClause(a,t,r);n.push(...p),a.length=0,i=p.filter(h=>{let y=h;return(y.action==="for"||y.action==="repeat"||y.action==="while")&&(!Array.isArray(y.body)||y.body.length===0)}).length,s.length=0;for(let h=0;h<i;h++)s.push("other")}e.advance();continue}if(m){e.advance();let p=[];for(;!e.isAtEnd();){let h=e.peek();if(!h||h.kind==="conjunction"||h.kind==="keyword"&&(this.isThenKeyword(h.value,r)||this.isEndKeyword(h.value,r)))break;p.push(h),e.advance()}if(p.length>0){let h=a.length>0?this.parseClause(a,t,r):[];h.length===0&&a.length>0?n.push(...this.parseClause([...a,...p],t,r)):(n.push(...h),n.push(...this.parseClause(p,t,r)))}else if(a.length>0){let h=this.parseClause(a,t,r);n.push(...h)}a.length=0;break}if(l.kind==="keyword"){let p=(l.normalized??l.value).toLowerCase();(this.isIfKeyword(p,r)||this.isUnlessKeyword(p,r)||p==="while"||p==="for"||p==="repeat")&&(i++,s.push(this.isIfKeyword(p,r)?"if":"other"))}a.push(l),e.advance()}if(a.length>0){let l=this.parseClause(a,t,r);n.push(...l)}this.foldFrontedWhileIntoRepeat(n,r);for(let l=n.length-1;l>=0;l--){let c=n[l];c.kind==="command"&&c.action==="for"&&(!(c.roles instanceof Map)||c.roles.size===0)&&(!Array.isArray(c.body)||c.body.length===0)&&n.splice(l,1)}return n.length>1?[qe(n,"then",{sourceLanguage:r})]:n}foldFrontedWhileIntoRepeat(e,t){for(let r=0;r+1<e.length;r++){let n=e[r],a=e[r+1];if(n.kind!=="command"||n.action!=="while"||a.kind!=="command"||a.action!=="repeat")continue;let i=n.roles.get("condition");if(!i||a.roles.has("condition")||Array.isArray(n.body)||Array.isArray(a.body))continue;let s=new Map(a.roles);s.set("condition",i),s.set("loopType",{type:"literal",value:"while",dataType:"string"}),e.splice(r,2,{...a,roles:s,metadata:{...a.metadata,sourceLanguage:t,patternId:`repeat-${t}-fronted-while-fold`,confidence:Math.max(a.metadata?.confidence??0,n.metadata?.confidence??0)}})}}parseClause(e,t,r){if(e.length===0)return[];let n=null,a=e,i=e[e.length-1];if(i&&e.length>=2){let y=(i.normalized??i.value).toLowerCase();this.isUnlessKeyword(y,r)&&(n="unless",a=e.slice(0,-1))}let s=null;if(n&&a.length>=3){let y=V(r),g=y?R.buildVerbLookup(y):null;if(g)for(let x=1;x<a.length-1;x++){let T=a[x],C=g.get(T.value.toLowerCase())??(T.normalized?g.get(T.normalized.toLowerCase()):void 0);if(C&&!R.CONDITION_OPERATORS.has(C)){s=a.slice(0,x),a=a.slice(x);break}}}let l=new X(a,r),c=[],d=0,u=[],f=s,m=()=>{if(u.length===0)return;let y=u.slice();if(u.length=0,n&&c.length===0&&f===null){f=y;return}let g=y[0];if(g&&(g.kind==="identifier"||g.kind==="selector"||g.kind==="literal"||g.kind==="reference"))for(let T of this.parseSOVClauseByVerbAnchoring(y,r)){let C=T.action,S=T.roles;C&&ne(C)&&S instanceof Map&&S.size>0&&c.push(T)}};for(;!l.isAtEnd();){let y=l.peek(),g=!!y&&y.normalized?.toLowerCase()==="repeat",x=l.mark(),T=se.matchBest(l,t);if(g&&T&&T.pattern.command!=="repeat"){l.reset(x),m(),c.push(H("repeat",{},{sourceLanguage:r,confidence:.6})),d++,l.advance();continue}if(T&&T.pattern.command==="if"){let C=l.mark(),S=u.length;for(l.reset(x);!l.isAtEnd();){let E=l.peek();if(!E||this.isIfKeyword((E.normalized??E.value).toLowerCase(),r))break;u.push(E),l.advance()}let k=this.tryParseConditionalBlock(l,t,r);if(k){m(),c.push(k),d++;continue}u.length=S,l.reset(C)}if(T){m();let C=this.buildCommand(T,r);c.push(C),d++,this.tryAttachTrailingRole(l,C,r)}else{let C=l.peek();C&&C.normalized?.toLowerCase()==="repeat"?(m(),c.push(H("repeat",{},{sourceLanguage:r,confidence:.6})),d++):C&&u.push(C),l.advance()}}m();let p=c;if(d===0){let y=this.parseSOVClauseByVerbAnchoring(a,r);y.length>0&&(p=y)}let h=f;return n&&p.length>0&&h&&h.length>0?[H(n,{condition:{type:"expression",raw:this.joinTokenText(h)}},{sourceLanguage:r,patternId:`${n}-${r}-trailing-guard`,confidence:.85}),...p]:p}tryAttachTrailingRole(e,t,r){let n=ne(t.action);if(!n)return;let a=V(r);if(!a)return;let i=t.roles,s=(c,d)=>{if(!c)return!1;if(c.kind==="selector")return!0;let u=(c.normalized??c.value).toLowerCase();return Qa.has(u)?!1:u==="body"||u==="it"||u==="you"||u==="result"||u==="document"||u==="window"||this.boundIdentifiers.has(c.value)?!0:d?!1:c.kind==="identifier"||c.kind==="reference"},l=[{role:"source",strict:!1},{role:"destination",strict:!0}];for(let{role:c,strict:d}of l){if(!n.roles.some(y=>y.role===c))continue;let u=a.roleMarkers?.[c];if(!u)continue;let f=i.get(c);if(f&&!(f.type==="reference"&&f.value==="me"))continue;let m=y=>{if(!y||y.kind!=="particle"&&y.kind!=="keyword")return!1;let g=y.value.toLowerCase();return u.primary?.toLowerCase()===g?!0:d?!1:(y.normalized??"").toLowerCase()===c?!0:!!u.alternatives?.some(x=>x.toLowerCase()===g)},p=e.peek(),h=e.peek(1);if(!p||!h)return;if(d&&u.position==="after"){let y=e.peek(2),g=(p.normalized??p.value).toLowerCase();if(ei.has(g)&&h.kind==="selector"&&m(y)){i.set(c,{type:"expression",raw:`${g} ${h.value}`}),e.advance(),e.advance(),e.advance();return}}if(u.position==="after"){if(s(p,d)&&m(h)){let y=this.tokenToSemanticValue(p);e.advance(),e.advance(),y&&i.set(c,y);return}}else if(m(p)&&s(h,d)){e.advance();let y=this.tokenToSemanticValue(e.advance());y&&i.set(c,y);return}}}static buildVerbLookup(e){let t=new Map;for(let[r,n]of Object.entries(e.keywords))if(!["on","if","else","when","where","while","end","then","and"].includes(r)&&(t.set(n.primary.toLowerCase(),r),n.alternatives))for(let a of n.alternatives)t.set(a.toLowerCase(),r);return t}static buildMarkerToRoleLookup(e){let t=new Map;for(let[r,n]of Object.entries(e.roleMarkers)){if(!n)continue;if((r!=="event"||!t.has(n.primary))&&t.set(n.primary,r),n.alternatives)for(let i of n.alternatives)t.has(i)||t.set(i,r)}return t}parseSOVClauseByVerbAnchoring(e,t){let r=V(t);if(!r||r.wordOrder!=="SOV")return[];let n=R.buildVerbLookup(r),a=R.buildMarkerToRoleLookup(r),i=[],s=0;for(;s<e.length;){let l=-1,c="";for(let p=s;p<e.length;p++){let h=e[p];if(a.has(h.value))continue;let y=n.get(h.value.toLowerCase()),g=h.normalized?n.get(h.normalized.toLowerCase()):void 0,x=y||g;if(x){l=p,c=x;break}}if(l===-1)break;let d=e.slice(s,l),u=e.length;for(let p=l+1;p<e.length;p++){let h=e[p];if(h.kind==="conjunction"||this.isThenKeyword(h.value,t)){u=p;break}if(p>l+1&&!a.has(h.value)&&(n.get(h.value.toLowerCase())||(h.normalized?n.get(h.normalized.toLowerCase()):void 0))){u=p;break}}let f=e.slice(l+1,u),m=this.extractRolesFromMarkedTokens(d,f,a,c,t);if(i.push(H(c,m,{sourceLanguage:t,confidence:.7})),s=u,s<e.length){let p=e[s];(p.kind==="conjunction"||this.isThenKeyword(p.value,t))&&s++}}return i}extractRolesFromMarkedTokens(e,t,r,n,a){let i={},s=l=>{let c=[];for(let d of l){let u=r.get(d.value);if(u&&d.kind==="particle"&&c.length>0){let f=this.tokensToSemanticValue(c);if(f){let m=this.mapRoleForCommand(u,n,i);m&&(i[m]=f)}c=[]}else c.push(d)}if(c.length>0)if(c.length===1&&/^\d+(\.\d+)?(ms|s)$/i.test(c[0].value)&&!i.duration&&ne(n)?.roles.some(u=>u.role==="duration"))i.duration={type:"literal",value:c[0].value,dataType:"string"};else{let u=this.tokensToSemanticValue(c);u&&(i.patient?i.destination||(i.destination=u):i.patient=u)}};return s(e),s(t),i}mapRoleForCommand(e,t,r){return r[e]?e==="patient"&&!r.destination?"destination":e==="destination"&&!r.patient?"patient":e==="source"&&!r.source?"source":null:e}tokensToSemanticValue(e){if(e.length===0)return null;let t=e.filter(a=>a.kind!=="whitespace");if(t.length===0)return null;if(t.length===1)return this.tokenToSemanticValue(t[0]);let r=t.map(a=>a.value).join(""),n=t[0];return n.kind==="selector"||n.value.startsWith("#")||n.value.startsWith(".")||n.value.startsWith("@")||n.value.startsWith("*")?re(r):n.kind==="literal"||n.value.startsWith('"')||n.value.startsWith("'")?q(Ir(r),"string"):n.kind==="reference"?Z(r):q(r)}tokenToSemanticValue(e){let t=e.value;if(e.kind==="selector"||t.startsWith("#")||t.startsWith(".")||t.startsWith("@")||t.startsWith("*"))return re(t);if(t.startsWith('"')||t.startsWith("'"))return q(Ir(t),"string");if(/^-?\d+(\.\d+)?$/.test(t))return q(parseFloat(t));if(t==="true"||t==="\u771F"||t==="\uCC38"||t==="do\u011Fru")return q(!0);if(t==="false"||t==="\u507D"||t==="\uAC70\uC9D3"||t==="yanl\u0131\u015F")return q(!1);let r=e.normalized?.toLowerCase();return r==="me"||r==="it"||r==="you"||r==="result"||r==="body"?Z(r):e.kind==="reference"?Z(e.normalized||"me"):q(t)}parseBodyWithGrammarPatterns(e,t,r,n){let a=[],i=[],s=!1,l=()=>{!s&&i.length>0&&a.push(...this.parseSOVClauseByVerbAnchoring(i,n)),i=[],s=!1},c=0,d=()=>{let u=0;for(let f of a){let m=f;(m.action==="for"||m.action==="repeat"||m.action==="while")&&(!Array.isArray(m.body)||m.body.length===0)&&u++}return u-c};for(;!e.isAtEnd();){let u=e.peek();if(u&&this.isThenKeyword(u.value,n)){l(),e.advance();continue}if(u&&this.isEndKeyword(u.value,n)){let m=e.peek(-1),p=e.peek(1);if(!Pt(n,u.value,m?.value,p?.value)){if(l(),d()>0){c++,e.advance();continue}e.advance();break}}if(u&&!s&&this.isIfKeyword((u.normalized??u.value).toLowerCase(),n)){l();let m=this.tryParseConditionalBlock(e,t,n);if(m){a.push(m),s=!0;continue}}let f=!1;if(r.length>0){let m=se.matchBest(e,r);if(m){let p=m.pattern.command,h={};for(let[x,T]of m.captured)x!=="event"&&x!=="action"&&x!=="continues"&&(h[x]=T);let y=H(p,h,{sourceLanguage:n,patternId:m.pattern.id});a.push(y),f=!0,s=!0;let g=m.captured.get("continues");if(g&&g.type==="literal"&&g.value==="then")continue}}if(!f){let m=e.mark(),p=se.matchBest(e,t);if(p){if(p.pattern.command==="if"){let y=e.mark();for(e.reset(m);!e.isAtEnd();){let x=e.peek();if(!x||this.isIfKeyword((x.normalized??x.value).toLowerCase(),n))break;e.advance()}let g=this.tryParseConditionalBlock(e,t,n);if(g){l(),a.push(g),s=!0;continue}e.reset(y)}let h=this.buildCommand(p,n);a.push(h),this.tryAttachTrailingRole(e,h,n),f=!0,s=!0}}f||(u&&i.push(u),e.advance())}l();for(let u=a.length-1;u>=0;u--){let f=a[u];f.kind==="command"&&f.action==="for"&&(!(f.roles instanceof Map)||f.roles.size===0)&&(!Array.isArray(f.body)||f.body.length===0)&&a.splice(u,1)}return a}tryCompoundCommandParsing(e,t,r){let n=e.tokens,a=n.some(c=>c.kind==="conjunction"||c.kind==="keyword"&&this.isThenKeyword(c.value,r)),i=n.some(c=>this.isElseKeyword(c.value,r));if(!a&&!i)return null;let s=new X(n,r),l=this.parseBodyWithClauses(s,t,r);return l.length===0?null:l.length===1?l[0]:qe(l,"then",{sourceLanguage:r,confidence:.65})}matchEventMarkerPhrase(e,t,r){let n=R.SOV_EVENT_MARKER_PHRASES[r];if(!n)return 0;for(let a of n)if(a.every((i,s)=>e[t+s]?.value===i))return a.length;return 0}hasSOVEventMarkerHead(e,t){let r=R.SOV_EVENT_MARKERS[t];if(r===void 0)return!1;let{tokens:n}=G(e,t),a=Se[t],i=new Set;if(a)for(let s of Object.keys(a))i.add(s.toLowerCase());for(let s=0;s<n.length;s++){let l=n[s],c=l.value.toLowerCase(),d=l.normalized?.toLowerCase();if(!(!!d&&(R.KNOWN_EVENTS.has(d)||Re.has(d))||R.KNOWN_EVENTS.has(c)||Re.has(c)||i.has(c)))continue;let f=this.matchEventParamPhrase(n,s+1).len,m=n[s+1+f];if(m&&(m.kind==="particle"||m.kind==="keyword")&&r.has(m.value)||this.matchEventMarkerPhrase(n,s+1+f,t)>0)return!0}return!1}matchEventParamPhrase(e,t){if(e[t]?.value!=="(")return{len:0,names:[]};let r=[];for(let n=t+1;n<e.length;n++){let a=e[n].value;if(a===")")return{len:n-t+1,names:r};if(a!==","){if(e[n].kind!=="identifier")break;r.push(a)}}return{len:0,names:[]}}isStrippableSourceRef(e,t){if(!e)return!1;let r=e.normalized?.toLowerCase();if(e.kind==="keyword"&&(r==="me"||r==="i"||r==="it"))return!0;let n=e.value.toLowerCase();return t.has(n)||!!r&&t.has(r)}tryTrailingEventExtraction(e,t,r){let n=G(e,t).tokens;if(n.length<3)return null;let a=Se[t],i=new Set;if(a)for(let T of Object.keys(a))i.add(T.toLowerCase());let s=n.length-2,l=n[s];if(!(l.kind==="keyword"&&l.normalized?.toLowerCase()==="on"))return null;let d=n[n.length-1],u=d.value.toLowerCase(),f=d.normalized?.toLowerCase();if(!(!!f&&R.KNOWN_EVENTS.has(f)||R.KNOWN_EVENTS.has(u)||i.has(u)))return null;let p=f&&R.KNOWN_EVENTS.has(f)?f:a?.[u]??u,h=n.slice(0,s);if(h.length===0)return null;let y=r.filter(T=>T.command!=="on"),g=new X(h,t),x=this.parseBodyWithClauses(g,y,t);return x.length===0?null:me({type:"literal",value:p},x,void 0,{sourceLanguage:t,confidence:.75})}tryMidStreamEventExtraction(e,t,r){let n=G(e,t).tokens;if(n.length<3)return null;let a=Se[t],i=new Set;if(a)for(let s of Object.keys(a))i.add(s.toLowerCase());for(let s=0;s<n.length-1;s++){let l=n[s];if(!(l.kind==="keyword"&&l.normalized?.toLowerCase()==="on"))continue;let d=n[s+1],u=d.value.toLowerCase(),f=d.normalized?.toLowerCase();if(!(!!f&&R.KNOWN_EVENTS.has(f)||R.KNOWN_EVENTS.has(u)||i.has(u)))continue;let p=f&&R.KNOWN_EVENTS.has(f)?f:a?.[u]??u,h=n.filter((T,C)=>C!==s&&C!==s+1);if(h.length===0)return null;let y=r.filter(T=>T.command!=="on"),g=new X(h,t),x=this.parseBodyWithClauses(g,y,t);return x.length===0?null:me({type:"literal",value:p},x,void 0,{sourceLanguage:t,confidence:.75})}return null}trySOVEventExtraction(e,t,r){let n=R.SOV_EVENT_MARKERS[t];if(!n)return null;let i=G(e,t).tokens,s=Se[t],l=new Set;if(s)for(let S of Object.keys(s))l.add(S.toLowerCase());let c=R.SOV_SOURCE_MARKERS[t],d=-1,u="",f="",m=1,p=[];for(let S=0;S<i.length;S++){let k=i[S],E=k.value.toLowerCase(),v=E,b="",P=E.indexOf("[");P>0&&(v=E.slice(0,P),b=k.value.slice(P));let N=k.normalized?.toLowerCase(),z=N&&(R.KNOWN_EVENTS.has(N)||Re.has(N)),M=l.has(E)||l.has(v),O=R.KNOWN_EVENTS.has(v)||Re.has(v);if(z||M||O){let _=i[S-1];if(_&&(_.normalized??_.value).toLowerCase()==="event")continue;let I;z?I=N:M?I=s?.[E]??s?.[v]??v:I=v;let K=this.matchEventParamPhrase(i,S+1);if(n.size>0){let F=1+K.len,fe=i[S+F];fe&&fe.kind==="selector"&&fe.value.startsWith("[")&&(F+=1);let oe=i[S+F];if(oe&&(oe.kind==="particle"||oe.kind==="keyword")&&n.has(oe.value)){d=S,u=I,f=b||(F===K.len+2?i[S+F-1].value:""),m=F+1,p=K.names;break}}else{d=S,u=I,f=b,m=1+K.len+this.matchEventMarkerPhrase(i,S+1+K.len,t),p=K.names;break}}}if(d===-1){let S=new Set(r.filter(k=>k.command!=="on").map(k=>k.command));for(let k=0;k<i.length;k++){let E=i[k];if(E.kind==="identifier")if(n.size>0){let v=1,b=i[k+1];b&&b.kind==="selector"&&b.value.startsWith("[")&&(v=2);let P=i[k+v];if(P&&(P.kind==="particle"||P.kind==="keyword")&&n.has(P.value)){d=k,u=E.value,f=v===2?i[k+1].value:"",m=v+1;break}}else{let v=this.matchEventMarkerPhrase(i,k+1,t);if(v>0){d=k,u=E.value,f="",m=1+v;break}let b=i[k+1];if(b&&b.kind==="keyword"&&b.normalized!=null&&S.has(b.normalized)){d=k,u=E.value,f="",m=1;break}}}}if(d===-1)return null;let h=new Set;for(let S=d;S<d+m;S++)h.add(S);if(c){let S=d+m;if(S<i.length){let k=i[S];if((k.kind==="particle"||k.kind==="keyword")&&c.markers.has(k.value))h.add(S);else if(this.isStrippableSourceRef(k,c.windowTokens)){let E=i[S+1];E&&(E.kind==="particle"||E.kind==="keyword")&&c.markers.has(E.value)&&(h.add(S),h.add(S+1))}}if(d>=2){let k=i[d-1];(k.kind==="particle"||k.kind==="keyword")&&c.markers.has(k.value)&&this.isStrippableSourceRef(i[d-2],c.windowTokens)&&(h.add(d-2),h.add(d-1))}for(let k=0;k<d;k++){let E=i[k],v=E.value.toLowerCase(),b=E.normalized?.toLowerCase();if(c.windowTokens.has(v)||b&&c.windowTokens.has(b)){h.add(k);break}}}let y=i.filter((S,k)=>!h.has(k));if(y.length===0)return null;let g=r.filter(S=>S.command!=="on"),x=new X(y,t),T=this.parseBodyWithClauses(x,g,t);if(T.length===0)return null;let C={sourceLanguage:t,confidence:.75};return f&&(C.keyFilter=f),me({type:"literal",value:u},T,void 0,C,p)}profileKeywordMatches(e,t,r){let n=V(e)?.keywords?.[t];return n?n.primary?.toLowerCase()===r?!0:!!n.alternatives?.some(a=>a.toLowerCase()===r):!1}consumeForPostposition(e,t){let r=e.peek();if(!r)return;let n=(r.normalized??"").toLowerCase(),a=V(t)?.keywords?.for;(n==="for"||r.value===a?.primary||(a?.alternatives??[]).includes(r.value))&&e.advance()}isThenKeyword(e,t){let r=e.toLowerCase(),a={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","\uADF8\uB7EC\uBA74"]),zh:new Set(["\u7136\u540E","\u63A5\u7740","\u90A3\u4E48"]),tr:new Set(["ard\u0131ndan","daha sonra","ardindan"]),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"]),tl:new Set(["pagkatapos","tapos"]),bn:new Set(["\u09A4\u09BE\u09B0\u09AA\u09B0"]),qu:new Set(["chaymantataq","hinaspa","chaymanta","chayqa"]),sw:new Set(["kisha","halafu","baadaye"])}[t];return a?a.has(r):r==="then"||this.profileKeywordMatches(t,"then",r)}isElseKeyword(e,t){let r=e.toLowerCase();return r==="else"?!0:this.profileKeywordMatches(t,"else",r)}isEndKeyword(e,t){let r=e.toLowerCase(),a={en:new Set(["end"]),ja:new Set(["\u7D42\u308F\u308A","\u304A\u308F\u308A"]),ar:new Set(["\u0646\u0647\u0627\u064A\u0629","\u0627\u0646\u062A\u0647\u0649","\u0627\u0644\u0646\u0647\u0627\u064A\u0629"]),es:new Set(["fin","final","terminar"]),ko:new Set(["\uB05D","\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","fertig"]),id:new Set(["selesai","akhir","tamat"]),tl:new Set(["wakas","tapos"]),bn:new Set(["\u09B8\u09AE\u09BE\u09AA\u09CD\u09A4"]),qu:new Set(["tukukuy","tukuy","puchukay"]),sw:new Set(["mwisho","maliza","tamati"])}[t];return a?r==="end"||a.has(r):r==="end"||this.profileKeywordMatches(t,"end",r)}isJsKeyword(e){let t=(e.normalized??e.value).toLowerCase();return t==="js"||this.profileKeywordMatches("en","js",t)}consumeJsBlock(e,t){let r=e.peek();if(!r||!this.isJsKeyword(r))return null;let n=e.mark(),a=[];e.advance();let i=!1;for(;!e.isAtEnd();){let l=e.peek();if(!l)break;if(e.advance(),this.isEndKeyword(l.value,t)){i=!0;break}a.push(l)}if(!i)return e.reset(n),null;let s=a.map(l=>l.value).join(" ").trim();return H("js",{patient:{type:"expression",raw:s||"()"}},{sourceLanguage:t,patternId:`js-opaque-${t}`,confidence:1})}isIfKeyword(e,t){let r=e.toLowerCase();return r==="if"?!0:this.profileKeywordMatches(t,"if",r)}isUnlessKeyword(e,t){let r=e.toLowerCase();return r==="unless"?!0:this.profileKeywordMatches(t,"unless",r)}isBlockEndToken(e,t,r){return this.isEndKeyword(e.value,r)?!0:e.kind!=="keyword"||(e.normalized??"").toLowerCase()!=="end"?!1:!(t&&t.kind==="selector")}tryParseConditionalBlock(e,t,r){let n=e.peek();if(!n)return null;let a=(n.normalized??n.value).toLowerCase();if(!this.isIfKeyword(a,r))return null;let i=e.mark();e.advance();let s=[],l=0;for(;!e.isAtEnd();){let k=e.peek();if(!k)break;let E=(k.normalized??k.value).toLowerCase();if(this.isIfKeyword(E,r)||this.isUnlessKeyword(E,r)){l++,s.push(k),e.advance();continue}if(this.isBlockEndToken(k,e.peek(1)??void 0,r)){if(l===0){e.advance();break}l--,s.push(k),e.advance();continue}s.push(k),e.advance()}if(s.length===0)return e.reset(i),null;let c=V(r),d=c?.wordOrder==="SOV"?R.buildVerbLookup(c):null,u=0,f=0,m=[],p=!1;for(;u<s.length;u++){let k=s[u],E=(k.normalized??k.value).toLowerCase();if(this.isIfKeyword(E,r)||this.isUnlessKeyword(E,r)?f++:this.isBlockEndToken(k,s[u+1],r)&&f--,f===0&&this.isThenKeyword(k.value,r)){p=!0,u++;break}if(f===0&&m.length>0){let v=(s[u-1].normalized??s[u-1].value).toLowerCase(),b=s[u-1].value.toLowerCase(),P=(k.normalized??k.value).toLowerCase(),N=R.CONDITION_COPULAS.has(v)||R.CONDITION_COPULAS_SURFACE.has(b)&&R.CONDITION_PREDICATES.has(P),z=d!==null&&d.has(k.value.toLowerCase())&&!R.CONDITION_PREDICATES.has(P);if(!R.CONDITION_OPERATORS.has(P)&&(!N||z)&&(this.tokensBeginCommand(s.slice(u),t,r)||this.sovCommandStartsAt(s.slice(u),d)))break}m.push(k)}if(m.length===0)return e.reset(i),null;let h=[],y=[],g=!1,x=0;for(;u<s.length;u++){let k=s[u],E=(k.normalized??k.value).toLowerCase();if(this.isIfKeyword(E,r)||this.isUnlessKeyword(E,r)?x++:this.isBlockEndToken(k,s[u+1],r)&&x--,x===0&&!g&&this.isElseKeyword(k.value,r)){g=!0;continue}(g?y:h).push(k)}let T={type:"expression",raw:this.joinTokenText(m)},C=this.parseBranch(h,t,r),S=y.length>0?this.parseBranch(y,t,r):void 0;return C.length===0&&(!S||S.length===0)?(e.reset(i),null):yr(T,C,S,{sourceLanguage:r,patternId:`conditional-${r}-folded`,confidence:1})}joinTokenText(e){return e.map(t=>t.kind==="keyword"?t.normalized??t.value:t.value).join(" ").trim()}tokensBeginCommand(e,t,r){if(e.length===0)return!1;let n=new X(e,r);return se.matchBest(n,t)!==null}sovCommandStartsAt(e,t){if(!t)return!1;let r=s=>t.has(s.value.toLowerCase())||!!s.normalized&&t.has(s.normalized.toLowerCase()),n=s=>s.kind==="identifier"||s.kind==="selector"||s.kind==="literal"||s.kind==="reference",a=0,i=0;for(;a+1<e.length;){let s=e[a],l=e[a+1];if(!n(s)||l.kind!=="particle")break;i+=1,a+=2;let c=e[a];if(i>=1&&c&&r(c))return!0}return!1}parseBranch(e,t,r){if(e.length===0)return[];let n=new X(e,r),a=this.parseBodyWithClauses(n,t,r);return a.length===1&&a[0]?.kind==="compound"?a[0].statements:a}extractStandaloneModifiers(e,t){let n=G(e,t).tokens;if(n.length===0)return{modifiers:null,remainingInput:null};let i=n[0].value.toLowerCase(),s=R.STANDALONE_MODIFIERS[i];if(!s)return{modifiers:null,remainingInput:null};let l={},c=1;if(s==="once")l.once=!0;else{let m=1;if(m<n.length){let p=n[m];(p.kind==="keyword"||p.kind==="particle")&&(m++,c++)}if(m<n.length){let p=n[m];if(p.kind==="literal"){let h=p.value.match(/^(\d+)(ms|s|m)?$/);if(h){let y=parseInt(h[1],10),g=h[2]||"ms";g==="s"?y*=1e3:g==="m"&&(y*=6e4),l[s]=y,c=m+1}}}l[s]||(l[s]=s==="debounce"?300:100)}let d=n.slice(c);if(d.length===0)return{modifiers:null,remainingInput:null};let u=d[0].position.start,f=e.slice(u);return{modifiers:l,remainingInput:f}}stripAsyncModifier(e,t){let r=V(t)?.keywords?.async,n=new Set(["async"]);r?.primary&&n.add(r.primary.toLowerCase()),r?.alternatives?.forEach(c=>n.add(c.toLowerCase()));let a=G(e,t).tokens,i=a.findIndex(c=>n.has(c.value.toLowerCase()));if(i===-1)return{remainingInput:null};let s=a[i],l=(e.slice(0,s.position.start)+e.slice(s.position.end)).replace(/\s{2,}/g," ").trim();return l.length===0?{remainingInput:null}:{remainingInput:l}}stripDoNotThrowModifier(e,t){let r=G(e,t).tokens;for(let n=0;n<r.length-1;n++){if(r[n].value.toLowerCase()!=="do")continue;let a=-1;for(let c=n+1;c<=n+5&&c<r.length;c++){let d=r[c];if(d.normalized?.toLowerCase()==="throw"){a=c;break}let u=d.kind;if(u==="selector"||u==="literal"||u==="reference"||u==="conjunction")break}if(a===-1)continue;let i=r[n].position.start,s=r[a].position.end,l=(e.slice(0,i)+e.slice(s)).replace(/\s{2,}/g," ").trim();return l.length===0?{remainingInput:null}:{remainingInput:l}}return{remainingInput:null}}applyModifiers(e,t){return{...e,eventModifiers:{...e.eventModifiers,...t}}}extractOrConjunctionEvents(e,t){let r=[];for(;;){let n=e.mark(),a=e.peek();if(!a)break;let i=(a.normalized||a.value).toLowerCase();if(!R.OR_KEYWORDS.has(i)){e.reset(n);break}e.advance();let s=e.peek();if(!s){e.reset(n);break}let l=(s.normalized||s.value).toLowerCase();e.advance(),r.push({type:"literal",value:l})}return r}};R.KNOWN_EVENTS=new Set(["click","dblclick","input","change","submit","keydown","keyup","keypress","mouseover","mouseout","mousedown","mouseup","focus","blur","load","scroll","resize","contextmenu"]),R.RESPONSE_TYPE_WORDS=new Set(["json","text","html","xml","blob","arraybuffer","formdata","response"]),R.SOV_EVENT_MARKERS={ja:new Set(["\u3067"]),ko:new Set,tr:new Set(["de","da","te","ta"]),bn:new Set(["\u098F"]),qu:new Set(["pi"]),hi:new Set(["\u092A\u0930"])},R.SOV_EVENT_MARKER_PHRASES={ko:[["\uD560","\uB54C"],["\uD560\uB54C"]]},R.SOV_SOURCE_MARKERS={ja:{markers:new Set(["\u304B\u3089"]),windowTokens:new Set(["\u30A6\u30A3\u30F3\u30C9\u30A6","\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8","window","document"])},ko:{markers:new Set(["\uC5D0\uC11C"]),windowTokens:new Set(["\uCC3D","\uC708\uB3C4\uC6B0","\uBB38\uC11C","window","document"])},tr:{markers:new Set(["den","dan","ten","tan"]),windowTokens:new Set(["pencere","belge","window","document"])},bn:{markers:new Set(["\u09A5\u09C7\u0995\u09C7","\u09AE\u09A7\u09CD\u09AF\u09C7"]),windowTokens:new Set(["\u0989\u0987\u09A8\u09CD\u09A1\u09CB","\u09A1\u0995\u09C1\u09AE\u09C7\u09A8\u09CD\u099F","window","document"])},qu:{markers:new Set(["manta"]),windowTokens:new Set(["k_iri","ventana","window","document"])},hi:{markers:new Set(["\u0938\u0947"]),windowTokens:new Set(["\u0935\u093F\u0902\u0921\u094B","\u0926\u0938\u094D\u0924\u093E\u0935\u0947\u091C\u093C","window","document"])}},R.CONDITION_COPULAS=new Set(["is","am","are","be","was","were","not","no"]),R.CONDITION_COPULAS_SURFACE=new Set(["est","\u0435\u0441\u0442\u044C","\u0454","\xE9","ay","\u0647\u0648","adalah","\u0E40\u0E1B\u0E47\u0E19","\u09B9\u09AF\u09BC","\u0939\u0948","dir","kanqa"]),R.CONDITION_PREDICATES=new Set(["empty","null","undefined"]),R.CONDITION_OPERATORS=new Set(["matches","match","contains","exists","has","have","equals","includes"]),R.STANDALONE_MODIFIERS={once:"once",debounced:"debounce",debounce:"debounce",throttled:"throttle",throttle:"throttle"},R.OR_KEYWORDS=new Set(["or","\u0623\u0648","o","ou","oder","atau","atau","\u6216","\u307E\u305F\u306F","\uB610\uB294","veya","\u0985\u09A5\u09AC\u09BE","utaq","au","\u0430\u0431\u043E","\u0438\u043B\u0438","ho\u1EB7c","lub","\u05D0\u05D5","\u0E2B\u0E23\u0E37\u0E2D","o","\u092F\u093E","\u0985\u09A5\u09AC\u09BE"]);var dt=R,$t=new dt;function Ae(o,e){return $t.parse(o,e)}function Dt(o,e){return $t.canParse(o,e)}function jt(o,e){if(de(o))return o;let t=Ae(o,e);return Fe(t)}function Wt(o,e){let t=Pe(o);return Ue(t,e)}function Kt(o,e){return de(o)?Pe(o):Ae(o,e)}vt("qu",it,ve);var ri="1.0.0-qu",ni=["qu"];function oi(){return[...ni]}function qr(o){if(o!=="qu")throw new Error(`Language not supported in this bundle: ${o}. Supported: qu`)}function ai(o,e){return qr(e),[...G(o,e).tokens]}function Br(o){return qr(o),Q(o)}function ii(o,e){return Br(o).filter(t=>t.command===e).sort((t,r)=>r.priority-t.priority)}return Fr(si);})();