@lokascript/hyperscript-adapter 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +183 -3
  2. package/dist/hyperscript-i18n-ar.global.js +4 -4
  3. package/dist/hyperscript-i18n-bn.global.js +4 -4
  4. package/dist/hyperscript-i18n-de.global.js +4 -4
  5. package/dist/hyperscript-i18n-east-asian.global.js +4 -4
  6. package/dist/hyperscript-i18n-en.global.js +6 -6
  7. package/dist/hyperscript-i18n-es.global.js +4 -4
  8. package/dist/hyperscript-i18n-fr.global.js +4 -4
  9. package/dist/hyperscript-i18n-he.global.js +4 -4
  10. package/dist/hyperscript-i18n-hi.global.js +4 -4
  11. package/dist/hyperscript-i18n-id.global.js +4 -4
  12. package/dist/hyperscript-i18n-it.global.js +4 -4
  13. package/dist/hyperscript-i18n-ja.global.js +4 -4
  14. package/dist/hyperscript-i18n-ko.global.js +4 -4
  15. package/dist/hyperscript-i18n-ms.global.js +5 -5
  16. package/dist/hyperscript-i18n-pl.global.js +4 -4
  17. package/dist/hyperscript-i18n-pt.global.js +4 -4
  18. package/dist/hyperscript-i18n-qu.global.js +4 -4
  19. package/dist/hyperscript-i18n-ru.global.js +4 -4
  20. package/dist/hyperscript-i18n-slavic.global.js +4 -4
  21. package/dist/hyperscript-i18n-south-asian.global.js +4 -4
  22. package/dist/hyperscript-i18n-southeast-asian.global.js +4 -4
  23. package/dist/hyperscript-i18n-sw.global.js +4 -4
  24. package/dist/hyperscript-i18n-th.global.js +5 -5
  25. package/dist/hyperscript-i18n-tl.global.js +4 -4
  26. package/dist/hyperscript-i18n-tr.global.js +4 -4
  27. package/dist/hyperscript-i18n-uk.global.js +4 -4
  28. package/dist/hyperscript-i18n-vi.global.js +5 -5
  29. package/dist/hyperscript-i18n-western.global.js +4 -4
  30. package/dist/hyperscript-i18n-zh.global.js +4 -4
  31. package/dist/hyperscript-i18n.global.js +24 -24
  32. package/dist/hyperscript-i18n.global.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/generated/syntax-table.ts +0 -1
@@ -1,5 +1,5 @@
1
1
  var HyperscriptI18n=(function(exports){'use strict';function le(i,e){return e?{type:"literal",value:i,dataType:e}:{type:"literal",value:i}}function Ze(i,e){return e?{type:"selector",value:i,selectorKind:e}:{type:"selector",value:i}}function _e(i){return {type:"reference",value:i}}function Je(i,e){return {type:"property-path",object:i,property:e}}var Ur=new Set(["me","you","it","result","event","target","body","document","window","detail"]);function fr(i,e=Ur){return e.has(i)}var xi=class{constructor(i){this.namespace=i,this.enabled=this.checkEnabled();}checkEnabled(){if(typeof process<"u"&&process.env){let i=process.env.DEBUG||"";return i==="*"||i.includes("framework:*")||i.includes(`framework:${this.namespace}`)}return false}log(i,e,...r){if(!this.enabled)return;let t=`[framework:${this.namespace}]`,n=new Date().toISOString();switch(i){case "debug":console.debug(`${n} ${t} DEBUG:`,e,...r);break;case "info":console.info(`${n} ${t} INFO:`,e,...r);break;case "warn":console.warn(`${n} ${t} WARN:`,e,...r);break;case "error":console.error(`${n} ${t} ERROR:`,e,...r);break}}debug(i,...e){this.log("debug",i,...e);}info(i,...e){this.log("info",i,...e);}warn(i,...e){this.log("warn",i,...e);}error(i,...e){this.log("error",i,...e);}isEnabled(){return this.enabled}enable(){this.enabled=true;}disable(){this.enabled=false;}};function Ti(i){return new xi(i)}function Ae(i,e){return !e||e.length===0||e.includes(i)||e.includes("expression")?true:i==="property-path"?e.some(r=>["selector","reference","expression"].includes(r)):false}function Fi(i,e){return i?.possessive?.keywords?.[e]}var je=class De{constructor(){this.logger=Ti("pattern-matcher"),this.stemMatchCount=0,this.totalKeywordMatches=0;}safeToLowerCase(e){return typeof e=="string"?e.toLowerCase():e==null?"":String(e).toLowerCase()}matchPattern(e,r,t){let n=e.mark(),a=new Map;if(this.logger.debug("========================================"),this.logger.debug("matchPattern ENTRY"),this.logger.debug("Pattern ID:",r.id),this.logger.debug("Pattern command:",r.command),this.logger.debug("Pattern language:",r.language),this.logger.debug("Pattern template:",JSON.stringify(r.template,null,2)),this.logger.isEnabled()){let s=[];for(let l=0;l<10;l++){let c=e.peek(l);if(c)s.push({type:c.type,value:c.value,kind:c.kind});else break}this.logger.debug("Input tokens (first 10):",s),this.logger.debug("Profile code:",t?.code);}this.currentProfile=t,this.stemMatchCount=0,this.totalKeywordMatches=0,this.logger.debug("--- Calling matchTokenSequence ---"),this.logger.debug("Pattern tokens to match:",JSON.stringify(r.template.tokens,null,2));let o=this.matchTokenSequence(e,r.template.tokens,a);if(this.logger.debug("matchTokenSequence returned:",o),this.logger.debug("Captured roles:",Array.from(a.entries()).map(([s,l])=>[s,JSON.stringify(l)])),!o)return this.logger.debug(">>> MATCH FAILED - resetting token position"),e.reset(n),null;let u=this.calculateConfidence(r,a);return this.applyExtractionRules(r,a),{pattern:r,captured:a,consumedTokens:e.position()-n.position,confidence:u}}matchBest(e,r,t){let n=[];for(let o of r){let u=e.mark(),s=this.matchPattern(e,o,t);s&&n.push(s),e.reset(u);}if(n.length===0)return null;n.sort((o,u)=>{let s=u.pattern.priority-o.pattern.priority;if(s!==0)return s;let l=u.confidence-o.confidence;return Math.abs(l)>.001?l:u.consumedTokens-o.consumedTokens});let a=n[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,r,t,n){let a=r[0],o=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!o)for(;e.peek()?.kind==="conjunction";)e.advance();let u=null,s=null;for(let l=0;l<r.length;l++){let c=r[l];this.logger.debug(" >> Matching pattern token:",JSON.stringify(c,null,2));let m=e.peek();if(this.logger.debug(" >> Current input token:",m?JSON.stringify({type:m.type,value:m.value,kind:m.kind}):"EOF"),c.type==="role"&&c.greedy){let E=this.collectStopMarkers(r,l+1);if(n)for(let h of n)E.add(h);let y=[];for(;!e.isAtEnd();){let h=e.peek();if(!h||this.isStopMarker(h,E))break;y.push(h.value),e.advance();}if(y.length>0){t.set(c.role,{type:"expression",raw:y.join(" ")}),u=null,s=null;continue}else {if(c.optional)continue;return false}}if(c.type==="group"){let E=this.collectStopMarkers(r,l+1);if(n)for(let h of n)E.add(h);if(this.matchGroupToken(e,c,t,E)){u=null,s=null;continue}if(this.isOptional(c))continue;return false}let d=c.type==="role"&&c.optional===true,p=d?e.mark():null;if(c.type==="role"&&!d){let E=l+1<r.length?r[l+1]:null;if(E?.type==="literal"){let y=e.peek();if(y&&this.getMatchType(y,E.value)!=="none"){if(this.logger.debug(" >> MARKER-STEAL GUARD: current token matches next literal, skipping role"),this.logger.debug(" >> Token match FAILED"),this.isOptional(c))continue;if(u&&s){this.logger.debug(" >> BACKTRACKING: undoing optional role",s),e.reset(u),t.delete(s),u=null,s=null;let h=this.matchPatternToken(e,c,t);if(this.logger.debug(" >> Backtrack retry result:",h),h)continue}return false}}}let v=this.matchPatternToken(e,c,t);if(this.logger.debug(" >> Match result:",v),v){d?(u=p,s=c.role):(u=null,s=null);continue}if(this.logger.debug(" >> Token match FAILED"),!this.isOptional(c)){if(u&&s){this.logger.debug(" >> BACKTRACKING: undoing optional role",s),e.reset(u),t.delete(s),u=null,s=null;let E=this.matchPatternToken(e,c,t);if(this.logger.debug(" >> Backtrack retry result:",E),E)continue}return false}}return true}matchPatternToken(e,r,t){switch(r.type){case "literal":return this.matchLiteralToken(e,r);case "role":return this.matchRoleToken(e,r,t);case "group":return this.matchGroupToken(e,r,t);default:return false}}matchLiteralToken(e,r){let t=e.peek();if(this.logger.debug(" >>> matchLiteralToken: expecting",r.value),this.logger.debug(" >>> matchLiteralToken: got token",t?JSON.stringify({type:t.type,value:t.value,kind:t.kind}):"null"),!t)return this.logger.debug(" >>> matchLiteralToken: FAIL - no token"),false;let n=this.getMatchType(t,r.value);if(this.logger.debug(" >>> matchType for",t.value,"vs",r.value,":",n),n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),true;if(r.alternatives)for(let a of r.alternatives){let o=this.getMatchType(t,a);if(o!=="none")return this.totalKeywordMatches++,o==="stem"&&this.stemMatchCount++,e.advance(),true}return false}matchRoleToken(e,r,t){this.logger.debug(" >>> matchRoleToken ENTRY: capturing role",r.role),this.logger.debug(" >>> matchRoleToken: expected types",r.expectedTypes),this.logger.debug(" >>> matchRoleToken: optional?",r.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 r.optional||false;let a=this.tryMatchPossessiveExpression(e);if(a)return r.expectedTypes&&r.expectedTypes.length>0&&!Ae(a.type,r.expectedTypes)?r.optional||false:(t.set(r.role,a),true);let o=this.tryMatchMethodCallExpression(e);if(o)return r.expectedTypes&&r.expectedTypes.length>0&&!Ae(o.type,r.expectedTypes)?r.optional||false:(t.set(r.role,o),true);let u=this.tryMatchPossessiveSelectorExpression(e);if(u)return r.expectedTypes&&r.expectedTypes.length>0&&!Ae(u.type,r.expectedTypes)?r.optional||false:(t.set(r.role,u),true);let s=this.tryMatchPropertyAccessExpression(e);if(s)return r.expectedTypes&&r.expectedTypes.length>0&&!Ae(s.type,r.expectedTypes)?r.optional||false:(t.set(r.role,s),true);let l=this.tryMatchSelectorPropertyExpression(e);if(l)return r.expectedTypes&&r.expectedTypes.length>0&&!Ae(l.type,r.expectedTypes)?r.optional||false:(t.set(r.role,l),true);this.logger.debug(" >>> Trying tokenToSemanticValue for token:",n?JSON.stringify({value:n.value,kind:n.kind}):"null");let c=this.tokenToSemanticValue(n);return this.logger.debug(" >>> tokenToSemanticValue returned:",c?JSON.stringify(c):"null"),c?(this.logger.debug(" >>> Validating type:",c.type,"against expected:",r.expectedTypes),r.expectedTypes&&r.expectedTypes.length>0&&!Ae(c.type,r.expectedTypes)?(this.logger.debug(" >>> TYPE MISMATCH - returning",r.optional||false),r.optional||false):(this.logger.debug(" >>> Type validation PASSED"),t.set(r.role,c),e.advance(),true)):r.optional||false}tryMatchPossessiveExpression(e){let r=e.peek();if(!r||!this.currentProfile)return null;let t=r.normalized||r.value,n=this.safeToLowerCase(t),a=Fi(this.currentProfile,n);if(!a)return null;let o=e.mark();e.advance();let u=e.peek();if(!u)return e.reset(o),null;if(u.kind==="identifier"||u.kind==="keyword"&&!this.isStructuralKeyword(u.value)||u.kind==="selector"&&u.value.startsWith("*")||u.kind==="selector"&&u.value.startsWith("@")||u.kind==="selector"&&u.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(u.value)){e.advance();let s=u.value;u.kind==="selector"&&s.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s)&&(s=s.substring(1));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();return c?.kind==="literal"&&c.value.startsWith("(")&&(l+=c.value,e.advance()),Je(_e(a),l)}return e.reset(o),null}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){let r=e.peek();if(!r||r.kind!=="selector")return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(t),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(t),null;e.advance();let o=e.peek();if(!o||o.kind!=="punctuation"||o.value!=="(")return e.reset(t),null;e.advance();let u=[];for(;!e.isAtEnd()&&u.length<De.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}u.push(l.value),e.advance();}return {type:"expression",raw:`${r.value}.${a.value}(${u.join(", ")})`}}tryMatchPropertyAccessExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"&&r.kind!=="keyword")return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(t),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(t),null;e.advance();let o=`${r.value}.${a.value}`,u=1;for(;!e.isAtEnd()&&u<De.MAX_PROPERTY_DEPTH;){let l=e.peek();if(!l||l.kind!=="operator"||l.value!==".")break;e.advance();let c=e.peek();if(!c||c.kind!=="identifier")break;e.advance(),o+=`.${c.value}`,u++;}let s=e.peek();if(s&&s.kind==="punctuation"&&s.value==="("){e.advance();let l=[],c=0;for(;!e.isAtEnd()&&l.length<De.MAX_METHOD_ARGS;){let d=e.peek();if(!d)break;if(d.kind==="punctuation"&&d.value===")"){if(c===0){e.advance();break}c--;}if(d.kind==="punctuation"&&d.value==="("&&c++,d.kind==="punctuation"&&d.value===","){e.advance();continue}l.push(d.value),e.advance();}return {type:"expression",raw:`${o}(${l.join(", ")})`}}return {type:"expression",raw:o}}tryMatchPossessiveSelectorExpression(e){let r=e.peek();if(!r||r.kind!=="selector")return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="punctuation"||n.value!=="'s")return e.reset(t),null;e.advance();let a=e.peek();return !a||a.kind!=="selector"&&a.kind!=="identifier"?(e.reset(t),null):(e.advance(),Je(Ze(r.value),a.value))}tryMatchSelectorPropertyExpression(e){let r=e.peek();if(!r||r.kind!=="selector"||typeof r.value!="string"||!r.value.startsWith("#"))return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(t),null;let a=e.peek(1);a&&a.kind,e.advance();let o=n.value.slice(1);return Je(Ze(r.value),o)}matchGroupToken(e,r,t,n){let a=e.mark(),o=new Set(t.keys());if(this.matchTokenSequence(e,r.tokens,t,n))return true;e.reset(a);for(let l of t.keys())o.has(l)||t.delete(l);if(!r.optional)return false;let s=this.getGroupLeadingMarker(r);if(s)for(let l=1;l<=De.MAX_MARKER_SCAN;l++){let c=e.peek(l);if(!c)break;if((c.normalized||c.value).toLowerCase()===s){this.logger.debug(" >> MARKER SCAN: found",s,"at offset",l,"- skipping intervening tokens");for(let p=0;p<l;p++)e.advance();if(this.matchTokenSequence(e,r.tokens,t,n))return true;e.reset(a);for(let p of t.keys())o.has(p)||t.delete(p);break}}return true}getGroupLeadingMarker(e){let r=e.tokens[0];return r?.type==="literal"?r.value.toLowerCase():null}getMatchType(e,r){return e.value===r?"exact":e.normalized===r?"normalized":e.stem===r&&e.stemConfidence!==void 0&&e.stemConfidence>=.7?"stem":e.kind==="keyword"&&this.safeToLowerCase(e.value)===r.toLowerCase()?"case-insensitive":"none"}collectStopMarkers(e,r){let t=new Set;for(let n=r;n<e.length;n++){let a=e[n];if(a.type==="literal"){if(t.add(a.value.toLowerCase()),a.alternatives)for(let o of a.alternatives)t.add(o.toLowerCase());break}if(a.type==="group"){for(let o of a.tokens)if(o.type==="literal"){if(t.add(o.value.toLowerCase()),o.alternatives)for(let u of o.alternatives)t.add(u.toLowerCase());break}if(!a.optional)break}}return t}isStopMarker(e,r){return r.size===0?false:!!(r.has(e.value.toLowerCase())||e.normalized&&r.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 r=e.normalized||e.value;this.safeToLowerCase(r);return le(e.normalized||e.value);case "identifier":if(typeof e.value=="string"&&e.value.startsWith(":"))return _e(e.value);this.safeToLowerCase(e.value);return {type:"expression",raw:e.value};case "url":return le(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 le(n,"string")}if(e==="true")return le(true,"boolean");if(e==="false")return le(false,"boolean");let r=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(r){let n=parseFloat(r[1]);return r[2]?le(e,"duration"):le(n,"number")}let t=parseFloat(e);return isNaN(t)?le(e,"string"):le(t,"number")}applyExtractionRules(e,r){for(let[t,n]of Object.entries(e.extraction))r.has(t)||(n.value!==void 0?r.set(t,{type:"literal",value:n.value}):n.default&&r.set(t,n.default));}isOptional(e){return e.type!=="literal"&&e.optional===true}calculateConfidence(e,r){let t=0,n=0,a=l=>e.extraction?.[l]?.default!==void 0;for(let l of e.template.tokens)if(l.type==="role")n+=1,r.has(l.role)&&(t+=1);else if(l.type==="group"){for(let c of l.tokens)if(c.type==="role"){let m=a(c.role),d=.8;n+=d,r.has(c.role)?t+=d:m&&(t+=d*.6);}}let o=n>0?t/n:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){let l=this.stemMatchCount/this.totalKeywordMatches*.15;o=Math.max(.5,o-l);}let u=this.calculateVSOConfidenceBoost(e);o=Math.min(1,o+u);let s=this.arabicPrepositionDisambiguation(e,r);return o=Math.max(0,Math.min(1,o+s)),o}calculateVSOConfidenceBoost(e){if(e.language!=="ar")return 0;let r=e.template.tokens[0];if(!r||r.type!=="literal")return 0;let t=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(t.has(r.value))return .15;if(r.alternatives){for(let n of r.alternatives)if(t.has(n))return .15}return 0}arabicPrepositionDisambiguation(e,r){if(e.language!=="ar")return 0;let t=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,o]of r.entries()){let u=n[a];if(!u||u.length===0)continue;let s="metadata"in o?o.metadata:void 0;if(s&&typeof s.prepositionValue=="string"){let l=s.prepositionValue;u.includes(l)?t+=.1:t-=.1;}}return Math.max(-0.1,Math.min(.1,t))}skipNoiseWords(e){let r=e.peek();if(!r)return;let t=this.safeToLowerCase(r.value);if(De.ENGLISH_NOISE_WORDS.has(t)){let n=e.mark();e.advance();let a=e.peek();if(a&&a.kind==="selector")return;e.reset(n);}t==="class"&&e.advance();}extractEventModifiers(e){let r={},t=false;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(t=true,a.modifierName){case "once":r.once=true;break;case "debounce":typeof a.value=="number"&&(r.debounce=a.value);break;case "throttle":typeof a.value=="number"&&(r.throttle=a.value);break;case "queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(r.queue=a.value);break}e.advance();}return t?r:void 0}};je.MAX_MARKER_SCAN=3;je.MAX_PROPERTY_DEPTH=10;je.MAX_METHOD_ARGS=20;je.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Ri=je;new Ri;var Zr=class{constructor(){this.name="string-literal";}canExtract(i,e){let r=i[e];return r==="'"&&e>0&&/[\p{L}\p{N}_)\]]/u.test(i[e-1])?false:r==='"'||r==="'"||r==="`"||r==="\u201C"||r==="\u2018"}extract(i,e){let r=i[e];if(r==="\u201C"){let a=1;for(;e+a<i.length;){if(i[e+a]==="\u201D")return a++,{value:i.substring(e,e+a),length:a};a++;}return null}if(r==="\u2018"){let a=1;for(;e+a<i.length;){if(i[e+a]==="\u2019")return a++,{value:i.substring(e,e+a),length:a};a++;}return null}let t=1,n=false;for(;e+t<i.length;){let a=i[e+t];if(n){n=false,t++;continue}if(a==="\\"){n=true,t++;continue}if(a===r)return t++,{value:i.substring(e,e+t),length:t};t++;}return null}},Jr=class{constructor(){this.name="number";}canExtract(i,e){return /\d/.test(i[e])}extract(i,e){let r=0,t=false;for(;e+r<i.length;){let o=i[e+r];if(/\d/.test(o))r++;else if(o==="."&&!t)t=true,r++;else break}if(r===0)return null;let n=i.substring(e,e+r),a=e+r;if(a<i.length){let o=i.slice(a),u=[{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 l of u)if(o.startsWith(l.pattern))return {value:n+l.suffix,length:r+l.pattern.length,metadata:{hasTimeUnit:true}};if(o.startsWith("ms"))return {value:n+"ms",length:r+2,metadata:{hasTimeUnit:true}};let s=[{pattern:"\u79D2",suffix:"s"},{pattern:"\u5206",suffix:"m"}];for(let l of s)if(o.startsWith(l.pattern))return {value:n+l.suffix,length:r+1,metadata:{hasTimeUnit:true}};if(/^[smh](?![a-zA-Z])/.test(o))return {value:n+o[0],length:r+1,metadata:{hasTimeUnit:true}}}return {value:n,length:r}}};function Oi(i){return "setContext"in i&&typeof i.setContext=="function"}function Pi(i){let e={language:i.language,direction:i.direction,lookupKeyword:i.lookupKeyword.bind(i),isKeyword:i.isKeyword.bind(i),isKeywordStart:i.isKeywordStart.bind(i),...i.isKeywordStartAtBoundary?{isKeywordStartAtBoundary:i.isKeywordStartAtBoundary.bind(i)}:{}};return i.normalizer?{...e,normalizer:i.normalizer}:e}var ie=class{constructor(i,e){this.pos=0,this.tokens=i,this.language=e;}peek(i=0){let e=this.pos+i;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(i){this.pos=i.position;}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(i){let e=[];for(;!this.isAtEnd()&&i(this.peek());)e.push(this.advance());return e}skipWhile(i){for(;!this.isAtEnd()&&i(this.peek());)this.advance();}};function U(i,e){return {start:i,end:e}}function G(i,e,r,t){if(typeof i=="object"){let{value:a,kind:o,position:u,normalized:s,stem:l,stemConfidence:c,metadata:m}=i;return {value:a,kind:o,position:u,...s!==void 0&&{normalized:s},...l!==void 0&&{stem:l},...c!==void 0&&{stemConfidence:c},...m!==void 0&&{metadata:m}}}let n=i;if(!e||!r)throw new Error("createToken requires kind and position parameters");if(typeof t=="string")return {value:n,kind:e,position:r,normalized:t};if(t){let{normalized:a,stem:o,stemConfidence:u,metadata:s}=t;return {value:n,kind:e,position:r,...a!==void 0&&{normalized:a},...o!==void 0&&{stem:o},...u!==void 0&&{stemConfidence:u},...s!==void 0&&{metadata:s}}}return {value:n,kind:e,position:r}}function Ie(i){return /\s/.test(i)}function Li(i){return i==="#"||i==="."||i==="["||i==="@"||i==="*"||i==="<"}function Ni(i){return i==='"'||i==="'"||i==="`"||i==="\u300C"||i==="\u300D"}function Ee(i){return /\d/.test(i)}function Qe(i){return i.replace(/[\u064b-\u0652\u0670]/g,"")}function Mi(i){return /[a-zA-Z]/.test(i)}function te(i){return /[a-zA-Z0-9_-]/.test(i)}function _i(i,e){if(e>=i.length)return null;let r=i[e];if(!Li(r))return null;let t=e,n="";if(r==="#"||r==="."){for(n+=i[t++];t<i.length&&te(i[t]);)n+=i[t++];if(n.length<=1)return null;if(t<i.length&&i[t]==="."&&r==="#"){let o=t+1;for(;o<i.length&&te(i[o]);)o++;if(o<i.length&&i[o]==="(")return n}}else if(r==="["){let a=1,o=false,u=null,s=false;for(n+=i[t++];t<i.length&&a>0;){let l=i[t];n+=l,s?s=false:l==="\\"?s=true:o?l===u&&(o=false,u=null):l==='"'||l==="'"||l==="`"?(o=true,u=l):l==="["?a++:l==="]"&&a--,t++;}if(a!==0)return null}else if(r==="@"){for(n+=i[t++];t<i.length&&te(i[t]);)n+=i[t++];if(n.length<=1)return null}else if(r==="*"){for(n+=i[t++];t<i.length&&te(i[t]);)n+=i[t++];if(n.length<=1)return null}else if(r==="<"){if(n+=i[t++],t>=i.length||!Mi(i[t]))return null;for(;t<i.length&&te(i[t]);)n+=i[t++];for(;t<i.length;){let a=i[t];if(a==="."){if(n+=i[t++],t>=i.length||!te(i[t]))return null;for(;t<i.length&&te(i[t]);)n+=i[t++];}else if(a==="#"){if(n+=i[t++],t>=i.length||!te(i[t]))return null;for(;t<i.length&&te(i[t]);)n+=i[t++];}else if(a==="["){let o=1,u=false,s=null,l=false;for(n+=i[t++];t<i.length&&o>0;){let c=i[t];n+=c,l?l=false:c==="\\"?l=true:u?c===s&&(u=false,s=null):c==='"'||c==="'"||c==="`"?(u=true,s=c):c==="["?o++:c==="]"&&o--,t++;}if(o!==0)return null}else break}for(;t<i.length&&Ie(i[t]);)n+=i[t++];if(t<i.length&&i[t]==="/")for(n+=i[t++];t<i.length&&Ie(i[t]);)n+=i[t++];if(t>=i.length||i[t]!==">")return null;n+=i[t++];}return n||null}function Ii(i,e){if(e>=i.length||i[e]!=="'"||e+1>=i.length||i[e+1].toLowerCase()!=="s")return false;if(e+2>=i.length)return true;let t=i[e+2];return Ie(t)||t==="*"||!te(t)}function ji(i,e){if(e>=i.length)return null;let r=i[e];if(!Ni(r)||r==="'"&&Ii(i,e))return null;let n={'"':'"',"'":"'","`":"`","\u300C":"\u300D"}[r];if(!n)return null;let a=e+1,o=r,u=false;for(;a<i.length;){let s=i[a];if(o+=s,u)u=false;else if(s==="\\")u=true;else if(s===n)return o;a++;}return o}function $i(i,e){if(e>=i.length)return false;let r=i[e],t=i[e+1]||"",n=i[e+2]||"";if(r==="/"&&t!=="/"&&/[a-zA-Z0-9._-]/.test(t)||r==="/"&&t==="/"&&/[a-zA-Z]/.test(n)||r==="."&&(t==="/"||t==="."&&n==="/"))return true;let a=i.slice(e,e+8).toLowerCase();return !!(a.startsWith("http://")||a.startsWith("https://"))}function Vi(i,e){if(!$i(i,e))return null;let r=e,t="",n=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;r<i.length;){let a=i[r];if(a==="#"){if(t.length>0&&/[a-zA-Z0-9/.]$/.test(t))for(t+=a,r++;r<i.length&&/[a-zA-Z0-9_-]/.test(i[r]);)t+=i[r++];break}if(n.test(a))t+=a,r++;else break}return t.length<2?null:t}function qi(i,e){if(e>=i.length)return null;let r=i[e];if(!Ee(r)&&r!=="-"&&r!=="+")return null;let t=e,n="";if((i[t]==="-"||i[t]==="+")&&(n+=i[t++]),t>=i.length||!Ee(i[t]))return null;for(;t<i.length&&Ee(i[t]);)n+=i[t++];if(t<i.length&&i[t]===".")for(n+=i[t++];t<i.length&&Ee(i[t]);)n+=i[t++];return t<i.length&&(i.slice(t,t+2)==="ms"?n+="ms":(i[t]==="s"||i[t]==="m"||i[t]==="h")&&(n+=i[t])),n}var Wi=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"];new Set(Wi);var Ki=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"]);function Hi(i){return i.includes("-")&&/^[\p{L}\p{N}_]+(-[\p{L}\p{N}_]+)+$/u.test(i)}var Ui=["click","dblclick","input","change","submit","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave","mousemove","pointerdown","pointerup","pointermove","focus","blur","load","resize","scroll"],er=class Xe{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){Oi(e)&&e.setContext(Pi(this)),this.extractors.push(e);}registerExtractors(e){for(let r of e)this.registerExtractor(r);}clearExtractors(){this.extractors=[];}isUsingExtractors(){return this.extractors.length>0}tokenizeWithExtractors(e){let r=[],t=0;for(;t<e.length;){for(;t<e.length&&Ie(e[t]);)t++;if(t>=e.length)break;let n=this.tryMultiWordKeyword(e,t);if(n){r.push(n),t=n.position.end;continue}let a=false;for(let o of this.extractors)if(o.canExtract(e,t)){let u=o.extract(e,t);if(u){let s=u.metadata?.normalized,l=u.metadata?.stem,c=u.metadata?.stemConfidence,m={};if(u.metadata)for(let[p,f]of Object.entries(u.metadata))p!=="normalized"&&p!=="stem"&&p!=="stemConfidence"&&(m[p]=f);let d={};s&&(d.normalized=s),l&&(d.stem=l),c!==void 0&&(d.stemConfidence=c),Object.keys(m).length>0&&(d.metadata=m),r.push(G(u.value,this.classifyToken(u.value),U(t,t+u.length),Object.keys(d).length>0?d:void 0)),t+=u.length,a=true;break}}if(!a){let o=e[t],u=this.classifyUnknownChar(o);r.push(G(o,u,U(t,t+1))),t++;}}return new ie(this.mergeColonQualifiedNames(r),this.language)}mergeColonQualifiedNames(e){let r=[];for(let t of e){let n=r[r.length-1];if(n&&Xe.ASCII_WORD.test(n.value)&&Xe.COLON_QUALIFIER.test(t.value)&&n.position.end===t.position.start){let a=n.value+t.value;r[r.length-1]=G(a,this.classifyToken(a),U(n.position.start,t.position.end));continue}r.push(t);}return r}classifyUnknownChar(e){return "()[]{},:;".includes(e)?"punctuation":"+-*/<>=!&|".includes(e)?"operator":"identifier"}tryPropertyAccess(e,r,t){if(e[r]!==".")return false;let n=t[t.length-1],a=n&&n.position.end<r;if(n&&!a&&(n.kind==="identifier"||n.kind==="keyword"||n.kind==="selector"))return t.push(G(".","operator",U(r,r+1))),true;let s=r+1;for(;s<e.length&&te(e[s]);)s++;return s<e.length&&e[s]==="("?(t.push(G(".","operator",U(r,r+1))),true):false}initializeKeywordsFromProfile(e,r=[]){let t=new Map;if(this.rawExtraEntries=r,e.keywords){for(let[n,a]of Object.entries(e.keywords))if(t.set(a.primary,{native:a.primary,normalized:a.normalized||n}),a.alternatives)for(let o of a.alternatives)t.set(o,{native:o,normalized:a.normalized||n});}if(e.references){for(let[n,a]of Object.entries(e.references))t.set(a,{native:a,normalized:n});for(let n of Object.keys(e.references))t.has(n)||t.set(n,{native:n,normalized:n});}if(e.roleMarkers){for(let[n,a]of Object.entries(e.roleMarkers))if(a.primary&&t.set(a.primary,{native:a.primary,normalized:n}),a.alternatives)for(let o of a.alternatives)t.set(o,{native:o,normalized:n});}if(e.possessive?.keywords)for(let[n,a]of Object.entries(e.possessive.keywords))t.set(n,{native:n,normalized:a});for(let n of Ui)t.has(n)||t.set(n,{native:n,normalized:n});for(let n of r)t.set(n.native,n);this.profileKeywords=Array.from(t.values()).sort((n,a)=>a.native.length-n.native.length),this.multiWordKeywords=this.profileKeywords.filter(n=>(n.native.includes(" ")||Hi(n.native))&&!Ki.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 Qe(e)}tryProfileKeyword(e,r){for(let t of this.profileKeywords)if(e.slice(r).startsWith(t.native))return G(t.native,"keyword",U(r,r+t.native.length),t.normalized);return null}tryMultiWordKeyword(e,r,t=n=>/[\p{L}\p{N}_]/u.test(n)){if(this.multiWordKeywords.length===0)return null;let n=e.slice(r);for(let a of this.multiWordKeywords){if(!n.startsWith(a.native))continue;let o=e[r+a.native.length];if(!(o!==void 0&&t(o)))return G(a.native,"keyword",U(r,r+a.native.length),a.normalized)}return null}isKeywordStart(e,r){let t=e.slice(r);return this.profileKeywords.some(n=>t.startsWith(n.native))}isKeywordStartAtBoundary(e,r,t=n=>/[\p{L}\p{N}_]/u.test(n)){let n=e.slice(r);return this.profileKeywords.some(a=>{if(!n.startsWith(a.native))return false;let o=e[r+a.native.length];return o===void 0||!t(o)})}lookupKeyword(e){let r=this.profileKeywordMap.get(e.toLowerCase());if(r)return r;let t=this.removeDiacritics(e);if(t!==e)return this.profileKeywordMap.get(t.toLowerCase())}isKeyword(e){return this.lookupKeyword(e)!==void 0}setNormalizer(e){this.normalizer=e;}tryNormalize(e){if(!this.normalizer)return null;let r=this.normalizer.normalize(e);return r.stem!==e&&r.confidence>=.7?r:null}tryMorphKeywordMatch(e,r,t){let n=this.tryNormalize(e);if(!n)return null;let a=this.lookupKeyword(n.stem);if(!a)return null;let o={normalized:a.normalized,stem:n.stem,stemConfidence:n.confidence};return G(e,"keyword",U(r,t),o)}trySelector(e,r){let t=_i(e,r);return t?G(t,"selector",U(r,r+t.length)):null}tryEventModifier(e,r){if(e[r]!==".")return null;let t=e.slice(r).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!t)return null;let n=t[0].replace(/(\s|\.)$/,""),a=n.slice(1).split("(")[0],o=t[1];return {...G(n,"event-modifier",U(r,r+n.length)),metadata:{modifierName:a,value:o?a==="queue"?o:parseInt(o,10):void 0}}}tryString(e,r){let t=ji(e,r);return t?G(t,"literal",U(r,r+t.length)):null}tryNumber(e,r){let t=qi(e,r);return t?G(t,"literal",U(r,r+t.length)):null}tryMatchTimeUnit(e,r,t,n=false){let a=r;if(n)for(;a<e.length&&Ie(e[a]);)a++;let o=e.slice(a);for(let u of t){let s=o.slice(0,u.length);if(u.caseInsensitive?s.toLowerCase()===u.pattern.toLowerCase():s===u.pattern){if(u.notFollowedBy&&(o[u.length]||"")===u.notFollowedBy)continue;if(u.checkBoundary){let c=o[u.length]||"";if(te(c))continue}return {suffix:u.suffix,endPos:a+u.length}}}return null}parseBaseNumber(e,r,t=true){let n=r,a="";if(t&&(e[n]==="-"||e[n]==="+")&&(a+=e[n++]),n>=e.length||!Ee(e[n]))return null;for(;n<e.length&&Ee(e[n]);)a+=e[n++];if(n<e.length&&e[n]===".")for(a+=e[n++];n<e.length&&Ee(e[n]);)a+=e[n++];return !a||a==="-"||a==="+"?null:{number:a,endPos:n}}tryNumberWithTimeUnits(e,r,t,n={}){let{allowSign:a=true,skipWhitespace:o=false}=n,u=this.parseBaseNumber(e,r,a);if(!u)return null;let{number:s,endPos:l}=u,c=[...t,...Xe.STANDARD_TIME_UNITS],m=this.tryMatchTimeUnit(e,l,c,o);return m&&(s+=m.suffix,l=m.endPos),G(s,"literal",U(r,l))}tryUrl(e,r){let t=Vi(e,r);return t?G(t,"url",U(r,r+t.length)):null}tryVariableRef(e,r){if(e[r]!==":"||r+1>=e.length||!te(e[r+1]))return null;let t=r+1;for(;t<e.length&&te(e[t]);)t++;let n=e.slice(r,t);return G(n,"identifier",U(r,t))}tryOperator(e,r){let t=e.slice(r,r+2);if(["==","!=","<=",">=","&&","||","->"].includes(t))return G(t,"operator",U(r,r+2));let n=e[r];return ["<",">","!","+","-","*","/","="].includes(n)?G(n,"operator",U(r,r+1)):["(",")","{","}",",",";",":"].includes(n)?G(n,"punctuation",U(r,r+1)):null}tryMultiCharParticle(e,r,t){for(let n of t)if(e.slice(r,r+n.length)===n)return G(n,"particle",U(r,r+n.length));return null}};er.ASCII_WORD=/^[A-Za-z_][A-Za-z0-9_]*$/;er.COLON_QUALIFIER=/^:[A-Za-z_][A-Za-z0-9_]*$/;er.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:true},{pattern:"m",suffix:"m",length:1,checkBoundary:true,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:true}];var Xr=er;function Qr(i){return {stem:i,confidence:1}}function rr(i,e,r){return r?{stem:i,confidence:e,metadata:r}:{stem:i,confidence:e}}var Gi=Object.defineProperty,Yi=Object.getOwnPropertyNames,zt=(i,e)=>function(){return i&&(e=(0, i[Yi(i)[0]])(i=0)),e},Zi=(i,e)=>{for(var r in e)Gi(i,r,{get:e[r],enumerable:true});};function et(i,e){return i.replace(/\{(\w+)\}/g,(r,t)=>String(e[t]??`{${t}}`))}function ne(i,e,r={},t){let n=kt[i],a=et(n,r),o=wt[i],u=o?et(o,r):void 0;return {code:i,message:a,severity:e,...t&&{role:t},...u&&{suggestion:u}}}var F,kt,wt,Ji=zt({"src/generators/schema-error-codes.ts"(){F={AMBIGUOUS_TYPE_LITERAL_SELECTOR:"SCHEMA_AMBIGUOUS_TYPE_LITERAL_SELECTOR",TOO_MANY_EXPECTED_TYPES:"SCHEMA_TOO_MANY_EXPECTED_TYPES",MULTI_TYPE_PATIENT_EXPECTED:"SCHEMA_MULTI_TYPE_PATIENT_EXPECTED",NO_REQUIRED_ROLES:"SCHEMA_NO_REQUIRED_ROLES",NO_REQUIRED_ROLES_EXPECTED:"SCHEMA_NO_REQUIRED_ROLES_EXPECTED",TRANSITION_PATIENT_ACCEPTS_SELECTOR:"SCHEMA_TRANSITION_PATIENT_ACCEPTS_SELECTOR",TRANSITION_MISSING_GOAL:"SCHEMA_TRANSITION_MISSING_GOAL",EVENT_HANDLER_MISSING_EVENT:"SCHEMA_EVENT_HANDLER_MISSING_EVENT",EVENT_HANDLER_EVENT_NOT_REQUIRED:"SCHEMA_EVENT_HANDLER_EVENT_NOT_REQUIRED",CONDITIONAL_MISSING_CONDITION:"SCHEMA_CONDITIONAL_MISSING_CONDITION",CONDITIONAL_CONDITION_NOT_REQUIRED:"SCHEMA_CONDITIONAL_CONDITION_NOT_REQUIRED",FOR_LOOP_MISSING_SOURCE:"SCHEMA_FOR_LOOP_MISSING_SOURCE",WHILE_LOOP_MISSING_CONDITION:"SCHEMA_WHILE_LOOP_MISSING_CONDITION",VALUE_TYPE_MISMATCH:"SCHEMA_VALUE_TYPE_MISMATCH",SELECTOR_KIND_MISMATCH:"SCHEMA_SELECTOR_KIND_MISMATCH",SELECTOR_KINDS_WITHOUT_SELECTOR_TYPE:"SCHEMA_SELECTOR_KINDS_WITHOUT_SELECTOR_TYPE",KEYWORD_COLLISION:"PROFILE_KEYWORD_COLLISION"},kt={[F.AMBIGUOUS_TYPE_LITERAL_SELECTOR]:"Role '{role}' accepts both 'literal' and 'selector'. This may cause ambiguous type inference for values starting with special characters (* . # etc.).",[F.TOO_MANY_EXPECTED_TYPES]:"Role '{role}' accepts {count} different types. This may make type inference unreliable.",[F.MULTI_TYPE_PATIENT_EXPECTED]:"Role '{role}' accepts multiple types (expected for {command} command).",[F.NO_REQUIRED_ROLES]:"Command has no required roles. Is this intentional?",[F.NO_REQUIRED_ROLES_EXPECTED]:"Command has no required roles (expected for {command}).",[F.TRANSITION_PATIENT_ACCEPTS_SELECTOR]:"Transition command 'patient' role (CSS property name) should only accept 'literal', not 'selector'. CSS property names like 'background-color' are strings, not CSS selectors.",[F.TRANSITION_MISSING_GOAL]:"Transition command requires a 'goal' role for the target value (to <value>). Without it, there's no way to specify what value to transition to.",[F.EVENT_HANDLER_MISSING_EVENT]:"Event handler command should have an 'event' role to specify which event to listen for.",[F.EVENT_HANDLER_EVENT_NOT_REQUIRED]:"Event role should be required - every event handler needs an event to listen for.",[F.CONDITIONAL_MISSING_CONDITION]:"Conditional command should have a 'condition' role for the boolean expression.",[F.CONDITIONAL_CONDITION_NOT_REQUIRED]:"Condition role should be required - conditionals need a condition to evaluate.",[F.FOR_LOOP_MISSING_SOURCE]:"For-loop should have a 'source' role for the collection to iterate over.",[F.WHILE_LOOP_MISSING_CONDITION]:"While-loop should have a 'condition' role for the loop condition.",[F.VALUE_TYPE_MISMATCH]:"Role '{role}' of command '{command}' expects type [{expectedTypes}], got '{actualType}'.",[F.SELECTOR_KIND_MISMATCH]:"Role '{role}' of command '{command}' expects selector kind [{selectorKinds}], got '{actualKind}'.",[F.SELECTOR_KINDS_WITHOUT_SELECTOR_TYPE]:"Role '{role}' has selectorKinds but expectedTypes does not include 'selector'.",[F.KEYWORD_COLLISION]:"Keyword '{keyword}' is used by multiple commands: {commands}. Only the first-registered command will be reachable."},wt={[F.AMBIGUOUS_TYPE_LITERAL_SELECTOR]:"Consider being more specific about which type is expected, or use explicit type markers.",[F.TOO_MANY_EXPECTED_TYPES]:"Consider narrowing the accepted types to improve type inference reliability.",[F.TRANSITION_PATIENT_ACCEPTS_SELECTOR]:"Remove 'selector' from expectedTypes and only accept 'literal'.",[F.TRANSITION_MISSING_GOAL]:"Add a 'goal' role with expectedTypes ['literal', 'variable'].",[F.EVENT_HANDLER_MISSING_EVENT]:"Add an 'event' role with expectedTypes ['literal'].",[F.EVENT_HANDLER_EVENT_NOT_REQUIRED]:"Set required: true on the 'event' role.",[F.CONDITIONAL_MISSING_CONDITION]:"Add a 'condition' role with expectedTypes ['expression'].",[F.CONDITIONAL_CONDITION_NOT_REQUIRED]:"Set required: true on the 'condition' role.",[F.FOR_LOOP_MISSING_SOURCE]:"Add a 'source' role for the collection to iterate over.",[F.WHILE_LOOP_MISSING_CONDITION]:"Add a 'condition' role for the loop continuation condition.",[F.VALUE_TYPE_MISMATCH]:"Ensure the value matches one of the expected types: [{expectedTypes}].",[F.SELECTOR_KIND_MISMATCH]:"Use a selector of the correct kind: [{selectorKinds}].",[F.SELECTOR_KINDS_WITHOUT_SELECTOR_TYPE]:"Either add 'selector' to expectedTypes or remove selectorKinds.",[F.KEYWORD_COLLISION]:"Give each command a unique keyword. Move the shared keyword to alternatives on one command, or use a more specific translation."};}}),bt={};Zi(bt,{SchemaErrorCodes:()=>F,formatValidationResults:()=>an,getValidationStats:()=>on,validateAllKeywordCollisions:()=>ln,validateAllSchemas:()=>nn,validateCommandSchema:()=>At,validateKeywordCollisions:()=>Dt,validateRoleValues:()=>un});function Xi(i,e){return {action:i,items:e}}function At(i){let e=[];for(let t of i.roles)t.expectedTypes.includes("literal")&&t.expectedTypes.includes("selector")&&(t.role==="patient"&&Cr.has(i.action)?e.push(ne(F.MULTI_TYPE_PATIENT_EXPECTED,"note",{role:t.role,command:i.action},t.role)):e.push(ne(F.AMBIGUOUS_TYPE_LITERAL_SELECTOR,"warning",{role:t.role},t.role))),t.expectedTypes.length>3&&!Cr.has(i.action)&&e.push(ne(F.TOO_MANY_EXPECTED_TYPES,"warning",{role:t.role,count:t.expectedTypes.length},t.role));for(let t of i.roles)t.selectorKinds&&t.selectorKinds.length>0&&(t.expectedTypes.includes("selector")||e.push(ne(F.SELECTOR_KINDS_WITHOUT_SELECTOR_TYPE,"warning",{role:t.role},t.role)));switch(i.action){case "transition":Qi(i,e);break;case "on":en(i,e);break;case "if":case "unless":rn(i,e);break;case "repeat":case "for":case "while":tn(i,e);break}return i.roles.filter(t=>t.required).length===0&&(St.has(i.action)?e.push(ne(F.NO_REQUIRED_ROLES_EXPECTED,"note",{command:i.action})):e.push(ne(F.NO_REQUIRED_ROLES,"warning",{}))),Xi(i.action,e)}function Qi(i,e){let r=i.roles.find(n=>n.role==="patient"),t=i.roles.find(n=>n.role==="goal");r&&!t&&e.push(ne(F.TRANSITION_MISSING_GOAL,"error",{}));}function en(i,e){let r=i.roles.find(t=>t.role==="event");r||e.push(ne(F.EVENT_HANDLER_MISSING_EVENT,"warning",{})),r&&!r.required&&e.push(ne(F.EVENT_HANDLER_EVENT_NOT_REQUIRED,"warning",{}));}function rn(i,e){let r=i.roles.find(t=>t.role==="condition");r||e.push(ne(F.CONDITIONAL_MISSING_CONDITION,"warning",{})),r&&!r.required&&e.push(ne(F.CONDITIONAL_CONDITION_NOT_REQUIRED,"warning",{}));}function tn(i,e){i.action==="for"?i.roles.find(t=>t.role==="source")||e.push(ne(F.FOR_LOOP_MISSING_SOURCE,"warning",{})):i.action==="while"&&(i.roles.find(t=>t.role==="condition")||e.push(ne(F.WHILE_LOOP_MISSING_CONDITION,"warning",{})));}function nn(i,e={}){let r=new Map,{includeNotes:t=false}=e;for(let[n,a]of Object.entries(i)){let o=At(a),u=o.items.some(l=>l.severity==="warning"||l.severity==="error"),s=t&&o.items.some(l=>l.severity==="note");(u||s)&&r.set(n,o);}return r}function an(i,e={}){let r=[],{showNotes:t=false,showCodes:n=true}=e;for(let[a,o]of i){let u=o.items.filter(c=>c.severity==="error"),s=o.items.filter(c=>c.severity==="warning"),l=o.items.filter(c=>c.severity==="note");if(u.length>0){r.push(` \u274C ${a}:`);for(let c of u){let m=n?` [${c.code}]`:"";r.push(` ERROR${m}: ${c.message}`),c.suggestion&&r.push(` \u{1F4A1} Suggestion: ${c.suggestion}`);}}if(s.length>0){r.push(` \u26A0\uFE0F ${a}:`);for(let c of s){let m=n?` [${c.code}]`:"";r.push(` ${m?`${c.code}: `:""}${c.message}`),c.suggestion&&r.push(` \u{1F4A1} ${c.suggestion}`);}}if(t&&l.length>0){r.push(` \u2139\uFE0F ${a}:`);for(let c of l){let m=n?` [${c.code}]`:"";r.push(` ${m?`${c.code}: `:""}${c.message}`);}}}return r.join(`
2
- `)}function on(i){let e=0,r=0,t=0,n={};for(let a of i.values())for(let o of a.items)o.severity==="error"?e++:o.severity==="warning"?r++:o.severity==="note"&&t++,n[o.code]=(n[o.code]||0)+1;return {totalCommands:i.size,errors:e,warnings:r,notes:t,byCode:n}}function un(i,e){let r=[];for(let t of e){let n=i.roles.find(a=>a.role===t.role);n&&(n.expectedTypes.length>0&&!n.expectedTypes.includes(t.type)&&(n.expectedTypes.includes("expression")||r.push({level:"error",role:t.role,message:`${i.action}.${t.role} expects type [${n.expectedTypes.join(", ")}], got '${t.type}'`,code:F.VALUE_TYPE_MISMATCH})),t.type==="selector"&&t.selectorKind&&n.selectorKinds&&n.selectorKinds.length>0&&(n.selectorKinds.includes(t.selectorKind)||r.push({level:"error",role:t.role,message:`${i.action}.${t.role} expects selector kind [${n.selectorKinds.join(", ")}], got '${t.selectorKind}'`,code:F.SELECTOR_KIND_MISMATCH})));}return r}function sn(i){if(i.length!==2)return false;let[e,r]=[...i].sort();return Bt.some(([t,n])=>t===e&&n===r)}function Dt(i){let e=[];if(!i.keywords)return {language:i.code,collisions:e};let r=new Map;for(let[n,a]of Object.entries(i.keywords)){if(!a||!a.primary)continue;let o=r.get(a.primary)||[];if(o.push({command:n,isPrimary:true}),r.set(a.primary,o),a.alternatives)for(let u of a.alternatives){let s=r.get(u)||[];s.push({command:n,isPrimary:false}),r.set(u,s);}}for(let[n,a]of r){let o=[...new Set(a.map(l=>l.command))];if(o.length<=1||sn(o))continue;let u=a.filter(l=>l.isPrimary).length,s;u>=2?s="primary-primary":u===1?s="primary-alternative":s="alternative-alternative",e.push({keyword:n,commands:o.sort(),type:s});}let t={"primary-primary":0,"primary-alternative":1,"alternative-alternative":2};return e.sort((n,a)=>t[n.type]-t[a.type]),{language:i.code,collisions:e}}function ln(i){let e=[];for(let[,r]of Object.entries(i)){let t=Dt(r);t.collisions.length>0&&e.push(t);}return e.sort((r,t)=>r.language.localeCompare(t.language))}var Cr,St,Bt,cn=zt({"src/generators/schema-validator.ts"(){Ji(),Cr=new Set(["put","append","prepend","log","throw","make","measure","return","swap","morph","beep","copy"]),St=new Set(["compound","else","halt","continue","async","init","settle","focus","blur","return","js","measure","break","exit","beep","empty","open","close","select","clear","reset","breakpoint","live","eventsource","socket","worker","intercept"]),Bt=[["change","changes"]];}});function ke(i){let e=i.roles.find(r=>r.role==="destination");return e?{destination:e.default?{fromRole:"destination",default:e.default}:{fromRole:"destination"}}:{}}function we(i){let e=i.roles.find(r=>r.role==="source");return e?{source:e.default?{fromRole:"source",default:e.default}:{fromRole:"source"}}:{}}function be(i,e){return Br(i,e,"source")}function Sr(i,e){return Br(i,e,"destination")}function mn(i,e){return Br(i,e,"patient")}function Br(i,e,r){if(!e||!i.roles.some(a=>a.role===r))return [];let t=e.alternatives?{type:"literal",value:e.primary,alternatives:[...e.alternatives]}:{type:"literal",value:e.primary},n={type:"role",role:r,optional:true};return [{type:"group",optional:true,tokens:e.position==="after"?[n,t]:[t,n]}]}var dn={action:"toggle",description:"Toggle a class or attribute on/off",category:"dom-class",primaryRole:"patient",ast:{args:["patient"],modifiers:{on:"destination",for:"duration"}},argSkipTokens:["on"],roles:[{role:"patient",description:"The class or attribute to toggle",required:true,expectedTypes:["selector"],selectorKinds:["class","attribute"],svoPosition:1,sovPosition:2,markerOptional:{zh:true}},{role:"destination",description:"The target element (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerVariants:{ko:["\uC5D0\uC11C"]}},{role:"duration",description:"How long the class stays on before reverting (`toggle .a for 2s`)",required:false,expectedTypes:["literal"],svoPosition:3,sovPosition:3,valueShape:"time",markerOverride:{en:"for",ja:"\u9593",ko:"\uB3D9\uC548"}}],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)"}},pn={action:"add",description:"Add a class or attribute to an element",category:"dom-class",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"destination"}},roles:[{role:"patient",description:"The class or attribute to add",required:true,expectedTypes:["selector","literal"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:false,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerOverride:{en:"to",es:"a",ar:"\u0625\u0644\u0649",zh:"\u5230",fr:"\xE0",de:"zu",pt:"a",he:"\u05D0\u05DC",id:"ke",it:"a",sw:"kwa"},markerLegacy:{es:["en","sobre","hacia"],ar:["\u0639\u0644\u0649","\u0641\u064A","\u0628"],zh:["\u5728","\u4E8E"],fr:["sur","dans"],de:["auf","in"],pt:["em","para"],he:["\u05E2\u05DC","\u05D1","\u05DC"],id:["pada","di"],it:["in","su"],sw:["kwenye"]}}],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"}},fn={action:"remove",description:"Remove a class or attribute from an element",category:"dom-class",primaryRole:"patient",ast:{args:["patient"],modifiers:{from:"source"}},targetRole:"source",argSkipTokens:["from"],roles:[{role:"patient",description:"The class/attribute to remove, or the element to remove",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to remove from (defaults to me)",required:false,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"}},yn={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:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"destination",description:"Where to put the content",required:true,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"into",ar:"\u0641\u064A",zh:"\u5230",fr:"dans",de:"in",he:"\u05D1",id:"ke",sw:"kwa"},markerVariants:{en:["before","after"]},markerLegacy:{ar:["\u0639\u0644\u0649","\u0625\u0644\u0649","\u0628"],zh:["\u5728","\u4E8E"],fr:["sur","\xE0"],de:["auf","zu"],he:["\u05E2\u05DC","\u05D0\u05DC","\u05DC"],id:["pada","di"],sw:["kwenye"]},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"}},hn={action:"set",description:"Set a property or variable to a value",category:"variable",primaryRole:"destination",ast:{args:["destination"],modifiers:{to:"patient",on:"scope"}},argSkipTokens:["to"],roles:[{role:"destination",description:"The property or variable to set",required:true,expectedTypes:["selector","reference","expression","property-path"],svoPosition:1,sovPosition:1,markerOverride:{en:"",es:"",ja:"\u3092",ko:"\uB97C",tr:"i",ar:"",sw:"",tl:"",th:"",bn:"\u0995\u09C7",qu:"ta",hi:"\u0915\u094B",zh:"\u628A"},markerOptional:{zh:true}},{role:"patient",description:"The value to set",required:true,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",th:"\u0E43\u0E19",bn:"\u09A4\u09C7",qu:"man",hi:"\u092E\u0947\u0902",zh:"\u5230"},markerVariants:{tr:["e","a","ye","ya"],zh:["\u4E3A","\u70BA","\u6210"]}},{role:"scope",description:"The element(s) the attribute/property is set on (defaults to me)",required:false,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>"}},vn={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:true,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:true,expectedTypes:["selector","reference","expression","property-path"],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>"}},En={action:"live",description:"Reactive block: re-run the body when its dependencies change",category:"control-flow",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},gn={action:"when",description:"Reactive observer: re-run the body when a watched expression changes",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,structuralOnly:true,roles:[{role:"condition",description:"The watched expression (`or`-separated expressions watch each)",required:true,expectedTypes:["expression","reference","selector"],svoPosition:1}]},Cn={action:"eventsource",description:"Open a Server-Sent Events stream and handle its events",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},zn={action:"socket",description:"Open a WebSocket and handle its messages",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},kn={action:"worker",description:"Define a Web Worker with inline methods",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},wn={action:"intercept",description:"Service-worker fetch interception / caching strategies",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},bn={action:"show",description:"Make an element visible",category:"dom-visibility",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{with:"duration"}},roles:[{role:"patient",description:"The element to show",required:true,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:false,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},An={action:"hide",description:"Make an element invisible",category:"dom-visibility",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{with:"duration"}},roles:[{role:"patient",description:"The element to hide",required:true,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:false,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},Dn={action:"on",description:"Handle an event",category:"event",primaryRole:"event",ast:{args:["event"],modifiers:{from:"source"}},hasBody:true,roles:[{role:"event",description:"The event to handle",required:true,expectedTypes:["literal"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to listen on (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}],widenTypeVariants:[{role:"event",types:["literal","expression"],idSuffix:"expr-event",excludeLanguages:["ko"]}]},Sn={action:"trigger",description:"Trigger/dispatch an event",category:"event",primaryRole:"event",ast:{args:["event"],modifiers:{on:"destination"}},argSkipTokens:["on"],roles:[{role:"event",description:"The event to trigger (supports namespaced events like draggable:start)",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2,markerVariants:{hi:["\u0915\u094B"],qu:["ta"],bn:["\u0995\u09C7"]},markerOverride:{bn:"\u0995\u09C7",hi:"\u0915\u094B"}},{role:"destination",description:"The target element (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Bn={action:"wait",description:"Wait for a duration or event",category:"async",primaryRole:"duration",roles:[{role:"duration",description:"Duration or event to wait for",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},xn={action:"fetch",description:"Fetch data from a URL",category:"async",primaryRole:"source",ast:{args:["source"],modifiers:{with:["style","method"],as:"responseType",body:"patient"},isBlocking:true},roles:[{role:"source",description:"The URL to fetch from",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,renderOverride:{en:""}},{role:"style",description:"Request options object (method, headers, body, credentials\u2026)",required:false,expectedTypes:["expression"],valueShape:"object",svoPosition:2,sovPosition:2},{role:"responseType",description:"Response format (json, text, html, blob, etc.)",required:false,expectedTypes:["literal","expression"],svoPosition:3,sovPosition:3,markerOverride:{en:"as",ja:"\u3068\u3057\u3066"}},{role:"method",description:"HTTP method (GET, POST, etc.)",required:false,expectedTypes:["literal"],svoPosition:4,sovPosition:4},{role:"destination",description:"Where to store the result",required:false,expectedTypes:["selector","reference"],svoPosition:5,sovPosition:5}]},Tn={action:"increment",description:"Increment a numeric value",category:"variable",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{by:"quantity"}},roles:[{role:"patient",description:"The value to increment",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to increment by (defaults to 1)",required:false,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Fn={action:"decrement",description:"Decrement a numeric value",category:"variable",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{by:"quantity"}},roles:[{role:"patient",description:"The value to decrement",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to decrement by (defaults to 1)",required:false,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Rn={action:"append",description:"Append content to an element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"destination"}},omitRoleVariants:["destination"],roles:[{role:"patient",description:"The content to append",required:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to append to",required:true,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},On={action:"prepend",description:"Prepend content to an element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"destination"}},omitRoleVariants:["destination"],roles:[{role:"patient",description:"The content to prepend",required:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to prepend to",required:true,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},Pn={action:"log",description:"Log a value to the console",category:"variable",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The value to log",required:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ln={action:"get",description:"Get a value from a source",category:"variable",primaryRole:"source",ast:{args:[["source","patient"]]},roles:[{role:"source",description:"The source to get from",required:true,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:false,expectedTypes:["reference"],svoPosition:2,sovPosition:1}]},Nn={action:"take",description:"Take content from a source element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{from:"source",for:"recipient"}},argSkipTokens:["from"],roles:[{role:"patient",description:"The class or element to take",required:true,expectedTypes:["selector"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to take from (defaults to all current holders)",required:false,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1},{role:"recipient",description:"The element the class moves ONTO (`take .active from .tab for me`)",required:false,expectedTypes:["reference"],svoPosition:3,sovPosition:3,valueShape:"reference",markerOverride:{en:"for"}}]},Mn={action:"make",description:"Create a new element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The element type or selector to create",required:true,expectedTypes:["literal","selector"],svoPosition:1,sovPosition:1}]},_n={action:"halt",description:"Halt/stop execution or event propagation",category:"control-flow",primaryRole:"patient",ast:{args:[],modifiers:{the:"patient"}},argSkipTokens:["the"],roles:[{role:"patient",description:"What to halt (event, default, bubbling, etc.)",required:false,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},In={action:"settle",description:"Wait for animations/transitions to settle",category:"async",primaryRole:"patient",ast:{args:[["destination","patient"]],isBlocking:true},roles:[{role:"patient",description:"The element to settle (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},jn={action:"throw",description:"Throw an error",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The error message or object to throw",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},$n={action:"send",description:"Send an event to an element",category:"event",primaryRole:"event",ast:{args:["event"],modifiers:{to:"destination",detail:"patient"}},roles:[{role:"event",description:"The event to send",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:false,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"}}]},Vn={action:"if",description:"Conditional execution",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,roles:[{role:"condition",description:"The condition to evaluate",required:true,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},qn={action:"unless",description:"Negated conditional execution (executes when condition is false)",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,roles:[{role:"condition",description:"The condition to evaluate (body executes when false)",required:true,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},Wn={action:"else",description:"Else branch of conditional",category:"control-flow",primaryRole:"patient",hasBody:true,roles:[]},Kn={action:"repeat",description:"Repeat a block of commands",category:"control-flow",primaryRole:"loopType",ast:{args:[["quantity","patient"]]},hasBody:true,roles:[{role:"loopType",description:"Loop variant: forever, times, for, while, until, until-event",required:true,expectedTypes:["literal"],svoPosition:0,sovPosition:0},{role:"quantity",description:"Number of times to repeat",required:false,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"event",description:"Event to wait for (terminates loop)",required:false,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2},{role:"source",description:"Element to listen for event on",required:false,expectedTypes:["selector","reference"],svoPosition:3,sovPosition:3}],notes:'Can also use "repeat forever", "repeat until condition", or "repeat until event X from Y"'},Hn={action:"for",description:"Iterate over a collection",category:"control-flow",primaryRole:"patient",ast:{args:["patient"],modifiers:{in:"source"}},hasBody:true,roles:[{role:"patient",description:"The iteration variable",required:true,expectedTypes:["reference","expression"],svoPosition:1,sovPosition:2},{role:"source",description:"The collection to iterate over",required:true,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"}}]},Un={action:"while",description:"Loop while condition is true",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,roles:[{role:"condition",description:"The condition to check",required:true,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},Gn={action:"continue",description:"Continue to next loop iteration",category:"control-flow",primaryRole:"patient",ast:{},roles:[]},xr={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"},Yn={action:"go",description:"Navigate to a URL",category:"navigation",primaryRole:"destination",roles:[{role:"destination",description:"The URL to navigate to",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to",es:"a",ar:"\u0625\u0644\u0649",fr:"\xE0",de:"zu",pt:"para",he:"\u05D0\u05DC",hi:"\u092A\u0930",id:"ke",it:"a",ru:"\u043D\u0430",sw:"kwa",uk:"\u043D\u0430"},renderOverride:{en:"",zh:"",vi:"",th:""},markerOptional:{en:true,zh:true,vi:true,th:true},markerVariants:{zh:["\u628A"]},markerLegacy:{es:["en","sobre","hacia"],ar:["\u0639\u0644\u0649","\u0641\u064A","\u0628"],fr:["sur","dans"],de:["auf","in"],pt:["em","a"],he:["\u05E2\u05DC","\u05D1","\u05DC","\u05D0\u05EA"],hi:["\u092E\u0947\u0902"],id:["pada","di"],it:["in","su"],ru:["\u0432","\u043A"],sw:["kwenye"],uk:["\u0432","\u0434\u043E"]}}],rolePrefixLiteralVariants:[{role:"destination",literal:xr,idSuffix:"url",priorityDelta:5,methodCarrier:"method"}]},Zn={action:"transition",description:"Transition an element with animation",category:"dom-visibility",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"goal",over:"duration",on:"destination"}},omitRoleVariants:["goal"],roles:[{role:"patient",description:"The property to transition (opacity, *background-color, etc.)",required:true,expectedTypes:["literal","expression","selector"],svoPosition:1,sovPosition:2,markerOverride:{en:"",ar:"",tl:"",sw:""}},{role:"goal",description:"The target value to transition to",required:true,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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:3,sovPosition:1},{role:"duration",description:"Transition duration (over 500ms, for 2 seconds)",required:false,expectedTypes:["literal"],svoPosition:4,sovPosition:4,markerOverride:{en:"over"}},{role:"style",description:"Easing function (ease-in, linear, etc.)",required:false,expectedTypes:["literal"],svoPosition:5,sovPosition:5}]},Jn={action:"clone",description:"Clone an element",category:"dom-content",primaryRole:"patient",ast:{args:[["source","patient"]],modifiers:{into:"destination"}},roles:[{role:"patient",description:"The element to clone",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"destination",description:"Where to put the clone",required:false,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"into"}}]},Xn={action:"focus",description:"Focus an element",category:"dom-content",primaryRole:"patient",ast:{args:[["destination","patient"]]},roles:[{role:"patient",description:"The element to focus (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},Qn={action:"blur",description:"Remove focus from an element",category:"dom-content",primaryRole:"patient",ast:{args:[["destination","patient"]]},roles:[{role:"patient",description:"The element to blur (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ea={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ra={action:"open",description:"Open a dialog, details element, or popover",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{as:"style"}},roles:[{role:"patient",description:"The element to open (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:2},{role:"style",description:"Open-mode variant (modal / non-modal) for <dialog>",required:false,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"as",ja:"\u3068\u3057\u3066"}}]},ta={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ia={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},na={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:false,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},aa={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},oa={action:"breakpoint",description:"Drop into the debugger",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:true},ua={action:"call",description:"Call a function",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The function to call",required:true,expectedTypes:["expression","reference"],markerOptional:{he:true,zh:true},svoPosition:1,sovPosition:1}]},sa={action:"return",description:"Return a value from a function",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The value to return",required:false,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1}]},la={action:"js",description:"Execute raw JavaScript code",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},hasBody:true,roles:[{role:"patient",description:"The JavaScript code to execute",required:false,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},ca={action:"async",description:"Execute commands asynchronously",category:"async",primaryRole:"patient",ast:{},hasBody:true,roles:[]},ma={action:"tell",description:"Execute commands in context of another element",category:"control-flow",primaryRole:"destination",ast:{args:[["destination","patient"]]},hasBody:true,roles:[{role:"destination",description:"The element to tell",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:"",he:"\u05D0\u05EA",zh:"\u628A"}}]},da={action:"default",description:"Set a default value for a variable",category:"variable",primaryRole:"destination",ast:{args:["destination"],modifiers:{to:"patient"}},roles:[{role:"destination",description:"The variable to set default for",required:true,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:true,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"}}]},pa={action:"init",description:"Initialization block that runs once",category:"control-flow",primaryRole:"patient",ast:{},hasBody:true,roles:[]},fa={action:"behavior",description:"Define a reusable behavior",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},hasBody:true,roles:[{role:"patient",description:"The behavior name (PascalCase identifier)",required:true,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},ya={action:"install",description:"Install a behavior on an element",category:"control-flow",primaryRole:"patient",ast:{args:["patient"],modifiers:{on:"destination"}},roles:[{role:"patient",description:"The behavior name to install",required:true,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"Element to install on (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},ha={action:"measure",description:"Measure element dimensions (x, y, width, height, etc.)",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{of:["destination","source"]}},roles:[{role:"patient",description:"Property to measure (x, y, width, height, top, left, etc.)",required:false,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"source",description:"Element to measure (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:2,markerOverride:{en:"of"}}]},va={en:"using view",es:"using view",pt:"using view",fr:"using view",de:"using view",it:"using view",ja:"using view",ko:"using view",zh:"using view",ar:"using view",he:"using view",hi:"using view",bn:"using view",tr:"using view",ru:"using view",uk:"using view",pl:"using view",id:"using view",vi:"using view",th:"using view",ms:"using view",tl:"using view",sw:"using view",qu:"using view"},Tr={role:"manner",description:"Run the swap inside a `document.startViewTransition()` (`using view transition`)",required:false,expectedTypes:["literal","expression"],valueShape:"keyword",markerOverride:va},Ea={action:"swap",description:"Swap DOM content using various strategies (innerHTML, outerHTML, delete, etc.)",category:"dom-content",primaryRole:"destination",ast:{args:["method","destination","patient"],modifiers:{viewTransition:"manner"}},roles:[{role:"method",description:"The swap strategy (innerHTML, outerHTML, beforebegin, afterend, delete)",required:false,expectedTypes:["literal"],svoPosition:1,sovPosition:3,markerOverride:{en:""}},{role:"destination",description:"The element to swap content in/for",required:true,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",tl:""}},{role:"patient",description:"The content to swap in (optional for delete)",required:false,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",hi:"\u0938\u0947",bn:"\u09A6\u09BF\u09AF\u09BC\u09C7",tr:"ile",qu:"wan",ar:"\u0628\u0640",tl:"nang"}},{...Tr,svoPosition:4,sovPosition:4}]},ga={action:"morph",description:"Morph an element into another using DOM diffing",category:"dom-content",primaryRole:"patient",ast:{args:[["source","destination"]],modifiers:{on:"patient",viewTransition:"manner"}},roles:[{role:"patient",description:"The element to morph",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:""}},{role:"destination",description:"The target content/element to morph into",required:true,expectedTypes:["literal","expression","selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"to"}},{...Tr,svoPosition:3,sovPosition:3}]},Ca={action:"beep",description:"Debug output for expressions with type information",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The expression(s) to debug",required:false,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},za={action:"break",description:"Exit from the current loop",category:"control-flow",primaryRole:"patient",roles:[]},ka={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:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},wa={action:"exit",description:"Exit from the current event handler",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:true},ba={action:"pick",description:"Select item(s), character(s), a range, first/last/random N, or regex matches from a root",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The range/count/index/regex argument to pick",required:true,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1},{role:"source",description:'The root to pick from (with "of"/"from" keyword)',required:false,expectedTypes:["reference","expression"],svoPosition:2,sovPosition:2}]},Aa={action:"scroll",description:"Scroll the viewport to a target element",category:"navigation",primaryRole:"destination",ast:{args:["destination"]},argSkipTokens:["of","the","top","bottom","middle","center","nearest","left","right","smoothly","instantly"],roles:[{role:"destination",description:"The element to scroll to",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to"}}]},Da={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"},Sa={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:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:xr}]},Ba={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:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:xr}]},xa={action:"process",description:"Process hx-partial markup in HTML content",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{viewTransition:"manner"}},roles:[{role:"patient",description:"The HTML content (string, element, or response) to process",required:true,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:Da},{...Tr,svoPosition:2,sovPosition:2}]},Ta={action:"render",description:"Render a template with optional variables",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The template to render",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"style",description:"Variables to pass to the template (with keyword)",required:false,expectedTypes:["expression"],valueShape:"object",svoPosition:2,sovPosition:1}]},se={toggle:dn,add:pn,remove:fn,put:yn,set:hn,show:bn,hide:An,on:Dn,trigger:Sn,wait:Bn,fetch:xn,increment:Tn,decrement:Fn,append:Rn,prepend:On,log:Pn,get:Ln,take:Nn,make:Mn,halt:_n,settle:In,throw:jn,send:$n,if:Vn,unless:qn,else:Wn,repeat:Kn,for:Hn,while:Un,continue:Gn,go:Yn,scroll:Aa,push:Sa,replace:Ba,process:xa,transition:Zn,clone:Jn,focus:Xn,blur:Qn,empty:ea,open:ra,close:ta,select:ia,clear:na,reset:aa,breakpoint:oa,call:ua,return:sa,js:la,async:ca,tell:ma,default:da,init:pa,behavior:fa,install:ya,measure:ha,swap:Ea,morph:ga,beep:Ca,break:za,copy:ka,exit:wa,pick:ba,render:Ta,bind:vn,live:En,when:gn,eventsource:Cn,socket:zn,worker:kn,intercept:wn,compound:{action:"compound",description:"A compound node representing chained statements",primaryRole:"patient",category:"control-flow",hasBody:true,roles:[]}};function re(i){return se[i]}function Fa(){return Object.values(se).filter(i=>i.structuralOnly!==true&&(i.roles.length>0||i.bareKeyword===true))}typeof process<"u"&&process.env.LOKASCRIPT_SCHEMA_VALIDATION==="1"&&Promise.resolve().then(()=>(cn(),bt)).then(({validateAllSchemas:i,formatValidationResults:e})=>{let r=i(se);r.size>0&&(console.warn("[SCHEMA VALIDATION] Found issues in command schemas:"),console.warn(e(r)),console.warn(`
3
- These warnings help identify potential schema design issues.`),console.warn("Fix them to improve type inference and avoid runtime bugs."));}).catch(i=>{console.debug("Schema validation skipped:",i);});var ze=new Map,pe=new Map,Ve=new Map,zr=null;function xt(i,e){let r={...i};for(let t of Object.keys(e)){let n=e[t],a=i[t];n!==void 0&&(typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof a=="object"&&a!==null&&!Array.isArray(a)?r[t]=xt(a,n):r[t]=n);}return r}function Ra(i,e){return xt(i,e)}function Fr(i){if(!i.extends)return i;let e=pe.get(i.extends);if(!e)return console.warn(`[Registry] Profile '${i.code}' extends '${i.extends}' but base is not registered. Make sure to import the base language before the variant.`),i;let r=Fr(e);return Ra(r,i)}function Tt(i,e,r){ze.set(i,e),pe.set(i,r),Ve.delete(i);}function Ft(i){zr=i;}var rt=new Map;function Te(i){return i.split("-")[0]}function Fe(i){return i.includes("-")}function Oa(i){let e=ze.get(i);if(!e&&Fe(i)){let r=Te(i);e=ze.get(r);}if(!e){let r=Array.from(ze.keys()).join(", ");throw new Error(`Language '${i}' is not registered. Registered languages: ${r||"none"}. Import the language module first: import '@lokascript/semantic/languages/${i}';`)}return e}function Pa(i){let e=pe.get(i);if(!e&&Fe(i)){let r=Te(i);e=pe.get(r);}if(!e){let r=Array.from(pe.keys()).join(", ");throw new Error(`Language profile '${i}' is not registered. Registered languages: ${r||"none"}. Import the language module first: import '@lokascript/semantic/languages/${i}';`)}return Fr(e)}function P(i){let e=pe.get(i);return !e&&Fe(i)&&(e=pe.get(Te(i))),e?Fr(e):void 0}function La(){return Array.from(ze.keys())}function Rt(i){if(ze.has(i)&&pe.has(i))return true;if(Fe(i)){let e=Te(i);return ze.has(e)&&pe.has(e)}return false}function Na(i,e){return Oa(e).tokenize(i)}function de(i){let e=Ve.get(i);if(!e&&Fe(i)&&(e=Ve.get(Te(i))),e)return e;let r=rt.get(i);if(!r&&Fe(i)&&(r=rt.get(Te(i))),r)return Ve.set(i,r),r;if(!zr)throw new Error(`No patterns registered for language '${i}'. Either import the language module or set a pattern generator.`);let t=Pa(i),n=zr(t);return Ve.set(i,n),n}var Ot={possessive:{specialForms:{me:"my",it:"its",you:"your"}}};function ve(i){let e="complex";return i.startsWith("#")&&!i.includes(" ")?e="id":i.startsWith(".")&&!i.includes(" ")?e="class":i.startsWith("[")&&i.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(i)&&(e="element"),{type:"selector",value:i,selectorKind:e}}function W(i,e){let r={type:"literal",value:i};return e!==void 0?{type:"literal",value:i,dataType:e}:r}function Se(i){return fr(i)}function ue(i){return {type:"reference",value:i}}function so(i,e){return e?{...i,position:e}:i}function ge(i,e,r){return r?{type:"property-path",object:i,property:e,access:r}:{type:"property-path",object:i,property:e}}function ee(i,e,r){let t={kind:"command",action:i,roles:new Map(Object.entries(e))};return r!==void 0?{...t,metadata:r}:t}function $e(i,e,r,t,n,a){let o=new Map;o.set("event",i);let u={kind:"event-handler",action:"on",roles:o,body:e};return r!==void 0&&(u.eventModifiers=r),t!==void 0&&(u.metadata=t),n!==void 0&&n.length>0&&(u.parameterNames=n),u}function lo(i,e,r,t,n){let a={kind:"behavior",action:"behavior",roles:new Map,name:i,parameters:e,eventHandlers:r};return t!==void 0&&t.length>0&&(a.initBlock=t),n!==void 0&&(a.metadata=n),a}function co(i,e,r,t){let n={kind:"def",action:"def",roles:new Map,name:i,parameters:e,body:r};return t!==void 0&&(n.metadata=t),n}function kr(i,e,r,t,n){let a={kind:"feature",action:i,roles:n??new Map,body:e};return r!==void 0&&(a.name=r),t!==void 0&&(a.metadata=t),a}function qe(i,e="then",r){let t={kind:"compound",action:"compound",roles:new Map,statements:i,chainType:e};return r!==void 0&&(t.metadata=r),t}function mo(i,e,r,t){let n=new Map;n.set("condition",i);let a={kind:"conditional",action:"if",roles:n,thenBranch:e};return r!==void 0&&(a.elseBranch=r),t!==void 0&&(a.metadata=t),a}function tr(i,e){return !e||e.length===0||e.includes(i)||e.includes("expression")?true:i==="property-path"?e.some(r=>["selector","reference","expression"].includes(r)):i==="expression"?e.some(r=>["selector","reference","expression"].includes(r)):false}function po(i,e){let r=i.markerOverride?.[e.code],t=e.roleMarkers[i.role];if(r!==void 0){let n=fo(i,e.code,r);return {primary:r,...n&&{alternatives:n},position:t?.position??"before",isOverride:true}}if(t&&t.primary){let n={primary:t.primary,position:t.position,isOverride:false};return t.alternatives&&(n.alternatives=t.alternatives),n}return null}function fo(i,e,r){let t=i.markerLegacy?.[e];if(!t?.length)return;let n=[...new Set(t)].filter(a=>a&&a!==r);return n.length?n:void 0}function fe(i,e,r){let t=i.markerLegacy?.[e]??[],n=i.methodCarrier?[]:i.markerVariants?.[e]??[],a=[...new Set([...t,...n])].filter(o=>o&&o!==r);return a.length?a:void 0}var Pt=new Set(["destination","source","patient","object","event","eventmarker","manner","instrument"]);function ce(i,e){let r=i.possessive?.keywords?.[e];if(r)return r;let t=i.possessive?.specialForms;if(t){for(let[n,a]of Object.entries(t))if(a===e)return n}}function yr(i){return Ot.possessive?.specialForms?.[i]??`${i}'s`}var Rr={ar:{\u0642\u064A\u0645\u0629:"value"},bn:{\u0985\u0995\u09CD\u09B7\u09AE:"disabled","\u099A\u09C7\u0995 \u0995\u09B0\u09BE":"checked",\u09A6\u09C8\u09B0\u09CD\u0998\u09CD\u09AF:"length",\u09AE\u09BE\u09A8:"value"},de:{wert:"value"},es:{valor:"value"},fr:{valeur:"value"},hi:{\u0905\u0915\u094D\u0937\u092E:"disabled",\u091A\u0947\u0915:"checked",\u091B\u093F\u092A\u093E:"hidden",\u092E\u093E\u0928:"value"},id:{nilai:"value"},it:{valore:"value"},ja:{\u5024:"value"},ko:{\uAC12:"value"},ms:{dilumpuhkan:"disabled",ditanda:"checked",nilai:"value",panjang:"length"},pl:{warto\u015B\u0107:"value"},pt:{valor:"value"},qu:{chanin:"value"},ru:{\u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435:"value",\u043E\u0442\u043A\u043B\u044E\u0447\u0435\u043D\u043E:"disabled",\u043E\u0442\u043C\u0435\u0447\u0435\u043D\u043E:"checked",\u0441\u043A\u0440\u044B\u0442\u043E:"hidden"},sw:{thamani:"value"},th:{\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27:"length",\u0E04\u0E48\u0E32:"value",\u0E1B\u0E34\u0E14\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19:"disabled",\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E41\u0E25\u0E49\u0E27:"checked"},tl:{haba:"length",halaga:"value",hindi_pinagana:"disabled",naka_tsek:"checked"},tr:{de\u011Fer:"value"},uk:{\u0432\u0438\u043C\u043A\u043D\u0435\u043D\u043E:"disabled",\u0437\u043D\u0430\u0447\u0435\u043D\u043D\u044F:"value",\u043F\u043E\u0437\u043D\u0430\u0447\u0435\u043D\u043E:"checked",\u043F\u0440\u0438\u0445\u043E\u0432\u0430\u043D\u043E:"hidden"},vi:{\u1EA9n:"hidden","\u0111\u01B0\u1EE3c ch\u1ECDn":"checked","gi\xE1 tr\u1ECB":"value","v\xF4 hi\u1EC7u":"disabled"},zh:{\u503C:"value"}},yo={ar:{\u0643\u0640:"as"},bn:{\u09B9\u09BF\u09B8\u09BE\u09AC\u09C7:"as"},de:{als:"as"},es:{como:"as"},fr:{comme:"as"},hi:{\u0915\u0947_\u0930\u0942\u092A_\u092E\u0947\u0902:"as"},id:{sebagai:"as"},it:{come:"as"},ja:{\u3068\u3057\u3066:"as"},ko:{\uB85C:"as"},ms:{sebagai:"as"},pl:{jako:"as"},pt:{como:"as"},qu:{hina:"as"},ru:{\u043A\u0430\u043A:"as"},sw:{kuwa:"as"},tl:{bilang:"as"},tr:{olarak:"as"},uk:{\u044F\u043A:"as"},vi:{nh\u01B0:"as"},zh:{\u4F5C\u4E3A:"as"}},Lt={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"]),ar:new Set(["\u0644\u0640"]),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","n\u0131n","nun","n\xFCn","in","\u0131n","un","\xFCn"])};function wr(i,e){let r=e.value.toLowerCase(),t=(e.normalized??"").toLowerCase();if(r==="of"||r==="ng"||t==="of"||t==="source")return true;let n=i?.code?Lt[i.code]:void 0;return !!n&&n.has(r)}var vo={destination:"in",source:"from"},Eo={ar:new Set(["\u0639\u0646\u062F","\u0641\u064A"]),bn:new Set(["\u098F","\u09A4\u09C7"]),de:new Set(["bei"]),es:new Set(["en"]),fr:new Set(["dans","en","\xE0"]),he:new Set(["\u05DC\u05EA\u05D5\u05DA"]),hi:new Set(["\u092A\u0930","\u092E\u0947\u0902"]),id:new Set(["dalam","di","ke_dalam"]),it:new Set(["a"]),ja:new Set(["\u3067","\u306E\u4E2D","\u3078"]),ko:new Set(["\uC548\uC5D0","\uC5D0","\uC73C\uB85C"]),ms:new Set(["dalam","di","ke_dalam"]),pl:new Set(["do","przy","w"]),pt:new Set(["dentro","em"]),qu:new Set(["pi","ukupi"]),ru:new Set(["\u0432","\u0443"]),sw:new Set(["katika","ndani"]),th:new Set(["\u0E17\u0E35\u0E48","\u0E43\u0E19"]),tl:new Set(["papasok_sa","sa","sa_loob"]),tr:new Set(["de","i\xE7inde","i\xE7ine"]),uk:new Set(["\u0432","\u0443"]),vi:new Set(["trong","t\u1EA1i","v\xE0o"]),zh:new Set(["\u5728","\u8FDB\u5165"])},go=new Set(["in","into","at","within","inside"]);function Co(i,e){let r=e.value.toLowerCase();if((i?.code?Eo[i.code]:void 0)?.has(r))return "in";let n=e.normalized??e.value,a=n.toLowerCase();return go.has(a)?"in":vo[a]??n}var hr=new Set(["first","last","next","previous","random","closest"]),zo={bn:{\u09B6\u09C7\u09B7:"last"}},Or=new Set(Object.keys(se).map(i=>i.toLowerCase()));function Nt(i,e,r,t){let n=i[e];if(!n)return null;let a=(n.normalized??n.value).toLowerCase(),o=i[e+1],u=r?.code&&o?.kind==="selector"&&o.value.startsWith("<")?zo[r.code]?.[n.value.toLowerCase()]:void 0;if(!hr.has(a)&&!hr.has(n.value.toLowerCase())&&u===void 0)return null;let s=[{text:u??n.normalized??n.value,token:n}],l=e+1,c=i[l];if(!c||c.kind!=="selector")return null;s.push({text:c.value,token:c}),l++;let m=0;for(;m++<8;){let f=i[l];if(f&&f.kind==="selector"&&f.value.startsWith("."))s.push({text:f.value,token:f}),l++;else break}let d=i[l],p=i[l+1];return d&&p&&p.kind==="selector"&&(d.kind==="keyword"||d.kind==="particle"||d.kind==="identifier")&&!hr.has((d.normalized??d.value).toLowerCase())&&!Or.has((d.normalized??d.value).toLowerCase())&&!(t?.(d)===true&&t(i[l+2])!==true)&&(s.push({text:Co(r,d),token:d}),s.push({text:p.value,token:p}),l+=2),{parts:s,consumed:l-e}}function ko(i,e){let r=yo[i];return r?r[e.toLowerCase()]??e:e}function me(i,e){let r=Rr[i];return r?r[e.toLowerCase()]??e:e}function wo(i,e){return Rr[i]?.[e.toLowerCase()]!==void 0}function bo(i,e){let r=[e.value,e.normalized].filter(Boolean);for(let t of r){let n=ce(i,t)??ce(i,t.toLowerCase());if(n)return n}}function Mt(i){return i.kind==="literal"||i.kind==="operator"||i.kind==="punctuation"?false:!/^[$:@#.*^(){}[\]]/.test(i.value)}function Ao(i,e){let r=i?.references;if(!r)return false;let t=Object.values(r).filter(a=>typeof a=="string").map(a=>a.toLowerCase());return [e.value,e.normalized].filter(Boolean).some(a=>t.includes(a.toLowerCase()))}function it(i,e){return Mt(i)?me(e,i.value)!==i.value?true:i.kind==="identifier":false}var Do={ar:{\u0647\u0648:{beforePredicate:"is"}},hi:{\u0939\u0948:{beforePredicate:"is"},\u0928\u0939\u0940\u0902:{beforeBareIdentifier:"no"}},th:{\u0E40\u0E1B\u0E47\u0E19:{beforeTypeName:"as",beforePredicate:"is"}},ja:{\u7A7A:{afterCopula:"empty"}},zh:{\u6CA1\u6709:{beforeBareIdentifier:"no"}},tl:{walang:{beforeBareIdentifier:"no"},may:{afterSubject:"exists"}},bn:{\u0986\u099B\u09C7:{afterSubject:"exists"}},tr:{var:{afterSubject:"exists"}}},So=new Set(["empty","null","undefined","true","false"]),_t=new Set(["Number","Int","Float","String","Date","Array","Object","JSON","json","FormData","HTML","Fragment","Values"]);function Bo(i,e,r,t){let n=Do[i],a=n?.[e.value]??n?.[e.value.toLowerCase()];if(a){if(a.beforeTypeName&&t?.kind==="identifier"&&_t.has(t.value))return a.beforeTypeName;if(a.beforePredicate&&t&&(t.kind==="literal"||t.kind==="keyword"&&So.has((t.normalized??"").toLowerCase())))return a.beforePredicate;if(a.beforeBareIdentifier&&t?.kind==="identifier"&&/^[A-Za-z_]\w*$/.test(t.value))return a.beforeBareIdentifier;if(a.afterSubject&&(r?.kind==="selector"||r?.kind==="reference"))return a.afterSubject;if(a.afterCopula&&r?.kind==="keyword"&&(r.normalized??"").toLowerCase()==="is")return a.afterCopula}}function xe(i,e){let r=e?.code??"en",t="",n,a=(u,s)=>{if(n===void 0){t=u,n=s;return}let c=n.position?.end!==void 0&&s.position?.start!==void 0&&n.position.end===s.position.start&&(u.startsWith(".")||u.startsWith("!"));t+=(c?"":" ")+u,n=s;},o=u=>u.kind==="keyword"?u.normalized??u.value:u.value;for(let u=0;u<i.length;u++){let s=i[u],l=e?bo(e,s):void 0,c=i[u+1];if(s.value==="'"&&n!==void 0&&c?.value==="s"&&s.position?.end!==void 0&&c.position?.start===s.position.end){t+="'s",n=c;let v=i[u+2];v&&me(r,v.value)!==v.value?(a(me(r,v.value),v),u+=2):u+=1;continue}if(l!==void 0&&c){let v=e?.possessive?.connectors,E=!!v?.length&&v.some(z=>{let A=z.toLowerCase();return A===c.value.toLowerCase()||A===(c.normalized??"").toLowerCase()}),y=E?u+2:u+1,h=i[y];if(h&&it(h,r)){a(yr(l),s),a(me(r,h.value),h),u=y;continue}if(E&&h&&/^\.[a-zA-Z_]\w*$/.test(h.value)&&c.position?.end!==void 0&&h.position?.start!==void 0&&c.position.end===h.position.start){a(yr(l),s),a(me(r,h.value.slice(1)),h),u=y;continue}if(!E&&/^\.[a-zA-Z_]\w*$/.test(c.value)&&s.position?.end!==void 0&&c.position?.start!==void 0&&s.position.end===c.position.start&&!Ao(e,s)){a(yr(l),s),a(me(r,c.value.slice(1)),c),u+=1;continue}}let m=i[u+2];if(c&&m&&m.kind==="selector"&&wr(e,c)&&Mt(s)){a(me(r,s.value),s),a("of",c),a(m.value,m),u+=2;continue}if(s.kind==="selector"&&c&&m&&wr(e,c)&&it(m,r)&&me(r,m.value)!==m.value){a(me(r,m.value),m),a("of",c),a(s.value,s),u+=2;continue}let d=Nt(i,u,e);if(d){for(let v of d.parts)a(v.text,v.token);u+=d.consumed-1;continue}let p=Bo(r,s,i[u-1],c);if(p!==void 0){a(p,s);continue}let f=ko(r,s.value);if(f!==s.value){a(f,s);continue}a(o(s),s);}return t.trim()}var It=[{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:true,objMarker:"i",at:"de",end:"son",of:"nin"},{lang:"ja",verb:"\u7F6E\u304F",sov:true,objMarker:"\u3092",at:"\u3067",end:"\u7D42\u308F\u308A",of:"\u306E"},{lang:"ko",verb:"\uB123\uB2E4",sov:true,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:true,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:true,objMarker:"\u0995\u09C7",at:"\u098F",end:"\u09B6\u09C7\u09B7",of:"\u09B0"},{lang:"qu",verb:"churay",sov:true,objMarker:"ta",at:"pi",end:"tukuy",of:"pa"}];function nt(i,e,r,t){let n=It.find(o=>o.lang===i);if(!n)return false;let a=(o,u)=>(o??"").toLowerCase()===u.toLowerCase();return a(e,n.end)&&a(r,n.at)&&a(t,n.of)}function xo(i,e){let r=It.find(n=>n.lang===i);if(!r)return false;let t=e.toLowerCase();return t===r.at.toLowerCase()||t===r.of.toLowerCase()||t===r.end.toLowerCase()}var jt={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"])};function To(i){return jt[i]}function at(i,e){return jt[e]?.has(i.toLowerCase())??false}var $t=96,Fo=/^[A-Za-z_][\w-]*$/,Ro=/^[A-Za-z_][\w-]*:[^\s'"`/:][^\s]*$/;function Vt(i,e){let r=i.peek(e);return !!r&&r.kind==="identifier"&&Ro.test(r.value)}function qt(i,e){let r=i.peek(e);if(!r||r.kind!=="identifier"&&r.kind!=="keyword"||!Fo.test(r.value))return false;let t=i.peek(e+1),n=i.peek(e+2);return !!t&&t.value===":"&&!!n}function ot(i,e=0){return Vt(i,e)||qt(i,e)}function Oo(i){let e=i.peek();if(!e||e.value!=="{"&&e.value!=="(")return null;let r="",t=-1,n=0,a=0;for(;!i.isAtEnd()&&a++<$t;){let o=i.advance();if(!o)break;if(t>=0&&o.position.start>t&&(r+=" ".repeat(o.position.start-t)),r+=o.value,t=o.position.end,o.value==="{"||o.value==="(")n++;else if((o.value==="}"||o.value===")")&&(n--,n===0))return r}return null}function ut(i){let e=i.peek();return e?e.value==="{"||e.value==="("?Oo(i):e.value===","||e.value===":"?null:(i.advance(),e.value):null}function We(i,e){let r=i.mark(),t=[];if(e!==void 0){let a=i.peek();if(!a||a.value!==":"||!i.peek(1))return null;i.advance();let o=ut(i);if(o===null)return i.reset(r),null;t.push(`${e}:${o}`);}else if(!ot(i))return null;let n=0;for(;n++<$t;){let a=i.peek();if(!a)break;if(a.value===","){if(t.length===0||!ot(i,1))break;i.advance();continue}if(Vt(i,0)){t.push(i.advance().value);continue}if(!qt(i,0))break;let o=i.advance().value;i.advance();let u=ut(i);if(u===null)return i.reset(r),null;t.push(`${o}:${u}`);}return t.length===0?(i.reset(r),null):`{${t.join(", ")}}`}var ir=.8,Po=.6,Lo=.15,No=.5,st=.15,lt=.1,ct=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"]),Mo={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"]},_o=class{calculate(i){return this.calculateWithBreakdown(i).final}calculateWithBreakdown(i){let e=this.scoreRoleCoverage(i),r=this.scoreStemPenalty(i),t=this.scoreLanguageBoost(i),n=this.scoreLanguageAdjustment(i),a=e;return a=Math.max(No,a+r),a=Math.min(1,a+t),a=Math.max(0,Math.min(1,a+n)),{roleCoverage:e,stemPenalty:r,languageBoost:t,languageAdjustment:n,final:a}}scoreRoleCoverage(i){let{pattern:e,captured:r}=i,t=0,n=0,a=l=>e.extraction?.[l]?.default!==void 0,o=e.command==="on"?e.extraction?.action?.value:void 0,u=se[o??e.command]?.roles,s=l=>u?.find(c=>c.role===l)?.valueShape!==void 0;for(let l of e.template.tokens)if(l.type==="role")r.has(l.role)?(n+=1,t+=1):s(l.role)||(n+=1);else if(l.type==="group")for(let c of l.tokens)c.type==="role"&&(r.has(c.role)?(n+=ir,t+=ir):s(c.role)||(n+=ir,a(c.role)&&(t+=ir*Po)));return n>0?t/n:1}scoreStemPenalty(i){let{stemMatchCount:e,totalKeywordMatches:r}=i;return e<=0||r<=0?0:-(e/r)*Lo}scoreLanguageBoost(i){let{pattern:e}=i;if(e.language!=="ar")return 0;let r=e.template.tokens[0];return !r||r.type!=="literal"?0:ct.has(r.value)||r.alternatives?.some(t=>ct.has(t))?st:0}scoreLanguageAdjustment(i){let{pattern:e,captured:r}=i;if(e.language!=="ar")return 0;let t=0;for(let[n,a]of r.entries()){let o=Mo[n];if(!o||o.length===0)continue;let u="metadata"in a?a.metadata:void 0;u&&typeof u.prepositionValue=="string"&&(o.includes(u.prepositionValue)?t+=.1:t-=.1);}return Math.max(-lt,Math.min(lt,t))}},Io=new _o,jo=new Set(Object.values(se).filter(i=>i.bareKeyword===true).map(i=>i.action));function $o(i){return i.startsWith("*")||i.startsWith("@")}var X=class M{constructor(e){this.matchCache=new Map,this.roleStarts=new Map,this.stemMatchCount=0,this.totalKeywordMatches=0,this.confidenceModel=e??Io;}matchPattern(e,r){let t=e.mark(),n=new Map;if(this.currentProfile=P(r.language),this.currentPatternCommand=r.command,this.stemMatchCount=0,this.totalKeywordMatches=0,this.roleStarts=new Map,!this.matchTokenSequence(e,r.template.tokens,n))return e.reset(t),null;let o=this.confidenceModel.calculate({pattern:r,captured:n,stemMatchCount:this.stemMatchCount,totalKeywordMatches:this.totalKeywordMatches});return this.applyExtractionRules(r,n),{pattern:r,captured:n,consumedTokens:e.position()-t.position,confidence:o,roleStarts:this.roleStarts}}matchBest(e,r){this.matchCache.clear();let t=[],n=e.position();for(let o of r){let u=e.mark(),s=`${n}:${o.id}`,l;this.matchCache.has(s)?l=this.matchCache.get(s):(l=this.matchPattern(e,o),this.matchCache.set(s,l)),l&&t.push(l),e.reset(u);}if(t.length===0)return null;t.sort((o,u)=>{let s=u.pattern.priority-o.pattern.priority;return s!==0?s:u.confidence-o.confidence});let a=t[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,r,t,n){let a=r[0],o=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!o)for(;e.peek()?.kind==="conjunction";)e.advance();let u=0;for(let s=0;s<r.length;s++){let l=r[s];if(u>0&&l.type==="literal"&&this.tryConsumeEventSourceClause(e,t,l),this.shouldTrySkippingVerbSlot(l,e,r[s+1]??n)){let m=e.mark(),d=new Map(t);if(this.matchTokenSequence(e,r.slice(s+1),d,n)&&this.atClauseEnd(e)){t.clear();for(let[p,f]of d)t.set(p,f);return true}e.reset(m);}let c=this.matchPatternToken(e,l,t,r[s+1]??n);if(u=l.type==="role"&&l.role==="event"?2:Math.max(0,u-1),!c){if(this.isOptional(l))continue;return false}}return true}tryConsumeEventSourceClause(e,r,t){if(r.has("source"))return;let n=e.peek(),a=e.peek(1);if(!n||!a||this.patternTokenWouldMatch(t,n))return;let o=this.currentProfile?.roleMarkers?.source,u=l=>{if(l.kind!=="particle"&&l.kind!=="keyword")return false;if((l.normalized??"").toLowerCase()==="source")return true;if(!o)return false;let c=l.value.toLowerCase();return o.primary?.toLowerCase()===c?true:!!o.alternatives?.some(m=>m.toLowerCase()===c)},s=o?.position;if(s!=="after"&&u(n)&&a.kind==="selector"){e.advance();let l=this.tokenToSemanticValue(e.advance());l&&r.set("source",l);return}if(s==="after"&&n.kind==="selector"&&u(a)){let l=this.tokenToSemanticValue(n);e.advance(),e.advance(),l&&r.set("source",l);}}matchPatternToken(e,r,t,n){switch(r.type){case "literal":return this.matchLiteralToken(e,r);case "role":{let a=e.position(),o=this.matchRoleToken(e,r,t,n);return o&&t.has(r.role)&&this.roleStarts.set(r.role,a),o}case "group":return this.matchGroupToken(e,r,t,n);default:return false}}matchLiteralToken(e,r){let t=e.peek();if(!t)return false;let n=this.getMatchType(t,r.value);if(n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),true;if(r.alternatives)for(let a of r.alternatives){let o=this.getMatchType(t,a);if(o!=="none")return this.totalKeywordMatches++,o==="stem"&&this.stemMatchCount++,e.advance(),true}for(let a of [r.value,...r.alternatives??[]])for(let o of ["-","_"])if(a.includes(o)&&this.tryMatchShatteredCompound(e,a,o))return this.totalKeywordMatches++,true;return false}tryFoldHyphenActionKeyword(e){let r=this.currentProfile;if(!r)return null;let t=e.mark(),n=[];for(;;){let o=e.peek();if(!o||o.kind!=="identifier"&&o.kind!=="keyword")break;n.push(o.value),e.advance();let u=e.peek();if(!u||u.value!=="-")break;e.advance(),n.push("-");}if(n.length<3||n[n.length-1]==="-")return e.reset(t),null;let a=n.join("").toLowerCase();for(let[o,u]of Object.entries(r.keywords))if(u.primary.toLowerCase()===a||u.alternatives?.some(s=>s.toLowerCase()===a))return W(o);return e.reset(t),null}tryMatchShatteredCompound(e,r,t){let n=r.split(t);if(n.length<2||n.some(o=>o.length===0))return false;let a=e.mark();for(let o=0;o<n.length;o++){if(o>0){let s=e.peek();if(!s||s.value!==t)return e.reset(a),false;e.advance();}let u=e.peek();if(!u||u.kind!=="identifier"&&u.kind!=="keyword"&&u.kind!=="particle"||u.value.toLowerCase()!==n[o].toLowerCase())return e.reset(a),false;e.advance();}return true}matchRoleToken(e,r,t,n){let a=e.position(),o=t.get(r.role);return this.matchRoleTokenCore(e,r,t,n)?(this.absorbTrailingConversion(e,r,t,n,a),this.absorbTrailingConditionOperand(e,r,t,n,a),this.stampCaptureSpan(e,r.role,t,a,o),true):false}stampCaptureSpan(e,r,t,n,a){let o=t.get(r);if(!o||o===a||o.position||e.position()<=n)return;let u=e.tokens[n],s=e.tokens[e.position()-1];!u||!s||t.set(r,so(o,{start:u.position.start,end:s.position.end}));}absorbTrailingConditionOperand(e,r,t,n,a){if(r.role!=="condition"||!t.has("condition")||e.position()<=a||n!==void 0||this.currentPatternCommand!=="on")return;let o=e.peek();if(!o)return;let u=M.CONDITION_OPERATOR_WORDS;if(!u.has((o.normalized??"").toLowerCase())&&!u.has(o.value.toLowerCase())||this.patternTokenWouldMatch(n,o))return;e.advance();let s=e.peek();s&&(s.kind==="selector"||s.kind==="identifier"||s.kind==="literal")&&!Or.has((s.normalized??s.value).toLowerCase())&&e.advance();let l=xe(e.tokens.slice(a,e.position()),this.currentProfile);t.set("condition",{type:"expression",raw:l,value:l});}conversionRunLength(e){let r=e.peek();if(!r||(r.normalized??r.value).toLowerCase()!=="as"&&r.value.toLowerCase()!=="as")return 0;let n=e.peek(1);return !n||!_t.has(n.value)?0:2}absorbTrailingConversion(e,r,t,n,a){if(r.role==="event"||r.role==="action"||!t.has(r.role)||e.position()<=a||this.conversionRunLength(e)!==2||this.patternTokenWouldMatch(n,e.peek()))return;e.advance(),e.advance();let o=xe(e.tokens.slice(a,e.position()),this.currentProfile);t.set(r.role,{type:"expression",raw:o,value:o});}matchRoleTokenCore(e,r,t,n){this.skipNoiseWords(e);let a=e.peek();if(!a)return r.optional||false;if(r.role==="action"&&this.currentProfile&&e.peek(1)?.value==="-"){let y=this.tryFoldHyphenActionKeyword(e);if(y)return t.set(r.role,y),true}if(r.role==="event"&&this.currentPatternCommand==="on"){if(!M.tokenLooksLikeEvent(a))return r.optional||false;let y=(a.normalized??a.value).toLowerCase();if(M.POSITIONAL_OR_SCOPE_KEYWORDS.has(y)||this.currentProfile&&(ce(this.currentProfile,a.value)??ce(this.currentProfile,y))!==void 0||a.value.includes("?."))return r.optional||false}if(r.role==="event"){let y=(a.normalized??a.value).toLowerCase();if(M.STRUCTURAL_NEVER_EVENT.has(y))return r.optional||false}if(a.kind==="keyword"){let y=(a.normalized??a.value).toLowerCase();if(y==="then"||y==="end"&&e.peek(1)?.kind!=="selector"||at(a.value,this.currentProfile?.code??"")||(r.role==="quantity"||r.role==="event"&&this.currentPatternCommand==="repeat")&&(a.normalized??a.value).toLowerCase()in se)return r.optional||false}if(r.role==="duration"){let y=(a.normalized??a.value).toLowerCase();if(M.POSITIONAL_OR_SCOPE_KEYWORDS.has(y))return r.optional||false}if(r.optional&&r.role!=="event"&&r.role!=="action"&&r.valueShape!=="keyword"&&a.kind==="keyword"&&(a.normalized??a.value).toLowerCase()in se&&(n===void 0||this.patternTokenWouldMatch(n,a)))return true;let o=this.tryMatchPositionalExpression(e,n);if(o)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(o.type,r.expectedTypes)?r.optional||false:(t.set(r.role,o),true);let u=this.tryMatchCaretScopeExpression(e);if(u)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(u.type,r.expectedTypes)?r.optional||false:(t.set(r.role,u),true);if(r.role!=="event"&&(!r.expectedTypes||r.expectedTypes.includes("expression"))){let y=this.tryMatchBeepPrefixExpression(e);if(y)return t.set(r.role,y),true;let h=this.tryMatchHyphenatedWord(e);if(h)return t.set(r.role,h),true;let z=this.tryMatchOperatorRunExpression(e);if(z)return t.set(r.role,z),true}if(this.currentPatternCommand==="pick"&&r.role==="patient"&&(!r.expectedTypes||r.expectedTypes.includes("expression"))){let y=this.tryMatchPickRangeExpression(e);if(y)return t.set(r.role,y),true}if(r.expectedTypes?.includes("property-path")){let y=this.tryMatchOfPossessiveExpression(e);if(y)return t.set(r.role,y),true;let h=this.tryMatchPostNominalPossessiveExpression(e);if(h)return t.set(r.role,h),true}let s=this.tryMatchPossessiveExpression(e);if(s)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(s.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,s),true);let l=this.tryMatchMethodCallExpression(e);if(l)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(l.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,l),true);let m=r.role==="event"&&this.currentPatternCommand==="on"||M.DECLARATION_COMMANDS.has(this.currentPatternCommand??"")?null:this.tryMatchBareCallExpression(e);if(m)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(m.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,m),true);let d=this.tryMatchPossessiveSelectorExpression(e);if(d)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(d.type,r.expectedTypes)?r.optional||false:(t.set(r.role,d),true);let p=r.role!=="condition",f=this.tryMatchPropertyAccessExpression(e,p);if(f)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(f.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,f),true);let v=this.tryMatchSelectorPropertyExpression(e);if(v)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(v.type,r.expectedTypes)?r.optional||false:(t.set(r.role,v),true);if(a.kind==="identifier"&&a.value==="{"){let y=r.expectedTypes,z=y?.length===1&&y[0]==="expression"?this.tryMatchBraceRunExpression(e):!y?.length||y.includes("literal")?this.tryMatchBraceRunLiteral(e):null;if(z)return t.set(r.role,z),true}if(r.role==="style"&&r.expectedTypes?.length===1&&r.expectedTypes[0]==="expression"){let y=We(e);if(y)return t.set(r.role,{type:"expression",raw:y}),true}let E=this.tokenToSemanticValue(a);if(!E)return r.optional||false;if(r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(E.type)){let y=E.type==="selector"&&String(E.value).startsWith("@"),h=r.expectedTypes.some(z=>z==="expression"||z==="reference");if(!(y&&h))return r.optional||false}if(r.valueShape==="keyword"&&E.type==="expression"?t.set(r.role,W(String(E.raw??""))):t.set(r.role,E),e.advance(),r.role==="event"){let y=e.peek();y&&y.kind==="selector"&&y.value.startsWith("[")&&"value"in E&&(t.set(r.role,W(`${String(E.value)}${y.value}`)),e.advance());let h=e.peek();if(h&&(h.kind==="particle"||h.kind==="keyword")&&(h.normalized??"").toLowerCase()==="source"&&!this.patternTokenWouldMatch(n,h)){let z=e.peek(1);if(z&&(z.kind==="selector"||z.kind==="identifier")){e.advance();let A=this.tokenToSemanticValue(e.advance());A&&!t.has("source")&&t.set("source",A);}}}return true}shouldTrySkippingVerbSlot(e,r,t){let n=e.type==="group"&&e.optional?e.tokens.every(u=>u.type==="role")?e.tokens[0]:void 0:e;if(!n||n.type!=="role"||!n.optional||n.role==="event"||n.role==="action"||n.valueShape==="keyword")return false;let a=r.peek();if(!a||a.kind!=="keyword"||t===void 0)return false;let o=this.patternTokenWouldMatch(t,a);return (a.normalized??a.value).toLowerCase()in se?!o:o}atClauseEnd(e){let r=e.peek();if(!r||r.kind==="conjunction")return true;if(r.kind!=="keyword")return false;let t=(r.normalized??r.value).toLowerCase();return t==="then"||t==="end"?true:at(r.value,this.currentProfile?.code??"")}patternTokenWouldMatch(e,r){return e?e.type==="literal"?this.getMatchType(r,e.value)!=="none"?true:!!e.alternatives?.some(t=>this.getMatchType(r,t)!=="none"):e.type==="group"?this.patternTokenWouldMatch(e.tokens?.[0],r):false:false}tryMatchPositionalExpression(e,r){let t=Nt(e.tokens,e.position(),this.currentProfile,n=>n===void 0?false:this.patternTokenWouldMatch(r,n));if(!t)return null;for(let n=0;n<t.consumed;n++)e.advance();return {type:"expression",raw:t.parts.map(n=>n.text).join(" ")}}tryMatchCaretScopeExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"||!r.value.startsWith("^"))return null;let t=e.peek(1),n=e.peek(2),a=(t?.normalized??"").toLowerCase(),o=!!t&&(t.value.toLowerCase()==="on"||a==="destination"||a==="on");return !t||!n||n.kind!=="selector"||!o?null:(e.advance(),e.advance(),e.advance(),{type:"expression",raw:`${r.value} on ${n.value}`})}isOfPossessiveMarker(e){return wr(this.currentProfile,e)}static isBareWordToken(e){return !!e&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(e.value)}static tokensAdjacent(e,r){return e?.position?.end!==void 0&&r?.position?.start!==void 0&&e.position.end===r.position.start}tryMatchBeepPrefixExpression(e){let r=e.peek(),t=e.peek(1);if(!r||!t||t.value!=="!"||(r.normalized??r.value).toLowerCase()!=="beep"||!(r.position?.end!==void 0&&t.position?.start!==void 0&&r.position.end===t.position.start))return null;let a=e.mark(),o=e.position();if(e.advance(),e.advance(),!this.tryConsumeRunOperand(e))return e.reset(a),null;for(;;){let s=e.peek();if(!s||!M.RUN_OPERATORS.has(s.value))break;let l=e.mark();if(e.advance(),!this.tryConsumeRunOperand(e)){e.reset(l);break}}let u=xe(e.tokens.slice(o,e.position()),this.currentProfile);return {type:"expression",raw:u,value:u}}tryMatchHyphenatedWord(e){let r=e.peek();if(!M.isBareWordToken(r))return null;let t=1,n=[r.value];for(;;){let a=e.peek(t),o=e.peek(t+1);if(!a||a.value!=="-"||!M.isBareWordToken(o)||!M.tokensAdjacent(e.peek(t-1),a)||!M.tokensAdjacent(a,o))break;n.push(o.value),t+=2;}if(n.length<2)return null;for(let a=0;a<t;a++)e.advance();return W(n.join("-"),"string")}tryMatchOperatorRunExpression(e){let r=e.mark(),t=e.position();if(!this.tryConsumeRunOperand(e))return e.reset(r),null;let n=1;for(;;){let o=e.peek();if(!o||!M.RUN_OPERATORS.has(o.value))break;let u=e.mark();if(e.advance(),!this.tryConsumeRunOperand(e)){e.reset(u);break}n++;}if(n<2)return e.reset(r),null;let a=xe(e.tokens.slice(t,e.position()),this.currentProfile);return {type:"expression",raw:a,value:a}}static rangeSeparatorFor(e){let[r]=M.PICK_RANGE_SEPARATORS_BY_LANG[e]??[];return r}isPickRangeSeparator(e){let r=(e.normalized??e.value).toLowerCase();if(M.PICK_RANGE_SEPARATORS.has(r))return true;let t=this.currentProfile?.code;return t?M.PICK_RANGE_SEPARATORS_BY_LANG[t]?.has(e.value.toLowerCase())??false:false}tryMatchPickRangeExpression(e){let r=e.mark(),t=e.position();if(!this.tryConsumePickRangeOperand(e))return e.reset(r),null;let n=e.peek();if(!n||!this.isPickRangeSeparator(n)||(e.advance(),!this.tryConsumePickRangeOperand(e)))return e.reset(r),null;let a=e.peek();a&&M.PICK_RANGE_MODES.has((a.normalized??a.value).toLowerCase())&&e.advance();let o=e.tokens.slice(t,e.position()),[u,,s,l]=o,c=d=>d.kind==="keyword"?d.normalized??d.value:d.value,m=`${c(u)} to ${c(s)}`;return l&&(m+=` ${(l.normalized??l.value).toLowerCase()}`),{type:"expression",raw:m,value:m}}tryConsumePickRangeOperand(e){let r=e.peek();if(!r)return false;let t=(r.normalized??r.value).toLowerCase();if(this.isPickRangeSeparator(r))return false;let n=t==="start"||t==="end";return r.kind==="literal"||r.kind==="identifier"||r.kind==="keyword"&&n?(e.advance(),true):false}tryConsumeRunOperand(e){let r=e.peek();if(!r)return false;if(r.value==="("){let t=e.mark(),n=0;for(;!e.isAtEnd();){let a=e.advance();if(a.value==="(")n++;else if(a.value===")"&&(n--,n===0))return true}return e.reset(t),false}return this.tryMatchPossessiveExpression(e)?true:(r.kind==="literal"||r.kind==="identifier"||r.kind==="selector"||r.kind==="keyword")&&!M.RUN_OPERATORS.has(r.value)&&r.value!==")"?(e.advance(),true):false}isPossessorToken(e){if(!this.currentProfile)return false;for(let r of [e.value,e.normalized].filter(Boolean))if(ce(this.currentProfile,r)??ce(this.currentProfile,r.toLowerCase()))return true;return false}isBareWordPropertyHead(e){return e.kind!=="identifier"||/^[$:@#.*]/.test(e.value)||this.isStructuralKeyword(e.value)||e.normalized&&this.isStructuralKeyword(e.normalized)||e.normalized&&this.isRoleMarkerConcept(e.normalized)?false:!this.isPossessorToken(e)}toEnglishProperty(e){return this.currentProfile?me(this.currentProfile.code,e):e}tryMatchOfPossessiveExpression(e){let r=e.peek();if(!r||r.kind!=="selector"&&!this.isBareWordPropertyHead(r))return null;let t=e.mark();e.advance();let n=e.peek();if(!n||!this.isOfPossessiveMarker(n))return e.reset(t),null;e.advance();let a=e.peek();return !a||a.kind!=="selector"||$o(a.value)?(e.reset(t),null):(e.advance(),ge(ve(a.value),this.toEnglishProperty(r.value),"possessive"))}tryMatchPossessiveExpression(e){let r=e.peek();if(!r||!this.currentProfile)return null;let t=[r.value,r.normalized].filter(Boolean),n;for(let s of t)if(n=ce(this.currentProfile,s)??ce(this.currentProfile,s.toLowerCase()),n)break;if(!n)return null;let a=e.mark();e.advance();let o=this.currentProfile.possessive?.connectors;if(o&&o.length>0){let s=e.peek();if(s){let l=s.value.toLowerCase(),c=(s.normalized??"").toLowerCase();o.some(m=>m.toLowerCase()===l||m.toLowerCase()===c)&&e.advance();}}let u=e.peek();if(!u||xo(this.currentProfile.code,u.value))return e.reset(a),null;if(u.kind==="identifier"||u.kind==="keyword"&&!this.isStructuralKeyword(u.value)&&!(u.normalized&&this.isStructuralKeyword(u.normalized))&&!(u.normalized&&this.isRoleMarkerConcept(u.normalized))&&!(u.normalized&&M.COMMAND_ACTION_KEYWORDS.has(u.normalized.toLowerCase()))||u.kind==="selector"&&u.value.startsWith("*")||u.kind==="selector"&&u.value.startsWith("@")||u.kind==="selector"&&u.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(u.value)){e.advance();let s=u.value;u.kind==="selector"&&s.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s)&&(s=s.substring(1)),s=this.toEnglishProperty(s);let l=s;for(;;){let m=e.peek();if(m?.kind==="selector"&&m.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(m.value)){l+=m.value,e.advance();continue}if(m?.value==="?"){let d=e.peek(1);if(d?.kind==="selector"&&d.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(d.value)){l+=`?${d.value}`,e.advance(),e.advance();continue}}break}let c=e.peek();if(c&&c.value.startsWith("(")){let m="",d=0,p=0;for(;!e.isAtEnd()&&p++<M.MAX_METHOD_ARGS+2;){let f=e.peek();if(!f)break;m+=f.value,e.advance();for(let v of f.value)v==="("?d++:v===")"&&d--;if(d<=0)break}l+=m;}return ge(ue(n),l,"possessive")}return e.reset(a),null}tryMatchPostNominalPossessiveExpression(e){if(!this.currentProfile||this.currentProfile.possessive?.markerPosition!=="after-object")return null;let r=e.peek();if(!r)return null;let t=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("@"))||t)||this.isPossessorToken(r))return null;let a=e.mark(),o=r.value;t&&(o=o.substring(1)),e.advance(),o=this.toEnglishProperty(o);let u=o;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)u+=e.peek().value,e.advance();let s=e.peek();if(!s)return e.reset(a),null;let l;for(let c of [s.value,s.normalized].filter(Boolean))if(l=ce(this.currentProfile,c)??ce(this.currentProfile,c.toLowerCase()),l)break;return l?(e.advance(),ge(ue(l),u,"possessive")):(e.reset(a),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 Pt.has(e.toLowerCase())}static tokenLooksLikeEvent(e){if(e.kind==="selector"||e.kind==="url"||e.kind==="literal")return false;let r=e.value;if(/[/#@*]/.test(r)||r.startsWith('"')||r.startsWith("'")||r.startsWith("`"))return false;let t=e.normalized?.toLowerCase();return !(t&&jo.has(t)||t==="me"||t==="it"||t==="you")}tryMatchBraceRunLiteral(e){let r=e.peek();if(!r||r.kind!=="identifier"||r.value!=="{")return null;let t=e.mark();e.advance();let n=["{"],a=1,o=0;for(;!e.isAtEnd()&&o++<M.MAX_BRACE_RUN_TOKENS;){let u=e.advance();if(!u)break;if(u.value==="{")a++;else if(u.value==="}"&&(a--,a===0))return n.push("}"),W(n.join(" "));n.push(u.value);}return e.reset(t),null}tryMatchBraceRunExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"||r.value!=="{")return null;let t=e.mark(),n="",a=-1,o=0,u=0;for(;!e.isAtEnd()&&u++<M.MAX_BRACE_RUN_TOKENS;){let s=e.advance();if(!s)break;if(a>=0&&s.position.start>a&&(n+=" ".repeat(s.position.start-a)),n+=s.value,a=s.position.end,s.value==="{")o++;else if(s.value==="}"&&(o--,o===0))return {type:"expression",raw:n}}return e.reset(t),null}tryMatchBareCallExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"||!/^[A-Za-z_][\w$]*$/.test(r.value))return null;let t=e.peek(1);if(!t||t.value!=="(")return null;let n=e.mark();e.advance();let a=e.advance(),o="",u=a.position?.end,s=false,l=0;for(;!e.isAtEnd()&&l++<M.MAX_METHOD_ARGS+2;){let c=e.peek();if(!c)break;if(c.value===")"){e.advance(),s=true;break}let m=u!==void 0&&c.position?.start===u;o+=(o===""||m?"":" ")+c.value,u=c.position?.end,e.advance();}return s?{type:"expression",raw:`${r.value}(${o})`}:(e.reset(n),null)}tryMatchMethodCallExpression(e){let r=e.peek();if(!r||r.kind!=="selector")return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(t),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(t),null;e.advance();let o=e.peek();if(!o||o.kind!=="punctuation"||o.value!=="(")return e.reset(t),null;e.advance();let u=[];for(;!e.isAtEnd()&&u.length<M.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}u.push(l.value),e.advance();}return {type:"expression",raw:`${r.value}.${a.value}(${u.join(", ")})`}}tryMatchPropertyAccessExpression(e,r=true){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let a=t.value.toLowerCase(),o=e.peek();if((t.kind==="identifier"||M.PROPERTY_ACCESS_BASES.has(a))&&o&&o.kind==="selector"&&/^\.[a-zA-Z_]/.test(o.value)){let p=t.value,f=[],v=0;for(;v<M.MAX_PROPERTY_DEPTH;){let h=e.peek();if(h&&h.kind==="selector"&&/^\.[a-zA-Z_]/.test(h.value))p+=`.${h.value.slice(1)}`,f.push(h.value.slice(1)),e.advance(),v++;else break}let E=e.peek(),y=!!E&&E.value.startsWith("(");if(r&&!y&&f.length>0&&Se(a))return ge(ue(a),f.join("."),"dot");if(y){let h=e.mark(),z=[],A=0,D=false;for(;!e.isAtEnd();){let b=e.peek();if(!b)break;if(b.value==="(")A++;else if(b.value===")"){if(z.push(b.value),e.advance(),A--,A===0&&(D=true),D)break;continue}z.push(b.value),e.advance();}D?p+=z.join(""):e.reset(h);}return {type:"expression",raw:p}}let u=e.peek();if(!u||u.kind!=="operator"||u.value!==".")return e.reset(n),null;e.advance();let s=e.peek();if(!s||s.kind!=="identifier")return e.reset(n),null;e.advance();let l=`${t.value}.${s.value}`,c=1;for(;!e.isAtEnd()&&c<M.MAX_PROPERTY_DEPTH;){let p=e.peek();if(!p||p.kind!=="operator"||p.value!==".")break;e.advance();let f=e.peek();if(!f||f.kind!=="identifier")break;e.advance(),l+=`.${f.value}`,c++;}let m=e.peek();if(m&&m.kind==="punctuation"&&m.value==="("){e.advance();let p=[],f=0;for(;!e.isAtEnd()&&p.length<M.MAX_METHOD_ARGS;){let E=e.peek();if(!E)break;if(E.kind==="punctuation"&&E.value===")"){if(f===0){e.advance();break}f--;}if(E.kind==="punctuation"&&E.value==="("&&f++,E.kind==="punctuation"&&E.value===","){e.advance();continue}p.push(E.value),e.advance();}return {type:"expression",raw:`${l}(${p.join(", ")})`}}let d=t.value.toLowerCase();if(r&&Se(d)){let p=l.split(".").slice(1).join(".");return ge(ue(d),p,"dot")}return {type:"expression",raw:l}}tryMatchPossessiveSelectorExpression(e){let r=e.peek();if(!r||r.kind!=="selector")return null;let t=e.mark();e.advance();let n=e.peek(),a=this.currentProfile?.possessive?.marker?.replace(/^-/,""),o=!!n&&n.kind==="punctuation"&&n.value==="'s",u=!!n&&n.value==="'"&&(e.peek(1)?.value??"").toLowerCase()==="s",s=(()=>{if(!this.currentPatternCommand||(n?.normalized??"").toLowerCase()!=="source")return false;let f=se[this.currentPatternCommand];return !!f&&f.roles.some(v=>v.role==="source")})(),l=!!n&&!!a&&a!=="'s"&&n.value===a&&(n.kind==="particle"||n.kind==="punctuation"||n.kind==="identifier")&&!s;if(!o&&!l&&!u)return e.reset(t),null;e.advance(),u&&e.advance();let c=e.peek();if(!c)return e.reset(t),null;let m=c.kind==="selector"&&c.value.startsWith("*"),d=c.kind==="keyword"&&!!this.currentProfile&&wo(this.currentProfile.code,c.value);return c.kind==="identifier"||m||d||(o||u)&&(c.kind==="selector"||c.kind==="keyword")?(e.advance(),ge(ve(r.value),this.toEnglishProperty(c.value),"possessive")):(e.reset(t),null)}tryMatchSelectorPropertyExpression(e){let r=e.peek();if(!r||r.kind!=="selector"||!r.value.startsWith("#"))return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(t),null;let a=e.peek(1);a&&a.kind,e.advance();let o=n.value.slice(1);return ge(ve(r.value),o,"dot")}matchGroupToken(e,r,t,n){let a=e.mark(),o=new Map(t),u=this.matchTokenSequence(e,r.tokens,t,n);if(u){let s=[];for(let l of r.tokens)if(l.type==="group"&&l.renderRequired)for(let c of l.tokens)c.type==="literal"&&s.push(c.value,...c.alternatives??[]);s.length>0&&[...t.keys()].some(c=>!o.has(c))&&(e.tokens.slice(a.position,e.position()).some(d=>s.some(p=>this.getMatchType(d,p)!=="none"))||(u=false));}if(!u){e.reset(a);for(let s of t.keys())o.has(s)||t.delete(s);for(let[s,l]of o)t.get(s)!==l&&t.set(s,l);return r.optional||false}return true}getMatchType(e,r){if(e.value===r)return "exact";if(e.normalized===r)return "normalized";if(e.stem===r&&e.stemConfidence!==void 0&&e.stemConfidence>=.7)return "stem";if(e.kind==="keyword"&&e.value.toLowerCase()===r.toLowerCase())return "case-insensitive";if(e.kind==="keyword"){let t=Qe(e.value).toLowerCase();if(t&&t===Qe(r).toLowerCase())return "case-insensitive"}return "none"}tokenToSemanticValue(e){switch(e.kind){case "selector":return ve(e.value);case "literal":return this.parseLiteralValue(e.value);case "keyword":let r=(e.normalized||e.value).toLowerCase();return Se(r)?ue(r):W(e.normalized||e.value);case "identifier":if(e.value.startsWith("@"))return ve(e.value);if(e.value.startsWith(":")||e.value.startsWith("$"))return ue(e.value);let t=e.value.toLowerCase();return Se(t)?ue(t):{type:"expression",raw:e.value};case "url":return W(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 W(n,"string")}if(e==="true")return W(true,"boolean");if(e==="false")return W(false,"boolean");let r=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(r){let n=parseFloat(r[1]);return r[2]?W(e,"duration"):W(n,"number")}let t=parseFloat(e);return isNaN(t)?W(e,"string"):W(t,"number")}applyExtractionRules(e,r){for(let[t,n]of Object.entries(e.extraction)){let a=r.get(t);if(a){if(n.transform){let o=a.type==="literal"?String(a.value):String(a.raw??"");r.set(t,n.transform(o));}}else n.value!==void 0?r.set(t,{type:"literal",value:n.value}):n.default&&r.set(t,{...n.default,implicit:true});}}isOptional(e){return e.type!=="literal"&&e.optional===true}skipNoiseWords(e){let r=e.peek();if(!r)return;let t=r.value.toLowerCase();if(M.ENGLISH_NOISE_WORDS.has(t)){let n=e.mark();e.advance();let a=e.peek();if(a&&(a.kind==="selector"||a.kind==="identifier"))return;let o=e.peek(1);if(a&&a.kind==="keyword"&&o&&o.kind==="selector"&&/^\.[a-zA-Z_]/.test(o.value))return;let u=a?(a.normalized??a.value).toLowerCase():"";if(a&&M.POSITIONAL_OR_SCOPE_KEYWORDS.has(u))return;let s=e.peek(1),l=s?(s.normalized??s.value).toLowerCase():"",c=this.currentProfile?.wordOrder!=="SOV"&&M.COMMAND_ACTION_KEYWORDS.has(l),m=!s||s.kind==="particle"||M.CLAUSE_BOUNDARY_KEYWORDS.has(l)||c;if(a&&a.kind==="keyword"&&this.currentProfile?.code!=="en"&&Se(u)&&m||a&&a.kind==="keyword"&&this.currentProfile?.code==="en"&&Se(u))return;e.reset(n);}t==="class"&&e.advance();}extractEventModifiers(e){let r={},t=false;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(t=true,a.modifierName){case "once":r.once=true;break;case "debounce":typeof a.value=="number"&&(r.debounce=a.value);break;case "throttle":typeof a.value=="number"&&(r.throttle=a.value);break;case "queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(r.queue=a.value);break}e.advance();}return t?r:void 0}};X.CONDITION_OPERATOR_WORDS=new Set(["matches","match","contains","exists","has","have","equals","includes"]);X.POSITIONAL_OR_SCOPE_KEYWORDS=new Set(["first","last","next","previous","random","closest","parent"]);X.STRUCTURAL_NEVER_EVENT=new Set(["if","unless","else","end","then","while"]);X.PROPERTY_ACCESS_BASES=new Set(["it","me","you","my","its","your","event","result","target","detail","body","window","document","self","this"]);X.COMMAND_ACTION_KEYWORDS=Or;X.CLAUSE_BOUNDARY_KEYWORDS=new Set(["then","and","or","end","else"]);X.RUN_OPERATORS=new Set(["+","-","*","/"]);X.PICK_RANGE_SEPARATORS=new Set(["to"]);X.PICK_RANGE_SEPARATORS_BY_LANG={ar:new Set(["\u0625\u0644\u0649"]),bn:new Set(["\u09A5\u09C7\u0995\u09C7"]),de:new Set(["zu","bis"]),es:new Set(["a"]),fr:new Set(["\xE0"]),he:new Set(["\u05E2\u05DC","\u05E2\u05D3"]),hi:new Set(["\u0938\u0947"]),id:new Set(["ke"]),it:new Set(["in","a"]),ja:new Set(["\u304B\u3089"]),ko:new Set(["\uBD80\uD130"]),ms:new Set(["ke"]),pl:new Set(["do"]),pt:new Set(["para","a"]),qu:new Set(["kama"]),ru:new Set(["\u0432","\u0434\u043E"]),sw:new Set(["kwa","hadi"]),th:new Set(["\u0E43\u0E19","\u0E16\u0E36\u0E07"]),tl:new Set(["sa"]),tr:new Set(["ile"]),uk:new Set(["\u0432","\u0434\u043E"]),vi:new Set(["v\xE0o","\u0111\u1EBFn"]),zh:new Set(["\u5230"])};X.PICK_RANGE_MODES=new Set(["inclusive","exclusive"]);X.MAX_BRACE_RUN_TOKENS=64;X.MAX_PROPERTY_DEPTH=10;X.MAX_METHOD_ARGS=20;X.DECLARATION_COMMANDS=new Set(["behavior","def","install"]);X.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Wt=X,oe=new Wt;function Y(i,e){return Na(i,e)}function Kt(){return La()}var Ht={ar:new Set(["\u0623\u0648"]),bn:new Set(["\u0985\u09A5\u09AC\u09BE"]),de:new Set(["oder"]),en:new Set(["or"]),es:new Set(["o"]),fr:new Set(["ou"]),he:new Set(["\u05D0\u05D5"]),hi:new Set(["\u092F\u093E"]),id:new Set(["atau"]),it:new Set(["o"]),ja:new Set(["\u307E\u305F\u306F"]),ko:new Set(["\uB610\uB294"]),ms:new Set(["atau"]),pl:new Set(["lub"]),pt:new Set(["ou"]),qu:new Set(["utaq"]),ru:new Set(["\u0438\u043B\u0438"]),sw:new Set(["au"]),th:new Set(["\u0E2B\u0E23\u0E37\u0E2D"]),tl:new Set(["o"]),tr:new Set(["veya"]),uk:new Set(["\u0430\u0431\u043E"]),vi:new Set(["ho\u1EB7c"]),zh:new Set(["\u6216"])},Vo=new Set(Object.values(Ht).flatMap(i=>[...i]));function br(i,e){let r=(i.normalized??i.value).toLowerCase();if(r==="or")return true;let t=e===void 0?Vo:Ht[e];return t?t.has(i.value)||t.has(r):false}var Le=["if","unless","repeat","for","while"],ar=/^[A-Z][A-Za-z0-9_]*$/;function K(i,e){let r=new Set([e]),n=P(i)?.keywords?.[e];if(n){n.primary&&r.add(n.primary.toLowerCase());for(let a of n.alternatives??[])r.add(a.toLowerCase());}return r}function $(i,e){return e.has(i.value.toLowerCase())?true:i.normalized?e.has(i.normalized.toLowerCase()):false}var qo=new Set(Le);function Ue(i,e){let r=i.normalized?.toLowerCase();return r?qo.has(r):e.some(t=>$(i,t))}var mt=new Set(["me","it","you","the","body","window","document","its","event","result","target","self","this","them","parent","next","previous","closest","first","last"]),Wo=new Set(["destination","source","style","patient","on","from","to"]);function Ke(i){if(!i||i.kind==="selector")return false;let e=(i.normalized??i.value).toLowerCase(),r=i.value.toLowerCase();return !(mt.has(e)||mt.has(r)||Wo.has(e))}var dt=new Set(["ja","ko"]);function Re(i){let e=new Set;i?.primary&&e.add(i.primary.toLowerCase());for(let r of i?.alternatives??[])e.add(r.toLowerCase());return e}function Ut(i,e){let r=[],t=e.position.end,n=i.slice(e.position.end).match(/^\s*\(([^)]*)\)/);if(n){t=e.position.end+n[0].length;for(let a of n[1].split(/[,\u060c\u3001]/)){let o=a.trim();o&&r.push(o);}}return {parameters:r,headerEnd:t}}function or(i,e,r){let t=e+1;if(t>=i.length)return -1;let n=Re(P(r)?.roleMarkers?.patient);return n.size>0&&$(i[t],n)&&t++,t<i.length?t:-1}var Gt=/^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*$/;function Ko(i){let e=1;if(i[1]?.value==="("){let r=0,t=1;for(;t<i.length;t++)if(i[t].value==="(")r++;else if(i[t].value===")"&&--r===0)break;if(t>=i.length)return -1;e=t+1;}return e+1}function Ho(i,e,r){let t=P(r);if(t?.wordOrder!=="SOV"||!Gt.test(i[0].value)||e!==Ko(i))return false;let n=Re(t.roleMarkers?.patient);return n.size===0?false:$(i[e-1],n)}function Uo(i,e,r){if(!P(e))return null;let t=K(e,"behavior"),n=K(e,"def"),a=i.toLowerCase(),o=[...t].some(m=>a.includes(m)),u=/\bdef\b/.test(a)||[...n].some(m=>m!=="def"&&a.includes(m));if(!o&&!u)return null;let s=Y(i,e).tokens;if(s.length<2)return null;if($(s[0],t))return pt(i,e,s,r,0);let l=s.findIndex((m,d)=>d>0&&$(m,t));if(l>0&&ar.test(s[0].value))return pt(i,e,s,r,l);if($(s[0],n))return ft(i,e,s,r,0);let c=s.findIndex((m,d)=>d>0&&$(m,n));return c>0&&Ho(s,c,e)?ft(i,e,s,r,c):null}function Go(i,e,r){let t=P(e);if(!t)return null;let n=t.wordOrder!=="SOV",a=dt.has(e)?Re(t.roleMarkers?.event):new Set,o=dt.has(e)?Re(t.keywords?.on):new Set,u=a.size>0&&o.size>0,s=K(e,"end"),l=K(e,"on"),c=i.toLowerCase(),m=[...s].some(b=>c.includes(b)),d=(n||u)&&(()=>{let b=0;for(let g of l)if(g){for(let w=c.indexOf(g);w>=0;w=c.indexOf(g,w+g.length))if(++b>=2)return true}return false})();if(!m&&!d)return null;let p=Y(i,e).tokens;if(p.length<2)return null;let f=Le.map(b=>K(e,b)),v=b=>Ue(b,f),E=b=>$(b,s),y=[],h=0,z=0;for(let b=0;b<p.length;b++){let g=p[b];if(E(g)){if(h>0){h--;continue}let w=i.slice(p[z].position.start,g.position.start).trim();w&&y.push(w),z=b+1;}else if(v(g))h++;else if(n&&h===0&&b>z&&$(g,l)&&Ke(p[b+1])){let w=i.slice(p[z].position.start,g.position.start).trim();w&&y.push(w),z=b;}else if(u&&h===0&&b-1>z&&$(g,a)&&p[b+1]!==void 0&&$(p[b+1],o)){let w=p[b-1],B=i.slice(p[z].position.start,w.position.start).trim();B&&y.push(B),z=b-1;}}if(z<p.length){let b=i.slice(p[z].position.start).trim();b&&y.push(b);}if(y.length<2)return null;let A=[],D=[];for(let b of y){let g;try{g=r.statement(b,e);}catch{return null}if(!g||g.kind!=="event-handler")return null;let w=g;if(A.push(w),!w.body||w.body.length===0)return null;D.push(w.metadata?.confidence??.75);}return qe(A,"then",{sourceLanguage:e,confidence:Oe(D),sourceText:i})}function Oe(i){return i.length>0?i.reduce((e,r)=>e+r,0)/i.length:0}function ur(i){let e=[];for(let r of i){let t=r.statements;r.kind==="compound"&&Array.isArray(t)?e.push(...t):e.push(r);}return e}function pt(i,e,r,t,n){let a=n>0,o=a?0:or(r,n,e);if(o<0)return null;let u=r[o],s=u.value;if(!ar.test(s))return null;let{parameters:l,headerEnd:c}=Ut(i,u),m=a?n+1:r.findIndex(w=>w.position.start>=c);m<=o&&(m=o+1);let d=K(e,"init"),p=K(e,"end"),f=Le.map(w=>K(e,w)),v=w=>Ue(w,f),E=w=>$(w,p),y=[],h=[],z=[],A=false,D=0,b=m;for(let w=m;w<r.length;w++){let B=r[w];if(E(B)){if(D>0){D--;continue}if(w===b){A=true;break}if($(r[b],d)){let C=i.slice(r[b].position.end,B.position.start).trim();if(C)try{let k=ur(t.body(C,e));h.push(...k),z.push(Oe(k.map(S=>S.metadata?.confidence??.75)));}catch{z.push(0);}}else {let C=i.slice(r[b].position.start,B.position.start).trim();try{let k=t.statement(C,e);if(k&&k.kind==="event-handler"){let S=k;y.push(S);let R=!S.body||S.body.length===0;z.push(R?.2:S.metadata?.confidence??.75);}else z.push(0);}catch{z.push(0);}}b=w+1;}else v(B)&&D++;}if(y.length===0&&h.length===0)return null;let g=(A?1:.8)*Oe(z);return lo(s,l,y,h.length>0?h:void 0,{sourceLanguage:e,confidence:g,sourceText:i})}function ft(i,e,r,t,n){let a=n>0,o=a?0:or(r,n,e);if(o<0)return null;let u=r[o],s=u.value;if(!Gt.test(s))return null;let{parameters:l,headerEnd:c}=Ut(i,u),m=a?n+1:r.findIndex(g=>g.position.start>=c);m<=o&&(m=o+1);let d=K(e,"end"),p=Le.map(g=>K(e,g)),f=g=>Ue(g,p),v=g=>$(g,d),E=0,y=-1;for(let g=m;g<r.length;g++)if(v(r[g])){if(E===0){y=g;break}E--;}else f(r[g])&&E++;let h=r[m]?.position.start??c,z=y>=0?r[y].position.start:i.length,A=i.slice(h,z).trim();if(!A)return null;let D;try{D=ur(t.body(A,e));}catch{return null}if(D.length===0)return null;let b=Oe(D.map(g=>g.metadata?.confidence??.75));return y<0&&(b*=.8),co(s,l,D,{sourceLanguage:e,confidence:b,sourceText:i})}var Ar=["live","eventsource","socket","worker","intercept"],Yo=new Set(["intercept"]),Pr=new Set(["eventsource","socket","worker"]),Zo=new Set(["eventsource","socket"]),Jo=new Set(["worker"]),Xo=6,Qo=2;function eu(i,e){for(let t of Ar)if($(i[0],K(e,t)))return {action:t,keywordIdx:0};if(P(e)?.wordOrder!=="SOV")return null;let r=Math.min(i.length,Xo);for(let t=1;t<r;t++)for(let n of Ar)if(n!=="live"&&$(i[t],K(e,n))&&!(Pr.has(n)&&!ar.test(i[0].value))&&!(n==="intercept"&&t>Qo))return {action:n,keywordIdx:t};return null}function ru(i,e,r){let t=Re(P(r)?.roleMarkers?.source);return t.size===0||e+1>=i.length?0:$(i[e],t)||$(i[e+1],t)?2:0}function Yt(i){let e=K(i,"on");e.add("when");let r=P(i)?.eventHandler;if(r?.keyword){e.add(r.keyword.primary.toLowerCase());for(let t of r.keyword.alternatives??[])e.add(t.toLowerCase());}for(let t of r?.temporalMarkers??[])e.add(t.toLowerCase());return e}function tu(i,e,r){let t=P(r)?.eventHandler,n=[t?.eventMarker?.primary,...t?.eventMarker?.alternatives??[],...t?.temporalMarkers??[]].filter(o=>!!o&&/\s/.test(o)),a=1;for(let o of n){let u=o.toLowerCase().split(/\s+/),s=e-u.length+1;s<0||u.every((l,c)=>i[s+c]?.value.toLowerCase()===l)&&(a=Math.max(a,u.length));}return a}function iu(i,e,r,t,n){if(i==="live")return r+1;if(r>0){let l=r+1;return i==="eventsource"&&(l+=ru(e,l,t)),l}let a=or(e,r,t);if(a<0)return -1;if(i==="worker")return a+1;let o=Yt(t),u=Re(P(t)?.roleMarkers?.event),s=n>=0?n:e.length;for(let l=a+1;l<s;l++){if(!$(e[l],o))continue;if(Ke(e[l+1]))return l;if(l>a+2&&u.size>0&&$(e[l-1],u)&&Ke(e[l-2]))return l-2;let c=tu(e,l,t);if(c>1&&l-c>a&&Ke(e[l-c]))return l-c;if(l>a+1&&Ke(e[l-1]))return l-1}return s}function nu(i,e,r,t){if(!Pr.has(i))return;let n=r>0?0:or(e,r,t);if(!(n<0))return e[n].value}function au(i,e,r){if(!P(e))return null;let t=i.toLowerCase(),n=false;for(let s of [...Ar,"changes"]){for(let l of K(e,s))if(l&&t.includes(l)){n=true;break}if(n)break}if(!n)return null;let a=Y(i,e).tokens;if(a.length<2)return null;let o=lu(a,e);if(o>=0)return mu(i,e,a,r,o);let u=eu(a,e);return u?ou(i,e,a,r,u.action,u.keywordIdx):null}function ou(i,e,r,t,n,a){let o=K(e,"end"),u=Le.map(A=>K(e,A)),s=A=>Ue(A,u),l=A=>$(A,o),c=nu(n,r,a,e);if(Pr.has(n)&&(!c||!ar.test(c)))return null;let m=A=>({sourceLanguage:e,confidence:A,sourceText:i}),d=Dr(r,a+1,l,s);if(Yo.has(n))return d>=0&&d!==r.length-1?null:kr(n,[],c,m(d>=0?1:.8));let p=iu(n,r,a,e,d);if(p<0||p>r.length)return null;let f=[],v=[],E=false,y=Jo.has(n);if(y||Zo.has(n)){let A=y?"def":"event-handler",D=0,b=p;for(let g=p;g<r.length;g++){let w=r[g];if(l(w)){if(D>0){D--;continue}if(E=true,g===b)break;let B=y?w.position.end:w.position.start,C=i.slice(r[b].position.start,B).trim();try{let k=t.statement(C,e);if(k&&k.kind===A){let S=k;f.push(S);let R=!S.body||S.body.length===0;v.push(R?.2:S.metadata?.confidence??.75);}else v.push(0);}catch{v.push(0);}b=g+1;}else s(w)&&D++;}}else {let A=Dr(r,p,l,s);E=A>=0;let D=A>=0?r[A].position.start:i.length,b=i.slice(r[p].position.start,D).trim();if(!b)return null;try{f.push(...ur(t.body(b,e)));}catch{return null}if(f.length===0)return null;v.push(...f.map(g=>g.metadata?.confidence??.75));}if(f.length===0&&!E)return null;let h=E?1:.8,z=v.length>0?h*Oe(v):h;return kr(n,f,c,m(z))}var uu=new Set([...Object.keys(se),"then","else"]);function su(i){let e=K(i,"when");for(let r of Yt(i))e.add(r);return e}function lu(i,e){if(i.length<3||!$(i[0],su(e)))return -1;let r=K(e,"changes"),t=K(e,"end");for(let n=2;n<i.length;n++){let a=i[n];if(a.kind==="literal")continue;if($(a,r))return n;if($(a,t))return -1;let o=(a.normalized??a.value).toLowerCase();if(a.kind==="keyword"&&uu.has(o))return -1}return -1}function cu(i,e,r){if(r==="en"){let n=e[0],a=e[e.length-1];return {type:"expression",raw:i.slice(n.position.start,a.position.end).trim()}}let t=e.map(n=>br(n,r)?{...n,kind:"keyword",normalized:"or"}:n);return {type:"expression",raw:xe(t,P(r))}}function mu(i,e,r,t,n){let a=K(e,"end"),o=Le.map(h=>K(e,h)),u=h=>Ue(h,o),s=h=>$(h,a),l=n+1;if(l>=r.length)return null;let c=Dr(r,l,s,u),m=c>=0;if(m&&c!==r.length-1)return null;let d=m?r[c].position.start:i.length,p=i.slice(r[l].position.start,d).trim();if(!p)return null;let f;try{f=ur(t.body(p,e));}catch{return null}if(f.length===0)return null;let v=cu(i,r.slice(1,n),e),y=(m?1:.8)*Oe(f.map(h=>h.metadata?.confidence??.75));return kr("when",f,void 0,{sourceLanguage:e,confidence:y,sourceText:i},new Map([["condition",v]]))}function Dr(i,e,r,t){let n=0;for(let a=e;a<i.length;a++)if(r(i[a])){if(n===0)return a;n--;}else t(i[a])&&n++;return -1}var he={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",\uB9C8\uC6B0\uC2A4\uC5D4\uD130:"mouseenter",\uB9C8\uC6B0\uC2A4\uB9AC\uBE0C:"mouseleave",\uB9C8\uC6B0\uC2A4\uBB34\uBE0C:"mousemove",\uD0A4\uD504\uB808\uC2A4:"keypress",\uD130\uCE58\uC885\uB8CC:"touchend",\uD130\uCE58\uCDE8\uC18C:"touchcancel"},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",\u307C\u304B\u3057:"blur"},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",\u062A\u0631\u0643\u064A\u0632:"focus","\u0645\u0641\u062A\u0627\u062D \u0623\u0633\u0641\u0644":"keydown","\u0645\u0641\u062A\u0627\u062D \u0623\u0639\u0644\u0649":"keyup","\u0641\u0623\u0631\u0629 \u0641\u0648\u0642":"mouseover","\u062A\u063A\u064A\u064A\u0631 \u062D\u062C\u0645":"resize"},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",cambiar:"change",enfocar:"focus",desenfocar:"blur",cargar:"load",desplazar:"scroll",dobleclic:"dblclick",rat\u00F3nentrar:"mouseenter",rat\u00F3nsalir:"mouseleave",rat\u00F3nmover:"mousemove",teclapresar:"keypress",descargar:"unload",toqueempezar:"touchstart",toqueterminar:"touchend",toquemover:"touchmove",toquecancelar:"touchcancel"},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",bulan\u0131k:"blur",farebas:"mousedown",fareb\u0131rak:"mouseup",kayd\u0131r:"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",duploClique:"dblclick",mouseEntrar:"mouseenter",mouseSair:"mouseleave",mouseMover:"mousemove",teclaPressionar:"keypress",descarregar:"unload",toqueIn\u00EDcio:"touchstart",toqueFim:"touchend",toqueMover:"touchmove",toqueCancelar:"touchcancel"},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",\u6309\u952E\u6309\u4E0B:"keydown",\u9F20\u6807\u79FB\u52A8:"mousemove",\u5378\u8F7D:"unload",\u8C03\u6574\u5927\u5C0F:"resize",\u89E6\u6478\u5F00\u59CB:"touchstart",\u89E6\u6478\u79FB\u52A8:"touchmove"},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",flou:"blur",doubleclic:"dblclick",sourisentrer:"mouseenter",sourissortir:"mouseleave",sourisbouger:"mousemove",touchepress\u00E9e:"keypress",d\u00E9charger:"unload",touchercommencer:"touchstart",toucherfin:"touchend",toucherbouger:"touchmove",toucherannuler:"touchcancel"},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","taste unten":"keydown","taste oben":"keyup","maus dr\xFCber":"mouseover","maus weg":"mouseout",doppelklick:"dblclick",mauseintreten:"mouseenter",mausverlassen:"mouseleave",mausbewegen:"mousemove",tastedr\u00FCcken:"keypress",entladen:"unload",ber\u00FChrungstart:"touchstart",ber\u00FChrungend:"touchend",ber\u00FChrungbewegen:"touchmove",ber\u00FChrungabbrechen:"touchcancel"},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",tekan_tombol:"keydown",keyup:"keyup",arahkan:"mouseover",tinggalkan:"mouseout",bongkar:"unload"},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",kambiay:"change",apachiy:"submit",kachay:"submit",apaykachay:"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",bonyeza:"click",ingizo:"input",kitufe_shuka:"keydown",kitufe_juu:"keyup",panya_nje:"mouseout",wasilisha:"submit","sogeza juu":"mouseover",shuka:"unload"},vi:{"\u0111\u1ED5i k\xEDch th\u01B0\u1EDBc":"resize"}};Object.fromEntries(Object.entries(he).map(([i,e])=>{let r={};for(let[t,n]of Object.entries(e))n in r||(r[n]=t);return [i,r]}));var yu={debounced:"debounce",debounce:"debounce",throttled:"throttle",throttle:"throttle"},hu=[["\u043E\u0434\u0438\u043D","_","\u0440\u0430\u0437"],["\u043E\u0434\u0438\u043D_\u0440\u0430\u0437"],["\u043E\u0434\u043D\u0430\u0436\u0434\u044B"],["m\u1ED9t","l\u1EA7n"],["once"]],vu=/^(\d+)(ms|s|m)?$/,Eu=new Set(["selector","literal","url","event-modifier"]);function gu(i){let e=i.match(vu);if(!e)return null;let r=parseInt(e[1],10),t=e[2]||"ms";return t==="s"?r*=1e3:t==="m"&&(r*=6e4),r}function Cu(i){for(let e=1;e<i.length;e++){let r=i[e];if(Eu.has(r.kind))continue;let t=r.value.toLowerCase(),n=yu[t];if(n){let a=0;for(let o=e+1;o<i.length;o++){let u=i[o],s=gu(u.value);if(s!==null)return {modifiers:{[n]:s},start:r.position.start,end:u.position.end};if(u.kind==="selector"||u.kind==="literal"||u.kind==="url"||++a>2)break}continue}for(let a of hu){if(a[0]!==t||e+a.length>i.length)continue;let o=true;for(let u=1;u<a.length;u++)if(i[e+u].value.toLowerCase()!==a[u]){o=false;break}if(o)return {modifiers:{once:true},start:r.position.start,end:i[e+a.length-1].position.end}}}return null}new Set(Object.values(Rr).flatMap(i=>Object.values(i)));var Ce=new Set(["if","unless","while","repeat","for"]),Er=new Set(["then","end","else","if","unless","while","for","repeat","and"]),Pu=new Set(["first","last","next","previous","random","closest"]),Be=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"]),ht=class extends Error{constructor(i,e,r,t){super(i),this.name="SemanticParseError",this.language=e,this.input=r,this.diagnostics=t;}};function V(i,e,r){return {message:i,severity:e,source:"semantic-parser",...r&&{code:r}}}function q(i,e){return e.length===0?i:{...i,diagnostics:e}}var nr=120;function Lu(i,e,r){let t=e.tokens.length;if(i.consumedTokens>=t)return null;let n=e.tokens[i.consumedTokens],a=e.tokens[t-1];if(!n||!a)return null;let o=r.slice(n.position.start,a.position.end);if(!o.trim())return null;let u=o.length>nr?`${o.slice(0,nr)}\u2026`:o,s=t-i.consumedTokens;return `pattern ${i.pattern.id} left ${s} token(s) unconsumed: "${u}"`}var Nu=new Set(["to","from","into","onto","with","as","at","of","in","on","by","and","or","then","end","else","the","a","an","async"]);function gr(i){let e=[],r=new Set((i.diagnostics??[]).map(n=>`${n.code}|${n.message}`)),t=n=>{if(!n||typeof n!="object")return;if(n!==i)for(let o of n.diagnostics??[]){if(o.code!=="unconsumed-input")continue;let u=`${o.code}|${o.message}`;r.has(u)||(r.add(u),e.push(o));}let a=n;for(let o of Jt){let u=a[o];if(Array.isArray(u))for(let s of u)t(s);}};return t(i),e.length===0?i:q(i,[...i.diagnostics??[],...e])}function vt(i){if(i.length>=2){let e=i[0];if((e==='"'||e==="'")&&i.endsWith(e))return i.slice(1,-1)}return i}var Jt=["body","statements","thenBranch","elseBranch","eventHandlers","initBlock"];function Xt(i,e){if(!i||typeof i!="object")return i;if(i.action&&i.roles instanceof Map){let t=re(i.action),n=t?.primaryRole;if(t&&n&&n!=="patient"&&!t.roles.some(a=>a.role==="patient")&&i.roles.has("patient")&&!i.roles.has(n)){let a=i.roles,o=a.get("patient");o!==void 0&&(a.delete("patient"),a.set(n,o));}if(i.action==="tell"){let a=i.roles,o=a.get("patient"),u=a.get("destination");o&&(o.type==="selector"||o.type==="reference")&&(!u||u.type==="literal")&&(a.delete("patient"),a.set("destination",o));}if(i.action==="transition"){let a=i.roles,o=a.get("goal");o&&o.type==="literal"&&o.dataType==="duration"&&!a.has("duration")&&(a.delete("goal"),a.set("duration",o));}if(i.action==="fetch"){let a=i.roles,o=a.get("patient"),u=a.get("source");o&&u&&(o.type==="literal"||o.type==="expression")&&u.type==="expression"&&!a.has("style")&&(a.delete("patient"),a.set("style",u),a.set("source",o));}if(i.action==="transition"){let a=i.roles,o=a.get("destination");o&&o.type==="literal"&&!a.has("goal")&&(a.delete("destination"),a.set("goal",o));let u=a.get("patient");u&&u.type==="literal"&&typeof u.value=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*$/.test(u.value)&&a.set("patient",{type:"expression",raw:u.value});}if(i.action==="morph"){let a=i.roles,o=a.get("patient");o&&o.type==="literal"&&typeof o.value=="string"&&/<[a-zA-Z][^>]*\/?>/.test(o.value)&&a.set("patient",{type:"expression",raw:o.value});}if(i.action==="wait"){let a=i.roles;if(!a.has("event")){let o=a.get("duration"),u=o?.type==="expression"?o.raw:o?.type==="literal"?o.value:void 0;typeof u=="string"&&Be.has(u.toLowerCase())&&(a.delete("duration"),a.set("event",{type:"literal",value:u,dataType:"string"}));}}if(i.kind==="command"&&i.action!=="on"){let a=i.roles,o=a.get("event");if(o&&o.type==="expression"){let u=o.raw;typeof u=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*(:[A-Za-z0-9_-]+)?$/.test(u)&&a.set("event",{type:"literal",value:u,dataType:"string"});}}if(e?.size){let a=i.roles;for(let o of ["destination","source"]){let u=a.get(o);u&&u.type==="literal"&&typeof u.value=="string"&&e.has(u.value)&&a.set(o,{type:"expression",raw:u.value});}}}let r=i;for(let t of Jt){let n=r[t];if(Array.isArray(n))for(let a of n)Xt(a,e);}return i}var Q=class x{constructor(){this.parseDepth=0,this.coverageFrames=[],this.boundIdentifiers=new Set;}parse(e,r){this.parseDepth===0&&this.boundIdentifiers.clear(),this.parseDepth++,this.coverageFrames.push([]);try{let t=Xt(this.parseInternal(e,r),this.boundIdentifiers),n=this.coverageFrames[this.coverageFrames.length-1];if(n.length>0&&(t=q(t,[...t.diagnostics??[],...n])),this.parseDepth===1&&(t=gr(t),t.kind==="event-handler")){let a={node:t,input:e},o=a.node.eventModifiers;if(o&&(o.once||o.debounce!==void 0||o.throttle!==void 0))for(let s=0;s<4;s++){let l=this.reclaimDanglingFromTail(a.node,a.input,r)??this.reclaimEventCompoundTail(a.node,a.input,r)??this.reclaimResponseTypeTail(a.node,a.input,r)??this.reclaimCapturedDestinationTail(a.node,a.input,r);if(!l)break;a=l;}let u=this.reclaimEventCompoundTail(a.node,a.input,r);u&&(a=u),t=a.node;}return t}finally{this.coverageFrames.pop(),this.parseDepth--;}}coverageMark(){let e=this.coverageFrames[this.coverageFrames.length-1];return e?e.length:0}coverageRollback(e){let r=this.coverageFrames[this.coverageFrames.length-1];r&&r.length>e&&(r.length=e);}static getCoverageMarkerSurfaces(e){let r=x.coverageMarkerSurfaces.get(e);if(!r){r=new Set;let t=P(e)?.roleMarkers;if(t){for(let n of Object.values(t))if(n){if(n.primary)for(let a of n.primary.toLowerCase().split(/\s+/))r.add(a);for(let a of n.alternatives??[])for(let o of a.toLowerCase().split(/\s+/))r.add(o);}}for(let n of x.LEAKED_RENDER_MARKERS[e]??[])r.add(n.toLowerCase());x.coverageMarkerSurfaces.set(e,r);}return r}isCoverageResidueToken(e,r){if(e.kind==="particle"||e.kind==="conjunction"||e.metadata?.closesTrackedBlock||this.isThenKeyword(e.value,r)||this.isEndKeyword(e.value,r)||this.isElseKeyword(e.value,r))return true;let t=(e.normalized??e.value).toLowerCase();return Nu.has(t)?true:x.getCoverageMarkerSurfaces(r).has(e.value.toLowerCase())}recordDroppedTokens(e,r,t){if(e.length===0)return;let n=this.coverageFrames[this.coverageFrames.length-1];if(!n||!e.some(u=>!this.isCoverageResidueToken(u,r)))return;let a=e.map(u=>u.value).join(" ").trim();if(!a)return;let o=a.length>nr?`${a.slice(0,nr)}\u2026`:a;n.push(V(`${t} left ${e.length} token(s) unconsumed: "${o}"`,"warning","unconsumed-input"));}registerBoundIdentifiers(e){let r=e.action==="repeat"||e.action==="for"?"patient":e.action==="set"?"destination":null;if(!r)return;let t=e.roles.get(r);t?.type==="expression"&&typeof t.raw=="string"&&/^[A-Za-z_]\w*$/.test(t.raw)&&this.boundIdentifiers.add(t.raw);}parseInternal(e,r){let t=Uo(e,r,{statement:(C,k)=>this.parse(C,k),body:(C,k)=>this.parseStatements(C,k)});if(t)return t;let n=au(e,r,{statement:(C,k)=>this.parse(C,k),body:(C,k)=>this.parseStatements(C,k)});if(n)return n;let a=Go(e,r,{statement:(C,k)=>this.parse(C,k),body:(C,k)=>this.parseStatements(C,k)});if(a)return a;let{modifiers:o,remainingInput:u}=this.extractStandaloneModifiers(e,r),s=u||e,c=this.stripAsyncModifier(s,r).remainingInput??s,d=this.stripDoNotThrowModifier(c,r).remainingInput??c,p=[],f=Y(d,r);this.positionSource=d;{let C=f.mark(),k=this.consumeJsBlock(f,r);if(k&&f.isAtEnd())return q(k,p);f.reset(C);}let v=de(r);if(v.length===0)throw new ht(`No patterns available for language: ${r}`,r,d,[V(`No patterns registered for language '${r}'`,"error","no-patterns")]);let E=[...v].sort((C,k)=>k.priority-C.priority);{let C=f.tokens;if(P(r)?.wordOrder==="VSO"&&C.length>=4&&C[0]?.normalized==="source"){let k=C.findIndex(S=>S.normalized==="on");if(k>=2&&k+1<C.length){let S=d.slice(C[0].position.start,C[k].position.start).trim(),R=C[k+1].position.end,T=d.slice(C[k].position.start,R)+" "+S+d.slice(R);if(T!==d)try{let O=this.parse(T,r);if(O&&O.kind==="event-handler"){let N=o?this.applyModifiers(O,o):O;return q(N,p)}}catch{}}}}{let C=f.tokens,k=C[0]?.normalized==="if";for(let S=0;k&&S+3<C.length;S++){let R=(C[S+3]?.normalized??C[S+3]?.value??"").toLowerCase();if(C[S]?.normalized==="source"&&C[S+2]?.normalized==="on"&&x.KNOWN_EVENTS.has(R)){let T=(d.slice(0,C[S].position.start).trimEnd()+" "+d.slice(C[S+1].position.end).trimStart()).trim();if(T&&T!==d)try{let O=this.parse(T,r);if(O&&O.kind==="event-handler"){let N=o?this.applyModifiers(O,o):O;return q(N,p)}}catch{}break}}}{let C=f.tokens;for(let k=1;k<C.length-1;k++){let S=C[k];if(!br(S,r))continue;let R=C[k+1],T=(R.normalized??R.value).toLowerCase();if(!x.KNOWN_EVENTS.has(T))break;let O=k+1,N=C[k+2];N&&N.kind==="selector"&&N.value.startsWith("[")&&(O=k+2);let I=C[k].position.start,j=C[O].position.end,L=(d.slice(0,I).trimEnd()+" "+d.slice(j).trimStart()).trim();if(L&&L!==d)try{let Z=this.parse(L,r);if(Z&&Z.kind==="event-handler"){Z.additionalEvents=[{type:"literal",value:T}];let J=o?this.applyModifiers(Z,o):Z;return q(J,p)}}catch{}break}}{let C=Cu(f.tokens);if(C){let k=(d.slice(0,C.start).trimEnd()+" "+d.slice(C.end).trimStart()).trim();if(k&&k!==d)try{let S=this.parse(k,r);if(S&&S.kind==="event-handler"){let R=this.applyModifiers(S,{...o??{},...C.modifiers});return q(R,p)}}catch{}}}let y=E.filter(C=>C.command==="on"),h=f.mark(),z=oe.matchBest(f,y);if(z){p.push(V(`event pattern matched: ${z.pattern.id} (confidence: ${z.confidence.toFixed(2)})`,"info","pattern-match"));let C=false;if(/^event-[a-z]+-bare$/.test(z.pattern.id)){let k=z.captured.get("event"),S=(k?.raw??k?.value??"").toString().toLowerCase(),R=he[r],T=x.KNOWN_EVENTS.has(S)||!!R&&Object.keys(R).some(O=>O.toLowerCase()===S);if(S&&!T){let O=this.trySOVEventExtraction(d,r,E);if(O){p.push(V(`bare-event mis-anchor on "${S}" rejected; SOV extraction preferred`,"info","stage-bare-event-guard"));let N=o?this.applyModifiers(O,o):O;return q(N,p)}if(k?.type==="reference"||k?.type==="expression"){f.reset(h);let N=E.filter(j=>j.command!=="on"),I=oe.matchBest(f,N);f.reset(h),I&&I.pattern.command!=="on"?(C=true,p.push(V(`bare-event mis-anchor on reference "${S}" rejected; command ${I.pattern.command} preferred`,"info","stage-bare-event-guard"))):oe.matchBest(f,y);}}}if(!C){let k=this.buildEventHandler(z,f,r),S=o?this.applyModifiers(k,o):k;return q(S,p)}}p.push(V(`event patterns: ${y.length} tried, no match`,"info","stage-event"));let A=this.tryTrailingEventExtraction(d,r,E);if(A){p.push(V("trailing event extraction succeeded","info","stage-trailing-event"));let C=o?this.applyModifiers(A,o):A;return q(C,p)}let D=E.filter(C=>C.command!=="on"),b=this.tryParseUnlessGuard(f,D,r);if(b&&b.length>0){let C=b.length===1?b[0]:qe(b,"then",{sourceLanguage:r,confidence:1});return q(C,p)}let g=oe.matchBest(f,D);if(g){if(Ce.has(g.pattern.command)){let k=this.trySOVEventExtraction(d,r,E);if(k){p.push(V(`SOV event extraction preferred over bare ${g.pattern.command} command`,"info","stage-sov-loop"));let R=o?this.applyModifiers(k,o):k;return q(R,p)}let S=this.tryMidStreamEventExtraction(d,r,E);if(S){p.push(V(`mid-stream event extraction preferred over bare ${g.pattern.command} command`,"info","stage-midstream-loop"));let R=o?this.applyModifiers(S,o):S;return q(R,p)}}else if(x.KNOWN_EVENTS.has(g.pattern.command)&&this.hasSOVEventMarkerHead(d,r)){let k=this.trySOVEventExtraction(d,r,E);if(k){p.push(V(`SOV event extraction preferred over command-homonym event ${g.pattern.command}`,"info","stage-sov-homonym"));let S=o?this.applyModifiers(k,o):k;return q(S,p)}}else if(P(r)?.wordOrder==="VSO"){let k=this.tryMidStreamEventExtraction(d,r,E);if(k){p.push(V(`mid-stream event extraction preferred over bare ${g.pattern.command} command`,"info","stage-midstream-cmd"));let S=o?this.applyModifiers(k,o):k;return q(S,p)}}if(g.consumedTokens<f.tokens.length&&P(r)?.wordOrder==="SOV"){let k=this.trySOVEventExtraction(d,r,E);if(k){p.push(V(`SOV event extraction preferred over partial ${g.pattern.command} command (trailing remainder)`,"info","stage-sov-trailing"));let S=o?this.applyModifiers(k,o):k;return q(S,p)}}if(g.consumedTokens<f.tokens.length&&!Ce.has(g.pattern.command)){let k=this.tryTopLevelCommandSequence(f,D,r);if(k)return p.push(V(`top-level command sequence: ${k.statements.length} commands`,"info","stage-top-level-sequence")),q(k,p)}p.push(V(`command pattern matched: ${g.pattern.id} (confidence: ${g.confidence.toFixed(2)})`,"info","pattern-match"));let C=Lu(g,f,d);return C&&p.push(V(C,"warning","unconsumed-input")),q(this.buildCommand(g,r),p)}if(p.push(V(`command patterns: ${D.length} tried, no match`,"info","stage-command")),!d.includes(`
4
- `)&&P(r)?.wordOrder==="VSO"){let C=this.tryMidStreamEventExtraction(d,r,E);if(C){p.push(V("mid-stream event extraction succeeded with no leading command match","info","stage-midstream-nocmd"));let k=o?this.applyModifiers(C,o):C;return q(k,p)}}let w=this.trySOVEventExtraction(d,r,E);if(w){p.push(V("SOV event extraction succeeded","info","stage-sov"));let C=o?this.applyModifiers(w,o):w;return q(C,p)}p.push(V("SOV event extraction: no event keyword found","info","stage-sov"));let B=this.tryCompoundCommandParsing(f,D,r);if(B)return p.push(V("compound command parsing succeeded","info","stage-compound")),q(B,p);throw p.push(V("compound parsing: no then-keywords or no command matches","info","stage-compound")),p.push(V(`all parse stages exhausted for "${d}"`,"error","parse-failed")),new ht(`Could not parse input in ${r}: ${d}`,r,d,p)}parseStatements(e,r){let t=Y(e,r),n=de(r).filter(a=>a.command!=="on").sort((a,o)=>o.priority-a.priority);this.coverageFrames.push([]);try{let a=this.parseBodyWithClauses(t,n,r),o=this.coverageFrames[this.coverageFrames.length-1];if(o.length>0&&a.length>0){let u=a[a.length-1];a[a.length-1]=q(u,[...u.diagnostics??[],...o]);}return a}finally{this.coverageFrames.pop();}}canParse(e,r){try{return this.parse(e,r),!0}catch{return false}}supportedLanguages(){return Kt()}buildCommand(e,r){if(!e)throw new Error("No match to build command from");let t={};for(let[a,o]of e.captured)t[a]=o;let n=ee(e.pattern.command,t,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence});return this.registerBoundIdentifiers(n),n}buildEventHandler(e,r,t){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 d=n.type==="expression"?n.raw:n.type==="literal"?n.value:void 0;if(typeof d=="string"&&/^[^\s()[\]{}:]+$/.test(d)){let p=he[t]?.[d];p?n={type:"literal",value:p,dataType:"string"}:n.type==="expression"&&x.KNOWN_EVENTS.has(d.toLowerCase())&&(n={type:"literal",value:d.toLowerCase(),dataType:"string"});}}let a=oe.extractEventModifiers(r),o=e.captured.get("source");o&&e.pattern.id.endsWith("source")&&!(o.type==="reference"&&o.value==="me")&&(a={...a??{},from:o});let u=this.extractOrConjunctionEvents(r,t),s=n;u.length>0&&n.type==="literal"&&(s={type:"literal",value:[String(n.value),...u.map(p=>String("value"in p?p.value:""))].join(" or ")});let l,c=e.captured.get("action");if(c&&c.type==="literal"&&c.value==="if"){let d=r.tokens,p=-1;for(let f=r.position()-1;f>=0;f--){let v=d[f],E=(v.normalized??v.value).toLowerCase();if(this.isIfKeyword(E,t)){p=f;break}}if(p>=0){let f=de(t).filter(A=>A.command!=="on").sort((A,D)=>D.priority-A.priority),v=d.slice(p);if(e.pattern.id.endsWith("vso-verb-first")&&s.type==="literal"){let A=String(s.value??"").split("[")[0].trim().toLowerCase(),D=v.findIndex((b,g)=>{if(g===0||A==="")return false;let w=(b.normalized??b.value).toLowerCase(),B=v[g-1];return w===A&&B.kind==="keyword"&&(B.normalized??"").toLowerCase()==="on"});if(D>0){let b=v[D+1],g=b&&b.kind==="selector"&&b.value.startsWith("[")?1:0;v=[...v.slice(0,D-1),...v.slice(D+1+g)];}}let E=new ie(v,t),y=this.coverageMark(),h=this.parseBodyWithClauses(E,f,t);if(h.some(A=>A.kind==="conditional")||h.length===1&&h[0]?.kind==="compound"&&h[0].statements.some(A=>A.kind==="conditional")){for(;!r.isAtEnd();)r.advance();return $e(s,h,a,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}this.coverageRollback(y);}}if(c&&c.type==="literal"&&String(c.value)!=="js"&&re(String(c.value))!==void 0){let d=c.value,p={};for(let[g,w]of e.captured)g!=="event"&&g!=="action"&&g!=="continues"&&(p[g]=w);if(d==="repeat"){let g=r.peek(),w=C=>(C.normalized??C.value).toLowerCase();if(g&&g.kind==="keyword"&&w(g)==="forever")p.loopType={type:"literal",value:"forever"},delete p.patient,r.advance();else if(g&&g.kind==="keyword"&&w(g)==="event"){r.advance();let C=r.peek();if(C)for(p.event={type:"literal",value:w(C)},p.loopType={type:"literal",value:"until-event"},delete p.patient;!r.isAtEnd();){let k=r.peek();if(!k||k.kind==="conjunction"||k.kind==="keyword"&&(this.isThenKeyword(k.value,t)||this.isEndKeyword(k.value,t)))break;r.advance();}}let B=p.patient;B&&B.type==="reference"&&B.value==="me"&&delete p.patient;}let f=ee(d,p,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence});this.registerBoundIdentifiers(f);let v=[];if(!Ce.has(d)||d==="repeat"||d==="while"){let g=e.pattern.id.includes("verb-first"),w=r.tokens,B=r.position(),C=R=>R.kind==="conjunction"||R.kind==="keyword"&&(this.isThenKeyword(R.value,t)||this.isEndKeyword(R.value,t)),k=new Set;{let R=P(t)?.keywords?.[d];R?.primary&&k.add(R.primary.toLowerCase());for(let T of R?.alternatives??[])k.add(T.toLowerCase());}let S=-1;for(let R=B-1;R>=0;R--){let T=w[R];if(C(T))break;if((T.normalized??T.value).toLowerCase()===d||k.has(T.value.toLowerCase())){S=R;break}}if(S>=0){let R=B;for(;R<w.length&&!C(w[R]);)R++;let T=w.slice(S,R),O=T;if(g){let N=String(n.value??"").toLowerCase(),I=T.findIndex(j=>(j.normalized??j.value).toLowerCase()===N);if(I<0)O=null;else {let j=T[I-1],L=j&&j.kind==="keyword"&&j.normalized?.toLowerCase()==="on"?I-1:I;O=[...T.slice(0,L),...T.slice(I+1)];}}if(O&&O.length>1){let N=de(t).filter(_=>_.command!=="on").sort((_,H)=>H.priority-_.priority),I=this.coverageMark(),j=this.parseClause(O,N,t),L=j[0],Z=_=>_!==null&&typeof _=="object"&&typeof _.type=="string"?_.type:typeof _,J=re(d),mr=J?.primaryRole,qr=_=>_==="patient"&&mr&&mr!=="patient"&&!J?.roles.some(H=>H.role==="patient")?mr:_,wi=(_,H)=>{if(!Ce.has(d)||!J)return false;let ye=J.roles.find(Me=>Me.role===qr(_));return ye?ye.expectedTypes.length>0&&!ye.expectedTypes.includes(Z(H)):true},dr=(_,H)=>_==="patient"&&!!J&&!J.roles.some(ye=>ye.role==="patient")&&Z(H)==="literal"&&Pt.has(String(H.value??"").toLowerCase()),pr=_=>_!==null&&typeof _=="object"&&_.implicit===true,bi=!!L&&L.kind==="command"&&Object.entries(p).every(([_,H])=>{if(pr(H)||wi(_,H)||dr(_,H))return true;let ye=L.roles.get(qr(_));if(ye!==void 0&&Z(ye)===Z(H))return true;if(_==="patient"&&d==="pick"&&Z(H)==="literal"){let Me=L.roles.get("method"),Kr=Z(Me),Hr=Kr==="literal"?String(Me.value):Kr==="expression"?String(Me.raw):void 0;return Hr!==void 0&&Hr===String(H.value)}return false}),Wr=L?.metadata?.patternId??"",Ai=!Ce.has(d)||/^repeat-.*-(times|for-in|while-head|until-head)$/.test(Wr),Di=/^repeat-.*-(times|for-in|while-head|until-head)$/.test(Wr);if((j.length===1||Di&&j.length>1)&&L&&L.kind==="command"&&(L.action===d||d==="while"&&L.action==="repeat"&&/-while-head$/.test(L.metadata?.patternId??""))&&bi&&Ai&&(L.roles.size>Object.entries(p).filter(([_,H])=>!dr(_,H)).length||[...L.roles.values()].filter(_=>!pr(_)).length>Object.entries(p).filter(([_,H])=>!dr(_,H)&&!pr(H)).length))for(f=L,v=j.slice(1);r.position()<R;)r.advance();else this.coverageRollback(I);}}}if(!Ce.has(d)){let g=f;if(re(d)?.roles.some(T=>T.role==="quantity"&&!T.required)&&!g.roles.has("quantity")){let T=r.peek();T&&/^-?\d+(\.\d+)?$/.test(T.value)&&(f=ee(d,{...Object.fromEntries(g.roles),quantity:{type:"literal",value:parseFloat(T.value),dataType:"number"}},g.metadata),r.advance());}let B=f;if(re(d)?.roles.some(T=>T.role==="duration"&&!T.required)&&!B.roles.has("duration")){let T=/^\d+(\.\d+)?(ms|s)$/i,O=r.peek(),N=false;if(O&&O.kind==="particle"){let I=r.peek(1);I&&T.test(I.value)&&(N=true,O=I);}O&&T.test(O.value)&&(f=ee(d,{...Object.fromEntries(B.roles),duration:{type:"literal",value:O.value,dataType:"string"}},B.metadata),N&&r.advance(),r.advance(),this.consumeForPostposition(r,t));}let k=f,S=re(d);if(S?.roles.find(T=>T.role==="responseType"&&!T.required)&&!k.roles.has("responseType")){let T=L=>typeof L=="string"&&x.RESPONSE_TYPE_WORDS.has(L.toLowerCase()),O=(L,Z)=>{let J=Object.fromEntries(k.roles);Z&&delete J.destination,J.responseType={type:"expression",raw:L},f=ee(d,J,k.metadata);},N=k.roles.get("destination"),I=S?.roles.find(L=>L.role==="destination"),j=N?.raw??N?.value;if(N&&I&&!I.expectedTypes.includes(N.type)&&T(j))O(j,true);else {let L=r.peek();L&&T(L.value)&&(O(L.value,false),r.advance());}}if(d==="wait"){let T=f;if(!T.roles.has("event")){let O=r.peek();if(O&&Be.has(O.value.toLowerCase())){let N=Object.fromEntries(T.roles),I=N.duration;I&&I.type!=="literal"&&I.type!=="expression"&&delete N.duration;let j=N.patient;j&&j.type==="reference"&&j.value==="me"&&delete N.patient,N.event={type:"literal",value:O.value,dataType:"string"},f=ee(d,N,T.metadata),r.advance(),this.consumeForPostposition(r,t);}}}this.tryAttachTrailingRole(r,f,t),this.tryAttachTrailingStyle(r,f,t),this.tryAttachTrailingExpressionRole(r,f,t);}let E=e.captured.get("continues"),y=E?.type==="literal"&&E.value==="then",h=r.peek(),z=!!h&&this.isThenKeyword(h.value,t),D=Ce.has(d)&&!!h&&!this.isEndKeyword(h.value,t),b=!!h&&!this.isEndKeyword(h.value,t);if(y||z||D||b){let g=de(t).filter(C=>C.command!=="on").sort((C,k)=>k.priority-C.priority),w=de(t).filter(C=>C.id.startsWith("grammar-")&&C.id.includes("-continuation")).sort((C,k)=>k.priority-C.priority),B=this.parseBodyWithGrammarPatterns(r,g,w,t);B.length>0?l=[f,...v,...B]:l=[f,...v];}else l=[f,...v],r.isAtEnd()||this.recordDroppedTokens(r.tokens.slice(r.position()),t,"handler body tail");}else {let d=de(t).filter(f=>f.command!=="on").sort((f,v)=>v.priority-f.priority),p=c?e.roleStarts?.get("action"):void 0;if(p!==void 0&&p<r.position()){let f=new ie(r.tokens.slice(p),t);for(l=this.parseBodyWithClauses(f,d,t);!r.isAtEnd();)r.advance();}else l=this.parseBodyWithClauses(r,d,t);}let m=l.length>1?[qe(l,"then",{sourceLanguage:t})]:l;return $e(s,m,a,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,r,t){let n=[],a=[],o=0,u=[];for(;!e.isAtEnd();){let s=e.peek();if(!s)break;if(a.length===0){let f=this.consumeJsBlock(e,t)??this.consumeVerbFinalJsBlock(e,t);if(f){n.push(f);continue}let v=this.tryParseConditionalBlock(e,r,t);if(v){n.push(v);continue}let E=this.tryParseUnlessGuard(e,r,t);if(E){n.push(...E);continue}}let l=s.kind==="conjunction"||s.kind==="keyword"&&this.isThenKeyword(s.value,t),c=a[a.length-1],m=e.peek(1),d=c?.value.toLowerCase()==="at"&&m?.value.toLowerCase()==="of"||nt(t,s.value,c?.value,m?.value),p=s.kind==="keyword"&&this.isEndKeyword(s.value,t)&&!d;if(p&&o>0){o--,u.pop(),a.push({...s,metadata:{...s.metadata,closesTrackedBlock:true}}),e.advance();continue}if(l&&u.includes("if")){a.push(s),e.advance();continue}if(l){if(a.length>0){let f=this.parseClause(a,r,t);n.push(...f),a.length=0,o=f.filter(v=>{let E=v;return (E.action==="for"||E.action==="repeat"||E.action==="while")&&(!Array.isArray(E.body)||E.body.length===0)}).length,u.length=0;for(let v=0;v<o;v++)u.push("other");}e.advance();continue}if(p){e.advance();let f=[];for(;!e.isAtEnd();){let v=e.peek();if(!v||v.kind==="conjunction"||v.kind==="keyword"&&(this.isThenKeyword(v.value,t)||this.isEndKeyword(v.value,t)))break;f.push(v),e.advance();}if(f.length>0){let v=this.coverageMark(),E=a.length>0?this.parseClause(a,r,t):[];E.length===0&&a.length>0?(this.coverageRollback(v),n.push(...this.parseClause([...a,...f],r,t))):(n.push(...E),n.push(...this.parseClause(f,r,t)));}else if(a.length>0){let v=this.parseClause(a,r,t);n.push(...v);}a.length=0;break}if(s.kind==="keyword"){let f=(s.normalized??s.value).toLowerCase();(this.isIfKeyword(f,t)||this.isUnlessKeyword(f,t)||f==="while"||f==="for"||f==="repeat")&&(o++,u.push(this.isIfKeyword(f,t)?"if":"other"));}a.push(s),e.advance();}if(a.length>0){let s=this.parseClause(a,r,t);n.push(...s);}e.isAtEnd()||this.recordDroppedTokens(e.tokens.slice(e.position()),t,"body stream tail"),this.foldFrontedWhileIntoRepeat(n,t);for(let s=n.length-1;s>=0;s--){let l=n[s];l.kind==="command"&&l.action==="for"&&(!(l.roles instanceof Map)||l.roles.size===0)&&(!Array.isArray(l.body)||l.body.length===0)&&n.splice(s,1);}return n.length>1?[qe(n,"then",{sourceLanguage:t})]:n}tryTopLevelCommandSequence(e,r,t){let n=this.coverageMark(),a;try{let l=new ie(e.tokens,t);a=this.parseBodyWithClauses(l,r,t);}catch{return this.coverageRollback(n),null}if(a.length!==1||a[0].kind!=="compound")return this.coverageRollback(n),null;let o=a[0];if(o.statements.length<2)return this.coverageRollback(n),null;let u=o.statements.map(l=>l.metadata?.confidence??.75),s=u.reduce((l,c)=>l+c,0)/u.length;return qe(o.statements,o.chainType,{sourceLanguage:t,confidence:s})}foldFrontedWhileIntoRepeat(e,r){for(let t=0;t+1<e.length;t++){let n=e[t],a=e[t+1];if(n.kind!=="command"||n.action!=="while"||a.kind!=="command"||a.action!=="repeat")continue;let o=n.roles.get("condition");if(!o||a.roles.has("condition")||Array.isArray(n.body)||Array.isArray(a.body))continue;let u=new Map(a.roles);u.set("condition",o),u.set("loopType",{type:"literal",value:"while",dataType:"string"}),e.splice(t,2,{...a,roles:u,metadata:{...a.metadata,sourceLanguage:r,patternId:`repeat-${r}-fronted-while-fold`,confidence:Math.max(a.metadata?.confidence??0,n.metadata?.confidence??0)}});}}parseClause(e,r,t){if(e.length===0)return [];let n=null,a=e,o=e[e.length-1];if(o&&e.length>=2){let y=(o.normalized??o.value).toLowerCase();this.isUnlessKeyword(y,t)&&(n="unless",a=e.slice(0,-1));}let u=null;if(n&&a.length>=3){let y=P(t),h=y?x.buildVerbLookup(y):null;if(h)for(let z=1;z<a.length-1;z++){let A=a[z],D=h.get(A.value.toLowerCase())??(A.normalized?h.get(A.normalized.toLowerCase()):void 0);if(D&&!x.CONDITION_OPERATORS.has(D)){u=a.slice(0,z),a=a.slice(z);break}}}let s=new ie(a,t),l=[],c=this.coverageMark(),m=0,d=[],p=u,f=()=>{if(d.length===0)return;let y=d.slice();if(d.length=0,n&&l.length===0&&p===null){p=y;return}let h=y[0];if(!(h&&(h.kind==="identifier"||h.kind==="selector"||h.kind==="literal"||h.kind==="reference"))){this.recordDroppedTokens(y,t,"body clause");return}let A=false;for(let D of this.parseSOVClauseByVerbAnchoring(y,t)){let b=D.action,g=D.roles;b&&re(b)&&g instanceof Map&&g.size>0&&(l.push(D),A=true);}A||this.recordDroppedTokens(y,t,"body clause");};for(;!s.isAtEnd();){let y=s.peek(),h=!!y&&y.normalized?.toLowerCase()==="repeat",z=s.mark(),A=oe.matchBest(s,r);if(h&&A&&A.pattern.command!=="repeat"){s.reset(z),f(),l.push(ee("repeat",{},{sourceLanguage:t,confidence:.6})),m++,s.advance();continue}if(A&&A.pattern.command==="if"){let D=s.mark(),b=d.length;for(s.reset(z);!s.isAtEnd();){let w=s.peek();if(!w||this.isIfKeyword((w.normalized??w.value).toLowerCase(),t))break;d.push(w),s.advance();}let g=this.tryParseConditionalBlock(s,r,t);if(g){f(),l.push(g),m++;continue}d.length=b,s.reset(D);}if(A){f();let D=this.buildCommand(A,t);l.push(D),m++,this.tryAttachTrailingRole(s,D,t),this.tryAttachTrailingStyle(s,D,t),this.tryAttachTrailingExpressionRole(s,D,t),this.tryAttachTrailingDuration(s,D);}else {let D=s.peek();D&&D.normalized?.toLowerCase()==="repeat"?(f(),l.push(ee("repeat",{},{sourceLanguage:t,confidence:.6})),m++):D&&d.push(D),s.advance();}}f();let v=l;if(m===0){let y=this.parseSOVClauseByVerbAnchoring(a,t);y.length>0&&(this.coverageRollback(c),v=y);}let E=p;return n&&v.length>0&&E&&E.length>0?[ee(n,{condition:{type:"expression",raw:this.joinTokenText(E,t)}},{sourceLanguage:t,patternId:`${n}-${t}-trailing-guard`,confidence:.85}),...v]:n&&E&&E.length>0&&v.length===0?[ee(n,{condition:{type:"expression",raw:this.joinTokenText(E,t)}},{sourceLanguage:t,patternId:`${n}-${t}-trailing-guard`,confidence:.85})]:v}tryAttachTrailingDuration(e,r){let t=r.roles;if(t.has("duration")||!re(r.action)?.roles.some(o=>o.role==="duration"&&!o.required))return;let a=e.peek();!a||!/^\d+(?:\.\d+)?(?:ms|s|m|h)$/.test(a.value)||(t.set("duration",W(a.value,"duration")),e.advance());}tryAttachTrailingRole(e,r,t){let n=re(r.action);if(!n)return;let a=P(t);if(!a)return;let o=r.roles,u=(l,c)=>{if(!l)return false;if(l.kind==="selector")return true;let m=(l.normalized??l.value).toLowerCase();return Er.has(m)?false:m==="body"||m==="it"||m==="you"||m==="result"||m==="document"||m==="window"||this.boundIdentifiers.has(l.value)?true:c?false:l.kind==="identifier"||l.kind==="reference"},s=[{role:"source",strict:false},{role:"destination",strict:true}];for(let{role:l,strict:c}of s){if(!n.roles.some(E=>E.role===l))continue;let m=a.roleMarkers?.[l];if(!m)continue;let d=o.get(l);if(d&&!(d.type==="reference"&&d.value==="me"))continue;let p=E=>{if(!E||E.kind!=="particle"&&E.kind!=="keyword")return false;let y=E.value.toLowerCase();return m.primary?.toLowerCase()===y?true:c?false:(E.normalized??"").toLowerCase()===l?true:!!m.alternatives?.some(h=>h.toLowerCase()===y)},f=e.peek(),v=e.peek(1);if(!f||!v)return;if(c&&m.position==="after"){let E=e.peek(2),y=(f.normalized??f.value).toLowerCase();if(Pu.has(y)&&v.kind==="selector"&&p(E)){o.set(l,{type:"expression",raw:`${y} ${v.value}`}),e.advance(),e.advance(),e.advance();return}}if(m.position==="after"){if(u(f,c)&&p(v)){let E=this.tokenToSemanticValue(f);e.advance(),e.advance(),E&&o.set(l,E);return}if(c&&u(f,c)){let E=e.peek(2),y=e.peek(3);if((v.normalized??v.value).toLowerCase()==="in"&&E&&!p(E)&&p(y)){let h=this.tokenToSemanticValue(f);e.advance(),e.advance(),e.advance(),e.advance(),h&&o.set(l,h);return}}}else if(p(f)&&u(v,c)){e.advance();let E=this.tokenToSemanticValue(e.advance());E&&o.set(l,E);return}}}tryAttachTrailingStyle(e,r,t){if(r.action!=="fetch"&&r.action!=="render")return;let n=r.roles;if(!re(r.action)?.roles.some(y=>y.role==="style"))return;let o=n.get("style");if(o){if(o.type==="expression"&&typeof o.raw=="string"&&/^[A-Za-z_][\w-]*$/.test(o.raw)&&e.peek()?.value===":"){let y=We(e,o.raw);y&&n.set("style",{type:"expression",raw:y});}this.tryAttachResponseTypeAfterStyle(e,r,t);return}if(r.action==="fetch"){let y=n.get("patient"),h=n.get("source");if(y&&h&&(y.type==="literal"||y.type==="expression")&&h.type==="expression"&&typeof h.raw=="string"&&/^[A-Za-z_][\w-]*$/.test(h.raw)&&e.peek()?.value===":"){let z=We(e,h.raw);z&&(n.set("source",{type:"expression",raw:z}),this.tryAttachResponseTypeAfterStyle(e,r,t));return}}let s=P(t)?.roleMarkers?.style;if(!s)return;if(s.position==="before"){let y=new Set([s.primary,...s.alternatives??[]].map(D=>D.toLowerCase())),h=e.peek();if(!h||!y.has(h.value.toLowerCase()))return;let z=e.mark();e.advance();let A=We(e);if(!A){e.reset(z);return}n.set("style",{type:"expression",raw:A}),this.tryAttachResponseTypeAfterStyle(e,r,t);return}if(s.position!=="after")return;let l=new Set([s.primary,...s.alternatives??[]].map(y=>y.toLowerCase())),c=y=>y.kind==="conjunction"||y.kind==="keyword"&&(this.isThenKeyword(y.value,t)||this.isEndKeyword(y.value,t)),m=24,d=-1,p=0;for(let y=0;y<m;y++){let h=e.peek(y);if(!h||c(h))break;if(h.value==="("||h.value==="{"?p++:(h.value===")"||h.value==="}")&&(p=Math.max(0,p-1)),p===0&&(h.kind==="particle"||h.kind==="keyword")&&l.has(h.value.toLowerCase())){d=y;break}}if(d<=0)return;let f=[];for(let y=0;y<d;y++){let h=e.peek(y);h&&f.push(h);}if(f.length===1&&x.RESPONSE_TYPE_WORDS.has(f[0].value.toLowerCase()))return;let v=new ie(f,t),E=We(v);n.set("style",{type:"expression",raw:E&&v.isAtEnd()?E:this.joinTokenText(f,t)});for(let y=0;y<=d;y++)e.advance();this.tryAttachResponseTypeAfterStyle(e,r,t);}tryAttachResponseTypeAfterStyle(e,r,t){let n=r.roles;if(n.has("responseType")||!re(r.action)?.roles.some(c=>c.role==="responseType"&&!c.required))return;let o=c=>!!c&&x.RESPONSE_TYPE_WORDS.has(c.toLowerCase()),u=e.peek();if(!u)return;let s=c=>{n.set("responseType",{type:"expression",raw:c});};if(x.AS_MARKERS_BEFORE[t]?.some(c=>u.value.toLowerCase()===c)){let c=e.peek(1);c&&o(c.value)&&(e.advance(),e.advance(),s(c.value));return}if(o(u.value)){e.advance(),s(u.value);for(let c of x.AS_MARKERS_AFTER[t]??[])if(c.every((m,d)=>e.peek(d)?.value.toLowerCase()===m)){for(let m=0;m<c.length;m++)e.advance();break}}}tryAttachTrailingExpressionRole(e,r,t){let n=r.action,a=n==="js"?{role:"patient",terminator:"boundary"}:n==="go"||n==="scroll"?{role:"destination",terminator:"destination-marker"}:null;if(!a)return;let o=r.roles,u=o.get(a.role);if(n==="go"&&u&&u.type==="expression"&&String(u.raw).toLowerCase()==="url"){let y=e.peek();if(y&&!Er.has((y.normalized??y.value).toLowerCase())){let z=this.tokenToSemanticValue(y);if(z.type==="literal"||z.type==="selector"){o.set(a.role,z),o.set("method",{type:"literal",value:"url"}),e.advance();return}}let h=o.get("patient");if(h&&(h.type==="literal"||h.type==="selector")){o.set(a.role,h),o.set("method",{type:"literal",value:"url"}),o.delete("patient");return}}if(n==="go"&&u&&u.type==="expression"){let y=/^url\s+(\S+)$/i.exec(String(u.raw??""));if(y){let h=y[1].replace(/^["']|["']$/g,"");o.set(a.role,{type:"literal",value:h,dataType:"string"}),o.set("method",{type:"literal",value:"url"});return}}if(n==="go"&&!u){let y=o.get("patient");if(y&&y.type==="expression"&&String(y.raw).toLowerCase()==="url"){let h=e.peek();if(h&&!Er.has((h.normalized??h.value).toLowerCase())){let z=this.tokenToSemanticValue(h);if(z.type==="literal"||z.type==="selector"){o.set(a.role,z),o.set("method",{type:"literal",value:"url"}),o.delete("patient"),e.advance();return}}}}if(u&&!(u.type==="reference"&&u.value==="me"))return;let s=P(t);if(!s)return;let l=null;if(a.terminator==="destination-marker"){let y=s.roleMarkers?.destination;if(!y||y.position!=="after")return;l=y.primary.toLowerCase();}let c=y=>y.kind==="conjunction"||y.kind==="keyword"&&(this.isThenKeyword(y.value,t)||this.isEndKeyword(y.value,t)),m=24,d=[],p=0,f=false;for(let y=0;y<m;y++){let h=e.peek(y);if(!h||c(h))break;if(h.value==="("||h.value==="{"?p++:(h.value===")"||h.value==="}")&&(p=Math.max(0,p-1)),l!==null&&p===0&&(h.kind==="particle"||h.kind==="keyword")&&h.value.toLowerCase()===l){f=true;break}d.push(h);}if(d.length===0||l!==null&&!f)return;let v=d.length+(f?1:0);if(n==="go"&&d.length===2&&d[0].value.toLowerCase()==="url"){let y=this.tokenToSemanticValue(d[1]);if(y.type==="literal"||y.type==="selector"){o.set(a.role,y),o.set("method",{type:"literal",value:"url"});let h=o.get("patient");h&&h.type==="reference"&&h.value==="me"&&!re(n)?.roles.some(z=>z.role==="patient")&&o.delete("patient");for(let z=0;z<v;z++)e.advance();return}}let E=d;if(n==="js"){let y=s.keywords?.js,h=A=>[y?.primary,...y?.alternatives??[]].some(D=>!!D&&D.length>A.value.length&&D.includes(A.value)),z=0;for(;z<E.length&&h(E[z]);)z++;if(E=E.slice(z),E.length===0)return}if(o.set(a.role,{type:"expression",raw:this.joinTokenText(E,t)}),a.role!=="patient"){let y=o.get("patient");y&&y.type==="reference"&&y.value==="me"&&!re(n)?.roles.some(h=>h.role==="patient")&&o.delete("patient");}for(let y=0;y<v;y++)e.advance();}static buildVerbLookup(e){let r=new Map;for(let[t,n]of Object.entries(e.keywords))if(!["on","if","else","when","where","while","end","then","and"].includes(t)&&(r.set(n.primary.toLowerCase(),t),n.alternatives))for(let a of n.alternatives)r.set(a.toLowerCase(),t);return r}static buildMarkerToRoleLookup(e){let r=new Map;for(let[t,n]of Object.entries(e.roleMarkers)){if(!n)continue;if((t!=="event"||!r.has(n.primary))&&r.set(n.primary,t),n.alternatives)for(let o of n.alternatives)r.has(o)||r.set(o,t);}return r}parseSOVClauseByVerbAnchoring(e,r){let t=P(r);if(!t||t.wordOrder!=="SOV")return [];let n=x.buildVerbLookup(t),a=x.buildMarkerToRoleLookup(t),o=[],u=0;for(;u<e.length;){let s=-1,l="";for(let f=u;f<e.length;f++){let v=e[f];if(a.has(v.value))continue;let E=n.get(v.value.toLowerCase()),y=v.normalized?n.get(v.normalized.toLowerCase()):void 0,h=E||y;if(h){s=f,l=h;break}}if(s===-1)break;let c=e.slice(u,s),m=e.length;for(let f=s+1;f<e.length;f++){let v=e[f];if(v.kind==="conjunction"||this.isThenKeyword(v.value,r)){m=f;break}if(f>s+1&&!a.has(v.value)&&(n.get(v.value.toLowerCase())||(v.normalized?n.get(v.normalized.toLowerCase()):void 0))){m=f;break}}let d=e.slice(s+1,m),p=this.extractRolesFromMarkedTokens(c,d,a,l,r);if(o.push(ee(l,p,{sourceLanguage:r,confidence:.7})),u=m,u<e.length){let f=e[u];(f.kind==="conjunction"||this.isThenKeyword(f.value,r))&&u++;}}return o}extractRolesFromMarkedTokens(e,r,t,n,a){let o={},u=(l,c)=>{let m=this.isEndKeyword(l.value,a),d=l.kind==="keyword"&&(l.normalized??"").toLowerCase()==="end";return !m&&!d?false:l.metadata?.closesTrackedBlock===true||m?true:!(c&&c.kind==="selector")},s=l=>{let c=[];for(let m=0;m<l.length;m++){let d=l[m];if(u(d,l[m+1]))continue;let p=t.get(d.value);if(p&&d.kind==="particle"&&c.length>0){let f=this.tokensToSemanticValue(c,a);if(f){let v=this.mapRoleForCommand(p,n,o);v&&(o[v]=f);}c=[];}else c.push(d);}if(c.length>0)if(c.length===1&&/^\d+(\.\d+)?(ms|s)$/i.test(c[0].value)&&!o.duration&&re(n)?.roles.some(d=>d.role==="duration"))o.duration={type:"literal",value:c[0].value,dataType:"string"};else {let d=this.tokensToSemanticValue(c,a);d&&(o.patient?o.destination||(o.destination=d):o.patient=d);}};return s(e),s(r),o}mapRoleForCommand(e,r,t){return r==="set"&&(e==="patient"?e="destination":e==="destination"&&(e="patient")),t[e]?e==="patient"&&!t.destination?"destination":e==="destination"&&!t.patient?"patient":e==="source"&&!t.source?"source":null:e}tokensToSemanticValue(e,r){if(e.length===0)return null;let t=e.filter(o=>o.kind!=="whitespace");if(t.length===0)return null;if(t.length>=2&&(t[0].kind==="selector"||/^[#.@*<]/.test(t[0].value))){let o=t.findIndex((u,s)=>s>0&&(u.normalized??u.value).toLowerCase()==="in");o>0&&(t=t.slice(0,o));}if(t.length===1)return this.tokenToSemanticValue(t[0]);let n=t.map(o=>o.value).join(""),a=t[0];return a.kind==="selector"||a.value.startsWith("#")||a.value.startsWith(".")||a.value.startsWith("@")||a.value.startsWith("*")?ve(n):a.kind==="literal"||a.value.startsWith('"')||a.value.startsWith("'")?W(vt(n),"string"):a.kind==="reference"?ue(n):W(this.joinTokenText(t,r))}tokenToSemanticValue(e){let r=e.value;if(e.kind==="selector"||r.startsWith("#")||r.startsWith(".")||r.startsWith("@")||r.startsWith("*"))return ve(r);if(r.startsWith('"')||r.startsWith("'"))return W(vt(r),"string");if(/^-?\d+(\.\d+)?$/.test(r))return W(parseFloat(r));if(r==="true"||r==="\u771F"||r==="\uCC38"||r==="do\u011Fru")return W(true);if(r==="false"||r==="\u507D"||r==="\uAC70\uC9D3"||r==="yanl\u0131\u015F")return W(false);if(r.length>1&&(r.startsWith(":")||r.startsWith("$")))return ue(r);let t=e.normalized?.toLowerCase();return t==="me"||t==="it"||t==="you"||t==="result"||t==="body"?ue(t):e.kind==="reference"?ue(e.normalized||"me"):W(r)}parseBodyWithGrammarPatterns(e,r,t,n){let a=[],o=[],u=false,s=()=>{if(!u&&o.length>0){let m=this.parseSOVClauseByVerbAnchoring(o,n);a.push(...m),m.length===0&&this.recordDroppedTokens(o,n,"fused body walk");}else o.length>0&&this.recordDroppedTokens(o,n,"fused body walk");o=[],u=false;},l=0,c=()=>{let m=0;for(let d of a){let p=d;(p.action==="for"||p.action==="repeat"||p.action==="while")&&(!Array.isArray(p.body)||p.body.length===0)&&m++;}return m-l};for(;!e.isAtEnd();){let m=e.peek();if(m&&this.isThenKeyword(m.value,n)){s(),e.advance();continue}if(m&&this.isEndKeyword(m.value,n)){let p=e.peek(-1),f=e.peek(1);if(!nt(n,m.value,p?.value,f?.value)){if(s(),c()>0){l++,e.advance();continue}e.advance();break}}if(m&&!u&&this.isIfKeyword((m.normalized??m.value).toLowerCase(),n)){s();let p=this.tryParseConditionalBlock(e,r,n);if(p){a.push(p),u=true;continue}}let d=false;if(t.length>0){let p=oe.matchBest(e,t);if(p){let f=p.pattern.command,v={};for(let[h,z]of p.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(v[h]=z);let E=ee(f,v,{sourceLanguage:n,patternId:p.pattern.id});a.push(E),d=true,u=true;let y=p.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!d){let p=e.mark(),f=oe.matchBest(e,r);if(f){if(f.pattern.command==="if"){let E=e.mark();for(e.reset(p);!e.isAtEnd();){let h=e.peek();if(!h||this.isIfKeyword((h.normalized??h.value).toLowerCase(),n))break;e.advance();}let y=this.tryParseConditionalBlock(e,r,n);if(y){s(),a.push(y),u=true;continue}e.reset(E);}let v=this.buildCommand(f,n);a.push(v),this.tryAttachTrailingRole(e,v,n),d=true,u=true;}}d||(m&&o.push(m),e.advance());}s(),e.isAtEnd()||this.recordDroppedTokens(e.tokens.slice(e.position()),n,"fused body walk");for(let m=a.length-1;m>=0;m--){let d=a[m];d.kind==="command"&&d.action==="for"&&(!(d.roles instanceof Map)||d.roles.size===0)&&(!Array.isArray(d.body)||d.body.length===0)&&a.splice(m,1);}return a}tryCompoundCommandParsing(e,r,t){let n=e.tokens,a=n.some(c=>c.kind==="conjunction"||c.kind==="keyword"&&this.isThenKeyword(c.value,t)),o=n.some(c=>this.isElseKeyword(c.value,t));if(!a&&!o)return null;let u=new ie(n,t),s=this.coverageMark(),l=this.parseBodyWithClauses(u,r,t);return l.length===0?(this.coverageRollback(s),null):l[0]}static isEnEventKeyword(e){if(typeof e!="string")return false;let r=e.toLowerCase(),t=x.enEventKeywordCache.get(r);if(t!==void 0)return t;let n=false;try{let a=Y(r,"en").tokens;n=a.length===1&&a[0]?.kind==="keyword";}catch{n=false;}return x.enEventKeywordCache.set(r,n),n}matchEventMarkerPhrase(e,r,t){let n=x.SOV_EVENT_MARKER_PHRASES[t];if(!n)return 0;for(let a of n)if(a.every((o,u)=>e[r+u]?.value===o))return a.length;return 0}hasSOVEventMarkerHead(e,r){let t=x.SOV_EVENT_MARKERS[r];if(t===void 0)return false;let{tokens:n}=Y(e,r),a=he[r],o=new Set;if(a)for(let u of Object.keys(a))o.add(u.toLowerCase());for(let u=0;u<n.length;u++){let s=n[u],l=s.value.toLowerCase(),c=s.normalized?.toLowerCase();if(!(!!c&&(x.KNOWN_EVENTS.has(c)||Be.has(c))||x.KNOWN_EVENTS.has(l)||Be.has(l)||o.has(l)))continue;let d=this.matchEventParamPhrase(n,u+1).len,p=n[u+1+d];if(p&&(p.kind==="particle"||p.kind==="keyword")&&t.has(p.value)||this.matchEventMarkerPhrase(n,u+1+d,r)>0)return true}return false}matchEventParamPhrase(e,r){if(e[r]?.value!=="(")return {len:0,names:[]};let t=[];for(let n=r+1;n<e.length;n++){let a=e[n].value;if(a===")")return {len:n-r+1,names:t};if(a!==","){if(e[n].kind!=="identifier")break;t.push(a);}}return {len:0,names:[]}}isStrippableSourceRef(e,r){if(!e)return false;let t=e.normalized?.toLowerCase();if(e.kind==="keyword"&&(t==="me"||t==="i"||t==="it"))return true;let n=e.value.toLowerCase();return r.has(n)||!!t&&r.has(t)}tryTrailingEventExtraction(e,r,t){let n=Y(e,r).tokens;if(n.length<3)return null;let a=he[r],o=new Set;if(a)for(let A of Object.keys(a))o.add(A.toLowerCase());let u=n.length-2,s=n[u];if(!(s.kind==="keyword"&&s.normalized?.toLowerCase()==="on"))return null;let c=n[n.length-1],m=c.value.toLowerCase(),d=c.normalized?.toLowerCase();if(!(!!d&&x.KNOWN_EVENTS.has(d)||x.KNOWN_EVENTS.has(m)||o.has(m)))return null;let f=d&&x.KNOWN_EVENTS.has(d)?d:a?.[m]??m,v=n.slice(0,u);if(v.length===0)return null;let E=t.filter(A=>A.command!=="on"),y=new ie(v,r),h=this.coverageMark(),z=this.parseBodyWithClauses(y,E,r);return z.length===0?(this.coverageRollback(h),null):$e({type:"literal",value:f},z,void 0,{sourceLanguage:r,confidence:.75})}tryMidStreamEventExtraction(e,r,t){let n=Y(e,r).tokens;if(n.length<3)return null;let a=he[r],o=new Set;if(a)for(let u of Object.keys(a))o.add(u.toLowerCase());for(let u=0;u<n.length-1;u++){let s=n[u];if(!(s.kind==="keyword"&&s.normalized?.toLowerCase()==="on"))continue;let c=n[u+1],m=c.value.toLowerCase(),d=c.normalized?.toLowerCase();if(!(!!d&&x.KNOWN_EVENTS.has(d)||x.KNOWN_EVENTS.has(m)||o.has(m)))continue;let f=d&&x.KNOWN_EVENTS.has(d)?d:a?.[m]??m,v=n.filter((A,D)=>D!==u&&D!==u+1);if(v.length===0)return null;let E=t.filter(A=>A.command!=="on"),y=new ie(v,r),h=this.coverageMark(),z=this.parseBodyWithClauses(y,E,r);return z.length===0?(this.coverageRollback(h),null):$e({type:"literal",value:f},z,void 0,{sourceLanguage:r,confidence:.75})}return null}trySOVEventExtraction(e,r,t){let n=x.SOV_EVENT_MARKERS[r];if(!n)return null;let o=Y(e,r).tokens,u=he[r],s=new Set;if(u)for(let b of Object.keys(u))s.add(b.toLowerCase());let l=x.SOV_SOURCE_MARKERS[r],c=-1,m="",d="",p=1,f=[];for(let b=0;b<o.length;b++){let g=o[b],w=g.value.toLowerCase(),B=w,C="",k=w.indexOf("[");k>0&&(B=w.slice(0,k),C=g.value.slice(k));let S=g.normalized?.toLowerCase(),R=S&&(x.KNOWN_EVENTS.has(S)||Be.has(S)),T=s.has(w)||s.has(B),O=x.KNOWN_EVENTS.has(B)||Be.has(B);if(R||T||O){let N=o[b-1];if(N&&(N.normalized??N.value).toLowerCase()==="event")continue;let I;R?I=S:T?I=u?.[w]??u?.[B]??B:I=B;let j=this.matchEventParamPhrase(o,b+1);if(n.size>0){let L=1+j.len,Z=o[b+L];Z&&Z.kind==="selector"&&Z.value.startsWith("[")&&(L+=1);let J=o[b+L];if(J&&(J.kind==="particle"||J.kind==="keyword")&&n.has(J.value)){c=b,m=I,d=C||(L===j.len+2?o[b+L-1].value:""),p=L+1,f=j.names;break}}else {c=b,m=I,d=C,p=1+j.len+this.matchEventMarkerPhrase(o,b+1+j.len,r),f=j.names;break}}}if(c===-1){let b=new Set(t.filter(g=>g.command!=="on").map(g=>g.command));for(let g=0;g<o.length;g++){let w=o[g];if(w.kind==="identifier")if(n.size>0){let B=1,C=o[g+1];C&&C.kind==="selector"&&C.value.startsWith("[")&&(B=2);let k=o[g+B];if(k&&(k.kind==="particle"||k.kind==="keyword")&&n.has(k.value)){c=g,m=w.value,d=B===2?o[g+1].value:"",p=B+1;break}}else {let B=this.matchEventMarkerPhrase(o,g+1,r);if(B>0){c=g,m=w.value,d="",p=1+B;break}let C=o[g+1];if(C&&C.kind==="keyword"&&C.normalized!=null&&b.has(C.normalized)){c=g,m=w.value,d="",p=1;break}}}}if(c===-1)return null;let v=new Set;for(let b=c;b<c+p;b++)v.add(b);if(l){let b=c+p;if(b<o.length){let g=o[b];if((g.kind==="particle"||g.kind==="keyword")&&l.markers.has(g.value))v.add(b);else if(this.isStrippableSourceRef(g,l.windowTokens)){let w=o[b+1];w&&(w.kind==="particle"||w.kind==="keyword")&&l.markers.has(w.value)&&(v.add(b),v.add(b+1));}}if(c>=2){let g=o[c-1];(g.kind==="particle"||g.kind==="keyword")&&l.markers.has(g.value)&&this.isStrippableSourceRef(o[c-2],l.windowTokens)&&(v.add(c-2),v.add(c-1));}for(let g=0;g<c;g++){let w=o[g],B=w.value.toLowerCase(),C=w.normalized?.toLowerCase();if(l.windowTokens.has(B)||C&&l.windowTokens.has(C)){v.add(g);break}}}let E=o.filter((b,g)=>!v.has(g));if(E.length===0)return null;let y=t.filter(b=>b.command!=="on"),h=new ie(E,r),z=this.coverageMark(),A=this.parseBodyWithClauses(h,y,r);if(A.length===0)return this.coverageRollback(z),null;let D={sourceLanguage:r,confidence:.75};return d&&(D.keyFilter=d),$e(x.isEnEventKeyword(m)?{type:"literal",value:m}:{type:"expression",raw:m},A,void 0,D,f)}profileKeywordMatches(e,r,t){let n=P(e)?.keywords?.[r];return n?n.primary?.toLowerCase()===t?true:!!n.alternatives?.some(a=>a.toLowerCase()===t):false}consumeForPostposition(e,r){let t=e.peek();if(!t)return;let n=(t.normalized??"").toLowerCase(),a=P(r)?.keywords?.for;(n==="for"||t.value===a?.primary||(a?.alternatives??[]).includes(t.value))&&e.advance();}isThenKeyword(e,r){let t=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"])}[r];return a?a.has(t):t==="then"||this.profileKeywordMatches(r,"then",t)}isElseKeyword(e,r){let t=e.toLowerCase();return t==="else"?true:this.profileKeywordMatches(r,"else",t)}isEndKeyword(e,r){let t=e.toLowerCase(),n=To(r);return n?t==="end"||n.has(t):t==="end"||this.profileKeywordMatches(r,"end",t)}isJsKeyword(e){let r=(e.normalized??e.value).toLowerCase();return r==="js"||this.profileKeywordMatches("en","js",r)}isPatientMarker(e,r){let t=P(r)?.roleMarkers?.patient;if(!t?.primary)return false;let n=e.value.toLowerCase();return t.primary.toLowerCase()===n?true:!!t.alternatives?.some(a=>a.toLowerCase()===n)}isJsBlockTerminator(e,r){return this.isEndKeyword(e,r)||this.profileKeywordMatches(r,"end",e.toLowerCase())}consumeVerbFinalJsBlock(e,r){let t=e.mark(),n=0,a=-1;for(;;){let c=e.peek(n);if(!c||this.isThenKeyword(c.value,r)||this.isJsBlockTerminator(c.value,r))break;if(this.isJsKeyword(c)){let m=e.peek(n+1),d=!!m&&c.position?.end!==void 0&&c.position.end===m.position?.start&&this.profileKeywordMatches(r,"js",`${c.value}${m.value}`.toLowerCase()),p=e.peek(n+(d?2:1));if(n>0&&p&&this.isJsBlockTerminator(p.value,r)){a=n;break}}n++;}if(a<=0)return null;let o=[];for(let c=0;c<a;c++){let m=e.peek(c);m&&o.push(m);}let u=o[o.length-1];if(u&&this.isPatientMarker(u,r)&&o.pop(),o.length===0)return e.reset(t),null;let s=this.rawJsBody(o);for(let c=0;c<a;c++)e.advance();e.advance();let l=e.peek();return l&&!this.isJsBlockTerminator(l.value,r)&&e.advance(),e.advance(),ee("js",{patient:{type:"expression",raw:s||"()"}},{sourceLanguage:r,patternId:`js-opaque-final-${r}`,confidence:1})}consumeJsBlock(e,r){let t=e.peek();if(!t||!this.isJsKeyword(t))return null;let n=e.mark(),a=[];e.advance();let o=e.peek();o&&t.position?.end!==void 0&&t.position.end===o.position?.start&&this.profileKeywordMatches(r,"js",`${t.value}${o.value}`.toLowerCase())&&e.advance();let u=e.peek();u&&this.isPatientMarker(u,r)&&e.advance();let s=false;for(;!e.isAtEnd();){let c=e.peek();if(!c)break;if(e.advance(),this.isJsBlockTerminator(c.value,r)){s=true;break}a.push(c);}if(!s)return e.reset(n),null;let l=this.rawJsBody(a);return ee("js",{patient:{type:"expression",raw:l||"()"}},{sourceLanguage:r,patternId:`js-opaque-${r}`,confidence:1})}rawJsBody(e){if(e.length===0)return "";let r=e[0].position?.start,t=e[e.length-1].position?.end,n=this.positionSource;if(n!==void 0&&r!==void 0&&t!==void 0){let o=n.slice(r,t),u=s=>s.replace(/\s+/g,"");if(u(o)===u(e.map(s=>s.value).join("")))return o.trim()}let a="";for(let o=0;o<e.length;o++){let u=e[o-1],s=u?.position?.end!==void 0&&e[o].position?.start===u.position.end;o>0&&!s&&(a+=" "),a+=e[o].value;}return a.trim()}isIfKeyword(e,r){let t=e.toLowerCase();return t==="if"?true:this.profileKeywordMatches(r,"if",t)}isUnlessKeyword(e,r){let t=e.toLowerCase();return t==="unless"?true:this.profileKeywordMatches(r,"unless",t)}tryParseUnlessGuard(e,r,t){let n=e.peek();if(!n||!this.isUnlessKeyword((n.normalized??n.value).toLowerCase(),t))return null;let a=e.mark(),o=this.tryParseConditionalBlock(e,r,t,true);if(!o||o.kind!=="conditional")return e.reset(a),null;let u=o;if(u.elseBranch&&u.elseBranch.length>0)return e.reset(a),null;let s=u.roles.get("condition");return s?[ee("unless",{condition:s},{sourceLanguage:t,patternId:`unless-${t}-guard`,confidence:1}),...u.thenBranch]:(e.reset(a),null)}isBlockEndToken(e,r,t){return this.isEndKeyword(e.value,t)?true:e.kind!=="keyword"||(e.normalized??"").toLowerCase()!=="end"?false:!(r&&r.kind==="selector")}tryParseConditionalBlock(e,r,t,n=false){let a=e.peek();if(!a)return null;let o=(a.normalized??a.value).toLowerCase();if(!this.isIfKeyword(o,t)&&!(n&&this.isUnlessKeyword(o,t)))return null;let u=e.mark(),s=this.coverageMark();e.advance();let l=[],c=0;for(;!e.isAtEnd();){let w=e.peek();if(!w)break;let B=(w.normalized??w.value).toLowerCase();if(this.isIfKeyword(B,t)||this.isUnlessKeyword(B,t)){c++,l.push(w),e.advance();continue}if(this.isBlockEndToken(w,e.peek(1)??void 0,t)){if(c===0){e.advance();break}c--,l.push(w),e.advance();continue}l.push(w),e.advance();}if(l.length===0)return e.reset(u),this.coverageRollback(s),null;let m=P(t),d=m?.wordOrder==="SOV"?x.buildVerbLookup(m):null,p=0,f=0,v=[];for(;p<l.length;p++){let w=l[p],B=(w.normalized??w.value).toLowerCase();if(this.isIfKeyword(B,t)||this.isUnlessKeyword(B,t)?f++:this.isBlockEndToken(w,l[p+1],t)&&f--,f===0&&this.isThenKeyword(w.value,t)){p++;break}if(f===0&&v.length>0){let C=(l[p-1].normalized??l[p-1].value).toLowerCase(),k=l[p-1].value.toLowerCase(),S=(w.normalized??w.value).toLowerCase(),R=x.CONDITION_COPULAS.has(C)||x.CONDITION_COPULAS_SURFACE.has(k)&&x.CONDITION_PREDICATES.has(S),T=d!==null&&d.has(w.value.toLowerCase())&&!x.CONDITION_PREDICATES.has(S),O=/^\.[a-zA-Z_]\w*$/.test(w.value)&&l[p-1].position?.end!==void 0&&w.position?.start!==void 0&&l[p-1].position.end===w.position.start;if(!x.CONDITION_OPERATORS.has(S)&&!O&&(!R||T)&&(this.tokensBeginCommand(l.slice(p),r,t)||this.sovCommandStartsAt(l.slice(p),d)))break}v.push(w);}if(v.length===0)return e.reset(u),this.coverageRollback(s),null;let y=[],h=[],z=false,A=0;for(;p<l.length;p++){let w=l[p],B=(w.normalized??w.value).toLowerCase();if(this.isIfKeyword(B,t)||this.isUnlessKeyword(B,t)?A++:this.isBlockEndToken(w,l[p+1],t)&&A--,A===0&&!z&&this.isElseKeyword(w.value,t)){z=true;continue}(z?h:y).push(w);}let D={type:"expression",raw:this.joinTokenText(v,t)},b=this.parseBranch(y,r,t),g=h.length>0?this.parseBranch(h,r,t):void 0;return b.length===0&&(!g||g.length===0)?(e.reset(u),this.coverageRollback(s),null):mo(D,b,g,{sourceLanguage:t,patternId:`conditional-${t}-folded`,confidence:1})}joinTokenText(e,r){return xe(e,P(r))}tokensBeginCommand(e,r,t){if(e.length===0)return false;let n=new ie(e,t);return oe.matchBest(n,r)!==null}sovCommandStartsAt(e,r){if(!r)return false;let t=u=>r.has(u.value.toLowerCase())||!!u.normalized&&r.has(u.normalized.toLowerCase()),n=u=>u.kind==="identifier"||u.kind==="selector"||u.kind==="literal"||u.kind==="reference",a=0,o=0;for(;a+1<e.length;){let u=e[a],s=e[a+1];if(!n(u)||s.kind!=="particle")break;o+=1,a+=2;let l=e[a];if(o>=1&&l&&t(l))return true}return false}parseBranch(e,r,t){if(e.length===0)return [];let n=new ie(e,t),a=this.parseBodyWithClauses(n,r,t);return a.length===1&&a[0]?.kind==="compound"?a[0].statements:a}extractStandaloneModifiers(e,r){let n=Y(e,r).tokens;if(n.length===0)return {modifiers:null,remainingInput:null};let o=n[0].value.toLowerCase(),u=x.STANDALONE_MODIFIERS[o];if(!u)return {modifiers:null,remainingInput:null};let s={},l=1;if(u==="once")s.once=true;else {let p=1;if(p<n.length){let f=n[p],v=n[p+1],E=f.kind==="identifier"&&v?.kind==="literal"&&/^\d+(ms|s|m)?$/.test(v.value);(f.kind==="keyword"||f.kind==="particle"||E)&&(p++,l++);}if(p<n.length){let f=n[p];if(f.kind==="literal"){let v=f.value.match(/^(\d+)(ms|s|m)?$/);if(v){let E=parseInt(v[1],10),y=v[2]||"ms";y==="s"?E*=1e3:y==="m"&&(E*=6e4),s[u]=E,l=p+1;}}}s[u]||(s[u]=u==="debounce"?300:100);}let c=n.slice(l);if(c.length===0)return {modifiers:null,remainingInput:null};let m=c[0].position.start,d=e.slice(m);return {modifiers:s,remainingInput:d}}stripAsyncModifier(e,r){let t=P(r)?.keywords?.async,n=new Set(["async"]);t?.primary&&n.add(t.primary.toLowerCase()),t?.alternatives?.forEach(l=>n.add(l.toLowerCase()));let a=Y(e,r).tokens,o=a.findIndex(l=>n.has(l.value.toLowerCase()));if(o===-1)return {remainingInput:null};let u=a[o],s=(e.slice(0,u.position.start)+e.slice(u.position.end)).replace(/\s{2,}/g," ").trim();return s.length===0?{remainingInput:null}:{remainingInput:s}}stripDoNotThrowModifier(e,r){let t=Y(e,r).tokens;for(let n=0;n<t.length-1;n++){if(t[n].value.toLowerCase()!=="do")continue;let a=-1;for(let l=n+1;l<=n+5&&l<t.length;l++){let c=t[l];if(c.normalized?.toLowerCase()==="throw"){a=l;break}let m=c.kind;if(m==="selector"||m==="literal"||m==="reference"||m==="conjunction")break}if(a===-1)continue;let o=t[n].position.start,u=t[a].position.end,s=(e.slice(0,o)+e.slice(u)).replace(/\s{2,}/g," ").trim();return s.length===0?{remainingInput:null}:{remainingInput:s}}return {remainingInput:null}}static droppedTokenCount(e){return (e.diagnostics??[]).filter(r=>r.code==="unconsumed-input").reduce((r,t)=>r+(parseInt(/left (\d+) token/.exec(t.message)?.[1]??"0",10)||0),0)}static unconsumedSpans(e){return (e.diagnostics??[]).filter(r=>r.code==="unconsumed-input").map(r=>/unconsumed: "(.*)"$/.exec(r.message)?.[1]).filter(r=>!!r).map(r=>r.replace(/\s+/g," ").trim())}static withoutSpanDiagnostics(e,r){return {...e,diagnostics:(e.diagnostics??[]).filter(t=>{if(t.code!=="unconsumed-input")return true;let n=/unconsumed: "(.*)"$/.exec(t.message)?.[1];return !n||n.replace(/\s+/g," ").trim()!==r})}}reclaimDanglingFromTail(e,r,t){let n=x.droppedTokenCount,a=x.unconsumedSpans(e);if(a.length===0)return null;let o=n(e),u=P(t)?.roleMarkers?.source,s=new Set;u?.primary&&s.add(u.primary),u?.alternatives?.forEach(c=>s.add(c));let l=Y(r,t).tokens;for(let c=0;c<l.length;c++){let m=l[c];if(m.normalized!=="source"&&!s.has(m.value))continue;let d=u?.position==="after"?c-1:c+1,p=l[d];if(!p||p.kind!=="identifier"&&p.kind!=="keyword")continue;let f=Math.min(m.position.start,p.position.start),v=Math.max(m.position.end,p.position.end),E=r.slice(f,v).replace(/\s+/g," ").trim();if(!a.some(h=>h===E||h.includes(E)))continue;let y=(r.slice(0,f).trimEnd()+" "+r.slice(v).trimStart()).trim();if(!(!y||y===r))try{let h=this.parse(y,t);if(!h||h.kind!=="event-handler")continue;let z=gr(h);if(n(z)<o)return {node:{...z,eventModifiers:{...z.eventModifiers,from:{type:"literal",value:p.value,dataType:"string"}}},input:y}}catch{}}return null}reclaimEventCompoundTail(e,r,t){let n=x.unconsumedSpans(e);if(n.length===0)return null;let a=he[t];if(!a)return null;let o=e.roles,u=o.get("event"),s=u?.type==="literal"&&typeof u.value=="string"?u.value:null;if(!s)return null;let l=m=>m.replace(/\s+/g," ").trim(),c=Y(r,t).tokens;for(let m of n)for(let d=1;d<c.length;d++)for(let p=d;p<c.length;p++){let f=l(r.slice(c[d].position.start,c[p].position.end));if(f.length>m.length)break;if(f!==m)continue;let v=c[d-1];if((a[v.value]??v.normalized)!==s)break;let y=l(r.slice(v.position.start,c[p].position.end)),h=a[y];if(!h)break;return o.set("event",{type:"literal",value:h,dataType:"string"}),{node:x.withoutSpanDiagnostics(e,m),input:r}}return null}reclaimResponseTypeTail(e,r,t){let n=x.unconsumedSpans(e);if(n.length===0)return null;let a=x.AS_MARKERS_BEFORE[t];if(!a)return null;let o=l=>l.replace(/\s+/g," ").trim(),u=x.droppedTokenCount(e),s=Y(r,t).tokens;for(let l=0;l+1<s.length;l++){let c=s[l],m=s[l+1];if(!a.some(f=>c.value.toLowerCase()===f)||!x.RESPONSE_TYPE_WORDS.has(m.value.toLowerCase()))continue;let d=o(r.slice(c.position.start,m.position.end));if(!n.includes(d))continue;let p=(r.slice(0,c.position.start).trimEnd()+" "+r.slice(m.position.end).trimStart()).trim();if(!(!p||p===r))try{let f=this.parse(p,t);if(!f||f.kind!=="event-handler")continue;let v=gr(f);if(x.droppedTokenCount(v)>=u)continue;let E=x.findResponseTypeTarget(v);if(!E)continue;return E.roles.set("responseType",{type:"expression",raw:m.value}),{node:v,input:p}}catch{}}return null}static findResponseTypeTarget(e){let r=null,t=n=>{if(!n||typeof n!="object"||r)return;if(n.kind==="command"){let o=n;if(re(o.action)?.roles.some(s=>s.role==="responseType"&&!s.required)&&!o.roles.has("responseType")){r=o;return}}let a=n;for(let o of ["body","statements","thenBranch","elseBranch","commands"]){let u=a[o];Array.isArray(u)&&u.forEach(s=>t(s));}};return t(e),r}reclaimCapturedDestinationTail(e,r,t){let n=x.unconsumedSpans(e);if(n.length===0)return null;let a=P(t)?.roleMarkers?.destination,o=new Set;if(a?.primary&&o.add(a.primary),a?.alternatives?.forEach(l=>o.add(l)),o.size===0)return null;let u=l=>l.replace(/\s+/g," ").trim(),s=Y(r,t).tokens;for(let l=0;l+1<s.length;l++){let c=s[l],m=s[l+1],d=o.has(c.value)&&m.normalized==="me",p=c.normalized==="me"&&o.has(m.value);if(!d&&!p)continue;let f=u(r.slice(c.position.start,m.position.end));if(!n.includes(f))continue;let v=false,E=y=>{if(!y||typeof y!="object"||v)return;if(y.kind==="command"){let z=y.roles.get("destination");if(z?.type==="reference"&&z.value==="me"){v=true;return}}let h=y;for(let z of ["body","statements","thenBranch","elseBranch","commands"]){let A=h[z];Array.isArray(A)&&A.forEach(D=>E(D));}};if(E(e),!!v)return {node:x.withoutSpanDiagnostics(e,f),input:r}}return null}applyModifiers(e,r){return {...e,eventModifiers:{...e.eventModifiers,...r}}}extractOrConjunctionEvents(e,r){let t=[];for(;;){let n=e.mark(),a=e.peek();if(!a)break;if(!br(a,r)){e.reset(n);break}e.advance();let o=e.peek();if(!o){e.reset(n);break}let u=(o.normalized||o.value).toLowerCase();e.advance(),t.push({type:"literal",value:u});}return t}};Q.coverageMarkerSurfaces=new Map;Q.LEAKED_RENDER_MARKERS={hi:["\u0915\u0947","\u0930\u0942\u092A","\u092E\u0947\u0902"],tr:["olarak"],qu:["hina"]};Q.AS_MARKERS_BEFORE={en:["as"],es:["como"],fr:["comme"],pt:["como"],it:["come"],de:["als"],id:["sebagai"],ms:["sebagai","sbg"],sw:["kuwa","kama"],th:["\u0E40\u0E1B\u0E47\u0E19"],vi:["nh\u01B0"],tl:["bilang"],he:["\u05DB"],ar:["\u0643\u0640"],pl:["jako"],ru:["\u043A\u0430\u043A"],uk:["\u044F\u043A"],zh:["\u7684","\u4F5C\u4E3A","\u5F53\u4F5C"]};Q.AS_MARKERS_AFTER={ko:[["\uB85C"],["\uC73C\uB85C"]],qu:[["hina"]],tr:[["olarak"]],hi:[["\u0915\u0947","\u0930\u0942\u092A","\u092E\u0947\u0902"]]};Q.enEventKeywordCache=new Map;Q.KNOWN_EVENTS=new Set(["click","dblclick","input","change","submit","keydown","keyup","keypress","mouseover","mouseout","mousedown","mouseup","focus","blur","load","scroll","resize","contextmenu"]);Q.RESPONSE_TYPE_WORDS=new Set(["json","text","html","xml","blob","arraybuffer","formdata","response"]);Q.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"])};Q.SOV_EVENT_MARKER_PHRASES={ko:[["\uD560","\uB54C"],["\uD560\uB54C"]]};Q.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"])}};Q.CONDITION_COPULAS=new Set(["is","am","are","be","was","were","not","no"]);Q.CONDITION_COPULAS_SURFACE=new Set(["\u0647\u0648","\u0E40\u0E1B\u0E47\u0E19","\u0939\u0948"]);Q.CONDITION_PREDICATES=new Set(["empty","null","undefined"]);Q.CONDITION_OPERATORS=new Set(["matches","match","contains","exists","has","have","equals","includes"]);Q.STANDALONE_MODIFIERS={once:"once",debounced:"debounce",debounce:"debounce",throttled:"throttle",throttle:"throttle"};var Mu=Q,_u=new Mu;function Iu(i,e){return _u.parse(i,e)}function ju(i,e){try{let r=Y(i,e),t=de(e);if(t.length===0)return {confidence:0,parseSuccess:!1,error:`No patterns available for language: ${e}`};let n=[...t].sort((l,c)=>c.priority-l.priority),a=n.filter(l=>l.command==="on"),o=oe.matchBest(r,a);if(o)return {confidence:o.confidence,parseSuccess:!0,patternId:o.pattern.id,action:o.pattern.command,tokensConsumed:o.consumedTokens};r.reset(r.mark());let u=n.filter(l=>l.command!=="on"),s=oe.matchBest(r,u);return s?{confidence:s.confidence,parseSuccess:!0,patternId:s.pattern.id,action:s.pattern.command,tokensConsumed:s.consumedTokens}:{confidence:0,parseSuccess:!1,error:`Could not match any patterns for: ${i}`}}catch(r){return {confidence:0,parseSuccess:false,error:r instanceof Error?r.message:String(r)}}}function Qt(i,e){try{let t=Iu(i,e);if(t)return {node:t,confidence:t.metadata?.confidence??.8,error:void 0,tokensConsumed:Y(i,e).tokens.length}}catch{}let r=ju(i,e);return r.parseSuccess?{node:null,confidence:r.confidence,error:void 0,tokensConsumed:r.tokensConsumed}:{node:null,confidence:0,error:r.error}}function ei(i,e){let r=e==="SOV"?"sovPosition":"svoPosition";return [...i].sort((t,n)=>{let a=t[r]??99,o=n[r]??99;return a-o})}function Pe(i,e){let r,t;if(i.markerOverride&&i.markerOverride[e.code]!==void 0)r=i.markerOverride[e.code],t=r?fe(i,e.code,r):void 0;else {let n=e.roleMarkers[i.role];if(n){r=n.primary;let a=fe(i,e.code,r)??[],o=[...new Set([...n.alternatives??[],...a])].filter(u=>u!==r);t=o.length?o:void 0;}}return {marker:r,alternatives:t}}function Ge(i,e,r){r.roles.find(n=>n.role==="scope"&&!n.required)&&(i.push({type:"group",optional:true,tokens:[{type:"literal",value:"on"},{type:"role",role:"scope",optional:true,expectedTypes:["selector","reference"]}]}),e.scope={fromRole:"scope"});}function Nr(i,e,r,t){ti(i,e,r,t,"manner",{requireMarker:true});}function ri(i,e,r,t){ti(i,e,r,t,"recipient",{requireMarker:false});}function ti(i,e,r,t,n,a){let o=r.roles.find(s=>s.role===n&&!s.required);if(!o)return;let u=o.markerOverride?.[t];a.requireMarker&&!u||(i.push({type:"group",optional:true,tokens:[...(u?u.split(/\s+/):[]).map(s=>({type:"literal",value:s})),{type:"role",role:n,optional:true,expectedTypes:o.expectedTypes,...o.valueShape!==void 0?{valueShape:o.valueShape}:{}}]}),e[n]={fromRole:n});}function ii(i){if(i.roles.some(t=>t.role==="patient"))return "patient";let e=i.roles.filter(t=>t.required),r=e.find(t=>t.role===i.primaryRole)??e[0];return !r||r.role==="event"?"patient":r.role}function ni(i,e,r){let t=i.roles.find(c=>c.role===r);if(!t||r==="patient")return [{type:"role",role:r,optional:false}];let{marker:n,alternatives:a}=Pe(t,e),o={type:"role",role:r,optional:false,...t.valueShape!==void 0?{valueShape:t.valueShape}:{}};if(!n)return [o];let u=n.split(/\s+/).filter(Boolean),s={type:"group",optional:true,tokens:u.map(c=>({type:"literal",value:c,...u.length===1&&a?.length?{alternatives:a}:{}}))};return (e.roleMarkers[r]?.position??"before")==="after"?[o,s]:[s,o]}function ai(i,e,r,t,n){for(let a of r.roles)a.required||n.has(a.role)||e[a.role]||!(a.markerOverride?.[t.code]??t.roleMarkers[a.role]?.primary)&&a.valueShape===void 0||(i.push({type:"group",optional:true,tokens:si(a,t)}),e[a.role]=a.default?{fromRole:a.role,default:a.default}:{fromRole:a.role});}function $u(i,e,r,t,n){let a=[];if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let f=t.primary.split(/\s+/);if(f.length>1)for(let v of f)a.push({type:"literal",value:v});else {let v=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(v);}}let o=ii(i),u=e.roleMarkers.destination,s=i.roles.some(f=>f.role==="destination");u&&s&&o!=="destination"&&a.push({type:"group",optional:true,tokens:[{type:"role",role:"destination",optional:true},u.alternatives?{type:"literal",value:u.primary,alternatives:u.alternatives}:{type:"literal",value:u.primary}]});let l=e.roleMarkers.source,c=i.roles.some(f=>f.role==="source");l&&c&&o!=="source"&&a.push({type:"group",optional:true,tokens:[{type:"role",role:"source",optional:true},l.alternatives?{type:"literal",value:l.primary,alternatives:l.alternatives}:{type:"literal",value:l.primary}]}),a.push(...ni(i,e,o));let m=e.roleMarkers.patient;if(m&&o==="patient"){let f=m.alternatives?{type:"literal",value:m.primary,alternatives:m.alternatives}:{type:"literal",value:m.primary};a.push(f);}let d=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(d),o!=="source"&&a.push(...be(i,e.roleMarkers.source)),o!=="destination"&&a.push(...Sr(i,e.roleMarkers.destination));let p={action:{value:i.action},event:{fromRole:"event"},[o]:{fromRole:o},...o==="destination"?{}:ke(i),...o==="source"?{}:we(i)};return ai(a,p,i,e,new Set(["event",o,"destination","source"])),{id:`${i.action}-event-${e.code}-sov`,language:e.code,command:"on",priority:(n.basePriority??100)+50,template:{format:`{event} ${t.primary} {destination?} {${o}} ${m?.primary||""} ${r.primary}`,tokens:a},extraction:p}}function Vu(i,e,r,t,n){let a=[],o=i.action==="swap",u=o?"destination":"patient";a.push({type:"role",role:u,optional:false});let s=e.roleMarkers.patient;if(s){let d=s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary};a.push(d);}if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let d=t.primary.split(/\s+/);if(d.length>1)for(let p of d)a.push({type:"literal",value:p});else {let p=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(p);}}let l=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(l),a.push(...be(i,e.roleMarkers.source));let c=e.roleMarkers.destination;if(o&&c){let d=i.roles.find(p=>p.role==="patient")?.markerOverride?.[e.code];if(d&&d!==c.primary){let p=c.alternatives??[];p.includes(d)||(c={...c,alternatives:[...p,d]});}}a.push(...o?mn(i,c):Sr(i,c));let m={action:{value:i.action},event:{fromRole:"event"},[u]:{fromRole:u},...o?{}:ke(i),...we(i)};return ri(a,m,i,e.code),Nr(a,m,i,e.code),{id:`${i.action}-event-${e.code}-sov-patient-first`,language:e.code,command:"on",priority:(n.basePriority??100)+45,template:{format:`{patient} ${s?.primary||""} {event} ${t.primary} ${r.primary}`,tokens:a},extraction:m}}function qu(i,e,r,t,n){let a=i.roles.find(m=>m.role==="source");if(!a)return null;let{marker:o,alternatives:u}=Pe(a,e),s=e.roleMarkers.patient;if(!o||o===t.primary||o===s?.primary)return null;let l=[];l.push({type:"role",role:"patient",optional:false}),s&&l.push(s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary}),l.push({type:"role",role:"source",optional:false,...a.expectedTypes?{expectedTypes:a.expectedTypes}:{},...a.valueShape!==void 0?{valueShape:a.valueShape}:{}});for(let m of o.split(/\s+/))l.push(u&&o.split(/\s+/).length===1?{type:"literal",value:m,alternatives:u}:{type:"literal",value:m});if(l.push({type:"role",role:"event",optional:false}),t.position==="after"){let m=t.primary.split(/\s+/);if(m.length>1)for(let d of m)l.push({type:"literal",value:d});else l.push(t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary});}l.push(r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary});let c={action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},source:{fromRole:"source"}};return ri(l,c,i,e.code),Nr(l,c,i,e.code),{id:`${i.action}-event-${e.code}-sov-source-fronted`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`{patient} ${s?.primary||""} {source} ${o} {event} ${t.primary} ${r.primary}`,tokens:l},extraction:c}}function Wu(i,e,r,t,n){let a=[];a.push({type:"role",role:"patient",optional:false});let o=e.roleMarkers.patient;if(o){let l=o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary};a.push(l);}let u=e.roleMarkers.destination;if(u&&(a.push({type:"role",role:"destination",optional:false}),a.push(u.alternatives?{type:"literal",value:u.primary,alternatives:u.alternatives}:{type:"literal",value:u.primary})),a.push({type:"role",role:"event",optional:false}),t.position==="after"){let l=t.primary.split(/\s+/);if(l.length>1)for(let c of l)a.push({type:"literal",value:c});else {let c=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(c);}}let s=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(s),{id:`${i.action}-event-${e.code}-sov-patient-first-dest`,language:e.code,command:"on",priority:(n.basePriority??100)+40,template:{format:`{patient} ${o?.primary||""} {destination} ${u?.primary||""} {event} ${t.primary} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},destination:{fromRole:"destination"}}}}function Ku(i,e,r,t,n){let a=[];a.push({type:"role",role:"event",optional:false});let o=t.alternatives?.filter(c=>!c.includes(" ")&&c.length>1)||[];o.length>0&&a.push({type:"literal",value:o[0],alternatives:o.slice(1)});let u=e.roleMarkers.destination;u&&a.push({type:"group",optional:true,tokens:[{type:"role",role:"destination",optional:true},u.alternatives?{type:"literal",value:u.primary,alternatives:u.alternatives}:{type:"literal",value:u.primary}]}),a.push({type:"role",role:"patient",optional:false});let s=e.roleMarkers.patient;if(s){let c=s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary};a.push(c);}let l=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(l),a.push(...be(i,e.roleMarkers.source)),a.push(...Sr(i,e.roleMarkers.destination)),{id:`${i.action}-event-${e.code}-sov-compact`,language:e.code,command:"on",priority:(n.basePriority??100)+52,template:{format:`{event}${o[0]||""} {patient} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},...ke(i),...we(i)}}}function Hu(i,e,r,t,n){let a=[];if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let u=t.primary.split(/\s+/);if(u.length>1)for(let s of u)a.push({type:"literal",value:s});else {let s=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(s);}}let o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(o),{id:`${i.action}-event-${e.code}-sov-simple`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`{event} ${t.primary} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{default:{type:"reference",value:"me"}}}}}function Uu(i,e,r,t){let n=e.eventHandler?.temporalMarkers;if(!n||n.length===0)return null;let a=[];a.push({type:"role",role:"event",optional:false}),e.possessive?.marker&&a.push({type:"group",optional:true,tokens:[{type:"literal",value:e.possessive.marker}]}),a.push({type:"literal",value:n[0],alternatives:n.slice(1)}),a.push({type:"role",role:"patient",optional:false});let o=e.roleMarkers.patient;if(o?.primary){let s=o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary};a.push(s);}let u=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(u),{id:`${i.action}-event-${e.code}-sov-temporal`,language:e.code,command:"on",priority:(t.basePriority??100)+49,template:{format:`{event} ${n[0]} {patient} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"}}}}function Gu(i,e,r,t,n){let a=[];if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let m=t.primary.split(/\s+/);if(m.length>1)for(let d of m)a.push({type:"literal",value:d});else {let d=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(d);}}let u=[...i.roles.filter(m=>m.required)].sort((m,d)=>{let p=m.sovPosition??999,f=d.sovPosition??999;return p-f});for(let m of u){a.push({type:"role",role:m.role,optional:false});let{marker:d,alternatives:p}=Pe(m,e);if(d){let f=p?{type:"literal",value:d,alternatives:p}:{type:"literal",value:d};a.push(f);}}let s=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(s);let l=u.map(m=>`{${m.role}}`).join(" "),c={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(u.map(m=>[m.role,{fromRole:m.role}]))};return Ge(a,c,i),{id:`${i.action}-event-${e.code}-sov-2role`,language:e.code,command:"on",priority:(n.basePriority??100)+55,template:{format:`{event} ${t.primary} ${l} ${r.primary}`,tokens:a},extraction:c}}function Yu(i,e,r,t,n){let a=[],u=[...i.roles.filter(c=>c.required)].sort((c,m)=>{let d=c.sovPosition??999,p=m.sovPosition??999;return d-p});for(let c of u){a.push({type:"role",role:c.role,optional:false});let{marker:m,alternatives:d}=Pe(c,e);m&&a.push(d?{type:"literal",value:m,alternatives:d}:{type:"literal",value:m});}if(a.push(r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary}),a.push({type:"role",role:"event",optional:false}),t.position==="after"){let c=t.primary.split(/\s+/);if(c.length>1)for(let m of c)a.push({type:"literal",value:m});else a.push(t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary});}let s=u.map(c=>`{${c.role}}`).join(" "),l={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(u.map(c=>[c.role,{fromRole:c.role}]))};return Ge(a,l,i),{id:`${i.action}-event-${e.code}-sov-2role-event-last`,language:e.code,command:"on",priority:(n.basePriority??100)+40,template:{format:`${s} ${r.primary} {event} ${t.primary}`,tokens:a},extraction:l}}function Zu(i,e,r,t,n){let a=[],u=[...i.roles.filter(E=>E.required)].sort((E,y)=>{let h=E.sovPosition??999,z=y.sovPosition??999;return h-z}),s=u[0];a.push({type:"role",role:s.role,optional:false});let{marker:l,alternatives:c}=Pe(s,e);if(l){let E=c?{type:"literal",value:l,alternatives:c}:{type:"literal",value:l};a.push(E);}if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let E=t.primary.split(/\s+/);if(E.length>1)for(let y of E)a.push({type:"literal",value:y});else {let y=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(y);}}let m=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(m);let d=u[1];a.push({type:"role",role:d.role,optional:false});let{marker:p,alternatives:f}=Pe(d,e);if(p){let E=f?{type:"literal",value:p,alternatives:f}:{type:"literal",value:p};a.push(E);}let v={action:{value:i.action},event:{fromRole:"event"},[s.role]:{fromRole:s.role},[d.role]:{fromRole:d.role}};return Ge(a,v,i),{id:`${i.action}-event-${e.code}-sov-2role-dest-first`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`{${s.role}} {event} ${t.primary} ${r.primary} {${d.role}}`,tokens:a},extraction:v}}function oi(i,e,r){let t=fe(i,e.code,r.primary)??[],n=[...new Set([...r.alternatives??[],...t])].filter(a=>a!==r.primary);return n.length?n:void 0}function Et(i,e,r,t,n){let a=[];if(t.position==="before"){let m=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(m);}a.push({type:"role",role:"event",optional:false});let o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let u=ii(i);a.push(...ni(i,e,u));let s=e.roleMarkers.destination,l=i.roles.some(m=>m.role==="destination");s&&l&&u!=="destination"&&a.push({type:"group",optional:true,tokens:[s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary},{type:"role",role:"destination",optional:true}]}),u!=="source"&&a.push(...be(i,e.roleMarkers.source));let c={action:{value:i.action},event:{fromRole:"event"},[u]:{fromRole:u},...u==="destination"?{}:ke(i),...u==="source"?{}:we(i)};return ai(a,c,i,e,new Set(["event",u,"destination","source"])),{id:`${i.action}-event-${e.code}-vso`,language:e.code,command:"on",priority:(n.basePriority??100)+50,template:{format:`${t.primary} {event} ${r.primary} {${u}} ${s?.primary||""} {destination?}`,tokens:a},extraction:c}}function Ju(i,e,r,t,n){let a=[],o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let u=i.action==="swap";a.push({type:"role",role:u?"destination":"patient",optional:false});let s=u?void 0:e.roleMarkers.destination;if(s&&a.push({type:"group",optional:true,tokens:[s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary},{type:"role",role:"destination",optional:true}]}),a.push(...be(i,e.roleMarkers.source)),t.position==="before"){let c=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(c);}if(a.push({type:"role",role:"event",optional:false}),u){let c=i.roles.find(m=>m.role==="patient")?.markerOverride?.[e.code];c&&a.push({type:"group",optional:true,tokens:[{type:"literal",value:c},{type:"role",role:"patient",optional:false}]});}let l={action:{value:i.action},event:{fromRole:"event"},[u?"destination":"patient"]:{fromRole:u?"destination":"patient"},...u?{}:ke(i),...we(i)};return Nr(a,l,i,e.code),{id:`${i.action}-event-${e.code}-vso-verb-first`,language:e.code,command:"on",priority:(n.basePriority??100)+45,template:{format:`${r.primary} {patient} ${s?.primary||""} {destination?} ${t.primary} {event}`,tokens:a},extraction:l}}function Xu(i,e,r,t,n){let a=[],o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let s=[...i.roles.filter(m=>m.required)].sort((m,d)=>{let p=m.svoPosition??999,f=d.svoPosition??999;return p-f});for(let m of s){let d,p;if(m.markerOverride&&m.markerOverride[e.code]!==void 0)d=m.markerOverride[e.code],p=d?fe(m,e.code,d):void 0;else {let f=e.roleMarkers[m.role];f&&(d=f.primary,p=oi(m,e,f));}if(d){let f=p?{type:"literal",value:d,alternatives:p}:{type:"literal",value:d};a.push(f);}a.push({type:"role",role:m.role,optional:false});}if(t.position==="before"){let m=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(m);}a.push({type:"role",role:"event",optional:false});let l=s.map(m=>`{${m.role}}`).join(" "),c={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(s.map(m=>[m.role,{fromRole:m.role}]))};return Ge(a,c,i),{id:`${i.action}-event-${e.code}-vso-verb-first-2role`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`${r.primary} ${l} ${t.primary} {event}`,tokens:a},extraction:c}}function gt(i,e,r,t,n){let a=[];if(t.position==="before"){let m=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(m);}a.push({type:"role",role:"event",optional:false});let o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let s=[...i.roles.filter(m=>m.required)].sort((m,d)=>{let p=m.svoPosition??999,f=d.svoPosition??999;return p-f});for(let m of s){let d,p;if(m.markerOverride&&m.markerOverride[e.code]!==void 0)d=m.markerOverride[e.code],p=d?fe(m,e.code,d):void 0;else {let f=e.roleMarkers[m.role];f&&(d=f.primary,p=oi(m,e,f));}if(d){let f=p?{type:"literal",value:d,alternatives:p}:{type:"literal",value:d};a.push(f);}a.push({type:"role",role:m.role,optional:false});}let l=s.map(m=>`{${m.role}}`).join(" "),c={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(s.map(m=>[m.role,{fromRole:m.role}]))};return Ge(a,c,i),{id:`${i.action}-event-${e.code}-vso-2role`,language:e.code,command:"on",priority:(n.basePriority??100)+55,template:{format:`${t.primary} {event} ${r.primary} ${l}`,tokens:a},extraction:c}}function Qu(i,e,r,t,n){let a=[],o=e.eventHandler?.negationMarker;if(t.position==="before"){let l=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(l);}if(o){let l=o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary};a.push(l);}a.push({type:"role",role:"event",optional:false});let u=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(u),a.push({type:"role",role:"patient",optional:false});let s=e.roleMarkers.destination;return s&&a.push({type:"group",optional:true,tokens:[s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary},{type:"role",role:"destination",optional:true}]}),a.push(...be(i,e.roleMarkers.source)),{id:`${i.action}-event-${e.code}-vso-negated`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`${t.primary} ${o?.primary||""} {event} ${r.primary} {patient} ${s?.primary||""} {destination?}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},...ke(i),...we(i)}}}function es(i,e,r,t){let n=[];n.push({type:"literal",value:"and",alternatives:["then"]}),n.push({type:"role",role:"event",optional:false});let a=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};n.push(a),n.push({type:"role",role:"patient",optional:false});let o=e.roleMarkers.destination;return o&&n.push({type:"group",optional:true,tokens:[o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary},{type:"role",role:"destination",optional:true}]}),n.push(...be(i,e.roleMarkers.source)),{id:`${i.action}-event-${e.code}-vso-proclitic`,language:e.code,command:"on",priority:(t.basePriority??100)+45,template:{format:`[proclitic?] {event} ${r.primary} {patient} ${o?.primary||""} {destination?}`,tokens:n},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},...ke(i),...we(i)}}}var Ne={basePriority:100,generateSimpleVariants:true,generateAlternatives:true};function He(i,e,r=Ne){let t=`${i.action}-${e.code}-generated`,n=r.basePriority??100,a=e.keywords[i.action];if(!a)throw new Error(`No keyword translation for '${i.action}' in ${e.code}`);let o=ns(i,e,a),u=Mr(i,e),s=ss(i,e,a);return {id:t,language:e.code,command:i.action,priority:n,template:{format:s,tokens:o},extraction:u}}function rs(i,e,r=Ne){if(i.roles.filter(u=>!u.required).length===0)return null;let n=i.roles.filter(u=>u.required),a={...i,roles:n};return {...He(a,e,r),id:`${i.action}-${e.code}-generated-simple`,priority:(r.basePriority??100)-5,extraction:Mr(i,e)}}function Ct(i,e,r=Ne){if(e.wordOrder!=="SOV")return null;let t=i.roles.filter(u=>u.required);if(t.length!==1)return null;let n=e.keywords[i.action];if(!n)return null;let a=n.alternatives?{type:"literal",value:n.primary,alternatives:n.alternatives}:{type:"literal",value:n.primary},o=t.flatMap(u=>{let s=u.valuePrefixLiteral?.[e.code],l={type:"role",role:u.role,optional:false,expectedTypes:u.expectedTypes};return s?[{type:"literal",value:s},l]:[l]});return {id:`${i.action}-${e.code}-generated-verb-first`,language:e.code,command:i.action,priority:(r.basePriority??100)-20,template:{format:`${n.primary} <${t[0].role}>`,tokens:[a,...o]},extraction:Mr(i,e)}}function ts(i,e,r=Ne){let t=[];if(t.push(He(i,e,r)),r.generateSimpleVariants){let n=rs(i,e,r);n&&t.push(n);}for(let n of i.omitRoleVariants??[]){let a={...i,roles:i.roles.filter(u=>u.role!==n)},o=He(a,e,r);t.push({...o,id:`${i.action}-${e.code}-generated-no-${n}`,priority:(r.basePriority??100)-8});}for(let n of i.widenTypeVariants??[]){if(n.excludeLanguages?.includes(e.code))continue;let a={...i,roles:i.roles.map(u=>u.role===n.role?{...u,expectedTypes:[...n.types]}:u)},o=He(a,e,r);t.push({...o,id:`${i.action}-${e.code}-generated-${n.idSuffix}`,priority:(r.basePriority??100)-(n.priorityDelta??15)});}if(r.generateVerbFirstVariants!==false){let n=Ct(i,e,r);n&&t.push(n);}for(let n of i.rolePrefixLiteralVariants??[]){let a=n.literal[e.code];if(!a)continue;let{rolePrefixLiteralVariants:o,...u}=i,s={...u,roles:i.roles.map(d=>d.role===n.role?{...d,valuePrefixLiteral:{[e.code]:a}}:d)},l=n.priorityDelta??5,c=n.methodCarrier?{[n.methodCarrier]:{value:a}}:{},m=He(s,e,r);if(t.push({...m,id:`${i.action}-${e.code}-generated-${n.idSuffix}`,priority:(r.basePriority??100)+l,extraction:{...m.extraction,...c}}),r.generateVerbFirstVariants!==false){let d=Ct(s,e,r);d&&t.push({...d,id:`${i.action}-${e.code}-generated-verb-first-${n.idSuffix}`,priority:(r.basePriority??100)-20+l,extraction:{...d.extraction,...c}});}}return t}function ui(i,e=Ne){let r=[],t=Fa();for(let n of t){if(!i.keywords[n.action])continue;let a=ts(n,i,e);if(r.push(...a),i.eventHandler?.eventMarker){let o=is(n,i,e);r.push(...o);}}return r}function is(i,e,r=Ne){if(!e.eventHandler||!e.eventHandler.eventMarker)return [];let t=[],n=e.eventHandler.eventMarker,a=e.keywords[i.action];if(!a)return [];if(i.roles.length===0)return [];if(i.action==="js")return [];let u=i.roles.filter(s=>s.required).length===2;if(e.wordOrder==="SOV")if(u)t.push(Gu(i,e,a,n,r)),t.push(Zu(i,e,a,n,r)),t.push(Yu(i,e,a,n,r));else {t.push($u(i,e,a,n,r)),t.push(Vu(i,e,a,n,r));let s=qu(i,e,a,n,r);s&&t.push(s);let l=e.roleMarkers.destination;l&&l.primary!==n.primary&&t.push(Wu(i,e,a,n,r));let c=n.primary.split(/\s+/),m=n.alternatives?.some(p=>!p.includes(" ")&&p.length>1);c.length>1&&m&&t.push(Ku(i,e,a,n,r)),t.push(Hu(i,e,a,n,r));let d=Uu(i,e,a,r);d&&t.push(d);}else e.wordOrder==="VSO"?u?(t.push(gt(i,e,a,n,r)),t.push(Xu(i,e,a,n,r))):(t.push(Et(i,e,a,n,r)),t.push(Ju(i,e,a,n,r)),e.eventHandler?.negationMarker&&t.push(Qu(i,e,a,n,r)),e.tokenization?.prefixes&&t.push(es(i,e,a,r))):u?t.push(gt(i,e,a,n,r)):t.push(Et(i,e,a,n,r));return t}function ns(i,e,r){let t=[],n=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary},a=os(i,e);switch(e.wordOrder){case "SVO":t.push(n),t.push(...a);break;case "SOV":t.push(...a),t.push(n);break;case "VSO":t.push(n),t.push(...a);break;default:t.push(n),t.push(...a);}return as(t)}function as(i){let e=[];for(let r of i){let t=e[e.length-1];if(t&&t.type==="literal"&&r.type==="literal"&&t.value===r.value){let n=[...t.alternatives??[],...r.alternatives??[]];n.length&&(e[e.length-1]={...t,alternatives:[...new Set(n)]});continue}e.push(r);}return e}function os(i,e){let r=[],t=ei(i.roles,e.wordOrder);for(let n of t){let a=si(n,e);n.required?r.push(...a):r.push({type:"group",optional:true,tokens:a});}return r}function si(i,e){let r=[],t=i.markerOverride?.[e.code],n=e.roleMarkers[i.role],a=i.renderOverride?.[e.code]==="",o={type:"role",role:i.role,optional:!i.required,expectedTypes:i.expectedTypes,...i.valueShape!==void 0?{valueShape:i.valueShape}:{}},u=i.valuePrefixLiteral?.[e.code],s=()=>{u&&r.push({type:"literal",value:u}),r.push(o);};if(t!==void 0){let l=t?t.split(/\s+/).filter(Boolean):[],c=t!==void 0&&t===i.markerOverride?.en,m=n?.position??(e.wordOrder==="SOV"&&!c?"after":"before"),d=i.markerOptional?.[e.code]===true,p=f=>{let v=l.length===1?fe(i,e.code,f)??[]:[],E={type:"literal",value:f,...v.length?{alternatives:v}:{},...a?{renderSuppress:true}:{}};r.push(d?{type:"group",optional:true,tokens:[E]}:E);};if(m==="before"){for(let f of l)p(f);s();}else {s();for(let f of l)p(f);}}else if(n){let l=()=>{let m=[...new Set([...n.alternatives??[],...fe(i,e.code,n.primary)??[]])].filter(d=>d!==n.primary);return {type:"literal",value:n.primary,...m.length?{alternatives:m}:{},...a?{renderSuppress:true}:{}}},c=m=>{if(!e.markersOptional&&!i.markerOptional?.[e.code]){r.push(m);return}r.push({type:"group",optional:true,...e.markersOptional&&!i.markerOptional?.[e.code]?{renderRequired:true}:{},tokens:[m]});};n.position==="before"?(n.primary&&c(l()),s()):(s(),c(l()));}else s();return r}function us(i,e){let r={};for(let t of i.roles){let n=t.markerOverride?.[e.code],a=e.roleMarkers[t.role];if(t.valuePrefixLiteral?.[e.code])r[t.role]={marker:t.valuePrefixLiteral[e.code]};else if(n!==void 0)if(!n)r[t.role]={};else {let u=!/\s/.test(n.trim())?fe(t,e.code,n)??[]:[];r[t.role]=u.length?{marker:n,markerAlternatives:u}:{marker:n};}else if(a&&a.primary){let o=[...new Set([...a.alternatives??[],...fe(t,e.code,a.primary)??[]])].filter(u=>u!==a.primary);r[t.role]=o.length?{marker:a.primary,markerAlternatives:o}:{marker:a.primary};}else r[t.role]={};}return r}function Mr(i,e){let r=us(i,e),t={};for(let n of i.roles){let a=r[n.role]||{};!n.required&&n.default?t[n.role]={...a,default:n.default}:t[n.role]=a;}return t}function ss(i,e,r){let t=[],a=ei(i.roles,e.wordOrder).map(o=>{let u=po(o,e),s="";return u&&u.primary?u.position==="before"?s=`${u.primary} {${o.role}}`:s=`{${o.role}} ${u.primary}`:s=`{${o.role}}`,o.required?s:`[${s}]`});switch(e.wordOrder){case "SVO":case "VSO":t.push(r.primary,...a);break;case "SOV":t.push(...a,r.primary);break;default:t.push(r.primary,...a);}return t.join(" ")}var ls=class{constructor(i={}){this.cache=new Map,this.config={maxSize:i.maxSize??1e3,ttlMs:i.ttlMs??0,enabled:i.enabled??true},this.stats={hits:0,misses:0,evictions:0,expirations:0};}makeKey(i,e){return `${e}:${i}`}isExpired(i){return this.config.ttlMs===0?false:Date.now()-i.createdAt>this.config.ttlMs}evictLRU(){let i=this.cache.keys().next().value;i!==void 0&&(this.cache.delete(i),this.stats.evictions++);}get(i,e){if(!this.config.enabled){this.stats.misses++;return}let r=this.makeKey(i,e),t=this.cache.get(r);if(!t){this.stats.misses++;return}if(this.isExpired(t)){this.cache.delete(r),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(r),t.lastAccessed=Date.now(),this.cache.set(r,t),this.stats.hits++,t.result}set(i,e,r){if(!this.config.enabled||r!==null&&typeof r=="object"&&"confidence"in r&&r.confidence===0)return;let t=this.makeKey(i,e),n=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(t,{result:r,createdAt:n,lastAccessed:n});}has(i,e){if(!this.config.enabled)return false;let r=this.makeKey(i,e),t=this.cache.get(r);return t?this.isExpired(t)?(this.cache.delete(r),this.stats.expirations++,false):true:false}delete(i,e){let r=this.makeKey(i,e);return this.cache.delete(r)}clear(){this.cache.clear();}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0};}getStats(){let i=this.stats.hits+this.stats.misses;return {hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:i>0?this.stats.hits/i:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(i){if(i.maxSize!==void 0)for(this.config.maxSize=i.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();i.ttlMs!==void 0&&(this.config.ttlMs=i.ttlMs),i.enabled!==void 0&&(this.config.enabled=i.enabled);}enable(){this.config.enabled=true;}disable(){this.config.enabled=false;}getConfig(){return {...this.config}}};new ls;function cs(i){let e=i.charCodeAt(0);return e>=44032&&e<=55203}function ms(i){for(let e of i)if(cs(e))return true;return false}var ds=[{pattern:"\uD558\uC2DC\uB2C8\uAE4C",confidence:.85,conjugationType:"honorific-causal",minStemLength:1},{pattern:"\uD558\uC2E4\uB54C",confidence:.88,conjugationType:"honorific-temporal",minStemLength:1},{pattern:"\uD558\uC2E4 \uB54C",confidence:.88,conjugationType:"honorific-temporal",minStemLength:1},{pattern:"\uD558\uC2DC\uBA74",confidence:.88,conjugationType:"honorific-conditional",minStemLength:1},{pattern:"\uC73C\uC2DC\uBA74",confidence:.85,conjugationType:"honorific-conditional",minStemLength:2},{pattern:"\uC2DC\uBA74",confidence:.82,conjugationType:"honorific-conditional",minStemLength:2},{pattern:"\uD558\uACE0\uB098\uC11C",confidence:.85,conjugationType:"sequential-after",minStemLength:1},{pattern:"\uD558\uACE0 \uB098\uC11C",confidence:.85,conjugationType:"sequential-after",minStemLength:1},{pattern:"\uD558\uACE0\uC11C",confidence:.85,conjugationType:"sequential-after",minStemLength:1},{pattern:"\uACE0\uB098\uC11C",confidence:.82,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uACE0 \uB098\uC11C",confidence:.82,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uACE0\uC11C",confidence:.82,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD558\uAE30\uC804\uC5D0",confidence:.85,conjugationType:"sequential-before",minStemLength:1},{pattern:"\uD558\uAE30 \uC804\uC5D0",confidence:.85,conjugationType:"sequential-before",minStemLength:1},{pattern:"\uAE30\uC804\uC5D0",confidence:.82,conjugationType:"sequential-before",minStemLength:2},{pattern:"\uAE30 \uC804\uC5D0",confidence:.82,conjugationType:"sequential-before",minStemLength:2},{pattern:"\uD558\uC790\uB9C8\uC790",confidence:.88,conjugationType:"immediate",minStemLength:1},{pattern:"\uC790\uB9C8\uC790",confidence:.85,conjugationType:"immediate",minStemLength:2},{pattern:"\uD574\uC57C\uD574\uC694",confidence:.85,conjugationType:"obligation",minStemLength:1},{pattern:"\uD574\uC57C\uD574",confidence:.85,conjugationType:"obligation",minStemLength:1},{pattern:"\uD574\uC57C\uD558\uB2E4",confidence:.85,conjugationType:"obligation",minStemLength:1},{pattern:"\uC5B4\uC57C\uD574\uC694",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uC5B4\uC57C\uD574",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uC544\uC57C\uD574\uC694",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uC544\uC57C\uD574",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uD558\uB2C8\uAE4C",confidence:.85,conjugationType:"causal-nikka",minStemLength:1},{pattern:"\uD560\uB54C",confidence:.88,conjugationType:"temporal-ttae",minStemLength:1},{pattern:"\uD560 \uB54C",confidence:.88,conjugationType:"temporal-ttae",minStemLength:1},{pattern:"\uC744\uB54C",confidence:.85,conjugationType:"temporal-ttae",minStemLength:2},{pattern:"\uC744 \uB54C",confidence:.85,conjugationType:"temporal-ttae",minStemLength:2},{pattern:"\uD558\uBA74",confidence:.88,conjugationType:"conditional-myeon",minStemLength:1},{pattern:"\uC73C\uBA74",confidence:.85,conjugationType:"conditional-myeon",minStemLength:2},{pattern:"\uB2C8\uAE4C",confidence:.82,conjugationType:"causal-nikka",minStemLength:2},{pattern:"\uBA74",confidence:.8,conjugationType:"conditional-myeon",minStemLength:2},{pattern:"\uD558\uC600\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD588\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD569\uB2C8\uB2E4",confidence:.85,conjugationType:"polite",minStemLength:1},{pattern:"\uC2B5\uB2C8\uB2E4",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uB429\uB2C8\uB2E4",confidence:.82,conjugationType:"polite",minStemLength:1},{pattern:"\u3142\uB2C8\uB2E4",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uD558\uC138\uC694",confidence:.85,conjugationType:"honorific",minStemLength:1},{pattern:"\uD558\uC2ED\uC2DC\uC624",confidence:.85,conjugationType:"honorific",minStemLength:1},{pattern:"\uC138\uC694",confidence:.82,conjugationType:"honorific",minStemLength:2},{pattern:"\uC2ED\uC2DC\uC624",confidence:.82,conjugationType:"honorific",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uC5B4\uC694",confidence:.82,conjugationType:"progressive",minStemLength:1},{pattern:"\uD558\uACE0\uC788\uC5B4",confidence:.82,conjugationType:"progressive",minStemLength:1},{pattern:"\uD588\uC5B4\uC694",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD574\uC694",confidence:.85,conjugationType:"polite",minStemLength:1},{pattern:"\uC5B4\uC694",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uC544\uC694",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uD588\uC5B4",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD574",confidence:.8,conjugationType:"present",minStemLength:1},{pattern:"\uC5C8\uC5B4",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\uC558\uC5B4",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uB2E4",confidence:.82,conjugationType:"progressive",minStemLength:1},{pattern:"\uACE0\uC788\uB2E4",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"\uACE0\uC788\uC5B4",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"\uD558\uB2E4",confidence:.88,conjugationType:"dictionary",minStemLength:1},{pattern:"\uD558\uC9C0\uC54A\uB2E4",confidence:.82,conjugationType:"negative",minStemLength:1},{pattern:"\uC548\uD558\uB2E4",confidence:.82,conjugationType:"negative",minStemLength:1},{pattern:"\uC9C0\uC54A\uB2E4",confidence:.8,conjugationType:"negative",minStemLength:2},{pattern:"\uD574\uB77C",confidence:.82,conjugationType:"imperative",minStemLength:1},{pattern:"\uD558\uB77C",confidence:.82,conjugationType:"imperative",minStemLength:1},{pattern:"\uB2E4",confidence:.75,conjugationType:"dictionary",minStemLength:2}],ps=[{pattern:"\uD558\uC2DC\uB2C8\uAE4C",confidence:.88,conjugationType:"honorific-causal"},{pattern:"\uD558\uC2E4\uB54C",confidence:.88,conjugationType:"honorific-temporal"},{pattern:"\uD558\uC2E4 \uB54C",confidence:.88,conjugationType:"honorific-temporal"},{pattern:"\uD558\uC2DC\uBA74",confidence:.88,conjugationType:"honorific-conditional"},{pattern:"\uD558\uC168\uC5B4\uC694",confidence:.85,conjugationType:"honorific-past"},{pattern:"\uD558\uC168\uC5B4",confidence:.85,conjugationType:"honorific-past"},{pattern:"\uD558\uC2ED\uB2C8\uB2E4",confidence:.85,conjugationType:"honorific-polite"},{pattern:"\uD558\uACE0\uB098\uC11C",confidence:.88,conjugationType:"sequential-after"},{pattern:"\uD558\uACE0 \uB098\uC11C",confidence:.88,conjugationType:"sequential-after"},{pattern:"\uD558\uACE0\uC11C",confidence:.88,conjugationType:"sequential-after"},{pattern:"\uD558\uAE30\uC804\uC5D0",confidence:.88,conjugationType:"sequential-before"},{pattern:"\uD558\uAE30 \uC804\uC5D0",confidence:.88,conjugationType:"sequential-before"},{pattern:"\uD558\uC790\uB9C8\uC790",confidence:.88,conjugationType:"immediate"},{pattern:"\uD574\uC57C\uD574\uC694",confidence:.88,conjugationType:"obligation"},{pattern:"\uD574\uC57C\uD574",confidence:.88,conjugationType:"obligation"},{pattern:"\uD574\uC57C\uD558\uB2E4",confidence:.88,conjugationType:"obligation"},{pattern:"\uD558\uB2C8\uAE4C",confidence:.88,conjugationType:"causal-nikka"},{pattern:"\uD560\uB54C",confidence:.88,conjugationType:"temporal-ttae"},{pattern:"\uD560 \uB54C",confidence:.88,conjugationType:"temporal-ttae"},{pattern:"\uD558\uBA74",confidence:.88,conjugationType:"conditional-myeon"},{pattern:"\uD558\uC600\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past"},{pattern:"\uD588\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past"},{pattern:"\uD569\uB2C8\uB2E4",confidence:.85,conjugationType:"polite"},{pattern:"\uD558\uC2ED\uC2DC\uC624",confidence:.85,conjugationType:"honorific"},{pattern:"\uD558\uC138\uC694",confidence:.85,conjugationType:"honorific"},{pattern:"\uD588\uC5B4\uC694",confidence:.85,conjugationType:"past"},{pattern:"\uD574\uC694",confidence:.85,conjugationType:"polite"},{pattern:"\uD588\uC5B4",confidence:.85,conjugationType:"past"},{pattern:"\uD574",confidence:.8,conjugationType:"present"},{pattern:"\uD558\uACE0\uC788\uC5B4\uC694",confidence:.82,conjugationType:"progressive"},{pattern:"\uD558\uACE0\uC788\uC5B4",confidence:.82,conjugationType:"progressive"},{pattern:"\uD558\uACE0\uC788\uB2E4",confidence:.82,conjugationType:"progressive"},{pattern:"\uD574\uC11C",confidence:.82,conjugationType:"connective"},{pattern:"\uD558\uACE0",confidence:.8,conjugationType:"connective"},{pattern:"\uD558\uC9C0\uC54A\uC544\uC694",confidence:.82,conjugationType:"negative"},{pattern:"\uD558\uC9C0\uC54A\uB2E4",confidence:.82,conjugationType:"negative"},{pattern:"\uC548\uD574\uC694",confidence:.82,conjugationType:"negative"},{pattern:"\uC548\uD574",confidence:.82,conjugationType:"negative"},{pattern:"\uD574\uB77C",confidence:.82,conjugationType:"imperative"},{pattern:"\uD558\uB77C",confidence:.82,conjugationType:"imperative"},{pattern:"\uD558\uB2E4",confidence:.88,conjugationType:"dictionary"}],pi=class{constructor(){this.language="ko";}isNormalizable(i){return !(!ms(i)||i.length<2)}normalize(i){let e=this.normalizeCompound(i);if(e)return e;let r=this.tryHadaNormalization(i);if(r)return r;for(let t of ds)if(i.endsWith(t.pattern)){let n=i.slice(0,-t.pattern.length),a=t.minStemLength??2;if(n.length<a)continue;let o={removedSuffixes:[t.pattern]};return t.conjugationType&&(o.conjugationType=t.conjugationType),rr(n,t.confidence,o)}return Qr(i)}tryHadaNormalization(i){for(let e of ps)if(i.endsWith(e.pattern)){let r=i.slice(0,-e.pattern.length);if(r.length<1)continue;return rr(r,e.confidence,{removedSuffixes:[e.pattern],conjugationType:e.conjugationType,originalForm:"hada-verb"})}return null}normalizeCompound(i){let e=[{pattern:"\uD558\uACE0\uB098\uC11C\uC600\uC5B4",suffixes:["\uD558\uACE0\uB098\uC11C","\uC600\uC5B4"],confidence:.78,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD558\uACE0\uB098\uC11C\uC600\uB2E4",suffixes:["\uD558\uACE0\uB098\uC11C","\uC600\uB2E4"],confidence:.78,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD558\uACE0\uB098\uC11C",suffixes:["\uD558\uACE0","\uB098\uC11C"],confidence:.85,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD574\uC57C\uD588\uC5B4",suffixes:["\uD574\uC57C","\uD588\uC5B4"],confidence:.8,conjugationType:"obligation",minStemLength:2},{pattern:"\uD574\uC57C\uD588\uB2E4",suffixes:["\uD574\uC57C","\uD588\uB2E4"],confidence:.8,conjugationType:"obligation",minStemLength:2},{pattern:"\uD574\uC57C\uD588\uC2B5\uB2C8\uB2E4",suffixes:["\uD574\uC57C","\uD588\uC2B5\uB2C8\uB2E4"],confidence:.8,conjugationType:"obligation",minStemLength:2},{pattern:"\uD558\uC2DC\uBA74\uC11C",suffixes:["\uD558\uC2DC","\uBA74\uC11C"],confidence:.82,conjugationType:"connective",minStemLength:2},{pattern:"\uD558\uC2DC\uBA70",suffixes:["\uD558\uC2DC","\uBA70"],confidence:.82,conjugationType:"connective",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uC5C8\uC5B4",suffixes:["\uD558\uACE0","\uC788\uC5C8\uC5B4"],confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uC5C8\uB2E4",suffixes:["\uD558\uACE0","\uC788\uC5C8\uB2E4"],confidence:.8,conjugationType:"progressive",minStemLength:2}];for(let{pattern:r,suffixes:t,confidence:n,conjugationType:a,minStemLength:o}of e)if(i.endsWith(r)){let u=i.slice(0,-r.length);if(u.length<o)continue;return rr(u,n,{removedSuffixes:t,conjugationType:a})}return null}},fi={code:"ko",name:"Korean",nativeName:"\uD55C\uAD6D\uC5B4",regions:["east-asian","priority"],direction:"ltr",script:"hangul",wordOrder:"SOV",markingStrategy:"particle",usesSpaces:true,verb:{position:"end",suffixes:["\uB2E4","\uC694","\uB2C8\uB2E4","\uC138\uC694"],subjectDrop:true},references:{me:"\uB098",it:"\uADF8\uAC83",you:"\uB108",result:"\uACB0\uACFC",event:"\uC774\uBCA4\uD2B8",target:"\uB300\uC0C1",body:"\uBC14\uB514",document:"\uBB38\uC11C",window:"\uCC3D",detail:"\uC138\uBD80"},possessive:{marker:"\uC758",markerPosition:"between",specialForms:{me:"\uB0B4",it:"\uADF8\uAC83\uC758",you:"\uB124"},keywords:{\uB0B4:"me",\uB124:"you",\uADF8\uC758:"it"}},roleMarkers:{patient:{primary:"\uC744",alternatives:["\uB97C"],position:"after"},destination:{primary:"\uC5D0",alternatives:["\uC73C\uB85C","\uB85C","\uC758"],position:"after"},source:{primary:"\uC5D0\uC11C",alternatives:["\uBD80\uD130"],position:"after"},style:{primary:"\uB85C",alternatives:["\uC73C\uB85C"],position:"after"},event:{primary:"\uC744",alternatives:["\uB97C"],position:"after"}},keywords:{toggle:{primary:"\uD1A0\uAE00",normalized:"toggle"},add:{primary:"\uCD94\uAC00",normalized:"add"},remove:{primary:"\uC81C\uAC70",alternatives:["\uC0AD\uC81C"],normalized:"remove"},put:{primary:"\uB123\uB2E4",alternatives:["\uB123\uAE30","\uB193\uAE30","\uB123\uC73C\uC138\uC694"],normalized:"put"},append:{primary:"\uB367\uBD99\uC774\uB2E4",alternatives:["\uB05D\uC5D0\uCD94\uAC00"],normalized:"append"},prepend:{primary:"\uC55E\uC5D0\uCD94\uAC00",alternatives:["\uC120\uB450\uCD94\uAC00"],normalized:"prepend"},take:{primary:"\uAC00\uC838\uC624\uB2E4",alternatives:["\uAC00\uC838\uC624\uC138\uC694"],normalized:"take"},make:{primary:"\uB9CC\uB4E4\uB2E4",normalized:"make"},clone:{primary:"\uBCF5\uC81C",normalized:"clone"},swap:{primary:"\uAD50\uD658",alternatives:["\uBC14\uAFB8\uB2E4"],normalized:"swap"},morph:{primary:"\uBCC0\uD615",alternatives:["\uBCC0\uD658"],normalized:"morph"},set:{primary:"\uC124\uC815",normalized:"set"},get:{primary:"\uC5BB\uB2E4",alternatives:["\uC5BB\uC73C\uC138\uC694"],normalized:"get"},increment:{primary:"\uC99D\uAC00",normalized:"increment"},decrement:{primary:"\uAC10\uC18C",normalized:"decrement"},log:{primary:"\uB85C\uADF8",normalized:"log"},show:{primary:"\uBCF4\uC774\uB2E4",alternatives:["\uD45C\uC2DC","\uBCF4\uC774\uAE30","\uBCF4\uC774\uC138\uC694"],normalized:"show"},hide:{primary:"\uC228\uAE30\uB2E4",alternatives:["\uC228\uAE30\uAE30","\uC228\uAE30\uC138\uC694"],normalized:"hide"},transition:{primary:"\uD2B8\uB79C\uC9C0\uC158",alternatives:["\uC804\uD658"],normalized:"transition"},on:{primary:"\uC5D0",alternatives:["\uC2DC","\uD560 \uB54C"],normalized:"on"},trigger:{primary:"\uD2B8\uB9AC\uAC70",normalized:"trigger"},send:{primary:"\uBCF4\uB0B4\uB2E4",alternatives:["\uBCF4\uB0B4\uC138\uC694"],normalized:"send"},focus:{primary:"\uD3EC\uCEE4\uC2A4",normalized:"focus"},blur:{primary:"\uD3EC\uCEE4\uC2A4\uC544\uC6C3",alternatives:["\uBE14\uB7EC"],normalized:"blur"},empty:{primary:"\uBE44\uC6B0\uAE30",alternatives:["\uBE44\uC5B4\uC788\uB294"],normalized:"empty"},open:{primary:"\uC5F4\uAE30",normalized:"open"},close:{primary:"\uB2EB\uAE30",normalized:"close"},select:{primary:"\uACE0\uB974\uAE30",normalized:"select"},clear:{primary:"\uC9C0\uC6B0\uAE30",normalized:"clear"},reset:{primary:"\uC7AC\uC124\uC815",normalized:"reset"},breakpoint:{primary:"\uC911\uB2E8\uC810",normalized:"breakpoint"},click:{primary:"\uD074\uB9AD",normalized:"click"},hover:{primary:"\uD638\uBC84",normalized:"hover"},submit:{primary:"\uC81C\uCD9C",normalized:"submit"},input:{primary:"\uC785\uB825",normalized:"input"},change:{primary:"\uBCC0\uACBD",normalized:"change"},go:{primary:"\uC774\uB3D9",normalized:"go"},scroll:{primary:"\uC2A4\uD06C\uB864",normalized:"scroll"},push:{primary:"\uD478\uC2DC",normalized:"push"},replace:{primary:"\uAD50\uCCB4",alternatives:["\uBC14\uAFB8\uAE30"],normalized:"replace"},process:{primary:"\uCC98\uB9AC",normalized:"process"},wait:{primary:"\uB300\uAE30",normalized:"wait"},fetch:{primary:"\uD328\uCE58",alternatives:["\uAC00\uC838\uC624\uAE30"],normalized:"fetch"},settle:{primary:"\uC548\uC815",normalized:"settle"},if:{primary:"\uB9CC\uC57D",normalized:"if"},when:{primary:"\uB54C",normalized:"when"},changes:{primary:"\uBCC0\uACBD\uB418\uBA74",normalized:"changes"},where:{primary:"\uC5B4\uB514",normalized:"where"},else:{primary:"\uC544\uB2C8\uBA74",normalized:"else"},unless:{primary:"\uC544\uB2C8\uB77C\uBA74",normalized:"unless"},repeat:{primary:"\uBC18\uBCF5",normalized:"repeat"},for:{primary:"\uAC01\uAC01",normalized:"for"},while:{primary:"\uB3D9\uC548",normalized:"while"},forever:{primary:"forever",normalized:"forever"},continue:{primary:"\uACC4\uC18D",normalized:"continue"},halt:{primary:"\uC815\uC9C0",normalized:"halt"},throw:{primary:"\uB358\uC9C0\uB2E4",normalized:"throw"},call:{primary:"\uD638\uCD9C",normalized:"call"},return:{primary:"\uBC18\uD658",normalized:"return"},then:{primary:"\uADF8\uB2E4\uC74C",alternatives:["\uADF8\uB7F0\uD6C4"],normalized:"then"},and:{primary:"\uADF8\uB9AC\uACE0",alternatives:["\uB610\uD55C","\uBC0F"],normalized:"and"},matches:{primary:"\uC77C\uCE58",normalized:"matches"},exists:{primary:"\uC874\uC7AC",normalized:"exists"},no:{primary:"\uC5C6\uC74C",normalized:"no"},end:{primary:"\uB05D",alternatives:["\uB9C8\uCE68"],normalized:"end"},js:{primary:"JS\uC2E4\uD589",alternatives:["js"],normalized:"js"},async:{primary:"\uBE44\uB3D9\uAE30",normalized:"async"},tell:{primary:"\uB9D0\uD558\uB2E4",normalized:"tell"},default:{primary:"\uAE30\uBCF8\uAC12",normalized:"default"},init:{primary:"\uCD08\uAE30\uD654",normalized:"init"},behavior:{primary:"\uB3D9\uC791",normalized:"behavior"},install:{primary:"\uC124\uCE58",normalized:"install"},measure:{primary:"\uCE21\uC815",normalized:"measure"},beep:{primary:"\uBE44\uD504",normalized:"beep"},break:{primary:"\uC911\uB2E8",normalized:"break"},copy:{primary:"\uBCF5\uC0AC",normalized:"copy"},exit:{primary:"\uB098\uAC00\uAE30",normalized:"exit"},pick:{primary:"\uC120\uD0DD",normalized:"pick"},render:{primary:"\uB80C\uB354\uB9C1",normalized:"render"},into:{primary:"\uC73C\uB85C",normalized:"into"},before:{primary:"\uC804\uC5D0",normalized:"before"},after:{primary:"\uD6C4\uC5D0",normalized:"after"},until:{primary:"\uAE4C\uC9C0",normalized:"until"},event:{primary:"\uC774\uBCA4\uD2B8",normalized:"event"},from:{primary:"\uC5D0\uC11C",normalized:"from"},connect:{primary:"\uC5F0\uACB0",alternatives:["\uC811\uC18D"],normalized:"connect"},stream:{primary:"\uC2A4\uD2B8\uB9BC",alternatives:["\uC2A4\uD2B8\uB9AC\uBC0D"],normalized:"stream"},live:{primary:"\uC2E4\uC2DC\uAC04",alternatives:["\uB77C\uC774\uBE0C"],normalized:"live"},socket:{primary:"\uC18C\uCF13",alternatives:["websocket"],normalized:"socket"},bind:{primary:"\uBC14\uC778\uB4DC",alternatives:["bind"],normalized:"bind"},intercept:{primary:"\uAC00\uB85C\uCC44\uAE30",alternatives:["\uC778\uD130\uC149\uD2B8","intercept"],normalized:"intercept"},worker:{primary:"\uC6CC\uCEE4",alternatives:["worker"],normalized:"worker"},eventsource:{primary:"eventsource",alternatives:["\uC774\uBCA4\uD2B8\uC18C\uC2A4"],normalized:"eventsource"}},tokenization:{particles:["\uC744","\uB97C","\uC774","\uAC00","\uC740","\uB294","\uC5D0","\uC5D0\uC11C","\uC73C\uB85C","\uB85C","\uC640","\uACFC","\uB3C4"],boundaryStrategy:"space"},eventHandler:{eventMarker:{primary:"\uD560 \uB54C",alternatives:["\uD560\uB54C","\uB54C","\uC5D0"],position:"after"},temporalMarkers:["\uD560 \uB54C","\uD560\uB54C","\uB54C"]}},fs=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"],ys=class{constructor(i=fs){this.name="operator",this.operators=[...i].sort((e,r)=>r.length-e.length);}canExtract(i,e){return this.operators.some(r=>i.startsWith(r,e))}extract(i,e){for(let r of this.operators)if(i.startsWith(r,e))return {value:r,length:r.length};return null}},hs="()[]{},:;",vs=class{constructor(i=hs){this.punctuation=i,this.name="punctuation";}canExtract(i,e){return this.punctuation.includes(i[e])}extract(i,e){let r=i[e];return this.punctuation.includes(r)?{value:r,length:1}:null}};function _r(i,e){let r=e;for(;r<i.length&&i[r]===":";){let t=i.slice(r).match(/^::?[a-zA-Z][a-zA-Z0-9-]*/);if(!t)break;let n=r+t[0].length;if(i[n]==="("){let a=0,o=n;for(;o<i.length;){if(i[o]==="(")a++;else if(i[o]===")"&&(a--,a===0)){o++;break}o++;}if(a!==0)break;n=o;}r=n;}return r}function li(i,e){let r=i[e];if(r==="#"){let t=i.slice(e).match(/^#[a-zA-Z_][\w-]*/);if(!t)return null;let n=_r(i,e+t[0].length);return i.slice(e,n)}if(r==="."){let t=i.slice(e).match(/^\.\{[a-zA-Z_$][\w$]*\}/);if(t)return t[0];let n=i.slice(e).match(/^\.[a-zA-Z_][\w-]*/);if(!n)return null;let a=_r(i,e+n[0].length);return i.slice(e,a)}if(r==="@"){let t=i.slice(e).match(/^@[a-zA-Z_][\w-]*/);return t?t[0]:null}if(r==="*"){let t=i.slice(e).match(/^\*(?:--)?[a-zA-Z_][\w-]*/);return t?t[0]:null}if(r==="["){let t=0,n=e;for(;n<i.length;){if(i[n]==="["&&t++,i[n]==="]"&&(t--,t===0)){let a=_r(i,n+1);return i.slice(e,a)}n++;}return null}if(r==="<"){let t=i.slice(e).match(/^<(?=[\w.#[])[\w-]*(?:[#.][\w-]+|\[[^\]]+\]|::?[a-zA-Z][a-zA-Z0-9-]*(?:\([^)]*\))?)*\s*\/>/);return t?t[0]:null}return null}var Es=class{constructor(){this.name="css-selector";}canExtract(i,e){let r=i[e];return r==="#"||r==="."||r==="["||r==="<"?true:r==="@"||r==="*"?li(i,e)!==null:false}extract(i,e){let r=li(i,e);return r?{value:r,length:r.length,metadata:{type:"css-selector"}}:null}},gs=class{constructor(){this.name="event-modifier";}canExtract(i,e){if(i[e]!==".")return false;let r=i.slice(e);return /^\.(once|prevent|stop|debounce|throttle|queue)/.test(r)}extract(i,e){let r=i.slice(e).match(/^\.(?:once|prevent|stop|debounce|throttle|queue)(?:\(([^)]+)\))?/);if(!r)return null;let t=r[0],n=t.slice(1).split("(")[0],a=r[1];return {value:t,length:t.length,metadata:{modifierName:n,value:a?n==="queue"?a:parseInt(a,10):void 0}}}},Cs=["http://","https://","//","./","../","/"];function zs(i,e){let r=1;for(let t=e;t<i.length;t++){let n=i[t];if(n==="{")r++;else if(n==="}"&&--r===0)return t+1}return -1}function ks(i,e){let r=i.slice(e),t=Cs.find(a=>r.startsWith(a));if(!t)return null;let n=t.length;for(;n<r.length;){let a=r[n];if(a==="$"&&r[n+1]==="{"){let o=zs(r,n+2);if(o!==-1){n=o;continue}}if(/\s/.test(a))break;n++;}return r.slice(0,n)}var ws=class{constructor(){this.name="url";}canExtract(i,e){let r=i.slice(e);return r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||r.startsWith("./")||r.startsWith("../")||r.startsWith("/")}extract(i,e){let r=ks(i,e);return r?{value:r,length:r.length,metadata:{type:"url"}}:null}},bs=class{constructor(){this.name="variable-ref";}canExtract(i,e){let r=i[e];return (r===":"||r==="$"||r==="^")&&e+1<i.length&&/[a-zA-Z_]/.test(i[e+1])}extract(i,e){if(!this.canExtract(i,e))return null;let r=1;for(;e+r<i.length&&/[a-zA-Z0-9_]/.test(i[e+r]);)r++;return {value:i.substring(e,e+r),length:r,metadata:{type:"variable-reference"}}}};function As(i){let e=i.charCodeAt(0);return e>=44032&&e<=55203}function Ds(i){let e=i.charCodeAt(0);return e>=4352&&e<=4607||e>=12592&&e<=12687}function Ir(i){return As(i)||Ds(i)}var Ss=["\uD560\uB54C","\uD558\uBA74","\uD558\uB2C8\uAE4C","\uD560 \uB54C"],Bs=class{constructor(){this.name="korean-keyword";}setContext(i){this.context=i;}canExtract(i,e){return Ir(i[e])}extract(i,e){if(!this.context)throw new Error("KoreanKeywordExtractor: context not set");let r=e,t=6;for(let m=Math.min(t,i.length-r);m>=2;m--){let d=i.slice(r,r+m),p=true;for(let v=0;v<d.length;v++)if(!Ir(d[v])){p=false;break}if(!p)continue;let f=this.context.lookupKeyword(d);if(f)return {value:d,length:m,metadata:{normalized:f.normalized!==f.native?f.normalized:void 0}};if(this.context.normalizer){let v=this.context.normalizer.normalize(d);if(v.stem!==d&&v.confidence>=.7){let E=this.context.lookupKeyword(v.stem);if(E)return {value:d,length:m,metadata:{normalized:E.normalized,stem:v.stem,stemConfidence:v.confidence}}}}}let n="",a=e;for(;a<i.length&&Ir(i[a])&&!(n.length>0&&this.context.isKeywordStart(i,a));)n+=i[a],a++;if(!n)return null;for(let m of Ss)if(n.endsWith(m)&&n.length>m.length){let d=n.slice(0,-m.length),p=this.context.lookupKeyword(d);if(p)return {value:d,length:d.length,metadata:{normalized:p.normalized,hasSuffix:true,suffix:m,stem:d}}}let o=this.context.lookupKeyword(n),u=o&&o.normalized!==o.native?o.normalized:void 0;n.includes("\uD1A0\uAE00")&&(console.log(`[KO DEBUG] word="${n}"`),console.log(`[KO DEBUG] keywordEntry=${o?"FOUND":"NOT FOUND"}`),console.log(`[KO DEBUG] normalizer=${this.context.normalizer?"EXISTS":"MISSING"}`));let s,l,c;if(!o&&this.context.normalizer){let m=this.context.normalizer.normalize(n);if(m.stem!==n&&m.confidence>=.7){let d=this.context.lookupKeyword(m.stem);d&&(s=d.normalized,l=m.stem,c=m.confidence,n.includes("\uD1A0\uAE00")&&console.log(`[KO DEBUG] word="${n}", stem="${m.stem}", normalized="${s}"`));}}return {value:n,length:a-r,metadata:{normalized:u||s,stem:l,stemConfidence:c}}}},ci=new Map([["\uC774",{role:"agent",confidence:.85,variant:"consonant",description:"subject marker (after consonant)"}],["\uAC00",{role:"agent",confidence:.85,variant:"vowel",description:"subject marker (after vowel)"}],["\uC744",{role:"patient",confidence:.95,variant:"consonant",description:"object marker (after consonant)"}],["\uB97C",{role:"patient",confidence:.95,variant:"vowel",description:"object marker (after vowel)"}],["\uC740",{role:"agent",confidence:.75,variant:"consonant",description:"topic marker (after consonant)"}],["\uB294",{role:"agent",confidence:.75,variant:"vowel",description:"topic marker (after vowel)"}],["\uC5D0",{role:"destination",confidence:.85,description:"at/to marker"}],["\uB85C",{role:"destination",confidence:.85,variant:"vowel",description:"to/by means (after vowel or \u3139)"}],["\uC640",{role:"style",confidence:.7,variant:"vowel",description:"and/with (after vowel)"}],["\uACFC",{role:"style",confidence:.7,variant:"consonant",description:"and/with (after consonant)"}],["\uC758",{role:"patient",confidence:.6,description:"possessive marker"}],["\uB3C4",{role:"patient",confidence:.65,description:"also/too marker"}],["\uB9CC",{role:"patient",confidence:.65,description:"only marker"}]]),mi=new Map([["\uC5D0\uC11C",{role:"source",confidence:.8,description:"at/from marker (action location)"}],["\uC73C\uB85C",{role:"destination",confidence:.85,variant:"consonant",description:"to/by means (after consonant)"}],["\uBD80\uD130",{role:"source",confidence:.9,description:"from/since marker"}],["\uAE4C\uC9C0",{role:"destination",confidence:.75,description:"until/to marker"}],["\uCC98\uB7FC",{role:"manner",confidence:.8,description:"like/as marker"}],["\uBCF4\uB2E4",{role:"source",confidence:.75,description:"than marker"}]]);function di(i){if(!i)return false;let e=i.codePointAt(0);return e>=44032&&e<=55203}var xs=class{constructor(){this.name="korean-particle";}setContext(i){this._context=i,this._context;}canExtract(i,e){let r=i[e];if(ci.has(r)&&!di(i[e+1]))return true;for(let[t]of mi)if(i.startsWith(t,e))return true;return false}extract(i,e){for(let[n,a]of mi)if(i.startsWith(n,e))return {value:n,length:n.length,metadata:{particleRole:a.role,particleConfidence:a.confidence,particleVariant:a.variant}};let r=i[e],t=ci.get(r);return t&&!di(i[e+1])?{value:r,length:1,metadata:{particleRole:t.role,particleConfidence:t.confidence,particleVariant:t.variant}}:null}};function Ts(i){let e=i.charCodeAt(0);return e>=65&&e<=90||e>=97&&e<=122||e===95||e===36}function Fs(i){let e=i.charCodeAt(0);return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95||e===36}var Rs=class{constructor(){this.name="ascii-identifier";}setContext(i){this.context=i;}canExtract(i,e){return Ts(i[e])}extract(i,e){if(!this.context)throw new Error("AsciiIdentifierExtractor: context not set");let r=e,t="",n=e;for(;n<i.length&&Fs(i[n]);)t+=i[n],n++;if(!t)return null;let a=this.context.lookupKeyword(t),o=a&&a.normalized!==a.native?a.normalized:void 0;return {value:t,length:n-r,metadata:{normalized:o}}}};function Os(){return [new ws,new gs,new bs,new Es]}var Ps=new Set(["\uC774","\uAC00","\uC744","\uB97C","\uC740","\uB294","\uC5D0","\uC5D0\uC11C","\uB85C","\uC73C\uB85C","\uC640","\uACFC","\uC758","\uB3C4","\uB9CC","\uBD80\uD130","\uAE4C\uC9C0","\uCC98\uB7FC","\uBCF4\uB2E4"]),Ls=[{native:"\uCC38",normalized:"true"},{native:"\uAC70\uC9D3",normalized:"false"},{native:"\uB110",normalized:"null"},{native:"\uBBF8\uC815\uC758",normalized:"undefined"},{native:"\uC815\uC758\uC548\uB428",normalized:"undefined"},{native:"\uCCAB\uBC88\uC9F8",normalized:"first"},{native:"\uB9C8\uC9C0\uB9C9",normalized:"last"},{native:"\uB2E4\uC74C",normalized:"next"},{native:"\uC774\uC804",normalized:"previous"},{native:"\uAC00\uC7A5\uAC00\uAE4C\uC6B4",normalized:"closest"},{native:"\uBD80\uBAA8",normalized:"parent"},{native:"\uC548\uC5D0",normalized:"in"},{native:"\uD074\uB9AD",normalized:"click"},{native:"\uB354\uBE14\uD074\uB9AD",normalized:"dblclick"},{native:"\uBCC0\uACBD",normalized:"change"},{native:"\uC81C\uCD9C",normalized:"submit"},{native:"\uC785\uB825",normalized:"input"},{native:"\uB85C\uB4DC",normalized:"load"},{native:"\uC2A4\uD06C\uB864",normalized:"scroll"},{native:"\uD0A4\uB2E4\uC6B4",normalized:"keydown"},{native:"\uD0A4\uC5C5",normalized:"keyup"},{native:"\uB9C8\uC6B0\uC2A4\uC624\uBC84",normalized:"mouseover"},{native:"\uB9C8\uC6B0\uC2A4\uC544\uC6C3",normalized:"mouseout"},{native:"\uB9C8\uC6B0\uC2A4\uB2E4\uC6B4",normalized:"mousedown"},{native:"\uB9C8\uC6B0\uC2A4\uC5C5",normalized:"mouseup"},{native:"\uB0B4",normalized:"my"},{native:"\uADF8\uAC83\uC758",normalized:"its"},{native:"\uADF8\uB2E4\uC74C",normalized:"then"},{native:"\uADF8\uB7F0\uD6C4",normalized:"then"},{native:"\uADF8\uB7EC\uBA74",normalized:"then"},{native:"\uADF8\uB9AC\uACE0",normalized:"and"},{native:"\uB610\uB294",normalized:"or"},{native:"\uC544\uB2C8",normalized:"not"},{native:"\uC774\uB2E4",normalized:"is"},{native:"\uCD08",normalized:"s"},{native:"\uBC00\uB9AC\uCD08",normalized:"ms"},{native:"\uBD84",normalized:"m"},{native:"\uC2DC\uAC04",normalized:"h"},{native:"\uD3EC\uD568",normalized:"inclusive"},{native:"\uC81C\uC678",normalized:"exclusive"},{native:"\uBB38\uC790",normalized:"characters"},{native:"\uBB34\uC791\uC704",normalized:"random"}],Ns=class extends Xr{constructor(){super(),this.language="ko",this.direction="ltr",this.initializeKeywordsFromProfile(fi,Ls),this.normalizer=new pi,this.registerExtractors(Os()),this.registerExtractor(new Zr),this.registerExtractor(new Jr),this.registerExtractor(new Rs),this.registerExtractor(new xs),this.registerExtractor(new Bs),this.registerExtractor(new ys),this.registerExtractor(new vs);}classifyToken(i){return Ps.has(i)?"particle":this.isKeyword(i)?"keyword":i.startsWith("/")||i.startsWith("./")||i.startsWith("../")||i.startsWith("http")?"url":/^\.(once|prevent|stop|debounce|throttle|queue)(\(.*\))?$/.test(i)?"event-modifier":i.startsWith("#")||i.startsWith(".")||i.startsWith("[")||i.startsWith("*")||i.startsWith("<")?"selector":i.startsWith('"')||i.startsWith("'")||/^\d/.test(i)?"literal":"identifier"}},Ms=new Ns;Tt("ko",Ms,fi);function lr(i){let e=i.getAttribute("data-lang");if(e)return sr(e);let r=i.getAttribute("data-hyperscript-lang")??i.closest?.("[data-hyperscript-lang]")?.getAttribute("data-hyperscript-lang");if(r)return sr(r);let t=i.closest?.("[lang]")?.getAttribute("lang");if(t)return sr(t);let n=typeof document<"u"?document.documentElement?.lang:null;return n&&n!=="en"?sr(n):null}function sr(i){return i.split("-")[0].toLowerCase()}var yi={add:[["patient",""],["destination","to"]],append:[["patient",""],["destination","to"]],async:[],beep:[["patient",""]],behavior:[["patient",""]],bind:[["destination",""],["source","to"]],blur:[["patient",""]],break:[],breakpoint:[],call:[["patient",""]],clear:[["patient",""]],clone:[["patient",""],["destination","into"]],close:[["patient",""]],compound:[],continue:[],copy:[["patient",""]],decrement:[["patient",""],["quantity","by"]],default:[["destination",""],["patient","to"]],else:[],empty:[["patient",""]],eventsource:[],exit:[],fetch:[["source",""],["style","with"],["responseType","as"],["method","via"],["destination","on"]],focus:[["patient",""]],for:[["patient",""],["source","in"]],get:[["source",""],["destination","on"]],go:[["destination",""]],halt:[["patient",""]],hide:[["patient",""],["style","with"]],if:[["condition",""]],increment:[["patient",""],["quantity","by"]],init:[],install:[["patient",""],["destination","on"]],intercept:[],js:[["patient",""]],live:[],log:[["patient",""]],make:[["patient",""]],measure:[["patient",""],["source","of"]],morph:[["patient",""],["destination","to"],["manner","using view"]],on:[["event",""],["source","from"]],open:[["patient",""],["style","as"]],pick:[["patient",""],["source","from"]],prepend:[["patient",""],["destination","to"]],process:[["patient","partials in"],["manner","using view"]],push:[["patient","url"]],put:[["patient",""],["destination","into"]],remove:[["patient",""],["source","from"]],render:[["patient",""],["style","with"]],repeat:[["quantity",""],["condition","until"]],replace:[["patient","url"]],reset:[["patient",""]],return:[["patient",""]],scroll:[["destination","to"]],select:[["patient",""]],send:[["event",""],["destination","to"]],set:[["destination",""],["patient","to"],["scope","on"]],settle:[["patient",""]],show:[["patient",""],["style","with"]],socket:[],swap:[["method",""],["destination","of"],["patient","with"],["manner","using view"]],take:[["patient",""],["source","from"],["recipient","for"]],tell:[["destination",""]],throw:[["patient",""]],toggle:[["patient",""],["destination","on"],["duration","for"]],transition:[["patient",""],["goal","to"],["destination","on"],["duration","over"],["style","with"]],trigger:[["event",""],["destination","on"]],unless:[["condition",""]],wait:[["duration",""]],when:[["condition",""]],while:[["condition",""]],worker:[]};var _s=new Set(["repeat","for","while","tell"]),Is=new Set(["js"]);function cr(i){switch(i.kind){case "event-handler":return js(i);case "compound":return $s(i);default:return Vs(i)}}function js(i){let e=["on"],r=i.roles.get("event");r&&e.push(r.type==="literal"?String(r.value):Ye(r));let t=i.roles.get("source");if(t&&e.push("from",Ye(t)),i.body&&i.body.length>0){let n=i.body.map(cr);e.push(n.join(" "));}return e.join(" ")}function $s(i){let e=i.chainType==="async"?"async":i.chainType,r=i.statements.map(cr),t=r[0]??"";for(let n=1;n<r.length;n++){let a=i.statements[n-1],o=i.statements[n],u=a.kind==="command"&&_s.has(a.action),s=a.kind==="command"&&a.action==="bind"&&o.kind==="command"&&o.action==="bind";a.kind==="command"&&Is.has(a.action)&&(t+=" end"),t+=(u||s?" ":` ${e} `)+r[n];}return t}function Vs(i){let e=yi[i.action];if(e){let t=[i.action];for(let[n,a]of e){let o=i.roles.get(n);o&&((n==="destination"||n==="source")&&o.type==="reference"&&o.value==="me"||(a&&t.push(a),t.push(Ye(o))));}return t.join(" ")}let r=[i.action];for(let[,t]of i.roles)r.push(Ye(t));return r.join(" ")}function Ye(i){switch(i.type){case "literal":return typeof i.value=="string"&&i.dataType==="string"?`"${i.value}"`:String(i.value);case "selector":return i.value;case "reference":return i.value;case "property-path":return qs(i);case "expression":return i.raw;case "flag":return i.enabled?`+${i.name}`:`~${i.name}`}}function qs(i){let e=Ye(i.object),r=i.property;if(i.object.type==="reference")switch(i.object.value){case "me":return `my ${r}`;case "it":return `its ${r}`;case "you":return `your ${r}`}return `${e}'s ${r}`}var Ws={confidenceThreshold:.5,strategy:"semantic"};function Ks(i,e){return typeof i=="number"?i:i[e]??i["*"]??.5}var Hs=/^(on\s+(?:every\s+)?[\w-]+(?:\[.*?\])?(?:\.[\w-]+(?:\([^)]*\))?)*(?:\s+from\s+\S+)?(?:\s+queue\s+\w+)?\s+)/;function Us(i){let e=i.match(Hs);if(!e)return null;let r=e[1],t=i.slice(r.length);return t?{prefix:r,commands:t}:null}function hi(i){function e(n,a,o){try{return i.isLanguageRegistered(a)?i.translateSingle(n,a,o):null}catch{return null}}function r(n,a,o){try{let u=o(n,a);return u!==n?u:null}catch{return null}}function t(n,a,o){if(o.strategy==="semantic"||o.strategy==="auto"){let u=Ks(o.confidenceThreshold,a),s=e(n,a,u);if(s!==null)return s}if((o.strategy==="auto"||o.strategy==="i18n")&&o.i18nToEnglish){let u=r(n,a,o.i18nToEnglish);if(u!==null)return u}return null}return function(a,o,u={}){if(o==="en")return a;let s={...Ws,...u},l=t(a,o,s);if(l!==null)return l;let c=Us(a);if(c){let m=t(c.commands,o,s);if(m!==null)return c.prefix+m}return a}}var jr=hi({isLanguageRegistered:Rt,translateSingle(i,e,r){let t=Qt(i,e);return t.confidence<r||!t.node?null:cr(t.node)}});var $r=new WeakSet;function Gs(i){return (i.config?.attributes??"_, script, data-script").split(",").map(r=>r.trim()).filter(Boolean)}function Ys(i,e){for(let r of e)if(i.hasAttribute(r))return r;return null}function vi(i,e){if(typeof i.addBeforeProcessHook!="function"){console.warn("[hyperscript-i18n] _hyperscript.addBeforeProcessHook is unavailable \u2014 this build of _hyperscript.org is not supported. Load a current version from https://unpkg.com/hyperscript.org.");return}let r=Gs(i),t=[...r.map(a=>`[${a}]`),'script[type="text/hyperscript"]'].join(", "),n=a=>{if($r.has(a))return;if(a instanceof HTMLScriptElement&&a.type==="text/hyperscript"){let l=a.textContent??"";if(!l)return;let c=e(l,a);$r.add(a),c!=null&&c!==l&&(a.textContent=c);return}let o=Ys(a,r);if(!o)return;let u=a.getAttribute(o);if(!u)return;let s=e(u,a);$r.add(a),s!=null&&s!==u&&a.setAttribute(o,s);};i.addBeforeProcessHook(a=>{!a||typeof a.querySelectorAll!="function"||(typeof a.matches=="function"&&a.matches(t)&&n(a),a.querySelectorAll(t).forEach(n));});}function gi(i,e){if(typeof i.parse!="function")return true;try{let r=i.parse(e);return !r?.errors||r.errors.length===0}catch{return false}}var Ei=new Set;function Ci(i,e,r){Ei.has(i)||(Ei.add(i),console.warn(`[hyperscript-i18n] Translation for lang="${i}" rendered hyperscript the host parser rejects \u2014 falling back to the original text. Source: "${e.length>60?e.slice(0,60)+"\u2026":e}" \u2192 "${r.length>60?r.slice(0,60)+"\u2026":r}". Further elements in this language stay quiet \u2014 enable { debug: true } for per-element detail.`));}function Vr(i={}){return function(r){let t=r;vi(t,(n,a)=>{let o=Zs(a,i);if(!o||o==="en")return n;let u=jr(n,o,i);if(u!==n){if(i.validateWithHost!==false&&!gi(t,u))return i.debug?console.log(`[hyperscript-i18n] ${o}: host rejected "${u}" \u2014 keeping "${n}"`):Ci(o,n,u),n;i.debug&&console.log(`[hyperscript-i18n] ${o}: "${n}" \u2192 "${u}"`);}return u});}}function Zs(i,e){if(e.languageAttribute){let t=i.getAttribute(e.languageAttribute);if(t)return t.split("-")[0].toLowerCase()}let r=lr(i);return r||(e.defaultLanguage??null)}function zi(i,e,r={}){return e==="en"?i:jr(i,e,r)}Ft(i=>ui(i));function ki(){typeof _hyperscript<"u"&&_hyperscript.use&&_hyperscript.use(Vr());}var Bc=["ko"];ki();
5
- exports.plugin=Vr;exports.preprocess=zi;exports.resolveLanguage=lr;exports.supportedLanguages=Bc;return exports;})({});
2
+ `)}function on(i){let e=0,r=0,t=0,n={};for(let a of i.values())for(let o of a.items)o.severity==="error"?e++:o.severity==="warning"?r++:o.severity==="note"&&t++,n[o.code]=(n[o.code]||0)+1;return {totalCommands:i.size,errors:e,warnings:r,notes:t,byCode:n}}function un(i,e){let r=[];for(let t of e){let n=i.roles.find(a=>a.role===t.role);n&&(n.expectedTypes.length>0&&!n.expectedTypes.includes(t.type)&&(n.expectedTypes.includes("expression")||r.push({level:"error",role:t.role,message:`${i.action}.${t.role} expects type [${n.expectedTypes.join(", ")}], got '${t.type}'`,code:F.VALUE_TYPE_MISMATCH})),t.type==="selector"&&t.selectorKind&&n.selectorKinds&&n.selectorKinds.length>0&&(n.selectorKinds.includes(t.selectorKind)||r.push({level:"error",role:t.role,message:`${i.action}.${t.role} expects selector kind [${n.selectorKinds.join(", ")}], got '${t.selectorKind}'`,code:F.SELECTOR_KIND_MISMATCH})));}return r}function sn(i){if(i.length!==2)return false;let[e,r]=[...i].sort();return Bt.some(([t,n])=>t===e&&n===r)}function Dt(i){let e=[];if(!i.keywords)return {language:i.code,collisions:e};let r=new Map;for(let[n,a]of Object.entries(i.keywords)){if(!a||!a.primary)continue;let o=r.get(a.primary)||[];if(o.push({command:n,isPrimary:true}),r.set(a.primary,o),a.alternatives)for(let u of a.alternatives){let s=r.get(u)||[];s.push({command:n,isPrimary:false}),r.set(u,s);}}for(let[n,a]of r){let o=[...new Set(a.map(l=>l.command))];if(o.length<=1||sn(o))continue;let u=a.filter(l=>l.isPrimary).length,s;u>=2?s="primary-primary":u===1?s="primary-alternative":s="alternative-alternative",e.push({keyword:n,commands:o.sort(),type:s});}let t={"primary-primary":0,"primary-alternative":1,"alternative-alternative":2};return e.sort((n,a)=>t[n.type]-t[a.type]),{language:i.code,collisions:e}}function ln(i){let e=[];for(let[,r]of Object.entries(i)){let t=Dt(r);t.collisions.length>0&&e.push(t);}return e.sort((r,t)=>r.language.localeCompare(t.language))}var Cr,St,Bt,cn=zt({"src/generators/schema-validator.ts"(){Ji(),Cr=new Set(["put","append","prepend","log","throw","make","measure","return","swap","morph","beep","copy"]),St=new Set(["compound","else","halt","continue","init","settle","focus","blur","return","js","measure","break","exit","beep","empty","open","close","select","clear","reset","breakpoint","live","eventsource","socket","worker","intercept"]),Bt=[["change","changes"]];}});function ke(i){let e=i.roles.find(r=>r.role==="destination");return e?{destination:e.default?{fromRole:"destination",default:e.default}:{fromRole:"destination"}}:{}}function we(i){let e=i.roles.find(r=>r.role==="source");return e?{source:e.default?{fromRole:"source",default:e.default}:{fromRole:"source"}}:{}}function be(i,e){return Br(i,e,"source")}function Sr(i,e){return Br(i,e,"destination")}function mn(i,e){return Br(i,e,"patient")}function Br(i,e,r){if(!e||!i.roles.some(a=>a.role===r))return [];let t=e.alternatives?{type:"literal",value:e.primary,alternatives:[...e.alternatives]}:{type:"literal",value:e.primary},n={type:"role",role:r,optional:true};return [{type:"group",optional:true,tokens:e.position==="after"?[n,t]:[t,n]}]}var dn={action:"toggle",description:"Toggle a class or attribute on/off",category:"dom-class",primaryRole:"patient",ast:{args:["patient"],modifiers:{on:"destination",for:"duration"}},argSkipTokens:["on"],roles:[{role:"patient",description:"The class or attribute to toggle",required:true,expectedTypes:["selector"],selectorKinds:["class","attribute"],svoPosition:1,sovPosition:2,markerOptional:{zh:true}},{role:"destination",description:"The target element (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerVariants:{ko:["\uC5D0\uC11C"]}},{role:"duration",description:"How long the class stays on before reverting (`toggle .a for 2s`)",required:false,expectedTypes:["literal"],svoPosition:3,sovPosition:3,valueShape:"time",markerOverride:{en:"for",ja:"\u9593",ko:"\uB3D9\uC548"}}],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)"}},pn={action:"add",description:"Add a class or attribute to an element",category:"dom-class",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"destination"}},roles:[{role:"patient",description:"The class or attribute to add",required:true,expectedTypes:["selector","literal"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:false,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1,markerOverride:{en:"to",es:"a",ar:"\u0625\u0644\u0649",zh:"\u5230",fr:"\xE0",de:"zu",pt:"a",he:"\u05D0\u05DC",id:"ke",it:"a",sw:"kwa"},markerLegacy:{es:["en","sobre","hacia"],ar:["\u0639\u0644\u0649","\u0641\u064A","\u0628"],zh:["\u5728","\u4E8E"],fr:["sur","dans"],de:["auf","in"],pt:["em","para"],he:["\u05E2\u05DC","\u05D1","\u05DC"],id:["pada","di"],it:["in","su"],sw:["kwenye"]}}],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"}},fn={action:"remove",description:"Remove a class or attribute from an element",category:"dom-class",primaryRole:"patient",ast:{args:["patient"],modifiers:{from:"source"}},targetRole:"source",argSkipTokens:["from"],roles:[{role:"patient",description:"The class/attribute to remove, or the element to remove",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to remove from (defaults to me)",required:false,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"}},yn={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:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"destination",description:"Where to put the content",required:true,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"into",ar:"\u0641\u064A",zh:"\u5230",fr:"dans",de:"in",he:"\u05D1",id:"ke",sw:"kwa"},markerVariants:{en:["before","after"]},markerLegacy:{ar:["\u0639\u0644\u0649","\u0625\u0644\u0649","\u0628"],zh:["\u5728","\u4E8E"],fr:["sur","\xE0"],de:["auf","zu"],he:["\u05E2\u05DC","\u05D0\u05DC","\u05DC"],id:["pada","di"],sw:["kwenye"]},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"}},hn={action:"set",description:"Set a property or variable to a value",category:"variable",primaryRole:"destination",ast:{args:["destination"],modifiers:{to:"patient",on:"scope"}},argSkipTokens:["to"],roles:[{role:"destination",description:"The property or variable to set",required:true,expectedTypes:["selector","reference","expression","property-path"],svoPosition:1,sovPosition:1,markerOverride:{en:"",es:"",ja:"\u3092",ko:"\uB97C",tr:"i",ar:"",sw:"",tl:"",th:"",bn:"\u0995\u09C7",qu:"ta",hi:"\u0915\u094B",zh:"\u628A"},markerOptional:{zh:true}},{role:"patient",description:"The value to set",required:true,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",th:"\u0E43\u0E19",bn:"\u09A4\u09C7",qu:"man",hi:"\u092E\u0947\u0902",zh:"\u5230"},markerVariants:{tr:["e","a","ye","ya"],zh:["\u4E3A","\u70BA","\u6210"]}},{role:"scope",description:"The element(s) the attribute/property is set on (defaults to me)",required:false,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>"}},vn={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:true,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:true,expectedTypes:["selector","reference","expression","property-path"],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>"}},En={action:"live",description:"Reactive block: re-run the body when its dependencies change",category:"control-flow",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},gn={action:"when",description:"Reactive observer: re-run the body when a watched expression changes",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,structuralOnly:true,roles:[{role:"condition",description:"The watched expression (`or`-separated expressions watch each)",required:true,expectedTypes:["expression","reference","selector"],svoPosition:1}]},Cn={action:"eventsource",description:"Open a Server-Sent Events stream and handle its events",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},zn={action:"socket",description:"Open a WebSocket and handle its messages",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},kn={action:"worker",description:"Define a Web Worker with inline methods",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},wn={action:"intercept",description:"Service-worker fetch interception / caching strategies",category:"async",primaryRole:"patient",hasBody:true,bareKeyword:true,roles:[]},bn={action:"show",description:"Make an element visible",category:"dom-visibility",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{with:"duration"}},roles:[{role:"patient",description:"The element to show",required:true,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:false,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},An={action:"hide",description:"Make an element invisible",category:"dom-visibility",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{with:"duration"}},roles:[{role:"patient",description:"The element to hide",required:true,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1},{role:"style",description:"Animation style (fade, slide, etc.)",required:false,expectedTypes:["literal"],svoPosition:2,sovPosition:2}]},Dn={action:"on",description:"Handle an event",category:"event",primaryRole:"event",ast:{args:["event"],modifiers:{from:"source"}},hasBody:true,roles:[{role:"event",description:"The event to handle",required:true,expectedTypes:["literal"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to listen on (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}],widenTypeVariants:[{role:"event",types:["literal","expression"],idSuffix:"expr-event",excludeLanguages:["ko"]}]},Sn={action:"trigger",description:"Trigger/dispatch an event",category:"event",primaryRole:"event",ast:{args:["event"],modifiers:{on:"destination"}},argSkipTokens:["on"],roles:[{role:"event",description:"The event to trigger (supports namespaced events like draggable:start)",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2,markerVariants:{hi:["\u0915\u094B"],qu:["ta"],bn:["\u0995\u09C7"]},markerOverride:{bn:"\u0995\u09C7",hi:"\u0915\u094B"}},{role:"destination",description:"The target element (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},Bn={action:"wait",description:"Wait for a duration or event",category:"async",primaryRole:"duration",roles:[{role:"duration",description:"Duration or event to wait for",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},xn={action:"fetch",description:"Fetch data from a URL",category:"async",primaryRole:"source",ast:{args:["source"],modifiers:{with:["style","method"],as:"responseType",body:"patient"},isBlocking:true},roles:[{role:"source",description:"The URL to fetch from",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,renderOverride:{en:""}},{role:"style",description:"Request options object (method, headers, body, credentials\u2026)",required:false,expectedTypes:["expression"],valueShape:"object",svoPosition:2,sovPosition:2},{role:"responseType",description:"Response format (json, text, html, blob, etc.)",required:false,expectedTypes:["literal","expression"],svoPosition:3,sovPosition:3,markerOverride:{en:"as",ja:"\u3068\u3057\u3066"}},{role:"method",description:"HTTP method (GET, POST, etc.)",required:false,expectedTypes:["literal"],svoPosition:4,sovPosition:4},{role:"destination",description:"Where to store the result",required:false,expectedTypes:["selector","reference"],svoPosition:5,sovPosition:5}]},Tn={action:"increment",description:"Increment a numeric value",category:"variable",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{by:"quantity"}},roles:[{role:"patient",description:"The value to increment",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to increment by (defaults to 1)",required:false,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Fn={action:"decrement",description:"Decrement a numeric value",category:"variable",primaryRole:"patient",ast:{args:[["destination","patient"]],modifiers:{by:"quantity"}},roles:[{role:"patient",description:"The value to decrement",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1},{role:"quantity",description:"Amount to decrement by (defaults to 1)",required:false,expectedTypes:["literal"],default:{type:"literal",value:1,dataType:"number"},svoPosition:2,sovPosition:2,markerOverride:{en:"by",es:"por",pt:"por",fr:"par",de:"um"}}]},Rn={action:"append",description:"Append content to an element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"destination"}},omitRoleVariants:["destination"],roles:[{role:"patient",description:"The content to append",required:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to append to",required:true,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},On={action:"prepend",description:"Prepend content to an element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"destination"}},omitRoleVariants:["destination"],roles:[{role:"patient",description:"The content to prepend",required:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The element to prepend to",required:true,expectedTypes:["selector","reference","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"to"}}]},Pn={action:"log",description:"Log a value to the console",category:"variable",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The value to log",required:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ln={action:"get",description:"Get a value from a source",category:"variable",primaryRole:"source",ast:{args:[["source","patient"]]},roles:[{role:"source",description:"The source to get from",required:true,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:false,expectedTypes:["reference"],svoPosition:2,sovPosition:1}]},Nn={action:"take",description:"Take content from a source element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{from:"source",for:"recipient"}},argSkipTokens:["from"],roles:[{role:"patient",description:"The class or element to take",required:true,expectedTypes:["selector"],svoPosition:1,sovPosition:2},{role:"source",description:"The element to take from (defaults to all current holders)",required:false,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1},{role:"recipient",description:"The element the class moves ONTO (`take .active from .tab for me`)",required:false,expectedTypes:["reference"],svoPosition:3,sovPosition:3,valueShape:"reference",markerOverride:{en:"for"}}]},Mn={action:"make",description:"Create a new element",category:"dom-content",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The element type or selector to create",required:true,expectedTypes:["literal","selector"],svoPosition:1,sovPosition:1}]},_n={action:"halt",description:"Halt/stop execution or event propagation",category:"control-flow",primaryRole:"patient",ast:{args:[],modifiers:{the:"patient"}},argSkipTokens:["the"],roles:[{role:"patient",description:"What to halt (event, default, bubbling, etc.)",required:false,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},In={action:"settle",description:"Wait for animations/transitions to settle",category:"async",primaryRole:"patient",ast:{args:[["destination","patient"]],isBlocking:true},roles:[{role:"patient",description:"The element to settle (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},jn={action:"throw",description:"Throw an error",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The error message or object to throw",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1}]},$n={action:"send",description:"Send an event to an element",category:"event",primaryRole:"event",ast:{args:["event"],modifiers:{to:"destination",detail:"patient"}},roles:[{role:"event",description:"The event to send",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"The target element (defaults to me)",required:false,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"}}]},Vn={action:"if",description:"Conditional execution",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,roles:[{role:"condition",description:"The condition to evaluate",required:true,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},qn={action:"unless",description:"Negated conditional execution (executes when condition is false)",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,roles:[{role:"condition",description:"The condition to evaluate (body executes when false)",required:true,expectedTypes:["expression","reference","selector"],svoPosition:1,sovPosition:1}]},Wn={action:"else",description:"Else branch of conditional",category:"control-flow",primaryRole:"patient",hasBody:true,roles:[]},Kn={action:"repeat",description:"Repeat a block of commands",category:"control-flow",primaryRole:"loopType",ast:{args:[["quantity","patient"]]},hasBody:true,roles:[{role:"loopType",description:"Loop variant: forever, times, for, while, until, until-event",required:true,expectedTypes:["literal"],svoPosition:0,sovPosition:0},{role:"quantity",description:"Number of times to repeat",required:false,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"event",description:"Event to wait for (terminates loop)",required:false,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:2},{role:"source",description:"Element to listen for event on",required:false,expectedTypes:["selector","reference"],svoPosition:3,sovPosition:3}],notes:'Can also use "repeat forever", "repeat until condition", or "repeat until event X from Y"'},Hn={action:"for",description:"Iterate over a collection",category:"control-flow",primaryRole:"patient",ast:{args:["patient"],modifiers:{in:"source"}},hasBody:true,roles:[{role:"patient",description:"The iteration variable",required:true,expectedTypes:["reference","expression"],svoPosition:1,sovPosition:2},{role:"source",description:"The collection to iterate over",required:true,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"}}]},Un={action:"while",description:"Loop while condition is true",category:"control-flow",primaryRole:"condition",ast:{args:["condition"]},hasBody:true,roles:[{role:"condition",description:"The condition to check",required:true,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},Gn={action:"continue",description:"Continue to next loop iteration",category:"control-flow",primaryRole:"patient",ast:{},roles:[]},xr={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"},Yn={action:"go",description:"Navigate to a URL",category:"navigation",primaryRole:"destination",roles:[{role:"destination",description:"The URL to navigate to",required:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to",es:"a",ar:"\u0625\u0644\u0649",fr:"\xE0",de:"zu",pt:"para",he:"\u05D0\u05DC",hi:"\u092A\u0930",id:"ke",it:"a",ru:"\u043D\u0430",sw:"kwa",uk:"\u043D\u0430"},renderOverride:{en:"",zh:"",vi:"",th:""},markerOptional:{en:true,zh:true,vi:true,th:true},markerVariants:{zh:["\u628A"]},markerLegacy:{es:["en","sobre","hacia"],ar:["\u0639\u0644\u0649","\u0641\u064A","\u0628"],fr:["sur","dans"],de:["auf","in"],pt:["em","a"],he:["\u05E2\u05DC","\u05D1","\u05DC","\u05D0\u05EA"],hi:["\u092E\u0947\u0902"],id:["pada","di"],it:["in","su"],ru:["\u0432","\u043A"],sw:["kwenye"],uk:["\u0432","\u0434\u043E"]}}],rolePrefixLiteralVariants:[{role:"destination",literal:xr,idSuffix:"url",priorityDelta:5,methodCarrier:"method"}]},Zn={action:"transition",description:"Transition an element with animation",category:"dom-visibility",primaryRole:"patient",ast:{args:["patient"],modifiers:{to:"goal",over:"duration",on:"destination"}},omitRoleVariants:["goal"],roles:[{role:"patient",description:"The property to transition (opacity, *background-color, etc.)",required:true,expectedTypes:["literal","expression","selector"],svoPosition:1,sovPosition:2,markerOverride:{en:"",ar:"",tl:"",sw:""}},{role:"goal",description:"The target value to transition to",required:true,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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:3,sovPosition:1},{role:"duration",description:"Transition duration (over 500ms, for 2 seconds)",required:false,expectedTypes:["literal"],svoPosition:4,sovPosition:4,markerOverride:{en:"over"}},{role:"style",description:"Easing function (ease-in, linear, etc.)",required:false,expectedTypes:["literal"],svoPosition:5,sovPosition:5}]},Jn={action:"clone",description:"Clone an element",category:"dom-content",primaryRole:"patient",ast:{args:[["source","patient"]],modifiers:{into:"destination"}},roles:[{role:"patient",description:"The element to clone",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:2},{role:"destination",description:"Where to put the clone",required:false,expectedTypes:["selector","reference"],svoPosition:2,sovPosition:1,markerOverride:{en:"into"}}]},Xn={action:"focus",description:"Focus an element",category:"dom-content",primaryRole:"patient",ast:{args:[["destination","patient"]]},roles:[{role:"patient",description:"The element to focus (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},Qn={action:"blur",description:"Remove focus from an element",category:"dom-content",primaryRole:"patient",ast:{args:[["destination","patient"]]},roles:[{role:"patient",description:"The element to blur (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ea={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ra={action:"open",description:"Open a dialog, details element, or popover",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{as:"style"}},roles:[{role:"patient",description:"The element to open (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:2},{role:"style",description:"Open-mode variant (modal / non-modal) for <dialog>",required:false,expectedTypes:["literal","expression"],svoPosition:2,sovPosition:1,markerOverride:{en:"as",ja:"\u3068\u3057\u3066"}}]},ta={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},ia={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},na={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:false,expectedTypes:["selector","reference","expression"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},aa={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:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:1,sovPosition:1}]},oa={action:"breakpoint",description:"Drop into the debugger",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:true},ua={action:"call",description:"Call a function",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The function to call",required:true,expectedTypes:["expression","reference"],markerOptional:{he:true,zh:true},svoPosition:1,sovPosition:1}]},sa={action:"return",description:"Return a value from a function",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},roles:[{role:"patient",description:"The value to return",required:false,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1}]},la={action:"js",description:"Execute raw JavaScript code",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},hasBody:true,roles:[{role:"patient",description:"The JavaScript code to execute",required:false,expectedTypes:["expression"],svoPosition:1,sovPosition:1}]},ca={action:"tell",description:"Execute commands in context of another element",category:"control-flow",primaryRole:"destination",ast:{args:[["destination","patient"]]},hasBody:true,roles:[{role:"destination",description:"The element to tell",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:"",he:"\u05D0\u05EA",zh:"\u628A"}}]},ma={action:"default",description:"Set a default value for a variable",category:"variable",primaryRole:"destination",ast:{args:["destination"],modifiers:{to:"patient"}},roles:[{role:"destination",description:"The variable to set default for",required:true,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:true,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"}}]},da={action:"init",description:"Initialization block that runs once",category:"control-flow",primaryRole:"patient",ast:{},hasBody:true,roles:[]},pa={action:"behavior",description:"Define a reusable behavior",category:"control-flow",primaryRole:"patient",ast:{args:["patient"]},hasBody:true,roles:[{role:"patient",description:"The behavior name (PascalCase identifier)",required:true,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1}]},fa={action:"install",description:"Install a behavior on an element",category:"control-flow",primaryRole:"patient",ast:{args:["patient"],modifiers:{on:"destination"}},roles:[{role:"patient",description:"The behavior name to install",required:true,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:2},{role:"destination",description:"Element to install on (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:1}]},ya={action:"measure",description:"Measure element dimensions (x, y, width, height, etc.)",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{of:["destination","source"]}},roles:[{role:"patient",description:"Property to measure (x, y, width, height, top, left, etc.)",required:false,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1},{role:"source",description:"Element to measure (defaults to me)",required:false,expectedTypes:["selector","reference"],default:{type:"reference",value:"me"},svoPosition:2,sovPosition:2,markerOverride:{en:"of"}}]},ha={en:"using view",es:"using view",pt:"using view",fr:"using view",de:"using view",it:"using view",ja:"using view",ko:"using view",zh:"using view",ar:"using view",he:"using view",hi:"using view",bn:"using view",tr:"using view",ru:"using view",uk:"using view",pl:"using view",id:"using view",vi:"using view",th:"using view",ms:"using view",tl:"using view",sw:"using view",qu:"using view"},Tr={role:"manner",description:"Run the swap inside a `document.startViewTransition()` (`using view transition`)",required:false,expectedTypes:["literal","expression"],valueShape:"keyword",markerOverride:ha},va={action:"swap",description:"Swap DOM content using various strategies (innerHTML, outerHTML, delete, etc.)",category:"dom-content",primaryRole:"destination",ast:{args:["method","destination","patient"],modifiers:{viewTransition:"manner"}},roles:[{role:"method",description:"The swap strategy (innerHTML, outerHTML, beforebegin, afterend, delete)",required:false,expectedTypes:["literal"],svoPosition:1,sovPosition:3,markerOverride:{en:""}},{role:"destination",description:"The element to swap content in/for",required:true,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",tl:""}},{role:"patient",description:"The content to swap in (optional for delete)",required:false,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",hi:"\u0938\u0947",bn:"\u09A6\u09BF\u09AF\u09BC\u09C7",tr:"ile",qu:"wan",ar:"\u0628\u0640",tl:"nang"}},{...Tr,svoPosition:4,sovPosition:4}]},Ea={action:"morph",description:"Morph an element into another using DOM diffing",category:"dom-content",primaryRole:"patient",ast:{args:[["source","destination"]],modifiers:{on:"patient",viewTransition:"manner"}},roles:[{role:"patient",description:"The element to morph",required:true,expectedTypes:["selector","reference"],svoPosition:1,sovPosition:1,markerOverride:{en:""}},{role:"destination",description:"The target content/element to morph into",required:true,expectedTypes:["literal","expression","selector","reference"],svoPosition:2,sovPosition:2,markerOverride:{en:"to"}},{...Tr,svoPosition:3,sovPosition:3}]},ga={action:"beep",description:"Debug output for expressions with type information",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The expression(s) to debug",required:false,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},Ca={action:"break",description:"Exit from the current loop",category:"control-flow",primaryRole:"patient",roles:[]},za={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:true,expectedTypes:["literal","selector","reference","expression"],svoPosition:1,sovPosition:1}]},ka={action:"exit",description:"Exit from the current event handler",category:"control-flow",primaryRole:"patient",roles:[],bareKeyword:true},wa={action:"pick",description:"Select item(s), character(s), a range, first/last/random N, or regex matches from a root",category:"variable",primaryRole:"patient",roles:[{role:"patient",description:"The range/count/index/regex argument to pick",required:true,expectedTypes:["literal","expression","reference"],svoPosition:1,sovPosition:1},{role:"source",description:'The root to pick from (with "of"/"from" keyword)',required:false,expectedTypes:["reference","expression"],svoPosition:2,sovPosition:2}]},ba={action:"scroll",description:"Scroll the viewport to a target element",category:"navigation",primaryRole:"destination",ast:{args:["destination"]},argSkipTokens:["of","the","top","bottom","middle","center","nearest","left","right","smoothly","instantly"],roles:[{role:"destination",description:"The element to scroll to",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:{en:"to"}}]},Aa={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"},Da={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:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:xr}]},Sa={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:true,expectedTypes:["literal","expression"],svoPosition:1,sovPosition:1,markerOverride:xr}]},Ba={action:"process",description:"Process hx-partial markup in HTML content",category:"dom-content",primaryRole:"patient",ast:{args:["patient"],modifiers:{viewTransition:"manner"}},roles:[{role:"patient",description:"The HTML content (string, element, or response) to process",required:true,expectedTypes:["literal","reference","expression"],svoPosition:1,sovPosition:1,markerOverride:Aa},{...Tr,svoPosition:2,sovPosition:2}]},xa={action:"render",description:"Render a template with optional variables",category:"dom-content",primaryRole:"patient",roles:[{role:"patient",description:"The template to render",required:true,expectedTypes:["selector","reference","expression"],svoPosition:1,sovPosition:2},{role:"style",description:"Variables to pass to the template (with keyword)",required:false,expectedTypes:["expression"],valueShape:"object",svoPosition:2,sovPosition:1}]},se={toggle:dn,add:pn,remove:fn,put:yn,set:hn,show:bn,hide:An,on:Dn,trigger:Sn,wait:Bn,fetch:xn,increment:Tn,decrement:Fn,append:Rn,prepend:On,log:Pn,get:Ln,take:Nn,make:Mn,halt:_n,settle:In,throw:jn,send:$n,if:Vn,unless:qn,else:Wn,repeat:Kn,for:Hn,while:Un,continue:Gn,go:Yn,scroll:ba,push:Da,replace:Sa,process:Ba,transition:Zn,clone:Jn,focus:Xn,blur:Qn,empty:ea,open:ra,close:ta,select:ia,clear:na,reset:aa,breakpoint:oa,call:ua,return:sa,js:la,tell:ca,default:ma,init:da,behavior:pa,install:fa,measure:ya,swap:va,morph:Ea,beep:ga,break:Ca,copy:za,exit:ka,pick:wa,render:xa,bind:vn,live:En,when:gn,eventsource:Cn,socket:zn,worker:kn,intercept:wn,compound:{action:"compound",description:"A compound node representing chained statements",primaryRole:"patient",category:"control-flow",hasBody:true,roles:[]}};function re(i){return se[i]}function Ta(){return Object.values(se).filter(i=>i.structuralOnly!==true&&(i.roles.length>0||i.bareKeyword===true))}typeof process<"u"&&process.env.LOKASCRIPT_SCHEMA_VALIDATION==="1"&&Promise.resolve().then(()=>(cn(),bt)).then(({validateAllSchemas:i,formatValidationResults:e})=>{let r=i(se);r.size>0&&(console.warn("[SCHEMA VALIDATION] Found issues in command schemas:"),console.warn(e(r)),console.warn(`
3
+ These warnings help identify potential schema design issues.`),console.warn("Fix them to improve type inference and avoid runtime bugs."));}).catch(i=>{console.debug("Schema validation skipped:",i);});var ze=new Map,pe=new Map,Ve=new Map,zr=null;function xt(i,e){let r={...i};for(let t of Object.keys(e)){let n=e[t],a=i[t];n!==void 0&&(typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof a=="object"&&a!==null&&!Array.isArray(a)?r[t]=xt(a,n):r[t]=n);}return r}function Fa(i,e){return xt(i,e)}function Fr(i){if(!i.extends)return i;let e=pe.get(i.extends);if(!e)return console.warn(`[Registry] Profile '${i.code}' extends '${i.extends}' but base is not registered. Make sure to import the base language before the variant.`),i;let r=Fr(e);return Fa(r,i)}function Tt(i,e,r){ze.set(i,e),pe.set(i,r),Ve.delete(i);}function Ft(i){zr=i;}var rt=new Map;function Te(i){return i.split("-")[0]}function Fe(i){return i.includes("-")}function Ra(i){let e=ze.get(i);if(!e&&Fe(i)){let r=Te(i);e=ze.get(r);}if(!e){let r=Array.from(ze.keys()).join(", ");throw new Error(`Language '${i}' is not registered. Registered languages: ${r||"none"}. Import the language module first: import '@lokascript/semantic/languages/${i}';`)}return e}function Oa(i){let e=pe.get(i);if(!e&&Fe(i)){let r=Te(i);e=pe.get(r);}if(!e){let r=Array.from(pe.keys()).join(", ");throw new Error(`Language profile '${i}' is not registered. Registered languages: ${r||"none"}. Import the language module first: import '@lokascript/semantic/languages/${i}';`)}return Fr(e)}function P(i){let e=pe.get(i);return !e&&Fe(i)&&(e=pe.get(Te(i))),e?Fr(e):void 0}function Pa(){return Array.from(ze.keys())}function Rt(i){if(ze.has(i)&&pe.has(i))return true;if(Fe(i)){let e=Te(i);return ze.has(e)&&pe.has(e)}return false}function La(i,e){return Ra(e).tokenize(i)}function de(i){let e=Ve.get(i);if(!e&&Fe(i)&&(e=Ve.get(Te(i))),e)return e;let r=rt.get(i);if(!r&&Fe(i)&&(r=rt.get(Te(i))),r)return Ve.set(i,r),r;if(!zr)throw new Error(`No patterns registered for language '${i}'. Either import the language module or set a pattern generator.`);let t=Oa(i),n=zr(t);return Ve.set(i,n),n}var Ot={possessive:{specialForms:{me:"my",it:"its",you:"your"}}};function ve(i){let e="complex";return i.startsWith("#")&&!i.includes(" ")?e="id":i.startsWith(".")&&!i.includes(" ")?e="class":i.startsWith("[")&&i.endsWith("]")?e="attribute":/^[a-z][a-z0-9]*$/i.test(i)&&(e="element"),{type:"selector",value:i,selectorKind:e}}function W(i,e){let r={type:"literal",value:i};return e!==void 0?{type:"literal",value:i,dataType:e}:r}function Se(i){return fr(i)}function ue(i){return {type:"reference",value:i}}function uo(i,e){return e?{...i,position:e}:i}function ge(i,e,r){return r?{type:"property-path",object:i,property:e,access:r}:{type:"property-path",object:i,property:e}}function ee(i,e,r){let t={kind:"command",action:i,roles:new Map(Object.entries(e))};return r!==void 0?{...t,metadata:r}:t}function $e(i,e,r,t,n,a){let o=new Map;o.set("event",i);let u={kind:"event-handler",action:"on",roles:o,body:e};return r!==void 0&&(u.eventModifiers=r),t!==void 0&&(u.metadata=t),n!==void 0&&n.length>0&&(u.parameterNames=n),u}function so(i,e,r,t,n){let a={kind:"behavior",action:"behavior",roles:new Map,name:i,parameters:e,eventHandlers:r};return t!==void 0&&t.length>0&&(a.initBlock=t),n!==void 0&&(a.metadata=n),a}function lo(i,e,r,t){let n={kind:"def",action:"def",roles:new Map,name:i,parameters:e,body:r};return t!==void 0&&(n.metadata=t),n}function kr(i,e,r,t,n){let a={kind:"feature",action:i,roles:n??new Map,body:e};return r!==void 0&&(a.name=r),t!==void 0&&(a.metadata=t),a}function qe(i,e="then",r){let t={kind:"compound",action:"compound",roles:new Map,statements:i,chainType:e};return r!==void 0&&(t.metadata=r),t}function co(i,e,r,t){let n=new Map;n.set("condition",i);let a={kind:"conditional",action:"if",roles:n,thenBranch:e};return r!==void 0&&(a.elseBranch=r),t!==void 0&&(a.metadata=t),a}function tr(i,e){return !e||e.length===0||e.includes(i)||e.includes("expression")?true:i==="property-path"?e.some(r=>["selector","reference","expression"].includes(r)):i==="expression"?e.some(r=>["selector","reference","expression"].includes(r)):false}function mo(i,e){let r=i.markerOverride?.[e.code],t=e.roleMarkers[i.role];if(r!==void 0){let n=po(i,e.code,r);return {primary:r,...n&&{alternatives:n},position:t?.position??"before",isOverride:true}}if(t&&t.primary){let n={primary:t.primary,position:t.position,isOverride:false};return t.alternatives&&(n.alternatives=t.alternatives),n}return null}function po(i,e,r){let t=i.markerLegacy?.[e];if(!t?.length)return;let n=[...new Set(t)].filter(a=>a&&a!==r);return n.length?n:void 0}function fe(i,e,r){let t=i.markerLegacy?.[e]??[],n=i.methodCarrier?[]:i.markerVariants?.[e]??[],a=[...new Set([...t,...n])].filter(o=>o&&o!==r);return a.length?a:void 0}var Pt=new Set(["destination","source","patient","object","event","eventmarker","manner","instrument"]);function ce(i,e){let r=i.possessive?.keywords?.[e];if(r)return r;let t=i.possessive?.specialForms;if(t){for(let[n,a]of Object.entries(t))if(a===e)return n}}function yr(i){return Ot.possessive?.specialForms?.[i]??`${i}'s`}var Rr={ar:{\u0642\u064A\u0645\u0629:"value"},bn:{\u0985\u0995\u09CD\u09B7\u09AE:"disabled","\u099A\u09C7\u0995 \u0995\u09B0\u09BE":"checked",\u09A6\u09C8\u09B0\u09CD\u0998\u09CD\u09AF:"length",\u09AE\u09BE\u09A8:"value"},de:{wert:"value"},es:{valor:"value"},fr:{valeur:"value"},hi:{\u0905\u0915\u094D\u0937\u092E:"disabled",\u091A\u0947\u0915:"checked",\u091B\u093F\u092A\u093E:"hidden",\u092E\u093E\u0928:"value"},id:{nilai:"value"},it:{valore:"value"},ja:{\u5024:"value"},ko:{\uAC12:"value"},ms:{dilumpuhkan:"disabled",ditanda:"checked",nilai:"value",panjang:"length"},pl:{warto\u015B\u0107:"value"},pt:{valor:"value"},qu:{chanin:"value"},ru:{\u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435:"value",\u043E\u0442\u043A\u043B\u044E\u0447\u0435\u043D\u043E:"disabled",\u043E\u0442\u043C\u0435\u0447\u0435\u043D\u043E:"checked",\u0441\u043A\u0440\u044B\u0442\u043E:"hidden"},sw:{thamani:"value"},th:{\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27:"length",\u0E04\u0E48\u0E32:"value",\u0E1B\u0E34\u0E14\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19:"disabled",\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E41\u0E25\u0E49\u0E27:"checked"},tl:{haba:"length",halaga:"value",hindi_pinagana:"disabled",naka_tsek:"checked"},tr:{de\u011Fer:"value"},uk:{\u0432\u0438\u043C\u043A\u043D\u0435\u043D\u043E:"disabled",\u0437\u043D\u0430\u0447\u0435\u043D\u043D\u044F:"value",\u043F\u043E\u0437\u043D\u0430\u0447\u0435\u043D\u043E:"checked",\u043F\u0440\u0438\u0445\u043E\u0432\u0430\u043D\u043E:"hidden"},vi:{\u1EA9n:"hidden","\u0111\u01B0\u1EE3c ch\u1ECDn":"checked","gi\xE1 tr\u1ECB":"value","v\xF4 hi\u1EC7u":"disabled"},zh:{\u503C:"value"}},fo={ar:{\u0643\u0640:"as"},bn:{\u09B9\u09BF\u09B8\u09BE\u09AC\u09C7:"as"},de:{als:"as"},es:{como:"as"},fr:{comme:"as"},hi:{\u0915\u0947_\u0930\u0942\u092A_\u092E\u0947\u0902:"as"},id:{sebagai:"as"},it:{come:"as"},ja:{\u3068\u3057\u3066:"as"},ko:{\uB85C:"as"},ms:{sebagai:"as"},pl:{jako:"as"},pt:{como:"as"},qu:{hina:"as"},ru:{\u043A\u0430\u043A:"as"},sw:{kuwa:"as"},tl:{bilang:"as"},tr:{olarak:"as"},uk:{\u044F\u043A:"as"},vi:{nh\u01B0:"as"},zh:{\u4F5C\u4E3A:"as"}},Lt={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"]),ar:new Set(["\u0644\u0640"]),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","n\u0131n","nun","n\xFCn","in","\u0131n","un","\xFCn"])};function wr(i,e){let r=e.value.toLowerCase(),t=(e.normalized??"").toLowerCase();if(r==="of"||r==="ng"||t==="of"||t==="source")return true;let n=i?.code?Lt[i.code]:void 0;return !!n&&n.has(r)}var ho={destination:"in",source:"from"},vo={ar:new Set(["\u0639\u0646\u062F","\u0641\u064A"]),bn:new Set(["\u098F","\u09A4\u09C7"]),de:new Set(["bei"]),es:new Set(["en"]),fr:new Set(["dans","en","\xE0"]),he:new Set(["\u05DC\u05EA\u05D5\u05DA"]),hi:new Set(["\u092A\u0930","\u092E\u0947\u0902"]),id:new Set(["dalam","di","ke_dalam"]),it:new Set(["a"]),ja:new Set(["\u3067","\u306E\u4E2D","\u3078"]),ko:new Set(["\uC548\uC5D0","\uC5D0","\uC73C\uB85C"]),ms:new Set(["dalam","di","ke_dalam"]),pl:new Set(["do","przy","w"]),pt:new Set(["dentro","em"]),qu:new Set(["pi","ukupi"]),ru:new Set(["\u0432","\u0443"]),sw:new Set(["katika","ndani"]),th:new Set(["\u0E17\u0E35\u0E48","\u0E43\u0E19"]),tl:new Set(["papasok_sa","sa","sa_loob"]),tr:new Set(["de","i\xE7inde","i\xE7ine"]),uk:new Set(["\u0432","\u0443"]),vi:new Set(["trong","t\u1EA1i","v\xE0o"]),zh:new Set(["\u5728","\u8FDB\u5165"])},Eo=new Set(["in","into","at","within","inside"]);function go(i,e){let r=e.value.toLowerCase();if((i?.code?vo[i.code]:void 0)?.has(r))return "in";let n=e.normalized??e.value,a=n.toLowerCase();return Eo.has(a)?"in":ho[a]??n}var hr=new Set(["first","last","next","previous","random","closest"]),Co={bn:{\u09B6\u09C7\u09B7:"last"}},Or=new Set(Object.keys(se).map(i=>i.toLowerCase()));function Nt(i,e,r,t){let n=i[e];if(!n)return null;let a=(n.normalized??n.value).toLowerCase(),o=i[e+1],u=r?.code&&o?.kind==="selector"&&o.value.startsWith("<")?Co[r.code]?.[n.value.toLowerCase()]:void 0;if(!hr.has(a)&&!hr.has(n.value.toLowerCase())&&u===void 0)return null;let s=[{text:u??n.normalized??n.value,token:n}],l=e+1,c=i[l];if(!c||c.kind!=="selector")return null;s.push({text:c.value,token:c}),l++;let m=0;for(;m++<8;){let f=i[l];if(f&&f.kind==="selector"&&f.value.startsWith("."))s.push({text:f.value,token:f}),l++;else break}let d=i[l],p=i[l+1];return d&&p&&p.kind==="selector"&&(d.kind==="keyword"||d.kind==="particle"||d.kind==="identifier")&&!hr.has((d.normalized??d.value).toLowerCase())&&!Or.has((d.normalized??d.value).toLowerCase())&&!(t?.(d)===true&&t(i[l+2])!==true)&&(s.push({text:go(r,d),token:d}),s.push({text:p.value,token:p}),l+=2),{parts:s,consumed:l-e}}function zo(i,e){let r=fo[i];return r?r[e.toLowerCase()]??e:e}function me(i,e){let r=Rr[i];return r?r[e.toLowerCase()]??e:e}function ko(i,e){return Rr[i]?.[e.toLowerCase()]!==void 0}function wo(i,e){let r=[e.value,e.normalized].filter(Boolean);for(let t of r){let n=ce(i,t)??ce(i,t.toLowerCase());if(n)return n}}function Mt(i){return i.kind==="literal"||i.kind==="operator"||i.kind==="punctuation"?false:!/^[$:@#.*^(){}[\]]/.test(i.value)}function bo(i,e){let r=i?.references;if(!r)return false;let t=Object.values(r).filter(a=>typeof a=="string").map(a=>a.toLowerCase());return [e.value,e.normalized].filter(Boolean).some(a=>t.includes(a.toLowerCase()))}function it(i,e){return Mt(i)?me(e,i.value)!==i.value?true:i.kind==="identifier":false}var Ao={ar:{\u0647\u0648:{beforePredicate:"is"}},hi:{\u0939\u0948:{beforePredicate:"is"},\u0928\u0939\u0940\u0902:{beforeBareIdentifier:"no"}},th:{\u0E40\u0E1B\u0E47\u0E19:{beforeTypeName:"as",beforePredicate:"is"}},ja:{\u7A7A:{afterCopula:"empty"}},zh:{\u6CA1\u6709:{beforeBareIdentifier:"no"}},tl:{walang:{beforeBareIdentifier:"no"},may:{afterSubject:"exists"}},bn:{\u0986\u099B\u09C7:{afterSubject:"exists"}},tr:{var:{afterSubject:"exists"}}},Do=new Set(["empty","null","undefined","true","false"]),_t=new Set(["Number","Int","Float","String","Date","Array","Object","JSON","json","FormData","HTML","Fragment","Values"]);function So(i,e,r,t){let n=Ao[i],a=n?.[e.value]??n?.[e.value.toLowerCase()];if(a){if(a.beforeTypeName&&t?.kind==="identifier"&&_t.has(t.value))return a.beforeTypeName;if(a.beforePredicate&&t&&(t.kind==="literal"||t.kind==="keyword"&&Do.has((t.normalized??"").toLowerCase())))return a.beforePredicate;if(a.beforeBareIdentifier&&t?.kind==="identifier"&&/^[A-Za-z_]\w*$/.test(t.value))return a.beforeBareIdentifier;if(a.afterSubject&&(r?.kind==="selector"||r?.kind==="reference"))return a.afterSubject;if(a.afterCopula&&r?.kind==="keyword"&&(r.normalized??"").toLowerCase()==="is")return a.afterCopula}}function xe(i,e){let r=e?.code??"en",t="",n,a=(u,s)=>{if(n===void 0){t=u,n=s;return}let c=n.position?.end!==void 0&&s.position?.start!==void 0&&n.position.end===s.position.start&&(u.startsWith(".")||u.startsWith("!"));t+=(c?"":" ")+u,n=s;},o=u=>u.kind==="keyword"?u.normalized??u.value:u.value;for(let u=0;u<i.length;u++){let s=i[u],l=e?wo(e,s):void 0,c=i[u+1];if(s.value==="'"&&n!==void 0&&c?.value==="s"&&s.position?.end!==void 0&&c.position?.start===s.position.end){t+="'s",n=c;let v=i[u+2];v&&me(r,v.value)!==v.value?(a(me(r,v.value),v),u+=2):u+=1;continue}if(l!==void 0&&c){let v=e?.possessive?.connectors,E=!!v?.length&&v.some(z=>{let A=z.toLowerCase();return A===c.value.toLowerCase()||A===(c.normalized??"").toLowerCase()}),y=E?u+2:u+1,h=i[y];if(h&&it(h,r)){a(yr(l),s),a(me(r,h.value),h),u=y;continue}if(E&&h&&/^\.[a-zA-Z_]\w*$/.test(h.value)&&c.position?.end!==void 0&&h.position?.start!==void 0&&c.position.end===h.position.start){a(yr(l),s),a(me(r,h.value.slice(1)),h),u=y;continue}if(!E&&/^\.[a-zA-Z_]\w*$/.test(c.value)&&s.position?.end!==void 0&&c.position?.start!==void 0&&s.position.end===c.position.start&&!bo(e,s)){a(yr(l),s),a(me(r,c.value.slice(1)),c),u+=1;continue}}let m=i[u+2];if(c&&m&&m.kind==="selector"&&wr(e,c)&&Mt(s)){a(me(r,s.value),s),a("of",c),a(m.value,m),u+=2;continue}if(s.kind==="selector"&&c&&m&&wr(e,c)&&it(m,r)&&me(r,m.value)!==m.value){a(me(r,m.value),m),a("of",c),a(s.value,s),u+=2;continue}let d=Nt(i,u,e);if(d){for(let v of d.parts)a(v.text,v.token);u+=d.consumed-1;continue}let p=So(r,s,i[u-1],c);if(p!==void 0){a(p,s);continue}let f=zo(r,s.value);if(f!==s.value){a(f,s);continue}a(o(s),s);}return t.trim()}var It=[{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:true,objMarker:"i",at:"de",end:"son",of:"nin"},{lang:"ja",verb:"\u7F6E\u304F",sov:true,objMarker:"\u3092",at:"\u3067",end:"\u7D42\u308F\u308A",of:"\u306E"},{lang:"ko",verb:"\uB123\uB2E4",sov:true,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:true,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:true,objMarker:"\u0995\u09C7",at:"\u098F",end:"\u09B6\u09C7\u09B7",of:"\u09B0"},{lang:"qu",verb:"churay",sov:true,objMarker:"ta",at:"pi",end:"tukuy",of:"pa"}];function nt(i,e,r,t){let n=It.find(o=>o.lang===i);if(!n)return false;let a=(o,u)=>(o??"").toLowerCase()===u.toLowerCase();return a(e,n.end)&&a(r,n.at)&&a(t,n.of)}function Bo(i,e){let r=It.find(n=>n.lang===i);if(!r)return false;let t=e.toLowerCase();return t===r.at.toLowerCase()||t===r.of.toLowerCase()||t===r.end.toLowerCase()}var jt={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"])};function xo(i){return jt[i]}function at(i,e){return jt[e]?.has(i.toLowerCase())??false}var $t=96,To=/^[A-Za-z_][\w-]*$/,Fo=/^[A-Za-z_][\w-]*:[^\s'"`/:][^\s]*$/;function Vt(i,e){let r=i.peek(e);return !!r&&r.kind==="identifier"&&Fo.test(r.value)}function qt(i,e){let r=i.peek(e);if(!r||r.kind!=="identifier"&&r.kind!=="keyword"||!To.test(r.value))return false;let t=i.peek(e+1),n=i.peek(e+2);return !!t&&t.value===":"&&!!n}function ot(i,e=0){return Vt(i,e)||qt(i,e)}function Ro(i){let e=i.peek();if(!e||e.value!=="{"&&e.value!=="(")return null;let r="",t=-1,n=0,a=0;for(;!i.isAtEnd()&&a++<$t;){let o=i.advance();if(!o)break;if(t>=0&&o.position.start>t&&(r+=" ".repeat(o.position.start-t)),r+=o.value,t=o.position.end,o.value==="{"||o.value==="(")n++;else if((o.value==="}"||o.value===")")&&(n--,n===0))return r}return null}function ut(i){let e=i.peek();return e?e.value==="{"||e.value==="("?Ro(i):e.value===","||e.value===":"?null:(i.advance(),e.value):null}function We(i,e){let r=i.mark(),t=[];if(e!==void 0){let a=i.peek();if(!a||a.value!==":"||!i.peek(1))return null;i.advance();let o=ut(i);if(o===null)return i.reset(r),null;t.push(`${e}:${o}`);}else if(!ot(i))return null;let n=0;for(;n++<$t;){let a=i.peek();if(!a)break;if(a.value===","){if(t.length===0||!ot(i,1))break;i.advance();continue}if(Vt(i,0)){t.push(i.advance().value);continue}if(!qt(i,0))break;let o=i.advance().value;i.advance();let u=ut(i);if(u===null)return i.reset(r),null;t.push(`${o}:${u}`);}return t.length===0?(i.reset(r),null):`{${t.join(", ")}}`}var ir=.8,Oo=.6,Po=.15,Lo=.5,st=.15,lt=.1,ct=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"]),No={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"]},Mo=class{calculate(i){return this.calculateWithBreakdown(i).final}calculateWithBreakdown(i){let e=this.scoreRoleCoverage(i),r=this.scoreStemPenalty(i),t=this.scoreLanguageBoost(i),n=this.scoreLanguageAdjustment(i),a=e;return a=Math.max(Lo,a+r),a=Math.min(1,a+t),a=Math.max(0,Math.min(1,a+n)),{roleCoverage:e,stemPenalty:r,languageBoost:t,languageAdjustment:n,final:a}}scoreRoleCoverage(i){let{pattern:e,captured:r}=i,t=0,n=0,a=l=>e.extraction?.[l]?.default!==void 0,o=e.command==="on"?e.extraction?.action?.value:void 0,u=se[o??e.command]?.roles,s=l=>u?.find(c=>c.role===l)?.valueShape!==void 0;for(let l of e.template.tokens)if(l.type==="role")r.has(l.role)?(n+=1,t+=1):s(l.role)||(n+=1);else if(l.type==="group")for(let c of l.tokens)c.type==="role"&&(r.has(c.role)?(n+=ir,t+=ir):s(c.role)||(n+=ir,a(c.role)&&(t+=ir*Oo)));return n>0?t/n:1}scoreStemPenalty(i){let{stemMatchCount:e,totalKeywordMatches:r}=i;return e<=0||r<=0?0:-(e/r)*Po}scoreLanguageBoost(i){let{pattern:e}=i;if(e.language!=="ar")return 0;let r=e.template.tokens[0];return !r||r.type!=="literal"?0:ct.has(r.value)||r.alternatives?.some(t=>ct.has(t))?st:0}scoreLanguageAdjustment(i){let{pattern:e,captured:r}=i;if(e.language!=="ar")return 0;let t=0;for(let[n,a]of r.entries()){let o=No[n];if(!o||o.length===0)continue;let u="metadata"in a?a.metadata:void 0;u&&typeof u.prepositionValue=="string"&&(o.includes(u.prepositionValue)?t+=.1:t-=.1);}return Math.max(-lt,Math.min(lt,t))}},_o=new Mo,Io=new Set(Object.values(se).filter(i=>i.bareKeyword===true).map(i=>i.action));function jo(i){return i.startsWith("*")||i.startsWith("@")}var X=class M{constructor(e){this.matchCache=new Map,this.roleStarts=new Map,this.stemMatchCount=0,this.totalKeywordMatches=0,this.confidenceModel=e??_o;}matchPattern(e,r){let t=e.mark(),n=new Map;if(this.currentProfile=P(r.language),this.currentPatternCommand=r.command,this.stemMatchCount=0,this.totalKeywordMatches=0,this.roleStarts=new Map,!this.matchTokenSequence(e,r.template.tokens,n))return e.reset(t),null;let o=this.confidenceModel.calculate({pattern:r,captured:n,stemMatchCount:this.stemMatchCount,totalKeywordMatches:this.totalKeywordMatches});return this.applyExtractionRules(r,n),{pattern:r,captured:n,consumedTokens:e.position()-t.position,confidence:o,roleStarts:this.roleStarts}}matchBest(e,r){this.matchCache.clear();let t=[],n=e.position();for(let o of r){let u=e.mark(),s=`${n}:${o.id}`,l;this.matchCache.has(s)?l=this.matchCache.get(s):(l=this.matchPattern(e,o),this.matchCache.set(s,l)),l&&t.push(l),e.reset(u);}if(t.length===0)return null;t.sort((o,u)=>{let s=u.pattern.priority-o.pattern.priority;return s!==0?s:u.confidence-o.confidence});let a=t[0];return this.matchPattern(e,a.pattern),a}matchTokenSequence(e,r,t,n){let a=r[0],o=a?.type==="literal"&&(a.value==="and"||a.value==="then"||a.alternatives?.includes("and")||a.alternatives?.includes("then"));if(this.currentProfile?.code==="ar"&&!o)for(;e.peek()?.kind==="conjunction";)e.advance();let u=0;for(let s=0;s<r.length;s++){let l=r[s];if(u>0&&l.type==="literal"&&this.tryConsumeEventSourceClause(e,t,l),this.shouldTrySkippingVerbSlot(l,e,r[s+1]??n)){let m=e.mark(),d=new Map(t);if(this.matchTokenSequence(e,r.slice(s+1),d,n)&&this.atClauseEnd(e)){t.clear();for(let[p,f]of d)t.set(p,f);return true}e.reset(m);}let c=this.matchPatternToken(e,l,t,r[s+1]??n);if(u=l.type==="role"&&l.role==="event"?2:Math.max(0,u-1),!c){if(this.isOptional(l))continue;return false}}return true}tryConsumeEventSourceClause(e,r,t){if(r.has("source"))return;let n=e.peek(),a=e.peek(1);if(!n||!a||this.patternTokenWouldMatch(t,n))return;let o=this.currentProfile?.roleMarkers?.source,u=l=>{if(l.kind!=="particle"&&l.kind!=="keyword")return false;if((l.normalized??"").toLowerCase()==="source")return true;if(!o)return false;let c=l.value.toLowerCase();return o.primary?.toLowerCase()===c?true:!!o.alternatives?.some(m=>m.toLowerCase()===c)},s=o?.position;if(s!=="after"&&u(n)&&a.kind==="selector"){e.advance();let l=this.tokenToSemanticValue(e.advance());l&&r.set("source",l);return}if(s==="after"&&n.kind==="selector"&&u(a)){let l=this.tokenToSemanticValue(n);e.advance(),e.advance(),l&&r.set("source",l);}}matchPatternToken(e,r,t,n){switch(r.type){case "literal":return this.matchLiteralToken(e,r);case "role":{let a=e.position(),o=this.matchRoleToken(e,r,t,n);return o&&t.has(r.role)&&this.roleStarts.set(r.role,a),o}case "group":return this.matchGroupToken(e,r,t,n);default:return false}}matchLiteralToken(e,r){let t=e.peek();if(!t)return false;let n=this.getMatchType(t,r.value);if(n!=="none")return this.totalKeywordMatches++,n==="stem"&&this.stemMatchCount++,e.advance(),true;if(r.alternatives)for(let a of r.alternatives){let o=this.getMatchType(t,a);if(o!=="none")return this.totalKeywordMatches++,o==="stem"&&this.stemMatchCount++,e.advance(),true}for(let a of [r.value,...r.alternatives??[]])for(let o of ["-","_"])if(a.includes(o)&&this.tryMatchShatteredCompound(e,a,o))return this.totalKeywordMatches++,true;return false}tryFoldHyphenActionKeyword(e){let r=this.currentProfile;if(!r)return null;let t=e.mark(),n=[];for(;;){let o=e.peek();if(!o||o.kind!=="identifier"&&o.kind!=="keyword")break;n.push(o.value),e.advance();let u=e.peek();if(!u||u.value!=="-")break;e.advance(),n.push("-");}if(n.length<3||n[n.length-1]==="-")return e.reset(t),null;let a=n.join("").toLowerCase();for(let[o,u]of Object.entries(r.keywords))if(u.primary.toLowerCase()===a||u.alternatives?.some(s=>s.toLowerCase()===a))return W(o);return e.reset(t),null}tryMatchShatteredCompound(e,r,t){let n=r.split(t);if(n.length<2||n.some(o=>o.length===0))return false;let a=e.mark();for(let o=0;o<n.length;o++){if(o>0){let s=e.peek();if(!s||s.value!==t)return e.reset(a),false;e.advance();}let u=e.peek();if(!u||u.kind!=="identifier"&&u.kind!=="keyword"&&u.kind!=="particle"||u.value.toLowerCase()!==n[o].toLowerCase())return e.reset(a),false;e.advance();}return true}matchRoleToken(e,r,t,n){let a=e.position(),o=t.get(r.role);return this.matchRoleTokenCore(e,r,t,n)?(this.absorbTrailingConversion(e,r,t,n,a),this.absorbTrailingConditionOperand(e,r,t,n,a),this.stampCaptureSpan(e,r.role,t,a,o),true):false}stampCaptureSpan(e,r,t,n,a){let o=t.get(r);if(!o||o===a||o.position||e.position()<=n)return;let u=e.tokens[n],s=e.tokens[e.position()-1];!u||!s||t.set(r,uo(o,{start:u.position.start,end:s.position.end}));}absorbTrailingConditionOperand(e,r,t,n,a){if(r.role!=="condition"||!t.has("condition")||e.position()<=a||n!==void 0||this.currentPatternCommand!=="on")return;let o=e.peek();if(!o)return;let u=M.CONDITION_OPERATOR_WORDS;if(!u.has((o.normalized??"").toLowerCase())&&!u.has(o.value.toLowerCase())||this.patternTokenWouldMatch(n,o))return;e.advance();let s=e.peek();s&&(s.kind==="selector"||s.kind==="identifier"||s.kind==="literal")&&!Or.has((s.normalized??s.value).toLowerCase())&&e.advance();let l=xe(e.tokens.slice(a,e.position()),this.currentProfile);t.set("condition",{type:"expression",raw:l,value:l});}conversionRunLength(e){let r=e.peek();if(!r||(r.normalized??r.value).toLowerCase()!=="as"&&r.value.toLowerCase()!=="as")return 0;let n=e.peek(1);return !n||!_t.has(n.value)?0:2}absorbTrailingConversion(e,r,t,n,a){if(r.role==="event"||r.role==="action"||!t.has(r.role)||e.position()<=a||this.conversionRunLength(e)!==2||this.patternTokenWouldMatch(n,e.peek()))return;e.advance(),e.advance();let o=xe(e.tokens.slice(a,e.position()),this.currentProfile);t.set(r.role,{type:"expression",raw:o,value:o});}matchRoleTokenCore(e,r,t,n){this.skipNoiseWords(e);let a=e.peek();if(!a)return r.optional||false;if(r.role==="action"&&this.currentProfile&&e.peek(1)?.value==="-"){let y=this.tryFoldHyphenActionKeyword(e);if(y)return t.set(r.role,y),true}if(r.role==="event"&&this.currentPatternCommand==="on"){if(!M.tokenLooksLikeEvent(a))return r.optional||false;let y=(a.normalized??a.value).toLowerCase();if(M.POSITIONAL_OR_SCOPE_KEYWORDS.has(y)||this.currentProfile&&(ce(this.currentProfile,a.value)??ce(this.currentProfile,y))!==void 0||a.value.includes("?."))return r.optional||false}if(r.role==="event"){let y=(a.normalized??a.value).toLowerCase();if(M.STRUCTURAL_NEVER_EVENT.has(y))return r.optional||false}if(a.kind==="keyword"){let y=(a.normalized??a.value).toLowerCase();if(y==="then"||y==="end"&&e.peek(1)?.kind!=="selector"||at(a.value,this.currentProfile?.code??"")||(r.role==="quantity"||r.role==="event"&&this.currentPatternCommand==="repeat")&&(a.normalized??a.value).toLowerCase()in se)return r.optional||false}if(r.role==="duration"){let y=(a.normalized??a.value).toLowerCase();if(M.POSITIONAL_OR_SCOPE_KEYWORDS.has(y))return r.optional||false}if(r.optional&&r.role!=="event"&&r.role!=="action"&&r.valueShape!=="keyword"&&a.kind==="keyword"&&(a.normalized??a.value).toLowerCase()in se&&(n===void 0||this.patternTokenWouldMatch(n,a)))return true;let o=this.tryMatchPositionalExpression(e,n);if(o)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(o.type,r.expectedTypes)?r.optional||false:(t.set(r.role,o),true);let u=this.tryMatchCaretScopeExpression(e);if(u)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(u.type,r.expectedTypes)?r.optional||false:(t.set(r.role,u),true);if(r.role!=="event"&&(!r.expectedTypes||r.expectedTypes.includes("expression"))){let y=this.tryMatchBeepPrefixExpression(e);if(y)return t.set(r.role,y),true;let h=this.tryMatchHyphenatedWord(e);if(h)return t.set(r.role,h),true;let z=this.tryMatchOperatorRunExpression(e);if(z)return t.set(r.role,z),true}if(this.currentPatternCommand==="pick"&&r.role==="patient"&&(!r.expectedTypes||r.expectedTypes.includes("expression"))){let y=this.tryMatchPickRangeExpression(e);if(y)return t.set(r.role,y),true}if(r.expectedTypes?.includes("property-path")){let y=this.tryMatchOfPossessiveExpression(e);if(y)return t.set(r.role,y),true;let h=this.tryMatchPostNominalPossessiveExpression(e);if(h)return t.set(r.role,h),true}let s=this.tryMatchPossessiveExpression(e);if(s)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(s.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,s),true);let l=this.tryMatchMethodCallExpression(e);if(l)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(l.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,l),true);let m=r.role==="event"&&this.currentPatternCommand==="on"||M.DECLARATION_COMMANDS.has(this.currentPatternCommand??"")?null:this.tryMatchBareCallExpression(e);if(m)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(m.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,m),true);let d=this.tryMatchPossessiveSelectorExpression(e);if(d)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(d.type,r.expectedTypes)?r.optional||false:(t.set(r.role,d),true);let p=r.role!=="condition",f=this.tryMatchPropertyAccessExpression(e,p);if(f)return r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(f.type)&&!r.expectedTypes.includes("expression")?r.optional||false:(t.set(r.role,f),true);let v=this.tryMatchSelectorPropertyExpression(e);if(v)return r.expectedTypes&&r.expectedTypes.length>0&&!tr(v.type,r.expectedTypes)?r.optional||false:(t.set(r.role,v),true);if(a.kind==="identifier"&&a.value==="{"){let y=r.expectedTypes,z=y?.length===1&&y[0]==="expression"?this.tryMatchBraceRunExpression(e):!y?.length||y.includes("literal")?this.tryMatchBraceRunLiteral(e):null;if(z)return t.set(r.role,z),true}if(r.role==="style"&&r.expectedTypes?.length===1&&r.expectedTypes[0]==="expression"){let y=We(e);if(y)return t.set(r.role,{type:"expression",raw:y}),true}let E=this.tokenToSemanticValue(a);if(!E)return r.optional||false;if(r.expectedTypes&&r.expectedTypes.length>0&&!r.expectedTypes.includes(E.type)){let y=E.type==="selector"&&String(E.value).startsWith("@"),h=r.expectedTypes.some(z=>z==="expression"||z==="reference");if(!(y&&h))return r.optional||false}if(r.valueShape==="keyword"&&E.type==="expression"?t.set(r.role,W(String(E.raw??""))):t.set(r.role,E),e.advance(),r.role==="event"){let y=e.peek();y&&y.kind==="selector"&&y.value.startsWith("[")&&"value"in E&&(t.set(r.role,W(`${String(E.value)}${y.value}`)),e.advance());let h=e.peek();if(h&&(h.kind==="particle"||h.kind==="keyword")&&(h.normalized??"").toLowerCase()==="source"&&!this.patternTokenWouldMatch(n,h)){let z=e.peek(1);if(z&&(z.kind==="selector"||z.kind==="identifier")){e.advance();let A=this.tokenToSemanticValue(e.advance());A&&!t.has("source")&&t.set("source",A);}}}return true}shouldTrySkippingVerbSlot(e,r,t){let n=e.type==="group"&&e.optional?e.tokens.every(u=>u.type==="role")?e.tokens[0]:void 0:e;if(!n||n.type!=="role"||!n.optional||n.role==="event"||n.role==="action"||n.valueShape==="keyword")return false;let a=r.peek();if(!a||a.kind!=="keyword"||t===void 0)return false;let o=this.patternTokenWouldMatch(t,a);return (a.normalized??a.value).toLowerCase()in se?!o:o}atClauseEnd(e){let r=e.peek();if(!r||r.kind==="conjunction")return true;if(r.kind!=="keyword")return false;let t=(r.normalized??r.value).toLowerCase();return t==="then"||t==="end"?true:at(r.value,this.currentProfile?.code??"")}patternTokenWouldMatch(e,r){return e?e.type==="literal"?this.getMatchType(r,e.value)!=="none"?true:!!e.alternatives?.some(t=>this.getMatchType(r,t)!=="none"):e.type==="group"?this.patternTokenWouldMatch(e.tokens?.[0],r):false:false}tryMatchPositionalExpression(e,r){let t=Nt(e.tokens,e.position(),this.currentProfile,n=>n===void 0?false:this.patternTokenWouldMatch(r,n));if(!t)return null;for(let n=0;n<t.consumed;n++)e.advance();return {type:"expression",raw:t.parts.map(n=>n.text).join(" ")}}tryMatchCaretScopeExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"||!r.value.startsWith("^"))return null;let t=e.peek(1),n=e.peek(2),a=(t?.normalized??"").toLowerCase(),o=!!t&&(t.value.toLowerCase()==="on"||a==="destination"||a==="on");return !t||!n||n.kind!=="selector"||!o?null:(e.advance(),e.advance(),e.advance(),{type:"expression",raw:`${r.value} on ${n.value}`})}isOfPossessiveMarker(e){return wr(this.currentProfile,e)}static isBareWordToken(e){return !!e&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(e.value)}static tokensAdjacent(e,r){return e?.position?.end!==void 0&&r?.position?.start!==void 0&&e.position.end===r.position.start}tryMatchBeepPrefixExpression(e){let r=e.peek(),t=e.peek(1);if(!r||!t||t.value!=="!"||(r.normalized??r.value).toLowerCase()!=="beep"||!(r.position?.end!==void 0&&t.position?.start!==void 0&&r.position.end===t.position.start))return null;let a=e.mark(),o=e.position();if(e.advance(),e.advance(),!this.tryConsumeRunOperand(e))return e.reset(a),null;for(;;){let s=e.peek();if(!s||!M.RUN_OPERATORS.has(s.value))break;let l=e.mark();if(e.advance(),!this.tryConsumeRunOperand(e)){e.reset(l);break}}let u=xe(e.tokens.slice(o,e.position()),this.currentProfile);return {type:"expression",raw:u,value:u}}tryMatchHyphenatedWord(e){let r=e.peek();if(!M.isBareWordToken(r))return null;let t=1,n=[r.value];for(;;){let a=e.peek(t),o=e.peek(t+1);if(!a||a.value!=="-"||!M.isBareWordToken(o)||!M.tokensAdjacent(e.peek(t-1),a)||!M.tokensAdjacent(a,o))break;n.push(o.value),t+=2;}if(n.length<2)return null;for(let a=0;a<t;a++)e.advance();return W(n.join("-"),"string")}tryMatchOperatorRunExpression(e){let r=e.mark(),t=e.position();if(!this.tryConsumeRunOperand(e))return e.reset(r),null;let n=1;for(;;){let o=e.peek();if(!o||!M.RUN_OPERATORS.has(o.value))break;let u=e.mark();if(e.advance(),!this.tryConsumeRunOperand(e)){e.reset(u);break}n++;}if(n<2)return e.reset(r),null;let a=xe(e.tokens.slice(t,e.position()),this.currentProfile);return {type:"expression",raw:a,value:a}}static rangeSeparatorFor(e){let[r]=M.PICK_RANGE_SEPARATORS_BY_LANG[e]??[];return r}isPickRangeSeparator(e){let r=(e.normalized??e.value).toLowerCase();if(M.PICK_RANGE_SEPARATORS.has(r))return true;let t=this.currentProfile?.code;return t?M.PICK_RANGE_SEPARATORS_BY_LANG[t]?.has(e.value.toLowerCase())??false:false}tryMatchPickRangeExpression(e){let r=e.mark(),t=e.position();if(!this.tryConsumePickRangeOperand(e))return e.reset(r),null;let n=e.peek();if(!n||!this.isPickRangeSeparator(n)||(e.advance(),!this.tryConsumePickRangeOperand(e)))return e.reset(r),null;let a=e.peek();a&&M.PICK_RANGE_MODES.has((a.normalized??a.value).toLowerCase())&&e.advance();let o=e.tokens.slice(t,e.position()),[u,,s,l]=o,c=d=>d.kind==="keyword"?d.normalized??d.value:d.value,m=`${c(u)} to ${c(s)}`;return l&&(m+=` ${(l.normalized??l.value).toLowerCase()}`),{type:"expression",raw:m,value:m}}tryConsumePickRangeOperand(e){let r=e.peek();if(!r)return false;let t=(r.normalized??r.value).toLowerCase();if(this.isPickRangeSeparator(r))return false;let n=t==="start"||t==="end";return r.kind==="literal"||r.kind==="identifier"||r.kind==="keyword"&&n?(e.advance(),true):false}tryConsumeRunOperand(e){let r=e.peek();if(!r)return false;if(r.value==="("){let t=e.mark(),n=0;for(;!e.isAtEnd();){let a=e.advance();if(a.value==="(")n++;else if(a.value===")"&&(n--,n===0))return true}return e.reset(t),false}return this.tryMatchPossessiveExpression(e)?true:(r.kind==="literal"||r.kind==="identifier"||r.kind==="selector"||r.kind==="keyword")&&!M.RUN_OPERATORS.has(r.value)&&r.value!==")"?(e.advance(),true):false}isPossessorToken(e){if(!this.currentProfile)return false;for(let r of [e.value,e.normalized].filter(Boolean))if(ce(this.currentProfile,r)??ce(this.currentProfile,r.toLowerCase()))return true;return false}isBareWordPropertyHead(e){return e.kind!=="identifier"||/^[$:@#.*]/.test(e.value)||this.isStructuralKeyword(e.value)||e.normalized&&this.isStructuralKeyword(e.normalized)||e.normalized&&this.isRoleMarkerConcept(e.normalized)?false:!this.isPossessorToken(e)}toEnglishProperty(e){return this.currentProfile?me(this.currentProfile.code,e):e}tryMatchOfPossessiveExpression(e){let r=e.peek();if(!r||r.kind!=="selector"&&!this.isBareWordPropertyHead(r))return null;let t=e.mark();e.advance();let n=e.peek();if(!n||!this.isOfPossessiveMarker(n))return e.reset(t),null;e.advance();let a=e.peek();return !a||a.kind!=="selector"||jo(a.value)?(e.reset(t),null):(e.advance(),ge(ve(a.value),this.toEnglishProperty(r.value),"possessive"))}tryMatchPossessiveExpression(e){let r=e.peek();if(!r||!this.currentProfile)return null;let t=[r.value,r.normalized].filter(Boolean),n;for(let s of t)if(n=ce(this.currentProfile,s)??ce(this.currentProfile,s.toLowerCase()),n)break;if(!n)return null;let a=e.mark();e.advance();let o=this.currentProfile.possessive?.connectors;if(o&&o.length>0){let s=e.peek();if(s){let l=s.value.toLowerCase(),c=(s.normalized??"").toLowerCase();o.some(m=>m.toLowerCase()===l||m.toLowerCase()===c)&&e.advance();}}let u=e.peek();if(!u||Bo(this.currentProfile.code,u.value))return e.reset(a),null;if(u.kind==="identifier"||u.kind==="keyword"&&!this.isStructuralKeyword(u.value)&&!(u.normalized&&this.isStructuralKeyword(u.normalized))&&!(u.normalized&&this.isRoleMarkerConcept(u.normalized))&&!(u.normalized&&M.COMMAND_ACTION_KEYWORDS.has(u.normalized.toLowerCase()))||u.kind==="selector"&&u.value.startsWith("*")||u.kind==="selector"&&u.value.startsWith("@")||u.kind==="selector"&&u.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(u.value)){e.advance();let s=u.value;u.kind==="selector"&&s.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(s)&&(s=s.substring(1)),s=this.toEnglishProperty(s);let l=s;for(;;){let m=e.peek();if(m?.kind==="selector"&&m.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(m.value)){l+=m.value,e.advance();continue}if(m?.value==="?"){let d=e.peek(1);if(d?.kind==="selector"&&d.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(d.value)){l+=`?${d.value}`,e.advance(),e.advance();continue}}break}let c=e.peek();if(c&&c.value.startsWith("(")){let m="",d=0,p=0;for(;!e.isAtEnd()&&p++<M.MAX_METHOD_ARGS+2;){let f=e.peek();if(!f)break;m+=f.value,e.advance();for(let v of f.value)v==="("?d++:v===")"&&d--;if(d<=0)break}l+=m;}return ge(ue(n),l,"possessive")}return e.reset(a),null}tryMatchPostNominalPossessiveExpression(e){if(!this.currentProfile||this.currentProfile.possessive?.markerPosition!=="after-object")return null;let r=e.peek();if(!r)return null;let t=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("@"))||t)||this.isPossessorToken(r))return null;let a=e.mark(),o=r.value;t&&(o=o.substring(1)),e.advance(),o=this.toEnglishProperty(o);let u=o;for(;e.peek()?.kind==="selector"&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)u+=e.peek().value,e.advance();let s=e.peek();if(!s)return e.reset(a),null;let l;for(let c of [s.value,s.normalized].filter(Boolean))if(l=ce(this.currentProfile,c)??ce(this.currentProfile,c.toLowerCase()),l)break;return l?(e.advance(),ge(ue(l),u,"possessive")):(e.reset(a),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 Pt.has(e.toLowerCase())}static tokenLooksLikeEvent(e){if(e.kind==="selector"||e.kind==="url"||e.kind==="literal")return false;let r=e.value;if(/[/#@*]/.test(r)||r.startsWith('"')||r.startsWith("'")||r.startsWith("`"))return false;let t=e.normalized?.toLowerCase();return !(t&&Io.has(t)||t==="me"||t==="it"||t==="you")}tryMatchBraceRunLiteral(e){let r=e.peek();if(!r||r.kind!=="identifier"||r.value!=="{")return null;let t=e.mark();e.advance();let n=["{"],a=1,o=0;for(;!e.isAtEnd()&&o++<M.MAX_BRACE_RUN_TOKENS;){let u=e.advance();if(!u)break;if(u.value==="{")a++;else if(u.value==="}"&&(a--,a===0))return n.push("}"),W(n.join(" "));n.push(u.value);}return e.reset(t),null}tryMatchBraceRunExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"||r.value!=="{")return null;let t=e.mark(),n="",a=-1,o=0,u=0;for(;!e.isAtEnd()&&u++<M.MAX_BRACE_RUN_TOKENS;){let s=e.advance();if(!s)break;if(a>=0&&s.position.start>a&&(n+=" ".repeat(s.position.start-a)),n+=s.value,a=s.position.end,s.value==="{")o++;else if(s.value==="}"&&(o--,o===0))return {type:"expression",raw:n}}return e.reset(t),null}tryMatchBareCallExpression(e){let r=e.peek();if(!r||r.kind!=="identifier"||!/^[A-Za-z_][\w$]*$/.test(r.value))return null;let t=e.peek(1);if(!t||t.value!=="(")return null;let n=e.mark();e.advance();let a=e.advance(),o="",u=a.position?.end,s=false,l=0;for(;!e.isAtEnd()&&l++<M.MAX_METHOD_ARGS+2;){let c=e.peek();if(!c)break;if(c.value===")"){e.advance(),s=true;break}let m=u!==void 0&&c.position?.start===u;o+=(o===""||m?"":" ")+c.value,u=c.position?.end,e.advance();}return s?{type:"expression",raw:`${r.value}(${o})`}:(e.reset(n),null)}tryMatchMethodCallExpression(e){let r=e.peek();if(!r||r.kind!=="selector")return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="operator"||n.value!==".")return e.reset(t),null;e.advance();let a=e.peek();if(!a||a.kind!=="identifier")return e.reset(t),null;e.advance();let o=e.peek();if(!o||o.kind!=="punctuation"||o.value!=="(")return e.reset(t),null;e.advance();let u=[];for(;!e.isAtEnd()&&u.length<M.MAX_METHOD_ARGS;){let l=e.peek();if(!l)break;if(l.kind==="punctuation"&&l.value===")"){e.advance();break}if(l.kind==="punctuation"&&l.value===","){e.advance();continue}u.push(l.value),e.advance();}return {type:"expression",raw:`${r.value}.${a.value}(${u.join(", ")})`}}tryMatchPropertyAccessExpression(e,r=true){let t=e.peek();if(!t||t.kind!=="identifier"&&t.kind!=="keyword")return null;let n=e.mark();e.advance();let a=t.value.toLowerCase(),o=e.peek();if((t.kind==="identifier"||M.PROPERTY_ACCESS_BASES.has(a))&&o&&o.kind==="selector"&&/^\.[a-zA-Z_]/.test(o.value)){let p=t.value,f=[],v=0;for(;v<M.MAX_PROPERTY_DEPTH;){let h=e.peek();if(h&&h.kind==="selector"&&/^\.[a-zA-Z_]/.test(h.value))p+=`.${h.value.slice(1)}`,f.push(h.value.slice(1)),e.advance(),v++;else break}let E=e.peek(),y=!!E&&E.value.startsWith("(");if(r&&!y&&f.length>0&&Se(a))return ge(ue(a),f.join("."),"dot");if(y){let h=e.mark(),z=[],A=0,D=false;for(;!e.isAtEnd();){let b=e.peek();if(!b)break;if(b.value==="(")A++;else if(b.value===")"){if(z.push(b.value),e.advance(),A--,A===0&&(D=true),D)break;continue}z.push(b.value),e.advance();}D?p+=z.join(""):e.reset(h);}return {type:"expression",raw:p}}let u=e.peek();if(!u||u.kind!=="operator"||u.value!==".")return e.reset(n),null;e.advance();let s=e.peek();if(!s||s.kind!=="identifier")return e.reset(n),null;e.advance();let l=`${t.value}.${s.value}`,c=1;for(;!e.isAtEnd()&&c<M.MAX_PROPERTY_DEPTH;){let p=e.peek();if(!p||p.kind!=="operator"||p.value!==".")break;e.advance();let f=e.peek();if(!f||f.kind!=="identifier")break;e.advance(),l+=`.${f.value}`,c++;}let m=e.peek();if(m&&m.kind==="punctuation"&&m.value==="("){e.advance();let p=[],f=0;for(;!e.isAtEnd()&&p.length<M.MAX_METHOD_ARGS;){let E=e.peek();if(!E)break;if(E.kind==="punctuation"&&E.value===")"){if(f===0){e.advance();break}f--;}if(E.kind==="punctuation"&&E.value==="("&&f++,E.kind==="punctuation"&&E.value===","){e.advance();continue}p.push(E.value),e.advance();}return {type:"expression",raw:`${l}(${p.join(", ")})`}}let d=t.value.toLowerCase();if(r&&Se(d)){let p=l.split(".").slice(1).join(".");return ge(ue(d),p,"dot")}return {type:"expression",raw:l}}tryMatchPossessiveSelectorExpression(e){let r=e.peek();if(!r||r.kind!=="selector")return null;let t=e.mark();e.advance();let n=e.peek(),a=this.currentProfile?.possessive?.marker?.replace(/^-/,""),o=!!n&&n.kind==="punctuation"&&n.value==="'s",u=!!n&&n.value==="'"&&(e.peek(1)?.value??"").toLowerCase()==="s",s=(()=>{if(!this.currentPatternCommand||(n?.normalized??"").toLowerCase()!=="source")return false;let f=se[this.currentPatternCommand];return !!f&&f.roles.some(v=>v.role==="source")})(),l=!!n&&!!a&&a!=="'s"&&n.value===a&&(n.kind==="particle"||n.kind==="punctuation"||n.kind==="identifier")&&!s;if(!o&&!l&&!u)return e.reset(t),null;e.advance(),u&&e.advance();let c=e.peek();if(!c)return e.reset(t),null;let m=c.kind==="selector"&&c.value.startsWith("*"),d=c.kind==="keyword"&&!!this.currentProfile&&ko(this.currentProfile.code,c.value);return c.kind==="identifier"||m||d||(o||u)&&(c.kind==="selector"||c.kind==="keyword")?(e.advance(),ge(ve(r.value),this.toEnglishProperty(c.value),"possessive")):(e.reset(t),null)}tryMatchSelectorPropertyExpression(e){let r=e.peek();if(!r||r.kind!=="selector"||!r.value.startsWith("#"))return null;let t=e.mark();e.advance();let n=e.peek();if(!n||n.kind!=="selector"||!n.value.startsWith("."))return e.reset(t),null;let a=e.peek(1);a&&a.kind,e.advance();let o=n.value.slice(1);return ge(ve(r.value),o,"dot")}matchGroupToken(e,r,t,n){let a=e.mark(),o=new Map(t),u=this.matchTokenSequence(e,r.tokens,t,n);if(u){let s=[];for(let l of r.tokens)if(l.type==="group"&&l.renderRequired)for(let c of l.tokens)c.type==="literal"&&s.push(c.value,...c.alternatives??[]);s.length>0&&[...t.keys()].some(c=>!o.has(c))&&(e.tokens.slice(a.position,e.position()).some(d=>s.some(p=>this.getMatchType(d,p)!=="none"))||(u=false));}if(!u){e.reset(a);for(let s of t.keys())o.has(s)||t.delete(s);for(let[s,l]of o)t.get(s)!==l&&t.set(s,l);return r.optional||false}return true}getMatchType(e,r){if(e.value===r)return "exact";if(e.normalized===r)return "normalized";if(e.stem===r&&e.stemConfidence!==void 0&&e.stemConfidence>=.7)return "stem";if(e.kind==="keyword"&&e.value.toLowerCase()===r.toLowerCase())return "case-insensitive";if(e.kind==="keyword"){let t=Qe(e.value).toLowerCase();if(t&&t===Qe(r).toLowerCase())return "case-insensitive"}return "none"}tokenToSemanticValue(e){switch(e.kind){case "selector":return ve(e.value);case "literal":return this.parseLiteralValue(e.value);case "keyword":let r=(e.normalized||e.value).toLowerCase();return Se(r)?ue(r):W(e.normalized||e.value);case "identifier":if(e.value.startsWith("@"))return ve(e.value);if(e.value.startsWith(":")||e.value.startsWith("$"))return ue(e.value);let t=e.value.toLowerCase();return Se(t)?ue(t):{type:"expression",raw:e.value};case "url":return W(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 W(n,"string")}if(e==="true")return W(true,"boolean");if(e==="false")return W(false,"boolean");let r=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(r){let n=parseFloat(r[1]);return r[2]?W(e,"duration"):W(n,"number")}let t=parseFloat(e);return isNaN(t)?W(e,"string"):W(t,"number")}applyExtractionRules(e,r){for(let[t,n]of Object.entries(e.extraction)){let a=r.get(t);if(a){if(n.transform){let o=a.type==="literal"?String(a.value):String(a.raw??"");r.set(t,n.transform(o));}}else n.value!==void 0?r.set(t,{type:"literal",value:n.value}):n.default&&r.set(t,{...n.default,implicit:true});}}isOptional(e){return e.type!=="literal"&&e.optional===true}skipNoiseWords(e){let r=e.peek();if(!r)return;let t=r.value.toLowerCase();if(M.ENGLISH_NOISE_WORDS.has(t)){let n=e.mark();e.advance();let a=e.peek();if(a&&(a.kind==="selector"||a.kind==="identifier"))return;let o=e.peek(1);if(a&&a.kind==="keyword"&&o&&o.kind==="selector"&&/^\.[a-zA-Z_]/.test(o.value))return;let u=a?(a.normalized??a.value).toLowerCase():"";if(a&&M.POSITIONAL_OR_SCOPE_KEYWORDS.has(u))return;let s=e.peek(1),l=s?(s.normalized??s.value).toLowerCase():"",c=this.currentProfile?.wordOrder!=="SOV"&&M.COMMAND_ACTION_KEYWORDS.has(l),m=!s||s.kind==="particle"||M.CLAUSE_BOUNDARY_KEYWORDS.has(l)||c;if(a&&a.kind==="keyword"&&this.currentProfile?.code!=="en"&&Se(u)&&m||a&&a.kind==="keyword"&&this.currentProfile?.code==="en"&&Se(u))return;e.reset(n);}t==="class"&&e.advance();}extractEventModifiers(e){let r={},t=false;for(;!e.isAtEnd();){let n=e.peek();if(!n||n.kind!=="event-modifier")break;let a=n.metadata;if(!a)break;switch(t=true,a.modifierName){case "once":r.once=true;break;case "debounce":typeof a.value=="number"&&(r.debounce=a.value);break;case "throttle":typeof a.value=="number"&&(r.throttle=a.value);break;case "queue":(a.value==="first"||a.value==="last"||a.value==="all"||a.value==="none")&&(r.queue=a.value);break}e.advance();}return t?r:void 0}};X.CONDITION_OPERATOR_WORDS=new Set(["matches","match","contains","exists","has","have","equals","includes"]);X.POSITIONAL_OR_SCOPE_KEYWORDS=new Set(["first","last","next","previous","random","closest","parent"]);X.STRUCTURAL_NEVER_EVENT=new Set(["if","unless","else","end","then","while"]);X.PROPERTY_ACCESS_BASES=new Set(["it","me","you","my","its","your","event","result","target","detail","body","window","document","self","this"]);X.COMMAND_ACTION_KEYWORDS=Or;X.CLAUSE_BOUNDARY_KEYWORDS=new Set(["then","and","or","end","else"]);X.RUN_OPERATORS=new Set(["+","-","*","/"]);X.PICK_RANGE_SEPARATORS=new Set(["to"]);X.PICK_RANGE_SEPARATORS_BY_LANG={ar:new Set(["\u0625\u0644\u0649"]),bn:new Set(["\u09A5\u09C7\u0995\u09C7"]),de:new Set(["zu","bis"]),es:new Set(["a"]),fr:new Set(["\xE0"]),he:new Set(["\u05E2\u05DC","\u05E2\u05D3"]),hi:new Set(["\u0938\u0947"]),id:new Set(["ke"]),it:new Set(["in","a"]),ja:new Set(["\u304B\u3089"]),ko:new Set(["\uBD80\uD130"]),ms:new Set(["ke"]),pl:new Set(["do"]),pt:new Set(["para","a"]),qu:new Set(["kama"]),ru:new Set(["\u0432","\u0434\u043E"]),sw:new Set(["kwa","hadi"]),th:new Set(["\u0E43\u0E19","\u0E16\u0E36\u0E07"]),tl:new Set(["sa"]),tr:new Set(["ile"]),uk:new Set(["\u0432","\u0434\u043E"]),vi:new Set(["v\xE0o","\u0111\u1EBFn"]),zh:new Set(["\u5230"])};X.PICK_RANGE_MODES=new Set(["inclusive","exclusive"]);X.MAX_BRACE_RUN_TOKENS=64;X.MAX_PROPERTY_DEPTH=10;X.MAX_METHOD_ARGS=20;X.DECLARATION_COMMANDS=new Set(["behavior","def","install"]);X.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var Wt=X,oe=new Wt;function Y(i,e){return La(i,e)}function Kt(){return Pa()}var Ht={ar:new Set(["\u0623\u0648"]),bn:new Set(["\u0985\u09A5\u09AC\u09BE"]),de:new Set(["oder"]),en:new Set(["or"]),es:new Set(["o"]),fr:new Set(["ou"]),he:new Set(["\u05D0\u05D5"]),hi:new Set(["\u092F\u093E"]),id:new Set(["atau"]),it:new Set(["o"]),ja:new Set(["\u307E\u305F\u306F"]),ko:new Set(["\uB610\uB294"]),ms:new Set(["atau"]),pl:new Set(["lub"]),pt:new Set(["ou"]),qu:new Set(["utaq"]),ru:new Set(["\u0438\u043B\u0438"]),sw:new Set(["au"]),th:new Set(["\u0E2B\u0E23\u0E37\u0E2D"]),tl:new Set(["o"]),tr:new Set(["veya"]),uk:new Set(["\u0430\u0431\u043E"]),vi:new Set(["ho\u1EB7c"]),zh:new Set(["\u6216"])},$o=new Set(Object.values(Ht).flatMap(i=>[...i]));function br(i,e){let r=(i.normalized??i.value).toLowerCase();if(r==="or")return true;let t=e===void 0?$o:Ht[e];return t?t.has(i.value)||t.has(r):false}var Le=["if","unless","repeat","for","while"],ar=/^[A-Z][A-Za-z0-9_]*$/;function K(i,e){let r=new Set([e]),n=P(i)?.keywords?.[e];if(n){n.primary&&r.add(n.primary.toLowerCase());for(let a of n.alternatives??[])r.add(a.toLowerCase());}return r}function $(i,e){return e.has(i.value.toLowerCase())?true:i.normalized?e.has(i.normalized.toLowerCase()):false}var Vo=new Set(Le);function Ue(i,e){let r=i.normalized?.toLowerCase();return r?Vo.has(r):e.some(t=>$(i,t))}var mt=new Set(["me","it","you","the","body","window","document","its","event","result","target","self","this","them","parent","next","previous","closest","first","last"]),qo=new Set(["destination","source","style","patient","on","from","to"]);function Ke(i){if(!i||i.kind==="selector")return false;let e=(i.normalized??i.value).toLowerCase(),r=i.value.toLowerCase();return !(mt.has(e)||mt.has(r)||qo.has(e))}var dt=new Set(["ja","ko"]);function Re(i){let e=new Set;i?.primary&&e.add(i.primary.toLowerCase());for(let r of i?.alternatives??[])e.add(r.toLowerCase());return e}function Ut(i,e){let r=[],t=e.position.end,n=i.slice(e.position.end).match(/^\s*\(([^)]*)\)/);if(n){t=e.position.end+n[0].length;for(let a of n[1].split(/[,\u060c\u3001]/)){let o=a.trim();o&&r.push(o);}}return {parameters:r,headerEnd:t}}function or(i,e,r){let t=e+1;if(t>=i.length)return -1;let n=Re(P(r)?.roleMarkers?.patient);return n.size>0&&$(i[t],n)&&t++,t<i.length?t:-1}var Gt=/^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*$/;function Wo(i){let e=1;if(i[1]?.value==="("){let r=0,t=1;for(;t<i.length;t++)if(i[t].value==="(")r++;else if(i[t].value===")"&&--r===0)break;if(t>=i.length)return -1;e=t+1;}return e+1}function Ko(i,e,r){let t=P(r);if(t?.wordOrder!=="SOV"||!Gt.test(i[0].value)||e!==Wo(i))return false;let n=Re(t.roleMarkers?.patient);return n.size===0?false:$(i[e-1],n)}function Ho(i,e,r){if(!P(e))return null;let t=K(e,"behavior"),n=K(e,"def"),a=i.toLowerCase(),o=[...t].some(m=>a.includes(m)),u=/\bdef\b/.test(a)||[...n].some(m=>m!=="def"&&a.includes(m));if(!o&&!u)return null;let s=Y(i,e).tokens;if(s.length<2)return null;if($(s[0],t))return pt(i,e,s,r,0);let l=s.findIndex((m,d)=>d>0&&$(m,t));if(l>0&&ar.test(s[0].value))return pt(i,e,s,r,l);if($(s[0],n))return ft(i,e,s,r,0);let c=s.findIndex((m,d)=>d>0&&$(m,n));return c>0&&Ko(s,c,e)?ft(i,e,s,r,c):null}function Uo(i,e,r){let t=P(e);if(!t)return null;let n=t.wordOrder!=="SOV",a=dt.has(e)?Re(t.roleMarkers?.event):new Set,o=dt.has(e)?Re(t.keywords?.on):new Set,u=a.size>0&&o.size>0,s=K(e,"end"),l=K(e,"on"),c=i.toLowerCase(),m=[...s].some(b=>c.includes(b)),d=(n||u)&&(()=>{let b=0;for(let g of l)if(g){for(let w=c.indexOf(g);w>=0;w=c.indexOf(g,w+g.length))if(++b>=2)return true}return false})();if(!m&&!d)return null;let p=Y(i,e).tokens;if(p.length<2)return null;let f=Le.map(b=>K(e,b)),v=b=>Ue(b,f),E=b=>$(b,s),y=[],h=0,z=0;for(let b=0;b<p.length;b++){let g=p[b];if(E(g)){if(h>0){h--;continue}let w=i.slice(p[z].position.start,g.position.start).trim();w&&y.push(w),z=b+1;}else if(v(g))h++;else if(n&&h===0&&b>z&&$(g,l)&&Ke(p[b+1])){let w=i.slice(p[z].position.start,g.position.start).trim();w&&y.push(w),z=b;}else if(u&&h===0&&b-1>z&&$(g,a)&&p[b+1]!==void 0&&$(p[b+1],o)){let w=p[b-1],B=i.slice(p[z].position.start,w.position.start).trim();B&&y.push(B),z=b-1;}}if(z<p.length){let b=i.slice(p[z].position.start).trim();b&&y.push(b);}if(y.length<2)return null;let A=[],D=[];for(let b of y){let g;try{g=r.statement(b,e);}catch{return null}if(!g||g.kind!=="event-handler")return null;let w=g;if(A.push(w),!w.body||w.body.length===0)return null;D.push(w.metadata?.confidence??.75);}return qe(A,"then",{sourceLanguage:e,confidence:Oe(D),sourceText:i})}function Oe(i){return i.length>0?i.reduce((e,r)=>e+r,0)/i.length:0}function ur(i){let e=[];for(let r of i){let t=r.statements;r.kind==="compound"&&Array.isArray(t)?e.push(...t):e.push(r);}return e}function pt(i,e,r,t,n){let a=n>0,o=a?0:or(r,n,e);if(o<0)return null;let u=r[o],s=u.value;if(!ar.test(s))return null;let{parameters:l,headerEnd:c}=Ut(i,u),m=a?n+1:r.findIndex(w=>w.position.start>=c);m<=o&&(m=o+1);let d=K(e,"init"),p=K(e,"end"),f=Le.map(w=>K(e,w)),v=w=>Ue(w,f),E=w=>$(w,p),y=[],h=[],z=[],A=false,D=0,b=m;for(let w=m;w<r.length;w++){let B=r[w];if(E(B)){if(D>0){D--;continue}if(w===b){A=true;break}if($(r[b],d)){let C=i.slice(r[b].position.end,B.position.start).trim();if(C)try{let k=ur(t.body(C,e));h.push(...k),z.push(Oe(k.map(S=>S.metadata?.confidence??.75)));}catch{z.push(0);}}else {let C=i.slice(r[b].position.start,B.position.start).trim();try{let k=t.statement(C,e);if(k&&k.kind==="event-handler"){let S=k;y.push(S);let R=!S.body||S.body.length===0;z.push(R?.2:S.metadata?.confidence??.75);}else z.push(0);}catch{z.push(0);}}b=w+1;}else v(B)&&D++;}if(y.length===0&&h.length===0)return null;let g=(A?1:.8)*Oe(z);return so(s,l,y,h.length>0?h:void 0,{sourceLanguage:e,confidence:g,sourceText:i})}function ft(i,e,r,t,n){let a=n>0,o=a?0:or(r,n,e);if(o<0)return null;let u=r[o],s=u.value;if(!Gt.test(s))return null;let{parameters:l,headerEnd:c}=Ut(i,u),m=a?n+1:r.findIndex(g=>g.position.start>=c);m<=o&&(m=o+1);let d=K(e,"end"),p=Le.map(g=>K(e,g)),f=g=>Ue(g,p),v=g=>$(g,d),E=0,y=-1;for(let g=m;g<r.length;g++)if(v(r[g])){if(E===0){y=g;break}E--;}else f(r[g])&&E++;let h=r[m]?.position.start??c,z=y>=0?r[y].position.start:i.length,A=i.slice(h,z).trim();if(!A)return null;let D;try{D=ur(t.body(A,e));}catch{return null}if(D.length===0)return null;let b=Oe(D.map(g=>g.metadata?.confidence??.75));return y<0&&(b*=.8),lo(s,l,D,{sourceLanguage:e,confidence:b,sourceText:i})}var Ar=["live","eventsource","socket","worker","intercept"],Go=new Set(["intercept"]),Pr=new Set(["eventsource","socket","worker"]),Yo=new Set(["eventsource","socket"]),Zo=new Set(["worker"]),Jo=6,Xo=2;function Qo(i,e){for(let t of Ar)if($(i[0],K(e,t)))return {action:t,keywordIdx:0};if(P(e)?.wordOrder!=="SOV")return null;let r=Math.min(i.length,Jo);for(let t=1;t<r;t++)for(let n of Ar)if(n!=="live"&&$(i[t],K(e,n))&&!(Pr.has(n)&&!ar.test(i[0].value))&&!(n==="intercept"&&t>Xo))return {action:n,keywordIdx:t};return null}function eu(i,e,r){let t=Re(P(r)?.roleMarkers?.source);return t.size===0||e+1>=i.length?0:$(i[e],t)||$(i[e+1],t)?2:0}function Yt(i){let e=K(i,"on");e.add("when");let r=P(i)?.eventHandler;if(r?.keyword){e.add(r.keyword.primary.toLowerCase());for(let t of r.keyword.alternatives??[])e.add(t.toLowerCase());}for(let t of r?.temporalMarkers??[])e.add(t.toLowerCase());return e}function ru(i,e,r){let t=P(r)?.eventHandler,n=[t?.eventMarker?.primary,...t?.eventMarker?.alternatives??[],...t?.temporalMarkers??[]].filter(o=>!!o&&/\s/.test(o)),a=1;for(let o of n){let u=o.toLowerCase().split(/\s+/),s=e-u.length+1;s<0||u.every((l,c)=>i[s+c]?.value.toLowerCase()===l)&&(a=Math.max(a,u.length));}return a}function tu(i,e,r,t,n){if(i==="live")return r+1;if(r>0){let l=r+1;return i==="eventsource"&&(l+=eu(e,l,t)),l}let a=or(e,r,t);if(a<0)return -1;if(i==="worker")return a+1;let o=Yt(t),u=Re(P(t)?.roleMarkers?.event),s=n>=0?n:e.length;for(let l=a+1;l<s;l++){if(!$(e[l],o))continue;if(Ke(e[l+1]))return l;if(l>a+2&&u.size>0&&$(e[l-1],u)&&Ke(e[l-2]))return l-2;let c=ru(e,l,t);if(c>1&&l-c>a&&Ke(e[l-c]))return l-c;if(l>a+1&&Ke(e[l-1]))return l-1}return s}function iu(i,e,r,t){if(!Pr.has(i))return;let n=r>0?0:or(e,r,t);if(!(n<0))return e[n].value}function nu(i,e,r){if(!P(e))return null;let t=i.toLowerCase(),n=false;for(let s of [...Ar,"changes"]){for(let l of K(e,s))if(l&&t.includes(l)){n=true;break}if(n)break}if(!n)return null;let a=Y(i,e).tokens;if(a.length<2)return null;let o=su(a,e);if(o>=0)return cu(i,e,a,r,o);let u=Qo(a,e);return u?au(i,e,a,r,u.action,u.keywordIdx):null}function au(i,e,r,t,n,a){let o=K(e,"end"),u=Le.map(A=>K(e,A)),s=A=>Ue(A,u),l=A=>$(A,o),c=iu(n,r,a,e);if(Pr.has(n)&&(!c||!ar.test(c)))return null;let m=A=>({sourceLanguage:e,confidence:A,sourceText:i}),d=Dr(r,a+1,l,s);if(Go.has(n))return d>=0&&d!==r.length-1?null:kr(n,[],c,m(d>=0?1:.8));let p=tu(n,r,a,e,d);if(p<0||p>r.length)return null;let f=[],v=[],E=false,y=Zo.has(n);if(y||Yo.has(n)){let A=y?"def":"event-handler",D=0,b=p;for(let g=p;g<r.length;g++){let w=r[g];if(l(w)){if(D>0){D--;continue}if(E=true,g===b)break;let B=y?w.position.end:w.position.start,C=i.slice(r[b].position.start,B).trim();try{let k=t.statement(C,e);if(k&&k.kind===A){let S=k;f.push(S);let R=!S.body||S.body.length===0;v.push(R?.2:S.metadata?.confidence??.75);}else v.push(0);}catch{v.push(0);}b=g+1;}else s(w)&&D++;}}else {let A=Dr(r,p,l,s);E=A>=0;let D=A>=0?r[A].position.start:i.length,b=i.slice(r[p].position.start,D).trim();if(!b)return null;try{f.push(...ur(t.body(b,e)));}catch{return null}if(f.length===0)return null;v.push(...f.map(g=>g.metadata?.confidence??.75));}if(f.length===0&&!E)return null;let h=E?1:.8,z=v.length>0?h*Oe(v):h;return kr(n,f,c,m(z))}var ou=new Set([...Object.keys(se),"then","else"]);function uu(i){let e=K(i,"when");for(let r of Yt(i))e.add(r);return e}function su(i,e){if(i.length<3||!$(i[0],uu(e)))return -1;let r=K(e,"changes"),t=K(e,"end");for(let n=2;n<i.length;n++){let a=i[n];if(a.kind==="literal")continue;if($(a,r))return n;if($(a,t))return -1;let o=(a.normalized??a.value).toLowerCase();if(a.kind==="keyword"&&ou.has(o))return -1}return -1}function lu(i,e,r){if(r==="en"){let n=e[0],a=e[e.length-1];return {type:"expression",raw:i.slice(n.position.start,a.position.end).trim()}}let t=e.map(n=>br(n,r)?{...n,kind:"keyword",normalized:"or"}:n);return {type:"expression",raw:xe(t,P(r))}}function cu(i,e,r,t,n){let a=K(e,"end"),o=Le.map(h=>K(e,h)),u=h=>Ue(h,o),s=h=>$(h,a),l=n+1;if(l>=r.length)return null;let c=Dr(r,l,s,u),m=c>=0;if(m&&c!==r.length-1)return null;let d=m?r[c].position.start:i.length,p=i.slice(r[l].position.start,d).trim();if(!p)return null;let f;try{f=ur(t.body(p,e));}catch{return null}if(f.length===0)return null;let v=lu(i,r.slice(1,n),e),y=(m?1:.8)*Oe(f.map(h=>h.metadata?.confidence??.75));return kr("when",f,void 0,{sourceLanguage:e,confidence:y,sourceText:i},new Map([["condition",v]]))}function Dr(i,e,r,t){let n=0;for(let a=e;a<i.length;a++)if(r(i[a])){if(n===0)return a;n--;}else t(i[a])&&n++;return -1}var he={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",\uB9C8\uC6B0\uC2A4\uC5D4\uD130:"mouseenter",\uB9C8\uC6B0\uC2A4\uB9AC\uBE0C:"mouseleave",\uB9C8\uC6B0\uC2A4\uBB34\uBE0C:"mousemove",\uD0A4\uD504\uB808\uC2A4:"keypress",\uD130\uCE58\uC885\uB8CC:"touchend",\uD130\uCE58\uCDE8\uC18C:"touchcancel"},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",\u307C\u304B\u3057:"blur"},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",\u062A\u0631\u0643\u064A\u0632:"focus","\u0645\u0641\u062A\u0627\u062D \u0623\u0633\u0641\u0644":"keydown","\u0645\u0641\u062A\u0627\u062D \u0623\u0639\u0644\u0649":"keyup","\u0641\u0623\u0631\u0629 \u0641\u0648\u0642":"mouseover","\u062A\u063A\u064A\u064A\u0631 \u062D\u062C\u0645":"resize"},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",cambiar:"change",enfocar:"focus",desenfocar:"blur",cargar:"load",desplazar:"scroll",dobleclic:"dblclick",rat\u00F3nentrar:"mouseenter",rat\u00F3nsalir:"mouseleave",rat\u00F3nmover:"mousemove",teclapresar:"keypress",descargar:"unload",toqueempezar:"touchstart",toqueterminar:"touchend",toquemover:"touchmove",toquecancelar:"touchcancel"},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",bulan\u0131k:"blur",farebas:"mousedown",fareb\u0131rak:"mouseup",kayd\u0131r:"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",duploClique:"dblclick",mouseEntrar:"mouseenter",mouseSair:"mouseleave",mouseMover:"mousemove",teclaPressionar:"keypress",descarregar:"unload",toqueIn\u00EDcio:"touchstart",toqueFim:"touchend",toqueMover:"touchmove",toqueCancelar:"touchcancel"},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",\u6309\u952E\u6309\u4E0B:"keydown",\u9F20\u6807\u79FB\u52A8:"mousemove",\u5378\u8F7D:"unload",\u8C03\u6574\u5927\u5C0F:"resize",\u89E6\u6478\u5F00\u59CB:"touchstart",\u89E6\u6478\u79FB\u52A8:"touchmove"},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",flou:"blur",doubleclic:"dblclick",sourisentrer:"mouseenter",sourissortir:"mouseleave",sourisbouger:"mousemove",touchepress\u00E9e:"keypress",d\u00E9charger:"unload",touchercommencer:"touchstart",toucherfin:"touchend",toucherbouger:"touchmove",toucherannuler:"touchcancel"},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","taste unten":"keydown","taste oben":"keyup","maus dr\xFCber":"mouseover","maus weg":"mouseout",doppelklick:"dblclick",mauseintreten:"mouseenter",mausverlassen:"mouseleave",mausbewegen:"mousemove",tastedr\u00FCcken:"keypress",entladen:"unload",ber\u00FChrungstart:"touchstart",ber\u00FChrungend:"touchend",ber\u00FChrungbewegen:"touchmove",ber\u00FChrungabbrechen:"touchcancel"},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",tekan_tombol:"keydown",keyup:"keyup",arahkan:"mouseover",tinggalkan:"mouseout",bongkar:"unload"},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",kambiay:"change",apachiy:"submit",kachay:"submit",apaykachay:"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",bonyeza:"click",ingizo:"input",kitufe_shuka:"keydown",kitufe_juu:"keyup",panya_nje:"mouseout",wasilisha:"submit","sogeza juu":"mouseover",shuka:"unload"},vi:{"\u0111\u1ED5i k\xEDch th\u01B0\u1EDBc":"resize"}};Object.fromEntries(Object.entries(he).map(([i,e])=>{let r={};for(let[t,n]of Object.entries(e))n in r||(r[n]=t);return [i,r]}));var fu={debounced:"debounce",debounce:"debounce",throttled:"throttle",throttle:"throttle"},yu=[["\u043E\u0434\u0438\u043D","_","\u0440\u0430\u0437"],["\u043E\u0434\u0438\u043D_\u0440\u0430\u0437"],["\u043E\u0434\u043D\u0430\u0436\u0434\u044B"],["m\u1ED9t","l\u1EA7n"],["once"]],hu=/^(\d+)(ms|s|m)?$/,vu=new Set(["selector","literal","url","event-modifier"]);function Eu(i){let e=i.match(hu);if(!e)return null;let r=parseInt(e[1],10),t=e[2]||"ms";return t==="s"?r*=1e3:t==="m"&&(r*=6e4),r}function gu(i){for(let e=1;e<i.length;e++){let r=i[e];if(vu.has(r.kind))continue;let t=r.value.toLowerCase(),n=fu[t];if(n){let a=0;for(let o=e+1;o<i.length;o++){let u=i[o],s=Eu(u.value);if(s!==null)return {modifiers:{[n]:s},start:r.position.start,end:u.position.end};if(u.kind==="selector"||u.kind==="literal"||u.kind==="url"||++a>2)break}continue}for(let a of yu){if(a[0]!==t||e+a.length>i.length)continue;let o=true;for(let u=1;u<a.length;u++)if(i[e+u].value.toLowerCase()!==a[u]){o=false;break}if(o)return {modifiers:{once:true},start:r.position.start,end:i[e+a.length-1].position.end}}}return null}new Set(Object.values(Rr).flatMap(i=>Object.values(i)));var Ce=new Set(["if","unless","while","repeat","for"]),Er=new Set(["then","end","else","if","unless","while","for","repeat","and"]),Ou=new Set(["first","last","next","previous","random","closest"]),Be=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"]),ht=class extends Error{constructor(i,e,r,t){super(i),this.name="SemanticParseError",this.language=e,this.input=r,this.diagnostics=t;}};function V(i,e,r){return {message:i,severity:e,source:"semantic-parser",...r&&{code:r}}}function q(i,e){return e.length===0?i:{...i,diagnostics:e}}var nr=120;function Pu(i,e,r){let t=e.tokens.length;if(i.consumedTokens>=t)return null;let n=e.tokens[i.consumedTokens],a=e.tokens[t-1];if(!n||!a)return null;let o=r.slice(n.position.start,a.position.end);if(!o.trim())return null;let u=o.length>nr?`${o.slice(0,nr)}\u2026`:o,s=t-i.consumedTokens;return `pattern ${i.pattern.id} left ${s} token(s) unconsumed: "${u}"`}var Lu=new Set(["to","from","into","onto","with","as","at","of","in","on","by","and","or","then","end","else","the","a","an","async"]);function gr(i){let e=[],r=new Set((i.diagnostics??[]).map(n=>`${n.code}|${n.message}`)),t=n=>{if(!n||typeof n!="object")return;if(n!==i)for(let o of n.diagnostics??[]){if(o.code!=="unconsumed-input")continue;let u=`${o.code}|${o.message}`;r.has(u)||(r.add(u),e.push(o));}let a=n;for(let o of Jt){let u=a[o];if(Array.isArray(u))for(let s of u)t(s);}};return t(i),e.length===0?i:q(i,[...i.diagnostics??[],...e])}function vt(i){if(i.length>=2){let e=i[0];if((e==='"'||e==="'")&&i.endsWith(e))return i.slice(1,-1)}return i}var Jt=["body","statements","thenBranch","elseBranch","eventHandlers","initBlock"];function Xt(i,e){if(!i||typeof i!="object")return i;if(i.action&&i.roles instanceof Map){let t=re(i.action),n=t?.primaryRole;if(t&&n&&n!=="patient"&&!t.roles.some(a=>a.role==="patient")&&i.roles.has("patient")&&!i.roles.has(n)){let a=i.roles,o=a.get("patient");o!==void 0&&(a.delete("patient"),a.set(n,o));}if(i.action==="tell"){let a=i.roles,o=a.get("patient"),u=a.get("destination");o&&(o.type==="selector"||o.type==="reference")&&(!u||u.type==="literal")&&(a.delete("patient"),a.set("destination",o));}if(i.action==="transition"){let a=i.roles,o=a.get("goal");o&&o.type==="literal"&&o.dataType==="duration"&&!a.has("duration")&&(a.delete("goal"),a.set("duration",o));}if(i.action==="fetch"){let a=i.roles,o=a.get("patient"),u=a.get("source");o&&u&&(o.type==="literal"||o.type==="expression")&&u.type==="expression"&&!a.has("style")&&(a.delete("patient"),a.set("style",u),a.set("source",o));}if(i.action==="transition"){let a=i.roles,o=a.get("destination");o&&o.type==="literal"&&!a.has("goal")&&(a.delete("destination"),a.set("goal",o));let u=a.get("patient");u&&u.type==="literal"&&typeof u.value=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*$/.test(u.value)&&a.set("patient",{type:"expression",raw:u.value});}if(i.action==="morph"){let a=i.roles,o=a.get("patient");o&&o.type==="literal"&&typeof o.value=="string"&&/<[a-zA-Z][^>]*\/?>/.test(o.value)&&a.set("patient",{type:"expression",raw:o.value});}if(i.action==="wait"){let a=i.roles;if(!a.has("event")){let o=a.get("duration"),u=o?.type==="expression"?o.raw:o?.type==="literal"?o.value:void 0;typeof u=="string"&&Be.has(u.toLowerCase())&&(a.delete("duration"),a.set("event",{type:"literal",value:u,dataType:"string"}));}}if(i.kind==="command"&&i.action!=="on"){let a=i.roles,o=a.get("event");if(o&&o.type==="expression"){let u=o.raw;typeof u=="string"&&/^[A-Za-z_][A-Za-z0-9_-]*(:[A-Za-z0-9_-]+)?$/.test(u)&&a.set("event",{type:"literal",value:u,dataType:"string"});}}if(e?.size){let a=i.roles;for(let o of ["destination","source"]){let u=a.get(o);u&&u.type==="literal"&&typeof u.value=="string"&&e.has(u.value)&&a.set(o,{type:"expression",raw:u.value});}}}let r=i;for(let t of Jt){let n=r[t];if(Array.isArray(n))for(let a of n)Xt(a,e);}return i}var Q=class x{constructor(){this.parseDepth=0,this.coverageFrames=[],this.boundIdentifiers=new Set;}parse(e,r){this.parseDepth===0&&this.boundIdentifiers.clear(),this.parseDepth++,this.coverageFrames.push([]);try{let t=Xt(this.parseInternal(e,r),this.boundIdentifiers),n=this.coverageFrames[this.coverageFrames.length-1];if(n.length>0&&(t=q(t,[...t.diagnostics??[],...n])),this.parseDepth===1&&(t=gr(t),t.kind==="event-handler")){let a={node:t,input:e},o=a.node.eventModifiers;if(o&&(o.once||o.debounce!==void 0||o.throttle!==void 0))for(let s=0;s<4;s++){let l=this.reclaimDanglingFromTail(a.node,a.input,r)??this.reclaimEventCompoundTail(a.node,a.input,r)??this.reclaimResponseTypeTail(a.node,a.input,r)??this.reclaimCapturedDestinationTail(a.node,a.input,r);if(!l)break;a=l;}let u=this.reclaimEventCompoundTail(a.node,a.input,r);u&&(a=u),t=a.node;}return t}finally{this.coverageFrames.pop(),this.parseDepth--;}}coverageMark(){let e=this.coverageFrames[this.coverageFrames.length-1];return e?e.length:0}coverageRollback(e){let r=this.coverageFrames[this.coverageFrames.length-1];r&&r.length>e&&(r.length=e);}static getCoverageMarkerSurfaces(e){let r=x.coverageMarkerSurfaces.get(e);if(!r){r=new Set;let t=P(e)?.roleMarkers;if(t){for(let n of Object.values(t))if(n){if(n.primary)for(let a of n.primary.toLowerCase().split(/\s+/))r.add(a);for(let a of n.alternatives??[])for(let o of a.toLowerCase().split(/\s+/))r.add(o);}}for(let n of x.LEAKED_RENDER_MARKERS[e]??[])r.add(n.toLowerCase());x.coverageMarkerSurfaces.set(e,r);}return r}isCoverageResidueToken(e,r){if(e.kind==="particle"||e.kind==="conjunction"||e.metadata?.closesTrackedBlock||this.isThenKeyword(e.value,r)||this.isEndKeyword(e.value,r)||this.isElseKeyword(e.value,r))return true;let t=(e.normalized??e.value).toLowerCase();return Lu.has(t)?true:x.getCoverageMarkerSurfaces(r).has(e.value.toLowerCase())}recordDroppedTokens(e,r,t){if(e.length===0)return;let n=this.coverageFrames[this.coverageFrames.length-1];if(!n||!e.some(u=>!this.isCoverageResidueToken(u,r)))return;let a=e.map(u=>u.value).join(" ").trim();if(!a)return;let o=a.length>nr?`${a.slice(0,nr)}\u2026`:a;n.push(V(`${t} left ${e.length} token(s) unconsumed: "${o}"`,"warning","unconsumed-input"));}registerBoundIdentifiers(e){let r=e.action==="repeat"||e.action==="for"?"patient":e.action==="set"?"destination":null;if(!r)return;let t=e.roles.get(r);t?.type==="expression"&&typeof t.raw=="string"&&/^[A-Za-z_]\w*$/.test(t.raw)&&this.boundIdentifiers.add(t.raw);}parseInternal(e,r){let t=Ho(e,r,{statement:(C,k)=>this.parse(C,k),body:(C,k)=>this.parseStatements(C,k)});if(t)return t;let n=nu(e,r,{statement:(C,k)=>this.parse(C,k),body:(C,k)=>this.parseStatements(C,k)});if(n)return n;let a=Uo(e,r,{statement:(C,k)=>this.parse(C,k),body:(C,k)=>this.parseStatements(C,k)});if(a)return a;let{modifiers:o,remainingInput:u}=this.extractStandaloneModifiers(e,r),s=u||e,c=this.stripAsyncModifier(s,r).remainingInput??s,d=this.stripDoNotThrowModifier(c,r).remainingInput??c,p=[],f=Y(d,r);this.positionSource=d;{let C=f.mark(),k=this.consumeJsBlock(f,r);if(k&&f.isAtEnd())return q(k,p);f.reset(C);}let v=de(r);if(v.length===0)throw new ht(`No patterns available for language: ${r}`,r,d,[V(`No patterns registered for language '${r}'`,"error","no-patterns")]);let E=[...v].sort((C,k)=>k.priority-C.priority);{let C=f.tokens;if(P(r)?.wordOrder==="VSO"&&C.length>=4&&C[0]?.normalized==="source"){let k=C.findIndex(S=>S.normalized==="on");if(k>=2&&k+1<C.length){let S=d.slice(C[0].position.start,C[k].position.start).trim(),R=C[k+1].position.end,T=d.slice(C[k].position.start,R)+" "+S+d.slice(R);if(T!==d)try{let O=this.parse(T,r);if(O&&O.kind==="event-handler"){let N=o?this.applyModifiers(O,o):O;return q(N,p)}}catch{}}}}{let C=f.tokens,k=C[0]?.normalized==="if";for(let S=0;k&&S+3<C.length;S++){let R=(C[S+3]?.normalized??C[S+3]?.value??"").toLowerCase();if(C[S]?.normalized==="source"&&C[S+2]?.normalized==="on"&&x.KNOWN_EVENTS.has(R)){let T=(d.slice(0,C[S].position.start).trimEnd()+" "+d.slice(C[S+1].position.end).trimStart()).trim();if(T&&T!==d)try{let O=this.parse(T,r);if(O&&O.kind==="event-handler"){let N=o?this.applyModifiers(O,o):O;return q(N,p)}}catch{}break}}}{let C=f.tokens;for(let k=1;k<C.length-1;k++){let S=C[k];if(!br(S,r))continue;let R=C[k+1],T=(R.normalized??R.value).toLowerCase();if(!x.KNOWN_EVENTS.has(T))break;let O=k+1,N=C[k+2];N&&N.kind==="selector"&&N.value.startsWith("[")&&(O=k+2);let I=C[k].position.start,j=C[O].position.end,L=(d.slice(0,I).trimEnd()+" "+d.slice(j).trimStart()).trim();if(L&&L!==d)try{let Z=this.parse(L,r);if(Z&&Z.kind==="event-handler"){Z.additionalEvents=[{type:"literal",value:T}];let J=o?this.applyModifiers(Z,o):Z;return q(J,p)}}catch{}break}}{let C=gu(f.tokens);if(C){let k=(d.slice(0,C.start).trimEnd()+" "+d.slice(C.end).trimStart()).trim();if(k&&k!==d)try{let S=this.parse(k,r);if(S&&S.kind==="event-handler"){let R=this.applyModifiers(S,{...o??{},...C.modifiers});return q(R,p)}}catch{}}}let y=E.filter(C=>C.command==="on"),h=f.mark(),z=oe.matchBest(f,y);if(z){p.push(V(`event pattern matched: ${z.pattern.id} (confidence: ${z.confidence.toFixed(2)})`,"info","pattern-match"));let C=false;if(/^event-[a-z]+-bare$/.test(z.pattern.id)){let k=z.captured.get("event"),S=(k?.raw??k?.value??"").toString().toLowerCase(),R=he[r],T=x.KNOWN_EVENTS.has(S)||!!R&&Object.keys(R).some(O=>O.toLowerCase()===S);if(S&&!T){let O=this.trySOVEventExtraction(d,r,E);if(O){p.push(V(`bare-event mis-anchor on "${S}" rejected; SOV extraction preferred`,"info","stage-bare-event-guard"));let N=o?this.applyModifiers(O,o):O;return q(N,p)}if(k?.type==="reference"||k?.type==="expression"){f.reset(h);let N=E.filter(j=>j.command!=="on"),I=oe.matchBest(f,N);f.reset(h),I&&I.pattern.command!=="on"?(C=true,p.push(V(`bare-event mis-anchor on reference "${S}" rejected; command ${I.pattern.command} preferred`,"info","stage-bare-event-guard"))):oe.matchBest(f,y);}}}if(!C){let k=this.buildEventHandler(z,f,r),S=o?this.applyModifiers(k,o):k;return q(S,p)}}p.push(V(`event patterns: ${y.length} tried, no match`,"info","stage-event"));let A=this.tryTrailingEventExtraction(d,r,E);if(A){p.push(V("trailing event extraction succeeded","info","stage-trailing-event"));let C=o?this.applyModifiers(A,o):A;return q(C,p)}let D=E.filter(C=>C.command!=="on"),b=this.tryParseUnlessGuard(f,D,r);if(b&&b.length>0){let C=b.length===1?b[0]:qe(b,"then",{sourceLanguage:r,confidence:1});return q(C,p)}let g=oe.matchBest(f,D);if(g){if(Ce.has(g.pattern.command)){let k=this.trySOVEventExtraction(d,r,E);if(k){p.push(V(`SOV event extraction preferred over bare ${g.pattern.command} command`,"info","stage-sov-loop"));let R=o?this.applyModifiers(k,o):k;return q(R,p)}let S=this.tryMidStreamEventExtraction(d,r,E);if(S){p.push(V(`mid-stream event extraction preferred over bare ${g.pattern.command} command`,"info","stage-midstream-loop"));let R=o?this.applyModifiers(S,o):S;return q(R,p)}}else if(x.KNOWN_EVENTS.has(g.pattern.command)&&this.hasSOVEventMarkerHead(d,r)){let k=this.trySOVEventExtraction(d,r,E);if(k){p.push(V(`SOV event extraction preferred over command-homonym event ${g.pattern.command}`,"info","stage-sov-homonym"));let S=o?this.applyModifiers(k,o):k;return q(S,p)}}else if(P(r)?.wordOrder==="VSO"){let k=this.tryMidStreamEventExtraction(d,r,E);if(k){p.push(V(`mid-stream event extraction preferred over bare ${g.pattern.command} command`,"info","stage-midstream-cmd"));let S=o?this.applyModifiers(k,o):k;return q(S,p)}}if(g.consumedTokens<f.tokens.length&&P(r)?.wordOrder==="SOV"){let k=this.trySOVEventExtraction(d,r,E);if(k){p.push(V(`SOV event extraction preferred over partial ${g.pattern.command} command (trailing remainder)`,"info","stage-sov-trailing"));let S=o?this.applyModifiers(k,o):k;return q(S,p)}}if(g.consumedTokens<f.tokens.length&&!Ce.has(g.pattern.command)){let k=this.tryTopLevelCommandSequence(f,D,r);if(k)return p.push(V(`top-level command sequence: ${k.statements.length} commands`,"info","stage-top-level-sequence")),q(k,p)}p.push(V(`command pattern matched: ${g.pattern.id} (confidence: ${g.confidence.toFixed(2)})`,"info","pattern-match"));let C=Pu(g,f,d);return C&&p.push(V(C,"warning","unconsumed-input")),q(this.buildCommand(g,r),p)}if(p.push(V(`command patterns: ${D.length} tried, no match`,"info","stage-command")),!d.includes(`
4
+ `)&&P(r)?.wordOrder==="VSO"){let C=this.tryMidStreamEventExtraction(d,r,E);if(C){p.push(V("mid-stream event extraction succeeded with no leading command match","info","stage-midstream-nocmd"));let k=o?this.applyModifiers(C,o):C;return q(k,p)}}let w=this.trySOVEventExtraction(d,r,E);if(w){p.push(V("SOV event extraction succeeded","info","stage-sov"));let C=o?this.applyModifiers(w,o):w;return q(C,p)}p.push(V("SOV event extraction: no event keyword found","info","stage-sov"));let B=this.tryCompoundCommandParsing(f,D,r);if(B)return p.push(V("compound command parsing succeeded","info","stage-compound")),q(B,p);throw p.push(V("compound parsing: no then-keywords or no command matches","info","stage-compound")),p.push(V(`all parse stages exhausted for "${d}"`,"error","parse-failed")),new ht(`Could not parse input in ${r}: ${d}`,r,d,p)}parseStatements(e,r){let t=Y(e,r),n=de(r).filter(a=>a.command!=="on").sort((a,o)=>o.priority-a.priority);this.coverageFrames.push([]);try{let a=this.parseBodyWithClauses(t,n,r),o=this.coverageFrames[this.coverageFrames.length-1];if(o.length>0&&a.length>0){let u=a[a.length-1];a[a.length-1]=q(u,[...u.diagnostics??[],...o]);}return a}finally{this.coverageFrames.pop();}}canParse(e,r){try{return this.parse(e,r),!0}catch{return false}}supportedLanguages(){return Kt()}buildCommand(e,r){if(!e)throw new Error("No match to build command from");let t={};for(let[a,o]of e.captured)t[a]=o;let n=ee(e.pattern.command,t,{sourceLanguage:r,patternId:e.pattern.id,confidence:e.confidence});return this.registerBoundIdentifiers(n),n}buildEventHandler(e,r,t){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 d=n.type==="expression"?n.raw:n.type==="literal"?n.value:void 0;if(typeof d=="string"&&/^[^\s()[\]{}:]+$/.test(d)){let p=he[t]?.[d];p?n={type:"literal",value:p,dataType:"string"}:n.type==="expression"&&x.KNOWN_EVENTS.has(d.toLowerCase())&&(n={type:"literal",value:d.toLowerCase(),dataType:"string"});}}let a=oe.extractEventModifiers(r),o=e.captured.get("source");o&&e.pattern.id.endsWith("source")&&!(o.type==="reference"&&o.value==="me")&&(a={...a??{},from:o});let u=this.extractOrConjunctionEvents(r,t),s=n;u.length>0&&n.type==="literal"&&(s={type:"literal",value:[String(n.value),...u.map(p=>String("value"in p?p.value:""))].join(" or ")});let l,c=e.captured.get("action");if(c&&c.type==="literal"&&c.value==="if"){let d=r.tokens,p=-1;for(let f=r.position()-1;f>=0;f--){let v=d[f],E=(v.normalized??v.value).toLowerCase();if(this.isIfKeyword(E,t)){p=f;break}}if(p>=0){let f=de(t).filter(A=>A.command!=="on").sort((A,D)=>D.priority-A.priority),v=d.slice(p);if(e.pattern.id.endsWith("vso-verb-first")&&s.type==="literal"){let A=String(s.value??"").split("[")[0].trim().toLowerCase(),D=v.findIndex((b,g)=>{if(g===0||A==="")return false;let w=(b.normalized??b.value).toLowerCase(),B=v[g-1];return w===A&&B.kind==="keyword"&&(B.normalized??"").toLowerCase()==="on"});if(D>0){let b=v[D+1],g=b&&b.kind==="selector"&&b.value.startsWith("[")?1:0;v=[...v.slice(0,D-1),...v.slice(D+1+g)];}}let E=new ie(v,t),y=this.coverageMark(),h=this.parseBodyWithClauses(E,f,t);if(h.some(A=>A.kind==="conditional")||h.length===1&&h[0]?.kind==="compound"&&h[0].statements.some(A=>A.kind==="conditional")){for(;!r.isAtEnd();)r.advance();return $e(s,h,a,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}this.coverageRollback(y);}}if(c&&c.type==="literal"&&String(c.value)!=="js"&&re(String(c.value))!==void 0){let d=c.value,p={};for(let[g,w]of e.captured)g!=="event"&&g!=="action"&&g!=="continues"&&(p[g]=w);if(d==="repeat"){let g=r.peek(),w=C=>(C.normalized??C.value).toLowerCase();if(g&&g.kind==="keyword"&&w(g)==="forever")p.loopType={type:"literal",value:"forever"},delete p.patient,r.advance();else if(g&&g.kind==="keyword"&&w(g)==="event"){r.advance();let C=r.peek();if(C)for(p.event={type:"literal",value:w(C)},p.loopType={type:"literal",value:"until-event"},delete p.patient;!r.isAtEnd();){let k=r.peek();if(!k||k.kind==="conjunction"||k.kind==="keyword"&&(this.isThenKeyword(k.value,t)||this.isEndKeyword(k.value,t)))break;r.advance();}}let B=p.patient;B&&B.type==="reference"&&B.value==="me"&&delete p.patient;}let f=ee(d,p,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence});this.registerBoundIdentifiers(f);let v=[];if(!Ce.has(d)||d==="repeat"||d==="while"){let g=e.pattern.id.includes("verb-first"),w=r.tokens,B=r.position(),C=R=>R.kind==="conjunction"||R.kind==="keyword"&&(this.isThenKeyword(R.value,t)||this.isEndKeyword(R.value,t)),k=new Set;{let R=P(t)?.keywords?.[d];R?.primary&&k.add(R.primary.toLowerCase());for(let T of R?.alternatives??[])k.add(T.toLowerCase());}let S=-1;for(let R=B-1;R>=0;R--){let T=w[R];if(C(T))break;if((T.normalized??T.value).toLowerCase()===d||k.has(T.value.toLowerCase())){S=R;break}}if(S>=0){let R=B;for(;R<w.length&&!C(w[R]);)R++;let T=w.slice(S,R),O=T;if(g){let N=String(n.value??"").toLowerCase(),I=T.findIndex(j=>(j.normalized??j.value).toLowerCase()===N);if(I<0)O=null;else {let j=T[I-1],L=j&&j.kind==="keyword"&&j.normalized?.toLowerCase()==="on"?I-1:I;O=[...T.slice(0,L),...T.slice(I+1)];}}if(O&&O.length>1){let N=de(t).filter(_=>_.command!=="on").sort((_,H)=>H.priority-_.priority),I=this.coverageMark(),j=this.parseClause(O,N,t),L=j[0],Z=_=>_!==null&&typeof _=="object"&&typeof _.type=="string"?_.type:typeof _,J=re(d),mr=J?.primaryRole,qr=_=>_==="patient"&&mr&&mr!=="patient"&&!J?.roles.some(H=>H.role==="patient")?mr:_,wi=(_,H)=>{if(!Ce.has(d)||!J)return false;let ye=J.roles.find(Me=>Me.role===qr(_));return ye?ye.expectedTypes.length>0&&!ye.expectedTypes.includes(Z(H)):true},dr=(_,H)=>_==="patient"&&!!J&&!J.roles.some(ye=>ye.role==="patient")&&Z(H)==="literal"&&Pt.has(String(H.value??"").toLowerCase()),pr=_=>_!==null&&typeof _=="object"&&_.implicit===true,bi=!!L&&L.kind==="command"&&Object.entries(p).every(([_,H])=>{if(pr(H)||wi(_,H)||dr(_,H))return true;let ye=L.roles.get(qr(_));if(ye!==void 0&&Z(ye)===Z(H))return true;if(_==="patient"&&d==="pick"&&Z(H)==="literal"){let Me=L.roles.get("method"),Kr=Z(Me),Hr=Kr==="literal"?String(Me.value):Kr==="expression"?String(Me.raw):void 0;return Hr!==void 0&&Hr===String(H.value)}return false}),Wr=L?.metadata?.patternId??"",Ai=!Ce.has(d)||/^repeat-.*-(times|for-in|while-head|until-head)$/.test(Wr),Di=/^repeat-.*-(times|for-in|while-head|until-head)$/.test(Wr);if((j.length===1||Di&&j.length>1)&&L&&L.kind==="command"&&(L.action===d||d==="while"&&L.action==="repeat"&&/-while-head$/.test(L.metadata?.patternId??""))&&bi&&Ai&&(L.roles.size>Object.entries(p).filter(([_,H])=>!dr(_,H)).length||[...L.roles.values()].filter(_=>!pr(_)).length>Object.entries(p).filter(([_,H])=>!dr(_,H)&&!pr(H)).length))for(f=L,v=j.slice(1);r.position()<R;)r.advance();else this.coverageRollback(I);}}}if(!Ce.has(d)){let g=f;if(re(d)?.roles.some(T=>T.role==="quantity"&&!T.required)&&!g.roles.has("quantity")){let T=r.peek();T&&/^-?\d+(\.\d+)?$/.test(T.value)&&(f=ee(d,{...Object.fromEntries(g.roles),quantity:{type:"literal",value:parseFloat(T.value),dataType:"number"}},g.metadata),r.advance());}let B=f;if(re(d)?.roles.some(T=>T.role==="duration"&&!T.required)&&!B.roles.has("duration")){let T=/^\d+(\.\d+)?(ms|s)$/i,O=r.peek(),N=false;if(O&&O.kind==="particle"){let I=r.peek(1);I&&T.test(I.value)&&(N=true,O=I);}O&&T.test(O.value)&&(f=ee(d,{...Object.fromEntries(B.roles),duration:{type:"literal",value:O.value,dataType:"string"}},B.metadata),N&&r.advance(),r.advance(),this.consumeForPostposition(r,t));}let k=f,S=re(d);if(S?.roles.find(T=>T.role==="responseType"&&!T.required)&&!k.roles.has("responseType")){let T=L=>typeof L=="string"&&x.RESPONSE_TYPE_WORDS.has(L.toLowerCase()),O=(L,Z)=>{let J=Object.fromEntries(k.roles);Z&&delete J.destination,J.responseType={type:"expression",raw:L},f=ee(d,J,k.metadata);},N=k.roles.get("destination"),I=S?.roles.find(L=>L.role==="destination"),j=N?.raw??N?.value;if(N&&I&&!I.expectedTypes.includes(N.type)&&T(j))O(j,true);else {let L=r.peek();L&&T(L.value)&&(O(L.value,false),r.advance());}}if(d==="wait"){let T=f;if(!T.roles.has("event")){let O=r.peek();if(O&&Be.has(O.value.toLowerCase())){let N=Object.fromEntries(T.roles),I=N.duration;I&&I.type!=="literal"&&I.type!=="expression"&&delete N.duration;let j=N.patient;j&&j.type==="reference"&&j.value==="me"&&delete N.patient,N.event={type:"literal",value:O.value,dataType:"string"},f=ee(d,N,T.metadata),r.advance(),this.consumeForPostposition(r,t);}}}this.tryAttachTrailingRole(r,f,t),this.tryAttachTrailingStyle(r,f,t),this.tryAttachTrailingExpressionRole(r,f,t);}let E=e.captured.get("continues"),y=E?.type==="literal"&&E.value==="then",h=r.peek(),z=!!h&&this.isThenKeyword(h.value,t),D=Ce.has(d)&&!!h&&!this.isEndKeyword(h.value,t),b=!!h&&!this.isEndKeyword(h.value,t);if(y||z||D||b){let g=de(t).filter(C=>C.command!=="on").sort((C,k)=>k.priority-C.priority),w=de(t).filter(C=>C.id.startsWith("grammar-")&&C.id.includes("-continuation")).sort((C,k)=>k.priority-C.priority),B=this.parseBodyWithGrammarPatterns(r,g,w,t);B.length>0?l=[f,...v,...B]:l=[f,...v];}else l=[f,...v],r.isAtEnd()||this.recordDroppedTokens(r.tokens.slice(r.position()),t,"handler body tail");}else {let d=de(t).filter(f=>f.command!=="on").sort((f,v)=>v.priority-f.priority),p=c?e.roleStarts?.get("action"):void 0;if(p!==void 0&&p<r.position()){let f=new ie(r.tokens.slice(p),t);for(l=this.parseBodyWithClauses(f,d,t);!r.isAtEnd();)r.advance();}else l=this.parseBodyWithClauses(r,d,t);}let m=l.length>1?[qe(l,"then",{sourceLanguage:t})]:l;return $e(s,m,a,{sourceLanguage:t,patternId:e.pattern.id,confidence:e.confidence})}parseBodyWithClauses(e,r,t){let n=[],a=[],o=0,u=[];for(;!e.isAtEnd();){let s=e.peek();if(!s)break;if(a.length===0){let f=this.consumeJsBlock(e,t)??this.consumeVerbFinalJsBlock(e,t);if(f){n.push(f);continue}let v=this.tryParseConditionalBlock(e,r,t);if(v){n.push(v);continue}let E=this.tryParseUnlessGuard(e,r,t);if(E){n.push(...E);continue}}let l=s.kind==="conjunction"||s.kind==="keyword"&&this.isThenKeyword(s.value,t),c=a[a.length-1],m=e.peek(1),d=c?.value.toLowerCase()==="at"&&m?.value.toLowerCase()==="of"||nt(t,s.value,c?.value,m?.value),p=s.kind==="keyword"&&this.isEndKeyword(s.value,t)&&!d;if(p&&o>0){o--,u.pop(),a.push({...s,metadata:{...s.metadata,closesTrackedBlock:true}}),e.advance();continue}if(l&&u.includes("if")){a.push(s),e.advance();continue}if(l){if(a.length>0){let f=this.parseClause(a,r,t);n.push(...f),a.length=0,o=f.filter(v=>{let E=v;return (E.action==="for"||E.action==="repeat"||E.action==="while")&&(!Array.isArray(E.body)||E.body.length===0)}).length,u.length=0;for(let v=0;v<o;v++)u.push("other");}e.advance();continue}if(p){e.advance();let f=[];for(;!e.isAtEnd();){let v=e.peek();if(!v||v.kind==="conjunction"||v.kind==="keyword"&&(this.isThenKeyword(v.value,t)||this.isEndKeyword(v.value,t)))break;f.push(v),e.advance();}if(f.length>0){let v=this.coverageMark(),E=a.length>0?this.parseClause(a,r,t):[];E.length===0&&a.length>0?(this.coverageRollback(v),n.push(...this.parseClause([...a,...f],r,t))):(n.push(...E),n.push(...this.parseClause(f,r,t)));}else if(a.length>0){let v=this.parseClause(a,r,t);n.push(...v);}a.length=0;break}if(s.kind==="keyword"){let f=(s.normalized??s.value).toLowerCase();(this.isIfKeyword(f,t)||this.isUnlessKeyword(f,t)||f==="while"||f==="for"||f==="repeat")&&(o++,u.push(this.isIfKeyword(f,t)?"if":"other"));}a.push(s),e.advance();}if(a.length>0){let s=this.parseClause(a,r,t);n.push(...s);}e.isAtEnd()||this.recordDroppedTokens(e.tokens.slice(e.position()),t,"body stream tail"),this.foldFrontedWhileIntoRepeat(n,t);for(let s=n.length-1;s>=0;s--){let l=n[s];l.kind==="command"&&l.action==="for"&&(!(l.roles instanceof Map)||l.roles.size===0)&&(!Array.isArray(l.body)||l.body.length===0)&&n.splice(s,1);}return n.length>1?[qe(n,"then",{sourceLanguage:t})]:n}tryTopLevelCommandSequence(e,r,t){let n=this.coverageMark(),a;try{let l=new ie(e.tokens,t);a=this.parseBodyWithClauses(l,r,t);}catch{return this.coverageRollback(n),null}if(a.length!==1||a[0].kind!=="compound")return this.coverageRollback(n),null;let o=a[0];if(o.statements.length<2)return this.coverageRollback(n),null;let u=o.statements.map(l=>l.metadata?.confidence??.75),s=u.reduce((l,c)=>l+c,0)/u.length;return qe(o.statements,o.chainType,{sourceLanguage:t,confidence:s})}foldFrontedWhileIntoRepeat(e,r){for(let t=0;t+1<e.length;t++){let n=e[t],a=e[t+1];if(n.kind!=="command"||n.action!=="while"||a.kind!=="command"||a.action!=="repeat")continue;let o=n.roles.get("condition");if(!o||a.roles.has("condition")||Array.isArray(n.body)||Array.isArray(a.body))continue;let u=new Map(a.roles);u.set("condition",o),u.set("loopType",{type:"literal",value:"while",dataType:"string"}),e.splice(t,2,{...a,roles:u,metadata:{...a.metadata,sourceLanguage:r,patternId:`repeat-${r}-fronted-while-fold`,confidence:Math.max(a.metadata?.confidence??0,n.metadata?.confidence??0)}});}}parseClause(e,r,t){if(e.length===0)return [];let n=null,a=e,o=e[e.length-1];if(o&&e.length>=2){let y=(o.normalized??o.value).toLowerCase();this.isUnlessKeyword(y,t)&&(n="unless",a=e.slice(0,-1));}let u=null;if(n&&a.length>=3){let y=P(t),h=y?x.buildVerbLookup(y):null;if(h)for(let z=1;z<a.length-1;z++){let A=a[z],D=h.get(A.value.toLowerCase())??(A.normalized?h.get(A.normalized.toLowerCase()):void 0);if(D&&!x.CONDITION_OPERATORS.has(D)){u=a.slice(0,z),a=a.slice(z);break}}}let s=new ie(a,t),l=[],c=this.coverageMark(),m=0,d=[],p=u,f=()=>{if(d.length===0)return;let y=d.slice();if(d.length=0,n&&l.length===0&&p===null){p=y;return}let h=y[0];if(!(h&&(h.kind==="identifier"||h.kind==="selector"||h.kind==="literal"||h.kind==="reference"))){this.recordDroppedTokens(y,t,"body clause");return}let A=false;for(let D of this.parseSOVClauseByVerbAnchoring(y,t)){let b=D.action,g=D.roles;b&&re(b)&&g instanceof Map&&g.size>0&&(l.push(D),A=true);}A||this.recordDroppedTokens(y,t,"body clause");};for(;!s.isAtEnd();){let y=s.peek(),h=!!y&&y.normalized?.toLowerCase()==="repeat",z=s.mark(),A=oe.matchBest(s,r);if(h&&A&&A.pattern.command!=="repeat"){s.reset(z),f(),l.push(ee("repeat",{},{sourceLanguage:t,confidence:.6})),m++,s.advance();continue}if(A&&A.pattern.command==="if"){let D=s.mark(),b=d.length;for(s.reset(z);!s.isAtEnd();){let w=s.peek();if(!w||this.isIfKeyword((w.normalized??w.value).toLowerCase(),t))break;d.push(w),s.advance();}let g=this.tryParseConditionalBlock(s,r,t);if(g){f(),l.push(g),m++;continue}d.length=b,s.reset(D);}if(A){f();let D=this.buildCommand(A,t);l.push(D),m++,this.tryAttachTrailingRole(s,D,t),this.tryAttachTrailingStyle(s,D,t),this.tryAttachTrailingExpressionRole(s,D,t),this.tryAttachTrailingDuration(s,D);}else {let D=s.peek();D&&D.normalized?.toLowerCase()==="repeat"?(f(),l.push(ee("repeat",{},{sourceLanguage:t,confidence:.6})),m++):D&&d.push(D),s.advance();}}f();let v=l;if(m===0){let y=this.parseSOVClauseByVerbAnchoring(a,t);y.length>0&&(this.coverageRollback(c),v=y);}let E=p;return n&&v.length>0&&E&&E.length>0?[ee(n,{condition:{type:"expression",raw:this.joinTokenText(E,t)}},{sourceLanguage:t,patternId:`${n}-${t}-trailing-guard`,confidence:.85}),...v]:n&&E&&E.length>0&&v.length===0?[ee(n,{condition:{type:"expression",raw:this.joinTokenText(E,t)}},{sourceLanguage:t,patternId:`${n}-${t}-trailing-guard`,confidence:.85})]:v}tryAttachTrailingDuration(e,r){let t=r.roles;if(t.has("duration")||!re(r.action)?.roles.some(o=>o.role==="duration"&&!o.required))return;let a=e.peek();!a||!/^\d+(?:\.\d+)?(?:ms|s|m|h)$/.test(a.value)||(t.set("duration",W(a.value,"duration")),e.advance());}tryAttachTrailingRole(e,r,t){let n=re(r.action);if(!n)return;let a=P(t);if(!a)return;let o=r.roles,u=(l,c)=>{if(!l)return false;if(l.kind==="selector")return true;let m=(l.normalized??l.value).toLowerCase();return Er.has(m)?false:m==="body"||m==="it"||m==="you"||m==="result"||m==="document"||m==="window"||this.boundIdentifiers.has(l.value)?true:c?false:l.kind==="identifier"||l.kind==="reference"},s=[{role:"source",strict:false},{role:"destination",strict:true}];for(let{role:l,strict:c}of s){if(!n.roles.some(E=>E.role===l))continue;let m=a.roleMarkers?.[l];if(!m)continue;let d=o.get(l);if(d&&!(d.type==="reference"&&d.value==="me"))continue;let p=E=>{if(!E||E.kind!=="particle"&&E.kind!=="keyword")return false;let y=E.value.toLowerCase();return m.primary?.toLowerCase()===y?true:c?false:(E.normalized??"").toLowerCase()===l?true:!!m.alternatives?.some(h=>h.toLowerCase()===y)},f=e.peek(),v=e.peek(1);if(!f||!v)return;if(c&&m.position==="after"){let E=e.peek(2),y=(f.normalized??f.value).toLowerCase();if(Ou.has(y)&&v.kind==="selector"&&p(E)){o.set(l,{type:"expression",raw:`${y} ${v.value}`}),e.advance(),e.advance(),e.advance();return}}if(m.position==="after"){if(u(f,c)&&p(v)){let E=this.tokenToSemanticValue(f);e.advance(),e.advance(),E&&o.set(l,E);return}if(c&&u(f,c)){let E=e.peek(2),y=e.peek(3);if((v.normalized??v.value).toLowerCase()==="in"&&E&&!p(E)&&p(y)){let h=this.tokenToSemanticValue(f);e.advance(),e.advance(),e.advance(),e.advance(),h&&o.set(l,h);return}}}else if(p(f)&&u(v,c)){e.advance();let E=this.tokenToSemanticValue(e.advance());E&&o.set(l,E);return}}}tryAttachTrailingStyle(e,r,t){if(r.action!=="fetch"&&r.action!=="render")return;let n=r.roles;if(!re(r.action)?.roles.some(y=>y.role==="style"))return;let o=n.get("style");if(o){if(o.type==="expression"&&typeof o.raw=="string"&&/^[A-Za-z_][\w-]*$/.test(o.raw)&&e.peek()?.value===":"){let y=We(e,o.raw);y&&n.set("style",{type:"expression",raw:y});}this.tryAttachResponseTypeAfterStyle(e,r,t);return}if(r.action==="fetch"){let y=n.get("patient"),h=n.get("source");if(y&&h&&(y.type==="literal"||y.type==="expression")&&h.type==="expression"&&typeof h.raw=="string"&&/^[A-Za-z_][\w-]*$/.test(h.raw)&&e.peek()?.value===":"){let z=We(e,h.raw);z&&(n.set("source",{type:"expression",raw:z}),this.tryAttachResponseTypeAfterStyle(e,r,t));return}}let s=P(t)?.roleMarkers?.style;if(!s)return;if(s.position==="before"){let y=new Set([s.primary,...s.alternatives??[]].map(D=>D.toLowerCase())),h=e.peek();if(!h||!y.has(h.value.toLowerCase()))return;let z=e.mark();e.advance();let A=We(e);if(!A){e.reset(z);return}n.set("style",{type:"expression",raw:A}),this.tryAttachResponseTypeAfterStyle(e,r,t);return}if(s.position!=="after")return;let l=new Set([s.primary,...s.alternatives??[]].map(y=>y.toLowerCase())),c=y=>y.kind==="conjunction"||y.kind==="keyword"&&(this.isThenKeyword(y.value,t)||this.isEndKeyword(y.value,t)),m=24,d=-1,p=0;for(let y=0;y<m;y++){let h=e.peek(y);if(!h||c(h))break;if(h.value==="("||h.value==="{"?p++:(h.value===")"||h.value==="}")&&(p=Math.max(0,p-1)),p===0&&(h.kind==="particle"||h.kind==="keyword")&&l.has(h.value.toLowerCase())){d=y;break}}if(d<=0)return;let f=[];for(let y=0;y<d;y++){let h=e.peek(y);h&&f.push(h);}if(f.length===1&&x.RESPONSE_TYPE_WORDS.has(f[0].value.toLowerCase()))return;let v=new ie(f,t),E=We(v);n.set("style",{type:"expression",raw:E&&v.isAtEnd()?E:this.joinTokenText(f,t)});for(let y=0;y<=d;y++)e.advance();this.tryAttachResponseTypeAfterStyle(e,r,t);}tryAttachResponseTypeAfterStyle(e,r,t){let n=r.roles;if(n.has("responseType")||!re(r.action)?.roles.some(c=>c.role==="responseType"&&!c.required))return;let o=c=>!!c&&x.RESPONSE_TYPE_WORDS.has(c.toLowerCase()),u=e.peek();if(!u)return;let s=c=>{n.set("responseType",{type:"expression",raw:c});};if(x.AS_MARKERS_BEFORE[t]?.some(c=>u.value.toLowerCase()===c)){let c=e.peek(1);c&&o(c.value)&&(e.advance(),e.advance(),s(c.value));return}if(o(u.value)){e.advance(),s(u.value);for(let c of x.AS_MARKERS_AFTER[t]??[])if(c.every((m,d)=>e.peek(d)?.value.toLowerCase()===m)){for(let m=0;m<c.length;m++)e.advance();break}}}tryAttachTrailingExpressionRole(e,r,t){let n=r.action,a=n==="js"?{role:"patient",terminator:"boundary"}:n==="go"||n==="scroll"?{role:"destination",terminator:"destination-marker"}:null;if(!a)return;let o=r.roles,u=o.get(a.role);if(n==="go"&&u&&u.type==="expression"&&String(u.raw).toLowerCase()==="url"){let y=e.peek();if(y&&!Er.has((y.normalized??y.value).toLowerCase())){let z=this.tokenToSemanticValue(y);if(z.type==="literal"||z.type==="selector"){o.set(a.role,z),o.set("method",{type:"literal",value:"url"}),e.advance();return}}let h=o.get("patient");if(h&&(h.type==="literal"||h.type==="selector")){o.set(a.role,h),o.set("method",{type:"literal",value:"url"}),o.delete("patient");return}}if(n==="go"&&u&&u.type==="expression"){let y=/^url\s+(\S+)$/i.exec(String(u.raw??""));if(y){let h=y[1].replace(/^["']|["']$/g,"");o.set(a.role,{type:"literal",value:h,dataType:"string"}),o.set("method",{type:"literal",value:"url"});return}}if(n==="go"&&!u){let y=o.get("patient");if(y&&y.type==="expression"&&String(y.raw).toLowerCase()==="url"){let h=e.peek();if(h&&!Er.has((h.normalized??h.value).toLowerCase())){let z=this.tokenToSemanticValue(h);if(z.type==="literal"||z.type==="selector"){o.set(a.role,z),o.set("method",{type:"literal",value:"url"}),o.delete("patient"),e.advance();return}}}}if(u&&!(u.type==="reference"&&u.value==="me"))return;let s=P(t);if(!s)return;let l=null;if(a.terminator==="destination-marker"){let y=s.roleMarkers?.destination;if(!y||y.position!=="after")return;l=y.primary.toLowerCase();}let c=y=>y.kind==="conjunction"||y.kind==="keyword"&&(this.isThenKeyword(y.value,t)||this.isEndKeyword(y.value,t)),m=24,d=[],p=0,f=false;for(let y=0;y<m;y++){let h=e.peek(y);if(!h||c(h))break;if(h.value==="("||h.value==="{"?p++:(h.value===")"||h.value==="}")&&(p=Math.max(0,p-1)),l!==null&&p===0&&(h.kind==="particle"||h.kind==="keyword")&&h.value.toLowerCase()===l){f=true;break}d.push(h);}if(d.length===0||l!==null&&!f)return;let v=d.length+(f?1:0);if(n==="go"&&d.length===2&&d[0].value.toLowerCase()==="url"){let y=this.tokenToSemanticValue(d[1]);if(y.type==="literal"||y.type==="selector"){o.set(a.role,y),o.set("method",{type:"literal",value:"url"});let h=o.get("patient");h&&h.type==="reference"&&h.value==="me"&&!re(n)?.roles.some(z=>z.role==="patient")&&o.delete("patient");for(let z=0;z<v;z++)e.advance();return}}let E=d;if(n==="js"){let y=s.keywords?.js,h=A=>[y?.primary,...y?.alternatives??[]].some(D=>!!D&&D.length>A.value.length&&D.includes(A.value)),z=0;for(;z<E.length&&h(E[z]);)z++;if(E=E.slice(z),E.length===0)return}if(o.set(a.role,{type:"expression",raw:this.joinTokenText(E,t)}),a.role!=="patient"){let y=o.get("patient");y&&y.type==="reference"&&y.value==="me"&&!re(n)?.roles.some(h=>h.role==="patient")&&o.delete("patient");}for(let y=0;y<v;y++)e.advance();}static buildVerbLookup(e){let r=new Map;for(let[t,n]of Object.entries(e.keywords))if(!["on","if","else","when","where","while","end","then","and"].includes(t)&&(r.set(n.primary.toLowerCase(),t),n.alternatives))for(let a of n.alternatives)r.set(a.toLowerCase(),t);return r}static buildMarkerToRoleLookup(e){let r=new Map;for(let[t,n]of Object.entries(e.roleMarkers)){if(!n)continue;if((t!=="event"||!r.has(n.primary))&&r.set(n.primary,t),n.alternatives)for(let o of n.alternatives)r.has(o)||r.set(o,t);}return r}parseSOVClauseByVerbAnchoring(e,r){let t=P(r);if(!t||t.wordOrder!=="SOV")return [];let n=x.buildVerbLookup(t),a=x.buildMarkerToRoleLookup(t),o=[],u=0;for(;u<e.length;){let s=-1,l="";for(let f=u;f<e.length;f++){let v=e[f];if(a.has(v.value))continue;let E=n.get(v.value.toLowerCase()),y=v.normalized?n.get(v.normalized.toLowerCase()):void 0,h=E||y;if(h){s=f,l=h;break}}if(s===-1)break;let c=e.slice(u,s),m=e.length;for(let f=s+1;f<e.length;f++){let v=e[f];if(v.kind==="conjunction"||this.isThenKeyword(v.value,r)){m=f;break}if(f>s+1&&!a.has(v.value)&&(n.get(v.value.toLowerCase())||(v.normalized?n.get(v.normalized.toLowerCase()):void 0))){m=f;break}}let d=e.slice(s+1,m),p=this.extractRolesFromMarkedTokens(c,d,a,l,r);if(o.push(ee(l,p,{sourceLanguage:r,confidence:.7})),u=m,u<e.length){let f=e[u];(f.kind==="conjunction"||this.isThenKeyword(f.value,r))&&u++;}}return o}extractRolesFromMarkedTokens(e,r,t,n,a){let o={},u=(l,c)=>{let m=this.isEndKeyword(l.value,a),d=l.kind==="keyword"&&(l.normalized??"").toLowerCase()==="end";return !m&&!d?false:l.metadata?.closesTrackedBlock===true||m?true:!(c&&c.kind==="selector")},s=l=>{let c=[];for(let m=0;m<l.length;m++){let d=l[m];if(u(d,l[m+1]))continue;let p=t.get(d.value);if(p&&d.kind==="particle"&&c.length>0){let f=this.tokensToSemanticValue(c,a);if(f){let v=this.mapRoleForCommand(p,n,o);v&&(o[v]=f);}c=[];}else c.push(d);}if(c.length>0)if(c.length===1&&/^\d+(\.\d+)?(ms|s)$/i.test(c[0].value)&&!o.duration&&re(n)?.roles.some(d=>d.role==="duration"))o.duration={type:"literal",value:c[0].value,dataType:"string"};else {let d=this.tokensToSemanticValue(c,a);d&&(o.patient?o.destination||(o.destination=d):o.patient=d);}};return s(e),s(r),o}mapRoleForCommand(e,r,t){return r==="set"&&(e==="patient"?e="destination":e==="destination"&&(e="patient")),t[e]?e==="patient"&&!t.destination?"destination":e==="destination"&&!t.patient?"patient":e==="source"&&!t.source?"source":null:e}tokensToSemanticValue(e,r){if(e.length===0)return null;let t=e.filter(o=>o.kind!=="whitespace");if(t.length===0)return null;if(t.length>=2&&(t[0].kind==="selector"||/^[#.@*<]/.test(t[0].value))){let o=t.findIndex((u,s)=>s>0&&(u.normalized??u.value).toLowerCase()==="in");o>0&&(t=t.slice(0,o));}if(t.length===1)return this.tokenToSemanticValue(t[0]);let n=t.map(o=>o.value).join(""),a=t[0];return a.kind==="selector"||a.value.startsWith("#")||a.value.startsWith(".")||a.value.startsWith("@")||a.value.startsWith("*")?ve(n):a.kind==="literal"||a.value.startsWith('"')||a.value.startsWith("'")?W(vt(n),"string"):a.kind==="reference"?ue(n):W(this.joinTokenText(t,r))}tokenToSemanticValue(e){let r=e.value;if(e.kind==="selector"||r.startsWith("#")||r.startsWith(".")||r.startsWith("@")||r.startsWith("*"))return ve(r);if(r.startsWith('"')||r.startsWith("'"))return W(vt(r),"string");if(/^-?\d+(\.\d+)?$/.test(r))return W(parseFloat(r));if(r==="true"||r==="\u771F"||r==="\uCC38"||r==="do\u011Fru")return W(true);if(r==="false"||r==="\u507D"||r==="\uAC70\uC9D3"||r==="yanl\u0131\u015F")return W(false);if(r.length>1&&(r.startsWith(":")||r.startsWith("$")))return ue(r);let t=e.normalized?.toLowerCase();return t==="me"||t==="it"||t==="you"||t==="result"||t==="body"?ue(t):e.kind==="reference"?ue(e.normalized||"me"):W(r)}parseBodyWithGrammarPatterns(e,r,t,n){let a=[],o=[],u=false,s=()=>{if(!u&&o.length>0){let m=this.parseSOVClauseByVerbAnchoring(o,n);a.push(...m),m.length===0&&this.recordDroppedTokens(o,n,"fused body walk");}else o.length>0&&this.recordDroppedTokens(o,n,"fused body walk");o=[],u=false;},l=0,c=()=>{let m=0;for(let d of a){let p=d;(p.action==="for"||p.action==="repeat"||p.action==="while")&&(!Array.isArray(p.body)||p.body.length===0)&&m++;}return m-l};for(;!e.isAtEnd();){let m=e.peek();if(m&&this.isThenKeyword(m.value,n)){s(),e.advance();continue}if(m&&this.isEndKeyword(m.value,n)){let p=e.peek(-1),f=e.peek(1);if(!nt(n,m.value,p?.value,f?.value)){if(s(),c()>0){l++,e.advance();continue}e.advance();break}}if(m&&!u&&this.isIfKeyword((m.normalized??m.value).toLowerCase(),n)){s();let p=this.tryParseConditionalBlock(e,r,n);if(p){a.push(p),u=true;continue}}let d=false;if(t.length>0){let p=oe.matchBest(e,t);if(p){let f=p.pattern.command,v={};for(let[h,z]of p.captured)h!=="event"&&h!=="action"&&h!=="continues"&&(v[h]=z);let E=ee(f,v,{sourceLanguage:n,patternId:p.pattern.id});a.push(E),d=true,u=true;let y=p.captured.get("continues");if(y&&y.type==="literal"&&y.value==="then")continue}}if(!d){let p=e.mark(),f=oe.matchBest(e,r);if(f){if(f.pattern.command==="if"){let E=e.mark();for(e.reset(p);!e.isAtEnd();){let h=e.peek();if(!h||this.isIfKeyword((h.normalized??h.value).toLowerCase(),n))break;e.advance();}let y=this.tryParseConditionalBlock(e,r,n);if(y){s(),a.push(y),u=true;continue}e.reset(E);}let v=this.buildCommand(f,n);a.push(v),this.tryAttachTrailingRole(e,v,n),d=true,u=true;}}d||(m&&o.push(m),e.advance());}s(),e.isAtEnd()||this.recordDroppedTokens(e.tokens.slice(e.position()),n,"fused body walk");for(let m=a.length-1;m>=0;m--){let d=a[m];d.kind==="command"&&d.action==="for"&&(!(d.roles instanceof Map)||d.roles.size===0)&&(!Array.isArray(d.body)||d.body.length===0)&&a.splice(m,1);}return a}tryCompoundCommandParsing(e,r,t){let n=e.tokens,a=n.some(c=>c.kind==="conjunction"||c.kind==="keyword"&&this.isThenKeyword(c.value,t)),o=n.some(c=>this.isElseKeyword(c.value,t));if(!a&&!o)return null;let u=new ie(n,t),s=this.coverageMark(),l=this.parseBodyWithClauses(u,r,t);return l.length===0?(this.coverageRollback(s),null):l[0]}static isEnEventKeyword(e){if(typeof e!="string")return false;let r=e.toLowerCase(),t=x.enEventKeywordCache.get(r);if(t!==void 0)return t;let n=false;try{let a=Y(r,"en").tokens;n=a.length===1&&a[0]?.kind==="keyword";}catch{n=false;}return x.enEventKeywordCache.set(r,n),n}matchEventMarkerPhrase(e,r,t){let n=x.SOV_EVENT_MARKER_PHRASES[t];if(!n)return 0;for(let a of n)if(a.every((o,u)=>e[r+u]?.value===o))return a.length;return 0}hasSOVEventMarkerHead(e,r){let t=x.SOV_EVENT_MARKERS[r];if(t===void 0)return false;let{tokens:n}=Y(e,r),a=he[r],o=new Set;if(a)for(let u of Object.keys(a))o.add(u.toLowerCase());for(let u=0;u<n.length;u++){let s=n[u],l=s.value.toLowerCase(),c=s.normalized?.toLowerCase();if(!(!!c&&(x.KNOWN_EVENTS.has(c)||Be.has(c))||x.KNOWN_EVENTS.has(l)||Be.has(l)||o.has(l)))continue;let d=this.matchEventParamPhrase(n,u+1).len,p=n[u+1+d];if(p&&(p.kind==="particle"||p.kind==="keyword")&&t.has(p.value)||this.matchEventMarkerPhrase(n,u+1+d,r)>0)return true}return false}matchEventParamPhrase(e,r){if(e[r]?.value!=="(")return {len:0,names:[]};let t=[];for(let n=r+1;n<e.length;n++){let a=e[n].value;if(a===")")return {len:n-r+1,names:t};if(a!==","){if(e[n].kind!=="identifier")break;t.push(a);}}return {len:0,names:[]}}isStrippableSourceRef(e,r){if(!e)return false;let t=e.normalized?.toLowerCase();if(e.kind==="keyword"&&(t==="me"||t==="i"||t==="it"))return true;let n=e.value.toLowerCase();return r.has(n)||!!t&&r.has(t)}tryTrailingEventExtraction(e,r,t){let n=Y(e,r).tokens;if(n.length<3)return null;let a=he[r],o=new Set;if(a)for(let A of Object.keys(a))o.add(A.toLowerCase());let u=n.length-2,s=n[u];if(!(s.kind==="keyword"&&s.normalized?.toLowerCase()==="on"))return null;let c=n[n.length-1],m=c.value.toLowerCase(),d=c.normalized?.toLowerCase();if(!(!!d&&x.KNOWN_EVENTS.has(d)||x.KNOWN_EVENTS.has(m)||o.has(m)))return null;let f=d&&x.KNOWN_EVENTS.has(d)?d:a?.[m]??m,v=n.slice(0,u);if(v.length===0)return null;let E=t.filter(A=>A.command!=="on"),y=new ie(v,r),h=this.coverageMark(),z=this.parseBodyWithClauses(y,E,r);return z.length===0?(this.coverageRollback(h),null):$e({type:"literal",value:f},z,void 0,{sourceLanguage:r,confidence:.75})}tryMidStreamEventExtraction(e,r,t){let n=Y(e,r).tokens;if(n.length<3)return null;let a=he[r],o=new Set;if(a)for(let u of Object.keys(a))o.add(u.toLowerCase());for(let u=0;u<n.length-1;u++){let s=n[u];if(!(s.kind==="keyword"&&s.normalized?.toLowerCase()==="on"))continue;let c=n[u+1],m=c.value.toLowerCase(),d=c.normalized?.toLowerCase();if(!(!!d&&x.KNOWN_EVENTS.has(d)||x.KNOWN_EVENTS.has(m)||o.has(m)))continue;let f=d&&x.KNOWN_EVENTS.has(d)?d:a?.[m]??m,v=n.filter((A,D)=>D!==u&&D!==u+1);if(v.length===0)return null;let E=t.filter(A=>A.command!=="on"),y=new ie(v,r),h=this.coverageMark(),z=this.parseBodyWithClauses(y,E,r);return z.length===0?(this.coverageRollback(h),null):$e({type:"literal",value:f},z,void 0,{sourceLanguage:r,confidence:.75})}return null}trySOVEventExtraction(e,r,t){let n=x.SOV_EVENT_MARKERS[r];if(!n)return null;let o=Y(e,r).tokens,u=he[r],s=new Set;if(u)for(let b of Object.keys(u))s.add(b.toLowerCase());let l=x.SOV_SOURCE_MARKERS[r],c=-1,m="",d="",p=1,f=[];for(let b=0;b<o.length;b++){let g=o[b],w=g.value.toLowerCase(),B=w,C="",k=w.indexOf("[");k>0&&(B=w.slice(0,k),C=g.value.slice(k));let S=g.normalized?.toLowerCase(),R=S&&(x.KNOWN_EVENTS.has(S)||Be.has(S)),T=s.has(w)||s.has(B),O=x.KNOWN_EVENTS.has(B)||Be.has(B);if(R||T||O){let N=o[b-1];if(N&&(N.normalized??N.value).toLowerCase()==="event")continue;let I;R?I=S:T?I=u?.[w]??u?.[B]??B:I=B;let j=this.matchEventParamPhrase(o,b+1);if(n.size>0){let L=1+j.len,Z=o[b+L];Z&&Z.kind==="selector"&&Z.value.startsWith("[")&&(L+=1);let J=o[b+L];if(J&&(J.kind==="particle"||J.kind==="keyword")&&n.has(J.value)){c=b,m=I,d=C||(L===j.len+2?o[b+L-1].value:""),p=L+1,f=j.names;break}}else {c=b,m=I,d=C,p=1+j.len+this.matchEventMarkerPhrase(o,b+1+j.len,r),f=j.names;break}}}if(c===-1){let b=new Set(t.filter(g=>g.command!=="on").map(g=>g.command));for(let g=0;g<o.length;g++){let w=o[g];if(w.kind==="identifier")if(n.size>0){let B=1,C=o[g+1];C&&C.kind==="selector"&&C.value.startsWith("[")&&(B=2);let k=o[g+B];if(k&&(k.kind==="particle"||k.kind==="keyword")&&n.has(k.value)){c=g,m=w.value,d=B===2?o[g+1].value:"",p=B+1;break}}else {let B=this.matchEventMarkerPhrase(o,g+1,r);if(B>0){c=g,m=w.value,d="",p=1+B;break}let C=o[g+1];if(C&&C.kind==="keyword"&&C.normalized!=null&&b.has(C.normalized)){c=g,m=w.value,d="",p=1;break}}}}if(c===-1)return null;let v=new Set;for(let b=c;b<c+p;b++)v.add(b);if(l){let b=c+p;if(b<o.length){let g=o[b];if((g.kind==="particle"||g.kind==="keyword")&&l.markers.has(g.value))v.add(b);else if(this.isStrippableSourceRef(g,l.windowTokens)){let w=o[b+1];w&&(w.kind==="particle"||w.kind==="keyword")&&l.markers.has(w.value)&&(v.add(b),v.add(b+1));}}if(c>=2){let g=o[c-1];(g.kind==="particle"||g.kind==="keyword")&&l.markers.has(g.value)&&this.isStrippableSourceRef(o[c-2],l.windowTokens)&&(v.add(c-2),v.add(c-1));}for(let g=0;g<c;g++){let w=o[g],B=w.value.toLowerCase(),C=w.normalized?.toLowerCase();if(l.windowTokens.has(B)||C&&l.windowTokens.has(C)){v.add(g);break}}}let E=o.filter((b,g)=>!v.has(g));if(E.length===0)return null;let y=t.filter(b=>b.command!=="on"),h=new ie(E,r),z=this.coverageMark(),A=this.parseBodyWithClauses(h,y,r);if(A.length===0)return this.coverageRollback(z),null;let D={sourceLanguage:r,confidence:.75};return d&&(D.keyFilter=d),$e(x.isEnEventKeyword(m)?{type:"literal",value:m}:{type:"expression",raw:m},A,void 0,D,f)}profileKeywordMatches(e,r,t){let n=P(e)?.keywords?.[r];return n?n.primary?.toLowerCase()===t?true:!!n.alternatives?.some(a=>a.toLowerCase()===t):false}consumeForPostposition(e,r){let t=e.peek();if(!t)return;let n=(t.normalized??"").toLowerCase(),a=P(r)?.keywords?.for;(n==="for"||t.value===a?.primary||(a?.alternatives??[]).includes(t.value))&&e.advance();}isThenKeyword(e,r){let t=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"])}[r];return a?a.has(t):t==="then"||this.profileKeywordMatches(r,"then",t)}isElseKeyword(e,r){let t=e.toLowerCase();return t==="else"?true:this.profileKeywordMatches(r,"else",t)}isEndKeyword(e,r){let t=e.toLowerCase(),n=xo(r);return n?t==="end"||n.has(t):t==="end"||this.profileKeywordMatches(r,"end",t)}isJsKeyword(e){let r=(e.normalized??e.value).toLowerCase();return r==="js"||this.profileKeywordMatches("en","js",r)}isPatientMarker(e,r){let t=P(r)?.roleMarkers?.patient;if(!t?.primary)return false;let n=e.value.toLowerCase();return t.primary.toLowerCase()===n?true:!!t.alternatives?.some(a=>a.toLowerCase()===n)}isJsBlockTerminator(e,r){return this.isEndKeyword(e,r)||this.profileKeywordMatches(r,"end",e.toLowerCase())}consumeVerbFinalJsBlock(e,r){let t=e.mark(),n=0,a=-1;for(;;){let c=e.peek(n);if(!c||this.isThenKeyword(c.value,r)||this.isJsBlockTerminator(c.value,r))break;if(this.isJsKeyword(c)){let m=e.peek(n+1),d=!!m&&c.position?.end!==void 0&&c.position.end===m.position?.start&&this.profileKeywordMatches(r,"js",`${c.value}${m.value}`.toLowerCase()),p=e.peek(n+(d?2:1));if(n>0&&p&&this.isJsBlockTerminator(p.value,r)){a=n;break}}n++;}if(a<=0)return null;let o=[];for(let c=0;c<a;c++){let m=e.peek(c);m&&o.push(m);}let u=o[o.length-1];if(u&&this.isPatientMarker(u,r)&&o.pop(),o.length===0)return e.reset(t),null;let s=this.rawJsBody(o);for(let c=0;c<a;c++)e.advance();e.advance();let l=e.peek();return l&&!this.isJsBlockTerminator(l.value,r)&&e.advance(),e.advance(),ee("js",{patient:{type:"expression",raw:s||"()"}},{sourceLanguage:r,patternId:`js-opaque-final-${r}`,confidence:1})}consumeJsBlock(e,r){let t=e.peek();if(!t||!this.isJsKeyword(t))return null;let n=e.mark(),a=[];e.advance();let o=e.peek();o&&t.position?.end!==void 0&&t.position.end===o.position?.start&&this.profileKeywordMatches(r,"js",`${t.value}${o.value}`.toLowerCase())&&e.advance();let u=e.peek();u&&this.isPatientMarker(u,r)&&e.advance();let s=false;for(;!e.isAtEnd();){let c=e.peek();if(!c)break;if(e.advance(),this.isJsBlockTerminator(c.value,r)){s=true;break}a.push(c);}if(!s)return e.reset(n),null;let l=this.rawJsBody(a);return ee("js",{patient:{type:"expression",raw:l||"()"}},{sourceLanguage:r,patternId:`js-opaque-${r}`,confidence:1})}rawJsBody(e){if(e.length===0)return "";let r=e[0].position?.start,t=e[e.length-1].position?.end,n=this.positionSource;if(n!==void 0&&r!==void 0&&t!==void 0){let o=n.slice(r,t),u=s=>s.replace(/\s+/g,"");if(u(o)===u(e.map(s=>s.value).join("")))return o.trim()}let a="";for(let o=0;o<e.length;o++){let u=e[o-1],s=u?.position?.end!==void 0&&e[o].position?.start===u.position.end;o>0&&!s&&(a+=" "),a+=e[o].value;}return a.trim()}isIfKeyword(e,r){let t=e.toLowerCase();return t==="if"?true:this.profileKeywordMatches(r,"if",t)}isUnlessKeyword(e,r){let t=e.toLowerCase();return t==="unless"?true:this.profileKeywordMatches(r,"unless",t)}tryParseUnlessGuard(e,r,t){let n=e.peek();if(!n||!this.isUnlessKeyword((n.normalized??n.value).toLowerCase(),t))return null;let a=e.mark(),o=this.tryParseConditionalBlock(e,r,t,true);if(!o||o.kind!=="conditional")return e.reset(a),null;let u=o;if(u.elseBranch&&u.elseBranch.length>0)return e.reset(a),null;let s=u.roles.get("condition");return s?[ee("unless",{condition:s},{sourceLanguage:t,patternId:`unless-${t}-guard`,confidence:1}),...u.thenBranch]:(e.reset(a),null)}isBlockEndToken(e,r,t){return this.isEndKeyword(e.value,t)?true:e.kind!=="keyword"||(e.normalized??"").toLowerCase()!=="end"?false:!(r&&r.kind==="selector")}tryParseConditionalBlock(e,r,t,n=false){let a=e.peek();if(!a)return null;let o=(a.normalized??a.value).toLowerCase();if(!this.isIfKeyword(o,t)&&!(n&&this.isUnlessKeyword(o,t)))return null;let u=e.mark(),s=this.coverageMark();e.advance();let l=[],c=0;for(;!e.isAtEnd();){let w=e.peek();if(!w)break;let B=(w.normalized??w.value).toLowerCase();if(this.isIfKeyword(B,t)||this.isUnlessKeyword(B,t)){c++,l.push(w),e.advance();continue}if(this.isBlockEndToken(w,e.peek(1)??void 0,t)){if(c===0){e.advance();break}c--,l.push(w),e.advance();continue}l.push(w),e.advance();}if(l.length===0)return e.reset(u),this.coverageRollback(s),null;let m=P(t),d=m?.wordOrder==="SOV"?x.buildVerbLookup(m):null,p=0,f=0,v=[];for(;p<l.length;p++){let w=l[p],B=(w.normalized??w.value).toLowerCase();if(this.isIfKeyword(B,t)||this.isUnlessKeyword(B,t)?f++:this.isBlockEndToken(w,l[p+1],t)&&f--,f===0&&this.isThenKeyword(w.value,t)){p++;break}if(f===0&&v.length>0){let C=(l[p-1].normalized??l[p-1].value).toLowerCase(),k=l[p-1].value.toLowerCase(),S=(w.normalized??w.value).toLowerCase(),R=x.CONDITION_COPULAS.has(C)||x.CONDITION_COPULAS_SURFACE.has(k)&&x.CONDITION_PREDICATES.has(S),T=d!==null&&d.has(w.value.toLowerCase())&&!x.CONDITION_PREDICATES.has(S),O=/^\.[a-zA-Z_]\w*$/.test(w.value)&&l[p-1].position?.end!==void 0&&w.position?.start!==void 0&&l[p-1].position.end===w.position.start;if(!x.CONDITION_OPERATORS.has(S)&&!O&&(!R||T)&&(this.tokensBeginCommand(l.slice(p),r,t)||this.sovCommandStartsAt(l.slice(p),d)))break}v.push(w);}if(v.length===0)return e.reset(u),this.coverageRollback(s),null;let y=[],h=[],z=false,A=0;for(;p<l.length;p++){let w=l[p],B=(w.normalized??w.value).toLowerCase();if(this.isIfKeyword(B,t)||this.isUnlessKeyword(B,t)?A++:this.isBlockEndToken(w,l[p+1],t)&&A--,A===0&&!z&&this.isElseKeyword(w.value,t)){z=true;continue}(z?h:y).push(w);}let D={type:"expression",raw:this.joinTokenText(v,t)},b=this.parseBranch(y,r,t),g=h.length>0?this.parseBranch(h,r,t):void 0;return b.length===0&&(!g||g.length===0)?(e.reset(u),this.coverageRollback(s),null):co(D,b,g,{sourceLanguage:t,patternId:`conditional-${t}-folded`,confidence:1})}joinTokenText(e,r){return xe(e,P(r))}tokensBeginCommand(e,r,t){if(e.length===0)return false;let n=new ie(e,t);return oe.matchBest(n,r)!==null}sovCommandStartsAt(e,r){if(!r)return false;let t=u=>r.has(u.value.toLowerCase())||!!u.normalized&&r.has(u.normalized.toLowerCase()),n=u=>u.kind==="identifier"||u.kind==="selector"||u.kind==="literal"||u.kind==="reference",a=0,o=0;for(;a+1<e.length;){let u=e[a],s=e[a+1];if(!n(u)||s.kind!=="particle")break;o+=1,a+=2;let l=e[a];if(o>=1&&l&&t(l))return true}return false}parseBranch(e,r,t){if(e.length===0)return [];let n=new ie(e,t),a=this.parseBodyWithClauses(n,r,t);return a.length===1&&a[0]?.kind==="compound"?a[0].statements:a}extractStandaloneModifiers(e,r){let n=Y(e,r).tokens;if(n.length===0)return {modifiers:null,remainingInput:null};let o=n[0].value.toLowerCase(),u=x.STANDALONE_MODIFIERS[o];if(!u)return {modifiers:null,remainingInput:null};let s={},l=1;if(u==="once")s.once=true;else {let p=1;if(p<n.length){let f=n[p],v=n[p+1],E=f.kind==="identifier"&&v?.kind==="literal"&&/^\d+(ms|s|m)?$/.test(v.value);(f.kind==="keyword"||f.kind==="particle"||E)&&(p++,l++);}if(p<n.length){let f=n[p];if(f.kind==="literal"){let v=f.value.match(/^(\d+)(ms|s|m)?$/);if(v){let E=parseInt(v[1],10),y=v[2]||"ms";y==="s"?E*=1e3:y==="m"&&(E*=6e4),s[u]=E,l=p+1;}}}s[u]||(s[u]=u==="debounce"?300:100);}let c=n.slice(l);if(c.length===0)return {modifiers:null,remainingInput:null};let m=c[0].position.start,d=e.slice(m);return {modifiers:s,remainingInput:d}}stripAsyncModifier(e,r){let t=P(r)?.keywords?.async,n=new Set(["async"]);t?.primary&&n.add(t.primary.toLowerCase()),t?.alternatives?.forEach(l=>n.add(l.toLowerCase()));let a=Y(e,r).tokens,o=a.findIndex(l=>n.has(l.value.toLowerCase()));if(o===-1)return {remainingInput:null};let u=a[o],s=(e.slice(0,u.position.start)+e.slice(u.position.end)).replace(/\s{2,}/g," ").trim();return s.length===0?{remainingInput:null}:{remainingInput:s}}stripDoNotThrowModifier(e,r){let t=Y(e,r).tokens;for(let n=0;n<t.length-1;n++){if(t[n].value.toLowerCase()!=="do")continue;let a=-1;for(let l=n+1;l<=n+5&&l<t.length;l++){let c=t[l];if(c.normalized?.toLowerCase()==="throw"){a=l;break}let m=c.kind;if(m==="selector"||m==="literal"||m==="reference"||m==="conjunction")break}if(a===-1)continue;let o=t[n].position.start,u=t[a].position.end,s=(e.slice(0,o)+e.slice(u)).replace(/\s{2,}/g," ").trim();return s.length===0?{remainingInput:null}:{remainingInput:s}}return {remainingInput:null}}static droppedTokenCount(e){return (e.diagnostics??[]).filter(r=>r.code==="unconsumed-input").reduce((r,t)=>r+(parseInt(/left (\d+) token/.exec(t.message)?.[1]??"0",10)||0),0)}static unconsumedSpans(e){return (e.diagnostics??[]).filter(r=>r.code==="unconsumed-input").map(r=>/unconsumed: "(.*)"$/.exec(r.message)?.[1]).filter(r=>!!r).map(r=>r.replace(/\s+/g," ").trim())}static withoutSpanDiagnostics(e,r){return {...e,diagnostics:(e.diagnostics??[]).filter(t=>{if(t.code!=="unconsumed-input")return true;let n=/unconsumed: "(.*)"$/.exec(t.message)?.[1];return !n||n.replace(/\s+/g," ").trim()!==r})}}reclaimDanglingFromTail(e,r,t){let n=x.droppedTokenCount,a=x.unconsumedSpans(e);if(a.length===0)return null;let o=n(e),u=P(t)?.roleMarkers?.source,s=new Set;u?.primary&&s.add(u.primary),u?.alternatives?.forEach(c=>s.add(c));let l=Y(r,t).tokens;for(let c=0;c<l.length;c++){let m=l[c];if(m.normalized!=="source"&&!s.has(m.value))continue;let d=u?.position==="after"?c-1:c+1,p=l[d];if(!p||p.kind!=="identifier"&&p.kind!=="keyword")continue;let f=Math.min(m.position.start,p.position.start),v=Math.max(m.position.end,p.position.end),E=r.slice(f,v).replace(/\s+/g," ").trim();if(!a.some(h=>h===E||h.includes(E)))continue;let y=(r.slice(0,f).trimEnd()+" "+r.slice(v).trimStart()).trim();if(!(!y||y===r))try{let h=this.parse(y,t);if(!h||h.kind!=="event-handler")continue;let z=gr(h);if(n(z)<o)return {node:{...z,eventModifiers:{...z.eventModifiers,from:{type:"literal",value:p.value,dataType:"string"}}},input:y}}catch{}}return null}reclaimEventCompoundTail(e,r,t){let n=x.unconsumedSpans(e);if(n.length===0)return null;let a=he[t];if(!a)return null;let o=e.roles,u=o.get("event"),s=u?.type==="literal"&&typeof u.value=="string"?u.value:null;if(!s)return null;let l=m=>m.replace(/\s+/g," ").trim(),c=Y(r,t).tokens;for(let m of n)for(let d=1;d<c.length;d++)for(let p=d;p<c.length;p++){let f=l(r.slice(c[d].position.start,c[p].position.end));if(f.length>m.length)break;if(f!==m)continue;let v=c[d-1];if((a[v.value]??v.normalized)!==s)break;let y=l(r.slice(v.position.start,c[p].position.end)),h=a[y];if(!h)break;return o.set("event",{type:"literal",value:h,dataType:"string"}),{node:x.withoutSpanDiagnostics(e,m),input:r}}return null}reclaimResponseTypeTail(e,r,t){let n=x.unconsumedSpans(e);if(n.length===0)return null;let a=x.AS_MARKERS_BEFORE[t];if(!a)return null;let o=l=>l.replace(/\s+/g," ").trim(),u=x.droppedTokenCount(e),s=Y(r,t).tokens;for(let l=0;l+1<s.length;l++){let c=s[l],m=s[l+1];if(!a.some(f=>c.value.toLowerCase()===f)||!x.RESPONSE_TYPE_WORDS.has(m.value.toLowerCase()))continue;let d=o(r.slice(c.position.start,m.position.end));if(!n.includes(d))continue;let p=(r.slice(0,c.position.start).trimEnd()+" "+r.slice(m.position.end).trimStart()).trim();if(!(!p||p===r))try{let f=this.parse(p,t);if(!f||f.kind!=="event-handler")continue;let v=gr(f);if(x.droppedTokenCount(v)>=u)continue;let E=x.findResponseTypeTarget(v);if(!E)continue;return E.roles.set("responseType",{type:"expression",raw:m.value}),{node:v,input:p}}catch{}}return null}static findResponseTypeTarget(e){let r=null,t=n=>{if(!n||typeof n!="object"||r)return;if(n.kind==="command"){let o=n;if(re(o.action)?.roles.some(s=>s.role==="responseType"&&!s.required)&&!o.roles.has("responseType")){r=o;return}}let a=n;for(let o of ["body","statements","thenBranch","elseBranch","commands"]){let u=a[o];Array.isArray(u)&&u.forEach(s=>t(s));}};return t(e),r}reclaimCapturedDestinationTail(e,r,t){let n=x.unconsumedSpans(e);if(n.length===0)return null;let a=P(t)?.roleMarkers?.destination,o=new Set;if(a?.primary&&o.add(a.primary),a?.alternatives?.forEach(l=>o.add(l)),o.size===0)return null;let u=l=>l.replace(/\s+/g," ").trim(),s=Y(r,t).tokens;for(let l=0;l+1<s.length;l++){let c=s[l],m=s[l+1],d=o.has(c.value)&&m.normalized==="me",p=c.normalized==="me"&&o.has(m.value);if(!d&&!p)continue;let f=u(r.slice(c.position.start,m.position.end));if(!n.includes(f))continue;let v=false,E=y=>{if(!y||typeof y!="object"||v)return;if(y.kind==="command"){let z=y.roles.get("destination");if(z?.type==="reference"&&z.value==="me"){v=true;return}}let h=y;for(let z of ["body","statements","thenBranch","elseBranch","commands"]){let A=h[z];Array.isArray(A)&&A.forEach(D=>E(D));}};if(E(e),!!v)return {node:x.withoutSpanDiagnostics(e,f),input:r}}return null}applyModifiers(e,r){return {...e,eventModifiers:{...e.eventModifiers,...r}}}extractOrConjunctionEvents(e,r){let t=[];for(;;){let n=e.mark(),a=e.peek();if(!a)break;if(!br(a,r)){e.reset(n);break}e.advance();let o=e.peek();if(!o){e.reset(n);break}let u=(o.normalized||o.value).toLowerCase();e.advance(),t.push({type:"literal",value:u});}return t}};Q.coverageMarkerSurfaces=new Map;Q.LEAKED_RENDER_MARKERS={hi:["\u0915\u0947","\u0930\u0942\u092A","\u092E\u0947\u0902"],tr:["olarak"],qu:["hina"]};Q.AS_MARKERS_BEFORE={en:["as"],es:["como"],fr:["comme"],pt:["como"],it:["come"],de:["als"],id:["sebagai"],ms:["sebagai","sbg"],sw:["kuwa","kama"],th:["\u0E40\u0E1B\u0E47\u0E19"],vi:["nh\u01B0"],tl:["bilang"],he:["\u05DB"],ar:["\u0643\u0640"],pl:["jako"],ru:["\u043A\u0430\u043A"],uk:["\u044F\u043A"],zh:["\u7684","\u4F5C\u4E3A","\u5F53\u4F5C"]};Q.AS_MARKERS_AFTER={ko:[["\uB85C"],["\uC73C\uB85C"]],qu:[["hina"]],tr:[["olarak"]],hi:[["\u0915\u0947","\u0930\u0942\u092A","\u092E\u0947\u0902"]]};Q.enEventKeywordCache=new Map;Q.KNOWN_EVENTS=new Set(["click","dblclick","input","change","submit","keydown","keyup","keypress","mouseover","mouseout","mousedown","mouseup","focus","blur","load","scroll","resize","contextmenu"]);Q.RESPONSE_TYPE_WORDS=new Set(["json","text","html","xml","blob","arraybuffer","formdata","response"]);Q.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"])};Q.SOV_EVENT_MARKER_PHRASES={ko:[["\uD560","\uB54C"],["\uD560\uB54C"]]};Q.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"])}};Q.CONDITION_COPULAS=new Set(["is","am","are","be","was","were","not","no"]);Q.CONDITION_COPULAS_SURFACE=new Set(["\u0647\u0648","\u0E40\u0E1B\u0E47\u0E19","\u0939\u0948"]);Q.CONDITION_PREDICATES=new Set(["empty","null","undefined"]);Q.CONDITION_OPERATORS=new Set(["matches","match","contains","exists","has","have","equals","includes"]);Q.STANDALONE_MODIFIERS={once:"once",debounced:"debounce",debounce:"debounce",throttled:"throttle",throttle:"throttle"};var Nu=Q,Mu=new Nu;function _u(i,e){return Mu.parse(i,e)}function Iu(i,e){try{let r=Y(i,e),t=de(e);if(t.length===0)return {confidence:0,parseSuccess:!1,error:`No patterns available for language: ${e}`};let n=[...t].sort((l,c)=>c.priority-l.priority),a=n.filter(l=>l.command==="on"),o=oe.matchBest(r,a);if(o)return {confidence:o.confidence,parseSuccess:!0,patternId:o.pattern.id,action:o.pattern.command,tokensConsumed:o.consumedTokens};r.reset(r.mark());let u=n.filter(l=>l.command!=="on"),s=oe.matchBest(r,u);return s?{confidence:s.confidence,parseSuccess:!0,patternId:s.pattern.id,action:s.pattern.command,tokensConsumed:s.consumedTokens}:{confidence:0,parseSuccess:!1,error:`Could not match any patterns for: ${i}`}}catch(r){return {confidence:0,parseSuccess:false,error:r instanceof Error?r.message:String(r)}}}function Qt(i,e){try{let t=_u(i,e);if(t)return {node:t,confidence:t.metadata?.confidence??.8,error:void 0,tokensConsumed:Y(i,e).tokens.length}}catch{}let r=Iu(i,e);return r.parseSuccess?{node:null,confidence:r.confidence,error:void 0,tokensConsumed:r.tokensConsumed}:{node:null,confidence:0,error:r.error}}function ei(i,e){let r=e==="SOV"?"sovPosition":"svoPosition";return [...i].sort((t,n)=>{let a=t[r]??99,o=n[r]??99;return a-o})}function Pe(i,e){let r,t;if(i.markerOverride&&i.markerOverride[e.code]!==void 0)r=i.markerOverride[e.code],t=r?fe(i,e.code,r):void 0;else {let n=e.roleMarkers[i.role];if(n){r=n.primary;let a=fe(i,e.code,r)??[],o=[...new Set([...n.alternatives??[],...a])].filter(u=>u!==r);t=o.length?o:void 0;}}return {marker:r,alternatives:t}}function Ge(i,e,r){r.roles.find(n=>n.role==="scope"&&!n.required)&&(i.push({type:"group",optional:true,tokens:[{type:"literal",value:"on"},{type:"role",role:"scope",optional:true,expectedTypes:["selector","reference"]}]}),e.scope={fromRole:"scope"});}function Nr(i,e,r,t){ti(i,e,r,t,"manner",{requireMarker:true});}function ri(i,e,r,t){ti(i,e,r,t,"recipient",{requireMarker:false});}function ti(i,e,r,t,n,a){let o=r.roles.find(s=>s.role===n&&!s.required);if(!o)return;let u=o.markerOverride?.[t];a.requireMarker&&!u||(i.push({type:"group",optional:true,tokens:[...(u?u.split(/\s+/):[]).map(s=>({type:"literal",value:s})),{type:"role",role:n,optional:true,expectedTypes:o.expectedTypes,...o.valueShape!==void 0?{valueShape:o.valueShape}:{}}]}),e[n]={fromRole:n});}function ii(i){if(i.roles.some(t=>t.role==="patient"))return "patient";let e=i.roles.filter(t=>t.required),r=e.find(t=>t.role===i.primaryRole)??e[0];return !r||r.role==="event"?"patient":r.role}function ni(i,e,r){let t=i.roles.find(c=>c.role===r);if(!t||r==="patient")return [{type:"role",role:r,optional:false}];let{marker:n,alternatives:a}=Pe(t,e),o={type:"role",role:r,optional:false,...t.valueShape!==void 0?{valueShape:t.valueShape}:{}};if(!n)return [o];let u=n.split(/\s+/).filter(Boolean),s={type:"group",optional:true,tokens:u.map(c=>({type:"literal",value:c,...u.length===1&&a?.length?{alternatives:a}:{}}))};return (e.roleMarkers[r]?.position??"before")==="after"?[o,s]:[s,o]}function ai(i,e,r,t,n){for(let a of r.roles)a.required||n.has(a.role)||e[a.role]||!(a.markerOverride?.[t.code]??t.roleMarkers[a.role]?.primary)&&a.valueShape===void 0||(i.push({type:"group",optional:true,tokens:si(a,t)}),e[a.role]=a.default?{fromRole:a.role,default:a.default}:{fromRole:a.role});}function ju(i,e,r,t,n){let a=[];if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let f=t.primary.split(/\s+/);if(f.length>1)for(let v of f)a.push({type:"literal",value:v});else {let v=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(v);}}let o=ii(i),u=e.roleMarkers.destination,s=i.roles.some(f=>f.role==="destination");u&&s&&o!=="destination"&&a.push({type:"group",optional:true,tokens:[{type:"role",role:"destination",optional:true},u.alternatives?{type:"literal",value:u.primary,alternatives:u.alternatives}:{type:"literal",value:u.primary}]});let l=e.roleMarkers.source,c=i.roles.some(f=>f.role==="source");l&&c&&o!=="source"&&a.push({type:"group",optional:true,tokens:[{type:"role",role:"source",optional:true},l.alternatives?{type:"literal",value:l.primary,alternatives:l.alternatives}:{type:"literal",value:l.primary}]}),a.push(...ni(i,e,o));let m=e.roleMarkers.patient;if(m&&o==="patient"){let f=m.alternatives?{type:"literal",value:m.primary,alternatives:m.alternatives}:{type:"literal",value:m.primary};a.push(f);}let d=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(d),o!=="source"&&a.push(...be(i,e.roleMarkers.source)),o!=="destination"&&a.push(...Sr(i,e.roleMarkers.destination));let p={action:{value:i.action},event:{fromRole:"event"},[o]:{fromRole:o},...o==="destination"?{}:ke(i),...o==="source"?{}:we(i)};return ai(a,p,i,e,new Set(["event",o,"destination","source"])),{id:`${i.action}-event-${e.code}-sov`,language:e.code,command:"on",priority:(n.basePriority??100)+50,template:{format:`{event} ${t.primary} {destination?} {${o}} ${m?.primary||""} ${r.primary}`,tokens:a},extraction:p}}function $u(i,e,r,t,n){let a=[],o=i.action==="swap",u=o?"destination":"patient";a.push({type:"role",role:u,optional:false});let s=e.roleMarkers.patient;if(s){let d=s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary};a.push(d);}if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let d=t.primary.split(/\s+/);if(d.length>1)for(let p of d)a.push({type:"literal",value:p});else {let p=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(p);}}let l=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(l),a.push(...be(i,e.roleMarkers.source));let c=e.roleMarkers.destination;if(o&&c){let d=i.roles.find(p=>p.role==="patient")?.markerOverride?.[e.code];if(d&&d!==c.primary){let p=c.alternatives??[];p.includes(d)||(c={...c,alternatives:[...p,d]});}}a.push(...o?mn(i,c):Sr(i,c));let m={action:{value:i.action},event:{fromRole:"event"},[u]:{fromRole:u},...o?{}:ke(i),...we(i)};return ri(a,m,i,e.code),Nr(a,m,i,e.code),{id:`${i.action}-event-${e.code}-sov-patient-first`,language:e.code,command:"on",priority:(n.basePriority??100)+45,template:{format:`{patient} ${s?.primary||""} {event} ${t.primary} ${r.primary}`,tokens:a},extraction:m}}function Vu(i,e,r,t,n){let a=i.roles.find(m=>m.role==="source");if(!a)return null;let{marker:o,alternatives:u}=Pe(a,e),s=e.roleMarkers.patient;if(!o||o===t.primary||o===s?.primary)return null;let l=[];l.push({type:"role",role:"patient",optional:false}),s&&l.push(s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary}),l.push({type:"role",role:"source",optional:false,...a.expectedTypes?{expectedTypes:a.expectedTypes}:{},...a.valueShape!==void 0?{valueShape:a.valueShape}:{}});for(let m of o.split(/\s+/))l.push(u&&o.split(/\s+/).length===1?{type:"literal",value:m,alternatives:u}:{type:"literal",value:m});if(l.push({type:"role",role:"event",optional:false}),t.position==="after"){let m=t.primary.split(/\s+/);if(m.length>1)for(let d of m)l.push({type:"literal",value:d});else l.push(t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary});}l.push(r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary});let c={action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},source:{fromRole:"source"}};return ri(l,c,i,e.code),Nr(l,c,i,e.code),{id:`${i.action}-event-${e.code}-sov-source-fronted`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`{patient} ${s?.primary||""} {source} ${o} {event} ${t.primary} ${r.primary}`,tokens:l},extraction:c}}function qu(i,e,r,t,n){let a=[];a.push({type:"role",role:"patient",optional:false});let o=e.roleMarkers.patient;if(o){let l=o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary};a.push(l);}let u=e.roleMarkers.destination;if(u&&(a.push({type:"role",role:"destination",optional:false}),a.push(u.alternatives?{type:"literal",value:u.primary,alternatives:u.alternatives}:{type:"literal",value:u.primary})),a.push({type:"role",role:"event",optional:false}),t.position==="after"){let l=t.primary.split(/\s+/);if(l.length>1)for(let c of l)a.push({type:"literal",value:c});else {let c=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(c);}}let s=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(s),{id:`${i.action}-event-${e.code}-sov-patient-first-dest`,language:e.code,command:"on",priority:(n.basePriority??100)+40,template:{format:`{patient} ${o?.primary||""} {destination} ${u?.primary||""} {event} ${t.primary} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},destination:{fromRole:"destination"}}}}function Wu(i,e,r,t,n){let a=[];a.push({type:"role",role:"event",optional:false});let o=t.alternatives?.filter(c=>!c.includes(" ")&&c.length>1)||[];o.length>0&&a.push({type:"literal",value:o[0],alternatives:o.slice(1)});let u=e.roleMarkers.destination;u&&a.push({type:"group",optional:true,tokens:[{type:"role",role:"destination",optional:true},u.alternatives?{type:"literal",value:u.primary,alternatives:u.alternatives}:{type:"literal",value:u.primary}]}),a.push({type:"role",role:"patient",optional:false});let s=e.roleMarkers.patient;if(s){let c=s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary};a.push(c);}let l=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(l),a.push(...be(i,e.roleMarkers.source)),a.push(...Sr(i,e.roleMarkers.destination)),{id:`${i.action}-event-${e.code}-sov-compact`,language:e.code,command:"on",priority:(n.basePriority??100)+52,template:{format:`{event}${o[0]||""} {patient} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},...ke(i),...we(i)}}}function Ku(i,e,r,t,n){let a=[];if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let u=t.primary.split(/\s+/);if(u.length>1)for(let s of u)a.push({type:"literal",value:s});else {let s=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(s);}}let o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(o),{id:`${i.action}-event-${e.code}-sov-simple`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`{event} ${t.primary} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{default:{type:"reference",value:"me"}}}}}function Hu(i,e,r,t){let n=e.eventHandler?.temporalMarkers;if(!n||n.length===0)return null;let a=[];a.push({type:"role",role:"event",optional:false}),e.possessive?.marker&&a.push({type:"group",optional:true,tokens:[{type:"literal",value:e.possessive.marker}]}),a.push({type:"literal",value:n[0],alternatives:n.slice(1)}),a.push({type:"role",role:"patient",optional:false});let o=e.roleMarkers.patient;if(o?.primary){let s=o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary};a.push(s);}let u=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};return a.push(u),{id:`${i.action}-event-${e.code}-sov-temporal`,language:e.code,command:"on",priority:(t.basePriority??100)+49,template:{format:`{event} ${n[0]} {patient} ${r.primary}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"}}}}function Uu(i,e,r,t,n){let a=[];if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let m=t.primary.split(/\s+/);if(m.length>1)for(let d of m)a.push({type:"literal",value:d});else {let d=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(d);}}let u=[...i.roles.filter(m=>m.required)].sort((m,d)=>{let p=m.sovPosition??999,f=d.sovPosition??999;return p-f});for(let m of u){a.push({type:"role",role:m.role,optional:false});let{marker:d,alternatives:p}=Pe(m,e);if(d){let f=p?{type:"literal",value:d,alternatives:p}:{type:"literal",value:d};a.push(f);}}let s=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(s);let l=u.map(m=>`{${m.role}}`).join(" "),c={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(u.map(m=>[m.role,{fromRole:m.role}]))};return Ge(a,c,i),{id:`${i.action}-event-${e.code}-sov-2role`,language:e.code,command:"on",priority:(n.basePriority??100)+55,template:{format:`{event} ${t.primary} ${l} ${r.primary}`,tokens:a},extraction:c}}function Gu(i,e,r,t,n){let a=[],u=[...i.roles.filter(c=>c.required)].sort((c,m)=>{let d=c.sovPosition??999,p=m.sovPosition??999;return d-p});for(let c of u){a.push({type:"role",role:c.role,optional:false});let{marker:m,alternatives:d}=Pe(c,e);m&&a.push(d?{type:"literal",value:m,alternatives:d}:{type:"literal",value:m});}if(a.push(r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary}),a.push({type:"role",role:"event",optional:false}),t.position==="after"){let c=t.primary.split(/\s+/);if(c.length>1)for(let m of c)a.push({type:"literal",value:m});else a.push(t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary});}let s=u.map(c=>`{${c.role}}`).join(" "),l={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(u.map(c=>[c.role,{fromRole:c.role}]))};return Ge(a,l,i),{id:`${i.action}-event-${e.code}-sov-2role-event-last`,language:e.code,command:"on",priority:(n.basePriority??100)+40,template:{format:`${s} ${r.primary} {event} ${t.primary}`,tokens:a},extraction:l}}function Yu(i,e,r,t,n){let a=[],u=[...i.roles.filter(E=>E.required)].sort((E,y)=>{let h=E.sovPosition??999,z=y.sovPosition??999;return h-z}),s=u[0];a.push({type:"role",role:s.role,optional:false});let{marker:l,alternatives:c}=Pe(s,e);if(l){let E=c?{type:"literal",value:l,alternatives:c}:{type:"literal",value:l};a.push(E);}if(a.push({type:"role",role:"event",optional:false}),t.position==="after"){let E=t.primary.split(/\s+/);if(E.length>1)for(let y of E)a.push({type:"literal",value:y});else {let y=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(y);}}let m=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(m);let d=u[1];a.push({type:"role",role:d.role,optional:false});let{marker:p,alternatives:f}=Pe(d,e);if(p){let E=f?{type:"literal",value:p,alternatives:f}:{type:"literal",value:p};a.push(E);}let v={action:{value:i.action},event:{fromRole:"event"},[s.role]:{fromRole:s.role},[d.role]:{fromRole:d.role}};return Ge(a,v,i),{id:`${i.action}-event-${e.code}-sov-2role-dest-first`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`{${s.role}} {event} ${t.primary} ${r.primary} {${d.role}}`,tokens:a},extraction:v}}function oi(i,e,r){let t=fe(i,e.code,r.primary)??[],n=[...new Set([...r.alternatives??[],...t])].filter(a=>a!==r.primary);return n.length?n:void 0}function Et(i,e,r,t,n){let a=[];if(t.position==="before"){let m=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(m);}a.push({type:"role",role:"event",optional:false});let o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let u=ii(i);a.push(...ni(i,e,u));let s=e.roleMarkers.destination,l=i.roles.some(m=>m.role==="destination");s&&l&&u!=="destination"&&a.push({type:"group",optional:true,tokens:[s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary},{type:"role",role:"destination",optional:true}]}),u!=="source"&&a.push(...be(i,e.roleMarkers.source));let c={action:{value:i.action},event:{fromRole:"event"},[u]:{fromRole:u},...u==="destination"?{}:ke(i),...u==="source"?{}:we(i)};return ai(a,c,i,e,new Set(["event",u,"destination","source"])),{id:`${i.action}-event-${e.code}-vso`,language:e.code,command:"on",priority:(n.basePriority??100)+50,template:{format:`${t.primary} {event} ${r.primary} {${u}} ${s?.primary||""} {destination?}`,tokens:a},extraction:c}}function Zu(i,e,r,t,n){let a=[],o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let u=i.action==="swap";a.push({type:"role",role:u?"destination":"patient",optional:false});let s=u?void 0:e.roleMarkers.destination;if(s&&a.push({type:"group",optional:true,tokens:[s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary},{type:"role",role:"destination",optional:true}]}),a.push(...be(i,e.roleMarkers.source)),t.position==="before"){let c=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(c);}if(a.push({type:"role",role:"event",optional:false}),u){let c=i.roles.find(m=>m.role==="patient")?.markerOverride?.[e.code];c&&a.push({type:"group",optional:true,tokens:[{type:"literal",value:c},{type:"role",role:"patient",optional:false}]});}let l={action:{value:i.action},event:{fromRole:"event"},[u?"destination":"patient"]:{fromRole:u?"destination":"patient"},...u?{}:ke(i),...we(i)};return Nr(a,l,i,e.code),{id:`${i.action}-event-${e.code}-vso-verb-first`,language:e.code,command:"on",priority:(n.basePriority??100)+45,template:{format:`${r.primary} {patient} ${s?.primary||""} {destination?} ${t.primary} {event}`,tokens:a},extraction:l}}function Ju(i,e,r,t,n){let a=[],o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let s=[...i.roles.filter(m=>m.required)].sort((m,d)=>{let p=m.svoPosition??999,f=d.svoPosition??999;return p-f});for(let m of s){let d,p;if(m.markerOverride&&m.markerOverride[e.code]!==void 0)d=m.markerOverride[e.code],p=d?fe(m,e.code,d):void 0;else {let f=e.roleMarkers[m.role];f&&(d=f.primary,p=oi(m,e,f));}if(d){let f=p?{type:"literal",value:d,alternatives:p}:{type:"literal",value:d};a.push(f);}a.push({type:"role",role:m.role,optional:false});}if(t.position==="before"){let m=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(m);}a.push({type:"role",role:"event",optional:false});let l=s.map(m=>`{${m.role}}`).join(" "),c={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(s.map(m=>[m.role,{fromRole:m.role}]))};return Ge(a,c,i),{id:`${i.action}-event-${e.code}-vso-verb-first-2role`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`${r.primary} ${l} ${t.primary} {event}`,tokens:a},extraction:c}}function gt(i,e,r,t,n){let a=[];if(t.position==="before"){let m=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(m);}a.push({type:"role",role:"event",optional:false});let o=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(o);let s=[...i.roles.filter(m=>m.required)].sort((m,d)=>{let p=m.svoPosition??999,f=d.svoPosition??999;return p-f});for(let m of s){let d,p;if(m.markerOverride&&m.markerOverride[e.code]!==void 0)d=m.markerOverride[e.code],p=d?fe(m,e.code,d):void 0;else {let f=e.roleMarkers[m.role];f&&(d=f.primary,p=oi(m,e,f));}if(d){let f=p?{type:"literal",value:d,alternatives:p}:{type:"literal",value:d};a.push(f);}a.push({type:"role",role:m.role,optional:false});}let l=s.map(m=>`{${m.role}}`).join(" "),c={action:{value:i.action},event:{fromRole:"event"},...Object.fromEntries(s.map(m=>[m.role,{fromRole:m.role}]))};return Ge(a,c,i),{id:`${i.action}-event-${e.code}-vso-2role`,language:e.code,command:"on",priority:(n.basePriority??100)+55,template:{format:`${t.primary} {event} ${r.primary} ${l}`,tokens:a},extraction:c}}function Xu(i,e,r,t,n){let a=[],o=e.eventHandler?.negationMarker;if(t.position==="before"){let l=t.alternatives?{type:"literal",value:t.primary,alternatives:t.alternatives}:{type:"literal",value:t.primary};a.push(l);}if(o){let l=o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary};a.push(l);}a.push({type:"role",role:"event",optional:false});let u=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};a.push(u),a.push({type:"role",role:"patient",optional:false});let s=e.roleMarkers.destination;return s&&a.push({type:"group",optional:true,tokens:[s.alternatives?{type:"literal",value:s.primary,alternatives:s.alternatives}:{type:"literal",value:s.primary},{type:"role",role:"destination",optional:true}]}),a.push(...be(i,e.roleMarkers.source)),{id:`${i.action}-event-${e.code}-vso-negated`,language:e.code,command:"on",priority:(n.basePriority??100)+48,template:{format:`${t.primary} ${o?.primary||""} {event} ${r.primary} {patient} ${s?.primary||""} {destination?}`,tokens:a},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},...ke(i),...we(i)}}}function Qu(i,e,r,t){let n=[];n.push({type:"literal",value:"and",alternatives:["then"]}),n.push({type:"role",role:"event",optional:false});let a=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary};n.push(a),n.push({type:"role",role:"patient",optional:false});let o=e.roleMarkers.destination;return o&&n.push({type:"group",optional:true,tokens:[o.alternatives?{type:"literal",value:o.primary,alternatives:o.alternatives}:{type:"literal",value:o.primary},{type:"role",role:"destination",optional:true}]}),n.push(...be(i,e.roleMarkers.source)),{id:`${i.action}-event-${e.code}-vso-proclitic`,language:e.code,command:"on",priority:(t.basePriority??100)+45,template:{format:`[proclitic?] {event} ${r.primary} {patient} ${o?.primary||""} {destination?}`,tokens:n},extraction:{action:{value:i.action},event:{fromRole:"event"},patient:{fromRole:"patient"},...ke(i),...we(i)}}}var Ne={basePriority:100,generateSimpleVariants:true,generateAlternatives:true};function He(i,e,r=Ne){let t=`${i.action}-${e.code}-generated`,n=r.basePriority??100,a=e.keywords[i.action];if(!a)throw new Error(`No keyword translation for '${i.action}' in ${e.code}`);let o=is(i,e,a),u=Mr(i,e),s=us(i,e,a);return {id:t,language:e.code,command:i.action,priority:n,template:{format:s,tokens:o},extraction:u}}function es(i,e,r=Ne){if(i.roles.filter(u=>!u.required).length===0)return null;let n=i.roles.filter(u=>u.required),a={...i,roles:n};return {...He(a,e,r),id:`${i.action}-${e.code}-generated-simple`,priority:(r.basePriority??100)-5,extraction:Mr(i,e)}}function Ct(i,e,r=Ne){if(e.wordOrder!=="SOV")return null;let t=i.roles.filter(u=>u.required);if(t.length!==1)return null;let n=e.keywords[i.action];if(!n)return null;let a=n.alternatives?{type:"literal",value:n.primary,alternatives:n.alternatives}:{type:"literal",value:n.primary},o=t.flatMap(u=>{let s=u.valuePrefixLiteral?.[e.code],l={type:"role",role:u.role,optional:false,expectedTypes:u.expectedTypes};return s?[{type:"literal",value:s},l]:[l]});return {id:`${i.action}-${e.code}-generated-verb-first`,language:e.code,command:i.action,priority:(r.basePriority??100)-20,template:{format:`${n.primary} <${t[0].role}>`,tokens:[a,...o]},extraction:Mr(i,e)}}function rs(i,e,r=Ne){let t=[];if(t.push(He(i,e,r)),r.generateSimpleVariants){let n=es(i,e,r);n&&t.push(n);}for(let n of i.omitRoleVariants??[]){let a={...i,roles:i.roles.filter(u=>u.role!==n)},o=He(a,e,r);t.push({...o,id:`${i.action}-${e.code}-generated-no-${n}`,priority:(r.basePriority??100)-8});}for(let n of i.widenTypeVariants??[]){if(n.excludeLanguages?.includes(e.code))continue;let a={...i,roles:i.roles.map(u=>u.role===n.role?{...u,expectedTypes:[...n.types]}:u)},o=He(a,e,r);t.push({...o,id:`${i.action}-${e.code}-generated-${n.idSuffix}`,priority:(r.basePriority??100)-(n.priorityDelta??15)});}if(r.generateVerbFirstVariants!==false){let n=Ct(i,e,r);n&&t.push(n);}for(let n of i.rolePrefixLiteralVariants??[]){let a=n.literal[e.code];if(!a)continue;let{rolePrefixLiteralVariants:o,...u}=i,s={...u,roles:i.roles.map(d=>d.role===n.role?{...d,valuePrefixLiteral:{[e.code]:a}}:d)},l=n.priorityDelta??5,c=n.methodCarrier?{[n.methodCarrier]:{value:a}}:{},m=He(s,e,r);if(t.push({...m,id:`${i.action}-${e.code}-generated-${n.idSuffix}`,priority:(r.basePriority??100)+l,extraction:{...m.extraction,...c}}),r.generateVerbFirstVariants!==false){let d=Ct(s,e,r);d&&t.push({...d,id:`${i.action}-${e.code}-generated-verb-first-${n.idSuffix}`,priority:(r.basePriority??100)-20+l,extraction:{...d.extraction,...c}});}}return t}function ui(i,e=Ne){let r=[],t=Ta();for(let n of t){if(!i.keywords[n.action])continue;let a=rs(n,i,e);if(r.push(...a),i.eventHandler?.eventMarker){let o=ts(n,i,e);r.push(...o);}}return r}function ts(i,e,r=Ne){if(!e.eventHandler||!e.eventHandler.eventMarker)return [];let t=[],n=e.eventHandler.eventMarker,a=e.keywords[i.action];if(!a)return [];if(i.roles.length===0)return [];if(i.action==="js")return [];let u=i.roles.filter(s=>s.required).length===2;if(e.wordOrder==="SOV")if(u)t.push(Uu(i,e,a,n,r)),t.push(Yu(i,e,a,n,r)),t.push(Gu(i,e,a,n,r));else {t.push(ju(i,e,a,n,r)),t.push($u(i,e,a,n,r));let s=Vu(i,e,a,n,r);s&&t.push(s);let l=e.roleMarkers.destination;l&&l.primary!==n.primary&&t.push(qu(i,e,a,n,r));let c=n.primary.split(/\s+/),m=n.alternatives?.some(p=>!p.includes(" ")&&p.length>1);c.length>1&&m&&t.push(Wu(i,e,a,n,r)),t.push(Ku(i,e,a,n,r));let d=Hu(i,e,a,r);d&&t.push(d);}else e.wordOrder==="VSO"?u?(t.push(gt(i,e,a,n,r)),t.push(Ju(i,e,a,n,r))):(t.push(Et(i,e,a,n,r)),t.push(Zu(i,e,a,n,r)),e.eventHandler?.negationMarker&&t.push(Xu(i,e,a,n,r)),e.tokenization?.prefixes&&t.push(Qu(i,e,a,r))):u?t.push(gt(i,e,a,n,r)):t.push(Et(i,e,a,n,r));return t}function is(i,e,r){let t=[],n=r.alternatives?{type:"literal",value:r.primary,alternatives:r.alternatives}:{type:"literal",value:r.primary},a=as(i,e);switch(e.wordOrder){case "SVO":t.push(n),t.push(...a);break;case "SOV":t.push(...a),t.push(n);break;case "VSO":t.push(n),t.push(...a);break;default:t.push(n),t.push(...a);}return ns(t)}function ns(i){let e=[];for(let r of i){let t=e[e.length-1];if(t&&t.type==="literal"&&r.type==="literal"&&t.value===r.value){let n=[...t.alternatives??[],...r.alternatives??[]];n.length&&(e[e.length-1]={...t,alternatives:[...new Set(n)]});continue}e.push(r);}return e}function as(i,e){let r=[],t=ei(i.roles,e.wordOrder);for(let n of t){let a=si(n,e);n.required?r.push(...a):r.push({type:"group",optional:true,tokens:a});}return r}function si(i,e){let r=[],t=i.markerOverride?.[e.code],n=e.roleMarkers[i.role],a=i.renderOverride?.[e.code]==="",o={type:"role",role:i.role,optional:!i.required,expectedTypes:i.expectedTypes,...i.valueShape!==void 0?{valueShape:i.valueShape}:{}},u=i.valuePrefixLiteral?.[e.code],s=()=>{u&&r.push({type:"literal",value:u}),r.push(o);};if(t!==void 0){let l=t?t.split(/\s+/).filter(Boolean):[],c=t!==void 0&&t===i.markerOverride?.en,m=n?.position??(e.wordOrder==="SOV"&&!c?"after":"before"),d=i.markerOptional?.[e.code]===true,p=f=>{let v=l.length===1?fe(i,e.code,f)??[]:[],E={type:"literal",value:f,...v.length?{alternatives:v}:{},...a?{renderSuppress:true}:{}};r.push(d?{type:"group",optional:true,tokens:[E]}:E);};if(m==="before"){for(let f of l)p(f);s();}else {s();for(let f of l)p(f);}}else if(n){let l=()=>{let m=[...new Set([...n.alternatives??[],...fe(i,e.code,n.primary)??[]])].filter(d=>d!==n.primary);return {type:"literal",value:n.primary,...m.length?{alternatives:m}:{},...a?{renderSuppress:true}:{}}},c=m=>{if(!e.markersOptional&&!i.markerOptional?.[e.code]){r.push(m);return}r.push({type:"group",optional:true,...e.markersOptional&&!i.markerOptional?.[e.code]?{renderRequired:true}:{},tokens:[m]});};n.position==="before"?(n.primary&&c(l()),s()):(s(),c(l()));}else s();return r}function os(i,e){let r={};for(let t of i.roles){let n=t.markerOverride?.[e.code],a=e.roleMarkers[t.role];if(t.valuePrefixLiteral?.[e.code])r[t.role]={marker:t.valuePrefixLiteral[e.code]};else if(n!==void 0)if(!n)r[t.role]={};else {let u=!/\s/.test(n.trim())?fe(t,e.code,n)??[]:[];r[t.role]=u.length?{marker:n,markerAlternatives:u}:{marker:n};}else if(a&&a.primary){let o=[...new Set([...a.alternatives??[],...fe(t,e.code,a.primary)??[]])].filter(u=>u!==a.primary);r[t.role]=o.length?{marker:a.primary,markerAlternatives:o}:{marker:a.primary};}else r[t.role]={};}return r}function Mr(i,e){let r=os(i,e),t={};for(let n of i.roles){let a=r[n.role]||{};!n.required&&n.default?t[n.role]={...a,default:n.default}:t[n.role]=a;}return t}function us(i,e,r){let t=[],a=ei(i.roles,e.wordOrder).map(o=>{let u=mo(o,e),s="";return u&&u.primary?u.position==="before"?s=`${u.primary} {${o.role}}`:s=`{${o.role}} ${u.primary}`:s=`{${o.role}}`,o.required?s:`[${s}]`});switch(e.wordOrder){case "SVO":case "VSO":t.push(r.primary,...a);break;case "SOV":t.push(...a,r.primary);break;default:t.push(r.primary,...a);}return t.join(" ")}var ss=class{constructor(i={}){this.cache=new Map,this.config={maxSize:i.maxSize??1e3,ttlMs:i.ttlMs??0,enabled:i.enabled??true},this.stats={hits:0,misses:0,evictions:0,expirations:0};}makeKey(i,e){return `${e}:${i}`}isExpired(i){return this.config.ttlMs===0?false:Date.now()-i.createdAt>this.config.ttlMs}evictLRU(){let i=this.cache.keys().next().value;i!==void 0&&(this.cache.delete(i),this.stats.evictions++);}get(i,e){if(!this.config.enabled){this.stats.misses++;return}let r=this.makeKey(i,e),t=this.cache.get(r);if(!t){this.stats.misses++;return}if(this.isExpired(t)){this.cache.delete(r),this.stats.expirations++,this.stats.misses++;return}return this.cache.delete(r),t.lastAccessed=Date.now(),this.cache.set(r,t),this.stats.hits++,t.result}set(i,e,r){if(!this.config.enabled||r!==null&&typeof r=="object"&&"confidence"in r&&r.confidence===0)return;let t=this.makeKey(i,e),n=Date.now();for(;this.cache.size>=this.config.maxSize;)this.evictLRU();this.cache.set(t,{result:r,createdAt:n,lastAccessed:n});}has(i,e){if(!this.config.enabled)return false;let r=this.makeKey(i,e),t=this.cache.get(r);return t?this.isExpired(t)?(this.cache.delete(r),this.stats.expirations++,false):true:false}delete(i,e){let r=this.makeKey(i,e);return this.cache.delete(r)}clear(){this.cache.clear();}resetStats(){this.stats={hits:0,misses:0,evictions:0,expirations:0};}getStats(){let i=this.stats.hits+this.stats.misses;return {hits:this.stats.hits,misses:this.stats.misses,size:this.cache.size,maxSize:this.config.maxSize,hitRate:i>0?this.stats.hits/i:0,evictions:this.stats.evictions,expirations:this.stats.expirations,enabled:this.config.enabled}}configure(i){if(i.maxSize!==void 0)for(this.config.maxSize=i.maxSize;this.cache.size>this.config.maxSize;)this.evictLRU();i.ttlMs!==void 0&&(this.config.ttlMs=i.ttlMs),i.enabled!==void 0&&(this.config.enabled=i.enabled);}enable(){this.config.enabled=true;}disable(){this.config.enabled=false;}getConfig(){return {...this.config}}};new ss;function ls(i){let e=i.charCodeAt(0);return e>=44032&&e<=55203}function cs(i){for(let e of i)if(ls(e))return true;return false}var ms=[{pattern:"\uD558\uC2DC\uB2C8\uAE4C",confidence:.85,conjugationType:"honorific-causal",minStemLength:1},{pattern:"\uD558\uC2E4\uB54C",confidence:.88,conjugationType:"honorific-temporal",minStemLength:1},{pattern:"\uD558\uC2E4 \uB54C",confidence:.88,conjugationType:"honorific-temporal",minStemLength:1},{pattern:"\uD558\uC2DC\uBA74",confidence:.88,conjugationType:"honorific-conditional",minStemLength:1},{pattern:"\uC73C\uC2DC\uBA74",confidence:.85,conjugationType:"honorific-conditional",minStemLength:2},{pattern:"\uC2DC\uBA74",confidence:.82,conjugationType:"honorific-conditional",minStemLength:2},{pattern:"\uD558\uACE0\uB098\uC11C",confidence:.85,conjugationType:"sequential-after",minStemLength:1},{pattern:"\uD558\uACE0 \uB098\uC11C",confidence:.85,conjugationType:"sequential-after",minStemLength:1},{pattern:"\uD558\uACE0\uC11C",confidence:.85,conjugationType:"sequential-after",minStemLength:1},{pattern:"\uACE0\uB098\uC11C",confidence:.82,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uACE0 \uB098\uC11C",confidence:.82,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uACE0\uC11C",confidence:.82,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD558\uAE30\uC804\uC5D0",confidence:.85,conjugationType:"sequential-before",minStemLength:1},{pattern:"\uD558\uAE30 \uC804\uC5D0",confidence:.85,conjugationType:"sequential-before",minStemLength:1},{pattern:"\uAE30\uC804\uC5D0",confidence:.82,conjugationType:"sequential-before",minStemLength:2},{pattern:"\uAE30 \uC804\uC5D0",confidence:.82,conjugationType:"sequential-before",minStemLength:2},{pattern:"\uD558\uC790\uB9C8\uC790",confidence:.88,conjugationType:"immediate",minStemLength:1},{pattern:"\uC790\uB9C8\uC790",confidence:.85,conjugationType:"immediate",minStemLength:2},{pattern:"\uD574\uC57C\uD574\uC694",confidence:.85,conjugationType:"obligation",minStemLength:1},{pattern:"\uD574\uC57C\uD574",confidence:.85,conjugationType:"obligation",minStemLength:1},{pattern:"\uD574\uC57C\uD558\uB2E4",confidence:.85,conjugationType:"obligation",minStemLength:1},{pattern:"\uC5B4\uC57C\uD574\uC694",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uC5B4\uC57C\uD574",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uC544\uC57C\uD574\uC694",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uC544\uC57C\uD574",confidence:.82,conjugationType:"obligation",minStemLength:2},{pattern:"\uD558\uB2C8\uAE4C",confidence:.85,conjugationType:"causal-nikka",minStemLength:1},{pattern:"\uD560\uB54C",confidence:.88,conjugationType:"temporal-ttae",minStemLength:1},{pattern:"\uD560 \uB54C",confidence:.88,conjugationType:"temporal-ttae",minStemLength:1},{pattern:"\uC744\uB54C",confidence:.85,conjugationType:"temporal-ttae",minStemLength:2},{pattern:"\uC744 \uB54C",confidence:.85,conjugationType:"temporal-ttae",minStemLength:2},{pattern:"\uD558\uBA74",confidence:.88,conjugationType:"conditional-myeon",minStemLength:1},{pattern:"\uC73C\uBA74",confidence:.85,conjugationType:"conditional-myeon",minStemLength:2},{pattern:"\uB2C8\uAE4C",confidence:.82,conjugationType:"causal-nikka",minStemLength:2},{pattern:"\uBA74",confidence:.8,conjugationType:"conditional-myeon",minStemLength:2},{pattern:"\uD558\uC600\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD588\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD569\uB2C8\uB2E4",confidence:.85,conjugationType:"polite",minStemLength:1},{pattern:"\uC2B5\uB2C8\uB2E4",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uB429\uB2C8\uB2E4",confidence:.82,conjugationType:"polite",minStemLength:1},{pattern:"\u3142\uB2C8\uB2E4",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uD558\uC138\uC694",confidence:.85,conjugationType:"honorific",minStemLength:1},{pattern:"\uD558\uC2ED\uC2DC\uC624",confidence:.85,conjugationType:"honorific",minStemLength:1},{pattern:"\uC138\uC694",confidence:.82,conjugationType:"honorific",minStemLength:2},{pattern:"\uC2ED\uC2DC\uC624",confidence:.82,conjugationType:"honorific",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uC5B4\uC694",confidence:.82,conjugationType:"progressive",minStemLength:1},{pattern:"\uD558\uACE0\uC788\uC5B4",confidence:.82,conjugationType:"progressive",minStemLength:1},{pattern:"\uD588\uC5B4\uC694",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD574\uC694",confidence:.85,conjugationType:"polite",minStemLength:1},{pattern:"\uC5B4\uC694",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uC544\uC694",confidence:.82,conjugationType:"polite",minStemLength:2},{pattern:"\uD588\uC5B4",confidence:.85,conjugationType:"past",minStemLength:1},{pattern:"\uD574",confidence:.8,conjugationType:"present",minStemLength:1},{pattern:"\uC5C8\uC5B4",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\uC558\uC5B4",confidence:.82,conjugationType:"past",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uB2E4",confidence:.82,conjugationType:"progressive",minStemLength:1},{pattern:"\uACE0\uC788\uB2E4",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"\uACE0\uC788\uC5B4",confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"\uD558\uB2E4",confidence:.88,conjugationType:"dictionary",minStemLength:1},{pattern:"\uD558\uC9C0\uC54A\uB2E4",confidence:.82,conjugationType:"negative",minStemLength:1},{pattern:"\uC548\uD558\uB2E4",confidence:.82,conjugationType:"negative",minStemLength:1},{pattern:"\uC9C0\uC54A\uB2E4",confidence:.8,conjugationType:"negative",minStemLength:2},{pattern:"\uD574\uB77C",confidence:.82,conjugationType:"imperative",minStemLength:1},{pattern:"\uD558\uB77C",confidence:.82,conjugationType:"imperative",minStemLength:1},{pattern:"\uB2E4",confidence:.75,conjugationType:"dictionary",minStemLength:2}],ds=[{pattern:"\uD558\uC2DC\uB2C8\uAE4C",confidence:.88,conjugationType:"honorific-causal"},{pattern:"\uD558\uC2E4\uB54C",confidence:.88,conjugationType:"honorific-temporal"},{pattern:"\uD558\uC2E4 \uB54C",confidence:.88,conjugationType:"honorific-temporal"},{pattern:"\uD558\uC2DC\uBA74",confidence:.88,conjugationType:"honorific-conditional"},{pattern:"\uD558\uC168\uC5B4\uC694",confidence:.85,conjugationType:"honorific-past"},{pattern:"\uD558\uC168\uC5B4",confidence:.85,conjugationType:"honorific-past"},{pattern:"\uD558\uC2ED\uB2C8\uB2E4",confidence:.85,conjugationType:"honorific-polite"},{pattern:"\uD558\uACE0\uB098\uC11C",confidence:.88,conjugationType:"sequential-after"},{pattern:"\uD558\uACE0 \uB098\uC11C",confidence:.88,conjugationType:"sequential-after"},{pattern:"\uD558\uACE0\uC11C",confidence:.88,conjugationType:"sequential-after"},{pattern:"\uD558\uAE30\uC804\uC5D0",confidence:.88,conjugationType:"sequential-before"},{pattern:"\uD558\uAE30 \uC804\uC5D0",confidence:.88,conjugationType:"sequential-before"},{pattern:"\uD558\uC790\uB9C8\uC790",confidence:.88,conjugationType:"immediate"},{pattern:"\uD574\uC57C\uD574\uC694",confidence:.88,conjugationType:"obligation"},{pattern:"\uD574\uC57C\uD574",confidence:.88,conjugationType:"obligation"},{pattern:"\uD574\uC57C\uD558\uB2E4",confidence:.88,conjugationType:"obligation"},{pattern:"\uD558\uB2C8\uAE4C",confidence:.88,conjugationType:"causal-nikka"},{pattern:"\uD560\uB54C",confidence:.88,conjugationType:"temporal-ttae"},{pattern:"\uD560 \uB54C",confidence:.88,conjugationType:"temporal-ttae"},{pattern:"\uD558\uBA74",confidence:.88,conjugationType:"conditional-myeon"},{pattern:"\uD558\uC600\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past"},{pattern:"\uD588\uC2B5\uB2C8\uB2E4",confidence:.85,conjugationType:"past"},{pattern:"\uD569\uB2C8\uB2E4",confidence:.85,conjugationType:"polite"},{pattern:"\uD558\uC2ED\uC2DC\uC624",confidence:.85,conjugationType:"honorific"},{pattern:"\uD558\uC138\uC694",confidence:.85,conjugationType:"honorific"},{pattern:"\uD588\uC5B4\uC694",confidence:.85,conjugationType:"past"},{pattern:"\uD574\uC694",confidence:.85,conjugationType:"polite"},{pattern:"\uD588\uC5B4",confidence:.85,conjugationType:"past"},{pattern:"\uD574",confidence:.8,conjugationType:"present"},{pattern:"\uD558\uACE0\uC788\uC5B4\uC694",confidence:.82,conjugationType:"progressive"},{pattern:"\uD558\uACE0\uC788\uC5B4",confidence:.82,conjugationType:"progressive"},{pattern:"\uD558\uACE0\uC788\uB2E4",confidence:.82,conjugationType:"progressive"},{pattern:"\uD574\uC11C",confidence:.82,conjugationType:"connective"},{pattern:"\uD558\uACE0",confidence:.8,conjugationType:"connective"},{pattern:"\uD558\uC9C0\uC54A\uC544\uC694",confidence:.82,conjugationType:"negative"},{pattern:"\uD558\uC9C0\uC54A\uB2E4",confidence:.82,conjugationType:"negative"},{pattern:"\uC548\uD574\uC694",confidence:.82,conjugationType:"negative"},{pattern:"\uC548\uD574",confidence:.82,conjugationType:"negative"},{pattern:"\uD574\uB77C",confidence:.82,conjugationType:"imperative"},{pattern:"\uD558\uB77C",confidence:.82,conjugationType:"imperative"},{pattern:"\uD558\uB2E4",confidence:.88,conjugationType:"dictionary"}],pi=class{constructor(){this.language="ko";}isNormalizable(i){return !(!cs(i)||i.length<2)}normalize(i){let e=this.normalizeCompound(i);if(e)return e;let r=this.tryHadaNormalization(i);if(r)return r;for(let t of ms)if(i.endsWith(t.pattern)){let n=i.slice(0,-t.pattern.length),a=t.minStemLength??2;if(n.length<a)continue;let o={removedSuffixes:[t.pattern]};return t.conjugationType&&(o.conjugationType=t.conjugationType),rr(n,t.confidence,o)}return Qr(i)}tryHadaNormalization(i){for(let e of ds)if(i.endsWith(e.pattern)){let r=i.slice(0,-e.pattern.length);if(r.length<1)continue;return rr(r,e.confidence,{removedSuffixes:[e.pattern],conjugationType:e.conjugationType,originalForm:"hada-verb"})}return null}normalizeCompound(i){let e=[{pattern:"\uD558\uACE0\uB098\uC11C\uC600\uC5B4",suffixes:["\uD558\uACE0\uB098\uC11C","\uC600\uC5B4"],confidence:.78,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD558\uACE0\uB098\uC11C\uC600\uB2E4",suffixes:["\uD558\uACE0\uB098\uC11C","\uC600\uB2E4"],confidence:.78,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD558\uACE0\uB098\uC11C",suffixes:["\uD558\uACE0","\uB098\uC11C"],confidence:.85,conjugationType:"sequential-after",minStemLength:2},{pattern:"\uD574\uC57C\uD588\uC5B4",suffixes:["\uD574\uC57C","\uD588\uC5B4"],confidence:.8,conjugationType:"obligation",minStemLength:2},{pattern:"\uD574\uC57C\uD588\uB2E4",suffixes:["\uD574\uC57C","\uD588\uB2E4"],confidence:.8,conjugationType:"obligation",minStemLength:2},{pattern:"\uD574\uC57C\uD588\uC2B5\uB2C8\uB2E4",suffixes:["\uD574\uC57C","\uD588\uC2B5\uB2C8\uB2E4"],confidence:.8,conjugationType:"obligation",minStemLength:2},{pattern:"\uD558\uC2DC\uBA74\uC11C",suffixes:["\uD558\uC2DC","\uBA74\uC11C"],confidence:.82,conjugationType:"connective",minStemLength:2},{pattern:"\uD558\uC2DC\uBA70",suffixes:["\uD558\uC2DC","\uBA70"],confidence:.82,conjugationType:"connective",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uC5C8\uC5B4",suffixes:["\uD558\uACE0","\uC788\uC5C8\uC5B4"],confidence:.8,conjugationType:"progressive",minStemLength:2},{pattern:"\uD558\uACE0\uC788\uC5C8\uB2E4",suffixes:["\uD558\uACE0","\uC788\uC5C8\uB2E4"],confidence:.8,conjugationType:"progressive",minStemLength:2}];for(let{pattern:r,suffixes:t,confidence:n,conjugationType:a,minStemLength:o}of e)if(i.endsWith(r)){let u=i.slice(0,-r.length);if(u.length<o)continue;return rr(u,n,{removedSuffixes:t,conjugationType:a})}return null}},fi={code:"ko",name:"Korean",nativeName:"\uD55C\uAD6D\uC5B4",regions:["east-asian","priority"],direction:"ltr",script:"hangul",wordOrder:"SOV",markingStrategy:"particle",usesSpaces:true,verb:{position:"end",suffixes:["\uB2E4","\uC694","\uB2C8\uB2E4","\uC138\uC694"],subjectDrop:true},references:{me:"\uB098",it:"\uADF8\uAC83",you:"\uB108",result:"\uACB0\uACFC",event:"\uC774\uBCA4\uD2B8",target:"\uB300\uC0C1",body:"\uBC14\uB514",document:"\uBB38\uC11C",window:"\uCC3D",detail:"\uC138\uBD80"},possessive:{marker:"\uC758",markerPosition:"between",specialForms:{me:"\uB0B4",it:"\uADF8\uAC83\uC758",you:"\uB124"},keywords:{\uB0B4:"me",\uB124:"you",\uADF8\uC758:"it"}},roleMarkers:{patient:{primary:"\uC744",alternatives:["\uB97C"],position:"after"},destination:{primary:"\uC5D0",alternatives:["\uC73C\uB85C","\uB85C","\uC758"],position:"after"},source:{primary:"\uC5D0\uC11C",alternatives:["\uBD80\uD130"],position:"after"},style:{primary:"\uB85C",alternatives:["\uC73C\uB85C"],position:"after"},event:{primary:"\uC744",alternatives:["\uB97C"],position:"after"}},keywords:{toggle:{primary:"\uD1A0\uAE00",normalized:"toggle"},add:{primary:"\uCD94\uAC00",normalized:"add"},remove:{primary:"\uC81C\uAC70",alternatives:["\uC0AD\uC81C"],normalized:"remove"},put:{primary:"\uB123\uB2E4",alternatives:["\uB123\uAE30","\uB193\uAE30","\uB123\uC73C\uC138\uC694"],normalized:"put"},append:{primary:"\uB367\uBD99\uC774\uB2E4",alternatives:["\uB05D\uC5D0\uCD94\uAC00"],normalized:"append"},prepend:{primary:"\uC55E\uC5D0\uCD94\uAC00",alternatives:["\uC120\uB450\uCD94\uAC00"],normalized:"prepend"},take:{primary:"\uAC00\uC838\uC624\uB2E4",alternatives:["\uAC00\uC838\uC624\uC138\uC694"],normalized:"take"},make:{primary:"\uB9CC\uB4E4\uB2E4",normalized:"make"},clone:{primary:"\uBCF5\uC81C",normalized:"clone"},swap:{primary:"\uAD50\uD658",alternatives:["\uBC14\uAFB8\uB2E4"],normalized:"swap"},morph:{primary:"\uBCC0\uD615",alternatives:["\uBCC0\uD658"],normalized:"morph"},set:{primary:"\uC124\uC815",normalized:"set"},get:{primary:"\uC5BB\uB2E4",alternatives:["\uC5BB\uC73C\uC138\uC694"],normalized:"get"},increment:{primary:"\uC99D\uAC00",normalized:"increment"},decrement:{primary:"\uAC10\uC18C",normalized:"decrement"},log:{primary:"\uB85C\uADF8",normalized:"log"},show:{primary:"\uBCF4\uC774\uB2E4",alternatives:["\uD45C\uC2DC","\uBCF4\uC774\uAE30","\uBCF4\uC774\uC138\uC694"],normalized:"show"},hide:{primary:"\uC228\uAE30\uB2E4",alternatives:["\uC228\uAE30\uAE30","\uC228\uAE30\uC138\uC694"],normalized:"hide"},transition:{primary:"\uD2B8\uB79C\uC9C0\uC158",alternatives:["\uC804\uD658"],normalized:"transition"},on:{primary:"\uC5D0",alternatives:["\uC2DC","\uD560 \uB54C"],normalized:"on"},trigger:{primary:"\uD2B8\uB9AC\uAC70",normalized:"trigger"},send:{primary:"\uBCF4\uB0B4\uB2E4",alternatives:["\uBCF4\uB0B4\uC138\uC694"],normalized:"send"},focus:{primary:"\uD3EC\uCEE4\uC2A4",normalized:"focus"},blur:{primary:"\uD3EC\uCEE4\uC2A4\uC544\uC6C3",alternatives:["\uBE14\uB7EC"],normalized:"blur"},empty:{primary:"\uBE44\uC6B0\uAE30",alternatives:["\uBE44\uC5B4\uC788\uB294"],normalized:"empty"},open:{primary:"\uC5F4\uAE30",normalized:"open"},close:{primary:"\uB2EB\uAE30",normalized:"close"},select:{primary:"\uACE0\uB974\uAE30",normalized:"select"},clear:{primary:"\uC9C0\uC6B0\uAE30",normalized:"clear"},reset:{primary:"\uC7AC\uC124\uC815",normalized:"reset"},breakpoint:{primary:"\uC911\uB2E8\uC810",normalized:"breakpoint"},click:{primary:"\uD074\uB9AD",normalized:"click"},hover:{primary:"\uD638\uBC84",normalized:"hover"},submit:{primary:"\uC81C\uCD9C",normalized:"submit"},input:{primary:"\uC785\uB825",normalized:"input"},change:{primary:"\uBCC0\uACBD",normalized:"change"},go:{primary:"\uC774\uB3D9",normalized:"go"},scroll:{primary:"\uC2A4\uD06C\uB864",normalized:"scroll"},push:{primary:"\uD478\uC2DC",normalized:"push"},replace:{primary:"\uAD50\uCCB4",alternatives:["\uBC14\uAFB8\uAE30"],normalized:"replace"},process:{primary:"\uCC98\uB9AC",normalized:"process"},wait:{primary:"\uB300\uAE30",normalized:"wait"},fetch:{primary:"\uD328\uCE58",alternatives:["\uAC00\uC838\uC624\uAE30"],normalized:"fetch"},settle:{primary:"\uC548\uC815",normalized:"settle"},if:{primary:"\uB9CC\uC57D",normalized:"if"},when:{primary:"\uB54C",normalized:"when"},changes:{primary:"\uBCC0\uACBD\uB418\uBA74",normalized:"changes"},where:{primary:"\uC5B4\uB514",normalized:"where"},else:{primary:"\uC544\uB2C8\uBA74",normalized:"else"},unless:{primary:"\uC544\uB2C8\uB77C\uBA74",normalized:"unless"},repeat:{primary:"\uBC18\uBCF5",normalized:"repeat"},for:{primary:"\uAC01\uAC01",normalized:"for"},while:{primary:"\uB3D9\uC548",normalized:"while"},forever:{primary:"forever",normalized:"forever"},continue:{primary:"\uACC4\uC18D",normalized:"continue"},halt:{primary:"\uC815\uC9C0",normalized:"halt"},throw:{primary:"\uB358\uC9C0\uB2E4",normalized:"throw"},call:{primary:"\uD638\uCD9C",normalized:"call"},return:{primary:"\uBC18\uD658",normalized:"return"},then:{primary:"\uADF8\uB2E4\uC74C",alternatives:["\uADF8\uB7F0\uD6C4"],normalized:"then"},and:{primary:"\uADF8\uB9AC\uACE0",alternatives:["\uB610\uD55C","\uBC0F"],normalized:"and"},matches:{primary:"\uC77C\uCE58",normalized:"matches"},exists:{primary:"\uC874\uC7AC",normalized:"exists"},no:{primary:"\uC5C6\uC74C",normalized:"no"},end:{primary:"\uB05D",alternatives:["\uB9C8\uCE68"],normalized:"end"},js:{primary:"JS\uC2E4\uD589",alternatives:["js"],normalized:"js"},async:{primary:"\uBE44\uB3D9\uAE30",normalized:"async"},tell:{primary:"\uB9D0\uD558\uB2E4",normalized:"tell"},default:{primary:"\uAE30\uBCF8\uAC12",normalized:"default"},init:{primary:"\uCD08\uAE30\uD654",normalized:"init"},behavior:{primary:"\uB3D9\uC791",normalized:"behavior"},install:{primary:"\uC124\uCE58",normalized:"install"},measure:{primary:"\uCE21\uC815",normalized:"measure"},beep:{primary:"\uBE44\uD504",normalized:"beep"},break:{primary:"\uC911\uB2E8",normalized:"break"},copy:{primary:"\uBCF5\uC0AC",normalized:"copy"},exit:{primary:"\uB098\uAC00\uAE30",normalized:"exit"},pick:{primary:"\uC120\uD0DD",normalized:"pick"},render:{primary:"\uB80C\uB354\uB9C1",normalized:"render"},into:{primary:"\uC73C\uB85C",normalized:"into"},before:{primary:"\uC804\uC5D0",normalized:"before"},after:{primary:"\uD6C4\uC5D0",normalized:"after"},until:{primary:"\uAE4C\uC9C0",normalized:"until"},event:{primary:"\uC774\uBCA4\uD2B8",normalized:"event"},from:{primary:"\uC5D0\uC11C",normalized:"from"},connect:{primary:"\uC5F0\uACB0",alternatives:["\uC811\uC18D"],normalized:"connect"},stream:{primary:"\uC2A4\uD2B8\uB9BC",alternatives:["\uC2A4\uD2B8\uB9AC\uBC0D"],normalized:"stream"},live:{primary:"\uC2E4\uC2DC\uAC04",alternatives:["\uB77C\uC774\uBE0C"],normalized:"live"},socket:{primary:"\uC18C\uCF13",alternatives:["websocket"],normalized:"socket"},bind:{primary:"\uBC14\uC778\uB4DC",alternatives:["bind"],normalized:"bind"},intercept:{primary:"\uAC00\uB85C\uCC44\uAE30",alternatives:["\uC778\uD130\uC149\uD2B8","intercept"],normalized:"intercept"},worker:{primary:"\uC6CC\uCEE4",alternatives:["worker"],normalized:"worker"},eventsource:{primary:"eventsource",alternatives:["\uC774\uBCA4\uD2B8\uC18C\uC2A4"],normalized:"eventsource"}},tokenization:{particles:["\uC744","\uB97C","\uC774","\uAC00","\uC740","\uB294","\uC5D0","\uC5D0\uC11C","\uC73C\uB85C","\uB85C","\uC640","\uACFC","\uB3C4"],boundaryStrategy:"space"},eventHandler:{eventMarker:{primary:"\uD560 \uB54C",alternatives:["\uD560\uB54C","\uB54C","\uC5D0"],position:"after"},temporalMarkers:["\uD560 \uB54C","\uD560\uB54C","\uB54C"]}},ps=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"],fs=class{constructor(i=ps){this.name="operator",this.operators=[...i].sort((e,r)=>r.length-e.length);}canExtract(i,e){return this.operators.some(r=>i.startsWith(r,e))}extract(i,e){for(let r of this.operators)if(i.startsWith(r,e))return {value:r,length:r.length};return null}},ys="()[]{},:;",hs=class{constructor(i=ys){this.punctuation=i,this.name="punctuation";}canExtract(i,e){return this.punctuation.includes(i[e])}extract(i,e){let r=i[e];return this.punctuation.includes(r)?{value:r,length:1}:null}};function _r(i,e){let r=e;for(;r<i.length&&i[r]===":";){let t=i.slice(r).match(/^::?[a-zA-Z][a-zA-Z0-9-]*/);if(!t)break;let n=r+t[0].length;if(i[n]==="("){let a=0,o=n;for(;o<i.length;){if(i[o]==="(")a++;else if(i[o]===")"&&(a--,a===0)){o++;break}o++;}if(a!==0)break;n=o;}r=n;}return r}function li(i,e){let r=i[e];if(r==="#"){let t=i.slice(e).match(/^#[a-zA-Z_][\w-]*/);if(!t)return null;let n=_r(i,e+t[0].length);return i.slice(e,n)}if(r==="."){let t=i.slice(e).match(/^\.\{[a-zA-Z_$][\w$]*\}/);if(t)return t[0];let n=i.slice(e).match(/^\.[a-zA-Z_][\w-]*/);if(!n)return null;let a=_r(i,e+n[0].length);return i.slice(e,a)}if(r==="@"){let t=i.slice(e).match(/^@[a-zA-Z_][\w-]*/);return t?t[0]:null}if(r==="*"){let t=i.slice(e).match(/^\*(?:--)?[a-zA-Z_][\w-]*/);return t?t[0]:null}if(r==="["){let t=0,n=e;for(;n<i.length;){if(i[n]==="["&&t++,i[n]==="]"&&(t--,t===0)){let a=_r(i,n+1);return i.slice(e,a)}n++;}return null}if(r==="<"){let t=i.slice(e).match(/^<(?=[\w.#[])[\w-]*(?:[#.][\w-]+|\[[^\]]+\]|::?[a-zA-Z][a-zA-Z0-9-]*(?:\([^)]*\))?)*\s*\/>/);return t?t[0]:null}return null}var vs=class{constructor(){this.name="css-selector";}canExtract(i,e){let r=i[e];return r==="#"||r==="."||r==="["||r==="<"?true:r==="@"||r==="*"?li(i,e)!==null:false}extract(i,e){let r=li(i,e);return r?{value:r,length:r.length,metadata:{type:"css-selector"}}:null}},Es=class{constructor(){this.name="event-modifier";}canExtract(i,e){if(i[e]!==".")return false;let r=i.slice(e);return /^\.(once|prevent|stop|debounce|throttle|queue)/.test(r)}extract(i,e){let r=i.slice(e).match(/^\.(?:once|prevent|stop|debounce|throttle|queue)(?:\(([^)]+)\))?/);if(!r)return null;let t=r[0],n=t.slice(1).split("(")[0],a=r[1];return {value:t,length:t.length,metadata:{modifierName:n,value:a?n==="queue"?a:parseInt(a,10):void 0}}}},gs=["http://","https://","//","./","../","/"];function Cs(i,e){let r=1;for(let t=e;t<i.length;t++){let n=i[t];if(n==="{")r++;else if(n==="}"&&--r===0)return t+1}return -1}function zs(i,e){let r=i.slice(e),t=gs.find(a=>r.startsWith(a));if(!t)return null;let n=t.length;for(;n<r.length;){let a=r[n];if(a==="$"&&r[n+1]==="{"){let o=Cs(r,n+2);if(o!==-1){n=o;continue}}if(/\s/.test(a))break;n++;}return r.slice(0,n)}var ks=class{constructor(){this.name="url";}canExtract(i,e){let r=i.slice(e);return r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||r.startsWith("./")||r.startsWith("../")||r.startsWith("/")}extract(i,e){let r=zs(i,e);return r?{value:r,length:r.length,metadata:{type:"url"}}:null}},ws=class{constructor(){this.name="variable-ref";}canExtract(i,e){let r=i[e];return (r===":"||r==="$"||r==="^")&&e+1<i.length&&/[a-zA-Z_]/.test(i[e+1])}extract(i,e){if(!this.canExtract(i,e))return null;let r=1;for(;e+r<i.length&&/[a-zA-Z0-9_]/.test(i[e+r]);)r++;return {value:i.substring(e,e+r),length:r,metadata:{type:"variable-reference"}}}};function bs(i){let e=i.charCodeAt(0);return e>=44032&&e<=55203}function As(i){let e=i.charCodeAt(0);return e>=4352&&e<=4607||e>=12592&&e<=12687}function Ir(i){return bs(i)||As(i)}var Ds=["\uD560\uB54C","\uD558\uBA74","\uD558\uB2C8\uAE4C","\uD560 \uB54C"],Ss=class{constructor(){this.name="korean-keyword";}setContext(i){this.context=i;}canExtract(i,e){return Ir(i[e])}extract(i,e){if(!this.context)throw new Error("KoreanKeywordExtractor: context not set");let r=e,t=6;for(let m=Math.min(t,i.length-r);m>=2;m--){let d=i.slice(r,r+m),p=true;for(let v=0;v<d.length;v++)if(!Ir(d[v])){p=false;break}if(!p)continue;let f=this.context.lookupKeyword(d);if(f)return {value:d,length:m,metadata:{normalized:f.normalized!==f.native?f.normalized:void 0}};if(this.context.normalizer){let v=this.context.normalizer.normalize(d);if(v.stem!==d&&v.confidence>=.7){let E=this.context.lookupKeyword(v.stem);if(E)return {value:d,length:m,metadata:{normalized:E.normalized,stem:v.stem,stemConfidence:v.confidence}}}}}let n="",a=e;for(;a<i.length&&Ir(i[a])&&!(n.length>0&&this.context.isKeywordStart(i,a));)n+=i[a],a++;if(!n)return null;for(let m of Ds)if(n.endsWith(m)&&n.length>m.length){let d=n.slice(0,-m.length),p=this.context.lookupKeyword(d);if(p)return {value:d,length:d.length,metadata:{normalized:p.normalized,hasSuffix:true,suffix:m,stem:d}}}let o=this.context.lookupKeyword(n),u=o&&o.normalized!==o.native?o.normalized:void 0;n.includes("\uD1A0\uAE00")&&(console.log(`[KO DEBUG] word="${n}"`),console.log(`[KO DEBUG] keywordEntry=${o?"FOUND":"NOT FOUND"}`),console.log(`[KO DEBUG] normalizer=${this.context.normalizer?"EXISTS":"MISSING"}`));let s,l,c;if(!o&&this.context.normalizer){let m=this.context.normalizer.normalize(n);if(m.stem!==n&&m.confidence>=.7){let d=this.context.lookupKeyword(m.stem);d&&(s=d.normalized,l=m.stem,c=m.confidence,n.includes("\uD1A0\uAE00")&&console.log(`[KO DEBUG] word="${n}", stem="${m.stem}", normalized="${s}"`));}}return {value:n,length:a-r,metadata:{normalized:u||s,stem:l,stemConfidence:c}}}},ci=new Map([["\uC774",{role:"agent",confidence:.85,variant:"consonant",description:"subject marker (after consonant)"}],["\uAC00",{role:"agent",confidence:.85,variant:"vowel",description:"subject marker (after vowel)"}],["\uC744",{role:"patient",confidence:.95,variant:"consonant",description:"object marker (after consonant)"}],["\uB97C",{role:"patient",confidence:.95,variant:"vowel",description:"object marker (after vowel)"}],["\uC740",{role:"agent",confidence:.75,variant:"consonant",description:"topic marker (after consonant)"}],["\uB294",{role:"agent",confidence:.75,variant:"vowel",description:"topic marker (after vowel)"}],["\uC5D0",{role:"destination",confidence:.85,description:"at/to marker"}],["\uB85C",{role:"destination",confidence:.85,variant:"vowel",description:"to/by means (after vowel or \u3139)"}],["\uC640",{role:"style",confidence:.7,variant:"vowel",description:"and/with (after vowel)"}],["\uACFC",{role:"style",confidence:.7,variant:"consonant",description:"and/with (after consonant)"}],["\uC758",{role:"patient",confidence:.6,description:"possessive marker"}],["\uB3C4",{role:"patient",confidence:.65,description:"also/too marker"}],["\uB9CC",{role:"patient",confidence:.65,description:"only marker"}]]),mi=new Map([["\uC5D0\uC11C",{role:"source",confidence:.8,description:"at/from marker (action location)"}],["\uC73C\uB85C",{role:"destination",confidence:.85,variant:"consonant",description:"to/by means (after consonant)"}],["\uBD80\uD130",{role:"source",confidence:.9,description:"from/since marker"}],["\uAE4C\uC9C0",{role:"destination",confidence:.75,description:"until/to marker"}],["\uCC98\uB7FC",{role:"manner",confidence:.8,description:"like/as marker"}],["\uBCF4\uB2E4",{role:"source",confidence:.75,description:"than marker"}]]);function di(i){if(!i)return false;let e=i.codePointAt(0);return e>=44032&&e<=55203}var Bs=class{constructor(){this.name="korean-particle";}setContext(i){this._context=i,this._context;}canExtract(i,e){let r=i[e];if(ci.has(r)&&!di(i[e+1]))return true;for(let[t]of mi)if(i.startsWith(t,e))return true;return false}extract(i,e){for(let[n,a]of mi)if(i.startsWith(n,e))return {value:n,length:n.length,metadata:{particleRole:a.role,particleConfidence:a.confidence,particleVariant:a.variant}};let r=i[e],t=ci.get(r);return t&&!di(i[e+1])?{value:r,length:1,metadata:{particleRole:t.role,particleConfidence:t.confidence,particleVariant:t.variant}}:null}};function xs(i){let e=i.charCodeAt(0);return e>=65&&e<=90||e>=97&&e<=122||e===95||e===36}function Ts(i){let e=i.charCodeAt(0);return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95||e===36}var Fs=class{constructor(){this.name="ascii-identifier";}setContext(i){this.context=i;}canExtract(i,e){return xs(i[e])}extract(i,e){if(!this.context)throw new Error("AsciiIdentifierExtractor: context not set");let r=e,t="",n=e;for(;n<i.length&&Ts(i[n]);)t+=i[n],n++;if(!t)return null;let a=this.context.lookupKeyword(t),o=a&&a.normalized!==a.native?a.normalized:void 0;return {value:t,length:n-r,metadata:{normalized:o}}}};function Rs(){return [new ks,new Es,new ws,new vs]}var Os=new Set(["\uC774","\uAC00","\uC744","\uB97C","\uC740","\uB294","\uC5D0","\uC5D0\uC11C","\uB85C","\uC73C\uB85C","\uC640","\uACFC","\uC758","\uB3C4","\uB9CC","\uBD80\uD130","\uAE4C\uC9C0","\uCC98\uB7FC","\uBCF4\uB2E4"]),Ps=[{native:"\uCC38",normalized:"true"},{native:"\uAC70\uC9D3",normalized:"false"},{native:"\uB110",normalized:"null"},{native:"\uBBF8\uC815\uC758",normalized:"undefined"},{native:"\uC815\uC758\uC548\uB428",normalized:"undefined"},{native:"\uCCAB\uBC88\uC9F8",normalized:"first"},{native:"\uB9C8\uC9C0\uB9C9",normalized:"last"},{native:"\uB2E4\uC74C",normalized:"next"},{native:"\uC774\uC804",normalized:"previous"},{native:"\uAC00\uC7A5\uAC00\uAE4C\uC6B4",normalized:"closest"},{native:"\uBD80\uBAA8",normalized:"parent"},{native:"\uC548\uC5D0",normalized:"in"},{native:"\uD074\uB9AD",normalized:"click"},{native:"\uB354\uBE14\uD074\uB9AD",normalized:"dblclick"},{native:"\uBCC0\uACBD",normalized:"change"},{native:"\uC81C\uCD9C",normalized:"submit"},{native:"\uC785\uB825",normalized:"input"},{native:"\uB85C\uB4DC",normalized:"load"},{native:"\uC2A4\uD06C\uB864",normalized:"scroll"},{native:"\uD0A4\uB2E4\uC6B4",normalized:"keydown"},{native:"\uD0A4\uC5C5",normalized:"keyup"},{native:"\uB9C8\uC6B0\uC2A4\uC624\uBC84",normalized:"mouseover"},{native:"\uB9C8\uC6B0\uC2A4\uC544\uC6C3",normalized:"mouseout"},{native:"\uB9C8\uC6B0\uC2A4\uB2E4\uC6B4",normalized:"mousedown"},{native:"\uB9C8\uC6B0\uC2A4\uC5C5",normalized:"mouseup"},{native:"\uB0B4",normalized:"my"},{native:"\uADF8\uAC83\uC758",normalized:"its"},{native:"\uADF8\uB2E4\uC74C",normalized:"then"},{native:"\uADF8\uB7F0\uD6C4",normalized:"then"},{native:"\uADF8\uB7EC\uBA74",normalized:"then"},{native:"\uADF8\uB9AC\uACE0",normalized:"and"},{native:"\uB610\uB294",normalized:"or"},{native:"\uC544\uB2C8",normalized:"not"},{native:"\uC774\uB2E4",normalized:"is"},{native:"\uCD08",normalized:"s"},{native:"\uBC00\uB9AC\uCD08",normalized:"ms"},{native:"\uBD84",normalized:"m"},{native:"\uC2DC\uAC04",normalized:"h"},{native:"\uD3EC\uD568",normalized:"inclusive"},{native:"\uC81C\uC678",normalized:"exclusive"},{native:"\uBB38\uC790",normalized:"characters"},{native:"\uBB34\uC791\uC704",normalized:"random"}],Ls=class extends Xr{constructor(){super(),this.language="ko",this.direction="ltr",this.initializeKeywordsFromProfile(fi,Ps),this.normalizer=new pi,this.registerExtractors(Rs()),this.registerExtractor(new Zr),this.registerExtractor(new Jr),this.registerExtractor(new Fs),this.registerExtractor(new Bs),this.registerExtractor(new Ss),this.registerExtractor(new fs),this.registerExtractor(new hs);}classifyToken(i){return Os.has(i)?"particle":this.isKeyword(i)?"keyword":i.startsWith("/")||i.startsWith("./")||i.startsWith("../")||i.startsWith("http")?"url":/^\.(once|prevent|stop|debounce|throttle|queue)(\(.*\))?$/.test(i)?"event-modifier":i.startsWith("#")||i.startsWith(".")||i.startsWith("[")||i.startsWith("*")||i.startsWith("<")?"selector":i.startsWith('"')||i.startsWith("'")||/^\d/.test(i)?"literal":"identifier"}},Ns=new Ls;Tt("ko",Ns,fi);function lr(i){let e=i.getAttribute("data-lang");if(e)return sr(e);let r=i.getAttribute("data-hyperscript-lang")??i.closest?.("[data-hyperscript-lang]")?.getAttribute("data-hyperscript-lang");if(r)return sr(r);let t=i.closest?.("[lang]")?.getAttribute("lang");if(t)return sr(t);let n=typeof document<"u"?document.documentElement?.lang:null;return n&&n!=="en"?sr(n):null}function sr(i){return i.split("-")[0].toLowerCase()}var yi={add:[["patient",""],["destination","to"]],append:[["patient",""],["destination","to"]],beep:[["patient",""]],behavior:[["patient",""]],bind:[["destination",""],["source","to"]],blur:[["patient",""]],break:[],breakpoint:[],call:[["patient",""]],clear:[["patient",""]],clone:[["patient",""],["destination","into"]],close:[["patient",""]],compound:[],continue:[],copy:[["patient",""]],decrement:[["patient",""],["quantity","by"]],default:[["destination",""],["patient","to"]],else:[],empty:[["patient",""]],eventsource:[],exit:[],fetch:[["source",""],["style","with"],["responseType","as"],["method","via"],["destination","on"]],focus:[["patient",""]],for:[["patient",""],["source","in"]],get:[["source",""],["destination","on"]],go:[["destination",""]],halt:[["patient",""]],hide:[["patient",""],["style","with"]],if:[["condition",""]],increment:[["patient",""],["quantity","by"]],init:[],install:[["patient",""],["destination","on"]],intercept:[],js:[["patient",""]],live:[],log:[["patient",""]],make:[["patient",""]],measure:[["patient",""],["source","of"]],morph:[["patient",""],["destination","to"],["manner","using view"]],on:[["event",""],["source","from"]],open:[["patient",""],["style","as"]],pick:[["patient",""],["source","from"]],prepend:[["patient",""],["destination","to"]],process:[["patient","partials in"],["manner","using view"]],push:[["patient","url"]],put:[["patient",""],["destination","into"]],remove:[["patient",""],["source","from"]],render:[["patient",""],["style","with"]],repeat:[["quantity",""],["condition","until"]],replace:[["patient","url"]],reset:[["patient",""]],return:[["patient",""]],scroll:[["destination","to"]],select:[["patient",""]],send:[["event",""],["destination","to"]],set:[["destination",""],["patient","to"],["scope","on"]],settle:[["patient",""]],show:[["patient",""],["style","with"]],socket:[],swap:[["method",""],["destination","of"],["patient","with"],["manner","using view"]],take:[["patient",""],["source","from"],["recipient","for"]],tell:[["destination",""]],throw:[["patient",""]],toggle:[["patient",""],["destination","on"],["duration","for"]],transition:[["patient",""],["goal","to"],["destination","on"],["duration","over"],["style","with"]],trigger:[["event",""],["destination","on"]],unless:[["condition",""]],wait:[["duration",""]],when:[["condition",""]],while:[["condition",""]],worker:[]};var Ms=new Set(["repeat","for","while","tell"]),_s=new Set(["js"]);function cr(i){switch(i.kind){case "event-handler":return Is(i);case "compound":return js(i);default:return $s(i)}}function Is(i){let e=["on"],r=i.roles.get("event");r&&e.push(r.type==="literal"?String(r.value):Ye(r));let t=i.roles.get("source");if(t&&e.push("from",Ye(t)),i.body&&i.body.length>0){let n=i.body.map(cr);e.push(n.join(" "));}return e.join(" ")}function js(i){let e=i.chainType==="async"?"async":i.chainType,r=i.statements.map(cr),t=r[0]??"";for(let n=1;n<r.length;n++){let a=i.statements[n-1],o=i.statements[n],u=a.kind==="command"&&Ms.has(a.action),s=a.kind==="command"&&a.action==="bind"&&o.kind==="command"&&o.action==="bind";a.kind==="command"&&_s.has(a.action)&&(t+=" end"),t+=(u||s?" ":` ${e} `)+r[n];}return t}function $s(i){let e=yi[i.action];if(e){let t=[i.action];for(let[n,a]of e){let o=i.roles.get(n);o&&((n==="destination"||n==="source")&&o.type==="reference"&&o.value==="me"||(a&&t.push(a),t.push(Ye(o))));}return t.join(" ")}let r=[i.action];for(let[,t]of i.roles)r.push(Ye(t));return r.join(" ")}function Ye(i){switch(i.type){case "literal":return typeof i.value=="string"&&i.dataType==="string"?`"${i.value}"`:String(i.value);case "selector":return i.value;case "reference":return i.value;case "property-path":return Vs(i);case "expression":return i.raw;case "flag":return i.enabled?`+${i.name}`:`~${i.name}`}}function Vs(i){let e=Ye(i.object),r=i.property;if(i.object.type==="reference")switch(i.object.value){case "me":return `my ${r}`;case "it":return `its ${r}`;case "you":return `your ${r}`}return `${e}'s ${r}`}var qs={confidenceThreshold:.5,strategy:"semantic"};function Ws(i,e){return typeof i=="number"?i:i[e]??i["*"]??.5}var Ks=/^(on\s+(?:every\s+)?[\w-]+(?:\[.*?\])?(?:\.[\w-]+(?:\([^)]*\))?)*(?:\s+from\s+\S+)?(?:\s+queue\s+\w+)?\s+)/;function Hs(i){let e=i.match(Ks);if(!e)return null;let r=e[1],t=i.slice(r.length);return t?{prefix:r,commands:t}:null}function hi(i){function e(n,a,o){try{return i.isLanguageRegistered(a)?i.translateSingle(n,a,o):null}catch{return null}}function r(n,a,o){try{let u=o(n,a);return u!==n?u:null}catch{return null}}function t(n,a,o){if(o.strategy==="semantic"||o.strategy==="auto"){let u=Ws(o.confidenceThreshold,a),s=e(n,a,u);if(s!==null)return s}if((o.strategy==="auto"||o.strategy==="i18n")&&o.i18nToEnglish){let u=r(n,a,o.i18nToEnglish);if(u!==null)return u}return null}return function(a,o,u={}){if(o==="en")return a;let s={...qs,...u},l=t(a,o,s);if(l!==null)return l;let c=Hs(a);if(c){let m=t(c.commands,o,s);if(m!==null)return c.prefix+m}return a}}var jr=hi({isLanguageRegistered:Rt,translateSingle(i,e,r){let t=Qt(i,e);return t.confidence<r||!t.node?null:cr(t.node)}});var $r=new WeakSet;function Us(i){return (i.config?.attributes??"_, script, data-script").split(",").map(r=>r.trim()).filter(Boolean)}function Gs(i,e){for(let r of e)if(i.hasAttribute(r))return r;return null}function vi(i,e){if(typeof i.addBeforeProcessHook!="function"){console.warn("[hyperscript-i18n] _hyperscript.addBeforeProcessHook is unavailable \u2014 this build of _hyperscript.org is not supported. Load a current version from https://unpkg.com/hyperscript.org.");return}let r=Us(i),t=[...r.map(a=>`[${a}]`),'script[type="text/hyperscript"]'].join(", "),n=a=>{if($r.has(a))return;if(a instanceof HTMLScriptElement&&a.type==="text/hyperscript"){let l=a.textContent??"";if(!l)return;let c=e(l,a);$r.add(a),c!=null&&c!==l&&(a.textContent=c);return}let o=Gs(a,r);if(!o)return;let u=a.getAttribute(o);if(!u)return;let s=e(u,a);$r.add(a),s!=null&&s!==u&&a.setAttribute(o,s);};i.addBeforeProcessHook(a=>{!a||typeof a.querySelectorAll!="function"||(typeof a.matches=="function"&&a.matches(t)&&n(a),a.querySelectorAll(t).forEach(n));});}function gi(i,e){if(typeof i.parse!="function")return true;try{let r=i.parse(e);return !r?.errors||r.errors.length===0}catch{return false}}var Ei=new Set;function Ci(i,e,r){Ei.has(i)||(Ei.add(i),console.warn(`[hyperscript-i18n] Translation for lang="${i}" rendered hyperscript the host parser rejects \u2014 falling back to the original text. Source: "${e.length>60?e.slice(0,60)+"\u2026":e}" \u2192 "${r.length>60?r.slice(0,60)+"\u2026":r}". Further elements in this language stay quiet \u2014 enable { debug: true } for per-element detail.`));}function Vr(i={}){return function(r){let t=r;vi(t,(n,a)=>{let o=Ys(a,i);if(!o||o==="en")return n;let u=jr(n,o,i);if(u!==n){if(i.validateWithHost!==false&&!gi(t,u))return i.debug?console.log(`[hyperscript-i18n] ${o}: host rejected "${u}" \u2014 keeping "${n}"`):Ci(o,n,u),n;i.debug&&console.log(`[hyperscript-i18n] ${o}: "${n}" \u2192 "${u}"`);}return u});}}function Ys(i,e){if(e.languageAttribute){let t=i.getAttribute(e.languageAttribute);if(t)return t.split("-")[0].toLowerCase()}let r=lr(i);return r||(e.defaultLanguage??null)}function zi(i,e,r={}){return e==="en"?i:jr(i,e,r)}Ft(i=>ui(i));function ki(){typeof _hyperscript<"u"&&_hyperscript.use&&_hyperscript.use(Vr());}var Sc=["ko"];ki();
5
+ exports.plugin=Vr;exports.preprocess=zi;exports.resolveLanguage=lr;exports.supportedLanguages=Sc;return exports;})({});