@nine-lab/nine-ai 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{few_shot-CsdUyb-S.js → few_shot-BRgFY2uB.js} +2 -2
- package/dist/{few_shot-CsdUyb-S.js.map → few_shot-BRgFY2uB.js.map} +1 -1
- package/dist/{index-bkxU1yQC.js → index-tIkLfn75.js} +12 -12
- package/dist/{index-bkxU1yQC.js.map → index-tIkLfn75.js.map} +1 -1
- package/dist/nine-ai.js +1 -1
- package/dist/nine-ai.umd.cjs +2 -2
- package/dist/nine-ai.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/nine-ai.umd.cjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/*!
|
|
13
13
|
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
|
14
14
|
* http://github.com/janl/mustache.js
|
|
15
|
-
*/var iu=Object.prototype.toString,nu=Array.isArray||function(e){return"[object Array]"===iu.call(e)};function ru(e){return"function"==typeof e}function su(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function au(e,t){return null!=e&&"object"==typeof e&&t in e}function ou(e,t){return null!=e&&"object"!=typeof e&&e.hasOwnProperty&&e.hasOwnProperty(t)}var lu=RegExp.prototype.test;var cu=/\S/;function hu(e){return!function(e,t){return lu.call(e,t)}(cu,e)}var uu={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};var du=/\s*/,pu=/\s+/,fu=/\s*=/,mu=/\s*\}/,gu=/#|\^|\/|>|\{|&|=|!/;function Ou(e){this.string=e,this.tail=e,this.pos=0}function vu(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function yu(){this.templateCache={_cache:{},set:function(e,t){this._cache[e]=t},get:function(e){return this._cache[e]},clear:function(){this._cache={}}}}Ou.prototype.eos=function(){return""===this.tail},Ou.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var i=t[0];return this.tail=this.tail.substring(i.length),this.pos+=i.length,i},Ou.prototype.scanUntil=function(e){var t,i=this.tail.search(e);switch(i){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,i),this.tail=this.tail.substring(i)}return this.pos+=t.length,t},vu.prototype.push=function(e){return new vu(e,this)},vu.prototype.lookup=function(e){var t,i=this.cache;if(i.hasOwnProperty(e))t=i[e];else{for(var n,r,s,a=this,o=!1;a;){if(e.indexOf(".")>0)for(n=a.view,r=e.split("."),s=0;null!=n&&s<r.length;)s===r.length-1&&(o=au(n,r[s])||ou(n,r[s])),n=n[r[s++]];else n=a.view[e],o=au(a.view,e);if(o){t=n;break}a=a.parent}i[e]=t}return ru(t)&&(t=t.call(this.view)),t},yu.prototype.clearCache=function(){void 0!==this.templateCache&&this.templateCache.clear()},yu.prototype.parse=function(e,t){var i=this.templateCache,n=e+":"+(t||bu.tags).join(":"),r=void 0!==i,s=r?i.get(n):void 0;return null==s&&(s=function(e,t){if(!e)return[];var i,n,r,s=!1,a=[],o=[],l=[],c=!1,h=!1,u="",d=0;function p(){if(c&&!h)for(;l.length;)delete o[l.pop()];else l=[];c=!1,h=!1}function f(e){if("string"==typeof e&&(e=e.split(pu,2)),!nu(e)||2!==e.length)throw new Error("Invalid tags: "+e);i=new RegExp(su(e[0])+"\\s*"),n=new RegExp("\\s*"+su(e[1])),r=new RegExp("\\s*"+su("}"+e[1]))}f(t||bu.tags);for(var m,g,O,v,y,b,w=new Ou(e);!w.eos();){if(m=w.pos,O=w.scanUntil(i))for(var _=0,x=O.length;_<x;++_)hu(v=O.charAt(_))?(l.push(o.length),u+=v):(h=!0,s=!0,u+=" "),o.push(["text",v,m,m+1]),m+=1,"\n"===v&&(p(),u="",d=0,s=!1);if(!w.scan(i))break;if(c=!0,g=w.scan(gu)||"name",w.scan(du),"="===g?(O=w.scanUntil(fu),w.scan(fu),w.scanUntil(n)):"{"===g?(O=w.scanUntil(r),w.scan(mu),w.scanUntil(n),g="&"):O=w.scanUntil(n),!w.scan(n))throw new Error("Unclosed tag at "+w.pos);if(y=">"==g?[g,O,m,w.pos,u,d,s]:[g,O,m,w.pos],d++,o.push(y),"#"===g||"^"===g)a.push(y);else if("/"===g){if(!(b=a.pop()))throw new Error('Unopened section "'+O+'" at '+m);if(b[1]!==O)throw new Error('Unclosed section "'+b[1]+'" at '+m)}else"name"===g||"{"===g||"&"===g?h=!0:"="===g&&f(O)}if(p(),b=a.pop())throw new Error('Unclosed section "'+b[1]+'" at '+w.pos);return function(e){for(var t,i=[],n=i,r=[],s=0,a=e.length;s<a;++s)switch((t=e[s])[0]){case"#":case"^":n.push(t),r.push(t),n=t[4]=[];break;case"/":r.pop()[5]=t[2],n=r.length>0?r[r.length-1][4]:i;break;default:n.push(t)}return i}(function(e){for(var t,i,n=[],r=0,s=e.length;r<s;++r)(t=e[r])&&("text"===t[0]&&i&&"text"===i[0]?(i[1]+=t[1],i[3]=t[3]):(n.push(t),i=t));return n}(o))}(e,t),r&&i.set(n,s)),s},yu.prototype.render=function(e,t,i,n){var r=this.getConfigTags(n),s=this.parse(e,r),a=t instanceof vu?t:new vu(t,void 0);return this.renderTokens(s,a,i,e,n)},yu.prototype.renderTokens=function(e,t,i,n,r){for(var s,a,o,l="",c=0,h=e.length;c<h;++c)o=void 0,"#"===(a=(s=e[c])[0])?o=this.renderSection(s,t,i,n,r):"^"===a?o=this.renderInverted(s,t,i,n,r):">"===a?o=this.renderPartial(s,t,i,r):"&"===a?o=this.unescapedValue(s,t):"name"===a?o=this.escapedValue(s,t,r):"text"===a&&(o=this.rawValue(s)),void 0!==o&&(l+=o);return l},yu.prototype.renderSection=function(e,t,i,n,r){var s=this,a="",o=t.lookup(e[1]);if(o){if(nu(o))for(var l=0,c=o.length;l<c;++l)a+=this.renderTokens(e[4],t.push(o[l]),i,n,r);else if("object"==typeof o||"string"==typeof o||"number"==typeof o)a+=this.renderTokens(e[4],t.push(o),i,n,r);else if(ru(o)){if("string"!=typeof n)throw new Error("Cannot use higher-order sections without the original template");null!=(o=o.call(t.view,n.slice(e[3],e[5]),function(e){return s.render(e,t,i,r)}))&&(a+=o)}else a+=this.renderTokens(e[4],t,i,n,r);return a}},yu.prototype.renderInverted=function(e,t,i,n,r){var s=t.lookup(e[1]);if(!s||nu(s)&&0===s.length)return this.renderTokens(e[4],t,i,n,r)},yu.prototype.indentPartial=function(e,t,i){for(var n=t.replace(/[^ \t]/g,""),r=e.split("\n"),s=0;s<r.length;s++)r[s].length&&(s>0||!i)&&(r[s]=n+r[s]);return r.join("\n")},yu.prototype.renderPartial=function(e,t,i,n){if(i){var r=this.getConfigTags(n),s=ru(i)?i(e[1]):i[e[1]];if(null!=s){var a=e[6],o=e[5],l=e[4],c=s;0==o&&l&&(c=this.indentPartial(s,l,a));var h=this.parse(c,r);return this.renderTokens(h,t,i,c,n)}}},yu.prototype.unescapedValue=function(e,t){var i=t.lookup(e[1]);if(null!=i)return i},yu.prototype.escapedValue=function(e,t,i){var n=this.getConfigEscape(i)||bu.escape,r=t.lookup(e[1]);if(null!=r)return"number"==typeof r&&n===bu.escape?String(r):n(r)},yu.prototype.rawValue=function(e){return e[1]},yu.prototype.getConfigTags=function(e){return nu(e)?e:e&&"object"==typeof e?e.tags:void 0},yu.prototype.getConfigEscape=function(e){return e&&"object"==typeof e&&!nu(e)?e.escape:void 0};var bu={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(e){wu.templateCache=e},get templateCache(){return wu.templateCache}},wu=new yu;function _u(){bu.escape=e=>e}bu.clearCache=function(){return wu.clearCache()},bu.parse=function(e,t){return wu.parse(e,t)},bu.render=function(e,t,i,n){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string" but "'+((nu(r=e)?"array":typeof r)+'" was given as the first argument for mustache#render(template, view, partials)'));var r;return wu.render(e,t,i,n)},bu.escape=function(e){return String(e).replace(/[&<>"'`=\/]/g,function(e){return uu[e]})},bu.Scanner=Ou,bu.Context=vu,bu.Writer=yu;const xu=e=>{const t=e.split(""),i=[],n=(e,i)=>{for(let n=i;n<t.length;n+=1)if(e.includes(t[n]))return n;return-1};let r=0;for(;r<t.length;)if("{"===t[r]&&r+1<t.length&&"{"===t[r+1])i.push({type:"literal",text:"{"}),r+=2;else if("}"===t[r]&&r+1<t.length&&"}"===t[r+1])i.push({type:"literal",text:"}"}),r+=2;else if("{"===t[r]){const e=n("}",r);if(e<0)throw new Error("Unclosed '{' in template.");i.push({type:"variable",name:t.slice(r+1,e).join("")}),r=e+1}else{if("}"===t[r])throw new Error("Single '}' in template.");{const e=n("{}",r),s=(e<0?t.slice(r):t.slice(r,e)).join("");i.push({type:"literal",text:s}),r=e<0?t.length:e}}return i},Su=(e,t=[])=>{const i=[];for(const n of e)if("name"===n[0]){const e=n[1].includes(".")?n[1].split(".")[0]:n[1];i.push({type:"variable",name:e})}else if(["#","&","^",">"].includes(n[0])){if(i.push({type:"variable",name:n[1]}),"#"===n[0]&&n.length>4&&Array.isArray(n[4])){const e=[...t,n[1]],r=Su(n[4],e);i.push(...r)}}else i.push({type:"literal",text:n[1]});return i},ku={"f-string":(e,t)=>xu(e).reduce((e,i)=>{if("variable"===i.type){if(i.name in t){return e+("string"==typeof t[i.name]?t[i.name]:JSON.stringify(t[i.name]))}throw new Error(`(f-string) Missing value for input ${i.name}`)}return e+i.text},""),mustache:(e,t)=>(_u(),bu.render(e,t))},Pu={"f-string":xu,mustache:e=>{_u();const t=bu.parse(e);return Su(t)}},Tu=(e,t,i)=>{try{return ku[t](e,i)}catch(n){throw vo(n,"INVALID_PROMPT_INPUT")}},$u=(e,t,i)=>{if(!(t in ku)){const e=Object.keys(ku);throw new Error(`Invalid template format. Got \`${t}\`;\n should be one of ${e}`)}try{const n=i.reduce((e,t)=>(e[t]="foo",e),{});Array.isArray(e)?e.forEach(e=>{if("text"===e.type)Tu(e.text,t,n);else{if("image_url"!==e.type)throw new Error(`Invalid message template received. ${JSON.stringify(e,null,2)}`);if("string"==typeof e.image_url)Tu(e.image_url,t,n);else{const i=e.image_url.url;Tu(i,t,n)}}}):Tu(e,t,n)}catch(n){throw new Error(`Invalid prompt schema: ${n.message}`)}};class Eu extends tu{static lc_name(){return"PromptTemplate"}constructor(e){if(super(e),Object.defineProperty(this,"template",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"templateFormat",{enumerable:!0,configurable:!0,writable:!0,value:"f-string"}),Object.defineProperty(this,"validateTemplate",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"additionalContentFields",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),"mustache"===e.templateFormat&&void 0===e.validateTemplate&&(this.validateTemplate=!1),Object.assign(this,e),this.validateTemplate){if("mustache"===this.templateFormat)throw new Error("Mustache templates cannot be validated.");let e=this.inputVariables;this.partialVariables&&(e=e.concat(Object.keys(this.partialVariables))),$u(this.template,this.templateFormat,e)}}_getPromptType(){return"prompt"}async format(e){const t=await this.mergePartialAndUserVariables(e);return Tu(this.template,this.templateFormat,t)}static fromExamples(e,t,i,n="\n\n",r=""){const s=[r,...e,t].join(n);return new Eu({inputVariables:i,template:s})}static fromTemplate(e,t){const{templateFormat:i="f-string",...n}=t??{},r=new Set;return((e,t)=>Pu[t](e))(e,i).forEach(e=>{"variable"===e.type&&r.add(e.name)}),new Eu({inputVariables:[...r],templateFormat:i,template:e,...n})}async partial(e){const t=this.inputVariables.filter(t=>!(t in e)),i={...this.partialVariables??{},...e},n={...this,inputVariables:t,partialVariables:i};return new Eu(n)}serialize(){if(void 0!==this.outputParser)throw new Error("Cannot serialize a prompt template with an output parser");return{_type:this._getPromptType(),input_variables:this.inputVariables,template:this.template,template_format:this.templateFormat}}static async deserialize(e){if(!e.template)throw new Error("Prompt template must have a template");return new Eu({inputVariables:e.input_variables,template:e.template,templateFormat:e.template_format})}}const Au=Object.freeze(Object.defineProperty({__proto__:null,PromptTemplate:Eu},Symbol.toStringTag,{value:"Module"}));class Cu extends tu{constructor(e){if(super(e),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"examples",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exampleSelector",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"examplePrompt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"suffix",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"exampleSeparator",{enumerable:!0,configurable:!0,writable:!0,value:"\n\n"}),Object.defineProperty(this,"prefix",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"templateFormat",{enumerable:!0,configurable:!0,writable:!0,value:"f-string"}),Object.defineProperty(this,"validateTemplate",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.assign(this,e),void 0!==this.examples&&void 0!==this.exampleSelector)throw new Error("Only one of 'examples' and 'example_selector' should be provided");if(void 0===this.examples&&void 0===this.exampleSelector)throw new Error("One of 'examples' and 'example_selector' should be provided");if(this.validateTemplate){let e=this.inputVariables;this.partialVariables&&(e=e.concat(Object.keys(this.partialVariables))),$u(this.prefix+this.suffix,this.templateFormat,e)}}_getPromptType(){return"few_shot"}static lc_name(){return"FewShotPromptTemplate"}async getExamples(e){if(void 0!==this.examples)return this.examples;if(void 0!==this.exampleSelector)return this.exampleSelector.selectExamples(e);throw new Error("One of 'examples' and 'example_selector' should be provided")}async partial(e){const t=this.inputVariables.filter(t=>!(t in e)),i={...this.partialVariables??{},...e},n={...this,inputVariables:t,partialVariables:i};return new Cu(n)}async format(e){const t=await this.mergePartialAndUserVariables(e),i=await this.getExamples(t),n=await Promise.all(i.map(e=>this.examplePrompt.format(e))),r=[this.prefix,...n,this.suffix].join(this.exampleSeparator);return Tu(r,this.templateFormat,t)}serialize(){if(this.exampleSelector||!this.examples)throw new Error("Serializing an example selector is not currently supported");if(void 0!==this.outputParser)throw new Error("Serializing an output parser is not currently supported");return{_type:this._getPromptType(),input_variables:this.inputVariables,example_prompt:this.examplePrompt.serialize(),example_separator:this.exampleSeparator,suffix:this.suffix,prefix:this.prefix,template_format:this.templateFormat,examples:this.examples}}static async deserialize(e){const{example_prompt:t}=e;if(!t)throw new Error("Missing example prompt");const i=await Eu.deserialize(t);let n;if(!Array.isArray(e.examples))throw new Error("Invalid examples format. Only list or string are supported.");return n=e.examples,new Cu({inputVariables:e.input_variables,examplePrompt:i,examples:n,exampleSeparator:e.example_separator,prefix:e.prefix,suffix:e.suffix,templateFormat:e.template_format})}}const Ru=Object.freeze(Object.defineProperty({__proto__:null,FewShotPromptTemplate:Cu},Symbol.toStringTag,{value:"Module"})),Qu=class{};i=new WeakMap,n=new WeakMap,ge(Qu,i,window.__API_BASE_URL__||""),ge(Qu,n,(e,n,r={})=>{n=`${me(Qu,i)}${n}`,t.loading.show(),"GET"===e&&(n+=`?${new URLSearchParams(r)}`);const s={method:e,headers:{"Content-Type":"application/json"}};return"GET"!==e&&(s.body=JSON.stringify(r)),fetch(n,s).then(e=>("/api/source/query"!==n&&t.loading.hide(),e.ok?e.json():e.text().then(t=>{throw new Error(`API 오류 (${e.status}): ${t}`)}))).catch(e=>{throw t.loading.hide(),e})}),pe(Qu,"get",(e,t={})=>{var i;return me(i=Qu,n).call(i,"GET",e,t)}),pe(Qu,"post",(e,t={})=>{var i;return me(i=Qu,n).call(i,"POST",e,t)});let Iu=Qu;const ju=Iu;class Mu{constructor(){}}var Nu,Lu,Zu,Du,zu,Uu;pe(Mu,"generatePrompt",async(e,t)=>{Array.isArray(e)||(e=[e]);let i="";for(let n of e)i+=await fetch(n).then(e=>e.text());return await new Eu({template:i,inputVariables:Object.keys(t)}).format(t)}),pe(Mu,"extractResponse",(e,t)=>{const i=e=>{const t=e.match(/```(?:json|jsx|xml|java)([\s\S]*?)```/);return t?t[1].trim():e};let n;switch(t){case"chatopenai":case"openai":case"gemini":n=i(e.content.trim());break;case"ollama":n=i(e)}try{return JSON.parse(n)}catch(r){return n}}),(Lu=Nu||(Nu={})).STRING="string",Lu.NUMBER="number",Lu.INTEGER="integer",Lu.BOOLEAN="boolean",Lu.ARRAY="array",Lu.OBJECT="object",(Du=Zu||(Zu={})).LANGUAGE_UNSPECIFIED="language_unspecified",Du.PYTHON="python",(Uu=zu||(zu={})).OUTCOME_UNSPECIFIED="outcome_unspecified",Uu.OUTCOME_OK="outcome_ok",Uu.OUTCOME_FAILED="outcome_failed",Uu.OUTCOME_DEADLINE_EXCEEDED="outcome_deadline_exceeded";
|
|
15
|
+
*/var iu=Object.prototype.toString,nu=Array.isArray||function(e){return"[object Array]"===iu.call(e)};function ru(e){return"function"==typeof e}function su(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function au(e,t){return null!=e&&"object"==typeof e&&t in e}function ou(e,t){return null!=e&&"object"!=typeof e&&e.hasOwnProperty&&e.hasOwnProperty(t)}var lu=RegExp.prototype.test;var cu=/\S/;function hu(e){return!function(e,t){return lu.call(e,t)}(cu,e)}var uu={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};var du=/\s*/,pu=/\s+/,fu=/\s*=/,mu=/\s*\}/,gu=/#|\^|\/|>|\{|&|=|!/;function Ou(e){this.string=e,this.tail=e,this.pos=0}function vu(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function yu(){this.templateCache={_cache:{},set:function(e,t){this._cache[e]=t},get:function(e){return this._cache[e]},clear:function(){this._cache={}}}}Ou.prototype.eos=function(){return""===this.tail},Ou.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var i=t[0];return this.tail=this.tail.substring(i.length),this.pos+=i.length,i},Ou.prototype.scanUntil=function(e){var t,i=this.tail.search(e);switch(i){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,i),this.tail=this.tail.substring(i)}return this.pos+=t.length,t},vu.prototype.push=function(e){return new vu(e,this)},vu.prototype.lookup=function(e){var t,i=this.cache;if(i.hasOwnProperty(e))t=i[e];else{for(var n,r,s,a=this,o=!1;a;){if(e.indexOf(".")>0)for(n=a.view,r=e.split("."),s=0;null!=n&&s<r.length;)s===r.length-1&&(o=au(n,r[s])||ou(n,r[s])),n=n[r[s++]];else n=a.view[e],o=au(a.view,e);if(o){t=n;break}a=a.parent}i[e]=t}return ru(t)&&(t=t.call(this.view)),t},yu.prototype.clearCache=function(){void 0!==this.templateCache&&this.templateCache.clear()},yu.prototype.parse=function(e,t){var i=this.templateCache,n=e+":"+(t||bu.tags).join(":"),r=void 0!==i,s=r?i.get(n):void 0;return null==s&&(s=function(e,t){if(!e)return[];var i,n,r,s=!1,a=[],o=[],l=[],c=!1,h=!1,u="",d=0;function p(){if(c&&!h)for(;l.length;)delete o[l.pop()];else l=[];c=!1,h=!1}function f(e){if("string"==typeof e&&(e=e.split(pu,2)),!nu(e)||2!==e.length)throw new Error("Invalid tags: "+e);i=new RegExp(su(e[0])+"\\s*"),n=new RegExp("\\s*"+su(e[1])),r=new RegExp("\\s*"+su("}"+e[1]))}f(t||bu.tags);for(var m,g,O,v,y,b,w=new Ou(e);!w.eos();){if(m=w.pos,O=w.scanUntil(i))for(var _=0,x=O.length;_<x;++_)hu(v=O.charAt(_))?(l.push(o.length),u+=v):(h=!0,s=!0,u+=" "),o.push(["text",v,m,m+1]),m+=1,"\n"===v&&(p(),u="",d=0,s=!1);if(!w.scan(i))break;if(c=!0,g=w.scan(gu)||"name",w.scan(du),"="===g?(O=w.scanUntil(fu),w.scan(fu),w.scanUntil(n)):"{"===g?(O=w.scanUntil(r),w.scan(mu),w.scanUntil(n),g="&"):O=w.scanUntil(n),!w.scan(n))throw new Error("Unclosed tag at "+w.pos);if(y=">"==g?[g,O,m,w.pos,u,d,s]:[g,O,m,w.pos],d++,o.push(y),"#"===g||"^"===g)a.push(y);else if("/"===g){if(!(b=a.pop()))throw new Error('Unopened section "'+O+'" at '+m);if(b[1]!==O)throw new Error('Unclosed section "'+b[1]+'" at '+m)}else"name"===g||"{"===g||"&"===g?h=!0:"="===g&&f(O)}if(p(),b=a.pop())throw new Error('Unclosed section "'+b[1]+'" at '+w.pos);return function(e){for(var t,i=[],n=i,r=[],s=0,a=e.length;s<a;++s)switch((t=e[s])[0]){case"#":case"^":n.push(t),r.push(t),n=t[4]=[];break;case"/":r.pop()[5]=t[2],n=r.length>0?r[r.length-1][4]:i;break;default:n.push(t)}return i}(function(e){for(var t,i,n=[],r=0,s=e.length;r<s;++r)(t=e[r])&&("text"===t[0]&&i&&"text"===i[0]?(i[1]+=t[1],i[3]=t[3]):(n.push(t),i=t));return n}(o))}(e,t),r&&i.set(n,s)),s},yu.prototype.render=function(e,t,i,n){var r=this.getConfigTags(n),s=this.parse(e,r),a=t instanceof vu?t:new vu(t,void 0);return this.renderTokens(s,a,i,e,n)},yu.prototype.renderTokens=function(e,t,i,n,r){for(var s,a,o,l="",c=0,h=e.length;c<h;++c)o=void 0,"#"===(a=(s=e[c])[0])?o=this.renderSection(s,t,i,n,r):"^"===a?o=this.renderInverted(s,t,i,n,r):">"===a?o=this.renderPartial(s,t,i,r):"&"===a?o=this.unescapedValue(s,t):"name"===a?o=this.escapedValue(s,t,r):"text"===a&&(o=this.rawValue(s)),void 0!==o&&(l+=o);return l},yu.prototype.renderSection=function(e,t,i,n,r){var s=this,a="",o=t.lookup(e[1]);if(o){if(nu(o))for(var l=0,c=o.length;l<c;++l)a+=this.renderTokens(e[4],t.push(o[l]),i,n,r);else if("object"==typeof o||"string"==typeof o||"number"==typeof o)a+=this.renderTokens(e[4],t.push(o),i,n,r);else if(ru(o)){if("string"!=typeof n)throw new Error("Cannot use higher-order sections without the original template");null!=(o=o.call(t.view,n.slice(e[3],e[5]),function(e){return s.render(e,t,i,r)}))&&(a+=o)}else a+=this.renderTokens(e[4],t,i,n,r);return a}},yu.prototype.renderInverted=function(e,t,i,n,r){var s=t.lookup(e[1]);if(!s||nu(s)&&0===s.length)return this.renderTokens(e[4],t,i,n,r)},yu.prototype.indentPartial=function(e,t,i){for(var n=t.replace(/[^ \t]/g,""),r=e.split("\n"),s=0;s<r.length;s++)r[s].length&&(s>0||!i)&&(r[s]=n+r[s]);return r.join("\n")},yu.prototype.renderPartial=function(e,t,i,n){if(i){var r=this.getConfigTags(n),s=ru(i)?i(e[1]):i[e[1]];if(null!=s){var a=e[6],o=e[5],l=e[4],c=s;0==o&&l&&(c=this.indentPartial(s,l,a));var h=this.parse(c,r);return this.renderTokens(h,t,i,c,n)}}},yu.prototype.unescapedValue=function(e,t){var i=t.lookup(e[1]);if(null!=i)return i},yu.prototype.escapedValue=function(e,t,i){var n=this.getConfigEscape(i)||bu.escape,r=t.lookup(e[1]);if(null!=r)return"number"==typeof r&&n===bu.escape?String(r):n(r)},yu.prototype.rawValue=function(e){return e[1]},yu.prototype.getConfigTags=function(e){return nu(e)?e:e&&"object"==typeof e?e.tags:void 0},yu.prototype.getConfigEscape=function(e){return e&&"object"==typeof e&&!nu(e)?e.escape:void 0};var bu={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(e){wu.templateCache=e},get templateCache(){return wu.templateCache}},wu=new yu;function _u(){bu.escape=e=>e}bu.clearCache=function(){return wu.clearCache()},bu.parse=function(e,t){return wu.parse(e,t)},bu.render=function(e,t,i,n){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string" but "'+((nu(r=e)?"array":typeof r)+'" was given as the first argument for mustache#render(template, view, partials)'));var r;return wu.render(e,t,i,n)},bu.escape=function(e){return String(e).replace(/[&<>"'`=\/]/g,function(e){return uu[e]})},bu.Scanner=Ou,bu.Context=vu,bu.Writer=yu;const xu=e=>{const t=e.split(""),i=[],n=(e,i)=>{for(let n=i;n<t.length;n+=1)if(e.includes(t[n]))return n;return-1};let r=0;for(;r<t.length;)if("{"===t[r]&&r+1<t.length&&"{"===t[r+1])i.push({type:"literal",text:"{"}),r+=2;else if("}"===t[r]&&r+1<t.length&&"}"===t[r+1])i.push({type:"literal",text:"}"}),r+=2;else if("{"===t[r]){const e=n("}",r);if(e<0)throw new Error("Unclosed '{' in template.");i.push({type:"variable",name:t.slice(r+1,e).join("")}),r=e+1}else{if("}"===t[r])throw new Error("Single '}' in template.");{const e=n("{}",r),s=(e<0?t.slice(r):t.slice(r,e)).join("");i.push({type:"literal",text:s}),r=e<0?t.length:e}}return i},Su=(e,t=[])=>{const i=[];for(const n of e)if("name"===n[0]){const e=n[1].includes(".")?n[1].split(".")[0]:n[1];i.push({type:"variable",name:e})}else if(["#","&","^",">"].includes(n[0])){if(i.push({type:"variable",name:n[1]}),"#"===n[0]&&n.length>4&&Array.isArray(n[4])){const e=[...t,n[1]],r=Su(n[4],e);i.push(...r)}}else i.push({type:"literal",text:n[1]});return i},ku={"f-string":(e,t)=>xu(e).reduce((e,i)=>{if("variable"===i.type){if(i.name in t){return e+("string"==typeof t[i.name]?t[i.name]:JSON.stringify(t[i.name]))}throw new Error(`(f-string) Missing value for input ${i.name}`)}return e+i.text},""),mustache:(e,t)=>(_u(),bu.render(e,t))},Pu={"f-string":xu,mustache:e=>{_u();const t=bu.parse(e);return Su(t)}},Tu=(e,t,i)=>{try{return ku[t](e,i)}catch(n){throw vo(n,"INVALID_PROMPT_INPUT")}},$u=(e,t,i)=>{if(!(t in ku)){const e=Object.keys(ku);throw new Error(`Invalid template format. Got \`${t}\`;\n should be one of ${e}`)}try{const n=i.reduce((e,t)=>(e[t]="foo",e),{});Array.isArray(e)?e.forEach(e=>{if("text"===e.type)Tu(e.text,t,n);else{if("image_url"!==e.type)throw new Error(`Invalid message template received. ${JSON.stringify(e,null,2)}`);if("string"==typeof e.image_url)Tu(e.image_url,t,n);else{const i=e.image_url.url;Tu(i,t,n)}}}):Tu(e,t,n)}catch(n){throw new Error(`Invalid prompt schema: ${n.message}`)}};class Eu extends tu{static lc_name(){return"PromptTemplate"}constructor(e){if(super(e),Object.defineProperty(this,"template",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"templateFormat",{enumerable:!0,configurable:!0,writable:!0,value:"f-string"}),Object.defineProperty(this,"validateTemplate",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"additionalContentFields",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),"mustache"===e.templateFormat&&void 0===e.validateTemplate&&(this.validateTemplate=!1),Object.assign(this,e),this.validateTemplate){if("mustache"===this.templateFormat)throw new Error("Mustache templates cannot be validated.");let e=this.inputVariables;this.partialVariables&&(e=e.concat(Object.keys(this.partialVariables))),$u(this.template,this.templateFormat,e)}}_getPromptType(){return"prompt"}async format(e){const t=await this.mergePartialAndUserVariables(e);return Tu(this.template,this.templateFormat,t)}static fromExamples(e,t,i,n="\n\n",r=""){const s=[r,...e,t].join(n);return new Eu({inputVariables:i,template:s})}static fromTemplate(e,t){const{templateFormat:i="f-string",...n}=t??{},r=new Set;return((e,t)=>Pu[t](e))(e,i).forEach(e=>{"variable"===e.type&&r.add(e.name)}),new Eu({inputVariables:[...r],templateFormat:i,template:e,...n})}async partial(e){const t=this.inputVariables.filter(t=>!(t in e)),i={...this.partialVariables??{},...e},n={...this,inputVariables:t,partialVariables:i};return new Eu(n)}serialize(){if(void 0!==this.outputParser)throw new Error("Cannot serialize a prompt template with an output parser");return{_type:this._getPromptType(),input_variables:this.inputVariables,template:this.template,template_format:this.templateFormat}}static async deserialize(e){if(!e.template)throw new Error("Prompt template must have a template");return new Eu({inputVariables:e.input_variables,template:e.template,templateFormat:e.template_format})}}const Au=Object.freeze(Object.defineProperty({__proto__:null,PromptTemplate:Eu},Symbol.toStringTag,{value:"Module"}));class Cu extends tu{constructor(e){if(super(e),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"examples",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exampleSelector",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"examplePrompt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"suffix",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"exampleSeparator",{enumerable:!0,configurable:!0,writable:!0,value:"\n\n"}),Object.defineProperty(this,"prefix",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"templateFormat",{enumerable:!0,configurable:!0,writable:!0,value:"f-string"}),Object.defineProperty(this,"validateTemplate",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.assign(this,e),void 0!==this.examples&&void 0!==this.exampleSelector)throw new Error("Only one of 'examples' and 'example_selector' should be provided");if(void 0===this.examples&&void 0===this.exampleSelector)throw new Error("One of 'examples' and 'example_selector' should be provided");if(this.validateTemplate){let e=this.inputVariables;this.partialVariables&&(e=e.concat(Object.keys(this.partialVariables))),$u(this.prefix+this.suffix,this.templateFormat,e)}}_getPromptType(){return"few_shot"}static lc_name(){return"FewShotPromptTemplate"}async getExamples(e){if(void 0!==this.examples)return this.examples;if(void 0!==this.exampleSelector)return this.exampleSelector.selectExamples(e);throw new Error("One of 'examples' and 'example_selector' should be provided")}async partial(e){const t=this.inputVariables.filter(t=>!(t in e)),i={...this.partialVariables??{},...e},n={...this,inputVariables:t,partialVariables:i};return new Cu(n)}async format(e){const t=await this.mergePartialAndUserVariables(e),i=await this.getExamples(t),n=await Promise.all(i.map(e=>this.examplePrompt.format(e))),r=[this.prefix,...n,this.suffix].join(this.exampleSeparator);return Tu(r,this.templateFormat,t)}serialize(){if(this.exampleSelector||!this.examples)throw new Error("Serializing an example selector is not currently supported");if(void 0!==this.outputParser)throw new Error("Serializing an output parser is not currently supported");return{_type:this._getPromptType(),input_variables:this.inputVariables,example_prompt:this.examplePrompt.serialize(),example_separator:this.exampleSeparator,suffix:this.suffix,prefix:this.prefix,template_format:this.templateFormat,examples:this.examples}}static async deserialize(e){const{example_prompt:t}=e;if(!t)throw new Error("Missing example prompt");const i=await Eu.deserialize(t);let n;if(!Array.isArray(e.examples))throw new Error("Invalid examples format. Only list or string are supported.");return n=e.examples,new Cu({inputVariables:e.input_variables,examplePrompt:i,examples:n,exampleSeparator:e.example_separator,prefix:e.prefix,suffix:e.suffix,templateFormat:e.template_format})}}const Ru=Object.freeze(Object.defineProperty({__proto__:null,FewShotPromptTemplate:Cu},Symbol.toStringTag,{value:"Module"})),Qu=class{};i=new WeakMap,n=new WeakMap,ge(Qu,i,window.__API_BASE_URL__||""),ge(Qu,n,(e,n,r={})=>{n=`${me(Qu,i)}${n}`,t.loading.show(),"GET"===e&&(n+=`?${new URLSearchParams(r)}`);const s={method:e,headers:{"Content-Type":"application/json"}};return"GET"!==e&&(s.body=JSON.stringify(r)),fetch(n,s).then(e=>("/nine-ai/source/query"!==n&&t.loading.hide(),e.ok?e.json():e.text().then(t=>{throw new Error(`API 오류 (${e.status}): ${t}`)}))).catch(e=>{throw t.loading.hide(),e})}),pe(Qu,"get",(e,t={})=>{var i;return me(i=Qu,n).call(i,"GET",e,t)}),pe(Qu,"post",(e,t={})=>{var i;return me(i=Qu,n).call(i,"POST",e,t)});let Iu=Qu;const ju=Iu;class Mu{constructor(){}}var Nu,Lu,Zu,Du,zu,Uu;pe(Mu,"generatePrompt",async(e,t)=>{Array.isArray(e)||(e=[e]);let i="";for(let n of e)i+=await fetch(n).then(e=>e.text());return await new Eu({template:i,inputVariables:Object.keys(t)}).format(t)}),pe(Mu,"extractResponse",(e,t)=>{const i=e=>{const t=e.match(/```(?:json|jsx|xml|java)([\s\S]*?)```/);return t?t[1].trim():e};let n;switch(t){case"chatopenai":case"openai":case"gemini":n=i(e.content.trim());break;case"ollama":n=i(e)}try{return JSON.parse(n)}catch(r){return n}}),(Lu=Nu||(Nu={})).STRING="string",Lu.NUMBER="number",Lu.INTEGER="integer",Lu.BOOLEAN="boolean",Lu.ARRAY="array",Lu.OBJECT="object",(Du=Zu||(Zu={})).LANGUAGE_UNSPECIFIED="language_unspecified",Du.PYTHON="python",(Uu=zu||(zu={})).OUTCOME_UNSPECIFIED="outcome_unspecified",Uu.OUTCOME_OK="outcome_ok",Uu.OUTCOME_FAILED="outcome_failed",Uu.OUTCOME_DEADLINE_EXCEEDED="outcome_deadline_exceeded";
|
|
16
16
|
/**
|
|
17
17
|
* @license
|
|
18
18
|
* Copyright 2024 Google LLC
|
|
@@ -233,5 +233,5 @@ class Zd{constructor(e,t,i={}){this.apiKey=e,this._requestOptions=i,t.model.incl
|
|
|
233
233
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
234
234
|
* @copyright Chen, Yi-Cyuan 2014-2017
|
|
235
235
|
* @license MIT
|
|
236
|
-
*/var zd="object"==typeof window?window:{},Ud="0123456789abcdef".split(""),qd=[-2147483648,8388608,32768,128],Xd=[24,16,8,0],Bd=[];function Wd(e){e?(Bd[0]=Bd[16]=Bd[1]=Bd[2]=Bd[3]=Bd[4]=Bd[5]=Bd[6]=Bd[7]=Bd[8]=Bd[9]=Bd[10]=Bd[11]=Bd[12]=Bd[13]=Bd[14]=Bd[15]=0,this.blocks=Bd):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=1732584193,this.h1=4023233417,this.h2=2562383102,this.h3=271733878,this.h4=3285377520,this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}Wd.prototype.update=function(e){if(!this.finalized){var t="string"!=typeof e;t&&e.constructor===zd.ArrayBuffer&&(e=new Uint8Array(e));for(var i,n,r=0,s=e.length||0,a=this.blocks;r<s;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),t)for(n=this.start;r<s&&n<64;++r)a[n>>2]|=e[r]<<Xd[3&n++];else for(n=this.start;r<s&&n<64;++r)(i=e.charCodeAt(r))<128?a[n>>2]|=i<<Xd[3&n++]:i<2048?(a[n>>2]|=(192|i>>6)<<Xd[3&n++],a[n>>2]|=(128|63&i)<<Xd[3&n++]):i<55296||i>=57344?(a[n>>2]|=(224|i>>12)<<Xd[3&n++],a[n>>2]|=(128|i>>6&63)<<Xd[3&n++],a[n>>2]|=(128|63&i)<<Xd[3&n++]):(i=65536+((1023&i)<<10|1023&e.charCodeAt(++r)),a[n>>2]|=(240|i>>18)<<Xd[3&n++],a[n>>2]|=(128|i>>12&63)<<Xd[3&n++],a[n>>2]|=(128|i>>6&63)<<Xd[3&n++],a[n>>2]|=(128|63&i)<<Xd[3&n++]);this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.block=a[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this}},Wd.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>2]|=qd[3&t],this.block=e[16],t>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},Wd.prototype.hash=function(){var e,t,i=this.h0,n=this.h1,r=this.h2,s=this.h3,a=this.h4,o=this.blocks;for(e=16;e<80;++e)t=o[e-3]^o[e-8]^o[e-14]^o[e-16],o[e]=t<<1|t>>>31;for(e=0;e<20;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n&r|~n&s)+a+1518500249+o[e]|0)<<5|a>>>27)+(i&(n=n<<30|n>>>2)|~i&r)+s+1518500249+o[e+1]|0)<<5|s>>>27)+(a&(i=i<<30|i>>>2)|~a&n)+r+1518500249+o[e+2]|0)<<5|r>>>27)+(s&(a=a<<30|a>>>2)|~s&i)+n+1518500249+o[e+3]|0)<<5|n>>>27)+(r&(s=s<<30|s>>>2)|~r&a)+i+1518500249+o[e+4]|0,r=r<<30|r>>>2;for(;e<40;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n^r^s)+a+1859775393+o[e]|0)<<5|a>>>27)+(i^(n=n<<30|n>>>2)^r)+s+1859775393+o[e+1]|0)<<5|s>>>27)+(a^(i=i<<30|i>>>2)^n)+r+1859775393+o[e+2]|0)<<5|r>>>27)+(s^(a=a<<30|a>>>2)^i)+n+1859775393+o[e+3]|0)<<5|n>>>27)+(r^(s=s<<30|s>>>2)^a)+i+1859775393+o[e+4]|0,r=r<<30|r>>>2;for(;e<60;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n&r|n&s|r&s)+a-1894007588+o[e]|0)<<5|a>>>27)+(i&(n=n<<30|n>>>2)|i&r|n&r)+s-1894007588+o[e+1]|0)<<5|s>>>27)+(a&(i=i<<30|i>>>2)|a&n|i&n)+r-1894007588+o[e+2]|0)<<5|r>>>27)+(s&(a=a<<30|a>>>2)|s&i|a&i)+n-1894007588+o[e+3]|0)<<5|n>>>27)+(r&(s=s<<30|s>>>2)|r&a|s&a)+i-1894007588+o[e+4]|0,r=r<<30|r>>>2;for(;e<80;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n^r^s)+a-899497514+o[e]|0)<<5|a>>>27)+(i^(n=n<<30|n>>>2)^r)+s-899497514+o[e+1]|0)<<5|s>>>27)+(a^(i=i<<30|i>>>2)^n)+r-899497514+o[e+2]|0)<<5|r>>>27)+(s^(a=a<<30|a>>>2)^i)+n-899497514+o[e+3]|0)<<5|n>>>27)+(r^(s=s<<30|s>>>2)^a)+i-899497514+o[e+4]|0,r=r<<30|r>>>2;this.h0=this.h0+i|0,this.h1=this.h1+n|0,this.h2=this.h2+r|0,this.h3=this.h3+s|0,this.h4=this.h4+a|0},Wd.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,i=this.h2,n=this.h3,r=this.h4;return Ud[e>>28&15]+Ud[e>>24&15]+Ud[e>>20&15]+Ud[e>>16&15]+Ud[e>>12&15]+Ud[e>>8&15]+Ud[e>>4&15]+Ud[15&e]+Ud[t>>28&15]+Ud[t>>24&15]+Ud[t>>20&15]+Ud[t>>16&15]+Ud[t>>12&15]+Ud[t>>8&15]+Ud[t>>4&15]+Ud[15&t]+Ud[i>>28&15]+Ud[i>>24&15]+Ud[i>>20&15]+Ud[i>>16&15]+Ud[i>>12&15]+Ud[i>>8&15]+Ud[i>>4&15]+Ud[15&i]+Ud[n>>28&15]+Ud[n>>24&15]+Ud[n>>20&15]+Ud[n>>16&15]+Ud[n>>12&15]+Ud[n>>8&15]+Ud[n>>4&15]+Ud[15&n]+Ud[r>>28&15]+Ud[r>>24&15]+Ud[r>>20&15]+Ud[r>>16&15]+Ud[r>>12&15]+Ud[r>>8&15]+Ud[r>>4&15]+Ud[15&r]},Wd.prototype.toString=Wd.prototype.hex,Wd.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,i=this.h2,n=this.h3,r=this.h4;return[e>>24&255,e>>16&255,e>>8&255,255&e,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24&255,i>>16&255,i>>8&255,255&i,n>>24&255,n>>16&255,n>>8&255,255&n,r>>24&255,r>>16&255,r>>8&255,255&r]},Wd.prototype.array=Wd.prototype.digest,Wd.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(20),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),e};let Vd=!1;const Fd=(...e)=>{return t=e.join("_"),Vd||(Vd=!0),new Wd(!0).update(t).hex();var t};class Yd{constructor(){Object.defineProperty(this,"keyEncoder",{enumerable:!0,configurable:!0,writable:!0,value:Fd})}makeDefaultKeyEncoder(e){this.keyEncoder=e}}const Gd=new Map;class Hd extends Yd{constructor(e){super(),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cache=e??new Map}lookup(e,t){return Promise.resolve(this.cache.get(this.keyEncoder(e,t))??null)}async update(e,t,i){this.cache.set(this.keyEncoder(e,t),i)}static global(){return new Hd(Gd)}}var Kd,Jd={};const ep=Gt(function(){if(Kd)return Jd;Kd=1,Jd.byteLength=function(e){var t=s(e),i=t[0],n=t[1];return 3*(i+n)/4-n},Jd.toByteArray=function(e){var n,r,a=s(e),o=a[0],l=a[1],c=new i(function(e,t,i){return 3*(t+i)/4-i}(0,o,l)),h=0,u=l>0?o-4:o;for(r=0;r<u;r+=4)n=t[e.charCodeAt(r)]<<18|t[e.charCodeAt(r+1)]<<12|t[e.charCodeAt(r+2)]<<6|t[e.charCodeAt(r+3)],c[h++]=n>>16&255,c[h++]=n>>8&255,c[h++]=255&n;2===l&&(n=t[e.charCodeAt(r)]<<2|t[e.charCodeAt(r+1)]>>4,c[h++]=255&n);1===l&&(n=t[e.charCodeAt(r)]<<10|t[e.charCodeAt(r+1)]<<4|t[e.charCodeAt(r+2)]>>2,c[h++]=n>>8&255,c[h++]=255&n);return c},Jd.fromByteArray=function(t){for(var i,n=t.length,r=n%3,s=[],a=16383,l=0,c=n-r;l<c;l+=a)s.push(o(t,l,l+a>c?c:l+a));1===r?(i=t[n-1],s.push(e[i>>2]+e[i<<4&63]+"==")):2===r&&(i=(t[n-2]<<8)+t[n-1],s.push(e[i>>10]+e[i>>4&63]+e[i<<2&63]+"="));return s.join("")};for(var e=[],t=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=0;r<64;++r)e[r]=n[r],t[n.charCodeAt(r)]=r;function s(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function a(t){return e[t>>18&63]+e[t>>12&63]+e[t>>6&63]+e[63&t]}function o(e,t,i){for(var n,r=[],s=t;s<i;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(255&e[s+2]),r.push(a(n));return r.join("")}return t["-".charCodeAt(0)]=62,t["_".charCodeAt(0)]=63,Jd}());var tp=Object.defineProperty;function ip(e,t){return 1===e.length?[t.get(e.join(","))]:function(e,t){let i=Array.from({length:e.length},(e,t)=>({start:t,end:t+1}));for(;i.length>1;){let n=null;for(let r=0;r<i.length-1;r++){const s=e.slice(i[r].start,i[r+1].end),a=t.get(s.join(","));null!=a&&(null==n||a<n[0])&&(n=[a,r])}if(null==n)break;{const e=n[1];i[e]={start:i[e].start,end:i[e+1].end},i.splice(e+1,1)}}return i}(e,t).map(i=>t.get(e.slice(i.start,i.end).join(","))).filter(e=>null!=e)}var np=class{constructor(e,t){pe(this,"specialTokens"),pe(this,"inverseSpecialTokens"),pe(this,"patStr"),pe(this,"textEncoder",new TextEncoder),pe(this,"textDecoder",new TextDecoder("utf-8")),pe(this,"rankMap",new Map),pe(this,"textMap",new Map),this.patStr=e.pat_str;const i=e.bpe_ranks.split("\n").filter(Boolean).reduce((e,t)=>{const[i,n,...r]=t.split(" "),s=Number.parseInt(n,10);return r.forEach((t,i)=>e[t]=s+i),e},{});for(const[n,r]of Object.entries(i)){const e=ep.toByteArray(n);this.rankMap.set(e.join(","),r),this.textMap.set(r,e)}this.specialTokens={...e.special_tokens,...t},this.inverseSpecialTokens=Object.entries(this.specialTokens).reduce((e,[t,i])=>(e[i]=this.textEncoder.encode(t),e),{})}encode(e,t=[],i="all"){const n=new RegExp(this.patStr,"ug"),r=np.specialTokenRegex(Object.keys(this.specialTokens)),s=[],a=new Set("all"===t?Object.keys(this.specialTokens):t),o=new Set("all"===i?Object.keys(this.specialTokens).filter(e=>!a.has(e)):i);if(o.size>0){const t=np.specialTokenRegex([...o]),i=e.match(t);if(null!=i)throw new Error(`The text contains a special token that is not allowed: ${i[0]}`)}let l=0;for(;;){let t=null,i=l;for(;r.lastIndex=i,t=r.exec(e),null!=t&&!a.has(t[0]);)i=t.index+1;const o=(null==t?void 0:t.index)??e.length;for(const r of e.substring(l,o).matchAll(n)){const e=this.textEncoder.encode(r[0]),t=this.rankMap.get(e.join(","));null==t?s.push(...ip(e,this.rankMap)):s.push(t)}if(null==t)break;let c=this.specialTokens[t[0]];s.push(c),l=t.index+t[0].length}return s}decode(e){const t=[];let i=0;for(let s=0;s<e.length;++s){const n=e[s],r=this.textMap.get(n)??this.inverseSpecialTokens[n];null!=r&&(t.push(r),i+=r.length)}const n=new Uint8Array(i);let r=0;for(const s of t)n.set(s,r),r+=s.length;return this.textDecoder.decode(n)}},rp=np;((e,t,i)=>{t in e?tp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(rp,"specialTokenRegex"+"",e=>new RegExp(e.map(e=>e.replace(/[\\^$*+?.()|[\]{}]/g,"\\$&")).join("|"),"g"));const sp={},ap=new Yl({});async function op(e){return async function(e){return e in sp||(sp[e]=ap.fetch(`https://tiktoken.pages.dev/js/${e}.json`).then(e=>e.json()).then(e=>new rp(e)).catch(t=>{throw delete sp[e],t})),await sp[e]}(function(e){switch(e){case"gpt2":return"gpt2";case"code-cushman-001":case"code-cushman-002":case"code-davinci-001":case"code-davinci-002":case"cushman-codex":case"davinci-codex":case"davinci-002":case"text-davinci-002":case"text-davinci-003":return"p50k_base";case"code-davinci-edit-001":case"text-davinci-edit-001":return"p50k_edit";case"ada":case"babbage":case"babbage-002":case"code-search-ada-code-001":case"code-search-babbage-code-001":case"curie":case"davinci":case"text-ada-001":case"text-babbage-001":case"text-curie-001":case"text-davinci-001":case"text-search-ada-doc-001":case"text-search-babbage-doc-001":case"text-search-curie-doc-001":case"text-search-davinci-doc-001":case"text-similarity-ada-001":case"text-similarity-babbage-001":case"text-similarity-curie-001":case"text-similarity-davinci-001":return"r50k_base";case"gpt-3.5-turbo-instruct-0914":case"gpt-3.5-turbo-instruct":case"gpt-3.5-turbo-16k-0613":case"gpt-3.5-turbo-16k":case"gpt-3.5-turbo-0613":case"gpt-3.5-turbo-0301":case"gpt-3.5-turbo":case"gpt-4-32k-0613":case"gpt-4-32k-0314":case"gpt-4-32k":case"gpt-4-0613":case"gpt-4-0314":case"gpt-4":case"gpt-3.5-turbo-1106":case"gpt-35-turbo":case"gpt-4-1106-preview":case"gpt-4-vision-preview":case"gpt-3.5-turbo-0125":case"gpt-4-turbo":case"gpt-4-turbo-2024-04-09":case"gpt-4-turbo-preview":case"gpt-4-0125-preview":case"text-embedding-ada-002":case"text-embedding-3-small":case"text-embedding-3-large":return"cl100k_base";case"gpt-4o":case"gpt-4o-2024-05-13":case"gpt-4o-2024-08-06":case"gpt-4o-2024-11-20":case"gpt-4o-mini-2024-07-18":case"gpt-4o-mini":case"gpt-4o-search-preview":case"gpt-4o-search-preview-2025-03-11":case"gpt-4o-mini-search-preview":case"gpt-4o-mini-search-preview-2025-03-11":case"gpt-4o-audio-preview":case"gpt-4o-audio-preview-2024-12-17":case"gpt-4o-audio-preview-2024-10-01":case"gpt-4o-mini-audio-preview":case"gpt-4o-mini-audio-preview-2024-12-17":case"o1":case"o1-2024-12-17":case"o1-mini":case"o1-mini-2024-09-12":case"o1-preview":case"o1-preview-2024-09-12":case"o1-pro":case"o1-pro-2025-03-19":case"o3":case"o3-2025-04-16":case"o3-mini":case"o3-mini-2025-01-31":case"o4-mini":case"o4-mini-2025-04-16":case"chatgpt-4o-latest":case"gpt-4o-realtime":case"gpt-4o-realtime-preview-2024-10-01":case"gpt-4o-realtime-preview-2024-12-17":case"gpt-4o-mini-realtime-preview":case"gpt-4o-mini-realtime-preview-2024-12-17":case"gpt-4.1":case"gpt-4.1-2025-04-14":case"gpt-4.1-mini":case"gpt-4.1-mini-2025-04-14":case"gpt-4.1-nano":case"gpt-4.1-nano-2025-04-14":case"gpt-4.5-preview":case"gpt-4.5-preview-2025-02-27":case"gpt-5":case"gpt-5-2025-08-07":case"gpt-5-nano":case"gpt-5-nano-2025-08-07":case"gpt-5-mini":case"gpt-5-mini-2025-08-07":case"gpt-5-chat-latest":return"o200k_base";default:throw new Error("Unknown model")}}(e))}function lp(e){return!("object"!=typeof e||!e)&&!!("type"in e&&"function"===e.type&&"function"in e&&"object"==typeof e.function&&e.function&&"name"in e.function&&"parameters"in e.function)}class cp extends Lh{get lc_attributes(){return{callbacks:void 0,verbose:void 0}}constructor(e){super(e),Object.defineProperty(this,"verbose",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"callbacks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tags",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metadata",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.verbose=e.verbose??!1,this.callbacks=e.callbacks,this.tags=e.tags??[],this.metadata=e.metadata??{}}}class hp extends cp{get callKeys(){return["stop","timeout","signal","tags","metadata","callbacks"]}constructor({callbacks:e,callbackManager:t,...i}){const{cache:n,...r}=i;super({callbacks:e??t,...r}),Object.defineProperty(this,"caller",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_encoding",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cache="object"==typeof n?n:n?Hd.global():void 0,this.caller=new Yl(i??{})}async getNumTokens(e){let t;t="string"==typeof e?e:e.map(e=>"string"==typeof e?e:"text"===e.type&&"text"in e?e.text:"").join("");let i=Math.ceil(t.length/4);if(!this._encoding)try{this._encoding=await op("modelName"in this?(n=this.modelName,n.startsWith("gpt-3.5-turbo-16k")?"gpt-3.5-turbo-16k":n.startsWith("gpt-3.5-turbo-")?"gpt-3.5-turbo":n.startsWith("gpt-4-32k")?"gpt-4-32k":n.startsWith("gpt-4-")?"gpt-4":n.startsWith("gpt-4o")?"gpt-4o":n):"gpt2")}catch(r){}var n;if(this._encoding)try{i=this._encoding.encode(t).length}catch(r){}return i}static _convertInputToPromptValue(e){return"string"==typeof e?new Jh(e):Array.isArray(e)?new eu(e.map(el)):e}_identifyingParams(){return{}}_getSerializedCacheKeyParametersForCall({config:e,...t}){const i={...this._identifyingParams(),...t,_type:this._llmType(),_model:this._modelType()},n=Object.entries(i).filter(([e,t])=>void 0!==t),r=n.map(([e,t])=>`${e}:${JSON.stringify(t)}`).sort().join(",");return r}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}static async deserialize(e){throw new Error("Use .toJSON() instead")}}class up extends Lh{static lc_name(){return"RunnablePassthrough"}constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain_core","runnables"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"func",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),e&&(this.func=e.func)}async invoke(e,t){const i=Tl(t);return this.func&&await this.func(e,i),this._callWithConfig(e=>Promise.resolve(e),e,i)}async*transform(e,t){const i=Tl(t);let n,r=!0;for await(const s of this._transformStreamWithConfig(e,e=>e,i))if(yield s,r)if(void 0===n)n=s;else try{n=Ql(n,s)}catch{n=void 0,r=!1}this.func&&void 0!==n&&await this.func(n,i)}static assign(e){return new Fh(new qh({steps:e}))}}function dp(e){const t=[];for(const i of e){let e=i;if(Array.isArray(i.content))for(let t=0;t<i.content.length;t++){const n=i.content[t];(So(n)||ko(n))&&e===i&&(e=new i.constructor({...e,content:[...i.content.slice(0,t),Po(n),...i.content.slice(t+1)]}))}t.push(e)}return t}class pp extends hp{constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","chat_models",this._llmType()]}),Object.defineProperty(this,"disableStreaming",{enumerable:!0,configurable:!0,writable:!0,value:!1})}_separateRunnableConfigFromCallOptionsCompat(e){const[t,i]=super._separateRunnableConfigFromCallOptions(e);return i.signal=t.signal,[t,i]}async invoke(e,t){const i=pp._convertInputToPromptValue(e);return(await this.generatePrompt([i],t,null==t?void 0:t.callbacks)).generations[0][0].message}async*_streamResponseChunks(e,t,i){throw new Error("Not implemented.")}async*_streamIterator(e,t){var i;if(this._streamResponseChunks===pp.prototype._streamResponseChunks||this.disableStreaming)yield this.invoke(e,t);else{const r=pp._convertInputToPromptValue(e).toChatMessages(),[s,a]=this._separateRunnableConfigFromCallOptionsCompat(t),o={...s.metadata,...this.getLsParams(a)},l=await yl.configure(s.callbacks,this.callbacks,s.tags,this.tags,o,this.metadata,{verbose:this.verbose}),c={options:a,invocation_params:null==this?void 0:this.invocationParams(a),batch_size:1},h=await(null==l?void 0:l.handleChatModelStart(this.toJSON(),[dp(r)],s.runId,void 0,c,void 0,void 0,s.runName));let u,d;try{for await(const e of this._streamResponseChunks(r,a,null==h?void 0:h[0])){if(null==e.message.id){const t=null==(i=null==h?void 0:h.at(0))?void 0:i.runId;null!=t&&e.message._updateId(`run-${t}`)}e.message.response_metadata={...e.generationInfo,...e.message.response_metadata},yield e.message,u=u?u.concat(e):e,Uo(e.message)&&void 0!==e.message.usage_metadata&&(d={tokenUsage:{promptTokens:e.message.usage_metadata.input_tokens,completionTokens:e.message.usage_metadata.output_tokens,totalTokens:e.message.usage_metadata.total_tokens}})}}catch(n){throw await Promise.all((h??[]).map(e=>null==e?void 0:e.handleLLMError(n))),n}await Promise.all((h??[]).map(e=>null==e?void 0:e.handleLLMEnd({generations:[[u]],llmOutput:d})))}}getLsParams(e){const t=this.getName().startsWith("Chat")?this.getName().replace("Chat",""):this.getName();return{ls_model_type:"chat",ls_stop:e.stop,ls_provider:t}}async _generateUncached(e,t,i,n){var r,s;const a=e.map(e=>e.map(el));let o;if(void 0!==n&&n.length===a.length)o=n;else{const e={...i.metadata,...this.getLsParams(t)},n=await yl.configure(i.callbacks,this.callbacks,i.tags,this.tags,e,this.metadata,{verbose:this.verbose}),r={options:t,invocation_params:null==this?void 0:this.invocationParams(t),batch_size:1};o=await(null==n?void 0:n.handleChatModelStart(this.toJSON(),a.map(dp),i.runId,void 0,r,void 0,void 0,i.runName))}const l=[],c=[];if(!!(null==o?void 0:o[0].handlers.find(no))&&!this.disableStreaming&&1===a.length&&this._streamResponseChunks!==pp.prototype._streamResponseChunks)try{const e=await this._streamResponseChunks(a[0],t,null==o?void 0:o[0]);let i,n;for await(const t of e){if(null==t.message.id){const e=null==(r=null==o?void 0:o.at(0))?void 0:r.runId;null!=e&&t.message._updateId(`run-${e}`)}i=void 0===i?t:Ql(i,t),Uo(t.message)&&void 0!==t.message.usage_metadata&&(n={tokenUsage:{promptTokens:t.message.usage_metadata.input_tokens,completionTokens:t.message.usage_metadata.output_tokens,totalTokens:t.message.usage_metadata.total_tokens}})}if(void 0===i)throw new Error("Received empty response from chat model call.");l.push([i]),await(null==o?void 0:o[0].handleLLMEnd({generations:l,llmOutput:n}))}catch(u){throw await(null==o?void 0:o[0].handleLLMError(u)),u}else{const e=await Promise.allSettled(a.map((e,i)=>this._generate(e,{...t,promptIndex:i},null==o?void 0:o[i])));await Promise.all(e.map(async(e,t)=>{var i,n,r;if("fulfilled"===e.status){const r=e.value;for(const e of r.generations){if(null==e.message.id){const t=null==(i=null==o?void 0:o.at(0))?void 0:i.runId;null!=t&&e.message._updateId(`run-${t}`)}e.message.response_metadata={...e.generationInfo,...e.message.response_metadata}}return 1===r.generations.length&&(r.generations[0].message.response_metadata={...r.llmOutput,...r.generations[0].message.response_metadata}),l[t]=r.generations,c[t]=r.llmOutput,null==(n=null==o?void 0:o[t])?void 0:n.handleLLMEnd({generations:[r.generations],llmOutput:r.llmOutput})}return await(null==(r=null==o?void 0:o[t])?void 0:r.handleLLMError(e.reason)),Promise.reject(e.reason)}))}const h={generations:l,llmOutput:c.length?null==(s=this._combineLLMOutput)?void 0:s.call(this,...c):void 0};return Object.defineProperty(h,zl,{value:o?{runIds:null==o?void 0:o.map(e=>e.runId)}:void 0,configurable:!0}),h}async _generateCached({messages:e,cache:t,llmStringKey:i,parsedOptions:n,handledOptions:r}){const s=e.map(e=>e.map(el)),a={...r.metadata,...this.getLsParams(n)},o=await yl.configure(r.callbacks,this.callbacks,r.tags,this.tags,a,this.metadata,{verbose:this.verbose}),l={options:n,invocation_params:null==this?void 0:this.invocationParams(n),batch_size:1},c=await(null==o?void 0:o.handleChatModelStart(this.toJSON(),s.map(dp),r.runId,void 0,l,void 0,void 0,r.runName)),h=[],u=(await Promise.allSettled(s.map(async(e,n)=>{const r=pp._convertInputToPromptValue(e).toString(),s=await t.lookup(r,i);return null==s&&h.push(n),s}))).map((e,t)=>({result:e,runManager:null==c?void 0:c[t]})).filter(({result:e})=>"fulfilled"===e.status&&null!=e.value||"rejected"===e.status),d=[];await Promise.all(u.map(async({result:e,runManager:t},i)=>{if("fulfilled"===e.status){const n=e.value;return d[i]=n.map(e=>("message"in e&&Mo(e.message)&&zo(e.message)&&(e.message.usage_metadata={input_tokens:0,output_tokens:0,total_tokens:0}),e.generationInfo={...e.generationInfo,tokenUsage:{}},e)),n.length&&await(null==t?void 0:t.handleLLMNewToken(n[0].text)),null==t?void 0:t.handleLLMEnd({generations:[n]},void 0,void 0,void 0,{cached:!0})}return await(null==t?void 0:t.handleLLMError(e.reason,void 0,void 0,void 0,{cached:!0})),Promise.reject(e.reason)}));const p={generations:d,missingPromptIndices:h,startedRunManagers:c};return Object.defineProperty(p,zl,{value:c?{runIds:null==c?void 0:c.map(e=>e.runId)}:void 0,configurable:!0}),p}async generate(e,t,i){let n;n=Array.isArray(t)?{stop:t}:t;const r=e.map(e=>e.map(el)),[s,a]=this._separateRunnableConfigFromCallOptionsCompat(n);if(s.callbacks=s.callbacks??i,!this.cache)return this._generateUncached(r,a,s);const{cache:o}=this,l=this._getSerializedCacheKeyParametersForCall(a),{generations:c,missingPromptIndices:h,startedRunManagers:u}=await this._generateCached({messages:r,cache:o,llmStringKey:l,parsedOptions:a,handledOptions:s});let d={};if(h.length>0){const e=await this._generateUncached(h.map(e=>r[e]),a,s,void 0!==u?h.map(e=>null==u?void 0:u[e]):void 0);await Promise.all(e.generations.map(async(e,t)=>{const i=h[t];c[i]=e;const n=pp._convertInputToPromptValue(r[i]).toString();return o.update(n,l,e)})),d=e.llmOutput??{}}return{generations:c,llmOutput:d}}invocationParams(e){return{}}_modelType(){return"base_chat_model"}serialize(){return{...this.invocationParams(),_type:this._llmType(),_model:this._modelType()}}async generatePrompt(e,t,i){const n=e.map(e=>e.toChatMessages());return this.generate(n,t,i)}async call(e,t,i){return(await this.generate([e.map(el)],t,i)).generations[0][0].message}async callPrompt(e,t,i){const n=e.toChatMessages();return this.call(n,t,i)}async predictMessages(e,t,i){return this.call(e,t,i)}async predict(e,t,i){const n=new Vo(e),r=await this.call([n],t,i);if("string"!=typeof r.content)throw new Error("Cannot use predict when output is not a string.");return r.content}withStructuredOutput(e,t){if("function"!=typeof this.bindTools)throw new Error('Chat model must implement ".bindTools()" to use withStructuredOutput.');if(null==t?void 0:t.strict)throw new Error('"strict" mode is not supported for this model by default.');const i=e,n=null==t?void 0:t.name,r=_h(i)??"A function available to call.",s=null==t?void 0:t.method,a=null==t?void 0:t.includeRaw;if("jsonMode"===s)throw new Error('Base withStructuredOutput implementation only supports "functionCalling" as a method.');let o,l=n??"extract";yh(i)?o=[{type:"function",function:{name:l,description:r,parameters:Th(i)}}]:("name"in i&&(l=i.name),o=[{type:"function",function:{name:l,description:r,parameters:i}}]);const c=this.bindTools(o),h=Bh.from(e=>{if(!e.tool_calls||0===e.tool_calls.length)throw new Error("No tool calls found in the response.");const t=e.tool_calls.find(e=>e.name===l);if(!t)throw new Error(`No tool call found with name ${l}.`);return t.args});if(!a)return c.pipe(h).withConfig({runName:"StructuredOutput"});const u=up.assign({parsed:(e,t)=>h.invoke(e.raw,t)}),d=up.assign({parsed:()=>null}),p=u.withFallbacks({fallbacks:[d]});return Uh.from([{raw:c},p]).withConfig({runName:"StructuredOutputRunnable"})}}class fp extends Lh{parseResultWithPrompt(e,t,i){return this.parseResult(e,i)}_baseMessageToString(e){return"string"==typeof e.content?e.content:this._baseMessageContentToString(e.content)}_baseMessageContentToString(e){return JSON.stringify(e)}async invoke(e,t){return"string"==typeof e?this._callWithConfig(async(e,t)=>this.parseResult([{text:e}],null==t?void 0:t.callbacks),e,{...t,runType:"parser"}):this._callWithConfig(async(e,t)=>this.parseResult([{message:e,text:this._baseMessageToString(e)}],null==t?void 0:t.callbacks),e,{...t,runType:"parser"})}}class mp extends fp{parseResult(e,t){return this.parse(e[0].text,t)}async parseWithPrompt(e,t,i){return this.parse(e,i)}_type(){throw new Error("_type not implemented")}}class gp extends Error{constructor(e,t,i,n=!1){if(super(e),Object.defineProperty(this,"llmOutput",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"observation",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sendToLLM",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.llmOutput=t,this.observation=i,this.sendToLLM=n,n&&(void 0===i||void 0===t))throw new Error("Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true");vo(this,"OUTPUT_PARSING_FAILURE")}}class Op extends mp{async*_transform(e){for await(const t of e)"string"==typeof t?yield this.parseResult([{text:t}]):yield this.parseResult([{message:t,text:this._baseMessageToString(t)}])}async*transform(e,t){yield*this._transformStreamWithConfig(e,this._transform.bind(this),{...t,runType:"parser"})}}class vp extends Op{constructor(e){super(e),Object.defineProperty(this,"diff",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.diff=(null==e?void 0:e.diff)??this.diff}async*_transform(e){let t,i;for await(const n of e){if("string"!=typeof n&&"string"!=typeof n.content)throw new Error("Cannot handle non-string output.");let e;if(No(n)){if("string"!=typeof n.content)throw new Error("Cannot handle non-string message output.");e=new ql({message:n,text:n.content})}else if(Mo(n)){if("string"!=typeof n.content)throw new Error("Cannot handle non-string message output.");e=new ql({message:il(n),text:n.content})}else e=new Ul({text:n});i=void 0===i?e:i.concat(e);const r=await this.parsePartialResult([i]);null==r||gh(r,t)||(this.diff?yield this._diff(t,r):yield r,t=r)}}getFormatInstructions(){return""}}class yp extends mp{static lc_name(){return"StructuredOutputParser"}toJSON(){return this.toJSONNotImplemented()}constructor(e){super(e),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","output_parsers","structured"]})}static fromZodSchema(e){return new this(e)}static fromNamesAndDescriptions(e){return new this(Yt(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Vt().describe(t)]))))}getFormatInstructions(){return`You must format your output as a JSON value that adheres to a given "JSON Schema" instance.\n\n"JSON Schema" is a declarative language that allows you to annotate and validate JSON documents.\n\nFor example, the example "JSON Schema" instance {{"properties": {{"foo": {{"description": "a list of test words", "type": "array", "items": {{"type": "string"}}}}}}, "required": ["foo"]}}\nwould match an object with one required property, "foo". The "type" property specifies "foo" must be an "array", and the "description" property semantically describes it as "a list of test words". The items within "foo" must be strings.\nThus, the object {{"foo": ["bar", "baz"]}} is a well-formatted instance of this example "JSON Schema". The object {{"properties": {{"foo": ["bar", "baz"]}}}} is not well-formatted.\n\nYour output will be parsed and type-checked according to the provided schema instance, so make sure all fields in your output match the schema exactly and there are no trailing commas!\n\nHere is the JSON Schema instance your output must adhere to. Include the enclosing markdown codeblock:\n\`\`\`json\n${JSON.stringify(Th(this.schema))}\n\`\`\`\n`}async parse(e){var t,i;try{const n=e.trim(),r=((null==(t=n.match(/^```(?:json)?\s*([\s\S]*?)```/))?void 0:t[1])||(null==(i=n.match(/```json\s*([\s\S]*?)```/))?void 0:i[1])||n).replace(/"([^"\\]*(\\.[^"\\]*)*)"/g,(e,t)=>`"${t.replace(/\n/g,"\\n")}"`).replace(/\n/g,"");return await wh(this.schema,JSON.parse(r))}catch(n){throw new gp(`Failed to parse. Text: "${e}". Error: ${n}`,e)}}}class bp extends vp{constructor(){super(...arguments),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain_core","output_parsers"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0})}static lc_name(){return"JsonOutputParser"}_concatOutputChunks(e,t){return this.diff?super._concatOutputChunks(e,t):t}_diff(e,t){if(t)return e?Wi(e,t):[{op:"replace",path:"",value:t}]}async parsePartialResult(e){return wo(e[0].text)}async parse(e){return wo(e,JSON.parse)}getFormatInstructions(){return""}}function wp(e){if("object"==typeof e&&null!==e){const t={...e};"additionalProperties"in t&&delete t.additionalProperties,"$schema"in t&&delete t.$schema,"strict"in t&&delete t.strict;for(const e in t)e in t&&(Array.isArray(t[e])?t[e]=t[e].map(wp):"object"==typeof t[e]&&null!==t[e]&&(t[e]=wp(t[e])));return t}return e}function _p(e){const t=wp(yh(e)?Th(e):e),{$schema:i,...n}=t;return n}function xp(e){const t=wp(e),{$schema:i,...n}=t;return n}function Sp(e){return function(e){return!!e&&"object"==typeof e&&"name"in e&&"schema"in e&&(yh(e.schema)||null!=e.schema&&"object"==typeof e.schema&&"type"in e.schema&&"string"==typeof e.schema.type&&["null","boolean","object","array","number","string"].includes(e.schema.type))}(e)||function(e){return void 0!==e&&Lh.isRunnable(e)&&"lc_name"in e.constructor&&"function"==typeof e.constructor.lc_name&&"RunnableToolLike"===e.constructor.lc_name()}(e)||function(e){return void 0!==e&&Array.isArray(e.lc_namespace)}(e)}function kp(e,t){return{name:e.name,description:e.description,parameters:Th(e.schema)}}const Pp=[];for(let AM=0;AM<256;++AM)Pp.push((AM+256).toString(16).slice(1));let Tp;const $p=new Uint8Array(16);const Ep={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ap(e,t,i){var n;if(Ep.randomUUID&&!e)return Ep.randomUUID();const r=(e=e||{}).random??(null==(n=e.rng)?void 0:n.call(e))??function(){if(!Tp){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Tp=crypto.getRandomValues.bind(crypto)}return Tp($p)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(e,t=0){return(Pp[e[t+0]]+Pp[e[t+1]]+Pp[e[t+2]]+Pp[e[t+3]]+"-"+Pp[e[t+4]]+Pp[e[t+5]]+"-"+Pp[e[t+6]]+Pp[e[t+7]]+"-"+Pp[e[t+8]]+Pp[e[t+9]]+"-"+Pp[e[t+10]]+Pp[e[t+11]]+Pp[e[t+12]]+Pp[e[t+13]]+Pp[e[t+14]]+Pp[e[t+15]]).toLowerCase()}(r)}function Cp(e,t){var i;if(xo(e))return Eo(e,function(e){return{providerName:"Google Gemini",fromStandardTextBlock:e=>({text:e.text}),fromStandardImageBlock(t){if(!e)throw new Error("This model does not support images");if("url"===t.source_type){const e=$o({dataUrl:t.url});return e?{inlineData:{mimeType:e.mime_type,data:e.data}}:{fileData:{mimeType:t.mime_type??"",fileUri:t.url}}}if("base64"===t.source_type)return{inlineData:{mimeType:t.mime_type??"",data:t.data}};throw new Error(`Unsupported source type: ${t.source_type}`)},fromStandardAudioBlock(t){if(!e)throw new Error("This model does not support audio");if("url"===t.source_type){const e=$o({dataUrl:t.url});return e?{inlineData:{mimeType:e.mime_type,data:e.data}}:{fileData:{mimeType:t.mime_type??"",fileUri:t.url}}}if("base64"===t.source_type)return{inlineData:{mimeType:t.mime_type??"",data:t.data}};throw new Error(`Unsupported source type: ${t.source_type}`)},fromStandardFileBlock(t){if(!e)throw new Error("This model does not support files");if("text"===t.source_type)return{text:t.text};if("url"===t.source_type){const e=$o({dataUrl:t.url});return e?{inlineData:{mimeType:e.mime_type,data:e.data}}:{fileData:{mimeType:t.mime_type??"",fileUri:t.url}}}if("base64"===t.source_type)return{inlineData:{mimeType:t.mime_type??"",data:t.data}};throw new Error(`Unsupported source type: ${t.source_type}`)}}}(t));if("text"===e.type)return{text:e.text};if("executableCode"===e.type)return{executableCode:e.executableCode};if("codeExecutionResult"===e.type)return{codeExecutionResult:e.codeExecutionResult};if("image_url"===e.type){if(!t)throw new Error("This model does not support images");let i;if("string"==typeof e.image_url)i=e.image_url;else{if("object"!=typeof e.image_url||!("url"in e.image_url))throw new Error("Please provide image as base64 encoded data URL");i=e.image_url.url}const[n,r]=i.split(",");if(!n.startsWith("data:"))throw new Error("Please provide image as base64 encoded data URL");const[s,a]=n.replace(/^data:/,"").split(";");if("base64"!==a)throw new Error("Please provide image as base64 encoded data URL");return{inlineData:{data:r,mimeType:s}}}if("media"===e.type)return function(e){if("mimeType"in e&&"data"in e)return{inlineData:{mimeType:e.mimeType,data:e.data}};if("mimeType"in e&&"fileUri"in e)return{fileData:{mimeType:e.mimeType,fileUri:e.fileUri}};throw new Error("Invalid media content")}(e);if("tool_use"===e.type)return{functionCall:{name:e.name,args:e.input}};if((null==(i=e.type)?void 0:i.includes("/"))&&2===e.type.split("/").length&&"data"in e&&"string"==typeof e.data)return{inlineData:{mimeType:e.type,data:e.data}};if(!("functionCall"in e))throw"type"in e?new Error(`Unknown content type ${e.type}`):new Error(`Unknown content ${JSON.stringify(e)}`)}function Rp(e,t,i){var n;if("tool"===e._getType()){const n=e.name??function(e,t){var i;return null==(i=t.map(e=>zo(e)?e.tool_calls??[]:[]).flat().find(t=>t.id===e.tool_call_id))?void 0:i.name}(e,i);if(void 0===n)throw new Error(`Google requires a tool name for each tool call response, and we could not infer a called tool name for ToolMessage "${e.id}" from your passed messages. Please populate a "name" field on that ToolMessage explicitly.`);const r=Array.isArray(e.content)?e.content.map(e=>Cp(e,t)).filter(e=>void 0!==e):e.content;return"error"===e.status?[{functionResponse:{name:n,response:{error:{details:r}}}}]:[{functionResponse:{name:n,response:{result:r}}}]}let r=[];const s=[];return"string"==typeof e.content&&e.content&&s.push({text:e.content}),Array.isArray(e.content)&&s.push(...e.content.map(e=>Cp(e,t)).filter(e=>void 0!==e)),zo(e)&&(null==(n=e.tool_calls)?void 0:n.length)&&(r=e.tool_calls.map(e=>({functionCall:{name:e.name,args:e.args}}))),[...s,...r]}function Qp(e,t,i=!1){return e.reduce((n,r,s)=>{if(!Mo(r))throw new Error("Unsupported message input");const a=function(e){const t=e._getType();return Xo.isInstance(e)?e.role:"tool"===t?t:e.name??t}(r);if("system"===a&&0!==s)throw new Error("System message should be the first one");const o=function(e){switch(e){case"supervisor":case"ai":case"model":return"model";case"system":return"system";case"human":return"user";case"tool":case"function":return"function";default:throw new Error(`Unknown / unsupported author: ${e}`)}}(a),l=n.content[n.content.length];if(!n.mergeWithPreviousContent&&l&&l.role===o)throw new Error("Google Generative AI requires alternate messages between authors");const c=Rp(r,t,e.slice(0,s));if(n.mergeWithPreviousContent){const e=n.content[n.content.length-1];if(!e)throw new Error("There was a problem parsing your system message. Please try a prompt without one.");return e.parts.push(...c),{mergeWithPreviousContent:!1,content:n.content}}let h=o;("function"===h||"system"===h&&!i)&&(h="user");const u={role:h,parts:c};return{mergeWithPreviousContent:"system"===a&&!i,content:[...n.content,u]}},{content:[],mergeWithPreviousContent:!1}).content}function Ip(e,t){if(!e.candidates||0===e.candidates.length)return null;const i=e.functionCalls(),[n]=e.candidates,{content:r,...s}=n;let a;a=Array.isArray(null==r?void 0:r.parts)&&r.parts.every(e=>"text"in e)?r.parts.map(e=>e.text).join(""):Array.isArray(null==r?void 0:r.parts)?r.parts.map(e=>"text"in e?{type:"text",text:e.text}:"executableCode"in e?{type:"executableCode",executableCode:e.executableCode}:"codeExecutionResult"in e?{type:"codeExecutionResult",codeExecutionResult:e.codeExecutionResult}:e):[];let o="";if(a&&"string"==typeof a)o=a;else if(Array.isArray(a)){const e=a.find(e=>"text"in e);o=(null==e?void 0:e.text)??""}const l=[];return i&&l.push(...i.map(e=>({...e,args:JSON.stringify(e.args),index:t.index,type:"tool_call_chunk",id:"id"in e&&"string"==typeof e.id?e.id:Ap()}))),new ql({text:o,message:new qo({content:a||"",name:r?r.role:void 0,tool_call_chunks:l,additional_kwargs:{},usage_metadata:t.usageMetadata}),generationInfo:s})}class jp extends fp{static lc_name(){return"GoogleGenerativeAIToolsOutputParser"}constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","google_genai","output_parsers"]}),Object.defineProperty(this,"returnId",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"keyName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"returnSingle",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"zodSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.keyName=e.keyName,this.returnSingle=e.returnSingle??this.returnSingle,this.zodSchema=e.zodSchema}async _validateResult(e){if(void 0===this.zodSchema)return e;const t=await bh(this.zodSchema,e);if(t.success)return t.data;throw new gp(`Failed to parse. Text: "${JSON.stringify(e,null,2)}". Error: ${JSON.stringify(t.error.issues)}`,JSON.stringify(e,null,2))}async parseResult(e){const t=e.flatMap(e=>{const{message:t}=e;return"tool_calls"in t&&Array.isArray(t.tool_calls)?t.tool_calls:[]});if(void 0===t[0])throw new Error("No parseable tool calls provided to GoogleGenerativeAIToolsOutputParser.");const[i]=t;return await this._validateResult(i.args)}}function Mp(e,t){const i=function(e){let t=[];const i=[];e.forEach(e=>{if(Sp(e)){const[i]=function(e){return e.every(e=>"functionDeclarations"in e&&Array.isArray(e.functionDeclarations))?e:[{functionDeclarations:e.map(e=>{if(Sp(e)){const t=_p(e.schema);return"object"===t.type&&"properties"in t&&0===Object.keys(t.properties).length?{name:e.name,description:e.description}:{name:e.name,description:e.description,parameters:t}}return lp(e)?{name:e.function.name,description:e.function.description??"A function available to call.",parameters:xp(e.function.parameters)}:e})}]}([e]);i.functionDeclarations&&t.push(...i.functionDeclarations)}else if(lp(e)){const{functionDeclarations:i}=function(e){return{functionDeclarations:[{name:e.function.name,description:e.function.description,parameters:wp(e.function.parameters)}]}}(e);if(!i)throw new Error("Failed to convert OpenAI structured tool to GenerativeAI tool");t.push(...i)}else i.push(e)});const n=i.find(e=>"functionDeclarations"in e);if(n)return i.map(e=>{if((null==t?void 0:t.length)>0&&"functionDeclarations"in e){const i={functionDeclarations:[...e.functionDeclarations||[],...t]};return t=[],i}return e});return[...i,...t.length>0?[{functionDeclarations:t}]:[]]}(e),n=function(e,t){if(!e.length||!t)return;const{toolChoice:i,allowedFunctionNames:n}=t,r={any:id.ANY,auto:id.AUTO,none:id.NONE};if(i&&["any","auto","none"].includes(i))return{functionCallingConfig:{mode:r[i]??"MODE_UNSPECIFIED",allowedFunctionNames:n}};if("string"==typeof i||n)return{functionCallingConfig:{mode:id.ANY,allowedFunctionNames:[...n??[],...i&&"string"==typeof i?[i]:[]]}};return}(i,t);return{tools:i,toolConfig:n}}class Np extends pp{static lc_name(){return"ChatGoogleGenerativeAI"}get lc_secrets(){return{apiKey:"GOOGLE_API_KEY"}}get lc_aliases(){return{apiKey:"google_api_key"}}get _isMultimodalModel(){return this.model.includes("vision")||this.model.startsWith("gemini-1.5")||this.model.startsWith("gemini-2")||this.model.startsWith("gemma-3-")&&!this.model.startsWith("gemma-3-1b")}constructor(e){if(super(e),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","chat_models","google_genai"]}),Object.defineProperty(this,"model",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"temperature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxOutputTokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stopSequences",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"safetySettings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streaming",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"json",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streamUsage",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"convertSystemMessageToHumanContent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.model=e.model.replace(/^models\//,""),this.maxOutputTokens=e.maxOutputTokens??this.maxOutputTokens,this.maxOutputTokens&&this.maxOutputTokens<0)throw new Error("`maxOutputTokens` must be a positive integer");if(this.temperature=e.temperature??this.temperature,this.temperature&&(this.temperature<0||this.temperature>2))throw new Error("`temperature` must be in the range of [0.0,2.0]");if(this.topP=e.topP??this.topP,this.topP&&this.topP<0)throw new Error("`topP` must be a positive integer");if(this.topP&&this.topP>1)throw new Error("`topP` must be below 1.");if(this.topK=e.topK??this.topK,this.topK&&this.topK<0)throw new Error("`topK` must be a positive integer");if(this.stopSequences=e.stopSequences??this.stopSequences,this.apiKey=e.apiKey??to("GOOGLE_API_KEY"),!this.apiKey)throw new Error("Please set an API key for Google GenerativeAI in the environment variable GOOGLE_API_KEY or in the `apiKey` field of the ChatGoogleGenerativeAI constructor");if(this.safetySettings=e.safetySettings??this.safetySettings,this.safetySettings&&this.safetySettings.length>0){if(new Set(this.safetySettings.map(e=>e.category)).size!==this.safetySettings.length)throw new Error("The categories in `safetySettings` array must be unique")}this.streaming=e.streaming??this.streaming,this.json=e.json,this.client=new Dd(this.apiKey).getGenerativeModel({model:this.model,safetySettings:this.safetySettings,generationConfig:{stopSequences:this.stopSequences,maxOutputTokens:this.maxOutputTokens,temperature:this.temperature,topP:this.topP,topK:this.topK,...this.json?{responseMimeType:"application/json"}:{}}},{apiVersion:e.apiVersion,baseUrl:e.baseUrl}),this.streamUsage=e.streamUsage??this.streamUsage}useCachedContent(e,t,i){this.apiKey&&(this.client=new Dd(this.apiKey).getGenerativeModelFromCachedContent(e,t,i))}get useSystemInstruction(){return"boolean"==typeof this.convertSystemMessageToHumanContent?!this.convertSystemMessageToHumanContent:this.computeUseSystemInstruction}get computeUseSystemInstruction(){return"gemini-1.0-pro-001"!==this.model&&(!this.model.startsWith("gemini-pro-vision")&&(!this.model.startsWith("gemini-1.0-pro-vision")&&"gemini-pro"!==this.model))}getLsParams(e){return{ls_provider:"google_genai",ls_model_name:this.model,ls_model_type:"chat",ls_temperature:this.client.generationConfig.temperature,ls_max_tokens:this.client.generationConfig.maxOutputTokens,ls_stop:e.stop}}_combineLLMOutput(){return[]}_llmType(){return"googlegenerativeai"}bindTools(e,t){var i;return this.withConfig({tools:null==(i=Mp(e))?void 0:i.tools,...t})}invocationParams(e){var t;const i=(null==(t=null==e?void 0:e.tools)?void 0:t.length)?Mp(e.tools,{toolChoice:e.tool_choice,allowedFunctionNames:e.allowedFunctionNames}):void 0;return(null==e?void 0:e.responseSchema)?(this.client.generationConfig.responseSchema=e.responseSchema,this.client.generationConfig.responseMimeType="application/json"):(this.client.generationConfig.responseSchema=void 0,this.client.generationConfig.responseMimeType=this.json?"application/json":void 0),{...(null==i?void 0:i.tools)?{tools:i.tools}:{},...(null==i?void 0:i.toolConfig)?{toolConfig:i.toolConfig}:{}}}async _generate(e,t,i){var n,r,s;const a=Qp(e,this._isMultimodalModel,this.useSystemInstruction);let o=a;if("system"===a[0].role){const[e]=a;this.client.systemInstruction=e,o=a.slice(1)}const l=this.invocationParams(t);if(this.streaming){const r={},s=this._streamResponseChunks(e,t,i),a={};for await(const e of s){const t=(null==(n=e.generationInfo)?void 0:n.completion)??0;void 0===a[t]?a[t]=e:a[t]=a[t].concat(e)}const o=Object.entries(a).sort(([e],[t])=>parseInt(e,10)-parseInt(t,10)).map(([e,t])=>t);return{generations:o,llmOutput:{estimatedTokenUsage:r}}}const c=await this.completionWithRetry({...l,contents:o});let h;if("usageMetadata"in c.response){const e=c.response.usageMetadata;h={input_tokens:e.promptTokenCount??0,output_tokens:e.candidatesTokenCount??0,total_tokens:e.totalTokenCount??0}}const u=function(e,t){var i,n,r;if(!e.candidates||0===e.candidates.length||!e.candidates[0])return{generations:[],llmOutput:{filters:e.promptFeedback}};const s=e.functionCalls(),[a]=e.candidates,{content:o,...l}=a;let c;c=Array.isArray(null==o?void 0:o.parts)&&1===o.parts.length&&o.parts[0].text?o.parts[0].text:Array.isArray(null==o?void 0:o.parts)&&o.parts.length>0?o.parts.map(e=>"text"in e?{type:"text",text:e.text}:"executableCode"in e?{type:"executableCode",executableCode:e.executableCode}:"codeExecutionResult"in e?{type:"codeExecutionResult",codeExecutionResult:e.codeExecutionResult}:e):[];let h="";if("string"==typeof c)h=c;else if(Array.isArray(c)&&c.length>0){const e=c.find(e=>"text"in e);h=(null==e?void 0:e.text)??h}return{generations:[{text:h,message:new Do({content:c??"",tool_calls:null==s?void 0:s.map(e=>({...e,type:"tool_call",id:"id"in e&&"string"==typeof e.id?e.id:Ap()})),additional_kwargs:{...l},usage_metadata:null==t?void 0:t.usageMetadata}),generationInfo:l}],llmOutput:{tokenUsage:{promptTokens:null==(i=null==t?void 0:t.usageMetadata)?void 0:i.input_tokens,completionTokens:null==(n=null==t?void 0:t.usageMetadata)?void 0:n.output_tokens,totalTokens:null==(r=null==t?void 0:t.usageMetadata)?void 0:r.total_tokens}}}}(c.response,{usageMetadata:h});return(null==(r=u.generations)?void 0:r.length)>0&&await(null==i?void 0:i.handleLLMNewToken((null==(s=u.generations[0])?void 0:s.text)??"")),u}async*_streamResponseChunks(e,t,i){const n=Qp(e,this._isMultimodalModel,this.useSystemInstruction);let r=n;if("system"===n[0].role){const[e]=n;this.client.systemInstruction=e,r=n.slice(1)}const s={...this.invocationParams(t),contents:r},a=await this.caller.callWithOptions({signal:null==t?void 0:t.signal},async()=>{const{stream:e}=await this.client.generateContentStream(s);return e});let o,l=0,c=0,h=0,u=0;for await(const d of a){if("usageMetadata"in d&&void 0!==d.usageMetadata&&!1!==this.streamUsage&&!1!==t.streamUsage){o={input_tokens:d.usageMetadata.promptTokenCount??0,output_tokens:d.usageMetadata.candidatesTokenCount??0,total_tokens:d.usageMetadata.totalTokenCount??0};const e=d.usageMetadata.promptTokenCount??0;o.input_tokens=Math.max(0,e-l),l=e;const t=d.usageMetadata.candidatesTokenCount??0;o.output_tokens=Math.max(0,t-c),c=t;const i=d.usageMetadata.totalTokenCount??0;o.total_tokens=Math.max(0,i-h),h=i}const e=Ip(d,{usageMetadata:o,index:u});u+=1,e&&(yield e,await(null==i?void 0:i.handleLLMNewToken(e.text??"")))}}async completionWithRetry(e,t){return this.caller.callWithOptions({signal:null==t?void 0:t.signal},async()=>{var t;try{return await this.client.generateContent(e)}catch(i){throw(null==(t=i.message)?void 0:t.includes("400 Bad Request"))&&(i.status=400),i}})}withStructuredOutput(e,t){const i=e,n=null==t?void 0:t.name,r=null==t?void 0:t.method,s=null==t?void 0:t.includeRaw;if("jsonMode"===r)throw new Error('ChatGoogleGenerativeAI only supports "jsonSchema" or "functionCalling" as a method.');let a,o;if("functionCalling"===r){let e,t=n??"extract";if(yh(i)){const n=_p(i);e=[{functionDeclarations:[{name:t,description:n.description??"A function available to call.",parameters:n}]}],o=new jp({returnSingle:!0,keyName:t,zodSchema:i})}else{let n;"string"==typeof i.name&&"object"==typeof i.parameters&&null!=i.parameters?(n=i,n.parameters=wp(i.parameters),t=i.name):n={name:t,description:i.description??"",parameters:wp(i)},e=[{functionDeclarations:[n]}],o=new jp({returnSingle:!0,keyName:t})}a=this.bindTools(e).withConfig({allowedFunctionNames:[t]})}else{const e=_p(i);a=this.withConfig({responseSchema:e}),o=new bp}if(!s)return a.pipe(o).withConfig({runName:"ChatGoogleGenerativeAIStructuredOutput"});const l=up.assign({parsed:(e,t)=>o.invoke(e.raw,t)}),c=up.assign({parsed:()=>null}),h=l.withFallbacks({fallbacks:[c]});return Uh.from([{raw:a},h]).withConfig({runName:"StructuredOutputRunnable"})}}var Lp="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},Zp="URLSearchParams"in Lp,Dp="Symbol"in Lp&&"iterator"in Symbol,zp="FileReader"in Lp&&"Blob"in Lp&&function(){try{return new Blob,!0}catch(e){return!1}}(),Up="FormData"in Lp,qp="ArrayBuffer"in Lp;if(qp)var Xp=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],Bp=ArrayBuffer.isView||function(e){return e&&Xp.indexOf(Object.prototype.toString.call(e))>-1};function Wp(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function Vp(e){return"string"!=typeof e&&(e=String(e)),e}function Fp(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return Dp&&(t[Symbol.iterator]=function(){return t}),t}function Yp(e){this.map={},e instanceof Yp?e.forEach(function(e,t){this.append(t,e)},this):Array.isArray(e)?e.forEach(function(e){if(2!=e.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+e.length);this.append(e[0],e[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function Gp(e){if(!e._noBody)return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function Hp(e){return new Promise(function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}})}function Kp(e){var t=new FileReader,i=Hp(t);return t.readAsArrayBuffer(e),i}function Jp(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function ef(){return this.bodyUsed=!1,this._initBody=function(e){this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:zp&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:Up&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:Zp&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():qp&&zp&&function(e){return e&&DataView.prototype.isPrototypeOf(e)}(e)?(this._bodyArrayBuffer=Jp(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):qp&&(ArrayBuffer.prototype.isPrototypeOf(e)||Bp(e))?this._bodyArrayBuffer=Jp(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):Zp&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},zp&&(this.blob=function(){var e=Gp(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=Gp(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(zp)return this.blob().then(Kp);throw new Error("could not read as ArrayBuffer")},this.text=function(){var e,t,i,n,r,s=Gp(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,i=Hp(t),n=/charset=([A-Za-z0-9_-]+)/.exec(e.type),r=n?n[1]:"utf-8",t.readAsText(e,r),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),n=0;n<t.length;n++)i[n]=String.fromCharCode(t[n]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},Up&&(this.formData=function(){return this.text().then(rf)}),this.json=function(){return this.text().then(JSON.parse)},this}Yp.prototype.append=function(e,t){e=Wp(e),t=Vp(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},Yp.prototype.delete=function(e){delete this.map[Wp(e)]},Yp.prototype.get=function(e){return e=Wp(e),this.has(e)?this.map[e]:null},Yp.prototype.has=function(e){return this.map.hasOwnProperty(Wp(e))},Yp.prototype.set=function(e,t){this.map[Wp(e)]=Vp(t)},Yp.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},Yp.prototype.keys=function(){var e=[];return this.forEach(function(t,i){e.push(i)}),Fp(e)},Yp.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),Fp(e)},Yp.prototype.entries=function(){var e=[];return this.forEach(function(t,i){e.push([i,t])}),Fp(e)},Dp&&(Yp.prototype[Symbol.iterator]=Yp.prototype.entries);var tf=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function nf(e,t){if(!(this instanceof nf))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var i,n,r=(t=t||{}).body;if(e instanceof nf){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new Yp(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new Yp(t.headers)),this.method=(i=t.method||this.method||"GET",n=i.toUpperCase(),tf.indexOf(n)>-1?n:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in Lp)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var s=/([?&])_=[^&]*/;if(s.test(this.url))this.url=this.url.replace(s,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function rf(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),r=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(r))}}),t}function sf(e,t){if(!(this instanceof sf))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new Yp(t.headers),this.url=t.url||"",this._initBody(e)}nf.prototype.clone=function(){return new nf(this,{body:this._bodyInit})},ef.call(nf.prototype),ef.call(sf.prototype),sf.prototype.clone=function(){return new sf(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Yp(this.headers),url:this.url})},sf.error=function(){var e=new sf(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var af=[301,302,303,307,308];sf.redirect=function(e,t){if(-1===af.indexOf(t))throw new RangeError("Invalid status code");return new sf(null,{status:t,headers:{location:e}})};var of=Lp.DOMException;try{new of}catch($M){(of=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack}).prototype=Object.create(Error.prototype),of.prototype.constructor=of}function lf(e,t){return new Promise(function(i,n){var r=new nf(e,t);if(r.signal&&r.signal.aborted)return n(new of("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}if(s.onload=function(){var e,t,n={statusText:s.statusText,headers:(e=s.getAllResponseHeaders()||"",t=new Yp,e.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e}).forEach(function(e){var i=e.split(":"),n=i.shift().trim();if(n){var r=i.join(":").trim();try{t.append(n,r)}catch(s){}}}),t)};0===r.url.indexOf("file://")&&(s.status<200||s.status>599)?n.status=200:n.status=s.status,n.url="responseURL"in s?s.responseURL:n.headers.get("X-Request-URL");var a="response"in s?s.response:s.responseText;setTimeout(function(){i(new sf(a,n))},0)},s.onerror=function(){setTimeout(function(){n(new TypeError("Network request failed"))},0)},s.ontimeout=function(){setTimeout(function(){n(new TypeError("Network request timed out"))},0)},s.onabort=function(){setTimeout(function(){n(new of("Aborted","AbortError"))},0)},s.open(r.method,function(e){try{return""===e&&Lp.location.href?Lp.location.href:e}catch(t){return e}}(r.url),!0),"include"===r.credentials?s.withCredentials=!0:"omit"===r.credentials&&(s.withCredentials=!1),"responseType"in s&&(zp?s.responseType="blob":qp&&(s.responseType="arraybuffer")),t&&"object"==typeof t.headers&&!(t.headers instanceof Yp||Lp.Headers&&t.headers instanceof Lp.Headers)){var o=[];Object.getOwnPropertyNames(t.headers).forEach(function(e){o.push(Wp(e)),s.setRequestHeader(e,Vp(t.headers[e]))}),r.headers.forEach(function(e,t){-1===o.indexOf(t)&&s.setRequestHeader(t,e)})}else r.headers.forEach(function(e,t){s.setRequestHeader(t,e)});r.signal&&(r.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&r.signal.removeEventListener("abort",a)}),s.send(void 0===r._bodyInit?null:r._bodyInit)})}lf.polyfill=!0,Lp.fetch||(Lp.fetch=lf,Lp.Headers=Yp,Lp.Request=nf,Lp.Response=sf);const cf="11434",hf=`http://127.0.0.1:${cf}`;var uf=Object.defineProperty,df=(e,t,i)=>(((e,t,i)=>{t in e?uf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);class pf extends Error{constructor(e,t){super(e),this.error=e,this.status_code=t,this.name="ResponseError",Error.captureStackTrace&&Error.captureStackTrace(this,pf)}}class ff{constructor(e,t,i){df(this,"abortController"),df(this,"itr"),df(this,"doneCallback"),this.abortController=e,this.itr=t,this.doneCallback=i}abort(){this.abortController.abort()}async*[Symbol.asyncIterator](){for await(const e of this.itr){if("error"in e)throw new Error(e.error);if(yield e,e.done||"success"===e.status)return void this.doneCallback()}throw new Error("Did not receive done or success response in stream.")}}const mf=async e=>{var t;if(e.ok)return;let i=`Error ${e.status}: ${e.statusText}`,n=null;if(null==(t=e.headers.get("content-type"))?void 0:t.includes("application/json"))try{n=await e.json(),i=n.error||i}catch(r){}else try{i=await e.text()||i}catch(r){}throw new pf(i,e.status)};function gf(){var e;if("undefined"!=typeof window&&window.navigator){const t=navigator;return"userAgentData"in t&&(null==(e=t.userAgentData)?void 0:e.platform)?`${t.userAgentData.platform.toLowerCase()} Browser/${navigator.userAgent};`:navigator.platform?`${navigator.platform.toLowerCase()} Browser/${navigator.userAgent};`:`unknown Browser/${navigator.userAgent};`}return"undefined"!=typeof process?`${process.arch} ${process.platform} Node.js/${process.version}`:""}const Of=async(e,t,i={})=>{const n={"Content-Type":"application/json",Accept:"application/json","User-Agent":`ollama-js/0.5.18 (${gf()})`};i.headers=function(e){if(e instanceof Headers){const t={};return e.forEach((e,i)=>{t[i]=e}),t}return Array.isArray(e)?Object.fromEntries(e):e||{}}(i.headers);const r=Object.fromEntries(Object.entries(i.headers).filter(([e])=>!Object.keys(n).some(t=>t.toLowerCase()===e.toLowerCase())));return i.headers={...n,...r},e(t,i)},vf=async(e,t,i)=>{const n=await Of(e,t,{headers:null==i?void 0:i.headers});return await mf(n),n},yf=async(e,t,i,n)=>{const r=null===(s=i)||"object"!=typeof s||Array.isArray(s)?i:JSON.stringify(i);var s;const a=await Of(e,t,{method:"POST",body:r,signal:null==n?void 0:n.signal,headers:null==n?void 0:n.headers});return await mf(a),a};var bf=Object.defineProperty,wf=(e,t,i)=>(((e,t,i)=>{t in e?bf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);let _f=class{constructor(e){wf(this,"config"),wf(this,"fetch"),wf(this,"ongoingStreamedRequests",[]),this.config={host:"",headers:null==e?void 0:e.headers},(null==e?void 0:e.proxy)||(this.config.host=(e=>{if(!e)return hf;let t=e.includes("://");e.startsWith(":")&&(e=`http://127.0.0.1${e}`,t=!0),t||(e=`http://${e}`);const i=new URL(e);let n=i.port;n||(n=t?"https:"===i.protocol?"443":"80":cf);let r="";i.username&&(r=i.username,i.password&&(r+=`:${i.password}`),r+="@");let s=`${i.protocol}//${r}${i.hostname}:${n}${i.pathname}`;return s.endsWith("/")&&(s=s.slice(0,-1)),s})((null==e?void 0:e.host)??hf)),this.fetch=(null==e?void 0:e.fetch)??fetch}abort(){for(const e of this.ongoingStreamedRequests)e.abort();this.ongoingStreamedRequests.length=0}async processStreamableRequest(e,t){t.stream=t.stream??!1;const i=`${this.config.host}/api/${e}`;if(t.stream){const e=new AbortController,n=await yf(this.fetch,i,t,{signal:e.signal,headers:this.config.headers});if(!n.body)throw new Error("Missing body");const r=async function*(e){const t=new TextDecoder("utf-8");let i="";const n=e.getReader();for(;;){const{done:e,value:s}=await n.read();if(e)break;i+=t.decode(s);const a=i.split("\n");i=a.pop()??"";for(const t of a)try{yield JSON.parse(t)}catch(r){}}for(const s of i.split("\n").filter(e=>""!==e))try{yield JSON.parse(s)}catch(r){}}(n.body),s=new ff(e,r,()=>{const e=this.ongoingStreamedRequests.indexOf(s);e>-1&&this.ongoingStreamedRequests.splice(e,1)});return this.ongoingStreamedRequests.push(s),s}const n=await yf(this.fetch,i,t,{headers:this.config.headers});return await n.json()}async encodeImage(e){if("string"!=typeof e){const t=new Uint8Array(e);let i="";const n=t.byteLength;for(let e=0;e<n;e++)i+=String.fromCharCode(t[e]);return btoa(i)}return e}async generate(e){return e.images&&(e.images=await Promise.all(e.images.map(this.encodeImage.bind(this)))),this.processStreamableRequest("generate",e)}async chat(e){if(e.messages)for(const t of e.messages)t.images&&(t.images=await Promise.all(t.images.map(this.encodeImage.bind(this))));return this.processStreamableRequest("chat",e)}async create(e){return this.processStreamableRequest("create",{...e})}async pull(e){return this.processStreamableRequest("pull",{name:e.model,stream:e.stream,insecure:e.insecure})}async push(e){return this.processStreamableRequest("push",{name:e.model,stream:e.stream,insecure:e.insecure})}async delete(e){return await(async(e,t,i,n)=>{const r=await Of(e,t,{method:"DELETE",body:JSON.stringify(i),headers:null==n?void 0:n.headers});return await mf(r),r})(this.fetch,`${this.config.host}/api/delete`,{name:e.model},{headers:this.config.headers}),{status:"success"}}async copy(e){return await yf(this.fetch,`${this.config.host}/api/copy`,{...e},{headers:this.config.headers}),{status:"success"}}async list(){const e=await vf(this.fetch,`${this.config.host}/api/tags`,{headers:this.config.headers});return await e.json()}async show(e){const t=await yf(this.fetch,`${this.config.host}/api/show`,{...e},{headers:this.config.headers});return await t.json()}async embed(e){const t=await yf(this.fetch,`${this.config.host}/api/embed`,{...e},{headers:this.config.headers});return await t.json()}async embeddings(e){const t=await yf(this.fetch,`${this.config.host}/api/embeddings`,{...e},{headers:this.config.headers});return await t.json()}async ps(){const e=await vf(this.fetch,`${this.config.host}/api/ps`,{headers:this.config.headers});return await e.json()}};new _f;class xf extends hp{constructor({concurrency:e,...t}){super(e?{maxConcurrency:e,...t}:t),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","llms",this._llmType()]})}async invoke(e,t){const i=xf._convertInputToPromptValue(e);return(await this.generatePrompt([i],t,null==t?void 0:t.callbacks)).generations[0][0].text}async*_streamResponseChunks(e,t,i){throw new Error("Not implemented.")}_separateRunnableConfigFromCallOptionsCompat(e){const[t,i]=super._separateRunnableConfigFromCallOptions(e);return i.signal=t.signal,[t,i]}async*_streamIterator(e,t){if(this._streamResponseChunks===xf.prototype._streamResponseChunks)yield this.invoke(e,t);else{const i=xf._convertInputToPromptValue(e),[n,r]=this._separateRunnableConfigFromCallOptionsCompat(t),s=await yl.configure(n.callbacks,this.callbacks,n.tags,this.tags,n.metadata,this.metadata,{verbose:this.verbose}),a={options:r,invocation_params:null==this?void 0:this.invocationParams(r),batch_size:1},o=await(null==s?void 0:s.handleLLMStart(this.toJSON(),[i.toString()],n.runId,void 0,a,void 0,void 0,n.runName));let l=new Ul({text:""});try{for await(const e of this._streamResponseChunks(i.toString(),r,null==o?void 0:o[0]))l=l?l.concat(e):e,"string"==typeof e.text&&(yield e.text)}catch($M){throw await Promise.all((o??[]).map(t=>null==t?void 0:t.handleLLMError($M))),$M}await Promise.all((o??[]).map(e=>null==e?void 0:e.handleLLMEnd({generations:[[l]]})))}}async generatePrompt(e,t,i){const n=e.map(e=>e.toString());return this.generate(n,t,i)}invocationParams(e){return{}}_flattenLLMResult(e){const t=[];for(let i=0;i<e.generations.length;i+=1){const n=e.generations[i];if(0===i)t.push({generations:[n],llmOutput:e.llmOutput});else{const i=e.llmOutput?{...e.llmOutput,tokenUsage:{}}:void 0;t.push({generations:[n],llmOutput:i})}}return t}async _generateUncached(e,t,i,n){let r;if(void 0!==n&&n.length===e.length)r=n;else{const n=await yl.configure(i.callbacks,this.callbacks,i.tags,this.tags,i.metadata,this.metadata,{verbose:this.verbose}),s={options:t,invocation_params:null==this?void 0:this.invocationParams(t),batch_size:e.length};r=await(null==n?void 0:n.handleLLMStart(this.toJSON(),e,i.runId,void 0,s,void 0,void 0,null==i?void 0:i.runName))}let s;if(!!(null==r?void 0:r[0].handlers.find(no))&&1===e.length&&this._streamResponseChunks!==xf.prototype._streamResponseChunks)try{const i=await this._streamResponseChunks(e[0],t,null==r?void 0:r[0]);let n;for await(const e of i)n=void 0===n?e:Ql(n,e);if(void 0===n)throw new Error("Received empty response from chat model call.");s={generations:[[n]],llmOutput:{}},await(null==r?void 0:r[0].handleLLMEnd(s))}catch(o){throw await(null==r?void 0:r[0].handleLLMError(o)),o}else{try{s=await this._generate(e,t,null==r?void 0:r[0])}catch($M){throw await Promise.all((r??[]).map(t=>null==t?void 0:t.handleLLMError($M))),$M}const i=this._flattenLLMResult(s);await Promise.all((r??[]).map((e,t)=>null==e?void 0:e.handleLLMEnd(i[t])))}const a=(null==r?void 0:r.map(e=>e.runId))||void 0;return Object.defineProperty(s,zl,{value:a?{runIds:a}:void 0,configurable:!0}),s}async _generateCached({prompts:e,cache:t,llmStringKey:i,parsedOptions:n,handledOptions:r,runId:s}){const a=await yl.configure(r.callbacks,this.callbacks,r.tags,this.tags,r.metadata,this.metadata,{verbose:this.verbose}),o={options:n,invocation_params:null==this?void 0:this.invocationParams(n),batch_size:e.length},l=await(null==a?void 0:a.handleLLMStart(this.toJSON(),e,s,void 0,o,void 0,void 0,null==r?void 0:r.runName)),c=[],h=(await Promise.allSettled(e.map(async(e,n)=>{const r=await t.lookup(e,i);return null==r&&c.push(n),r}))).map((e,t)=>({result:e,runManager:null==l?void 0:l[t]})).filter(({result:e})=>"fulfilled"===e.status&&null!=e.value||"rejected"===e.status),u=[];await Promise.all(h.map(async({result:e,runManager:t},i)=>{if("fulfilled"===e.status){const n=e.value;return u[i]=n.map(e=>(e.generationInfo={...e.generationInfo,tokenUsage:{}},e)),n.length&&await(null==t?void 0:t.handleLLMNewToken(n[0].text)),null==t?void 0:t.handleLLMEnd({generations:[n]},void 0,void 0,void 0,{cached:!0})}return await(null==t?void 0:t.handleLLMError(e.reason,void 0,void 0,void 0,{cached:!0})),Promise.reject(e.reason)}));const d={generations:u,missingPromptIndices:c,startedRunManagers:l};return Object.defineProperty(d,zl,{value:l?{runIds:null==l?void 0:l.map(e=>e.runId)}:void 0,configurable:!0}),d}async generate(e,t,i){if(!Array.isArray(e))throw new Error("Argument 'prompts' is expected to be a string[]");let n;n=Array.isArray(t)?{stop:t}:t;const[r,s]=this._separateRunnableConfigFromCallOptionsCompat(n);if(r.callbacks=r.callbacks??i,!this.cache)return this._generateUncached(e,s,r);const{cache:a}=this,o=this._getSerializedCacheKeyParametersForCall(s),{generations:l,missingPromptIndices:c,startedRunManagers:h}=await this._generateCached({prompts:e,cache:a,llmStringKey:o,parsedOptions:s,handledOptions:r,runId:r.runId});let u={};if(c.length>0){const t=await this._generateUncached(c.map(t=>e[t]),s,r,void 0!==h?c.map(e=>null==h?void 0:h[e]):void 0);await Promise.all(t.generations.map(async(t,i)=>{const n=c[i];return l[n]=t,a.update(e[n],o,t)})),u=t.llmOutput??{}}return{generations:l,llmOutput:u}}async call(e,t,i){const{generations:n}=await this.generate([e],t,i);return n[0][0].text}async predict(e,t,i){return this.call(e,t,i)}async predictMessages(e,t,i){const n=tl(e),r=await this.call(n,t,i);return new Do(r)}_identifyingParams(){return{}}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}_modelType(){return"base_llm"}}class Sf extends xf{async _generate(e,t,i){return{generations:await Promise.all(e.map((e,n)=>this._call(e,{...t,promptIndex:n},i).then(e=>[{text:e}])))}}}class kf extends Sf{static lc_name(){return"Ollama"}constructor(e){var t;super(e??{}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"model",{enumerable:!0,configurable:!0,writable:!0,value:"llama3"}),Object.defineProperty(this,"baseUrl",{enumerable:!0,configurable:!0,writable:!0,value:"http://localhost:11434"}),Object.defineProperty(this,"keepAlive",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"embeddingOnly",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"f16KV",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"frequencyPenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logitsAll",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lowVram",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mainGpu",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mirostat",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mirostatEta",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mirostatTau",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numBatch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numCtx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numGpu",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numKeep",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numPredict",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numThread",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"penalizeNewline",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"presencePenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"repeatLastN",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"repeatPenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"temperature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tfsZ",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"typicalP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useMLock",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useMMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"vocabOnly",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"format",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.model=(null==e?void 0:e.model)??this.model,this.baseUrl=(null==(t=null==e?void 0:e.baseUrl)?void 0:t.endsWith("/"))?null==e?void 0:e.baseUrl.slice(0,-1):(null==e?void 0:e.baseUrl)??this.baseUrl,this.client=new _f({fetch:null==e?void 0:e.fetch,host:this.baseUrl,headers:null==e?void 0:e.headers}),this.keepAlive=null==e?void 0:e.keepAlive,this.embeddingOnly=null==e?void 0:e.embeddingOnly,this.f16KV=null==e?void 0:e.f16Kv,this.frequencyPenalty=null==e?void 0:e.frequencyPenalty,this.logitsAll=null==e?void 0:e.logitsAll,this.lowVram=null==e?void 0:e.lowVram,this.mainGpu=null==e?void 0:e.mainGpu,this.mirostat=null==e?void 0:e.mirostat,this.mirostatEta=null==e?void 0:e.mirostatEta,this.mirostatTau=null==e?void 0:e.mirostatTau,this.numBatch=null==e?void 0:e.numBatch,this.numCtx=null==e?void 0:e.numCtx,this.numGpu=null==e?void 0:e.numGpu,this.numKeep=null==e?void 0:e.numKeep,this.numPredict=null==e?void 0:e.numPredict,this.numThread=null==e?void 0:e.numThread,this.penalizeNewline=null==e?void 0:e.penalizeNewline,this.presencePenalty=null==e?void 0:e.presencePenalty,this.repeatLastN=null==e?void 0:e.repeatLastN,this.repeatPenalty=null==e?void 0:e.repeatPenalty,this.temperature=null==e?void 0:e.temperature,this.stop=null==e?void 0:e.stop,this.tfsZ=null==e?void 0:e.tfsZ,this.topK=null==e?void 0:e.topK,this.topP=null==e?void 0:e.topP,this.typicalP=null==e?void 0:e.typicalP,this.useMLock=null==e?void 0:e.useMlock,this.useMMap=null==e?void 0:e.useMmap,this.vocabOnly=null==e?void 0:e.vocabOnly,this.format=null==e?void 0:e.format}_llmType(){return"ollama"}invocationParams(e){return{model:this.model,format:this.format,keep_alive:this.keepAlive,images:null==e?void 0:e.images,options:{embedding_only:this.embeddingOnly,f16_kv:this.f16KV,frequency_penalty:this.frequencyPenalty,logits_all:this.logitsAll,low_vram:this.lowVram,main_gpu:this.mainGpu,mirostat:this.mirostat,mirostat_eta:this.mirostatEta,mirostat_tau:this.mirostatTau,num_batch:this.numBatch,num_ctx:this.numCtx,num_gpu:this.numGpu,num_keep:this.numKeep,num_predict:this.numPredict,num_thread:this.numThread,penalize_newline:this.penalizeNewline,presence_penalty:this.presencePenalty,repeat_last_n:this.repeatLastN,repeat_penalty:this.repeatPenalty,temperature:this.temperature,stop:(null==e?void 0:e.stop)??this.stop,tfs_z:this.tfsZ,top_k:this.topK,top_p:this.topP,typical_p:this.typicalP,use_mlock:this.useMLock,use_mmap:this.useMMap,vocab_only:this.vocabOnly}}}async*_streamResponseChunks(e,t,i){var n;const r=await this.caller.call(async()=>this.client.generate({...this.invocationParams(t),prompt:e,stream:!0}));for await(const s of r){if(null==(n=t.signal)?void 0:n.aborted)throw new Error("This operation was aborted");s.done?yield new Ul({text:"",generationInfo:{model:s.model,total_duration:s.total_duration,load_duration:s.load_duration,prompt_eval_count:s.prompt_eval_count,prompt_eval_duration:s.prompt_eval_duration,eval_count:s.eval_count,eval_duration:s.eval_duration}}):(yield new Ul({text:s.response,generationInfo:{...s,response:void 0}}),await(null==i?void 0:i.handleLLMNewToken(s.response??"")))}}async _call(e,t,i){const n=[];for await(const r of this._streamResponseChunks(e,t,i))n.push(r.text);return n.join("")}}function Pf(e,t,i,n,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,i),i}function Tf(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}let $f=function(){const{crypto:e}=globalThis;if(null==e?void 0:e.randomUUID)return $f=e.randomUUID.bind(e),e.randomUUID();const t=new Uint8Array(1),i=e?()=>e.getRandomValues(t)[0]:()=>255*Math.random()&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(+e^i()&15>>+e/4).toString(16))};function Ef(e){return"object"==typeof e&&null!==e&&("name"in e&&"AbortError"===e.name||"message"in e&&String(e.message).includes("FetchRequestCanceledException"))}const Af=e=>{if(e instanceof Error)return e;if("object"==typeof e&&null!==e){try{if("[object Error]"===Object.prototype.toString.call(e)){const t=new Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return new Error(JSON.stringify(e))}catch{}}return new Error(e)};class Cf extends Error{}class Rf extends Cf{constructor(e,t,i,n){super(`${Rf.makeMessage(e,t,i)}`),this.status=e,this.headers=n,this.requestID=null==n?void 0:n.get("x-request-id"),this.error=t;const r=t;this.code=null==r?void 0:r.code,this.param=null==r?void 0:r.param,this.type=null==r?void 0:r.type}static makeMessage(e,t,i){const n=(null==t?void 0:t.message)?"string"==typeof t.message?t.message:JSON.stringify(t.message):t?JSON.stringify(t):i;return e&&n?`${e} ${n}`:e?`${e} status code (no body)`:n||"(no status code or body)"}static generate(e,t,i,n){if(!e||!n)return new If({message:i,cause:Af(t)});const r=null==t?void 0:t.error;return 400===e?new Mf(e,r,i,n):401===e?new Nf(e,r,i,n):403===e?new Lf(e,r,i,n):404===e?new Zf(e,r,i,n):409===e?new Df(e,r,i,n):422===e?new zf(e,r,i,n):429===e?new Uf(e,r,i,n):e>=500?new qf(e,r,i,n):new Rf(e,r,i,n)}}class Qf extends Rf{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class If extends Rf{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class jf extends If{constructor({message:e}={}){super({message:e??"Request timed out."})}}class Mf extends Rf{}class Nf extends Rf{}class Lf extends Rf{}class Zf extends Rf{}class Df extends Rf{}class zf extends Rf{}class Uf extends Rf{}class qf extends Rf{}class Xf extends Cf{constructor(){super("Could not parse response content as the length limit was reached")}}class Bf extends Cf{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}class Wf extends Error{constructor(e){super(e)}}const Vf=/^[a-z][a-z0-9+.-]*:/i;let Ff=e=>(Ff=Array.isArray,Ff(e)),Yf=Ff;function Gf(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)}const Hf=e=>new Promise(t=>setTimeout(t,e)),Kf="5.12.2";const Jf=()=>{var e;const t="undefined"!=typeof Deno&&null!=Deno.build?"deno":"undefined"!=typeof EdgeRuntime?"edge":"[object process]"===Object.prototype.toString.call(void 0!==globalThis.process?globalThis.process:0)?"node":"unknown";if("deno"===t)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":tm(Deno.build.os),"X-Stainless-Arch":em(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":"string"==typeof Deno.version?Deno.version:(null==(e=Deno.version)?void 0:e.deno)??"unknown"};if("undefined"!=typeof EdgeRuntime)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if("node"===t)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":tm(globalThis.process.platform??"unknown"),"X-Stainless-Arch":em(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};const i=function(){if("undefined"==typeof navigator||!navigator)return null;const e=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:t,pattern:i}of e){const e=i.exec(navigator.userAgent);if(e){return{browser:t,version:`${e[1]||0}.${e[2]||0}.${e[3]||0}`}}}return null}();return i?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${i.browser}`,"X-Stainless-Runtime-Version":i.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};const em=e=>"x32"===e?"x32":"x86_64"===e||"x64"===e?"x64":"arm"===e?"arm":"aarch64"===e||"arm64"===e?"arm64":e?`other:${e}`:"unknown",tm=e=>(e=e.toLowerCase()).includes("ios")?"iOS":"android"===e?"Android":"darwin"===e?"MacOS":"win32"===e?"Windows":"freebsd"===e?"FreeBSD":"openbsd"===e?"OpenBSD":"linux"===e?"Linux":e?`Other:${e}`:"Unknown";let im;function nm(...e){const t=globalThis.ReadableStream;if(void 0===t)throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function rm(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return nm({start(){},async pull(e){const{done:i,value:n}=await t.next();i?e.close():e.enqueue(n)},async cancel(){var e;await(null==(e=t.return)?void 0:e.call(t))}})}function sm(e){if(e[Symbol.asyncIterator])return e;const t=e.getReader();return{async next(){try{const e=await t.read();return(null==e?void 0:e.done)&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){const e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}const am=({headers:e,body:t})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(t)}),om="RFC3986",lm=e=>String(e),cm={RFC1738:e=>String(e).replace(/%20/g,"+"),RFC3986:lm};let hm=(e,t)=>(hm=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),hm(e,t));const um=(()=>{const e=[];for(let t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e})(),dm=1024;function pm(e,t){if(Ff(e)){const i=[];for(let n=0;n<e.length;n+=1)i.push(t(e[n]));return i}return t(e)}const fm={brackets:e=>String(e)+"[]",comma:"comma",indices:(e,t)=>String(e)+"["+t+"]",repeat:e=>String(e)},mm=function(e,t){Array.prototype.push.apply(e,Ff(t)?t:[t])};let gm;const Om={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:(e,t,i,n,r)=>{if(0===e.length)return e;let s=e;if("symbol"==typeof e?s=Symbol.prototype.toString.call(e):"string"!=typeof e&&(s=String(e)),"iso-8859-1"===i)return escape(s).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});let a="";for(let o=0;o<s.length;o+=dm){const e=s.length>=dm?s.slice(o,o+dm):s,t=[];for(let i=0;i<e.length;++i){let n=e.charCodeAt(i);45===n||46===n||95===n||126===n||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122||"RFC1738"===r&&(40===n||41===n)?t[t.length]=e.charAt(i):n<128?t[t.length]=um[n]:n<2048?t[t.length]=um[192|n>>6]+um[128|63&n]:n<55296||n>=57344?t[t.length]=um[224|n>>12]+um[128|n>>6&63]+um[128|63&n]:(i+=1,n=65536+((1023&n)<<10|1023&e.charCodeAt(i)),t[t.length]=um[240|n>>18]+um[128|n>>12&63]+um[128|n>>6&63]+um[128|63&n])}a+=t.join("")}return a},encodeValuesOnly:!1,format:om,formatter:lm,indices:!1,serializeDate:e=>(gm??(gm=Function.prototype.call.bind(Date.prototype.toISOString)))(e),skipNulls:!1,strictNullHandling:!1};const vm={};function ym(e,t,i,n,r,s,a,o,l,c,h,u,d,p,f,m,g,O){let v=e,y=O,b=0,w=!1;for(;void 0!==(y=y.get(vm))&&!w;){const t=y.get(e);if(b+=1,void 0!==t){if(t===b)throw new RangeError("Cyclic object value");w=!0}void 0===y.get(vm)&&(b=0)}if("function"==typeof c?v=c(t,v):v instanceof Date?v=null==d?void 0:d(v):"comma"===i&&Ff(v)&&(v=pm(v,function(e){return e instanceof Date?null==d?void 0:d(e):e})),null===v){if(s)return l&&!m?l(t,Om.encoder,g,"key",p):t;v=""}if("string"==typeof(_=v)||"number"==typeof _||"boolean"==typeof _||"symbol"==typeof _||"bigint"==typeof _||function(e){return!(!e||"object"!=typeof e||!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e)))}(v)){if(l){const e=m?t:l(t,Om.encoder,g,"key",p);return[(null==f?void 0:f(e))+"="+(null==f?void 0:f(l(v,Om.encoder,g,"value",p)))]}return[(null==f?void 0:f(t))+"="+(null==f?void 0:f(String(v)))]}var _;const x=[];if(void 0===v)return x;let S;if("comma"===i&&Ff(v))m&&l&&(v=pm(v,l)),S=[{value:v.length>0?v.join(",")||null:void 0}];else if(Ff(c))S=c;else{const e=Object.keys(v);S=h?e.sort(h):e}const k=o?String(t).replace(/\./g,"%2E"):String(t),P=n&&Ff(v)&&1===v.length?k+"[]":k;if(r&&Ff(v)&&0===v.length)return P+"[]";for(let T=0;T<S.length;++T){const t=S[T],y="object"==typeof t&&void 0!==t.value?t.value:v[t];if(a&&null===y)continue;const w=u&&o?t.replace(/\./g,"%2E"):t,_=Ff(v)?"function"==typeof i?i(P,w):P:P+(u?"."+w:"["+w+"]");O.set(e,b);const k=new WeakMap;k.set(vm,O),mm(x,ym(y,_,i,n,r,s,a,o,"comma"===i&&m&&Ff(v)?null:l,c,h,u,d,p,f,m,g,k))}return x}function bm(e,t={}){let i=e;const n=function(e=Om){if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.encodeDotInKeys&&"boolean"!=typeof e.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");const t=e.charset||Om.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let i=om;if(void 0!==e.format){if(!hm(cm,e.format))throw new TypeError("Unknown format option provided.");i=e.format}const n=cm[i];let r,s=Om.filter;if(("function"==typeof e.filter||Ff(e.filter))&&(s=e.filter),r=e.arrayFormat&&e.arrayFormat in fm?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":Om.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const a=void 0===e.allowDots?1==!!e.encodeDotInKeys||Om.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:Om.addQueryPrefix,allowDots:a,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:Om.allowEmptyArrays,arrayFormat:r,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:Om.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?Om.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:Om.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:Om.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:Om.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:Om.encodeValuesOnly,filter:s,format:i,formatter:n,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:Om.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:Om.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:Om.strictNullHandling}}(t);let r,s;"function"==typeof n.filter?(s=n.filter,i=s("",i)):Ff(n.filter)&&(s=n.filter,r=s);const a=[];if("object"!=typeof i||null===i)return"";const o=fm[n.arrayFormat],l="comma"===o&&n.commaRoundTrip;r||(r=Object.keys(i)),n.sort&&r.sort(n.sort);const c=new WeakMap;for(let d=0;d<r.length;++d){const e=r[d];n.skipNulls&&null===i[e]||mm(a,ym(i[e],e,o,l,n.allowEmptyArrays,n.strictNullHandling,n.skipNulls,n.encodeDotInKeys,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,c))}const h=a.join(n.delimiter);let u=!0===n.addQueryPrefix?"?":"";return n.charsetSentinel&&("iso-8859-1"===n.charset?u+="utf8=%26%2310003%3B&":u+="utf8=%E2%9C%93&"),h.length>0?u+h:""}let wm,_m;function xm(e){let t;return(wm??(t=new globalThis.TextEncoder,wm=t.encode.bind(t)))(e)}function Sm(e){let t;return(_m??(t=new globalThis.TextDecoder,_m=t.decode.bind(t)))(e)}var km,Pm;class Tm{constructor(){km.set(this,void 0),Pm.set(this,void 0),Pf(this,km,new Uint8Array),Pf(this,Pm,null)}decode(e){if(null==e)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):"string"==typeof e?xm(e):e;Pf(this,km,function(e){let t=0;for(const r of e)t+=r.length;const i=new Uint8Array(t);let n=0;for(const r of e)i.set(r,n),n+=r.length;return i}([Tf(this,km,"f"),t]));const i=[];let n;for(;null!=(n=$m(Tf(this,km,"f"),Tf(this,Pm,"f")));){if(n.carriage&&null==Tf(this,Pm,"f")){Pf(this,Pm,n.index);continue}if(null!=Tf(this,Pm,"f")&&(n.index!==Tf(this,Pm,"f")+1||n.carriage)){i.push(Sm(Tf(this,km,"f").subarray(0,Tf(this,Pm,"f")-1))),Pf(this,km,Tf(this,km,"f").subarray(Tf(this,Pm,"f"))),Pf(this,Pm,null);continue}const e=null!==Tf(this,Pm,"f")?n.preceding-1:n.preceding,t=Sm(Tf(this,km,"f").subarray(0,e));i.push(t),Pf(this,km,Tf(this,km,"f").subarray(n.index)),Pf(this,Pm,null)}return i}flush(){return Tf(this,km,"f").length?this.decode("\n"):[]}}function $m(e,t){for(let i=t??0;i<e.length;i++){if(10===e[i])return{preceding:i,index:i+1,carriage:!1};if(13===e[i])return{preceding:i,index:i+1,carriage:!0}}return null}function Em(e){for(let t=0;t<e.length-1;t++){if(10===e[t]&&10===e[t+1])return t+2;if(13===e[t]&&13===e[t+1])return t+2;if(13===e[t]&&10===e[t+1]&&t+3<e.length&&13===e[t+2]&&10===e[t+3])return t+4}return-1}km=new WeakMap,Pm=new WeakMap,Tm.NEWLINE_CHARS=new Set(["\n","\r"]),Tm.NEWLINE_REGEXP=/\r\n|[\n\r]/g;const Am={off:0,error:200,warn:300,info:400,debug:500},Cm=(e,t,i)=>{if(e)return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(Am,e)?e:void Mm(i).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(Am))}`)};function Rm(){}function Qm(e,t,i){return!t||Am[e]>Am[i]?Rm:t[e].bind(t)}const Im={error:Rm,warn:Rm,info:Rm,debug:Rm};let jm=new WeakMap;function Mm(e){const t=e.logger,i=e.logLevel??"off";if(!t)return Im;const n=jm.get(t);if(n&&n[0]===i)return n[1];const r={error:Qm("error",t,i),warn:Qm("warn",t,i),info:Qm("info",t,i),debug:Qm("debug",t,i)};return jm.set(t,[i,r]),r}const Nm=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&(e.headers=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,"authorization"===e.toLowerCase()||"cookie"===e.toLowerCase()||"set-cookie"===e.toLowerCase()?"***":t]))),"retryOfRequestLogID"in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e);var Lm,Zm,Dm;class zm{constructor(e,t,i){this.iterator=e,Lm.set(this,void 0),this.controller=t,Pf(this,Lm,i)}static fromSSEResponse(e,t,i){let n=!1;const r=i?Mm(i):console;return new zm(async function*(){if(n)throw new Cf("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let i=!1;try{for await(const n of async function*(e,t){if(!e.body){if(t.abort(),void 0!==globalThis.navigator&&"ReactNative"===globalThis.navigator.product)throw new Cf("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api");throw new Cf("Attempted to iterate over a response with no body")}const i=new Um,n=new Tm,r=sm(e.body);for await(const s of async function*(e){let t=new Uint8Array;for await(const i of e){if(null==i)continue;const e=i instanceof ArrayBuffer?new Uint8Array(i):"string"==typeof i?xm(i):i;let n,r=new Uint8Array(t.length+e.length);for(r.set(t),r.set(e,t.length),t=r;-1!==(n=Em(t));)yield t.slice(0,n),t=t.slice(n)}t.length>0&&(yield t)}(r))for(const e of n.decode(s)){const t=i.decode(e);t&&(yield t)}for(const s of n.flush()){const e=i.decode(s);e&&(yield e)}}(e,t))if(!i)if(n.data.startsWith("[DONE]"))i=!0;else if(null!==n.event&&n.event.startsWith("thread.")){let e;try{e=JSON.parse(n.data)}catch(s){throw s}if("error"==n.event)throw new Rf(void 0,e.error,e.message,void 0);yield{event:n.event,data:e}}else{let t;try{t=JSON.parse(n.data)}catch(s){throw r.error("Could not parse message into JSON:",n.data),r.error("From chunk:",n.raw),s}if(t&&t.error)throw new Rf(void 0,t.error,void 0,e.headers);yield t}i=!0}catch(s){if(Ef(s))return;throw s}finally{i||t.abort()}},t,i)}static fromReadableStream(e,t,i){let n=!1;return new zm(async function*(){if(n)throw new Cf("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let i=!1;try{for await(const t of async function*(){const t=new Tm,i=sm(e);for await(const e of i)for(const i of t.decode(e))yield i;for(const e of t.flush())yield e}())i||t&&(yield JSON.parse(t));i=!0}catch(r){if(Ef(r))return;throw r}finally{i||t.abort()}},t,i)}[(Lm=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){const e=[],t=[],i=this.iterator(),n=n=>({next:()=>{if(0===n.length){const n=i.next();e.push(n),t.push(n)}return n.shift()}});return[new zm(()=>n(e),this.controller,Tf(this,Lm,"f")),new zm(()=>n(t),this.controller,Tf(this,Lm,"f"))]}toReadableStream(){const e=this;let t;return nm({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{const{value:i,done:n}=await t.next();if(n)return e.close();const r=xm(JSON.stringify(i)+"\n");e.enqueue(r)}catch($M){e.error($M)}},async cancel(){var e;await(null==(e=t.return)?void 0:e.call(t))}})}}class Um{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const e={event:this.event,data:this.data.join("\n"),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(":"))return null;let[t,i,n]=function(e,t){const i=e.indexOf(t);if(-1!==i)return[e.substring(0,i),t,e.substring(i+t.length)];return[e,"",""]}(e,":");return n.startsWith(" ")&&(n=n.substring(1)),"event"===t?this.event=n:"data"===t&&this.data.push(n),null}}async function qm(e,t){const{response:i,requestLogID:n,retryOfRequestLogID:r,startTime:s}=t,a=await(async()=>{var n;if(t.options.stream)return Mm(e).debug("response",i.status,i.url,i.headers,i.body),t.options.__streamClass?t.options.__streamClass.fromSSEResponse(i,t.controller,e):zm.fromSSEResponse(i,t.controller,e);if(204===i.status)return null;if(t.options.__binaryResponse)return i;const r=i.headers.get("content-type"),s=null==(n=null==r?void 0:r.split(";")[0])?void 0:n.trim();if((null==s?void 0:s.includes("application/json"))||(null==s?void 0:s.endsWith("+json"))){return Xm(await i.json(),i)}return await i.text()})();return Mm(e).debug(`[${n}] response parsed`,Nm({retryOfRequestLogID:r,url:i.url,status:i.status,body:a,durationMs:Date.now()-s})),a}function Xm(e,t){return!e||"object"!=typeof e||Array.isArray(e)?e:Object.defineProperty(e,"_request_id",{value:t.headers.get("x-request-id"),enumerable:!1})}class Bm extends Promise{constructor(e,t,i=qm){super(e=>{e(null)}),this.responsePromise=t,this.parseResponse=i,Zm.set(this,void 0),Pf(this,Zm,e)}_thenUnwrap(e){return new Bm(Tf(this,Zm,"f"),this.responsePromise,async(t,i)=>Xm(e(await this.parseResponse(t,i),i),i.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get("x-request-id")}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(e=>this.parseResponse(Tf(this,Zm,"f"),e))),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}}Zm=new WeakMap;class Wm{constructor(e,t,i,n){Dm.set(this,void 0),Pf(this,Dm,e),this.options=n,this.response=t,this.body=i}hasNextPage(){return!!this.getPaginatedItems().length&&null!=this.nextPageRequestOptions()}async getNextPage(){const e=this.nextPageRequestOptions();if(!e)throw new Cf("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");return await Tf(this,Dm,"f").requestAPIList(this.constructor,e)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(Dm=new WeakMap,Symbol.asyncIterator)](){for await(const e of this.iterPages())for(const t of e.getPaginatedItems())yield t}}class Vm extends Bm{constructor(e,t,i){super(e,t,async(e,t)=>new i(e,t.response,await qm(e,t),t.options))}async*[Symbol.asyncIterator](){const e=await(this);for await(const t of e)yield t}}class Fm extends Wm{constructor(e,t,i,n){super(e,t,i,n),this.data=i.data||[],this.object=i.object}getPaginatedItems(){return this.data??[]}nextPageRequestOptions(){return null}}class Ym extends Wm{constructor(e,t,i,n){super(e,t,i,n),this.data=i.data||[],this.has_more=i.has_more||!1}getPaginatedItems(){return this.data??[]}hasNextPage(){return!1!==this.has_more&&super.hasNextPage()}nextPageRequestOptions(){var e;const t=this.getPaginatedItems(),i=null==(e=t[t.length-1])?void 0:e.id;return i?{...this.options,query:{...(n=this.options.query,"object"!=typeof n?{}:n??{}),after:i}}:null;var n}}const Gm=()=>{var e;if("undefined"==typeof File){const{process:t}=globalThis,i="string"==typeof(null==(e=null==t?void 0:t.versions)?void 0:e.node)&&parseInt(t.versions.node.split("."))<20;throw new Error("`File` is not defined as a global, which is required for file uploads."+(i?" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.":""))}};function Hm(e,t,i){return Gm(),new File(e,t??"unknown_file",i)}function Km(e){return("object"==typeof e&&null!==e&&("name"in e&&e.name&&String(e.name)||"url"in e&&e.url&&String(e.url)||"filename"in e&&e.filename&&String(e.filename)||"path"in e&&e.path&&String(e.path))||"").split(/[\\/]/).pop()||void 0}const Jm=e=>null!=e&&"object"==typeof e&&"function"==typeof e[Symbol.asyncIterator],eg=async(e,t)=>({...e,body:await ig(e.body,t)}),tg=new WeakMap;const ig=async(e,t)=>{if(!(await function(e){const t="function"==typeof e?e:e.fetch,i=tg.get(t);if(i)return i;const n=(async()=>{try{const e="Response"in t?t.Response:(await t("data:,")).constructor,i=new FormData;return i.toString()!==await new e(i).text()}catch{return!0}})();return tg.set(t,n),n}(t)))throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");const i=new FormData;return await Promise.all(Object.entries(e||{}).map(([e,t])=>ng(i,e,t))),i},ng=async(e,t,i)=>{if(void 0!==i){if(null==i)throw new TypeError(`Received null for "${t}"; to pass null in FormData, you must use the string 'null'`);if("string"==typeof i||"number"==typeof i||"boolean"==typeof i)e.append(t,String(i));else if(i instanceof Response)e.append(t,Hm([await i.blob()],Km(i)));else if(Jm(i))e.append(t,Hm([await new Response(rm(i)).blob()],Km(i)));else if((e=>e instanceof Blob&&"name"in e)(i))e.append(t,i,Km(i));else if(Array.isArray(i))await Promise.all(i.map(i=>ng(e,t+"[]",i)));else{if("object"!=typeof i)throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${i} instead`);await Promise.all(Object.entries(i).map(([i,n])=>ng(e,`${t}[${i}]`,n)))}}},rg=e=>null!=e&&"object"==typeof e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.text&&"function"==typeof e.slice&&"function"==typeof e.arrayBuffer;async function sg(e){var t;let i=[];if("string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)i.push(e);else if(rg(e))i.push(e instanceof Blob?e:await e.arrayBuffer());else{if(!Jm(e)){const i=null==(t=null==e?void 0:e.constructor)?void 0:t.name;throw new Error(`Unexpected data type: ${typeof e}${i?`; constructor: ${i}`:""}${function(e){if("object"!=typeof e||null===e)return"";const t=Object.getOwnPropertyNames(e);return`; props: [${t.map(e=>`"${e}"`).join(", ")}]`}(e)}`)}for await(const t of e)i.push(...await sg(t))}return i}class ag{constructor(e){this._client=e}}function og(e){return e.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}const lg=Object.freeze(Object.create(null)),cg=(e=og)=>function(t,...i){if(1===t.length)return t[0];let n=!1;const r=[],s=t.reduce((t,s,a)=>{var o;/[?#]/.test(s)&&(n=!0);const l=i[a];let c=(n?encodeURIComponent:e)(""+l);return a!==i.length&&(null==l||"object"==typeof l&&l.toString===(null==(o=Object.getPrototypeOf(Object.getPrototypeOf(l.hasOwnProperty??lg)??lg))?void 0:o.toString))&&(c=l+"",r.push({start:t.length+s.length,length:c.length,error:`Value of type ${Object.prototype.toString.call(l).slice(8,-1)} is not a valid path parameter`})),t+s+(a===i.length?"":c)},""),a=s.split(/[?#]/,1)[0],o=new RegExp("(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)","gi");let l;for(;null!==(l=o.exec(a));)r.push({start:l.index,length:l[0].length,error:`Value "${l[0]}" can't be safely passed as a path parameter`});if(r.sort((e,t)=>e.start-t.start),r.length>0){let e=0;const t=r.reduce((t,i)=>{const n=" ".repeat(i.start-e),r="^".repeat(i.length);return e=i.start+i.length,t+n+r},"");throw new Cf(`Path parameters result in path with invalid segments:\n${r.map(e=>e.error).join("\n")}\n${s}\n${t}`)}return s},hg=cg(og);let ug=class extends ag{list(e,t={},i){return this._client.getAPIList(hg`/chat/completions/${e}/messages`,Ym,{query:t,...i})}};function dg(e){return void 0!==e&&"function"in e&&void 0!==e.function}function pg(e){return"auto-parseable-response-format"===(null==e?void 0:e.$brand)}function fg(e){return"auto-parseable-tool"===(null==e?void 0:e.$brand)}function mg(e,t){const i=e.choices.map(e=>{var i;if("length"===e.finish_reason)throw new Xf;if("content_filter"===e.finish_reason)throw new Bf;return yg(e.message.tool_calls),{...e,message:{...e.message,...e.message.tool_calls?{tool_calls:(null==(i=e.message.tool_calls)?void 0:i.map(e=>function(e,t){var i;const n=null==(i=e.tools)?void 0:i.find(e=>{var i;return dg(e)&&(null==(i=e.function)?void 0:i.name)===t.function.name});return{...t,function:{...t.function,parsed_arguments:fg(n)?n.$parseRaw(t.function.arguments):(null==n?void 0:n.function.strict)?JSON.parse(t.function.arguments):null}}}(t,e)))??void 0}:void 0,parsed:e.message.content&&!e.message.refusal?gg(t,e.message.content):null}}});return{...e,choices:i}}function gg(e,t){var i,n;if("json_schema"!==(null==(i=e.response_format)?void 0:i.type))return null;if("json_schema"===(null==(n=e.response_format)?void 0:n.type)){if("$parseRaw"in e.response_format){return e.response_format.$parseRaw(t)}return JSON.parse(t)}return null}function Og(e,t){var i;if(!e||!("tools"in e)||!e.tools)return!1;const n=null==(i=e.tools)?void 0:i.find(e=>{var i;return dg(e)&&(null==(i=e.function)?void 0:i.name)===t.function.name});return dg(n)&&(fg(n)||(null==n?void 0:n.function.strict)||!1)}function vg(e){var t;return!!pg(e.response_format)||((null==(t=e.tools)?void 0:t.some(e=>fg(e)||"function"===e.type&&!0===e.function.strict))??!1)}function yg(e){for(const t of e||[])if("function"!==t.type)throw new Cf(`Currently only \`function\` tool calls are supported; Received \`${t.type}\``)}const bg=e=>"assistant"===(null==e?void 0:e.role),wg=e=>"tool"===(null==e?void 0:e.role);var _g,xg,Sg,kg,Pg,Tg,$g,Eg,Ag,Cg,Rg,Qg,Ig,jg,Mg,Ng,Lg,Zg,Dg,zg,Ug;class qg{constructor(){_g.add(this),this.controller=new AbortController,xg.set(this,void 0),Sg.set(this,()=>{}),kg.set(this,()=>{}),Pg.set(this,void 0),Tg.set(this,()=>{}),$g.set(this,()=>{}),Eg.set(this,{}),Ag.set(this,!1),Cg.set(this,!1),Rg.set(this,!1),Qg.set(this,!1),Pf(this,xg,new Promise((e,t)=>{Pf(this,Sg,e),Pf(this,kg,t)})),Pf(this,Pg,new Promise((e,t)=>{Pf(this,Tg,e),Pf(this,$g,t)})),Tf(this,xg,"f").catch(()=>{}),Tf(this,Pg,"f").catch(()=>{})}_run(e){setTimeout(()=>{e().then(()=>{this._emitFinal(),this._emit("end")},Tf(this,_g,"m",Ig).bind(this))},0)}_connected(){this.ended||(Tf(this,Sg,"f").call(this),this._emit("connect"))}get ended(){return Tf(this,Ag,"f")}get errored(){return Tf(this,Cg,"f")}get aborted(){return Tf(this,Rg,"f")}abort(){this.controller.abort()}on(e,t){return(Tf(this,Eg,"f")[e]||(Tf(this,Eg,"f")[e]=[])).push({listener:t}),this}off(e,t){const i=Tf(this,Eg,"f")[e];if(!i)return this;const n=i.findIndex(e=>e.listener===t);return n>=0&&i.splice(n,1),this}once(e,t){return(Tf(this,Eg,"f")[e]||(Tf(this,Eg,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,i)=>{Pf(this,Qg,!0),"error"!==e&&this.once("error",i),this.once(e,t)})}async done(){Pf(this,Qg,!0),await Tf(this,Pg,"f")}_emit(e,...t){if(Tf(this,Ag,"f"))return;"end"===e&&(Pf(this,Ag,!0),Tf(this,Tg,"f").call(this));const i=Tf(this,Eg,"f")[e];if(i&&(Tf(this,Eg,"f")[e]=i.filter(e=>!e.once),i.forEach(({listener:e})=>e(...t))),"abort"===e){const e=t[0];return Tf(this,Qg,"f")||(null==i?void 0:i.length)||Promise.reject(e),Tf(this,kg,"f").call(this,e),Tf(this,$g,"f").call(this,e),void this._emit("end")}if("error"===e){const e=t[0];Tf(this,Qg,"f")||(null==i?void 0:i.length)||Promise.reject(e),Tf(this,kg,"f").call(this,e),Tf(this,$g,"f").call(this,e),this._emit("end")}}_emitFinal(){}}function Xg(e){return"function"==typeof e.parse}xg=new WeakMap,Sg=new WeakMap,kg=new WeakMap,Pg=new WeakMap,Tg=new WeakMap,$g=new WeakMap,Eg=new WeakMap,Ag=new WeakMap,Cg=new WeakMap,Rg=new WeakMap,Qg=new WeakMap,_g=new WeakSet,Ig=function(e){if(Pf(this,Cg,!0),e instanceof Error&&"AbortError"===e.name&&(e=new Qf),e instanceof Qf)return Pf(this,Rg,!0),this._emit("abort",e);if(e instanceof Cf)return this._emit("error",e);if(e instanceof Error){const t=new Cf(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new Cf(String(e)))};const Bg=10;class Wg extends qg{constructor(){super(...arguments),jg.add(this),this._chatCompletions=[],this.messages=[]}_addChatCompletion(e){var t;this._chatCompletions.push(e),this._emit("chatCompletion",e);const i=null==(t=e.choices[0])?void 0:t.message;return i&&this._addMessage(i),e}_addMessage(e,t=!0){if("content"in e||(e.content=null),this.messages.push(e),t)if(this._emit("message",e),wg(e)&&e.content)this._emit("functionToolCallResult",e.content);else if(bg(e)&&e.tool_calls)for(const i of e.tool_calls)"function"===i.type&&this._emit("functionToolCall",i.function)}async finalChatCompletion(){await this.done();const e=this._chatCompletions[this._chatCompletions.length-1];if(!e)throw new Cf("stream ended without producing a ChatCompletion");return e}async finalContent(){return await this.done(),Tf(this,jg,"m",Mg).call(this)}async finalMessage(){return await this.done(),Tf(this,jg,"m",Ng).call(this)}async finalFunctionToolCall(){return await this.done(),Tf(this,jg,"m",Lg).call(this)}async finalFunctionToolCallResult(){return await this.done(),Tf(this,jg,"m",Zg).call(this)}async totalUsage(){return await this.done(),Tf(this,jg,"m",Dg).call(this)}allChatCompletions(){return[...this._chatCompletions]}_emitFinal(){const e=this._chatCompletions[this._chatCompletions.length-1];e&&this._emit("finalChatCompletion",e);const t=Tf(this,jg,"m",Ng).call(this);t&&this._emit("finalMessage",t);const i=Tf(this,jg,"m",Mg).call(this);i&&this._emit("finalContent",i);const n=Tf(this,jg,"m",Lg).call(this);n&&this._emit("finalFunctionToolCall",n);const r=Tf(this,jg,"m",Zg).call(this);null!=r&&this._emit("finalFunctionToolCallResult",r),this._chatCompletions.some(e=>e.usage)&&this._emit("totalUsage",Tf(this,jg,"m",Dg).call(this))}async _createChatCompletion(e,t,i){const n=null==i?void 0:i.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),Tf(this,jg,"m",zg).call(this,t);const r=await e.chat.completions.create({...t,stream:!1},{...i,signal:this.controller.signal});return this._connected(),this._addChatCompletion(mg(r,t))}async _runChatCompletion(e,t,i){for(const n of t.messages)this._addMessage(n,!1);return await this._createChatCompletion(e,t,i)}async _runTools(e,t,i){var n,r,s;const a="tool",{tool_choice:o="auto",stream:l,...c}=t,h="string"!=typeof o&&"function"===o.type&&(null==(n=null==o?void 0:o.function)?void 0:n.name),{maxChatCompletions:u=Bg}=i||{},d=t.tools.map(e=>{if(fg(e)){if(!e.$callback)throw new Cf("Tool given to `.runTools()` that does not have an associated function");return{type:"function",function:{function:e.$callback,name:e.function.name,description:e.function.description||"",parameters:e.function.parameters,parse:e.$parseRaw,strict:!0}}}return e}),p={};for(const g of d)"function"===g.type&&(p[g.function.name||g.function.function.name]=g.function);const f="tools"in t?d.map(e=>"function"===e.type?{type:"function",function:{name:e.function.name||e.function.function.name,parameters:e.function.parameters,description:e.function.description,strict:e.function.strict}}:e):void 0;for(const g of t.messages)this._addMessage(g,!1);for(let g=0;g<u;++g){const t=null==(r=(await this._createChatCompletion(e,{...c,tool_choice:o,tools:f,messages:[...this.messages]},i)).choices[0])?void 0:r.message;if(!t)throw new Cf("missing message in ChatCompletion response");if(!(null==(s=t.tool_calls)?void 0:s.length))return;for(const e of t.tool_calls){if("function"!==e.type)continue;const t=e.id,{name:i,arguments:n}=e.function,r=p[i];if(!r){const e=`Invalid tool_call: ${JSON.stringify(i)}. Available options are: ${Object.keys(p).map(e=>JSON.stringify(e)).join(", ")}. Please try again`;this._addMessage({role:a,tool_call_id:t,content:e});continue}if(h&&h!==i){const e=`Invalid tool_call: ${JSON.stringify(i)}. ${JSON.stringify(h)} requested. Please try again`;this._addMessage({role:a,tool_call_id:t,content:e});continue}let s;try{s=Xg(r)?await r.parse(n):n}catch(m){const e=m instanceof Error?m.message:String(m);this._addMessage({role:a,tool_call_id:t,content:e});continue}const o=await r.function(s,this),l=Tf(this,jg,"m",Ug).call(this,o);if(this._addMessage({role:a,tool_call_id:t,content:l}),h)return}}}}jg=new WeakSet,Mg=function(){return Tf(this,jg,"m",Ng).call(this).content??null},Ng=function(){let e=this.messages.length;for(;e-- >0;){const t=this.messages[e];if(bg(t)){return{...t,content:t.content??null,refusal:t.refusal??null}}}throw new Cf("stream ended without producing a ChatCompletionMessage with role=assistant")},Lg=function(){var e,t;for(let i=this.messages.length-1;i>=0;i--){const n=this.messages[i];if(bg(n)&&(null==(e=null==n?void 0:n.tool_calls)?void 0:e.length))return null==(t=n.tool_calls.filter(e=>"function"===e.type).at(-1))?void 0:t.function}},Zg=function(){for(let e=this.messages.length-1;e>=0;e--){const t=this.messages[e];if(wg(t)&&null!=t.content&&"string"==typeof t.content&&this.messages.some(e=>{var i;return"assistant"===e.role&&(null==(i=e.tool_calls)?void 0:i.some(e=>"function"===e.type&&e.id===t.tool_call_id))}))return t.content}},Dg=function(){const e={completion_tokens:0,prompt_tokens:0,total_tokens:0};for(const{usage:t}of this._chatCompletions)t&&(e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens);return e},zg=function(e){if(null!=e.n&&e.n>1)throw new Cf("ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.")},Ug=function(e){return"string"==typeof e?e:void 0===e?"undefined":JSON.stringify(e)};class Vg extends Wg{static runTools(e,t,i){const n=new Vg,r={...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"runTools"}};return n._run(()=>n._runTools(e,t,r)),n}_addMessage(e,t=!0){super._addMessage(e,t),bg(e)&&e.content&&this._emit("content",e.content)}}const Fg=1,Yg=2,Gg=4,Hg=8,Kg=16,Jg=32,eO=64,tO=128,iO=256,nO=511;class rO extends Error{}class sO extends Error{}const aO=(e,t)=>{const i=e.length;let n=0;const r=e=>{throw new rO(`${e} at position ${n}`)},s=e=>{throw new sO(`${e} at position ${n}`)},a=()=>(u(),n>=i&&r("Unexpected end of input"),'"'===e[n]?o():"{"===e[n]?l():"["===e[n]?c():"null"===e.substring(n,n+4)||Kg&t&&i-n<4&&"null".startsWith(e.substring(n))?(n+=4,null):"true"===e.substring(n,n+4)||Jg&t&&i-n<4&&"true".startsWith(e.substring(n))?(n+=4,!0):"false"===e.substring(n,n+5)||Jg&t&&i-n<5&&"false".startsWith(e.substring(n))?(n+=5,!1):"Infinity"===e.substring(n,n+8)||tO&t&&i-n<8&&"Infinity".startsWith(e.substring(n))?(n+=8,1/0):"-Infinity"===e.substring(n,n+9)||iO&t&&1<i-n&&i-n<9&&"-Infinity".startsWith(e.substring(n))?(n+=9,-1/0):"NaN"===e.substring(n,n+3)||eO&t&&i-n<3&&"NaN".startsWith(e.substring(n))?(n+=3,NaN):h()),o=()=>{const a=n;let o=!1;for(n++;n<i&&('"'!==e[n]||o&&"\\"===e[n-1]);)o="\\"===e[n]&&!o,n++;if('"'==e.charAt(n))try{return JSON.parse(e.substring(a,++n-Number(o)))}catch(l){s(String(l))}else if(Fg&t)try{return JSON.parse(e.substring(a,n-Number(o))+'"')}catch(l){return JSON.parse(e.substring(a,e.lastIndexOf("\\"))+'"')}r("Unterminated string literal")},l=()=>{n++,u();const s={};try{for(;"}"!==e[n];){if(u(),n>=i&&Hg&t)return s;const r=o();u(),n++;try{const e=a();Object.defineProperty(s,r,{value:e,writable:!0,enumerable:!0,configurable:!0})}catch(l){if(Hg&t)return s;throw l}u(),","===e[n]&&n++}}catch(l){if(Hg&t)return s;r("Expected '}' at end of object")}return n++,s},c=()=>{n++;const i=[];try{for(;"]"!==e[n];)i.push(a()),u(),","===e[n]&&n++}catch(s){if(Gg&t)return i;r("Expected ']' at end of array")}return n++,i},h=()=>{if(0===n){"-"===e&&Yg&t&&r("Not sure what '-' is");try{return JSON.parse(e)}catch(o){if(Yg&t)try{return"."===e[e.length-1]?JSON.parse(e.substring(0,e.lastIndexOf("."))):JSON.parse(e.substring(0,e.lastIndexOf("e")))}catch(l){}s(String(o))}}const a=n;for("-"===e[n]&&n++;e[n]&&!",]}".includes(e[n]);)n++;n!=i||Yg&t||r("Unterminated number literal");try{return JSON.parse(e.substring(a,n))}catch(o){"-"===e.substring(a,n)&&Yg&t&&r("Not sure what '-' is");try{return JSON.parse(e.substring(a,e.lastIndexOf("e")))}catch(l){s(String(l))}}},u=()=>{for(;n<i&&" \n\r\t".includes(e[n]);)n++};return a()},oO=e=>function(e,t=nO){if("string"!=typeof e)throw new TypeError("expecting str, got "+typeof e);if(!e.trim())throw new Error(`${e} is empty`);return aO(e.trim(),t)}(e,nO^Yg);var lO,cO,hO,uO,dO,pO,fO,mO,gO,OO,vO,yO;class bO extends Wg{constructor(e){super(),lO.add(this),cO.set(this,void 0),hO.set(this,void 0),uO.set(this,void 0),Pf(this,cO,e),Pf(this,hO,[])}get currentChatCompletionSnapshot(){return Tf(this,uO,"f")}static fromReadableStream(e){const t=new bO(null);return t._run(()=>t._fromReadableStream(e)),t}static createChatCompletion(e,t,i){const n=new bO(t);return n._run(()=>n._runChatCompletion(e,{...t,stream:!0},{...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"stream"}})),n}async _createChatCompletion(e,t,i){var n;super._createChatCompletion;const r=null==i?void 0:i.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),Tf(this,lO,"m",dO).call(this);const s=await e.chat.completions.create({...t,stream:!0},{...i,signal:this.controller.signal});this._connected();for await(const a of s)Tf(this,lO,"m",fO).call(this,a);if(null==(n=s.controller.signal)?void 0:n.aborted)throw new Qf;return this._addChatCompletion(Tf(this,lO,"m",OO).call(this))}async _fromReadableStream(e,t){var i;const n=null==t?void 0:t.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),Tf(this,lO,"m",dO).call(this),this._connected();const r=zm.fromReadableStream(e,this.controller);let s;for await(const a of r)s&&s!==a.id&&this._addChatCompletion(Tf(this,lO,"m",OO).call(this)),Tf(this,lO,"m",fO).call(this,a),s=a.id;if(null==(i=r.controller.signal)?void 0:i.aborted)throw new Qf;return this._addChatCompletion(Tf(this,lO,"m",OO).call(this))}[(cO=new WeakMap,hO=new WeakMap,uO=new WeakMap,lO=new WeakSet,dO=function(){this.ended||Pf(this,uO,void 0)},pO=function(e){let t=Tf(this,hO,"f")[e.index];return t||(t={content_done:!1,refusal_done:!1,logprobs_content_done:!1,logprobs_refusal_done:!1,done_tool_calls:new Set,current_tool_call_index:null},Tf(this,hO,"f")[e.index]=t,t)},fO=function(e){var t,i,n,r,s,a,o,l,c,h,u,d,p,f,m;if(this.ended)return;const g=Tf(this,lO,"m",yO).call(this,e);this._emit("chunk",e,g);for(const O of e.choices){const e=g.choices[O.index];null!=O.delta.content&&"assistant"===(null==(t=e.message)?void 0:t.role)&&(null==(i=e.message)?void 0:i.content)&&(this._emit("content",O.delta.content,e.message.content),this._emit("content.delta",{delta:O.delta.content,snapshot:e.message.content,parsed:e.message.parsed})),null!=O.delta.refusal&&"assistant"===(null==(n=e.message)?void 0:n.role)&&(null==(r=e.message)?void 0:r.refusal)&&this._emit("refusal.delta",{delta:O.delta.refusal,snapshot:e.message.refusal}),null!=(null==(s=O.logprobs)?void 0:s.content)&&"assistant"===(null==(a=e.message)?void 0:a.role)&&this._emit("logprobs.content.delta",{content:null==(o=O.logprobs)?void 0:o.content,snapshot:(null==(l=e.logprobs)?void 0:l.content)??[]}),null!=(null==(c=O.logprobs)?void 0:c.refusal)&&"assistant"===(null==(h=e.message)?void 0:h.role)&&this._emit("logprobs.refusal.delta",{refusal:null==(u=O.logprobs)?void 0:u.refusal,snapshot:(null==(d=e.logprobs)?void 0:d.refusal)??[]});const v=Tf(this,lO,"m",pO).call(this,e);e.finish_reason&&(Tf(this,lO,"m",gO).call(this,e),null!=v.current_tool_call_index&&Tf(this,lO,"m",mO).call(this,e,v.current_tool_call_index));for(const t of O.delta.tool_calls??[])v.current_tool_call_index!==t.index&&(Tf(this,lO,"m",gO).call(this,e),null!=v.current_tool_call_index&&Tf(this,lO,"m",mO).call(this,e,v.current_tool_call_index)),v.current_tool_call_index=t.index;for(const t of O.delta.tool_calls??[]){const i=null==(p=e.message.tool_calls)?void 0:p[t.index];(null==i?void 0:i.type)&&("function"===(null==i?void 0:i.type)?this._emit("tool_calls.function.arguments.delta",{name:null==(f=i.function)?void 0:f.name,index:t.index,arguments:i.function.arguments,parsed_arguments:i.function.parsed_arguments,arguments_delta:(null==(m=t.function)?void 0:m.arguments)??""}):_O(null==i?void 0:i.type))}}},mO=function(e,t){var i,n,r;if(Tf(this,lO,"m",pO).call(this,e).done_tool_calls.has(t))return;const s=null==(i=e.message.tool_calls)?void 0:i[t];if(!s)throw new Error("no tool call snapshot");if(!s.type)throw new Error("tool call snapshot missing `type`");if("function"===s.type){const e=null==(r=null==(n=Tf(this,cO,"f"))?void 0:n.tools)?void 0:r.find(e=>dg(e)&&e.function.name===s.function.name);this._emit("tool_calls.function.arguments.done",{name:s.function.name,index:t,arguments:s.function.arguments,parsed_arguments:fg(e)?e.$parseRaw(s.function.arguments):(null==e?void 0:e.function.strict)?JSON.parse(s.function.arguments):null})}else s.type},gO=function(e){var t,i;const n=Tf(this,lO,"m",pO).call(this,e);if(e.message.content&&!n.content_done){n.content_done=!0;const t=Tf(this,lO,"m",vO).call(this);this._emit("content.done",{content:e.message.content,parsed:t?t.$parseRaw(e.message.content):null})}e.message.refusal&&!n.refusal_done&&(n.refusal_done=!0,this._emit("refusal.done",{refusal:e.message.refusal})),(null==(t=e.logprobs)?void 0:t.content)&&!n.logprobs_content_done&&(n.logprobs_content_done=!0,this._emit("logprobs.content.done",{content:e.logprobs.content})),(null==(i=e.logprobs)?void 0:i.refusal)&&!n.logprobs_refusal_done&&(n.logprobs_refusal_done=!0,this._emit("logprobs.refusal.done",{refusal:e.logprobs.refusal}))},OO=function(){if(this.ended)throw new Cf("stream has ended, this shouldn't happen");const e=Tf(this,uO,"f");if(!e)throw new Cf("request ended without sending any chunks");return Pf(this,uO,void 0),Pf(this,hO,[]),function(e,t){const{id:i,choices:n,created:r,model:s,system_fingerprint:a,...o}=e,l={...o,id:i,choices:n.map(({message:t,finish_reason:i,index:n,logprobs:r,...s})=>{if(!i)throw new Cf(`missing finish_reason for choice ${n}`);const{content:a=null,function_call:o,tool_calls:l,...c}=t,h=t.role;if(!h)throw new Cf(`missing role for choice ${n}`);if(o){const{arguments:e,name:l}=o;if(null==e)throw new Cf(`missing function_call.arguments for choice ${n}`);if(!l)throw new Cf(`missing function_call.name for choice ${n}`);return{...s,message:{content:a,function_call:{arguments:e,name:l},role:h,refusal:t.refusal??null},finish_reason:i,index:n,logprobs:r}}return l?{...s,index:n,finish_reason:i,logprobs:r,message:{...c,role:h,content:a,refusal:t.refusal??null,tool_calls:l.map((t,i)=>{const{function:r,type:s,id:a,...o}=t,{arguments:l,name:c,...h}=r||{};if(null==a)throw new Cf(`missing choices[${n}].tool_calls[${i}].id\n${wO(e)}`);if(null==s)throw new Cf(`missing choices[${n}].tool_calls[${i}].type\n${wO(e)}`);if(null==c)throw new Cf(`missing choices[${n}].tool_calls[${i}].function.name\n${wO(e)}`);if(null==l)throw new Cf(`missing choices[${n}].tool_calls[${i}].function.arguments\n${wO(e)}`);return{...o,id:a,type:s,function:{...h,name:c,arguments:l}}})}}:{...s,message:{...c,content:a,role:h,refusal:t.refusal??null},finish_reason:i,index:n,logprobs:r}}),created:r,model:s,object:"chat.completion",...a?{system_fingerprint:a}:{}};return function(e,t){return t&&vg(t)?mg(e,t):{...e,choices:e.choices.map(e=>(yg(e.message.tool_calls),{...e,message:{...e.message,parsed:null,...e.message.tool_calls?{tool_calls:e.message.tool_calls}:void 0}}))}}(l,t)}(e,Tf(this,cO,"f"))},vO=function(){var e;const t=null==(e=Tf(this,cO,"f"))?void 0:e.response_format;return pg(t)?t:null},yO=function(e){var t,i,n,r;let s=Tf(this,uO,"f");const{choices:a,...o}=e;s?Object.assign(s,o):s=Pf(this,uO,{...o,choices:[]});for(const{delta:l,finish_reason:c,index:h,logprobs:u=null,...d}of e.choices){let e=s.choices[h];if(e||(e=s.choices[h]={finish_reason:c,index:h,message:{},logprobs:u,...d}),u)if(e.logprobs){const{content:n,refusal:r,...s}=u;Object.assign(e.logprobs,s),n&&((t=e.logprobs).content??(t.content=[]),e.logprobs.content.push(...n)),r&&((i=e.logprobs).refusal??(i.refusal=[]),e.logprobs.refusal.push(...r))}else e.logprobs=Object.assign({},u);if(c&&(e.finish_reason=c,Tf(this,cO,"f")&&vg(Tf(this,cO,"f")))){if("length"===c)throw new Xf;if("content_filter"===c)throw new Bf}if(Object.assign(e,d),!l)continue;const{content:a,refusal:o,function_call:p,role:f,tool_calls:m,...g}=l;if(Object.assign(e.message,g),o&&(e.message.refusal=(e.message.refusal||"")+o),f&&(e.message.role=f),p&&(e.message.function_call?(p.name&&(e.message.function_call.name=p.name),p.arguments&&((n=e.message.function_call).arguments??(n.arguments=""),e.message.function_call.arguments+=p.arguments)):e.message.function_call=p),a&&(e.message.content=(e.message.content||"")+a,!e.message.refusal&&Tf(this,lO,"m",vO).call(this)&&(e.message.parsed=oO(e.message.content))),m){e.message.tool_calls||(e.message.tool_calls=[]);for(const{index:t,id:i,type:n,function:s,...a}of m){const o=(r=e.message.tool_calls)[t]??(r[t]={});Object.assign(o,a),i&&(o.id=i),n&&(o.type=n),s&&(o.function??(o.function={name:s.name??"",arguments:""})),(null==s?void 0:s.name)&&(o.function.name=s.name),(null==s?void 0:s.arguments)&&(o.function.arguments+=s.arguments,Og(Tf(this,cO,"f"),o)&&(o.function.parsed_arguments=oO(o.function.arguments)))}}}return s},Symbol.asyncIterator)](){const e=[],t=[];let i=!1;return this.on("chunk",i=>{const n=t.shift();n?n.resolve(i):e.push(i)}),this.on("end",()=>{i=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),this.on("error",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),{next:async()=>{if(!e.length)return i?{value:void 0,done:!0}:new Promise((e,i)=>t.push({resolve:e,reject:i})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0});return{value:e.shift(),done:!1}},return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new zm(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}function wO(e){return JSON.stringify(e)}function _O(e){}class xO extends bO{static fromReadableStream(e){const t=new xO(null);return t._run(()=>t._fromReadableStream(e)),t}static runTools(e,t,i){const n=new xO(t),r={...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"runTools"}};return n._run(()=>n._runTools(e,t,r)),n}}let SO=class extends ag{constructor(){super(...arguments),this.messages=new ug(this._client)}create(e,t){return this._client.post("/chat/completions",{body:e,...t,stream:e.stream??!1})}retrieve(e,t){return this._client.get(hg`/chat/completions/${e}`,t)}update(e,t,i){return this._client.post(hg`/chat/completions/${e}`,{body:t,...i})}list(e={},t){return this._client.getAPIList("/chat/completions",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/chat/completions/${e}`,t)}parse(e,t){return function(e){for(const t of e??[]){if("function"!==t.type)throw new Cf(`Currently only \`function\` tool types support auto-parsing; Received \`${t.type}\``);if(!0!==t.function.strict)throw new Cf(`The \`${t.function.name}\` tool is not marked with \`strict: true\`. Only strict function tools can be auto-parsed`)}}(e.tools),this._client.chat.completions.create(e,{...t,headers:{...null==t?void 0:t.headers,"X-Stainless-Helper-Method":"chat.completions.parse"}})._thenUnwrap(t=>mg(t,e))}runTools(e,t){return e.stream?xO.runTools(this._client,e,t):Vg.runTools(this._client,e,t)}stream(e,t){return bO.createChatCompletion(this._client,e,t)}};SO.Messages=ug;class kO extends ag{constructor(){super(...arguments),this.completions=new SO(this._client)}}kO.Completions=SO;const PO=Symbol("brand.privateNullableHeaders");function*TO(e){if(!e)return;if(PO in e){const{values:t,nulls:i}=e;yield*t.entries();for(const e of i)yield[e,null];return}let t,i=!1;e instanceof Headers?t=e.entries():Yf(e)?t=e:(i=!0,t=Object.entries(e??{}));for(let n of t){const e=n[0];if("string"!=typeof e)throw new TypeError("expected header name to be a string");const t=Yf(n[1])?n[1]:[n[1]];let r=!1;for(const n of t)void 0!==n&&(i&&!r&&(r=!0,yield[e,null]),yield[e,n])}}const $O=e=>{const t=new Headers,i=new Set;for(const n of e){const e=new Set;for(const[r,s]of TO(n)){const n=r.toLowerCase();e.has(n)||(t.delete(r),e.add(n)),null===s?(t.delete(r),i.add(n)):(t.append(r,s),i.delete(n))}}return{[PO]:!0,values:t,nulls:i}};class EO extends ag{create(e,t){return this._client.post("/audio/speech",{body:e,...t,headers:$O([{Accept:"application/octet-stream"},null==t?void 0:t.headers]),__binaryResponse:!0})}}class AO extends ag{create(e,t){return this._client.post("/audio/transcriptions",eg({body:e,...t,stream:e.stream??!1,__metadata:{model:e.model}},this._client))}}class CO extends ag{create(e,t){return this._client.post("/audio/translations",eg({body:e,...t,__metadata:{model:e.model}},this._client))}}class RO extends ag{constructor(){super(...arguments),this.transcriptions=new AO(this._client),this.translations=new CO(this._client),this.speech=new EO(this._client)}}RO.Transcriptions=AO,RO.Translations=CO,RO.Speech=EO;class QO extends ag{create(e,t){return this._client.post("/batches",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/batches/${e}`,t)}list(e={},t){return this._client.getAPIList("/batches",Ym,{query:e,...t})}cancel(e,t){return this._client.post(hg`/batches/${e}/cancel`,t)}}class IO extends ag{create(e,t){return this._client.post("/assistants",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}retrieve(e,t){return this._client.get(hg`/assistants/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}update(e,t,i){return this._client.post(hg`/assistants/${e}`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e={},t){return this._client.getAPIList("/assistants",Ym,{query:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}delete(e,t){return this._client.delete(hg`/assistants/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}}class jO extends ag{create(e,t){return this._client.post("/realtime/sessions",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}}class MO extends ag{create(e,t){return this._client.post("/realtime/transcription_sessions",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}}class NO extends ag{constructor(){super(...arguments),this.sessions=new jO(this._client),this.transcriptionSessions=new MO(this._client)}}NO.Sessions=jO,NO.TranscriptionSessions=MO;class LO extends ag{create(e,t,i){return this._client.post(hg`/threads/${e}/messages`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}retrieve(e,t,i){const{thread_id:n}=t;return this._client.get(hg`/threads/${n}/messages/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}update(e,t,i){const{thread_id:n,...r}=t;return this._client.post(hg`/threads/${n}/messages/${e}`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t={},i){return this._client.getAPIList(hg`/threads/${e}/messages`,Ym,{query:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}delete(e,t,i){const{thread_id:n}=t;return this._client.delete(hg`/threads/${n}/messages/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}class ZO extends ag{retrieve(e,t,i){const{thread_id:n,run_id:r,...s}=t;return this._client.get(hg`/threads/${n}/runs/${r}/steps/${e}`,{query:s,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t,i){const{thread_id:n,...r}=t;return this._client.getAPIList(hg`/threads/${n}/runs/${e}/steps`,Ym,{query:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}const DO=e=>{var t,i,n,r,s;return void 0!==globalThis.process?(null==(i=null==(t=globalThis.process.env)?void 0:t[e])?void 0:i.trim())??void 0:void 0!==globalThis.Deno?null==(s=null==(r=null==(n=globalThis.Deno.env)?void 0:n.get)?void 0:r.call(n,e))?void 0:s.trim():void 0};var zO,UO,qO,XO,BO,WO,VO,FO,YO,GO,HO,KO,JO,ev,tv,iv,nv,rv,sv,av,ov,lv,cv;class hv extends qg{constructor(){super(...arguments),zO.add(this),qO.set(this,[]),XO.set(this,{}),BO.set(this,{}),WO.set(this,void 0),VO.set(this,void 0),FO.set(this,void 0),YO.set(this,void 0),GO.set(this,void 0),HO.set(this,void 0),KO.set(this,void 0),JO.set(this,void 0),ev.set(this,void 0)}[(qO=new WeakMap,XO=new WeakMap,BO=new WeakMap,WO=new WeakMap,VO=new WeakMap,FO=new WeakMap,YO=new WeakMap,GO=new WeakMap,HO=new WeakMap,KO=new WeakMap,JO=new WeakMap,ev=new WeakMap,zO=new WeakSet,Symbol.asyncIterator)](){const e=[],t=[];let i=!1;return this.on("event",i=>{const n=t.shift();n?n.resolve(i):e.push(i)}),this.on("end",()=>{i=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),this.on("error",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),{next:async()=>{if(!e.length)return i?{value:void 0,done:!0}:new Promise((e,i)=>t.push({resolve:e,reject:i})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0});return{value:e.shift(),done:!1}},return:async()=>(this.abort(),{value:void 0,done:!0})}}static fromReadableStream(e){const t=new UO;return t._run(()=>t._fromReadableStream(e)),t}async _fromReadableStream(e,t){var i;const n=null==t?void 0:t.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),this._connected();const r=zm.fromReadableStream(e,this.controller);for await(const s of r)Tf(this,zO,"m",tv).call(this,s);if(null==(i=r.controller.signal)?void 0:i.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}toReadableStream(){return new zm(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}static createToolAssistantStream(e,t,i,n){const r=new UO;return r._run(()=>r._runToolAssistantStream(e,t,i,{...n,headers:{...null==n?void 0:n.headers,"X-Stainless-Helper-Method":"stream"}})),r}async _createToolAssistantStream(e,t,i,n){var r;const s=null==n?void 0:n.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort()));const a={...i,stream:!0},o=await e.submitToolOutputs(t,a,{...n,signal:this.controller.signal});this._connected();for await(const l of o)Tf(this,zO,"m",tv).call(this,l);if(null==(r=o.controller.signal)?void 0:r.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}static createThreadAssistantStream(e,t,i){const n=new UO;return n._run(()=>n._threadAssistantStream(e,t,{...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"stream"}})),n}static createAssistantStream(e,t,i,n){const r=new UO;return r._run(()=>r._runAssistantStream(e,t,i,{...n,headers:{...null==n?void 0:n.headers,"X-Stainless-Helper-Method":"stream"}})),r}currentEvent(){return Tf(this,KO,"f")}currentRun(){return Tf(this,JO,"f")}currentMessageSnapshot(){return Tf(this,WO,"f")}currentRunStepSnapshot(){return Tf(this,ev,"f")}async finalRunSteps(){return await this.done(),Object.values(Tf(this,XO,"f"))}async finalMessages(){return await this.done(),Object.values(Tf(this,BO,"f"))}async finalRun(){if(await this.done(),!Tf(this,VO,"f"))throw Error("Final run was not received.");return Tf(this,VO,"f")}async _createThreadAssistantStream(e,t,i){var n;const r=null==i?void 0:i.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort()));const s={...t,stream:!0},a=await e.createAndRun(s,{...i,signal:this.controller.signal});this._connected();for await(const o of a)Tf(this,zO,"m",tv).call(this,o);if(null==(n=a.controller.signal)?void 0:n.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}async _createAssistantStream(e,t,i,n){var r;const s=null==n?void 0:n.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort()));const a={...i,stream:!0},o=await e.create(t,a,{...n,signal:this.controller.signal});this._connected();for await(const l of o)Tf(this,zO,"m",tv).call(this,l);if(null==(r=o.controller.signal)?void 0:r.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}static accumulateDelta(e,t){for(const[i,n]of Object.entries(t)){if(!e.hasOwnProperty(i)){e[i]=n;continue}let t=e[i];if(null!=t)if("index"!==i&&"type"!==i){if("string"==typeof t&&"string"==typeof n)t+=n;else if("number"==typeof t&&"number"==typeof n)t+=n;else{if(!Gf(t)||!Gf(n)){if(Array.isArray(t)&&Array.isArray(n)){if(t.every(e=>"string"==typeof e||"number"==typeof e)){t.push(...n);continue}for(const e of n){if(!Gf(e))throw new Error(`Expected array delta entry to be an object but got: ${e}`);const i=e.index;if(null==i)throw new Error("Expected array delta entry to have an `index` property");if("number"!=typeof i)throw new Error(`Expected array delta entry \`index\` property to be a number but got ${i}`);const n=t[i];null==n?t.push(e):t[i]=this.accumulateDelta(n,e)}continue}throw Error(`Unhandled record type: ${i}, deltaValue: ${n}, accValue: ${t}`)}t=this.accumulateDelta(t,n)}e[i]=t}else e[i]=n;else e[i]=n}return e}_addRun(e){return e}async _threadAssistantStream(e,t,i){return await this._createThreadAssistantStream(t,e,i)}async _runAssistantStream(e,t,i,n){return await this._createAssistantStream(t,e,i,n)}async _runToolAssistantStream(e,t,i,n){return await this._createToolAssistantStream(t,e,i,n)}}UO=hv,tv=function(e){if(!this.ended)switch(Pf(this,KO,e),Tf(this,zO,"m",sv).call(this,e),e.event){case"thread.created":break;case"thread.run.created":case"thread.run.queued":case"thread.run.in_progress":case"thread.run.requires_action":case"thread.run.completed":case"thread.run.incomplete":case"thread.run.failed":case"thread.run.cancelling":case"thread.run.cancelled":case"thread.run.expired":Tf(this,zO,"m",cv).call(this,e);break;case"thread.run.step.created":case"thread.run.step.in_progress":case"thread.run.step.delta":case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":Tf(this,zO,"m",rv).call(this,e);break;case"thread.message.created":case"thread.message.in_progress":case"thread.message.delta":case"thread.message.completed":case"thread.message.incomplete":Tf(this,zO,"m",nv).call(this,e);break;case"error":throw new Error("Encountered an error event in event processing - errors should be processed earlier")}},iv=function(){if(this.ended)throw new Cf("stream has ended, this shouldn't happen");if(!Tf(this,VO,"f"))throw Error("Final run has not been received");return Tf(this,VO,"f")},nv=function(e){const[t,i]=Tf(this,zO,"m",ov).call(this,e,Tf(this,WO,"f"));Pf(this,WO,t),Tf(this,BO,"f")[t.id]=t;for(const n of i){const e=t.content[n.index];"text"==(null==e?void 0:e.type)&&this._emit("textCreated",e.text)}switch(e.event){case"thread.message.created":this._emit("messageCreated",e.data);break;case"thread.message.in_progress":break;case"thread.message.delta":if(this._emit("messageDelta",e.data.delta,t),e.data.delta.content)for(const i of e.data.delta.content){if("text"==i.type&&i.text){let e=i.text,n=t.content[i.index];if(!n||"text"!=n.type)throw Error("The snapshot associated with this text delta is not text or missing");this._emit("textDelta",e,n.text)}if(i.index!=Tf(this,FO,"f")){if(Tf(this,YO,"f"))switch(Tf(this,YO,"f").type){case"text":this._emit("textDone",Tf(this,YO,"f").text,Tf(this,WO,"f"));break;case"image_file":this._emit("imageFileDone",Tf(this,YO,"f").image_file,Tf(this,WO,"f"))}Pf(this,FO,i.index)}Pf(this,YO,t.content[i.index])}break;case"thread.message.completed":case"thread.message.incomplete":if(void 0!==Tf(this,FO,"f")){const t=e.data.content[Tf(this,FO,"f")];if(t)switch(t.type){case"image_file":this._emit("imageFileDone",t.image_file,Tf(this,WO,"f"));break;case"text":this._emit("textDone",t.text,Tf(this,WO,"f"))}}Tf(this,WO,"f")&&this._emit("messageDone",e.data),Pf(this,WO,void 0)}},rv=function(e){const t=Tf(this,zO,"m",av).call(this,e);switch(Pf(this,ev,t),e.event){case"thread.run.step.created":this._emit("runStepCreated",e.data);break;case"thread.run.step.delta":const i=e.data.delta;if(i.step_details&&"tool_calls"==i.step_details.type&&i.step_details.tool_calls&&"tool_calls"==t.step_details.type)for(const e of i.step_details.tool_calls)e.index==Tf(this,GO,"f")?this._emit("toolCallDelta",e,t.step_details.tool_calls[e.index]):(Tf(this,HO,"f")&&this._emit("toolCallDone",Tf(this,HO,"f")),Pf(this,GO,e.index),Pf(this,HO,t.step_details.tool_calls[e.index]),Tf(this,HO,"f")&&this._emit("toolCallCreated",Tf(this,HO,"f")));this._emit("runStepDelta",e.data.delta,t);break;case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":Pf(this,ev,void 0);"tool_calls"==e.data.step_details.type&&Tf(this,HO,"f")&&(this._emit("toolCallDone",Tf(this,HO,"f")),Pf(this,HO,void 0)),this._emit("runStepDone",e.data,t)}},sv=function(e){Tf(this,qO,"f").push(e),this._emit("event",e)},av=function(e){switch(e.event){case"thread.run.step.created":return Tf(this,XO,"f")[e.data.id]=e.data,e.data;case"thread.run.step.delta":let t=Tf(this,XO,"f")[e.data.id];if(!t)throw Error("Received a RunStepDelta before creation of a snapshot");let i=e.data;if(i.delta){const n=UO.accumulateDelta(t,i.delta);Tf(this,XO,"f")[e.data.id]=n}return Tf(this,XO,"f")[e.data.id];case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":case"thread.run.step.in_progress":Tf(this,XO,"f")[e.data.id]=e.data}if(Tf(this,XO,"f")[e.data.id])return Tf(this,XO,"f")[e.data.id];throw new Error("No snapshot available")},ov=function(e,t){let i=[];switch(e.event){case"thread.message.created":return[e.data,i];case"thread.message.delta":if(!t)throw Error("Received a delta with no existing snapshot (there should be one from message creation)");let n=e.data;if(n.delta.content)for(const e of n.delta.content)if(e.index in t.content){let i=t.content[e.index];t.content[e.index]=Tf(this,zO,"m",lv).call(this,e,i)}else t.content[e.index]=e,i.push(e);return[t,i];case"thread.message.in_progress":case"thread.message.completed":case"thread.message.incomplete":if(t)return[t,i];throw Error("Received thread message event with no existing snapshot")}throw Error("Tried to accumulate a non-message event")},lv=function(e,t){return UO.accumulateDelta(t,e)},cv=function(e){switch(Pf(this,JO,e.data),e.event){case"thread.run.created":case"thread.run.queued":case"thread.run.in_progress":break;case"thread.run.requires_action":case"thread.run.cancelled":case"thread.run.failed":case"thread.run.completed":case"thread.run.expired":case"thread.run.incomplete":Pf(this,VO,e.data),Tf(this,HO,"f")&&(this._emit("toolCallDone",Tf(this,HO,"f")),Pf(this,HO,void 0))}};let uv=class extends ag{constructor(){super(...arguments),this.steps=new ZO(this._client)}create(e,t,i){const{include:n,...r}=t;return this._client.post(hg`/threads/${e}/runs`,{query:{include:n},body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers]),stream:t.stream??!1})}retrieve(e,t,i){const{thread_id:n}=t;return this._client.get(hg`/threads/${n}/runs/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}update(e,t,i){const{thread_id:n,...r}=t;return this._client.post(hg`/threads/${n}/runs/${e}`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t={},i){return this._client.getAPIList(hg`/threads/${e}/runs`,Ym,{query:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}cancel(e,t,i){const{thread_id:n}=t;return this._client.post(hg`/threads/${n}/runs/${e}/cancel`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async createAndPoll(e,t,i){const n=await this.create(e,t,i);return await this.poll(n.id,{thread_id:e},i)}createAndStream(e,t,i){return hv.createAssistantStream(e,this._client.beta.threads.runs,t,i)}async poll(e,t,i){var n;const r=$O([null==i?void 0:i.headers,{"X-Stainless-Poll-Helper":"true","X-Stainless-Custom-Poll-Interval":(null==(n=null==i?void 0:i.pollIntervalMs)?void 0:n.toString())??void 0}]);for(;;){const{data:n,response:s}=await this.retrieve(e,t,{...i,headers:{...null==i?void 0:i.headers,...r}}).withResponse();switch(n.status){case"queued":case"in_progress":case"cancelling":let e=5e3;if(null==i?void 0:i.pollIntervalMs)e=i.pollIntervalMs;else{const t=s.headers.get("openai-poll-after-ms");if(t){const i=parseInt(t);isNaN(i)||(e=i)}}await Hf(e);break;case"requires_action":case"incomplete":case"cancelled":case"completed":case"failed":case"expired":return n}}}stream(e,t,i){return hv.createAssistantStream(e,this._client.beta.threads.runs,t,i)}submitToolOutputs(e,t,i){const{thread_id:n,...r}=t;return this._client.post(hg`/threads/${n}/runs/${e}/submit_tool_outputs`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers]),stream:t.stream??!1})}async submitToolOutputsAndPoll(e,t,i){const n=await this.submitToolOutputs(e,t,i);return await this.poll(n.id,t,i)}submitToolOutputsStream(e,t,i){return hv.createToolAssistantStream(e,this._client.beta.threads.runs,t,i)}};uv.Steps=ZO;class dv extends ag{constructor(){super(...arguments),this.runs=new uv(this._client),this.messages=new LO(this._client)}create(e={},t){return this._client.post("/threads",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}retrieve(e,t){return this._client.get(hg`/threads/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}update(e,t,i){return this._client.post(hg`/threads/${e}`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}delete(e,t){return this._client.delete(hg`/threads/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}createAndRun(e,t){return this._client.post("/threads/runs",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers]),stream:e.stream??!1})}async createAndRunPoll(e,t){const i=await this.createAndRun(e,t);return await this.runs.poll(i.id,{thread_id:i.thread_id},t)}createAndRunStream(e,t){return hv.createThreadAssistantStream(e,this._client.beta.threads,t)}}dv.Runs=uv,dv.Messages=LO;class pv extends ag{constructor(){super(...arguments),this.realtime=new NO(this._client),this.assistants=new IO(this._client),this.threads=new dv(this._client)}}pv.Realtime=NO,pv.Assistants=IO,pv.Threads=dv;class fv extends ag{create(e,t){return this._client.post("/completions",{body:e,...t,stream:e.stream??!1})}}class mv extends ag{retrieve(e,t,i){const{container_id:n}=t;return this._client.get(hg`/containers/${n}/files/${e}/content`,{...i,headers:$O([{Accept:"application/binary"},null==i?void 0:i.headers]),__binaryResponse:!0})}}let gv=class extends ag{constructor(){super(...arguments),this.content=new mv(this._client)}create(e,t,i){return this._client.post(hg`/containers/${e}/files`,eg({body:t,...i},this._client))}retrieve(e,t,i){const{container_id:n}=t;return this._client.get(hg`/containers/${n}/files/${e}`,i)}list(e,t={},i){return this._client.getAPIList(hg`/containers/${e}/files`,Ym,{query:t,...i})}delete(e,t,i){const{container_id:n}=t;return this._client.delete(hg`/containers/${n}/files/${e}`,{...i,headers:$O([{Accept:"*/*"},null==i?void 0:i.headers])})}};gv.Content=mv;class Ov extends ag{constructor(){super(...arguments),this.files=new gv(this._client)}create(e,t){return this._client.post("/containers",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/containers/${e}`,t)}list(e={},t){return this._client.getAPIList("/containers",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/containers/${e}`,{...t,headers:$O([{Accept:"*/*"},null==t?void 0:t.headers])})}}Ov.Files=gv;class vv extends ag{create(e,t){const i=!!e.encoding_format;let n=i?e.encoding_format:"base64";i&&Mm(this._client).debug("embeddings/user defined encoding_format:",e.encoding_format);const r=this._client.post("/embeddings",{body:{...e,encoding_format:n},...t});return i?r:(Mm(this._client).debug("embeddings/decoding base64 embeddings from base64"),r._thenUnwrap(e=>(e&&e.data&&e.data.forEach(e=>{const t=e.embedding;e.embedding=(e=>{if("undefined"!=typeof Buffer){const t=Buffer.from(e,"base64");return Array.from(new Float32Array(t.buffer,t.byteOffset,t.length/Float32Array.BYTES_PER_ELEMENT))}{const t=atob(e),i=t.length,n=new Uint8Array(i);for(let e=0;e<i;e++)n[e]=t.charCodeAt(e);return Array.from(new Float32Array(n.buffer))}})(t)}),e)))}}class yv extends ag{retrieve(e,t,i){const{eval_id:n,run_id:r}=t;return this._client.get(hg`/evals/${n}/runs/${r}/output_items/${e}`,i)}list(e,t,i){const{eval_id:n,...r}=t;return this._client.getAPIList(hg`/evals/${n}/runs/${e}/output_items`,Ym,{query:r,...i})}}class bv extends ag{constructor(){super(...arguments),this.outputItems=new yv(this._client)}create(e,t,i){return this._client.post(hg`/evals/${e}/runs`,{body:t,...i})}retrieve(e,t,i){const{eval_id:n}=t;return this._client.get(hg`/evals/${n}/runs/${e}`,i)}list(e,t={},i){return this._client.getAPIList(hg`/evals/${e}/runs`,Ym,{query:t,...i})}delete(e,t,i){const{eval_id:n}=t;return this._client.delete(hg`/evals/${n}/runs/${e}`,i)}cancel(e,t,i){const{eval_id:n}=t;return this._client.post(hg`/evals/${n}/runs/${e}`,i)}}bv.OutputItems=yv;class wv extends ag{constructor(){super(...arguments),this.runs=new bv(this._client)}create(e,t){return this._client.post("/evals",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/evals/${e}`,t)}update(e,t,i){return this._client.post(hg`/evals/${e}`,{body:t,...i})}list(e={},t){return this._client.getAPIList("/evals",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/evals/${e}`,t)}}wv.Runs=bv;let _v=class extends ag{create(e,t){return this._client.post("/files",eg({body:e,...t},this._client))}retrieve(e,t){return this._client.get(hg`/files/${e}`,t)}list(e={},t){return this._client.getAPIList("/files",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/files/${e}`,t)}content(e,t){return this._client.get(hg`/files/${e}/content`,{...t,headers:$O([{Accept:"application/binary"},null==t?void 0:t.headers]),__binaryResponse:!0})}async waitForProcessing(e,{pollInterval:t=5e3,maxWait:i=18e5}={}){const n=new Set(["processed","error","deleted"]),r=Date.now();let s=await this.retrieve(e);for(;!s.status||!n.has(s.status);)if(await Hf(t),s=await this.retrieve(e),Date.now()-r>i)throw new jf({message:`Giving up on waiting for file ${e} to finish processing after ${i} milliseconds.`});return s}};class xv extends ag{}let Sv=class extends ag{run(e,t){return this._client.post("/fine_tuning/alpha/graders/run",{body:e,...t})}validate(e,t){return this._client.post("/fine_tuning/alpha/graders/validate",{body:e,...t})}};class kv extends ag{constructor(){super(...arguments),this.graders=new Sv(this._client)}}kv.Graders=Sv;class Pv extends ag{create(e,t,i){return this._client.getAPIList(hg`/fine_tuning/checkpoints/${e}/permissions`,Fm,{body:t,method:"post",...i})}retrieve(e,t={},i){return this._client.get(hg`/fine_tuning/checkpoints/${e}/permissions`,{query:t,...i})}delete(e,t,i){const{fine_tuned_model_checkpoint:n}=t;return this._client.delete(hg`/fine_tuning/checkpoints/${n}/permissions/${e}`,i)}}let Tv=class extends ag{constructor(){super(...arguments),this.permissions=new Pv(this._client)}};Tv.Permissions=Pv;class $v extends ag{list(e,t={},i){return this._client.getAPIList(hg`/fine_tuning/jobs/${e}/checkpoints`,Ym,{query:t,...i})}}class Ev extends ag{constructor(){super(...arguments),this.checkpoints=new $v(this._client)}create(e,t){return this._client.post("/fine_tuning/jobs",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/fine_tuning/jobs/${e}`,t)}list(e={},t){return this._client.getAPIList("/fine_tuning/jobs",Ym,{query:e,...t})}cancel(e,t){return this._client.post(hg`/fine_tuning/jobs/${e}/cancel`,t)}listEvents(e,t={},i){return this._client.getAPIList(hg`/fine_tuning/jobs/${e}/events`,Ym,{query:t,...i})}pause(e,t){return this._client.post(hg`/fine_tuning/jobs/${e}/pause`,t)}resume(e,t){return this._client.post(hg`/fine_tuning/jobs/${e}/resume`,t)}}Ev.Checkpoints=$v;class Av extends ag{constructor(){super(...arguments),this.methods=new xv(this._client),this.jobs=new Ev(this._client),this.checkpoints=new Tv(this._client),this.alpha=new kv(this._client)}}Av.Methods=xv,Av.Jobs=Ev,Av.Checkpoints=Tv,Av.Alpha=kv;class Cv extends ag{}class Rv extends ag{constructor(){super(...arguments),this.graderModels=new Cv(this._client)}}Rv.GraderModels=Cv;class Qv extends ag{createVariation(e,t){return this._client.post("/images/variations",eg({body:e,...t},this._client))}edit(e,t){return this._client.post("/images/edits",eg({body:e,...t,stream:e.stream??!1},this._client))}generate(e,t){return this._client.post("/images/generations",{body:e,...t,stream:e.stream??!1})}}class Iv extends ag{retrieve(e,t){return this._client.get(hg`/models/${e}`,t)}list(e){return this._client.getAPIList("/models",Fm,e)}delete(e,t){return this._client.delete(hg`/models/${e}`,t)}}class jv extends ag{create(e,t){return this._client.post("/moderations",{body:e,...t})}}function Mv(e,t){return t&&function(e){var t;if(pg(null==(t=e.text)?void 0:t.format))return!0;return!1}(t)?Nv(e,t):{...e,output_parsed:null,output:e.output.map(e=>"function_call"===e.type?{...e,parsed_arguments:null}:"message"===e.type?{...e,content:e.content.map(e=>({...e,parsed:null}))}:e)}}function Nv(e,t){const i=e.output.map(e=>{if("function_call"===e.type)return{...e,parsed_arguments:Zv(t,e)};if("message"===e.type){const i=e.content.map(e=>"output_text"===e.type?{...e,parsed:Lv(t,e.text)}:e);return{...e,content:i}}return e}),n=Object.assign({},e,{output:i});return Object.getOwnPropertyDescriptor(e,"output_text")||Dv(n),Object.defineProperty(n,"output_parsed",{enumerable:!0,get(){for(const e of n.output)if("message"===e.type)for(const t of e.content)if("output_text"===t.type&&null!==t.parsed)return t.parsed;return null}}),n}function Lv(e,t){var i,n,r,s;if("json_schema"!==(null==(n=null==(i=e.text)?void 0:i.format)?void 0:n.type))return null;if("$parseRaw"in(null==(r=e.text)?void 0:r.format)){return(null==(s=e.text)?void 0:s.format).$parseRaw(t)}return JSON.parse(t)}function Zv(e,t){const i=(n=e.tools??[],r=t.name,n.find(e=>"function"===e.type&&e.name===r));var n,r,s;return{...t,...t,parsed_arguments:(s=i,"auto-parseable-tool"===(null==s?void 0:s.$brand)?i.$parseRaw(t.arguments):(null==i?void 0:i.strict)?JSON.parse(t.arguments):null)}}function Dv(e){const t=[];for(const i of e.output)if("message"===i.type)for(const e of i.content)"output_text"===e.type&&t.push(e.text);e.output_text=t.join("")}var zv,Uv,qv,Xv,Bv,Wv,Vv,Fv;class Yv extends qg{constructor(e){super(),zv.add(this),Uv.set(this,void 0),qv.set(this,void 0),Xv.set(this,void 0),Pf(this,Uv,e)}static createResponse(e,t,i){const n=new Yv(t);return n._run(()=>n._createOrRetrieveResponse(e,t,{...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"stream"}})),n}async _createOrRetrieveResponse(e,t,i){var n;const r=null==i?void 0:i.signal;let s;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),Tf(this,zv,"m",Bv).call(this);let a=null;"response_id"in t?(s=await e.responses.retrieve(t.response_id,{stream:!0},{...i,signal:this.controller.signal,stream:!0}),a=t.starting_after??null):s=await e.responses.create({...t,stream:!0},{...i,signal:this.controller.signal}),this._connected();for await(const o of s)Tf(this,zv,"m",Wv).call(this,o,a);if(null==(n=s.controller.signal)?void 0:n.aborted)throw new Qf;return Tf(this,zv,"m",Vv).call(this)}[(Uv=new WeakMap,qv=new WeakMap,Xv=new WeakMap,zv=new WeakSet,Bv=function(){this.ended||Pf(this,qv,void 0)},Wv=function(e,t){if(this.ended)return;const i=(e,i)=>{(null==t||i.sequence_number>t)&&this._emit(e,i)},n=Tf(this,zv,"m",Fv).call(this,e);switch(i("event",e),e.type){case"response.output_text.delta":{const t=n.output[e.output_index];if(!t)throw new Cf(`missing output at index ${e.output_index}`);if("message"===t.type){const n=t.content[e.content_index];if(!n)throw new Cf(`missing content at index ${e.content_index}`);if("output_text"!==n.type)throw new Cf(`expected content to be 'output_text', got ${n.type}`);i("response.output_text.delta",{...e,snapshot:n.text})}break}case"response.function_call_arguments.delta":{const t=n.output[e.output_index];if(!t)throw new Cf(`missing output at index ${e.output_index}`);"function_call"===t.type&&i("response.function_call_arguments.delta",{...e,snapshot:t.arguments});break}default:i(e.type,e)}},Vv=function(){if(this.ended)throw new Cf("stream has ended, this shouldn't happen");const e=Tf(this,qv,"f");if(!e)throw new Cf("request ended without sending any events");Pf(this,qv,void 0);const t=function(e,t){return Mv(e,t)}(e,Tf(this,Uv,"f"));return Pf(this,Xv,t),t},Fv=function(e){let t=Tf(this,qv,"f");if(!t){if("response.created"!==e.type)throw new Cf(`When snapshot hasn't been set yet, expected 'response.created' event, got ${e.type}`);return t=Pf(this,qv,e.response),t}switch(e.type){case"response.output_item.added":t.output.push(e.item);break;case"response.content_part.added":{const i=t.output[e.output_index];if(!i)throw new Cf(`missing output at index ${e.output_index}`);"message"===i.type&&i.content.push(e.part);break}case"response.output_text.delta":{const i=t.output[e.output_index];if(!i)throw new Cf(`missing output at index ${e.output_index}`);if("message"===i.type){const t=i.content[e.content_index];if(!t)throw new Cf(`missing content at index ${e.content_index}`);if("output_text"!==t.type)throw new Cf(`expected content to be 'output_text', got ${t.type}`);t.text+=e.delta}break}case"response.function_call_arguments.delta":{const i=t.output[e.output_index];if(!i)throw new Cf(`missing output at index ${e.output_index}`);"function_call"===i.type&&(i.arguments+=e.delta);break}case"response.completed":Pf(this,qv,e.response)}return t},Symbol.asyncIterator)](){const e=[],t=[];let i=!1;return this.on("event",i=>{const n=t.shift();n?n.resolve(i):e.push(i)}),this.on("end",()=>{i=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),this.on("error",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),{next:async()=>{if(!e.length)return i?{value:void 0,done:!0}:new Promise((e,i)=>t.push({resolve:e,reject:i})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0});return{value:e.shift(),done:!1}},return:async()=>(this.abort(),{value:void 0,done:!0})}}async finalResponse(){await this.done();const e=Tf(this,Xv,"f");if(!e)throw new Cf("stream ended without producing a ChatCompletion");return e}}class Gv extends ag{list(e,t={},i){return this._client.getAPIList(hg`/responses/${e}/input_items`,Ym,{query:t,...i})}}class Hv extends ag{constructor(){super(...arguments),this.inputItems=new Gv(this._client)}create(e,t){return this._client.post("/responses",{body:e,...t,stream:e.stream??!1})._thenUnwrap(e=>("object"in e&&"response"===e.object&&Dv(e),e))}retrieve(e,t={},i){return this._client.get(hg`/responses/${e}`,{query:t,...i,stream:(null==t?void 0:t.stream)??!1})._thenUnwrap(e=>("object"in e&&"response"===e.object&&Dv(e),e))}delete(e,t){return this._client.delete(hg`/responses/${e}`,{...t,headers:$O([{Accept:"*/*"},null==t?void 0:t.headers])})}parse(e,t){return this._client.responses.create(e,t)._thenUnwrap(t=>Nv(t,e))}stream(e,t){return Yv.createResponse(this._client,e,t)}cancel(e,t){return this._client.post(hg`/responses/${e}/cancel`,t)}}Hv.InputItems=Gv;class Kv extends ag{create(e,t,i){return this._client.post(hg`/uploads/${e}/parts`,eg({body:t,...i},this._client))}}class Jv extends ag{constructor(){super(...arguments),this.parts=new Kv(this._client)}create(e,t){return this._client.post("/uploads",{body:e,...t})}cancel(e,t){return this._client.post(hg`/uploads/${e}/cancel`,t)}complete(e,t,i){return this._client.post(hg`/uploads/${e}/complete`,{body:t,...i})}}Jv.Parts=Kv;class ey extends ag{create(e,t,i){return this._client.post(hg`/vector_stores/${e}/file_batches`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}retrieve(e,t,i){const{vector_store_id:n}=t;return this._client.get(hg`/vector_stores/${n}/file_batches/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}cancel(e,t,i){const{vector_store_id:n}=t;return this._client.post(hg`/vector_stores/${n}/file_batches/${e}/cancel`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async createAndPoll(e,t,i){const n=await this.create(e,t);return await this.poll(e,n.id,i)}listFiles(e,t,i){const{vector_store_id:n,...r}=t;return this._client.getAPIList(hg`/vector_stores/${n}/file_batches/${e}/files`,Ym,{query:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async poll(e,t,i){var n;const r=$O([null==i?void 0:i.headers,{"X-Stainless-Poll-Helper":"true","X-Stainless-Custom-Poll-Interval":(null==(n=null==i?void 0:i.pollIntervalMs)?void 0:n.toString())??void 0}]);for(;;){const{data:n,response:s}=await this.retrieve(t,{vector_store_id:e},{...i,headers:r}).withResponse();switch(n.status){case"in_progress":let e=5e3;if(null==i?void 0:i.pollIntervalMs)e=i.pollIntervalMs;else{const t=s.headers.get("openai-poll-after-ms");if(t){const i=parseInt(t);isNaN(i)||(e=i)}}await Hf(e);break;case"failed":case"cancelled":case"completed":return n}}}async uploadAndPoll(e,{files:t,fileIds:i=[]},n){if(null==t||0==t.length)throw new Error("No `files` provided to process. If you've already uploaded files you should use `.createAndPoll()` instead");const r=(null==n?void 0:n.maxConcurrency)??5,s=Math.min(r,t.length),a=this._client,o=t.values(),l=[...i];const c=Array(s).fill(o).map(async function(e){for(let t of e){const e=await a.files.create({file:t,purpose:"assistants"},n);l.push(e.id)}});return await(async e=>{const t=await Promise.allSettled(e),i=t.filter(e=>"rejected"===e.status);if(i.length){for(const e of i);throw new Error(`${i.length} promise(s) failed - see the above errors`)}const n=[];for(const r of t)"fulfilled"===r.status&&n.push(r.value);return n})(c),await this.createAndPoll(e,{file_ids:l})}}class ty extends ag{create(e,t,i){return this._client.post(hg`/vector_stores/${e}/files`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}retrieve(e,t,i){const{vector_store_id:n}=t;return this._client.get(hg`/vector_stores/${n}/files/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}update(e,t,i){const{vector_store_id:n,...r}=t;return this._client.post(hg`/vector_stores/${n}/files/${e}`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t={},i){return this._client.getAPIList(hg`/vector_stores/${e}/files`,Ym,{query:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}delete(e,t,i){const{vector_store_id:n}=t;return this._client.delete(hg`/vector_stores/${n}/files/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async createAndPoll(e,t,i){const n=await this.create(e,t,i);return await this.poll(e,n.id,i)}async poll(e,t,i){var n;const r=$O([null==i?void 0:i.headers,{"X-Stainless-Poll-Helper":"true","X-Stainless-Custom-Poll-Interval":(null==(n=null==i?void 0:i.pollIntervalMs)?void 0:n.toString())??void 0}]);for(;;){const n=await this.retrieve(t,{vector_store_id:e},{...i,headers:r}).withResponse(),s=n.data;switch(s.status){case"in_progress":let e=5e3;if(null==i?void 0:i.pollIntervalMs)e=i.pollIntervalMs;else{const t=n.response.headers.get("openai-poll-after-ms");if(t){const i=parseInt(t);isNaN(i)||(e=i)}}await Hf(e);break;case"failed":case"completed":return s}}}async upload(e,t,i){const n=await this._client.files.create({file:t,purpose:"assistants"},i);return this.create(e,{file_id:n.id},i)}async uploadAndPoll(e,t,i){const n=await this.upload(e,t,i);return await this.poll(e,n.id,i)}content(e,t,i){const{vector_store_id:n}=t;return this._client.getAPIList(hg`/vector_stores/${n}/files/${e}/content`,Fm,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}class iy extends ag{constructor(){super(...arguments),this.files=new ty(this._client),this.fileBatches=new ey(this._client)}create(e,t){return this._client.post("/vector_stores",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}retrieve(e,t){return this._client.get(hg`/vector_stores/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}update(e,t,i){return this._client.post(hg`/vector_stores/${e}`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e={},t){return this._client.getAPIList("/vector_stores",Ym,{query:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}delete(e,t){return this._client.delete(hg`/vector_stores/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}search(e,t,i){return this._client.getAPIList(hg`/vector_stores/${e}/search`,Fm,{body:t,method:"post",...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}var ny,ry,sy,ay,oy,ly,cy;iy.Files=ty,iy.FileBatches=ey;class hy extends ag{constructor(){super(...arguments),ny.add(this)}async unwrap(e,t,i=this._client.webhookSecret,n=300){return await this.verifySignature(e,t,i,n),JSON.parse(e)}async verifySignature(e,t,i=this._client.webhookSecret,n=300){if("undefined"==typeof crypto||"function"!=typeof crypto.subtle.importKey||"function"!=typeof crypto.subtle.verify)throw new Error("Webhook signature verification is only supported when the `crypto` global is defined");Tf(this,ny,"m",ry).call(this,i);const r=$O([t]).values,s=Tf(this,ny,"m",sy).call(this,r,"webhook-signature"),a=Tf(this,ny,"m",sy).call(this,r,"webhook-timestamp"),o=Tf(this,ny,"m",sy).call(this,r,"webhook-id"),l=parseInt(a,10);if(isNaN(l))throw new Wf("Invalid webhook timestamp format");const c=Math.floor(Date.now()/1e3);if(c-l>n)throw new Wf("Webhook timestamp is too old");if(l>c+n)throw new Wf("Webhook timestamp is too new");const h=s.split(" ").map(e=>e.startsWith("v1,")?e.substring(3):e),u=i.startsWith("whsec_")?Buffer.from(i.replace("whsec_",""),"base64"):Buffer.from(i,"utf-8"),d=o?`${o}.${a}.${e}`:`${a}.${e}`,p=await crypto.subtle.importKey("raw",u,{name:"HMAC",hash:"SHA-256"},!1,["verify"]);for(const f of h)try{const e=Buffer.from(f,"base64");if(await crypto.subtle.verify("HMAC",p,e,(new TextEncoder).encode(d)))return}catch{continue}throw new Wf("The given webhook signature does not match the expected signature")}}ny=new WeakSet,ry=function(e){if("string"!=typeof e||0===e.length)throw new Error("The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function")},sy=function(e,t){if(!e)throw new Error("Headers are required");const i=e.get(t);if(null==i)throw new Error(`Missing required header: ${t}`);return i};let uy=class{constructor({baseURL:e=DO("OPENAI_BASE_URL"),apiKey:t=DO("OPENAI_API_KEY"),organization:i=DO("OPENAI_ORG_ID")??null,project:n=DO("OPENAI_PROJECT_ID")??null,webhookSecret:r=DO("OPENAI_WEBHOOK_SECRET")??null,...s}={}){if(ay.add(this),ly.set(this,void 0),this.completions=new fv(this),this.chat=new kO(this),this.embeddings=new vv(this),this.files=new _v(this),this.images=new Qv(this),this.audio=new RO(this),this.moderations=new jv(this),this.models=new Iv(this),this.fineTuning=new Av(this),this.graders=new Rv(this),this.vectorStores=new iy(this),this.webhooks=new hy(this),this.beta=new pv(this),this.batches=new QO(this),this.uploads=new Jv(this),this.responses=new Hv(this),this.evals=new wv(this),this.containers=new Ov(this),void 0===t)throw new Cf("The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).");const a={apiKey:t,organization:i,project:n,webhookSecret:r,...s,baseURL:e||"https://api.openai.com/v1"};if(!a.dangerouslyAllowBrowser&&"undefined"!=typeof window&&void 0!==window.document&&"undefined"!=typeof navigator)throw new Cf("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n");this.baseURL=a.baseURL,this.timeout=a.timeout??oy.DEFAULT_TIMEOUT,this.logger=a.logger??console;const o="warn";this.logLevel=o,this.logLevel=Cm(a.logLevel,"ClientOptions.logLevel",this)??Cm(DO("OPENAI_LOG"),"process.env['OPENAI_LOG']",this)??o,this.fetchOptions=a.fetchOptions,this.maxRetries=a.maxRetries??2,this.fetch=a.fetch??function(){if("undefined"!=typeof fetch)return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}(),Pf(this,ly,am),this._options=a,this.apiKey=t,this.organization=i,this.project=n,this.webhookSecret=r}withOptions(e){return new this.constructor({...this._options,baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,organization:this.organization,project:this.project,webhookSecret:this.webhookSecret,...e})}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:t}){}async authHeaders(e){return $O([{Authorization:`Bearer ${this.apiKey}`}])}stringifyQuery(e){return bm(e,{arrayFormat:"brackets"})}getUserAgent(){return`${this.constructor.name}/JS ${Kf}`}defaultIdempotencyKey(){return`stainless-node-retry-${$f()}`}makeStatusError(e,t,i,n){return Rf.generate(e,t,i,n)}buildURL(e,t,i){const n=!Tf(this,ay,"m",cy).call(this)&&i||this.baseURL,r=(e=>Vf.test(e))(e)?new URL(e):new URL(n+(n.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),s=this.defaultQuery();return function(e){if(!e)return!0;for(const t in e)return!1;return!0}(s)||(t={...s,...t}),"object"==typeof t&&t&&!Array.isArray(t)&&(r.search=this.stringifyQuery(t)),r.toString()}async prepareOptions(e){}async prepareRequest(e,{url:t,options:i}){}get(e,t){return this.methodRequest("get",e,t)}post(e,t){return this.methodRequest("post",e,t)}patch(e,t){return this.methodRequest("patch",e,t)}put(e,t){return this.methodRequest("put",e,t)}delete(e,t){return this.methodRequest("delete",e,t)}methodRequest(e,t,i){return this.request(Promise.resolve(i).then(i=>({method:e,path:t,...i})))}request(e,t=null){return new Bm(this,this.makeRequest(e,t,void 0))}async makeRequest(e,t,i){var n,r;const s=await e,a=s.maxRetries??this.maxRetries;null==t&&(t=a),await this.prepareOptions(s);const{req:o,url:l,timeout:c}=await this.buildRequest(s,{retryCount:a-t});await this.prepareRequest(o,{url:l,options:s});const h="log_"+(Math.random()*(1<<24)|0).toString(16).padStart(6,"0"),u=void 0===i?"":`, retryOf: ${i}`,d=Date.now();if(Mm(this).debug(`[${h}] sending request`,Nm({retryOfRequestLogID:i,method:s.method,url:l,options:s,headers:o.headers})),null==(n=s.signal)?void 0:n.aborted)throw new Qf;const p=new AbortController,f=await this.fetchWithTimeout(l,o,c,p).catch(Af),m=Date.now();if(f instanceof Error){const e=`retrying, ${t} attempts remaining`;if(null==(r=s.signal)?void 0:r.aborted)throw new Qf;const n=Ef(f)||/timed? ?out/i.test(String(f)+("cause"in f?String(f.cause):""));if(t)return Mm(this).info(`[${h}] connection ${n?"timed out":"failed"} - ${e}`),Mm(this).debug(`[${h}] connection ${n?"timed out":"failed"} (${e})`,Nm({retryOfRequestLogID:i,url:l,durationMs:m-d,message:f.message})),this.retryRequest(s,t,i??h);if(Mm(this).info(`[${h}] connection ${n?"timed out":"failed"} - error; no more retries left`),Mm(this).debug(`[${h}] connection ${n?"timed out":"failed"} (error; no more retries left)`,Nm({retryOfRequestLogID:i,url:l,durationMs:m-d,message:f.message})),n)throw new jf;throw new If({cause:f})}const g=[...f.headers.entries()].filter(([e])=>"x-request-id"===e).map(([e,t])=>", "+e+": "+JSON.stringify(t)).join(""),O=`[${h}${u}${g}] ${o.method} ${l} ${f.ok?"succeeded":"failed"} with status ${f.status} in ${m-d}ms`;if(!f.ok){const e=await this.shouldRetry(f);if(t&&e){const e=`retrying, ${t} attempts remaining`;return await async function(e){var t,i;if(null===e||"object"!=typeof e)return;if(e[Symbol.asyncIterator])return void(await(null==(i=(t=e[Symbol.asyncIterator]()).return)?void 0:i.call(t)));const n=e.getReader(),r=n.cancel();n.releaseLock(),await r}(f.body),Mm(this).info(`${O} - ${e}`),Mm(this).debug(`[${h}] response error (${e})`,Nm({retryOfRequestLogID:i,url:f.url,status:f.status,headers:f.headers,durationMs:m-d})),this.retryRequest(s,t,i??h,f.headers)}const n=e?"error; no more retries left":"error; not retryable";Mm(this).info(`${O} - ${n}`);const r=await f.text().catch(e=>Af(e).message),a=(e=>{try{return JSON.parse(e)}catch($M){return}})(r),o=a?void 0:r;Mm(this).debug(`[${h}] response error (${n})`,Nm({retryOfRequestLogID:i,url:f.url,status:f.status,headers:f.headers,message:o,durationMs:Date.now()-d}));throw this.makeStatusError(f.status,a,o,f.headers)}return Mm(this).info(O),Mm(this).debug(`[${h}] response start`,Nm({retryOfRequestLogID:i,url:f.url,status:f.status,headers:f.headers,durationMs:m-d})),{response:f,options:s,controller:p,requestLogID:h,retryOfRequestLogID:i,startTime:d}}getAPIList(e,t,i){return this.requestAPIList(t,{method:"get",path:e,...i})}requestAPIList(e,t){const i=this.makeRequest(t,null,void 0);return new Vm(this,i,e)}async fetchWithTimeout(e,t,i,n){const{signal:r,method:s,...a}=t||{};r&&r.addEventListener("abort",()=>n.abort());const o=setTimeout(()=>n.abort(),i),l=globalThis.ReadableStream&&a.body instanceof globalThis.ReadableStream||"object"==typeof a.body&&null!==a.body&&Symbol.asyncIterator in a.body,c={signal:n.signal,...l?{duplex:"half"}:{},method:"GET",...a};s&&(c.method=s.toUpperCase());try{return await this.fetch.call(void 0,e,c)}finally{clearTimeout(o)}}async shouldRetry(e){const t=e.headers.get("x-should-retry");return"true"===t||"false"!==t&&(408===e.status||(409===e.status||(429===e.status||e.status>=500)))}async retryRequest(e,t,i,n){let r;const s=null==n?void 0:n.get("retry-after-ms");if(s){const e=parseFloat(s);Number.isNaN(e)||(r=e)}const a=null==n?void 0:n.get("retry-after");if(a&&!r){const e=parseFloat(a);r=Number.isNaN(e)?Date.parse(a)-Date.now():1e3*e}if(!(r&&0<=r&&r<6e4)){const i=e.maxRetries??this.maxRetries;r=this.calculateDefaultRetryTimeoutMillis(t,i)}return await Hf(r),this.makeRequest(e,t-1,i)}calculateDefaultRetryTimeoutMillis(e,t){const i=t-e;return Math.min(.5*Math.pow(2,i),8)*(1-.25*Math.random())*1e3}async buildRequest(e,{retryCount:t=0}={}){const i={...e},{method:n,path:r,query:s,defaultBaseURL:a}=i,o=this.buildURL(r,s,a);"timeout"in i&&((e,t)=>{if("number"!=typeof t||!Number.isInteger(t))throw new Cf(`${e} must be an integer`);if(t<0)throw new Cf(`${e} must be a positive integer`)})("timeout",i.timeout),i.timeout=i.timeout??this.timeout;const{bodyHeaders:l,body:c}=this.buildBody({options:i});return{req:{method:n,headers:await this.buildHeaders({options:e,method:n,bodyHeaders:l,retryCount:t}),...i.signal&&{signal:i.signal},...globalThis.ReadableStream&&c instanceof globalThis.ReadableStream&&{duplex:"half"},...c&&{body:c},...this.fetchOptions??{},...i.fetchOptions??{}},url:o,timeout:i.timeout}}async buildHeaders({options:e,method:t,bodyHeaders:i,retryCount:n}){let r={};this.idempotencyHeader&&"get"!==t&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),r[this.idempotencyHeader]=e.idempotencyKey);const s=$O([r,{Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(n),...e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{},...im??(im=Jf()),"OpenAI-Organization":this.organization,"OpenAI-Project":this.project},await this.authHeaders(e),this._options.defaultHeaders,i,e.headers]);return this.validateHeaders(s),s.values}buildBody({options:{body:e,headers:t}}){if(!e)return{bodyHeaders:void 0,body:void 0};const i=$O([t]);return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||"string"==typeof e&&i.values.has("content-type")||e instanceof Blob||e instanceof FormData||e instanceof URLSearchParams||globalThis.ReadableStream&&e instanceof globalThis.ReadableStream?{bodyHeaders:void 0,body:e}:"object"==typeof e&&(Symbol.asyncIterator in e||Symbol.iterator in e&&"next"in e&&"function"==typeof e.next)?{bodyHeaders:void 0,body:rm(e)}:Tf(this,ly,"f").call(this,{body:e,headers:i})}};function dy(e,t){if(void 0===e.function)return;let i;if(null==t?void 0:t.partial)try{i=_o(e.function.arguments??"{}")}catch(r){return}else try{i=JSON.parse(e.function.arguments)}catch(r){throw new gp([`Function "${e.function.name}" arguments:`,"",e.function.arguments,"","are not valid JSON.",`Error: ${r.message}`].join("\n"))}const n={name:e.function.name,args:i,type:"tool_call"};return(null==t?void 0:t.returnId)&&(n.id=e.id),n}function py(e){if(void 0===e.id)throw new Error('All OpenAI tool calls must have an "id" field.');return{id:e.id,type:"function",function:{name:e.name,arguments:JSON.stringify(e.args)}}}function fy(e,t){var i,n;return{name:null==(i=e.function)?void 0:i.name,args:null==(n=e.function)?void 0:n.arguments,id:e.id,error:t,type:"invalid_tool_call"}}oy=uy,ly=new WeakMap,ay=new WeakSet,cy=function(){return"https://api.openai.com/v1"!==this.baseURL},uy.OpenAI=oy,uy.DEFAULT_TIMEOUT=6e5,uy.OpenAIError=Cf,uy.APIError=Rf,uy.APIConnectionError=If,uy.APIConnectionTimeoutError=jf,uy.APIUserAbortError=Qf,uy.NotFoundError=Zf,uy.ConflictError=Df,uy.RateLimitError=Uf,uy.BadRequestError=Mf,uy.AuthenticationError=Nf,uy.InternalServerError=qf,uy.PermissionDeniedError=Lf,uy.UnprocessableEntityError=zf,uy.InvalidWebhookSignatureError=Wf,uy.toFile=async function(e,t,i){if(Gm(),(e=>null!=e&&"object"==typeof e&&"string"==typeof e.name&&"number"==typeof e.lastModified&&rg(e))(e=await e))return e instanceof File?e:Hm([await e.arrayBuffer()],e.name);if((e=>null!=e&&"object"==typeof e&&"string"==typeof e.url&&"function"==typeof e.blob)(e)){const n=await e.blob();return t||(t=new URL(e.url).pathname.split(/[\\/]/).pop()),Hm(await sg(n),t,i)}const n=await sg(e);if(t||(t=Km(e)),!(null==i?void 0:i.type)){const e=n.find(e=>"object"==typeof e&&"type"in e&&e.type);"string"==typeof e&&(i={...i,type:e})}return Hm(n,t,i)},uy.Completions=fv,uy.Chat=kO,uy.Embeddings=vv,uy.Files=_v,uy.Images=Qv,uy.Audio=RO,uy.Moderations=jv,uy.Models=Iv,uy.FineTuning=Av,uy.Graders=Rv,uy.VectorStores=iy,uy.Webhooks=hy,uy.Beta=pv,uy.Batches=QO,uy.Uploads=Jv,uy.Responses=Hv,uy.Evals=wv,uy.Containers=Ov;class my extends vp{static lc_name(){return"JsonOutputToolsParser"}constructor(e){super(e),Object.defineProperty(this,"returnId",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","output_parsers","openai_tools"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this.returnId=(null==e?void 0:e.returnId)??this.returnId}_diff(){throw new Error("Not supported.")}async parse(){throw new Error("Not implemented.")}async parseResult(e){return await this.parsePartialResult(e,!1)}async parsePartialResult(e,t=!0){var i;const n=e[0].message;let r;if(zo(n)&&(null==(i=n.tool_calls)?void 0:i.length))r=n.tool_calls.map(e=>{const{id:t,...i}=e;return this.returnId?{id:t,...i}:i});else if(void 0!==n.additional_kwargs.tool_calls){r=JSON.parse(JSON.stringify(n.additional_kwargs.tool_calls)).map(e=>dy(e,{returnId:this.returnId,partial:t}))}if(!r)return[];const s=[];for(const a of r)if(void 0!==a){const e={type:a.name,args:a.args,id:a.id};s.push(e)}return s}}class gy extends my{static lc_name(){return"JsonOutputKeyToolsParser"}constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","output_parsers","openai_tools"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"returnId",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"keyName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"returnSingle",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"zodSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.keyName=e.keyName,this.returnSingle=e.returnSingle??this.returnSingle,this.zodSchema=e.zodSchema}async _validateResult(e){var t;if(void 0===this.zodSchema)return e;const i=await bh(this.zodSchema,e);if(i.success)return i.data;throw new gp(`Failed to parse. Text: "${JSON.stringify(e,null,2)}". Error: ${JSON.stringify(null==(t=i.error)?void 0:t.issues)}`,JSON.stringify(e,null,2))}async parsePartialResult(e){const t=(await super.parsePartialResult(e)).filter(e=>e.type===this.keyName);let i=t;if(t.length)return this.returnId||(i=t.map(e=>e.args)),this.returnSingle?i[0]:i}async parseResult(e){const t=(await super.parsePartialResult(e,!1)).filter(e=>e.type===this.keyName);let i=t;if(!t.length)return;if(this.returnId||(i=t.map(e=>e.args)),this.returnSingle)return this._validateResult(i[0]);const n=await Promise.all(i.map(e=>this._validateResult(e)));return n}}const Oy=Symbol("Let zodToJsonSchema decide on which parser to use"),vy={name:void 0,$refStrategy:"root",effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",nullableStrategy:"from-target",removeAdditionalStrategy:"passthrough",definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},yy=e=>"_def"in e?e._def:e;const by=e=>{const t=(e=>"string"==typeof e?{...vy,basePath:["#"],definitions:{},name:e}:{...vy,basePath:["#"],definitions:{},...e})(e),i=void 0!==t.name?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,currentPath:i,propertyPath:void 0,seenRefs:new Set,seen:new Map(Object.entries(t.definitions).map(([e,i])=>[yy(i),{def:yy(i),path:[...t.basePath,t.definitionPath,e],jsonSchema:void 0}]))}};function wy(e,t,i,n){(null==n?void 0:n.errorMessages)&&i&&(e.errorMessage={...e.errorMessage,[t]:i})}function _y(e,t,i,n,r){e[t]=i,wy(e,t,n,r)}function xy(e,t,i){const n=i??t.dateStrategy;if(Array.isArray(n))return{anyOf:n.map((i,n)=>xy(e,t,i))};switch(n){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return Sy(e,t)}}const Sy=(e,t)=>{const i={type:"integer",format:"unix-time"};if("openApi3"===t.target)return i;for(const n of e.checks)switch(n.kind){case"min":_y(i,"minimum",n.value,n.message,t);break;case"max":_y(i,"maximum",n.value,n.message,t)}return i};let ky;const Py=/^[cC][^\s-]{8,}$/,Ty=/^[0-9a-z]+$/,$y=/^[0-9A-HJKMNP-TV-Z]{26}$/,Ey=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,Ay=()=>(void 0===ky&&(ky=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ky),Cy=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ry=/^[a-zA-Z0-9_-]{21}$/;function Qy(e,t){const i={type:"string"};function n(e){return"escape"===t.patternStrategy?Iy(e):e}if(e.checks)for(const r of e.checks)switch(r.kind){case"min":_y(i,"minLength","number"==typeof i.minLength?Math.max(i.minLength,r.value):r.value,r.message,t);break;case"max":_y(i,"maxLength","number"==typeof i.maxLength?Math.min(i.maxLength,r.value):r.value,r.message,t);break;case"email":switch(t.emailStrategy){case"format:email":jy(i,"email",r.message,t);break;case"format:idn-email":jy(i,"idn-email",r.message,t);break;case"pattern:zod":My(i,Ey,r.message,t)}break;case"url":jy(i,"uri",r.message,t);break;case"uuid":jy(i,"uuid",r.message,t);break;case"regex":My(i,r.regex,r.message,t);break;case"cuid":My(i,Py,r.message,t);break;case"cuid2":My(i,Ty,r.message,t);break;case"startsWith":My(i,RegExp(`^${n(r.value)}`),r.message,t);break;case"endsWith":My(i,RegExp(`${n(r.value)}$`),r.message,t);break;case"datetime":jy(i,"date-time",r.message,t);break;case"date":jy(i,"date",r.message,t);break;case"time":jy(i,"time",r.message,t);break;case"duration":jy(i,"duration",r.message,t);break;case"length":_y(i,"minLength","number"==typeof i.minLength?Math.max(i.minLength,r.value):r.value,r.message,t),_y(i,"maxLength","number"==typeof i.maxLength?Math.min(i.maxLength,r.value):r.value,r.message,t);break;case"includes":My(i,RegExp(n(r.value)),r.message,t);break;case"ip":"v6"!==r.version&&jy(i,"ipv4",r.message,t),"v4"!==r.version&&jy(i,"ipv6",r.message,t);break;case"emoji":My(i,Ay,r.message,t);break;case"ulid":My(i,$y,r.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":jy(i,"binary",r.message,t);break;case"contentEncoding:base64":_y(i,"contentEncoding","base64",r.message,t);break;case"pattern:zod":My(i,Cy,r.message,t)}break;case"nanoid":My(i,Ry,r.message,t)}return i}const Iy=e=>Array.from(e).map(e=>/[a-zA-Z0-9]/.test(e)?e:`\\${e}`).join(""),jy=(e,t,i,n)=>{var r;e.format||(null==(r=e.anyOf)?void 0:r.some(e=>e.format))?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&n.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...i&&n.errorMessages&&{errorMessage:{format:i}}})):_y(e,"format",t,i,n)},My=(e,t,i,n)=>{var r;e.pattern||(null==(r=e.allOf)?void 0:r.some(e=>e.pattern))?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&n.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:Ny(t,n),...i&&n.errorMessages&&{errorMessage:{pattern:i}}})):_y(e,"pattern",Ny(t,n),i,n)},Ny=(e,t)=>{var i;const n="function"==typeof e?e():e;if(!t.applyRegexFlags||!n.flags)return n.source;const r=n.flags.includes("i"),s=n.flags.includes("m"),a=n.flags.includes("s"),o=r?n.source.toLowerCase():n.source;let l="",c=!1,h=!1,u=!1;for(let d=0;d<o.length;d++)if(c)l+=o[d],c=!1;else{if(r)if(h){if(o[d].match(/[a-z]/)){u?(l+=o[d],l+=`${o[d-2]}-${o[d]}`.toUpperCase(),u=!1):"-"===o[d+1]&&(null==(i=o[d+2])?void 0:i.match(/[a-z]/))?(l+=o[d],u=!0):l+=`${o[d]}${o[d].toUpperCase()}`;continue}}else if(o[d].match(/[a-z]/)){l+=`[${o[d]}${o[d].toUpperCase()}]`;continue}if(s){if("^"===o[d]){l+="(^|(?<=[\r\n]))";continue}if("$"===o[d]){l+="($|(?=[\r\n]))";continue}}a&&"."===o[d]?l+=h?`${o[d]}\r\n`:`[${o[d]}\r\n]`:(l+=o[d],"\\"===o[d]?c=!0:h&&"]"===o[d]?h=!1:h||"["!==o[d]||(h=!0))}try{new RegExp(l)}catch{return n.source}return l};function Ly(e,t){var i,n,r,s;if("openApi3"===t.target&&(null==(i=e.keyType)?void 0:i._def.typeName)===Bt.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((i,n)=>({...i,[n]:Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",n]})??{}}),{}),additionalProperties:!1};const a={type:"object",additionalProperties:Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??{}};if("openApi3"===t.target)return a;if((null==(n=e.keyType)?void 0:n._def.typeName)===Bt.ZodString&&(null==(r=e.keyType._def.checks)?void 0:r.length)){const i=Object.entries(Qy(e.keyType._def,t)).reduce((e,[t,i])=>"type"===t?e:{...e,[t]:i},{});return{...a,propertyNames:i}}return(null==(s=e.keyType)?void 0:s._def.typeName)===Bt.ZodEnum?{...a,propertyNames:{enum:e.keyType._def.values}}:a}const Zy={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};const Dy=(e,t)=>{const i=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,i)=>Uy(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${i}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return i.length?{anyOf:i}:void 0};function zy(e,t){return"strict"===t.removeAdditionalStrategy?"ZodNever"===e.catchall._def.typeName?"strict"!==e.unknownKeys:Uy(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??!0:"ZodNever"===e.catchall._def.typeName?"passthrough"===e.unknownKeys:Uy(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??!0}function Uy(e,t,i=!1){var n;const r=t.seen.get(e);if(t.override){const s=null==(n=t.override)?void 0:n.call(t,e,t,r,i);if(s!==Oy)return s}if(r&&!i){const e=qy(r,t);if(void 0!==e)return"$ref"in e&&t.seenRefs.add(e.$ref),e}const s={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,s);const a=By(e,e.typeName,t,i);return a&&Wy(e,t,a),s.jsonSchema=a,a}const qy=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"extract-to-root":const i=e.path.slice(t.basePath.length+1).join("_");return i!==t.name&&"duplicate-ref"===t.nameStrategy&&(t.definitions[i]=e.def),{$ref:[...t.basePath,t.definitionPath,i].join("/")};case"relative":return{$ref:Xy(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every((e,i)=>t.currentPath[i]===e)||"seen"===t.$refStrategy?{}:void 0}},Xy=(e,t)=>{let i=0;for(;i<e.length&&i<t.length&&e[i]===t[i];i++);return[(e.length-i).toString(),...t.slice(i)].join("/")},By=(e,t,i,n)=>{switch(t){case Bt.ZodString:return Qy(e,i);case Bt.ZodNumber:return function(e,t){const i={type:"number"};if(!e.checks)return i;for(const n of e.checks)switch(n.kind){case"int":i.type="integer",wy(i,"type",n.message,t);break;case"min":"jsonSchema7"===t.target?n.inclusive?_y(i,"minimum",n.value,n.message,t):_y(i,"exclusiveMinimum",n.value,n.message,t):(n.inclusive||(i.exclusiveMinimum=!0),_y(i,"minimum",n.value,n.message,t));break;case"max":"jsonSchema7"===t.target?n.inclusive?_y(i,"maximum",n.value,n.message,t):_y(i,"exclusiveMaximum",n.value,n.message,t):(n.inclusive||(i.exclusiveMaximum=!0),_y(i,"maximum",n.value,n.message,t));break;case"multipleOf":_y(i,"multipleOf",n.value,n.message,t)}return i}(e,i);case Bt.ZodObject:return function(e,t){const i={type:"object",...Object.entries(e.shape()).reduce((e,[i,n])=>{var r;if(void 0===n||void 0===n._def)return e;const s=[...t.currentPath,"properties",i],a=Uy(n._def,{...t,currentPath:s,propertyPath:s});if(void 0===a)return e;if(t.openaiStrictMode&&n.isOptional()&&!n.isNullable()&&void 0===(null==(r=n._def)?void 0:r.defaultValue))throw new Error(`Zod field at \`${s.join("/")}\` uses \`.optional()\` without \`.nullable()\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required`);return{properties:{...e.properties,[i]:a},required:n.isOptional()&&!t.openaiStrictMode?e.required:[...e.required,i]}},{properties:{},required:[]}),additionalProperties:zy(e,t)};return i.required.length||delete i.required,i}(e,i);case Bt.ZodBigInt:return function(e,t){const i={type:"integer",format:"int64"};if(!e.checks)return i;for(const n of e.checks)switch(n.kind){case"min":"jsonSchema7"===t.target?n.inclusive?_y(i,"minimum",n.value,n.message,t):_y(i,"exclusiveMinimum",n.value,n.message,t):(n.inclusive||(i.exclusiveMinimum=!0),_y(i,"minimum",n.value,n.message,t));break;case"max":"jsonSchema7"===t.target?n.inclusive?_y(i,"maximum",n.value,n.message,t):_y(i,"exclusiveMaximum",n.value,n.message,t):(n.inclusive||(i.exclusiveMaximum=!0),_y(i,"maximum",n.value,n.message,t));break;case"multipleOf":_y(i,"multipleOf",n.value,n.message,t)}return i}(e,i);case Bt.ZodBoolean:return{type:"boolean"};case Bt.ZodDate:return xy(e,i);case Bt.ZodUndefined:return{not:{}};case Bt.ZodNull:return function(e){return"openApi3"===e.target?{enum:["null"],nullable:!0}:{type:"null"}}(i);case Bt.ZodArray:return function(e,t){var i,n;const r={type:"array"};return(null==(n=null==(i=e.type)?void 0:i._def)?void 0:n.typeName)!==Bt.ZodAny&&(r.items=Uy(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&_y(r,"minItems",e.minLength.value,e.minLength.message,t),e.maxLength&&_y(r,"maxItems",e.maxLength.value,e.maxLength.message,t),e.exactLength&&(_y(r,"minItems",e.exactLength.value,e.exactLength.message,t),_y(r,"maxItems",e.exactLength.value,e.exactLength.message,t)),r}(e,i);case Bt.ZodUnion:case Bt.ZodDiscriminatedUnion:return function(e,t){if("openApi3"===t.target)return Dy(e,t);const i=e.options instanceof Map?Array.from(e.options.values()):e.options;if(i.every(e=>e._def.typeName in Zy&&(!e._def.checks||!e._def.checks.length))){const e=i.reduce((e,t)=>{const i=Zy[t._def.typeName];return i&&!e.includes(i)?[...e,i]:e},[]);return{type:e.length>1?e:e[0]}}if(i.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){const e=i.reduce((e,t)=>{const i=typeof t._def.value;switch(i){case"string":case"number":case"boolean":return[...e,i];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===i.length){const t=e.filter((e,t,i)=>i.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:i.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(i.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:i.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return Dy(e,t)}(e,i);case Bt.ZodIntersection:return function(e,t){const i=[Uy(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),Uy(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter(e=>!!e);let n="jsonSchema2019-09"===t.target?{unevaluatedProperties:!1}:void 0;const r=[];return i.forEach(e=>{if("type"in(t=e)&&"string"===t.type||!("allOf"in t)){let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){const{additionalProperties:i,...n}=e;t=n}else n=void 0;r.push(t)}else r.push(...e.allOf),void 0===e.unevaluatedProperties&&(n=void 0);var t}),r.length?{allOf:r,...n}:void 0}(e,i);case Bt.ZodTuple:return function(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,i)=>Uy(e._def,{...t,currentPath:[...t.currentPath,"items",`${i}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:Uy(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,i)=>Uy(e._def,{...t,currentPath:[...t.currentPath,"items",`${i}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])}}(e,i);case Bt.ZodRecord:return Ly(e,i);case Bt.ZodLiteral:return function(e,t){const i=typeof e.value;return"bigint"!==i&&"number"!==i&&"boolean"!==i&&"string"!==i?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===t.target?{type:"bigint"===i?"integer":i,enum:[e.value]}:{type:"bigint"===i?"integer":i,const:e.value}}(e,i);case Bt.ZodEnum:return function(e){return{type:"string",enum:[...e.values]}}(e);case Bt.ZodNativeEnum:return function(e){const t=e.values,i=Object.keys(e.values).filter(e=>"number"!=typeof t[t[e]]),n=i.map(e=>t[e]),r=Array.from(new Set(n.map(e=>typeof e)));return{type:1===r.length?"string"===r[0]?"string":"number":["string","number"],enum:n}}(e);case Bt.ZodNullable:return function(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===t.target||"property"===t.nullableStrategy?{type:Zy[e.innerType._def.typeName],nullable:!0}:{type:[Zy[e.innerType._def.typeName],"null"]};if("openApi3"===t.target){const i=Uy(e.innerType._def,{...t,currentPath:[...t.currentPath]});return i&&"$ref"in i?{allOf:[i],nullable:!0}:i&&{...i,nullable:!0}}const i=Uy(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return i&&{anyOf:[i,{type:"null"}]}}(e,i);case Bt.ZodOptional:return((e,t)=>{if(t.propertyPath&&t.currentPath.slice(0,t.propertyPath.length).toString()===t.propertyPath.toString())return Uy(e.innerType._def,{...t,currentPath:t.currentPath});const i=Uy(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return i?{anyOf:[{not:{}},i]}:{}})(e,i);case Bt.ZodMap:return function(e,t){return"record"===t.mapStrategy?Ly(e,t):{type:"array",maxItems:125,items:{type:"array",items:[Uy(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||{},Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||{}],minItems:2,maxItems:2}}}(e,i);case Bt.ZodSet:return function(e,t){const i={type:"array",uniqueItems:!0,items:Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&_y(i,"minItems",e.minSize.value,e.minSize.message,t),e.maxSize&&_y(i,"maxItems",e.maxSize.value,e.maxSize.message,t),i}(e,i);case Bt.ZodLazy:return Uy(e.getter()._def,i);case Bt.ZodPromise:return function(e,t){return Uy(e.type._def,t)}(e,i);case Bt.ZodNaN:case Bt.ZodNever:return{not:{}};case Bt.ZodEffects:return function(e,t,i){return"input"===t.effectStrategy?Uy(e.schema._def,t,i):{}}(e,i,n);case Bt.ZodAny:case Bt.ZodUnknown:return{};case Bt.ZodDefault:return function(e,t){return{...Uy(e.innerType._def,t),default:e.defaultValue()}}(e,i);case Bt.ZodBranded:return function(e,t){return Uy(e.type._def,t)}(e,i);case Bt.ZodReadonly:case Bt.ZodCatch:return((e,t)=>Uy(e.innerType._def,t))(e,i);case Bt.ZodPipeline:return((e,t)=>{if("input"===t.pipeStrategy)return Uy(e.in._def,t);if("output"===t.pipeStrategy)return Uy(e.out._def,t);const i=Uy(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]});return{allOf:[i,Uy(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",i?"1":"0"]})].filter(e=>void 0!==e)}})(e,i);case Bt.ZodFunction:case Bt.ZodVoid:case Bt.ZodSymbol:default:return}},Wy=(e,t,i)=>(e.description&&(i.description=e.description,t.markdownDescription&&(i.markdownDescription=e.description)),i);function Vy(e,t){return((e,t)=>{const i=by(t),n="string"==typeof t?t:"title"===(null==t?void 0:t.nameStrategy)||null==t?void 0:t.name,r=Uy(e._def,void 0===n?i:{...i,currentPath:[...i.basePath,i.definitionPath,n]},!1)??{},s="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==s&&(r.title=s);const a=(()=>{if(function(e){if(!e)return!0;for(const t in e)return!1;return!0}(i.definitions))return;const e={},t=new Set;for(let n=0;n<500;n++){const n=Object.entries(i.definitions).filter(([e])=>!t.has(e));if(0===n.length)break;for(const[r,s]of n)e[r]=Uy(yy(s),{...i,currentPath:[...i.basePath,i.definitionPath,r]},!0)??{},t.add(r)}return e})(),o=void 0===n?a?{...r,[i.definitionPath]:a}:r:"duplicate-ref"===i.nameStrategy?{...r,...a||i.seenRefs.size?{[i.definitionPath]:{...a,...i.seenRefs.size?{[n]:r}:void 0}}:void 0}:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,n].join("/"),[i.definitionPath]:{...a,[n]:r}};return"jsonSchema7"===i.target?o.$schema="http://json-schema.org/draft-07/schema#":"jsonSchema2019-09"===i.target&&(o.$schema="https://json-schema.org/draft/2019-09/schema#"),o})(e,{openaiStrictMode:!0,name:t.name,nameStrategy:"duplicate-ref",$refStrategy:"extract-to-root",nullableStrategy:"property"})}function Fy(e,t,i){return function(e,t){const i={...e};return Object.defineProperties(i,{$brand:{value:"auto-parseable-response-format",enumerable:!1},$parseRaw:{value:t,enumerable:!1}}),i}({type:"json_schema",json_schema:{...i,name:t,strict:!0,schema:Vy(e,{name:t})}},t=>e.parse(JSON.parse(t)))}function Yy(e,t){return e.lc_error_code=t,e.message=`${e.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${t}/\n`,e}function Gy(e){let t;return e.constructor.name===jf.name?(t=new Error(e.message),t.name="TimeoutError"):e.constructor.name===Qf.name?(t=new Error(e.message),t.name="AbortError"):t=400===e.status&&e.message.includes("tool_calls")?Yy(e,"INVALID_TOOL_RESULTS"):401===e.status?Yy(e,"MODEL_AUTHENTICATION"):429===e.status?Yy(e,"MODEL_RATE_LIMIT"):404===e.status?Yy(e,"MODEL_NOT_FOUND"):e,t}function Hy(e){return e?"any"===e||"required"===e?"required":"auto"===e?"auto":"none"===e?"none":"string"==typeof e?{type:"function",function:{name:e}}:e:void 0}function Ky(e,t,i){if(vh(e))return Fy(e,t,i);if(Oh(e))return function(e,t){const i={...e};return Object.defineProperties(i,{$brand:{value:"auto-parseable-response-format",enumerable:!1},$parseRaw:{value:t,enumerable:!1}}),i}({type:"json_schema",json_schema:{...i,name:t,strict:!0,schema:Cc(e,{cycles:"ref",reused:"ref",override(e){e.jsonSchema.title=t}})}},t=>Oc(e,JSON.parse(t)));throw new Error("Unsupported schema response format")}function Jy(e,t){var i;const n=[];for(const[r,s]of Object.entries(e.properties??{}))s.description&&t<2&&n.push(`// ${s.description}`),(null==(i=e.required)?void 0:i.includes(r))?n.push(`${r}: ${eb(s,t)},`):n.push(`${r}?: ${eb(s,t)},`);return n.map(e=>" ".repeat(t)+e).join("\n")}function eb(e,t){if(void 0!==(i=e).anyOf&&Array.isArray(i.anyOf))return e.anyOf.map(e=>eb(e,t)).join(" | ");var i;switch(e.type){case"string":return e.enum?e.enum.map(e=>`"${e}"`).join(" | "):"string";case"number":case"integer":return e.enum?e.enum.map(e=>`${e}`).join(" | "):"number";case"boolean":return"boolean";case"null":return"null";case"object":return["{",Jy(e,t+2),"}"].join("\n");case"array":return e.items?`${eb(e.items,t)}[]`:"any[]";default:return""}}function tb(e,t){let i;return i=Sp(e)?function(e){let t;return t=Sp(e)?{type:"function",function:kp(e)}:e,t}(e):e,"function"===i.type&&void 0!==(null==t?void 0:t.strict)&&(i.function.strict=t.strict),i}function ib(e){return"type"in e&&"function"!==e.type&&"custom"!==e.type}function nb(e){return"type"in e&&"custom"===e.type&&"custom"in e&&"object"==typeof e.custom&&null!==e.custom}function rb(e){if("custom_tool_call"===e.type)return{...e,type:"tool_call",call_id:e.id,id:e.call_id,name:e.name,isCustomTool:!0,args:{input:e.input}}}function sb(e){return{type:"custom",name:e.custom.name,description:e.custom.description,format:(()=>{if(e.custom.format)return"grammar"===e.custom.format.type?{type:"grammar",definition:e.custom.format.grammar.definition,syntax:e.custom.format.grammar.syntax}:"text"===e.custom.format.type?{type:"text"}:void 0})()}}function ab(e){var t,i,n,r;const s={...null!=(null==(t=null==e?void 0:e.input_tokens_details)?void 0:t.cached_tokens)&&{cache_read:null==(i=null==e?void 0:e.input_tokens_details)?void 0:i.cached_tokens}},a={...null!=(null==(n=null==e?void 0:e.output_tokens_details)?void 0:n.reasoning_tokens)&&{reasoning:null==(r=null==e?void 0:e.output_tokens_details)?void 0:r.reasoning_tokens}};return{input_tokens:(null==e?void 0:e.input_tokens)??0,output_tokens:(null==e?void 0:e.output_tokens)??0,total_tokens:(null==e?void 0:e.total_tokens)??0,input_token_details:s,output_token_details:a}}const ob="__openai_function_call_ids__";function lb(e){return!!e&&(!!/^o\d/.test(e??"")||!(!e.startsWith("gpt-5")||e.startsWith("gpt-5-chat")))}function cb(e){const t=e._getType();switch(t){case"system":return"system";case"ai":return"assistant";case"human":return"user";case"function":return"function";case"tool":return"tool";case"generic":if(!Xo.isInstance(e))throw new Error("Invalid generic chat message");return function(e){return"system"!==e.role&&"developer"!==e.role&&"assistant"!==e.role&&"user"!==e.role&&"function"!==e.role&&e.role,e.role}(e);default:throw new Error(`Unknown message type: ${t}`)}}const hb={providerName:"ChatOpenAI",fromStandardTextBlock:e=>({type:"text",text:e.text}),fromStandardImageBlock(e){var t,i;if("url"===e.source_type)return{type:"image_url",image_url:{url:e.url,...(null==(t=e.metadata)?void 0:t.detail)?{detail:e.metadata.detail}:{}}};if("base64"===e.source_type){return{type:"image_url",image_url:{url:`data:${e.mime_type??""};base64,${e.data}`,...(null==(i=e.metadata)?void 0:i.detail)?{detail:e.metadata.detail}:{}}}}throw new Error(`Image content blocks with source_type ${e.source_type} are not supported for ChatOpenAI`)},fromStandardAudioBlock(e){if("url"===e.source_type){const t=$o({dataUrl:e.url});if(!t)throw new Error(`URL audio blocks with source_type ${e.source_type} must be formatted as a data URL for ChatOpenAI`);const i=t.mime_type||e.mime_type||"";let n;try{n=To(i)}catch{throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`)}if("audio"!==n.type||"wav"!==n.subtype&&"mp3"!==n.subtype)throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`);return{type:"input_audio",input_audio:{format:n.subtype,data:t.data}}}if("base64"===e.source_type){let t;try{t=To(e.mime_type??"")}catch{throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`)}if("audio"!==t.type||"wav"!==t.subtype&&"mp3"!==t.subtype)throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`);return{type:"input_audio",input_audio:{format:t.subtype,data:e.data}}}throw new Error(`Audio content blocks with source_type ${e.source_type} are not supported for ChatOpenAI`)},fromStandardFileBlock(e){var t,i,n,r,s,a,o,l,c,h;if("url"===e.source_type){if(!$o({dataUrl:e.url}))throw new Error(`URL file blocks with source_type ${e.source_type} must be formatted as a data URL for ChatOpenAI`);return{type:"file",file:{file_data:e.url,...(null==(t=e.metadata)?void 0:t.filename)||(null==(i=e.metadata)?void 0:i.name)?{filename:(null==(n=e.metadata)?void 0:n.filename)||(null==(r=e.metadata)?void 0:r.name)}:{}}}}if("base64"===e.source_type)return{type:"file",file:{file_data:`data:${e.mime_type??""};base64,${e.data}`,...(null==(s=e.metadata)?void 0:s.filename)||(null==(a=e.metadata)?void 0:a.name)||(null==(o=e.metadata)?void 0:o.title)?{filename:(null==(l=e.metadata)?void 0:l.filename)||(null==(c=e.metadata)?void 0:c.name)||(null==(h=e.metadata)?void 0:h.title)}:{}}};if("id"===e.source_type)return{type:"file",file:{file_id:e.id}};throw new Error(`File content blocks with source_type ${e.source_type} are not supported for ChatOpenAI`)}};function ub(e,t){return e.flatMap(e=>{var i;let n=cb(e);"system"===n&&lb(t)&&(n="developer");const r={role:n,content:"string"==typeof e.content?e.content:e.content.map(e=>xo(e)?Eo(e,hb):e)};if(null!=e.name&&(r.name=e.name),null!=e.additional_kwargs.function_call&&(r.function_call=e.additional_kwargs.function_call,r.content=""),zo(e)&&(null==(i=e.tool_calls)?void 0:i.length)?(r.tool_calls=e.tool_calls.map(py),r.content=""):(null!=e.additional_kwargs.tool_calls&&(r.tool_calls=e.additional_kwargs.tool_calls),null!=e.tool_call_id&&(r.tool_call_id=e.tool_call_id)),e.additional_kwargs.audio&&"object"==typeof e.additional_kwargs.audio&&"id"in e.additional_kwargs.audio){return[r,{role:"assistant",audio:{id:e.additional_kwargs.audio.id}}]}return r})}class db extends pp{_llmType(){return"openai"}static lc_name(){return"ChatOpenAI"}get callKeys(){return[...super.callKeys,"options","function_call","functions","tools","tool_choice","promptIndex","response_format","seed","reasoning","reasoningEffort","service_tier"]}get lc_secrets(){return{apiKey:"OPENAI_API_KEY",organization:"OPENAI_ORGANIZATION"}}get lc_aliases(){return{apiKey:"openai_api_key",modelName:"model",reasoningEffort:"reasoning_effort"}}get lc_serializable_keys(){return["configuration","logprobs","topLogprobs","prefixMessages","supportsStrictToolCalling","modalities","audio","temperature","maxTokens","topP","frequencyPenalty","presencePenalty","n","logitBias","user","streaming","streamUsage","model","modelName","modelKwargs","stop","stopSequences","timeout","apiKey","cache","maxConcurrency","maxRetries","verbose","callbacks","tags","metadata","disableStreaming","zdrEnabled","reasoning","reasoningEffort","promptCacheKey","verbosity"]}getLsParams(e){const t=this.invocationParams(e);return{ls_provider:"openai",ls_model_name:this.model,ls_model_type:"chat",ls_temperature:t.temperature??void 0,ls_max_tokens:t.max_tokens??void 0,ls_stop:e.stop}}_identifyingParams(){return{model_name:this.model,...this.invocationParams(),...this.clientConfig}}identifyingParams(){return this._identifyingParams()}constructor(e){var t,i;super(e??{}),Object.defineProperty(this,"temperature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"frequencyPenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"presencePenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"n",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logitBias",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"model",{enumerable:!0,configurable:!0,writable:!0,value:"gpt-3.5-turbo"}),Object.defineProperty(this,"modelKwargs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stopSequences",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"user",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streaming",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"streamUsage",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"maxTokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logprobs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topLogprobs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"organization",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"__includeRawResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clientConfig",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"supportsStrictToolCalling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"modalities",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"reasoning",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"zdrEnabled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"service_tier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"promptCacheKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"verbosity",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"defaultOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this.apiKey=(null==e?void 0:e.apiKey)??(null==(t=null==e?void 0:e.configuration)?void 0:t.apiKey)??to("OPENAI_API_KEY"),this.organization=(null==(i=null==e?void 0:e.configuration)?void 0:i.organization)??to("OPENAI_ORGANIZATION"),this.model=(null==e?void 0:e.model)??(null==e?void 0:e.modelName)??this.model,this.modelKwargs=(null==e?void 0:e.modelKwargs)??{},this.timeout=null==e?void 0:e.timeout,this.temperature=(null==e?void 0:e.temperature)??this.temperature,this.topP=(null==e?void 0:e.topP)??this.topP,this.frequencyPenalty=(null==e?void 0:e.frequencyPenalty)??this.frequencyPenalty,this.presencePenalty=(null==e?void 0:e.presencePenalty)??this.presencePenalty,this.logprobs=null==e?void 0:e.logprobs,this.topLogprobs=null==e?void 0:e.topLogprobs,this.n=(null==e?void 0:e.n)??this.n,this.logitBias=null==e?void 0:e.logitBias,this.stop=(null==e?void 0:e.stopSequences)??(null==e?void 0:e.stop),this.stopSequences=this.stop,this.user=null==e?void 0:e.user,this.__includeRawResponse=null==e?void 0:e.__includeRawResponse,this.audio=null==e?void 0:e.audio,this.modalities=null==e?void 0:e.modalities,this.reasoning=(null==e?void 0:e.reasoning)??((null==e?void 0:e.reasoningEffort)?{effort:e.reasoningEffort}:void 0),this.maxTokens=(null==e?void 0:e.maxCompletionTokens)??(null==e?void 0:e.maxTokens),this.disableStreaming=!0===(null==e?void 0:e.disableStreaming),this.streaming=!0===(null==e?void 0:e.streaming),this.promptCacheKey=(null==e?void 0:e.promptCacheKey)??this.promptCacheKey,this.verbosity=(null==e?void 0:e.verbosity)??this.verbosity,!1===(null==e?void 0:e.streaming)&&(this.disableStreaming=!0),!0===this.disableStreaming&&(this.streaming=!1),this.streamUsage=(null==e?void 0:e.streamUsage)??this.streamUsage,this.disableStreaming&&(this.streamUsage=!1),this.clientConfig={apiKey:this.apiKey,organization:this.organization,dangerouslyAllowBrowser:!0,...null==e?void 0:e.configuration},void 0!==(null==e?void 0:e.supportsStrictToolCalling)&&(this.supportsStrictToolCalling=e.supportsStrictToolCalling),void 0!==(null==e?void 0:e.service_tier)&&(this.service_tier=e.service_tier),this.zdrEnabled=(null==e?void 0:e.zdrEnabled)??!1}_getReasoningParams(e){if(!lb(this.model))return;let t;return void 0!==this.reasoning&&(t={...t,...this.reasoning}),void 0!==(null==e?void 0:e.reasoning)&&(t={...t,...e.reasoning}),t}_getResponseFormat(e){return e&&"json_schema"===e.type&&e.json_schema.schema&&yh(e.json_schema.schema)?Ky(e.json_schema.schema,e.json_schema.name,{description:e.json_schema.description}):e}_combineCallOptions(e){return{...this.defaultOptions,...e??{}}}_getClientOptions(e){if(!this.client){const e=function(e){const{azureOpenAIApiDeploymentName:t,azureOpenAIApiInstanceName:i,azureOpenAIApiKey:n,azureOpenAIBasePath:r,baseURL:s,azureADTokenProvider:a,azureOpenAIEndpoint:o}=e;if((n||a)&&r&&t)return`${r}/${t}`;if((n||a)&&o&&t)return`${o}/openai/deployments/${t}`;if(n||a){if(!i)throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");if(!t)throw new Error("azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey");return`https://${i}.openai.azure.com/openai/deployments/${t}`}return s}({baseURL:this.clientConfig.baseURL}),t={...this.clientConfig,baseURL:e,timeout:this.timeout,maxRetries:0};t.baseURL||delete t.baseURL,this.client=new uy(t)}return{...this.clientConfig,...e}}_convertChatOpenAIToolToCompletionsTool(e,t){return function(e){return"object"==typeof e&&null!==e&&"metadata"in e&&"object"==typeof e.metadata&&null!==e.metadata&&"customTool"in e.metadata&&"object"==typeof e.metadata.customTool&&null!==e.metadata.customTool}(e)?function(e){return{type:"custom",custom:{name:e.name,description:e.description,format:(()=>{if(e.format)return"grammar"===e.format.type?{type:"grammar",grammar:{definition:e.format.definition,syntax:e.format.syntax}}:"text"===e.format.type?{type:"text"}:void 0})()}}}(e.metadata.customTool):lp(e)?void 0!==(null==t?void 0:t.strict)?{...e,function:{...e.function,strict:t.strict}}:e:tb(e,t)}bindTools(e,t){let i;return void 0!==(null==t?void 0:t.strict)?i=t.strict:void 0!==this.supportsStrictToolCalling&&(i=this.supportsStrictToolCalling),this.withConfig({tools:e.map(e=>ib(e)?e:this._convertChatOpenAIToolToCompletionsTool(e,{strict:i})),...t})}async stream(e,t){return super.stream(e,this._combineCallOptions(t))}async invoke(e,t){return super.invoke(e,this._combineCallOptions(t))}_combineLLMOutput(...e){return e.reduce((e,t)=>(t&&t.tokenUsage&&(e.tokenUsage.completionTokens+=t.tokenUsage.completionTokens??0,e.tokenUsage.promptTokens+=t.tokenUsage.promptTokens??0,e.tokenUsage.totalTokens+=t.tokenUsage.totalTokens??0),e),{tokenUsage:{completionTokens:0,promptTokens:0,totalTokens:0}})}async getNumTokensFromMessages(e){let t=0,i=0,n=0;"gpt-3.5-turbo-0301"===this.model?(i=4,n=-1):(i=3,n=1);const r=await Promise.all(e.map(async e=>{var r,s,a,o,l,c;const h=await this.getNumTokens(e.content),u=await this.getNumTokens(cb(e)),d=void 0!==e.name?n+await this.getNumTokens(e.name):0;let p=h+i+u+d;const f=e;if("function"===f._getType()&&(p-=2),(null==(r=f.additional_kwargs)?void 0:r.function_call)&&(p+=3),(null==(s=null==f?void 0:f.additional_kwargs.function_call)?void 0:s.name)&&(p+=await this.getNumTokens(null==(a=f.additional_kwargs.function_call)?void 0:a.name)),null==(o=f.additional_kwargs.function_call)?void 0:o.arguments)try{p+=await this.getNumTokens(JSON.stringify(JSON.parse(null==(l=f.additional_kwargs.function_call)?void 0:l.arguments)))}catch(m){p+=await this.getNumTokens(null==(c=f.additional_kwargs.function_call)?void 0:c.arguments)}return t+=p,p}));return t+=3,{totalCount:t,countPerMessage:r}}async _getNumTokensFromGenerations(e){return(await Promise.all(e.map(async e=>{var t;return(null==(t=e.message.additional_kwargs)?void 0:t.function_call)?(await this.getNumTokensFromMessages([e.message])).countPerMessage[0]:await this.getNumTokens(e.message.content)}))).reduce((e,t)=>e+t,0)}async _getEstimatedTokenCountFromPrompt(e,t,i){let n=(await this.getNumTokensFromMessages(e)).totalCount;if(t&&"auto"!==i){const e=function(e){const t=["namespace functions {",""];for(const i of e)i.description&&t.push(`// ${i.description}`),Object.keys(i.parameters.properties??{}).length>0?(t.push(`type ${i.name} = (_: {`),t.push(Jy(i.parameters,0)),t.push("}) => any;")):t.push(`type ${i.name} = () => any;`),t.push("");return t.push("} // namespace functions"),t.join("\n")}(t);n+=await this.getNumTokens(e),n+=9}return t&&e.find(e=>"system"===e._getType())&&(n-=4),"none"===i?n+=1:"object"==typeof i&&(n+=await this.getNumTokens(i.name)+4),n}_getStructuredOutputMethod(e){const t={...e};if(this.model.startsWith("gpt-3")||this.model.startsWith("gpt-4-")||"gpt-4"===this.model)t.method;else if(void 0===(null==t?void 0:t.method))return"jsonSchema";return t.method}withStructuredOutput(e,t){let i,n,r,s;var a;let o,l;if(void 0!==(a=e)&&"object"==typeof a.schema?(i=e.schema,n=e.name,r=e.method,s=e.includeRaw):(i=e,n=null==t?void 0:t.name,r=null==t?void 0:t.method,s=null==t?void 0:t.includeRaw),void 0!==(null==t?void 0:t.strict)&&"jsonMode"===r)throw new Error("Argument `strict` is only supported for `method` = 'function_calling'");if(r=this._getStructuredOutputMethod({...t,method:r}),"jsonMode"===r){l=yh(i)?yp.fromZodSchema(i):new bp;const e=Th(i);o=this.withConfig({response_format:{type:"json_object"},ls_structured_output_format:{kwargs:{method:"json_mode"},schema:{title:n??"extract",...e}}})}else if("jsonSchema"===r){const e={name:n??"extract",description:_h(i),schema:i,strict:null==t?void 0:t.strict},r=Th(e.schema);if(o=this.withConfig({response_format:{type:"json_schema",json_schema:e},ls_structured_output_format:{kwargs:{method:"json_schema"},schema:{title:e.name,description:e.description,...r}}}),yh(i)){const e=yp.fromZodSchema(i);l=Bh.from(t=>"parsed"in t.additional_kwargs?t.additional_kwargs.parsed:e)}else l=new bp}else{let e=n??"extract";if(yh(i)){const n=Th(i);o=this.withConfig({tools:[{type:"function",function:{name:e,description:n.description,parameters:n}}],tool_choice:{type:"function",function:{name:e}},ls_structured_output_format:{kwargs:{method:"function_calling"},schema:{title:e,...n}},...void 0!==(null==t?void 0:t.strict)?{strict:t.strict}:{}}),l=new gy({returnSingle:!0,keyName:e,zodSchema:i})}else{let n;"string"==typeof i.name&&"object"==typeof i.parameters&&null!=i.parameters?(n=i,e=i.name):(e=i.title??e,n={name:e,description:i.description??"",parameters:i});const r=Th(i);o=this.withConfig({tools:[{type:"function",function:n}],tool_choice:{type:"function",function:{name:e}},ls_structured_output_format:{kwargs:{method:"function_calling"},schema:{title:e,...r}},...void 0!==(null==t?void 0:t.strict)?{strict:t.strict}:{}}),l=new gy({returnSingle:!0,keyName:e})}}if(!s)return o.pipe(l);const c=up.assign({parsed:(e,t)=>l.invoke(e.raw,t)}),h=up.assign({parsed:()=>null}),u=c.withFallbacks({fallbacks:[h]});return Uh.from([{raw:o},u])}}class pb extends db{invocationParams(e){var t;let i;void 0!==(null==e?void 0:e.strict)?i=e.strict:void 0!==this.supportsStrictToolCalling&&(i=this.supportsStrictToolCalling);const n={model:this.model,temperature:this.temperature,top_p:this.topP,user:this.user,stream:this.streaming,previous_response_id:null==e?void 0:e.previous_response_id,truncation:null==e?void 0:e.truncation,include:null==e?void 0:e.include,tools:(null==(t=null==e?void 0:e.tools)?void 0:t.length)?this._reduceChatOpenAITools(e.tools,{stream:this.streaming,strict:i}):void 0,tool_choice:(r=null==e?void 0:e.tool_choice,null!=r&&"object"==typeof r&&"type"in r&&"function"!==r.type?null==e?void 0:e.tool_choice:(()=>{const t=Hy(null==e?void 0:e.tool_choice);if("object"==typeof t&&"type"in t){if("function"===t.type)return{type:"function",name:t.function.name};if("allowed_tools"===t.type)return{type:"allowed_tools",mode:t.allowed_tools.mode,tools:t.allowed_tools.tools};if("custom"===t.type)return{type:"custom",name:t.custom.name}}})()),text:(()=>{if(null==e?void 0:e.text)return e.text;const t=this._getResponseFormat(null==e?void 0:e.response_format);return"json_schema"===(null==t?void 0:t.type)?null!=t.json_schema.schema?{format:{type:"json_schema",schema:t.json_schema.schema,description:t.json_schema.description,name:t.json_schema.name,strict:t.json_schema.strict},verbosity:null==e?void 0:e.verbosity}:void 0:{format:t,verbosity:null==e?void 0:e.verbosity}})(),parallel_tool_calls:null==e?void 0:e.parallel_tool_calls,max_output_tokens:-1===this.maxTokens?void 0:this.maxTokens,prompt_cache_key:(null==e?void 0:e.promptCacheKey)??this.promptCacheKey,...this.zdrEnabled?{store:!1}:{},...this.modelKwargs};var r;const s=this._getReasoningParams(e);return void 0!==s&&(n.reasoning=s),n}async _generate(e,t){var i;const n=this.invocationParams(t);if(n.stream){const n=this._streamResponseChunks(e,t);let r;for await(const e of n)e.message.response_metadata={...e.generationInfo,...e.message.response_metadata},r=(null==r?void 0:r.concat(e))??e;return{generations:r?[r]:[],llmOutput:{estimatedTokenUsage:null==(i=null==r?void 0:r.message)?void 0:i.usage_metadata}}}{const i=this._convertMessagesToResponsesParams(e),r=await this.completionWithRetry({input:i,...n,stream:!1},{signal:null==t?void 0:t.signal,...null==t?void 0:t.options});return{generations:[{text:r.output_text,message:this._convertResponsesMessageToBaseMessage(r)}],llmOutput:{id:r.id,estimatedTokenUsage:r.usage?{promptTokens:r.usage.input_tokens,completionTokens:r.usage.output_tokens,totalTokens:r.usage.total_tokens}:void 0}}}}async*_streamResponseChunks(e,t,i){const n=await this.completionWithRetry({...this.invocationParams(t),input:this._convertMessagesToResponsesParams(e),stream:!0},t);for await(const r of n){const e=this._convertResponsesDeltaToBaseMessageChunk(r);null!=e&&(yield e,await(null==i?void 0:i.handleLLMNewToken(e.text||"",{prompt:t.promptIndex??0,completion:0},void 0,void 0,void 0,{chunk:e})))}}async completionWithRetry(e,t){return this.caller.call(async()=>{var i,n;const r=this._getClientOptions(t);try{return"json_schema"!==(null==(n=null==(i=e.text)?void 0:i.format)?void 0:n.type)||e.stream?await this.client.responses.create(e,r):await this.client.responses.parse(e,r)}catch(s){throw Gy(s)}})}_convertResponsesMessageToBaseMessage(e){if(e.error){const t=new Error(e.error.message);throw t.name=e.error.code,t}let t;const i=[],n=[],r=[],s={model:e.model,created_at:e.created_at,id:e.id,incomplete_details:e.incomplete_details,metadata:e.metadata,object:e.object,status:e.status,user:e.user,service_tier:e.service_tier,model_name:e.model},a={};for(const l of e.output)if("message"===l.type)t=l.id,i.push(...l.content.flatMap(e=>"output_text"===e.type?("parsed"in e&&null!=e.parsed&&(a.parsed=e.parsed),{type:"text",text:e.text,annotations:e.annotations}):"refusal"===e.type?(a.refusal=e.refusal,[]):e));else if("function_call"===l.type){const e={function:{name:l.name,arguments:l.arguments},id:l.call_id};try{n.push(dy(e,{returnId:!0}))}catch(o){let t;"object"==typeof o&&null!=o&&"message"in o&&"string"==typeof o.message&&(t=o.message),r.push(fy(e,t))}a[ob]??(a[ob]={}),l.id&&(a[ob][l.call_id]=l.id)}else if("reasoning"===l.type)a.reasoning=l;else if("custom_tool_call"===l.type){const e=rb(l);e?n.push(e):r.push(fy(l,"Malformed custom tool call"))}else a.tool_outputs??(a.tool_outputs=[]),a.tool_outputs.push(l);return new Do({id:t,content:i,tool_calls:n,invalid_tool_calls:r,usage_metadata:ab(e.usage),additional_kwargs:a,response_metadata:s})}_convertResponsesDeltaToBaseMessageChunk(e){var t,i;const n=[];let r,s={};const a=[],o={},l={};let c;if("response.output_text.delta"===e.type)n.push({type:"text",text:e.delta,index:e.content_index});else if("response.output_text.annotation.added"===e.type)n.push({type:"text",text:"",annotations:[e.annotation],index:e.content_index});else if("response.output_item.added"===e.type&&"message"===e.item.type)c=e.item.id;else if("response.output_item.added"===e.type&&"function_call"===e.item.type)a.push({type:"tool_call_chunk",name:e.item.name,args:e.item.arguments,id:e.item.call_id,index:e.output_index}),l[ob]={[e.item.call_id]:e.item.id};else if("response.output_item.done"===e.type&&["web_search_call","file_search_call","computer_call","code_interpreter_call","mcp_call","mcp_list_tools","mcp_approval_request","image_generation_call","custom_tool_call"].includes(e.item.type))l.tool_outputs=[e.item];else if("response.created"===e.type)o.id=e.response.id,o.model_name=e.response.model,o.model=e.response.model;else if("response.completed"===e.type){const n=this._convertResponsesMessageToBaseMessage(e.response);r=ab(e.response.usage),"json_schema"===(null==(i=null==(t=e.response.text)?void 0:t.format)?void 0:i.type)&&(l.parsed??(l.parsed=JSON.parse(n.text)));for(const[t,i]of Object.entries(e.response))"id"!==t&&(o[t]=i)}else if("response.function_call_arguments.delta"===e.type||"response.custom_tool_call_input.delta"===e.type)a.push({type:"tool_call_chunk",args:e.delta,index:e.output_index});else if("response.web_search_call.completed"===e.type||"response.file_search_call.completed"===e.type)s={tool_outputs:{id:e.item_id,type:e.type.replace("response.","").replace(".completed",""),status:"completed"}};else if("response.refusal.done"===e.type)l.refusal=e.refusal;else if("response.output_item.added"===e.type&&"item"in e&&"reasoning"===e.item.type){const t=e.item.summary?e.item.summary.map((e,t)=>({...e,index:t})):void 0;l.reasoning={id:e.item.id,type:e.item.type,...t?{summary:t}:{}}}else if("response.reasoning_summary_part.added"===e.type)l.reasoning={type:"reasoning",summary:[{...e.part,index:e.summary_index}]};else{if("response.reasoning_summary_text.delta"!==e.type)return e.type,null;l.reasoning={type:"reasoning",summary:[{text:e.delta,type:"summary_text",index:e.summary_index}]}}return new ql({text:n.map(e=>e.text).join(""),message:new qo({id:c,content:n,tool_call_chunks:a,usage_metadata:r,additional_kwargs:l,response_metadata:o}),generationInfo:s})}_convertMessagesToResponsesParams(e){return e.flatMap(e=>{var t,i,n,r;const s=e.additional_kwargs;let a=cb(e);if("system"===a&&lb(this.model)&&(a="developer"),"function"===a)throw new Error("Function messages are not supported in Responses API");if("tool"===a){const n=e;if("computer_call_output"===(null==s?void 0:s.type)){return{type:"computer_call_output",output:(()=>{if("string"==typeof n.content)return{type:"computer_screenshot",image_url:n.content};if(Array.isArray(n.content)){const e=n.content.find(e=>"computer_screenshot"===e.type);if(e)return e;const t=n.content.find(e=>"image_url"===e.type);if(t)return{type:"computer_screenshot",image_url:"string"==typeof t.image_url?t.image_url:t.image_url.url}}throw new Error("Invalid computer call output")})(),call_id:n.tool_call_id}}return(null==(t=n.metadata)?void 0:t.customTool)?{type:"custom_tool_call_output",call_id:n.tool_call_id,output:n.content}:{type:"function_call_output",call_id:n.tool_call_id,id:(null==(i=n.id)?void 0:i.startsWith("fc_"))?n.id:void 0,output:"string"!=typeof n.content?JSON.stringify(n.content):n.content}}if("assistant"===a){if(!this.zdrEnabled&&null!=e.response_metadata.output&&Array.isArray(e.response_metadata.output)&&e.response_metadata.output.length>0&&e.response_metadata.output.every(e=>"type"in e))return e.response_metadata.output;const t=[];if((null==s?void 0:s.reasoning)&&!this.zdrEnabled){const e=this._convertReasoningSummary(s.reasoning);t.push(e)}let{content:i}=e;(null==s?void 0:s.refusal)&&("string"==typeof i&&(i=[{type:"output_text",text:i,annotations:[]}]),i=[...i,{type:"refusal",refusal:s.refusal}]),("string"==typeof i||i.length>0)&&t.push({type:"message",role:"assistant",...e.id&&!this.zdrEnabled&&e.id.startsWith("msg_")?{id:e.id}:{},content:"string"==typeof i?i:i.flatMap(e=>"text"===e.type?{type:"output_text",text:e.text,annotations:e.annotations??[]}:"output_text"===e.type||"refusal"===e.type?e:[])});const a=null==s?void 0:s[ob];zo(e)&&(null==(n=e.tool_calls)?void 0:n.length)?t.push(...e.tool_calls.map(e=>function(e){return"tool_call"===e.type&&"isCustomTool"in e&&!0===e.isCustomTool}(e)?{type:"custom_tool_call",id:e.call_id,call_id:e.id??"",input:e.args.input,name:e.name}:{type:"function_call",name:e.name,arguments:JSON.stringify(e.args),call_id:e.id,...this.zdrEnabled?{id:null==a?void 0:a[e.id]}:{}})):(null==s?void 0:s.tool_calls)&&t.push(...s.tool_calls.map(e=>({type:"function_call",name:e.function.name,call_id:e.id,arguments:e.function.arguments,...this.zdrEnabled?{id:null==a?void 0:a[e.id]}:{}})));const o=(null==(r=e.response_metadata.output)?void 0:r.length)?e.response_metadata.output:s.tool_outputs,l=["computer_call","mcp_call","code_interpreter_call","image_generation_call"];if(null!=o){const e=null==o?void 0:o.filter(e=>l.includes(e.type));e.length>0&&t.push(...e)}return t}if("user"===a||"system"===a||"developer"===a){if("string"==typeof e.content)return{type:"message",role:a,content:e.content};const t=[],i=e.content.flatMap(e=>("mcp_approval_response"===e.type&&t.push({type:"mcp_approval_response",approval_request_id:e.approval_request_id,approve:e.approve}),xo(e)?Eo(e,hb):"text"===e.type?{type:"input_text",text:e.text}:"image_url"===e.type?{type:"input_image",image_url:"string"==typeof e.image_url?e.image_url:e.image_url.url,detail:"string"==typeof e.image_url?"auto":e.image_url.detail}:"input_text"===e.type||"input_image"===e.type||"input_file"===e.type?e:[]));return i.length>0&&t.push({type:"message",role:a,content:i}),t}return[]})}_convertReasoningSummary(e){const t=(e.summary.length>1?e.summary.reduce((e,t)=>{const i=e.at(-1);return i.index===t.index?i.text+=t.text:e.push(t),e},[{...e.summary[0]}]):e.summary).map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>"index"!==e)));return{...e,summary:t}}_reduceChatOpenAITools(e,t){const i=[];for(const n of e)ib(n)?("image_generation"===n.type&&(null==t?void 0:t.stream)&&(n.partial_images=1),i.push(n)):lp(n)?i.push({type:"function",name:n.function.name,parameters:n.function.parameters,description:n.function.description,strict:(null==t?void 0:t.strict)??null}):nb(n)&&i.push(sb(n));return i}}class fb extends db{invocationParams(e,t){var i;let n;void 0!==(null==e?void 0:e.strict)?n=e.strict:void 0!==this.supportsStrictToolCalling&&(n=this.supportsStrictToolCalling);let r={};void 0!==(null==e?void 0:e.stream_options)?r={stream_options:e.stream_options}:this.streamUsage&&(this.streaming||(null==t?void 0:t.streaming))&&(r={stream_options:{include_usage:!0}});const s={model:this.model,temperature:this.temperature,top_p:this.topP,frequency_penalty:this.frequencyPenalty,presence_penalty:this.presencePenalty,logprobs:this.logprobs,top_logprobs:this.topLogprobs,n:this.n,logit_bias:this.logitBias,stop:(null==e?void 0:e.stop)??this.stopSequences,user:this.user,stream:this.streaming,functions:null==e?void 0:e.functions,function_call:null==e?void 0:e.function_call,tools:(null==(i=null==e?void 0:e.tools)?void 0:i.length)?e.tools.map(e=>this._convertChatOpenAIToolToCompletionsTool(e,{strict:n})):void 0,tool_choice:Hy(null==e?void 0:e.tool_choice),response_format:this._getResponseFormat(null==e?void 0:e.response_format),seed:null==e?void 0:e.seed,...r,parallel_tool_calls:null==e?void 0:e.parallel_tool_calls,...this.audio||(null==e?void 0:e.audio)?{audio:this.audio||(null==e?void 0:e.audio)}:{},...this.modalities||(null==e?void 0:e.modalities)?{modalities:this.modalities||(null==e?void 0:e.modalities)}:{},...this.modelKwargs,prompt_cache_key:(null==e?void 0:e.promptCacheKey)??this.promptCacheKey,verbosity:(null==e?void 0:e.verbosity)??this.verbosity};void 0!==(null==e?void 0:e.prediction)&&(s.prediction=e.prediction),void 0!==this.service_tier&&(s.service_tier=this.service_tier),void 0!==(null==e?void 0:e.service_tier)&&(s.service_tier=e.service_tier);const a=this._getReasoningParams(e);return void 0!==a&&void 0!==a.effort&&(s.reasoning_effort=a.effort),lb(s.model)?s.max_completion_tokens=-1===this.maxTokens?void 0:this.maxTokens:s.max_tokens=-1===this.maxTokens?void 0:this.maxTokens,s}async _generate(e,t,i){var n,r;const s={},a=this.invocationParams(t),o=ub(e,this.model);if(a.stream){const r=this._streamResponseChunks(e,t,i),a={};for await(const e of r){e.message.response_metadata={...e.generationInfo,...e.message.response_metadata};const t=(null==(n=e.generationInfo)?void 0:n.completion)??0;void 0===a[t]?a[t]=e:a[t]=a[t].concat(e)}const o=Object.entries(a).sort(([e],[t])=>parseInt(e,10)-parseInt(t,10)).map(([e,t])=>t),{functions:l,function_call:c}=this.invocationParams(t),h=await this._getEstimatedTokenCountFromPrompt(e,l,c),u=await this._getNumTokensFromGenerations(o);return s.input_tokens=h,s.output_tokens=u,s.total_tokens=h+u,{generations:o,llmOutput:{estimatedTokenUsage:{promptTokens:s.input_tokens,completionTokens:s.output_tokens,totalTokens:s.total_tokens}}}}{const e=await this.completionWithRetry({...a,stream:!1,messages:o},{signal:null==t?void 0:t.signal,...null==t?void 0:t.options}),{completion_tokens:i,prompt_tokens:n,total_tokens:l,prompt_tokens_details:c,completion_tokens_details:h}=(null==e?void 0:e.usage)??{};i&&(s.output_tokens=(s.output_tokens??0)+i),n&&(s.input_tokens=(s.input_tokens??0)+n),l&&(s.total_tokens=(s.total_tokens??0)+l),null===(null==c?void 0:c.audio_tokens)&&null===(null==c?void 0:c.cached_tokens)||(s.input_token_details={...null!==(null==c?void 0:c.audio_tokens)&&{audio:null==c?void 0:c.audio_tokens},...null!==(null==c?void 0:c.cached_tokens)&&{cache_read:null==c?void 0:c.cached_tokens}}),null===(null==h?void 0:h.audio_tokens)&&null===(null==h?void 0:h.reasoning_tokens)||(s.output_token_details={...null!==(null==h?void 0:h.audio_tokens)&&{audio:null==h?void 0:h.audio_tokens},...null!==(null==h?void 0:h.reasoning_tokens)&&{reasoning:null==h?void 0:h.reasoning_tokens}});const u=[];for(const t of(null==e?void 0:e.choices)??[]){const i={text:(null==(r=t.message)?void 0:r.content)??"",message:this._convertCompletionsMessageToBaseMessage(t.message??{role:"assistant"},e)};i.generationInfo={...t.finish_reason?{finish_reason:t.finish_reason}:{},...t.logprobs?{logprobs:t.logprobs}:{}},zo(i.message)&&(i.message.usage_metadata=s),i.message=new Do(Object.fromEntries(Object.entries(i.message).filter(([e])=>!e.startsWith("lc_")))),u.push(i)}return{generations:u,llmOutput:{tokenUsage:{promptTokens:s.input_tokens,completionTokens:s.output_tokens,totalTokens:s.total_tokens}}}}}async*_streamResponseChunks(e,t,i){var n,r,s,a,o,l,c,h,u,d;const p=ub(e,this.model),f={...this.invocationParams(t,{streaming:!0}),messages:p,stream:!0};let m;const g=await this.completionWithRetry(f,t);let O;for await(const v of g){const e=null==(n=null==v?void 0:v.choices)?void 0:n[0];if(v.usage&&(O=v.usage),!e)continue;const{delta:r}=e;if(!r)continue;const s=this._convertCompletionsDeltaToBaseMessageChunk(r,v,m);m=r.role??m;const a={prompt:t.promptIndex??0,completion:e.index??0};if("string"!=typeof s.content)continue;const o={...a};null!=e.finish_reason&&(o.finish_reason=e.finish_reason,o.system_fingerprint=v.system_fingerprint,o.model_name=v.model,o.service_tier=v.service_tier),this.logprobs&&(o.logprobs=e.logprobs);const l=new ql({message:s,text:s.content,generationInfo:o});yield l,await(null==i?void 0:i.handleLLMNewToken(l.text??"",a,void 0,void 0,void 0,{chunk:l}))}if(O){const e={...null!==(null==(r=O.prompt_tokens_details)?void 0:r.audio_tokens)&&{audio:null==(s=O.prompt_tokens_details)?void 0:s.audio_tokens},...null!==(null==(a=O.prompt_tokens_details)?void 0:a.cached_tokens)&&{cache_read:null==(o=O.prompt_tokens_details)?void 0:o.cached_tokens}},t={...null!==(null==(l=O.completion_tokens_details)?void 0:l.audio_tokens)&&{audio:null==(c=O.completion_tokens_details)?void 0:c.audio_tokens},...null!==(null==(h=O.completion_tokens_details)?void 0:h.reasoning_tokens)&&{reasoning:null==(u=O.completion_tokens_details)?void 0:u.reasoning_tokens}},i=new ql({message:new qo({content:"",response_metadata:{usage:{...O}},usage_metadata:{input_tokens:O.prompt_tokens,output_tokens:O.completion_tokens,total_tokens:O.total_tokens,...Object.keys(e).length>0&&{input_token_details:e},...Object.keys(t).length>0&&{output_token_details:t}}}),text:""});yield i}if(null==(d=t.signal)?void 0:d.aborted)throw new Error("AbortError")}async completionWithRetry(e,t){const i=this._getClientOptions(t),n=e.response_format&&"json_schema"===e.response_format.type;return this.caller.call(async()=>{try{return n&&!e.stream?await this.client.chat.completions.parse(e,i):await this.client.chat.completions.create(e,i)}catch(t){throw Gy(t)}})}_convertCompletionsMessageToBaseMessage(e,t){var i,n;const r=e.tool_calls;if("assistant"===e.role){const a=[],o=[];for(const e of r??[])try{a.push(dy(e,{returnId:!0}))}catch(s){o.push(fy(e,s.message))}const l={function_call:e.function_call,tool_calls:r};void 0!==this.__includeRawResponse&&(l.__raw_response=t);const c={model_name:t.model,...t.system_fingerprint?{usage:{...t.usage},system_fingerprint:t.system_fingerprint}:{}};e.audio&&(l.audio=e.audio);const h=function(e,t){if(t&&"object"==typeof t&&"images"in t&&Array.isArray(t.images))return[{type:"text",text:e,source_type:"text"},...t.images.filter(e=>{var t;return"string"==typeof(null==(t=null==e?void 0:e.image_url)?void 0:t.url)}).map(e=>({type:"image",url:e.image_url.url,source_type:"url"}))];return e}(e.content||"",null==(n=null==(i=t.choices)?void 0:i[0])?void 0:n.message);return new Do({content:h,tool_calls:a,invalid_tool_calls:o,additional_kwargs:l,response_metadata:c,id:t.id})}return new Xo(e.content||"",e.role??"unknown")}_convertCompletionsDeltaToBaseMessageChunk(e,t,i){var n,r;const s=e.role??i,a=e.content??"";let o;o=e.function_call?{function_call:e.function_call}:e.tool_calls?{tool_calls:e.tool_calls}:{},this.__includeRawResponse&&(o.__raw_response=t),e.audio&&(o.audio={...e.audio,index:t.choices[0].index});const l={usage:{...t.usage}};if("user"===s)return new Fo({content:a,response_metadata:l});if("assistant"===s){const i=[];if(Array.isArray(e.tool_calls))for(const t of e.tool_calls)i.push({name:null==(n=t.function)?void 0:n.name,args:null==(r=t.function)?void 0:r.arguments,id:t.id,index:t.index,type:"tool_call_chunk"});return new qo({content:a,tool_call_chunks:i,additional_kwargs:o,id:t.id,response_metadata:l})}return"system"===s?new Ho({content:a,response_metadata:l}):"developer"===s?new Ho({content:a,response_metadata:l,additional_kwargs:{__openai_role__:"developer"}}):"function"===s?new Wo({content:a,additional_kwargs:o,name:e.name,response_metadata:l}):"tool"===s?new Zo({content:a,additional_kwargs:o,tool_call_id:e.tool_call_id,response_metadata:l}):new Bo({content:a,role:s,response_metadata:l})}}class mb extends db{get lc_serializable_keys(){return[...super.lc_serializable_keys,"useResponsesApi"]}constructor(e){super(e),Object.defineProperty(this,"fields",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"useResponsesApi",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"responses",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"completions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.useResponsesApi=(null==e?void 0:e.useResponsesApi)??!1,this.responses=(null==e?void 0:e.responses)??new pb(e),this.completions=(null==e?void 0:e.completions)??new fb(e)}_useResponsesApi(e){var t,i,n,r;const s=null==(t=null==e?void 0:e.tools)?void 0:t.some(ib),a=null!=(null==e?void 0:e.previous_response_id)||null!=(null==e?void 0:e.text)||null!=(null==e?void 0:e.truncation)||null!=(null==e?void 0:e.include)||null!=(null==(i=null==e?void 0:e.reasoning)?void 0:i.summary)||null!=(null==(n=this.reasoning)?void 0:n.summary),o=null==(r=null==e?void 0:e.tools)?void 0:r.some(nb);return this.useResponsesApi||s||a||o}getLsParams(e){const t=this._combineCallOptions(e);return this._useResponsesApi(e)?this.responses.getLsParams(t):this.completions.getLsParams(t)}invocationParams(e){const t=this._combineCallOptions(e);return this._useResponsesApi(e)?this.responses.invocationParams(t):this.completions.invocationParams(t)}async _generate(e,t,i){return this._useResponsesApi(t)?this.responses._generate(e,t):this.completions._generate(e,t,i)}async*_streamResponseChunks(e,t,i){this._useResponsesApi(t)?yield*this.responses._streamResponseChunks(e,this._combineCallOptions(t),i):yield*this.completions._streamResponseChunks(e,this._combineCallOptions(t),i)}withConfig(e){const t=new mb(this.fields);return t.defaultOptions={...this.defaultOptions,...e},t}}class gb{constructor(e){ge(this,r,"http://localhost:8091"),ge(this,s,"booxtory_250131"),ge(this,a),ge(this,o),pe(this,"prompt",null),ge(this,l,()=>{switch(me(this,o).settings.server){case"chatopenai":Oe(this,a,new mb({modelName:me(this,o).settings.model,openAIApiKey:me(this,o).settings.CHATOPENAI_API_KEY,configuration:{baseURL:"https://openrouter.ai/api/v1"},temperature:0}));break;case"gemini":Oe(this,a,new Np({model:me(this,o).settings.model,apiKey:me(this,o).settings.geminiApiKey,temperature:0}));break;case"openai":Oe(this,a,new mb({model:me(this,o).settings.model,apiKey:me(this,o).settings.openaiApiKey,temperature:0}));break;case"ollama":Oe(this,a,new kf({model:me(this,o).settings.model,host:me(this,o).settings.ollamaUrl,temperature:0}))}}),ge(this,c,()=>{let e=[];return t.querySelectorAll("nx-side-menu-item[href][title]").forEach(t=>{e.push({url:t.getAttribute("href"),title:t.getAttribute("title")})}),e}),ge(this,h,async()=>{const e=await fetch("/api/meta/selectTableList",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schema:me(this,s)})});return await e.json()}),ge(this,u,async e=>{const t=await fetch("/api/meta/selectColumnInfo",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schema:me(this,s),tables:e})});return await t.json()}),ge(this,d,async(e,t)=>{const i=await Mu.generatePrompt(e,t);try{const e=await me(this,a).invoke([new Vo(i)]);return Mu.extractResponse(e,me(this,o).settings.server)}catch(n){throw n}}),ge(this,p,async e=>{const t=await me(this,d).call(this,"/prompts/meta/1.what.txt",{userPrompt:e});if("[object Object]"!==Object.prototype.toString.call(t)||!t.hasOwnProperty("result"))throw new Error(t);if("0"===t.result)throw new Error(t.reason);return t.result}),ge(this,f,async(e,t,i)=>{const n=await me(this,d).call(this,"/prompts/meta/2.where.txt",{userPrompt:e,menuList:JSON.stringify(t),tableDefinitions:JSON.stringify(i)});if("[object Object]"!==Object.prototype.toString.call(n)||!n.hasOwnProperty("result"))throw new Error(n);if("0"===n.result)throw new Error(n.reason);return n}),ge(this,m,async(e,t,i)=>{let n=await me(this,d).call(this,e,i);return n.endsWith("```")&&(n=n.slice(0,-3)),await ju.post("/api/source/generateTmplFile",{basePath:`${me(this,o).settings.beProjectName}/tmpl`,fileNm:t,contents:n}),n}),ge(this,g,()=>{const e=document.querySelectorAll('div[class^="detail-wrapper-"]');for(const t of e)if(""===t.innerHTML.trim()){const e=t.className.match(/detail-wrapper-([^ ]+)/);if(e&&e[1])return e[1]}return null}),ge(this,O,()=>{const e=document.querySelectorAll('div[class^="detail-wrapper-"]');for(let t=0;t<e.length;t++){const i=e[t];if(i.classList.contains("active")){const e=i.className.match(/detail-wrapper-([^ ]+)/);if(e&&e[1])return e[1]}}return null}),ge(this,v,e=>{const t=e.replace(/^\/+/,""),i=t.split("/").join(".").toLowerCase().replace(/[^a-z0-9.]/g,""),n=`${me(this,o).config.basePackage}.${i}`,r=n.split(".").slice(0,-1).join("."),s=t.split("/").at(-1).toLowerCase().split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(""),a=`${i.split(".").slice(0,-1).join("/")}/${t.split("/").at(-1)}`,l=me(this,g).call(this),c=me(this,O).call(this),h=c?a+"-detail-"+c:a,u=a+"-detail-"+l,d=c?s+"Detail"+c:s,p=s+"Detail"+l;return{package:r,namespace:n,baseClass:s,resultType:"ide.assi.util.CamelCaseMap",mybatis:`${i.split(".").slice(0,-1).join("/")}/${s}Mapper.xml`,classFrom:d,classTo:p,activeIndex:c,emptyIndex:l,mybatisPullPath:`${me(this,o).settings.beProjectName}/src/main/resources/mapper/${i.split(".").slice(0,-1).join("/")}/${s}Mapper.xml`,controllerPullPath:`${me(this,o).settings.beProjectName}/src/main/java/${r.replaceAll(".","/")}/controller/${s}Controller.java`,servicePullPath:`${me(this,o).settings.beProjectName}/src/main/java/${r.replaceAll(".","/")}/service/${s}Service.java`,javascriptFrom:`${me(this,o).settings.feProjectName}/src/views/${h}.jsx`,javascriptTo:`${me(this,o).settings.feProjectName}/src/views/${u}.jsx`}}),ge(this,y,async(e,i,n,r)=>{let s,a;if("C1"===e)s=await me(this,f).call(this,i,me(this,c).call(this),await me(this,h).call(this)),a=s.menu.url;else{if(!["U1","U2","C2"].includes(e))throw new Error("invalid command type.");{const e=t.querySelector("nx-side-menu-item.active");if(!e)throw new Error("관련 메뉴를 찾을 수 없습니다.");a=e.getAttribute("href");const n=e.getAttribute("title");s=await me(this,f).call(this,`${n}에서 ${i}`,[{url:a,title:n}],await me(this,h).call(this))}}const o=me(this,v).call(this,a),l=await ju.post("/api/source/read",o);r.updateProgress("prepare2","completed");const d=await me(this,u).call(this,s.table);let p={mybatis:l.mybatis,service:l.service,controller:l.controller,javascriptFrom:l.javascriptFrom,javascriptTo:l.javascriptTo};if(n.mybatis&&(p.mybatis=await me(this,m).call(this,"/prompts/meta/U.BuildMyBatisMapper.txt","mybatis.xml",{userPrompt:i,originSrc:l.mybatis,resultType:o.resultType,namespace:o.namespace,tableDefinitions:JSON.stringify(d)}),r.updateProgress("mybatis","completed")),n.service&&(p.service=await me(this,m).call(this,"/prompts/meta/U.BuildService.txt","service.java",{userPrompt:i,originSrc:l.service,baseClass:o.baseClass,myBatisPath:o.mybatis,namespace:o.namespace,package:o.package+".service",mybatisXmlSource:p.mybatis}),r.updateProgress("service","completed")),n.controller&&(p.controller=await me(this,m).call(this,"/prompts/meta/U.BuildController.txt","controller.java",{userPrompt:i,originSrc:l.controller,baseClass:o.baseClass,menuUrl:s.menu.url,package:o.package+".controller",serviceSource:p.service}),r.updateProgress("controller","completed")),n.javascript){const t=this.prompt.react.filter(e=>e.includes(".main.")||e.includes(".all.")),n=this.prompt.react.filter(e=>e.includes(".sub.")||e.includes(".all."));if(["C1","U1"].includes(e)){const e=o.javascriptTo.split("/").pop();p.javascriptFrom=await me(this,m).call(this,t,"reactFrom.jsx",{userPrompt:i,mybatis:o.mybatis,originSrc:l.javascriptFrom,menuUrl:s.menu.url,menuName:s.menu.name,baseClass:o.baseClass,classFrom:o.classFro,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:e,mybatisXmlSource:p.mybatis,controllerSource:p.controller,tableDefinitions:JSON.stringify(d)})}else{const e=o.javascriptTo.split("/").pop();p.javascriptFrom=await me(this,m).call(this,t,"reactFrom.jsx",{userPrompt:i,mybatis:o.mybatis,originSrc:l.javascriptFrom,menuUrl:s.menu.url,menuName:s.menu.name,baseClass:o.baseClass,classFrom:o.classFrom,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:e,mybatisXmlSource:p.mybatis,controllerSource:p.controller,tableDefinitions:JSON.stringify(d)}),p.javascriptTo=await me(this,m).call(this,n,"reactTo.jsx",{userPrompt:i,mybatis:o.mybatis,originSrc:l.javascriptTo,menuUrl:s.menu.url,menuName:s.menu.name,baseClass:o.baseClass,classFrom:o.classFrom,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:e,mybatisXmlSource:p.mybatis,controllerSource:p.controller,tableDefinitions:JSON.stringify(d)})}r.updateProgress("javascript","completed")}const g=[],O={mybatis:{path:o.mybatisPullPath,src:p.mybatis},service:{path:o.servicePullPath,src:p.service},controller:{path:o.controllerPullPath,src:p.controller},javascriptFrom:{path:o.javascriptFrom,src:p.javascriptFrom},javascriptTo:{path:o.javascriptTo,src:p.javascriptTo}};n.javascript&&(n.javascriptFrom=!0,n.javascriptTo=!0,n.javascript=!1);for(const t in n)n[t]&&O[t].src&&g.push({[t]:{asis:l[t],tobe:O[t].src,tobePath:O[t].path}});return g}),ge(this,b,async(e,i,n)=>{const r=t.querySelector("nx-side-menu-item.active");if(!r)throw new Error("관련 메뉴를 찾을 수 없습니다.");const s=r.getAttribute("href"),a=r.getAttribute("title"),o=me(this,v).call(this,s),l=await ju.post("/api/source/read",o),c=await me(this,f).call(this,`${a}에서 ${e}`,[{url:s,title:a}],await me(this,h).call(this));n.updateProgress("prepare2","completed");const d=await me(this,u).call(this,c.table);let p,g,O,y,b;if(i.mybatis?(p=await me(this,m).call(this,"/prompts/meta/U.BuildMyBatisMapper.txt","mybatis.xml",{userPrompt:e,originSrc:l.mybatis,resultType:o.resultType,namespace:o.namespace,tableDefinitions:JSON.stringify(d)}),n.updateProgress("mybatis","completed")):p=l.mybatis,i.service?(g=await me(this,m).call(this,"/prompts/meta/U.BuildService.txt","service.java",{userPrompt:e,originSrc:l.service,baseClass:o.baseClass,myBatisPath:o.mybatis,namespace:o.namespace,package:o.package+".service",mybatisXmlSource:p}),n.updateProgress("service","completed")):g=l.service,i.controller?(O=await me(this,m).call(this,"/prompts/meta/U.BuildController.txt","controller.java",{userPrompt:e,originSrc:l.controller,baseClass:o.baseClass,menuUrl:c.menu.url,package:o.package+".controller",serviceSource:g}),n.updateProgress("controller","completed")):O=l.controller,i.javascript){const t=o.javascriptTo.split("/").pop();y=await me(this,m).call(this,"/prompts/meta/detail/4.BuildReactJsx_Link.txt","reactFrom.jsx",{userPrompt:e,mybatis:o.mybatis,originSrc:l.javascript2,menuUrl:c.menu.url,menuName:c.menu.name,baseClass:o.baseClass,classFrom:o.classFrom,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:t,mybatisXmlSource:p,controllerSource:O,tableDefinitions:JSON.stringify(d)}),b=await me(this,m).call(this,"/prompts/meta/detail/4.BuildReactJsx_Detail.txt","reactTo.jsx",{userPrompt:e,mybatis:o.mybatis,originSrc:l.javascript,menuUrl:c.menu.url,menuName:c.menu.name,baseClass:o.baseClass,className:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,mybatisXmlSource:p,controllerSource:O,tableDefinitions:JSON.stringify(d)}),n.updateProgress("javascript","completed")}else b=l.javascriptTo;const w=[],_={mybatis:{path:o.mybatisPullPath,src:p},service:{path:o.servicePullPath,src:g},controller:{path:o.controllerPullPath,src:O},javascript:{path:o.javascriptToPullPath,src:b},javascript2:{path:o.javascriptFromPullPath,src:y}};i.javascript&&(i.javascript2=!0);for(const t in i)i[t]&&w.push({[t]:{asis:l[t],tobe:_[t].src,tobePath:_[t].path}});return w}),ge(this,w,async(e,i,n)=>{const r=t.querySelector("nx-side-menu-item.active");if(!r)throw new Error("관련 메뉴를 찾을 수 없습니다.");const s=r.getAttribute("href"),a=r.getAttribute("title"),o=me(this,v).call(this,s),l=await ju.post("/api/source/read",o),c=await me(this,f).call(this,`${a}에서 ${e}`,[{url:s,title:a}],await me(this,h).call(this));n.updateProgress("prepare2","completed");const d=await me(this,u).call(this,c.table);let p,g,O,y;i.mybatis?(p=await me(this,m).call(this,"/prompts/meta/U.BuildMyBatisMapper.txt","mybatis.xml",{userPrompt:e,originSrc:l.mybatis,resultType:o.resultType,namespace:o.namespace,tableDefinitions:JSON.stringify(d)}),n.updateProgress("mybatis","completed")):p=l.mybatis,i.service?(g=await me(this,m).call(this,"/prompts/meta/U.BuildService.txt","service.java",{userPrompt:e,originSrc:l.service,baseClass:o.baseClass,myBatisPath:o.mybatis,namespace:o.namespace,package:o.package+".service",mybatisXmlSource:p}),n.updateProgress("service","completed")):g=l.service,i.controller?(O=await me(this,m).call(this,"/prompts/meta/U.BuildController.txt","controller.java",{userPrompt:e,originSrc:l.controller,baseClass:o.baseClass,menuUrl:c.menu.url,package:o.package+".controller",serviceSource:g}),n.updateProgress("controller","completed")):O=l.controller,i.javascript?(y=await me(this,m).call(this,"/prompts/meta/detail/4.BuildReactJsx_Detail.txt","reactTo.jsx",{userPrompt:e,mybatis:o.mybatis,originSrc:l.javascriptFrom,menuUrl:c.menu.url,menuName:c.menu.name,baseClass:o.baseClass,className:o.classFrom,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,mybatisXmlSource:p,controllerSource:O,tableDefinitions:JSON.stringify(d)}),n.updateProgress("javascript","completed")):y=l.javascriptTo;const b=[],w={mybatis:{path:o.mybatisPullPath,src:p},service:{path:o.servicePullPath,src:g},controller:{path:o.controllerPullPath,src:O},javascript:{path:o.javascriptFromPullPath,src:y}};l.javascript=l.javascriptFrom;for(const t in i)i[t]&&b.push({[t]:{asis:l[t],tobe:w[t].src,tobePath:w[t].path}});return b}),pe(this,"generateSourceClient",async(e,t)=>{me(this,l).call(this);const i=[{id:"prepare1",message:"명령을 해석중입니다.",completedMessage:"명령을 해석했습니다."},{id:"prepare2",message:"메뉴와 테이블을 검색중입니다.",completedMessage:"관련 메뉴와 테이블을 찾았습니다."}];t.mybatis&&i.push({id:"mybatis",message:"MyBatis 소스를 생성중입니다.",completedMessage:"MyBatis 소스를 생성했습니다."}),t.service&&i.push({id:"service",message:"Java(Service) 소스를 생성중입니다.",completedMessage:"Java(Service) 소스를 생성했습니다."}),t.controller&&i.push({id:"controller",message:"Java(Controller) 소스를 생성중입니다.",completedMessage:"Java(Controller) 소스를 생성했습니다."}),t.javascript&&i.push({id:"javascript",message:"Jsx(React) 소스를 생성중입니다.",completedMessage:"Jsx(React) 소스를 생성했습니다."});const n=me(this,o).shadowRoot.querySelector("nx-ai-chat").addProgress(i),r=await me(this,p).call(this,e);if(n.updateProgress("prepare1","completed"),["C1","C2"].includes(r)&&t.mybatis&&t.service&&t.controller&&t.javascript,"C1"===r)return await me(this,y).call(this,r,e,t,n);if("C2"===r)return await me(this,y).call(this,r,e,t,n);if("U1"===r){return document.querySelector(".list-wrapper.active")?await me(this,y).call(this,r,e,t,n):await me(this,y).call(this,"U2",e,t,n)}}),Oe(this,o,e)}}r=new WeakMap,s=new WeakMap,a=new WeakMap,o=new WeakMap,l=new WeakMap,c=new WeakMap,h=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,m=new WeakMap,g=new WeakMap,O=new WeakMap,v=new WeakMap,y=new WeakMap,b=new WeakMap,w=new WeakMap,pe(gb,"generateWhereCause",async(e,t,i,n)=>{const r=await ju.post("/api/source/query",{xmlPath:e,queryId:t});if(r.query){return await(async(e,t)=>{const i=await Mu.generatePrompt(e,t);try{const e=new Np({model:"gemini-2.5-flash",apiKey:n,temperature:0}),t=await e.invoke([new Vo(i)]);return Mu.extractResponse(t,"gemini")}catch(r){throw r}})("/prompts/user/generateWhereCause.txt",{query:r.query,userPrompt:i})}});var Ob,vb,yb,bb,wb,_b,xb=Object.defineProperty,Sb=e=>{throw TypeError(e)},kb=(e,t,i)=>((e,t,i)=>t in e?xb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i),Pb=(e,t,i)=>t.has(e)||Sb("Cannot "+i),Tb=(e,t,i)=>(Pb(e,t,"read from private field"),t.get(e)),$b=(e,t,i)=>t.has(e)?Sb("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Eb=(e,t,i,n)=>(Pb(e,t,"write to private field"),t.set(e,i),i);Ob=new WeakMap,vb=new WeakMap,yb=new WeakMap,bb=new WeakSet,wb=function(){if("undefined"==typeof window)return;"localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname||window.location.hostname.startsWith("192.168.")?this.enable():this.disable()};const Ab=new class{constructor(e=null,t="green"){$b(this,bb),$b(this,Ob),$b(this,vb),$b(this,yb,!0),Eb(this,Ob,e),Eb(this,vb,t),((e,t,i)=>(Pb(e,t,"access private method"),i))(this,bb,wb).call(this)}init(e,t="green"){Eb(this,Ob,e),Eb(this,vb,t)}log(...e){if(!Tb(this,yb))return;Tb(this,vb);Tb(this,Ob)}warn(...e){Tb(this,yb)&&Tb(this,Ob)}error(...e){Tb(this,Ob)}enable(){Eb(this,yb,!0)}disable(){Eb(this,yb,!1)}};"undefined"!=typeof window&&(window.trace=Ab);class Cb{static show(){let e=document.getElementById("global-loading-overlay");if(!e&&(e=document.createElement("div"),e.id="global-loading-overlay",e.style.cssText="\n position: fixed; inset: 0; z-index: 9999;\n background: rgba(0, 0, 0, 0.4); display: flex; \n justify-content: center; align-items: center;\n backdrop-filter: blur(2px);\n ",e.innerHTML='<div class="loading-spinner"></div>',document.body.appendChild(e),!document.getElementById("nine-util-style"))){const e=document.createElement("style");e.id="nine-util-style",e.innerHTML="\n .loading-spinner {\n width: 48px; height: 48px;\n border: 5px solid rgba(255, 255, 255, 0.3);\n border-top-color: white; border-radius: 50%;\n animation: nine-spin 1s linear infinite;\n }\n @keyframes nine-spin { to { transform: rotate(360deg); } }\n ",document.head.appendChild(e)}e.style.display="flex"}static hide(){const e=document.getElementById("global-loading-overlay");e&&(e.style.display="none")}}const Rb=class{};_b=new WeakMap,kb(Rb,"BASE_URL",window.__API_BASE_URL__||""),$b(Rb,_b,(e,t,i={})=>{const n=t.startsWith("http")?t:`${Rb.BASE_URL}${t}`;Cb.show();const r={method:e,headers:{"Content-Type":"application/json"}};let s=n;return"GET"===e?s+=`?${new URLSearchParams(i)}`:r.body=JSON.stringify(i),fetch(s,r).then(async e=>{if(t.includes("/api/source/query")||Cb.hide(),!e.ok){const t=await e.text();throw new Error(`API 오류 (${e.status}): ${t}`)}return e.json()}).catch(e=>{throw Cb.hide(),e})}),kb(Rb,"get",(e,t={})=>{var i;return Tb(i=Rb,_b).call(i,"GET",e,t)}),kb(Rb,"post",(e,t={})=>{var i;return Tb(i=Rb,_b).call(i,"POST",e,t)});const Qb=Rb;class Ib extends HTMLElement{constructor(){super(),ge(this,_,!1),ge(this,x),pe(this,"settings"),pe(this,"config"),ge(this,S,async()=>{this.config=await Qb.post("/nine-ai/config/get")}),ge(this,k,()=>{["mybatis","service","controller","javascript"].forEach(e=>{const t="true"===localStorage.getItem(`ide-assi-${e}`);this.shadowRoot.querySelector(`#${e}`).checked=t})}),ge(this,P,e=>{Object.entries(e).forEach(([e,t])=>{localStorage.setItem(`ide-assi-${e}`,String(t))})}),ge(this,T,()=>{me(this,S).call(this),me(this,k).call(this),this.settings=this.shadowRoot.querySelector("ide-assi-settings");const e=document.createElement("ide-tip-popup");this.shadowRoot.appendChild(e);const t=document.createElement("ide-diff-popup");this.shadowRoot.appendChild(t),this.shadowRoot.querySelector("textarea").addEventListener("keydown",me(this,$)),this.shadowRoot.querySelector(".expand-icon").addEventListener("click",me(this,E)),this.shadowRoot.querySelector(".collapse-icon").addEventListener("click",me(this,E)),this.shadowRoot.querySelectorAll(".menu-icon").forEach(e=>e.addEventListener("click",me(this,A))),setTimeout(()=>{Qb.post("/api/prompt/dir",{feProjectName:this.settings.feProjectName}).then(e=>{me(this,x).prompt=e})},1e3)}),pe(this,"addMessage",e=>{const t=this.shadowRoot.querySelector("nx-ai-chat");t.add("ai",e),t.add("ing","...")}),ge(this,$,async e=>{if("Enter"!==e.key)return;e.preventDefault();const t={mybatis:this.shadowRoot.querySelector("#mybatis").checked,service:this.shadowRoot.querySelector("#service").checked,controller:this.shadowRoot.querySelector("#controller").checked,javascript:this.shadowRoot.querySelector("#javascript").checked};if(!(t.mybatis||t.service||t.controller||t.javascript))return;const i=e.target.value.trim();if(!i)return;if(me(this,_))return;Oe(this,_,!0),me(this,P).call(this,t),setTimeout(()=>{this.shadowRoot.querySelector("textarea").value=""});const n=this.shadowRoot.querySelector("nx-ai-chat");n.add("me",i),n.add("ing","...");const r=this.shadowRoot.querySelector("ide-tip-popup");r.popup();try{const e=await me(this,x).generateSourceClient(i,t);r.close(),e&&this.shadowRoot.querySelector("ide-diff-popup").popup(e)}catch(s){r.close(),n.add("ai",String(s).replace("Error:",""))}Oe(this,_,!1)}),ge(this,E,()=>{this.classList.toggle("collapse")}),ge(this,A,e=>{this.shadowRoot.querySelectorAll(".menu-icon").forEach(e=>e.classList.remove("active"));const t=e.target.closest(".menu-icon");t&&t.classList.add("active"),this.settings.classList.toggle("expand",!!e.target.closest(".menu-setting"))}),this.attachShadow({mode:"open"}),Oe(this,x,new gb(this))}connectedCallback(){this.shadowRoot.innerHTML=`\n\t\t\t<style>\n\t\t\t\t@import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n\t\t\t\t${t.getCustomPath(this,"ideAssi.css")}\n\t\t\t</style>\n\n\t\t\t<div class="wrapper">\n\t\t\t\t<ide-assi-settings></ide-assi-settings>\n\t\t\t\n\t\t\t\t<div class="container">\n\t\t\t\t\t<div class="head">\n\t\t\t\t\t\t<div class="logo"><span></span></div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<nx-ai-chat></nx-ai-chat>\n\t\t\t\t\t<div class="foot">\n\t\t\t\t\t\t<div class="apply-src">\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="mybatis" name="mybatis" value="Y" checked />\n\t\t\t\t\t\t\t <label for="mybatis">MyBatis</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="service" name="service" value="Y" checked />\n\t\t\t\t\t\t\t <label for="service">Service</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="controller" name="controller" value="Y" checked />\n\t\t\t\t\t\t\t <label for="controller">Controller</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="javascript" name="javascript" value="Y" checked />\n\t\t\t\t\t\t\t <label for="javascript">JavaScript</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<textarea name="ask" id="q" name="q" rows="4" placeholder="나에게 무엇이든 물어봐..."></textarea>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div class="menu">\n\t\t\t\t\t<div class="collapse-icon"></div>\n\t\t\t\t\t<div class="menu-icon menu-filter active"></div>\n\t\t\t\t\t<div class="menu-icon menu-general"></div>\n\t\t\t\t\t<div class="menu-icon menu-setting"></div>\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t<div class="expand-icon"></div>\n\t\t`,requestAnimationFrame(()=>{me(this,T).call(this)})}}_=new WeakMap,x=new WeakMap,S=new WeakMap,k=new WeakMap,P=new WeakMap,T=new WeakMap,$=new WeakMap,E=new WeakMap,A=new WeakMap,customElements.define("nine-ai",Ib);class jb extends HTMLElement{constructor(){super(),ge(this,C,()=>{this.shadowRoot.querySelectorAll('input[name="server"]').forEach(e=>{e.addEventListener("change",()=>{const e=this.shadowRoot.querySelector('input[name="server"]:checked').value;["gemini","openai","ollama","chatopenai"].forEach(t=>{this.shadowRoot.querySelectorAll("."+t).forEach(i=>{i.style.display=e===t?"flex":"none"})})})})}),this.attachShadow({mode:"open"})}get geminiApiKey(){return this.shadowRoot.querySelector("#geminiApiKey").value}set geminiApiKey(e){this.shadowRoot.querySelector("#geminiApiKey").value=e}get openaiApiKey(){return this.shadowRoot.querySelector("#openaiApiKey").value}set openaiApiKey(e){this.shadowRoot.querySelector("#openaiApiKey").value=e}get ollamaUrl(){return this.shadowRoot.querySelector("#ollamaUrl").value}set ollamaUrl(e){this.shadowRoot.querySelector("#ollamaUrl").value=e}get qdrantUrl(){return this.shadowRoot.querySelector("#qdrantUrl").value}set qdrantUrl(e){this.shadowRoot.querySelector("#qdrantUrl").value=e}get server(){var e;return null==(e=this.shadowRoot.querySelector('input[name="server"]:checked'))?void 0:e.value}set server(e){const t=this.shadowRoot.querySelector(`input[name="server"][value="${e}"]`);t&&(t.checked=!0),this.shadowRoot.querySelectorAll('input[name="server"]').forEach(e=>{e.dispatchEvent(new Event("change"))})}get model(){var e;return null==(e=this.shadowRoot.querySelector(`#${this.server}Model`))?void 0:e.value}set model(e){const t=this.shadowRoot.querySelector(`#${this.server}Model`);t&&(t.value=e,t.dispatchEvent(new Event("change")))}connectedCallback(){this.shadowRoot.innerHTML=`\n\t\t\t<style>\n\t\t\t\t@import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n\t\t\t\t${t.getCustomPath(this,"ideAssi.css")}\n\t\t\t</style>\n\n\t\t\t<div class="line subject">\n\t\t\t\t<label for="server">Server:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents">\n\t\t\t\t\x3c!--<label><input name="server" type="radio" value="chatopenai" >Chat Open AI</label>--\x3e\n\t\t\t\t<label><input name="server" type="radio" value="gemini" checked>Gemini</label>\n\t\t\t\t<label><input name="server" type="radio" value="openai">Open AI</label>\n\t\t\t\t<label><input name="server" type="radio" value="ollama">Ollama</label>\n\t\t\t</div>\n\t\t\t<div class="line gemini-bak" style="display:none;">\n\t\t\t\t<label>API Key: <input id="geminiApiKey" value=""/></label>\n\t\t\t</div>\n\t\t\t<div class="line openai-bak" style="display:none;">\n\t\t\t\t<label>API Key: <input id="openaiApiKey" value=""/></label>\n\t\t\t</div>\n\t\t\t<div class="line subject ollama">\n\t\t\t\t<label for="ollamaUrl">Server Url:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents ollama">\n\t\t\t\t<input type="text" id="ollamaUrl" value="http://localhost:11434"/></label>\n\t\t\t</div>\n\t\t\t<div class="line subject ollama">\n\t\t\t\t<label for="ollamaModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents ollama">\n\t\t\t\t<select id="ollamaModel">\n\t\t\t\t\t<option value="codellama:13b">codellama:13b</option>\n\t\t\t\t\t<option value="deepseek-coder:6.7b">deepseek-coder:6.7b</option>\n\t\t\t\t\t<option value="phi4:14b">phi4:14b</option>\n\t\t\t\t\t<option value="llama3.1:8b">llama3.1:8b</option>\n\t\t\t\t\t<option value="mistral:7b">mistral:7b</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t<div class="line subject gemini">\n\t\t\t\t<label for="geminiModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents gemini">\n\t\t\t\t<select id="geminiModel">\n\t\t\t\t\t<option value="gemini-2.5-flash">gemini-2.5-flash</option>\n\t\t\t\t\t<option value="gemini-2.5-pro">gemini-2.5-pro</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t<div class="line subject chatopenai">\n\t\t\t\t<label for="chatopenaiModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents chatopenai">\n\t\t\t\t<select id="chatopenaiModel">\n\t\t\t\t\t<option value="google/gemma-2-9b-it">google/gemma-2-9b-it</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t<div class="line subject openai">\n\t\t\t\t<label for="openaiModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents openai">\n\t\t\t\t<select id="openaiModel">\n\t\t\t\t\t<option value="gpt-4">gpt-4</option>\n\t\t\t\t\t<option value="gpt-4o">gpt-4o</option>\n\t\t\t\t\t<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t\n\t\t\t<div class="line subject qdrant">\n\t\t\t\t<label for="qdrantUrl">Qdrant Url:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents qdrant">\n\t\t\t\t<input type="text" id="qdrantUrl" value="http://localhost:6333"/>\n\t\t\t</div>\n\n\t\t\t<div class="line subject analyze">\n\t\t\t\t<input id="chkAnalyze" type="checkbox" checked> <input id="txtAnalyze" type="number" value="100"><label>건 미만인 경우 데이타 분석 요청</label>\n\t\t\t</div>\n\t\t`,me(this,C).call(this),setTimeout(()=>{this.server="chatopenai"},0)}}C=new WeakMap,customElements.define("ide-assi-settings",jb);class Mb extends HTMLElement{constructor(){super(),ge(this,R,[]),ge(this,Q,0),ge(this,I,0),ge(this,j,null),ge(this,M,null),ge(this,N,1e4),ge(this,L,3e3),pe(this,"tipElement",null),pe(this,"loadingAnimation",null),pe(this,"tipImageElement",null),pe(this,"tipImageContainer",null),this.attachShadow({mode:"open"})}connectedCallback(){this.shadowRoot.innerHTML=`\n <style>\n /* Import ninegrid's base AI CSS */\n @import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n /* Import custom CSS specific to this component (adjust path as needed) */\n ${t.getCustomPath(this,"ideAssi.css")}\n\n \n .loading-animation {\n --animation: spin 1s linear infinite;\n }\n\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n </style>\n <div class="chat-message loading-tips-message">\n\t\t\t\t<div class="loading-bar-wrapper">\n\t\t\t\t <div class="loading-bar"></div>\n\t\t\t\t</div>\n\t\t\t\t<div class="tip-content">\n\t\t\t\t\t<div class="tip-image-container">\n\t\t\t\t\t\t<img class="tip-image" src="" alt="팁 관련 이미지">\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div class="current-tip-wrapper">\n\t\t\t\t\t<p class="current-tip"></p>\n\t\t\t\t</div>\n\t\t\t</div>\n `,this.tipElement=this.shadowRoot.querySelector(".current-tip"),this.loadingAnimation=this.shadowRoot.querySelector(".loading-animation"),this.loadingAnimationWrapper=this.shadowRoot.querySelector(".loading-animation-wrapper"),this.tipImageElement=this.shadowRoot.querySelector(".tip-image"),this.tipImageContainer=this.shadowRoot.querySelector(".tip-image-container")}disconnectedCallback(){this.stopTips()}async startTips(e,t){if(e&&t)try{const i=await fetch(e);if(!i.ok)throw new Error(`Failed to fetch tips: ${i.statusText}`);const n=(await i.json())[t];if(!n||0===n.length)return;Oe(this,R,n),Oe(this,Q,Math.floor(Math.random()*me(this,R).length)),this.stopTips(),this.showRandomTip(),Oe(this,j,setInterval(()=>{this.showRandomTip()},me(this,N)))}catch(i){this.stopTips(),this.tipElement&&(this.tipElement.textContent="팁을 불러오는 중 오류가 발생했습니다.")}}stopTips(){me(this,j)&&(clearInterval(me(this,j)),Oe(this,j,null)),me(this,M)&&(clearInterval(me(this,M)),Oe(this,M,null)),this.tipImageElement.style.display="none",this.tipImageElement.src="",this.tipImageContainer.style.display="none"}showRandomTip(){if(0===me(this,R).length)return this.tipElement.textContent="",this.tipImageElement.style.display="none",void(this.tipImageContainer.style.display="none");let e=me(this,Q);if(me(this,R).length>1)for(let i=0;i<3;i++){const t=Math.floor(Math.random()*me(this,R).length);if(t!==me(this,Q)){e=t;break}}Oe(this,Q,e);const t=me(this,R)[me(this,Q)];this.tipElement&&t&&(this.tipElement.innerHTML=t.text,me(this,M)&&(clearInterval(me(this,M)),Oe(this,M,null)),t.images&&t.images.length>0?(Oe(this,I,0),this.showCurrentImage(t.images[me(this,I)]),this.tipImageElement.style.display="block",this.tipImageContainer.style.display="flex",t.images.length>1&&Oe(this,M,setInterval(()=>{Oe(this,I,(me(this,I)+1)%t.images.length),this.showCurrentImage(t.images[me(this,I)])},me(this,L)))):(this.tipImageElement.style.display="none",this.tipImageContainer.style.display="none",this.tipImageElement.src=""))}showCurrentImage(e){this.tipImageElement&&(this.tipImageElement.src=e)}}R=new WeakMap,Q=new WeakMap,I=new WeakMap,j=new WeakMap,M=new WeakMap,N=new WeakMap,L=new WeakMap,customElements.define("ide-loading-tips",Mb);class Nb extends HTMLElement{constructor(){super(),ge(this,Z,null),ge(this,D,"/data/tips.json"),ge(this,z,"componentTips"),ge(this,U,()=>{const e=this.shadowRoot.querySelector("nx-dialog");e&&e.addEventListener("close",()=>{me(this,Z)&&(me(this,Z).stopTips(),me(this,Z).remove(),Oe(this,Z,null))})}),pe(this,"close",()=>{var e;me(this,Z).stopTips(),null==(e=this.shadowRoot.querySelector("nx-dialog"))||e.close()}),this.attachShadow({mode:"open"})}connectedCallback(){this.shadowRoot.innerHTML=`\n <style>\n @import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n ${t.getCustomPath(this,"ideAssi.css")}\n </style>\n\n <nx-dialog>\n <div class="dialog-content"></div>\n </nx-dialog>\n `,me(this,U).call(this)}async popup(e="componentTips",t="/tips/tip.json"){var i;Oe(this,z,e),Oe(this,D,t);const n=this.shadowRoot.querySelector(".dialog-content");n&&(me(this,Z)&&(me(this,Z).stopTips(),me(this,Z).remove(),Oe(this,Z,null)),Oe(this,Z,document.createElement("ide-loading-tips")),n.appendChild(me(this,Z)),await me(this,Z).startTips(me(this,D),me(this,z)),null==(i=this.shadowRoot.querySelector("nx-dialog"))||i.showModal())}}Z=new WeakMap,D=new WeakMap,z=new WeakMap,U=new WeakMap,customElements.define("ide-tip-popup",Nb);class Lb extends HTMLElement{constructor(){super(),ge(this,q),ge(this,X,()=>{t.querySelector(".save",this.shadowRoot).addEventListener("click",e=>{me(this,B).call(this)})}),ge(this,B,()=>{let e=[];for(const i of me(this,q)){const n=Object.keys(i)[0],r=t.querySelector(`ide-diff.${n}`,this.shadowRoot);e.push({path:i[n].tobePath,contents:r.getContents()})}ju.post("/api/source/generateRealFile",{list:e}).then(e=>{t.alert("소스를 변경하였습니다.")})}),pe(this,"popup",e=>{Oe(this,q,e);const i=this.shadowRoot.querySelector("nx-tab");setTimeout(()=>{var n;for(const i of e){const[e,n]=Object.entries(i)[0],r=t.querySelector(`ide-diff.${e}`,this.shadowRoot);r&&r.initialize(n.asis,n.tobe,t.decode(e,"mybatis","xml","java","java","javascript"))}i.tabpage.showAll();const r=e.map(e=>Object.keys(e)[0]);t.querySelectorAll("ide-diff",this.shadowRoot).forEach(e=>{const t=e.className.trim();r.includes(t)||i.tabpage.hide(t)}),i.shadowRoot.querySelectorAll(".tab-button").forEach((i,n)=>{i.innerHTML=((t,i="tobePath")=>{if(!e)return null;for(const n of e)if(n.hasOwnProperty(t)&&n[t][i]){const e=n[t][i].split("/");return e.length>0?e.pop():null}return null})(t.decode(n,0,"mybatis",1,"service",2,"controller",3,"javascriptFrom","javascriptTo"))}),i.initialize(),null==(n=this.shadowRoot.querySelector("nx-dialog"))||n.showModal()},100)}),this.attachShadow({mode:"open"})}connectedCallback(){this.shadowRoot.innerHTML='\n\t\t\t<style>\n\t\t\t\tdiv.buttons {\n\t\t\t\t\tposition: absolute;\n\t\t\t\t\tright: 16px;\n\t\t\t\t\t/* width: 100px; */\n\t\t\t\t\tdisplay: flex;\n\t\t\t\t\tflex-direction: row;\n\t\t\t\t\tjustify-content: flex-end;\n\t\t\t\t\tz-index: 1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbutton.save {\n\t\t\t\t\tcursor: pointer;\n\t\t\t\t\toutline: none;\n\t\t\t\t}\n\t\t\t</style>\n\n\t\t\t<nx-dialog>\n\t\t\t\t<div class="buttons">\n\t\t\t\t\t<button class="save">Apply</button>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t<nx-tab theme="theme-4">\n\t\t\t\t <nx-tab-page caption="mybatis">\n\t\t\t\t\t<ide-diff class="mybatis"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="service">\n\t\t\t\t\t<ide-diff class="service"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="controller">\n\t\t\t\t\t<ide-diff class="controller"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="javascriptFrom">\n\t\t\t\t\t<ide-diff class="javascriptFrom"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="javascriptTo">\n\t\t\t\t\t<ide-diff class="javascriptTo"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t</nx-tab>\n\t\t\t</nx-dialog>\n\t\t',me(this,X).call(this)}}q=new WeakMap,X=new WeakMap,B=new WeakMap,customElements.define("ide-diff-popup",Lb);let Zb=[],Db=[];function zb(e){if(e<768)return!1;for(let t=0,i=Zb.length;;){let n=t+i>>1;if(e<Zb[n])i=n;else{if(!(e>=Db[n]))return!0;t=n+1}if(t==i)return!1}}function Ub(e){return e>=127462&&e<=127487}(()=>{let e="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let t=0,i=0;t<e.length;t++)(t%2?Db:Zb).push(i+=e[t])})();function qb(e,t,i=!0,n=!0){return(i?Xb:Bb)(e,t,n)}function Xb(e,t,i){if(t==e.length)return t;t&&Vb(e.charCodeAt(t))&&Fb(e.charCodeAt(t-1))&&t--;let n=Wb(e,t);for(t+=Yb(n);t<e.length;){let r=Wb(e,t);if(8205==n||8205==r||i&&zb(r))t+=Yb(r),n=r;else{if(!Ub(r))break;{let i=0,n=t-2;for(;n>=0&&Ub(Wb(e,n));)i++,n-=2;if(i%2==0)break;t+=2}}}return t}function Bb(e,t,i){for(;t>0;){let n=Xb(e,t-2,i);if(n<t)return n;t--}return 0}function Wb(e,t){let i=e.charCodeAt(t);if(!Fb(i)||t+1==e.length)return i;let n=e.charCodeAt(t+1);return Vb(n)?n-56320+(i-55296<<10)+65536:i}function Vb(e){return e>=56320&&e<57344}function Fb(e){return e>=55296&&e<56320}function Yb(e){return e<65536?1:2}class Gb{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=sw(this,e,t);let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),Kb.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=sw(this,e,t);let i=[];return this.decompose(e,t,i,0),Kb.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new tw(this),r=new tw(e);for(let s=t,a=t;;){if(n.next(s),r.next(s),s=0,n.lineBreak!=r.lineBreak||n.done!=r.done||n.value!=r.value)return!1;if(a+=n.value.length,n.done||a>=i)return!0}}iter(e=1){return new tw(this,e)}iterRange(e,t=this.length){return new iw(this,e,t)}iterLines(e,t){let i;if(null==e)i=this.iter();else{null==t&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new nw(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(0==e.length)throw new RangeError("A document must have at least one line");return 1!=e.length||e[0]?e.length<=32?new Hb(e):Kb.from(Hb.split(e,[])):Gb.empty}}class Hb extends Gb{constructor(e,t=function(e){let t=-1;for(let i of e)t+=i.length+1;return t}(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let r=0;;r++){let s=this.text[r],a=n+s.length;if((t?i:a)>=e)return new rw(n,a,i,s);n=a+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new Hb(ew(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(1&n){let e=i.pop(),t=Jb(r.text,e.text.slice(),0,r.length);if(t.length<=32)i.push(new Hb(t,e.length+r.length));else{let e=t.length>>1;i.push(new Hb(t.slice(0,e)),new Hb(t.slice(e)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof Hb))return super.replace(e,t,i);[e,t]=sw(this,e,t);let n=Jb(this.text,Jb(i.text,ew(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new Hb(n,r):Kb.from(Hb.split(n,[]),r)}sliceString(e,t=this.length,i="\n"){[e,t]=sw(this,e,t);let n="";for(let r=0,s=0;r<=t&&s<this.text.length;s++){let a=this.text[s],o=r+a.length;r>e&&s&&(n+=i),e<o&&t>r&&(n+=a.slice(Math.max(0,e-r),t-r)),r=o+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let r of e)i.push(r),n+=r.length+1,32==i.length&&(t.push(new Hb(i,n)),i=[],n=-1);return n>-1&&t.push(new Hb(i,n)),t}}class Kb extends Gb{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let r=0;;r++){let s=this.children[r],a=n+s.length,o=i+s.lines-1;if((t?o:a)>=e)return s.lineInner(e,t,i,n);n=a+1,i=o+1}}decompose(e,t,i,n){for(let r=0,s=0;s<=t&&r<this.children.length;r++){let a=this.children[r],o=s+a.length;if(e<=o&&t>=s){let r=n&((s<=e?1:0)|(o>=t?2:0));s>=e&&o<=t&&!r?i.push(a):a.decompose(e-s,t-s,i,r)}s=o+1}}replace(e,t,i){if([e,t]=sw(this,e,t),i.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let s=this.children[n],a=r+s.length;if(e>=r&&t<=a){let o=s.replace(e-r,t-r,i),l=this.lines-s.lines+o.lines;if(o.lines<l>>4&&o.lines>l>>6){let r=this.children.slice();return r[n]=o,new Kb(r,this.length-(t-e)+i.length)}return super.replace(r,a,o)}r=a+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i="\n"){[e,t]=sw(this,e,t);let n="";for(let r=0,s=0;r<this.children.length&&s<=t;r++){let a=this.children[r],o=s+a.length;s>e&&r&&(n+=i),e<o&&t>s&&(n+=a.sliceString(e-s,t-s,i)),s=o+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Kb))return 0;let i=0,[n,r,s,a]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,r+=t){if(n==s||r==a)return i;let o=this.children[n],l=e.children[r];if(o!=l)return i+o.scanIdentical(l,t);i+=o.length+1}}static from(e,t=e.reduce((e,t)=>e+t.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let i=[];for(let t of e)t.flatten(i);return new Hb(i,t)}let n=Math.max(32,i>>5),r=n<<1,s=n>>1,a=[],o=0,l=-1,c=[];function h(e){let t;if(e.lines>r&&e instanceof Kb)for(let i of e.children)h(i);else e.lines>s&&(o>s||!o)?(u(),a.push(e)):e instanceof Hb&&o&&(t=c[c.length-1])instanceof Hb&&e.lines+t.lines<=32?(o+=e.lines,l+=e.length+1,c[c.length-1]=new Hb(t.text.concat(e.text),t.length+1+e.length)):(o+e.lines>n&&u(),o+=e.lines,l+=e.length+1,c.push(e))}function u(){0!=o&&(a.push(1==c.length?c[0]:Kb.from(c,l)),l=-1,o=c.length=0)}for(let d of e)h(d);return u(),1==a.length?a[0]:new Kb(a,t)}}function Jb(e,t,i=0,n=1e9){for(let r=0,s=0,a=!0;s<e.length&&r<=n;s++){let o=e[s],l=r+o.length;l>=i&&(l>n&&(o=o.slice(0,n-r)),r<i&&(o=o.slice(i-r)),a?(t[t.length-1]+=o,a=!1):t.push(o)),r=l+1}return t}function ew(e,t,i){return Jb(e,[""],t,i)}Gb.empty=new Hb([""],0);class tw{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof Hb?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],s=r>>1,a=n instanceof Hb?n.text.length:n.children.length;if(s==(t>0?a:0)){if(0==i)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(t>0?0:1)){if(this.offsets[i]+=t,0==e)return this.lineBreak=!0,this.value="\n",this;e--}else if(n instanceof Hb){let r=n.text[s+(t<0?-1:0)];if(this.offsets[i]+=t,r.length>Math.max(0,e))return this.value=0==e?r:t>0?r.slice(e):r.slice(0,r.length-e),this;e-=r.length}else{let r=n.children[s+(t<0?-1:0)];e>r.length?(e-=r.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(r),this.offsets.push(t>0?1:(r instanceof Hb?r.text.length:r.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class iw{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new tw(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class nw{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(Gb.prototype[Symbol.iterator]=function(){return this.iter()},tw.prototype[Symbol.iterator]=iw.prototype[Symbol.iterator]=nw.prototype[Symbol.iterator]=function(){return this});class rw{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}function sw(e,t,i){return[t=Math.max(0,Math.min(e.length,t)),Math.max(t,Math.min(e.length,i))]}function aw(e,t,i=!0,n=!0){return qb(e,t,i,n)}function ow(e,t){let i=e.charCodeAt(t);if(!(n=i,n>=55296&&n<56320&&t+1!=e.length))return i;var n;let r=e.charCodeAt(t+1);return function(e){return e>=56320&&e<57344}(r)?r-56320+(i-55296<<10)+65536:i}function lw(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10),56320+(1023&e)))}function cw(e){return e<65536?1:2}const hw=/\r\n?|\n/;var uw=function(e){return e[e.Simple=0]="Simple",e[e.TrackDel=1]="TrackDel",e[e.TrackBefore=2]="TrackBefore",e[e.TrackAfter=3]="TrackAfter",e}(uw||(uw={}));class dw{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return 0==this.sections.length||2==this.sections.length&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],s=this.sections[t++];s<0?(e(i,n,r),n+=r):n+=s,i+=r}}iterChangedRanges(e,t=!1){gw(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new dw(e)}composeDesc(e){return this.empty?e:e.empty?this:vw(this,e)}mapDesc(e,t=!1){return e.empty?this:Ow(this,e,t)}mapPos(e,t=-1,i=uw.Simple){let n=0,r=0;for(let s=0;s<this.sections.length;){let a=this.sections[s++],o=this.sections[s++],l=n+a;if(o<0){if(l>e)return r+(e-n);r+=a}else{if(i!=uw.Simple&&l>=e&&(i==uw.TrackDel&&n<e&&l>e||i==uw.TrackBefore&&n<e||i==uw.TrackAfter&&l>e))return null;if(l>e||l==e&&t<0&&!a)return e==n||t<0?r:r+o;r+=o}n=l}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return r}touchesRange(e,t=e){for(let i=0,n=0;i<this.sections.length&&n<=t;){let r=n+this.sections[i++];if(this.sections[i++]>=0&&n<=t&&r>=e)return!(n<e&&r>t)||"cover";n=r}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(e=>"number"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeDesc");return new dw(e)}static create(e){return new dw(e)}}class pw extends dw{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return gw(this,(t,i,n,r,s)=>e=e.replace(n,n+(i-t),s),!1),e}mapDesc(e,t=!1){return Ow(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let s=t[n],a=t[n+1];if(a>=0){t[n]=a,t[n+1]=s;let o=n>>1;for(;i.length<o;)i.push(Gb.empty);i.push(s?e.slice(r,r+s):Gb.empty)}r+=s}return new pw(t,i)}compose(e){return this.empty?e:e.empty?this:vw(this,e,!0)}map(e,t=!1){return e.empty?this:Ow(this,e,t,!0)}iterChanges(e,t=!1){gw(this,e,t)}get desc(){return dw.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new yw(this);e:for(let s=0,a=0;;){let o=s==e.length?1e9:e[s++];for(;a<o||a==o&&0==r.len;){if(r.done)break e;let e=Math.min(r.len,o-a);fw(n,e,-1);let s=-1==r.ins?-1:0==r.off?r.ins:0;fw(t,e,s),s>0&&mw(i,t,r.text),r.forward(e),a+=e}let l=e[s++];for(;a<l;){if(r.done)break e;let e=Math.min(r.len,l-a);fw(t,e,-1),fw(n,e,-1==r.ins?-1:0==r.off?r.ins:0),r.forward(e),a+=e}}return{changes:new pw(t,i),filtered:dw.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):0==n?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],s=0,a=null;function o(e=!1){if(!e&&!n.length)return;s<t&&fw(n,t-s,-1);let i=new pw(n,r);a=a?a.compose(i.map(a)):i,n=[],r=[],s=0}return function e(l){if(Array.isArray(l))for(let t of l)e(t);else if(l instanceof pw){if(l.length!=t)throw new RangeError(`Mismatched change set length (got ${l.length}, expected ${t})`);o(),a=a?a.compose(l.map(a)):l}else{let{from:e,to:a=e,insert:c}=l;if(e>a||e<0||a>t)throw new RangeError(`Invalid change range ${e} to ${a} (in doc of length ${t})`);let h=c?"string"==typeof c?Gb.of(c.split(i||hw)):c:Gb.empty,u=h.length;if(e==a&&0==u)return;e<s&&o(),e>s&&fw(n,e-s,-1),fw(n,a-e,u),mw(r,n,h),s=a}}(e),o(!a),a}static empty(e){return new pw(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if("number"==typeof r)t.push(r,-1);else{if(!Array.isArray(r)||"number"!=typeof r[0]||r.some((e,t)=>t&&"string"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)t.push(r[0],0);else{for(;i.length<n;)i.push(Gb.empty);i[n]=Gb.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new pw(t,i)}static createSet(e,t){return new pw(e,t)}}function fw(e,t,i,n=!1){if(0==t&&i<=0)return;let r=e.length-2;r>=0&&i<=0&&i==e[r+1]?e[r]+=t:r>=0&&0==t&&0==e[r]?e[r+1]+=i:n?(e[r]+=t,e[r+1]+=i):e.push(t,i)}function mw(e,t,i){if(0==i.length)return;let n=t.length-2>>1;if(n<e.length)e[e.length-1]=e[e.length-1].append(i);else{for(;e.length<n;)e.push(Gb.empty);e.push(i)}}function gw(e,t,i){let n=e.inserted;for(let r=0,s=0,a=0;a<e.sections.length;){let o=e.sections[a++],l=e.sections[a++];if(l<0)r+=o,s+=o;else{let c=r,h=s,u=Gb.empty;for(;c+=o,h+=l,l&&n&&(u=u.append(n[a-2>>1])),!(i||a==e.sections.length||e.sections[a+1]<0);)o=e.sections[a++],l=e.sections[a++];t(r,c,s,h,u),r=c,s=h}}}function Ow(e,t,i,n=!1){let r=[],s=n?[]:null,a=new yw(e),o=new yw(t);for(let l=-1;;){if(a.done&&o.len||o.done&&a.len)throw new Error("Mismatched change set lengths");if(-1==a.ins&&-1==o.ins){let e=Math.min(a.len,o.len);fw(r,e,-1),a.forward(e),o.forward(e)}else if(o.ins>=0&&(a.ins<0||l==a.i||0==a.off&&(o.len<a.len||o.len==a.len&&!i))){let e=o.len;for(fw(r,o.ins,-1);e;){let t=Math.min(a.len,e);a.ins>=0&&l<a.i&&a.len<=t&&(fw(r,0,a.ins),s&&mw(s,r,a.text),l=a.i),a.forward(t),e-=t}o.next()}else{if(!(a.ins>=0)){if(a.done&&o.done)return s?pw.createSet(r,s):dw.create(r);throw new Error("Mismatched change set lengths")}{let e=0,t=a.len;for(;t;)if(-1==o.ins){let i=Math.min(t,o.len);e+=i,t-=i,o.forward(i)}else{if(!(0==o.ins&&o.len<t))break;t-=o.len,o.next()}fw(r,e,l<a.i?a.ins:0),s&&l<a.i&&mw(s,r,a.text),l=a.i,a.forward(a.len-t)}}}}function vw(e,t,i=!1){let n=[],r=i?[]:null,s=new yw(e),a=new yw(t);for(let o=!1;;){if(s.done&&a.done)return r?pw.createSet(n,r):dw.create(n);if(0==s.ins)fw(n,s.len,0,o),s.next();else if(0!=a.len||a.done){if(s.done||a.done)throw new Error("Mismatched change set lengths");{let e=Math.min(s.len2,a.len),t=n.length;if(-1==s.ins){let t=-1==a.ins?-1:a.off?0:a.ins;fw(n,e,t,o),r&&t&&mw(r,n,a.text)}else-1==a.ins?(fw(n,s.off?0:s.len,e,o),r&&mw(r,n,s.textBit(e))):(fw(n,s.off?0:s.len,a.off?0:a.ins,o),r&&!a.off&&mw(r,n,a.text));o=(s.ins>e||a.ins>=0&&a.len>e)&&(o||n.length>t),s.forward2(e),a.forward(e)}}else fw(n,0,a.ins,o),r&&mw(r,n,a.text),a.next()}}class yw{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return-2==this.ins}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?Gb.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?Gb.empty:t[i].slice(this.off,null==e?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){-1==this.ins?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class bw{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let e=7&this.flags;return 7==e?null:e}get goalColumn(){let e=this.flags>>6;return 16777215==e?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new bw(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return ww.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return ww.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return!(this.anchor!=e.anchor||this.head!=e.head||this.goalColumn!=e.goalColumn||t&&this.empty&&this.assoc!=e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||"number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid JSON representation for SelectionRange");return ww.range(e.anchor,e.head)}static create(e,t,i){return new bw(e,t,i)}}class ww{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:ww.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return 1==this.ranges.length?this:new ww([this.main],0)}addRange(e,t=!0){return ww.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,ww.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||"number"!=typeof e.main||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new ww(e.ranges.map(e=>bw.fromJSON(e)),e.main)}static single(e,t=e){return new ww([ww.range(e,t)],0)}static create(e,t=0){if(0==e.length)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return ww.normalized(e.slice(),t);i=r.to}return new ww(e,t)}static cursor(e,t=0,i,n){return bw.create(e,e,(0==t?0:t<0?8:16)|(null==i?7:Math.min(6,i))|(null!=n?n:16777215)<<6)}static range(e,t,i,n,r){let s=(null!=i?i:16777215)<<6|(null==n?7:Math.min(6,n));return r||e==t||(r=t<e?1:-1),t<e?bw.create(t,e,48|s):bw.create(e,t,(r?r<0?8:16:0)|s)}static normalized(e,t=0){let i=e[t];e.sort((e,t)=>e.from-t.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let i=e[n],r=e[n-1];if(i.empty?i.from<=r.to:i.from<r.to){let s=r.from,a=Math.max(i.to,r.to);n<=t&&t--,e.splice(--n,2,i.anchor>i.head?ww.range(a,s):ww.range(s,a))}}return new ww(e,t)}}function _w(e,t){for(let i of e.ranges)if(i.to>t)throw new RangeError("Selection points outside of document")}let xw=0;class Sw{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=xw++,this.default=e([]),this.extensions="function"==typeof r?r(this):r}get reader(){return this}static define(e={}){return new Sw(e.combine||(e=>e),e.compareInput||((e,t)=>e===t),e.compare||(e.combine?(e,t)=>e===t:kw),!!e.static,e.enables)}of(e){return new Pw([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Pw(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Pw(e,this,2,t)}from(e,t){return t||(t=e=>e),this.compute([e],i=>t(i.field(e)))}}function kw(e,t){return e==t||e.length==t.length&&e.every((e,i)=>e===t[i])}class Pw{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=xw++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,r=this.id,s=e[r]>>1,a=2==this.type,o=!1,l=!1,c=[];for(let h of this.dependencies)"doc"==h?o=!0:"selection"==h?l=!0:1&(null!==(t=e[h.id])&&void 0!==t?t:1)||c.push(e[h.id]);return{create:e=>(e.values[s]=i(e),1),update(e,t){if(o&&t.docChanged||l&&(t.docChanged||t.selection)||$w(e,c)){let t=i(e);if(a?!Tw(t,e.values[s],n):!n(t,e.values[s]))return e.values[s]=t,1}return 0},reconfigure:(e,t)=>{let o,l=t.config.address[r];if(null!=l){let r=qw(t,l);if(this.dependencies.every(i=>i instanceof Sw?t.facet(i)===e.facet(i):!(i instanceof Cw)||t.field(i,!1)==e.field(i,!1))||(a?Tw(o=i(e),r,n):n(o=i(e),r)))return e.values[s]=r,0}else o=i(e);return e.values[s]=o,1}}}}function Tw(e,t,i){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!i(e[n],t[n]))return!1;return!0}function $w(e,t){let i=!1;for(let n of t)1&Uw(e,n)&&(i=!0);return i}function Ew(e,t,i){let n=i.map(t=>e[t.id]),r=i.map(e=>e.type),s=n.filter(e=>!(1&e)),a=e[t.id]>>1;function o(e){let i=[];for(let t=0;t<n.length;t++){let s=qw(e,n[t]);if(2==r[t])for(let e of s)i.push(e);else i.push(s)}return t.combine(i)}return{create(e){for(let t of n)Uw(e,t);return e.values[a]=o(e),1},update(e,i){if(!$w(e,s))return 0;let n=o(e);return t.compare(n,e.values[a])?0:(e.values[a]=n,1)},reconfigure(e,r){let s=$w(e,n),l=r.config.facets[t.id],c=r.facet(t);if(l&&!s&&kw(i,l))return e.values[a]=c,0;let h=o(e);return t.compare(h,c)?(e.values[a]=c,0):(e.values[a]=h,1)}}}const Aw=Sw.define({static:!0});class Cw{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new Cw(xw++,e.create,e.update,e.compare||((e,t)=>e===t),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Aw).find(e=>e.field==this);return((null==t?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,i)=>{let n=e.values[t],r=this.updateF(n,i);return this.compareF(n,r)?0:(e.values[t]=r,1)},reconfigure:(e,i)=>{let n,r=e.facet(Aw),s=i.facet(Aw);return(n=r.find(e=>e.field==this))&&n!=s.find(e=>e.field==this)?(e.values[t]=n.create(e),1):null!=i.config.address[this.id]?(e.values[t]=i.field(this),0):(e.values[t]=this.create(e),1)}}}init(e){return[this,Aw.of({field:this,create:e})]}get extension(){return this}}const Rw=4,Qw=3,Iw=2,jw=1;function Mw(e){return t=>new Lw(t,e)}const Nw={highest:Mw(0),high:Mw(jw),default:Mw(Iw),low:Mw(Qw),lowest:Mw(Rw)};class Lw{constructor(e,t){this.inner=e,this.prec=t}}class Zw{of(e){return new Dw(this,e)}reconfigure(e){return Zw.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Dw{constructor(e,t){this.compartment=e,this.inner=t}}class zw{constructor(e,t,i,n,r,s){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=s,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return null==t?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],r=Object.create(null),s=new Map;for(let u of function(e,t,i){let n=[[],[],[],[],[]],r=new Map;function s(e,a){let o=r.get(e);if(null!=o){if(o<=a)return;let t=n[o].indexOf(e);t>-1&&n[o].splice(t,1),e instanceof Dw&&i.delete(e.compartment)}if(r.set(e,a),Array.isArray(e))for(let t of e)s(t,a);else if(e instanceof Dw){if(i.has(e.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=t.get(e.compartment)||e.inner;i.set(e.compartment,n),s(n,a)}else if(e instanceof Lw)s(e.inner,e.prec);else if(e instanceof Cw)n[a].push(e),e.provides&&s(e.provides,a);else if(e instanceof Pw)n[a].push(e),e.facet.extensions&&s(e.facet.extensions,Iw);else{let t=e.extension;if(!t)throw new Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(t,a)}}return s(e,Iw),n.reduce((e,t)=>e.concat(t))}(e,t,s))u instanceof Cw?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let a=Object.create(null),o=[],l=[];for(let u of n)a[u.id]=l.length<<1,l.push(e=>u.slot(e));let c=null==i?void 0:i.config.facets;for(let u in r){let e=r[u],t=e[0].facet,n=c&&c[u]||[];if(e.every(e=>0==e.type))if(a[t.id]=o.length<<1|1,kw(n,e))o.push(i.facet(t));else{let n=t.combine(e.map(e=>e.value));o.push(i&&t.compare(n,i.facet(t))?i.facet(t):n)}else{for(let t of e)0==t.type?(a[t.id]=o.length<<1|1,o.push(t.value)):(a[t.id]=l.length<<1,l.push(e=>t.dynamicSlot(e)));a[t.id]=l.length<<1,l.push(i=>Ew(i,t,e))}}let h=l.map(e=>e(a));return new zw(e,s,h,a,o,r)}}function Uw(e,t){if(1&t)return 2;let i=t>>1,n=e.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;e.status[i]=4;let r=e.computeSlot(e,e.config.dynamicSlots[i]);return e.status[i]=2|r}function qw(e,t){return 1&t?e.config.staticValues[t>>1]:e.values[t>>1]}const Xw=Sw.define(),Bw=Sw.define({combine:e=>e.some(e=>e),static:!0}),Ww=Sw.define({combine:e=>e.length?e[0]:void 0,static:!0}),Vw=Sw.define(),Fw=Sw.define(),Yw=Sw.define(),Gw=Sw.define({combine:e=>!!e.length&&e[0]});class Hw{constructor(e,t){this.type=e,this.value=t}static define(){return new Kw}}class Kw{of(e){return new Hw(this,e)}}class Jw{constructor(e){this.map=e}of(e){return new e_(this,e)}}class e_{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return void 0===t?void 0:t==this.value?this:new e_(this.type,t)}is(e){return this.type==e}static define(e={}){return new Jw(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let e=n.map(t);e&&i.push(e)}return i}}e_.reconfigure=e_.define(),e_.appendConfig=e_.define();class t_{constructor(e,t,i,n,r,s){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=s,this._doc=null,this._state=null,i&&_w(i,t.newLength),r.some(e=>e.type==t_.time)||(this.annotations=r.concat(t_.time.of(Date.now())))}static create(e,t,i,n,r,s){return new t_(e,t,i,n,r,s)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(t_.userEvent);return!(!t||!(t==e||t.length>e.length&&t.slice(0,e.length)==e&&"."==t[e.length]))}}function i_(e,t){let i=[];for(let n=0,r=0;;){let s,a;if(n<e.length&&(r==t.length||t[r]>=e[n]))s=e[n++],a=e[n++];else{if(!(r<t.length))return i;s=t[r++],a=t[r++]}!i.length||i[i.length-1]<s?i.push(s,a):i[i.length-1]<a&&(i[i.length-1]=a)}}function n_(e,t,i){var n;let r,s,a;return i?(r=t.changes,s=pw.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),s=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(s):null===(n=e.selection)||void 0===n?void 0:n.map(r),effects:e_.mapEffects(e.effects,r).concat(e_.mapEffects(t.effects,s)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function r_(e,t,i){let n=t.selection,r=o_(t.annotations);return t.userEvent&&(r=r.concat(t_.userEvent.of(t.userEvent))),{changes:t.changes instanceof pw?t.changes:pw.of(t.changes||[],i,e.facet(Ww)),selection:n&&(n instanceof ww?n:ww.single(n.anchor,n.head)),effects:o_(t.effects),annotations:r,scrollIntoView:!!t.scrollIntoView}}function s_(e,t,i){let n=r_(e,t.length?t[0]:{},e.doc.length);t.length&&!1===t[0].filter&&(i=!1);for(let s=1;s<t.length;s++){!1===t[s].filter&&(i=!1);let r=!!t[s].sequential;n=n_(n,r_(e,t[s],r?n.changes.newLength:e.doc.length),r)}let r=t_.create(e,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return function(e){let t=e.startState,i=t.facet(Yw),n=e;for(let r=i.length-1;r>=0;r--){let s=i[r](e);s&&Object.keys(s).length&&(n=n_(n,r_(t,s,e.changes.newLength),!0))}return n==e?e:t_.create(t,e.changes,e.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(e){let t=e.startState,i=!0;for(let r of t.facet(Vw)){let t=r(e);if(!1===t){i=!1;break}Array.isArray(t)&&(i=!0===i?t:i_(i,t))}if(!0!==i){let n,r;if(!1===i)r=e.changes.invertedDesc,n=pw.empty(t.doc.length);else{let t=e.changes.filter(i);n=t.changes,r=t.filtered.mapDesc(t.changes).invertedDesc}e=t_.create(t,n,e.selection&&e.selection.map(r),e_.mapEffects(e.effects,r),e.annotations,e.scrollIntoView)}let n=t.facet(Fw);for(let r=n.length-1;r>=0;r--){let i=n[r](e);e=i instanceof t_?i:Array.isArray(i)&&1==i.length&&i[0]instanceof t_?i[0]:s_(t,o_(i),!1)}return e}(r):r)}t_.time=Hw.define(),t_.userEvent=Hw.define(),t_.addToHistory=Hw.define(),t_.remote=Hw.define();const a_=[];function o_(e){return null==e?a_:Array.isArray(e)?e:[e]}var l_=function(e){return e[e.Word=0]="Word",e[e.Space=1]="Space",e[e.Other=2]="Other",e}(l_||(l_={}));const c_=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let h_;try{h_=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(EM){}function u_(e){return t=>{if(!/\S/.test(t))return l_.Space;if(function(e){if(h_)return h_.test(e);for(let t=0;t<e.length;t++){let i=e[t];if(/\w/.test(i)||i>""&&(i.toUpperCase()!=i.toLowerCase()||c_.test(i)))return!0}return!1}(t))return l_.Word;for(let i=0;i<e.length;i++)if(t.indexOf(e[i])>-1)return l_.Word;return l_.Other}}class d_{constructor(e,t,i,n,r,s){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,s&&(s._state=this);for(let a=0;a<this.config.dynamicSlots.length;a++)Uw(this,a<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(null!=i)return Uw(this,i),qw(this,i);if(t)throw new RangeError("Field is not present in this state")}update(...e){return s_(this,e,!0)}applyTransaction(e){let t,i=this.config,{base:n,compartments:r}=i;for(let a of e.effects)a.is(Zw.reconfigure)?(i&&(r=new Map,i.compartments.forEach((e,t)=>r.set(t,e)),i=null),r.set(a.value.compartment,a.value.extension)):a.is(e_.reconfigure)?(i=null,n=a.value):a.is(e_.appendConfig)&&(i=null,n=o_(n).concat(a.value));if(i)t=e.startState.values.slice();else{i=zw.resolve(n,r,this),t=new d_(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values}let s=e.startState.facet(Bw)?e.newSelection:e.newSelection.asSingle();new d_(i,e.newDoc,s,t,(t,i)=>i.update(t,e),e)}replaceSelection(e){return"string"==typeof e&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:ww.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],s=o_(i.effects);for(let a=1;a<t.ranges.length;a++){let i=e(t.ranges[a]),o=this.changes(i.changes),l=o.map(n);for(let e=0;e<a;e++)r[e]=r[e].map(l);let c=n.mapDesc(o,!0);r.push(i.range.map(c)),n=n.compose(l),s=e_.mapEffects(s,l).concat(e_.mapEffects(o_(i.effects),c))}return{changes:n,selection:ww.create(r,t.mainIndex),effects:s}}changes(e=[]){return e instanceof pw?e:pw.of(e,this.doc.length,this.facet(d_.lineSeparator))}toText(e){return Gb.of(e.split(this.facet(d_.lineSeparator)||hw))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return null==t?e.default:(Uw(this,t),qw(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof Cw&&null!=this.config.address[n.id]&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||"string"!=typeof e.doc)throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i)for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let t=i[r],s=e[r];n.push(t.init(e=>t.spec.fromJSON(s,e)))}return d_.create({doc:e.doc,selection:ww.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=zw.resolve(e.extensions||[],new Map),i=e.doc instanceof Gb?e.doc:Gb.of((e.doc||"").split(t.staticFacet(d_.lineSeparator)||hw)),n=e.selection?e.selection instanceof ww?e.selection:ww.single(e.selection.anchor,e.selection.head):ww.single(0);return _w(n,i.length),t.staticFacet(Bw)||(n=n.asSingle()),new d_(t,i,n,t.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(d_.tabSize)}get lineBreak(){return this.facet(d_.lineSeparator)||"\n"}get readOnly(){return this.facet(Gw)}phrase(e,...t){for(let i of this.facet(d_.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(e,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>t.length?e:t[n-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let r of this.facet(Xw))for(let s of r(this,t,i))Object.prototype.hasOwnProperty.call(s,e)&&n.push(s[e]);return n}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return u_(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),r=this.charCategorizer(e),s=e-i,a=e-i;for(;s>0;){let e=aw(t,s,!1);if(r(t.slice(e,s))!=l_.Word)break;s=e}for(;a<n;){let e=aw(t,a);if(r(t.slice(a,e))!=l_.Word)break;a=e}return s==a?null:ww.range(s+i,a+i)}}function p_(e,t,i={}){let n={};for(let r of e)for(let e of Object.keys(r)){let t=r[e],s=n[e];if(void 0===s)n[e]=t;else if(s===t||void 0===t);else{if(!Object.hasOwnProperty.call(i,e))throw new Error("Config merge conflict for field "+e);n[e]=i[e](s,t)}}for(let r in t)void 0===n[r]&&(n[r]=t[r]);return n}d_.allowMultipleSelections=Bw,d_.tabSize=Sw.define({combine:e=>e.length?e[0]:4}),d_.lineSeparator=Ww,d_.readOnly=Gw,d_.phrases=Sw.define({compare(e,t){let i=Object.keys(e),n=Object.keys(t);return i.length==n.length&&i.every(i=>e[i]==t[i])}}),d_.languageData=Xw,d_.changeFilter=Vw,d_.transactionFilter=Fw,d_.transactionExtender=Yw,Zw.reconfigure=e_.define();class f_{eq(e){return this==e}range(e,t=e){return g_.create(e,t,this)}}function m_(e,t){return e==t||e.constructor==t.constructor&&e.eq(t)}f_.prototype.startSide=f_.prototype.endSide=0,f_.prototype.point=!1,f_.prototype.mapMode=uw.TrackDel;let g_=class e{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(t,i,n){return new e(t,i,n)}};function O_(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}class v_{constructor(e,t,i,n){this.from=e,this.to=t,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,n=0){let r=i?this.to:this.from;for(let s=n,a=r.length;;){if(s==a)return s;let n=s+a>>1,o=r[n]-e||(i?this.value[n].endSide:this.value[n].startSide)-t;if(n==s)return o>=0?s:a;o>=0?a=n:s=n+1}}between(e,t,i,n){for(let r=this.findIndex(t,-1e9,!0),s=this.findIndex(i,1e9,!1,r);r<s;r++)if(!1===n(this.from[r]+e,this.to[r]+e,this.value[r]))return!1}map(e,t){let i=[],n=[],r=[],s=-1,a=-1;for(let o=0;o<this.value.length;o++){let l,c,h=this.value[o],u=this.from[o]+e,d=this.to[o]+e;if(u==d){let e=t.mapPos(u,h.startSide,h.mapMode);if(null==e)continue;if(l=c=e,h.startSide!=h.endSide&&(c=t.mapPos(u,h.endSide),c<l))continue}else if(l=t.mapPos(u,h.startSide),c=t.mapPos(d,h.endSide),l>c||l==c&&h.startSide>0&&h.endSide<=0)continue;(c-l||h.endSide-h.startSide)<0||(s<0&&(s=l),h.point&&(a=Math.max(a,c-l)),i.push(h),n.push(l-s),r.push(c-s))}return{mapped:i.length?new v_(n,r,i,a):null,pos:s}}}class y_{constructor(e,t,i,n){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=n}static create(e,t,i,n){return new y_(e,t,i,n)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:n=0,filterTo:r=this.length}=e,s=e.filter;if(0==t.length&&!s)return this;if(i&&(t=t.slice().sort(O_)),this.isEmpty)return t.length?y_.of(t):this;let a=new __(this,null,-1).goto(0),o=0,l=[],c=new b_;for(;a.value||o<t.length;)if(o<t.length&&(a.from-t[o].from||a.startSide-t[o].value.startSide)>=0){let e=t[o++];c.addInner(e.from,e.to,e.value)||l.push(e)}else 1==a.rangeIndex&&a.chunkIndex<this.chunk.length&&(o==t.length||this.chunkEnd(a.chunkIndex)<t[o].from)&&(!s||n>this.chunkEnd(a.chunkIndex)||r<this.chunkPos[a.chunkIndex])&&c.addChunk(this.chunkPos[a.chunkIndex],this.chunk[a.chunkIndex])?a.nextChunk():((!s||n>a.to||r<a.from||s(a.from,a.to,a.value))&&(c.addInner(a.from,a.to,a.value)||l.push(g_.create(a.from,a.to,a.value))),a.next());return c.finishInner(this.nextLayer.isEmpty&&!l.length?y_.empty:this.nextLayer.update({add:l,filter:s,filterFrom:n,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],a=this.chunk[s],o=e.touchesRange(r,r+a.length);if(!1===o)n=Math.max(n,a.maxPoint),t.push(a),i.push(e.mapPos(r));else if(!0===o){let{mapped:s,pos:o}=a.map(r,e);s&&(n=Math.max(n,s.maxPoint),t.push(s),i.push(o))}}let r=this.nextLayer.map(e);return 0==t.length?r:new y_(i,t,r||y_.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],s=this.chunk[n];if(t>=r&&e<=r+s.length&&!1===s.between(r,e-r,t-r,i))return}this.nextLayer.between(e,t,i)}}iter(e=0){return x_.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return x_.from(e).goto(t)}static compare(e,t,i,n,r=-1){let s=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=r),a=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=r),o=w_(s,a,i),l=new k_(s,o,r),c=new k_(a,o,r);i.iterGaps((e,t,i)=>P_(l,e,c,t,i,n)),i.empty&&0==i.length&&P_(l,0,c,0,0,n)}static eq(e,t,i=0,n){null==n&&(n=999999999);let r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(r.length!=s.length)return!1;if(!r.length)return!0;let a=w_(r,s),o=new k_(r,a,0).goto(i),l=new k_(s,a,0).goto(i);for(;;){if(o.to!=l.to||!T_(o.active,l.active)||o.point&&(!l.point||!m_(o.point,l.point)))return!1;if(o.to>n)return!0;o.next(),l.next()}}static spans(e,t,i,n,r=-1){let s=new k_(e,null,r).goto(t),a=t,o=s.openStart;for(;;){let e=Math.min(s.to,i);if(s.point){let i=s.activeForPoint(s.to),r=s.pointFrom<t?i.length+1:s.point.startSide<0?i.length:Math.min(i.length,o);n.point(a,e,s.point,i,r,s.pointRank),o=Math.min(s.openEnd(e),i.length)}else e>a&&(n.span(a,e,s.active,o),o=s.openEnd(e));if(s.to>i)return o+(s.point&&s.to>i?1:0);a=s.to,s.next()}}static of(e,t=!1){let i=new b_;for(let n of e instanceof g_?[e]:t?function(e){if(e.length>1)for(let t=e[0],i=1;i<e.length;i++){let n=e[i];if(O_(t,n)>0)return e.slice().sort(O_);t=n}return e}(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return y_.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=y_.empty;n=n.nextLayer)t=new y_(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}y_.empty=new y_([],[],null,-1),y_.empty.nextLayer=y_.empty;class b_{finishChunk(e){this.chunks.push(new v_(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new b_)).add(e,t,i)}addInner(e,t,i){let n=e-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(y_.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return e;let t=y_.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function w_(e,t,i){let n=new Map;for(let s of e)for(let e=0;e<s.chunk.length;e++)s.chunk[e].maxPoint<=0&&n.set(s.chunk[e],s.chunkPos[e]);let r=new Set;for(let s of t)for(let e=0;e<s.chunk.length;e++){let t=n.get(s.chunk[e]);null==t||(i?i.mapPos(t):t)!=s.chunkPos[e]||(null==i?void 0:i.touchesRange(t,t+s.chunk[e].length))||r.add(s.chunk[e])}return r}class __{constructor(e,t,i,n=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let t=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(t)||this.layer.chunkEnd(this.chunkIndex)<e||t.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class x_{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let r=0;r<e.length;r++)for(let s=e[r];!s.isEmpty;s=s.nextLayer)s.maxPoint>=i&&n.push(new __(s,t,i,r));return 1==n.length?n[0]:new x_(n)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)S_(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)S_(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),S_(this.heap,0)}}}function S_(e,t){for(let i=e[t];;){let n=1+(t<<1);if(n>=e.length)break;let r=e[n];if(n+1<e.length&&r.compare(e[n+1])>=0&&(r=e[n+1],n++),i.compare(r)<0)break;e[n]=i,e[t]=r,t=n}}class k_{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=x_.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){$_(this.active,e),$_(this.activeTo,e),$_(this.activeRank,e),this.minActive=A_(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||n-this.activeTo[t])>0;)t++;E_(this.active,t,i),E_(this.activeTo,t,n),E_(this.activeRank,t,r),e&&E_(e,t,this.cursor.from),this.minActive=A_(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&$_(i,n)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let e=this.cursor.value;if(e.point){if(!(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){this.point=e,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=e.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}this.cursor.next()}else this.addActive(i),this.cursor.next()}}}if(i){this.openStart=0;for(let t=i.length-1;t>=0&&i[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function P_(e,t,i,n,r,s){e.goto(t),i.goto(n);let a=n+r,o=n,l=n-t,c=!!s.boundChange;for(let h=!1;;){let t=e.to+l-i.to,n=t||e.endSide-i.endSide,r=n<0?e.to+l:i.to,u=Math.min(r,a);if(e.point||i.point?(e.point&&i.point&&m_(e.point,i.point)&&T_(e.activeForPoint(e.to),i.activeForPoint(i.to))||s.comparePoint(o,u,e.point,i.point),h=!1):(h&&s.boundChange(o),u>o&&!T_(e.active,i.active)&&s.compareRange(o,u,e.active,i.active),c&&u<a&&(t||e.openEnd(r)!=i.openEnd(r))&&(h=!0)),r>a)break;o=r,n<=0&&e.next(),n>=0&&i.next()}}function T_(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(e[i]!=t[i]&&!m_(e[i],t[i]))return!1;return!0}function $_(e,t){for(let i=t,n=e.length-1;i<n;i++)e[i]=e[i+1];e.pop()}function E_(e,t,i){for(let n=e.length-1;n>=t;n--)e[n+1]=e[n];e[t]=i}function A_(e,t){let i=-1,n=1e9;for(let r=0;r<t.length;r++)(t[r]-n||e[r].endSide-e[i].endSide)<0&&(i=r,n=t[r]);return i}function C_(e,t,i=e.length){let n=0;for(let r=0;r<i&&r<e.length;)9==e.charCodeAt(r)?(n+=t-n%t,r++):(n++,r=aw(e,r));return n}const R_="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Q_="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),I_="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class j_{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function r(e,t,s,a){let o=[],l=/^@(\w+)\b/.exec(e[0]),c=l&&"keyframes"==l[1];if(l&&null==t)return s.push(e[0]+";");for(let i in t){let a=t[i];if(/&/.test(i))r(i.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),a,s);else if(a&&"object"==typeof a){if(!l)throw new RangeError("The value of a property ("+i+") should be a primitive value.");r(n(i),a,o,c)}else null!=a&&o.push(i.replace(/_.*/,"").replace(/[A-Z]/g,e=>"-"+e.toLowerCase())+": "+a+";")}(o.length||c)&&s.push((!i||l||a?e:e.map(i)).join(", ")+" {"+o.join(" ")+"}")}for(let s in e)r(n(s),e[s],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let e=I_[R_]||1;return I_[R_]=e+1,"ͼ"+e.toString(36)}static mount(e,t,i){let n=e[Q_],r=i&&i.nonce;n?r&&n.setNonce(r):n=new N_(e,r),n.mount(Array.isArray(t)?t:[t],e)}}let M_=new Map;class N_{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let t=M_.get(i);if(t)return e[Q_]=t;this.sheet=new n.CSSStyleSheet,M_.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[Q_]=this}mount(e,t){let i=this.sheet,n=0,r=0;for(let s=0;s<e.length;s++){let t=e[s],a=this.modules.indexOf(t);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),-1==a){if(this.modules.splice(r++,0,t),i)for(let e=0;e<t.rules.length;e++)i.insertRule(t.rules[e],n++)}else{for(;r<a;)n+=this.modules[r++].rules.length;n+=t.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let e="";for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+"\n";this.styleTag.textContent=e;let i=t.head||t;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}for(var L_={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Z_={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},D_="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),z_="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),U_=0;U_<10;U_++)L_[48+U_]=L_[96+U_]=String(U_);for(U_=1;U_<=24;U_++)L_[U_+111]="F"+U_;for(U_=65;U_<=90;U_++)L_[U_]=String.fromCharCode(U_+32),Z_[U_]=String.fromCharCode(U_);for(var q_ in L_)Z_.hasOwnProperty(q_)||(Z_[q_]=L_[q_]);function X_(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var r=i[n];"string"==typeof r?e.setAttribute(n,r):null!=r&&(e[n]=r)}t++}for(;t<arguments.length;t++)B_(e,arguments[t]);return e}function B_(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var i=0;i<t.length;i++)B_(e,t[i])}}let W_="undefined"!=typeof navigator?navigator:{userAgent:"",vendor:"",platform:""},V_="undefined"!=typeof document?document:{documentElement:{style:{}}};const F_=/Edge\/(\d+)/.exec(W_.userAgent),Y_=/MSIE \d/.test(W_.userAgent),G_=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(W_.userAgent),H_=!!(Y_||G_||F_),K_=!H_&&/gecko\/(\d+)/i.test(W_.userAgent),J_=!H_&&/Chrome\/(\d+)/.exec(W_.userAgent),ex="webkitFontSmoothing"in V_.documentElement.style,tx=!H_&&/Apple Computer/.test(W_.vendor),ix=tx&&(/Mobile\/\w+/.test(W_.userAgent)||W_.maxTouchPoints>2);var nx={mac:ix||/Mac/.test(W_.platform),windows:/Win/.test(W_.platform),linux:/Linux|X11/.test(W_.platform),ie:H_,ie_version:Y_?V_.documentMode||6:G_?+G_[1]:F_?+F_[1]:0,gecko:K_,gecko_version:K_?+(/Firefox\/(\d+)/.exec(W_.userAgent)||[0,0])[1]:0,chrome:!!J_,chrome_version:J_?+J_[1]:0,ios:ix,android:/Android\b/.test(W_.userAgent),webkit:ex,webkit_version:ex?+(/\bAppleWebKit\/(\d+)/.exec(W_.userAgent)||[0,0])[1]:0,safari:tx,safari_version:tx?+(/\bVersion\/(\d+(\.\d+)?)/.exec(W_.userAgent)||[0,0])[1]:0,tabSize:null!=V_.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function rx(e,t){for(let i in e)"class"==i&&t.class?t.class+=" "+e.class:"style"==i&&t.style?t.style+=";"+e.style:t[i]=e[i];return t}const sx=Object.create(null);function ax(e,t,i){if(e==t)return!0;e||(e=sx),t||(t=sx);let n=Object.keys(e),r=Object.keys(t);if(n.length-0!=r.length-0)return!1;for(let s of n)if(s!=i&&(-1==r.indexOf(s)||e[s]!==t[s]))return!1;return!0}function ox(e,t,i){let n=!1;if(t)for(let r in t)i&&r in i||(n=!0,"style"==r?e.style.cssText="":e.removeAttribute(r));if(i)for(let r in i)t&&t[r]==i[r]||(n=!0,"style"==r?e.style.cssText=i[r]:e.setAttribute(r,i[r]));return n}function lx(e){let t=Object.create(null);for(let i=0;i<e.attributes.length;i++){let n=e.attributes[i];t[n.name]=n.value}return t}class cx{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var hx=function(e){return e[e.Text=0]="Text",e[e.WidgetBefore=1]="WidgetBefore",e[e.WidgetAfter=2]="WidgetAfter",e[e.WidgetRange=3]="WidgetRange",e}(hx||(hx={}));class ux extends f_{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new dx(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new fx(e,t,t,i,e.widget||null,!1)}static replace(e){let t,i,n=!!e.block;if(e.isBlockGap)t=-5e8,i=4e8;else{let{start:r,end:s}=mx(e,n);t=(r?n?-3e8:-1:5e8)-1,i=1+(s?n?2e8:1:-6e8)}return new fx(e,t,i,n,e.widget||null,!0)}static line(e){return new px(e)}static set(e,t=!1){return y_.of(e,t)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ux.none=y_.empty;class dx extends ux{constructor(e){let{start:t,end:i}=mx(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?rx(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||sx}eq(e){return this==e||e instanceof dx&&this.tagName==e.tagName&&ax(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}dx.prototype.point=!1;class px extends ux{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof px&&this.spec.class==e.spec.class&&ax(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}px.prototype.mapMode=uw.TrackBefore,px.prototype.point=!0;class fx extends ux{constructor(e,t,i,n,r,s){super(t,i,r,e),this.block=n,this.isReplace=s,this.mapMode=n?t<=0?uw.TrackBefore:uw.TrackAfter:uw.TrackDel}get type(){return this.startSide!=this.endSide?hx.WidgetRange:this.startSide<=0?hx.WidgetBefore:hx.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof fx&&(t=this.widget,i=e.widget,t==i||!!(t&&i&&t.compare(i)))&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide;var t,i}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}function mx(e,t=!1){let{inclusiveStart:i,inclusiveEnd:n}=e;return null==i&&(i=e.inclusive),null==n&&(n=e.inclusive),{start:null!=i?i:t,end:null!=n?n:t}}function gx(e,t,i,n=0){let r=i.length-1;r>=0&&i[r]+n>=e?i[r]=Math.max(i[r],t):i.push(e,t)}fx.prototype.point=!0;class Ox extends f_{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof Ox&&this.tagName==e.tagName&&ax(this.attributes,e.attributes)}static create(e){return new Ox(e.tagName,e.attributes||sx)}static set(e,t=!1){return y_.of(e,t)}}function vx(e){let t;return t=11==e.nodeType?e.getSelection?e:e.ownerDocument:e,t.getSelection()}function yx(e,t){return!!t&&(e==t||e.contains(1!=t.nodeType?t.parentNode:t))}function bx(e,t){if(!t.anchorNode)return!1;try{return yx(e,t.anchorNode)}catch(EM){return!1}}function wx(e){return 3==e.nodeType?jx(e,0,e.nodeValue.length).getClientRects():1==e.nodeType?e.getClientRects():[]}function _x(e,t,i,n){return!!i&&(kx(e,t,i,n,-1)||kx(e,t,i,n,1))}function xx(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t}function Sx(e){return 1==e.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}function kx(e,t,i,n,r){for(;;){if(e==i&&t==n)return!0;if(t==(r<0?0:Px(e))){if("DIV"==e.nodeName)return!1;let i=e.parentNode;if(!i||1!=i.nodeType)return!1;t=xx(e)+(r<0?0:1),e=i}else{if(1!=e.nodeType)return!1;if(1==(e=e.childNodes[t+(r<0?-1:0)]).nodeType&&"false"==e.contentEditable)return!1;t=r<0?Px(e):0}}}function Px(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Tx(e,t){let i=t?e.left:e.right;return{left:i,right:i,top:e.top,bottom:e.bottom}}function $x(e){let t=e.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.innerWidth,top:0,bottom:e.innerHeight}}function Ex(e,t){let i=t.width/e.offsetWidth,n=t.height/e.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.width-e.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(t.height-e.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}function Ax(e,t=!0){let i=e.ownerDocument,n=null,r=null;for(let s=e.parentNode;s&&(s!=i.body&&(t&&!n||!r));)if(1==s.nodeType)!r&&s.scrollHeight>s.clientHeight&&(r=s),t&&!n&&s.scrollWidth>s.clientWidth&&(n=s),s=s.assignedSlot||s.parentNode;else{if(11!=s.nodeType)break;s=s.host}return{x:n,y:r}}Ox.prototype.startSide=Ox.prototype.endSide=-1;class Cx{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Px(t):0),i,Math.min(e.focusOffset,i?Px(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let Rx,Qx=null;function Ix(e){if(e.setActive)return e.setActive();if(Qx)return e.focus(Qx);let t=[];for(let i=e;i&&(t.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(e.focus(null==Qx?{get preventScroll(){return Qx={preventScroll:!0},!0}}:void 0),!Qx){Qx=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}function jx(e,t,i=t){let n=Rx||(Rx=document.createRange());return n.setEnd(e,i),n.setStart(e,t),n}function Mx(e,t,i,n){let r={key:t,code:t,keyCode:i,which:i,cancelable:!0};n&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=n);let s=new KeyboardEvent("keydown",r);s.synthetic=!0,e.dispatchEvent(s);let a=new KeyboardEvent("keyup",r);return a.synthetic=!0,e.dispatchEvent(a),s.defaultPrevented||a.defaultPrevented}function Nx(e){return e instanceof Window?e.pageYOffset>Math.max(0,e.document.documentElement.scrollHeight-e.innerHeight-4):e.scrollTop>Math.max(1,e.scrollHeight-e.clientHeight-4)}function Lx(e,t){for(let i=e,n=t;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=Px(i)}else{if(!i.parentNode||Sx(i))return null;n=xx(i),i=i.parentNode}}}function Zx(e,t){for(let i=e,n=t;;){if(3==i.nodeType&&n<i.nodeValue.length)return{node:i,offset:n};if(1==i.nodeType&&n<i.childNodes.length){if("false"==i.contentEditable)return null;i=i.childNodes[n],n=0}else{if(!i.parentNode||Sx(i))return null;n=xx(i)+1,i=i.parentNode}}}nx.safari&&nx.safari_version>=26&&(Qx=!1);class Dx{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Dx(e.parentNode,xx(e),t)}static after(e,t){return new Dx(e.parentNode,xx(e)+1,t)}}var zx=function(e){return e[e.LTR=0]="LTR",e[e.RTL=1]="RTL",e}(zx||(zx={}));const Ux=zx.LTR,qx=zx.RTL;function Xx(e){let t=[];for(let i=0;i<e.length;i++)t.push(1<<+e[i]);return t}const Bx=Xx("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Wx=Xx("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Vx=Object.create(null),Fx=[];for(let AM of["()","[]","{}"]){let e=AM.charCodeAt(0),t=AM.charCodeAt(1);Vx[e]=t,Vx[t]=-e}function Yx(e){return e<=247?Bx[e]:1424<=e&&e<=1524?2:1536<=e&&e<=1785?Wx[e-1536]:1774<=e&&e<=2220?4:8192<=e&&e<=8204?256:64336<=e&&e<=65023?4:1}const Gx=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Hx{get dir(){return this.level%2?qx:Ux}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let s=0;s<e.length;s++){let a=e[s];if(a.from<=t&&a.to>=t){if(a.level==i)return s;(r<0||(0!=n?n<0?a.from<t:a.to>t:e[r].level>a.level))&&(r=s)}}if(r<0)throw new RangeError("Index out of range");return r}}function Kx(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.direction!=r.direction||!Kx(n.inner,r.inner))return!1}return!0}const Jx=[];function eS(e,t,i,n,r,s,a){let o=n%2?2:1;if(n%2==r%2)for(let l=t,c=0;l<i;){let t=!0,h=!1;if(c==s.length||l<s[c].from){let e=Jx[l];e!=o&&(t=!1,h=16==e)}let u=t||1!=o?null:[],d=t?n:n+1,p=l;e:for(;;)if(c<s.length&&p==s[c].from){if(h)break e;let f=s[c];if(!t)for(let e=f.to,t=c+1;;){if(e==i)break e;if(!(t<s.length&&s[t].from==e)){if(Jx[e]==o)break e;break}e=s[t++].to}if(c++,u)u.push(f);else{f.from>l&&a.push(new Hx(l,f.from,d)),tS(e,f.direction==Ux!=!(d%2)?n+1:n,r,f.inner,f.from,f.to,a),l=f.to}p=f.to}else{if(p==i||(t?Jx[p]!=o:Jx[p]==o))break;p++}u?eS(e,l,p,n+1,r,u,a):l<p&&a.push(new Hx(l,p,d)),l=p}else for(let l=i,c=s.length;l>t;){let i=!0,h=!1;if(!c||l>s[c-1].to){let e=Jx[l-1];e!=o&&(i=!1,h=16==e)}let u=i||1!=o?null:[],d=i?n:n+1,p=l;e:for(;;)if(c&&p==s[c-1].to){if(h)break e;let f=s[--c];if(!i)for(let e=f.from,i=c;;){if(e==t)break e;if(!i||s[i-1].to!=e){if(Jx[e-1]==o)break e;break}e=s[--i].from}if(u)u.push(f);else{f.to<l&&a.push(new Hx(f.to,l,d)),tS(e,f.direction==Ux!=!(d%2)?n+1:n,r,f.inner,f.from,f.to,a),l=f.from}p=f.from}else{if(p==t||(i?Jx[p-1]!=o:Jx[p-1]==o))break;p--}u?eS(e,p,l,n+1,r,u,a):p<l&&a.push(new Hx(p,l,d)),l=p}}function tS(e,t,i,n,r,s,a){let o=t%2?2:1;!function(e,t,i,n,r){for(let s=0;s<=n.length;s++){let a=s?n[s-1].to:t,o=s<n.length?n[s].from:i,l=s?256:r;for(let t=a,i=l,n=l;t<o;t++){let r=Yx(e.charCodeAt(t));512==r?r=i:8==r&&4==n&&(r=16),Jx[t]=4==r?2:r,7&r&&(n=r),i=r}for(let e=a,t=l,n=l;e<o;e++){let r=Jx[e];if(128==r)e<o-1&&t==Jx[e+1]&&24&t?r=Jx[e]=t:Jx[e]=256;else if(64==r){let r=e+1;for(;r<o&&64==Jx[r];)r++;let s=e&&8==t||r<i&&8==Jx[r]?1==n?1:8:256;for(let t=e;t<r;t++)Jx[t]=s;e=r-1}else 8==r&&1==n&&(Jx[e]=1);t=r,7&r&&(n=r)}}}(e,r,s,n,o),function(e,t,i,n,r){let s=1==r?2:1;for(let a=0,o=0,l=0;a<=n.length;a++){let c=a?n[a-1].to:t,h=a<n.length?n[a].from:i;for(let t,i,n,a=c;a<h;a++)if(i=Vx[t=e.charCodeAt(a)])if(i<0){for(let e=o-3;e>=0;e-=3)if(Fx[e+1]==-i){let t=Fx[e+2],i=2&t?r:4&t?1&t?s:r:0;i&&(Jx[a]=Jx[Fx[e]]=i),o=e;break}}else{if(189==Fx.length)break;Fx[o++]=a,Fx[o++]=t,Fx[o++]=l}else if(2==(n=Jx[a])||1==n){let e=n==r;l=e?0:1;for(let t=o-3;t>=0;t-=3){let i=Fx[t+2];if(2&i)break;if(e)Fx[t+2]|=2;else{if(4&i)break;Fx[t+2]|=4}}}}}(e,r,s,n,o),function(e,t,i,n){for(let r=0,s=n;r<=i.length;r++){let a=r?i[r-1].to:e,o=r<i.length?i[r].from:t;for(let l=a;l<o;){let a=Jx[l];if(256==a){let a=l+1;for(;;)if(a==o){if(r==i.length)break;a=i[r++].to,o=r<i.length?i[r].from:t}else{if(256!=Jx[a])break;a++}let c=1==s,h=c==(1==(a<t?Jx[a]:n))?c?1:2:n;for(let t=a,n=r,s=n?i[n-1].to:e;t>l;)t==s&&(t=i[--n].from,s=n?i[n-1].to:e),Jx[--t]=h;l=a}else s=a,l++}}}(r,s,n,o),eS(e,r,s,t,i,n,a)}function iS(e){return[new Hx(0,e,0)]}let nS="";function rS(e,t,i,n,r){var s;let a=n.head-e.from,o=Hx.find(t,a,null!==(s=n.bidiLevel)&&void 0!==s?s:-1,n.assoc),l=t[o],c=l.side(r,i);if(a==c){let e=o+=r?1:-1;if(e<0||e>=t.length)return null;l=t[o=e],a=l.side(!r,i),c=l.side(r,i)}let h=aw(e.text,a,l.forward(r,i));(h<l.from||h>l.to)&&(h=c),nS=e.text.slice(Math.min(a,h),Math.max(a,h));let u=o==(r?t.length-1:0)?null:t[o+(r?1:-1)];return u&&h==c&&u.level+(r?0:1)<l.level?ww.cursor(u.side(!r,i)+e.from,u.forward(r,i)?1:-1,u.level):ww.cursor(h+e.from,l.forward(r,i)?-1:1,l.level)}function sS(e,t,i){for(let n=t;n<i;n++){let t=Yx(e.charCodeAt(n));if(1==t)return Ux;if(2==t||4==t)return qx}return Ux}const aS=Sw.define(),oS=Sw.define(),lS=Sw.define(),cS=Sw.define(),hS=Sw.define(),uS=Sw.define(),dS=Sw.define(),pS=Sw.define(),fS=Sw.define(),mS=Sw.define({combine:e=>e.some(e=>e)}),gS=Sw.define({combine:e=>e.some(e=>e)}),OS=Sw.define();class vS{constructor(e,t,i,n,r,s=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=s}map(e){return e.empty?this:new vS(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new vS(ww.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const yS=e_.define({map:(e,t)=>e.map(t)}),bS=e_.define();function wS(e,t,i){let n=e.facet(cS);n.length?n[0](t):window.onerror&&window.onerror(String(t),i,void 0,void 0,t)}const _S=Sw.define({combine:e=>!e.length||e[0]});let xS=0;const SS=Sw.define({combine:e=>e.filter((t,i)=>{for(let n=0;n<i;n++)if(e[n].plugin==t.plugin)return!1;return!0})});class kS{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(SS.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(SS.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:s}=t||{};return new kS(xS++,e,i,n,e=>{let t=[];return s&&t.push(ES.of(t=>{let i=t.plugin(e);return i?s(i):ux.none})),r&&t.push(r(e)),t})}static fromClass(e,t){return kS.define((t,i)=>new e(t,i),t)}}class PS{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(wS(e.state,t,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(EM){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){wS(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(null===(t=this.value)||void 0===t?void 0:t.destroy)try{this.value.destroy()}catch(i){wS(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const TS=Sw.define(),$S=Sw.define(),ES=Sw.define(),AS=Sw.define(),CS=Sw.define(),RS=Sw.define(),QS=Sw.define();function IS(e,t){let i=e.state.facet(QS);if(!i.length)return i;let n=i.map(t=>t instanceof Function?t(e):t),r=[];return y_.spans(n,t.from,t.to,{point(){},span(e,i,n,s){let a=e-t.from,o=i-t.from,l=r;for(let r=n.length-1;r>=0;r--,s--){let e,i=n[r].spec.bidiIsolate;if(null==i&&(i=sS(t.text,a,o)),s>0&&l.length&&(e=l[l.length-1]).to==a&&e.direction==i)e.to=o,l=e.inner;else{let e={from:a,to:o,direction:i,inner:[]};l.push(e),l=e.inner}}}}),r}const jS=Sw.define();function MS(e){let t=0,i=0,n=0,r=0;for(let s of e.state.facet(jS)){let a=s(e);a&&(null!=a.left&&(t=Math.max(t,a.left)),null!=a.right&&(i=Math.max(i,a.right)),null!=a.top&&(n=Math.max(n,a.top)),null!=a.bottom&&(r=Math.max(r,a.bottom)))}return{left:t,right:i,top:n,bottom:r}}const NS=Sw.define();class LS{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new LS(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(0==t.length)return e;let i=[];for(let n=0,r=0,s=0;;){let a=n<e.length?e[n].fromB:1e9,o=r<t.length?t[r]:1e9,l=Math.min(a,o);if(1e9==l)break;let c=l+s,h=l,u=c;for(;;)if(r<t.length&&t[r]<=h){let i=t[r+1];r+=2,h=Math.max(h,i);for(let t=n;t<e.length&&e[t].fromB<=h;t++)s=e[t].toA-e[t].toB;u=Math.max(u,i+s)}else{if(!(n<e.length&&e[n].fromB<=h))break;{let t=e[n++];h=Math.max(h,t.toB),u=Math.max(u,t.toA),s=t.toA-t.toB}}i.push(new LS(c,u,l,h))}return i}}class ZS{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=pw.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((e,t,i,r)=>n.push(new LS(e,t,i,r))),this.changedRanges=n}static create(e,t,i){return new ZS(e,t,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}const DS=[];class zS{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return 1&this.flags}get children(){return DS}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,4&this.flags){this.flags&=-5;let e=this.domAttrs;e&&function(e,t){for(let i=e.attributes.length-1;i>=0;i--){let n=e.attributes[i].name;null==t[n]&&e.removeAttribute(n)}for(let i in t){let n=t[i];"style"==i?e.style.cssText=n:e.getAttribute(i)!=n&&e.setAttribute(i,n)}}(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let n of this.children){if(n==e)return i;i+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=xx(this.dom),n=this.length?e>0:t>0;return new Dx(this.parent.dom,i+(n?1:0),0==e||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&2&this.parent.flags&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof XS)return e;return null}static get(e){return e.cmTile}}class US extends zS{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(2&this.flags)return;super.sync(e);let t,i=this.dom,n=null,r=(null==e?void 0:e.node)==i?e:null,s=0;for(let a of this.children){if(a.sync(e),s+=a.length+a.breakAfter,t=n?n.nextSibling:i.firstChild,r&&t!=a.dom&&(r.written=!0),a.dom.parentNode==i)for(;t&&t!=a.dom;)t=qS(t);else i.insertBefore(a.dom,t);n=a.dom}for(t=n?n.nextSibling:i.firstChild,r&&t&&(r.written=!0);t;)t=qS(t);this.length=s}}function qS(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class XS extends US{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=zS.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let s=i.children[n++];if(s instanceof BS)t.push(n),i=s,n=0;else{let t=r+s.length,i=e(s,r);if(void 0!==i)return i;r=t+s.breakAfter}}}resolveBlock(e,t){let i,n,r=-1,s=-1;if(this.blockTiles((a,o)=>{let l=o+a.length;if(e>=o&&e<=l){if(a.isWidget()&&t>=-1&&t<=1){if(32&a.flags)return!0;16&a.flags&&(i=void 0)}(o<e||e==l&&(t<-1?a.length:a.covers(1)))&&(!i||!a.isWidget()&&i.isWidget())&&(i=a,r=e-o),(l>e||e==o&&(t>1?a.length:a.covers(-1)))&&(!n||!a.isWidget()&&n.isWidget())&&(n=a,s=e-o)}}),!i&&!n)throw new Error("No tile at position "+e);return i&&t<0||!n?{tile:i,offset:r}:{tile:n,offset:s}}}class BS extends US{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return!!this.children.length&&(e<0?this.children[0].covers(-1):this.lastChild.covers(1))}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new BS(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class WS extends US{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new WS(t||document.createElement("div"),e);return t&&i||(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(e,t,i){let n=null,r=-1,s=null,a=-1;!function e(o,l){for(let c=0,h=0;c<o.children.length&&h<=l;c++){let u=o.children[c],d=h+u.length;d>=l&&(u.isComposite()?e(u,l-h):(!s||s.isHidden&&(t>0||i&&VS(s,u)))&&(d>l||32&u.flags)?(s=u,a=l-h):(h<l||16&u.flags&&!u.isHidden)&&(n=u,r=l-h)),h=d}}(this,e);let o=(t<0?n:s)||n||s;return o?{tile:o,offset:o==n?r:a}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):function(e){let t=e.dom.lastChild;if(!t)return e.dom.getBoundingClientRect();let i=wx(t);return i[i.length-1]||null}(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:e,offset:n}=i;if(this.dom.contains(e.dom))return e.isText()?new Dx(e.dom,Math.min(e.dom.nodeValue.length,n)):e.domPosFor(n,16&e.flags?1:32&e.flags?-1:t);let r=i.tile.parent,s=!1;for(let t of r.children){if(s)return new Dx(t.dom,0);t==i.tile&&(s=!0)}}return new Dx(this.dom,0)}}function VS(e,t){let i=e.coordsIn(0,1),n=t.coordsIn(0,1);return i&&n&&n.top<i.bottom}class FS extends US{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new FS(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class YS extends zS{constructor(e,t){super(e,t.length),this.text=t}sync(e){2&this.flags||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let n=e,r=e,s=0;0==e&&t<0||e==i&&t>=0?nx.chrome||nx.gecko||(e?(n--,s=1):r<i&&(r++,s=-1)):t<0?n--:r<i&&r++;let a=jx(this.dom,n,r).getClientRects();if(!a.length)return null;let o=a[(s?s<0:t>=0)?0:a.length-1];return nx.safari&&!s&&0==o.width&&(o=Array.prototype.find.call(a,e=>e.width)||o),s?Tx(o,s<0):o||null}static of(e,t){let i=new YS(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class GS extends zS{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return!(48&this.flags)&&(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return Tx(this.dom.getBoundingClientRect(),this.length?0==e:t<=0);{let t=this.dom.getClientRects(),i=null;if(!t.length)return null;let n=!!(16&this.flags)||!(32&this.flags)&&e>0;for(let r=n?t.length-1:0;i=t[r],!(e>0?0==r:r==t.length-1||i.top<i.bottom);r+=n?-1:1);return Tx(i,!n)}}get overrideDOMText(){if(!this.length)return Gb.empty;let{root:e}=this;if(!e)return Gb.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,n,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new GS(r,i,e,n)}}class HS extends zS{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return Gb.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class KS{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:n,index:r,beforeBreak:s,parents:a}=this;for(;e||t>0;)if(n.isComposite())if(s){if(!e)break;i&&i.break(),e--,s=!1}else if(r==n.children.length){if(!e&&!a.length)break;i&&i.leave(n),s=!!n.breakAfter,({tile:n,index:r}=a.pop()),r++}else{let o=n.children[r],l=o.breakAfter;!(t>0?o.length<=e:o.length<e)||i&&!1===i.skip(o,0,o.length)&&o.isComposite?(a.push({tile:n,index:r}),n=o,r=0,i&&o.isComposite()&&i.enter(o)):(s=!!l,r++,e-=o.length)}else if(r==n.length)s=!!n.breakAfter,({tile:n,index:r}=a.pop()),r++;else{if(!e)break;{let t=Math.min(e,n.length-r);i&&i.skip(n,r,r+t),e-=t,r+=t}}return this.tile=n,this.index=r,this.beforeBreak=s,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class JS{constructor(e,t,i,n){this.from=e,this.to=t,this.wrapper=i,this.rank=n}}class ek{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,n){var r;this.flushBuffer();let s=this.ensureMarks(t,i),a=s.lastChild;if(a&&a.isText()&&!(8&a.flags)&&a.length+e.length<512){this.cache.reused.set(a,2),(s.children[s.children.length-1]=new YS(a.dom,a.text+e)).parent=s}else s.append(n||YS.of(e,null===(r=this.cache.find(YS))||void 0===r?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?ok(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let n=i;for(let a=t.marks.length-1;a>=0;a--){let e=t.marks[a],i=n.lastChild;if(i instanceof FS&&i.mark.eq(e.mark))i.dom!=e.dom&&i.setDOM(ok(e.dom)),n=i;else{if(this.cache.reused.get(e)){let t=zS.get(e.dom);t&&t.setDOM(ok(e.dom))}let t=FS.of(e.mark,e.dom);n.append(t),n=t}this.cache.reused.set(e,2)}let r=zS.get(e.text);r&&this.cache.reused.set(r,2);let s=new YS(e.text,e.text.nodeValue);s.flags|=8,n.append(s)}addInlineWidget(e,t,i){let n=this.afterWidget&&48&e.flags&&(48&this.afterWidget.flags)==(48&e.flags);n||this.flushBuffer();let r=this.ensureMarks(t,i);n||16&e.flags||r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){(this.afterWidget||this.lastBlock).length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=ak);let n=WS.start(e,t||(null===(i=this.cache.find(WS))||void 0===i?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let n=this.curLine;for(let r=e.length-1;r>=0;r--){let s,a=e[r];if(t>0&&(s=n.lastChild)&&s instanceof FS&&s.mark.eq(a))n=s,t--;else{let e=FS.of(a,null===(i=this.cache.find(FS,e=>e.mark.eq(a)))||void 0===i?void 0:i.dom);n.append(e),n=e,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;e&&sk(this.curLine,!1)&&("BR"==e.dom.nodeName||!e.isWidget()||nx.ios&&sk(this.curLine,!0))||this.curLine.append(this.cache.findWidget(ck,0,32)||new GS(ck.toDOM(),0,ck,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new JS(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.from<this.pos&&n instanceof BS&&n.wrapper.eq(i.wrapper))t=n;else{let n=BS.of(i.wrapper,null===(e=this.cache.find(BS,e=>e.wrapper.eq(i.wrapper)))||void 0===e?void 0:e.dom);t.append(n),t=n}}return t}blockPosCovered(){let e=this.lastBlock;return null!=e&&!e.breakAfter&&(!e.isWidget()||(160&e.flags)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(HS,void 0,1);return i&&(i.flags=t),i||new HS(t)}flushBuffer(){!this.afterWidget||32&this.afterWidget.flags||(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class tk{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:t,lineBreak:i,done:n}=this.cursor.next(this.skipCount);if(this.skipCount=0,n)throw new Error("Ran out of text content when drawing inline views");this.text=t;let r=this.textOff=Math.min(e,t.length);return i?null:t.slice(0,r)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const ik=[GS,WS,YS,FS,HS,BS,XS];for(let AM=0;AM<ik.length;AM++)ik[AM].bucket=AM;class nk{constructor(e){this.view=e,this.buckets=ik.map(()=>[]),this.index=ik.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let n=e.bucket,r=this.buckets[n],s=this.index[n];for(let a=r.length-1;a>=0;a--){let e=(a+s)%r.length,o=r[e];if((!t||t(o))&&!this.reused.has(o))return r.splice(e,1),e<s&&this.index[n]--,this.reused.set(o,i),o}return null}findWidget(e,t,i){let n=this.buckets[0];if(n.length)for(let r=0,s=0;;r++){if(r==n.length){if(s)return null;s=1,r=0}let a=n[r];if(!this.reused.has(a)&&(0==s?a.widget.compare(e):a.widget.constructor==e.constructor&&e.updateDOM(a.dom,this.view,a.widget)))return n.splice(r,1),r<this.index[0]&&this.index[0]--,a.widget==e&&a.length==t&&(497&a.flags)==i?(this.reused.set(a,1),a):(this.reused.set(a,2),new GS(a.dom,t,e,-498&a.flags|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class rk{constructor(e,t,i,n,r){this.view=e,this.decorations=n,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new nk(e),this.text=new tk(e.state.doc),this.builder=new ek(this.cache,new XS(e,e.contentDOM),y_.iter(i)),this.cache.reused.set(t,2),this.old=new KS(t),this.reuseWalker={skip:(e,t,i)=>{if(this.cache.add(e),e.isComposite())return!1},enter:e=>this.cache.add(e),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let n=0,r=0,s=0;;){let a=s<e.length?e[s++]:null,o=a?a.fromA:this.old.root.length;if(o>n){let e=o-n;this.preserve(e,!s,!a),n=o,r+=e}if(!a)break;t&&a.fromA<=t.range.fromA&&a.toA>=t.range.toA?(this.forward(a.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,a.toA),this.emit(t.range.toB,a.toB)):(this.forward(a.fromA,a.toA),this.emit(r,a.toB)),r=a.toB,n=a.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let n=function(e){let t=[];for(let i=e.parents.length;i>1;i--){let n=i==e.parents.length?e.tile:e.parents[i].tile;n instanceof FS&&t.push(n.mark)}return t}(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(e,t,i)=>{if(e.isWidget())if(this.openWidget)this.builder.continueWidget(i-t);else{let s=i>0||t<e.length?GS.of(e.widget,this.view,i-t,496&e.flags,this.cache.maybeReuse(e)):this.cache.reuse(e);256&s.flags?(s.flags&=-2,this.builder.addBlockWidget(s)):(this.builder.ensureLine(null),this.builder.addInlineWidget(s,n,r),r=n.length)}else if(e.isText())this.builder.ensureLine(null),t||i!=e.length||this.cache.reused.has(e)?(this.cache.add(e),this.builder.addText(e.text.slice(t,i),n,r)):this.builder.addText(e.text,n,r,this.cache.reuse(e)),r=n.length;else if(e.isLine())e.flags&=-2,this.cache.reused.set(e,1),this.builder.addLine(e);else if(e instanceof HS)this.cache.add(e);else{if(!(e instanceof FS))return!1;this.builder.ensureLine(null),this.builder.addMark(e,n,r),this.cache.reused.set(e,1),r=n.length}this.openWidget=!1},enter:e=>{e.isLine()?this.builder.addLineStart(e.attrs,this.cache.maybeReuse(e)):(this.cache.add(e),e instanceof FS&&n.unshift(e.mark)),this.openWidget=!1},leave:e=>{e.isLine()?n.length&&(n.length=r=0):e instanceof FS&&(n.shift(),r=Math.min(r,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,n=this.builder,r=0,s=y_.spans(this.decorations,e,t,{point:(e,t,s,a,o,l)=>{if(s instanceof fx){if(this.disallowBlockEffectsFor[l]){if(s.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.view.state.doc.lineAt(e).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=a.length,o>a.length)n.continueWidget(t-e);else{let r=s.widget||(s.block?lk.block:lk.inline),l=function(e){let t=e.isReplace?(e.startSide<0?64:0)|(e.endSide>0?128:0):e.startSide>0?32:16;e.block&&(t|=256);return t}(s),c=this.cache.findWidget(r,t-e,l)||GS.of(r,this.view,t-e,l);s.block?(s.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(c)):(n.ensureLine(i),n.addInlineWidget(c,a,o))}i=null}else i=function(e,t){let i=t.spec.attributes,n=t.spec.class;if(!i&&!n)return e;e||(e={class:"cm-line"});i&&rx(i,e);n&&(e.class+=" "+n);return e}(i,s);t>e&&this.text.skip(t-e)},span:(e,t,r,s)=>{for(let a=e;a<t;){let o=this.text.next(Math.min(512,t-a));null==o?(n.addLineStartIfNotCovered(i),n.addBreak(),a++):(n.ensureLine(i),n.addText(o,r,a==e?s:r.length),a+=o.length),i=null}}});n.addLineStartIfNotCovered(i),this.openWidget=s>r,this.openMarks=s}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let e=zS.get(n);if(n==this.view.contentDOM)break;e instanceof FS?t.push(e):(null==e?void 0:e.isLine())?i=e:e instanceof BS||("DIV"!=n.nodeName||i||n==this.view.contentDOM?i||t.push(FS.of(new dx({tagName:n.nodeName.toLowerCase(),attributes:lx(n)}),n)):i=new WS(n,ak))}return{line:i,marks:t}}}function sk(e,t){let i=e=>{for(let n of e.children)if((t?n.isText():n.length)||i(n))return!0;return!1};return i(e)}const ak={class:"cm-line"};function ok(e){let t=zS.get(e);return t&&t.setDOM(e.cloneNode()),e}class lk extends cx{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}lk.inline=new lk("span"),lk.block=new lk("div");const ck=new class extends cx{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class hk{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=ux.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new XS(e,e.contentDOM),this.updateInner([new LS(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:e,toA:t})=>t<this.minWidthFrom||e>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(t=this.domChanged)||void 0===t?void 0:t.newSel)?n=this.domChanged.newSel.head:function(e,t){let i=!1;t&&e.iterChangedRanges((e,n)=>{e<t.to&&n>t.from&&(i=!0)});return i}(e.changes,this.hasComposition)||e.selectionSet||(n=e.state.selection.main.head));let r=n>-1?function(e,t,i){let n=dk(e,i);if(!n)return null;let{node:r,from:s,to:a}=n,o=r.nodeValue;if(/[\n\r]/.test(o))return null;if(e.state.doc.sliceString(n.from,n.to)!=o)return null;let l=t.invertedDesc;return{range:new LS(l.mapPos(s),l.mapPos(a),s,a),text:r}}(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:t,to:n}=this.hasComposition;i=new LS(t,n,e.changes.mapPos(t,-1),e.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(nx.ie||nx.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let s=this.decorations,a=this.blockWrappers;this.updateDeco();let o=function(e,t,i){let n=new pk;return y_.compare(e,t,i,n),n.changes}(s,this.decorations,e.changes);o.length&&(i=LS.extendWithRanges(i,o));let l=function(e,t,i){let n=new fk;return y_.compare(e,t,i,n),n.changes}(a,this.blockWrappers,e.changes);return l.length&&(i=LS.extendWithRanges(i,l)),r&&!i.some(e=>e.fromA<=r.range.fromA&&e.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),!(2&this.tile.flags&&0==i.length)&&(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let i=this.tile,n=new rk(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&zS.get(t.text)&&n.cache.reused.set(zS.get(t.text),2),this.tile=n.run(e,t),uk(i,n.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let n=nx.chrome||nx.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(n),!n||!n.written&&i.selectionRange.focusNode==n.node&&this.tile.dom.contains(n.node)||(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof mk&&n.push(r.dom);i.updateGaps(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(bS)&&(this.editContextFormatting=e.value)}updateSelection(e=!1,t=!1){!e&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let{dom:i}=this.tile,n=this.view.root.activeElement,r=n==i,s=!r&&!(this.view.state.facet(_S)||i.tabIndex>-1)&&bx(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(r||t||s))return;let a=this.forceSelection;this.forceSelection=!1;let o,l,c=this.view.state.selection.main;if(c.empty?l=o=this.inlineDOMNearPos(c.anchor,c.assoc||1):(l=this.inlineDOMNearPos(c.head,c.head==c.from?1:-1),o=this.inlineDOMNearPos(c.anchor,c.anchor==c.from?1:-1)),nx.gecko&&c.empty&&!this.hasComposition&&(1==(h=o).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable))){let e=document.createTextNode("");this.view.observer.ignore(()=>o.node.insertBefore(e,o.node.childNodes[o.offset]||null)),o=l=new Dx(e,0),a=!0}var h;let u=this.view.observer.selectionRange;!a&&u.focusNode&&(_x(o.node,o.offset,u.anchorNode,u.anchorOffset)&&_x(l.node,l.offset,u.focusNode,u.focusOffset)||this.suppressWidgetCursorChange(u,c))||(this.view.observer.ignore(()=>{nx.android&&nx.chrome&&i.contains(u.focusNode)&&function(e,t){for(let i=e;i&&i!=t;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(u.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let e=vx(this.view.root);if(e)if(c.empty){if(nx.gecko){let e=(t=o.node,r=o.offset,1!=t.nodeType?0:(r&&"false"==t.childNodes[r-1].contentEditable?1:0)|(r<t.childNodes.length&&"false"==t.childNodes[r].contentEditable?2:0));if(e&&3!=e){let t=(1==e?Lx:Zx)(o.node,o.offset);t&&(o=new Dx(t.node,t.offset))}}e.collapse(o.node,o.offset),null!=c.bidiLevel&&void 0!==e.caretBidiLevel&&(e.caretBidiLevel=c.bidiLevel)}else if(e.extend){e.collapse(o.node,o.offset);try{e.extend(l.node,l.offset)}catch(EM){}}else{let t=document.createRange();c.anchor>c.head&&([o,l]=[l,o]),t.setEnd(l.node,l.offset),t.setStart(o.node,o.offset),e.removeAllRanges(),e.addRange(t)}else;var t,r;s&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(o,l)),this.impreciseAnchor=o.precise?null:new Dx(u.anchorNode,u.anchorOffset),this.impreciseHead=l.precise?null:new Dx(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&_x(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=vx(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!(i&&t.empty&&t.assoc&&i.modify))return;let s=this.lineAt(t.head,t.assoc);if(!s)return;let a=s.posAtStart;if(t.head==a||t.head==a+s.length)return;let o=this.coordsAt(t.head,-1),l=this.coordsAt(t.head,1);if(!o||!l||o.bottom>l.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let h=e.observer.selectionRange;e.docView.posFromDOM(h.anchorNode,h.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return 2&this.tile.dom.compareDocumentPosition(e)?0:this.view.state.doc.length;let n=i.posAtStart;if(!i.isComposite())return i.isText()?e==i.dom?n+t:n+(t?i.length:0):n;{let r;if(e==i.dom)r=i.dom.childNodes[t];else{let n=0==Px(e)?0:0==t?-1:1;for(;;){let t=e.parentNode;if(t==i.dom)break;0==n&&t.firstChild!=t.lastChild&&(n=e==t.firstChild?-1:1),e=t}r=n<0?e:e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!zS.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let e=0,t=n;;e++){let n=i.children[e];if(n.dom==r)return t;t+=n.length+n.breakAfter}}}domAtPos(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(n,t)}inlineDOMNearPos(e,t){let i,n,r=-1,s=!1,a=-1,o=!1;return this.tile.blockTiles((t,l)=>{if(t.isWidget()){if(32&t.flags&&l>=e)return!0;16&t.flags&&(s=!0)}else{let c=l+t.length;if(l<=e&&(i=t,r=e-l,s=c<e),c>=e&&!n&&(n=t,a=e-l,o=l>e),l>e&&n)return!0}}),i||n?(s&&n?i=null:o&&i&&(n=null),i&&t<0||!n?i.domIn(r,t):n.domIn(a,t)):this.domAtPos(e,t)}coordsAt(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof mk?null:i.coordsInWidget(n,t,!0):i.coordsIn(n,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;return function e(t,i){if(t.isComposite())for(let n of t.children){if(n.length>=i){let t=e(n,i);if(t)return t}if((i-=n.length)<0)break}else if(t.isText()&&i<t.length){let e=aw(t.text,i);if(e==i)return null;let n=jx(t.dom,i,e).getClientRects();for(let t=0;t<n.length;t++){let e=n[t];if(t==n.length-1||e.top<e.bottom&&e.left<e.right)return e}}return null}(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,r=this.view.contentDOM.clientWidth,s=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,a=-1,o=this.view.textDirection==zx.LTR,l=0,c=(e,h,u)=>{for(let d=0;d<e.children.length&&!(h>n);d++){let n=e.children[d],p=h+n.length,f=n.dom.getBoundingClientRect(),{height:m}=f;if(u&&!d&&(l+=f.top-u.top),n instanceof BS)p>i&&c(n,h,f);else if(h>=i&&(l>0&&t.push(-l),t.push(m+l),l=0,s)){let e=n.dom.lastChild,t=e?wx(e):[];if(t.length){let e=t[t.length-1],i=o?e.right-f.left:f.right-e.left;i>a&&(a=i,this.minWidth=r,this.minWidthFrom=h,this.minWidthTo=p)}}u&&d==e.children.length-1&&(l+=u.bottom-f.bottom),h=p+n.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return"rtl"==getComputedStyle(t.dom).direction?zx.RTL:zx.LTR}measureTextSize(){let e=this.tile.blockTiles(e=>{if(e.isLine()&&e.children.length&&e.length<=20){let t,i=0;for(let n of e.children){if(!n.isText()||/[^ -~]/.test(n.text))return;let e=wx(n.dom);if(1!=e.length)return;i+=e[0].width,t=e[0].height}if(i)return{lineHeight:e.dom.getBoundingClientRect().height,charWidth:i/e.length,textHeight:t}}});if(e)return e;let t,i,n,r=document.createElement("div");return r.className="cm-line",r.style.width="99999px",r.style.position="absolute",r.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(r);let e=wx(r.firstChild)[0];t=r.getBoundingClientRect().height,i=e&&e.width?e.width/27:7,n=e&&e.height?e.height:t,r.remove()}),{lineHeight:t,charWidth:i,textHeight:n}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],s=r?r.from-1:this.view.state.doc.length;if(s>i){let n=(t.lineBlockAt(s).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(ux.replace({widget:new mk(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,s))}if(!r)break;i=r.to+1}return ux.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ES).map(t=>(this.dynamicDecorationMap[e++]="function"==typeof t)?t(this.view):t),i=!1,n=this.view.state.facet(CS).map((e,t)=>{let n="function"==typeof e;return n&&(i=!0),n?e(this.view):e});for(n.length&&(this.dynamicDecorationMap[e++]=i,t.push(y_.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(AS).map(e=>"function"==typeof e?e(this.view):e)}scrollIntoView(e){var t;if(e.isSnapshot){let t=this.view.viewState.lineBlockAt(e.range.head);return this.view.scrollDOM.scrollTop=t.top-e.yMargin,void(this.view.scrollDOM.scrollLeft=e.xMargin)}for(let h of this.view.state.facet(OS))try{if(h(this.view,e.range,e))return!0}catch(c){wS(this.view.state,c,"scroll handler")}let i,{range:n}=e,r=this.coordsAt(n.head,null!==(t=n.assoc)&&void 0!==t?t:n.empty?0:n.head>n.anchor?-1:1);if(!r)return;!n.empty&&(i=this.coordsAt(n.anchor,n.anchor>n.head?-1:1))&&(r={left:Math.min(r.left,i.left),top:Math.min(r.top,i.top),right:Math.max(r.right,i.right),bottom:Math.max(r.bottom,i.bottom)});let s=MS(this.view),a={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(function(e,t,i,n,r,s,a,o){let l=e.ownerDocument,c=l.defaultView||window;for(let h=e,u=!1;h&&!u;)if(1==h.nodeType){let e,d=h==l.body,p=1,f=1;if(d)e=$x(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(u=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let t=h.getBoundingClientRect();({scaleX:p,scaleY:f}=Ex(h,t)),e={left:t.left,right:t.left+h.clientWidth*p,top:t.top,bottom:t.top+h.clientHeight*f}}let m=0,g=0;if("nearest"==r)t.top<e.top+a?(g=t.top-(e.top+a),i>0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+a)):t.bottom>e.bottom-a&&(g=t.bottom-e.bottom+a,i<0&&t.top-g<e.top&&(g=t.top-(e.top+a)));else{let n=t.bottom-t.top,s=e.bottom-e.top;g=("center"==r&&n<=s?t.top+n/2-s/2:"start"==r||"center"==r&&i<0?t.top-a:t.bottom-s+a)-e.top}if("nearest"==n?t.left<e.left+s?(m=t.left-(e.left+s),i>0&&t.right>e.right+m&&(m=t.right-e.right+s)):t.right>e.right-s&&(m=t.right-e.right+s,i<0&&t.left<e.left+m&&(m=t.left-(e.left+s))):m=("center"==n?t.left+(t.right-t.left)/2-(e.right-e.left)/2:"start"==n==o?t.left-s:t.right-(e.right-e.left)+s)-e.left,m||g)if(d)c.scrollBy(m,g);else{let e=0,i=0;if(g){let e=h.scrollTop;h.scrollTop+=g/f,i=(h.scrollTop-e)*f}if(m){let t=h.scrollLeft;h.scrollLeft+=m/p,e=(h.scrollLeft-t)*p}t={left:t.left-e,top:t.top-i,right:t.right-e,bottom:t.bottom-i},e&&Math.abs(e-m)<1&&(n="nearest"),i&&Math.abs(i-g)<1&&(r="nearest")}if(d)break;(t.top<e.top||t.bottom>e.bottom||t.left<e.left||t.right>e.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),h=h.assignedSlot||h.parentNode}else{if(11!=h.nodeType)break;h=h.host}}(this.view.scrollDOM,a,n.head<n.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==zx.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let e=this.view.docView.lineAt(n.head,1);e&&e.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=e=>e.isWidget()||e.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){uk(this.tile)}}function uk(e,t){let i=null==t?void 0:t.get(e);if(1!=i){null==i&&e.destroy();for(let i of e.children)uk(i,t)}}function dk(e,t){let i=e.observer.selectionRange;if(!i.focusNode)return null;let n=Lx(i.focusNode,i.focusOffset),r=Zx(i.focusNode,i.focusOffset),s=n||r;if(r&&n&&r.node!=n.node){let t=zS.get(r.node);if(!t||t.isText()&&t.text!=r.node.nodeValue)s=r;else if(e.docView.lastCompositionAfterCursor){let e=zS.get(n.node);!e||e.isText()&&e.text!=n.node.nodeValue||(s=r)}}if(e.docView.lastCompositionAfterCursor=s!=n,!s)return null;let a=t-s.offset;return{from:a,to:a+s.node.nodeValue.length,node:s.node}}let pk=class{constructor(){this.changes=[]}compareRange(e,t){gx(e,t,this.changes)}comparePoint(e,t){gx(e,t,this.changes)}boundChange(e){gx(e,e,this.changes)}};class fk{constructor(){this.changes=[]}compareRange(e,t){gx(e,t,this.changes)}comparePoint(){}boundChange(e){gx(e,e,this.changes)}}class mk extends cx{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function gk(e,t,i,n,r){let s=Math.round((n-t.left)*e.defaultCharacterWidth);if(e.lineWrapping&&i.height>1.5*e.defaultLineHeight){let t=e.viewState.heightOracle.textHeight;s+=Math.floor((r-i.top-.5*(e.defaultLineHeight-t))/t)*e.viewState.heightOracle.lineLength}let a=e.state.sliceDoc(i.from,i.to);return i.from+function(e,t,i){for(let n=0,r=0;;){if(r>=t)return n;if(n==e.length)break;r+=9==e.charCodeAt(n)?i-r%i:1,n=aw(e,n)}return e.length}(a,s,e.state.tabSize)}function Ok(e,t,i){let n=e.lineBlockAt(t);if(Array.isArray(n.type)){let e;for(let r of n.type){if(r.from>t)break;if(!(r.to<t)){if(r.from<t&&r.to>t)return r;e&&(r.type!=hx.Text||e.type==r.type&&!(i<0?r.from<t:r.to>t))||(e=r)}}return e||n}return n}function vk(e,t,i,n){let r=e.state.doc.lineAt(t.head),s=e.bidiSpans(r),a=e.textDirectionAt(r.from);for(let o=t,l=null;;){let t=rS(r,s,a,o,i),c=nS;if(!t){if(r.number==(i?e.state.doc.lines:1))return o;c="\n",r=e.state.doc.line(r.number+(i?1:-1)),s=e.bidiSpans(r),t=e.visualLineSide(r,!i)}if(l){if(!l(c))return o}else{if(!n)return t;l=n(c)}o=t}}function yk(e,t,i){for(;;){let n=0;for(let r of e)r.between(t-1,t+1,(e,r,s)=>{if(t>e&&t<r){let s=n||i||(t-e<r-t?-1:1);t=s<0?e:r,n=s}});if(!n)return t}}function bk(e,t){let i=null;for(let n=0;n<t.ranges.length;n++){let r=t.ranges[n],s=null;if(r.empty){let t=yk(e,r.from,0);t!=r.from&&(s=ww.cursor(t,-1))}else{let t=yk(e,r.from,-1),i=yk(e,r.to,1);t==r.from&&i==r.to||(s=ww.range(r.from==r.anchor?t:i,r.from==r.head?t:i))}s&&(i||(i=t.ranges.slice()),i[n]=s)}return i?ww.create(i,t.mainIndex):t}function wk(e,t,i){let n=yk(e.state.facet(RS).map(t=>t(e)),i.from,t.head>i.from?-1:1);return n==i.from?i:ww.cursor(n,n<i.from?1:-1)}class _k{constructor(e,t){this.pos=e,this.assoc=t}}function xk(e,t,i,n){let r,s=e.contentDOM.getBoundingClientRect(),a=s.top+e.viewState.paddingTop,{x:o,y:l}=t,c=l-a;for(;;){if(c<0)return new _k(0,1);if(c>e.viewState.docHeight)return new _k(e.state.doc.length,-1);if(r=e.elementAtHeight(c),null==n)break;if(r.type==hx.Text){if(n<0?r.to<e.viewport.from:r.from>e.viewport.to)break;let t=e.docView.coordsAt(n<0?r.from:r.to,n>0?-1:1);if(t&&(n<0?t.top<=c+a:t.bottom>=c+a))break}let t=e.viewState.heightOracle.textHeight/2;c=n>0?r.bottom+t:r.top-t}if(e.viewport.from>=r.to||e.viewport.to<=r.from){if(i)return null;if(r.type==hx.Text){let t=gk(e,s,r,o,l);return new _k(t,t==r.from?1:-1)}}if(r.type!=hx.Text)return c<(r.top+r.bottom)/2?new _k(r.from,1):new _k(r.to,-1);let h=e.docView.lineAt(r.from,2);return h&&h.length==r.length||(h=e.docView.lineAt(r.from,-2)),new Sk(e,o,l,e.textDirectionAt(r.from)).scanTile(h,r.from)}class Sk{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Hx.find(n,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Hx.find(n,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:n}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from<t)}scan(e,t){let i,n,r,s=0,a=e.length-1,o=new Set,l=this.bidiIn(e[0],e[a]),c=-1,h=1e9;e:for(;s<a;){let u=a-s,d=s+a>>1;t:if(o.has(d)){let e=s+Math.floor(Math.random()*u);for(let t=0;t<u;t++){if(!o.has(e)){d=e;break t}e++,e==a&&(e=s)}break e}o.add(d);let p=t(d);if(p)for(let t=0;t<p.length;t++){let o=p[t],u=0;if(!(0==o.width&&p.length>1)){if(o.bottom<this.y)(!i||i.bottom<o.bottom)&&(i=o),u=1;else if(o.top>this.y)(!n||n.top>o.top)&&(n=o),u=-1;else{let e=o.left>this.x?this.x-o.left:o.right<this.x?this.x-o.right:0,t=Math.abs(e);t<h&&(c=d,h=t,r=o),e&&(u=e<0==(this.baseDir==zx.LTR)?-1:1)}-1!=u||l&&!this.baseDirAt(e[d],1)?1!=u||l&&!this.baseDirAt(e[d+1],-1)||(s=d+1):a=d}}}if(!r){let r=i&&(!n||this.y-i.bottom<n.top-this.y)?i:n;return this.y=(r.top+r.bottom)/2,this.scan(e,t)}if(h){if(i&&i.bottom>r.top)return this.y=i.bottom-1,this.scan(e,t);if(n&&n.top<r.bottom)return this.y=n.top+1,this.scan(e,t)}let u=(l?this.dirAt(e[c],1):this.baseDir)==zx.LTR;return{i:c,after:this.x>(r.left+r.right)/2==u}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=aw(e.text,r))i.push(t+r);i.push(t+e.length);let n=this.scan(i,n=>{let r=i[n]-t,s=i[n+1]-t;return jx(e.dom,r,s).getClientRects()});return n.after?new _k(i[n.i+1],-1):new _k(i[n.i],1)}scanTile(e,t){if(!e.length)return new _k(t,1);if(1==e.children.length){let i=e.children[0];if(i.isText())return this.scanText(i,t);if(i.isComposite())return this.scanTile(i,t)}let i=[t];for(let a=0,o=t;a<e.children.length;a++)i.push(o+=e.children[a].length);let n=this.scan(i,t=>{let i=e.children[t];return 48&i.flags?null:(1==i.dom.nodeType?i.dom:jx(i.dom,0,i.length)).getClientRects()}),r=e.children[n.i],s=i[n.i];return r.isText()?this.scanText(r,s):r.isComposite()?this.scanTile(r,s):n.after?new _k(i[n.i+1],-1):new _k(s,1)}}const kk="";class Pk{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(d_.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=kk}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let e=this.text.length;this.readNode(n);let r=zS.get(n),s=n.nextSibling;if(s==t){(null==r?void 0:r.breakAfter)&&!s&&i!=this.view.contentDOM&&this.lineBreak();break}let a=zS.get(s);(r&&a?r.breakAfter:(r?r.breakAfter:Sx(n))||Sx(s)&&("BR"!=n.nodeName||(null==r?void 0:r.isWidget()))&&this.text.length>e)&&!$k(s,t)&&this.lineBreak(),n=s}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r,s=-1,a=1;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,i),a=this.lineSeparator.length):(r=n.exec(t))&&(s=r.index,a=r[0].length),this.append(t.slice(i,s<0?t.length:s)),s<0)break;if(this.lineBreak(),a>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=a-1);i=s+a}}readNode(e){let t=zS.get(e),i=t&&t.overrideDOMText;if(null!=i){this.findPointInside(e,i.length);for(let e=i.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else 3==e.nodeType?this.readTextNode(e):"BR"==e.nodeName?e.nextSibling&&this.lineBreak():1==e.nodeType&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(3==e.nodeType?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(Tk(e,i.node,i.offset)?t:0))}}function Tk(e,t,i){for(;;){if(!t||i<Px(t))return!1;if(t==e)return!0;i=xx(t)+1,t=t.parentNode}}function $k(e,t){let i;for(;e!=t&&e;e=e.nextSibling){let t=zS.get(e);if(!(null==t?void 0:t.isWidget()))return!1;t&&(i||(i=[])).push(t)}if(i)for(let n of i){let e=n.overrideDOMText;if(null==e?void 0:e.length)return!1}return!0}class Ek{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Ak{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:s}=e.docView,a=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Ck(e.docView.tile,t,i,0))){let t=r||s?[]:function(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:s}=e.observer.selectionRange;i&&(t.push(new Ek(i,n)),r==i&&s==n||t.push(new Ek(r,s)));return t}(e),i=new Pk(t,e);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(e,t){if(0==e.length)return null;let i=e[0].pos,n=2==e.length?e[1].pos:i;return i>-1&&n>-1?ww.single(i+t,n+t):null}(t,this.bounds.from)}else{let t=e.observer.selectionRange,i=r&&r.node==t.focusNode&&r.offset==t.focusOffset||!yx(e.contentDOM,t.focusNode)?a.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),n=s&&s.node==t.anchorNode&&s.offset==t.anchorOffset||!yx(e.contentDOM,t.anchorNode)?a.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),o=e.viewport;if((nx.ios||nx.chrome)&&a.main.empty&&i!=n&&(o.from>0||o.to<e.state.doc.length)){let t=Math.min(i,n),r=Math.max(i,n),s=o.from-t,a=o.to-r;0!=s&&1!=s&&0!=t||0!=a&&-1!=a&&r!=e.state.doc.length||(i=0,n=e.state.doc.length)}if(e.inputState.composing>-1&&a.ranges.length>1)this.newSel=a.replaceRange(ww.range(n,i));else if(e.lineWrapping&&n==i&&(!a.main.empty||a.main.head!=i)&&e.inputState.lastTouchTime>Date.now()-100){let t=e.coordsAtPos(i,-1),n=0;t&&(n=e.inputState.lastTouchY<=t.bottom?-1:1),this.newSel=ww.create([ww.cursor(i,n)])}else this.newSel=ww.single(n,i)}}}function Ck(e,t,i,n){if(e.isComposite()){let r=-1,s=-1,a=-1,o=-1;for(let l=0,c=n,h=n;l<e.children.length;l++){let n=e.children[l],u=c+n.length;if(c<t&&u>i)return Ck(n,t,i,c);if(u>=t&&-1==r&&(r=l,s=c),c>i&&n.dom.parentNode==e.dom){a=l,o=h;break}h=u,c=u+n.breakAfter}return{from:s,to:o<0?n+e.length:o,startDOM:(r?e.children[r-1].dom.nextSibling:null)||e.dom.firstChild,endDOM:a<e.children.length&&a>=0?e.children[a].dom:null}}return e.isText()?{from:n,to:n+e.length,startDOM:e.dom,endDOM:e.dom.nextSibling}:null}function Rk(e,t){let i,{newSel:n}=t,{state:r}=e,s=r.selection.main,a=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:e,to:n}=t.bounds,o=s.from,l=null;(8===a||nx.android&&t.text.length<n-e)&&(o=s.to,l="end");let c,h,u=r.doc.sliceString(e,n,kk);!s.empty&&s.from>=e&&s.to<=n&&(t.typeOver||u!=t.text)&&u.slice(0,s.from-e)==t.text.slice(0,s.from-e)&&u.slice(s.to-e)==t.text.slice(c=t.text.length-(u.length-(s.to-e)))?i={from:s.from,to:s.to,insert:Gb.of(t.text.slice(s.from-e,c).split(kk))}:(h=Ik(u,t.text,o-e,l))&&(nx.chrome&&13==a&&h.toB==h.from+2&&t.text.slice(h.from,h.toB)==kk+kk&&h.toB--,i={from:e+h.from,to:e+h.toA,insert:Gb.of(t.text.slice(h.from,h.toB).split(kk))})}else n&&(!e.hasFocus&&r.facet(_S)||jk(n,s))&&(n=null);if(!i&&!n)return!1;if((nx.mac||nx.android)&&i&&i.from==i.to&&i.from==s.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=ww.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:Gb.of([i.insert.toString().replace("."," ")])}):r.doc.lineAt(s.from).to<s.to&&e.docView.lineHasWidget(s.to)&&e.inputState.insertingTextAt>Date.now()-50?i={from:s.from,to:s.to,insert:r.toText(e.inputState.insertingText)}:nx.chrome&&i&&i.from==i.to&&i.from==s.head&&"\n "==i.insert.toString()&&e.lineWrapping&&(n&&(n=ww.single(n.main.anchor-1,n.main.head-1)),i={from:s.from,to:s.to,insert:Gb.of([" "])}),i)return Qk(e,i,n,a);if(n&&!jk(n,s)){let t=!1,i="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),i=e.inputState.lastSelectionOrigin,"select.pointer"==i&&(n=bk(r.facet(RS).map(t=>t(e)),n))),e.dispatch({selection:n,scrollIntoView:t,userEvent:i}),!0}return!1}function Qk(e,t,i,n=-1){if(nx.ios&&e.inputState.flushIOSKey(t))return!0;let r=e.state.selection.main;if(nx.android&&(t.to==r.to&&(t.from==r.from||t.from==r.from-1&&" "==e.state.sliceDoc(t.from,r.from))&&1==t.insert.length&&2==t.insert.lines&&Mx(e.contentDOM,"Enter",13)||(t.from==r.from-1&&t.to==r.to&&0==t.insert.length||8==n&&t.insert.length<t.to-t.from&&t.to>r.head)&&Mx(e.contentDOM,"Backspace",8)||t.from==r.from&&t.to==r.to+1&&0==t.insert.length&&Mx(e.contentDOM,"Delete",46)))return!0;let s,a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o=()=>s||(s=function(e,t,i){let n,r=e.state,s=r.selection.main,a=-1;if(t.from==t.to&&t.from<s.from||t.from>s.to){let i=t.from<s.from?-1:1,n=i<0?s.from:s.to,o=yk(r.facet(RS).map(t=>t(e)),n,i);t.from==o&&(a=o)}if(a>-1)n={changes:t,selection:ww.cursor(t.from+t.insert.length,-1)};else if(t.from>=s.from&&t.to<=s.to&&t.to-t.from>=(s.to-s.from)/3&&(!i||i.main.empty&&i.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let i=s.from<t.from?r.sliceDoc(s.from,t.from):"",a=s.to>t.to?r.sliceDoc(t.to,s.to):"";n=r.replaceSelection(e.state.toText(i+t.insert.sliceString(0,void 0,e.state.lineBreak)+a))}else{let a=r.changes(t),o=i&&i.main.to<=a.newLength?i.main:void 0;if(r.selection.ranges.length>1&&(e.inputState.composing>=0||e.inputState.compositionPendingChange)&&t.to<=s.to+10&&t.to>=s.to-10){let l,c=e.state.sliceDoc(t.from,t.to),h=i&&dk(e,i.main.head);if(h){let e=t.insert.length-(t.to-t.from);l={from:h.from,to:h.to-e}}else l=e.state.doc.lineAt(s.head);let u=s.to-t.to;n=r.changeByRange(i=>{if(i.from==s.from&&i.to==s.to)return{changes:a,range:o||i.map(a)};let n=i.to-u,h=n-c.length;if(e.state.sliceDoc(h,n)!=c||n>=l.from&&h<=l.to)return{range:i};let d=r.changes({from:h,to:n,insert:t.insert}),p=i.to-s.to;return{changes:d,range:o?ww.range(Math.max(0,o.anchor+p),Math.max(0,o.head+p)):i.map(d)}})}else n={changes:a,selection:o&&r.selection.replaceRange(o)}}let o="input.type";(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,o+=".compose",e.inputState.compositionFirstChange&&(o+=".start",e.inputState.compositionFirstChange=!1));return r.update(n,{userEvent:o,scrollIntoView:!0})}(e,t,i));return e.state.facet(uS).some(i=>i(e,t.from,t.to,a,o))||e.dispatch(o()),!0}function Ik(e,t,i,n){let r=Math.min(e.length,t.length),s=0;for(;s<r&&e.charCodeAt(s)==t.charCodeAt(s);)s++;if(s==r&&e.length==t.length)return null;let a=e.length,o=t.length;for(;a>0&&o>0&&e.charCodeAt(a-1)==t.charCodeAt(o-1);)a--,o--;if("end"==n){i-=a+Math.max(0,s-Math.min(a,o))-s}if(a<s&&e.length<t.length){s-=i<=s&&i>=a?s-i:0,o=s+(o-a),a=s}else if(o<s){s-=i<=s&&i>=o?s-i:0,a=s+(a-o),o=s}return{from:s,toA:a,toB:o}}function jk(e,t){return t.head==e.main.head&&t.anchor==e.main.anchor}class Mk{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){var t;this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,nx.safari&&e.contentDOM.addEventListener("input",()=>null),nx.gecko&&(t=e.contentDOM.ownerDocument,sP.has(t)||(sP.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{})))}handleEvent(e){(function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let i,n=t.target;n!=e.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=zS.get(n))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0})(this.view,e)&&!this.ignoreDuringComposition(e)&&("keydown"==e.type&&this.keydown(e)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e)))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let e of i.observers)e(this.view,t);for(let e of i.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=function(e){let t=Object.create(null);function i(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let n of e){let e=n.spec,t=e&&e.plugin.domEventHandlers,r=e&&e.plugin.domEventObservers;if(t)for(let s in t){let e=t[s];e&&i(s).handlers.push(Nk(n.value,e))}if(r)for(let s in r){let e=r[s];e&&i(s).observers.push(Nk(n.value,e))}}for(let n in qk)i(n).handlers.push(qk[n]);for(let n in Xk)i(n).observers.push(Xk[n]);return t}(e),i=this.handlers,n=this.view.contentDOM;for(let r in t)if("scroll"!=r){let e=!t[r].handlers.length,s=i[r];s&&e!=!s.handlers.length&&(n.removeEventListener(r,this.handleEvent),s=null),s||n.addEventListener(r,this.handleEvent,{passive:e})}for(let r in i)"scroll"==r||t[r]||n.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=e.keyCode&&Dk.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),nx.android&&nx.chrome&&!e.synthetic&&(13==e.keyCode||8==e.keyCode))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return!nx.ios||e.synthetic||e.altKey||e.metaKey||e.shiftKey||!((t=Lk.find(t=>t.keyCode==e.keyCode))&&!e.ctrlKey||Zk.indexOf(e.key)>-1&&e.ctrlKey)?(229!=e.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(e){let t=this.pendingIOSKey;return!!t&&(!("Enter"==t.key&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString()))&&(this.pendingIOSKey=void 0,Mx(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0)))}ignoreDuringComposition(e){return!(!/^key/.test(e.type)||e.synthetic)&&(this.composing>0||!!(nx.safari&&!nx.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Nk(e,t){return(i,n)=>{try{return t.call(e,n,i)}catch(r){wS(i.state,r)}}}const Lk=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Zk="dthko",Dk=[16,17,18,20,91,92,224,225];function zk(e){return.7*Math.max(0,e)+8}class Uk{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Ax(e.contentDOM),this.atoms=e.state.facet(RS).map(t=>t(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(d_.allowMultipleSelections)&&function(e,t){let i=e.state.facet(aS);return i.length?i[0](t):nx.mac?t.metaKey:t.ctrlKey}(e,t),this.dragging=!(!function(e,t){let{main:i}=e.state.selection;if(i.empty)return!1;let n=vx(e.root);if(!n||0==n.rangeCount)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s<r.length;s++){let e=r[s];if(e.left<=t.clientX&&e.right>=t.clientX&&e.top<=t.clientY&&e.bottom>=t.clientY)return!0}return!1}(e,t)||1!=Jk(t))&&null}start(e){!1===this.dragging&&this.select(e)}move(e){if(0==e.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(t=this.startEvent,i=e,Math.max(Math.abs(t.clientX-i.clientX),Math.abs(t.clientY-i.clientY))<10))return;var t,i;this.select(this.lastEvent=e);let n=0,r=0,s=0,a=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:a,bottom:l}=this.scrollParents.y.getBoundingClientRect());let c=MS(this.view);e.clientX-c.left<=s+6?n=-zk(s-e.clientX):e.clientX+c.right>=o-6&&(n=zk(e.clientX-o)),e.clientY-c.top<=a+6?r=-zk(a-e.clientY):e.clientY+c.bottom>=l-6&&(r=zk(e.clientY-l)),this.setScrollSpeed(n,r)}up(e){null==this.dragging&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),!1===this.dragging&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=bk(this.atoms,this.style.get(e,this.extend,this.multiple));!this.mustSelect&&i.eq(t.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}const qk=Object.create(null),Xk=Object.create(null),Bk=nx.ie&&nx.ie_version<15||nx.ios&&nx.webkit_version<604;function Wk(e,t,i){for(let n of e.facet(t))i=n(i,e);return i}function Vk(e,t){t=Wk(e.state,pS,t);let i,{state:n}=e,r=1,s=n.toText(t),a=s.lines==n.selection.ranges.length;if(null!=tP&&n.selection.ranges.every(e=>e.empty)&&tP==s.toString()){let e=-1;i=n.changeByRange(i=>{let o=n.doc.lineAt(i.from);if(o.from==e)return{range:i};e=o.from;let l=n.toText((a?s.line(r++).text:t)+n.lineBreak);return{changes:{from:o.from,insert:l},range:ww.cursor(i.from+l.length)}})}else i=a?n.changeByRange(e=>{let t=s.line(r++);return{changes:{from:e.from,to:e.to,insert:t.text},range:ww.cursor(e.from+t.length)}}):n.replaceSelection(s);e.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function Fk(e,t,i,n){if(1==n)return ww.cursor(t,i);if(2==n)return function(e,t,i=1){let n=e.charCategorizer(t),r=e.doc.lineAt(t),s=t-r.from;if(0==r.length)return ww.cursor(t);0==s?i=1:s==r.length&&(i=-1);let a=s,o=s;i<0?a=aw(r.text,s,!1):o=aw(r.text,s);let l=n(r.text.slice(a,o));for(;a>0;){let e=aw(r.text,a,!1);if(n(r.text.slice(e,a))!=l)break;a=e}for(;o<r.length;){let e=aw(r.text,o);if(n(r.text.slice(o,e))!=l)break;o=e}return ww.range(a+r.from,o+r.from)}(e.state,t,i);{let n=e.docView.lineAt(t,i),r=e.state.doc.lineAt(n?n.posAtEnd:t),s=n?n.posAtStart:r.from,a=n?n.posAtEnd:r.to;return a<e.state.doc.length&&a==r.to&&a++,ww.range(s,a)}}Xk.scroll=e=>{e.inputState.lastScrollTop=e.scrollDOM.scrollTop,e.inputState.lastScrollLeft=e.scrollDOM.scrollLeft},Xk.wheel=Xk.mousewheel=e=>{e.inputState.lastWheelEvent=Date.now()},qk.keydown=(e,t)=>(e.inputState.setSelectionOrigin("select"),27==t.keyCode&&0!=e.inputState.tabFocusMode&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),Xk.touchstart=(e,t)=>{let i=e.inputState,n=t.targetTouches[0];i.lastTouchTime=Date.now(),n&&(i.lastTouchX=n.clientX,i.lastTouchY=n.clientY),i.setSelectionOrigin("select.pointer")},Xk.touchmove=e=>{e.inputState.setSelectionOrigin("select.pointer")},qk.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of e.state.facet(lS))if(i=n(e,t),i)break;if(i||0!=t.button||(i=function(e,t){let i=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),n=Jk(t),r=e.state.selection;return{update(e){e.docChanged&&(i.pos=e.changes.mapPos(i.pos),r=r.map(e.changes))},get(t,s,a){let o,l=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),c=Fk(e,l.pos,l.assoc,n);if(i.pos!=l.pos&&!s){let t=Fk(e,i.pos,i.assoc,n),r=Math.min(t.from,c.from),s=Math.max(t.to,c.to);c=r<c.from?ww.range(r,s,c.assoc):ww.range(s,r,c.assoc)}return s?r.replaceRange(r.main.extend(c.from,c.to,c.assoc)):a&&1==n&&r.ranges.length>1&&(o=function(e,t){for(let i=0;i<e.ranges.length;i++){let{from:n,to:r}=e.ranges[i];if(n<=t&&r>=t)return ww.create(e.ranges.slice(0,i).concat(e.ranges.slice(i+1)),e.mainIndex==i?0:e.mainIndex-(e.mainIndex>i?1:0))}return null}(r,l.pos))?o:a?r.addRange(c):ww.create([c])}}}(e,t)),i){let n=!e.hasFocus;e.inputState.startMouseSelection(new Uk(e,t,i,n)),n&&e.observer.ignore(()=>{Ix(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()});let r=e.inputState.mouseSelection;if(r)return r.start(t),!1===r.dragging}else e.inputState.setSelectionOrigin("select.pointer");return!1};const Yk=nx.ie&&nx.ie_version<=11;let Gk=null,Hk=0,Kk=0;function Jk(e){if(!Yk)return e.detail;let t=Gk,i=Kk;return Gk=e,Kk=Date.now(),Hk=!t||i>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(Hk+1)%3:1}function eP(e,t,i,n){if(!(i=Wk(e.state,pS,i)))return;let r=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:s}=e.inputState,a=n&&s&&function(e,t){let i=e.state.facet(oS);return i.length?i[0](t):nx.mac?!t.altKey:!t.ctrlKey}(e,t)?{from:s.from,to:s.to}:null,o={from:r,insert:i},l=e.state.changes(a?[a,o]:o);e.focus(),e.dispatch({changes:l,selection:{anchor:l.mapPos(r,-1),head:l.mapPos(r,1)},userEvent:a?"move.drop":"input.drop"}),e.inputState.draggedContent=null}qk.dragstart=(e,t)=>{let{selection:{main:i}}=e.state;if(t.target.draggable){let n=e.docView.tile.nearest(t.target);if(n&&n.isWidget()){let e=n.posAtStart,t=e+n.length;(e>=i.to||t<=i.from)&&(i=ww.range(e,t))}}let{inputState:n}=e;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,t.dataTransfer&&(t.dataTransfer.setData("Text",Wk(e.state,fS,e.state.sliceDoc(i.from,i.to))),t.dataTransfer.effectAllowed="copyMove"),!1},qk.dragend=e=>(e.inputState.draggedContent=null,!1),qk.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let i=t.dataTransfer.files;if(i&&i.length){let n=Array(i.length),r=0,s=()=>{++r==i.length&&eP(e,t,n.filter(e=>null!=e).join(e.state.lineBreak),!1)};for(let e=0;e<i.length;e++){let t=new FileReader;t.onerror=s,t.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(n[e]=t.result),s()},t.readAsText(i[e])}return!0}{let i=t.dataTransfer.getData("Text");if(i)return eP(e,t,i,!0),!0}return!1},qk.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let i=Bk?null:t.clipboardData;return i?(Vk(e,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(e){let t=e.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{e.focus(),i.remove(),Vk(e,i.value)},50)}(e),!1)};let tP=null;qk.copy=qk.cut=(e,t)=>{if(!bx(e.contentDOM,e.observer.selectionRange))return!1;let{text:i,ranges:n,linewise:r}=function(e){let t=[],i=[],n=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),i.push(r));if(!t.length){let r=-1;for(let{from:n}of e.selection.ranges){let s=e.doc.lineAt(n);s.number>r&&(t.push(s.text),i.push({from:s.from,to:Math.min(e.doc.length,s.to+1)})),r=s.number}n=!0}return{text:Wk(e,fS,t.join(e.lineBreak)),ranges:i,linewise:n}}(e.state);if(!i&&!r)return!1;tP=r?i:null,"cut"!=t.type||e.state.readOnly||e.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=Bk?null:t.clipboardData;return s?(s.clearData(),s.setData("text/plain",i),!0):(function(e,t){let i=e.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=t,n.focus(),n.selectionEnd=t.length,n.selectionStart=0,setTimeout(()=>{n.remove(),e.focus()},50)}(e,i),!1)};const iP=Hw.define();function nP(e,t){let i=[];for(let n of e.facet(dS)){let r=n(e,t);r&&i.push(r)}return i.length?e.update({effects:i,annotations:iP.of(!0)}):null}function rP(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let i=nP(e.state,t);i?e.dispatch(i):e.update([])}},10)}Xk.focus=e=>{e.inputState.lastFocusTime=Date.now(),e.scrollDOM.scrollTop||!e.inputState.lastScrollTop&&!e.inputState.lastScrollLeft||(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),rP(e)},Xk.blur=e=>{e.observer.clearSelectionRange(),rP(e)},Xk.compositionstart=Xk.compositionupdate=e=>{e.observer.editContext||(null==e.inputState.compositionFirstChange&&(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},Xk.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,nx.chrome&&nx.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then(()=>e.observer.flush()):setTimeout(()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])},50))},Xk.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},qk.beforeinput=(e,t)=>{var i,n;if("insertText"!=t.inputType&&"insertCompositionText"!=t.inputType||(e.inputState.insertingText=t.data,e.inputState.insertingTextAt=Date.now()),"insertReplacementText"==t.inputType&&e.observer.editContext){let n=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),r=t.getTargetRanges();if(n&&r.length){let t=r[0],i=e.posAtDOM(t.startContainer,t.startOffset),s=e.posAtDOM(t.endContainer,t.endOffset);return Qk(e,{from:i,to:s,insert:e.state.toText(n)},null),!0}}let r;if(nx.chrome&&nx.android&&(r=Lk.find(e=>e.inputType==t.inputType))&&(e.observer.delayAndroidKey(r.key,r.keyCode),"Backspace"==r.key||"Delete"==r.key)){let t=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())},100)}return nx.ios&&"deleteContentForward"==t.inputType&&e.observer.flushSoon(),nx.safari&&"insertText"==t.inputType&&e.inputState.composing>=0&&setTimeout(()=>Xk.compositionend(e,t),20),!1};const sP=new Set;const aP=["pre-wrap","normal","pre-line","break-spaces"];let oP=!1;function lP(){oP=!1}class cP{constructor(e){this.lineWrapping=e,this.doc=Gb.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return aP.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(10*n)]||(t=!0,this.heightSamples[Math.floor(10*n)]=!0)}return t}refresh(e,t,i,n,r,s){let a=aP.indexOf(e)>-1,o=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=a||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=a,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,o){this.heightSamples={};for(let e=0;e<s.length;e++){let t=s[e];t<0?e++:this.heightSamples[Math.floor(10*t)]=!0}}return o}}class hP{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class uP{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return"number"==typeof this._content?hx.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof fx?this._content.widget:null}get widgetLineBreaks(){return"number"==typeof this._content?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new uP(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var dP=function(e){return e[e.ByPos=0]="ByPos",e[e.ByHeight=1]="ByHeight",e[e.ByPosNoHeight=2]="ByPosNoHeight",e}(dP||(dP={}));const pP=.001;class fP{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(2&this.flags)>0}set outdated(e){this.flags=(e?2:0)|-3&this.flags}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>pP&&(oP=!0),this.height=e)}replace(e,t,i){return fP.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let r=this,s=i.doc;for(let a=n.length-1;a>=0;a--){let{fromA:o,toA:l,fromB:c,toB:h}=n[a],u=r.lineAt(o,dP.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=l?u:r.lineAt(l,dP.ByPosNoHeight,i,0,0);for(h+=d.to-l,l=d.to;a>0&&u.from<=n[a-1].toA;)o=n[a-1].fromA,c=n[a-1].fromB,a--,o<u.from&&(u=r.lineAt(o,dP.ByPosNoHeight,i,0,0));c+=u.from-o,o=u.from;let p=_P.build(i.setDoc(s),e,c,h);r=mP(r,r.replace(o,l,p))}return r.updateHeight(i,0)}static empty(){return new vP(0,0,0)}static of(e){if(1==e.length)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>2*r){let r=e[t-1];r.break?e.splice(--t,1,r.left,null,r.right):e.splice(--t,1,r.left,r.right),i+=1+r.break,n-=r.size}else{if(!(r>2*n))break;{let t=e[i];t.break?e.splice(i,1,t.left,null,t.right):e.splice(i,1,t.left,t.right),i+=2+t.break,r-=t.size}}else if(n<r){let i=e[t++];i&&(n+=i.size)}else{let t=e[--i];t&&(r+=t.size)}let s=0;return null==e[t-1]?(s=1,t--):null==e[t]&&(s=1,i++),new bP(fP.of(e.slice(0,t)),s,fP.of(e.slice(i)))}}function mP(e,t){return e==t?e:(e.constructor!=t.constructor&&(oP=!0),t)}fP.prototype.size=1;const gP=ux.replace({});class OP extends fP{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new uP(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,n){return this.spaceAbove&&e<i+this.spaceAbove?new uP(n,0,i,this.spaceAbove,gP):this.mainBlock(i,n)}lineAt(e,t,i,n,r){let s=this.mainBlock(n,r);return this.spaceAbove?this.blockAt(0,i,n,r).join(s):s}forEachLine(e,t,i,n,r,s){e<=r+this.length&&t>=r&&s(this.lineAt(0,dP.ByPos,i,n,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class vP extends OP{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new uP(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let n=i[0];return 1==i.length&&(n instanceof vP||n instanceof yP&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof yP?n=new vP(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):fP.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class yP extends fP{constructor(e){super(e,0)}heightMetrics(e,t){let i,n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,a=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*s);i=t/s,this.length>s+1&&(a=(this.height-t)/(this.length-s-1))}else i=this.height/s;return{firstLine:n,lastLine:r,perLine:i,perChar:a}}blockAt(e,t,i,n){let{firstLine:r,lastLine:s,perLine:a,perChar:o}=this.heightMetrics(t,n);if(t.lineWrapping){let r=n+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),s=t.doc.lineAt(r),l=a+s.length*o,c=Math.max(i,e-l/2);return new uP(s.from,s.length,c,l,0)}{let n=Math.max(0,Math.min(s-r,Math.floor((e-i)/a))),{from:o,length:l}=t.doc.line(r+n);return new uP(o,l,i+a*n,a,0)}}lineAt(e,t,i,n,r){if(t==dP.ByHeight)return this.blockAt(e,i,n,r);if(t==dP.ByPosNoHeight){let{from:t,to:n}=i.doc.lineAt(e);return new uP(t,n-t,0,0,0)}let{firstLine:s,perLine:a,perChar:o}=this.heightMetrics(i,r),l=i.doc.lineAt(e),c=a+l.length*o,h=l.number-s,u=n+a*h+o*(l.from-r-h);return new uP(l.from,l.length,Math.max(n,Math.min(u,n+this.height-c)),c,0)}forEachLine(e,t,i,n,r,s){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:a,perLine:o,perChar:l}=this.heightMetrics(i,r);for(let c=e,h=n;c<=t;){let t=i.doc.lineAt(c);if(c==e){let i=t.number-a;h+=o*i+l*(e-r-i)}let n=o+l*t.length;s(new uP(t.from,t.length,h,n,0)),h+=n,c=t.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let e=i[i.length-1];e instanceof yP?i[i.length-1]=new yP(e.length+n):i.push(null,new yP(n-1))}if(e>0){let t=i[0];t instanceof yP?i[0]=new yP(e+t.length):i.unshift(new yP(e-1),null)}return fP.of(i)}decomposeLeft(e,t){t.push(new yP(e-1),null)}decomposeRight(e,t){t.push(null,new yP(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let r=t+this.length;if(n&&n.from<=t+this.length&&n.more){let i=[],s=Math.max(t,n.from),a=-1;for(n.from>t&&i.push(new yP(n.from-t-1).updateHeight(e,t));s<=r&&n.more;){let t=e.doc.lineAt(s).length;i.length&&i.push(null);let r=n.heights[n.index++],o=0;r<0&&(o=-r,r=n.heights[n.index++]),-1==a?a=r:Math.abs(r-a)>=pP&&(a=-2);let l=new vP(t,r,o);l.outdated=!1,i.push(l),s+=t+1}s<=r&&i.push(null,new yP(r-s).updateHeight(e,s));let o=fP.of(i);return(a<0||Math.abs(o.height-this.height)>=pP||Math.abs(a-this.heightMetrics(e,t).perLine)>=pP)&&(oP=!0),mP(this,o)}return(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class bP extends fP{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return 1&this.flags}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let s=n+this.left.height,a=r+this.left.length+this.break,o=t==dP.ByHeight?e<s:e<a,l=o?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,s,a);if(this.break||(o?l.to<a:l.from>a))return l;let c=t==dP.ByPosNoHeight?dP.ByPosNoHeight:dP.ByPos;return o?l.join(this.right.lineAt(a,c,i,s,a)):this.left.lineAt(a,c,i,n,r).join(l)}forEachLine(e,t,i,n,r,s){let a=n+this.left.height,o=r+this.left.length+this.break;if(this.break)e<o&&this.left.forEachLine(e,t,i,n,r,s),t>=o&&this.right.forEachLine(e,t,i,a,o,s);else{let l=this.lineAt(o,dP.ByPos,i,n,r);e<l.from&&this.left.forEachLine(e,l.from-1,i,n,r,s),l.to>=e&&l.from<=t&&s(l),t>l.to&&this.right.forEachLine(l.to+1,t,i,a,o,s)}}replace(e,t,i){let n=this.left.length+this.break;if(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let s=r.length;for(let a of i)r.push(a);if(e>0&&wP(r,s-1),t<this.length){let e=r.length;this.decomposeRight(t,r),wP(r,e)}return fP.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?fP.of(this.break?[e,null,t]:[e,t]):(this.left=mP(this.left,e),this.right=mP(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:r,right:s}=this,a=t+r.length+this.break,o=null;return n&&n.from<=t+r.length&&n.more?o=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=a+s.length&&n.more?o=s=s.updateHeight(e,a,i,n):s.updateHeight(e,a,i),o?this.balanced(r,s):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function wP(e,t){let i,n;null==e[t]&&(i=e[t-1])instanceof yP&&(n=e[t+1])instanceof yP&&e.splice(t-1,3,new yP(i.length+1+n.length))}class _P{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof vP?i.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new vP(e-this.pos,-1,0)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let s=t-e;i.block?this.addBlock(new OP(s,n,i)):(s||r||n>=5)&&this.addLineDeco(n,r,s)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||null==this.nodes[this.nodes.length-1])&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new vP(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new yP(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof vP)return e;let t=new vP(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||t instanceof vP||this.isCovered?(this.writtenTo<this.pos||null==t)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos)):this.nodes.push(new vP(0,-1,0));let i=e;for(let n of this.nodes)n instanceof vP&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new _P(i,e);return y_.spans(t,i,n,r,0),r.finish(i)}}class xP{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&gx(e,t,this.changes,5)}}function SP(e,t){let i=e.getBoundingClientRect(),n=e.ownerDocument,r=n.defaultView||window,s=Math.max(0,i.left),a=Math.min(r.innerWidth,i.right),o=Math.max(0,i.top),l=Math.min(r.innerHeight,i.bottom);for(let c=e.parentNode;c&&c!=n.body;)if(1==c.nodeType){let t=c,i=window.getComputedStyle(t);if((t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&"visible"!=i.overflow){let i=t.getBoundingClientRect();s=Math.max(s,i.left),a=Math.min(a,i.right),o=Math.max(o,i.top),l=Math.min(c==e.parentNode?r.innerHeight:l,i.bottom)}c="absolute"==i.position||"fixed"==i.position?t.offsetParent:t.parentNode}else{if(11!=c.nodeType)break;c=c.host}return{left:s-i.left,right:Math.max(s,a)-i.left,top:o-(i.top+t),bottom:Math.max(o,l)-(i.top+t)}}function kP(e,t){let i=e.getBoundingClientRect();return{left:0,right:i.right-i.left,top:t,bottom:i.bottom-(i.top+t)}}class PP{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return ux.replace({widget:new TP(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class TP extends cx{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class $P{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=RP,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=zx.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet($S).some(e=>"function"!=typeof e&&"cm-lineWrapping"==e.class);this.heightOracle=new cP(i),this.stateDeco=QP(t),this.heightMap=fP.empty().applyChanges(this.stateDeco,Gb.empty,this.heightOracle.setDoc(t.doc),[new LS(0,0,0,t.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ux.set(this.lineGaps.map(e=>e.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:e,to:t})=>n>=e&&n<=t)){let{from:t,to:i}=this.lineBlockAt(n);e.push(new EP(t,i))}}return this.viewports=e.sort((e,t)=>e.from-t.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?RP:new IP(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(jP(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=QP(this.state);let n=e.changedRanges,r=LS.extendWithRanges(n,function(e,t,i){let n=new xP;return y_.compare(e,t,i,n,0),n.changes}(i,this.stateDeco,e?e.changes:pw.empty(this.state.doc.length))),s=this.heightMap.height,a=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);lP(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=s||oP)&&(e.flags|=2),a?(this.scrollAnchorPos=e.changes.mapPos(a.from,-1),this.scrollAnchorHeight=a.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=s);let o=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<o.from||t.range.head>o.to)||!this.viewportIsAppropriate(o))&&(o=this.getViewport(0,t));let l=o.from!=this.viewport.from||o.to!=this.viewport.to;this.viewport=o,e.flags|=this.updateForViewport(),(l||!e.changes.empty||2&e.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(gS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?zx.RTL:zx.LTR;let s=this.heightOracle.mustRefreshForWrapping(r)||"refresh"===this.mustMeasureContent,a=t.getBoundingClientRect(),o=s||this.mustMeasureContent||this.contentDOMHeight!=a.height;this.contentDOMHeight=a.height,this.mustMeasureContent=!1;let l=0,c=0;if(a.width&&a.height){let{scaleX:e,scaleY:i}=Ex(t,a);(e>.005&&Math.abs(this.scaleX-e)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=e,this.scaleY=i,l|=16,s=o=!0)}let h=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==h&&this.paddingBottom==u||(this.paddingTop=h,this.paddingBottom=u,l|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(o=!0),this.editorWidth=e.scrollDOM.clientWidth,l|=16);let d=Ax(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Nx(this.scrollParent||e.win);let f=(this.printing?kP:SP)(t,this.paddingTop),m=f.top-this.pixelViewport.top,g=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let O=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(O!=this.inView&&(this.inView=O,O&&(o=!0)),!this.inView&&!this.scrollTarget&&!function(e){let t=e.getBoundingClientRect(),i=e.ownerDocument.defaultView||window;return t.left<i.innerWidth&&t.right>0&&t.top<i.innerHeight&&t.bottom>0}(e.dom))return 0;let v=a.width;if(this.contentDOMWidth==v&&this.editorHeight==e.scrollDOM.clientHeight||(this.contentDOMWidth=a.width,this.editorHeight=e.scrollDOM.clientHeight,l|=16),o){let t=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(t)&&(s=!0),s||n.lineWrapping&&Math.abs(v-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:a,textHeight:o}=e.docView.measureTextSize();s=i>0&&n.refresh(r,i,a,o,Math.max(5,v/a),t),s&&(e.docView.minWidth=0,l|=16)}m>0&&g>0?c=Math.max(m,g):m<0&&g<0&&(c=Math.min(m,g)),lP();for(let i of this.viewports){let r=i.from==this.viewport.from?t:e.docView.measureVisibleLineHeights(i);this.heightMap=(s?fP.empty().applyChanges(this.stateDeco,Gb.empty,this.heightOracle,[new LS(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,s,new hP(i.from,r))}oP&&(l|=2)}let y=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return y&&(2&l&&(l|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),l|=this.updateForViewport()),(2&l||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(s?[]:this.lineGaps,e)),l|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),l}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:s,visibleBottom:a}=this,o=new EP(n.lineAt(s-1e3*i,dP.ByHeight,r,0,0).from,n.lineAt(a+1e3*(1-i),dP.ByHeight,r,0,0).to);if(t){let{head:e}=t.range;if(e<o.from||e>o.to){let i,s=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),a=n.lineAt(e,dP.ByPos,r,0,0);i="center"==t.y?(a.top+a.bottom)/2-s/2:"start"==t.y||"nearest"==t.y&&e<o.from?a.top:a.bottom-s,o=new EP(n.lineAt(i-500,dP.ByHeight,r,0,0).from,n.lineAt(i+s+500,dP.ByHeight,r,0,0).to)}}return o}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new EP(this.heightMap.lineAt(i,dP.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,dP.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,dP.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,dP.ByPos,this.heightOracle,0,0),{visibleTop:s,visibleBottom:a}=this;return(0==e||n<=s-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=a+Math.max(10,Math.min(i,250)))&&n>s-2e3&&r<a+2e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new PP(t.mapPos(n.from),t.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,s=n<<1;if(this.defaultTextDirection!=zx.LTR&&!i)return[];let a=[],o=(n,s,l,c)=>{if(s-n<r)return;let h=this.state.selection.main,u=[h.from];h.empty||u.push(h.to);for(let e of u)if(e>n&&e<s)return o(n,e-10,l,c),void o(e+10,s,l,c);let d=function(e,t){for(let i of e)if(t(i))return i;return}(e,e=>e.from>=l.from&&e.to<=l.to&&Math.abs(e.from-n)<r&&Math.abs(e.to-s)<r&&!u.some(t=>e.from<t&&e.to>t));if(!d){if(s<l.to&&t&&i&&t.visibleRanges.some(e=>e.from<=s&&e.to>=s)){let e=t.moveToLineBoundary(ww.cursor(s),!1,!0).head;e>n&&(s=e)}let e=this.gapSize(l,n,s,c);d=new PP(n,s,e,i||e<2e6?e:2e6)}a.push(d)},l=t=>{if(t.length<s||t.type!=hx.Text)return;let r=function(e,t,i){let n=[],r=e,s=0;y_.spans(i,e,t,{span(){},point(e,t){e>r&&(n.push({from:r,to:e}),s+=e-r),r=t}},20),r<t&&(n.push({from:r,to:t}),s+=t-r);return{total:s,ranges:n}}(t.from,t.to,this.stateDeco);if(r.total<s)return;let a,l,c=this.scrollTarget?this.scrollTarget.range.head:null;if(i){let e,i,s=n/this.heightOracle.lineLength*this.heightOracle.lineHeight;if(null!=c){let n=CP(r,c),a=((this.visibleBottom-this.visibleTop)/2+s)/t.height;e=n-a,i=n+a}else e=(this.visibleTop-t.top-s)/t.height,i=(this.visibleBottom-t.top+s)/t.height;a=AP(r,e),l=AP(r,i)}else{let i=r.total*this.heightOracle.charWidth,s=n*this.heightOracle.charWidth,o=0;if(i>2e6)for(let n of e)n.from>=t.from&&n.from<t.to&&n.size!=n.displaySize&&n.from*this.heightOracle.charWidth+o<this.pixelViewport.left&&(o=n.size-n.displaySize);let h,u,d=this.pixelViewport.left+o,p=this.pixelViewport.right+o;if(null!=c){let e=CP(r,c),t=((p-d)/2+s)/i;h=e-t,u=e+t}else h=(d-s)/i,u=(p+s)/i;a=AP(r,h),l=AP(r,u)}a>t.from&&o(t.from,a,t,r),l<t.to&&o(l,t.to,t,r)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(l):l(c);return a}gapSize(e,t,i,n){let r=CP(n,i)-CP(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){PP.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=ux.set(e.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];y_.spans(t,this.viewport.from,this.viewport.to,{span(e,t){i.push({from:e,to:t})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r<i.length&&!(8&n);r++){let t=this.visibleRanges[r],s=i[r];t.from==s.from&&t.to==s.to||(n|=4,e&&e.mapPos(t.from,-1)==s.from&&e.mapPos(t.to,1)==s.to||(n|=8))}return this.visibleRanges=i,n}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||jP(this.heightMap.lineAt(e,dP.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||jP(this.heightMap.lineAt(this.scaler.fromDOM(e),dP.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return jP(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class EP{constructor(e,t){this.from=e,this.to=t}}function AP({total:e,ranges:t},i){if(i<=0)return t[0].from;if(i>=1)return t[t.length-1].to;let n=Math.floor(e*i);for(let r=0;;r++){let{from:e,to:i}=t[r],s=i-e;if(n<=s)return e+n;n-=s}}function CP(e,t){let i=0;for(let{from:n,to:r}of e.ranges){if(t<=r){i+=t-n;break}i+=r-n}return i/e.total}const RP={toDOM:e=>e,fromDOM:e=>e,scale:1,eq(e){return e==this}};function QP(e){let t=e.facet(ES).filter(e=>"function"!=typeof e),i=e.facet(CS).filter(e=>"function"!=typeof e);return i.length&&t.push(y_.join(i)),t}class IP{constructor(e,t,i){let n=0,r=0,s=0;this.viewports=i.map(({from:i,to:r})=>{let s=t.lineAt(i,dP.ByPos,e,0,0).top,a=t.lineAt(r,dP.ByPos,e,0,0).bottom;return n+=a-s,{from:i,to:r,top:s,bottom:a,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let a of this.viewports)a.domTop=s+(a.top-r)*this.scale,s=a.domBottom=a.domTop+(a.bottom-a.top),r=a.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}eq(e){return e instanceof IP&&(this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to))}}function jP(e,t){if(1==t.scale)return e;let i=t.toDOM(e.top),n=t.toDOM(e.bottom);return new uP(e.from,e.length,i,n-i,Array.isArray(e._content)?e._content.map(e=>jP(e,t)):e._content)}const MP=Sw.define({combine:e=>e.join(" ")}),NP=Sw.define({combine:e=>e.indexOf(!0)>-1}),LP=j_.newName(),ZP=j_.newName(),DP=j_.newName(),zP={"&light":"."+ZP,"&dark":"."+DP};function UP(e,t,i){return new j_(t,{finish:t=>/&/.test(t)?t.replace(/&\w*/,t=>{if("&"==t)return e;if(!i||!i[t])throw new RangeError(`Unsupported selector: ${t}`);return i[t]}):e+" "+t})}const qP=UP("."+LP,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},zP),XP={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},BP=nx.ie&&nx.ie_version<=11;class WP{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Cx,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let e of t)this.queue.push(e);(nx.ie&&nx.ie_version<=11||nx.ios&&e.composing)&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!nx.android||!1===e.constructor.EDIT_CONTEXT||nx.chrome&&nx.chrome_version<126||(this.editContext=new YP(e),e.state.facet(_S)&&(e.contentDOM.editContext=this.editContext.editContext)),BP&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var e;(null===(e=this.view.docView)||void 0===e?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){("change"!=e.type&&e.type||e.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(_S)?i.root.activeElement!=this.dom:!bx(this.dom,n))return;let r=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);r&&r.isWidget()&&r.widget.ignoreEvent(e)?t||(this.selectionChanged=!1):(nx.ie&&nx.ie_version<=11||nx.android&&nx.chrome)&&!i.state.selection.main.empty&&n.focusNode&&_x(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=vx(e.root);if(!t)return!1;let i=nx.safari&&11==e.root.nodeType&&e.root.activeElement==this.dom&&function(e,t){if(t.getComposedRanges){let i=t.getComposedRanges(e.root)[0];if(i)return FP(e,i)}let i=null;function n(e){e.preventDefault(),e.stopImmediatePropagation(),i=e.getTargetRanges()[0]}return e.contentDOM.addEventListener("beforeinput",n,!0),e.dom.ownerDocument.execCommand("indent"),e.contentDOM.removeEventListener("beforeinput",n,!0),i?FP(e,i):null}(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=bx(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&function(e,t){let i=t.focusNode,n=t.focusOffset;if(!i||t.anchorNode!=i||t.anchorOffset!=n)return!1;for(n=Math.min(n,Px(i));;)if(n){if(1!=i.nodeType)return!1;let e=i.childNodes[n-1];"false"==e.contentEditable?n--:(i=e,n=Px(i))}else{if(i==e)return!0;n=xx(i),i=i.parentNode}}(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(1==i.nodeType)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else{if(11!=i.nodeType)break;i=i.host}if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let e of this.scrollTargets)e.removeEventListener("scroll",this.onScroll);for(let e of this.scrollTargets=t)e.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,XP),BP&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),BP&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let e=()=>{let e=this.delayedAndroidKey;if(e){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&Mx(this.dom,e.key,e.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}this.delayedAndroidKey&&"Enter"!=e||(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(null===(i=this.delayedAndroidKey)||void 0===i?void 0:i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let e=this.readMutation(r);e&&(e.typeOver&&(n=!0),-1==t?({from:t,to:i}=e):(t=Math.min(e.from,t),i=Math.max(e.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&bx(this.dom,this.selectionRange);if(e<0&&!n)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Ak(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,n=Rk(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!jk(this.view.state.selection,t.newSel.main))&&this.view.update([]),n}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty("attributes"==e.type),"childList"==e.type){let i=VP(t,e.previousSibling||e.target.previousSibling,-1),n=VP(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}return"characterData"==e.type?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(_S)!=e.state.facet(_S)&&(e.view.contentDOM.editContext=e.state.facet(_S)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),null===(e=this.intersection)||void 0===e||e.disconnect(),null===(t=this.gapIntersection)||void 0===t||t.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function VP(e,t,i){for(;t;){let n=zS.get(t);if(n&&n.parent==e)return n;let r=t.parentNode;t=r!=e.dom?r:i>0?t.nextSibling:t.previousSibling}return null}function FP(e,t){let i=t.startContainer,n=t.startOffset,r=t.endContainer,s=t.endOffset,a=e.docView.domAtPos(e.state.selection.main.anchor,1);return _x(a.node,a.offset,r,s)&&([i,n,r,s]=[r,s,i,n]),{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:s}}class YP{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let n=e.state.selection.main,{anchor:r,head:s}=n,a=this.toEditorPos(i.updateRangeStart),o=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:a,drifted:!1});let l=o-a>i.text.length;a==this.from&&r<this.from?a=r:o==this.to&&r>this.to&&(o=r);let c=Ik(e.state.sliceDoc(a,o),i.text,(l?n.from:n.to)-a,l?"end":null);if(!c){let t=ww.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(jk(t,n)||e.dispatch({selection:t,userEvent:"select"}))}let h={from:c.from+a,to:c.toA+a,insert:Gb.of(i.text.slice(c.from,c.toB).split("\n"))};if((nx.mac||nx.android)&&h.from==s-1&&/^\. ?$/.test(i.text)&&"off"==e.contentDOM.getAttribute("autocorrect")&&(h={from:a,to:o,insert:Gb.of([i.text.replace("."," ")])}),this.pendingContextChange=h,!e.state.readOnly){let t=this.to-this.from+(h.to-h.from+h.insert.length);Qk(e,h,ww.single(this.toEditorPos(i.selectionStart,t),this.toEditorPos(i.selectionEnd,t)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),h.from<h.to&&!h.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let t=this.toEditorPos(i.rangeStart),s=this.toEditorPos(i.rangeEnd);t<s;t++){let i=e.coordsForChar(t);r=i&&new DOMRect(i.left,i.top,i.right-i.left,i.bottom-i.top)||r||new DOMRect,n.push(r)}t.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=t=>{let i=[];for(let e of t.getTextFormats()){let t=e.underlineStyle,n=e.underlineThickness;if(!/none/i.test(t)&&!/none/i.test(n)){let r=this.toEditorPos(e.rangeStart),s=this.toEditorPos(e.rangeEnd);if(r<s){let e=`text-decoration: underline ${/^[a-z]/.test(t)?t+" ":"Dashed"==t?"dashed ":"Squiggle"==t?"wavy ":""}${/thin/i.test(n)?1:2}px`;i.push(ux.mark({attributes:{style:e}}).range(r,s))}}}e.dispatch({effects:bS.of(ux.set(i))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:t}=this.composing;this.composing=null,t&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:e=>{this.editContext.updateControlBounds(e.contentDOM.getBoundingClientRect());let t=vx(e.root);t&&t.rangeCount&&this.editContext.updateSelectionBounds(t.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,n=this.pendingContextChange;return e.changes.iterChanges((r,s,a,o,l)=>{if(i)return;let c=l.length-(s-r);if(n&&s>=n.to){if(n.from==r&&n.to==s&&n.insert.eq(l))return n=this.pendingContextChange=null,t+=c,void(this.to+=c);n=null,this.revertPending(e.state)}if(r+=t,(s+=t)<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||s>this.to||this.to-this.from+l.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(r),this.toContextPos(s),l.toString()),this.to+=c}t+=c}),n&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(e=>!e.isUserEvent("input.type")&&e.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):this.applyEdits(e)&&this.rangeIsValid(e.state)?(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state):(this.pendingContextChange=null,this.reset(e.state)),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),n=this.toContextPos(t.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>3e4)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class GP{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(e=>e.forEach(e=>i(e,this)))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||function(e){for(;e;){if(e&&(9==e.nodeType||11==e.nodeType&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}(e.parent)||document,this.viewState=new $P(this,e.state||d_.create(e)),e.scrollTo&&e.scrollTo.is(yS)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(SS).map(e=>new PS(e));for(let n of this.plugins)n.update(this);this.observer=new WP(this),this.inputState=new Mk(this),this.inputState.ensureHandlers(this.plugins),this.docView=new hk(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(t=document.fonts)||void 0===t?void 0:t.ready)&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=1==e.length&&e[0]instanceof t_?e:1==e.length&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t,i=!1,n=!1,r=this.state;for(let d of e){if(d.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=d.state}if(this.destroyed)return void(this.viewState.state=r);let s=this.hasFocus,a=0,o=null;e.some(e=>e.annotation(iP))?(this.inputState.notifiedFocused=s,a=1):s!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=s,o=nP(r,s),o||(a=1));let l=this.observer.delayedAndroidKey,c=null;if(l?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(d_.phrases)!=this.state.facet(d_.phrases))return this.setState(r);t=ZS.create(this,r,e),t.flags|=a;let h=this.viewState.scrollTarget;try{this.updateState=2;for(let t of e){if(h&&(h=h.map(t.changes)),t.scrollIntoView){let{main:e}=t.state.selection,{x:i,y:n}=this.state.facet(GP.cursorScrollMargin);h=new vS(e.empty?e:ww.cursor(e.head,e.head>e.anchor?-1:1),"nearest","nearest",n,i)}for(let e of t.effects)e.is(yS)&&(h=e.value.clip(this.state))}this.viewState.update(t,h),this.bidiCache=JP.update(this.bidiCache,t.changes),t.empty||(this.updatePlugins(t),this.inputState.update(t)),i=this.docView.update(t),this.state.facet(NS)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(i,e.some(e=>e.isUserEvent("select.pointer")))}finally{this.updateState=0}if(t.startState.facet(MP)!=t.state.facet(MP)&&(this.viewState.mustMeasureContent=!0),(i||n||h||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!t.empty)for(let d of this.state.facet(hS))try{d(t)}catch(u){wS(this.state,u,"update listener")}(o||c)&&Promise.resolve().then(()=>{o&&this.state==o.startState&&this.dispatch(o),c&&!Rk(this,c)&&l.force&&Mx(this.contentDOM,l.key,l.keyCode)})}setState(e){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=e);this.updateState=2;let t=this.hasFocus;try{for(let e of this.plugins)e.destroy(this);this.viewState=new $P(this,e),this.plugins=e.facet(SS).map(e=>new PS(e)),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView.destroy(),this.docView=new hk(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(SS),i=e.state.facet(SS);if(t!=i){let n=[];for(let r of i){let i=t.indexOf(r);if(i<0)n.push(new PS(r));else{let t=this.plugins[i];t.mustUpdate=e,n.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let i=t.value;if(i&&i.docViewUpdate)try{i.docViewUpdate(this)}catch(e){wS(this.state,e,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:s}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(s=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(s<0)if(Nx(i||this.win))r=-1,s=this.viewState.heightMap.height;else{let e=this.viewState.scrollAnchorAt(n);r=e.from,s=e.top}this.updateState=1;let o=this.viewState.measure();if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(e>5)break;let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let c=l.map(e=>{try{return e.read(this)}catch(t){return wS(this.state,t),KP}}),h=ZS.create(this,this.state,[]),u=!1;h.flags|=o,t?t.flags|=o:t=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),u=this.docView.update(h),u&&this.docViewUpdate());for(let e=0;e<l.length;e++)if(c[e]!=KP)try{let t=l[e];t.write&&t.write(c[e],this)}catch(a){wS(this.state,a)}if(u&&this.docView.updateSelection(!0),!h.viewportChanged&&0==this.measureRequests.length){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,s=-1;continue}{let e=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-s)/this.scaleY;if((e>1||e<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n+=e,i?i.scrollTop+=e:this.win.scrollBy(0,e),s=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let o of this.state.facet(hS))o(t)}get themeClasses(){return LP+" "+(this.state.facet(NP)?DP:ZP)+" "+this.state.facet(MP)}updateAttrs(){let e=eT(this,TS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(_S)?"true":"false",class:"cm-content",style:`${nx.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),eT(this,$S,t);let i=this.observer.ignore(()=>{let i=ox(this.contentDOM,this.contentAttrs,t),n=ox(this.dom,this.editorAttrs,e);return i||n});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let e of i.effects)if(e.is(GP.announce)){t&&(this.announceDOM.textContent=""),t=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=e.value}}mountStyles(){this.styleModules=this.state.facet(NS);let e=this.state.facet(GP.cspNonce);j_.mount(this.root,this.styleModules.concat(qP).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(null!=e.key)for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key)return void(this.measureRequests[t]=e);this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(void 0===t||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(t=>t.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return wk(this,e,vk(this,e,t,i))}moveByGroup(e,t){return wk(this,e,vk(this,e,t,t=>function(e,t,i){let n=e.state.charCategorizer(t),r=n(i);return e=>{let t=n(e);return r==l_.Space&&(r=t),r==t}}(this,e.head,t)))}visualLineSide(e,t){let i=this.bidiSpans(e),n=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return ww.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return function(e,t,i,n){let r=Ok(e,t.head,t.assoc||-1),s=n&&r.type==hx.Text&&(e.lineWrapping||r.widgetLineBreaks)?e.coordsAtPos(t.assoc<0&&t.head>r.from?t.head-1:t.head):null;if(s){let t=e.dom.getBoundingClientRect(),n=e.textDirectionAt(r.from),a=e.posAtCoords({x:i==(n==zx.LTR)?t.right-1:t.left+1,y:(s.top+s.bottom)/2});if(null!=a)return ww.cursor(a,i?-1:1)}return ww.cursor(i?r.to:r.from,i?-1:1)}(this,e,t,i)}moveVertically(e,t,i){return wk(this,e,function(e,t,i,n){let r=t.head,s=i?1:-1;if(r==(i?e.state.doc.length:0))return ww.cursor(r,t.assoc);let a,o=t.goalColumn,l=e.contentDOM.getBoundingClientRect(),c=e.coordsAtPos(r,t.assoc||((t.empty?i:t.head==t.from)?1:-1)),h=e.documentTop;if(c)null==o&&(o=c.left-l.left),a=s<0?c.top:c.bottom;else{let t=e.viewState.lineBlockAt(r);null==o&&(o=Math.min(l.right-l.left,e.defaultCharacterWidth*(r-t.from))),a=(s<0?t.top:t.bottom)+h}let u=l.left+o,d=e.viewState.heightOracle.textHeight>>1,p=null!=n?n:d;for(let f=0;;f+=d){let t=a+(p+f)*s,n=xk(e,{x:u,y:t},!1,s);if(i?t>l.bottom:t<l.top)return ww.cursor(n.pos,n.assoc);let r=e.coordsAtPos(n.pos,n.assoc),c=r?(r.top+r.bottom)/2:0;if(!r||(i?c>a:c<a))return ww.cursor(n.pos,n.assoc,void 0,o)}}(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=xk(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),xk(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(e),r=this.bidiSpans(n);return Tx(i,r[Hx.find(r,e-n.from,-1,t)].dir==zx.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(mS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>HP)return iS(e.length);let t,i=this.textDirectionAt(e.from);for(let r of this.bidiCache)if(r.from==e.from&&r.dir==i&&(r.fresh||Kx(r.isolates,t=IS(this,e))))return r.order;t||(t=IS(this,e));let n=function(e,t,i){if(!e)return[new Hx(0,0,t==qx?1:0)];if(t==Ux&&!i.length&&!Gx.test(e))return iS(e.length);if(i.length)for(;e.length>Jx.length;)Jx[Jx.length]=256;let n=[],r=t==Ux?0:1;return tS(e,r,r,i,0,e.length,n),n}(e.text,i,t);return this.bidiCache.push(new JP(e.from,e.to,i,t,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||nx.safari&&(null===(e=this.inputState)||void 0===e?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ix(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((9==e.nodeType?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var i,n,r,s;return yS.of(new vS("number"==typeof e?ww.cursor(e):e,null!==(i=t.y)&&void 0!==i?i:"nearest",null!==(n=t.x)&&void 0!==n?n:"nearest",null!==(r=t.yMargin)&&void 0!==r?r:5,null!==(s=t.xMargin)&&void 0!==s?s:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return yS.of(new vS(ww.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){null==e?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof e?this.inputState.tabFocusMode=e?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return kS.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return kS.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=j_.newName(),n=[MP.of(i),NS.of(UP(`.${i}`,e))];return t&&t.dark&&n.push(NP.of(!0)),n}static baseTheme(e){return Nw.lowest(NS.of(UP("."+LP,e,zP)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&zS.get(i)||zS.get(e);return(null===(t=null==n?void 0:n.root)||void 0===t?void 0:t.view)||null}}GP.styleModule=NS,GP.inputHandler=uS,GP.clipboardInputFilter=pS,GP.clipboardOutputFilter=fS,GP.scrollHandler=OS,GP.focusChangeEffect=dS,GP.perLineTextDirection=mS,GP.exceptionSink=cS,GP.updateListener=hS,GP.editable=_S,GP.mouseSelectionStyle=lS,GP.dragMovesSelection=oS,GP.clickAddsSelectionRange=aS,GP.decorations=ES,GP.blockWrappers=AS,GP.outerDecorations=CS,GP.atomicRanges=RS,GP.bidiIsolatedRanges=QS,GP.cursorScrollMargin=Sw.define({combine:e=>{let t=5,i=5;for(let n of e)"number"==typeof n?t=i=n:({x:t,y:i}=n);return{x:t,y:i}}}),GP.scrollMargins=jS,GP.darkTheme=NP,GP.cspNonce=Sw.define({combine:e=>e.length?e[0]:""}),GP.contentAttributes=$S,GP.editorAttributes=TS,GP.lineWrapping=GP.contentAttributes.of({class:"cm-lineWrapping"}),GP.announce=e_.define();const HP=4096,KP={};class JP{constructor(e,t,i,n,r,s){this.from=e,this.to=t,this.dir=i,this.isolates=n,this.fresh=r,this.order=s}static update(e,t){if(t.empty&&!e.some(e=>e.fresh))return e;let i=[],n=e.length?e[e.length-1].dir:zx.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let s=e[r];s.dir!=n||t.touchesRange(s.from,s.to)||i.push(new JP(t.mapPos(s.from,1),t.mapPos(s.to,-1),s.dir,s.isolates,!1,s.order))}return i}}function eT(e,t,i){for(let n=e.state.facet(t),r=n.length-1;r>=0;r--){let t=n[r],s="function"==typeof t?t(e):t;s&&rx(s,i)}return i}const tT=nx.mac?"mac":nx.windows?"win":nx.linux?"linux":"key";function iT(e,t,i){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),!1!==i&&t.shiftKey&&(e="Shift-"+e),e}const nT=Nw.default(GP.domEventHandlers({keydown:(e,t)=>hT(aT(t.state),e,t,"editor")})),rT=Sw.define({enables:nT}),sT=new WeakMap;function aT(e){let t=e.facet(rT),i=sT.get(t);return i||sT.set(t,i=function(e,t=tT){let i=Object.create(null),n=Object.create(null),r=(e,t)=>{let i=n[e];if(null==i)n[e]=t;else if(i!=t)throw new Error("Key binding "+e+" is used both as a regular binding and as a multi-stroke prefix")},s=(e,n,s,a,o)=>{var l,c;let h=i[e]||(i[e]=Object.create(null)),u=n.split(/ (?!$)/).map(e=>function(e,t){const i=e.split(/-(?!$)/);let n,r,s,a,o=i[i.length-1];"Space"==o&&(o=" ");for(let l=0;l<i.length-1;++l){const e=i[l];if(/^(cmd|meta|m)$/i.test(e))a=!0;else if(/^a(lt)?$/i.test(e))n=!0;else if(/^(c|ctrl|control)$/i.test(e))r=!0;else if(/^s(hift)?$/i.test(e))s=!0;else{if(!/^mod$/i.test(e))throw new Error("Unrecognized modifier name: "+e);"mac"==t?a=!0:r=!0}}return n&&(o="Alt-"+o),r&&(o="Ctrl-"+o),a&&(o="Meta-"+o),s&&(o="Shift-"+o),o}(e,t));for(let t=1;t<u.length;t++){let i=u.slice(0,t).join(" ");r(i,!0),h[i]||(h[i]={preventDefault:!0,stopPropagation:!1,run:[t=>{let n=oT={view:t,prefix:i,scope:e};return setTimeout(()=>{oT==n&&(oT=null)},lT),!0}]})}let d=u.join(" ");r(d,!1);let p=h[d]||(h[d]={preventDefault:!1,stopPropagation:!1,run:(null===(c=null===(l=h._any)||void 0===l?void 0:l.run)||void 0===c?void 0:c.slice())||[]});s&&p.run.push(s),a&&(p.preventDefault=!0),o&&(p.stopPropagation=!0)};for(let a of e){let e=a.scope?a.scope.split(" "):["editor"];if(a.any)for(let t of e){let e=i[t]||(i[t]=Object.create(null));e._any||(e._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:n}=a;for(let t in e)e[t].run.push(e=>n(e,cT))}let n=a[t]||a.key;if(n)for(let t of e)s(t,n,a.run,a.preventDefault,a.stopPropagation),a.shift&&s(t,"Shift-"+n,a.shift,a.preventDefault,a.stopPropagation)}return i}(t.reduce((e,t)=>e.concat(t),[]))),i}let oT=null;const lT=4e3;let cT=null;function hT(e,t,i,n){cT=t;let r=function(e){var t=!(D_&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||z_&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?Z_:L_)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}(t),s=cw(ow(r,0))==r.length&&" "!=r,a="",o=!1,l=!1,c=!1;oT&&oT.view==i&&oT.scope==n&&(a=oT.prefix+" ",Dk.indexOf(t.keyCode)<0&&(l=!0,oT=null));let h,u,d=new Set,p=e=>{if(e){for(let t of e.run)if(!d.has(t)&&(d.add(t),t(i)))return e.stopPropagation&&(c=!0),!0;e.preventDefault&&(e.stopPropagation&&(c=!0),l=!0)}return!1},f=e[n];return f&&(p(f[a+iT(r,t,!s)])?o=!0:!s||!(t.altKey||t.metaKey||t.ctrlKey)||nx.windows&&t.ctrlKey&&t.altKey||nx.mac&&t.altKey&&!t.ctrlKey&&!t.metaKey||!(h=L_[t.keyCode])||h==r?s&&t.shiftKey&&p(f[a+iT(r,t,!0)])&&(o=!0):(p(f[a+iT(h,t,!0)])||t.shiftKey&&(u=Z_[t.keyCode])!=r&&u!=h&&p(f[a+iT(u,t,!1)]))&&(o=!0),!o&&p(f._any)&&(o=!0)),l&&(o=!0),o&&c&&t.stopPropagation(),cT=null,o}class uT{constructor(e,t,i,n,r){this.className=e,this.left=t,this.top=i,this.width=n,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className==this.className&&(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",null!=this.width&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let n=e.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let r=dT(e);return[new uT(t,n.left-r.left,n.top-r.top,null,n.bottom-n.top)]}return function(e,t,i){if(i.to<=e.viewport.from||i.from>=e.viewport.to)return[];let n=Math.max(i.from,e.viewport.from),r=Math.min(i.to,e.viewport.to),s=e.textDirection==zx.LTR,a=e.contentDOM,o=a.getBoundingClientRect(),l=dT(e),c=a.querySelector(".cm-line"),h=c&&window.getComputedStyle(c),u=o.left+(h?parseInt(h.paddingLeft)+Math.min(0,parseInt(h.textIndent)):0),d=o.right-(h?parseInt(h.paddingRight):0),p=Ok(e,n,1),f=Ok(e,r,-1),m=p.type==hx.Text?p:null,g=f.type==hx.Text?f:null;m&&(e.lineWrapping||p.widgetLineBreaks)&&(m=pT(e,n,1,m));g&&(e.lineWrapping||f.widgetLineBreaks)&&(g=pT(e,r,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return v(y(i.from,i.to,m));{let t=m?y(i.from,null,m):b(p,!1),n=g?y(null,i.to,g):b(f,!0),r=[];return(m||p).to<(g||f).from-(m&&g?1:0)||p.widgetLineBreaks>1&&t.bottom+e.defaultLineHeight/2<n.top?r.push(O(u,t.bottom,d,n.top)):t.bottom<n.top&&e.elementAtHeight((t.bottom+n.top)/2).type==hx.Text&&(t.bottom=n.top=(t.bottom+n.top)/2),v(t).concat(r).concat(v(n))}function O(e,i,n,r){return new uT(t,e-l.left,i-l.top,Math.max(0,n-e),r-i)}function v({top:e,bottom:t,horizontal:i}){let n=[];for(let r=0;r<i.length;r+=2)n.push(O(i[r],e,i[r+1],t));return n}function y(t,i,n){let r=1e9,a=-1e9,o=[];function l(t,i,l,c,h){let p=e.coordsAtPos(t,t==n.to?-2:2),f=e.coordsAtPos(l,l==n.from?2:-2);p&&f&&(r=Math.min(p.top,f.top,r),a=Math.max(p.bottom,f.bottom,a),h==zx.LTR?o.push(s&&i?u:p.left,s&&c?d:f.right):o.push(!s&&c?u:f.left,!s&&i?d:p.right))}let c=null!=t?t:n.from,h=null!=i?i:n.to;for(let s of e.visibleRanges)if(s.to>c&&s.from<h)for(let n=Math.max(s.from,c),r=Math.min(s.to,h);;){let s=e.state.doc.lineAt(n);for(let a of e.bidiSpans(s)){let e=a.from+s.from,o=a.to+s.from;if(e>=r)break;o>n&&l(Math.max(e,n),null==t&&e<=c,Math.min(o,r),null==i&&o>=h,a.dir)}if(n=s.to+1,n>=r)break}return 0==o.length&&l(c,null==t,h,null==i,e.textDirection),{top:r,bottom:a,horizontal:o}}function b(e,t){let i=o.top+(t?e.top:e.bottom);return{top:i,bottom:i,horizontal:[]}}}(e,t,i)}}function dT(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==zx.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function pT(e,t,i,n){let r=e.coordsAtPos(t,2*i);if(!r)return n;let s=e.dom.getBoundingClientRect(),a=(r.top+r.bottom)/2,o=e.posAtCoords({x:s.left+1,y:a}),l=e.posAtCoords({x:s.right-1,y:a});return null==o||null==l?n:{from:Math.max(n.from,Math.min(o,l)),to:Math.min(n.to,Math.max(o,l))}}class fT{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(mT)!=e.state.facet(mT)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){!1!==this.layer.updateOnDocViewUpdate&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(mT);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;e==this.scaleX&&t==this.scaleY||(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((e,t)=>{return i=e,n=this.drawn[t],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let t=this.dom.firstChild,i=0;for(let n of e)n.update&&t&&n.constructor&&this.drawn[i].constructor&&n.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(n.draw(),t);for(;t;){let e=t.nextSibling;t.remove(),t=e}this.drawn=e,nx.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const mT=Sw.define();function gT(e){return[kS.define(t=>new fT(t,e)),mT.of(e)]}const OT=Sw.define({combine:e=>p_(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})});function vT(e={}){return[OT.of(e),bT,_T,xT,gS.of(!0)]}function yT(e){return e.startState.facet(OT)!=e.state.facet(OT)}const bT=gT({above:!0,markers(e){let{state:t}=e,i=t.facet(OT),n=[];for(let r of t.selection.ranges){let s=r==t.selection.main;if(r.empty||i.drawRangeCursor&&!(s&&nx.ios&&i.iosSelectionHandles)){let t=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=r.empty?r:ww.cursor(r.head,r.assoc);for(let r of uT.forRange(e,t,i))n.push(r)}}return n},update(e,t){e.transactions.some(e=>e.selection)&&(t.style.animationName="cm-blink"==t.style.animationName?"cm-blink2":"cm-blink");let i=yT(e);return i&&wT(e.state,t),e.docChanged||e.selectionSet||i},mount(e,t){wT(t.state,e)},class:"cm-cursorLayer"});function wT(e,t){t.style.animationDuration=e.facet(OT).cursorBlinkRate+"ms"}const _T=gT({above:!1,markers(e){let t=[],{main:i,ranges:n}=e.state.selection;for(let r of n)if(!r.empty)for(let i of uT.forRange(e,"cm-selectionBackground",r))t.push(i);if(nx.ios&&!i.empty&&e.state.facet(OT).iosSelectionHandles){for(let n of uT.forRange(e,"cm-selectionHandle cm-selectionHandle-start",ww.cursor(i.from,1)))t.push(n);for(let n of uT.forRange(e,"cm-selectionHandle cm-selectionHandle-end",ww.cursor(i.to,1)))t.push(n)}return t},update:(e,t)=>e.docChanged||e.selectionSet||e.viewportChanged||yT(e),class:"cm-selectionLayer"}),xT=Nw.highest(GP.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),ST=e_.define({map:(e,t)=>null==e?null:t.mapPos(e)}),kT=Cw.define({create:()=>null,update:(e,t)=>(null!=e&&(e=t.changes.mapPos(e)),t.effects.reduce((e,t)=>t.is(ST)?t.value:e,e))}),PT=kS.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let i=e.state.field(kT);null==i?null!=this.cursor&&(null===(t=this.cursor)||void 0===t||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(kT)!=i||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:e}=this,t=e.state.field(kT),i=null!=t&&e.coordsAtPos(t);if(!i)return null;let n=e.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+e.scrollDOM.scrollLeft*e.scaleX,top:i.top-n.top+e.scrollDOM.scrollTop*e.scaleY,height:i.bottom-i.top}}drawCursor(e){if(this.cursor){let{scaleX:t,scaleY:i}=this.view;e?(this.cursor.style.left=e.left/t+"px",this.cursor.style.top=e.top/i+"px",this.cursor.style.height=e.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(kT)!=e&&this.view.dispatch({effects:ST.of(e)})}},{eventObservers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){e.target!=this.view.contentDOM&&this.view.contentDOM.contains(e.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function TT(e,t,i,n,r){t.lastIndex=0;for(let s,a=e.iterRange(i,n),o=i;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;s=t.exec(a.value);)r(o+s.index,s)}class $T{constructor(e){const{regexp:t,decoration:i,decorate:n,boundary:r,maxLength:s=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,n)this.addMatch=(e,t,i,r)=>n(r,i,i+e[0].length,e,t);else if("function"==typeof i)this.addMatch=(e,t,n,r)=>{let s=i(e,t,n);s&&r(n,n+e[0].length,s)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(e,t,n,r)=>r(n,n+e[0].length,i)}this.boundary=r,this.maxLength=s}createDeco(e){let t=new b_,i=t.add.bind(t);for(let{from:n,to:r}of function(e,t){let i=e.visibleRanges;if(1==i.length&&i[0].from==e.viewport.from&&i[0].to==e.viewport.to)return i;let n=[];for(let{from:r,to:s}of i)r=Math.max(e.state.doc.lineAt(r).from,r-t),s=Math.min(e.state.doc.lineAt(s).to,s+t),n.length&&n[n.length-1].to>=r?n[n.length-1].to=s:n.push({from:r,to:s});return n}(e,this.maxLength))TT(e.state.doc,this.regexp,n,r,(t,n)=>this.addMatch(n,e,t,i));return t.finish()}updateDeco(e,t){let i=1e9,n=-1;return e.docChanged&&e.changes.iterChanges((t,r,s,a)=>{a>=e.view.viewport.from&&s<=e.view.viewport.to&&(i=Math.min(s,i),n=Math.max(a,n))}),e.viewportMoved||n-i>1e3?this.createDeco(e.view):n>-1?this.updateRange(e.view,t.map(e.changes),i,n):t}updateRange(e,t,i,n){for(let r of e.visibleRanges){let s=Math.max(r.from,i),a=Math.min(r.to,n);if(a>=s){let i=e.state.doc.lineAt(s),n=i.to<a?e.state.doc.lineAt(a):i,o=Math.max(r.from,i.from),l=Math.min(r.to,n.to);if(this.boundary){for(;s>i.from;s--)if(this.boundary.test(i.text[s-1-i.from])){o=s;break}for(;a<n.to;a++)if(this.boundary.test(n.text[a-n.from])){l=a;break}}let c,h=[],u=(e,t,i)=>h.push(i.range(e,t));if(i==n)for(this.regexp.lastIndex=o-i.from;(c=this.regexp.exec(i.text))&&c.index<l-i.from;)this.addMatch(c,e,c.index+i.from,u);else TT(e.state.doc,this.regexp,o,l,(t,i)=>this.addMatch(i,e,t,u));t=t.update({filterFrom:o,filterTo:l,filter:(e,t)=>e<o||t>l,add:h})}}return t}}const ET=null!=/x/.unicode?"gu":"g",AT=new RegExp("[\0-\b\n--\u2028\u2029\ufeff-]",ET),CT={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let RT=null;const QT=Sw.define({combine(e){let t=p_(e,{render:null,specialChars:AT,addSpecialChars:null});return(t.replaceTabs=!function(){var e;if(null==RT&&"undefined"!=typeof document&&document.body){let t=document.body.style;RT=null!=(null!==(e=t.tabSize)&&void 0!==e?e:t.MozTabSize)}return RT||!1}())&&(t.specialChars=new RegExp("\t|"+t.specialChars.source,ET)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,ET)),t}});function IT(e={}){return[QT.of(e),jT||(jT=kS.fromClass(class{constructor(e){this.view=e,this.decorations=ux.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(QT)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new $T({regexp:e.specialChars,decoration:(t,i,n)=>{let{doc:r}=i.state,s=ow(t[0],0);if(9==s){let e=r.lineAt(n),t=i.state.tabSize,s=C_(e.text,t,n-e.from);return ux.replace({widget:new NT((t-s%t)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[s]||(this.decorationCache[s]=ux.replace({widget:new MT(e,s)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(QT);e.startState.facet(QT)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))]}let jT=null;class MT extends cx{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=(i=this.code)>=32?"•":10==i?"":String.fromCharCode(9216+i);var i;let n=e.state.phrase("Control character")+" "+(CT[this.code]||"0x"+this.code.toString(16)),r=this.options.render&&this.options.render(this.code,n,t);if(r)return r;let s=document.createElement("span");return s.textContent=t,s.title=n,s.setAttribute("aria-label",n),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class NT extends cx{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent="\t",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}const LT=ux.line({class:"cm-activeLine"}),ZT=kS.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,i=[];for(let n of e.state.selection.ranges){let r=e.lineBlockAt(n.head);r.from>t&&(i.push(LT.range(r.from)),t=r.from)}return ux.set(i)}},{decorations:e=>e.decorations}),DT="-10000px";class zT{constructor(e,t,i,n){this.facet=t,this.createTooltipView=i,this.removeTooltipView=n,this.input=e.state.facet(t),this.tooltips=this.input.filter(e=>e);let r=null;this.tooltipViews=this.tooltips.map(e=>r=i(e,r))}update(e,t){var i;let n=e.state.facet(this.facet),r=n.filter(e=>e);if(n===this.input){for(let t of this.tooltipViews)t.update&&t.update(e);return!1}let s=[],a=t?[]:null;for(let o=0;o<r.length;o++){let i=r[o],n=-1;if(i){for(let e=0;e<this.tooltips.length;e++){let t=this.tooltips[e];t&&t.create==i.create&&(n=e)}if(n<0)s[o]=this.createTooltipView(i,o?s[o-1]:null),a&&(a[o]=!!i.above);else{let i=s[o]=this.tooltipViews[n];a&&(a[o]=t[n]),i.update&&i.update(e)}}}for(let o of this.tooltipViews)s.indexOf(o)<0&&(this.removeTooltipView(o),null===(i=o.destroy)||void 0===i||i.call(o));return t&&(a.forEach((e,i)=>t[i]=e),t.length=a.length),this.input=n,this.tooltips=r,this.tooltipViews=s,!0}}function UT(e){let t=e.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const qT=Sw.define({combine:e=>{var t,i,n;return{position:nx.ios?"absolute":(null===(t=e.find(e=>e.position))||void 0===t?void 0:t.position)||"fixed",parent:(null===(i=e.find(e=>e.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(n=e.find(e=>e.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||UT}}}),XT=new WeakMap,BT=kS.fromClass(class{constructor(e){this.view=e,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(qT);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new zT(e,YT,(e,t)=>this.createTooltip(e,t),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),e.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e,this.above);t&&this.observeIntersection();let i=t||e.geometryChanged,n=e.state.facet(qT);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let e of this.manager.tooltipViews)e.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let e of this.manager.tooltipViews)this.container.appendChild(e.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(e,t){let i=e.create(this.view),n=t?t.dom:null;if(i.dom.classList.add("cm-tooltip"),e.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let e=document.createElement("div");e.className="cm-tooltip-arrow",i.dom.appendChild(e)}return i.dom.style.position=this.position,i.dom.style.top=DT,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var e,t,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let n of this.manager.tooltipViews)n.dom.remove(),null===(e=n.destroy)||void 0===e||e.call(n);this.parent&&this.container.remove(),null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=1,t=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:e}=this.manager.tooltipViews[0];if(nx.safari){let t=e.getBoundingClientRect();i=Math.abs(t.top+1e4)>1||Math.abs(t.left)>1}else i=!!e.offsetParent&&e.offsetParent!=this.container.ownerDocument.body}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(e=i.width/this.parent.offsetWidth,t=i.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),r=MS(this.view);return{visible:{left:n.left+r.left,top:n.top+r.top,right:n.right-r.right,bottom:n.bottom-r.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((e,t)=>{let i=this.manager.tooltipViews[t];return i.getCoords?i.getCoords(e.pos):this.view.coordsAtPos(e.pos)}),size:this.manager.tooltipViews.map(({dom:e})=>e.getBoundingClientRect()),space:this.view.state.facet(qT).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:i}}writeMeasure(e){var t;if(e.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let e of this.manager.tooltipViews)e.dom.style.position="absolute"}let{visible:i,space:n,scaleX:r,scaleY:s}=e,a=[];for(let o=0;o<this.manager.tooltips.length;o++){let l=this.manager.tooltips[o],c=this.manager.tooltipViews[o],{dom:h}=c,u=e.pos[o],d=e.size[o];if(!u||!1!==l.clip&&(u.bottom<=Math.max(i.top,n.top)||u.top>=Math.min(i.bottom,n.bottom)||u.right<Math.max(i.left,n.left)-.1||u.left>Math.min(i.right,n.right)+.1)){h.style.top=DT;continue}let p=l.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,f=p?7:0,m=d.right-d.left,g=null!==(t=XT.get(c))&&void 0!==t?t:d.bottom-d.top,O=c.offset||FT,v=this.view.textDirection==zx.LTR,y=d.width>n.right-n.left?v?n.left:n.right-d.width:v?Math.max(n.left,Math.min(u.left-(p?14:0)+O.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(p?14:0)-O.x),n.right-m),b=this.above[o];!l.strictSide&&(b?u.top-g-f-O.y<n.top:u.bottom+g+f+O.y>n.bottom)&&b==n.bottom-u.bottom>u.top-n.top&&(b=this.above[o]=!b);let w=(b?u.top-n.top:n.bottom-u.bottom)-f;if(w<g&&!1!==c.resize){if(w<this.view.defaultLineHeight){h.style.top=DT;continue}XT.set(c,g),h.style.height=(g=w)/s+"px"}else h.style.height&&(h.style.height="");let _=b?u.top-g-f-O.y:u.bottom+f+O.y,x=y+m;if(!0!==c.overlap)for(let e of a)e.left<x&&e.right>y&&e.top<_+g&&e.bottom>_&&(_=b?e.top-g-2-f:e.bottom+f+2);if("absolute"==this.position?(h.style.top=(_-e.parent.top)/s+"px",WT(h,(y-e.parent.left)/r)):(h.style.top=_/s+"px",WT(h,y/r)),p){let e=u.left+(v?O.x:-O.x)-(y+14-7);p.style.left=e/r+"px"}!0!==c.overlap&&a.push({left:y,top:_,right:x,bottom:_+g}),h.classList.toggle("cm-tooltip-above",b),h.classList.toggle("cm-tooltip-below",!b),c.positioned&&c.positioned(e.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let e of this.manager.tooltipViews)e.dom.style.top=DT}},{eventObservers:{scroll(){this.maybeMeasure()}}});function WT(e,t){let i=parseInt(e.style.left,10);(isNaN(i)||Math.abs(t-i)>1)&&(e.style.left=t+"px")}const VT=GP.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),FT={x:0,y:0},YT=Sw.define({enables:[BT,VT]}),GT=Sw.define({combine:e=>e.reduce((e,t)=>e.concat(t),[])});class HT{static create(e){return new HT(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new zT(e,GT,(e,t)=>this.createHostedView(e,t),e=>e.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)null===(e=t.destroy)||void 0===e||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let n=i[e];if(void 0!==n)if(void 0===t)t=n;else if(t!==n)return}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const KT=YT.compute([GT],e=>{let t=e.facet(GT);return 0===t.length?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var t;return null!==(t=e.end)&&void 0!==t?t:e.pos})),create:HT.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class JT{constructor(e,t,i,n,r){this.view=e,this.source=t,this.field=i,this.setHover=n,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,i=e.docView.tile.nearest(t.target);if(!i)return;let n,r=1;if(i.isWidget())n=i.posAtStart;else{if(n=e.posAtCoords(t),null==n)return;let i=e.coordsAtPos(n);if(!i||t.y<i.top||t.y>i.bottom||t.x<i.left-e.defaultCharacterWidth||t.x>i.right+e.defaultCharacterWidth)return;let s=e.bidiSpans(e.state.doc.lineAt(n)).find(e=>e.from<=n&&e.to>=n),a=s&&s.dir==zx.RTL?-1:1;r=t.x<i.left?-a:a}let s=this.source(e,n,r);if(null==s?void 0:s.then){let t=this.pending={pos:n};s.then(i=>{this.pending==t&&(this.pending=null,!i||Array.isArray(i)&&!i.length||e.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},t=>wS(e.state,t,"hover tooltip"))}else!s||Array.isArray(s)&&!s.length||e.dispatch({effects:this.setHover.of(Array.isArray(s)?s:[s])})}get tooltip(){let e=this.view.plugin(BT),t=e?e.manager.tooltips.findIndex(e=>e.create==HT.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&r&&!function(e,t){let i,{left:n,right:r,top:s,bottom:a}=e.getBoundingClientRect();if(i=e.querySelector(".cm-tooltip-arrow")){let e=i.getBoundingClientRect();s=Math.min(e.top,s),a=Math.max(e.bottom,a)}return t.clientX>=n-e$&&t.clientX<=r+e$&&t.clientY>=s-e$&&t.clientY<=a+e$}(r.dom,e)||this.pending){let{pos:r}=n[0]||this.pending,s=null!==(i=null===(t=n[0])||void 0===t?void 0:t.end)&&void 0!==i?i:r;(r==s?this.view.posAtCoords(this.lastMove)==r:function(e,t,i,n,r){let s=e.scrollDOM.getBoundingClientRect(),a=e.documentTop+e.documentPadding.top+e.contentHeight;if(s.left>n||s.right<n||s.top>r||Math.min(s.bottom,a)<r)return!1;let o=e.posAtCoords({x:n,y:r},!1);return o>=t&&o<=i}(this.view,r,s,e.clientX,e.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length){let{tooltip:t}=this;t&&t.dom.contains(e.relatedTarget)?this.watchTooltipLeave(t.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const e$=4;function t$(e,t={}){let i=e_.define(),n=Cw.define({create:()=>[],update(e,n){if(e.length&&(t.hideOnChange&&(n.docChanged||n.selection)?e=[]:t.hideOn&&(e=e.filter(e=>!t.hideOn(n,e))),n.docChanged)){let t=[];for(let i of e){let e=n.changes.mapPos(i.pos,-1,uw.TrackDel);if(null!=e){let r=Object.assign(Object.create(null),i);r.pos=e,null!=r.end&&(r.end=n.changes.mapPos(r.end)),t.push(r)}}e=t}for(let t of n.effects)t.is(i)&&(e=t.value),t.is(n$)&&(e=[]);return e},provide:e=>GT.from(e)});return{active:n,extension:[n,kS.define(r=>new JT(r,e,n,i,t.hoverTime||300)),KT]}}function i$(e,t){let i=e.plugin(BT);if(!i)return null;let n=i.manager.tooltips.indexOf(t);return n<0?null:i.manager.tooltipViews[n]}const n$=e_.define(),r$=Sw.define({combine(e){let t,i;for(let n of e)t=t||n.topContainer,i=i||n.bottomContainer;return{topContainer:t,bottomContainer:i}}});function s$(e,t){let i=e.plugin(a$),n=i?i.specs.indexOf(t):-1;return n>-1?i.panels[n]:null}const a$=kS.fromClass(class{constructor(e){this.input=e.state.facet(c$),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(t=>t(e));let t=e.state.facet(r$);this.top=new o$(e,!0,t.topContainer),this.bottom=new o$(e,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let i of this.panels)i.dom.classList.add("cm-panel"),i.mount&&i.mount()}update(e){let t=e.state.facet(r$);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new o$(e.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new o$(e.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=e.state.facet(c$);if(i!=this.input){let t=i.filter(e=>e),n=[],r=[],s=[],a=[];for(let i of t){let t,o=this.specs.indexOf(i);o<0?(t=i(e.view),a.push(t)):(t=this.panels[o],t.update&&t.update(e)),n.push(t),(t.top?r:s).push(t)}this.specs=t,this.panels=n,this.top.sync(r),this.bottom.sync(s);for(let e of a)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}else for(let n of this.panels)n.update&&n.update(e)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:e=>GP.scrollMargins.of(t=>{let i=t.plugin(e);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class o${constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=l$(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=l$(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(this.container&&this.classes!=this.view.themeClasses){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function l$(e){let t=e.nextSibling;return e.remove(),t}const c$=Sw.define({enables:a$});function h$(e,t){let i,n=new Promise(e=>i=e),r=e=>function(e,t,i){let n=t.content?t.content(e,()=>a(null)):null;if(!n){if(n=X_("form"),t.input){let e=X_("input",t.input);/^(text|password|number|email|tel|url)$/.test(e.type)&&e.classList.add("cm-textfield"),e.name||(e.name="input"),n.appendChild(X_("label",(t.label||"")+": ",e))}else n.appendChild(document.createTextNode(t.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(X_("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let r="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let o=0;o<r.length;o++){let e=r[o];e.addEventListener("keydown",t=>{27==t.keyCode?(t.preventDefault(),a(null)):13==t.keyCode&&(t.preventDefault(),a(e))}),e.addEventListener("submit",t=>{t.preventDefault(),a(e)})}let s=X_("div",n,X_("button",{onclick:()=>a(null),"aria-label":e.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(s.className=t.class);function a(t){s.contains(s.ownerDocument.activeElement)&&e.focus(),i(t)}return s.classList.add("cm-dialog"),{dom:s,top:t.top,mount:()=>{if(t.focus){let e;e="string"==typeof t.focus?n.querySelector(t.focus):n.querySelector("input")||n.querySelector("button"),e&&"select"in e?e.select():e&&"focus"in e&&e.focus()}}}}(e,t,i);e.state.field(u$,!1)?e.dispatch({effects:d$.of(r)}):e.dispatch({effects:e_.appendConfig.of(u$.init(()=>[r]))});let s=p$.of(r);return{close:s,result:n.then(t=>((e.win.queueMicrotask||(t=>e.win.setTimeout(t,10)))(()=>{e.state.field(u$).indexOf(r)>-1&&e.dispatch({effects:s})}),t))}}const u$=Cw.define({create:()=>[],update(e,t){for(let i of t.effects)i.is(d$)?e=[i.value].concat(e):i.is(p$)&&(e=e.filter(e=>e!=i.value));return e},provide:e=>c$.computeN([e],t=>t.field(e))}),d$=e_.define(),p$=e_.define();class f$ extends f_{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}f$.prototype.elementClass="",f$.prototype.toDOM=void 0,f$.prototype.mapMode=uw.TrackBefore,f$.prototype.startSide=f$.prototype.endSide=-1,f$.prototype.point=!0;const m$=Sw.define(),g$=Sw.define(),O$=Sw.define(),v$=Sw.define({combine:e=>e.some(e=>e)});const y$=kS.fromClass(class{constructor(e){this.view=e,this.domAfter=null,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=e.state.facet(O$).map(t=>new x$(e,t)),this.fixed=!e.state.facet(v$);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(e){if(this.updateGutters(e)){let t=this.prevViewport,i=e.view.viewport,n=Math.min(t.to,i.to)-Math.max(t.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(e.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(v$)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=y_.iter(this.view.state.facet(m$),this.view.viewport.from),n=[],r=this.gutters.map(e=>new _$(e,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(s.type)){let e=!0;for(let t of s.type)if(t.type==hx.Text&&e){w$(i,n,t.from);for(let e of r)e.line(this.view,t,n);e=!1}else if(t.widget)for(let e of r)e.widget(this.view,t)}else if(s.type==hx.Text){w$(i,n,s.from);for(let e of r)e.line(this.view,s,n)}else if(s.widget)for(let e of r)e.widget(this.view,s);for(let s of r)s.finish();e&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(e){let t=e.startState.facet(O$),i=e.state.facet(O$),n=e.docChanged||e.heightChanged||e.viewportChanged||!y_.eq(e.startState.facet(m$),e.state.facet(m$),e.view.viewport.from,e.view.viewport.to);if(t==i)for(let r of this.gutters)r.update(e)&&(n=!0);else{n=!0;let r=[];for(let n of i){let i=t.indexOf(n);i<0?r.push(new x$(this.view,n)):(this.gutters[i].update(e),r.push(this.gutters[i]))}for(let e of this.gutters)e.dom.remove(),r.indexOf(e)<0&&e.destroy();for(let e of r)"after"==e.config.side?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.gutters=r}return n}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:e=>GP.scrollMargins.of(t=>{let i=t.plugin(e);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*t.scaleX,r=i.domAfter?i.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==zx.LTR?{left:n,right:r}:{right:n,left:r}})});function b$(e){return Array.isArray(e)?e:[e]}function w$(e,t,i){for(;e.value&&e.from<=i;)e.from==i&&t.push(e.value),e.next()}class _${constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=y_.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:n}=this,r=(t.top-this.height)/e.scaleY,s=t.height/e.scaleY;if(this.i==n.elements.length){let t=new S$(e,s,r,i);n.elements.push(t),n.dom.appendChild(t.dom)}else n.elements[this.i].update(e,s,r,i);this.height=t.bottom,this.i++}line(e,t,i){let n=[];w$(this.cursor,n,t.from),i.length&&(n=n.concat(i));let r=this.gutter.config.lineMarker(e,t,n);r&&n.unshift(r);let s=this.gutter;(0!=n.length||s.config.renderEmptyElements)&&this.addElement(e,t,n)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),n=i?[i]:null;for(let r of e.state.facet(g$)){let i=r(e,t.widget,t);i&&(n||(n=[])).push(i)}n&&this.addElement(e,t,n)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class x${constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,n=>{let r,s=n.target;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let e=s.getBoundingClientRect();r=(e.top+e.bottom)/2}else r=n.clientY;let a=e.lineBlockAtHeight(r-e.documentTop);t.domEventHandlers[i](e,a,n)&&n.preventDefault()});this.markers=b$(t.markers(e)),t.initialSpacer&&(this.spacer=new S$(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=b$(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let t=this.config.updateSpacer(this.spacer.markers[0],e);t!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[t])}let i=e.view.viewport;return!y_.eq(this.markers,t,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(e)}destroy(){for(let e of this.elements)e.destroy()}}class S${constructor(e,t,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,n)}update(e,t,i,n){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].compare(t[i]))return!1;return!0}(this.markers,n)||this.setMarkers(e,n)}setMarkers(e,t){let i="cm-gutterElement",n=this.dom.firstChild;for(let r=0,s=0;;){let a=s,o=r<t.length?t[r++]:null,l=!1;if(o){let e=o.elementClass;e&&(i+=" "+e);for(let t=s;t<this.markers.length;t++)if(this.markers[t].compare(o)){a=t,l=!0;break}}else a=this.markers.length;for(;s<a;){let e=this.markers[s++];if(e.toDOM){e.destroy(n);let t=n.nextSibling;n.remove(),n=t}}if(!o)break;o.toDOM&&(l?n=n.nextSibling:this.dom.insertBefore(o.toDOM(e),n)),l&&s++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}const k$=Sw.define(),P$=Sw.define(),T$=Sw.define({combine:e=>p_(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let n in t){let e=i[n],r=t[n];i[n]=e?(t,i,n)=>e(t,i,n)||r(t,i,n):r}return i}})});class $$ extends f${constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function E$(e,t){return e.state.facet(T$).formatNumber(t,e.state)}const A$=O$.compute([T$],e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:e=>e.state.facet(k$),lineMarker:(e,t,i)=>i.some(e=>e.toDOM)?null:new $$(E$(e,e.state.doc.lineAt(t.from).number)),widgetMarker:(e,t,i)=>{for(let n of e.state.facet(P$)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(T$)!=e.state.facet(T$),initialSpacer:e=>new $$(E$(e,R$(e.state.doc.lines))),updateSpacer(e,t){let i=E$(t.view,R$(t.view.state.doc.lines));return i==e.number?e:new $$(i)},domEventHandlers:e.facet(T$).domEventHandlers,side:"before"}));function C$(e={}){return[T$.of(e),[y$],A$]}function R$(e){let t=9;for(;t<e;)t=10*t+9;return t}const Q$=new class extends f${constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},I$=m$.compute(["selection"],e=>{let t=[],i=-1;for(let n of e.selection.ranges){let r=e.doc.lineAt(n.head).from;r>i&&(i=r,t.push(Q$.range(r)))}return y_.of(t)});const j$=1024;let M$=0;class N${constructor(e,t){this.from=e,this.to=t}}class L${constructor(e={}){this.id=M$++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof e&&(e=z$.match(e)),t=>{let i=e(t);return void 0===i?null:[this,i]}}}L$.closedBy=new L$({deserialize:e=>e.split(" ")}),L$.openedBy=new L$({deserialize:e=>e.split(" ")}),L$.group=new L$({deserialize:e=>e.split(" ")}),L$.isolate=new L$({deserialize:e=>{if(e&&"rtl"!=e&&"ltr"!=e&&"auto"!=e)throw new RangeError("Invalid value for isolate: "+e);return e||"auto"}}),L$.contextHash=new L$({perNode:!0}),L$.lookAhead=new L$({perNode:!0}),L$.mounted=new L$({perNode:!0});class Z${constructor(e,t,i,n=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=n}static get(e){return e&&e.props&&e.props[L$.mounted.id]}}const D$=Object.create(null);class z${constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):D$,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(null==e.name?8:0),n=new z$(e.name||"",t,e.id,i);if(e.props)for(let r of e.props)if(Array.isArray(r)||(r=r(n)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}return n}prop(e){return this.props[e.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(e){if("string"==typeof e){if(this.name==e)return!0;let t=this.prop(L$.group);return!!t&&t.indexOf(e)>-1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return e=>{for(let i=e.prop(L$.group),n=-1;n<(i?i.length:0);n++){let r=t[n<0?e.name:i[n]];if(r)return r}}}}z$.none=new z$("",Object.create(null),0,8);class U${constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let t of e){let e=t(i);if(e){n||(n=Object.assign({},i.props));let t=e[1],r=e[0];r.combine&&r.id in n&&(t=r.combine(n[r.id],t)),n[r.id]=t}}t.push(n?new z$(i.name,n,i.id,i.flags):i)}return new U$(t)}}const q$=new WeakMap,X$=new WeakMap;var B$,W$;(W$=B$||(B$={}))[W$.ExcludeBuffers=1]="ExcludeBuffers",W$[W$.IncludeAnonymous=2]="IncludeAnonymous",W$[W$.IgnoreMounts=4]="IgnoreMounts",W$[W$.IgnoreOverlays=8]="IgnoreOverlays",W$[W$.EnterBracketed=16]="EnterBracketed";class V${constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[e,t]of r)this.props["number"==typeof e?e:e.id]=t}}toString(){let e=Z$.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let e=i.toString();e&&(t&&(t+=","),t+=e)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new aE(this.topNode,e)}cursorAt(e,t=0,i=0){let n=q$.get(this)||this.topNode,r=new aE(n);return r.moveTo(e,t),q$.set(this,r._tree),r}get topNode(){return new J$(this,0,0,null)}resolve(e,t=0){let i=H$(q$.get(this)||this.topNode,e,t,!1);return q$.set(this,i),i}resolveInner(e,t=0){let i=H$(X$.get(this)||this.topNode,e,t,!0);return X$.set(this,i),i}resolveStack(e,t=0){return function(e,t,i){let n=e.resolveInner(t,i),r=null;for(let s=n instanceof J$?n:n.context.parent;s;s=s.parent)if(s.index<0){let e=s.parent;(r||(r=[n])).push(e.resolve(t,i)),s=e}else{let e=Z$.get(s.tree);if(e&&e.overlay&&e.overlay[0].from<=t&&e.overlay[e.overlay.length-1].to>=t){let a=new J$(e.tree,e.overlay[0].from+s.from,-1,s);(r||(r=[n])).push(H$(a,t,i,!1))}}return r?rE(r):n}(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,s=e.mode||0,a=(s&B$.IncludeAnonymous)>0;for(let o=this.cursor(s|B$.IncludeAnonymous);;){let e=!1;if(o.from<=r&&o.to>=n&&(!a&&o.type.isAnonymous||!1!==t(o))){if(o.firstChild())continue;e=!0}for(;e&&i&&(a||!o.type.isAnonymous)&&i(o),!o.nextSibling();){if(!o.parent())return;e=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:hE(z$.none,this.children,this.positions,0,this.children.length,0,this.length,(e,t,i)=>new V$(this.type,e,t,i,this.propValues),e.makeTree||((e,t,i)=>new V$(z$.none,e,t,i)))}static build(e){return function(e){var t;let{buffer:i,nodeSet:n,maxBufferLength:r=j$,reused:s=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(i)?new F$(i,i.length):i,l=n.types,c=0,h=0;function u(e,t,i,v,y,b){let{id:w,start:_,end:x,size:S}=o,k=h,P=c;if(S<0){if(o.next(),-1==S){let t=s[w];return i.push(t),void v.push(_-e)}if(-3==S)return void(c=w);if(-4==S)return void(h=w);throw new RangeError(`Unrecognized record size: ${S}`)}let T,$,E=l[w],A=_-e;if(x-_<=r&&($=g(o.pos-t,y))){let t=new Uint16Array($.size-$.skip),i=o.pos-$.size,r=t.length;for(;o.pos>i;)r=O($.start,t,r);T=new Y$(t,x-$.start,n),A=$.start-e}else{let e=o.pos-S;o.next();let t=[],i=[],n=w>=a?w:-1,s=0,l=x;for(;o.pos>e;)n>=0&&o.id==n&&o.size>=0?(o.end<=l-r&&(f(t,i,_,s,o.end,l,n,k,P),s=t.length,l=o.end),o.next()):b>2500?d(_,e,t,i):u(_,e,t,i,n,b+1);if(n>=0&&s>0&&s<t.length&&f(t,i,_,s,_,l,n,k,P),t.reverse(),i.reverse(),n>-1&&s>0){let e=p(E,P);T=hE(E,t,i,0,t.length,0,x-_,e,e)}else T=m(E,t,i,x-_,k-x,P)}i.push(T),v.push(A)}function d(e,t,i,s){let a=[],l=0,c=-1;for(;o.pos>t;){let{id:e,start:t,end:i,size:n}=o;if(n>4)o.next();else{if(c>-1&&t<c)break;c<0&&(c=i-r),a.push(e,t,i),l++,o.next()}}if(l){let t=new Uint16Array(4*l),r=a[a.length-2];for(let e=a.length-3,i=0;e>=0;e-=3)t[i++]=a[e],t[i++]=a[e+1]-r,t[i++]=a[e+2]-r,t[i++]=i;i.push(new Y$(t,a[2]-r,n)),s.push(r-e)}}function p(e,t){return(i,n,r)=>{let s,a,o=0,l=i.length-1;if(l>=0&&(s=i[l])instanceof V$){if(!l&&s.type==e&&s.length==r)return s;(a=s.prop(L$.lookAhead))&&(o=n[l]+s.length+a)}return m(e,i,n,r,o,t)}}function f(e,t,i,r,s,a,o,l,c){let h=[],u=[];for(;e.length>r;)h.push(e.pop()),u.push(t.pop()+i-s);e.push(m(n.types[o],h,u,a-s,l-a,c)),t.push(s-i)}function m(e,t,i,n,r,s,a){if(s){let e=[L$.contextHash,s];a=a?[e].concat(a):[e]}if(r>25){let e=[L$.lookAhead,r];a=a?[e].concat(a):[e]}return new V$(e,t,i,n,a)}function g(e,t){let i=o.fork(),n=0,s=0,l=0,c=i.end-r,h={size:0,start:0,skip:0};e:for(let r=i.pos-e;i.pos>r;){let e=i.size;if(i.id==t&&e>=0){h.size=n,h.start=s,h.skip=l,l+=4,n+=4,i.next();continue}let o=i.pos-e;if(e<0||o<r||i.start<c)break;let u=i.id>=a?4:0,d=i.start;for(i.next();i.pos>o;){if(i.size<0){if(-3!=i.size&&-4!=i.size)break e;u+=4}else i.id>=a&&(u+=4);i.next()}s=d,n+=e,l+=u}return(t<0||n==e)&&(h.size=n,h.start=s,h.skip=l),h.size>4?h:void 0}function O(e,t,i){let{id:n,start:r,end:s,size:l}=o;if(o.next(),l>=0&&n<a){let a=i;if(l>4){let n=o.pos-(l-4);for(;o.pos>n;)i=O(e,t,i)}t[--i]=a,t[--i]=s-e,t[--i]=r-e,t[--i]=n}else-3==l?c=n:-4==l&&(h=n);return i}let v=[],y=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,v,y,-1,0);let b=null!==(t=e.length)&&void 0!==t?t:v.length?y[0]+v[0].length:0;return new V$(l[e.topID],v.reverse(),y.reverse(),b)}(e)}}V$.empty=new V$(z$.none,[],[],0);class F${constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new F$(this.buffer,this.index)}}class Y${constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return z$.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),i==(e+=4))return r;let s=[];for(;e<i;)s.push(this.childString(e)),e=this.buffer[e+3];return r+"("+s.join(",")+")"}findChild(e,t,i,n,r){let{buffer:s}=this,a=-1;for(let o=e;o!=t&&!(G$(r,n,s[o+1],s[o+2])&&(a=o,i>0));o=s[o+3]);return a}slice(e,t,i){let n=this.buffer,r=new Uint16Array(t-e),s=0;for(let a=e,o=0;a<t;){r[o++]=n[a++],r[o++]=n[a++]-i;let t=r[o++]=n[a++]-i;r[o++]=n[a++]-e,s=Math.max(s,t)}return new Y$(r,s,this.set)}}function G$(e,t,i,n){switch(e){case-2:return i<t;case-1:return n>=t&&i<t;case 0:return i<t&&n>t;case 1:return i<=t&&n>t;case 2:return n>t;case 4:return!0}}function H$(e,t,i,n){for(var r;e.from==e.to||(i<1?e.from>=t:e.from>t)||(i>-1?e.to<=t:e.to<t);){let t=!n&&e instanceof J$&&e.index<0?null:e.parent;if(!t)return e;e=t}let s=n?0:B$.IgnoreOverlays;if(n)for(let a=e,o=a.parent;o;a=o,o=a.parent)a instanceof J$&&a.index<0&&(null===(r=o.enter(t,i,s))||void 0===r?void 0:r.from)!=a.from&&(e=o);for(;;){let n=e.enter(t,i,s);if(!n)return e;e=n}}class K${cursor(e=0){return new aE(this,e)}getChild(e,t=null,i=null){let n=eE(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return eE(this,e,t,i)}resolve(e,t=0){return H$(this,e,t,!1)}resolveInner(e,t=0){return H$(this,e,t,!0)}matchContext(e){return tE(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(i=t,t=e.prevSibling):t=e}return i}get node(){return this}get next(){return this.parent}}class J$ extends K${constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let s=this;;){for(let{children:a,positions:o}=s._tree,l=t>0?a.length:-1;e!=l;e+=t){let l,c=a[e],h=o[e]+s.from;if(r&B$.EnterBracketed&&c instanceof V$&&(l=Z$.get(c))&&!l.overlay&&l.bracketed&&i>=h&&i<=h+c.length||G$(n,i,h,h+c.length))if(c instanceof Y$){if(r&B$.ExcludeBuffers)continue;let a=c.findChild(0,c.buffer.length,t,i-h,n);if(a>-1)return new nE(new iE(s,c,e,h),null,a)}else if(r&B$.IncludeAnonymous||!c.type.isAnonymous||oE(c)){let a;if(!(r&B$.IgnoreMounts)&&(a=Z$.get(c))&&!a.overlay)return new J$(a.tree,h,e,s);let o=new J$(c,h,e,s);return r&B$.IncludeAnonymous||!o.type.isAnonymous?o:o.nextChild(t<0?c.children.length-1:0,t,i,n,r)}}if(r&B$.IncludeAnonymous||!s.type.isAnonymous)return null;if(e=s.index>=0?s.index+t:t<0?-1:s._parent._tree.children.length,s=s._parent,!s)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let n;if(!(i&B$.IgnoreOverlays)&&(n=Z$.get(this._tree))&&n.overlay){let r=e-this.from,s=i&B$.EnterBracketed&&n.bracketed;for(let{from:e,to:i}of n.overlay)if((t>0||s?e<=r:e<r)&&(t<0||s?i>=r:i>r))return new J$(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function eE(e,t,i,n){let r=e.cursor(),s=[];if(!r.firstChild())return s;if(null!=i)for(let a=!1;!a;)if(a=r.type.is(i),!r.nextSibling())return s;for(;;){if(null!=n&&r.type.is(n))return s;if(r.type.is(t)&&s.push(r.node),!r.nextSibling())return null==n?s:[]}}function tE(e,t,i=t.length-1){for(let n=e;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(t[i]&&t[i]!=n.name)return!1;i--}}return!0}class iE{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class nE extends K${get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new nE(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&B$.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new nE(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new nE(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new nE(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let s=i.buffer[this.index+1];e.push(i.slice(n,r,s)),t.push(0)}return new V$(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function rE(e){if(!e.length)return null;let t=0,i=e[0];for(let s=1;s<e.length;s++){let n=e[s];(n.from>i.from||n.to<i.to)&&(i=n,t=s)}let n=i instanceof J$&&i.index<0?null:i.parent,r=e.slice();return n?r[t]=n:r.splice(t,1),new sE(r,i)}class sE{constructor(e,t){this.heads=e,this.node=t}get next(){return rE(this.heads)}}class aE{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~B$.EnterBracketed,e instanceof J$)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return!!e&&(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0)}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return!!e&&(e instanceof J$?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return!(r<0)&&(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?!(i&B$.ExcludeBuffers)&&this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&B$.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&B$.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode));let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let e=i<0?0:this.stack[i]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(e)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(n.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;({index:t,_parent:i}=i))if(t>-1)for(let n=t+e,r=e<0?-1:i._tree.children.length;n!=r;n+=e){let e=i._tree.children[n];if(this.mode&B$.IncludeAnonymous||e instanceof Y$||!e.type.isAnonymous||oE(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let s=e;s;s=s._parent)if(s.index==n){if(n==this.index)return s;t=s,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new nE(this.buffer,t,this.stack[n]);return this.bufferNode=new nE(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||!1!==e(this)){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return tE(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return tE(this._tree,e,n);let s=i[t.buffer[this.stack[r]]];if(!s.isAnonymous){if(e[n]&&e[n]!=s.name)return!1;n--}}return!0}}function oE(e){return e.children.some(e=>e instanceof Y$||!e.type.isAnonymous||oE(e))}const lE=new WeakMap;function cE(e,t){if(!e.isAnonymous||t instanceof Y$||t.type!=e)return 1;let i=lE.get(t);if(null==i){i=1;for(let n of t.children){if(n.type!=e||!(n instanceof V$)){i=1;break}i+=cE(e,n)}lE.set(t,i)}return i}function hE(e,t,i,n,r,s,a,o,l){let c=0;for(let p=n;p<r;p++)c+=cE(e,t[p]);let h=Math.ceil(1.5*c/8),u=[],d=[];return function t(i,n,r,a,o){for(let c=r;c<a;){let r=c,p=n[c],f=cE(e,i[c]);for(c++;c<a;c++){let t=cE(e,i[c]);if(f+t>=h)break;f+=t}if(c==r+1){if(f>h){let e=i[r];t(e.children,e.positions,0,e.children.length,n[r]+o);continue}u.push(i[r])}else{let t=n[c-1]+i[c-1].length-p;u.push(hE(e,i,n,r,c,p,t,null,l))}d.push(p+o-s)}}(t,i,n,r,0),(o||l)(u,d,a)}class uE{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof nE?this.setBuffer(e.context.buffer,e.index,t):e instanceof J$&&this.map.set(e.tree,t)}get(e){return e instanceof nE?this.getBuffer(e.context.buffer,e.index):e instanceof J$?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class dE{constructor(e,t,i,n,r=!1,s=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(r?1:0)|(s?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(e,t=[],i=!1){let n=[new dE(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&n.push(r);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],r=1,s=e.length?e[0]:null;for(let a=0,o=0,l=0;;a++){let c=a<t.length?t[a]:null,h=c?c.fromA:1e9;if(h-o>=i)for(;s&&s.from<h;){let t=s;if(o>=t.from||h<=t.to||l){let e=Math.max(t.from,o)-l,i=Math.min(t.to,h)-l;t=e>=i?null:new dE(e,i,t.tree,t.offset+l,a>0,!!c)}if(t&&n.push(t),s.to>h)break;s=r<e.length?e[r++]:null}if(!c)break;o=c.toA,l=c.toA-c.toB}return n}}class pE{startParse(e,t,i){return"string"==typeof e&&(e=new fE(e)),i=i?i.length?i.map(e=>new N$(e.from,e.to)):[new N$(0,0)]:[new N$(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let e=n.advance();if(e)return e}}}class fE{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new L$({perNode:!0});let mE=0;class gE{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=mE++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i="string"==typeof e?e:"?";if(e instanceof gE&&(t=e),null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let n=new gE(i,[],null,[]);if(n.set.push(n),t)for(let r of t.set)n.set.push(r);return n}static defineModifier(e){let t=new vE(e);return e=>e.modified.indexOf(t)>-1?e:vE.get(e.base||e,e.modified.concat(t).sort((e,t)=>e.id-t.id))}}let OE=0;class vE{constructor(e){this.name=e,this.instances=[],this.id=OE++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(i=>{return i.base==e&&(n=t,r=i.modified,n.length==r.length&&n.every((e,t)=>e==r[t]));var n,r});if(i)return i;let n=[],r=new gE(e.name,n,e,t);for(let a of t)a.instances.push(r);let s=function(e){let t=[[]];for(let i=0;i<e.length;i++)for(let n=0,r=t.length;n<r;n++)t.push(t[n].concat(e[i]));return t.sort((e,t)=>t.length-e.length)}(t);for(let a of e.set)if(!a.modified.length)for(let e of s)n.push(vE.get(a,e));return r}}function yE(e){let t=Object.create(null);for(let i in e){let n=e[i];Array.isArray(n)||(n=[n]);for(let e of i.split(" "))if(e){let i=[],r=2,s=e;for(let t=0;;){if("..."==s&&t>0&&t+3==e.length){r=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(s);if(!n)throw new RangeError("Invalid path: "+e);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),t+=n[0].length,t==e.length)break;let a=e[t++];if(t==e.length&&"!"==a){r=0;break}if("/"!=a)throw new RangeError("Invalid path: "+e);s=e.slice(t)}let a=i.length-1,o=i[a];if(!o)throw new RangeError("Invalid path: "+e);let l=new wE(n,r,a>0?i.slice(0,a):null);t[o]=l.sort(t[o])}}return bE.add(t)}const bE=new L$({combine(e,t){let i,n,r;for(;e||t;){if(!e||t&&e.depth>=t.depth?(r=t,t=t.next):(r=e,e=e.next),i&&i.mode==r.mode&&!r.context&&!i.context)continue;let s=new wE(r.tags,r.mode,r.context);i?i.next=s:n=s,i=s}return n}});class wE{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}function _E(e,t){let i=Object.create(null);for(let s of e)if(Array.isArray(s.tag))for(let e of s.tag)i[e.id]=s.class;else i[s.tag.id]=s.class;let{scope:n,all:r=null}=t||{};return{style:e=>{let t=r;for(let n of e)for(let e of n.set){let n=i[e.id];if(n){t=t?t+" "+n:n;break}}return t},scope:n}}function xE(e,t,i,n=0,r=e.length){let s=new SE(n,Array.isArray(t)?t:[t],i);s.highlightRange(e.cursor(),n,r,"",s.highlighters),s.flush(r)}wE.empty=new wE([],2,null);class SE{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,n,r){let{type:s,from:a,to:o}=e;if(a>=i||o<=t)return;s.isTop&&(r=this.highlighters.filter(e=>!e.scope||e.scope(s)));let l=n,c=function(e){let t=e.type.prop(bE);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}(e)||wE.empty,h=function(e,t){let i=null;for(let n of e){let e=n.style(t);e&&(i=i?i+" "+e:e)}return i}(r,c.tags);if(h&&(l&&(l+=" "),l+=h,1==c.mode&&(n+=(n?" ":"")+h)),this.startSpan(Math.max(t,a),l),c.opaque)return;let u=e.tree&&e.tree.prop(L$.mounted);if(u&&u.overlay){let s=e.node.enter(u.overlay[0].from+a,1),c=this.highlighters.filter(e=>!e.scope||e.scope(u.tree.type)),h=e.firstChild();for(let d=0,p=a;;d++){let f=d<u.overlay.length?u.overlay[d]:null,m=f?f.from+a:o,g=Math.max(t,p),O=Math.min(i,m);if(g<O&&h)for(;e.from<O&&(this.highlightRange(e,g,O,n,r),this.startSpan(Math.min(O,e.to),l),!(e.to>=m)&&e.nextSibling()););if(!f||m>i)break;p=f.to+a,p>t&&(this.highlightRange(s.cursor(),Math.max(t,f.from+a),Math.min(i,p),"",c),this.startSpan(Math.min(i,p),l))}h&&e.parent()}else if(e.firstChild()){u&&(n="");do{if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,n,r),this.startSpan(Math.min(i,e.to),l)}}while(e.nextSibling());e.parent()}}}const kE=gE.define,PE=kE(),TE=kE(),$E=kE(TE),EE=kE(TE),AE=kE(),CE=kE(AE),RE=kE(AE),QE=kE(),IE=kE(QE),jE=kE(),ME=kE(),NE=kE(),LE=kE(NE),ZE=kE(),DE={comment:PE,lineComment:kE(PE),blockComment:kE(PE),docComment:kE(PE),name:TE,variableName:kE(TE),typeName:$E,tagName:kE($E),propertyName:EE,attributeName:kE(EE),className:kE(TE),labelName:kE(TE),namespace:kE(TE),macroName:kE(TE),literal:AE,string:CE,docString:kE(CE),character:kE(CE),attributeValue:kE(CE),number:RE,integer:kE(RE),float:kE(RE),bool:kE(AE),regexp:kE(AE),escape:kE(AE),color:kE(AE),url:kE(AE),keyword:jE,self:kE(jE),null:kE(jE),atom:kE(jE),unit:kE(jE),modifier:kE(jE),operatorKeyword:kE(jE),controlKeyword:kE(jE),definitionKeyword:kE(jE),moduleKeyword:kE(jE),operator:ME,derefOperator:kE(ME),arithmeticOperator:kE(ME),logicOperator:kE(ME),bitwiseOperator:kE(ME),compareOperator:kE(ME),updateOperator:kE(ME),definitionOperator:kE(ME),typeOperator:kE(ME),controlOperator:kE(ME),punctuation:NE,separator:kE(NE),bracket:LE,angleBracket:kE(LE),squareBracket:kE(LE),paren:kE(LE),brace:kE(LE),content:QE,heading:IE,heading1:kE(IE),heading2:kE(IE),heading3:kE(IE),heading4:kE(IE),heading5:kE(IE),heading6:kE(IE),contentSeparator:kE(QE),list:kE(QE),quote:kE(QE),emphasis:kE(QE),strong:kE(QE),link:kE(QE),monospace:kE(QE),strikethrough:kE(QE),inserted:kE(),deleted:kE(),changed:kE(),invalid:kE(),meta:ZE,documentMeta:kE(ZE),annotation:kE(ZE),processingInstruction:kE(ZE),definition:gE.defineModifier("definition"),constant:gE.defineModifier("constant"),function:gE.defineModifier("function"),standard:gE.defineModifier("standard"),local:gE.defineModifier("local"),special:gE.defineModifier("special")};for(let AM in DE){let e=DE[AM];e instanceof gE&&(e.name=AM)}var zE;_E([{tag:DE.link,class:"tok-link"},{tag:DE.heading,class:"tok-heading"},{tag:DE.emphasis,class:"tok-emphasis"},{tag:DE.strong,class:"tok-strong"},{tag:DE.keyword,class:"tok-keyword"},{tag:DE.atom,class:"tok-atom"},{tag:DE.bool,class:"tok-bool"},{tag:DE.url,class:"tok-url"},{tag:DE.labelName,class:"tok-labelName"},{tag:DE.inserted,class:"tok-inserted"},{tag:DE.deleted,class:"tok-deleted"},{tag:DE.literal,class:"tok-literal"},{tag:DE.string,class:"tok-string"},{tag:DE.number,class:"tok-number"},{tag:[DE.regexp,DE.escape,DE.special(DE.string)],class:"tok-string2"},{tag:DE.variableName,class:"tok-variableName"},{tag:DE.local(DE.variableName),class:"tok-variableName tok-local"},{tag:DE.definition(DE.variableName),class:"tok-variableName tok-definition"},{tag:DE.special(DE.variableName),class:"tok-variableName2"},{tag:DE.definition(DE.propertyName),class:"tok-propertyName tok-definition"},{tag:DE.typeName,class:"tok-typeName"},{tag:DE.namespace,class:"tok-namespace"},{tag:DE.className,class:"tok-className"},{tag:DE.macroName,class:"tok-macroName"},{tag:DE.propertyName,class:"tok-propertyName"},{tag:DE.operator,class:"tok-operator"},{tag:DE.comment,class:"tok-comment"},{tag:DE.meta,class:"tok-meta"},{tag:DE.invalid,class:"tok-invalid"},{tag:DE.punctuation,class:"tok-punctuation"}]);const UE=new L$;function qE(e){return Sw.define({combine:e?t=>t.concat(e):void 0})}const XE=new L$;class BE{constructor(e,t,i=[],n=""){this.data=e,this.name=n,d_.prototype.hasOwnProperty("tree")||Object.defineProperty(d_.prototype,"tree",{get(){return FE(this)}}),this.parser=t,this.extension=[nA.of(this),d_.languageData.of((e,t,i)=>{let n=WE(e,t,i),r=n.type.prop(UE);if(!r)return[];let s=e.facet(r),a=n.type.prop(XE);if(a){let r=n.resolve(t-n.from,i);for(let t of a)if(t.test(r,e)){let i=e.facet(t.facet);return"replace"==t.type?i:i.concat(s)}}return s})].concat(i)}isActiveAt(e,t,i=-1){return WE(e,t,i).type.prop(UE)==this.data}findRegions(e){let t=e.facet(nA);if((null==t?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(e,t)=>{if(e.prop(UE)==this.data)return void i.push({from:t,to:t+e.length});let r=e.prop(L$.mounted);if(r){if(r.tree.prop(UE)==this.data){if(r.overlay)for(let e of r.overlay)i.push({from:e.from+t,to:e.to+t});else i.push({from:t,to:t+e.length});return}if(r.overlay){let e=i.length;if(n(r.tree,r.overlay[0].from+t),i.length>e)return}}for(let i=0;i<e.children.length;i++){let r=e.children[i];r instanceof V$&&n(r,e.positions[i]+t)}};return n(FE(e),0),i}get allowsNesting(){return!0}}function WE(e,t,i){let n=e.facet(nA),r=FE(e).topNode;if(!n||n.allowsNesting)for(let s=r;s;s=s.enter(t,i,B$.ExcludeBuffers|B$.EnterBracketed))s.type.isTop&&(r=s);return r}BE.setState=e_.define();class VE extends BE{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=qE(e.languageData);return new VE(t,e.parser.configure({props:[UE.add(e=>e.isTop?t:void 0)]}),e.name)}configure(e,t){return new VE(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function FE(e){let t=e.field(BE.state,!1);return t?t.tree:V$.empty}class YE{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let GE=null;class HE{constructor(e,t,i=[],n,r,s,a,o){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=s,this.skipped=a,this.scheduleOn=o,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new HE(e,t,[],V$.empty,0,i,[],null)}startParse(){return this.parser.startParse(new YE(this.state.doc),this.fragments)}work(e,t){return null!=t&&t>=this.state.doc.length&&(t=void 0),this.tree!=V$.empty&&this.isDone(null!=t?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if("number"==typeof e){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||(this.parse=this.startParse()),null!=t&&(null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n){if(this.fragments=this.withoutTempSkipped(dE.addTree(n,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(i=this.parse.stoppedAt)&&void 0!==i?i:this.state.doc.length,this.tree=n,this.parse=null,!(this.treeLen<(null!=t?t:this.state.doc.length)))return!0;this.parse=this.startParse()}if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(dE.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=GE;GE=this;try{return e()}finally{GE=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=KE(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:r,viewport:s,skipped:a}=this;if(this.takeTree(),!e.empty){let t=[];if(e.iterChangedRanges((e,i,n,r)=>t.push({fromA:e,toA:i,fromB:n,toB:r})),i=dE.applyChanges(i,t),n=V$.empty,r=0,s={from:e.mapPos(s.from,-1),to:e.mapPos(s.to,1)},this.skipped.length){a=[];for(let t of this.skipped){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);i<n&&a.push({from:i,to:n})}}}return new HE(this.parser,t,i,n,r,s,a,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:t,to:n}=this.skipped[i];t<e.to&&n>e.from&&(this.fragments=KE(this.fragments,t,n),this.skipped.splice(i--,1))}return!(this.skipped.length>=t)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends pE{createParse(t,i,n){let r=n[0].from,s=n[n.length-1].to;return{parsedPos:r,advance(){let t=GE;if(t){for(let e of n)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=s,new V$(z$.none,[],[],s-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&0==t[0].from&&t[0].to>=e}static get(){return GE}}function KE(e,t,i){return dE.applyChanges(e,[{fromA:t,toA:i,fromB:t,toB:i}])}class JE{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new JE(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=HE.create(e.facet(nA).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new JE(i)}}BE.state=Cw.define({create:JE.init,update(e,t){for(let i of t.effects)if(i.is(BE.setState))return i.value;return t.startState.facet(nA)!=t.state.facet(nA)?JE.init(t.state):e.apply(t)}});let eA=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};"undefined"!=typeof requestIdleCallback&&(eA=e=>{let t=-1,i=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(i):cancelIdleCallback(t)});const tA="undefined"!=typeof navigator&&(null===(zE=navigator.scheduling)||void 0===zE?void 0:zE.isInputPending)?()=>navigator.scheduling.isInputPending():null,iA=kS.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(BE.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(BE.state);t.tree==t.context.tree&&t.context.isDone(e.doc.length)||(this.working=eA(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(BE.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let s=Date.now()+Math.min(this.chunkBudget,100,e&&!tA?Math.max(25,e.timeRemaining()-5):1e9),a=r.context.treeLen<n&&i.doc.length>n+1e3,o=r.context.work(()=>tA&&tA()||Date.now()>s,n+(a?0:1e5));this.chunkBudget-=Date.now()-t,(o||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:BE.setState.of(new JE(r.context))})),this.chunkBudget>0&&(!o||a)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(e=>wS(this.view.state,e)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),nA=Sw.define({combine:e=>e.length?e[0]:null,enables:e=>[BE.state,iA,GP.contentAttributes.compute([e],t=>{let i=t.facet(e);return i&&i.name?{"data-language":i.name}:{}})]});class rA{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const sA=Sw.define(),aA=Sw.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function oA(e){let t=e.facet(aA);return 9==t.charCodeAt(0)?e.tabSize*t.length:t.length}function lA(e,t){let i="",n=e.tabSize,r=e.facet(aA)[0];if("\t"==r){for(;t>=n;)i+="\t",t-=n;r=" "}for(let s=0;s<t;s++)i+=r;return i}function cA(e,t){e instanceof d_&&(e=new hA(e));for(let n of e.state.facet(sA)){let i=n(e,t);if(void 0!==i)return i}let i=FE(e.state);return i.length>=t?function(e,t,i){let n=t.resolveStack(i),r=t.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(r!=n.node){let e=[];for(let t=r;t&&!(t.from<n.node.from||t.to>n.node.to||t.from==n.node.from&&t.type==n.node.type);t=t.parent)e.push(t);for(let t=e.length-1;t>=0;t--)n={node:e[t],next:n}}return dA(n,e,i)}(e,i,t):null}class hA{constructor(e,t={}){this.state=e,this.options=t,this.unit=oA(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return null!=n&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),s=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return s>-1&&(r+=s-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return C_(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let e=r(n);if(e>-1)return e}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const uA=new L$;function dA(e,t,i){for(let n=e;n;n=n.next){let e=pA(n.node);if(e)return e(mA.create(t,i,n))}return 0}function pA(e){let t=e.type.prop(uA);if(t)return t;let i,n=e.firstChild;if(n&&(i=n.type.prop(L$.closedBy))){let t=e.lastChild,n=t&&i.indexOf(t.name)>-1;return e=>vA(e,!0,1,void 0,n&&!function(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}(e)?t.from:void 0)}return null==e.parent?fA:null}function fA(){return 0}class mA extends hA{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new mA(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(gA(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return dA(this.context.next,this.base,this.pos)}}function gA(e,t){for(let i=t;i;i=i.parent)if(e==i)return!0;return!1}function OA({closing:e,align:t=!0,units:i=1}){return n=>vA(n,t,i,e)}function vA(e,t,i,n,r){let s=e.textAfter,a=s.match(/^\s*/)[0].length,o=n&&s.slice(a,a+n.length)==n||r==e.pos+a,l=t?function(e){let t=e.node,i=t.childAfter(t.from),n=t.lastChild;if(!i)return null;let r=e.options.simulateBreak,s=e.state.doc.lineAt(i.from),a=null==r||r<=s.from?s.to:Math.min(s.to,r);for(let o=i.to;;){let e=t.childAfter(o);if(!e||e==n)return null;if(!e.type.isSkipped){if(e.from>=a)return null;let t=/^ */.exec(s.text.slice(i.to-s.from))[0].length;return{from:i.from,to:i.to+t}}o=e.to}}(e):null;return l?o?e.column(l.from):e.column(l.to):e.baseIndent+(o?0:e.unit*i)}function yA({except:e,units:t=1}={}){return i=>{let n=e&&e.test(i.textAfter);return i.baseIndent+(n?0:t*i.unit)}}const bA=new L$;class wA{constructor(e,t){let i;function n(e){let t=j_.newName();return(i||(i=Object.create(null)))["."+t]=e,t}this.specs=e;const r="string"==typeof t.all?t.all:t.all?n(t.all):void 0,s=t.scope;this.scope=s instanceof BE?e=>e.prop(UE)==s.data:s?e=>e==s:void 0,this.style=_E(e.map(e=>({tag:e.tag,class:e.class||n(Object.assign({},e,{tag:null}))})),{all:r}).style,this.module=i?new j_(i):null,this.themeType=t.themeType}static define(e,t){return new wA(e,t||{})}}const _A=Sw.define(),xA=Sw.define({combine:e=>e.length?[e[0]]:null});function SA(e){let t=e.facet(_A);return t.length?t:e.facet(xA)}function kA(e,t){let i,n=[TA];return e instanceof wA&&(e.module&&n.push(GP.styleModule.of(e.module)),i=e.themeType),i?n.push(_A.computeN([GP.darkTheme],t=>t.facet(GP.darkTheme)==("dark"==i)?[e]:[])):n.push(_A.of(e)),n}class PA{constructor(e){this.markCache=Object.create(null),this.tree=FE(e.state),this.decorations=this.buildDeco(e,SA(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=FE(e.state),i=SA(e.state),n=i!=SA(e.startState),{viewport:r}=e.view,s=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&s>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=s):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return ux.none;let i=new b_;for(let{from:n,to:r}of e.visibleRanges)xE(this.tree,t,(e,t,n)=>{i.add(e,t,this.markCache[n]||(this.markCache[n]=ux.mark({class:n})))},n,r);return i.finish()}}const TA=Nw.high(kS.fromClass(PA,{decorations:e=>e.decorations})),$A=wA.define([{tag:DE.meta,color:"#404740"},{tag:DE.link,textDecoration:"underline"},{tag:DE.heading,textDecoration:"underline",fontWeight:"bold"},{tag:DE.emphasis,fontStyle:"italic"},{tag:DE.strong,fontWeight:"bold"},{tag:DE.strikethrough,textDecoration:"line-through"},{tag:DE.keyword,color:"#708"},{tag:[DE.atom,DE.bool,DE.url,DE.contentSeparator,DE.labelName],color:"#219"},{tag:[DE.literal,DE.inserted],color:"#164"},{tag:[DE.string,DE.deleted],color:"#a11"},{tag:[DE.regexp,DE.escape,DE.special(DE.string)],color:"#e40"},{tag:DE.definition(DE.variableName),color:"#00f"},{tag:DE.local(DE.variableName),color:"#30a"},{tag:[DE.typeName,DE.namespace],color:"#085"},{tag:DE.className,color:"#167"},{tag:[DE.special(DE.variableName),DE.macroName],color:"#256"},{tag:DE.definition(DE.propertyName),color:"#00c"},{tag:DE.comment,color:"#940"},{tag:DE.invalid,color:"#f00"}]),EA=GP.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),AA="()[]{}",CA=Sw.define({combine:e=>p_(e,{afterCursor:!0,brackets:AA,maxScanDistance:1e4,renderMatch:IA})}),RA=ux.mark({class:"cm-matchingBracket"}),QA=ux.mark({class:"cm-nonmatchingBracket"});function IA(e){let t=[],i=e.matched?RA:QA;return t.push(i.range(e.start.from,e.start.to)),e.end&&t.push(i.range(e.end.from,e.end.to)),t}function jA(e){let t=[],i=e.facet(CA);for(let n of e.selection.ranges){if(!n.empty)continue;let r=zA(e,n.head,-1,i)||n.head>0&&zA(e,n.head-1,1,i)||i.afterCursor&&(zA(e,n.head,1,i)||n.head<e.doc.length&&zA(e,n.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e)))}return ux.set(t,!0)}const MA=[kS.fromClass(class{constructor(e){this.paused=!1,this.decorations=jA(e.state)}update(e){(e.docChanged||e.selectionSet||this.paused)&&(e.view.composing?(this.decorations=this.decorations.map(e.changes),this.paused=!0):(this.decorations=jA(e.state),this.paused=!1))}},{decorations:e=>e.decorations}),EA];function NA(e={}){return[CA.of(e),MA]}const LA=new L$;function ZA(e,t,i){let n=e.prop(t<0?L$.openedBy:L$.closedBy);if(n)return n;if(1==e.name.length){let n=i.indexOf(e.name);if(n>-1&&n%2==(t<0?1:0))return[i[n+t]]}return null}function DA(e){let t=e.type.prop(LA);return t?t(e.node):e}function zA(e,t,i,n={}){let r=n.maxScanDistance||1e4,s=n.brackets||AA,a=FE(e),o=a.resolveInner(t,i);for(let l=o;l;l=l.parent){let n=ZA(l.type,i,s);if(n&&l.from<l.to){let r=DA(l);if(r&&(i>0?t>=r.from&&t<r.to:t>r.from&&t<=r.to))return UA(e,t,i,l,r,n,s)}}return function(e,t,i,n,r,s,a){if(i<0?!t:t==e.doc.length)return null;let o=i<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),l=a.indexOf(o);if(l<0||l%2==0!=i>0)return null;let c={from:i<0?t-1:t,to:i>0?t+1:t},h=e.doc.iterRange(t,i>0?e.doc.length:0),u=0;for(let d=0;!h.next().done&&d<=s;){let e=h.value;i<0&&(d+=e.length);let s=t+d*i;for(let t=i>0?0:e.length-1,o=i>0?e.length:-1;t!=o;t+=i){let o=a.indexOf(e[t]);if(!(o<0||n.resolveInner(s+t,1).type!=r))if(o%2==0==i>0)u++;else{if(1==u)return{start:c,end:{from:s+t,to:s+t+1},matched:o>>1==l>>1};u--}}i>0&&(d+=e.length)}return h.done?{start:c,matched:!1}:null}(e,t,i,a,o.type,r,s)}function UA(e,t,i,n,r,s,a){let o=n.parent,l={from:r.from,to:r.to},c=0,h=null==o?void 0:o.cursor();if(h&&(i<0?h.childBefore(n.from):h.childAfter(n.to)))do{if(i<0?h.to<=n.from:h.from>=n.to){if(0==c&&s.indexOf(h.type.name)>-1&&h.from<h.to){let e=DA(h);return{start:l,end:e?{from:e.from,to:e.to}:void 0,matched:!0}}if(ZA(h.type,i,a))c++;else if(ZA(h.type,-i,a)){if(0==c){let e=DA(h);return{start:l,end:e&&e.from<e.to?{from:e.from,to:e.to}:void 0,matched:!1}}c--}}}while(i<0?h.prevSibling():h.nextSibling());return{start:l,matched:!1}}const qA=Object.create(null),XA=[z$.none],BA=[],WA=Object.create(null),VA=Object.create(null);for(let[AM,CM]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])VA[AM]=YA(qA,CM);function FA(e,t){BA.indexOf(e)>-1||BA.push(e)}function YA(e,t){let i=[];for(let o of t.split(" ")){let t=[];for(let i of o.split(".")){let n=e[i]||DE[i];n?"function"==typeof n?t.length?t=t.map(n):FA(i):t.length?FA(i):t=Array.isArray(n)?n:[n]:FA(i)}for(let e of t)i.push(e)}if(!i.length)return 0;let n=t.replace(/ /g,"_"),r=n+" "+i.map(e=>e.id),s=WA[r];if(s)return s.id;let a=WA[r]=z$.define({id:XA.length,name:n,props:[yE({[n]:i})]});return XA.push(a),a.id}zx.RTL,zx.LTR;function GA(e,t){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let r=e(t,i);return!!r&&(n(i.update(r)),!0)}}const HA=GA(nC,0),KA=GA(iC,0),JA=GA((e,t)=>iC(e,t,function(e){let t=[];for(let i of e.selection.ranges){let n=e.doc.lineAt(i.from),r=i.to<=n.to?n:e.doc.lineAt(i.to);r.from>n.from&&r.from==i.to&&(r=i.to==n.to+1?n:e.doc.lineAt(i.to-1));let s=t.length-1;s>=0&&t[s].to>n.from?t[s].to=r.to:t.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:r.to})}return t}(t)),0);function eC(e,t){let i=e.languageDataAt("commentTokens",t,1);return i.length?i[0]:{}}const tC=50;function iC(e,t,i=t.selection.ranges){let n=i.map(e=>eC(t,e.from).block);if(!n.every(e=>e))return null;let r=i.map((e,i)=>function(e,{open:t,close:i},n,r){let s,a,o=e.sliceDoc(n-tC,n),l=e.sliceDoc(r,r+tC),c=/\s*$/.exec(o)[0].length,h=/^\s*/.exec(l)[0].length,u=o.length-c;if(o.slice(u-t.length,u)==t&&l.slice(h,h+i.length)==i)return{open:{pos:n-c,margin:c&&1},close:{pos:r+h,margin:h&&1}};r-n<=2*tC?s=a=e.sliceDoc(n,r):(s=e.sliceDoc(n,n+tC),a=e.sliceDoc(r-tC,r));let d=/^\s*/.exec(s)[0].length,p=/\s*$/.exec(a)[0].length,f=a.length-p-i.length;return s.slice(d,d+t.length)==t&&a.slice(f,f+i.length)==i?{open:{pos:n+d+t.length,margin:/\s/.test(s.charAt(d+t.length))?1:0},close:{pos:r-p-i.length,margin:/\s/.test(a.charAt(f-1))?1:0}}:null}(t,n[i],e.from,e.to));if(2!=e&&!r.every(e=>e))return{changes:t.changes(i.map((e,t)=>r[t]?[]:[{from:e.from,insert:n[t].open+" "},{from:e.to,insert:" "+n[t].close}]))};if(1!=e&&r.some(e=>e)){let e=[];for(let t,i=0;i<r.length;i++)if(t=r[i]){let r=n[i],{open:s,close:a}=t;e.push({from:s.pos-r.open.length,to:s.pos+s.margin},{from:a.pos-a.margin,to:a.pos+r.close.length})}return{changes:e}}return null}function nC(e,t,i=t.selection.ranges){let n=[],r=-1;e:for(let{from:s,to:a}of i){let e,i=n.length,o=1e9;for(let l=s;l<=a;){let i=t.doc.lineAt(l);if(null==e&&(e=eC(t,i.from).line,!e))continue e;if(i.from>r&&(s==a||a>i.from)){r=i.from;let t=/^\s*/.exec(i.text)[0].length,s=t==i.length,a=i.text.slice(t,t+e.length)==e?t:-1;t<i.text.length&&t<o&&(o=t),n.push({line:i,comment:a,token:e,indent:t,empty:s,single:!1})}l=i.to+1}if(o<1e9)for(let t=i;t<n.length;t++)n[t].indent<n[t].line.text.length&&(n[t].indent=o);n.length==i+1&&(n[i].single=!0)}if(2!=e&&n.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:r,indent:s,empty:a,single:o}of n)!o&&a||e.push({from:t.from+s,insert:r+" "});let i=t.changes(e);return{changes:i,selection:t.selection.map(i,1)}}if(1!=e&&n.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:i,token:r}of n)if(i>=0){let n=t.from+i,s=n+r.length;" "==t.text[s-t.from]&&s++,e.push({from:n,to:s})}return{changes:e}}return null}const rC=Hw.define(),sC=Hw.define(),aC=Sw.define(),oC=Sw.define({combine:e=>p_(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,n)=>e(i,n)||t(i,n)})}),lC=Cw.define({create:()=>kC.empty,update(e,t){let i=t.state.facet(oC),n=t.annotation(rC);if(n){let r=mC.fromTransaction(t,n.selection),s=n.side,a=0==s?e.undone:e.done;return a=r?gC(a,a.length,i.minDepth,r):bC(a,t.startState.selection),new kC(0==s?n.rest:a,0==s?a:n.rest)}let r=t.annotation(sC);if("full"!=r&&"before"!=r||(e=e.isolate()),!1===t.annotation(t_.addToHistory))return t.changes.empty?e:e.addMapping(t.changes.desc);let s=mC.fromTransaction(t),a=t.annotation(t_.time),o=t.annotation(t_.userEvent);return s?e=e.addChanges(s,a,o,i,t):t.selection&&(e=e.addSelection(t.startState.selection,a,o,i.newGroupDelay)),"full"!=r&&"after"!=r||(e=e.isolate()),e},toJSON:e=>({done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}),fromJSON:e=>new kC(e.done.map(mC.fromJSON),e.undone.map(mC.fromJSON))});function cC(e={}){return[lC,oC.of(e),GP.domEventHandlers({beforeinput(e,t){let i="historyUndo"==e.inputType?uC:"historyRedo"==e.inputType?dC:null;return!!i&&(e.preventDefault(),i(t))}})]}function hC(e,t){return function({state:i,dispatch:n}){if(!t&&i.readOnly)return!1;let r=i.field(lC,!1);if(!r)return!1;let s=r.pop(e,i,t);return!!s&&(n(s),!0)}}const uC=hC(0,!1),dC=hC(1,!1),pC=hC(0,!0),fC=hC(1,!0);class mC{constructor(e,t,i,n,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(e){return new mC(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:null===(e=this.changes)||void 0===e?void 0:e.toJSON(),mapped:null===(t=this.mapped)||void 0===t?void 0:t.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(e){return new mC(e.changes&&pw.fromJSON(e.changes),[],e.mapped&&dw.fromJSON(e.mapped),e.startSelection&&ww.fromJSON(e.startSelection),e.selectionsAfter.map(ww.fromJSON))}static fromTransaction(e,t){let i=vC;for(let n of e.startState.facet(aC)){let t=n(e);t.length&&(i=i.concat(t))}return!i.length&&e.changes.empty?null:new mC(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,vC)}static selection(e){return new mC(void 0,vC,void 0,void 0,e)}}function gC(e,t,i,n){let r=t+1>i+20?t-i-1:0,s=e.slice(r,t);return s.push(n),s}function OC(e,t){return e.length?t.length?e.concat(t):e:t}const vC=[],yC=200;function bC(e,t){if(e.length){let i=e[e.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-yC));return n.length&&n[n.length-1].eq(t)?e:(n.push(t),gC(e,e.length-1,1e9,i.setSelAfter(n)))}return[mC.selection([t])]}function wC(e){let t=e[e.length-1],i=e.slice();return i[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),i}function _C(e,t){if(!e.length)return e;let i=e.length,n=vC;for(;i;){let r=xC(e[i-1],t,n);if(r.changes&&!r.changes.empty||r.effects.length){let t=e.slice(0,i);return t[i-1]=r,t}t=r.mapped,i--,n=r.selectionsAfter}return n.length?[mC.selection(n)]:vC}function xC(e,t,i){let n=OC(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):vC,i);if(!e.changes)return mC.selection(n);let r=e.changes.map(t),s=t.mapDesc(e.changes,!0),a=e.mapped?e.mapped.composeDesc(s):s;return new mC(r,e_.mapEffects(e.effects,t),a,e.startSelection.map(s),n)}const SC=/^(input\.type|delete)($|\.)/;class kC{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new kC(this.done,this.undone):this}addChanges(e,t,i,n,r){let s=this.done,a=s[s.length-1];return s=a&&a.changes&&!a.changes.empty&&e.changes&&(!i||SC.test(i))&&(!a.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,function(e,t){let i=[],n=!1;return e.iterChangedRanges((e,t)=>i.push(e,t)),t.iterChangedRanges((e,t,r,s)=>{for(let a=0;a<i.length;){let e=i[a++],t=i[a++];s>=e&&r<=t&&(n=!0)}}),n}(a.changes,e.changes))||"input.type.compose"==i)?gC(s,s.length-1,n.minDepth,new mC(e.changes.compose(a.changes),OC(e_.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,vC)):gC(s,s.length,n.minDepth,e),new kC(s,vC,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:vC;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&(s=r[r.length-1],a=e,s.ranges.length==a.ranges.length&&0===s.ranges.filter((e,t)=>e.empty!=a.ranges[t].empty).length)?this:new kC(bC(this.done,e),this.undone,t,i);var s,a}addMapping(e){return new kC(_C(this.done,e),_C(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=0==e?this.done:this.undone;if(0==n.length)return null;let r=n[n.length-1],s=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:rC.of({side:e,rest:wC(n),selection:s}),userEvent:0==e?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let i=1==n.length?vC:n.slice(0,n.length-1);return r.mapped&&(i=_C(i,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:rC.of({side:e,rest:i,selection:s}),filter:!1,userEvent:0==e?"undo":"redo",scrollIntoView:!0})}return null}}kC.empty=new kC(vC,vC);const PC=[{key:"Mod-z",run:uC,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:dC,preventDefault:!0},{linux:"Ctrl-Shift-z",run:dC,preventDefault:!0},{key:"Mod-u",run:pC,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:fC,preventDefault:!0}];function TC(e,t){return ww.create(e.ranges.map(t),e.mainIndex)}function $C(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function EC({state:e,dispatch:t},i){let n=TC(e.selection,i);return!n.eq(e.selection,!0)&&(t($C(e,n)),!0)}function AC(e,t){return ww.cursor(t?e.to:e.from)}function CC(e,t){return EC(e,i=>i.empty?e.moveByChar(i,t):AC(i,t))}function RC(e){return e.textDirectionAt(e.state.selection.main.head)==zx.LTR}const QC=e=>CC(e,!RC(e)),IC=e=>CC(e,RC(e));function jC(e,t){return EC(e,i=>i.empty?e.moveByGroup(i,t):AC(i,t))}function MC(e,t,i){if(t.type.prop(i))return!0;let n=t.to-t.from;return n&&(n>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function NC(e,t,i){let n,r,s=FE(e).resolveInner(t.head),a=i?L$.closedBy:L$.openedBy;for(let o=t.head;;){let t=i?s.childAfter(o):s.childBefore(o);if(!t)break;MC(e,t,a)?s=t:o=i?t.to:t.from}return r=s.type.prop(a)&&(n=i?zA(e,s.from,1):zA(e,s.to,-1))&&n.matched?i?n.end.to:n.end.from:i?s.to:s.from,ww.cursor(r,i?-1:1)}function LC(e,t){return EC(e,i=>{if(!i.empty)return AC(i,t);let n=e.moveVertically(i,t);return n.head!=i.head?n:e.moveToLineBoundary(i,t)})}const ZC=e=>LC(e,!1),DC=e=>LC(e,!0);function zC(e){let t,i=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0;if(i){for(let t of e.state.facet(GP.scrollMargins)){let i=t(e);(null==i?void 0:i.top)&&(n=Math.max(null==i?void 0:i.top,n)),(null==i?void 0:i.bottom)&&(r=Math.max(null==i?void 0:i.bottom,r))}t=e.scrollDOM.clientHeight-n-r}else t=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:i,height:Math.max(e.defaultLineHeight,t-5)}}function UC(e,t){let i,n=zC(e),{state:r}=e,s=TC(r.selection,i=>i.empty?e.moveVertically(i,t,n.height):AC(i,t));if(s.eq(r.selection))return!1;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),a=e.scrollDOM.getBoundingClientRect(),o=a.top+n.marginTop,l=a.bottom-n.marginBottom;t&&t.top>o&&t.bottom<l&&(i=GP.scrollIntoView(s.main.head,{y:"start",yMargin:t.top-o}))}return e.dispatch($C(r,s),{effects:i}),!0}const qC=e=>UC(e,!1),XC=e=>UC(e,!0);function BC(e,t,i){let n=e.lineBlockAt(t.head),r=e.moveToLineBoundary(t,i);if(r.head==t.head&&r.head!=(i?n.to:n.from)&&(r=e.moveToLineBoundary(t,i,!1)),!i&&r.head==n.from&&n.length){let i=/^\s*/.exec(e.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&t.head!=n.from+i&&(r=ww.cursor(n.from+i))}return r}function WC(e,t){let i=TC(e.state.selection,e=>{let i=t(e);return ww.range(e.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return!i.eq(e.state.selection)&&(e.dispatch($C(e.state,i)),!0)}function VC(e,t){return WC(e,i=>e.moveByChar(i,t))}const FC=e=>VC(e,!RC(e)),YC=e=>VC(e,RC(e));function GC(e,t){return WC(e,i=>e.moveByGroup(i,t))}function HC(e,t){return WC(e,i=>e.moveVertically(i,t))}const KC=e=>HC(e,!1),JC=e=>HC(e,!0);function eR(e,t){return WC(e,i=>e.moveVertically(i,t,zC(e).height))}const tR=e=>eR(e,!1),iR=e=>eR(e,!0),nR=({state:e,dispatch:t})=>(t($C(e,{anchor:0})),!0),rR=({state:e,dispatch:t})=>(t($C(e,{anchor:e.doc.length})),!0),sR=({state:e,dispatch:t})=>(t($C(e,{anchor:e.selection.main.anchor,head:0})),!0),aR=({state:e,dispatch:t})=>(t($C(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),oR=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0);function lR(e,t){let{state:i}=e,n=i.selection,r=i.selection.ranges.slice();for(let s of i.selection.ranges){let n=i.doc.lineAt(s.head);if(t?n.to<e.state.doc.length:n.from>0)for(let i=s;;){let s=e.moveVertically(i,t);if(s.head<n.from||s.head>n.to){r.some(e=>e.head==s.head)||r.push(s);break}if(s.head==i.head)break;i=s}}return r.length!=n.ranges.length&&(e.dispatch($C(i,ww.create(r,r.length-1))),!0)}function cR(e,t){if(e.state.readOnly)return!1;let i="delete.selection",{state:n}=e,r=n.changeByRange(n=>{let{from:r,to:s}=n;if(r==s){let a=t(n);a<r?(i="delete.backward",a=hR(e,a,!1)):a>r&&(i="delete.forward",a=hR(e,a,!0)),r=Math.min(r,a),s=Math.max(s,a)}else r=hR(e,r,!1),s=hR(e,s,!0);return r==s?{range:n}:{changes:{from:r,to:s},range:ww.cursor(r,r<n.head?-1:1)}});return!r.changes.empty&&(e.dispatch(n.update(r,{scrollIntoView:!0,userEvent:i,effects:"delete.selection"==i?GP.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function hR(e,t,i){if(e instanceof GP)for(let n of e.state.facet(GP.atomicRanges).map(t=>t(e)))n.between(t,t,(e,n)=>{e<t&&n>t&&(t=i?n:e)});return t}const uR=(e,t,i)=>cR(e,n=>{let r,s,a=n.from,{state:o}=e,l=o.doc.lineAt(a);if(i&&!t&&a>l.from&&a<l.from+200&&!/[^ \t]/.test(r=l.text.slice(0,a-l.from))){if("\t"==r[r.length-1])return a-1;let e=C_(r,o.tabSize)%oA(o)||oA(o);for(let t=0;t<e&&" "==r[r.length-1-t];t++)a--;s=a}else s=aw(l.text,a-l.from,t,t)+l.from,s==a&&l.number!=(t?o.doc.lines:1)?s+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(l.text.slice(s-l.from,a-l.from))&&(s=aw(l.text,s-l.from,!1,!1)+l.from);return s}),dR=e=>uR(e,!1,!0),pR=e=>uR(e,!0,!1),fR=(e,t)=>cR(e,i=>{let n=i.head,{state:r}=e,s=r.doc.lineAt(n),a=r.charCategorizer(n);for(let e=null;;){if(n==(t?s.to:s.from)){n==i.head&&s.number!=(t?r.doc.lines:1)&&(n+=t?1:-1);break}let o=aw(s.text,n-s.from,t)+s.from,l=s.text.slice(Math.min(n,o)-s.from,Math.max(n,o)-s.from),c=a(l);if(null!=e&&c!=e)break;" "==l&&n==i.head||(e=c),n=o}return n}),mR=e=>fR(e,!1);function gR(e){let t=[],i=-1;for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),s=e.doc.lineAt(n.to);if(n.empty||n.to!=s.from||(s=e.doc.lineAt(n.to-1)),i>=r.number){let e=t[t.length-1];e.to=s.to,e.ranges.push(n)}else t.push({from:r.from,to:s.to,ranges:[n]});i=s.number+1}return t}function OR(e,t,i){if(e.readOnly)return!1;let n=[],r=[];for(let s of gR(e)){if(i?s.to==e.doc.length:0==s.from)continue;let t=e.doc.lineAt(i?s.to+1:s.from-1),a=t.length+1;if(i){n.push({from:s.to,to:t.to},{from:s.from,insert:t.text+e.lineBreak});for(let t of s.ranges)r.push(ww.range(Math.min(e.doc.length,t.anchor+a),Math.min(e.doc.length,t.head+a)))}else{n.push({from:t.from,to:s.from},{from:s.to,insert:e.lineBreak+t.text});for(let e of s.ranges)r.push(ww.range(e.anchor-a,e.head-a))}}return!!n.length&&(t(e.update({changes:n,scrollIntoView:!0,selection:ww.create(r,e.selection.mainIndex),userEvent:"move.line"})),!0)}function vR(e,t,i){if(e.readOnly)return!1;let n=[];for(let s of gR(e))i?n.push({from:s.from,insert:e.doc.slice(s.from,s.to)+e.lineBreak}):n.push({from:s.to,insert:e.lineBreak+e.doc.slice(s.from,s.to)});let r=e.changes(n);return t(e.update({changes:r,selection:e.selection.map(r,i?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const yR=bR(!1);function bR(e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=t.changeByRange(i=>{let{from:n,to:r}=i,s=t.doc.lineAt(n),a=!e&&n==r&&function(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let i,n=FE(e).resolveInner(t),r=n.childBefore(t),s=n.childAfter(t);return r&&s&&r.to<=t&&s.from>=t&&(i=r.type.prop(L$.closedBy))&&i.indexOf(s.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(s.from).from&&!/\S/.test(e.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}(t,n);e&&(n=r=(r<=s.to?s:t.doc.lineAt(r)).to);let o=new hA(t,{simulateBreak:n,simulateDoubleBreak:!!a}),l=cA(o,n);for(null==l&&(l=C_(/^\s*/.exec(t.doc.lineAt(n).text)[0],t.tabSize));r<s.to&&/\s/.test(s.text[r-s.from]);)r++;a?({from:n,to:r}=a):n>s.from&&n<s.from+100&&!/\S/.test(s.text.slice(0,n))&&(n=s.from);let c=["",lA(t,l)];return a&&c.push(lA(t,o.lineIndent(s.from,-1))),{changes:{from:n,to:r,insert:Gb.of(c)},range:ww.cursor(n+1+c[1].length)}});return i(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function wR(e,t){let i=-1;return e.changeByRange(n=>{let r=[];for(let a=n.from;a<=n.to;){let s=e.doc.lineAt(a);s.number>i&&(n.empty||n.to>s.from)&&(t(s,r,n),i=s.number),a=s.to+1}let s=e.changes(r);return{changes:r,range:ww.range(s.mapPos(n.anchor,1),s.mapPos(n.head,1))}})}const _R=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(wR(e,(t,i)=>{i.push({from:t.from,insert:e.facet(aA)})}),{userEvent:"input.indent"})),!0),xR=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(wR(e,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=C_(n,e.tabSize),s=0,a=lA(e,Math.max(0,r-oA(e)));for(;s<n.length&&s<a.length&&n.charCodeAt(s)==a.charCodeAt(s);)s++;i.push({from:t.from+s,to:t.from+n.length,insert:a.slice(s)})}),{userEvent:"delete.dedent"})),!0),SR=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:e=>EC(e,t=>NC(e.state,t,!RC(e))),shift:e=>WC(e,t=>NC(e.state,t,!RC(e)))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:e=>EC(e,t=>NC(e.state,t,RC(e))),shift:e=>WC(e,t=>NC(e.state,t,RC(e)))},{key:"Alt-ArrowUp",run:({state:e,dispatch:t})=>OR(e,t,!1)},{key:"Shift-Alt-ArrowUp",run:({state:e,dispatch:t})=>vR(e,t,!1)},{key:"Alt-ArrowDown",run:({state:e,dispatch:t})=>OR(e,t,!0)},{key:"Shift-Alt-ArrowDown",run:({state:e,dispatch:t})=>vR(e,t,!0)},{key:"Mod-Alt-ArrowUp",run:e=>lR(e,!1)},{key:"Mod-Alt-ArrowDown",run:e=>lR(e,!0)},{key:"Escape",run:({state:e,dispatch:t})=>{let i=e.selection,n=null;return i.ranges.length>1?n=ww.create([i.main]):i.main.empty||(n=ww.create([ww.cursor(i.main.head)])),!!n&&(t($C(e,n)),!0)}},{key:"Mod-Enter",run:bR(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:e,dispatch:t})=>{let i=gR(e).map(({from:t,to:i})=>ww.range(t,Math.min(i+1,e.doc.length)));return t(e.update({selection:ww.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:e,dispatch:t})=>{let i=TC(e.selection,t=>{let i=FE(e),n=i.resolveStack(t.from,1);if(t.empty){let e=i.resolveStack(t.from,-1);e.node.from>=n.node.from&&e.node.to<=n.node.to&&(n=e)}for(let e=n;e;e=e.next){let{node:i}=e;if((i.from<t.from&&i.to>=t.to||i.to>t.to&&i.from<=t.from)&&e.next)return ww.range(i.to,i.from)}return t});return!i.eq(e.selection)&&(t($C(e,i)),!0)},preventDefault:!0},{key:"Mod-[",run:xR},{key:"Mod-]",run:_R},{key:"Mod-Alt-\\",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=Object.create(null),n=new hA(e,{overrideIndentation:e=>{let t=i[e];return null==t?-1:t}}),r=wR(e,(t,r,s)=>{let a=cA(n,t.from);if(null==a)return;/\S/.test(t.text)||(a=0);let o=/^\s*/.exec(t.text)[0],l=lA(e,a);(o!=l||s.from<t.from+o.length)&&(i[t.from]=a,r.push({from:t.from,to:t.from+o.length,insert:l}))});return r.changes.empty||t(e.update(r,{userEvent:"indent"})),!0}},{key:"Shift-Mod-k",run:e=>{if(e.state.readOnly)return!1;let{state:t}=e,i=t.changes(gR(t).map(({from:e,to:i})=>(e>0?e--:i<t.doc.length&&i++,{from:e,to:i}))),n=TC(t.selection,t=>{let i;if(e.lineWrapping){let n=e.lineBlockAt(t.head),r=e.coordsAtPos(t.head,t.assoc||1);r&&(i=n.bottom+e.documentTop-r.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,i)}).map(i);return e.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:e,dispatch:t})=>function(e,t){let i=!1,n=TC(e.selection,t=>{let n=zA(e,t.head,-1)||zA(e,t.head,1)||t.head>0&&zA(e,t.head-1,1)||t.head<e.doc.length&&zA(e,t.head+1,-1);if(!n||!n.end)return t;i=!0;let r=n.start.from==t.head?n.end.to:n.end.from;return ww.cursor(r)});return!!i&&(t($C(e,n)),!0)}(e,t)},{key:"Mod-/",run:e=>{let{state:t}=e,i=t.doc.lineAt(t.selection.main.from),n=eC(e.state,i.from);return n.line?HA(e):!!n.block&&JA(e)}},{key:"Alt-A",run:KA},{key:"Ctrl-m",mac:"Shift-Alt-m",run:e=>(e.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:QC,shift:FC,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e=>jC(e,!RC(e)),shift:e=>GC(e,!RC(e)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:e=>EC(e,t=>BC(e,t,!RC(e))),shift:e=>WC(e,t=>BC(e,t,!RC(e))),preventDefault:!0},{key:"ArrowRight",run:IC,shift:YC,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:e=>jC(e,RC(e)),shift:e=>GC(e,RC(e)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:e=>EC(e,t=>BC(e,t,RC(e))),shift:e=>WC(e,t=>BC(e,t,RC(e))),preventDefault:!0},{key:"ArrowUp",run:ZC,shift:KC,preventDefault:!0},{mac:"Cmd-ArrowUp",run:nR,shift:sR},{mac:"Ctrl-ArrowUp",run:qC,shift:tR},{key:"ArrowDown",run:DC,shift:JC,preventDefault:!0},{mac:"Cmd-ArrowDown",run:rR,shift:aR},{mac:"Ctrl-ArrowDown",run:XC,shift:iR},{key:"PageUp",run:qC,shift:tR},{key:"PageDown",run:XC,shift:iR},{key:"Home",run:e=>EC(e,t=>BC(e,t,!1)),shift:e=>WC(e,t=>BC(e,t,!1)),preventDefault:!0},{key:"Mod-Home",run:nR,shift:sR},{key:"End",run:e=>EC(e,t=>BC(e,t,!0)),shift:e=>WC(e,t=>BC(e,t,!0)),preventDefault:!0},{key:"Mod-End",run:rR,shift:aR},{key:"Enter",run:yR,shift:yR},{key:"Mod-a",run:oR},{key:"Backspace",run:dR,shift:dR,preventDefault:!0},{key:"Delete",run:pR,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:mR,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:e=>fR(e,!0),preventDefault:!0},{mac:"Mod-Backspace",run:e=>cR(e,t=>{let i=e.moveToLineBoundary(t,!1).head;return t.head>i?i:Math.max(0,t.head-1)}),preventDefault:!0},{mac:"Mod-Delete",run:e=>cR(e,t=>{let i=e.moveToLineBoundary(t,!0).head;return t.head<i?i:Math.min(e.state.doc.length,t.head+1)}),preventDefault:!0}].concat([{key:"Ctrl-b",run:QC,shift:FC,preventDefault:!0},{key:"Ctrl-f",run:IC,shift:YC},{key:"Ctrl-p",run:ZC,shift:KC},{key:"Ctrl-n",run:DC,shift:JC},{key:"Ctrl-a",run:e=>EC(e,t=>ww.cursor(e.lineBlockAt(t.head).from,1)),shift:e=>WC(e,t=>ww.cursor(e.lineBlockAt(t.head).from))},{key:"Ctrl-e",run:e=>EC(e,t=>ww.cursor(e.lineBlockAt(t.head).to,-1)),shift:e=>WC(e,t=>ww.cursor(e.lineBlockAt(t.head).to))},{key:"Ctrl-d",run:pR},{key:"Ctrl-h",run:dR},{key:"Ctrl-k",run:e=>cR(e,t=>{let i=e.lineBlockAt(t.head).to;return t.head<i?i:Math.min(e.state.doc.length,t.head+1)})},{key:"Ctrl-Alt-h",run:mR},{key:"Ctrl-o",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:Gb.of(["",""])},range:ww.cursor(e.from)}));return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(t=>{if(!t.empty||0==t.from||t.from==e.doc.length)return{range:t};let i=t.from,n=e.doc.lineAt(i),r=i==n.from?i-1:aw(n.text,i-n.from,!1)+n.from,s=i==n.to?i+1:aw(n.text,i-n.from,!0)+n.from;return{changes:{from:r,to:s,insert:e.doc.slice(i,s).append(e.doc.slice(r,i))},range:ww.cursor(s)}});return!i.changes.empty&&(t(e.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:XC}].map(e=>({mac:e.key,run:e.run,shift:e.shift})))),kR={key:"Tab",run:_R,shift:xR},PR="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class TR{constructor(e,t,i=0,n=e.length,r,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?e=>r(PR(e)):PR,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ow(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=lw(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=cw(e);let n=this.normalize(t);if(n.length)for(let r=0,s=i;;r++){let e=n.charCodeAt(r),a=this.match(e,s,this.bufferPos+this.bufferStart);if(r==n.length-1){if(a)return this.value=a,this;break}s==i&&r<t.length&&t.charCodeAt(r)==e&&s++}}}match(e,t,i){let n=null;for(let r=0;r<this.matches.length;r+=2){let t=this.matches[r],s=!1;this.query.charCodeAt(t)==e&&(t==this.query.length-1?n={from:this.matches[r+1],to:i}:(this.matches[r]++,s=!0)),s||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(1==this.query.length?n={from:t,to:i}:this.matches.push(1,t)),n&&this.test&&!this.test(n.from,n.to,this.buffer,this.bufferStart)&&(n=null),n}}"undefined"!=typeof Symbol&&(TR.prototype[Symbol.iterator]=function(){return this});const $R={from:-1,to:-1,match:/.*/.exec("")},ER="gm"+(null==/x/.unicode?"":"u");class AR{constructor(e,t,i,n=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=$R,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new QR(e,t,i,n,r);this.re=new RegExp(t,ER+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.iter=e.iter();let s=e.lineAt(n);this.curLineStart=s.from,this.matchPos=IR(e,n),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,n=i+t[0].length;if(this.matchPos=IR(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,match:t},this;e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),e=0}}}}const CR=new WeakMap;class RR{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let n=CR.get(e);if(!n||n.from>=i||n.to<=t){let n=new RR(t,e.sliceString(t,i));return CR.set(e,n),n}if(n.from==t&&n.to==i)return n;let{text:r,from:s}=n;return s>t&&(r=e.sliceString(t,s)+r,s=t),n.to<i&&(r+=e.sliceString(n.to,i)),CR.set(e,new RR(s,r)),new RR(t,r.slice(t-s,i-s))}}class QR{constructor(e,t,i,n,r){this.text=e,this.to=r,this.done=!1,this.value=$R,this.matchPos=IR(e,n),this.re=new RegExp(t,ER+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.flat=RR.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,i=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,i,t)))return this.value={from:e,to:i,match:t},this.matchPos=IR(this.text,i+(e==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=RR.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function IR(e,t){if(t>=e.length)return t;let i,n=e.lineAt(t);for(;t<n.to&&(i=n.text.charCodeAt(t-n.from))>=56320&&i<57344;)t++;return t}"undefined"!=typeof Symbol&&(AR.prototype[Symbol.iterator]=QR.prototype[Symbol.iterator]=function(){return this});const jR={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},MR=Sw.define({combine:e=>p_(e,jR,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});const NR=ux.mark({class:"cm-selectionMatch"}),LR=ux.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ZR(e,t,i,n){return!(0!=i&&e(t.sliceDoc(i-1,i))==l_.Word||n!=t.doc.length&&e(t.sliceDoc(n,n+1))==l_.Word)}const DR=kS.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(MR),{state:i}=e,n=i.selection;if(n.ranges.length>1)return ux.none;let r,s=n.main,a=null;if(s.empty){if(!t.highlightWordAroundCursor)return ux.none;let e=i.wordAt(s.head);if(!e)return ux.none;a=i.charCategorizer(s.head),r=i.sliceDoc(e.from,e.to)}else{let e=s.to-s.from;if(e<t.minSelectionLength||e>200)return ux.none;if(t.wholeWords){if(r=i.sliceDoc(s.from,s.to),a=i.charCategorizer(s.head),!ZR(a,i,s.from,s.to)||!function(e,t,i,n){return e(t.sliceDoc(i,i+1))==l_.Word&&e(t.sliceDoc(n-1,n))==l_.Word}(a,i,s.from,s.to))return ux.none}else if(r=i.sliceDoc(s.from,s.to),!r)return ux.none}let o=[];for(let l of e.visibleRanges){let e=new TR(i.doc,r,l.from,l.to);for(;!e.next().done;){let{from:n,to:r}=e.value;if((!a||ZR(a,i,n,r))&&(s.empty&&n<=s.from&&r>=s.to?o.push(LR.range(n,r)):(n>=s.to||r<=s.from)&&o.push(NR.range(n,r)),o.length>t.maxMatches))return ux.none}}return ux.set(o)}},{decorations:e=>e.decorations}),zR=GP.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const UR=Sw.define({combine:e=>p_(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new OQ(e),scrollToMatch:e=>GP.scrollIntoView(e)})});class qR{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||function(e){try{return new RegExp(e,ER),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>"n"==t?"\n":"r"==t?"\r":"t"==t?"\t":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new GR(this):new WR(this)}getCursor(e,t=0,i){let n=e.doc?e:d_.create({doc:e});return null==i&&(i=n.doc.length),this.regexp?VR(this,n,t,i):BR(this,n,t,i)}}class XR{constructor(e){this.spec=e}}function BR(e,t,i,n){let r;var s,a;return e.wholeWord&&(s=t.doc,a=t.charCategorizer(t.selection.main.head),r=(e,t,i,n)=>((n>e||n+i.length<t)&&(n=Math.max(0,e-2),i=s.sliceString(n,Math.min(s.length,t+2))),!(a(FR(i,e-n))==l_.Word&&a(YR(i,e-n))==l_.Word||a(YR(i,t-n))==l_.Word&&a(FR(i,t-n))==l_.Word))),e.test&&(r=function(e,t,i){return(n,r,s,a)=>{if(i&&!i(n,r,s,a))return!1;let o=n>=a&&r<=a+s.length?s.slice(n-a,r-a):t.doc.sliceString(n,r);return e(o,t,n,r)}}(e.test,t,r)),new TR(t.doc,e.unquoted,i,n,e.caseSensitive?void 0:e=>e.toLowerCase(),r)}class WR extends XR{constructor(e){super(e)}nextMatch(e,t,i){let n=BR(this.spec,e,i,e.doc.length).nextOverlapping();if(n.done){let i=Math.min(e.doc.length,t+this.spec.unquoted.length);n=BR(this.spec,e,0,i).nextOverlapping()}return n.done||n.value.from==t&&n.value.to==i?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let i=Math.max(t,n-1e4-this.spec.unquoted.length),r=BR(this.spec,e,i,n),s=null;for(;!r.nextOverlapping().done;)s=r.value;if(s)return s;if(i==t)return null;n-=1e4}}prevMatch(e,t,i){let n=this.prevMatchInRange(e,0,t);return n||(n=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),!n||n.from==t&&n.to==i?null:n}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=BR(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=BR(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function VR(e,t,i,n){let r;var s;return e.wholeWord&&(s=t.charCategorizer(t.selection.main.head),r=(e,t,i)=>!i[0].length||(s(FR(i.input,i.index))!=l_.Word||s(YR(i.input,i.index))!=l_.Word)&&(s(YR(i.input,i.index+i[0].length))!=l_.Word||s(FR(i.input,i.index+i[0].length))!=l_.Word)),e.test&&(r=function(e,t,i){return(n,r,s)=>(!i||i(n,r,s))&&e(s[0],t,n,r)}(e.test,t,r)),new AR(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:r},i,n)}function FR(e,t){return e.slice(aw(e,t,!1),t)}function YR(e,t){return e.slice(t,aw(e,t))}class GR extends XR{nextMatch(e,t,i){let n=VR(this.spec,e,i,e.doc.length).next();return n.done&&(n=VR(this.spec,e,0,t).next()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=1;;n++){let r=Math.max(t,i-1e4*n),s=VR(this.spec,e,r,i),a=null;for(;!s.next().done;)a=s.value;if(a&&(r==t||a.from>r+10))return a;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if("&"==i)return e.match[0];if("$"==i)return"$";for(let n=i.length;n>0;n--){let t=+i.slice(0,n);if(t>0&&t<e.match.length)return e.match[t]+i.slice(n)}return t})}matchAll(e,t){let i=VR(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=VR(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const HR=e_.define(),KR=e_.define(),JR=Cw.define({create:e=>new eQ(uQ(e).create(),null),update(e,t){for(let i of t.effects)i.is(HR)?e=new eQ(i.value.create(),e.panel):i.is(KR)&&(e=new eQ(e.query,i.value?hQ:null));return e},provide:e=>c$.from(e,e=>e.panel)});class eQ{constructor(e,t){this.query=e,this.panel=t}}const tQ=ux.mark({class:"cm-searchMatch"}),iQ=ux.mark({class:"cm-searchMatch cm-searchMatch-selected"}),nQ=kS.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(JR))}update(e){let t=e.state.field(JR);(t!=e.startState.field(JR)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return ux.none;let{view:i}=this,n=new b_;for(let r=0,s=i.visibleRanges,a=s.length;r<a;r++){let{from:t,to:o}=s[r];for(;r<a-1&&o>s[r+1].from-500;)o=s[++r].to;e.highlight(i.state,t,o,(e,t)=>{let r=i.state.selection.ranges.some(i=>i.from==e&&i.to==t);n.add(e,t,r?iQ:tQ)})}return n.finish()}},{decorations:e=>e.decorations});function rQ(e){return t=>{let i=t.state.field(JR,!1);return i&&i.query.spec.valid?e(t,i):fQ(t)}}const sQ=rQ((e,{query:t})=>{let{to:i}=e.state.selection.main,n=t.nextMatch(e.state,i,i);if(!n)return!1;let r=ww.single(n.from,n.to),s=e.state.facet(UR);return e.dispatch({selection:r,effects:[wQ(e,n),s.scrollToMatch(r.main,e)],userEvent:"select.search"}),pQ(e),!0}),aQ=rQ((e,{query:t})=>{let{state:i}=e,{from:n}=i.selection.main,r=t.prevMatch(i,n,n);if(!r)return!1;let s=ww.single(r.from,r.to),a=e.state.facet(UR);return e.dispatch({selection:s,effects:[wQ(e,r),a.scrollToMatch(s.main,e)],userEvent:"select.search"}),pQ(e),!0}),oQ=rQ((e,{query:t})=>{let i=t.matchAll(e.state,1e3);return!(!i||!i.length)&&(e.dispatch({selection:ww.create(i.map(e=>ww.range(e.from,e.to))),userEvent:"select.search.matches"}),!0)}),lQ=rQ((e,{query:t})=>{let{state:i}=e,{from:n,to:r}=i.selection.main;if(i.readOnly)return!1;let s=t.nextMatch(i,n,n);if(!s)return!1;let a,o,l=s,c=[],h=[];l.from==n&&l.to==r&&(o=i.toText(t.getReplacement(l)),c.push({from:l.from,to:l.to,insert:o}),l=t.nextMatch(i,l.from,l.to),h.push(GP.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+".")));let u=e.state.changes(c);return l&&(a=ww.single(l.from,l.to).map(u),h.push(wQ(e,l)),h.push(i.facet(UR).scrollToMatch(a.main,e))),e.dispatch({changes:u,selection:a,effects:h,userEvent:"input.replace"}),!0}),cQ=rQ((e,{query:t})=>{if(e.state.readOnly)return!1;let i=t.matchAll(e.state,1e9).map(e=>{let{from:i,to:n}=e;return{from:i,to:n,insert:t.getReplacement(e)}});if(!i.length)return!1;let n=e.state.phrase("replaced $ matches",i.length)+".";return e.dispatch({changes:i,effects:GP.announce.of(n),userEvent:"input.replace.all"}),!0});function hQ(e){return e.state.facet(UR).createPanel(e)}function uQ(e,t){var i,n,r,s,a;let o=e.selection.main,l=o.empty||o.to>o.from+100?"":e.sliceDoc(o.from,o.to);if(t&&!l)return t;let c=e.facet(UR);return new qR({search:(null!==(i=null==t?void 0:t.literal)&&void 0!==i?i:c.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==t?void 0:t.caseSensitive)&&void 0!==n?n:c.caseSensitive,literal:null!==(r=null==t?void 0:t.literal)&&void 0!==r?r:c.literal,regexp:null!==(s=null==t?void 0:t.regexp)&&void 0!==s?s:c.regexp,wholeWord:null!==(a=null==t?void 0:t.wholeWord)&&void 0!==a?a:c.wholeWord})}function dQ(e){let t=s$(e,hQ);return t&&t.dom.querySelector("[main-field]")}function pQ(e){let t=dQ(e);t&&t==e.root.activeElement&&t.select()}const fQ=e=>{let t=e.state.field(JR,!1);if(t&&t.panel){let i=dQ(e);if(i&&i!=e.root.activeElement){let n=uQ(e.state,t.query.spec);n.valid&&e.dispatch({effects:HR.of(n)}),i.focus(),i.select()}}else e.dispatch({effects:[KR.of(!0),t?HR.of(uQ(e.state,t.query.spec)):e_.appendConfig.of(xQ)]});return!0},mQ=e=>{let t=e.state.field(JR,!1);if(!t||!t.panel)return!1;let i=s$(e,hQ);return i&&i.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:KR.of(!1)}),!0},gQ=[{key:"Mod-f",run:fQ,scope:"editor search-panel"},{key:"F3",run:sQ,shift:aQ,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:sQ,shift:aQ,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:mQ,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:e,dispatch:t})=>{let i=e.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:n,to:r}=i.main,s=[],a=0;for(let o=new TR(e.doc,e.sliceDoc(n,r));!o.next().done;){if(s.length>1e3)return!1;o.value.from==n&&(a=s.length),s.push(ww.range(o.value.from,o.value.to))}return t(e.update({selection:ww.create(s,a),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:e=>{let{state:t}=e,i=String(t.doc.lineAt(e.state.selection.main.head).number),{close:n,result:r}=h$(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:i},focus:!0,submitLabel:t.phrase("go")});return r.then(i=>{let r=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!r)return void e.dispatch({effects:n});let s=t.doc.lineAt(t.selection.main.head),[,a,o,l,c]=r,h=l?+l.slice(1):0,u=o?+o:s.number;if(o&&c){let e=u/100;a&&(e=e*("-"==a?-1:1)+s.number/t.doc.lines),u=Math.round(t.doc.lines*e)}else o&&a&&(u=u*("-"==a?-1:1)+s.number);let d=t.doc.line(Math.max(1,Math.min(t.doc.lines,u))),p=ww.cursor(d.from+Math.max(0,Math.min(h,d.length)));e.dispatch({effects:[n,GP.scrollIntoView(p.from,{y:"center"})],selection:p})}),!0}},{key:"Mod-d",run:({state:e,dispatch:t})=>{let{ranges:i}=e.selection;if(i.some(e=>e.from===e.to))return(({state:e,dispatch:t})=>{let{selection:i}=e,n=ww.create(i.ranges.map(t=>e.wordAt(t.head)||ww.cursor(t.head)),i.mainIndex);return!n.eq(i)&&(t(e.update({selection:n})),!0)})({state:e,dispatch:t});let n=e.sliceDoc(i[0].from,i[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=n))return!1;let r=function(e,t){let{main:i,ranges:n}=e.selection,r=e.wordAt(i.head),s=r&&r.from==i.from&&r.to==i.to;for(let a=!1,o=new TR(e.doc,t,n[n.length-1].to);;){if(o.next(),!o.done){if(a&&n.some(e=>e.from==o.value.from))continue;if(s){let t=e.wordAt(o.value.from);if(!t||t.from!=o.value.from||t.to!=o.value.to)continue}return o.value}if(a)return null;o=new TR(e.doc,t,0,Math.max(0,n[n.length-1].from-1)),a=!0}}(e,n);return!!r&&(t(e.update({selection:e.selection.addRange(ww.range(r.from,r.to),!1),effects:GP.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class OQ{constructor(e){this.view=e;let t=this.query=e.state.field(JR).query.spec;function i(e,t,i){return X_("button",{class:"cm-button",name:e,onclick:t,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=X_("input",{value:t.search,placeholder:vQ(e,"Find"),"aria-label":vQ(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=X_("input",{value:t.replace,placeholder:vQ(e,"Replace"),"aria-label":vQ(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=X_("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=X_("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=X_("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=X_("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,i("next",()=>sQ(e),[vQ(e,"next")]),i("prev",()=>aQ(e),[vQ(e,"previous")]),i("select",()=>oQ(e),[vQ(e,"all")]),X_("label",null,[this.caseField,vQ(e,"match case")]),X_("label",null,[this.reField,vQ(e,"regexp")]),X_("label",null,[this.wordField,vQ(e,"by word")]),...e.state.readOnly?[]:[X_("br"),this.replaceField,i("replace",()=>lQ(e),[vQ(e,"replace")]),i("replaceAll",()=>cQ(e),[vQ(e,"replace all")])],X_("button",{name:"close",onclick:()=>mQ(e),"aria-label":vQ(e,"close"),type:"button"},["×"])])}commit(){let e=new qR({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:HR.of(e)}))}keydown(e){var t,i,n;t=this.view,i=e,n="search-panel",hT(aT(t.state),i,t,n)?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?aQ:sQ)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),lQ(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(HR)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(UR).top}}function vQ(e,t){return e.state.phrase(t)}const yQ=30,bQ=/[\s\.,:;?!]/;function wQ(e,{from:t,to:i}){let n=e.state.doc.lineAt(t),r=e.state.doc.lineAt(i).to,s=Math.max(n.from,t-yQ),a=Math.min(r,i+yQ),o=e.state.sliceDoc(s,a);if(s!=n.from)for(let l=0;l<yQ;l++)if(!bQ.test(o[l+1])&&bQ.test(o[l])){o=o.slice(l);break}if(a!=r)for(let l=o.length-1;l>o.length-yQ;l--)if(!bQ.test(o[l-1])&&bQ.test(o[l])){o=o.slice(0,l);break}return GP.announce.of(`${e.state.phrase("current match")}. ${o} ${e.state.phrase("on line")} ${n.number}.`)}const _Q=GP.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),xQ=[JR,Nw.low(nQ),_Q];class SQ{constructor(e,t,i,n,r,s,a,o,l,c=0,h){this.p=e,this.stack=t,this.state=i,this.reducePos=n,this.pos=r,this.score=s,this.buffer=a,this.bufferBase=o,this.curContext=l,this.lookAhead=c,this.parent=h}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let n=e.parser.context;return new SQ(e,[],t,i,i,0,[],0,n?new kQ(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,n=65535&e,{parser:r}=this.p,s=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),a=r.dynamicPrecedence(n);if(a&&(this.score+=a),0==i)return this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,s?8:4,!0),void this.reduceContext(n,this.reducePos);let o=this.stack.length-3*(i-1)-(262144&e?6:0),l=o?this.stack[o-2]:this.p.ranges[0].from,c=this.reducePos-l;c>=2e3&&!(null===(t=this.p.parser.nodeSet.types[n])||void 0===t?void 0:t.isAnonymous)&&(l==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=l,this.p.lastBigReductionSize=c));let h=o?this.stack[o-1]:0,u=this.bufferBase+this.buffer.length-h;if(n<r.minRepeatTerm||131072&e){let e=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,l,e,u+4,!0)}if(262144&e)this.state=this.stack[o];else{let e=this.stack[o-3];this.state=r.getGoto(e,n,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(n,l)}storeNode(e,t,i,n=4,r=!1){if(0==e&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let e=this,n=this.buffer.length;if(0==n&&e.parent&&(n=e.bufferBase-e.parent.bufferBase,e=e.parent),n>0&&0==e.buffer[n-4]&&e.buffer[n-1]>-1){if(t==i)return;if(e.buffer[n-2]>=t)return void(e.buffer[n-2]=i)}}if(r&&this.pos!=i){let r=this.buffer.length;if(r>0&&(0!=this.buffer[r-4]||this.buffer[r-1]<0)){let e=!1;for(let t=r;t>0&&this.buffer[t-2]>i;t-=4)if(this.buffer[t-1]>=0){e=!0;break}if(e)for(;r>0&&this.buffer[r-2]>i;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,n>4&&(n-=4)}this.buffer[r]=e,this.buffer[r+1]=t,this.buffer[r+2]=i,this.buffer[r+3]=n}else this.buffer.push(e,t,i,n)}shift(e,t,i,n){if(131072&e)this.pushState(65535&e,this.pos);else if(262144&e)this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4);else{let r=e,{parser:s}=this.p;this.pos=n;let a=s.stateFlag(r,1);!a&&(n>i||t<=s.maxNode)&&(this.reducePos=n),this.pushState(r,a?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=s.maxNode&&this.buffer.push(t,i,n,4)}}apply(e,t,i,n){65536&e?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new SQ(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new PQ(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(0==i)return!1;if(!(65536&i))return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let i=[];for(let n,r=0;r<t.length;r+=2)(n=t[r+1])!=this.state&&this.p.parser.hasAction(n,e)&&i.push(t[r],n);if(this.stack.length<120)for(let e=0;i.length<8&&e<t.length;e+=2){let n=t[e+1];i.some((e,t)=>1&t&&e==n)||i.push(t[e],n)}t=i}let i=[];for(let n=0;n<t.length&&i.length<4;n+=2){let e=t[n+1];if(e==this.state)continue;let r=this.split();r.pushState(e,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(t[n],this.pos),r.reducePos=this.pos,r.score-=200,i.push(r)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if(!(65536&t))return!1;if(!e.validAction(this.state,t)){let i=t>>19,n=65535&t,r=this.stack.length-3*i;if(r<0||e.getGoto(this.stack[r],n,!1)<0){let e=this.findForcedReduction();if(null==e)return!1;t=e}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(n,r)=>{if(!t.includes(n))return t.push(n),e.allActions(n,t=>{if(393216&t);else if(65536&t){let i=(t>>19)-r;if(i>1){let n=65535&t,r=this.stack.length-3*i;if(r>=0&&e.getGoto(this.stack[r],n,!1)>=0)return i<<19|65536|n}}else{let e=i(t,r+1);if(null!=e)return e}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:e}=this.p;return 65535==e.data[e.stateSlot(this.state,1)]&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||-3!=this.buffer[e])&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||-4!=this.buffer[e])&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new kQ(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return!(e<=this.lookAhead)&&(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class kQ{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class PQ{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=65535&e,i=e>>19;0==i?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(i-1);let n=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=n}}class TQ{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,0==this.index&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new TQ(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;null!=e&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new TQ(this.stack,this.pos,this.index)}}function $Q(e,t=Uint16Array){if("string"!=typeof e)return e;let i=null;for(let n=0,r=0;n<e.length;){let s=0;for(;;){let t=e.charCodeAt(n++),i=!1;if(126==t){s=65535;break}t>=92&&t--,t>=34&&t--;let r=t-32;if(r>=46&&(r-=46,i=!0),s+=r,i)break;s*=46}i?i[r++]=s:i=new t(s)}return i}class EQ{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const AQ=new EQ;class CQ{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=AQ,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,n=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!n)return null;let e=this.ranges[--n];r-=i.from-e.to,i=e}for(;t<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let e=this.ranges[++n];r+=e.from-i.to,i=e}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t,i,n=this.chunkOff+e;if(n>=0&&n<this.chunk.length)t=this.pos+e,i=this.chunk.charCodeAt(n);else{let n=this.resolveOffset(e,1);if(null==n)return-1;if(t=n,t>=this.chunk2Pos&&t<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(t-this.chunk2Pos);else{let e=this.rangeIndex,n=this.range;for(;n.to<=t;)n=this.ranges[++e];this.chunk2=this.input.chunk(this.chunk2Pos=t),t+this.chunk2.length>n.to&&(this.chunk2=this.chunk2.slice(0,n.to-t)),i=this.chunk2.charCodeAt(0)}}return t>=this.token.lookAhead&&(this.token.lookAhead=t+1),i}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(null==i||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=AQ,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let n of this.ranges){if(n.from>=t)break;n.to>e&&(i+=this.input.read(Math.max(n.from,e),Math.min(n.to,t)))}return i}}class RQ{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;jQ(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}RQ.prototype.contextual=RQ.prototype.fallback=RQ.prototype.extend=!1;class QQ{constructor(e,t,i){this.precTable=t,this.elseToken=i,this.data="string"==typeof e?$Q(e):e}token(e,t){let i=e.pos,n=0;for(;;){let i=e.next<0,r=e.resolveOffset(1,1);if(jQ(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(null==this.elseToken)return;if(i||n++,null==r)break;e.reset(r,e.token)}n&&(e.reset(i,e.token),e.acceptToken(this.elseToken,n))}}QQ.prototype.contextual=RQ.prototype.fallback=RQ.prototype.extend=!1;class IQ{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function jQ(e,t,i,n,r,s){let a=0,o=1<<n,{dialect:l}=i.p.parser;e:for(;0!=(o&e[a]);){let i=e[a+1];for(let u=a+3;u<i;u+=2)if((e[u+1]&o)>0){let i=e[u];if(l.allows(i)&&(-1==t.token.value||t.token.value==i||NQ(i,t.token.value,r,s))){t.acceptToken(i);break}}let n=t.next,c=0,h=e[a+2];if(!(t.next<0&&h>c&&65535==e[i+3*h-3])){for(;c<h;){let r=c+h>>1,s=i+r+(r<<1),o=e[s],l=e[s+1]||65536;if(n<o)h=r;else{if(!(n>=l)){a=e[s+2],t.advance();continue e}c=r+1}}break}a=e[i+3*h-1]}}function MQ(e,t,i){for(let n,r=t;65535!=(n=e[r]);r++)if(n==i)return r-t;return-1}function NQ(e,t,i,n){let r=MQ(i,n,t);return r<0||MQ(i,n,e)<r}const LQ="undefined"!=typeof process&&process.env&&/\bparse\b/.test(process.env.LOG);let ZQ=null;function DQ(e,t,i){let n=e.cursor(B$.IncludeAnonymous);for(n.moveTo(t);;)if(!(i<0?n.childBefore(t):n.childAfter(t)))for(;;){if((i<0?n.to<t:n.from>t)&&!n.type.isError)return i<0?Math.max(0,Math.min(n.to-1,t-25)):Math.min(e.length,Math.max(n.from+1,t+25));if(i<0?n.prevSibling():n.nextSibling())break;if(!n.parent())return i<0?0:e.length}}class zQ{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?DQ(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?DQ(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],n=this.index[t];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],s=this.start[t]+i.positions[n];if(s>e)return this.nextStart=s,null;if(r instanceof V$){if(s==e){if(s<this.safeFrom)return null;let e=s+r.length;if(e<=this.safeTo){let t=r.prop(L$.lookAhead);if(!t||e+t<this.fragment.to)return r}}this.index[t]++,s+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(s),this.index.push(0))}else this.index[t]++,this.nextStart=s+r.length}}}class UQ{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(e=>new EQ)}getActions(e){let t=0,i=null,{parser:n}=e.p,{tokenizers:r}=n,s=n.stateSlot(e.state,3),a=e.curContext?e.curContext.hash:0,o=0;for(let l=0;l<r.length;l++){if(!(1<<l&s))continue;let n=r[l],c=this.tokens[l];if((!i||n.fallback)&&((n.contextual||c.start!=e.pos||c.mask!=s||c.context!=a)&&(this.updateCachedToken(c,n,e),c.mask=s,c.context=a),c.lookAhead>c.end+25&&(o=Math.max(c.lookAhead,o)),0!=c.value)){let r=t;if(c.extended>-1&&(t=this.addActions(e,c.extended,c.end,t)),t=this.addActions(e,c.value,c.end,t),!n.extend&&(i=c,t>r))break}}for(;this.actions.length>t;)this.actions.pop();return o&&e.setLookAhead(o),i||e.pos!=this.stream.end||(i=new EQ,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new EQ,{pos:i,p:n}=e;return t.start=i,t.end=Math.min(i+1,n.stream.end),t.value=i==n.stream.end?n.parser.eofTerm:0,t}updateCachedToken(e,t,i){let n=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(n,e),i),e.value>-1){let{parser:t}=i.p;for(let n=0;n<t.specialized.length;n++)if(t.specialized[n]==e.value){let r=t.specializers[n](this.stream.read(e.start,e.end),i);if(r>=0&&i.p.parser.dialect.allows(r>>1)){1&r?e.extended=r>>1:e.value=r>>1;break}}}else e.value=0,e.end=this.stream.clipPos(n+1)}putAction(e,t,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==e)return n;return this.actions[n++]=e,this.actions[n++]=t,this.actions[n++]=i,n}addActions(e,t,i,n){let{state:r}=e,{parser:s}=e.p,{data:a}=s;for(let o=0;o<2;o++)for(let e=s.stateSlot(r,o?2:1);;e+=3){if(65535==a[e]){if(1!=a[e+1]){0==n&&2==a[e+1]&&(n=this.putAction(FQ(a,e+2),t,i,n));break}e=FQ(a,e+2)}a[e]==t&&(n=this.putAction(FQ(a,e+1),t,i,n))}return n}}class qQ{constructor(e,t,i,n){this.parser=e,this.input=t,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new CQ(t,n),this.tokens=new UQ(e,this.stream),this.topTerm=e.top[1];let{from:r}=n[0];this.stacks=[SQ.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>4*e.bufferLength?new zQ(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e,t,i=this.stacks,n=this.minStackPos,r=this.stacks=[];if(this.bigReductionCount>300&&1==i.length){let[e]=i;for(;e.forceReduce()&&e.stack.length&&e.stack[e.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let s=0;s<i.length;s++){let a=i[s];for(;;){if(this.tokens.mainToken=null,a.pos>n)r.push(a);else{if(this.advanceStack(a,r,i))continue;{e||(e=[],t=[]),e.push(a);let i=this.tokens.getMainToken(a);t.push(i.value,i.end)}}break}}if(!r.length){let t=e&&function(e){let t=null;for(let i of e){let e=i.p.stoppedAt;(i.pos==i.p.stream.end||null!=e&&i.pos>e)&&i.p.parser.stateFlag(i.state,2)&&(!t||t.score<i.score)&&(t=i)}return t}(e);if(t)return this.stackToTree(t);if(this.parser.strict)throw new SyntaxError("No parse at "+n);this.recovering||(this.recovering=5)}if(this.recovering&&e){let i=null!=this.stoppedAt&&e[0].pos>this.stoppedAt?e[0]:this.runRecovery(e,t,r);if(i)return this.stackToTree(i.forceAll())}if(this.recovering){let e=1==this.recovering?1:3*this.recovering;if(r.length>e)for(r.sort((e,t)=>t.score-e.score);r.length>e;)r.pop();r.some(e=>e.reducePos>n)&&this.recovering--}else if(r.length>1){e:for(let e=0;e<r.length-1;e++){let t=r[e];for(let i=e+1;i<r.length;i++){let n=r[i];if(t.sameState(n)||t.buffer.length>500&&n.buffer.length>500){if(!((t.score-n.score||t.buffer.length-n.buffer.length)>0)){r.splice(e--,1);continue e}r.splice(i--,1)}}}r.length>12&&(r.sort((e,t)=>t.score-e.score),r.splice(12,r.length-12))}this.minStackPos=r[0].pos;for(let s=1;s<r.length;s++)r[s].pos<this.minStackPos&&(this.minStackPos=r[s].pos);return null}stopAt(e){if(null!=this.stoppedAt&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let n=e.pos,{parser:r}=this;LQ&&this.stackID(e);if(null!=this.stoppedAt&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let t=e.curContext&&e.curContext.tracker.strict,i=t?e.curContext.hash:0;for(let s=this.fragments.nodeAt(n);s;){let n=this.parser.nodeSet.types[s.type.id]==s.type?r.getGoto(e.state,s.type.id):-1;if(n>-1&&s.length&&(!t||(s.prop(L$.contextHash)||0)==i))return e.useNode(s,n),!0;if(!(s instanceof V$)||0==s.children.length||s.positions[0]>0)break;let a=s.children[0];if(!(a instanceof V$&&0==s.positions[0]))break;s=a}}let s=r.stateSlot(e.state,4);if(s>0)return e.reduce(s),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let o=0;o<a.length;){let r=a[o++],s=a[o++],l=a[o++],c=o==a.length||!i,h=c?e:e.split(),u=this.tokens.mainToken;if(h.apply(r,s,u?u.start:h.pos,l),c)return!0;h.pos>n?t.push(h):i.push(h)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return XQ(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let s=0;s<e.length;s++){let a=e[s],o=t[s<<1],l=t[1+(s<<1)],c=LQ?this.stackID(a)+" -> ":"";if(a.deadEnd){if(r)continue;if(r=!0,a.restart(),this.advanceFully(a,i))continue}let h=a.split(),u=c;for(let e=0;e<10&&h.forceReduce();e++){if(this.advanceFully(h,i))break;LQ&&(u=this.stackID(h)+" -> ")}for(let e of a.recoverByInsert(o))this.advanceFully(e,i);this.stream.end>a.pos?(l==a.pos&&(l++,o=0),a.recoverByDelete(o,l),XQ(a,i)):(!n||n.score<h.score)&&(n=h)}return n}stackToTree(e){return e.close(),V$.build({buffer:TQ.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(ZQ||(ZQ=new WeakMap)).get(e);return t||ZQ.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function XQ(e,t){for(let i=0;i<t.length;i++){let n=t[i];if(n.pos==e.pos&&n.sameState(e))return void(t[i].score<e.score&&(t[i]=e))}t.push(e)}class BQ{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||0==this.disabled[e]}}const WQ=e=>e;class VQ extends pE{constructor(e){if(super(),this.wrappers=[],14!=e.version)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let a=0;a<e.repeatNodeCount;a++)t.push("");let i=Object.keys(e.topRules).map(t=>e.topRules[t][1]),n=[];for(let a=0;a<t.length;a++)n.push([]);function r(e,t,i){n[e].push([t,t.deserialize(String(i))])}if(e.nodeProps)for(let a of e.nodeProps){let e=a[0];"string"==typeof e&&(e=L$[e]);for(let t=1;t<a.length;){let i=a[t++];if(i>=0)r(i,e,a[t++]);else{let n=a[t+-i];for(let s=-i;s>0;s--)r(a[t++],e,n);t++}}}this.nodeSet=new U$(t.map((t,r)=>z$.define({name:r>=this.minRepeatTerm?void 0:t,id:r,props:n[r],top:i.indexOf(r)>-1,error:0==r,skipped:e.skippedNodes&&e.skippedNodes.indexOf(r)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=j$;let s=$Q(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let a=0;a<this.specializerSpecs.length;a++)this.specialized[a]=this.specializerSpecs[a].term;this.specializers=this.specializerSpecs.map(YQ),this.states=$Q(e.states,Uint32Array),this.data=$Q(e.stateData),this.goto=$Q(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(e=>"number"==typeof e?new RQ(s,e):e),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let n=new qQ(this,e,t,i);for(let r of this.wrappers)n=r(n,e,t,i);return n}getGoto(e,t,i=!1){let n=this.goto;if(t>=n[0])return-1;for(let r=n[t+1];;){let t=n[r++],s=1&t,a=n[r++];if(s&&i)return a;for(let i=r+(t>>1);r<i;r++)if(n[r]==e)return a;if(s)return-1}}hasAction(e,t){let i=this.data;for(let n=0;n<2;n++)for(let r,s=this.stateSlot(e,n?2:1);;s+=3){if(65535==(r=i[s])){if(1!=i[s+1]){if(2==i[s+1])return FQ(i,s+2);break}r=i[s=FQ(i,s+2)]}if(r==t||0==r)return FQ(i,s+1)}return 0}stateSlot(e,t){return this.states[6*e+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,e=>e==t||null)}allActions(e,t){let i=this.stateSlot(e,4),n=i?t(i):void 0;for(let r=this.stateSlot(e,1);null==n;r+=3){if(65535==this.data[r]){if(1!=this.data[r+1])break;r=FQ(this.data,r+2)}n=t(FQ(this.data,r+1))}return n}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=FQ(this.data,i+2)}if(!(1&this.data[i+2])){let e=this.data[i+1];t.some((t,i)=>1&i&&t==e)||t.push(this.data[i],e)}}return t}configure(e){let t=Object.assign(Object.create(VQ.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(t=>{let i=e.tokenizers.find(e=>e.from==t);return i?i.to:t})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=e.specializers.find(e=>e.from==i.external);if(!r)return i;let s=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[n]=YQ(s),s})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),null!=e.strict&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),null!=e.bufferLength&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return null==t?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let e=t.indexOf(r);e>=0&&(i[e]=!0)}let n=null;for(let r=0;r<t.length;r++)if(!i[r])for(let e,i=this.dialects[t[r]];65535!=(e=this.data[i++]);)(n||(n=new Uint8Array(this.maxTerm+1)))[e]=1;return new BQ(e,i,n)}static deserialize(e){return new VQ(e)}}function FQ(e,t){return e[t]|e[t+1]<<16}function YQ(e){if(e.external){let t=e.extend?1:0;return(i,n)=>e.external(i,n)<<1|t}return e.get}const GQ=[9,10,11,12,13,32,133,160,5760,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8232,8233,8239,8287,12288],HQ=new class{constructor(e){this.start=e.start,this.shift=e.shift||WQ,this.reduce=e.reduce||WQ,this.reuse=e.reuse||WQ,this.hash=e.hash||(()=>0),this.strict=!1!==e.strict}}({start:!1,shift:(e,t)=>5==t||6==t||320==t?e:321==t,strict:!1}),KQ=new IQ((e,t)=>{let{next:i}=e;(125==i||-1==i||t.context)&&e.acceptToken(318)},{contextual:!0,fallback:!0}),JQ=new IQ((e,t)=>{let i,{next:n}=e;GQ.indexOf(n)>-1||(47!=n||47!=(i=e.peek(1))&&42!=i)&&(125==n||59==n||-1==n||t.context||e.acceptToken(316))},{contextual:!0}),eI=new IQ((e,t)=>{91!=e.next||t.context||e.acceptToken(317)},{contextual:!0}),tI=new IQ((e,t)=>{let{next:i}=e;if(43==i||45==i){if(e.advance(),i==e.next){e.advance();let i=!t.context&&t.canShift(1);e.acceptToken(i?1:2)}}else 63==i&&46==e.peek(1)&&(e.advance(),e.advance(),(e.next<48||e.next>57)&&e.acceptToken(3))},{contextual:!0});function iI(e,t){return e>=65&&e<=90||e>=97&&e<=122||95==e||e>=192||!t&&e>=48&&e<=57}const nI=new IQ((e,t)=>{if(60!=e.next||!t.dialectEnabled(0))return;if(e.advance(),47==e.next)return;let i=0;for(;GQ.indexOf(e.next)>-1;)e.advance(),i++;if(iI(e.next,!0)){for(e.advance(),i++;iI(e.next,!1);)e.advance(),i++;for(;GQ.indexOf(e.next)>-1;)e.advance(),i++;if(44==e.next)return;for(let t=0;;t++){if(7==t){if(!iI(e.next,!0))return;break}if(e.next!="extends".charCodeAt(t))break;e.advance(),i++}}e.acceptToken(4,-i)}),rI=yE({"get set async static":DE.modifier,"for while do if else switch try catch finally return throw break continue default case defer":DE.controlKeyword,"in of await yield void typeof delete instanceof as satisfies":DE.operatorKeyword,"let var const using function class extends":DE.definitionKeyword,"import export from":DE.moduleKeyword,"with debugger new":DE.keyword,TemplateString:DE.special(DE.string),super:DE.atom,BooleanLiteral:DE.bool,this:DE.self,null:DE.null,Star:DE.modifier,VariableName:DE.variableName,"CallExpression/VariableName TaggedTemplateExpression/VariableName":DE.function(DE.variableName),VariableDefinition:DE.definition(DE.variableName),Label:DE.labelName,PropertyName:DE.propertyName,PrivatePropertyName:DE.special(DE.propertyName),"CallExpression/MemberExpression/PropertyName":DE.function(DE.propertyName),"FunctionDeclaration/VariableDefinition":DE.function(DE.definition(DE.variableName)),"ClassDeclaration/VariableDefinition":DE.definition(DE.className),"NewExpression/VariableName":DE.className,PropertyDefinition:DE.definition(DE.propertyName),PrivatePropertyDefinition:DE.definition(DE.special(DE.propertyName)),UpdateOp:DE.updateOperator,"LineComment Hashbang":DE.lineComment,BlockComment:DE.blockComment,Number:DE.number,String:DE.string,Escape:DE.escape,ArithOp:DE.arithmeticOperator,LogicOp:DE.logicOperator,BitOp:DE.bitwiseOperator,CompareOp:DE.compareOperator,RegExp:DE.regexp,Equals:DE.definitionOperator,Arrow:DE.function(DE.punctuation),": Spread":DE.punctuation,"( )":DE.paren,"[ ]":DE.squareBracket,"{ }":DE.brace,"InterpolationStart InterpolationEnd":DE.special(DE.brace),".":DE.derefOperator,", ;":DE.separator,"@":DE.meta,TypeName:DE.typeName,TypeDefinition:DE.definition(DE.typeName),"type enum interface implements namespace module declare":DE.definitionKeyword,"abstract global Privacy readonly override":DE.modifier,"is keyof unique infer asserts":DE.operatorKeyword,JSXAttributeValue:DE.attributeValue,JSXText:DE.content,"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag":DE.angleBracket,"JSXIdentifier JSXNameSpacedName":DE.tagName,"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName":DE.attributeName,"JSXBuiltin/JSXIdentifier":DE.standard(DE.tagName)}),sI={__proto__:null,export:20,as:25,from:33,default:36,async:41,function:42,in:52,out:55,const:56,extends:60,this:64,true:72,false:72,null:84,void:88,typeof:92,super:108,new:142,delete:154,yield:163,await:167,class:172,public:235,private:235,protected:235,readonly:237,instanceof:256,satisfies:259,import:292,keyof:349,unique:353,infer:359,asserts:395,is:397,abstract:417,implements:419,type:421,let:424,var:426,using:429,interface:435,enum:439,namespace:445,module:447,declare:451,global:455,defer:471,for:476,of:485,while:488,with:492,do:496,if:500,else:502,switch:506,case:512,try:518,catch:522,finally:526,return:530,throw:534,break:538,continue:542,debugger:546},aI={__proto__:null,async:129,get:131,set:133,declare:195,public:197,private:197,protected:197,static:199,abstract:201,override:203,readonly:209,accessor:211,new:401},oI={__proto__:null,"<":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Declaration export Star as VariableName String Escape from ; default FunctionDeclaration async function VariableDefinition > < TypeParamList in out const TypeDefinition extends ThisType this LiteralType ArithOp Number BooleanLiteral TemplateType InterpolationEnd Interpolation InterpolationStart NullType null VoidType void TypeofType typeof MemberExpression . PropertyName [ TemplateString Escape Interpolation super RegExp ] ArrayExpression Spread , } { ObjectExpression Property async get set PropertyDefinition Block : NewTarget new NewExpression ) ( ArgList UnaryExpression delete LogicOp BitOp YieldExpression yield AwaitExpression await ParenthesizedExpression ClassExpression class ClassBody MethodDeclaration Decorator @ MemberExpression PrivatePropertyName CallExpression TypeArgList CompareOp < declare Privacy static abstract override PrivatePropertyDefinition PropertyDeclaration readonly accessor Optional TypeAnnotation Equals StaticBlock FunctionExpression ArrowFunction ParamList ParamList ArrayPattern ObjectPattern PatternProperty Privacy readonly Arrow MemberExpression BinaryExpression ArithOp ArithOp ArithOp ArithOp BitOp CompareOp instanceof satisfies CompareOp BitOp BitOp BitOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression UpdateOp PostfixExpression CallExpression InstantiationExpression TaggedTemplateExpression DynamicImport import ImportMeta JSXElement JSXSelfCloseEndTag JSXSelfClosingTag JSXIdentifier JSXBuiltin JSXIdentifier JSXNamespacedName JSXMemberExpression JSXSpreadAttribute JSXAttribute JSXAttributeValue JSXEscape JSXEndTag JSXOpenTag JSXFragmentTag JSXText JSXEscape JSXStartCloseTag JSXCloseTag PrefixCast < ArrowFunction TypeParamList SequenceExpression InstantiationExpression KeyofType keyof UniqueType unique ImportType InferredType infer TypeName ParenthesizedType FunctionSignature ParamList NewSignature IndexedType TupleType Label ArrayType ReadonlyType ObjectType MethodType PropertyType IndexSignature PropertyDefinition CallSignature TypePredicate asserts is NewSignature new UnionType LogicOp IntersectionType LogicOp ConditionalType ParameterizedType ClassDeclaration abstract implements type VariableDeclaration let var using TypeAliasDeclaration InterfaceDeclaration interface EnumDeclaration enum EnumBody NamespaceDeclaration namespace module AmbientDeclaration declare GlobalDeclaration global ClassDeclaration ClassBody AmbientFunctionDeclaration ExportGroup VariableName VariableName ImportDeclaration defer ImportGroup ForStatement for ForSpec ForInSpec ForOfSpec of WhileStatement while WithStatement with DoStatement do IfStatement if else SwitchStatement switch SwitchBody CaseLabel case DefaultLabel TryStatement try CatchClause catch FinallyClause finally ReturnStatement return ThrowStatement throw BreakStatement break ContinueStatement continue DebuggerStatement debugger LabeledStatement ExpressionStatement SingleExpression SingleClassItem",maxTerm:380,context:HQ,nodeProps:[["isolate",-8,5,6,14,37,39,51,53,55,""],["group",-26,9,17,19,68,207,211,215,216,218,221,224,234,237,243,245,247,249,252,258,264,266,268,270,272,274,275,"Statement",-34,13,14,32,35,36,42,51,54,55,57,62,70,72,76,80,82,84,85,110,111,120,121,136,139,141,142,143,144,145,147,148,167,169,171,"Expression",-23,31,33,37,41,43,45,173,175,177,178,180,181,182,184,185,186,188,189,190,201,203,205,206,"Type",-3,88,103,109,"ClassItem"],["openedBy",23,"<",38,"InterpolationStart",56,"[",60,"{",73,"(",160,"JSXStartCloseTag"],["closedBy",-2,24,168,">",40,"InterpolationEnd",50,"]",61,"}",74,")",165,"JSXEndTag"]],propSources:[rI],skippedNodes:[0,5,6,278],repeatNodeCount:37,tokenData:"$Fq07[R!bOX%ZXY+gYZ-yZ[+g[]%Z]^.c^p%Zpq+gqr/mrs3cst:_tuEruvJSvwLkwx! Yxy!'iyz!(sz{!)}{|!,q|}!.O}!O!,q!O!P!/Y!P!Q!9j!Q!R#:O!R![#<_![!]#I_!]!^#Jk!^!_#Ku!_!`$![!`!a$$v!a!b$*T!b!c$,r!c!}Er!}#O$-|#O#P$/W#P#Q$4o#Q#R$5y#R#SEr#S#T$7W#T#o$8b#o#p$<r#p#q$=h#q#r$>x#r#s$@U#s$f%Z$f$g+g$g#BYEr#BY#BZ$A`#BZ$ISEr$IS$I_$A`$I_$I|Er$I|$I}$Dk$I}$JO$Dk$JO$JTEr$JT$JU$A`$JU$KVEr$KV$KW$A`$KW&FUEr&F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JU$A`$JU$KVEr$KV$KW$A`$KW&FUEr&FU&FV$A`&FV;'SEr;'S;=`I|<%l?HTEr?HT?HU$A`?HUOEr07[$D|k$i&j(Wp(Z!b'}0/l$]#t(T,2j(e$I[OY%ZYZ&cZr%Zrs&}st%ZtuEruw%Zwx(rx}%Z}!OGv!O!Q%Z!Q![Er![!^%Z!^!_*g!_!c%Z!c!}Er!}#O%Z#O#P&c#P#R%Z#R#SEr#S#T%Z#T#oEr#o#p*g#p$g%Z$g;'SEr;'S;=`I|<%lOEr",tokenizers:[JQ,eI,tI,nI,2,3,4,5,6,7,8,9,10,11,12,13,14,KQ,new QQ("$S~RRtu[#O#Pg#S#T#|~_P#o#pb~gOx~~jVO#i!P#i#j!U#j#l!P#l#m!q#m;'S!P;'S;=`#v<%lO!P~!UO!U~~!XS!Q![!e!c!i!e#T#Z!e#o#p#Z~!hR!Q![!q!c!i!q#T#Z!q~!tR!Q![!}!c!i!}#T#Z!}~#QR!Q![!P!c!i!P#T#Z!P~#^R!Q![#g!c!i#g#T#Z#g~#jS!Q![#g!c!i#g#T#Z#g#q#r!P~#yP;=`<%l!P~$RO(c~~",141,340),new QQ("j~RQYZXz{^~^O(Q~~aP!P!Qd~iO(R~~",25,323)],topRules:{Script:[0,7],SingleExpression:[1,276],SingleClassItem:[2,277]},dialects:{jsx:0,ts:15175},dynamicPrecedences:{80:1,82:1,94:1,169:1,199:1},specialized:[{term:327,get:e=>sI[e]||-1},{term:343,get:e=>aI[e]||-1},{term:95,get:e=>oI[e]||-1}],tokenPrec:15201});class cI{constructor(e,t,i,n){this.state=e,this.pos=t,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=FE(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),n=t.text.slice(i-t.from,this.pos-t.from),r=n.search(fI(e,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return null==this.abortListeners}addEventListener(e,t,i){"abort"==e&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function hI(e){let t=Object.keys(e).join(""),i=/\w/.test(t);return i&&(t=t.replace(/\w/g,"")),`[${i?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function uI(e){let t=e.map(e=>"string"==typeof e?{label:e}:e),[i,n]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:function(e){let t=Object.create(null),i=Object.create(null);for(let{label:r}of e){t[r[0]]=!0;for(let e=1;e<r.length;e++)i[r[e]]=!0}let n=hI(t)+hI(i)+"*$";return[new RegExp("^"+n),new RegExp(n)]}(t);return e=>{let r=e.matchBefore(n);return r||e.explicit?{from:r?r.from:e.pos,options:t,validFor:i}:null}}class dI{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function pI(e){return e.selection.main.from}function fI(e,t){var i;let{source:n}=e,r=t&&"^"!=n[0],s="$"!=n[n.length-1];return r||s?new RegExp(`${r?"^":""}(?:${n})${s?"$":""}`,null!==(i=e.flags)&&void 0!==i?i:e.ignoreCase?"i":""):e}const mI=Hw.define();function gI(e,t,i,n){let{main:r}=e.selection,s=i-r.from,a=n-r.from;return{...e.changeByRange(o=>{if(o!=r&&i!=n&&e.sliceDoc(o.from+s,o.from+a)!=e.sliceDoc(i,n))return{range:o};let l=e.toText(t);return{changes:{from:o.from+s,to:n==r.from?o.to:o.from+a,insert:l},range:ww.cursor(o.from+s+l.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const OI=new WeakMap;function vI(e){if(!Array.isArray(e))return e;let t=OI.get(e);return t||OI.set(e,t=uI(e)),t}const yI=e_.define(),bI=e_.define();class wI{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=ow(e,t),n=cw(i);this.chars.push(i);let r=e.slice(t,t+n),s=r.toUpperCase();this.folded.push(ow(s==r?r.toLowerCase():s,0)),t+=n}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(0==this.pattern.length)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:n,precise:r,byWord:s}=this;if(1==t.length){let n=ow(e,0),r=cw(n),s=r==e.length?0:-100;if(n==t[0]);else{if(n!=i[0])return null;s+=-200}return this.ret(s,[0,r])}let a=e.indexOf(this.pattern);if(0==a)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let o=t.length,l=0;if(a<0){for(let r=0,s=Math.min(e.length,200);r<s&&l<o;){let s=ow(e,r);s!=t[l]&&s!=i[l]||(n[l++]=r),r+=cw(s)}if(l<o)return null}let c=0,h=0,u=!1,d=0,p=-1,f=-1,m=/[a-z]/.test(e),g=!0;for(let O=0,v=Math.min(e.length,200),y=0;O<v&&h<o;){let n=ow(e,O);a<0&&(c<o&&n==t[c]&&(r[c++]=O),d<o&&(n==t[d]||n==i[d]?(0==d&&(p=O),f=O+1,d++):d=0));let l,v=n<255?n>=48&&n<=57||n>=97&&n<=122?2:n>=65&&n<=90?1:0:(l=lw(n))!=l.toLowerCase()?1:l!=l.toUpperCase()?2:0;(!O||1==v&&m||0==y&&0!=v)&&(t[h]==n||i[h]==n&&(u=!0)?s[h++]=O:s.length&&(g=!1)),y=v,O+=cw(n)}return h==o&&0==s[0]&&g?this.result((u?-200:0)-100,s,e):d==o&&0==p?this.ret(-200-e.length+(f==e.length?0:-100),[0,f]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):d==o?this.ret(-900-e.length,[p,f]):h==o?this.result((u?-200:0)-100-700+(g?0:-1100),s,e):2==t.length?null:this.result((n[0]?-700:0)-200-1100,n,e)}result(e,t,i){let n=[],r=0;for(let s of t){let e=s+(this.astral?cw(ow(i,s)):1);r&&n[r-1]==s?n[r-1]=e:(n[r++]=s,n[r++]=e)}return this.ret(e-i.length,n)}}class _I{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return null==i?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const xI=Sw.define({combine:e=>p_(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:kI,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>SI(e(i),t(i)),optionClass:(e,t)=>i=>SI(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})});function SI(e,t){return e?t?e+" "+t:e:t}function kI(e,t,i,n,r,s){let a,o,l=e.textDirection==zx.RTL,c=l,h=!1,u="top",d=t.left-r.left,p=r.right-t.right,f=n.right-n.left,m=n.bottom-n.top;if(c&&d<Math.min(f,p)?c=!1:!c&&p<Math.min(f,d)&&(c=!0),f<=(c?d:p))a=Math.max(r.top,Math.min(i.top,r.bottom-m))-t.top,o=Math.min(400,c?d:p);else{h=!0,o=Math.min(400,(l?t.right:r.right-t.left)-30);let e=r.bottom-t.bottom;e>=m||e>t.top?a=i.bottom-t.top:(u="bottom",a=t.bottom-i.top)}return{style:`${u}: ${a/((t.bottom-t.top)/s.offsetHeight)}px; max-width: ${o/((t.right-t.left)/s.offsetWidth)}px`,class:"cm-completionInfo-"+(h?l?"left-narrow":"right-narrow":c?"left":"right")}}const PI=e_.define();function TI(e,t,i){if(e<=i)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let e=Math.floor(t/i);return{from:e*i,to:(e+1)*i}}let n=Math.floor((e-t)/i);return{from:e-(n+1)*i,to:e-n*i}}class $I{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:e=>this.placeInfo(e),key:this},this.space=null,this.currentClass="";let n=e.state.field(t),{options:r,selected:s}=n.open,a=e.state.facet(xI);this.optionContent=function(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(e){let t=document.createElement("div");return t.classList.add("cm-completionIcon"),e.type&&t.classList.add(...e.type.split(/\s+/g).map(e=>"cm-completionIcon-"+e)),t.setAttribute("aria-hidden","true"),t},position:20}),t.push({render(e,t,i,n){let r=document.createElement("span");r.className="cm-completionLabel";let s=e.displayLabel||e.label,a=0;for(let o=0;o<n.length;){let e=n[o++],t=n[o++];e>a&&r.appendChild(document.createTextNode(s.slice(a,e)));let i=r.appendChild(document.createElement("span"));i.appendChild(document.createTextNode(s.slice(e,t))),i.className="cm-completionMatchedText",a=t}return a<s.length&&r.appendChild(document.createTextNode(s.slice(a))),r},position:50},{render(e){if(!e.detail)return null;let t=document.createElement("span");return t.className="cm-completionDetail",t.textContent=e.detail,t},position:80}),t.sort((e,t)=>e.position-t.position).map(e=>e.render)}(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=TI(r.length,s,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=e.state.field(t).open;for(let t,r=i.target;r&&r!=this.dom;r=r.parentNode)if("LI"==r.nodeName&&(t=/-(\d+)$/.exec(r.id))&&+t[1]<n.length)return this.applyCompletion(e,n[+t[1]]),void i.preventDefault();if(i.target==this.list){let t=this.list.classList.contains("cm-completionListIncompleteTop")&&i.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&i.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;null!=t&&(e.dispatch({effects:PI.of(t)}),i.preventDefault())}}),this.dom.addEventListener("focusout",t=>{let i=e.state.field(this.stateField,!1);i&&i.tooltip&&e.state.facet(xI).closeOnBlur&&t.relatedTarget!=e.contentDOM&&e.dispatch({effects:bI.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=n){let{options:r,selected:s,disabled:a}=i.open;n.open&&n.open.options==r||(this.range=TI(r.length,s,e.state.facet(xI).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),a!=(null===(t=n.open)||void 0===t?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let e of this.currentClass.split(" "))e&&this.dom.classList.remove(e);for(let e of t.split(" "))e&&this.dom.classList.add(e);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=TI(t.options.length,t.selected,this.view.state.facet(xI).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:n}=t.options[t.selected],{info:r}=n;if(!r)return;let s="string"==typeof r?document.createTextNode(r):r(n);if(!s)return;"then"in s?s.then(t=>{t&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(t,n)}).catch(e=>wS(this.view.state,e,"completion info")):(this.addInfoPane(s,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=e.nodeType)i.appendChild(e),this.infoDestroy=null;else{let{dom:t,destroy:n}=e;i.appendChild(t),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby")):n--;return t&&function(e,t){let i=e.getBoundingClientRect(),n=t.getBoundingClientRect(),r=i.height/e.offsetHeight;n.top<i.top?e.scrollTop-=(i.top-n.top)/r:n.bottom>i.bottom&&(e.scrollTop+=(n.bottom-i.bottom)/r)}(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=e.getBoundingClientRect(),r=this.space;if(!r){let e=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:e.clientWidth,bottom:e.clientHeight}}return n.top>Math.min(r.bottom,t.bottom)-10||n.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(xI).positionInfo(this.view,t,n,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const n=document.createElement("ul");n.id=t,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",e=>{e.target==n&&e.preventDefault()});let r=null;for(let s=i.from;s<i.to;s++){let{completion:a,match:o}=e[s],{section:l}=a;if(l){let e="string"==typeof l?l:l.name;if(e!=r&&(s>i.from||0==i.from))if(r=e,"string"!=typeof l&&l.header)n.appendChild(l.header(l));else{n.appendChild(document.createElement("completion-section")).textContent=e}}const c=n.appendChild(document.createElement("li"));c.id=t+"-"+s,c.setAttribute("role","option");let h=this.optionClass(a);h&&(c.className=h);for(let e of this.optionContent){let t=e(a,this.view.state,this.view,o);t&&c.appendChild(t)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function EI(e,t){return i=>new $I(i,e,t)}function AI(e){return 100*(e.boost||0)+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}class CI{constructor(e,t,i,n,r,s){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=s}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new CI(this.options,jI(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,n,r,s){if(n&&!s&&e.some(e=>e.isPending))return n.setDisabled();let a=function(e,t){let i=[],n=null,r=null,s=e=>{i.push(e);let{section:t}=e.completion;if(t){n||(n=[]);let e="string"==typeof t?t:t.name;n.some(t=>t.name==e)||n.push("string"==typeof t?{name:e}:t)}},a=t.facet(xI);for(let h of e)if(h.hasResult()){let e=h.result.getMatch;if(!1===h.result.filter)for(let t of h.result.options)s(new dI(t,h.source,e?e(t):[],1e9-i.length));else{let i,n=t.sliceDoc(h.from,h.to),o=a.filterStrict?new _I(n):new wI(n);for(let t of h.result.options)if(i=o.match(t.label)){let n=t.displayLabel?e?e(t,i.matched):[]:i.matched,a=i.score+(t.boost||0);if(s(new dI(t,h.source,n,a)),"object"==typeof t.section&&"dynamic"===t.section.rank){let{name:e}=t.section;r||(r=Object.create(null)),r[e]=Math.max(a,r[e]||-1e9)}}}}if(n){let e=Object.create(null),t=0,s=(e,t)=>("dynamic"===e.rank&&"dynamic"===t.rank?r[t.name]-r[e.name]:0)||("number"==typeof e.rank?e.rank:1e9)-("number"==typeof t.rank?t.rank:1e9)||(e.name<t.name?-1:1);for(let i of n.sort(s))t-=1e5,e[i.name]=t;for(let n of i){let{section:t}=n.completion;t&&(n.score+=e["string"==typeof t?t:t.name])}}let o=[],l=null,c=a.compareCompletions;for(let h of i.sort((e,t)=>t.score-e.score||c(e.completion,t.completion))){let e=h.completion;!l||l.label!=e.label||l.detail!=e.detail||null!=l.type&&null!=e.type&&l.type!=e.type||l.apply!=e.apply||l.boost!=e.boost?o.push(h):AI(h.completion)>AI(l)&&(o[o.length-1]=h),l=h.completion}return o}(e,t);if(!a.length)return n&&e.some(e=>e.isPending)?n.setDisabled():null;let o=t.facet(xI).selectOnOpen?0:-1;if(n&&n.selected!=o&&-1!=n.selected){let e=n.options[n.selected].completion;for(let t=0;t<a.length;t++)if(a[t].completion==e){o=t;break}}return new CI(a,jI(i,o),{pos:e.reduce((e,t)=>t.hasResult()?Math.min(e,t.from):e,1e8),create:qI,above:r.aboveCursor},n?n.timestamp:Date.now(),o,!1)}map(e){return new CI(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new CI(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class RI{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new RI(MI,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(e){let{state:t}=e,i=t.facet(xI),n=(i.override||t.languageDataAt("autocomplete",pI(t)).map(vI)).map(t=>(this.active.find(e=>e.source==t)||new LI(t,this.active.some(e=>0!=e.state)?1:0)).update(e,i));n.length==this.active.length&&n.every((e,t)=>e==this.active[t])&&(n=this.active);let r=this.open,s=e.effects.some(e=>e.is(DI));r&&e.docChanged&&(r=r.map(e.changes)),e.selection||n.some(t=>t.hasResult()&&e.changes.touchesRange(t.from,t.to))||!function(e,t){if(e==t)return!0;for(let i=0,n=0;;){for(;i<e.length&&!e[i].hasResult();)i++;for(;n<t.length&&!t[n].hasResult();)n++;let r=i==e.length,s=n==t.length;if(r||s)return r==s;if(e[i++].result!=t[n++].result)return!1}}(n,this.active)||s?r=CI.build(n,t,this.id,r,i,s):r&&r.disabled&&!n.some(e=>e.isPending)&&(r=null),!r&&n.every(e=>!e.isPending)&&n.some(e=>e.hasResult())&&(n=n.map(e=>e.hasResult()?new LI(e.source,0):e));for(let a of e.effects)a.is(PI)&&(r=r&&r.setSelected(a.value,this.id));return n==this.active&&r==this.open?this:new RI(n,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?QI:II}}const QI={"aria-autocomplete":"list"},II={};function jI(e,t){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(i["aria-activedescendant"]=e+"-"+t),i}const MI=[];function NI(e,t){if(e.isUserEvent("input.complete")){let i=e.annotation(mI);if(i&&t.activateOnCompletion(i))return 12}let i=e.isUserEvent("input.type");return i&&t.activateOnTyping?5:i?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class LI{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(e,t){let i=NI(e,t),n=this;(8&i||16&i&&this.touches(e))&&(n=new LI(n.source,0)),4&i&&0==n.state&&(n=new LI(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(yI))n=new LI(n.source,1,r.value);else if(r.is(bI))n=new LI(n.source,0);else if(r.is(DI))for(let e of r.value)e.source==n.source&&(n=e);return n}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(pI(e.state))}}class ZI extends LI{constructor(e,t,i,n,r,s){super(e,3,t),this.limit=i,this.result=n,this.from=r,this.to=s}hasResult(){return!0}updateFor(e,t){var i;if(!(3&t))return this.map(e.changes);let n=this.result;n.map&&!e.changes.empty&&(n=n.map(n,e.changes));let r=e.changes.mapPos(this.from),s=e.changes.mapPos(this.to,1),a=pI(e.state);if(a>s||!n||2&t&&(pI(e.startState)==this.from||a<this.limit))return new LI(this.source,4&t?1:0);let o=e.changes.mapPos(this.limit);return function(e,t,i,n){if(!e)return!1;let r=t.sliceDoc(i,n);return"function"==typeof e?e(r,i,n,t):fI(e,!0).test(r)}(n.validFor,e.state,r,s)?new ZI(this.source,this.explicit,o,n,r,s):n.update&&(n=n.update(n,r,s,new cI(e.state,a,!1)))?new ZI(this.source,this.explicit,o,n,n.from,null!==(i=n.to)&&void 0!==i?i:pI(e.state)):new LI(this.source,1,this.explicit)}map(e){if(e.empty)return this;return(this.result.map?this.result.map(this.result,e):this.result)?new ZI(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new LI(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}const DI=e_.define({map:(e,t)=>e.map(e=>e.map(t))}),zI=Cw.define({create:()=>RI.start(),update:(e,t)=>e.update(t),provide:e=>[YT.from(e,e=>e.tooltip),GP.contentAttributes.from(e,e=>e.attrs)]});function UI(e,t){const i=t.completion.apply||t.completion.label;let n=e.state.field(zI).active.find(e=>e.source==t.source);return n instanceof ZI&&("string"==typeof i?e.dispatch({...gI(e.state,i,n.from,n.to),annotations:mI.of(t.completion)}):i(e,t.completion,n.from,n.to),!0)}const qI=EI(zI,UI);function XI(e,t="option"){return i=>{let n=i.state.field(zI,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp<i.state.facet(xI).interactionDelay)return!1;let r,s=1;"page"==t&&(r=i$(i,n.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:a}=n.open.options,o=n.open.selected>-1?n.open.selected+s*(e?1:-1):e?0:a-1;return o<0?o="page"==t?0:a-1:o>=a&&(o="page"==t?a-1:0),i.dispatch({effects:PI.of(o)}),!0}}const BI=e=>!!e.state.field(zI,!1)&&(e.dispatch({effects:yI.of(!0)}),!0);class WI{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const VI=kS.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(zI).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(zI),i=e.state.facet(xI);if(!e.selectionSet&&!e.docChanged&&e.startState.field(zI)==t)return;let n=e.transactions.some(e=>{let t=NI(e,i);return 8&t||(e.selection||e.docChanged)&&!(3&t)});for(let a=0;a<this.running.length;a++){let t=this.running[a];if(n||t.context.abortOnDocChange&&e.docChanged||t.updates.length+e.transactions.length>50&&Date.now()-t.time>1e3){for(let e of t.context.abortListeners)try{e()}catch(s){wS(this.view.state,s)}t.context.abortListeners=null,this.running.splice(a--,1)}else t.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(e=>e.effects.some(e=>e.is(yI)))&&(this.pendingStart=!0);let r=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(e=>e.isPending&&!this.running.some(t=>t.active.source==e.source))?setTimeout(()=>this.startUpdate(),r):-1,0!=this.composing)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:2==this.composing&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(zI);for(let i of t.active)i.isPending&&!this.running.some(e=>e.active.source==i.source)&&this.startQuery(i);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(xI).updateSyncTime))}startQuery(e){let{state:t}=this.view,i=pI(t),n=new cI(t,i,e.explicit,this.view),r=new WI(e,n);this.running.push(r),Promise.resolve(e.source(n)).then(e=>{r.context.aborted||(r.done=e||null,this.scheduleAccept())},e=>{this.view.dispatch({effects:bI.of(null)}),wS(this.view.state,e)})}scheduleAccept(){this.running.every(e=>void 0!==e.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(xI).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],i=this.view.state.facet(xI),n=this.view.state.field(zI);for(let r=0;r<this.running.length;r++){let s=this.running[r];if(void 0===s.done)continue;if(this.running.splice(r--,1),s.done){let n=pI(s.updates.length?s.updates[0].startState:this.view.state),r=Math.min(n,s.done.from+(s.active.explicit?0:1)),a=new ZI(s.active.source,s.active.explicit,r,s.done,s.done.from,null!==(e=s.done.to)&&void 0!==e?e:n);for(let e of s.updates)a=a.update(e,i);if(a.hasResult()){t.push(a);continue}}let a=n.active.find(e=>e.source==s.active.source);if(a&&a.isPending)if(null==s.done){let e=new LI(s.active.source,0);for(let t of s.updates)e=e.update(t,i);e.isPending||t.push(e)}else this.startQuery(a)}(t.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:DI.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(zI,!1);if(t&&t.tooltip&&this.view.state.facet(xI).closeOnBlur){let i=t.open&&i$(this.view,t.open.tooltip);i&&i.dom.contains(e.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:bI.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:yI.of(!1)}),20),this.composing=0}}}),FI="object"==typeof navigator&&/Win/.test(navigator.platform),YI=Nw.highest(GP.domEventHandlers({keydown(e,t){let i=t.state.field(zI,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||e.key.length>1||e.ctrlKey&&(!FI||!e.altKey)||e.metaKey)return!1;let n=i.open.options[i.open.selected],r=i.active.find(e=>e.source==n.source),s=n.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(e.key)>-1&&UI(t,n),!1}})),GI=GP.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class HI{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class KI{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,uw.TrackDel),i=e.mapPos(this.to,1,uw.TrackDel);return null==t||null==i?null:new KI(this.field,t,i)}}class JI{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),s=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let i=s,r=/^\t*/.exec(a)[0].length;for(let t=0;t<r;t++)i+=e.facet(aA);n.push(t+i.length-r),a=i+a.slice(r)}i.push(a),t+=a.length+1}return{text:i,ranges:this.fieldPositions.map(e=>new KI(e.field,n[e.line]+e.from,n[e.line]+e.to))}}static parse(e){let t,i=[],n=[],r=[];for(let s of e.split(/\r\n?|\n/)){for(;t=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(s);){let e=t[1]?+t[1]:null,a=t[2]||t[3]||"",o=-1,l=a.replace(/\\[{}]/g,e=>e[1]);for(let t=0;t<i.length;t++)(null!=e?i[t].seq==e:l&&i[t].name==l)&&(o=t);if(o<0){let t=0;for(;t<i.length&&(null==e||null!=i[t].seq&&i[t].seq<e);)t++;i.splice(t,0,{seq:e,name:l}),o=t;for(let e of r)e.field>=o&&e.field++}for(let i of r)if(i.line==n.length&&i.from>t.index){let e=t[2]?3+(t[1]||"").length:2;i.from-=e,i.to-=e}r.push(new HI(o,n.length,t.index,t.index+l.length)),s=s.slice(0,t.index)+a+s.slice(t.index+t[0].length)}s=s.replace(/\\([{}])/g,(e,t,i)=>{for(let s of r)s.line==n.length&&s.from>i&&(s.from--,s.to--);return t}),n.push(s)}return new JI(n,r)}}let ej=ux.widget({widget:new class extends cx{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),tj=ux.mark({class:"cm-snippetField"});class ij{constructor(e,t){this.ranges=e,this.active=t,this.deco=ux.set(e.map(e=>(e.from==e.to?ej:tj).range(e.from,e.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new ij(t,this.active)}selectionInsideField(e){return e.ranges.every(e=>this.ranges.some(t=>t.field==this.active&&t.from<=e.from&&t.to>=e.to))}}const nj=e_.define({map:(e,t)=>e&&e.map(t)}),rj=e_.define(),sj=Cw.define({create:()=>null,update(e,t){for(let i of t.effects){if(i.is(nj))return i.value;if(i.is(rj)&&e)return new ij(e.ranges,i.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>GP.decorations.from(e,e=>e?e.deco:ux.none)});function aj(e,t){return ww.create(e.filter(e=>e.field==t).map(e=>ww.range(e.from,e.to)))}function oj(e){let t=JI.parse(e);return(e,i,n,r)=>{let{text:s,ranges:a}=t.instantiate(e.state,n),{main:o}=e.state.selection,l={changes:{from:n,to:r==o.from?o.to:r,insert:Gb.of(s)},scrollIntoView:!0,annotations:i?[mI.of(i),t_.userEvent.of("input.complete")]:void 0};if(a.length&&(l.selection=aj(a,0)),a.some(e=>e.field>0)){let t=new ij(a,0),i=l.effects=[nj.of(t)];void 0===e.state.field(sj,!1)&&i.push(e_.appendConfig.of([sj,uj,pj,GI]))}e.dispatch(e.state.update(l))}}function lj(e){return({state:t,dispatch:i})=>{let n=t.field(sj,!1);if(!n||e<0&&0==n.active)return!1;let r=n.active+e,s=e>0&&!n.ranges.some(t=>t.field==r+e);return i(t.update({selection:aj(n.ranges,r),effects:nj.of(s?null:new ij(n.ranges,r)),scrollIntoView:!0})),!0}}const cj=[{key:"Tab",run:lj(1),shift:lj(-1)},{key:"Escape",run:({state:e,dispatch:t})=>!!e.field(sj,!1)&&(t(e.update({effects:nj.of(null)})),!0)}],hj=Sw.define({combine:e=>e.length?e[0]:cj}),uj=Nw.highest(rT.compute([hj],e=>e.facet(hj)));function dj(e,t){return{...t,apply:oj(e)}}const pj=GP.domEventHandlers({mousedown(e,t){let i,n=t.state.field(sj,!1);if(!n||null==(i=t.posAtCoords({x:e.clientX,y:e.clientY})))return!1;let r=n.ranges.find(e=>e.from<=i&&e.to>=i);return!(!r||r.field==n.active)&&(t.dispatch({selection:aj(n.ranges,r.field),effects:nj.of(n.ranges.some(e=>e.field>r.field)?new ij(n.ranges,r.field):null),scrollIntoView:!0}),!0)}}),fj=new class extends f_{};function mj(e={}){return[YI,zI,xI.of(e),VI,Oj,GI]}fj.startSide=1,fj.endSide=-1;const gj=[{key:"Ctrl-Space",run:BI},{mac:"Alt-`",run:BI},{mac:"Alt-i",run:BI},{key:"Escape",run:e=>{let t=e.state.field(zI,!1);return!(!t||!t.active.some(e=>0!=e.state))&&(e.dispatch({effects:bI.of(null)}),!0)}},{key:"ArrowDown",run:XI(!0)},{key:"ArrowUp",run:XI(!1)},{key:"PageDown",run:XI(!0,"page")},{key:"PageUp",run:XI(!1,"page")},{key:"Enter",run:e=>{let t=e.state.field(zI,!1);return!(e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(xI).interactionDelay)&&UI(e,t.open.options[t.open.selected])}}],Oj=Nw.highest(rT.computeN([xI],e=>e.facet(xI).defaultKeymap?[gj]:[])),vj=[dj("function ${name}(${params}) {\n\t${}\n}",{label:"function",detail:"definition",type:"keyword"}),dj("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n\t${}\n}",{label:"for",detail:"loop",type:"keyword"}),dj("for (let ${name} of ${collection}) {\n\t${}\n}",{label:"for",detail:"of loop",type:"keyword"}),dj("do {\n\t${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),dj("while (${}) {\n\t${}\n}",{label:"while",detail:"loop",type:"keyword"}),dj("try {\n\t${}\n} catch (${error}) {\n\t${}\n}",{label:"try",detail:"/ catch block",type:"keyword"}),dj("if (${}) {\n\t${}\n}",{label:"if",detail:"block",type:"keyword"}),dj("if (${}) {\n\t${}\n} else {\n\t${}\n}",{label:"if",detail:"/ else block",type:"keyword"}),dj("class ${name} {\n\tconstructor(${params}) {\n\t\t${}\n\t}\n}",{label:"class",detail:"definition",type:"keyword"}),dj('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),dj('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],yj=vj.concat([dj("interface ${name} {\n\t${}\n}",{label:"interface",detail:"definition",type:"keyword"}),dj("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),dj("enum ${name} {\n\t${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),bj=new uE,wj=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function _j(e){return(t,i)=>{let n=t.node.getChild("VariableDefinition");return n&&i(n,e),!0}}const xj=["FunctionDeclaration"],Sj={FunctionDeclaration:_j("function"),ClassDeclaration:_j("class"),ClassExpression:()=>!0,EnumDeclaration:_j("constant"),TypeAliasDeclaration:_j("type"),NamespaceDeclaration:_j("namespace"),VariableDefinition(e,t){e.matchContext(xj)||t(e,"variable")},TypeDefinition(e,t){t(e,"type")},__proto__:null};function kj(e,t){let i=bj.get(t);if(i)return i;let n=[],r=!0;function s(t,i){let r=e.sliceString(t.from,t.to);n.push({label:r,type:i})}return t.cursor(B$.IncludeAnonymous).iterate(t=>{if(r)r=!1;else if(t.name){let e=Sj[t.name];if(e&&e(t,s)||wj.has(t.name))return!1}else if(t.to-t.from>8192){for(let i of kj(e,t.node))n.push(i);return!1}}),bj.set(t,n),n}const Pj=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Tj=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function $j(e){let t=FE(e.state).resolveInner(e.pos,-1);if(Tj.indexOf(t.name)>-1)return null;let i="VariableName"==t.name||t.to-t.from<20&&Pj.test(e.state.sliceDoc(t.from,t.to));if(!i&&!e.explicit)return null;let n=[];for(let r=t;r;r=r.parent)wj.has(r.name)&&(n=n.concat(kj(e.state.doc,r)));return{options:n,from:i?t.from:e.pos,validFor:Pj}}const Ej=VE.define({name:"javascript",parser:lI.configure({props:[uA.add({IfStatement:yA({except:/^\s*({|else\b)/}),TryStatement:yA({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:e=>e.baseIndent,SwitchBody:e=>{let t=e.textAfter,i=/^\s*\}/.test(t),n=/^\s*(case|default)\b/.test(t);return e.baseIndent+(i?0:n?1:2)*e.unit},Block:OA({closing:"}"}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":yA({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag":e=>e.column(e.node.from)+e.unit}),bA.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":function(e){let t=e.firstChild,i=e.lastChild;return t&&t.to<i.from?{from:t.to,to:i.type.isError?e.to:i.from}:null},BlockComment:e=>({from:e.from+2,to:e.to-2}),JSXElement(e){let t=e.firstChild;if(!t||"JSXSelfClosingTag"==t.name)return null;let i=e.lastChild;return{from:t.to,to:i.type.isError?e.to:i.from}},"JSXSelfClosingTag JSXOpenTag"(e){var t;let i=null===(t=e.firstChild)||void 0===t?void 0:t.nextSibling,n=e.lastChild;return!i||i.type.isError?null:{from:i.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),Aj={test:e=>/^JSX/.test(e.name),facet:qE({commentTokens:{block:{open:"{/*",close:"*/}"}}})},Cj=Ej.configure({dialect:"ts"},"typescript"),Rj=Ej.configure({dialect:"jsx",props:[XE.add(e=>e.isTop?[Aj]:void 0)]}),Qj=Ej.configure({dialect:"jsx ts",props:[XE.add(e=>e.isTop?[Aj]:void 0)]},"typescript");let Ij=e=>({label:e,type:"keyword"});const jj="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(Ij),Mj=jj.concat(["declare","implements","private","protected","public"].map(Ij));function Nj(e={}){let t=e.jsx?e.typescript?Qj:Rj:e.typescript?Cj:Ej,i=e.typescript?yj.concat(Mj):vj.concat(jj);return new rA(t,[Ej.data.of({autocomplete:(n=Tj,r=uI(i),e=>{for(let t=FE(e.state).resolveInner(e.pos,-1);t;t=t.parent){if(n.indexOf(t.name)>-1)return null;if(t.type.isTop)break}return r(e)})}),Ej.data.of({autocomplete:$j}),e.jsx?Dj:[]]);var n,r}function Lj(e,t,i=e.length){for(let n=null==t?void 0:t.firstChild;n;n=n.nextSibling)if("JSXIdentifier"==n.name||"JSXBuiltin"==n.name||"JSXNamespacedName"==n.name||"JSXMemberExpression"==n.name)return e.sliceString(n.from,Math.min(n.to,i));return""}const Zj="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),Dj=GP.inputHandler.of((e,t,i,n,r)=>{if((Zj?e.composing:e.compositionStarted)||e.state.readOnly||t!=i||">"!=n&&"/"!=n||!Ej.isActiveAt(e.state,t,-1))return!1;let s=r(),{state:a}=s,o=a.changeByRange(e=>{var t;let i,{head:r}=e,s=FE(a).resolveInner(r-1,-1);if("JSXStartTag"==s.name&&(s=s.parent),a.doc.sliceString(r-1,r)!=n||"JSXAttributeValue"==s.name&&s.to>r);else{if(">"==n&&"JSXFragmentTag"==s.name)return{range:e,changes:{from:r,insert:"</>"}};if("/"==n&&"JSXStartCloseTag"==s.name){let e=s.parent,n=e.parent;if(n&&e.from==r-2&&((i=Lj(a.doc,n.firstChild,r))||"JSXFragmentTag"==(null===(t=n.firstChild)||void 0===t?void 0:t.name))){let e=`${i}>`;return{range:ww.cursor(r+e.length,-1),changes:{from:r,insert:e}}}}else if(">"==n){let t=function(e){for(;;){if("JSXOpenTag"==e.name||"JSXSelfClosingTag"==e.name||"JSXFragmentTag"==e.name)return e;if("JSXEscape"==e.name||!e.parent)return null;e=e.parent}}(s);if(t&&"JSXOpenTag"==t.name&&!/^\/?>|^<\//.test(a.doc.sliceString(r,r+2))&&(i=Lj(a.doc,t,r)))return{range:e,changes:{from:r,insert:`</${i}>`}}}}return{range:e}});return!o.changes.empty&&(e.dispatch([s,a.update(o,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});class zj{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class Uj{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(Jj).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((e,t)=>e.from-t.from||e.to-t.to),s=new b_,a=[],o=0,l=i.doc.iter(),c=0,h=i.doc.length;for(let d=0;;){let e,t,i=d==r.length?null:r[d];if(!i&&!a.length)break;if(a.length)e=o,t=a.reduce((e,t)=>Math.min(e,t.to),i&&i.from>e?i.from:1e8);else{if(e=i.from,e>h)break;t=i.to,a.push(i),d++}for(;d<r.length;){let i=r[d];if(i.from!=e||!(i.to>i.from||i.to==e)){t=Math.min(i.from,t);break}a.push(i),d++,t=Math.min(i.to,t)}t=Math.min(t,h);let n=!1;if(a.some(i=>i.from==e&&(i.to==t||t==h))&&(n=e==t,!n&&t-e<10)){let i=e-(c+l.value.length);i>0&&(l.next(i),c=e);for(let r=e;;){if(r>=t){n=!0;break}if(!l.lineBreak&&c+l.value.length>r)break;r=c+l.value.length,c+=l.value.length,l.next()}}let u=cM(a);if(n)s.add(e,e,ux.widget({widget:new nM(u),diagnostics:a.slice()}));else{let i=a.reduce((e,t)=>t.markClass?e+" "+t.markClass:e,"");s.add(e,t,ux.mark({class:"cm-lintRange cm-lintRange-"+u+i,diagnostics:a.slice(),inclusiveEnd:a.some(e=>e.to>t)}))}if(o=t,o==h)break;for(let r=0;r<a.length;r++)a[r].to<=o&&a.splice(r--,1)}let u=s.finish();return new Uj(u,t,qj(u))}}function qj(e,t=null,i=0){let n=null;return e.between(i,1e9,(e,i,{spec:r})=>{if(!(t&&r.diagnostics.indexOf(t)<0))if(n){if(r.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new zj(n.from,i,n.diagnostic)}else n=new zj(e,i,t||r.diagnostics[0])}),n}const Xj=e_.define(),Bj=e_.define(),Wj=e_.define(),Vj=Cw.define({create:()=>new Uj(ux.none,null,null),update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),n=null,r=e.panel;if(e.selected){let r=t.changes.mapPos(e.selected.from,1);n=qj(i,e.selected.diagnostic,r)||qj(i,null,r)}!i.size&&r&&t.state.facet(Jj).autoPanel&&(r=null),e=new Uj(i,r,n)}for(let i of t.effects)if(i.is(Xj)){let n=t.state.facet(Jj).autoPanel?i.value.length?sM.open:null:e.panel;e=Uj.init(i.value,n,t.state)}else i.is(Bj)?e=new Uj(e.diagnostics,i.value?sM.open:null,e.selected):i.is(Wj)&&(e=new Uj(e.diagnostics,e.panel,i.value));return e},provide:e=>[c$.from(e,e=>e.panel),GP.decorations.from(e,e=>e.diagnostics)]}),Fj=ux.mark({class:"cm-lintRange cm-lintRange-active"});function Yj(e,t,i){let n,{diagnostics:r}=e.state.field(Vj),s=-1,a=-1;r.between(t-(i<0?1:0),t+(i>0?1:0),(e,r,{spec:o})=>{if(t>=e&&t<=r&&(e==r||(t>e||i>0)&&(t<r||i<0)))return n=o.diagnostics,s=e,a=r,!1});let o=e.state.facet(Jj).tooltipFilter;return n&&o&&(n=o(n,e.state)),n?{pos:s,end:a,above:e.state.doc.lineAt(s).to<a,create:()=>({dom:Gj(e,n)})}:null}function Gj(e,t){return X_("ul",{class:"cm-tooltip-lint"},t.map(t=>iM(e,t,!1)))}const Hj=e=>{let t=e.state.field(Vj,!1);return!(!t||!t.panel)&&(e.dispatch({effects:Bj.of(!1)}),!0)},Kj=[{key:"Mod-Shift-m",run:e=>{let t=e.state.field(Vj,!1);var i,n;t&&t.panel||e.dispatch({effects:(i=e.state,n=[Bj.of(!0)],i.field(Vj,!1)?n:n.concat(e_.appendConfig.of(hM)))});let r=s$(e,sM.open);return r&&r.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:e=>{let t=e.state.field(Vj,!1);if(!t)return!1;let i=e.state.selection.main,n=qj(t.diagnostics,null,i.to+1);return!(!n&&(n=qj(t.diagnostics,null,0),!n||n.from==i.from&&n.to==i.to))&&(e.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)}}],Jj=Sw.define({combine:e=>({sources:e.map(e=>e.source).filter(e=>null!=e),...p_(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:eM,tooltipFilter:eM,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})})});function eM(e,t){return e?t?(i,n)=>t(e(i,n),n):e:t}function tM(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let n=i[e];if(/[a-zA-Z]/.test(n)&&!t.some(e=>e.toLowerCase()==n.toLowerCase())){t.push(n);continue e}}t.push("")}return t}function iM(e,t,i){var n;let r=i?tM(t.actions):[];return X_("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},X_("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),null===(n=t.actions)||void 0===n?void 0:n.map((i,n)=>{let s=!1,a=n=>{if(n.preventDefault(),s)return;s=!0;let r=qj(e.state.field(Vj).diagnostics,t);r&&i.apply(e,r.from,r.to)},{name:o}=i,l=r[n]?o.indexOf(r[n]):-1,c=l<0?o:[o.slice(0,l),X_("u",o.slice(l,l+1)),o.slice(l+1)];return X_("button",{type:"button",class:"cm-diagnosticAction"+(i.markClass?" "+i.markClass:""),onclick:a,onmousedown:a,"aria-label":` Action: ${o}${l<0?"":` (access key "${r[n]})"`}.`},c)}),t.source&&X_("div",{class:"cm-diagnosticSource"},t.source))}class nM extends cx{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return X_("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class rM{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=iM(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class sM{constructor(e){this.view=e,this.items=[];this.list=X_("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(27==t.keyCode)Hj(this.view),this.view.focus();else if(38==t.keyCode||33==t.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==t.keyCode||34==t.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==t.keyCode)this.moveSelection(0);else if(35==t.keyCode)this.moveSelection(this.items.length-1);else if(13==t.keyCode)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=tM(i.actions);for(let r=0;r<n.length;r++)if(n[r].toUpperCase().charCodeAt(0)==t.keyCode){let t=qj(this.view.state.field(Vj).diagnostics,i);t&&i.actions[r].apply(e,t.from,t.to)}}}t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=X_("div",{class:"cm-panel-lint"},this.list,X_("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Hj(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Vj).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Vj),i=0,n=!1,r=null,s=new Set;for(e.between(0,this.view.state.doc.length,(e,a,{spec:o})=>{for(let l of o.diagnostics){if(s.has(l))continue;s.add(l);let e,a=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==l){a=t;break}a<0?(e=new rM(this.view,l),this.items.splice(i,0,e),n=!0):(e=this.items[a],a>i&&(this.items.splice(i,a-i),n=!0)),t&&e.diagnostic==t.diagnostic?e.dom.hasAttribute("aria-selected")||(e.dom.setAttribute("aria-selected","true"),r=e):e.dom.hasAttribute("aria-selected")&&e.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();0==this.items.length&&(this.items.push(new rM(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let i=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/i:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=qj(this.view.state.field(Vj).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:Wj.of(t)})}static open(e){return new sM(e)}}function aM(e){return function(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const oM=GP.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:aM("#d11")},".cm-lintRange-warning":{backgroundImage:aM("orange")},".cm-lintRange-info":{backgroundImage:aM("#999")},".cm-lintRange-hint":{backgroundImage:aM("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function lM(e){return"error"==e?4:"warning"==e?3:"info"==e?2:1}function cM(e){let t="hint",i=1;for(let n of e){let e=lM(n.severity);e>i&&(i=e,t=n.severity)}return t}const hM=[Vj,GP.decorations.compute([Vj],e=>{let{selected:t,panel:i}=e.field(Vj);return t&&i&&t.from!=t.to?ux.set([Fj.range(t.from,t.to)]):ux.none}),t$(Yj,{hideOn:function(e,t){let i=t.pos,n=t.end||i,r=e.state.facet(Jj).hideOn(e,i,n);if(null!=r)return r;let s=e.startState.doc.lineAt(t.pos);return!(!e.effects.some(e=>e.is(Xj))&&!e.changes.touchesRange(s.from,Math.max(s.to,n)))}}),oM];var uM,dM={exports:{}};var pM,fM,mM,gM=(uM||(uM=1,pM=dM,mM=-1,(fM=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32}).Diff=function(e,t){return[e,t]},fM.prototype.diff_main=function(e,t,i,n){void 0===n&&(n=this.Diff_Timeout<=0?Number.MAX_VALUE:(new Date).getTime()+1e3*this.Diff_Timeout);var r=n;if(null==e||null==t)throw new Error("Null input. (diff_main)");if(e==t)return e?[new fM.Diff(0,e)]:[];void 0===i&&(i=!0);var s=i,a=this.diff_commonPrefix(e,t),o=e.substring(0,a);e=e.substring(a),t=t.substring(a),a=this.diff_commonSuffix(e,t);var l=e.substring(e.length-a);e=e.substring(0,e.length-a),t=t.substring(0,t.length-a);var c=this.diff_compute_(e,t,s,r);return o&&c.unshift(new fM.Diff(0,o)),l&&c.push(new fM.Diff(0,l)),this.diff_cleanupMerge(c),c},fM.prototype.diff_compute_=function(e,t,i,n){var r;if(!e)return[new fM.Diff(1,t)];if(!t)return[new fM.Diff(mM,e)];var s=e.length>t.length?e:t,a=e.length>t.length?t:e,o=s.indexOf(a);if(-1!=o)return r=[new fM.Diff(1,s.substring(0,o)),new fM.Diff(0,a),new fM.Diff(1,s.substring(o+a.length))],e.length>t.length&&(r[0][0]=r[2][0]=mM),r;if(1==a.length)return[new fM.Diff(mM,e),new fM.Diff(1,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],h=l[1],u=l[2],d=l[3],p=l[4],f=this.diff_main(c,u,i,n),m=this.diff_main(h,d,i,n);return f.concat([new fM.Diff(0,p)],m)}return i&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)},fM.prototype.diff_lineMode_=function(e,t,i){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var r=n.lineArray,s=this.diff_main(e,t,!1,i);this.diff_charsToLines_(s,r),this.diff_cleanupSemantic(s),s.push(new fM.Diff(0,""));for(var a=0,o=0,l=0,c="",h="";a<s.length;){switch(s[a][0]){case 1:l++,h+=s[a][1];break;case mM:o++,c+=s[a][1];break;case 0:if(o>=1&&l>=1){s.splice(a-o-l,o+l),a=a-o-l;for(var u=this.diff_main(c,h,!1,i),d=u.length-1;d>=0;d--)s.splice(a,0,u[d]);a+=u.length}l=0,o=0,c="",h=""}a++}return s.pop(),s},fM.prototype.diff_bisect_=function(e,t,i){for(var n=e.length,r=t.length,s=Math.ceil((n+r)/2),a=s,o=2*s,l=new Array(o),c=new Array(o),h=0;h<o;h++)l[h]=-1,c[h]=-1;l[a+1]=0,c[a+1]=0;for(var u=n-r,d=u%2!=0,p=0,f=0,m=0,g=0,O=0;O<s&&!((new Date).getTime()>i);O++){for(var v=-O+p;v<=O-f;v+=2){for(var y=a+v,b=(k=v==-O||v!=O&&l[y-1]<l[y+1]?l[y+1]:l[y-1]+1)-v;k<n&&b<r&&e.charAt(k)==t.charAt(b);)k++,b++;if(l[y]=k,k>n)f+=2;else if(b>r)p+=2;else if(d&&(x=a+u-v)>=0&&x<o&&-1!=c[x]&&k>=(_=n-c[x]))return this.diff_bisectSplit_(e,t,k,b,i)}for(var w=-O+m;w<=O-g;w+=2){for(var _,x=a+w,S=(_=w==-O||w!=O&&c[x-1]<c[x+1]?c[x+1]:c[x-1]+1)-w;_<n&&S<r&&e.charAt(n-_-1)==t.charAt(r-S-1);)_++,S++;if(c[x]=_,_>n)g+=2;else if(S>r)m+=2;else if(!d){var k;if((y=a+u-w)>=0&&y<o&&-1!=l[y]&&(b=a+(k=l[y])-y,k>=(_=n-_)))return this.diff_bisectSplit_(e,t,k,b,i)}}}return[new fM.Diff(mM,e),new fM.Diff(1,t)]},fM.prototype.diff_bisectSplit_=function(e,t,i,n,r){var s=e.substring(0,i),a=t.substring(0,n),o=e.substring(i),l=t.substring(n),c=this.diff_main(s,a,!1,r),h=this.diff_main(o,l,!1,r);return c.concat(h)},fM.prototype.diff_linesToChars_=function(e,t){var i=[],n={};function r(e){for(var t="",r=0,a=-1,o=i.length;a<e.length-1;){-1==(a=e.indexOf("\n",r))&&(a=e.length-1);var l=e.substring(r,a+1);(n.hasOwnProperty?n.hasOwnProperty(l):void 0!==n[l])?t+=String.fromCharCode(n[l]):(o==s&&(l=e.substring(r),a=e.length),t+=String.fromCharCode(o),n[l]=o,i[o++]=l),r=a+1}return t}i[0]="";var s=4e4,a=r(e);return s=65535,{chars1:a,chars2:r(t),lineArray:i}},fM.prototype.diff_charsToLines_=function(e,t){for(var i=0;i<e.length;i++){for(var n=e[i][1],r=[],s=0;s<n.length;s++)r[s]=t[n.charCodeAt(s)];e[i][1]=r.join("")}},fM.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var i=0,n=Math.min(e.length,t.length),r=n,s=0;i<r;)e.substring(s,r)==t.substring(s,r)?s=i=r:n=r,r=Math.floor((n-i)/2+i);return r},fM.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var i=0,n=Math.min(e.length,t.length),r=n,s=0;i<r;)e.substring(e.length-r,e.length-s)==t.substring(t.length-r,t.length-s)?s=i=r:n=r,r=Math.floor((n-i)/2+i);return r},fM.prototype.diff_commonOverlap_=function(e,t){var i=e.length,n=t.length;if(0==i||0==n)return 0;i>n?e=e.substring(i-n):i<n&&(t=t.substring(0,i));var r=Math.min(i,n);if(e==t)return r;for(var s=0,a=1;;){var o=e.substring(r-a),l=t.indexOf(o);if(-1==l)return s;a+=l,0!=l&&e.substring(r-a)!=t.substring(0,a)||(s=a,a++)}},fM.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var i=e.length>t.length?e:t,n=e.length>t.length?t:e;if(i.length<4||2*n.length<i.length)return null;var r=this;function s(e,t,i){for(var n,s,a,o,l=e.substring(i,i+Math.floor(e.length/4)),c=-1,h="";-1!=(c=t.indexOf(l,c+1));){var u=r.diff_commonPrefix(e.substring(i),t.substring(c)),d=r.diff_commonSuffix(e.substring(0,i),t.substring(0,c));h.length<d+u&&(h=t.substring(c-d,c)+t.substring(c,c+u),n=e.substring(0,i-d),s=e.substring(i+u),a=t.substring(0,c-d),o=t.substring(c+u))}return 2*h.length>=e.length?[n,s,a,o,h]:null}var a,o,l,c,h,u=s(i,n,Math.ceil(i.length/4)),d=s(i,n,Math.ceil(i.length/2));return u||d?(a=d?u&&u[4].length>d[4].length?u:d:u,e.length>t.length?(o=a[0],l=a[1],c=a[2],h=a[3]):(c=a[0],h=a[1],o=a[2],l=a[3]),[o,l,c,h,a[4]]):null},fM.prototype.diff_cleanupSemantic=function(e){for(var t=!1,i=[],n=0,r=null,s=0,a=0,o=0,l=0,c=0;s<e.length;)0==e[s][0]?(i[n++]=s,a=l,o=c,l=0,c=0,r=e[s][1]):(1==e[s][0]?l+=e[s][1].length:c+=e[s][1].length,r&&r.length<=Math.max(a,o)&&r.length<=Math.max(l,c)&&(e.splice(i[n-1],0,new fM.Diff(mM,r)),e[i[n-1]+1][0]=1,n--,s=--n>0?i[n-1]:-1,a=0,o=0,l=0,c=0,r=null,t=!0)),s++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),s=1;s<e.length;){if(e[s-1][0]==mM&&1==e[s][0]){var h=e[s-1][1],u=e[s][1],d=this.diff_commonOverlap_(h,u),p=this.diff_commonOverlap_(u,h);d>=p?(d>=h.length/2||d>=u.length/2)&&(e.splice(s,0,new fM.Diff(0,u.substring(0,d))),e[s-1][1]=h.substring(0,h.length-d),e[s+1][1]=u.substring(d),s++):(p>=h.length/2||p>=u.length/2)&&(e.splice(s,0,new fM.Diff(0,h.substring(0,p))),e[s-1][0]=1,e[s-1][1]=u.substring(0,u.length-p),e[s+1][0]=mM,e[s+1][1]=h.substring(p),s++),s++}s++}},fM.prototype.diff_cleanupSemanticLossless=function(e){function t(e,t){if(!e||!t)return 6;var i=e.charAt(e.length-1),n=t.charAt(0),r=i.match(fM.nonAlphaNumericRegex_),s=n.match(fM.nonAlphaNumericRegex_),a=r&&i.match(fM.whitespaceRegex_),o=s&&n.match(fM.whitespaceRegex_),l=a&&i.match(fM.linebreakRegex_),c=o&&n.match(fM.linebreakRegex_),h=l&&e.match(fM.blanklineEndRegex_),u=c&&t.match(fM.blanklineStartRegex_);return h||u?5:l||c?4:r&&!a&&o?3:a||o?2:r||s?1:0}for(var i=1;i<e.length-1;){if(0==e[i-1][0]&&0==e[i+1][0]){var n=e[i-1][1],r=e[i][1],s=e[i+1][1],a=this.diff_commonSuffix(n,r);if(a){var o=r.substring(r.length-a);n=n.substring(0,n.length-a),r=o+r.substring(0,r.length-a),s=o+s}for(var l=n,c=r,h=s,u=t(n,r)+t(r,s);r.charAt(0)===s.charAt(0);){n+=r.charAt(0),r=r.substring(1)+s.charAt(0),s=s.substring(1);var d=t(n,r)+t(r,s);d>=u&&(u=d,l=n,c=r,h=s)}e[i-1][1]!=l&&(l?e[i-1][1]=l:(e.splice(i-1,1),i--),e[i][1]=c,h?e[i+1][1]=h:(e.splice(i+1,1),i--))}i++}},fM.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,fM.whitespaceRegex_=/\s/,fM.linebreakRegex_=/[\r\n]/,fM.blanklineEndRegex_=/\n\r?\n$/,fM.blanklineStartRegex_=/^\r?\n\r?\n/,fM.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,i=[],n=0,r=null,s=0,a=!1,o=!1,l=!1,c=!1;s<e.length;)0==e[s][0]?(e[s][1].length<this.Diff_EditCost&&(l||c)?(i[n++]=s,a=l,o=c,r=e[s][1]):(n=0,r=null),l=c=!1):(e[s][0]==mM?c=!0:l=!0,r&&(a&&o&&l&&c||r.length<this.Diff_EditCost/2&&a+o+l+c==3)&&(e.splice(i[n-1],0,new fM.Diff(mM,r)),e[i[n-1]+1][0]=1,n--,r=null,a&&o?(l=c=!0,n=0):(s=--n>0?i[n-1]:-1,l=c=!1),t=!0)),s++;t&&this.diff_cleanupMerge(e)},fM.prototype.diff_cleanupMerge=function(e){e.push(new fM.Diff(0,""));for(var t,i=0,n=0,r=0,s="",a="";i<e.length;)switch(e[i][0]){case 1:r++,a+=e[i][1],i++;break;case mM:n++,s+=e[i][1],i++;break;case 0:n+r>1?(0!==n&&0!==r&&(0!==(t=this.diff_commonPrefix(a,s))&&(i-n-r>0&&0==e[i-n-r-1][0]?e[i-n-r-1][1]+=a.substring(0,t):(e.splice(0,0,new fM.Diff(0,a.substring(0,t))),i++),a=a.substring(t),s=s.substring(t)),0!==(t=this.diff_commonSuffix(a,s))&&(e[i][1]=a.substring(a.length-t)+e[i][1],a=a.substring(0,a.length-t),s=s.substring(0,s.length-t))),i-=n+r,e.splice(i,n+r),s.length&&(e.splice(i,0,new fM.Diff(mM,s)),i++),a.length&&(e.splice(i,0,new fM.Diff(1,a)),i++),i++):0!==i&&0==e[i-1][0]?(e[i-1][1]+=e[i][1],e.splice(i,1)):i++,r=0,n=0,s="",a=""}""===e[e.length-1][1]&&e.pop();var o=!1;for(i=1;i<e.length-1;)0==e[i-1][0]&&0==e[i+1][0]&&(e[i][1].substring(e[i][1].length-e[i-1][1].length)==e[i-1][1]?(e[i][1]=e[i-1][1]+e[i][1].substring(0,e[i][1].length-e[i-1][1].length),e[i+1][1]=e[i-1][1]+e[i+1][1],e.splice(i-1,1),o=!0):e[i][1].substring(0,e[i+1][1].length)==e[i+1][1]&&(e[i-1][1]+=e[i+1][1],e[i][1]=e[i][1].substring(e[i+1][1].length)+e[i+1][1],e.splice(i+1,1),o=!0)),i++;o&&this.diff_cleanupMerge(e)},fM.prototype.diff_xIndex=function(e,t){var i,n=0,r=0,s=0,a=0;for(i=0;i<e.length&&(1!==e[i][0]&&(n+=e[i][1].length),e[i][0]!==mM&&(r+=e[i][1].length),!(n>t));i++)s=n,a=r;return e.length!=i&&e[i][0]===mM?a:a+(t-s)},fM.prototype.diff_prettyHtml=function(e){for(var t=[],i=/&/g,n=/</g,r=/>/g,s=/\n/g,a=0;a<e.length;a++){var o=e[a][0],l=e[a][1].replace(i,"&").replace(n,"<").replace(r,">").replace(s,"¶<br>");switch(o){case 1:t[a]='<ins style="background:#e6ffe6;">'+l+"</ins>";break;case mM:t[a]='<del style="background:#ffe6e6;">'+l+"</del>";break;case 0:t[a]="<span>"+l+"</span>"}}return t.join("")},fM.prototype.diff_text1=function(e){for(var t=[],i=0;i<e.length;i++)1!==e[i][0]&&(t[i]=e[i][1]);return t.join("")},fM.prototype.diff_text2=function(e){for(var t=[],i=0;i<e.length;i++)e[i][0]!==mM&&(t[i]=e[i][1]);return t.join("")},fM.prototype.diff_levenshtein=function(e){for(var t=0,i=0,n=0,r=0;r<e.length;r++){var s=e[r][0],a=e[r][1];switch(s){case 1:i+=a.length;break;case mM:n+=a.length;break;case 0:t+=Math.max(i,n),i=0,n=0}}return t+=Math.max(i,n)},fM.prototype.diff_toDelta=function(e){for(var t=[],i=0;i<e.length;i++)switch(e[i][0]){case 1:t[i]="+"+encodeURI(e[i][1]);break;case mM:t[i]="-"+e[i][1].length;break;case 0:t[i]="="+e[i][1].length}return t.join("\t").replace(/%20/g," ")},fM.prototype.diff_fromDelta=function(e,t){for(var i=[],n=0,r=0,s=t.split(/\t/g),a=0;a<s.length;a++){var o=s[a].substring(1);switch(s[a].charAt(0)){case"+":try{i[n++]=new fM.Diff(1,decodeURI(o))}catch(h){throw new Error("Illegal escape in diff_fromDelta: "+o)}break;case"-":case"=":var l=parseInt(o,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+o);var c=e.substring(r,r+=l);"="==s[a].charAt(0)?i[n++]=new fM.Diff(0,c):i[n++]=new fM.Diff(mM,c);break;default:if(s[a])throw new Error("Invalid diff operation in diff_fromDelta: "+s[a])}}if(r!=e.length)throw new Error("Delta length ("+r+") does not equal source text length ("+e.length+").");return i},fM.prototype.match_main=function(e,t,i){if(null==e||null==t||null==i)throw new Error("Null input. (match_main)");return i=Math.max(0,Math.min(i,e.length)),e==t?0:e.length?e.substring(i,i+t.length)==t?i:this.match_bitap_(e,t,i):-1},fM.prototype.match_bitap_=function(e,t,i){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),r=this;function s(e,n){var s=e/t.length,a=Math.abs(i-n);return r.Match_Distance?s+a/r.Match_Distance:a?1:s}var a=this.Match_Threshold,o=e.indexOf(t,i);-1!=o&&(a=Math.min(s(0,o),a),-1!=(o=e.lastIndexOf(t,i+t.length))&&(a=Math.min(s(0,o),a)));var l,c,h=1<<t.length-1;o=-1;for(var u,d=t.length+e.length,p=0;p<t.length;p++){for(l=0,c=d;l<c;)s(p,i+c)<=a?l=c:d=c,c=Math.floor((d-l)/2+l);d=c;var f=Math.max(1,i-c+1),m=Math.min(i+c,e.length)+t.length,g=Array(m+2);g[m+1]=(1<<p)-1;for(var O=m;O>=f;O--){var v=n[e.charAt(O-1)];if(g[O]=0===p?(g[O+1]<<1|1)&v:(g[O+1]<<1|1)&v|(u[O+1]|u[O])<<1|1|u[O+1],g[O]&h){var y=s(p,O-1);if(y<=a){if(a=y,!((o=O-1)>i))break;f=Math.max(1,2*i-o)}}}if(s(p+1,i)>a)break;u=g}return o},fM.prototype.match_alphabet_=function(e){for(var t={},i=0;i<e.length;i++)t[e.charAt(i)]=0;for(i=0;i<e.length;i++)t[e.charAt(i)]|=1<<e.length-i-1;return t},fM.prototype.patch_addContext_=function(e,t){if(0!=t.length){if(null===e.start2)throw Error("patch not initialized");for(var i=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(i)!=t.lastIndexOf(i)&&i.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,i=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var r=t.substring(e.start2-n,e.start2);r&&e.diffs.unshift(new fM.Diff(0,r));var s=t.substring(e.start2+e.length1,e.start2+e.length1+n);s&&e.diffs.push(new fM.Diff(0,s)),e.start1-=r.length,e.start2-=r.length,e.length1+=r.length+s.length,e.length2+=r.length+s.length}},fM.prototype.patch_make=function(e,t,i){var n,r;if("string"==typeof e&&"string"==typeof t&&void 0===i)n=e,(r=this.diff_main(n,t,!0)).length>2&&(this.diff_cleanupSemantic(r),this.diff_cleanupEfficiency(r));else if(e&&"object"==typeof e&&void 0===t&&void 0===i)r=e,n=this.diff_text1(r);else if("string"==typeof e&&t&&"object"==typeof t&&void 0===i)n=e,r=t;else{if("string"!=typeof e||"string"!=typeof t||!i||"object"!=typeof i)throw new Error("Unknown call format to patch_make.");n=e,r=i}if(0===r.length)return[];for(var s=[],a=new fM.patch_obj,o=0,l=0,c=0,h=n,u=n,d=0;d<r.length;d++){var p=r[d][0],f=r[d][1];switch(o||0===p||(a.start1=l,a.start2=c),p){case 1:a.diffs[o++]=r[d],a.length2+=f.length,u=u.substring(0,c)+f+u.substring(c);break;case mM:a.length1+=f.length,a.diffs[o++]=r[d],u=u.substring(0,c)+u.substring(c+f.length);break;case 0:f.length<=2*this.Patch_Margin&&o&&r.length!=d+1?(a.diffs[o++]=r[d],a.length1+=f.length,a.length2+=f.length):f.length>=2*this.Patch_Margin&&o&&(this.patch_addContext_(a,h),s.push(a),a=new fM.patch_obj,o=0,h=u,l=c)}1!==p&&(l+=f.length),p!==mM&&(c+=f.length)}return o&&(this.patch_addContext_(a,h),s.push(a)),s},fM.prototype.patch_deepCopy=function(e){for(var t=[],i=0;i<e.length;i++){var n=e[i],r=new fM.patch_obj;r.diffs=[];for(var s=0;s<n.diffs.length;s++)r.diffs[s]=new fM.Diff(n.diffs[s][0],n.diffs[s][1]);r.start1=n.start1,r.start2=n.start2,r.length1=n.length1,r.length2=n.length2,t[i]=r}return t},fM.prototype.patch_apply=function(e,t){if(0==e.length)return[t,[]];e=this.patch_deepCopy(e);var i=this.patch_addPadding(e);t=i+t+i,this.patch_splitMax(e);for(var n=0,r=[],s=0;s<e.length;s++){var a,o,l=e[s].start2+n,c=this.diff_text1(e[s].diffs),h=-1;if(c.length>this.Match_MaxBits?-1!=(a=this.match_main(t,c.substring(0,this.Match_MaxBits),l))&&(-1==(h=this.match_main(t,c.substring(c.length-this.Match_MaxBits),l+c.length-this.Match_MaxBits))||a>=h)&&(a=-1):a=this.match_main(t,c,l),-1==a)r[s]=!1,n-=e[s].length2-e[s].length1;else if(r[s]=!0,n=a-l,c==(o=-1==h?t.substring(a,a+c.length):t.substring(a,h+this.Match_MaxBits)))t=t.substring(0,a)+this.diff_text2(e[s].diffs)+t.substring(a+c.length);else{var u=this.diff_main(c,o,!1);if(c.length>this.Match_MaxBits&&this.diff_levenshtein(u)/c.length>this.Patch_DeleteThreshold)r[s]=!1;else{this.diff_cleanupSemanticLossless(u);for(var d,p=0,f=0;f<e[s].diffs.length;f++){var m=e[s].diffs[f];0!==m[0]&&(d=this.diff_xIndex(u,p)),1===m[0]?t=t.substring(0,a+d)+m[1]+t.substring(a+d):m[0]===mM&&(t=t.substring(0,a+d)+t.substring(a+this.diff_xIndex(u,p+m[1].length))),m[0]!==mM&&(p+=m[1].length)}}}}return[t=t.substring(i.length,t.length-i.length),r]},fM.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,i="",n=1;n<=t;n++)i+=String.fromCharCode(n);for(n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var r=e[0],s=r.diffs;if(0==s.length||0!=s[0][0])s.unshift(new fM.Diff(0,i)),r.start1-=t,r.start2-=t,r.length1+=t,r.length2+=t;else if(t>s[0][1].length){var a=t-s[0][1].length;s[0][1]=i.substring(s[0][1].length)+s[0][1],r.start1-=a,r.start2-=a,r.length1+=a,r.length2+=a}return 0==(s=(r=e[e.length-1]).diffs).length||0!=s[s.length-1][0]?(s.push(new fM.Diff(0,i)),r.length1+=t,r.length2+=t):t>s[s.length-1][1].length&&(a=t-s[s.length-1][1].length,s[s.length-1][1]+=i.substring(0,a),r.length1+=a,r.length2+=a),i},fM.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,i=0;i<e.length;i++)if(!(e[i].length1<=t)){var n=e[i];e.splice(i--,1);for(var r=n.start1,s=n.start2,a="";0!==n.diffs.length;){var o=new fM.patch_obj,l=!0;for(o.start1=r-a.length,o.start2=s-a.length,""!==a&&(o.length1=o.length2=a.length,o.diffs.push(new fM.Diff(0,a)));0!==n.diffs.length&&o.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],h=n.diffs[0][1];1===c?(o.length2+=h.length,s+=h.length,o.diffs.push(n.diffs.shift()),l=!1):c===mM&&1==o.diffs.length&&0==o.diffs[0][0]&&h.length>2*t?(o.length1+=h.length,r+=h.length,l=!1,o.diffs.push(new fM.Diff(c,h)),n.diffs.shift()):(h=h.substring(0,t-o.length1-this.Patch_Margin),o.length1+=h.length,r+=h.length,0===c?(o.length2+=h.length,s+=h.length):l=!1,o.diffs.push(new fM.Diff(c,h)),h==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(h.length))}a=(a=this.diff_text2(o.diffs)).substring(a.length-this.Patch_Margin);var u=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);""!==u&&(o.length1+=u.length,o.length2+=u.length,0!==o.diffs.length&&0===o.diffs[o.diffs.length-1][0]?o.diffs[o.diffs.length-1][1]+=u:o.diffs.push(new fM.Diff(0,u))),l||e.splice(++i,0,o)}}},fM.prototype.patch_toText=function(e){for(var t=[],i=0;i<e.length;i++)t[i]=e[i];return t.join("")},fM.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var i=e.split("\n"),n=0,r=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<i.length;){var s=i[n].match(r);if(!s)throw new Error("Invalid patch string: "+i[n]);var a=new fM.patch_obj;for(t.push(a),a.start1=parseInt(s[1],10),""===s[2]?(a.start1--,a.length1=1):"0"==s[2]?a.length1=0:(a.start1--,a.length1=parseInt(s[2],10)),a.start2=parseInt(s[3],10),""===s[4]?(a.start2--,a.length2=1):"0"==s[4]?a.length2=0:(a.start2--,a.length2=parseInt(s[4],10)),n++;n<i.length;){var o=i[n].charAt(0);try{var l=decodeURI(i[n].substring(1))}catch(c){throw new Error("Illegal escape in patch_fromText: "+l)}if("-"==o)a.diffs.push(new fM.Diff(mM,l));else if("+"==o)a.diffs.push(new fM.Diff(1,l));else if(" "==o)a.diffs.push(new fM.Diff(0,l));else{if("@"==o)break;if(""!==o)throw new Error('Invalid patch mode "'+o+'" in: '+l)}n++}}return t},(fM.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0}).prototype.toString=function(){for(var e,t=["@@ -"+(0===this.length1?this.start1+",0":1==this.length1?this.start1+1:this.start1+1+","+this.length1)+" +"+(0===this.length2?this.start2+",0":1==this.length2?this.start2+1:this.start2+1+","+this.length2)+" @@\n"],i=0;i<this.diffs.length;i++){switch(this.diffs[i][0]){case 1:e="+";break;case mM:e="-";break;case 0:e=" "}t[i+1]=e+encodeURI(this.diffs[i][1])+"\n"}return t.join("").replace(/%20/g," ")},pM.exports=fM,pM.exports.diff_match_patch=fM,pM.exports.DIFF_DELETE=mM,pM.exports.DIFF_INSERT=1,pM.exports.DIFF_EQUAL=0),dM.exports);const OM=e_.define(),vM=e_.define(),yM=e_.define(),bM=e_.define(),wM=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(OM))return i.value;return e},provide:e=>GP.decorations.from(e)}),_M=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(vM))return i.value;return e},provide:e=>GP.decorations.from(e)}),xM=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(yM))return i.value;return e},provide:e=>GP.decorations.from(e)}),SM=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(bM))return i.value;return e},provide:e=>GP.decorations.from(e)});class kM extends cx{constructor(e,t,i,n,r){super(),this.isAsisButton=e,this.textToApply=t,this.targetEditorView=i,this.diffRange=n,this.hostComponent=r}eq(e){return!1}toDOM(e){const t=document.createElement("button");this.isAsisButton?t.className="cm-merge-button revert":t.className="cm-merge-button accept",t.addEventListener("click",()=>{this.applyChanges(this.textToApply,this.targetEditorView,this.diffRange)});const i=document.createElement("div");return i.className="cm-merge-button-container",i.appendChild(t),i}applyChanges(e,t,i){t&&i&&(t.dispatch({changes:{from:i.from,to:i.to,insert:e}}),requestAnimationFrame(()=>{this.hostComponent.recalculateDiff()}))}}class PM extends HTMLElement{constructor(){super(),ge(this,W),ge(this,V),ge(this,F),ge(this,Y),ge(this,G,new Zw),ge(this,H,!1),pe(this,"_asisScrollHandler",null),pe(this,"_tobeScrollHandler",null),pe(this,"getContents",()=>me(this,V)?me(this,V).state.doc.toString():""),ge(this,K,()=>{if(Oe(this,F,this.shadowRoot.querySelector(".panel.asis")),Oe(this,Y,this.shadowRoot.querySelector(".panel.tobe")),!me(this,F)||!me(this,Y))return;const e=[C$(),IT(),cC(),vT(),[kT,PT],d_.allowMultipleSelections.of(!0),d_.transactionFilter.of(e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let i=e.newDoc,{head:n}=e.newSelection.main,r=i.lineAt(n);if(n>r.from+200)return e;let s=i.sliceString(r.from,n);if(!t.some(e=>e.test(s)))return e;let{state:a}=e,o=-1,l=[];for(let{head:c}of a.selection.ranges){let e=a.doc.lineAt(c);if(e.from==o)continue;o=e.from;let t=cA(a,e.from);if(null==t)continue;let i=/^\s*/.exec(e.text)[0],n=lA(a,t);i!=n&&l.push({from:e.from,to:e.from+i.length,insert:n})}return l.length?[e,{changes:l,sequential:!0}]:e}),NA(),ZT,I$,[zR,DR],rT.of([...SR,...gQ,...PC,...Kj,...gj,kR,oR]),kA($A),mj()];Oe(this,W,new GP({state:d_.create({doc:"",extensions:[e,me(this,G).of(Nj()),d_.readOnly.of(!1),wM,xM,GP.updateListener.of(e=>{e.view.contentDOM.firstChild&&!e.view._initialAsisContentLoaded&&(e.view._initialAsisContentLoaded=!0)})]}),parent:me(this,F)})),Oe(this,V,new GP({state:d_.create({doc:"",extensions:[e,me(this,G).of(Nj()),d_.readOnly.of(!0),_M,SM,GP.updateListener.of(e=>{e.view.contentDOM.firstChild&&!e.view._initialTobeContentLoaded&&(e.view._initialTobeContentLoaded=!0)})]}),parent:me(this,Y)})),me(this,J).call(this)}),ge(this,J,()=>{this._asisScrollHandler&&(me(this,W).scrollDOM.removeEventListener("scroll",this._asisScrollHandler),me(this,V).scrollDOM.removeEventListener("scroll",this._tobeScrollHandler));let e=!1,t=!1;this._asisScrollHandler=()=>{me(this,H)&&(t||(e=!0,me(this,V).scrollDOM.scrollTop=me(this,W).scrollDOM.scrollTop,me(this,V).scrollDOM.scrollLeft=me(this,W).scrollDOM.scrollLeft),t=!1)},this._tobeScrollHandler=()=>{me(this,H)&&(e||(t=!0,me(this,W).scrollDOM.scrollTop=me(this,V).scrollDOM.scrollTop,me(this,W).scrollDOM.scrollLeft=me(this,V).scrollDOM.scrollLeft),e=!1)},me(this,W).scrollDOM.addEventListener("scroll",this._asisScrollHandler),me(this,V).scrollDOM.addEventListener("scroll",this._tobeScrollHandler)}),ge(this,ee,(e,t)=>{const i=new gM.diff_match_patch,n=i.diff_linesToChars_(e,t),r=n.chars1,s=n.chars2,a=n.lineArray,o=i.diff_main(r,s,!0);i.diff_cleanupSemantic(o),i.diff_charsToLines_(o,a);const l=new b_,c=new b_,h=new b_,u=new b_;let d=0,p=0;const f=ux.line({class:"cm-inserted-line-bg"}),m=ux.line({class:"cm-deleted-line-bg"}),g=this;for(const[O,v]of o){const e=v.length,t=d,i=p;switch(O){case gM.diff_match_patch.DIFF_INSERT:const n=v.split("\n");for(let e=0;e<n.length;e++)e===n.length-1&&""===n[e]&&v.endsWith("\n")||c.add(p,p,f),p+=n[e].length+(e<n.length-1?1:0);u.add(i,i,ux.widget({widget:new kM(!1,v,me(g,W),{from:t,to:t+0},g),side:1}));break;case gM.diff_match_patch.DIFF_DELETE:const r=v.split("\n");for(let e=0;e<r.length;e++)e===r.length-1&&""===r[e]&&v.endsWith("\n")||l.add(d,d,m),d+=r[e].length+(e<r.length-1?1:0);h.add(t,t,ux.widget({widget:new kM(!0,"",me(g,W),{from:t,to:t+v.length},g),side:1}));break;case gM.diff_match_patch.DIFF_EQUAL:d+=e,p+=e}}return{asisDecorations:l.finish(),tobeDecorations:c.finish(),asisButtonDecorations:h.finish(),tobeButtonDecorations:u.finish()}}),pe(this,"recalculateDiff",()=>{const e=me(this,W).state.doc.toString(),t=me(this,V).state.doc.toString(),{asisDecorations:i,tobeDecorations:n,asisButtonDecorations:r,tobeButtonDecorations:s}=me(this,ee).call(this,e,t);me(this,W).dispatch({effects:[OM.of(i),yM.of(r)]}),me(this,V).dispatch({effects:[vM.of(n),bM.of(s)]})}),pe(this,"initialize",(e,t,i="javascript")=>{if(!me(this,W)||!me(this,V))return;let n;Oe(this,H,!1),n=Nj(),me(this,W).dispatch({changes:{from:0,to:me(this,W).state.doc.length,insert:e},effects:[me(this,G).reconfigure(n)]}),me(this,V).dispatch({changes:{from:0,to:me(this,V).state.doc.length,insert:t},effects:[me(this,G).reconfigure(n)]}),requestAnimationFrame(()=>{const{asisDecorations:i,tobeDecorations:n,asisButtonDecorations:r,tobeButtonDecorations:s}=me(this,ee).call(this,e,t);me(this,W).dispatch({effects:[OM.of(i),yM.of(r)]}),me(this,V).dispatch({effects:[vM.of(n),bM.of(s)]}),requestAnimationFrame(()=>{Oe(this,H,!0)})})}),this.attachShadow({mode:"open"})}get asisEditorView(){return me(this,W)}get tobeEditorView(){return me(this,V)}connectedCallback(){this.shadowRoot.innerHTML=`\n <style>\n /* ninegrid CSS 및 필요한 기본 스타일 임포트 */\n @import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideDiff.css";\n /* 새로 만든 ideDiff.css 파일 임포트 */\n ${t.getCustomPath(this,"ideDiff.css")}\n </style>\n\n <div class="wrapper">\n <div class="panel asis"></div>\n <nx-splitter></nx-splitter>\n <div class="panel tobe"></div>\n </div>\n `,requestAnimationFrame(()=>{me(this,K).call(this)})}disconnectedCallback(){this._asisScrollHandler&&(me(this,W).scrollDOM.removeEventListener("scroll",this._asisScrollHandler),me(this,V).scrollDOM.removeEventListener("scroll",this._tobeScrollHandler),this._asisScrollHandler=null,this._tobeScrollHandler=null),me(this,W)&&me(this,W).destroy(),me(this,V)&&me(this,V).destroy()}}W=new WeakMap,V=new WeakMap,F=new WeakMap,Y=new WeakMap,G=new WeakMap,H=new WeakMap,K=new WeakMap,J=new WeakMap,ee=new WeakMap,customElements.define("ide-diff",PM);class TM extends HTMLElement{constructor(){super(),ge(this,te),ge(this,ie),ge(this,ne),ge(this,re),ge(this,se),pe(this,"initialize",e=>{Oe(this,re,e.selectFunc),Oe(this,te,e.apiKey),Oe(this,ie,e.xmlPath),Oe(this,ne,e.queryId)}),ge(this,ae,async e=>{if("Enter"===e.key&&!e.isComposing&&me(this,re)){if(me(this,se).disabled=!0,t.loading.show(),me(this,se).value){const e=await gb.generateWhereCause(me(this,ie),me(this,ne),me(this,se).value,me(this,te));!0===e.result?me(this,re).call(this,{_whereClause:e.condition}):(t.loading.hide(),t.alert(e.condition,null,{class:"rgb",animation:"shake"}))}else me(this,re).call(this,{});me(this,se).disabled=!1}}),ge(this,oe,()=>{const e=this.getAttribute("placeholder")||"자연어 검색어를 입력하세요 (ex: 작성자가 홍길동인 데이타를 찾아줘)";this.innerHTML=`\n\t\t\t<input type="text" placeholder="${e}" style="width: 100%;" />\n\t\t`,Oe(this,se,this.querySelector("input")),me(this,se).addEventListener("keydown",me(this,ae))})}connectedCallback(){me(this,oe).call(this)}set selectFunc(e){Oe(this,re,e)}}te=new WeakMap,ie=new WeakMap,ne=new WeakMap,re=new WeakMap,se=new WeakMap,ae=new WeakMap,oe=new WeakMap,customElements.define("ai-natual-input",TM),e.IdeAssi=Ib,e.ai=gb,e.api=Iu,e.default=Ib,e.defineCustomElements=function(){customElements.get("nine-ai")||customElements.define("nine-ai",Ib)},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
236
|
+
*/var zd="object"==typeof window?window:{},Ud="0123456789abcdef".split(""),qd=[-2147483648,8388608,32768,128],Xd=[24,16,8,0],Bd=[];function Wd(e){e?(Bd[0]=Bd[16]=Bd[1]=Bd[2]=Bd[3]=Bd[4]=Bd[5]=Bd[6]=Bd[7]=Bd[8]=Bd[9]=Bd[10]=Bd[11]=Bd[12]=Bd[13]=Bd[14]=Bd[15]=0,this.blocks=Bd):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=1732584193,this.h1=4023233417,this.h2=2562383102,this.h3=271733878,this.h4=3285377520,this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}Wd.prototype.update=function(e){if(!this.finalized){var t="string"!=typeof e;t&&e.constructor===zd.ArrayBuffer&&(e=new Uint8Array(e));for(var i,n,r=0,s=e.length||0,a=this.blocks;r<s;){if(this.hashed&&(this.hashed=!1,a[0]=this.block,a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),t)for(n=this.start;r<s&&n<64;++r)a[n>>2]|=e[r]<<Xd[3&n++];else for(n=this.start;r<s&&n<64;++r)(i=e.charCodeAt(r))<128?a[n>>2]|=i<<Xd[3&n++]:i<2048?(a[n>>2]|=(192|i>>6)<<Xd[3&n++],a[n>>2]|=(128|63&i)<<Xd[3&n++]):i<55296||i>=57344?(a[n>>2]|=(224|i>>12)<<Xd[3&n++],a[n>>2]|=(128|i>>6&63)<<Xd[3&n++],a[n>>2]|=(128|63&i)<<Xd[3&n++]):(i=65536+((1023&i)<<10|1023&e.charCodeAt(++r)),a[n>>2]|=(240|i>>18)<<Xd[3&n++],a[n>>2]|=(128|i>>12&63)<<Xd[3&n++],a[n>>2]|=(128|i>>6&63)<<Xd[3&n++],a[n>>2]|=(128|63&i)<<Xd[3&n++]);this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.block=a[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this}},Wd.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>2]|=qd[3&t],this.block=e[16],t>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},Wd.prototype.hash=function(){var e,t,i=this.h0,n=this.h1,r=this.h2,s=this.h3,a=this.h4,o=this.blocks;for(e=16;e<80;++e)t=o[e-3]^o[e-8]^o[e-14]^o[e-16],o[e]=t<<1|t>>>31;for(e=0;e<20;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n&r|~n&s)+a+1518500249+o[e]|0)<<5|a>>>27)+(i&(n=n<<30|n>>>2)|~i&r)+s+1518500249+o[e+1]|0)<<5|s>>>27)+(a&(i=i<<30|i>>>2)|~a&n)+r+1518500249+o[e+2]|0)<<5|r>>>27)+(s&(a=a<<30|a>>>2)|~s&i)+n+1518500249+o[e+3]|0)<<5|n>>>27)+(r&(s=s<<30|s>>>2)|~r&a)+i+1518500249+o[e+4]|0,r=r<<30|r>>>2;for(;e<40;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n^r^s)+a+1859775393+o[e]|0)<<5|a>>>27)+(i^(n=n<<30|n>>>2)^r)+s+1859775393+o[e+1]|0)<<5|s>>>27)+(a^(i=i<<30|i>>>2)^n)+r+1859775393+o[e+2]|0)<<5|r>>>27)+(s^(a=a<<30|a>>>2)^i)+n+1859775393+o[e+3]|0)<<5|n>>>27)+(r^(s=s<<30|s>>>2)^a)+i+1859775393+o[e+4]|0,r=r<<30|r>>>2;for(;e<60;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n&r|n&s|r&s)+a-1894007588+o[e]|0)<<5|a>>>27)+(i&(n=n<<30|n>>>2)|i&r|n&r)+s-1894007588+o[e+1]|0)<<5|s>>>27)+(a&(i=i<<30|i>>>2)|a&n|i&n)+r-1894007588+o[e+2]|0)<<5|r>>>27)+(s&(a=a<<30|a>>>2)|s&i|a&i)+n-1894007588+o[e+3]|0)<<5|n>>>27)+(r&(s=s<<30|s>>>2)|r&a|s&a)+i-1894007588+o[e+4]|0,r=r<<30|r>>>2;for(;e<80;e+=5)i=(t=(n=(t=(r=(t=(s=(t=(a=(t=i<<5|i>>>27)+(n^r^s)+a-899497514+o[e]|0)<<5|a>>>27)+(i^(n=n<<30|n>>>2)^r)+s-899497514+o[e+1]|0)<<5|s>>>27)+(a^(i=i<<30|i>>>2)^n)+r-899497514+o[e+2]|0)<<5|r>>>27)+(s^(a=a<<30|a>>>2)^i)+n-899497514+o[e+3]|0)<<5|n>>>27)+(r^(s=s<<30|s>>>2)^a)+i-899497514+o[e+4]|0,r=r<<30|r>>>2;this.h0=this.h0+i|0,this.h1=this.h1+n|0,this.h2=this.h2+r|0,this.h3=this.h3+s|0,this.h4=this.h4+a|0},Wd.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,i=this.h2,n=this.h3,r=this.h4;return Ud[e>>28&15]+Ud[e>>24&15]+Ud[e>>20&15]+Ud[e>>16&15]+Ud[e>>12&15]+Ud[e>>8&15]+Ud[e>>4&15]+Ud[15&e]+Ud[t>>28&15]+Ud[t>>24&15]+Ud[t>>20&15]+Ud[t>>16&15]+Ud[t>>12&15]+Ud[t>>8&15]+Ud[t>>4&15]+Ud[15&t]+Ud[i>>28&15]+Ud[i>>24&15]+Ud[i>>20&15]+Ud[i>>16&15]+Ud[i>>12&15]+Ud[i>>8&15]+Ud[i>>4&15]+Ud[15&i]+Ud[n>>28&15]+Ud[n>>24&15]+Ud[n>>20&15]+Ud[n>>16&15]+Ud[n>>12&15]+Ud[n>>8&15]+Ud[n>>4&15]+Ud[15&n]+Ud[r>>28&15]+Ud[r>>24&15]+Ud[r>>20&15]+Ud[r>>16&15]+Ud[r>>12&15]+Ud[r>>8&15]+Ud[r>>4&15]+Ud[15&r]},Wd.prototype.toString=Wd.prototype.hex,Wd.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,i=this.h2,n=this.h3,r=this.h4;return[e>>24&255,e>>16&255,e>>8&255,255&e,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24&255,i>>16&255,i>>8&255,255&i,n>>24&255,n>>16&255,n>>8&255,255&n,r>>24&255,r>>16&255,r>>8&255,255&r]},Wd.prototype.array=Wd.prototype.digest,Wd.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(20),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),e};let Vd=!1;const Fd=(...e)=>{return t=e.join("_"),Vd||(Vd=!0),new Wd(!0).update(t).hex();var t};class Yd{constructor(){Object.defineProperty(this,"keyEncoder",{enumerable:!0,configurable:!0,writable:!0,value:Fd})}makeDefaultKeyEncoder(e){this.keyEncoder=e}}const Gd=new Map;class Hd extends Yd{constructor(e){super(),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cache=e??new Map}lookup(e,t){return Promise.resolve(this.cache.get(this.keyEncoder(e,t))??null)}async update(e,t,i){this.cache.set(this.keyEncoder(e,t),i)}static global(){return new Hd(Gd)}}var Kd,Jd={};const ep=Gt(function(){if(Kd)return Jd;Kd=1,Jd.byteLength=function(e){var t=s(e),i=t[0],n=t[1];return 3*(i+n)/4-n},Jd.toByteArray=function(e){var n,r,a=s(e),o=a[0],l=a[1],c=new i(function(e,t,i){return 3*(t+i)/4-i}(0,o,l)),h=0,u=l>0?o-4:o;for(r=0;r<u;r+=4)n=t[e.charCodeAt(r)]<<18|t[e.charCodeAt(r+1)]<<12|t[e.charCodeAt(r+2)]<<6|t[e.charCodeAt(r+3)],c[h++]=n>>16&255,c[h++]=n>>8&255,c[h++]=255&n;2===l&&(n=t[e.charCodeAt(r)]<<2|t[e.charCodeAt(r+1)]>>4,c[h++]=255&n);1===l&&(n=t[e.charCodeAt(r)]<<10|t[e.charCodeAt(r+1)]<<4|t[e.charCodeAt(r+2)]>>2,c[h++]=n>>8&255,c[h++]=255&n);return c},Jd.fromByteArray=function(t){for(var i,n=t.length,r=n%3,s=[],a=16383,l=0,c=n-r;l<c;l+=a)s.push(o(t,l,l+a>c?c:l+a));1===r?(i=t[n-1],s.push(e[i>>2]+e[i<<4&63]+"==")):2===r&&(i=(t[n-2]<<8)+t[n-1],s.push(e[i>>10]+e[i>>4&63]+e[i<<2&63]+"="));return s.join("")};for(var e=[],t=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=0;r<64;++r)e[r]=n[r],t[n.charCodeAt(r)]=r;function s(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function a(t){return e[t>>18&63]+e[t>>12&63]+e[t>>6&63]+e[63&t]}function o(e,t,i){for(var n,r=[],s=t;s<i;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(255&e[s+2]),r.push(a(n));return r.join("")}return t["-".charCodeAt(0)]=62,t["_".charCodeAt(0)]=63,Jd}());var tp=Object.defineProperty;function ip(e,t){return 1===e.length?[t.get(e.join(","))]:function(e,t){let i=Array.from({length:e.length},(e,t)=>({start:t,end:t+1}));for(;i.length>1;){let n=null;for(let r=0;r<i.length-1;r++){const s=e.slice(i[r].start,i[r+1].end),a=t.get(s.join(","));null!=a&&(null==n||a<n[0])&&(n=[a,r])}if(null==n)break;{const e=n[1];i[e]={start:i[e].start,end:i[e+1].end},i.splice(e+1,1)}}return i}(e,t).map(i=>t.get(e.slice(i.start,i.end).join(","))).filter(e=>null!=e)}var np=class{constructor(e,t){pe(this,"specialTokens"),pe(this,"inverseSpecialTokens"),pe(this,"patStr"),pe(this,"textEncoder",new TextEncoder),pe(this,"textDecoder",new TextDecoder("utf-8")),pe(this,"rankMap",new Map),pe(this,"textMap",new Map),this.patStr=e.pat_str;const i=e.bpe_ranks.split("\n").filter(Boolean).reduce((e,t)=>{const[i,n,...r]=t.split(" "),s=Number.parseInt(n,10);return r.forEach((t,i)=>e[t]=s+i),e},{});for(const[n,r]of Object.entries(i)){const e=ep.toByteArray(n);this.rankMap.set(e.join(","),r),this.textMap.set(r,e)}this.specialTokens={...e.special_tokens,...t},this.inverseSpecialTokens=Object.entries(this.specialTokens).reduce((e,[t,i])=>(e[i]=this.textEncoder.encode(t),e),{})}encode(e,t=[],i="all"){const n=new RegExp(this.patStr,"ug"),r=np.specialTokenRegex(Object.keys(this.specialTokens)),s=[],a=new Set("all"===t?Object.keys(this.specialTokens):t),o=new Set("all"===i?Object.keys(this.specialTokens).filter(e=>!a.has(e)):i);if(o.size>0){const t=np.specialTokenRegex([...o]),i=e.match(t);if(null!=i)throw new Error(`The text contains a special token that is not allowed: ${i[0]}`)}let l=0;for(;;){let t=null,i=l;for(;r.lastIndex=i,t=r.exec(e),null!=t&&!a.has(t[0]);)i=t.index+1;const o=(null==t?void 0:t.index)??e.length;for(const r of e.substring(l,o).matchAll(n)){const e=this.textEncoder.encode(r[0]),t=this.rankMap.get(e.join(","));null==t?s.push(...ip(e,this.rankMap)):s.push(t)}if(null==t)break;let c=this.specialTokens[t[0]];s.push(c),l=t.index+t[0].length}return s}decode(e){const t=[];let i=0;for(let s=0;s<e.length;++s){const n=e[s],r=this.textMap.get(n)??this.inverseSpecialTokens[n];null!=r&&(t.push(r),i+=r.length)}const n=new Uint8Array(i);let r=0;for(const s of t)n.set(s,r),r+=s.length;return this.textDecoder.decode(n)}},rp=np;((e,t,i)=>{t in e?tp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(rp,"specialTokenRegex"+"",e=>new RegExp(e.map(e=>e.replace(/[\\^$*+?.()|[\]{}]/g,"\\$&")).join("|"),"g"));const sp={},ap=new Yl({});async function op(e){return async function(e){return e in sp||(sp[e]=ap.fetch(`https://tiktoken.pages.dev/js/${e}.json`).then(e=>e.json()).then(e=>new rp(e)).catch(t=>{throw delete sp[e],t})),await sp[e]}(function(e){switch(e){case"gpt2":return"gpt2";case"code-cushman-001":case"code-cushman-002":case"code-davinci-001":case"code-davinci-002":case"cushman-codex":case"davinci-codex":case"davinci-002":case"text-davinci-002":case"text-davinci-003":return"p50k_base";case"code-davinci-edit-001":case"text-davinci-edit-001":return"p50k_edit";case"ada":case"babbage":case"babbage-002":case"code-search-ada-code-001":case"code-search-babbage-code-001":case"curie":case"davinci":case"text-ada-001":case"text-babbage-001":case"text-curie-001":case"text-davinci-001":case"text-search-ada-doc-001":case"text-search-babbage-doc-001":case"text-search-curie-doc-001":case"text-search-davinci-doc-001":case"text-similarity-ada-001":case"text-similarity-babbage-001":case"text-similarity-curie-001":case"text-similarity-davinci-001":return"r50k_base";case"gpt-3.5-turbo-instruct-0914":case"gpt-3.5-turbo-instruct":case"gpt-3.5-turbo-16k-0613":case"gpt-3.5-turbo-16k":case"gpt-3.5-turbo-0613":case"gpt-3.5-turbo-0301":case"gpt-3.5-turbo":case"gpt-4-32k-0613":case"gpt-4-32k-0314":case"gpt-4-32k":case"gpt-4-0613":case"gpt-4-0314":case"gpt-4":case"gpt-3.5-turbo-1106":case"gpt-35-turbo":case"gpt-4-1106-preview":case"gpt-4-vision-preview":case"gpt-3.5-turbo-0125":case"gpt-4-turbo":case"gpt-4-turbo-2024-04-09":case"gpt-4-turbo-preview":case"gpt-4-0125-preview":case"text-embedding-ada-002":case"text-embedding-3-small":case"text-embedding-3-large":return"cl100k_base";case"gpt-4o":case"gpt-4o-2024-05-13":case"gpt-4o-2024-08-06":case"gpt-4o-2024-11-20":case"gpt-4o-mini-2024-07-18":case"gpt-4o-mini":case"gpt-4o-search-preview":case"gpt-4o-search-preview-2025-03-11":case"gpt-4o-mini-search-preview":case"gpt-4o-mini-search-preview-2025-03-11":case"gpt-4o-audio-preview":case"gpt-4o-audio-preview-2024-12-17":case"gpt-4o-audio-preview-2024-10-01":case"gpt-4o-mini-audio-preview":case"gpt-4o-mini-audio-preview-2024-12-17":case"o1":case"o1-2024-12-17":case"o1-mini":case"o1-mini-2024-09-12":case"o1-preview":case"o1-preview-2024-09-12":case"o1-pro":case"o1-pro-2025-03-19":case"o3":case"o3-2025-04-16":case"o3-mini":case"o3-mini-2025-01-31":case"o4-mini":case"o4-mini-2025-04-16":case"chatgpt-4o-latest":case"gpt-4o-realtime":case"gpt-4o-realtime-preview-2024-10-01":case"gpt-4o-realtime-preview-2024-12-17":case"gpt-4o-mini-realtime-preview":case"gpt-4o-mini-realtime-preview-2024-12-17":case"gpt-4.1":case"gpt-4.1-2025-04-14":case"gpt-4.1-mini":case"gpt-4.1-mini-2025-04-14":case"gpt-4.1-nano":case"gpt-4.1-nano-2025-04-14":case"gpt-4.5-preview":case"gpt-4.5-preview-2025-02-27":case"gpt-5":case"gpt-5-2025-08-07":case"gpt-5-nano":case"gpt-5-nano-2025-08-07":case"gpt-5-mini":case"gpt-5-mini-2025-08-07":case"gpt-5-chat-latest":return"o200k_base";default:throw new Error("Unknown model")}}(e))}function lp(e){return!("object"!=typeof e||!e)&&!!("type"in e&&"function"===e.type&&"function"in e&&"object"==typeof e.function&&e.function&&"name"in e.function&&"parameters"in e.function)}class cp extends Lh{get lc_attributes(){return{callbacks:void 0,verbose:void 0}}constructor(e){super(e),Object.defineProperty(this,"verbose",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"callbacks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tags",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metadata",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.verbose=e.verbose??!1,this.callbacks=e.callbacks,this.tags=e.tags??[],this.metadata=e.metadata??{}}}class hp extends cp{get callKeys(){return["stop","timeout","signal","tags","metadata","callbacks"]}constructor({callbacks:e,callbackManager:t,...i}){const{cache:n,...r}=i;super({callbacks:e??t,...r}),Object.defineProperty(this,"caller",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_encoding",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cache="object"==typeof n?n:n?Hd.global():void 0,this.caller=new Yl(i??{})}async getNumTokens(e){let t;t="string"==typeof e?e:e.map(e=>"string"==typeof e?e:"text"===e.type&&"text"in e?e.text:"").join("");let i=Math.ceil(t.length/4);if(!this._encoding)try{this._encoding=await op("modelName"in this?(n=this.modelName,n.startsWith("gpt-3.5-turbo-16k")?"gpt-3.5-turbo-16k":n.startsWith("gpt-3.5-turbo-")?"gpt-3.5-turbo":n.startsWith("gpt-4-32k")?"gpt-4-32k":n.startsWith("gpt-4-")?"gpt-4":n.startsWith("gpt-4o")?"gpt-4o":n):"gpt2")}catch(r){}var n;if(this._encoding)try{i=this._encoding.encode(t).length}catch(r){}return i}static _convertInputToPromptValue(e){return"string"==typeof e?new Jh(e):Array.isArray(e)?new eu(e.map(el)):e}_identifyingParams(){return{}}_getSerializedCacheKeyParametersForCall({config:e,...t}){const i={...this._identifyingParams(),...t,_type:this._llmType(),_model:this._modelType()},n=Object.entries(i).filter(([e,t])=>void 0!==t),r=n.map(([e,t])=>`${e}:${JSON.stringify(t)}`).sort().join(",");return r}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}static async deserialize(e){throw new Error("Use .toJSON() instead")}}class up extends Lh{static lc_name(){return"RunnablePassthrough"}constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain_core","runnables"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"func",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),e&&(this.func=e.func)}async invoke(e,t){const i=Tl(t);return this.func&&await this.func(e,i),this._callWithConfig(e=>Promise.resolve(e),e,i)}async*transform(e,t){const i=Tl(t);let n,r=!0;for await(const s of this._transformStreamWithConfig(e,e=>e,i))if(yield s,r)if(void 0===n)n=s;else try{n=Ql(n,s)}catch{n=void 0,r=!1}this.func&&void 0!==n&&await this.func(n,i)}static assign(e){return new Fh(new qh({steps:e}))}}function dp(e){const t=[];for(const i of e){let e=i;if(Array.isArray(i.content))for(let t=0;t<i.content.length;t++){const n=i.content[t];(So(n)||ko(n))&&e===i&&(e=new i.constructor({...e,content:[...i.content.slice(0,t),Po(n),...i.content.slice(t+1)]}))}t.push(e)}return t}class pp extends hp{constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","chat_models",this._llmType()]}),Object.defineProperty(this,"disableStreaming",{enumerable:!0,configurable:!0,writable:!0,value:!1})}_separateRunnableConfigFromCallOptionsCompat(e){const[t,i]=super._separateRunnableConfigFromCallOptions(e);return i.signal=t.signal,[t,i]}async invoke(e,t){const i=pp._convertInputToPromptValue(e);return(await this.generatePrompt([i],t,null==t?void 0:t.callbacks)).generations[0][0].message}async*_streamResponseChunks(e,t,i){throw new Error("Not implemented.")}async*_streamIterator(e,t){var i;if(this._streamResponseChunks===pp.prototype._streamResponseChunks||this.disableStreaming)yield this.invoke(e,t);else{const r=pp._convertInputToPromptValue(e).toChatMessages(),[s,a]=this._separateRunnableConfigFromCallOptionsCompat(t),o={...s.metadata,...this.getLsParams(a)},l=await yl.configure(s.callbacks,this.callbacks,s.tags,this.tags,o,this.metadata,{verbose:this.verbose}),c={options:a,invocation_params:null==this?void 0:this.invocationParams(a),batch_size:1},h=await(null==l?void 0:l.handleChatModelStart(this.toJSON(),[dp(r)],s.runId,void 0,c,void 0,void 0,s.runName));let u,d;try{for await(const e of this._streamResponseChunks(r,a,null==h?void 0:h[0])){if(null==e.message.id){const t=null==(i=null==h?void 0:h.at(0))?void 0:i.runId;null!=t&&e.message._updateId(`run-${t}`)}e.message.response_metadata={...e.generationInfo,...e.message.response_metadata},yield e.message,u=u?u.concat(e):e,Uo(e.message)&&void 0!==e.message.usage_metadata&&(d={tokenUsage:{promptTokens:e.message.usage_metadata.input_tokens,completionTokens:e.message.usage_metadata.output_tokens,totalTokens:e.message.usage_metadata.total_tokens}})}}catch(n){throw await Promise.all((h??[]).map(e=>null==e?void 0:e.handleLLMError(n))),n}await Promise.all((h??[]).map(e=>null==e?void 0:e.handleLLMEnd({generations:[[u]],llmOutput:d})))}}getLsParams(e){const t=this.getName().startsWith("Chat")?this.getName().replace("Chat",""):this.getName();return{ls_model_type:"chat",ls_stop:e.stop,ls_provider:t}}async _generateUncached(e,t,i,n){var r,s;const a=e.map(e=>e.map(el));let o;if(void 0!==n&&n.length===a.length)o=n;else{const e={...i.metadata,...this.getLsParams(t)},n=await yl.configure(i.callbacks,this.callbacks,i.tags,this.tags,e,this.metadata,{verbose:this.verbose}),r={options:t,invocation_params:null==this?void 0:this.invocationParams(t),batch_size:1};o=await(null==n?void 0:n.handleChatModelStart(this.toJSON(),a.map(dp),i.runId,void 0,r,void 0,void 0,i.runName))}const l=[],c=[];if(!!(null==o?void 0:o[0].handlers.find(no))&&!this.disableStreaming&&1===a.length&&this._streamResponseChunks!==pp.prototype._streamResponseChunks)try{const e=await this._streamResponseChunks(a[0],t,null==o?void 0:o[0]);let i,n;for await(const t of e){if(null==t.message.id){const e=null==(r=null==o?void 0:o.at(0))?void 0:r.runId;null!=e&&t.message._updateId(`run-${e}`)}i=void 0===i?t:Ql(i,t),Uo(t.message)&&void 0!==t.message.usage_metadata&&(n={tokenUsage:{promptTokens:t.message.usage_metadata.input_tokens,completionTokens:t.message.usage_metadata.output_tokens,totalTokens:t.message.usage_metadata.total_tokens}})}if(void 0===i)throw new Error("Received empty response from chat model call.");l.push([i]),await(null==o?void 0:o[0].handleLLMEnd({generations:l,llmOutput:n}))}catch(u){throw await(null==o?void 0:o[0].handleLLMError(u)),u}else{const e=await Promise.allSettled(a.map((e,i)=>this._generate(e,{...t,promptIndex:i},null==o?void 0:o[i])));await Promise.all(e.map(async(e,t)=>{var i,n,r;if("fulfilled"===e.status){const r=e.value;for(const e of r.generations){if(null==e.message.id){const t=null==(i=null==o?void 0:o.at(0))?void 0:i.runId;null!=t&&e.message._updateId(`run-${t}`)}e.message.response_metadata={...e.generationInfo,...e.message.response_metadata}}return 1===r.generations.length&&(r.generations[0].message.response_metadata={...r.llmOutput,...r.generations[0].message.response_metadata}),l[t]=r.generations,c[t]=r.llmOutput,null==(n=null==o?void 0:o[t])?void 0:n.handleLLMEnd({generations:[r.generations],llmOutput:r.llmOutput})}return await(null==(r=null==o?void 0:o[t])?void 0:r.handleLLMError(e.reason)),Promise.reject(e.reason)}))}const h={generations:l,llmOutput:c.length?null==(s=this._combineLLMOutput)?void 0:s.call(this,...c):void 0};return Object.defineProperty(h,zl,{value:o?{runIds:null==o?void 0:o.map(e=>e.runId)}:void 0,configurable:!0}),h}async _generateCached({messages:e,cache:t,llmStringKey:i,parsedOptions:n,handledOptions:r}){const s=e.map(e=>e.map(el)),a={...r.metadata,...this.getLsParams(n)},o=await yl.configure(r.callbacks,this.callbacks,r.tags,this.tags,a,this.metadata,{verbose:this.verbose}),l={options:n,invocation_params:null==this?void 0:this.invocationParams(n),batch_size:1},c=await(null==o?void 0:o.handleChatModelStart(this.toJSON(),s.map(dp),r.runId,void 0,l,void 0,void 0,r.runName)),h=[],u=(await Promise.allSettled(s.map(async(e,n)=>{const r=pp._convertInputToPromptValue(e).toString(),s=await t.lookup(r,i);return null==s&&h.push(n),s}))).map((e,t)=>({result:e,runManager:null==c?void 0:c[t]})).filter(({result:e})=>"fulfilled"===e.status&&null!=e.value||"rejected"===e.status),d=[];await Promise.all(u.map(async({result:e,runManager:t},i)=>{if("fulfilled"===e.status){const n=e.value;return d[i]=n.map(e=>("message"in e&&Mo(e.message)&&zo(e.message)&&(e.message.usage_metadata={input_tokens:0,output_tokens:0,total_tokens:0}),e.generationInfo={...e.generationInfo,tokenUsage:{}},e)),n.length&&await(null==t?void 0:t.handleLLMNewToken(n[0].text)),null==t?void 0:t.handleLLMEnd({generations:[n]},void 0,void 0,void 0,{cached:!0})}return await(null==t?void 0:t.handleLLMError(e.reason,void 0,void 0,void 0,{cached:!0})),Promise.reject(e.reason)}));const p={generations:d,missingPromptIndices:h,startedRunManagers:c};return Object.defineProperty(p,zl,{value:c?{runIds:null==c?void 0:c.map(e=>e.runId)}:void 0,configurable:!0}),p}async generate(e,t,i){let n;n=Array.isArray(t)?{stop:t}:t;const r=e.map(e=>e.map(el)),[s,a]=this._separateRunnableConfigFromCallOptionsCompat(n);if(s.callbacks=s.callbacks??i,!this.cache)return this._generateUncached(r,a,s);const{cache:o}=this,l=this._getSerializedCacheKeyParametersForCall(a),{generations:c,missingPromptIndices:h,startedRunManagers:u}=await this._generateCached({messages:r,cache:o,llmStringKey:l,parsedOptions:a,handledOptions:s});let d={};if(h.length>0){const e=await this._generateUncached(h.map(e=>r[e]),a,s,void 0!==u?h.map(e=>null==u?void 0:u[e]):void 0);await Promise.all(e.generations.map(async(e,t)=>{const i=h[t];c[i]=e;const n=pp._convertInputToPromptValue(r[i]).toString();return o.update(n,l,e)})),d=e.llmOutput??{}}return{generations:c,llmOutput:d}}invocationParams(e){return{}}_modelType(){return"base_chat_model"}serialize(){return{...this.invocationParams(),_type:this._llmType(),_model:this._modelType()}}async generatePrompt(e,t,i){const n=e.map(e=>e.toChatMessages());return this.generate(n,t,i)}async call(e,t,i){return(await this.generate([e.map(el)],t,i)).generations[0][0].message}async callPrompt(e,t,i){const n=e.toChatMessages();return this.call(n,t,i)}async predictMessages(e,t,i){return this.call(e,t,i)}async predict(e,t,i){const n=new Vo(e),r=await this.call([n],t,i);if("string"!=typeof r.content)throw new Error("Cannot use predict when output is not a string.");return r.content}withStructuredOutput(e,t){if("function"!=typeof this.bindTools)throw new Error('Chat model must implement ".bindTools()" to use withStructuredOutput.');if(null==t?void 0:t.strict)throw new Error('"strict" mode is not supported for this model by default.');const i=e,n=null==t?void 0:t.name,r=_h(i)??"A function available to call.",s=null==t?void 0:t.method,a=null==t?void 0:t.includeRaw;if("jsonMode"===s)throw new Error('Base withStructuredOutput implementation only supports "functionCalling" as a method.');let o,l=n??"extract";yh(i)?o=[{type:"function",function:{name:l,description:r,parameters:Th(i)}}]:("name"in i&&(l=i.name),o=[{type:"function",function:{name:l,description:r,parameters:i}}]);const c=this.bindTools(o),h=Bh.from(e=>{if(!e.tool_calls||0===e.tool_calls.length)throw new Error("No tool calls found in the response.");const t=e.tool_calls.find(e=>e.name===l);if(!t)throw new Error(`No tool call found with name ${l}.`);return t.args});if(!a)return c.pipe(h).withConfig({runName:"StructuredOutput"});const u=up.assign({parsed:(e,t)=>h.invoke(e.raw,t)}),d=up.assign({parsed:()=>null}),p=u.withFallbacks({fallbacks:[d]});return Uh.from([{raw:c},p]).withConfig({runName:"StructuredOutputRunnable"})}}class fp extends Lh{parseResultWithPrompt(e,t,i){return this.parseResult(e,i)}_baseMessageToString(e){return"string"==typeof e.content?e.content:this._baseMessageContentToString(e.content)}_baseMessageContentToString(e){return JSON.stringify(e)}async invoke(e,t){return"string"==typeof e?this._callWithConfig(async(e,t)=>this.parseResult([{text:e}],null==t?void 0:t.callbacks),e,{...t,runType:"parser"}):this._callWithConfig(async(e,t)=>this.parseResult([{message:e,text:this._baseMessageToString(e)}],null==t?void 0:t.callbacks),e,{...t,runType:"parser"})}}class mp extends fp{parseResult(e,t){return this.parse(e[0].text,t)}async parseWithPrompt(e,t,i){return this.parse(e,i)}_type(){throw new Error("_type not implemented")}}class gp extends Error{constructor(e,t,i,n=!1){if(super(e),Object.defineProperty(this,"llmOutput",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"observation",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sendToLLM",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.llmOutput=t,this.observation=i,this.sendToLLM=n,n&&(void 0===i||void 0===t))throw new Error("Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true");vo(this,"OUTPUT_PARSING_FAILURE")}}class Op extends mp{async*_transform(e){for await(const t of e)"string"==typeof t?yield this.parseResult([{text:t}]):yield this.parseResult([{message:t,text:this._baseMessageToString(t)}])}async*transform(e,t){yield*this._transformStreamWithConfig(e,this._transform.bind(this),{...t,runType:"parser"})}}class vp extends Op{constructor(e){super(e),Object.defineProperty(this,"diff",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.diff=(null==e?void 0:e.diff)??this.diff}async*_transform(e){let t,i;for await(const n of e){if("string"!=typeof n&&"string"!=typeof n.content)throw new Error("Cannot handle non-string output.");let e;if(No(n)){if("string"!=typeof n.content)throw new Error("Cannot handle non-string message output.");e=new ql({message:n,text:n.content})}else if(Mo(n)){if("string"!=typeof n.content)throw new Error("Cannot handle non-string message output.");e=new ql({message:il(n),text:n.content})}else e=new Ul({text:n});i=void 0===i?e:i.concat(e);const r=await this.parsePartialResult([i]);null==r||gh(r,t)||(this.diff?yield this._diff(t,r):yield r,t=r)}}getFormatInstructions(){return""}}class yp extends mp{static lc_name(){return"StructuredOutputParser"}toJSON(){return this.toJSONNotImplemented()}constructor(e){super(e),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","output_parsers","structured"]})}static fromZodSchema(e){return new this(e)}static fromNamesAndDescriptions(e){return new this(Yt(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Vt().describe(t)]))))}getFormatInstructions(){return`You must format your output as a JSON value that adheres to a given "JSON Schema" instance.\n\n"JSON Schema" is a declarative language that allows you to annotate and validate JSON documents.\n\nFor example, the example "JSON Schema" instance {{"properties": {{"foo": {{"description": "a list of test words", "type": "array", "items": {{"type": "string"}}}}}}, "required": ["foo"]}}\nwould match an object with one required property, "foo". The "type" property specifies "foo" must be an "array", and the "description" property semantically describes it as "a list of test words". The items within "foo" must be strings.\nThus, the object {{"foo": ["bar", "baz"]}} is a well-formatted instance of this example "JSON Schema". The object {{"properties": {{"foo": ["bar", "baz"]}}}} is not well-formatted.\n\nYour output will be parsed and type-checked according to the provided schema instance, so make sure all fields in your output match the schema exactly and there are no trailing commas!\n\nHere is the JSON Schema instance your output must adhere to. Include the enclosing markdown codeblock:\n\`\`\`json\n${JSON.stringify(Th(this.schema))}\n\`\`\`\n`}async parse(e){var t,i;try{const n=e.trim(),r=((null==(t=n.match(/^```(?:json)?\s*([\s\S]*?)```/))?void 0:t[1])||(null==(i=n.match(/```json\s*([\s\S]*?)```/))?void 0:i[1])||n).replace(/"([^"\\]*(\\.[^"\\]*)*)"/g,(e,t)=>`"${t.replace(/\n/g,"\\n")}"`).replace(/\n/g,"");return await wh(this.schema,JSON.parse(r))}catch(n){throw new gp(`Failed to parse. Text: "${e}". Error: ${n}`,e)}}}class bp extends vp{constructor(){super(...arguments),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain_core","output_parsers"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0})}static lc_name(){return"JsonOutputParser"}_concatOutputChunks(e,t){return this.diff?super._concatOutputChunks(e,t):t}_diff(e,t){if(t)return e?Wi(e,t):[{op:"replace",path:"",value:t}]}async parsePartialResult(e){return wo(e[0].text)}async parse(e){return wo(e,JSON.parse)}getFormatInstructions(){return""}}function wp(e){if("object"==typeof e&&null!==e){const t={...e};"additionalProperties"in t&&delete t.additionalProperties,"$schema"in t&&delete t.$schema,"strict"in t&&delete t.strict;for(const e in t)e in t&&(Array.isArray(t[e])?t[e]=t[e].map(wp):"object"==typeof t[e]&&null!==t[e]&&(t[e]=wp(t[e])));return t}return e}function _p(e){const t=wp(yh(e)?Th(e):e),{$schema:i,...n}=t;return n}function xp(e){const t=wp(e),{$schema:i,...n}=t;return n}function Sp(e){return function(e){return!!e&&"object"==typeof e&&"name"in e&&"schema"in e&&(yh(e.schema)||null!=e.schema&&"object"==typeof e.schema&&"type"in e.schema&&"string"==typeof e.schema.type&&["null","boolean","object","array","number","string"].includes(e.schema.type))}(e)||function(e){return void 0!==e&&Lh.isRunnable(e)&&"lc_name"in e.constructor&&"function"==typeof e.constructor.lc_name&&"RunnableToolLike"===e.constructor.lc_name()}(e)||function(e){return void 0!==e&&Array.isArray(e.lc_namespace)}(e)}function kp(e,t){return{name:e.name,description:e.description,parameters:Th(e.schema)}}const Pp=[];for(let AM=0;AM<256;++AM)Pp.push((AM+256).toString(16).slice(1));let Tp;const $p=new Uint8Array(16);const Ep={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ap(e,t,i){var n;if(Ep.randomUUID&&!e)return Ep.randomUUID();const r=(e=e||{}).random??(null==(n=e.rng)?void 0:n.call(e))??function(){if(!Tp){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Tp=crypto.getRandomValues.bind(crypto)}return Tp($p)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(e,t=0){return(Pp[e[t+0]]+Pp[e[t+1]]+Pp[e[t+2]]+Pp[e[t+3]]+"-"+Pp[e[t+4]]+Pp[e[t+5]]+"-"+Pp[e[t+6]]+Pp[e[t+7]]+"-"+Pp[e[t+8]]+Pp[e[t+9]]+"-"+Pp[e[t+10]]+Pp[e[t+11]]+Pp[e[t+12]]+Pp[e[t+13]]+Pp[e[t+14]]+Pp[e[t+15]]).toLowerCase()}(r)}function Cp(e,t){var i;if(xo(e))return Eo(e,function(e){return{providerName:"Google Gemini",fromStandardTextBlock:e=>({text:e.text}),fromStandardImageBlock(t){if(!e)throw new Error("This model does not support images");if("url"===t.source_type){const e=$o({dataUrl:t.url});return e?{inlineData:{mimeType:e.mime_type,data:e.data}}:{fileData:{mimeType:t.mime_type??"",fileUri:t.url}}}if("base64"===t.source_type)return{inlineData:{mimeType:t.mime_type??"",data:t.data}};throw new Error(`Unsupported source type: ${t.source_type}`)},fromStandardAudioBlock(t){if(!e)throw new Error("This model does not support audio");if("url"===t.source_type){const e=$o({dataUrl:t.url});return e?{inlineData:{mimeType:e.mime_type,data:e.data}}:{fileData:{mimeType:t.mime_type??"",fileUri:t.url}}}if("base64"===t.source_type)return{inlineData:{mimeType:t.mime_type??"",data:t.data}};throw new Error(`Unsupported source type: ${t.source_type}`)},fromStandardFileBlock(t){if(!e)throw new Error("This model does not support files");if("text"===t.source_type)return{text:t.text};if("url"===t.source_type){const e=$o({dataUrl:t.url});return e?{inlineData:{mimeType:e.mime_type,data:e.data}}:{fileData:{mimeType:t.mime_type??"",fileUri:t.url}}}if("base64"===t.source_type)return{inlineData:{mimeType:t.mime_type??"",data:t.data}};throw new Error(`Unsupported source type: ${t.source_type}`)}}}(t));if("text"===e.type)return{text:e.text};if("executableCode"===e.type)return{executableCode:e.executableCode};if("codeExecutionResult"===e.type)return{codeExecutionResult:e.codeExecutionResult};if("image_url"===e.type){if(!t)throw new Error("This model does not support images");let i;if("string"==typeof e.image_url)i=e.image_url;else{if("object"!=typeof e.image_url||!("url"in e.image_url))throw new Error("Please provide image as base64 encoded data URL");i=e.image_url.url}const[n,r]=i.split(",");if(!n.startsWith("data:"))throw new Error("Please provide image as base64 encoded data URL");const[s,a]=n.replace(/^data:/,"").split(";");if("base64"!==a)throw new Error("Please provide image as base64 encoded data URL");return{inlineData:{data:r,mimeType:s}}}if("media"===e.type)return function(e){if("mimeType"in e&&"data"in e)return{inlineData:{mimeType:e.mimeType,data:e.data}};if("mimeType"in e&&"fileUri"in e)return{fileData:{mimeType:e.mimeType,fileUri:e.fileUri}};throw new Error("Invalid media content")}(e);if("tool_use"===e.type)return{functionCall:{name:e.name,args:e.input}};if((null==(i=e.type)?void 0:i.includes("/"))&&2===e.type.split("/").length&&"data"in e&&"string"==typeof e.data)return{inlineData:{mimeType:e.type,data:e.data}};if(!("functionCall"in e))throw"type"in e?new Error(`Unknown content type ${e.type}`):new Error(`Unknown content ${JSON.stringify(e)}`)}function Rp(e,t,i){var n;if("tool"===e._getType()){const n=e.name??function(e,t){var i;return null==(i=t.map(e=>zo(e)?e.tool_calls??[]:[]).flat().find(t=>t.id===e.tool_call_id))?void 0:i.name}(e,i);if(void 0===n)throw new Error(`Google requires a tool name for each tool call response, and we could not infer a called tool name for ToolMessage "${e.id}" from your passed messages. Please populate a "name" field on that ToolMessage explicitly.`);const r=Array.isArray(e.content)?e.content.map(e=>Cp(e,t)).filter(e=>void 0!==e):e.content;return"error"===e.status?[{functionResponse:{name:n,response:{error:{details:r}}}}]:[{functionResponse:{name:n,response:{result:r}}}]}let r=[];const s=[];return"string"==typeof e.content&&e.content&&s.push({text:e.content}),Array.isArray(e.content)&&s.push(...e.content.map(e=>Cp(e,t)).filter(e=>void 0!==e)),zo(e)&&(null==(n=e.tool_calls)?void 0:n.length)&&(r=e.tool_calls.map(e=>({functionCall:{name:e.name,args:e.args}}))),[...s,...r]}function Qp(e,t,i=!1){return e.reduce((n,r,s)=>{if(!Mo(r))throw new Error("Unsupported message input");const a=function(e){const t=e._getType();return Xo.isInstance(e)?e.role:"tool"===t?t:e.name??t}(r);if("system"===a&&0!==s)throw new Error("System message should be the first one");const o=function(e){switch(e){case"supervisor":case"ai":case"model":return"model";case"system":return"system";case"human":return"user";case"tool":case"function":return"function";default:throw new Error(`Unknown / unsupported author: ${e}`)}}(a),l=n.content[n.content.length];if(!n.mergeWithPreviousContent&&l&&l.role===o)throw new Error("Google Generative AI requires alternate messages between authors");const c=Rp(r,t,e.slice(0,s));if(n.mergeWithPreviousContent){const e=n.content[n.content.length-1];if(!e)throw new Error("There was a problem parsing your system message. Please try a prompt without one.");return e.parts.push(...c),{mergeWithPreviousContent:!1,content:n.content}}let h=o;("function"===h||"system"===h&&!i)&&(h="user");const u={role:h,parts:c};return{mergeWithPreviousContent:"system"===a&&!i,content:[...n.content,u]}},{content:[],mergeWithPreviousContent:!1}).content}function Ip(e,t){if(!e.candidates||0===e.candidates.length)return null;const i=e.functionCalls(),[n]=e.candidates,{content:r,...s}=n;let a;a=Array.isArray(null==r?void 0:r.parts)&&r.parts.every(e=>"text"in e)?r.parts.map(e=>e.text).join(""):Array.isArray(null==r?void 0:r.parts)?r.parts.map(e=>"text"in e?{type:"text",text:e.text}:"executableCode"in e?{type:"executableCode",executableCode:e.executableCode}:"codeExecutionResult"in e?{type:"codeExecutionResult",codeExecutionResult:e.codeExecutionResult}:e):[];let o="";if(a&&"string"==typeof a)o=a;else if(Array.isArray(a)){const e=a.find(e=>"text"in e);o=(null==e?void 0:e.text)??""}const l=[];return i&&l.push(...i.map(e=>({...e,args:JSON.stringify(e.args),index:t.index,type:"tool_call_chunk",id:"id"in e&&"string"==typeof e.id?e.id:Ap()}))),new ql({text:o,message:new qo({content:a||"",name:r?r.role:void 0,tool_call_chunks:l,additional_kwargs:{},usage_metadata:t.usageMetadata}),generationInfo:s})}class jp extends fp{static lc_name(){return"GoogleGenerativeAIToolsOutputParser"}constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","google_genai","output_parsers"]}),Object.defineProperty(this,"returnId",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"keyName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"returnSingle",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"zodSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.keyName=e.keyName,this.returnSingle=e.returnSingle??this.returnSingle,this.zodSchema=e.zodSchema}async _validateResult(e){if(void 0===this.zodSchema)return e;const t=await bh(this.zodSchema,e);if(t.success)return t.data;throw new gp(`Failed to parse. Text: "${JSON.stringify(e,null,2)}". Error: ${JSON.stringify(t.error.issues)}`,JSON.stringify(e,null,2))}async parseResult(e){const t=e.flatMap(e=>{const{message:t}=e;return"tool_calls"in t&&Array.isArray(t.tool_calls)?t.tool_calls:[]});if(void 0===t[0])throw new Error("No parseable tool calls provided to GoogleGenerativeAIToolsOutputParser.");const[i]=t;return await this._validateResult(i.args)}}function Mp(e,t){const i=function(e){let t=[];const i=[];e.forEach(e=>{if(Sp(e)){const[i]=function(e){return e.every(e=>"functionDeclarations"in e&&Array.isArray(e.functionDeclarations))?e:[{functionDeclarations:e.map(e=>{if(Sp(e)){const t=_p(e.schema);return"object"===t.type&&"properties"in t&&0===Object.keys(t.properties).length?{name:e.name,description:e.description}:{name:e.name,description:e.description,parameters:t}}return lp(e)?{name:e.function.name,description:e.function.description??"A function available to call.",parameters:xp(e.function.parameters)}:e})}]}([e]);i.functionDeclarations&&t.push(...i.functionDeclarations)}else if(lp(e)){const{functionDeclarations:i}=function(e){return{functionDeclarations:[{name:e.function.name,description:e.function.description,parameters:wp(e.function.parameters)}]}}(e);if(!i)throw new Error("Failed to convert OpenAI structured tool to GenerativeAI tool");t.push(...i)}else i.push(e)});const n=i.find(e=>"functionDeclarations"in e);if(n)return i.map(e=>{if((null==t?void 0:t.length)>0&&"functionDeclarations"in e){const i={functionDeclarations:[...e.functionDeclarations||[],...t]};return t=[],i}return e});return[...i,...t.length>0?[{functionDeclarations:t}]:[]]}(e),n=function(e,t){if(!e.length||!t)return;const{toolChoice:i,allowedFunctionNames:n}=t,r={any:id.ANY,auto:id.AUTO,none:id.NONE};if(i&&["any","auto","none"].includes(i))return{functionCallingConfig:{mode:r[i]??"MODE_UNSPECIFIED",allowedFunctionNames:n}};if("string"==typeof i||n)return{functionCallingConfig:{mode:id.ANY,allowedFunctionNames:[...n??[],...i&&"string"==typeof i?[i]:[]]}};return}(i,t);return{tools:i,toolConfig:n}}class Np extends pp{static lc_name(){return"ChatGoogleGenerativeAI"}get lc_secrets(){return{apiKey:"GOOGLE_API_KEY"}}get lc_aliases(){return{apiKey:"google_api_key"}}get _isMultimodalModel(){return this.model.includes("vision")||this.model.startsWith("gemini-1.5")||this.model.startsWith("gemini-2")||this.model.startsWith("gemma-3-")&&!this.model.startsWith("gemma-3-1b")}constructor(e){if(super(e),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","chat_models","google_genai"]}),Object.defineProperty(this,"model",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"temperature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxOutputTokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stopSequences",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"safetySettings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streaming",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"json",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streamUsage",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"convertSystemMessageToHumanContent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.model=e.model.replace(/^models\//,""),this.maxOutputTokens=e.maxOutputTokens??this.maxOutputTokens,this.maxOutputTokens&&this.maxOutputTokens<0)throw new Error("`maxOutputTokens` must be a positive integer");if(this.temperature=e.temperature??this.temperature,this.temperature&&(this.temperature<0||this.temperature>2))throw new Error("`temperature` must be in the range of [0.0,2.0]");if(this.topP=e.topP??this.topP,this.topP&&this.topP<0)throw new Error("`topP` must be a positive integer");if(this.topP&&this.topP>1)throw new Error("`topP` must be below 1.");if(this.topK=e.topK??this.topK,this.topK&&this.topK<0)throw new Error("`topK` must be a positive integer");if(this.stopSequences=e.stopSequences??this.stopSequences,this.apiKey=e.apiKey??to("GOOGLE_API_KEY"),!this.apiKey)throw new Error("Please set an API key for Google GenerativeAI in the environment variable GOOGLE_API_KEY or in the `apiKey` field of the ChatGoogleGenerativeAI constructor");if(this.safetySettings=e.safetySettings??this.safetySettings,this.safetySettings&&this.safetySettings.length>0){if(new Set(this.safetySettings.map(e=>e.category)).size!==this.safetySettings.length)throw new Error("The categories in `safetySettings` array must be unique")}this.streaming=e.streaming??this.streaming,this.json=e.json,this.client=new Dd(this.apiKey).getGenerativeModel({model:this.model,safetySettings:this.safetySettings,generationConfig:{stopSequences:this.stopSequences,maxOutputTokens:this.maxOutputTokens,temperature:this.temperature,topP:this.topP,topK:this.topK,...this.json?{responseMimeType:"application/json"}:{}}},{apiVersion:e.apiVersion,baseUrl:e.baseUrl}),this.streamUsage=e.streamUsage??this.streamUsage}useCachedContent(e,t,i){this.apiKey&&(this.client=new Dd(this.apiKey).getGenerativeModelFromCachedContent(e,t,i))}get useSystemInstruction(){return"boolean"==typeof this.convertSystemMessageToHumanContent?!this.convertSystemMessageToHumanContent:this.computeUseSystemInstruction}get computeUseSystemInstruction(){return"gemini-1.0-pro-001"!==this.model&&(!this.model.startsWith("gemini-pro-vision")&&(!this.model.startsWith("gemini-1.0-pro-vision")&&"gemini-pro"!==this.model))}getLsParams(e){return{ls_provider:"google_genai",ls_model_name:this.model,ls_model_type:"chat",ls_temperature:this.client.generationConfig.temperature,ls_max_tokens:this.client.generationConfig.maxOutputTokens,ls_stop:e.stop}}_combineLLMOutput(){return[]}_llmType(){return"googlegenerativeai"}bindTools(e,t){var i;return this.withConfig({tools:null==(i=Mp(e))?void 0:i.tools,...t})}invocationParams(e){var t;const i=(null==(t=null==e?void 0:e.tools)?void 0:t.length)?Mp(e.tools,{toolChoice:e.tool_choice,allowedFunctionNames:e.allowedFunctionNames}):void 0;return(null==e?void 0:e.responseSchema)?(this.client.generationConfig.responseSchema=e.responseSchema,this.client.generationConfig.responseMimeType="application/json"):(this.client.generationConfig.responseSchema=void 0,this.client.generationConfig.responseMimeType=this.json?"application/json":void 0),{...(null==i?void 0:i.tools)?{tools:i.tools}:{},...(null==i?void 0:i.toolConfig)?{toolConfig:i.toolConfig}:{}}}async _generate(e,t,i){var n,r,s;const a=Qp(e,this._isMultimodalModel,this.useSystemInstruction);let o=a;if("system"===a[0].role){const[e]=a;this.client.systemInstruction=e,o=a.slice(1)}const l=this.invocationParams(t);if(this.streaming){const r={},s=this._streamResponseChunks(e,t,i),a={};for await(const e of s){const t=(null==(n=e.generationInfo)?void 0:n.completion)??0;void 0===a[t]?a[t]=e:a[t]=a[t].concat(e)}const o=Object.entries(a).sort(([e],[t])=>parseInt(e,10)-parseInt(t,10)).map(([e,t])=>t);return{generations:o,llmOutput:{estimatedTokenUsage:r}}}const c=await this.completionWithRetry({...l,contents:o});let h;if("usageMetadata"in c.response){const e=c.response.usageMetadata;h={input_tokens:e.promptTokenCount??0,output_tokens:e.candidatesTokenCount??0,total_tokens:e.totalTokenCount??0}}const u=function(e,t){var i,n,r;if(!e.candidates||0===e.candidates.length||!e.candidates[0])return{generations:[],llmOutput:{filters:e.promptFeedback}};const s=e.functionCalls(),[a]=e.candidates,{content:o,...l}=a;let c;c=Array.isArray(null==o?void 0:o.parts)&&1===o.parts.length&&o.parts[0].text?o.parts[0].text:Array.isArray(null==o?void 0:o.parts)&&o.parts.length>0?o.parts.map(e=>"text"in e?{type:"text",text:e.text}:"executableCode"in e?{type:"executableCode",executableCode:e.executableCode}:"codeExecutionResult"in e?{type:"codeExecutionResult",codeExecutionResult:e.codeExecutionResult}:e):[];let h="";if("string"==typeof c)h=c;else if(Array.isArray(c)&&c.length>0){const e=c.find(e=>"text"in e);h=(null==e?void 0:e.text)??h}return{generations:[{text:h,message:new Do({content:c??"",tool_calls:null==s?void 0:s.map(e=>({...e,type:"tool_call",id:"id"in e&&"string"==typeof e.id?e.id:Ap()})),additional_kwargs:{...l},usage_metadata:null==t?void 0:t.usageMetadata}),generationInfo:l}],llmOutput:{tokenUsage:{promptTokens:null==(i=null==t?void 0:t.usageMetadata)?void 0:i.input_tokens,completionTokens:null==(n=null==t?void 0:t.usageMetadata)?void 0:n.output_tokens,totalTokens:null==(r=null==t?void 0:t.usageMetadata)?void 0:r.total_tokens}}}}(c.response,{usageMetadata:h});return(null==(r=u.generations)?void 0:r.length)>0&&await(null==i?void 0:i.handleLLMNewToken((null==(s=u.generations[0])?void 0:s.text)??"")),u}async*_streamResponseChunks(e,t,i){const n=Qp(e,this._isMultimodalModel,this.useSystemInstruction);let r=n;if("system"===n[0].role){const[e]=n;this.client.systemInstruction=e,r=n.slice(1)}const s={...this.invocationParams(t),contents:r},a=await this.caller.callWithOptions({signal:null==t?void 0:t.signal},async()=>{const{stream:e}=await this.client.generateContentStream(s);return e});let o,l=0,c=0,h=0,u=0;for await(const d of a){if("usageMetadata"in d&&void 0!==d.usageMetadata&&!1!==this.streamUsage&&!1!==t.streamUsage){o={input_tokens:d.usageMetadata.promptTokenCount??0,output_tokens:d.usageMetadata.candidatesTokenCount??0,total_tokens:d.usageMetadata.totalTokenCount??0};const e=d.usageMetadata.promptTokenCount??0;o.input_tokens=Math.max(0,e-l),l=e;const t=d.usageMetadata.candidatesTokenCount??0;o.output_tokens=Math.max(0,t-c),c=t;const i=d.usageMetadata.totalTokenCount??0;o.total_tokens=Math.max(0,i-h),h=i}const e=Ip(d,{usageMetadata:o,index:u});u+=1,e&&(yield e,await(null==i?void 0:i.handleLLMNewToken(e.text??"")))}}async completionWithRetry(e,t){return this.caller.callWithOptions({signal:null==t?void 0:t.signal},async()=>{var t;try{return await this.client.generateContent(e)}catch(i){throw(null==(t=i.message)?void 0:t.includes("400 Bad Request"))&&(i.status=400),i}})}withStructuredOutput(e,t){const i=e,n=null==t?void 0:t.name,r=null==t?void 0:t.method,s=null==t?void 0:t.includeRaw;if("jsonMode"===r)throw new Error('ChatGoogleGenerativeAI only supports "jsonSchema" or "functionCalling" as a method.');let a,o;if("functionCalling"===r){let e,t=n??"extract";if(yh(i)){const n=_p(i);e=[{functionDeclarations:[{name:t,description:n.description??"A function available to call.",parameters:n}]}],o=new jp({returnSingle:!0,keyName:t,zodSchema:i})}else{let n;"string"==typeof i.name&&"object"==typeof i.parameters&&null!=i.parameters?(n=i,n.parameters=wp(i.parameters),t=i.name):n={name:t,description:i.description??"",parameters:wp(i)},e=[{functionDeclarations:[n]}],o=new jp({returnSingle:!0,keyName:t})}a=this.bindTools(e).withConfig({allowedFunctionNames:[t]})}else{const e=_p(i);a=this.withConfig({responseSchema:e}),o=new bp}if(!s)return a.pipe(o).withConfig({runName:"ChatGoogleGenerativeAIStructuredOutput"});const l=up.assign({parsed:(e,t)=>o.invoke(e.raw,t)}),c=up.assign({parsed:()=>null}),h=l.withFallbacks({fallbacks:[c]});return Uh.from([{raw:a},h]).withConfig({runName:"StructuredOutputRunnable"})}}var Lp="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},Zp="URLSearchParams"in Lp,Dp="Symbol"in Lp&&"iterator"in Symbol,zp="FileReader"in Lp&&"Blob"in Lp&&function(){try{return new Blob,!0}catch(e){return!1}}(),Up="FormData"in Lp,qp="ArrayBuffer"in Lp;if(qp)var Xp=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],Bp=ArrayBuffer.isView||function(e){return e&&Xp.indexOf(Object.prototype.toString.call(e))>-1};function Wp(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||""===e)throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function Vp(e){return"string"!=typeof e&&(e=String(e)),e}function Fp(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return Dp&&(t[Symbol.iterator]=function(){return t}),t}function Yp(e){this.map={},e instanceof Yp?e.forEach(function(e,t){this.append(t,e)},this):Array.isArray(e)?e.forEach(function(e){if(2!=e.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+e.length);this.append(e[0],e[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function Gp(e){if(!e._noBody)return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function Hp(e){return new Promise(function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}})}function Kp(e){var t=new FileReader,i=Hp(t);return t.readAsArrayBuffer(e),i}function Jp(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function ef(){return this.bodyUsed=!1,this._initBody=function(e){this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:zp&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:Up&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:Zp&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():qp&&zp&&function(e){return e&&DataView.prototype.isPrototypeOf(e)}(e)?(this._bodyArrayBuffer=Jp(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):qp&&(ArrayBuffer.prototype.isPrototypeOf(e)||Bp(e))?this._bodyArrayBuffer=Jp(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):Zp&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},zp&&(this.blob=function(){var e=Gp(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=Gp(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(zp)return this.blob().then(Kp);throw new Error("could not read as ArrayBuffer")},this.text=function(){var e,t,i,n,r,s=Gp(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,i=Hp(t),n=/charset=([A-Za-z0-9_-]+)/.exec(e.type),r=n?n[1]:"utf-8",t.readAsText(e,r),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),n=0;n<t.length;n++)i[n]=String.fromCharCode(t[n]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},Up&&(this.formData=function(){return this.text().then(rf)}),this.json=function(){return this.text().then(JSON.parse)},this}Yp.prototype.append=function(e,t){e=Wp(e),t=Vp(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},Yp.prototype.delete=function(e){delete this.map[Wp(e)]},Yp.prototype.get=function(e){return e=Wp(e),this.has(e)?this.map[e]:null},Yp.prototype.has=function(e){return this.map.hasOwnProperty(Wp(e))},Yp.prototype.set=function(e,t){this.map[Wp(e)]=Vp(t)},Yp.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},Yp.prototype.keys=function(){var e=[];return this.forEach(function(t,i){e.push(i)}),Fp(e)},Yp.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),Fp(e)},Yp.prototype.entries=function(){var e=[];return this.forEach(function(t,i){e.push([i,t])}),Fp(e)},Dp&&(Yp.prototype[Symbol.iterator]=Yp.prototype.entries);var tf=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function nf(e,t){if(!(this instanceof nf))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var i,n,r=(t=t||{}).body;if(e instanceof nf){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new Yp(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new Yp(t.headers)),this.method=(i=t.method||this.method||"GET",n=i.toUpperCase(),tf.indexOf(n)>-1?n:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in Lp)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==t.cache&&"no-cache"!==t.cache)){var s=/([?&])_=[^&]*/;if(s.test(this.url))this.url=this.url.replace(s,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function rf(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),r=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(r))}}),t}function sf(e,t){if(!(this instanceof sf))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===t.statusText?"":""+t.statusText,this.headers=new Yp(t.headers),this.url=t.url||"",this._initBody(e)}nf.prototype.clone=function(){return new nf(this,{body:this._bodyInit})},ef.call(nf.prototype),ef.call(sf.prototype),sf.prototype.clone=function(){return new sf(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Yp(this.headers),url:this.url})},sf.error=function(){var e=new sf(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var af=[301,302,303,307,308];sf.redirect=function(e,t){if(-1===af.indexOf(t))throw new RangeError("Invalid status code");return new sf(null,{status:t,headers:{location:e}})};var of=Lp.DOMException;try{new of}catch($M){(of=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack}).prototype=Object.create(Error.prototype),of.prototype.constructor=of}function lf(e,t){return new Promise(function(i,n){var r=new nf(e,t);if(r.signal&&r.signal.aborted)return n(new of("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}if(s.onload=function(){var e,t,n={statusText:s.statusText,headers:(e=s.getAllResponseHeaders()||"",t=new Yp,e.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(e){return 0===e.indexOf("\n")?e.substr(1,e.length):e}).forEach(function(e){var i=e.split(":"),n=i.shift().trim();if(n){var r=i.join(":").trim();try{t.append(n,r)}catch(s){}}}),t)};0===r.url.indexOf("file://")&&(s.status<200||s.status>599)?n.status=200:n.status=s.status,n.url="responseURL"in s?s.responseURL:n.headers.get("X-Request-URL");var a="response"in s?s.response:s.responseText;setTimeout(function(){i(new sf(a,n))},0)},s.onerror=function(){setTimeout(function(){n(new TypeError("Network request failed"))},0)},s.ontimeout=function(){setTimeout(function(){n(new TypeError("Network request timed out"))},0)},s.onabort=function(){setTimeout(function(){n(new of("Aborted","AbortError"))},0)},s.open(r.method,function(e){try{return""===e&&Lp.location.href?Lp.location.href:e}catch(t){return e}}(r.url),!0),"include"===r.credentials?s.withCredentials=!0:"omit"===r.credentials&&(s.withCredentials=!1),"responseType"in s&&(zp?s.responseType="blob":qp&&(s.responseType="arraybuffer")),t&&"object"==typeof t.headers&&!(t.headers instanceof Yp||Lp.Headers&&t.headers instanceof Lp.Headers)){var o=[];Object.getOwnPropertyNames(t.headers).forEach(function(e){o.push(Wp(e)),s.setRequestHeader(e,Vp(t.headers[e]))}),r.headers.forEach(function(e,t){-1===o.indexOf(t)&&s.setRequestHeader(t,e)})}else r.headers.forEach(function(e,t){s.setRequestHeader(t,e)});r.signal&&(r.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&r.signal.removeEventListener("abort",a)}),s.send(void 0===r._bodyInit?null:r._bodyInit)})}lf.polyfill=!0,Lp.fetch||(Lp.fetch=lf,Lp.Headers=Yp,Lp.Request=nf,Lp.Response=sf);const cf="11434",hf=`http://127.0.0.1:${cf}`;var uf=Object.defineProperty,df=(e,t,i)=>(((e,t,i)=>{t in e?uf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);class pf extends Error{constructor(e,t){super(e),this.error=e,this.status_code=t,this.name="ResponseError",Error.captureStackTrace&&Error.captureStackTrace(this,pf)}}class ff{constructor(e,t,i){df(this,"abortController"),df(this,"itr"),df(this,"doneCallback"),this.abortController=e,this.itr=t,this.doneCallback=i}abort(){this.abortController.abort()}async*[Symbol.asyncIterator](){for await(const e of this.itr){if("error"in e)throw new Error(e.error);if(yield e,e.done||"success"===e.status)return void this.doneCallback()}throw new Error("Did not receive done or success response in stream.")}}const mf=async e=>{var t;if(e.ok)return;let i=`Error ${e.status}: ${e.statusText}`,n=null;if(null==(t=e.headers.get("content-type"))?void 0:t.includes("application/json"))try{n=await e.json(),i=n.error||i}catch(r){}else try{i=await e.text()||i}catch(r){}throw new pf(i,e.status)};function gf(){var e;if("undefined"!=typeof window&&window.navigator){const t=navigator;return"userAgentData"in t&&(null==(e=t.userAgentData)?void 0:e.platform)?`${t.userAgentData.platform.toLowerCase()} Browser/${navigator.userAgent};`:navigator.platform?`${navigator.platform.toLowerCase()} Browser/${navigator.userAgent};`:`unknown Browser/${navigator.userAgent};`}return"undefined"!=typeof process?`${process.arch} ${process.platform} Node.js/${process.version}`:""}const Of=async(e,t,i={})=>{const n={"Content-Type":"application/json",Accept:"application/json","User-Agent":`ollama-js/0.5.18 (${gf()})`};i.headers=function(e){if(e instanceof Headers){const t={};return e.forEach((e,i)=>{t[i]=e}),t}return Array.isArray(e)?Object.fromEntries(e):e||{}}(i.headers);const r=Object.fromEntries(Object.entries(i.headers).filter(([e])=>!Object.keys(n).some(t=>t.toLowerCase()===e.toLowerCase())));return i.headers={...n,...r},e(t,i)},vf=async(e,t,i)=>{const n=await Of(e,t,{headers:null==i?void 0:i.headers});return await mf(n),n},yf=async(e,t,i,n)=>{const r=null===(s=i)||"object"!=typeof s||Array.isArray(s)?i:JSON.stringify(i);var s;const a=await Of(e,t,{method:"POST",body:r,signal:null==n?void 0:n.signal,headers:null==n?void 0:n.headers});return await mf(a),a};var bf=Object.defineProperty,wf=(e,t,i)=>(((e,t,i)=>{t in e?bf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);let _f=class{constructor(e){wf(this,"config"),wf(this,"fetch"),wf(this,"ongoingStreamedRequests",[]),this.config={host:"",headers:null==e?void 0:e.headers},(null==e?void 0:e.proxy)||(this.config.host=(e=>{if(!e)return hf;let t=e.includes("://");e.startsWith(":")&&(e=`http://127.0.0.1${e}`,t=!0),t||(e=`http://${e}`);const i=new URL(e);let n=i.port;n||(n=t?"https:"===i.protocol?"443":"80":cf);let r="";i.username&&(r=i.username,i.password&&(r+=`:${i.password}`),r+="@");let s=`${i.protocol}//${r}${i.hostname}:${n}${i.pathname}`;return s.endsWith("/")&&(s=s.slice(0,-1)),s})((null==e?void 0:e.host)??hf)),this.fetch=(null==e?void 0:e.fetch)??fetch}abort(){for(const e of this.ongoingStreamedRequests)e.abort();this.ongoingStreamedRequests.length=0}async processStreamableRequest(e,t){t.stream=t.stream??!1;const i=`${this.config.host}/api/${e}`;if(t.stream){const e=new AbortController,n=await yf(this.fetch,i,t,{signal:e.signal,headers:this.config.headers});if(!n.body)throw new Error("Missing body");const r=async function*(e){const t=new TextDecoder("utf-8");let i="";const n=e.getReader();for(;;){const{done:e,value:s}=await n.read();if(e)break;i+=t.decode(s);const a=i.split("\n");i=a.pop()??"";for(const t of a)try{yield JSON.parse(t)}catch(r){}}for(const s of i.split("\n").filter(e=>""!==e))try{yield JSON.parse(s)}catch(r){}}(n.body),s=new ff(e,r,()=>{const e=this.ongoingStreamedRequests.indexOf(s);e>-1&&this.ongoingStreamedRequests.splice(e,1)});return this.ongoingStreamedRequests.push(s),s}const n=await yf(this.fetch,i,t,{headers:this.config.headers});return await n.json()}async encodeImage(e){if("string"!=typeof e){const t=new Uint8Array(e);let i="";const n=t.byteLength;for(let e=0;e<n;e++)i+=String.fromCharCode(t[e]);return btoa(i)}return e}async generate(e){return e.images&&(e.images=await Promise.all(e.images.map(this.encodeImage.bind(this)))),this.processStreamableRequest("generate",e)}async chat(e){if(e.messages)for(const t of e.messages)t.images&&(t.images=await Promise.all(t.images.map(this.encodeImage.bind(this))));return this.processStreamableRequest("chat",e)}async create(e){return this.processStreamableRequest("create",{...e})}async pull(e){return this.processStreamableRequest("pull",{name:e.model,stream:e.stream,insecure:e.insecure})}async push(e){return this.processStreamableRequest("push",{name:e.model,stream:e.stream,insecure:e.insecure})}async delete(e){return await(async(e,t,i,n)=>{const r=await Of(e,t,{method:"DELETE",body:JSON.stringify(i),headers:null==n?void 0:n.headers});return await mf(r),r})(this.fetch,`${this.config.host}/api/delete`,{name:e.model},{headers:this.config.headers}),{status:"success"}}async copy(e){return await yf(this.fetch,`${this.config.host}/api/copy`,{...e},{headers:this.config.headers}),{status:"success"}}async list(){const e=await vf(this.fetch,`${this.config.host}/api/tags`,{headers:this.config.headers});return await e.json()}async show(e){const t=await yf(this.fetch,`${this.config.host}/api/show`,{...e},{headers:this.config.headers});return await t.json()}async embed(e){const t=await yf(this.fetch,`${this.config.host}/api/embed`,{...e},{headers:this.config.headers});return await t.json()}async embeddings(e){const t=await yf(this.fetch,`${this.config.host}/api/embeddings`,{...e},{headers:this.config.headers});return await t.json()}async ps(){const e=await vf(this.fetch,`${this.config.host}/api/ps`,{headers:this.config.headers});return await e.json()}};new _f;class xf extends hp{constructor({concurrency:e,...t}){super(e?{maxConcurrency:e,...t}:t),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","llms",this._llmType()]})}async invoke(e,t){const i=xf._convertInputToPromptValue(e);return(await this.generatePrompt([i],t,null==t?void 0:t.callbacks)).generations[0][0].text}async*_streamResponseChunks(e,t,i){throw new Error("Not implemented.")}_separateRunnableConfigFromCallOptionsCompat(e){const[t,i]=super._separateRunnableConfigFromCallOptions(e);return i.signal=t.signal,[t,i]}async*_streamIterator(e,t){if(this._streamResponseChunks===xf.prototype._streamResponseChunks)yield this.invoke(e,t);else{const i=xf._convertInputToPromptValue(e),[n,r]=this._separateRunnableConfigFromCallOptionsCompat(t),s=await yl.configure(n.callbacks,this.callbacks,n.tags,this.tags,n.metadata,this.metadata,{verbose:this.verbose}),a={options:r,invocation_params:null==this?void 0:this.invocationParams(r),batch_size:1},o=await(null==s?void 0:s.handleLLMStart(this.toJSON(),[i.toString()],n.runId,void 0,a,void 0,void 0,n.runName));let l=new Ul({text:""});try{for await(const e of this._streamResponseChunks(i.toString(),r,null==o?void 0:o[0]))l=l?l.concat(e):e,"string"==typeof e.text&&(yield e.text)}catch($M){throw await Promise.all((o??[]).map(t=>null==t?void 0:t.handleLLMError($M))),$M}await Promise.all((o??[]).map(e=>null==e?void 0:e.handleLLMEnd({generations:[[l]]})))}}async generatePrompt(e,t,i){const n=e.map(e=>e.toString());return this.generate(n,t,i)}invocationParams(e){return{}}_flattenLLMResult(e){const t=[];for(let i=0;i<e.generations.length;i+=1){const n=e.generations[i];if(0===i)t.push({generations:[n],llmOutput:e.llmOutput});else{const i=e.llmOutput?{...e.llmOutput,tokenUsage:{}}:void 0;t.push({generations:[n],llmOutput:i})}}return t}async _generateUncached(e,t,i,n){let r;if(void 0!==n&&n.length===e.length)r=n;else{const n=await yl.configure(i.callbacks,this.callbacks,i.tags,this.tags,i.metadata,this.metadata,{verbose:this.verbose}),s={options:t,invocation_params:null==this?void 0:this.invocationParams(t),batch_size:e.length};r=await(null==n?void 0:n.handleLLMStart(this.toJSON(),e,i.runId,void 0,s,void 0,void 0,null==i?void 0:i.runName))}let s;if(!!(null==r?void 0:r[0].handlers.find(no))&&1===e.length&&this._streamResponseChunks!==xf.prototype._streamResponseChunks)try{const i=await this._streamResponseChunks(e[0],t,null==r?void 0:r[0]);let n;for await(const e of i)n=void 0===n?e:Ql(n,e);if(void 0===n)throw new Error("Received empty response from chat model call.");s={generations:[[n]],llmOutput:{}},await(null==r?void 0:r[0].handleLLMEnd(s))}catch(o){throw await(null==r?void 0:r[0].handleLLMError(o)),o}else{try{s=await this._generate(e,t,null==r?void 0:r[0])}catch($M){throw await Promise.all((r??[]).map(t=>null==t?void 0:t.handleLLMError($M))),$M}const i=this._flattenLLMResult(s);await Promise.all((r??[]).map((e,t)=>null==e?void 0:e.handleLLMEnd(i[t])))}const a=(null==r?void 0:r.map(e=>e.runId))||void 0;return Object.defineProperty(s,zl,{value:a?{runIds:a}:void 0,configurable:!0}),s}async _generateCached({prompts:e,cache:t,llmStringKey:i,parsedOptions:n,handledOptions:r,runId:s}){const a=await yl.configure(r.callbacks,this.callbacks,r.tags,this.tags,r.metadata,this.metadata,{verbose:this.verbose}),o={options:n,invocation_params:null==this?void 0:this.invocationParams(n),batch_size:e.length},l=await(null==a?void 0:a.handleLLMStart(this.toJSON(),e,s,void 0,o,void 0,void 0,null==r?void 0:r.runName)),c=[],h=(await Promise.allSettled(e.map(async(e,n)=>{const r=await t.lookup(e,i);return null==r&&c.push(n),r}))).map((e,t)=>({result:e,runManager:null==l?void 0:l[t]})).filter(({result:e})=>"fulfilled"===e.status&&null!=e.value||"rejected"===e.status),u=[];await Promise.all(h.map(async({result:e,runManager:t},i)=>{if("fulfilled"===e.status){const n=e.value;return u[i]=n.map(e=>(e.generationInfo={...e.generationInfo,tokenUsage:{}},e)),n.length&&await(null==t?void 0:t.handleLLMNewToken(n[0].text)),null==t?void 0:t.handleLLMEnd({generations:[n]},void 0,void 0,void 0,{cached:!0})}return await(null==t?void 0:t.handleLLMError(e.reason,void 0,void 0,void 0,{cached:!0})),Promise.reject(e.reason)}));const d={generations:u,missingPromptIndices:c,startedRunManagers:l};return Object.defineProperty(d,zl,{value:l?{runIds:null==l?void 0:l.map(e=>e.runId)}:void 0,configurable:!0}),d}async generate(e,t,i){if(!Array.isArray(e))throw new Error("Argument 'prompts' is expected to be a string[]");let n;n=Array.isArray(t)?{stop:t}:t;const[r,s]=this._separateRunnableConfigFromCallOptionsCompat(n);if(r.callbacks=r.callbacks??i,!this.cache)return this._generateUncached(e,s,r);const{cache:a}=this,o=this._getSerializedCacheKeyParametersForCall(s),{generations:l,missingPromptIndices:c,startedRunManagers:h}=await this._generateCached({prompts:e,cache:a,llmStringKey:o,parsedOptions:s,handledOptions:r,runId:r.runId});let u={};if(c.length>0){const t=await this._generateUncached(c.map(t=>e[t]),s,r,void 0!==h?c.map(e=>null==h?void 0:h[e]):void 0);await Promise.all(t.generations.map(async(t,i)=>{const n=c[i];return l[n]=t,a.update(e[n],o,t)})),u=t.llmOutput??{}}return{generations:l,llmOutput:u}}async call(e,t,i){const{generations:n}=await this.generate([e],t,i);return n[0][0].text}async predict(e,t,i){return this.call(e,t,i)}async predictMessages(e,t,i){const n=tl(e),r=await this.call(n,t,i);return new Do(r)}_identifyingParams(){return{}}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}_modelType(){return"base_llm"}}class Sf extends xf{async _generate(e,t,i){return{generations:await Promise.all(e.map((e,n)=>this._call(e,{...t,promptIndex:n},i).then(e=>[{text:e}])))}}}class kf extends Sf{static lc_name(){return"Ollama"}constructor(e){var t;super(e??{}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"model",{enumerable:!0,configurable:!0,writable:!0,value:"llama3"}),Object.defineProperty(this,"baseUrl",{enumerable:!0,configurable:!0,writable:!0,value:"http://localhost:11434"}),Object.defineProperty(this,"keepAlive",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"embeddingOnly",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"f16KV",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"frequencyPenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logitsAll",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lowVram",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mainGpu",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mirostat",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mirostatEta",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mirostatTau",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numBatch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numCtx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numGpu",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numKeep",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numPredict",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"numThread",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"penalizeNewline",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"presencePenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"repeatLastN",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"repeatPenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"temperature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tfsZ",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"typicalP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useMLock",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useMMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"vocabOnly",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"format",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.model=(null==e?void 0:e.model)??this.model,this.baseUrl=(null==(t=null==e?void 0:e.baseUrl)?void 0:t.endsWith("/"))?null==e?void 0:e.baseUrl.slice(0,-1):(null==e?void 0:e.baseUrl)??this.baseUrl,this.client=new _f({fetch:null==e?void 0:e.fetch,host:this.baseUrl,headers:null==e?void 0:e.headers}),this.keepAlive=null==e?void 0:e.keepAlive,this.embeddingOnly=null==e?void 0:e.embeddingOnly,this.f16KV=null==e?void 0:e.f16Kv,this.frequencyPenalty=null==e?void 0:e.frequencyPenalty,this.logitsAll=null==e?void 0:e.logitsAll,this.lowVram=null==e?void 0:e.lowVram,this.mainGpu=null==e?void 0:e.mainGpu,this.mirostat=null==e?void 0:e.mirostat,this.mirostatEta=null==e?void 0:e.mirostatEta,this.mirostatTau=null==e?void 0:e.mirostatTau,this.numBatch=null==e?void 0:e.numBatch,this.numCtx=null==e?void 0:e.numCtx,this.numGpu=null==e?void 0:e.numGpu,this.numKeep=null==e?void 0:e.numKeep,this.numPredict=null==e?void 0:e.numPredict,this.numThread=null==e?void 0:e.numThread,this.penalizeNewline=null==e?void 0:e.penalizeNewline,this.presencePenalty=null==e?void 0:e.presencePenalty,this.repeatLastN=null==e?void 0:e.repeatLastN,this.repeatPenalty=null==e?void 0:e.repeatPenalty,this.temperature=null==e?void 0:e.temperature,this.stop=null==e?void 0:e.stop,this.tfsZ=null==e?void 0:e.tfsZ,this.topK=null==e?void 0:e.topK,this.topP=null==e?void 0:e.topP,this.typicalP=null==e?void 0:e.typicalP,this.useMLock=null==e?void 0:e.useMlock,this.useMMap=null==e?void 0:e.useMmap,this.vocabOnly=null==e?void 0:e.vocabOnly,this.format=null==e?void 0:e.format}_llmType(){return"ollama"}invocationParams(e){return{model:this.model,format:this.format,keep_alive:this.keepAlive,images:null==e?void 0:e.images,options:{embedding_only:this.embeddingOnly,f16_kv:this.f16KV,frequency_penalty:this.frequencyPenalty,logits_all:this.logitsAll,low_vram:this.lowVram,main_gpu:this.mainGpu,mirostat:this.mirostat,mirostat_eta:this.mirostatEta,mirostat_tau:this.mirostatTau,num_batch:this.numBatch,num_ctx:this.numCtx,num_gpu:this.numGpu,num_keep:this.numKeep,num_predict:this.numPredict,num_thread:this.numThread,penalize_newline:this.penalizeNewline,presence_penalty:this.presencePenalty,repeat_last_n:this.repeatLastN,repeat_penalty:this.repeatPenalty,temperature:this.temperature,stop:(null==e?void 0:e.stop)??this.stop,tfs_z:this.tfsZ,top_k:this.topK,top_p:this.topP,typical_p:this.typicalP,use_mlock:this.useMLock,use_mmap:this.useMMap,vocab_only:this.vocabOnly}}}async*_streamResponseChunks(e,t,i){var n;const r=await this.caller.call(async()=>this.client.generate({...this.invocationParams(t),prompt:e,stream:!0}));for await(const s of r){if(null==(n=t.signal)?void 0:n.aborted)throw new Error("This operation was aborted");s.done?yield new Ul({text:"",generationInfo:{model:s.model,total_duration:s.total_duration,load_duration:s.load_duration,prompt_eval_count:s.prompt_eval_count,prompt_eval_duration:s.prompt_eval_duration,eval_count:s.eval_count,eval_duration:s.eval_duration}}):(yield new Ul({text:s.response,generationInfo:{...s,response:void 0}}),await(null==i?void 0:i.handleLLMNewToken(s.response??"")))}}async _call(e,t,i){const n=[];for await(const r of this._streamResponseChunks(e,t,i))n.push(r.text);return n.join("")}}function Pf(e,t,i,n,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,i),i}function Tf(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}let $f=function(){const{crypto:e}=globalThis;if(null==e?void 0:e.randomUUID)return $f=e.randomUUID.bind(e),e.randomUUID();const t=new Uint8Array(1),i=e?()=>e.getRandomValues(t)[0]:()=>255*Math.random()&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(+e^i()&15>>+e/4).toString(16))};function Ef(e){return"object"==typeof e&&null!==e&&("name"in e&&"AbortError"===e.name||"message"in e&&String(e.message).includes("FetchRequestCanceledException"))}const Af=e=>{if(e instanceof Error)return e;if("object"==typeof e&&null!==e){try{if("[object Error]"===Object.prototype.toString.call(e)){const t=new Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return new Error(JSON.stringify(e))}catch{}}return new Error(e)};class Cf extends Error{}class Rf extends Cf{constructor(e,t,i,n){super(`${Rf.makeMessage(e,t,i)}`),this.status=e,this.headers=n,this.requestID=null==n?void 0:n.get("x-request-id"),this.error=t;const r=t;this.code=null==r?void 0:r.code,this.param=null==r?void 0:r.param,this.type=null==r?void 0:r.type}static makeMessage(e,t,i){const n=(null==t?void 0:t.message)?"string"==typeof t.message?t.message:JSON.stringify(t.message):t?JSON.stringify(t):i;return e&&n?`${e} ${n}`:e?`${e} status code (no body)`:n||"(no status code or body)"}static generate(e,t,i,n){if(!e||!n)return new If({message:i,cause:Af(t)});const r=null==t?void 0:t.error;return 400===e?new Mf(e,r,i,n):401===e?new Nf(e,r,i,n):403===e?new Lf(e,r,i,n):404===e?new Zf(e,r,i,n):409===e?new Df(e,r,i,n):422===e?new zf(e,r,i,n):429===e?new Uf(e,r,i,n):e>=500?new qf(e,r,i,n):new Rf(e,r,i,n)}}class Qf extends Rf{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class If extends Rf{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class jf extends If{constructor({message:e}={}){super({message:e??"Request timed out."})}}class Mf extends Rf{}class Nf extends Rf{}class Lf extends Rf{}class Zf extends Rf{}class Df extends Rf{}class zf extends Rf{}class Uf extends Rf{}class qf extends Rf{}class Xf extends Cf{constructor(){super("Could not parse response content as the length limit was reached")}}class Bf extends Cf{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}class Wf extends Error{constructor(e){super(e)}}const Vf=/^[a-z][a-z0-9+.-]*:/i;let Ff=e=>(Ff=Array.isArray,Ff(e)),Yf=Ff;function Gf(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)}const Hf=e=>new Promise(t=>setTimeout(t,e)),Kf="5.12.2";const Jf=()=>{var e;const t="undefined"!=typeof Deno&&null!=Deno.build?"deno":"undefined"!=typeof EdgeRuntime?"edge":"[object process]"===Object.prototype.toString.call(void 0!==globalThis.process?globalThis.process:0)?"node":"unknown";if("deno"===t)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":tm(Deno.build.os),"X-Stainless-Arch":em(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":"string"==typeof Deno.version?Deno.version:(null==(e=Deno.version)?void 0:e.deno)??"unknown"};if("undefined"!=typeof EdgeRuntime)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if("node"===t)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":tm(globalThis.process.platform??"unknown"),"X-Stainless-Arch":em(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};const i=function(){if("undefined"==typeof navigator||!navigator)return null;const e=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:t,pattern:i}of e){const e=i.exec(navigator.userAgent);if(e){return{browser:t,version:`${e[1]||0}.${e[2]||0}.${e[3]||0}`}}}return null}();return i?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${i.browser}`,"X-Stainless-Runtime-Version":i.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kf,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};const em=e=>"x32"===e?"x32":"x86_64"===e||"x64"===e?"x64":"arm"===e?"arm":"aarch64"===e||"arm64"===e?"arm64":e?`other:${e}`:"unknown",tm=e=>(e=e.toLowerCase()).includes("ios")?"iOS":"android"===e?"Android":"darwin"===e?"MacOS":"win32"===e?"Windows":"freebsd"===e?"FreeBSD":"openbsd"===e?"OpenBSD":"linux"===e?"Linux":e?`Other:${e}`:"Unknown";let im;function nm(...e){const t=globalThis.ReadableStream;if(void 0===t)throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function rm(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return nm({start(){},async pull(e){const{done:i,value:n}=await t.next();i?e.close():e.enqueue(n)},async cancel(){var e;await(null==(e=t.return)?void 0:e.call(t))}})}function sm(e){if(e[Symbol.asyncIterator])return e;const t=e.getReader();return{async next(){try{const e=await t.read();return(null==e?void 0:e.done)&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){const e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}const am=({headers:e,body:t})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(t)}),om="RFC3986",lm=e=>String(e),cm={RFC1738:e=>String(e).replace(/%20/g,"+"),RFC3986:lm};let hm=(e,t)=>(hm=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),hm(e,t));const um=(()=>{const e=[];for(let t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e})(),dm=1024;function pm(e,t){if(Ff(e)){const i=[];for(let n=0;n<e.length;n+=1)i.push(t(e[n]));return i}return t(e)}const fm={brackets:e=>String(e)+"[]",comma:"comma",indices:(e,t)=>String(e)+"["+t+"]",repeat:e=>String(e)},mm=function(e,t){Array.prototype.push.apply(e,Ff(t)?t:[t])};let gm;const Om={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:(e,t,i,n,r)=>{if(0===e.length)return e;let s=e;if("symbol"==typeof e?s=Symbol.prototype.toString.call(e):"string"!=typeof e&&(s=String(e)),"iso-8859-1"===i)return escape(s).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});let a="";for(let o=0;o<s.length;o+=dm){const e=s.length>=dm?s.slice(o,o+dm):s,t=[];for(let i=0;i<e.length;++i){let n=e.charCodeAt(i);45===n||46===n||95===n||126===n||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122||"RFC1738"===r&&(40===n||41===n)?t[t.length]=e.charAt(i):n<128?t[t.length]=um[n]:n<2048?t[t.length]=um[192|n>>6]+um[128|63&n]:n<55296||n>=57344?t[t.length]=um[224|n>>12]+um[128|n>>6&63]+um[128|63&n]:(i+=1,n=65536+((1023&n)<<10|1023&e.charCodeAt(i)),t[t.length]=um[240|n>>18]+um[128|n>>12&63]+um[128|n>>6&63]+um[128|63&n])}a+=t.join("")}return a},encodeValuesOnly:!1,format:om,formatter:lm,indices:!1,serializeDate:e=>(gm??(gm=Function.prototype.call.bind(Date.prototype.toISOString)))(e),skipNulls:!1,strictNullHandling:!1};const vm={};function ym(e,t,i,n,r,s,a,o,l,c,h,u,d,p,f,m,g,O){let v=e,y=O,b=0,w=!1;for(;void 0!==(y=y.get(vm))&&!w;){const t=y.get(e);if(b+=1,void 0!==t){if(t===b)throw new RangeError("Cyclic object value");w=!0}void 0===y.get(vm)&&(b=0)}if("function"==typeof c?v=c(t,v):v instanceof Date?v=null==d?void 0:d(v):"comma"===i&&Ff(v)&&(v=pm(v,function(e){return e instanceof Date?null==d?void 0:d(e):e})),null===v){if(s)return l&&!m?l(t,Om.encoder,g,"key",p):t;v=""}if("string"==typeof(_=v)||"number"==typeof _||"boolean"==typeof _||"symbol"==typeof _||"bigint"==typeof _||function(e){return!(!e||"object"!=typeof e||!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e)))}(v)){if(l){const e=m?t:l(t,Om.encoder,g,"key",p);return[(null==f?void 0:f(e))+"="+(null==f?void 0:f(l(v,Om.encoder,g,"value",p)))]}return[(null==f?void 0:f(t))+"="+(null==f?void 0:f(String(v)))]}var _;const x=[];if(void 0===v)return x;let S;if("comma"===i&&Ff(v))m&&l&&(v=pm(v,l)),S=[{value:v.length>0?v.join(",")||null:void 0}];else if(Ff(c))S=c;else{const e=Object.keys(v);S=h?e.sort(h):e}const k=o?String(t).replace(/\./g,"%2E"):String(t),P=n&&Ff(v)&&1===v.length?k+"[]":k;if(r&&Ff(v)&&0===v.length)return P+"[]";for(let T=0;T<S.length;++T){const t=S[T],y="object"==typeof t&&void 0!==t.value?t.value:v[t];if(a&&null===y)continue;const w=u&&o?t.replace(/\./g,"%2E"):t,_=Ff(v)?"function"==typeof i?i(P,w):P:P+(u?"."+w:"["+w+"]");O.set(e,b);const k=new WeakMap;k.set(vm,O),mm(x,ym(y,_,i,n,r,s,a,o,"comma"===i&&m&&Ff(v)?null:l,c,h,u,d,p,f,m,g,k))}return x}function bm(e,t={}){let i=e;const n=function(e=Om){if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.encodeDotInKeys&&"boolean"!=typeof e.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");const t=e.charset||Om.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let i=om;if(void 0!==e.format){if(!hm(cm,e.format))throw new TypeError("Unknown format option provided.");i=e.format}const n=cm[i];let r,s=Om.filter;if(("function"==typeof e.filter||Ff(e.filter))&&(s=e.filter),r=e.arrayFormat&&e.arrayFormat in fm?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":Om.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const a=void 0===e.allowDots?1==!!e.encodeDotInKeys||Om.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:Om.addQueryPrefix,allowDots:a,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:Om.allowEmptyArrays,arrayFormat:r,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:Om.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?Om.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:Om.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:Om.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:Om.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:Om.encodeValuesOnly,filter:s,format:i,formatter:n,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:Om.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:Om.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:Om.strictNullHandling}}(t);let r,s;"function"==typeof n.filter?(s=n.filter,i=s("",i)):Ff(n.filter)&&(s=n.filter,r=s);const a=[];if("object"!=typeof i||null===i)return"";const o=fm[n.arrayFormat],l="comma"===o&&n.commaRoundTrip;r||(r=Object.keys(i)),n.sort&&r.sort(n.sort);const c=new WeakMap;for(let d=0;d<r.length;++d){const e=r[d];n.skipNulls&&null===i[e]||mm(a,ym(i[e],e,o,l,n.allowEmptyArrays,n.strictNullHandling,n.skipNulls,n.encodeDotInKeys,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,c))}const h=a.join(n.delimiter);let u=!0===n.addQueryPrefix?"?":"";return n.charsetSentinel&&("iso-8859-1"===n.charset?u+="utf8=%26%2310003%3B&":u+="utf8=%E2%9C%93&"),h.length>0?u+h:""}let wm,_m;function xm(e){let t;return(wm??(t=new globalThis.TextEncoder,wm=t.encode.bind(t)))(e)}function Sm(e){let t;return(_m??(t=new globalThis.TextDecoder,_m=t.decode.bind(t)))(e)}var km,Pm;class Tm{constructor(){km.set(this,void 0),Pm.set(this,void 0),Pf(this,km,new Uint8Array),Pf(this,Pm,null)}decode(e){if(null==e)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):"string"==typeof e?xm(e):e;Pf(this,km,function(e){let t=0;for(const r of e)t+=r.length;const i=new Uint8Array(t);let n=0;for(const r of e)i.set(r,n),n+=r.length;return i}([Tf(this,km,"f"),t]));const i=[];let n;for(;null!=(n=$m(Tf(this,km,"f"),Tf(this,Pm,"f")));){if(n.carriage&&null==Tf(this,Pm,"f")){Pf(this,Pm,n.index);continue}if(null!=Tf(this,Pm,"f")&&(n.index!==Tf(this,Pm,"f")+1||n.carriage)){i.push(Sm(Tf(this,km,"f").subarray(0,Tf(this,Pm,"f")-1))),Pf(this,km,Tf(this,km,"f").subarray(Tf(this,Pm,"f"))),Pf(this,Pm,null);continue}const e=null!==Tf(this,Pm,"f")?n.preceding-1:n.preceding,t=Sm(Tf(this,km,"f").subarray(0,e));i.push(t),Pf(this,km,Tf(this,km,"f").subarray(n.index)),Pf(this,Pm,null)}return i}flush(){return Tf(this,km,"f").length?this.decode("\n"):[]}}function $m(e,t){for(let i=t??0;i<e.length;i++){if(10===e[i])return{preceding:i,index:i+1,carriage:!1};if(13===e[i])return{preceding:i,index:i+1,carriage:!0}}return null}function Em(e){for(let t=0;t<e.length-1;t++){if(10===e[t]&&10===e[t+1])return t+2;if(13===e[t]&&13===e[t+1])return t+2;if(13===e[t]&&10===e[t+1]&&t+3<e.length&&13===e[t+2]&&10===e[t+3])return t+4}return-1}km=new WeakMap,Pm=new WeakMap,Tm.NEWLINE_CHARS=new Set(["\n","\r"]),Tm.NEWLINE_REGEXP=/\r\n|[\n\r]/g;const Am={off:0,error:200,warn:300,info:400,debug:500},Cm=(e,t,i)=>{if(e)return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(Am,e)?e:void Mm(i).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(Am))}`)};function Rm(){}function Qm(e,t,i){return!t||Am[e]>Am[i]?Rm:t[e].bind(t)}const Im={error:Rm,warn:Rm,info:Rm,debug:Rm};let jm=new WeakMap;function Mm(e){const t=e.logger,i=e.logLevel??"off";if(!t)return Im;const n=jm.get(t);if(n&&n[0]===i)return n[1];const r={error:Qm("error",t,i),warn:Qm("warn",t,i),info:Qm("info",t,i),debug:Qm("debug",t,i)};return jm.set(t,[i,r]),r}const Nm=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&(e.headers=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,"authorization"===e.toLowerCase()||"cookie"===e.toLowerCase()||"set-cookie"===e.toLowerCase()?"***":t]))),"retryOfRequestLogID"in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e);var Lm,Zm,Dm;class zm{constructor(e,t,i){this.iterator=e,Lm.set(this,void 0),this.controller=t,Pf(this,Lm,i)}static fromSSEResponse(e,t,i){let n=!1;const r=i?Mm(i):console;return new zm(async function*(){if(n)throw new Cf("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let i=!1;try{for await(const n of async function*(e,t){if(!e.body){if(t.abort(),void 0!==globalThis.navigator&&"ReactNative"===globalThis.navigator.product)throw new Cf("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api");throw new Cf("Attempted to iterate over a response with no body")}const i=new Um,n=new Tm,r=sm(e.body);for await(const s of async function*(e){let t=new Uint8Array;for await(const i of e){if(null==i)continue;const e=i instanceof ArrayBuffer?new Uint8Array(i):"string"==typeof i?xm(i):i;let n,r=new Uint8Array(t.length+e.length);for(r.set(t),r.set(e,t.length),t=r;-1!==(n=Em(t));)yield t.slice(0,n),t=t.slice(n)}t.length>0&&(yield t)}(r))for(const e of n.decode(s)){const t=i.decode(e);t&&(yield t)}for(const s of n.flush()){const e=i.decode(s);e&&(yield e)}}(e,t))if(!i)if(n.data.startsWith("[DONE]"))i=!0;else if(null!==n.event&&n.event.startsWith("thread.")){let e;try{e=JSON.parse(n.data)}catch(s){throw s}if("error"==n.event)throw new Rf(void 0,e.error,e.message,void 0);yield{event:n.event,data:e}}else{let t;try{t=JSON.parse(n.data)}catch(s){throw r.error("Could not parse message into JSON:",n.data),r.error("From chunk:",n.raw),s}if(t&&t.error)throw new Rf(void 0,t.error,void 0,e.headers);yield t}i=!0}catch(s){if(Ef(s))return;throw s}finally{i||t.abort()}},t,i)}static fromReadableStream(e,t,i){let n=!1;return new zm(async function*(){if(n)throw new Cf("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let i=!1;try{for await(const t of async function*(){const t=new Tm,i=sm(e);for await(const e of i)for(const i of t.decode(e))yield i;for(const e of t.flush())yield e}())i||t&&(yield JSON.parse(t));i=!0}catch(r){if(Ef(r))return;throw r}finally{i||t.abort()}},t,i)}[(Lm=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){const e=[],t=[],i=this.iterator(),n=n=>({next:()=>{if(0===n.length){const n=i.next();e.push(n),t.push(n)}return n.shift()}});return[new zm(()=>n(e),this.controller,Tf(this,Lm,"f")),new zm(()=>n(t),this.controller,Tf(this,Lm,"f"))]}toReadableStream(){const e=this;let t;return nm({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{const{value:i,done:n}=await t.next();if(n)return e.close();const r=xm(JSON.stringify(i)+"\n");e.enqueue(r)}catch($M){e.error($M)}},async cancel(){var e;await(null==(e=t.return)?void 0:e.call(t))}})}}class Um{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const e={event:this.event,data:this.data.join("\n"),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(":"))return null;let[t,i,n]=function(e,t){const i=e.indexOf(t);if(-1!==i)return[e.substring(0,i),t,e.substring(i+t.length)];return[e,"",""]}(e,":");return n.startsWith(" ")&&(n=n.substring(1)),"event"===t?this.event=n:"data"===t&&this.data.push(n),null}}async function qm(e,t){const{response:i,requestLogID:n,retryOfRequestLogID:r,startTime:s}=t,a=await(async()=>{var n;if(t.options.stream)return Mm(e).debug("response",i.status,i.url,i.headers,i.body),t.options.__streamClass?t.options.__streamClass.fromSSEResponse(i,t.controller,e):zm.fromSSEResponse(i,t.controller,e);if(204===i.status)return null;if(t.options.__binaryResponse)return i;const r=i.headers.get("content-type"),s=null==(n=null==r?void 0:r.split(";")[0])?void 0:n.trim();if((null==s?void 0:s.includes("application/json"))||(null==s?void 0:s.endsWith("+json"))){return Xm(await i.json(),i)}return await i.text()})();return Mm(e).debug(`[${n}] response parsed`,Nm({retryOfRequestLogID:r,url:i.url,status:i.status,body:a,durationMs:Date.now()-s})),a}function Xm(e,t){return!e||"object"!=typeof e||Array.isArray(e)?e:Object.defineProperty(e,"_request_id",{value:t.headers.get("x-request-id"),enumerable:!1})}class Bm extends Promise{constructor(e,t,i=qm){super(e=>{e(null)}),this.responsePromise=t,this.parseResponse=i,Zm.set(this,void 0),Pf(this,Zm,e)}_thenUnwrap(e){return new Bm(Tf(this,Zm,"f"),this.responsePromise,async(t,i)=>Xm(e(await this.parseResponse(t,i),i),i.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get("x-request-id")}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(e=>this.parseResponse(Tf(this,Zm,"f"),e))),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}}Zm=new WeakMap;class Wm{constructor(e,t,i,n){Dm.set(this,void 0),Pf(this,Dm,e),this.options=n,this.response=t,this.body=i}hasNextPage(){return!!this.getPaginatedItems().length&&null!=this.nextPageRequestOptions()}async getNextPage(){const e=this.nextPageRequestOptions();if(!e)throw new Cf("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");return await Tf(this,Dm,"f").requestAPIList(this.constructor,e)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(Dm=new WeakMap,Symbol.asyncIterator)](){for await(const e of this.iterPages())for(const t of e.getPaginatedItems())yield t}}class Vm extends Bm{constructor(e,t,i){super(e,t,async(e,t)=>new i(e,t.response,await qm(e,t),t.options))}async*[Symbol.asyncIterator](){const e=await(this);for await(const t of e)yield t}}class Fm extends Wm{constructor(e,t,i,n){super(e,t,i,n),this.data=i.data||[],this.object=i.object}getPaginatedItems(){return this.data??[]}nextPageRequestOptions(){return null}}class Ym extends Wm{constructor(e,t,i,n){super(e,t,i,n),this.data=i.data||[],this.has_more=i.has_more||!1}getPaginatedItems(){return this.data??[]}hasNextPage(){return!1!==this.has_more&&super.hasNextPage()}nextPageRequestOptions(){var e;const t=this.getPaginatedItems(),i=null==(e=t[t.length-1])?void 0:e.id;return i?{...this.options,query:{...(n=this.options.query,"object"!=typeof n?{}:n??{}),after:i}}:null;var n}}const Gm=()=>{var e;if("undefined"==typeof File){const{process:t}=globalThis,i="string"==typeof(null==(e=null==t?void 0:t.versions)?void 0:e.node)&&parseInt(t.versions.node.split("."))<20;throw new Error("`File` is not defined as a global, which is required for file uploads."+(i?" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.":""))}};function Hm(e,t,i){return Gm(),new File(e,t??"unknown_file",i)}function Km(e){return("object"==typeof e&&null!==e&&("name"in e&&e.name&&String(e.name)||"url"in e&&e.url&&String(e.url)||"filename"in e&&e.filename&&String(e.filename)||"path"in e&&e.path&&String(e.path))||"").split(/[\\/]/).pop()||void 0}const Jm=e=>null!=e&&"object"==typeof e&&"function"==typeof e[Symbol.asyncIterator],eg=async(e,t)=>({...e,body:await ig(e.body,t)}),tg=new WeakMap;const ig=async(e,t)=>{if(!(await function(e){const t="function"==typeof e?e:e.fetch,i=tg.get(t);if(i)return i;const n=(async()=>{try{const e="Response"in t?t.Response:(await t("data:,")).constructor,i=new FormData;return i.toString()!==await new e(i).text()}catch{return!0}})();return tg.set(t,n),n}(t)))throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");const i=new FormData;return await Promise.all(Object.entries(e||{}).map(([e,t])=>ng(i,e,t))),i},ng=async(e,t,i)=>{if(void 0!==i){if(null==i)throw new TypeError(`Received null for "${t}"; to pass null in FormData, you must use the string 'null'`);if("string"==typeof i||"number"==typeof i||"boolean"==typeof i)e.append(t,String(i));else if(i instanceof Response)e.append(t,Hm([await i.blob()],Km(i)));else if(Jm(i))e.append(t,Hm([await new Response(rm(i)).blob()],Km(i)));else if((e=>e instanceof Blob&&"name"in e)(i))e.append(t,i,Km(i));else if(Array.isArray(i))await Promise.all(i.map(i=>ng(e,t+"[]",i)));else{if("object"!=typeof i)throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${i} instead`);await Promise.all(Object.entries(i).map(([i,n])=>ng(e,`${t}[${i}]`,n)))}}},rg=e=>null!=e&&"object"==typeof e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.text&&"function"==typeof e.slice&&"function"==typeof e.arrayBuffer;async function sg(e){var t;let i=[];if("string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)i.push(e);else if(rg(e))i.push(e instanceof Blob?e:await e.arrayBuffer());else{if(!Jm(e)){const i=null==(t=null==e?void 0:e.constructor)?void 0:t.name;throw new Error(`Unexpected data type: ${typeof e}${i?`; constructor: ${i}`:""}${function(e){if("object"!=typeof e||null===e)return"";const t=Object.getOwnPropertyNames(e);return`; props: [${t.map(e=>`"${e}"`).join(", ")}]`}(e)}`)}for await(const t of e)i.push(...await sg(t))}return i}class ag{constructor(e){this._client=e}}function og(e){return e.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}const lg=Object.freeze(Object.create(null)),cg=(e=og)=>function(t,...i){if(1===t.length)return t[0];let n=!1;const r=[],s=t.reduce((t,s,a)=>{var o;/[?#]/.test(s)&&(n=!0);const l=i[a];let c=(n?encodeURIComponent:e)(""+l);return a!==i.length&&(null==l||"object"==typeof l&&l.toString===(null==(o=Object.getPrototypeOf(Object.getPrototypeOf(l.hasOwnProperty??lg)??lg))?void 0:o.toString))&&(c=l+"",r.push({start:t.length+s.length,length:c.length,error:`Value of type ${Object.prototype.toString.call(l).slice(8,-1)} is not a valid path parameter`})),t+s+(a===i.length?"":c)},""),a=s.split(/[?#]/,1)[0],o=new RegExp("(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)","gi");let l;for(;null!==(l=o.exec(a));)r.push({start:l.index,length:l[0].length,error:`Value "${l[0]}" can't be safely passed as a path parameter`});if(r.sort((e,t)=>e.start-t.start),r.length>0){let e=0;const t=r.reduce((t,i)=>{const n=" ".repeat(i.start-e),r="^".repeat(i.length);return e=i.start+i.length,t+n+r},"");throw new Cf(`Path parameters result in path with invalid segments:\n${r.map(e=>e.error).join("\n")}\n${s}\n${t}`)}return s},hg=cg(og);let ug=class extends ag{list(e,t={},i){return this._client.getAPIList(hg`/chat/completions/${e}/messages`,Ym,{query:t,...i})}};function dg(e){return void 0!==e&&"function"in e&&void 0!==e.function}function pg(e){return"auto-parseable-response-format"===(null==e?void 0:e.$brand)}function fg(e){return"auto-parseable-tool"===(null==e?void 0:e.$brand)}function mg(e,t){const i=e.choices.map(e=>{var i;if("length"===e.finish_reason)throw new Xf;if("content_filter"===e.finish_reason)throw new Bf;return yg(e.message.tool_calls),{...e,message:{...e.message,...e.message.tool_calls?{tool_calls:(null==(i=e.message.tool_calls)?void 0:i.map(e=>function(e,t){var i;const n=null==(i=e.tools)?void 0:i.find(e=>{var i;return dg(e)&&(null==(i=e.function)?void 0:i.name)===t.function.name});return{...t,function:{...t.function,parsed_arguments:fg(n)?n.$parseRaw(t.function.arguments):(null==n?void 0:n.function.strict)?JSON.parse(t.function.arguments):null}}}(t,e)))??void 0}:void 0,parsed:e.message.content&&!e.message.refusal?gg(t,e.message.content):null}}});return{...e,choices:i}}function gg(e,t){var i,n;if("json_schema"!==(null==(i=e.response_format)?void 0:i.type))return null;if("json_schema"===(null==(n=e.response_format)?void 0:n.type)){if("$parseRaw"in e.response_format){return e.response_format.$parseRaw(t)}return JSON.parse(t)}return null}function Og(e,t){var i;if(!e||!("tools"in e)||!e.tools)return!1;const n=null==(i=e.tools)?void 0:i.find(e=>{var i;return dg(e)&&(null==(i=e.function)?void 0:i.name)===t.function.name});return dg(n)&&(fg(n)||(null==n?void 0:n.function.strict)||!1)}function vg(e){var t;return!!pg(e.response_format)||((null==(t=e.tools)?void 0:t.some(e=>fg(e)||"function"===e.type&&!0===e.function.strict))??!1)}function yg(e){for(const t of e||[])if("function"!==t.type)throw new Cf(`Currently only \`function\` tool calls are supported; Received \`${t.type}\``)}const bg=e=>"assistant"===(null==e?void 0:e.role),wg=e=>"tool"===(null==e?void 0:e.role);var _g,xg,Sg,kg,Pg,Tg,$g,Eg,Ag,Cg,Rg,Qg,Ig,jg,Mg,Ng,Lg,Zg,Dg,zg,Ug;class qg{constructor(){_g.add(this),this.controller=new AbortController,xg.set(this,void 0),Sg.set(this,()=>{}),kg.set(this,()=>{}),Pg.set(this,void 0),Tg.set(this,()=>{}),$g.set(this,()=>{}),Eg.set(this,{}),Ag.set(this,!1),Cg.set(this,!1),Rg.set(this,!1),Qg.set(this,!1),Pf(this,xg,new Promise((e,t)=>{Pf(this,Sg,e),Pf(this,kg,t)})),Pf(this,Pg,new Promise((e,t)=>{Pf(this,Tg,e),Pf(this,$g,t)})),Tf(this,xg,"f").catch(()=>{}),Tf(this,Pg,"f").catch(()=>{})}_run(e){setTimeout(()=>{e().then(()=>{this._emitFinal(),this._emit("end")},Tf(this,_g,"m",Ig).bind(this))},0)}_connected(){this.ended||(Tf(this,Sg,"f").call(this),this._emit("connect"))}get ended(){return Tf(this,Ag,"f")}get errored(){return Tf(this,Cg,"f")}get aborted(){return Tf(this,Rg,"f")}abort(){this.controller.abort()}on(e,t){return(Tf(this,Eg,"f")[e]||(Tf(this,Eg,"f")[e]=[])).push({listener:t}),this}off(e,t){const i=Tf(this,Eg,"f")[e];if(!i)return this;const n=i.findIndex(e=>e.listener===t);return n>=0&&i.splice(n,1),this}once(e,t){return(Tf(this,Eg,"f")[e]||(Tf(this,Eg,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,i)=>{Pf(this,Qg,!0),"error"!==e&&this.once("error",i),this.once(e,t)})}async done(){Pf(this,Qg,!0),await Tf(this,Pg,"f")}_emit(e,...t){if(Tf(this,Ag,"f"))return;"end"===e&&(Pf(this,Ag,!0),Tf(this,Tg,"f").call(this));const i=Tf(this,Eg,"f")[e];if(i&&(Tf(this,Eg,"f")[e]=i.filter(e=>!e.once),i.forEach(({listener:e})=>e(...t))),"abort"===e){const e=t[0];return Tf(this,Qg,"f")||(null==i?void 0:i.length)||Promise.reject(e),Tf(this,kg,"f").call(this,e),Tf(this,$g,"f").call(this,e),void this._emit("end")}if("error"===e){const e=t[0];Tf(this,Qg,"f")||(null==i?void 0:i.length)||Promise.reject(e),Tf(this,kg,"f").call(this,e),Tf(this,$g,"f").call(this,e),this._emit("end")}}_emitFinal(){}}function Xg(e){return"function"==typeof e.parse}xg=new WeakMap,Sg=new WeakMap,kg=new WeakMap,Pg=new WeakMap,Tg=new WeakMap,$g=new WeakMap,Eg=new WeakMap,Ag=new WeakMap,Cg=new WeakMap,Rg=new WeakMap,Qg=new WeakMap,_g=new WeakSet,Ig=function(e){if(Pf(this,Cg,!0),e instanceof Error&&"AbortError"===e.name&&(e=new Qf),e instanceof Qf)return Pf(this,Rg,!0),this._emit("abort",e);if(e instanceof Cf)return this._emit("error",e);if(e instanceof Error){const t=new Cf(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new Cf(String(e)))};const Bg=10;class Wg extends qg{constructor(){super(...arguments),jg.add(this),this._chatCompletions=[],this.messages=[]}_addChatCompletion(e){var t;this._chatCompletions.push(e),this._emit("chatCompletion",e);const i=null==(t=e.choices[0])?void 0:t.message;return i&&this._addMessage(i),e}_addMessage(e,t=!0){if("content"in e||(e.content=null),this.messages.push(e),t)if(this._emit("message",e),wg(e)&&e.content)this._emit("functionToolCallResult",e.content);else if(bg(e)&&e.tool_calls)for(const i of e.tool_calls)"function"===i.type&&this._emit("functionToolCall",i.function)}async finalChatCompletion(){await this.done();const e=this._chatCompletions[this._chatCompletions.length-1];if(!e)throw new Cf("stream ended without producing a ChatCompletion");return e}async finalContent(){return await this.done(),Tf(this,jg,"m",Mg).call(this)}async finalMessage(){return await this.done(),Tf(this,jg,"m",Ng).call(this)}async finalFunctionToolCall(){return await this.done(),Tf(this,jg,"m",Lg).call(this)}async finalFunctionToolCallResult(){return await this.done(),Tf(this,jg,"m",Zg).call(this)}async totalUsage(){return await this.done(),Tf(this,jg,"m",Dg).call(this)}allChatCompletions(){return[...this._chatCompletions]}_emitFinal(){const e=this._chatCompletions[this._chatCompletions.length-1];e&&this._emit("finalChatCompletion",e);const t=Tf(this,jg,"m",Ng).call(this);t&&this._emit("finalMessage",t);const i=Tf(this,jg,"m",Mg).call(this);i&&this._emit("finalContent",i);const n=Tf(this,jg,"m",Lg).call(this);n&&this._emit("finalFunctionToolCall",n);const r=Tf(this,jg,"m",Zg).call(this);null!=r&&this._emit("finalFunctionToolCallResult",r),this._chatCompletions.some(e=>e.usage)&&this._emit("totalUsage",Tf(this,jg,"m",Dg).call(this))}async _createChatCompletion(e,t,i){const n=null==i?void 0:i.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),Tf(this,jg,"m",zg).call(this,t);const r=await e.chat.completions.create({...t,stream:!1},{...i,signal:this.controller.signal});return this._connected(),this._addChatCompletion(mg(r,t))}async _runChatCompletion(e,t,i){for(const n of t.messages)this._addMessage(n,!1);return await this._createChatCompletion(e,t,i)}async _runTools(e,t,i){var n,r,s;const a="tool",{tool_choice:o="auto",stream:l,...c}=t,h="string"!=typeof o&&"function"===o.type&&(null==(n=null==o?void 0:o.function)?void 0:n.name),{maxChatCompletions:u=Bg}=i||{},d=t.tools.map(e=>{if(fg(e)){if(!e.$callback)throw new Cf("Tool given to `.runTools()` that does not have an associated function");return{type:"function",function:{function:e.$callback,name:e.function.name,description:e.function.description||"",parameters:e.function.parameters,parse:e.$parseRaw,strict:!0}}}return e}),p={};for(const g of d)"function"===g.type&&(p[g.function.name||g.function.function.name]=g.function);const f="tools"in t?d.map(e=>"function"===e.type?{type:"function",function:{name:e.function.name||e.function.function.name,parameters:e.function.parameters,description:e.function.description,strict:e.function.strict}}:e):void 0;for(const g of t.messages)this._addMessage(g,!1);for(let g=0;g<u;++g){const t=null==(r=(await this._createChatCompletion(e,{...c,tool_choice:o,tools:f,messages:[...this.messages]},i)).choices[0])?void 0:r.message;if(!t)throw new Cf("missing message in ChatCompletion response");if(!(null==(s=t.tool_calls)?void 0:s.length))return;for(const e of t.tool_calls){if("function"!==e.type)continue;const t=e.id,{name:i,arguments:n}=e.function,r=p[i];if(!r){const e=`Invalid tool_call: ${JSON.stringify(i)}. Available options are: ${Object.keys(p).map(e=>JSON.stringify(e)).join(", ")}. Please try again`;this._addMessage({role:a,tool_call_id:t,content:e});continue}if(h&&h!==i){const e=`Invalid tool_call: ${JSON.stringify(i)}. ${JSON.stringify(h)} requested. Please try again`;this._addMessage({role:a,tool_call_id:t,content:e});continue}let s;try{s=Xg(r)?await r.parse(n):n}catch(m){const e=m instanceof Error?m.message:String(m);this._addMessage({role:a,tool_call_id:t,content:e});continue}const o=await r.function(s,this),l=Tf(this,jg,"m",Ug).call(this,o);if(this._addMessage({role:a,tool_call_id:t,content:l}),h)return}}}}jg=new WeakSet,Mg=function(){return Tf(this,jg,"m",Ng).call(this).content??null},Ng=function(){let e=this.messages.length;for(;e-- >0;){const t=this.messages[e];if(bg(t)){return{...t,content:t.content??null,refusal:t.refusal??null}}}throw new Cf("stream ended without producing a ChatCompletionMessage with role=assistant")},Lg=function(){var e,t;for(let i=this.messages.length-1;i>=0;i--){const n=this.messages[i];if(bg(n)&&(null==(e=null==n?void 0:n.tool_calls)?void 0:e.length))return null==(t=n.tool_calls.filter(e=>"function"===e.type).at(-1))?void 0:t.function}},Zg=function(){for(let e=this.messages.length-1;e>=0;e--){const t=this.messages[e];if(wg(t)&&null!=t.content&&"string"==typeof t.content&&this.messages.some(e=>{var i;return"assistant"===e.role&&(null==(i=e.tool_calls)?void 0:i.some(e=>"function"===e.type&&e.id===t.tool_call_id))}))return t.content}},Dg=function(){const e={completion_tokens:0,prompt_tokens:0,total_tokens:0};for(const{usage:t}of this._chatCompletions)t&&(e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens);return e},zg=function(e){if(null!=e.n&&e.n>1)throw new Cf("ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.")},Ug=function(e){return"string"==typeof e?e:void 0===e?"undefined":JSON.stringify(e)};class Vg extends Wg{static runTools(e,t,i){const n=new Vg,r={...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"runTools"}};return n._run(()=>n._runTools(e,t,r)),n}_addMessage(e,t=!0){super._addMessage(e,t),bg(e)&&e.content&&this._emit("content",e.content)}}const Fg=1,Yg=2,Gg=4,Hg=8,Kg=16,Jg=32,eO=64,tO=128,iO=256,nO=511;class rO extends Error{}class sO extends Error{}const aO=(e,t)=>{const i=e.length;let n=0;const r=e=>{throw new rO(`${e} at position ${n}`)},s=e=>{throw new sO(`${e} at position ${n}`)},a=()=>(u(),n>=i&&r("Unexpected end of input"),'"'===e[n]?o():"{"===e[n]?l():"["===e[n]?c():"null"===e.substring(n,n+4)||Kg&t&&i-n<4&&"null".startsWith(e.substring(n))?(n+=4,null):"true"===e.substring(n,n+4)||Jg&t&&i-n<4&&"true".startsWith(e.substring(n))?(n+=4,!0):"false"===e.substring(n,n+5)||Jg&t&&i-n<5&&"false".startsWith(e.substring(n))?(n+=5,!1):"Infinity"===e.substring(n,n+8)||tO&t&&i-n<8&&"Infinity".startsWith(e.substring(n))?(n+=8,1/0):"-Infinity"===e.substring(n,n+9)||iO&t&&1<i-n&&i-n<9&&"-Infinity".startsWith(e.substring(n))?(n+=9,-1/0):"NaN"===e.substring(n,n+3)||eO&t&&i-n<3&&"NaN".startsWith(e.substring(n))?(n+=3,NaN):h()),o=()=>{const a=n;let o=!1;for(n++;n<i&&('"'!==e[n]||o&&"\\"===e[n-1]);)o="\\"===e[n]&&!o,n++;if('"'==e.charAt(n))try{return JSON.parse(e.substring(a,++n-Number(o)))}catch(l){s(String(l))}else if(Fg&t)try{return JSON.parse(e.substring(a,n-Number(o))+'"')}catch(l){return JSON.parse(e.substring(a,e.lastIndexOf("\\"))+'"')}r("Unterminated string literal")},l=()=>{n++,u();const s={};try{for(;"}"!==e[n];){if(u(),n>=i&&Hg&t)return s;const r=o();u(),n++;try{const e=a();Object.defineProperty(s,r,{value:e,writable:!0,enumerable:!0,configurable:!0})}catch(l){if(Hg&t)return s;throw l}u(),","===e[n]&&n++}}catch(l){if(Hg&t)return s;r("Expected '}' at end of object")}return n++,s},c=()=>{n++;const i=[];try{for(;"]"!==e[n];)i.push(a()),u(),","===e[n]&&n++}catch(s){if(Gg&t)return i;r("Expected ']' at end of array")}return n++,i},h=()=>{if(0===n){"-"===e&&Yg&t&&r("Not sure what '-' is");try{return JSON.parse(e)}catch(o){if(Yg&t)try{return"."===e[e.length-1]?JSON.parse(e.substring(0,e.lastIndexOf("."))):JSON.parse(e.substring(0,e.lastIndexOf("e")))}catch(l){}s(String(o))}}const a=n;for("-"===e[n]&&n++;e[n]&&!",]}".includes(e[n]);)n++;n!=i||Yg&t||r("Unterminated number literal");try{return JSON.parse(e.substring(a,n))}catch(o){"-"===e.substring(a,n)&&Yg&t&&r("Not sure what '-' is");try{return JSON.parse(e.substring(a,e.lastIndexOf("e")))}catch(l){s(String(l))}}},u=()=>{for(;n<i&&" \n\r\t".includes(e[n]);)n++};return a()},oO=e=>function(e,t=nO){if("string"!=typeof e)throw new TypeError("expecting str, got "+typeof e);if(!e.trim())throw new Error(`${e} is empty`);return aO(e.trim(),t)}(e,nO^Yg);var lO,cO,hO,uO,dO,pO,fO,mO,gO,OO,vO,yO;class bO extends Wg{constructor(e){super(),lO.add(this),cO.set(this,void 0),hO.set(this,void 0),uO.set(this,void 0),Pf(this,cO,e),Pf(this,hO,[])}get currentChatCompletionSnapshot(){return Tf(this,uO,"f")}static fromReadableStream(e){const t=new bO(null);return t._run(()=>t._fromReadableStream(e)),t}static createChatCompletion(e,t,i){const n=new bO(t);return n._run(()=>n._runChatCompletion(e,{...t,stream:!0},{...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"stream"}})),n}async _createChatCompletion(e,t,i){var n;super._createChatCompletion;const r=null==i?void 0:i.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),Tf(this,lO,"m",dO).call(this);const s=await e.chat.completions.create({...t,stream:!0},{...i,signal:this.controller.signal});this._connected();for await(const a of s)Tf(this,lO,"m",fO).call(this,a);if(null==(n=s.controller.signal)?void 0:n.aborted)throw new Qf;return this._addChatCompletion(Tf(this,lO,"m",OO).call(this))}async _fromReadableStream(e,t){var i;const n=null==t?void 0:t.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),Tf(this,lO,"m",dO).call(this),this._connected();const r=zm.fromReadableStream(e,this.controller);let s;for await(const a of r)s&&s!==a.id&&this._addChatCompletion(Tf(this,lO,"m",OO).call(this)),Tf(this,lO,"m",fO).call(this,a),s=a.id;if(null==(i=r.controller.signal)?void 0:i.aborted)throw new Qf;return this._addChatCompletion(Tf(this,lO,"m",OO).call(this))}[(cO=new WeakMap,hO=new WeakMap,uO=new WeakMap,lO=new WeakSet,dO=function(){this.ended||Pf(this,uO,void 0)},pO=function(e){let t=Tf(this,hO,"f")[e.index];return t||(t={content_done:!1,refusal_done:!1,logprobs_content_done:!1,logprobs_refusal_done:!1,done_tool_calls:new Set,current_tool_call_index:null},Tf(this,hO,"f")[e.index]=t,t)},fO=function(e){var t,i,n,r,s,a,o,l,c,h,u,d,p,f,m;if(this.ended)return;const g=Tf(this,lO,"m",yO).call(this,e);this._emit("chunk",e,g);for(const O of e.choices){const e=g.choices[O.index];null!=O.delta.content&&"assistant"===(null==(t=e.message)?void 0:t.role)&&(null==(i=e.message)?void 0:i.content)&&(this._emit("content",O.delta.content,e.message.content),this._emit("content.delta",{delta:O.delta.content,snapshot:e.message.content,parsed:e.message.parsed})),null!=O.delta.refusal&&"assistant"===(null==(n=e.message)?void 0:n.role)&&(null==(r=e.message)?void 0:r.refusal)&&this._emit("refusal.delta",{delta:O.delta.refusal,snapshot:e.message.refusal}),null!=(null==(s=O.logprobs)?void 0:s.content)&&"assistant"===(null==(a=e.message)?void 0:a.role)&&this._emit("logprobs.content.delta",{content:null==(o=O.logprobs)?void 0:o.content,snapshot:(null==(l=e.logprobs)?void 0:l.content)??[]}),null!=(null==(c=O.logprobs)?void 0:c.refusal)&&"assistant"===(null==(h=e.message)?void 0:h.role)&&this._emit("logprobs.refusal.delta",{refusal:null==(u=O.logprobs)?void 0:u.refusal,snapshot:(null==(d=e.logprobs)?void 0:d.refusal)??[]});const v=Tf(this,lO,"m",pO).call(this,e);e.finish_reason&&(Tf(this,lO,"m",gO).call(this,e),null!=v.current_tool_call_index&&Tf(this,lO,"m",mO).call(this,e,v.current_tool_call_index));for(const t of O.delta.tool_calls??[])v.current_tool_call_index!==t.index&&(Tf(this,lO,"m",gO).call(this,e),null!=v.current_tool_call_index&&Tf(this,lO,"m",mO).call(this,e,v.current_tool_call_index)),v.current_tool_call_index=t.index;for(const t of O.delta.tool_calls??[]){const i=null==(p=e.message.tool_calls)?void 0:p[t.index];(null==i?void 0:i.type)&&("function"===(null==i?void 0:i.type)?this._emit("tool_calls.function.arguments.delta",{name:null==(f=i.function)?void 0:f.name,index:t.index,arguments:i.function.arguments,parsed_arguments:i.function.parsed_arguments,arguments_delta:(null==(m=t.function)?void 0:m.arguments)??""}):_O(null==i?void 0:i.type))}}},mO=function(e,t){var i,n,r;if(Tf(this,lO,"m",pO).call(this,e).done_tool_calls.has(t))return;const s=null==(i=e.message.tool_calls)?void 0:i[t];if(!s)throw new Error("no tool call snapshot");if(!s.type)throw new Error("tool call snapshot missing `type`");if("function"===s.type){const e=null==(r=null==(n=Tf(this,cO,"f"))?void 0:n.tools)?void 0:r.find(e=>dg(e)&&e.function.name===s.function.name);this._emit("tool_calls.function.arguments.done",{name:s.function.name,index:t,arguments:s.function.arguments,parsed_arguments:fg(e)?e.$parseRaw(s.function.arguments):(null==e?void 0:e.function.strict)?JSON.parse(s.function.arguments):null})}else s.type},gO=function(e){var t,i;const n=Tf(this,lO,"m",pO).call(this,e);if(e.message.content&&!n.content_done){n.content_done=!0;const t=Tf(this,lO,"m",vO).call(this);this._emit("content.done",{content:e.message.content,parsed:t?t.$parseRaw(e.message.content):null})}e.message.refusal&&!n.refusal_done&&(n.refusal_done=!0,this._emit("refusal.done",{refusal:e.message.refusal})),(null==(t=e.logprobs)?void 0:t.content)&&!n.logprobs_content_done&&(n.logprobs_content_done=!0,this._emit("logprobs.content.done",{content:e.logprobs.content})),(null==(i=e.logprobs)?void 0:i.refusal)&&!n.logprobs_refusal_done&&(n.logprobs_refusal_done=!0,this._emit("logprobs.refusal.done",{refusal:e.logprobs.refusal}))},OO=function(){if(this.ended)throw new Cf("stream has ended, this shouldn't happen");const e=Tf(this,uO,"f");if(!e)throw new Cf("request ended without sending any chunks");return Pf(this,uO,void 0),Pf(this,hO,[]),function(e,t){const{id:i,choices:n,created:r,model:s,system_fingerprint:a,...o}=e,l={...o,id:i,choices:n.map(({message:t,finish_reason:i,index:n,logprobs:r,...s})=>{if(!i)throw new Cf(`missing finish_reason for choice ${n}`);const{content:a=null,function_call:o,tool_calls:l,...c}=t,h=t.role;if(!h)throw new Cf(`missing role for choice ${n}`);if(o){const{arguments:e,name:l}=o;if(null==e)throw new Cf(`missing function_call.arguments for choice ${n}`);if(!l)throw new Cf(`missing function_call.name for choice ${n}`);return{...s,message:{content:a,function_call:{arguments:e,name:l},role:h,refusal:t.refusal??null},finish_reason:i,index:n,logprobs:r}}return l?{...s,index:n,finish_reason:i,logprobs:r,message:{...c,role:h,content:a,refusal:t.refusal??null,tool_calls:l.map((t,i)=>{const{function:r,type:s,id:a,...o}=t,{arguments:l,name:c,...h}=r||{};if(null==a)throw new Cf(`missing choices[${n}].tool_calls[${i}].id\n${wO(e)}`);if(null==s)throw new Cf(`missing choices[${n}].tool_calls[${i}].type\n${wO(e)}`);if(null==c)throw new Cf(`missing choices[${n}].tool_calls[${i}].function.name\n${wO(e)}`);if(null==l)throw new Cf(`missing choices[${n}].tool_calls[${i}].function.arguments\n${wO(e)}`);return{...o,id:a,type:s,function:{...h,name:c,arguments:l}}})}}:{...s,message:{...c,content:a,role:h,refusal:t.refusal??null},finish_reason:i,index:n,logprobs:r}}),created:r,model:s,object:"chat.completion",...a?{system_fingerprint:a}:{}};return function(e,t){return t&&vg(t)?mg(e,t):{...e,choices:e.choices.map(e=>(yg(e.message.tool_calls),{...e,message:{...e.message,parsed:null,...e.message.tool_calls?{tool_calls:e.message.tool_calls}:void 0}}))}}(l,t)}(e,Tf(this,cO,"f"))},vO=function(){var e;const t=null==(e=Tf(this,cO,"f"))?void 0:e.response_format;return pg(t)?t:null},yO=function(e){var t,i,n,r;let s=Tf(this,uO,"f");const{choices:a,...o}=e;s?Object.assign(s,o):s=Pf(this,uO,{...o,choices:[]});for(const{delta:l,finish_reason:c,index:h,logprobs:u=null,...d}of e.choices){let e=s.choices[h];if(e||(e=s.choices[h]={finish_reason:c,index:h,message:{},logprobs:u,...d}),u)if(e.logprobs){const{content:n,refusal:r,...s}=u;Object.assign(e.logprobs,s),n&&((t=e.logprobs).content??(t.content=[]),e.logprobs.content.push(...n)),r&&((i=e.logprobs).refusal??(i.refusal=[]),e.logprobs.refusal.push(...r))}else e.logprobs=Object.assign({},u);if(c&&(e.finish_reason=c,Tf(this,cO,"f")&&vg(Tf(this,cO,"f")))){if("length"===c)throw new Xf;if("content_filter"===c)throw new Bf}if(Object.assign(e,d),!l)continue;const{content:a,refusal:o,function_call:p,role:f,tool_calls:m,...g}=l;if(Object.assign(e.message,g),o&&(e.message.refusal=(e.message.refusal||"")+o),f&&(e.message.role=f),p&&(e.message.function_call?(p.name&&(e.message.function_call.name=p.name),p.arguments&&((n=e.message.function_call).arguments??(n.arguments=""),e.message.function_call.arguments+=p.arguments)):e.message.function_call=p),a&&(e.message.content=(e.message.content||"")+a,!e.message.refusal&&Tf(this,lO,"m",vO).call(this)&&(e.message.parsed=oO(e.message.content))),m){e.message.tool_calls||(e.message.tool_calls=[]);for(const{index:t,id:i,type:n,function:s,...a}of m){const o=(r=e.message.tool_calls)[t]??(r[t]={});Object.assign(o,a),i&&(o.id=i),n&&(o.type=n),s&&(o.function??(o.function={name:s.name??"",arguments:""})),(null==s?void 0:s.name)&&(o.function.name=s.name),(null==s?void 0:s.arguments)&&(o.function.arguments+=s.arguments,Og(Tf(this,cO,"f"),o)&&(o.function.parsed_arguments=oO(o.function.arguments)))}}}return s},Symbol.asyncIterator)](){const e=[],t=[];let i=!1;return this.on("chunk",i=>{const n=t.shift();n?n.resolve(i):e.push(i)}),this.on("end",()=>{i=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),this.on("error",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),{next:async()=>{if(!e.length)return i?{value:void 0,done:!0}:new Promise((e,i)=>t.push({resolve:e,reject:i})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0});return{value:e.shift(),done:!1}},return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new zm(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}function wO(e){return JSON.stringify(e)}function _O(e){}class xO extends bO{static fromReadableStream(e){const t=new xO(null);return t._run(()=>t._fromReadableStream(e)),t}static runTools(e,t,i){const n=new xO(t),r={...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"runTools"}};return n._run(()=>n._runTools(e,t,r)),n}}let SO=class extends ag{constructor(){super(...arguments),this.messages=new ug(this._client)}create(e,t){return this._client.post("/chat/completions",{body:e,...t,stream:e.stream??!1})}retrieve(e,t){return this._client.get(hg`/chat/completions/${e}`,t)}update(e,t,i){return this._client.post(hg`/chat/completions/${e}`,{body:t,...i})}list(e={},t){return this._client.getAPIList("/chat/completions",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/chat/completions/${e}`,t)}parse(e,t){return function(e){for(const t of e??[]){if("function"!==t.type)throw new Cf(`Currently only \`function\` tool types support auto-parsing; Received \`${t.type}\``);if(!0!==t.function.strict)throw new Cf(`The \`${t.function.name}\` tool is not marked with \`strict: true\`. Only strict function tools can be auto-parsed`)}}(e.tools),this._client.chat.completions.create(e,{...t,headers:{...null==t?void 0:t.headers,"X-Stainless-Helper-Method":"chat.completions.parse"}})._thenUnwrap(t=>mg(t,e))}runTools(e,t){return e.stream?xO.runTools(this._client,e,t):Vg.runTools(this._client,e,t)}stream(e,t){return bO.createChatCompletion(this._client,e,t)}};SO.Messages=ug;class kO extends ag{constructor(){super(...arguments),this.completions=new SO(this._client)}}kO.Completions=SO;const PO=Symbol("brand.privateNullableHeaders");function*TO(e){if(!e)return;if(PO in e){const{values:t,nulls:i}=e;yield*t.entries();for(const e of i)yield[e,null];return}let t,i=!1;e instanceof Headers?t=e.entries():Yf(e)?t=e:(i=!0,t=Object.entries(e??{}));for(let n of t){const e=n[0];if("string"!=typeof e)throw new TypeError("expected header name to be a string");const t=Yf(n[1])?n[1]:[n[1]];let r=!1;for(const n of t)void 0!==n&&(i&&!r&&(r=!0,yield[e,null]),yield[e,n])}}const $O=e=>{const t=new Headers,i=new Set;for(const n of e){const e=new Set;for(const[r,s]of TO(n)){const n=r.toLowerCase();e.has(n)||(t.delete(r),e.add(n)),null===s?(t.delete(r),i.add(n)):(t.append(r,s),i.delete(n))}}return{[PO]:!0,values:t,nulls:i}};class EO extends ag{create(e,t){return this._client.post("/audio/speech",{body:e,...t,headers:$O([{Accept:"application/octet-stream"},null==t?void 0:t.headers]),__binaryResponse:!0})}}class AO extends ag{create(e,t){return this._client.post("/audio/transcriptions",eg({body:e,...t,stream:e.stream??!1,__metadata:{model:e.model}},this._client))}}class CO extends ag{create(e,t){return this._client.post("/audio/translations",eg({body:e,...t,__metadata:{model:e.model}},this._client))}}class RO extends ag{constructor(){super(...arguments),this.transcriptions=new AO(this._client),this.translations=new CO(this._client),this.speech=new EO(this._client)}}RO.Transcriptions=AO,RO.Translations=CO,RO.Speech=EO;class QO extends ag{create(e,t){return this._client.post("/batches",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/batches/${e}`,t)}list(e={},t){return this._client.getAPIList("/batches",Ym,{query:e,...t})}cancel(e,t){return this._client.post(hg`/batches/${e}/cancel`,t)}}class IO extends ag{create(e,t){return this._client.post("/assistants",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}retrieve(e,t){return this._client.get(hg`/assistants/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}update(e,t,i){return this._client.post(hg`/assistants/${e}`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e={},t){return this._client.getAPIList("/assistants",Ym,{query:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}delete(e,t){return this._client.delete(hg`/assistants/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}}class jO extends ag{create(e,t){return this._client.post("/realtime/sessions",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}}class MO extends ag{create(e,t){return this._client.post("/realtime/transcription_sessions",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}}class NO extends ag{constructor(){super(...arguments),this.sessions=new jO(this._client),this.transcriptionSessions=new MO(this._client)}}NO.Sessions=jO,NO.TranscriptionSessions=MO;class LO extends ag{create(e,t,i){return this._client.post(hg`/threads/${e}/messages`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}retrieve(e,t,i){const{thread_id:n}=t;return this._client.get(hg`/threads/${n}/messages/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}update(e,t,i){const{thread_id:n,...r}=t;return this._client.post(hg`/threads/${n}/messages/${e}`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t={},i){return this._client.getAPIList(hg`/threads/${e}/messages`,Ym,{query:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}delete(e,t,i){const{thread_id:n}=t;return this._client.delete(hg`/threads/${n}/messages/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}class ZO extends ag{retrieve(e,t,i){const{thread_id:n,run_id:r,...s}=t;return this._client.get(hg`/threads/${n}/runs/${r}/steps/${e}`,{query:s,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t,i){const{thread_id:n,...r}=t;return this._client.getAPIList(hg`/threads/${n}/runs/${e}/steps`,Ym,{query:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}const DO=e=>{var t,i,n,r,s;return void 0!==globalThis.process?(null==(i=null==(t=globalThis.process.env)?void 0:t[e])?void 0:i.trim())??void 0:void 0!==globalThis.Deno?null==(s=null==(r=null==(n=globalThis.Deno.env)?void 0:n.get)?void 0:r.call(n,e))?void 0:s.trim():void 0};var zO,UO,qO,XO,BO,WO,VO,FO,YO,GO,HO,KO,JO,ev,tv,iv,nv,rv,sv,av,ov,lv,cv;class hv extends qg{constructor(){super(...arguments),zO.add(this),qO.set(this,[]),XO.set(this,{}),BO.set(this,{}),WO.set(this,void 0),VO.set(this,void 0),FO.set(this,void 0),YO.set(this,void 0),GO.set(this,void 0),HO.set(this,void 0),KO.set(this,void 0),JO.set(this,void 0),ev.set(this,void 0)}[(qO=new WeakMap,XO=new WeakMap,BO=new WeakMap,WO=new WeakMap,VO=new WeakMap,FO=new WeakMap,YO=new WeakMap,GO=new WeakMap,HO=new WeakMap,KO=new WeakMap,JO=new WeakMap,ev=new WeakMap,zO=new WeakSet,Symbol.asyncIterator)](){const e=[],t=[];let i=!1;return this.on("event",i=>{const n=t.shift();n?n.resolve(i):e.push(i)}),this.on("end",()=>{i=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),this.on("error",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),{next:async()=>{if(!e.length)return i?{value:void 0,done:!0}:new Promise((e,i)=>t.push({resolve:e,reject:i})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0});return{value:e.shift(),done:!1}},return:async()=>(this.abort(),{value:void 0,done:!0})}}static fromReadableStream(e){const t=new UO;return t._run(()=>t._fromReadableStream(e)),t}async _fromReadableStream(e,t){var i;const n=null==t?void 0:t.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),this._connected();const r=zm.fromReadableStream(e,this.controller);for await(const s of r)Tf(this,zO,"m",tv).call(this,s);if(null==(i=r.controller.signal)?void 0:i.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}toReadableStream(){return new zm(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}static createToolAssistantStream(e,t,i,n){const r=new UO;return r._run(()=>r._runToolAssistantStream(e,t,i,{...n,headers:{...null==n?void 0:n.headers,"X-Stainless-Helper-Method":"stream"}})),r}async _createToolAssistantStream(e,t,i,n){var r;const s=null==n?void 0:n.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort()));const a={...i,stream:!0},o=await e.submitToolOutputs(t,a,{...n,signal:this.controller.signal});this._connected();for await(const l of o)Tf(this,zO,"m",tv).call(this,l);if(null==(r=o.controller.signal)?void 0:r.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}static createThreadAssistantStream(e,t,i){const n=new UO;return n._run(()=>n._threadAssistantStream(e,t,{...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"stream"}})),n}static createAssistantStream(e,t,i,n){const r=new UO;return r._run(()=>r._runAssistantStream(e,t,i,{...n,headers:{...null==n?void 0:n.headers,"X-Stainless-Helper-Method":"stream"}})),r}currentEvent(){return Tf(this,KO,"f")}currentRun(){return Tf(this,JO,"f")}currentMessageSnapshot(){return Tf(this,WO,"f")}currentRunStepSnapshot(){return Tf(this,ev,"f")}async finalRunSteps(){return await this.done(),Object.values(Tf(this,XO,"f"))}async finalMessages(){return await this.done(),Object.values(Tf(this,BO,"f"))}async finalRun(){if(await this.done(),!Tf(this,VO,"f"))throw Error("Final run was not received.");return Tf(this,VO,"f")}async _createThreadAssistantStream(e,t,i){var n;const r=null==i?void 0:i.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort()));const s={...t,stream:!0},a=await e.createAndRun(s,{...i,signal:this.controller.signal});this._connected();for await(const o of a)Tf(this,zO,"m",tv).call(this,o);if(null==(n=a.controller.signal)?void 0:n.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}async _createAssistantStream(e,t,i,n){var r;const s=null==n?void 0:n.signal;s&&(s.aborted&&this.controller.abort(),s.addEventListener("abort",()=>this.controller.abort()));const a={...i,stream:!0},o=await e.create(t,a,{...n,signal:this.controller.signal});this._connected();for await(const l of o)Tf(this,zO,"m",tv).call(this,l);if(null==(r=o.controller.signal)?void 0:r.aborted)throw new Qf;return this._addRun(Tf(this,zO,"m",iv).call(this))}static accumulateDelta(e,t){for(const[i,n]of Object.entries(t)){if(!e.hasOwnProperty(i)){e[i]=n;continue}let t=e[i];if(null!=t)if("index"!==i&&"type"!==i){if("string"==typeof t&&"string"==typeof n)t+=n;else if("number"==typeof t&&"number"==typeof n)t+=n;else{if(!Gf(t)||!Gf(n)){if(Array.isArray(t)&&Array.isArray(n)){if(t.every(e=>"string"==typeof e||"number"==typeof e)){t.push(...n);continue}for(const e of n){if(!Gf(e))throw new Error(`Expected array delta entry to be an object but got: ${e}`);const i=e.index;if(null==i)throw new Error("Expected array delta entry to have an `index` property");if("number"!=typeof i)throw new Error(`Expected array delta entry \`index\` property to be a number but got ${i}`);const n=t[i];null==n?t.push(e):t[i]=this.accumulateDelta(n,e)}continue}throw Error(`Unhandled record type: ${i}, deltaValue: ${n}, accValue: ${t}`)}t=this.accumulateDelta(t,n)}e[i]=t}else e[i]=n;else e[i]=n}return e}_addRun(e){return e}async _threadAssistantStream(e,t,i){return await this._createThreadAssistantStream(t,e,i)}async _runAssistantStream(e,t,i,n){return await this._createAssistantStream(t,e,i,n)}async _runToolAssistantStream(e,t,i,n){return await this._createToolAssistantStream(t,e,i,n)}}UO=hv,tv=function(e){if(!this.ended)switch(Pf(this,KO,e),Tf(this,zO,"m",sv).call(this,e),e.event){case"thread.created":break;case"thread.run.created":case"thread.run.queued":case"thread.run.in_progress":case"thread.run.requires_action":case"thread.run.completed":case"thread.run.incomplete":case"thread.run.failed":case"thread.run.cancelling":case"thread.run.cancelled":case"thread.run.expired":Tf(this,zO,"m",cv).call(this,e);break;case"thread.run.step.created":case"thread.run.step.in_progress":case"thread.run.step.delta":case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":Tf(this,zO,"m",rv).call(this,e);break;case"thread.message.created":case"thread.message.in_progress":case"thread.message.delta":case"thread.message.completed":case"thread.message.incomplete":Tf(this,zO,"m",nv).call(this,e);break;case"error":throw new Error("Encountered an error event in event processing - errors should be processed earlier")}},iv=function(){if(this.ended)throw new Cf("stream has ended, this shouldn't happen");if(!Tf(this,VO,"f"))throw Error("Final run has not been received");return Tf(this,VO,"f")},nv=function(e){const[t,i]=Tf(this,zO,"m",ov).call(this,e,Tf(this,WO,"f"));Pf(this,WO,t),Tf(this,BO,"f")[t.id]=t;for(const n of i){const e=t.content[n.index];"text"==(null==e?void 0:e.type)&&this._emit("textCreated",e.text)}switch(e.event){case"thread.message.created":this._emit("messageCreated",e.data);break;case"thread.message.in_progress":break;case"thread.message.delta":if(this._emit("messageDelta",e.data.delta,t),e.data.delta.content)for(const i of e.data.delta.content){if("text"==i.type&&i.text){let e=i.text,n=t.content[i.index];if(!n||"text"!=n.type)throw Error("The snapshot associated with this text delta is not text or missing");this._emit("textDelta",e,n.text)}if(i.index!=Tf(this,FO,"f")){if(Tf(this,YO,"f"))switch(Tf(this,YO,"f").type){case"text":this._emit("textDone",Tf(this,YO,"f").text,Tf(this,WO,"f"));break;case"image_file":this._emit("imageFileDone",Tf(this,YO,"f").image_file,Tf(this,WO,"f"))}Pf(this,FO,i.index)}Pf(this,YO,t.content[i.index])}break;case"thread.message.completed":case"thread.message.incomplete":if(void 0!==Tf(this,FO,"f")){const t=e.data.content[Tf(this,FO,"f")];if(t)switch(t.type){case"image_file":this._emit("imageFileDone",t.image_file,Tf(this,WO,"f"));break;case"text":this._emit("textDone",t.text,Tf(this,WO,"f"))}}Tf(this,WO,"f")&&this._emit("messageDone",e.data),Pf(this,WO,void 0)}},rv=function(e){const t=Tf(this,zO,"m",av).call(this,e);switch(Pf(this,ev,t),e.event){case"thread.run.step.created":this._emit("runStepCreated",e.data);break;case"thread.run.step.delta":const i=e.data.delta;if(i.step_details&&"tool_calls"==i.step_details.type&&i.step_details.tool_calls&&"tool_calls"==t.step_details.type)for(const e of i.step_details.tool_calls)e.index==Tf(this,GO,"f")?this._emit("toolCallDelta",e,t.step_details.tool_calls[e.index]):(Tf(this,HO,"f")&&this._emit("toolCallDone",Tf(this,HO,"f")),Pf(this,GO,e.index),Pf(this,HO,t.step_details.tool_calls[e.index]),Tf(this,HO,"f")&&this._emit("toolCallCreated",Tf(this,HO,"f")));this._emit("runStepDelta",e.data.delta,t);break;case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":Pf(this,ev,void 0);"tool_calls"==e.data.step_details.type&&Tf(this,HO,"f")&&(this._emit("toolCallDone",Tf(this,HO,"f")),Pf(this,HO,void 0)),this._emit("runStepDone",e.data,t)}},sv=function(e){Tf(this,qO,"f").push(e),this._emit("event",e)},av=function(e){switch(e.event){case"thread.run.step.created":return Tf(this,XO,"f")[e.data.id]=e.data,e.data;case"thread.run.step.delta":let t=Tf(this,XO,"f")[e.data.id];if(!t)throw Error("Received a RunStepDelta before creation of a snapshot");let i=e.data;if(i.delta){const n=UO.accumulateDelta(t,i.delta);Tf(this,XO,"f")[e.data.id]=n}return Tf(this,XO,"f")[e.data.id];case"thread.run.step.completed":case"thread.run.step.failed":case"thread.run.step.cancelled":case"thread.run.step.expired":case"thread.run.step.in_progress":Tf(this,XO,"f")[e.data.id]=e.data}if(Tf(this,XO,"f")[e.data.id])return Tf(this,XO,"f")[e.data.id];throw new Error("No snapshot available")},ov=function(e,t){let i=[];switch(e.event){case"thread.message.created":return[e.data,i];case"thread.message.delta":if(!t)throw Error("Received a delta with no existing snapshot (there should be one from message creation)");let n=e.data;if(n.delta.content)for(const e of n.delta.content)if(e.index in t.content){let i=t.content[e.index];t.content[e.index]=Tf(this,zO,"m",lv).call(this,e,i)}else t.content[e.index]=e,i.push(e);return[t,i];case"thread.message.in_progress":case"thread.message.completed":case"thread.message.incomplete":if(t)return[t,i];throw Error("Received thread message event with no existing snapshot")}throw Error("Tried to accumulate a non-message event")},lv=function(e,t){return UO.accumulateDelta(t,e)},cv=function(e){switch(Pf(this,JO,e.data),e.event){case"thread.run.created":case"thread.run.queued":case"thread.run.in_progress":break;case"thread.run.requires_action":case"thread.run.cancelled":case"thread.run.failed":case"thread.run.completed":case"thread.run.expired":case"thread.run.incomplete":Pf(this,VO,e.data),Tf(this,HO,"f")&&(this._emit("toolCallDone",Tf(this,HO,"f")),Pf(this,HO,void 0))}};let uv=class extends ag{constructor(){super(...arguments),this.steps=new ZO(this._client)}create(e,t,i){const{include:n,...r}=t;return this._client.post(hg`/threads/${e}/runs`,{query:{include:n},body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers]),stream:t.stream??!1})}retrieve(e,t,i){const{thread_id:n}=t;return this._client.get(hg`/threads/${n}/runs/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}update(e,t,i){const{thread_id:n,...r}=t;return this._client.post(hg`/threads/${n}/runs/${e}`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t={},i){return this._client.getAPIList(hg`/threads/${e}/runs`,Ym,{query:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}cancel(e,t,i){const{thread_id:n}=t;return this._client.post(hg`/threads/${n}/runs/${e}/cancel`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async createAndPoll(e,t,i){const n=await this.create(e,t,i);return await this.poll(n.id,{thread_id:e},i)}createAndStream(e,t,i){return hv.createAssistantStream(e,this._client.beta.threads.runs,t,i)}async poll(e,t,i){var n;const r=$O([null==i?void 0:i.headers,{"X-Stainless-Poll-Helper":"true","X-Stainless-Custom-Poll-Interval":(null==(n=null==i?void 0:i.pollIntervalMs)?void 0:n.toString())??void 0}]);for(;;){const{data:n,response:s}=await this.retrieve(e,t,{...i,headers:{...null==i?void 0:i.headers,...r}}).withResponse();switch(n.status){case"queued":case"in_progress":case"cancelling":let e=5e3;if(null==i?void 0:i.pollIntervalMs)e=i.pollIntervalMs;else{const t=s.headers.get("openai-poll-after-ms");if(t){const i=parseInt(t);isNaN(i)||(e=i)}}await Hf(e);break;case"requires_action":case"incomplete":case"cancelled":case"completed":case"failed":case"expired":return n}}}stream(e,t,i){return hv.createAssistantStream(e,this._client.beta.threads.runs,t,i)}submitToolOutputs(e,t,i){const{thread_id:n,...r}=t;return this._client.post(hg`/threads/${n}/runs/${e}/submit_tool_outputs`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers]),stream:t.stream??!1})}async submitToolOutputsAndPoll(e,t,i){const n=await this.submitToolOutputs(e,t,i);return await this.poll(n.id,t,i)}submitToolOutputsStream(e,t,i){return hv.createToolAssistantStream(e,this._client.beta.threads.runs,t,i)}};uv.Steps=ZO;class dv extends ag{constructor(){super(...arguments),this.runs=new uv(this._client),this.messages=new LO(this._client)}create(e={},t){return this._client.post("/threads",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}retrieve(e,t){return this._client.get(hg`/threads/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}update(e,t,i){return this._client.post(hg`/threads/${e}`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}delete(e,t){return this._client.delete(hg`/threads/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}createAndRun(e,t){return this._client.post("/threads/runs",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers]),stream:e.stream??!1})}async createAndRunPoll(e,t){const i=await this.createAndRun(e,t);return await this.runs.poll(i.id,{thread_id:i.thread_id},t)}createAndRunStream(e,t){return hv.createThreadAssistantStream(e,this._client.beta.threads,t)}}dv.Runs=uv,dv.Messages=LO;class pv extends ag{constructor(){super(...arguments),this.realtime=new NO(this._client),this.assistants=new IO(this._client),this.threads=new dv(this._client)}}pv.Realtime=NO,pv.Assistants=IO,pv.Threads=dv;class fv extends ag{create(e,t){return this._client.post("/completions",{body:e,...t,stream:e.stream??!1})}}class mv extends ag{retrieve(e,t,i){const{container_id:n}=t;return this._client.get(hg`/containers/${n}/files/${e}/content`,{...i,headers:$O([{Accept:"application/binary"},null==i?void 0:i.headers]),__binaryResponse:!0})}}let gv=class extends ag{constructor(){super(...arguments),this.content=new mv(this._client)}create(e,t,i){return this._client.post(hg`/containers/${e}/files`,eg({body:t,...i},this._client))}retrieve(e,t,i){const{container_id:n}=t;return this._client.get(hg`/containers/${n}/files/${e}`,i)}list(e,t={},i){return this._client.getAPIList(hg`/containers/${e}/files`,Ym,{query:t,...i})}delete(e,t,i){const{container_id:n}=t;return this._client.delete(hg`/containers/${n}/files/${e}`,{...i,headers:$O([{Accept:"*/*"},null==i?void 0:i.headers])})}};gv.Content=mv;class Ov extends ag{constructor(){super(...arguments),this.files=new gv(this._client)}create(e,t){return this._client.post("/containers",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/containers/${e}`,t)}list(e={},t){return this._client.getAPIList("/containers",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/containers/${e}`,{...t,headers:$O([{Accept:"*/*"},null==t?void 0:t.headers])})}}Ov.Files=gv;class vv extends ag{create(e,t){const i=!!e.encoding_format;let n=i?e.encoding_format:"base64";i&&Mm(this._client).debug("embeddings/user defined encoding_format:",e.encoding_format);const r=this._client.post("/embeddings",{body:{...e,encoding_format:n},...t});return i?r:(Mm(this._client).debug("embeddings/decoding base64 embeddings from base64"),r._thenUnwrap(e=>(e&&e.data&&e.data.forEach(e=>{const t=e.embedding;e.embedding=(e=>{if("undefined"!=typeof Buffer){const t=Buffer.from(e,"base64");return Array.from(new Float32Array(t.buffer,t.byteOffset,t.length/Float32Array.BYTES_PER_ELEMENT))}{const t=atob(e),i=t.length,n=new Uint8Array(i);for(let e=0;e<i;e++)n[e]=t.charCodeAt(e);return Array.from(new Float32Array(n.buffer))}})(t)}),e)))}}class yv extends ag{retrieve(e,t,i){const{eval_id:n,run_id:r}=t;return this._client.get(hg`/evals/${n}/runs/${r}/output_items/${e}`,i)}list(e,t,i){const{eval_id:n,...r}=t;return this._client.getAPIList(hg`/evals/${n}/runs/${e}/output_items`,Ym,{query:r,...i})}}class bv extends ag{constructor(){super(...arguments),this.outputItems=new yv(this._client)}create(e,t,i){return this._client.post(hg`/evals/${e}/runs`,{body:t,...i})}retrieve(e,t,i){const{eval_id:n}=t;return this._client.get(hg`/evals/${n}/runs/${e}`,i)}list(e,t={},i){return this._client.getAPIList(hg`/evals/${e}/runs`,Ym,{query:t,...i})}delete(e,t,i){const{eval_id:n}=t;return this._client.delete(hg`/evals/${n}/runs/${e}`,i)}cancel(e,t,i){const{eval_id:n}=t;return this._client.post(hg`/evals/${n}/runs/${e}`,i)}}bv.OutputItems=yv;class wv extends ag{constructor(){super(...arguments),this.runs=new bv(this._client)}create(e,t){return this._client.post("/evals",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/evals/${e}`,t)}update(e,t,i){return this._client.post(hg`/evals/${e}`,{body:t,...i})}list(e={},t){return this._client.getAPIList("/evals",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/evals/${e}`,t)}}wv.Runs=bv;let _v=class extends ag{create(e,t){return this._client.post("/files",eg({body:e,...t},this._client))}retrieve(e,t){return this._client.get(hg`/files/${e}`,t)}list(e={},t){return this._client.getAPIList("/files",Ym,{query:e,...t})}delete(e,t){return this._client.delete(hg`/files/${e}`,t)}content(e,t){return this._client.get(hg`/files/${e}/content`,{...t,headers:$O([{Accept:"application/binary"},null==t?void 0:t.headers]),__binaryResponse:!0})}async waitForProcessing(e,{pollInterval:t=5e3,maxWait:i=18e5}={}){const n=new Set(["processed","error","deleted"]),r=Date.now();let s=await this.retrieve(e);for(;!s.status||!n.has(s.status);)if(await Hf(t),s=await this.retrieve(e),Date.now()-r>i)throw new jf({message:`Giving up on waiting for file ${e} to finish processing after ${i} milliseconds.`});return s}};class xv extends ag{}let Sv=class extends ag{run(e,t){return this._client.post("/fine_tuning/alpha/graders/run",{body:e,...t})}validate(e,t){return this._client.post("/fine_tuning/alpha/graders/validate",{body:e,...t})}};class kv extends ag{constructor(){super(...arguments),this.graders=new Sv(this._client)}}kv.Graders=Sv;class Pv extends ag{create(e,t,i){return this._client.getAPIList(hg`/fine_tuning/checkpoints/${e}/permissions`,Fm,{body:t,method:"post",...i})}retrieve(e,t={},i){return this._client.get(hg`/fine_tuning/checkpoints/${e}/permissions`,{query:t,...i})}delete(e,t,i){const{fine_tuned_model_checkpoint:n}=t;return this._client.delete(hg`/fine_tuning/checkpoints/${n}/permissions/${e}`,i)}}let Tv=class extends ag{constructor(){super(...arguments),this.permissions=new Pv(this._client)}};Tv.Permissions=Pv;class $v extends ag{list(e,t={},i){return this._client.getAPIList(hg`/fine_tuning/jobs/${e}/checkpoints`,Ym,{query:t,...i})}}class Ev extends ag{constructor(){super(...arguments),this.checkpoints=new $v(this._client)}create(e,t){return this._client.post("/fine_tuning/jobs",{body:e,...t})}retrieve(e,t){return this._client.get(hg`/fine_tuning/jobs/${e}`,t)}list(e={},t){return this._client.getAPIList("/fine_tuning/jobs",Ym,{query:e,...t})}cancel(e,t){return this._client.post(hg`/fine_tuning/jobs/${e}/cancel`,t)}listEvents(e,t={},i){return this._client.getAPIList(hg`/fine_tuning/jobs/${e}/events`,Ym,{query:t,...i})}pause(e,t){return this._client.post(hg`/fine_tuning/jobs/${e}/pause`,t)}resume(e,t){return this._client.post(hg`/fine_tuning/jobs/${e}/resume`,t)}}Ev.Checkpoints=$v;class Av extends ag{constructor(){super(...arguments),this.methods=new xv(this._client),this.jobs=new Ev(this._client),this.checkpoints=new Tv(this._client),this.alpha=new kv(this._client)}}Av.Methods=xv,Av.Jobs=Ev,Av.Checkpoints=Tv,Av.Alpha=kv;class Cv extends ag{}class Rv extends ag{constructor(){super(...arguments),this.graderModels=new Cv(this._client)}}Rv.GraderModels=Cv;class Qv extends ag{createVariation(e,t){return this._client.post("/images/variations",eg({body:e,...t},this._client))}edit(e,t){return this._client.post("/images/edits",eg({body:e,...t,stream:e.stream??!1},this._client))}generate(e,t){return this._client.post("/images/generations",{body:e,...t,stream:e.stream??!1})}}class Iv extends ag{retrieve(e,t){return this._client.get(hg`/models/${e}`,t)}list(e){return this._client.getAPIList("/models",Fm,e)}delete(e,t){return this._client.delete(hg`/models/${e}`,t)}}class jv extends ag{create(e,t){return this._client.post("/moderations",{body:e,...t})}}function Mv(e,t){return t&&function(e){var t;if(pg(null==(t=e.text)?void 0:t.format))return!0;return!1}(t)?Nv(e,t):{...e,output_parsed:null,output:e.output.map(e=>"function_call"===e.type?{...e,parsed_arguments:null}:"message"===e.type?{...e,content:e.content.map(e=>({...e,parsed:null}))}:e)}}function Nv(e,t){const i=e.output.map(e=>{if("function_call"===e.type)return{...e,parsed_arguments:Zv(t,e)};if("message"===e.type){const i=e.content.map(e=>"output_text"===e.type?{...e,parsed:Lv(t,e.text)}:e);return{...e,content:i}}return e}),n=Object.assign({},e,{output:i});return Object.getOwnPropertyDescriptor(e,"output_text")||Dv(n),Object.defineProperty(n,"output_parsed",{enumerable:!0,get(){for(const e of n.output)if("message"===e.type)for(const t of e.content)if("output_text"===t.type&&null!==t.parsed)return t.parsed;return null}}),n}function Lv(e,t){var i,n,r,s;if("json_schema"!==(null==(n=null==(i=e.text)?void 0:i.format)?void 0:n.type))return null;if("$parseRaw"in(null==(r=e.text)?void 0:r.format)){return(null==(s=e.text)?void 0:s.format).$parseRaw(t)}return JSON.parse(t)}function Zv(e,t){const i=(n=e.tools??[],r=t.name,n.find(e=>"function"===e.type&&e.name===r));var n,r,s;return{...t,...t,parsed_arguments:(s=i,"auto-parseable-tool"===(null==s?void 0:s.$brand)?i.$parseRaw(t.arguments):(null==i?void 0:i.strict)?JSON.parse(t.arguments):null)}}function Dv(e){const t=[];for(const i of e.output)if("message"===i.type)for(const e of i.content)"output_text"===e.type&&t.push(e.text);e.output_text=t.join("")}var zv,Uv,qv,Xv,Bv,Wv,Vv,Fv;class Yv extends qg{constructor(e){super(),zv.add(this),Uv.set(this,void 0),qv.set(this,void 0),Xv.set(this,void 0),Pf(this,Uv,e)}static createResponse(e,t,i){const n=new Yv(t);return n._run(()=>n._createOrRetrieveResponse(e,t,{...i,headers:{...null==i?void 0:i.headers,"X-Stainless-Helper-Method":"stream"}})),n}async _createOrRetrieveResponse(e,t,i){var n;const r=null==i?void 0:i.signal;let s;r&&(r.aborted&&this.controller.abort(),r.addEventListener("abort",()=>this.controller.abort())),Tf(this,zv,"m",Bv).call(this);let a=null;"response_id"in t?(s=await e.responses.retrieve(t.response_id,{stream:!0},{...i,signal:this.controller.signal,stream:!0}),a=t.starting_after??null):s=await e.responses.create({...t,stream:!0},{...i,signal:this.controller.signal}),this._connected();for await(const o of s)Tf(this,zv,"m",Wv).call(this,o,a);if(null==(n=s.controller.signal)?void 0:n.aborted)throw new Qf;return Tf(this,zv,"m",Vv).call(this)}[(Uv=new WeakMap,qv=new WeakMap,Xv=new WeakMap,zv=new WeakSet,Bv=function(){this.ended||Pf(this,qv,void 0)},Wv=function(e,t){if(this.ended)return;const i=(e,i)=>{(null==t||i.sequence_number>t)&&this._emit(e,i)},n=Tf(this,zv,"m",Fv).call(this,e);switch(i("event",e),e.type){case"response.output_text.delta":{const t=n.output[e.output_index];if(!t)throw new Cf(`missing output at index ${e.output_index}`);if("message"===t.type){const n=t.content[e.content_index];if(!n)throw new Cf(`missing content at index ${e.content_index}`);if("output_text"!==n.type)throw new Cf(`expected content to be 'output_text', got ${n.type}`);i("response.output_text.delta",{...e,snapshot:n.text})}break}case"response.function_call_arguments.delta":{const t=n.output[e.output_index];if(!t)throw new Cf(`missing output at index ${e.output_index}`);"function_call"===t.type&&i("response.function_call_arguments.delta",{...e,snapshot:t.arguments});break}default:i(e.type,e)}},Vv=function(){if(this.ended)throw new Cf("stream has ended, this shouldn't happen");const e=Tf(this,qv,"f");if(!e)throw new Cf("request ended without sending any events");Pf(this,qv,void 0);const t=function(e,t){return Mv(e,t)}(e,Tf(this,Uv,"f"));return Pf(this,Xv,t),t},Fv=function(e){let t=Tf(this,qv,"f");if(!t){if("response.created"!==e.type)throw new Cf(`When snapshot hasn't been set yet, expected 'response.created' event, got ${e.type}`);return t=Pf(this,qv,e.response),t}switch(e.type){case"response.output_item.added":t.output.push(e.item);break;case"response.content_part.added":{const i=t.output[e.output_index];if(!i)throw new Cf(`missing output at index ${e.output_index}`);"message"===i.type&&i.content.push(e.part);break}case"response.output_text.delta":{const i=t.output[e.output_index];if(!i)throw new Cf(`missing output at index ${e.output_index}`);if("message"===i.type){const t=i.content[e.content_index];if(!t)throw new Cf(`missing content at index ${e.content_index}`);if("output_text"!==t.type)throw new Cf(`expected content to be 'output_text', got ${t.type}`);t.text+=e.delta}break}case"response.function_call_arguments.delta":{const i=t.output[e.output_index];if(!i)throw new Cf(`missing output at index ${e.output_index}`);"function_call"===i.type&&(i.arguments+=e.delta);break}case"response.completed":Pf(this,qv,e.response)}return t},Symbol.asyncIterator)](){const e=[],t=[];let i=!1;return this.on("event",i=>{const n=t.shift();n?n.resolve(i):e.push(i)}),this.on("end",()=>{i=!0;for(const e of t)e.resolve(void 0);t.length=0}),this.on("abort",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),this.on("error",e=>{i=!0;for(const i of t)i.reject(e);t.length=0}),{next:async()=>{if(!e.length)return i?{value:void 0,done:!0}:new Promise((e,i)=>t.push({resolve:e,reject:i})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0});return{value:e.shift(),done:!1}},return:async()=>(this.abort(),{value:void 0,done:!0})}}async finalResponse(){await this.done();const e=Tf(this,Xv,"f");if(!e)throw new Cf("stream ended without producing a ChatCompletion");return e}}class Gv extends ag{list(e,t={},i){return this._client.getAPIList(hg`/responses/${e}/input_items`,Ym,{query:t,...i})}}class Hv extends ag{constructor(){super(...arguments),this.inputItems=new Gv(this._client)}create(e,t){return this._client.post("/responses",{body:e,...t,stream:e.stream??!1})._thenUnwrap(e=>("object"in e&&"response"===e.object&&Dv(e),e))}retrieve(e,t={},i){return this._client.get(hg`/responses/${e}`,{query:t,...i,stream:(null==t?void 0:t.stream)??!1})._thenUnwrap(e=>("object"in e&&"response"===e.object&&Dv(e),e))}delete(e,t){return this._client.delete(hg`/responses/${e}`,{...t,headers:$O([{Accept:"*/*"},null==t?void 0:t.headers])})}parse(e,t){return this._client.responses.create(e,t)._thenUnwrap(t=>Nv(t,e))}stream(e,t){return Yv.createResponse(this._client,e,t)}cancel(e,t){return this._client.post(hg`/responses/${e}/cancel`,t)}}Hv.InputItems=Gv;class Kv extends ag{create(e,t,i){return this._client.post(hg`/uploads/${e}/parts`,eg({body:t,...i},this._client))}}class Jv extends ag{constructor(){super(...arguments),this.parts=new Kv(this._client)}create(e,t){return this._client.post("/uploads",{body:e,...t})}cancel(e,t){return this._client.post(hg`/uploads/${e}/cancel`,t)}complete(e,t,i){return this._client.post(hg`/uploads/${e}/complete`,{body:t,...i})}}Jv.Parts=Kv;class ey extends ag{create(e,t,i){return this._client.post(hg`/vector_stores/${e}/file_batches`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}retrieve(e,t,i){const{vector_store_id:n}=t;return this._client.get(hg`/vector_stores/${n}/file_batches/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}cancel(e,t,i){const{vector_store_id:n}=t;return this._client.post(hg`/vector_stores/${n}/file_batches/${e}/cancel`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async createAndPoll(e,t,i){const n=await this.create(e,t);return await this.poll(e,n.id,i)}listFiles(e,t,i){const{vector_store_id:n,...r}=t;return this._client.getAPIList(hg`/vector_stores/${n}/file_batches/${e}/files`,Ym,{query:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async poll(e,t,i){var n;const r=$O([null==i?void 0:i.headers,{"X-Stainless-Poll-Helper":"true","X-Stainless-Custom-Poll-Interval":(null==(n=null==i?void 0:i.pollIntervalMs)?void 0:n.toString())??void 0}]);for(;;){const{data:n,response:s}=await this.retrieve(t,{vector_store_id:e},{...i,headers:r}).withResponse();switch(n.status){case"in_progress":let e=5e3;if(null==i?void 0:i.pollIntervalMs)e=i.pollIntervalMs;else{const t=s.headers.get("openai-poll-after-ms");if(t){const i=parseInt(t);isNaN(i)||(e=i)}}await Hf(e);break;case"failed":case"cancelled":case"completed":return n}}}async uploadAndPoll(e,{files:t,fileIds:i=[]},n){if(null==t||0==t.length)throw new Error("No `files` provided to process. If you've already uploaded files you should use `.createAndPoll()` instead");const r=(null==n?void 0:n.maxConcurrency)??5,s=Math.min(r,t.length),a=this._client,o=t.values(),l=[...i];const c=Array(s).fill(o).map(async function(e){for(let t of e){const e=await a.files.create({file:t,purpose:"assistants"},n);l.push(e.id)}});return await(async e=>{const t=await Promise.allSettled(e),i=t.filter(e=>"rejected"===e.status);if(i.length){for(const e of i);throw new Error(`${i.length} promise(s) failed - see the above errors`)}const n=[];for(const r of t)"fulfilled"===r.status&&n.push(r.value);return n})(c),await this.createAndPoll(e,{file_ids:l})}}class ty extends ag{create(e,t,i){return this._client.post(hg`/vector_stores/${e}/files`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}retrieve(e,t,i){const{vector_store_id:n}=t;return this._client.get(hg`/vector_stores/${n}/files/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}update(e,t,i){const{vector_store_id:n,...r}=t;return this._client.post(hg`/vector_stores/${n}/files/${e}`,{body:r,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e,t={},i){return this._client.getAPIList(hg`/vector_stores/${e}/files`,Ym,{query:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}delete(e,t,i){const{vector_store_id:n}=t;return this._client.delete(hg`/vector_stores/${n}/files/${e}`,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}async createAndPoll(e,t,i){const n=await this.create(e,t,i);return await this.poll(e,n.id,i)}async poll(e,t,i){var n;const r=$O([null==i?void 0:i.headers,{"X-Stainless-Poll-Helper":"true","X-Stainless-Custom-Poll-Interval":(null==(n=null==i?void 0:i.pollIntervalMs)?void 0:n.toString())??void 0}]);for(;;){const n=await this.retrieve(t,{vector_store_id:e},{...i,headers:r}).withResponse(),s=n.data;switch(s.status){case"in_progress":let e=5e3;if(null==i?void 0:i.pollIntervalMs)e=i.pollIntervalMs;else{const t=n.response.headers.get("openai-poll-after-ms");if(t){const i=parseInt(t);isNaN(i)||(e=i)}}await Hf(e);break;case"failed":case"completed":return s}}}async upload(e,t,i){const n=await this._client.files.create({file:t,purpose:"assistants"},i);return this.create(e,{file_id:n.id},i)}async uploadAndPoll(e,t,i){const n=await this.upload(e,t,i);return await this.poll(e,n.id,i)}content(e,t,i){const{vector_store_id:n}=t;return this._client.getAPIList(hg`/vector_stores/${n}/files/${e}/content`,Fm,{...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}class iy extends ag{constructor(){super(...arguments),this.files=new ty(this._client),this.fileBatches=new ey(this._client)}create(e,t){return this._client.post("/vector_stores",{body:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}retrieve(e,t){return this._client.get(hg`/vector_stores/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}update(e,t,i){return this._client.post(hg`/vector_stores/${e}`,{body:t,...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}list(e={},t){return this._client.getAPIList("/vector_stores",Ym,{query:e,...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}delete(e,t){return this._client.delete(hg`/vector_stores/${e}`,{...t,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==t?void 0:t.headers])})}search(e,t,i){return this._client.getAPIList(hg`/vector_stores/${e}/search`,Fm,{body:t,method:"post",...i,headers:$O([{"OpenAI-Beta":"assistants=v2"},null==i?void 0:i.headers])})}}var ny,ry,sy,ay,oy,ly,cy;iy.Files=ty,iy.FileBatches=ey;class hy extends ag{constructor(){super(...arguments),ny.add(this)}async unwrap(e,t,i=this._client.webhookSecret,n=300){return await this.verifySignature(e,t,i,n),JSON.parse(e)}async verifySignature(e,t,i=this._client.webhookSecret,n=300){if("undefined"==typeof crypto||"function"!=typeof crypto.subtle.importKey||"function"!=typeof crypto.subtle.verify)throw new Error("Webhook signature verification is only supported when the `crypto` global is defined");Tf(this,ny,"m",ry).call(this,i);const r=$O([t]).values,s=Tf(this,ny,"m",sy).call(this,r,"webhook-signature"),a=Tf(this,ny,"m",sy).call(this,r,"webhook-timestamp"),o=Tf(this,ny,"m",sy).call(this,r,"webhook-id"),l=parseInt(a,10);if(isNaN(l))throw new Wf("Invalid webhook timestamp format");const c=Math.floor(Date.now()/1e3);if(c-l>n)throw new Wf("Webhook timestamp is too old");if(l>c+n)throw new Wf("Webhook timestamp is too new");const h=s.split(" ").map(e=>e.startsWith("v1,")?e.substring(3):e),u=i.startsWith("whsec_")?Buffer.from(i.replace("whsec_",""),"base64"):Buffer.from(i,"utf-8"),d=o?`${o}.${a}.${e}`:`${a}.${e}`,p=await crypto.subtle.importKey("raw",u,{name:"HMAC",hash:"SHA-256"},!1,["verify"]);for(const f of h)try{const e=Buffer.from(f,"base64");if(await crypto.subtle.verify("HMAC",p,e,(new TextEncoder).encode(d)))return}catch{continue}throw new Wf("The given webhook signature does not match the expected signature")}}ny=new WeakSet,ry=function(e){if("string"!=typeof e||0===e.length)throw new Error("The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function")},sy=function(e,t){if(!e)throw new Error("Headers are required");const i=e.get(t);if(null==i)throw new Error(`Missing required header: ${t}`);return i};let uy=class{constructor({baseURL:e=DO("OPENAI_BASE_URL"),apiKey:t=DO("OPENAI_API_KEY"),organization:i=DO("OPENAI_ORG_ID")??null,project:n=DO("OPENAI_PROJECT_ID")??null,webhookSecret:r=DO("OPENAI_WEBHOOK_SECRET")??null,...s}={}){if(ay.add(this),ly.set(this,void 0),this.completions=new fv(this),this.chat=new kO(this),this.embeddings=new vv(this),this.files=new _v(this),this.images=new Qv(this),this.audio=new RO(this),this.moderations=new jv(this),this.models=new Iv(this),this.fineTuning=new Av(this),this.graders=new Rv(this),this.vectorStores=new iy(this),this.webhooks=new hy(this),this.beta=new pv(this),this.batches=new QO(this),this.uploads=new Jv(this),this.responses=new Hv(this),this.evals=new wv(this),this.containers=new Ov(this),void 0===t)throw new Cf("The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).");const a={apiKey:t,organization:i,project:n,webhookSecret:r,...s,baseURL:e||"https://api.openai.com/v1"};if(!a.dangerouslyAllowBrowser&&"undefined"!=typeof window&&void 0!==window.document&&"undefined"!=typeof navigator)throw new Cf("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n");this.baseURL=a.baseURL,this.timeout=a.timeout??oy.DEFAULT_TIMEOUT,this.logger=a.logger??console;const o="warn";this.logLevel=o,this.logLevel=Cm(a.logLevel,"ClientOptions.logLevel",this)??Cm(DO("OPENAI_LOG"),"process.env['OPENAI_LOG']",this)??o,this.fetchOptions=a.fetchOptions,this.maxRetries=a.maxRetries??2,this.fetch=a.fetch??function(){if("undefined"!=typeof fetch)return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}(),Pf(this,ly,am),this._options=a,this.apiKey=t,this.organization=i,this.project=n,this.webhookSecret=r}withOptions(e){return new this.constructor({...this._options,baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,organization:this.organization,project:this.project,webhookSecret:this.webhookSecret,...e})}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:t}){}async authHeaders(e){return $O([{Authorization:`Bearer ${this.apiKey}`}])}stringifyQuery(e){return bm(e,{arrayFormat:"brackets"})}getUserAgent(){return`${this.constructor.name}/JS ${Kf}`}defaultIdempotencyKey(){return`stainless-node-retry-${$f()}`}makeStatusError(e,t,i,n){return Rf.generate(e,t,i,n)}buildURL(e,t,i){const n=!Tf(this,ay,"m",cy).call(this)&&i||this.baseURL,r=(e=>Vf.test(e))(e)?new URL(e):new URL(n+(n.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),s=this.defaultQuery();return function(e){if(!e)return!0;for(const t in e)return!1;return!0}(s)||(t={...s,...t}),"object"==typeof t&&t&&!Array.isArray(t)&&(r.search=this.stringifyQuery(t)),r.toString()}async prepareOptions(e){}async prepareRequest(e,{url:t,options:i}){}get(e,t){return this.methodRequest("get",e,t)}post(e,t){return this.methodRequest("post",e,t)}patch(e,t){return this.methodRequest("patch",e,t)}put(e,t){return this.methodRequest("put",e,t)}delete(e,t){return this.methodRequest("delete",e,t)}methodRequest(e,t,i){return this.request(Promise.resolve(i).then(i=>({method:e,path:t,...i})))}request(e,t=null){return new Bm(this,this.makeRequest(e,t,void 0))}async makeRequest(e,t,i){var n,r;const s=await e,a=s.maxRetries??this.maxRetries;null==t&&(t=a),await this.prepareOptions(s);const{req:o,url:l,timeout:c}=await this.buildRequest(s,{retryCount:a-t});await this.prepareRequest(o,{url:l,options:s});const h="log_"+(Math.random()*(1<<24)|0).toString(16).padStart(6,"0"),u=void 0===i?"":`, retryOf: ${i}`,d=Date.now();if(Mm(this).debug(`[${h}] sending request`,Nm({retryOfRequestLogID:i,method:s.method,url:l,options:s,headers:o.headers})),null==(n=s.signal)?void 0:n.aborted)throw new Qf;const p=new AbortController,f=await this.fetchWithTimeout(l,o,c,p).catch(Af),m=Date.now();if(f instanceof Error){const e=`retrying, ${t} attempts remaining`;if(null==(r=s.signal)?void 0:r.aborted)throw new Qf;const n=Ef(f)||/timed? ?out/i.test(String(f)+("cause"in f?String(f.cause):""));if(t)return Mm(this).info(`[${h}] connection ${n?"timed out":"failed"} - ${e}`),Mm(this).debug(`[${h}] connection ${n?"timed out":"failed"} (${e})`,Nm({retryOfRequestLogID:i,url:l,durationMs:m-d,message:f.message})),this.retryRequest(s,t,i??h);if(Mm(this).info(`[${h}] connection ${n?"timed out":"failed"} - error; no more retries left`),Mm(this).debug(`[${h}] connection ${n?"timed out":"failed"} (error; no more retries left)`,Nm({retryOfRequestLogID:i,url:l,durationMs:m-d,message:f.message})),n)throw new jf;throw new If({cause:f})}const g=[...f.headers.entries()].filter(([e])=>"x-request-id"===e).map(([e,t])=>", "+e+": "+JSON.stringify(t)).join(""),O=`[${h}${u}${g}] ${o.method} ${l} ${f.ok?"succeeded":"failed"} with status ${f.status} in ${m-d}ms`;if(!f.ok){const e=await this.shouldRetry(f);if(t&&e){const e=`retrying, ${t} attempts remaining`;return await async function(e){var t,i;if(null===e||"object"!=typeof e)return;if(e[Symbol.asyncIterator])return void(await(null==(i=(t=e[Symbol.asyncIterator]()).return)?void 0:i.call(t)));const n=e.getReader(),r=n.cancel();n.releaseLock(),await r}(f.body),Mm(this).info(`${O} - ${e}`),Mm(this).debug(`[${h}] response error (${e})`,Nm({retryOfRequestLogID:i,url:f.url,status:f.status,headers:f.headers,durationMs:m-d})),this.retryRequest(s,t,i??h,f.headers)}const n=e?"error; no more retries left":"error; not retryable";Mm(this).info(`${O} - ${n}`);const r=await f.text().catch(e=>Af(e).message),a=(e=>{try{return JSON.parse(e)}catch($M){return}})(r),o=a?void 0:r;Mm(this).debug(`[${h}] response error (${n})`,Nm({retryOfRequestLogID:i,url:f.url,status:f.status,headers:f.headers,message:o,durationMs:Date.now()-d}));throw this.makeStatusError(f.status,a,o,f.headers)}return Mm(this).info(O),Mm(this).debug(`[${h}] response start`,Nm({retryOfRequestLogID:i,url:f.url,status:f.status,headers:f.headers,durationMs:m-d})),{response:f,options:s,controller:p,requestLogID:h,retryOfRequestLogID:i,startTime:d}}getAPIList(e,t,i){return this.requestAPIList(t,{method:"get",path:e,...i})}requestAPIList(e,t){const i=this.makeRequest(t,null,void 0);return new Vm(this,i,e)}async fetchWithTimeout(e,t,i,n){const{signal:r,method:s,...a}=t||{};r&&r.addEventListener("abort",()=>n.abort());const o=setTimeout(()=>n.abort(),i),l=globalThis.ReadableStream&&a.body instanceof globalThis.ReadableStream||"object"==typeof a.body&&null!==a.body&&Symbol.asyncIterator in a.body,c={signal:n.signal,...l?{duplex:"half"}:{},method:"GET",...a};s&&(c.method=s.toUpperCase());try{return await this.fetch.call(void 0,e,c)}finally{clearTimeout(o)}}async shouldRetry(e){const t=e.headers.get("x-should-retry");return"true"===t||"false"!==t&&(408===e.status||(409===e.status||(429===e.status||e.status>=500)))}async retryRequest(e,t,i,n){let r;const s=null==n?void 0:n.get("retry-after-ms");if(s){const e=parseFloat(s);Number.isNaN(e)||(r=e)}const a=null==n?void 0:n.get("retry-after");if(a&&!r){const e=parseFloat(a);r=Number.isNaN(e)?Date.parse(a)-Date.now():1e3*e}if(!(r&&0<=r&&r<6e4)){const i=e.maxRetries??this.maxRetries;r=this.calculateDefaultRetryTimeoutMillis(t,i)}return await Hf(r),this.makeRequest(e,t-1,i)}calculateDefaultRetryTimeoutMillis(e,t){const i=t-e;return Math.min(.5*Math.pow(2,i),8)*(1-.25*Math.random())*1e3}async buildRequest(e,{retryCount:t=0}={}){const i={...e},{method:n,path:r,query:s,defaultBaseURL:a}=i,o=this.buildURL(r,s,a);"timeout"in i&&((e,t)=>{if("number"!=typeof t||!Number.isInteger(t))throw new Cf(`${e} must be an integer`);if(t<0)throw new Cf(`${e} must be a positive integer`)})("timeout",i.timeout),i.timeout=i.timeout??this.timeout;const{bodyHeaders:l,body:c}=this.buildBody({options:i});return{req:{method:n,headers:await this.buildHeaders({options:e,method:n,bodyHeaders:l,retryCount:t}),...i.signal&&{signal:i.signal},...globalThis.ReadableStream&&c instanceof globalThis.ReadableStream&&{duplex:"half"},...c&&{body:c},...this.fetchOptions??{},...i.fetchOptions??{}},url:o,timeout:i.timeout}}async buildHeaders({options:e,method:t,bodyHeaders:i,retryCount:n}){let r={};this.idempotencyHeader&&"get"!==t&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),r[this.idempotencyHeader]=e.idempotencyKey);const s=$O([r,{Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(n),...e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{},...im??(im=Jf()),"OpenAI-Organization":this.organization,"OpenAI-Project":this.project},await this.authHeaders(e),this._options.defaultHeaders,i,e.headers]);return this.validateHeaders(s),s.values}buildBody({options:{body:e,headers:t}}){if(!e)return{bodyHeaders:void 0,body:void 0};const i=$O([t]);return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||"string"==typeof e&&i.values.has("content-type")||e instanceof Blob||e instanceof FormData||e instanceof URLSearchParams||globalThis.ReadableStream&&e instanceof globalThis.ReadableStream?{bodyHeaders:void 0,body:e}:"object"==typeof e&&(Symbol.asyncIterator in e||Symbol.iterator in e&&"next"in e&&"function"==typeof e.next)?{bodyHeaders:void 0,body:rm(e)}:Tf(this,ly,"f").call(this,{body:e,headers:i})}};function dy(e,t){if(void 0===e.function)return;let i;if(null==t?void 0:t.partial)try{i=_o(e.function.arguments??"{}")}catch(r){return}else try{i=JSON.parse(e.function.arguments)}catch(r){throw new gp([`Function "${e.function.name}" arguments:`,"",e.function.arguments,"","are not valid JSON.",`Error: ${r.message}`].join("\n"))}const n={name:e.function.name,args:i,type:"tool_call"};return(null==t?void 0:t.returnId)&&(n.id=e.id),n}function py(e){if(void 0===e.id)throw new Error('All OpenAI tool calls must have an "id" field.');return{id:e.id,type:"function",function:{name:e.name,arguments:JSON.stringify(e.args)}}}function fy(e,t){var i,n;return{name:null==(i=e.function)?void 0:i.name,args:null==(n=e.function)?void 0:n.arguments,id:e.id,error:t,type:"invalid_tool_call"}}oy=uy,ly=new WeakMap,ay=new WeakSet,cy=function(){return"https://api.openai.com/v1"!==this.baseURL},uy.OpenAI=oy,uy.DEFAULT_TIMEOUT=6e5,uy.OpenAIError=Cf,uy.APIError=Rf,uy.APIConnectionError=If,uy.APIConnectionTimeoutError=jf,uy.APIUserAbortError=Qf,uy.NotFoundError=Zf,uy.ConflictError=Df,uy.RateLimitError=Uf,uy.BadRequestError=Mf,uy.AuthenticationError=Nf,uy.InternalServerError=qf,uy.PermissionDeniedError=Lf,uy.UnprocessableEntityError=zf,uy.InvalidWebhookSignatureError=Wf,uy.toFile=async function(e,t,i){if(Gm(),(e=>null!=e&&"object"==typeof e&&"string"==typeof e.name&&"number"==typeof e.lastModified&&rg(e))(e=await e))return e instanceof File?e:Hm([await e.arrayBuffer()],e.name);if((e=>null!=e&&"object"==typeof e&&"string"==typeof e.url&&"function"==typeof e.blob)(e)){const n=await e.blob();return t||(t=new URL(e.url).pathname.split(/[\\/]/).pop()),Hm(await sg(n),t,i)}const n=await sg(e);if(t||(t=Km(e)),!(null==i?void 0:i.type)){const e=n.find(e=>"object"==typeof e&&"type"in e&&e.type);"string"==typeof e&&(i={...i,type:e})}return Hm(n,t,i)},uy.Completions=fv,uy.Chat=kO,uy.Embeddings=vv,uy.Files=_v,uy.Images=Qv,uy.Audio=RO,uy.Moderations=jv,uy.Models=Iv,uy.FineTuning=Av,uy.Graders=Rv,uy.VectorStores=iy,uy.Webhooks=hy,uy.Beta=pv,uy.Batches=QO,uy.Uploads=Jv,uy.Responses=Hv,uy.Evals=wv,uy.Containers=Ov;class my extends vp{static lc_name(){return"JsonOutputToolsParser"}constructor(e){super(e),Object.defineProperty(this,"returnId",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","output_parsers","openai_tools"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this.returnId=(null==e?void 0:e.returnId)??this.returnId}_diff(){throw new Error("Not supported.")}async parse(){throw new Error("Not implemented.")}async parseResult(e){return await this.parsePartialResult(e,!1)}async parsePartialResult(e,t=!0){var i;const n=e[0].message;let r;if(zo(n)&&(null==(i=n.tool_calls)?void 0:i.length))r=n.tool_calls.map(e=>{const{id:t,...i}=e;return this.returnId?{id:t,...i}:i});else if(void 0!==n.additional_kwargs.tool_calls){r=JSON.parse(JSON.stringify(n.additional_kwargs.tool_calls)).map(e=>dy(e,{returnId:this.returnId,partial:t}))}if(!r)return[];const s=[];for(const a of r)if(void 0!==a){const e={type:a.name,args:a.args,id:a.id};s.push(e)}return s}}class gy extends my{static lc_name(){return"JsonOutputKeyToolsParser"}constructor(e){super(e),Object.defineProperty(this,"lc_namespace",{enumerable:!0,configurable:!0,writable:!0,value:["langchain","output_parsers","openai_tools"]}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"returnId",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"keyName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"returnSingle",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"zodSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.keyName=e.keyName,this.returnSingle=e.returnSingle??this.returnSingle,this.zodSchema=e.zodSchema}async _validateResult(e){var t;if(void 0===this.zodSchema)return e;const i=await bh(this.zodSchema,e);if(i.success)return i.data;throw new gp(`Failed to parse. Text: "${JSON.stringify(e,null,2)}". Error: ${JSON.stringify(null==(t=i.error)?void 0:t.issues)}`,JSON.stringify(e,null,2))}async parsePartialResult(e){const t=(await super.parsePartialResult(e)).filter(e=>e.type===this.keyName);let i=t;if(t.length)return this.returnId||(i=t.map(e=>e.args)),this.returnSingle?i[0]:i}async parseResult(e){const t=(await super.parsePartialResult(e,!1)).filter(e=>e.type===this.keyName);let i=t;if(!t.length)return;if(this.returnId||(i=t.map(e=>e.args)),this.returnSingle)return this._validateResult(i[0]);const n=await Promise.all(i.map(e=>this._validateResult(e)));return n}}const Oy=Symbol("Let zodToJsonSchema decide on which parser to use"),vy={name:void 0,$refStrategy:"root",effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",nullableStrategy:"from-target",removeAdditionalStrategy:"passthrough",definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},yy=e=>"_def"in e?e._def:e;const by=e=>{const t=(e=>"string"==typeof e?{...vy,basePath:["#"],definitions:{},name:e}:{...vy,basePath:["#"],definitions:{},...e})(e),i=void 0!==t.name?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,currentPath:i,propertyPath:void 0,seenRefs:new Set,seen:new Map(Object.entries(t.definitions).map(([e,i])=>[yy(i),{def:yy(i),path:[...t.basePath,t.definitionPath,e],jsonSchema:void 0}]))}};function wy(e,t,i,n){(null==n?void 0:n.errorMessages)&&i&&(e.errorMessage={...e.errorMessage,[t]:i})}function _y(e,t,i,n,r){e[t]=i,wy(e,t,n,r)}function xy(e,t,i){const n=i??t.dateStrategy;if(Array.isArray(n))return{anyOf:n.map((i,n)=>xy(e,t,i))};switch(n){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return Sy(e,t)}}const Sy=(e,t)=>{const i={type:"integer",format:"unix-time"};if("openApi3"===t.target)return i;for(const n of e.checks)switch(n.kind){case"min":_y(i,"minimum",n.value,n.message,t);break;case"max":_y(i,"maximum",n.value,n.message,t)}return i};let ky;const Py=/^[cC][^\s-]{8,}$/,Ty=/^[0-9a-z]+$/,$y=/^[0-9A-HJKMNP-TV-Z]{26}$/,Ey=/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,Ay=()=>(void 0===ky&&(ky=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ky),Cy=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ry=/^[a-zA-Z0-9_-]{21}$/;function Qy(e,t){const i={type:"string"};function n(e){return"escape"===t.patternStrategy?Iy(e):e}if(e.checks)for(const r of e.checks)switch(r.kind){case"min":_y(i,"minLength","number"==typeof i.minLength?Math.max(i.minLength,r.value):r.value,r.message,t);break;case"max":_y(i,"maxLength","number"==typeof i.maxLength?Math.min(i.maxLength,r.value):r.value,r.message,t);break;case"email":switch(t.emailStrategy){case"format:email":jy(i,"email",r.message,t);break;case"format:idn-email":jy(i,"idn-email",r.message,t);break;case"pattern:zod":My(i,Ey,r.message,t)}break;case"url":jy(i,"uri",r.message,t);break;case"uuid":jy(i,"uuid",r.message,t);break;case"regex":My(i,r.regex,r.message,t);break;case"cuid":My(i,Py,r.message,t);break;case"cuid2":My(i,Ty,r.message,t);break;case"startsWith":My(i,RegExp(`^${n(r.value)}`),r.message,t);break;case"endsWith":My(i,RegExp(`${n(r.value)}$`),r.message,t);break;case"datetime":jy(i,"date-time",r.message,t);break;case"date":jy(i,"date",r.message,t);break;case"time":jy(i,"time",r.message,t);break;case"duration":jy(i,"duration",r.message,t);break;case"length":_y(i,"minLength","number"==typeof i.minLength?Math.max(i.minLength,r.value):r.value,r.message,t),_y(i,"maxLength","number"==typeof i.maxLength?Math.min(i.maxLength,r.value):r.value,r.message,t);break;case"includes":My(i,RegExp(n(r.value)),r.message,t);break;case"ip":"v6"!==r.version&&jy(i,"ipv4",r.message,t),"v4"!==r.version&&jy(i,"ipv6",r.message,t);break;case"emoji":My(i,Ay,r.message,t);break;case"ulid":My(i,$y,r.message,t);break;case"base64":switch(t.base64Strategy){case"format:binary":jy(i,"binary",r.message,t);break;case"contentEncoding:base64":_y(i,"contentEncoding","base64",r.message,t);break;case"pattern:zod":My(i,Cy,r.message,t)}break;case"nanoid":My(i,Ry,r.message,t)}return i}const Iy=e=>Array.from(e).map(e=>/[a-zA-Z0-9]/.test(e)?e:`\\${e}`).join(""),jy=(e,t,i,n)=>{var r;e.format||(null==(r=e.anyOf)?void 0:r.some(e=>e.format))?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format,...e.errorMessage&&n.errorMessages&&{errorMessage:{format:e.errorMessage.format}}}),delete e.format,e.errorMessage&&(delete e.errorMessage.format,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.anyOf.push({format:t,...i&&n.errorMessages&&{errorMessage:{format:i}}})):_y(e,"format",t,i,n)},My=(e,t,i,n)=>{var r;e.pattern||(null==(r=e.allOf)?void 0:r.some(e=>e.pattern))?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern,...e.errorMessage&&n.errorMessages&&{errorMessage:{pattern:e.errorMessage.pattern}}}),delete e.pattern,e.errorMessage&&(delete e.errorMessage.pattern,0===Object.keys(e.errorMessage).length&&delete e.errorMessage)),e.allOf.push({pattern:Ny(t,n),...i&&n.errorMessages&&{errorMessage:{pattern:i}}})):_y(e,"pattern",Ny(t,n),i,n)},Ny=(e,t)=>{var i;const n="function"==typeof e?e():e;if(!t.applyRegexFlags||!n.flags)return n.source;const r=n.flags.includes("i"),s=n.flags.includes("m"),a=n.flags.includes("s"),o=r?n.source.toLowerCase():n.source;let l="",c=!1,h=!1,u=!1;for(let d=0;d<o.length;d++)if(c)l+=o[d],c=!1;else{if(r)if(h){if(o[d].match(/[a-z]/)){u?(l+=o[d],l+=`${o[d-2]}-${o[d]}`.toUpperCase(),u=!1):"-"===o[d+1]&&(null==(i=o[d+2])?void 0:i.match(/[a-z]/))?(l+=o[d],u=!0):l+=`${o[d]}${o[d].toUpperCase()}`;continue}}else if(o[d].match(/[a-z]/)){l+=`[${o[d]}${o[d].toUpperCase()}]`;continue}if(s){if("^"===o[d]){l+="(^|(?<=[\r\n]))";continue}if("$"===o[d]){l+="($|(?=[\r\n]))";continue}}a&&"."===o[d]?l+=h?`${o[d]}\r\n`:`[${o[d]}\r\n]`:(l+=o[d],"\\"===o[d]?c=!0:h&&"]"===o[d]?h=!1:h||"["!==o[d]||(h=!0))}try{new RegExp(l)}catch{return n.source}return l};function Ly(e,t){var i,n,r,s;if("openApi3"===t.target&&(null==(i=e.keyType)?void 0:i._def.typeName)===Bt.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((i,n)=>({...i,[n]:Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",n]})??{}}),{}),additionalProperties:!1};const a={type:"object",additionalProperties:Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??{}};if("openApi3"===t.target)return a;if((null==(n=e.keyType)?void 0:n._def.typeName)===Bt.ZodString&&(null==(r=e.keyType._def.checks)?void 0:r.length)){const i=Object.entries(Qy(e.keyType._def,t)).reduce((e,[t,i])=>"type"===t?e:{...e,[t]:i},{});return{...a,propertyNames:i}}return(null==(s=e.keyType)?void 0:s._def.typeName)===Bt.ZodEnum?{...a,propertyNames:{enum:e.keyType._def.values}}:a}const Zy={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};const Dy=(e,t)=>{const i=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,i)=>Uy(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${i}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return i.length?{anyOf:i}:void 0};function zy(e,t){return"strict"===t.removeAdditionalStrategy?"ZodNever"===e.catchall._def.typeName?"strict"!==e.unknownKeys:Uy(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??!0:"ZodNever"===e.catchall._def.typeName?"passthrough"===e.unknownKeys:Uy(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??!0}function Uy(e,t,i=!1){var n;const r=t.seen.get(e);if(t.override){const s=null==(n=t.override)?void 0:n.call(t,e,t,r,i);if(s!==Oy)return s}if(r&&!i){const e=qy(r,t);if(void 0!==e)return"$ref"in e&&t.seenRefs.add(e.$ref),e}const s={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,s);const a=By(e,e.typeName,t,i);return a&&Wy(e,t,a),s.jsonSchema=a,a}const qy=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"extract-to-root":const i=e.path.slice(t.basePath.length+1).join("_");return i!==t.name&&"duplicate-ref"===t.nameStrategy&&(t.definitions[i]=e.def),{$ref:[...t.basePath,t.definitionPath,i].join("/")};case"relative":return{$ref:Xy(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every((e,i)=>t.currentPath[i]===e)||"seen"===t.$refStrategy?{}:void 0}},Xy=(e,t)=>{let i=0;for(;i<e.length&&i<t.length&&e[i]===t[i];i++);return[(e.length-i).toString(),...t.slice(i)].join("/")},By=(e,t,i,n)=>{switch(t){case Bt.ZodString:return Qy(e,i);case Bt.ZodNumber:return function(e,t){const i={type:"number"};if(!e.checks)return i;for(const n of e.checks)switch(n.kind){case"int":i.type="integer",wy(i,"type",n.message,t);break;case"min":"jsonSchema7"===t.target?n.inclusive?_y(i,"minimum",n.value,n.message,t):_y(i,"exclusiveMinimum",n.value,n.message,t):(n.inclusive||(i.exclusiveMinimum=!0),_y(i,"minimum",n.value,n.message,t));break;case"max":"jsonSchema7"===t.target?n.inclusive?_y(i,"maximum",n.value,n.message,t):_y(i,"exclusiveMaximum",n.value,n.message,t):(n.inclusive||(i.exclusiveMaximum=!0),_y(i,"maximum",n.value,n.message,t));break;case"multipleOf":_y(i,"multipleOf",n.value,n.message,t)}return i}(e,i);case Bt.ZodObject:return function(e,t){const i={type:"object",...Object.entries(e.shape()).reduce((e,[i,n])=>{var r;if(void 0===n||void 0===n._def)return e;const s=[...t.currentPath,"properties",i],a=Uy(n._def,{...t,currentPath:s,propertyPath:s});if(void 0===a)return e;if(t.openaiStrictMode&&n.isOptional()&&!n.isNullable()&&void 0===(null==(r=n._def)?void 0:r.defaultValue))throw new Error(`Zod field at \`${s.join("/")}\` uses \`.optional()\` without \`.nullable()\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required`);return{properties:{...e.properties,[i]:a},required:n.isOptional()&&!t.openaiStrictMode?e.required:[...e.required,i]}},{properties:{},required:[]}),additionalProperties:zy(e,t)};return i.required.length||delete i.required,i}(e,i);case Bt.ZodBigInt:return function(e,t){const i={type:"integer",format:"int64"};if(!e.checks)return i;for(const n of e.checks)switch(n.kind){case"min":"jsonSchema7"===t.target?n.inclusive?_y(i,"minimum",n.value,n.message,t):_y(i,"exclusiveMinimum",n.value,n.message,t):(n.inclusive||(i.exclusiveMinimum=!0),_y(i,"minimum",n.value,n.message,t));break;case"max":"jsonSchema7"===t.target?n.inclusive?_y(i,"maximum",n.value,n.message,t):_y(i,"exclusiveMaximum",n.value,n.message,t):(n.inclusive||(i.exclusiveMaximum=!0),_y(i,"maximum",n.value,n.message,t));break;case"multipleOf":_y(i,"multipleOf",n.value,n.message,t)}return i}(e,i);case Bt.ZodBoolean:return{type:"boolean"};case Bt.ZodDate:return xy(e,i);case Bt.ZodUndefined:return{not:{}};case Bt.ZodNull:return function(e){return"openApi3"===e.target?{enum:["null"],nullable:!0}:{type:"null"}}(i);case Bt.ZodArray:return function(e,t){var i,n;const r={type:"array"};return(null==(n=null==(i=e.type)?void 0:i._def)?void 0:n.typeName)!==Bt.ZodAny&&(r.items=Uy(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&_y(r,"minItems",e.minLength.value,e.minLength.message,t),e.maxLength&&_y(r,"maxItems",e.maxLength.value,e.maxLength.message,t),e.exactLength&&(_y(r,"minItems",e.exactLength.value,e.exactLength.message,t),_y(r,"maxItems",e.exactLength.value,e.exactLength.message,t)),r}(e,i);case Bt.ZodUnion:case Bt.ZodDiscriminatedUnion:return function(e,t){if("openApi3"===t.target)return Dy(e,t);const i=e.options instanceof Map?Array.from(e.options.values()):e.options;if(i.every(e=>e._def.typeName in Zy&&(!e._def.checks||!e._def.checks.length))){const e=i.reduce((e,t)=>{const i=Zy[t._def.typeName];return i&&!e.includes(i)?[...e,i]:e},[]);return{type:e.length>1?e:e[0]}}if(i.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){const e=i.reduce((e,t)=>{const i=typeof t._def.value;switch(i){case"string":case"number":case"boolean":return[...e,i];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===i.length){const t=e.filter((e,t,i)=>i.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:i.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(i.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:i.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return Dy(e,t)}(e,i);case Bt.ZodIntersection:return function(e,t){const i=[Uy(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),Uy(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter(e=>!!e);let n="jsonSchema2019-09"===t.target?{unevaluatedProperties:!1}:void 0;const r=[];return i.forEach(e=>{if("type"in(t=e)&&"string"===t.type||!("allOf"in t)){let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){const{additionalProperties:i,...n}=e;t=n}else n=void 0;r.push(t)}else r.push(...e.allOf),void 0===e.unevaluatedProperties&&(n=void 0);var t}),r.length?{allOf:r,...n}:void 0}(e,i);case Bt.ZodTuple:return function(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,i)=>Uy(e._def,{...t,currentPath:[...t.currentPath,"items",`${i}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:Uy(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,i)=>Uy(e._def,{...t,currentPath:[...t.currentPath,"items",`${i}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])}}(e,i);case Bt.ZodRecord:return Ly(e,i);case Bt.ZodLiteral:return function(e,t){const i=typeof e.value;return"bigint"!==i&&"number"!==i&&"boolean"!==i&&"string"!==i?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===t.target?{type:"bigint"===i?"integer":i,enum:[e.value]}:{type:"bigint"===i?"integer":i,const:e.value}}(e,i);case Bt.ZodEnum:return function(e){return{type:"string",enum:[...e.values]}}(e);case Bt.ZodNativeEnum:return function(e){const t=e.values,i=Object.keys(e.values).filter(e=>"number"!=typeof t[t[e]]),n=i.map(e=>t[e]),r=Array.from(new Set(n.map(e=>typeof e)));return{type:1===r.length?"string"===r[0]?"string":"number":["string","number"],enum:n}}(e);case Bt.ZodNullable:return function(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===t.target||"property"===t.nullableStrategy?{type:Zy[e.innerType._def.typeName],nullable:!0}:{type:[Zy[e.innerType._def.typeName],"null"]};if("openApi3"===t.target){const i=Uy(e.innerType._def,{...t,currentPath:[...t.currentPath]});return i&&"$ref"in i?{allOf:[i],nullable:!0}:i&&{...i,nullable:!0}}const i=Uy(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return i&&{anyOf:[i,{type:"null"}]}}(e,i);case Bt.ZodOptional:return((e,t)=>{if(t.propertyPath&&t.currentPath.slice(0,t.propertyPath.length).toString()===t.propertyPath.toString())return Uy(e.innerType._def,{...t,currentPath:t.currentPath});const i=Uy(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return i?{anyOf:[{not:{}},i]}:{}})(e,i);case Bt.ZodMap:return function(e,t){return"record"===t.mapStrategy?Ly(e,t):{type:"array",maxItems:125,items:{type:"array",items:[Uy(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||{},Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||{}],minItems:2,maxItems:2}}}(e,i);case Bt.ZodSet:return function(e,t){const i={type:"array",uniqueItems:!0,items:Uy(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&_y(i,"minItems",e.minSize.value,e.minSize.message,t),e.maxSize&&_y(i,"maxItems",e.maxSize.value,e.maxSize.message,t),i}(e,i);case Bt.ZodLazy:return Uy(e.getter()._def,i);case Bt.ZodPromise:return function(e,t){return Uy(e.type._def,t)}(e,i);case Bt.ZodNaN:case Bt.ZodNever:return{not:{}};case Bt.ZodEffects:return function(e,t,i){return"input"===t.effectStrategy?Uy(e.schema._def,t,i):{}}(e,i,n);case Bt.ZodAny:case Bt.ZodUnknown:return{};case Bt.ZodDefault:return function(e,t){return{...Uy(e.innerType._def,t),default:e.defaultValue()}}(e,i);case Bt.ZodBranded:return function(e,t){return Uy(e.type._def,t)}(e,i);case Bt.ZodReadonly:case Bt.ZodCatch:return((e,t)=>Uy(e.innerType._def,t))(e,i);case Bt.ZodPipeline:return((e,t)=>{if("input"===t.pipeStrategy)return Uy(e.in._def,t);if("output"===t.pipeStrategy)return Uy(e.out._def,t);const i=Uy(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]});return{allOf:[i,Uy(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",i?"1":"0"]})].filter(e=>void 0!==e)}})(e,i);case Bt.ZodFunction:case Bt.ZodVoid:case Bt.ZodSymbol:default:return}},Wy=(e,t,i)=>(e.description&&(i.description=e.description,t.markdownDescription&&(i.markdownDescription=e.description)),i);function Vy(e,t){return((e,t)=>{const i=by(t),n="string"==typeof t?t:"title"===(null==t?void 0:t.nameStrategy)||null==t?void 0:t.name,r=Uy(e._def,void 0===n?i:{...i,currentPath:[...i.basePath,i.definitionPath,n]},!1)??{},s="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==s&&(r.title=s);const a=(()=>{if(function(e){if(!e)return!0;for(const t in e)return!1;return!0}(i.definitions))return;const e={},t=new Set;for(let n=0;n<500;n++){const n=Object.entries(i.definitions).filter(([e])=>!t.has(e));if(0===n.length)break;for(const[r,s]of n)e[r]=Uy(yy(s),{...i,currentPath:[...i.basePath,i.definitionPath,r]},!0)??{},t.add(r)}return e})(),o=void 0===n?a?{...r,[i.definitionPath]:a}:r:"duplicate-ref"===i.nameStrategy?{...r,...a||i.seenRefs.size?{[i.definitionPath]:{...a,...i.seenRefs.size?{[n]:r}:void 0}}:void 0}:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,n].join("/"),[i.definitionPath]:{...a,[n]:r}};return"jsonSchema7"===i.target?o.$schema="http://json-schema.org/draft-07/schema#":"jsonSchema2019-09"===i.target&&(o.$schema="https://json-schema.org/draft/2019-09/schema#"),o})(e,{openaiStrictMode:!0,name:t.name,nameStrategy:"duplicate-ref",$refStrategy:"extract-to-root",nullableStrategy:"property"})}function Fy(e,t,i){return function(e,t){const i={...e};return Object.defineProperties(i,{$brand:{value:"auto-parseable-response-format",enumerable:!1},$parseRaw:{value:t,enumerable:!1}}),i}({type:"json_schema",json_schema:{...i,name:t,strict:!0,schema:Vy(e,{name:t})}},t=>e.parse(JSON.parse(t)))}function Yy(e,t){return e.lc_error_code=t,e.message=`${e.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${t}/\n`,e}function Gy(e){let t;return e.constructor.name===jf.name?(t=new Error(e.message),t.name="TimeoutError"):e.constructor.name===Qf.name?(t=new Error(e.message),t.name="AbortError"):t=400===e.status&&e.message.includes("tool_calls")?Yy(e,"INVALID_TOOL_RESULTS"):401===e.status?Yy(e,"MODEL_AUTHENTICATION"):429===e.status?Yy(e,"MODEL_RATE_LIMIT"):404===e.status?Yy(e,"MODEL_NOT_FOUND"):e,t}function Hy(e){return e?"any"===e||"required"===e?"required":"auto"===e?"auto":"none"===e?"none":"string"==typeof e?{type:"function",function:{name:e}}:e:void 0}function Ky(e,t,i){if(vh(e))return Fy(e,t,i);if(Oh(e))return function(e,t){const i={...e};return Object.defineProperties(i,{$brand:{value:"auto-parseable-response-format",enumerable:!1},$parseRaw:{value:t,enumerable:!1}}),i}({type:"json_schema",json_schema:{...i,name:t,strict:!0,schema:Cc(e,{cycles:"ref",reused:"ref",override(e){e.jsonSchema.title=t}})}},t=>Oc(e,JSON.parse(t)));throw new Error("Unsupported schema response format")}function Jy(e,t){var i;const n=[];for(const[r,s]of Object.entries(e.properties??{}))s.description&&t<2&&n.push(`// ${s.description}`),(null==(i=e.required)?void 0:i.includes(r))?n.push(`${r}: ${eb(s,t)},`):n.push(`${r}?: ${eb(s,t)},`);return n.map(e=>" ".repeat(t)+e).join("\n")}function eb(e,t){if(void 0!==(i=e).anyOf&&Array.isArray(i.anyOf))return e.anyOf.map(e=>eb(e,t)).join(" | ");var i;switch(e.type){case"string":return e.enum?e.enum.map(e=>`"${e}"`).join(" | "):"string";case"number":case"integer":return e.enum?e.enum.map(e=>`${e}`).join(" | "):"number";case"boolean":return"boolean";case"null":return"null";case"object":return["{",Jy(e,t+2),"}"].join("\n");case"array":return e.items?`${eb(e.items,t)}[]`:"any[]";default:return""}}function tb(e,t){let i;return i=Sp(e)?function(e){let t;return t=Sp(e)?{type:"function",function:kp(e)}:e,t}(e):e,"function"===i.type&&void 0!==(null==t?void 0:t.strict)&&(i.function.strict=t.strict),i}function ib(e){return"type"in e&&"function"!==e.type&&"custom"!==e.type}function nb(e){return"type"in e&&"custom"===e.type&&"custom"in e&&"object"==typeof e.custom&&null!==e.custom}function rb(e){if("custom_tool_call"===e.type)return{...e,type:"tool_call",call_id:e.id,id:e.call_id,name:e.name,isCustomTool:!0,args:{input:e.input}}}function sb(e){return{type:"custom",name:e.custom.name,description:e.custom.description,format:(()=>{if(e.custom.format)return"grammar"===e.custom.format.type?{type:"grammar",definition:e.custom.format.grammar.definition,syntax:e.custom.format.grammar.syntax}:"text"===e.custom.format.type?{type:"text"}:void 0})()}}function ab(e){var t,i,n,r;const s={...null!=(null==(t=null==e?void 0:e.input_tokens_details)?void 0:t.cached_tokens)&&{cache_read:null==(i=null==e?void 0:e.input_tokens_details)?void 0:i.cached_tokens}},a={...null!=(null==(n=null==e?void 0:e.output_tokens_details)?void 0:n.reasoning_tokens)&&{reasoning:null==(r=null==e?void 0:e.output_tokens_details)?void 0:r.reasoning_tokens}};return{input_tokens:(null==e?void 0:e.input_tokens)??0,output_tokens:(null==e?void 0:e.output_tokens)??0,total_tokens:(null==e?void 0:e.total_tokens)??0,input_token_details:s,output_token_details:a}}const ob="__openai_function_call_ids__";function lb(e){return!!e&&(!!/^o\d/.test(e??"")||!(!e.startsWith("gpt-5")||e.startsWith("gpt-5-chat")))}function cb(e){const t=e._getType();switch(t){case"system":return"system";case"ai":return"assistant";case"human":return"user";case"function":return"function";case"tool":return"tool";case"generic":if(!Xo.isInstance(e))throw new Error("Invalid generic chat message");return function(e){return"system"!==e.role&&"developer"!==e.role&&"assistant"!==e.role&&"user"!==e.role&&"function"!==e.role&&e.role,e.role}(e);default:throw new Error(`Unknown message type: ${t}`)}}const hb={providerName:"ChatOpenAI",fromStandardTextBlock:e=>({type:"text",text:e.text}),fromStandardImageBlock(e){var t,i;if("url"===e.source_type)return{type:"image_url",image_url:{url:e.url,...(null==(t=e.metadata)?void 0:t.detail)?{detail:e.metadata.detail}:{}}};if("base64"===e.source_type){return{type:"image_url",image_url:{url:`data:${e.mime_type??""};base64,${e.data}`,...(null==(i=e.metadata)?void 0:i.detail)?{detail:e.metadata.detail}:{}}}}throw new Error(`Image content blocks with source_type ${e.source_type} are not supported for ChatOpenAI`)},fromStandardAudioBlock(e){if("url"===e.source_type){const t=$o({dataUrl:e.url});if(!t)throw new Error(`URL audio blocks with source_type ${e.source_type} must be formatted as a data URL for ChatOpenAI`);const i=t.mime_type||e.mime_type||"";let n;try{n=To(i)}catch{throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`)}if("audio"!==n.type||"wav"!==n.subtype&&"mp3"!==n.subtype)throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`);return{type:"input_audio",input_audio:{format:n.subtype,data:t.data}}}if("base64"===e.source_type){let t;try{t=To(e.mime_type??"")}catch{throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`)}if("audio"!==t.type||"wav"!==t.subtype&&"mp3"!==t.subtype)throw new Error(`Audio blocks with source_type ${e.source_type} must have mime type of audio/wav or audio/mp3`);return{type:"input_audio",input_audio:{format:t.subtype,data:e.data}}}throw new Error(`Audio content blocks with source_type ${e.source_type} are not supported for ChatOpenAI`)},fromStandardFileBlock(e){var t,i,n,r,s,a,o,l,c,h;if("url"===e.source_type){if(!$o({dataUrl:e.url}))throw new Error(`URL file blocks with source_type ${e.source_type} must be formatted as a data URL for ChatOpenAI`);return{type:"file",file:{file_data:e.url,...(null==(t=e.metadata)?void 0:t.filename)||(null==(i=e.metadata)?void 0:i.name)?{filename:(null==(n=e.metadata)?void 0:n.filename)||(null==(r=e.metadata)?void 0:r.name)}:{}}}}if("base64"===e.source_type)return{type:"file",file:{file_data:`data:${e.mime_type??""};base64,${e.data}`,...(null==(s=e.metadata)?void 0:s.filename)||(null==(a=e.metadata)?void 0:a.name)||(null==(o=e.metadata)?void 0:o.title)?{filename:(null==(l=e.metadata)?void 0:l.filename)||(null==(c=e.metadata)?void 0:c.name)||(null==(h=e.metadata)?void 0:h.title)}:{}}};if("id"===e.source_type)return{type:"file",file:{file_id:e.id}};throw new Error(`File content blocks with source_type ${e.source_type} are not supported for ChatOpenAI`)}};function ub(e,t){return e.flatMap(e=>{var i;let n=cb(e);"system"===n&&lb(t)&&(n="developer");const r={role:n,content:"string"==typeof e.content?e.content:e.content.map(e=>xo(e)?Eo(e,hb):e)};if(null!=e.name&&(r.name=e.name),null!=e.additional_kwargs.function_call&&(r.function_call=e.additional_kwargs.function_call,r.content=""),zo(e)&&(null==(i=e.tool_calls)?void 0:i.length)?(r.tool_calls=e.tool_calls.map(py),r.content=""):(null!=e.additional_kwargs.tool_calls&&(r.tool_calls=e.additional_kwargs.tool_calls),null!=e.tool_call_id&&(r.tool_call_id=e.tool_call_id)),e.additional_kwargs.audio&&"object"==typeof e.additional_kwargs.audio&&"id"in e.additional_kwargs.audio){return[r,{role:"assistant",audio:{id:e.additional_kwargs.audio.id}}]}return r})}class db extends pp{_llmType(){return"openai"}static lc_name(){return"ChatOpenAI"}get callKeys(){return[...super.callKeys,"options","function_call","functions","tools","tool_choice","promptIndex","response_format","seed","reasoning","reasoningEffort","service_tier"]}get lc_secrets(){return{apiKey:"OPENAI_API_KEY",organization:"OPENAI_ORGANIZATION"}}get lc_aliases(){return{apiKey:"openai_api_key",modelName:"model",reasoningEffort:"reasoning_effort"}}get lc_serializable_keys(){return["configuration","logprobs","topLogprobs","prefixMessages","supportsStrictToolCalling","modalities","audio","temperature","maxTokens","topP","frequencyPenalty","presencePenalty","n","logitBias","user","streaming","streamUsage","model","modelName","modelKwargs","stop","stopSequences","timeout","apiKey","cache","maxConcurrency","maxRetries","verbose","callbacks","tags","metadata","disableStreaming","zdrEnabled","reasoning","reasoningEffort","promptCacheKey","verbosity"]}getLsParams(e){const t=this.invocationParams(e);return{ls_provider:"openai",ls_model_name:this.model,ls_model_type:"chat",ls_temperature:t.temperature??void 0,ls_max_tokens:t.max_tokens??void 0,ls_stop:e.stop}}_identifyingParams(){return{model_name:this.model,...this.invocationParams(),...this.clientConfig}}identifyingParams(){return this._identifyingParams()}constructor(e){var t,i;super(e??{}),Object.defineProperty(this,"temperature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"frequencyPenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"presencePenalty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"n",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logitBias",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"model",{enumerable:!0,configurable:!0,writable:!0,value:"gpt-3.5-turbo"}),Object.defineProperty(this,"modelKwargs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stopSequences",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"user",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streaming",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"streamUsage",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"maxTokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logprobs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"topLogprobs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"organization",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"__includeRawResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clientConfig",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"supportsStrictToolCalling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"modalities",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"reasoning",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"zdrEnabled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"service_tier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"promptCacheKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"verbosity",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"defaultOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this.apiKey=(null==e?void 0:e.apiKey)??(null==(t=null==e?void 0:e.configuration)?void 0:t.apiKey)??to("OPENAI_API_KEY"),this.organization=(null==(i=null==e?void 0:e.configuration)?void 0:i.organization)??to("OPENAI_ORGANIZATION"),this.model=(null==e?void 0:e.model)??(null==e?void 0:e.modelName)??this.model,this.modelKwargs=(null==e?void 0:e.modelKwargs)??{},this.timeout=null==e?void 0:e.timeout,this.temperature=(null==e?void 0:e.temperature)??this.temperature,this.topP=(null==e?void 0:e.topP)??this.topP,this.frequencyPenalty=(null==e?void 0:e.frequencyPenalty)??this.frequencyPenalty,this.presencePenalty=(null==e?void 0:e.presencePenalty)??this.presencePenalty,this.logprobs=null==e?void 0:e.logprobs,this.topLogprobs=null==e?void 0:e.topLogprobs,this.n=(null==e?void 0:e.n)??this.n,this.logitBias=null==e?void 0:e.logitBias,this.stop=(null==e?void 0:e.stopSequences)??(null==e?void 0:e.stop),this.stopSequences=this.stop,this.user=null==e?void 0:e.user,this.__includeRawResponse=null==e?void 0:e.__includeRawResponse,this.audio=null==e?void 0:e.audio,this.modalities=null==e?void 0:e.modalities,this.reasoning=(null==e?void 0:e.reasoning)??((null==e?void 0:e.reasoningEffort)?{effort:e.reasoningEffort}:void 0),this.maxTokens=(null==e?void 0:e.maxCompletionTokens)??(null==e?void 0:e.maxTokens),this.disableStreaming=!0===(null==e?void 0:e.disableStreaming),this.streaming=!0===(null==e?void 0:e.streaming),this.promptCacheKey=(null==e?void 0:e.promptCacheKey)??this.promptCacheKey,this.verbosity=(null==e?void 0:e.verbosity)??this.verbosity,!1===(null==e?void 0:e.streaming)&&(this.disableStreaming=!0),!0===this.disableStreaming&&(this.streaming=!1),this.streamUsage=(null==e?void 0:e.streamUsage)??this.streamUsage,this.disableStreaming&&(this.streamUsage=!1),this.clientConfig={apiKey:this.apiKey,organization:this.organization,dangerouslyAllowBrowser:!0,...null==e?void 0:e.configuration},void 0!==(null==e?void 0:e.supportsStrictToolCalling)&&(this.supportsStrictToolCalling=e.supportsStrictToolCalling),void 0!==(null==e?void 0:e.service_tier)&&(this.service_tier=e.service_tier),this.zdrEnabled=(null==e?void 0:e.zdrEnabled)??!1}_getReasoningParams(e){if(!lb(this.model))return;let t;return void 0!==this.reasoning&&(t={...t,...this.reasoning}),void 0!==(null==e?void 0:e.reasoning)&&(t={...t,...e.reasoning}),t}_getResponseFormat(e){return e&&"json_schema"===e.type&&e.json_schema.schema&&yh(e.json_schema.schema)?Ky(e.json_schema.schema,e.json_schema.name,{description:e.json_schema.description}):e}_combineCallOptions(e){return{...this.defaultOptions,...e??{}}}_getClientOptions(e){if(!this.client){const e=function(e){const{azureOpenAIApiDeploymentName:t,azureOpenAIApiInstanceName:i,azureOpenAIApiKey:n,azureOpenAIBasePath:r,baseURL:s,azureADTokenProvider:a,azureOpenAIEndpoint:o}=e;if((n||a)&&r&&t)return`${r}/${t}`;if((n||a)&&o&&t)return`${o}/openai/deployments/${t}`;if(n||a){if(!i)throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");if(!t)throw new Error("azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey");return`https://${i}.openai.azure.com/openai/deployments/${t}`}return s}({baseURL:this.clientConfig.baseURL}),t={...this.clientConfig,baseURL:e,timeout:this.timeout,maxRetries:0};t.baseURL||delete t.baseURL,this.client=new uy(t)}return{...this.clientConfig,...e}}_convertChatOpenAIToolToCompletionsTool(e,t){return function(e){return"object"==typeof e&&null!==e&&"metadata"in e&&"object"==typeof e.metadata&&null!==e.metadata&&"customTool"in e.metadata&&"object"==typeof e.metadata.customTool&&null!==e.metadata.customTool}(e)?function(e){return{type:"custom",custom:{name:e.name,description:e.description,format:(()=>{if(e.format)return"grammar"===e.format.type?{type:"grammar",grammar:{definition:e.format.definition,syntax:e.format.syntax}}:"text"===e.format.type?{type:"text"}:void 0})()}}}(e.metadata.customTool):lp(e)?void 0!==(null==t?void 0:t.strict)?{...e,function:{...e.function,strict:t.strict}}:e:tb(e,t)}bindTools(e,t){let i;return void 0!==(null==t?void 0:t.strict)?i=t.strict:void 0!==this.supportsStrictToolCalling&&(i=this.supportsStrictToolCalling),this.withConfig({tools:e.map(e=>ib(e)?e:this._convertChatOpenAIToolToCompletionsTool(e,{strict:i})),...t})}async stream(e,t){return super.stream(e,this._combineCallOptions(t))}async invoke(e,t){return super.invoke(e,this._combineCallOptions(t))}_combineLLMOutput(...e){return e.reduce((e,t)=>(t&&t.tokenUsage&&(e.tokenUsage.completionTokens+=t.tokenUsage.completionTokens??0,e.tokenUsage.promptTokens+=t.tokenUsage.promptTokens??0,e.tokenUsage.totalTokens+=t.tokenUsage.totalTokens??0),e),{tokenUsage:{completionTokens:0,promptTokens:0,totalTokens:0}})}async getNumTokensFromMessages(e){let t=0,i=0,n=0;"gpt-3.5-turbo-0301"===this.model?(i=4,n=-1):(i=3,n=1);const r=await Promise.all(e.map(async e=>{var r,s,a,o,l,c;const h=await this.getNumTokens(e.content),u=await this.getNumTokens(cb(e)),d=void 0!==e.name?n+await this.getNumTokens(e.name):0;let p=h+i+u+d;const f=e;if("function"===f._getType()&&(p-=2),(null==(r=f.additional_kwargs)?void 0:r.function_call)&&(p+=3),(null==(s=null==f?void 0:f.additional_kwargs.function_call)?void 0:s.name)&&(p+=await this.getNumTokens(null==(a=f.additional_kwargs.function_call)?void 0:a.name)),null==(o=f.additional_kwargs.function_call)?void 0:o.arguments)try{p+=await this.getNumTokens(JSON.stringify(JSON.parse(null==(l=f.additional_kwargs.function_call)?void 0:l.arguments)))}catch(m){p+=await this.getNumTokens(null==(c=f.additional_kwargs.function_call)?void 0:c.arguments)}return t+=p,p}));return t+=3,{totalCount:t,countPerMessage:r}}async _getNumTokensFromGenerations(e){return(await Promise.all(e.map(async e=>{var t;return(null==(t=e.message.additional_kwargs)?void 0:t.function_call)?(await this.getNumTokensFromMessages([e.message])).countPerMessage[0]:await this.getNumTokens(e.message.content)}))).reduce((e,t)=>e+t,0)}async _getEstimatedTokenCountFromPrompt(e,t,i){let n=(await this.getNumTokensFromMessages(e)).totalCount;if(t&&"auto"!==i){const e=function(e){const t=["namespace functions {",""];for(const i of e)i.description&&t.push(`// ${i.description}`),Object.keys(i.parameters.properties??{}).length>0?(t.push(`type ${i.name} = (_: {`),t.push(Jy(i.parameters,0)),t.push("}) => any;")):t.push(`type ${i.name} = () => any;`),t.push("");return t.push("} // namespace functions"),t.join("\n")}(t);n+=await this.getNumTokens(e),n+=9}return t&&e.find(e=>"system"===e._getType())&&(n-=4),"none"===i?n+=1:"object"==typeof i&&(n+=await this.getNumTokens(i.name)+4),n}_getStructuredOutputMethod(e){const t={...e};if(this.model.startsWith("gpt-3")||this.model.startsWith("gpt-4-")||"gpt-4"===this.model)t.method;else if(void 0===(null==t?void 0:t.method))return"jsonSchema";return t.method}withStructuredOutput(e,t){let i,n,r,s;var a;let o,l;if(void 0!==(a=e)&&"object"==typeof a.schema?(i=e.schema,n=e.name,r=e.method,s=e.includeRaw):(i=e,n=null==t?void 0:t.name,r=null==t?void 0:t.method,s=null==t?void 0:t.includeRaw),void 0!==(null==t?void 0:t.strict)&&"jsonMode"===r)throw new Error("Argument `strict` is only supported for `method` = 'function_calling'");if(r=this._getStructuredOutputMethod({...t,method:r}),"jsonMode"===r){l=yh(i)?yp.fromZodSchema(i):new bp;const e=Th(i);o=this.withConfig({response_format:{type:"json_object"},ls_structured_output_format:{kwargs:{method:"json_mode"},schema:{title:n??"extract",...e}}})}else if("jsonSchema"===r){const e={name:n??"extract",description:_h(i),schema:i,strict:null==t?void 0:t.strict},r=Th(e.schema);if(o=this.withConfig({response_format:{type:"json_schema",json_schema:e},ls_structured_output_format:{kwargs:{method:"json_schema"},schema:{title:e.name,description:e.description,...r}}}),yh(i)){const e=yp.fromZodSchema(i);l=Bh.from(t=>"parsed"in t.additional_kwargs?t.additional_kwargs.parsed:e)}else l=new bp}else{let e=n??"extract";if(yh(i)){const n=Th(i);o=this.withConfig({tools:[{type:"function",function:{name:e,description:n.description,parameters:n}}],tool_choice:{type:"function",function:{name:e}},ls_structured_output_format:{kwargs:{method:"function_calling"},schema:{title:e,...n}},...void 0!==(null==t?void 0:t.strict)?{strict:t.strict}:{}}),l=new gy({returnSingle:!0,keyName:e,zodSchema:i})}else{let n;"string"==typeof i.name&&"object"==typeof i.parameters&&null!=i.parameters?(n=i,e=i.name):(e=i.title??e,n={name:e,description:i.description??"",parameters:i});const r=Th(i);o=this.withConfig({tools:[{type:"function",function:n}],tool_choice:{type:"function",function:{name:e}},ls_structured_output_format:{kwargs:{method:"function_calling"},schema:{title:e,...r}},...void 0!==(null==t?void 0:t.strict)?{strict:t.strict}:{}}),l=new gy({returnSingle:!0,keyName:e})}}if(!s)return o.pipe(l);const c=up.assign({parsed:(e,t)=>l.invoke(e.raw,t)}),h=up.assign({parsed:()=>null}),u=c.withFallbacks({fallbacks:[h]});return Uh.from([{raw:o},u])}}class pb extends db{invocationParams(e){var t;let i;void 0!==(null==e?void 0:e.strict)?i=e.strict:void 0!==this.supportsStrictToolCalling&&(i=this.supportsStrictToolCalling);const n={model:this.model,temperature:this.temperature,top_p:this.topP,user:this.user,stream:this.streaming,previous_response_id:null==e?void 0:e.previous_response_id,truncation:null==e?void 0:e.truncation,include:null==e?void 0:e.include,tools:(null==(t=null==e?void 0:e.tools)?void 0:t.length)?this._reduceChatOpenAITools(e.tools,{stream:this.streaming,strict:i}):void 0,tool_choice:(r=null==e?void 0:e.tool_choice,null!=r&&"object"==typeof r&&"type"in r&&"function"!==r.type?null==e?void 0:e.tool_choice:(()=>{const t=Hy(null==e?void 0:e.tool_choice);if("object"==typeof t&&"type"in t){if("function"===t.type)return{type:"function",name:t.function.name};if("allowed_tools"===t.type)return{type:"allowed_tools",mode:t.allowed_tools.mode,tools:t.allowed_tools.tools};if("custom"===t.type)return{type:"custom",name:t.custom.name}}})()),text:(()=>{if(null==e?void 0:e.text)return e.text;const t=this._getResponseFormat(null==e?void 0:e.response_format);return"json_schema"===(null==t?void 0:t.type)?null!=t.json_schema.schema?{format:{type:"json_schema",schema:t.json_schema.schema,description:t.json_schema.description,name:t.json_schema.name,strict:t.json_schema.strict},verbosity:null==e?void 0:e.verbosity}:void 0:{format:t,verbosity:null==e?void 0:e.verbosity}})(),parallel_tool_calls:null==e?void 0:e.parallel_tool_calls,max_output_tokens:-1===this.maxTokens?void 0:this.maxTokens,prompt_cache_key:(null==e?void 0:e.promptCacheKey)??this.promptCacheKey,...this.zdrEnabled?{store:!1}:{},...this.modelKwargs};var r;const s=this._getReasoningParams(e);return void 0!==s&&(n.reasoning=s),n}async _generate(e,t){var i;const n=this.invocationParams(t);if(n.stream){const n=this._streamResponseChunks(e,t);let r;for await(const e of n)e.message.response_metadata={...e.generationInfo,...e.message.response_metadata},r=(null==r?void 0:r.concat(e))??e;return{generations:r?[r]:[],llmOutput:{estimatedTokenUsage:null==(i=null==r?void 0:r.message)?void 0:i.usage_metadata}}}{const i=this._convertMessagesToResponsesParams(e),r=await this.completionWithRetry({input:i,...n,stream:!1},{signal:null==t?void 0:t.signal,...null==t?void 0:t.options});return{generations:[{text:r.output_text,message:this._convertResponsesMessageToBaseMessage(r)}],llmOutput:{id:r.id,estimatedTokenUsage:r.usage?{promptTokens:r.usage.input_tokens,completionTokens:r.usage.output_tokens,totalTokens:r.usage.total_tokens}:void 0}}}}async*_streamResponseChunks(e,t,i){const n=await this.completionWithRetry({...this.invocationParams(t),input:this._convertMessagesToResponsesParams(e),stream:!0},t);for await(const r of n){const e=this._convertResponsesDeltaToBaseMessageChunk(r);null!=e&&(yield e,await(null==i?void 0:i.handleLLMNewToken(e.text||"",{prompt:t.promptIndex??0,completion:0},void 0,void 0,void 0,{chunk:e})))}}async completionWithRetry(e,t){return this.caller.call(async()=>{var i,n;const r=this._getClientOptions(t);try{return"json_schema"!==(null==(n=null==(i=e.text)?void 0:i.format)?void 0:n.type)||e.stream?await this.client.responses.create(e,r):await this.client.responses.parse(e,r)}catch(s){throw Gy(s)}})}_convertResponsesMessageToBaseMessage(e){if(e.error){const t=new Error(e.error.message);throw t.name=e.error.code,t}let t;const i=[],n=[],r=[],s={model:e.model,created_at:e.created_at,id:e.id,incomplete_details:e.incomplete_details,metadata:e.metadata,object:e.object,status:e.status,user:e.user,service_tier:e.service_tier,model_name:e.model},a={};for(const l of e.output)if("message"===l.type)t=l.id,i.push(...l.content.flatMap(e=>"output_text"===e.type?("parsed"in e&&null!=e.parsed&&(a.parsed=e.parsed),{type:"text",text:e.text,annotations:e.annotations}):"refusal"===e.type?(a.refusal=e.refusal,[]):e));else if("function_call"===l.type){const e={function:{name:l.name,arguments:l.arguments},id:l.call_id};try{n.push(dy(e,{returnId:!0}))}catch(o){let t;"object"==typeof o&&null!=o&&"message"in o&&"string"==typeof o.message&&(t=o.message),r.push(fy(e,t))}a[ob]??(a[ob]={}),l.id&&(a[ob][l.call_id]=l.id)}else if("reasoning"===l.type)a.reasoning=l;else if("custom_tool_call"===l.type){const e=rb(l);e?n.push(e):r.push(fy(l,"Malformed custom tool call"))}else a.tool_outputs??(a.tool_outputs=[]),a.tool_outputs.push(l);return new Do({id:t,content:i,tool_calls:n,invalid_tool_calls:r,usage_metadata:ab(e.usage),additional_kwargs:a,response_metadata:s})}_convertResponsesDeltaToBaseMessageChunk(e){var t,i;const n=[];let r,s={};const a=[],o={},l={};let c;if("response.output_text.delta"===e.type)n.push({type:"text",text:e.delta,index:e.content_index});else if("response.output_text.annotation.added"===e.type)n.push({type:"text",text:"",annotations:[e.annotation],index:e.content_index});else if("response.output_item.added"===e.type&&"message"===e.item.type)c=e.item.id;else if("response.output_item.added"===e.type&&"function_call"===e.item.type)a.push({type:"tool_call_chunk",name:e.item.name,args:e.item.arguments,id:e.item.call_id,index:e.output_index}),l[ob]={[e.item.call_id]:e.item.id};else if("response.output_item.done"===e.type&&["web_search_call","file_search_call","computer_call","code_interpreter_call","mcp_call","mcp_list_tools","mcp_approval_request","image_generation_call","custom_tool_call"].includes(e.item.type))l.tool_outputs=[e.item];else if("response.created"===e.type)o.id=e.response.id,o.model_name=e.response.model,o.model=e.response.model;else if("response.completed"===e.type){const n=this._convertResponsesMessageToBaseMessage(e.response);r=ab(e.response.usage),"json_schema"===(null==(i=null==(t=e.response.text)?void 0:t.format)?void 0:i.type)&&(l.parsed??(l.parsed=JSON.parse(n.text)));for(const[t,i]of Object.entries(e.response))"id"!==t&&(o[t]=i)}else if("response.function_call_arguments.delta"===e.type||"response.custom_tool_call_input.delta"===e.type)a.push({type:"tool_call_chunk",args:e.delta,index:e.output_index});else if("response.web_search_call.completed"===e.type||"response.file_search_call.completed"===e.type)s={tool_outputs:{id:e.item_id,type:e.type.replace("response.","").replace(".completed",""),status:"completed"}};else if("response.refusal.done"===e.type)l.refusal=e.refusal;else if("response.output_item.added"===e.type&&"item"in e&&"reasoning"===e.item.type){const t=e.item.summary?e.item.summary.map((e,t)=>({...e,index:t})):void 0;l.reasoning={id:e.item.id,type:e.item.type,...t?{summary:t}:{}}}else if("response.reasoning_summary_part.added"===e.type)l.reasoning={type:"reasoning",summary:[{...e.part,index:e.summary_index}]};else{if("response.reasoning_summary_text.delta"!==e.type)return e.type,null;l.reasoning={type:"reasoning",summary:[{text:e.delta,type:"summary_text",index:e.summary_index}]}}return new ql({text:n.map(e=>e.text).join(""),message:new qo({id:c,content:n,tool_call_chunks:a,usage_metadata:r,additional_kwargs:l,response_metadata:o}),generationInfo:s})}_convertMessagesToResponsesParams(e){return e.flatMap(e=>{var t,i,n,r;const s=e.additional_kwargs;let a=cb(e);if("system"===a&&lb(this.model)&&(a="developer"),"function"===a)throw new Error("Function messages are not supported in Responses API");if("tool"===a){const n=e;if("computer_call_output"===(null==s?void 0:s.type)){return{type:"computer_call_output",output:(()=>{if("string"==typeof n.content)return{type:"computer_screenshot",image_url:n.content};if(Array.isArray(n.content)){const e=n.content.find(e=>"computer_screenshot"===e.type);if(e)return e;const t=n.content.find(e=>"image_url"===e.type);if(t)return{type:"computer_screenshot",image_url:"string"==typeof t.image_url?t.image_url:t.image_url.url}}throw new Error("Invalid computer call output")})(),call_id:n.tool_call_id}}return(null==(t=n.metadata)?void 0:t.customTool)?{type:"custom_tool_call_output",call_id:n.tool_call_id,output:n.content}:{type:"function_call_output",call_id:n.tool_call_id,id:(null==(i=n.id)?void 0:i.startsWith("fc_"))?n.id:void 0,output:"string"!=typeof n.content?JSON.stringify(n.content):n.content}}if("assistant"===a){if(!this.zdrEnabled&&null!=e.response_metadata.output&&Array.isArray(e.response_metadata.output)&&e.response_metadata.output.length>0&&e.response_metadata.output.every(e=>"type"in e))return e.response_metadata.output;const t=[];if((null==s?void 0:s.reasoning)&&!this.zdrEnabled){const e=this._convertReasoningSummary(s.reasoning);t.push(e)}let{content:i}=e;(null==s?void 0:s.refusal)&&("string"==typeof i&&(i=[{type:"output_text",text:i,annotations:[]}]),i=[...i,{type:"refusal",refusal:s.refusal}]),("string"==typeof i||i.length>0)&&t.push({type:"message",role:"assistant",...e.id&&!this.zdrEnabled&&e.id.startsWith("msg_")?{id:e.id}:{},content:"string"==typeof i?i:i.flatMap(e=>"text"===e.type?{type:"output_text",text:e.text,annotations:e.annotations??[]}:"output_text"===e.type||"refusal"===e.type?e:[])});const a=null==s?void 0:s[ob];zo(e)&&(null==(n=e.tool_calls)?void 0:n.length)?t.push(...e.tool_calls.map(e=>function(e){return"tool_call"===e.type&&"isCustomTool"in e&&!0===e.isCustomTool}(e)?{type:"custom_tool_call",id:e.call_id,call_id:e.id??"",input:e.args.input,name:e.name}:{type:"function_call",name:e.name,arguments:JSON.stringify(e.args),call_id:e.id,...this.zdrEnabled?{id:null==a?void 0:a[e.id]}:{}})):(null==s?void 0:s.tool_calls)&&t.push(...s.tool_calls.map(e=>({type:"function_call",name:e.function.name,call_id:e.id,arguments:e.function.arguments,...this.zdrEnabled?{id:null==a?void 0:a[e.id]}:{}})));const o=(null==(r=e.response_metadata.output)?void 0:r.length)?e.response_metadata.output:s.tool_outputs,l=["computer_call","mcp_call","code_interpreter_call","image_generation_call"];if(null!=o){const e=null==o?void 0:o.filter(e=>l.includes(e.type));e.length>0&&t.push(...e)}return t}if("user"===a||"system"===a||"developer"===a){if("string"==typeof e.content)return{type:"message",role:a,content:e.content};const t=[],i=e.content.flatMap(e=>("mcp_approval_response"===e.type&&t.push({type:"mcp_approval_response",approval_request_id:e.approval_request_id,approve:e.approve}),xo(e)?Eo(e,hb):"text"===e.type?{type:"input_text",text:e.text}:"image_url"===e.type?{type:"input_image",image_url:"string"==typeof e.image_url?e.image_url:e.image_url.url,detail:"string"==typeof e.image_url?"auto":e.image_url.detail}:"input_text"===e.type||"input_image"===e.type||"input_file"===e.type?e:[]));return i.length>0&&t.push({type:"message",role:a,content:i}),t}return[]})}_convertReasoningSummary(e){const t=(e.summary.length>1?e.summary.reduce((e,t)=>{const i=e.at(-1);return i.index===t.index?i.text+=t.text:e.push(t),e},[{...e.summary[0]}]):e.summary).map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>"index"!==e)));return{...e,summary:t}}_reduceChatOpenAITools(e,t){const i=[];for(const n of e)ib(n)?("image_generation"===n.type&&(null==t?void 0:t.stream)&&(n.partial_images=1),i.push(n)):lp(n)?i.push({type:"function",name:n.function.name,parameters:n.function.parameters,description:n.function.description,strict:(null==t?void 0:t.strict)??null}):nb(n)&&i.push(sb(n));return i}}class fb extends db{invocationParams(e,t){var i;let n;void 0!==(null==e?void 0:e.strict)?n=e.strict:void 0!==this.supportsStrictToolCalling&&(n=this.supportsStrictToolCalling);let r={};void 0!==(null==e?void 0:e.stream_options)?r={stream_options:e.stream_options}:this.streamUsage&&(this.streaming||(null==t?void 0:t.streaming))&&(r={stream_options:{include_usage:!0}});const s={model:this.model,temperature:this.temperature,top_p:this.topP,frequency_penalty:this.frequencyPenalty,presence_penalty:this.presencePenalty,logprobs:this.logprobs,top_logprobs:this.topLogprobs,n:this.n,logit_bias:this.logitBias,stop:(null==e?void 0:e.stop)??this.stopSequences,user:this.user,stream:this.streaming,functions:null==e?void 0:e.functions,function_call:null==e?void 0:e.function_call,tools:(null==(i=null==e?void 0:e.tools)?void 0:i.length)?e.tools.map(e=>this._convertChatOpenAIToolToCompletionsTool(e,{strict:n})):void 0,tool_choice:Hy(null==e?void 0:e.tool_choice),response_format:this._getResponseFormat(null==e?void 0:e.response_format),seed:null==e?void 0:e.seed,...r,parallel_tool_calls:null==e?void 0:e.parallel_tool_calls,...this.audio||(null==e?void 0:e.audio)?{audio:this.audio||(null==e?void 0:e.audio)}:{},...this.modalities||(null==e?void 0:e.modalities)?{modalities:this.modalities||(null==e?void 0:e.modalities)}:{},...this.modelKwargs,prompt_cache_key:(null==e?void 0:e.promptCacheKey)??this.promptCacheKey,verbosity:(null==e?void 0:e.verbosity)??this.verbosity};void 0!==(null==e?void 0:e.prediction)&&(s.prediction=e.prediction),void 0!==this.service_tier&&(s.service_tier=this.service_tier),void 0!==(null==e?void 0:e.service_tier)&&(s.service_tier=e.service_tier);const a=this._getReasoningParams(e);return void 0!==a&&void 0!==a.effort&&(s.reasoning_effort=a.effort),lb(s.model)?s.max_completion_tokens=-1===this.maxTokens?void 0:this.maxTokens:s.max_tokens=-1===this.maxTokens?void 0:this.maxTokens,s}async _generate(e,t,i){var n,r;const s={},a=this.invocationParams(t),o=ub(e,this.model);if(a.stream){const r=this._streamResponseChunks(e,t,i),a={};for await(const e of r){e.message.response_metadata={...e.generationInfo,...e.message.response_metadata};const t=(null==(n=e.generationInfo)?void 0:n.completion)??0;void 0===a[t]?a[t]=e:a[t]=a[t].concat(e)}const o=Object.entries(a).sort(([e],[t])=>parseInt(e,10)-parseInt(t,10)).map(([e,t])=>t),{functions:l,function_call:c}=this.invocationParams(t),h=await this._getEstimatedTokenCountFromPrompt(e,l,c),u=await this._getNumTokensFromGenerations(o);return s.input_tokens=h,s.output_tokens=u,s.total_tokens=h+u,{generations:o,llmOutput:{estimatedTokenUsage:{promptTokens:s.input_tokens,completionTokens:s.output_tokens,totalTokens:s.total_tokens}}}}{const e=await this.completionWithRetry({...a,stream:!1,messages:o},{signal:null==t?void 0:t.signal,...null==t?void 0:t.options}),{completion_tokens:i,prompt_tokens:n,total_tokens:l,prompt_tokens_details:c,completion_tokens_details:h}=(null==e?void 0:e.usage)??{};i&&(s.output_tokens=(s.output_tokens??0)+i),n&&(s.input_tokens=(s.input_tokens??0)+n),l&&(s.total_tokens=(s.total_tokens??0)+l),null===(null==c?void 0:c.audio_tokens)&&null===(null==c?void 0:c.cached_tokens)||(s.input_token_details={...null!==(null==c?void 0:c.audio_tokens)&&{audio:null==c?void 0:c.audio_tokens},...null!==(null==c?void 0:c.cached_tokens)&&{cache_read:null==c?void 0:c.cached_tokens}}),null===(null==h?void 0:h.audio_tokens)&&null===(null==h?void 0:h.reasoning_tokens)||(s.output_token_details={...null!==(null==h?void 0:h.audio_tokens)&&{audio:null==h?void 0:h.audio_tokens},...null!==(null==h?void 0:h.reasoning_tokens)&&{reasoning:null==h?void 0:h.reasoning_tokens}});const u=[];for(const t of(null==e?void 0:e.choices)??[]){const i={text:(null==(r=t.message)?void 0:r.content)??"",message:this._convertCompletionsMessageToBaseMessage(t.message??{role:"assistant"},e)};i.generationInfo={...t.finish_reason?{finish_reason:t.finish_reason}:{},...t.logprobs?{logprobs:t.logprobs}:{}},zo(i.message)&&(i.message.usage_metadata=s),i.message=new Do(Object.fromEntries(Object.entries(i.message).filter(([e])=>!e.startsWith("lc_")))),u.push(i)}return{generations:u,llmOutput:{tokenUsage:{promptTokens:s.input_tokens,completionTokens:s.output_tokens,totalTokens:s.total_tokens}}}}}async*_streamResponseChunks(e,t,i){var n,r,s,a,o,l,c,h,u,d;const p=ub(e,this.model),f={...this.invocationParams(t,{streaming:!0}),messages:p,stream:!0};let m;const g=await this.completionWithRetry(f,t);let O;for await(const v of g){const e=null==(n=null==v?void 0:v.choices)?void 0:n[0];if(v.usage&&(O=v.usage),!e)continue;const{delta:r}=e;if(!r)continue;const s=this._convertCompletionsDeltaToBaseMessageChunk(r,v,m);m=r.role??m;const a={prompt:t.promptIndex??0,completion:e.index??0};if("string"!=typeof s.content)continue;const o={...a};null!=e.finish_reason&&(o.finish_reason=e.finish_reason,o.system_fingerprint=v.system_fingerprint,o.model_name=v.model,o.service_tier=v.service_tier),this.logprobs&&(o.logprobs=e.logprobs);const l=new ql({message:s,text:s.content,generationInfo:o});yield l,await(null==i?void 0:i.handleLLMNewToken(l.text??"",a,void 0,void 0,void 0,{chunk:l}))}if(O){const e={...null!==(null==(r=O.prompt_tokens_details)?void 0:r.audio_tokens)&&{audio:null==(s=O.prompt_tokens_details)?void 0:s.audio_tokens},...null!==(null==(a=O.prompt_tokens_details)?void 0:a.cached_tokens)&&{cache_read:null==(o=O.prompt_tokens_details)?void 0:o.cached_tokens}},t={...null!==(null==(l=O.completion_tokens_details)?void 0:l.audio_tokens)&&{audio:null==(c=O.completion_tokens_details)?void 0:c.audio_tokens},...null!==(null==(h=O.completion_tokens_details)?void 0:h.reasoning_tokens)&&{reasoning:null==(u=O.completion_tokens_details)?void 0:u.reasoning_tokens}},i=new ql({message:new qo({content:"",response_metadata:{usage:{...O}},usage_metadata:{input_tokens:O.prompt_tokens,output_tokens:O.completion_tokens,total_tokens:O.total_tokens,...Object.keys(e).length>0&&{input_token_details:e},...Object.keys(t).length>0&&{output_token_details:t}}}),text:""});yield i}if(null==(d=t.signal)?void 0:d.aborted)throw new Error("AbortError")}async completionWithRetry(e,t){const i=this._getClientOptions(t),n=e.response_format&&"json_schema"===e.response_format.type;return this.caller.call(async()=>{try{return n&&!e.stream?await this.client.chat.completions.parse(e,i):await this.client.chat.completions.create(e,i)}catch(t){throw Gy(t)}})}_convertCompletionsMessageToBaseMessage(e,t){var i,n;const r=e.tool_calls;if("assistant"===e.role){const a=[],o=[];for(const e of r??[])try{a.push(dy(e,{returnId:!0}))}catch(s){o.push(fy(e,s.message))}const l={function_call:e.function_call,tool_calls:r};void 0!==this.__includeRawResponse&&(l.__raw_response=t);const c={model_name:t.model,...t.system_fingerprint?{usage:{...t.usage},system_fingerprint:t.system_fingerprint}:{}};e.audio&&(l.audio=e.audio);const h=function(e,t){if(t&&"object"==typeof t&&"images"in t&&Array.isArray(t.images))return[{type:"text",text:e,source_type:"text"},...t.images.filter(e=>{var t;return"string"==typeof(null==(t=null==e?void 0:e.image_url)?void 0:t.url)}).map(e=>({type:"image",url:e.image_url.url,source_type:"url"}))];return e}(e.content||"",null==(n=null==(i=t.choices)?void 0:i[0])?void 0:n.message);return new Do({content:h,tool_calls:a,invalid_tool_calls:o,additional_kwargs:l,response_metadata:c,id:t.id})}return new Xo(e.content||"",e.role??"unknown")}_convertCompletionsDeltaToBaseMessageChunk(e,t,i){var n,r;const s=e.role??i,a=e.content??"";let o;o=e.function_call?{function_call:e.function_call}:e.tool_calls?{tool_calls:e.tool_calls}:{},this.__includeRawResponse&&(o.__raw_response=t),e.audio&&(o.audio={...e.audio,index:t.choices[0].index});const l={usage:{...t.usage}};if("user"===s)return new Fo({content:a,response_metadata:l});if("assistant"===s){const i=[];if(Array.isArray(e.tool_calls))for(const t of e.tool_calls)i.push({name:null==(n=t.function)?void 0:n.name,args:null==(r=t.function)?void 0:r.arguments,id:t.id,index:t.index,type:"tool_call_chunk"});return new qo({content:a,tool_call_chunks:i,additional_kwargs:o,id:t.id,response_metadata:l})}return"system"===s?new Ho({content:a,response_metadata:l}):"developer"===s?new Ho({content:a,response_metadata:l,additional_kwargs:{__openai_role__:"developer"}}):"function"===s?new Wo({content:a,additional_kwargs:o,name:e.name,response_metadata:l}):"tool"===s?new Zo({content:a,additional_kwargs:o,tool_call_id:e.tool_call_id,response_metadata:l}):new Bo({content:a,role:s,response_metadata:l})}}class mb extends db{get lc_serializable_keys(){return[...super.lc_serializable_keys,"useResponsesApi"]}constructor(e){super(e),Object.defineProperty(this,"fields",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"useResponsesApi",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"responses",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"completions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.useResponsesApi=(null==e?void 0:e.useResponsesApi)??!1,this.responses=(null==e?void 0:e.responses)??new pb(e),this.completions=(null==e?void 0:e.completions)??new fb(e)}_useResponsesApi(e){var t,i,n,r;const s=null==(t=null==e?void 0:e.tools)?void 0:t.some(ib),a=null!=(null==e?void 0:e.previous_response_id)||null!=(null==e?void 0:e.text)||null!=(null==e?void 0:e.truncation)||null!=(null==e?void 0:e.include)||null!=(null==(i=null==e?void 0:e.reasoning)?void 0:i.summary)||null!=(null==(n=this.reasoning)?void 0:n.summary),o=null==(r=null==e?void 0:e.tools)?void 0:r.some(nb);return this.useResponsesApi||s||a||o}getLsParams(e){const t=this._combineCallOptions(e);return this._useResponsesApi(e)?this.responses.getLsParams(t):this.completions.getLsParams(t)}invocationParams(e){const t=this._combineCallOptions(e);return this._useResponsesApi(e)?this.responses.invocationParams(t):this.completions.invocationParams(t)}async _generate(e,t,i){return this._useResponsesApi(t)?this.responses._generate(e,t):this.completions._generate(e,t,i)}async*_streamResponseChunks(e,t,i){this._useResponsesApi(t)?yield*this.responses._streamResponseChunks(e,this._combineCallOptions(t),i):yield*this.completions._streamResponseChunks(e,this._combineCallOptions(t),i)}withConfig(e){const t=new mb(this.fields);return t.defaultOptions={...this.defaultOptions,...e},t}}class gb{constructor(e){ge(this,r,"http://localhost:8091"),ge(this,s,"booxtory_250131"),ge(this,a),ge(this,o),pe(this,"prompt",null),ge(this,l,()=>{switch(me(this,o).settings.server){case"chatopenai":Oe(this,a,new mb({modelName:me(this,o).settings.model,openAIApiKey:me(this,o).settings.CHATOPENAI_API_KEY,configuration:{baseURL:"https://openrouter.ai/api/v1"},temperature:0}));break;case"gemini":Oe(this,a,new Np({model:me(this,o).settings.model,apiKey:me(this,o).settings.geminiApiKey,temperature:0}));break;case"openai":Oe(this,a,new mb({model:me(this,o).settings.model,apiKey:me(this,o).settings.openaiApiKey,temperature:0}));break;case"ollama":Oe(this,a,new kf({model:me(this,o).settings.model,host:me(this,o).settings.ollamaUrl,temperature:0}))}}),ge(this,c,()=>{let e=[];return t.querySelectorAll("nx-side-menu-item[href][title]").forEach(t=>{e.push({url:t.getAttribute("href"),title:t.getAttribute("title")})}),e}),ge(this,h,async()=>{const e=await fetch("/nine-ai/meta/selectTableList",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schema:me(this,s)})});return await e.json()}),ge(this,u,async e=>{const t=await fetch("/nine-ai/meta/selectColumnInfo",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schema:me(this,s),tables:e})});return await t.json()}),ge(this,d,async(e,t)=>{const i=await Mu.generatePrompt(e,t);try{const e=await me(this,a).invoke([new Vo(i)]);return Mu.extractResponse(e,me(this,o).settings.server)}catch(n){throw n}}),ge(this,p,async e=>{const t=await me(this,d).call(this,"/prompts/meta/1.what.txt",{userPrompt:e});if("[object Object]"!==Object.prototype.toString.call(t)||!t.hasOwnProperty("result"))throw new Error(t);if("0"===t.result)throw new Error(t.reason);return t.result}),ge(this,f,async(e,t,i)=>{const n=await me(this,d).call(this,"/prompts/meta/2.where.txt",{userPrompt:e,menuList:JSON.stringify(t),tableDefinitions:JSON.stringify(i)});if("[object Object]"!==Object.prototype.toString.call(n)||!n.hasOwnProperty("result"))throw new Error(n);if("0"===n.result)throw new Error(n.reason);return n}),ge(this,m,async(e,t,i)=>{let n=await me(this,d).call(this,e,i);return n.endsWith("```")&&(n=n.slice(0,-3)),await ju.post("/nine-ai/source/generateTmplFile",{basePath:`${me(this,o).settings.beProjectName}/tmpl`,fileNm:t,contents:n}),n}),ge(this,g,()=>{const e=document.querySelectorAll('div[class^="detail-wrapper-"]');for(const t of e)if(""===t.innerHTML.trim()){const e=t.className.match(/detail-wrapper-([^ ]+)/);if(e&&e[1])return e[1]}return null}),ge(this,O,()=>{const e=document.querySelectorAll('div[class^="detail-wrapper-"]');for(let t=0;t<e.length;t++){const i=e[t];if(i.classList.contains("active")){const e=i.className.match(/detail-wrapper-([^ ]+)/);if(e&&e[1])return e[1]}}return null}),ge(this,v,e=>{const t=e.replace(/^\/+/,""),i=t.split("/").join(".").toLowerCase().replace(/[^a-z0-9.]/g,""),n=`${me(this,o).config.basePackage}.${i}`,r=n.split(".").slice(0,-1).join("."),s=t.split("/").at(-1).toLowerCase().split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(""),a=`${i.split(".").slice(0,-1).join("/")}/${t.split("/").at(-1)}`,l=me(this,g).call(this),c=me(this,O).call(this),h=c?a+"-detail-"+c:a,u=a+"-detail-"+l,d=c?s+"Detail"+c:s,p=s+"Detail"+l;return{package:r,namespace:n,baseClass:s,resultType:"ide.assi.util.CamelCaseMap",mybatis:`${i.split(".").slice(0,-1).join("/")}/${s}Mapper.xml`,classFrom:d,classTo:p,activeIndex:c,emptyIndex:l,mybatisPullPath:`${me(this,o).settings.beProjectName}/src/main/resources/mapper/${i.split(".").slice(0,-1).join("/")}/${s}Mapper.xml`,controllerPullPath:`${me(this,o).settings.beProjectName}/src/main/java/${r.replaceAll(".","/")}/controller/${s}Controller.java`,servicePullPath:`${me(this,o).settings.beProjectName}/src/main/java/${r.replaceAll(".","/")}/service/${s}Service.java`,javascriptFrom:`${me(this,o).settings.feProjectName}/src/views/${h}.jsx`,javascriptTo:`${me(this,o).settings.feProjectName}/src/views/${u}.jsx`}}),ge(this,y,async(e,i,n,r)=>{let s,a;if("C1"===e)s=await me(this,f).call(this,i,me(this,c).call(this),await me(this,h).call(this)),a=s.menu.url;else{if(!["U1","U2","C2"].includes(e))throw new Error("invalid command type.");{const e=t.querySelector("nx-side-menu-item.active");if(!e)throw new Error("관련 메뉴를 찾을 수 없습니다.");a=e.getAttribute("href");const n=e.getAttribute("title");s=await me(this,f).call(this,`${n}에서 ${i}`,[{url:a,title:n}],await me(this,h).call(this))}}const o=me(this,v).call(this,a),l=await ju.post("/nine-ai/source/read",o);r.updateProgress("prepare2","completed");const d=await me(this,u).call(this,s.table);let p={mybatis:l.mybatis,service:l.service,controller:l.controller,javascriptFrom:l.javascriptFrom,javascriptTo:l.javascriptTo};if(n.mybatis&&(p.mybatis=await me(this,m).call(this,"/prompts/meta/U.BuildMyBatisMapper.txt","mybatis.xml",{userPrompt:i,originSrc:l.mybatis,resultType:o.resultType,namespace:o.namespace,tableDefinitions:JSON.stringify(d)}),r.updateProgress("mybatis","completed")),n.service&&(p.service=await me(this,m).call(this,"/prompts/meta/U.BuildService.txt","service.java",{userPrompt:i,originSrc:l.service,baseClass:o.baseClass,myBatisPath:o.mybatis,namespace:o.namespace,package:o.package+".service",mybatisXmlSource:p.mybatis}),r.updateProgress("service","completed")),n.controller&&(p.controller=await me(this,m).call(this,"/prompts/meta/U.BuildController.txt","controller.java",{userPrompt:i,originSrc:l.controller,baseClass:o.baseClass,menuUrl:s.menu.url,package:o.package+".controller",serviceSource:p.service}),r.updateProgress("controller","completed")),n.javascript){const t=this.prompt.react.filter(e=>e.includes(".main.")||e.includes(".all.")),n=this.prompt.react.filter(e=>e.includes(".sub.")||e.includes(".all."));if(["C1","U1"].includes(e)){const e=o.javascriptTo.split("/").pop();p.javascriptFrom=await me(this,m).call(this,t,"reactFrom.jsx",{userPrompt:i,mybatis:o.mybatis,originSrc:l.javascriptFrom,menuUrl:s.menu.url,menuName:s.menu.name,baseClass:o.baseClass,classFrom:o.classFro,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:e,mybatisXmlSource:p.mybatis,controllerSource:p.controller,tableDefinitions:JSON.stringify(d)})}else{const e=o.javascriptTo.split("/").pop();p.javascriptFrom=await me(this,m).call(this,t,"reactFrom.jsx",{userPrompt:i,mybatis:o.mybatis,originSrc:l.javascriptFrom,menuUrl:s.menu.url,menuName:s.menu.name,baseClass:o.baseClass,classFrom:o.classFrom,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:e,mybatisXmlSource:p.mybatis,controllerSource:p.controller,tableDefinitions:JSON.stringify(d)}),p.javascriptTo=await me(this,m).call(this,n,"reactTo.jsx",{userPrompt:i,mybatis:o.mybatis,originSrc:l.javascriptTo,menuUrl:s.menu.url,menuName:s.menu.name,baseClass:o.baseClass,classFrom:o.classFrom,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:e,mybatisXmlSource:p.mybatis,controllerSource:p.controller,tableDefinitions:JSON.stringify(d)})}r.updateProgress("javascript","completed")}const g=[],O={mybatis:{path:o.mybatisPullPath,src:p.mybatis},service:{path:o.servicePullPath,src:p.service},controller:{path:o.controllerPullPath,src:p.controller},javascriptFrom:{path:o.javascriptFrom,src:p.javascriptFrom},javascriptTo:{path:o.javascriptTo,src:p.javascriptTo}};n.javascript&&(n.javascriptFrom=!0,n.javascriptTo=!0,n.javascript=!1);for(const t in n)n[t]&&O[t].src&&g.push({[t]:{asis:l[t],tobe:O[t].src,tobePath:O[t].path}});return g}),ge(this,b,async(e,i,n)=>{const r=t.querySelector("nx-side-menu-item.active");if(!r)throw new Error("관련 메뉴를 찾을 수 없습니다.");const s=r.getAttribute("href"),a=r.getAttribute("title"),o=me(this,v).call(this,s),l=await ju.post("/nine-ai/source/read",o),c=await me(this,f).call(this,`${a}에서 ${e}`,[{url:s,title:a}],await me(this,h).call(this));n.updateProgress("prepare2","completed");const d=await me(this,u).call(this,c.table);let p,g,O,y,b;if(i.mybatis?(p=await me(this,m).call(this,"/prompts/meta/U.BuildMyBatisMapper.txt","mybatis.xml",{userPrompt:e,originSrc:l.mybatis,resultType:o.resultType,namespace:o.namespace,tableDefinitions:JSON.stringify(d)}),n.updateProgress("mybatis","completed")):p=l.mybatis,i.service?(g=await me(this,m).call(this,"/prompts/meta/U.BuildService.txt","service.java",{userPrompt:e,originSrc:l.service,baseClass:o.baseClass,myBatisPath:o.mybatis,namespace:o.namespace,package:o.package+".service",mybatisXmlSource:p}),n.updateProgress("service","completed")):g=l.service,i.controller?(O=await me(this,m).call(this,"/prompts/meta/U.BuildController.txt","controller.java",{userPrompt:e,originSrc:l.controller,baseClass:o.baseClass,menuUrl:c.menu.url,package:o.package+".controller",serviceSource:g}),n.updateProgress("controller","completed")):O=l.controller,i.javascript){const t=o.javascriptTo.split("/").pop();y=await me(this,m).call(this,"/prompts/meta/detail/4.BuildReactJsx_Link.txt","reactFrom.jsx",{userPrompt:e,mybatis:o.mybatis,originSrc:l.javascript2,menuUrl:c.menu.url,menuName:c.menu.name,baseClass:o.baseClass,classFrom:o.classFrom,classTo:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,javascriptFileTo:t,mybatisXmlSource:p,controllerSource:O,tableDefinitions:JSON.stringify(d)}),b=await me(this,m).call(this,"/prompts/meta/detail/4.BuildReactJsx_Detail.txt","reactTo.jsx",{userPrompt:e,mybatis:o.mybatis,originSrc:l.javascript,menuUrl:c.menu.url,menuName:c.menu.name,baseClass:o.baseClass,className:o.classTo,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,mybatisXmlSource:p,controllerSource:O,tableDefinitions:JSON.stringify(d)}),n.updateProgress("javascript","completed")}else b=l.javascriptTo;const w=[],_={mybatis:{path:o.mybatisPullPath,src:p},service:{path:o.servicePullPath,src:g},controller:{path:o.controllerPullPath,src:O},javascript:{path:o.javascriptToPullPath,src:b},javascript2:{path:o.javascriptFromPullPath,src:y}};i.javascript&&(i.javascript2=!0);for(const t in i)i[t]&&w.push({[t]:{asis:l[t],tobe:_[t].src,tobePath:_[t].path}});return w}),ge(this,w,async(e,i,n)=>{const r=t.querySelector("nx-side-menu-item.active");if(!r)throw new Error("관련 메뉴를 찾을 수 없습니다.");const s=r.getAttribute("href"),a=r.getAttribute("title"),o=me(this,v).call(this,s),l=await ju.post("/nine-ai/source/read",o),c=await me(this,f).call(this,`${a}에서 ${e}`,[{url:s,title:a}],await me(this,h).call(this));n.updateProgress("prepare2","completed");const d=await me(this,u).call(this,c.table);let p,g,O,y;i.mybatis?(p=await me(this,m).call(this,"/prompts/meta/U.BuildMyBatisMapper.txt","mybatis.xml",{userPrompt:e,originSrc:l.mybatis,resultType:o.resultType,namespace:o.namespace,tableDefinitions:JSON.stringify(d)}),n.updateProgress("mybatis","completed")):p=l.mybatis,i.service?(g=await me(this,m).call(this,"/prompts/meta/U.BuildService.txt","service.java",{userPrompt:e,originSrc:l.service,baseClass:o.baseClass,myBatisPath:o.mybatis,namespace:o.namespace,package:o.package+".service",mybatisXmlSource:p}),n.updateProgress("service","completed")):g=l.service,i.controller?(O=await me(this,m).call(this,"/prompts/meta/U.BuildController.txt","controller.java",{userPrompt:e,originSrc:l.controller,baseClass:o.baseClass,menuUrl:c.menu.url,package:o.package+".controller",serviceSource:g}),n.updateProgress("controller","completed")):O=l.controller,i.javascript?(y=await me(this,m).call(this,"/prompts/meta/detail/4.BuildReactJsx_Detail.txt","reactTo.jsx",{userPrompt:e,mybatis:o.mybatis,originSrc:l.javascriptFrom,menuUrl:c.menu.url,menuName:c.menu.name,baseClass:o.baseClass,className:o.classFrom,emptyIndex:o.emptyIndex,activeIndex:o.activeIndex,mybatisXmlSource:p,controllerSource:O,tableDefinitions:JSON.stringify(d)}),n.updateProgress("javascript","completed")):y=l.javascriptTo;const b=[],w={mybatis:{path:o.mybatisPullPath,src:p},service:{path:o.servicePullPath,src:g},controller:{path:o.controllerPullPath,src:O},javascript:{path:o.javascriptFromPullPath,src:y}};l.javascript=l.javascriptFrom;for(const t in i)i[t]&&b.push({[t]:{asis:l[t],tobe:w[t].src,tobePath:w[t].path}});return b}),pe(this,"generateSourceClient",async(e,t)=>{me(this,l).call(this);const i=[{id:"prepare1",message:"명령을 해석중입니다.",completedMessage:"명령을 해석했습니다."},{id:"prepare2",message:"메뉴와 테이블을 검색중입니다.",completedMessage:"관련 메뉴와 테이블을 찾았습니다."}];t.mybatis&&i.push({id:"mybatis",message:"MyBatis 소스를 생성중입니다.",completedMessage:"MyBatis 소스를 생성했습니다."}),t.service&&i.push({id:"service",message:"Java(Service) 소스를 생성중입니다.",completedMessage:"Java(Service) 소스를 생성했습니다."}),t.controller&&i.push({id:"controller",message:"Java(Controller) 소스를 생성중입니다.",completedMessage:"Java(Controller) 소스를 생성했습니다."}),t.javascript&&i.push({id:"javascript",message:"Jsx(React) 소스를 생성중입니다.",completedMessage:"Jsx(React) 소스를 생성했습니다."});const n=me(this,o).shadowRoot.querySelector("nx-ai-chat").addProgress(i),r=await me(this,p).call(this,e);if(n.updateProgress("prepare1","completed"),["C1","C2"].includes(r)&&t.mybatis&&t.service&&t.controller&&t.javascript,"C1"===r)return await me(this,y).call(this,r,e,t,n);if("C2"===r)return await me(this,y).call(this,r,e,t,n);if("U1"===r){return document.querySelector(".list-wrapper.active")?await me(this,y).call(this,r,e,t,n):await me(this,y).call(this,"U2",e,t,n)}}),Oe(this,o,e)}}r=new WeakMap,s=new WeakMap,a=new WeakMap,o=new WeakMap,l=new WeakMap,c=new WeakMap,h=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,m=new WeakMap,g=new WeakMap,O=new WeakMap,v=new WeakMap,y=new WeakMap,b=new WeakMap,w=new WeakMap,pe(gb,"generateWhereCause",async(e,t,i,n)=>{const r=await ju.post("/nine-ai/source/query",{xmlPath:e,queryId:t});if(r.query){return await(async(e,t)=>{const i=await Mu.generatePrompt(e,t);try{const e=new Np({model:"gemini-2.5-flash",apiKey:n,temperature:0}),t=await e.invoke([new Vo(i)]);return Mu.extractResponse(t,"gemini")}catch(r){throw r}})("/prompts/user/generateWhereCause.txt",{query:r.query,userPrompt:i})}});var Ob,vb,yb,bb,wb,_b,xb=Object.defineProperty,Sb=e=>{throw TypeError(e)},kb=(e,t,i)=>((e,t,i)=>t in e?xb(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i),Pb=(e,t,i)=>t.has(e)||Sb("Cannot "+i),Tb=(e,t,i)=>(Pb(e,t,"read from private field"),t.get(e)),$b=(e,t,i)=>t.has(e)?Sb("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Eb=(e,t,i,n)=>(Pb(e,t,"write to private field"),t.set(e,i),i);Ob=new WeakMap,vb=new WeakMap,yb=new WeakMap,bb=new WeakSet,wb=function(){if("undefined"==typeof window)return;"localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname||window.location.hostname.startsWith("192.168.")?this.enable():this.disable()};const Ab=new class{constructor(e=null,t="green"){$b(this,bb),$b(this,Ob),$b(this,vb),$b(this,yb,!0),Eb(this,Ob,e),Eb(this,vb,t),((e,t,i)=>(Pb(e,t,"access private method"),i))(this,bb,wb).call(this)}init(e,t="green"){Eb(this,Ob,e),Eb(this,vb,t)}log(...e){if(!Tb(this,yb))return;Tb(this,vb);Tb(this,Ob)}warn(...e){Tb(this,yb)&&Tb(this,Ob)}error(...e){Tb(this,Ob)}enable(){Eb(this,yb,!0)}disable(){Eb(this,yb,!1)}};"undefined"!=typeof window&&(window.trace=Ab);class Cb{static show(){let e=document.getElementById("global-loading-overlay");if(!e&&(e=document.createElement("div"),e.id="global-loading-overlay",e.style.cssText="\n position: fixed; inset: 0; z-index: 9999;\n background: rgba(0, 0, 0, 0.4); display: flex; \n justify-content: center; align-items: center;\n backdrop-filter: blur(2px);\n ",e.innerHTML='<div class="loading-spinner"></div>',document.body.appendChild(e),!document.getElementById("nine-util-style"))){const e=document.createElement("style");e.id="nine-util-style",e.innerHTML="\n .loading-spinner {\n width: 48px; height: 48px;\n border: 5px solid rgba(255, 255, 255, 0.3);\n border-top-color: white; border-radius: 50%;\n animation: nine-spin 1s linear infinite;\n }\n @keyframes nine-spin { to { transform: rotate(360deg); } }\n ",document.head.appendChild(e)}e.style.display="flex"}static hide(){const e=document.getElementById("global-loading-overlay");e&&(e.style.display="none")}}const Rb=class{};_b=new WeakMap,kb(Rb,"BASE_URL",window.__API_BASE_URL__||""),$b(Rb,_b,(e,t,i={})=>{const n=t.startsWith("http")?t:`${Rb.BASE_URL}${t}`;Cb.show();const r={method:e,headers:{"Content-Type":"application/json"}};let s=n;return"GET"===e?s+=`?${new URLSearchParams(i)}`:r.body=JSON.stringify(i),fetch(s,r).then(async e=>{if(t.includes("/api/source/query")||Cb.hide(),!e.ok){const t=await e.text();throw new Error(`API 오류 (${e.status}): ${t}`)}return e.json()}).catch(e=>{throw Cb.hide(),e})}),kb(Rb,"get",(e,t={})=>{var i;return Tb(i=Rb,_b).call(i,"GET",e,t)}),kb(Rb,"post",(e,t={})=>{var i;return Tb(i=Rb,_b).call(i,"POST",e,t)});const Qb=Rb;class Ib extends HTMLElement{constructor(){super(),ge(this,_,!1),ge(this,x),pe(this,"settings"),pe(this,"config"),ge(this,S,async()=>{this.config=await Qb.post("/nine-ai/config/get")}),ge(this,k,()=>{["mybatis","service","controller","javascript"].forEach(e=>{const t="true"===localStorage.getItem(`ide-assi-${e}`);this.shadowRoot.querySelector(`#${e}`).checked=t})}),ge(this,P,e=>{Object.entries(e).forEach(([e,t])=>{localStorage.setItem(`ide-assi-${e}`,String(t))})}),ge(this,T,()=>{me(this,S).call(this),me(this,k).call(this),this.settings=this.shadowRoot.querySelector("ide-assi-settings");const e=document.createElement("ide-tip-popup");this.shadowRoot.appendChild(e);const t=document.createElement("ide-diff-popup");this.shadowRoot.appendChild(t),this.shadowRoot.querySelector("textarea").addEventListener("keydown",me(this,$)),this.shadowRoot.querySelector(".expand-icon").addEventListener("click",me(this,E)),this.shadowRoot.querySelector(".collapse-icon").addEventListener("click",me(this,E)),this.shadowRoot.querySelectorAll(".menu-icon").forEach(e=>e.addEventListener("click",me(this,A))),setTimeout(()=>{Qb.post("/nine-ai/prompt/dir",{feProjectName:this.settings.feProjectName}).then(e=>{me(this,x).prompt=e})},1e3)}),pe(this,"addMessage",e=>{const t=this.shadowRoot.querySelector("nx-ai-chat");t.add("ai",e),t.add("ing","...")}),ge(this,$,async e=>{if("Enter"!==e.key)return;e.preventDefault();const t={mybatis:this.shadowRoot.querySelector("#mybatis").checked,service:this.shadowRoot.querySelector("#service").checked,controller:this.shadowRoot.querySelector("#controller").checked,javascript:this.shadowRoot.querySelector("#javascript").checked};if(!(t.mybatis||t.service||t.controller||t.javascript))return;const i=e.target.value.trim();if(!i)return;if(me(this,_))return;Oe(this,_,!0),me(this,P).call(this,t),setTimeout(()=>{this.shadowRoot.querySelector("textarea").value=""});const n=this.shadowRoot.querySelector("nx-ai-chat");n.add("me",i),n.add("ing","...");const r=this.shadowRoot.querySelector("ide-tip-popup");r.popup();try{const e=await me(this,x).generateSourceClient(i,t);r.close(),e&&this.shadowRoot.querySelector("ide-diff-popup").popup(e)}catch(s){r.close(),n.add("ai",String(s).replace("Error:",""))}Oe(this,_,!1)}),ge(this,E,()=>{this.classList.toggle("collapse")}),ge(this,A,e=>{this.shadowRoot.querySelectorAll(".menu-icon").forEach(e=>e.classList.remove("active"));const t=e.target.closest(".menu-icon");t&&t.classList.add("active"),this.settings.classList.toggle("expand",!!e.target.closest(".menu-setting"))}),this.attachShadow({mode:"open"}),Oe(this,x,new gb(this))}connectedCallback(){this.shadowRoot.innerHTML=`\n\t\t\t<style>\n\t\t\t\t@import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n\t\t\t\t${t.getCustomPath(this,"ideAssi.css")}\n\t\t\t</style>\n\n\t\t\t<div class="wrapper">\n\t\t\t\t<ide-assi-settings></ide-assi-settings>\n\t\t\t\n\t\t\t\t<div class="container">\n\t\t\t\t\t<div class="head">\n\t\t\t\t\t\t<div class="logo"><span></span></div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<nx-ai-chat></nx-ai-chat>\n\t\t\t\t\t<div class="foot">\n\t\t\t\t\t\t<div class="apply-src">\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="mybatis" name="mybatis" value="Y" checked />\n\t\t\t\t\t\t\t <label for="mybatis">MyBatis</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="service" name="service" value="Y" checked />\n\t\t\t\t\t\t\t <label for="service">Service</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="controller" name="controller" value="Y" checked />\n\t\t\t\t\t\t\t <label for="controller">Controller</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t <input type="checkbox" id="javascript" name="javascript" value="Y" checked />\n\t\t\t\t\t\t\t <label for="javascript">JavaScript</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<textarea name="ask" id="q" name="q" rows="4" placeholder="나에게 무엇이든 물어봐..."></textarea>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div class="menu">\n\t\t\t\t\t<div class="collapse-icon"></div>\n\t\t\t\t\t<div class="menu-icon menu-filter active"></div>\n\t\t\t\t\t<div class="menu-icon menu-general"></div>\n\t\t\t\t\t<div class="menu-icon menu-setting"></div>\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t<div class="expand-icon"></div>\n\t\t`,requestAnimationFrame(()=>{me(this,T).call(this)})}}_=new WeakMap,x=new WeakMap,S=new WeakMap,k=new WeakMap,P=new WeakMap,T=new WeakMap,$=new WeakMap,E=new WeakMap,A=new WeakMap,customElements.define("nine-ai",Ib);class jb extends HTMLElement{constructor(){super(),ge(this,C,()=>{this.shadowRoot.querySelectorAll('input[name="server"]').forEach(e=>{e.addEventListener("change",()=>{const e=this.shadowRoot.querySelector('input[name="server"]:checked').value;["gemini","openai","ollama","chatopenai"].forEach(t=>{this.shadowRoot.querySelectorAll("."+t).forEach(i=>{i.style.display=e===t?"flex":"none"})})})})}),this.attachShadow({mode:"open"})}get geminiApiKey(){return this.shadowRoot.querySelector("#geminiApiKey").value}set geminiApiKey(e){this.shadowRoot.querySelector("#geminiApiKey").value=e}get openaiApiKey(){return this.shadowRoot.querySelector("#openaiApiKey").value}set openaiApiKey(e){this.shadowRoot.querySelector("#openaiApiKey").value=e}get ollamaUrl(){return this.shadowRoot.querySelector("#ollamaUrl").value}set ollamaUrl(e){this.shadowRoot.querySelector("#ollamaUrl").value=e}get qdrantUrl(){return this.shadowRoot.querySelector("#qdrantUrl").value}set qdrantUrl(e){this.shadowRoot.querySelector("#qdrantUrl").value=e}get server(){var e;return null==(e=this.shadowRoot.querySelector('input[name="server"]:checked'))?void 0:e.value}set server(e){const t=this.shadowRoot.querySelector(`input[name="server"][value="${e}"]`);t&&(t.checked=!0),this.shadowRoot.querySelectorAll('input[name="server"]').forEach(e=>{e.dispatchEvent(new Event("change"))})}get model(){var e;return null==(e=this.shadowRoot.querySelector(`#${this.server}Model`))?void 0:e.value}set model(e){const t=this.shadowRoot.querySelector(`#${this.server}Model`);t&&(t.value=e,t.dispatchEvent(new Event("change")))}connectedCallback(){this.shadowRoot.innerHTML=`\n\t\t\t<style>\n\t\t\t\t@import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n\t\t\t\t${t.getCustomPath(this,"ideAssi.css")}\n\t\t\t</style>\n\n\t\t\t<div class="line subject">\n\t\t\t\t<label for="server">Server:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents">\n\t\t\t\t\x3c!--<label><input name="server" type="radio" value="chatopenai" >Chat Open AI</label>--\x3e\n\t\t\t\t<label><input name="server" type="radio" value="gemini" checked>Gemini</label>\n\t\t\t\t<label><input name="server" type="radio" value="openai">Open AI</label>\n\t\t\t\t<label><input name="server" type="radio" value="ollama">Ollama</label>\n\t\t\t</div>\n\t\t\t<div class="line gemini-bak" style="display:none;">\n\t\t\t\t<label>API Key: <input id="geminiApiKey" value=""/></label>\n\t\t\t</div>\n\t\t\t<div class="line openai-bak" style="display:none;">\n\t\t\t\t<label>API Key: <input id="openaiApiKey" value=""/></label>\n\t\t\t</div>\n\t\t\t<div class="line subject ollama">\n\t\t\t\t<label for="ollamaUrl">Server Url:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents ollama">\n\t\t\t\t<input type="text" id="ollamaUrl" value="http://localhost:11434"/></label>\n\t\t\t</div>\n\t\t\t<div class="line subject ollama">\n\t\t\t\t<label for="ollamaModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents ollama">\n\t\t\t\t<select id="ollamaModel">\n\t\t\t\t\t<option value="codellama:13b">codellama:13b</option>\n\t\t\t\t\t<option value="deepseek-coder:6.7b">deepseek-coder:6.7b</option>\n\t\t\t\t\t<option value="phi4:14b">phi4:14b</option>\n\t\t\t\t\t<option value="llama3.1:8b">llama3.1:8b</option>\n\t\t\t\t\t<option value="mistral:7b">mistral:7b</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t<div class="line subject gemini">\n\t\t\t\t<label for="geminiModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents gemini">\n\t\t\t\t<select id="geminiModel">\n\t\t\t\t\t<option value="gemini-2.5-flash">gemini-2.5-flash</option>\n\t\t\t\t\t<option value="gemini-2.5-pro">gemini-2.5-pro</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t<div class="line subject chatopenai">\n\t\t\t\t<label for="chatopenaiModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents chatopenai">\n\t\t\t\t<select id="chatopenaiModel">\n\t\t\t\t\t<option value="google/gemma-2-9b-it">google/gemma-2-9b-it</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t<div class="line subject openai">\n\t\t\t\t<label for="openaiModel">Model:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents openai">\n\t\t\t\t<select id="openaiModel">\n\t\t\t\t\t<option value="gpt-4">gpt-4</option>\n\t\t\t\t\t<option value="gpt-4o">gpt-4o</option>\n\t\t\t\t\t<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t\t\n\t\t\t<div class="line subject qdrant">\n\t\t\t\t<label for="qdrantUrl">Qdrant Url:</label>\n\t\t\t</div>\n\t\t\t<div class="line contents qdrant">\n\t\t\t\t<input type="text" id="qdrantUrl" value="http://localhost:6333"/>\n\t\t\t</div>\n\n\t\t\t<div class="line subject analyze">\n\t\t\t\t<input id="chkAnalyze" type="checkbox" checked> <input id="txtAnalyze" type="number" value="100"><label>건 미만인 경우 데이타 분석 요청</label>\n\t\t\t</div>\n\t\t`,me(this,C).call(this),setTimeout(()=>{this.server="chatopenai"},0)}}C=new WeakMap,customElements.define("ide-assi-settings",jb);class Mb extends HTMLElement{constructor(){super(),ge(this,R,[]),ge(this,Q,0),ge(this,I,0),ge(this,j,null),ge(this,M,null),ge(this,N,1e4),ge(this,L,3e3),pe(this,"tipElement",null),pe(this,"loadingAnimation",null),pe(this,"tipImageElement",null),pe(this,"tipImageContainer",null),this.attachShadow({mode:"open"})}connectedCallback(){this.shadowRoot.innerHTML=`\n <style>\n /* Import ninegrid's base AI CSS */\n @import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n /* Import custom CSS specific to this component (adjust path as needed) */\n ${t.getCustomPath(this,"ideAssi.css")}\n\n \n .loading-animation {\n --animation: spin 1s linear infinite;\n }\n\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n </style>\n <div class="chat-message loading-tips-message">\n\t\t\t\t<div class="loading-bar-wrapper">\n\t\t\t\t <div class="loading-bar"></div>\n\t\t\t\t</div>\n\t\t\t\t<div class="tip-content">\n\t\t\t\t\t<div class="tip-image-container">\n\t\t\t\t\t\t<img class="tip-image" src="" alt="팁 관련 이미지">\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div class="current-tip-wrapper">\n\t\t\t\t\t<p class="current-tip"></p>\n\t\t\t\t</div>\n\t\t\t</div>\n `,this.tipElement=this.shadowRoot.querySelector(".current-tip"),this.loadingAnimation=this.shadowRoot.querySelector(".loading-animation"),this.loadingAnimationWrapper=this.shadowRoot.querySelector(".loading-animation-wrapper"),this.tipImageElement=this.shadowRoot.querySelector(".tip-image"),this.tipImageContainer=this.shadowRoot.querySelector(".tip-image-container")}disconnectedCallback(){this.stopTips()}async startTips(e,t){if(e&&t)try{const i=await fetch(e);if(!i.ok)throw new Error(`Failed to fetch tips: ${i.statusText}`);const n=(await i.json())[t];if(!n||0===n.length)return;Oe(this,R,n),Oe(this,Q,Math.floor(Math.random()*me(this,R).length)),this.stopTips(),this.showRandomTip(),Oe(this,j,setInterval(()=>{this.showRandomTip()},me(this,N)))}catch(i){this.stopTips(),this.tipElement&&(this.tipElement.textContent="팁을 불러오는 중 오류가 발생했습니다.")}}stopTips(){me(this,j)&&(clearInterval(me(this,j)),Oe(this,j,null)),me(this,M)&&(clearInterval(me(this,M)),Oe(this,M,null)),this.tipImageElement.style.display="none",this.tipImageElement.src="",this.tipImageContainer.style.display="none"}showRandomTip(){if(0===me(this,R).length)return this.tipElement.textContent="",this.tipImageElement.style.display="none",void(this.tipImageContainer.style.display="none");let e=me(this,Q);if(me(this,R).length>1)for(let i=0;i<3;i++){const t=Math.floor(Math.random()*me(this,R).length);if(t!==me(this,Q)){e=t;break}}Oe(this,Q,e);const t=me(this,R)[me(this,Q)];this.tipElement&&t&&(this.tipElement.innerHTML=t.text,me(this,M)&&(clearInterval(me(this,M)),Oe(this,M,null)),t.images&&t.images.length>0?(Oe(this,I,0),this.showCurrentImage(t.images[me(this,I)]),this.tipImageElement.style.display="block",this.tipImageContainer.style.display="flex",t.images.length>1&&Oe(this,M,setInterval(()=>{Oe(this,I,(me(this,I)+1)%t.images.length),this.showCurrentImage(t.images[me(this,I)])},me(this,L)))):(this.tipImageElement.style.display="none",this.tipImageContainer.style.display="none",this.tipImageElement.src=""))}showCurrentImage(e){this.tipImageElement&&(this.tipImageElement.src=e)}}R=new WeakMap,Q=new WeakMap,I=new WeakMap,j=new WeakMap,M=new WeakMap,N=new WeakMap,L=new WeakMap,customElements.define("ide-loading-tips",Mb);class Nb extends HTMLElement{constructor(){super(),ge(this,Z,null),ge(this,D,"/data/tips.json"),ge(this,z,"componentTips"),ge(this,U,()=>{const e=this.shadowRoot.querySelector("nx-dialog");e&&e.addEventListener("close",()=>{me(this,Z)&&(me(this,Z).stopTips(),me(this,Z).remove(),Oe(this,Z,null))})}),pe(this,"close",()=>{var e;me(this,Z).stopTips(),null==(e=this.shadowRoot.querySelector("nx-dialog"))||e.close()}),this.attachShadow({mode:"open"})}connectedCallback(){this.shadowRoot.innerHTML=`\n <style>\n @import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideAssi.css";\n ${t.getCustomPath(this,"ideAssi.css")}\n </style>\n\n <nx-dialog>\n <div class="dialog-content"></div>\n </nx-dialog>\n `,me(this,U).call(this)}async popup(e="componentTips",t="/tips/tip.json"){var i;Oe(this,z,e),Oe(this,D,t);const n=this.shadowRoot.querySelector(".dialog-content");n&&(me(this,Z)&&(me(this,Z).stopTips(),me(this,Z).remove(),Oe(this,Z,null)),Oe(this,Z,document.createElement("ide-loading-tips")),n.appendChild(me(this,Z)),await me(this,Z).startTips(me(this,D),me(this,z)),null==(i=this.shadowRoot.querySelector("nx-dialog"))||i.showModal())}}Z=new WeakMap,D=new WeakMap,z=new WeakMap,U=new WeakMap,customElements.define("ide-tip-popup",Nb);class Lb extends HTMLElement{constructor(){super(),ge(this,q),ge(this,X,()=>{t.querySelector(".save",this.shadowRoot).addEventListener("click",e=>{me(this,B).call(this)})}),ge(this,B,()=>{let e=[];for(const i of me(this,q)){const n=Object.keys(i)[0],r=t.querySelector(`ide-diff.${n}`,this.shadowRoot);e.push({path:i[n].tobePath,contents:r.getContents()})}ju.post("/nine-ai/source/generateRealFile",{list:e}).then(e=>{t.alert("소스를 변경하였습니다.")})}),pe(this,"popup",e=>{Oe(this,q,e);const i=this.shadowRoot.querySelector("nx-tab");setTimeout(()=>{var n;for(const i of e){const[e,n]=Object.entries(i)[0],r=t.querySelector(`ide-diff.${e}`,this.shadowRoot);r&&r.initialize(n.asis,n.tobe,t.decode(e,"mybatis","xml","java","java","javascript"))}i.tabpage.showAll();const r=e.map(e=>Object.keys(e)[0]);t.querySelectorAll("ide-diff",this.shadowRoot).forEach(e=>{const t=e.className.trim();r.includes(t)||i.tabpage.hide(t)}),i.shadowRoot.querySelectorAll(".tab-button").forEach((i,n)=>{i.innerHTML=((t,i="tobePath")=>{if(!e)return null;for(const n of e)if(n.hasOwnProperty(t)&&n[t][i]){const e=n[t][i].split("/");return e.length>0?e.pop():null}return null})(t.decode(n,0,"mybatis",1,"service",2,"controller",3,"javascriptFrom","javascriptTo"))}),i.initialize(),null==(n=this.shadowRoot.querySelector("nx-dialog"))||n.showModal()},100)}),this.attachShadow({mode:"open"})}connectedCallback(){this.shadowRoot.innerHTML='\n\t\t\t<style>\n\t\t\t\tdiv.buttons {\n\t\t\t\t\tposition: absolute;\n\t\t\t\t\tright: 16px;\n\t\t\t\t\t/* width: 100px; */\n\t\t\t\t\tdisplay: flex;\n\t\t\t\t\tflex-direction: row;\n\t\t\t\t\tjustify-content: flex-end;\n\t\t\t\t\tz-index: 1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbutton.save {\n\t\t\t\t\tcursor: pointer;\n\t\t\t\t\toutline: none;\n\t\t\t\t}\n\t\t\t</style>\n\n\t\t\t<nx-dialog>\n\t\t\t\t<div class="buttons">\n\t\t\t\t\t<button class="save">Apply</button>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t<nx-tab theme="theme-4">\n\t\t\t\t <nx-tab-page caption="mybatis">\n\t\t\t\t\t<ide-diff class="mybatis"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="service">\n\t\t\t\t\t<ide-diff class="service"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="controller">\n\t\t\t\t\t<ide-diff class="controller"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="javascriptFrom">\n\t\t\t\t\t<ide-diff class="javascriptFrom"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t <nx-tab-page caption="javascriptTo">\n\t\t\t\t\t<ide-diff class="javascriptTo"></ide-diff>\n\t\t\t\t </nx-tab-page>\n\t\t\t\t</nx-tab>\n\t\t\t</nx-dialog>\n\t\t',me(this,X).call(this)}}q=new WeakMap,X=new WeakMap,B=new WeakMap,customElements.define("ide-diff-popup",Lb);let Zb=[],Db=[];function zb(e){if(e<768)return!1;for(let t=0,i=Zb.length;;){let n=t+i>>1;if(e<Zb[n])i=n;else{if(!(e>=Db[n]))return!0;t=n+1}if(t==i)return!1}}function Ub(e){return e>=127462&&e<=127487}(()=>{let e="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,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n)}function Xb(e,t,i){if(t==e.length)return t;t&&Vb(e.charCodeAt(t))&&Fb(e.charCodeAt(t-1))&&t--;let n=Wb(e,t);for(t+=Yb(n);t<e.length;){let r=Wb(e,t);if(8205==n||8205==r||i&&zb(r))t+=Yb(r),n=r;else{if(!Ub(r))break;{let i=0,n=t-2;for(;n>=0&&Ub(Wb(e,n));)i++,n-=2;if(i%2==0)break;t+=2}}}return t}function Bb(e,t,i){for(;t>0;){let n=Xb(e,t-2,i);if(n<t)return n;t--}return 0}function Wb(e,t){let i=e.charCodeAt(t);if(!Fb(i)||t+1==e.length)return i;let n=e.charCodeAt(t+1);return Vb(n)?n-56320+(i-55296<<10)+65536:i}function Vb(e){return e>=56320&&e<57344}function Fb(e){return e>=55296&&e<56320}function Yb(e){return e<65536?1:2}class Gb{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=sw(this,e,t);let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),Kb.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=sw(this,e,t);let i=[];return this.decompose(e,t,i,0),Kb.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new tw(this),r=new tw(e);for(let s=t,a=t;;){if(n.next(s),r.next(s),s=0,n.lineBreak!=r.lineBreak||n.done!=r.done||n.value!=r.value)return!1;if(a+=n.value.length,n.done||a>=i)return!0}}iter(e=1){return new tw(this,e)}iterRange(e,t=this.length){return new iw(this,e,t)}iterLines(e,t){let i;if(null==e)i=this.iter();else{null==t&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new nw(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(0==e.length)throw new RangeError("A document must have at least one line");return 1!=e.length||e[0]?e.length<=32?new Hb(e):Kb.from(Hb.split(e,[])):Gb.empty}}class Hb extends Gb{constructor(e,t=function(e){let t=-1;for(let i of e)t+=i.length+1;return t}(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let r=0;;r++){let s=this.text[r],a=n+s.length;if((t?i:a)>=e)return new rw(n,a,i,s);n=a+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new Hb(ew(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(1&n){let e=i.pop(),t=Jb(r.text,e.text.slice(),0,r.length);if(t.length<=32)i.push(new Hb(t,e.length+r.length));else{let e=t.length>>1;i.push(new Hb(t.slice(0,e)),new Hb(t.slice(e)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof Hb))return super.replace(e,t,i);[e,t]=sw(this,e,t);let n=Jb(this.text,Jb(i.text,ew(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new Hb(n,r):Kb.from(Hb.split(n,[]),r)}sliceString(e,t=this.length,i="\n"){[e,t]=sw(this,e,t);let n="";for(let r=0,s=0;r<=t&&s<this.text.length;s++){let a=this.text[s],o=r+a.length;r>e&&s&&(n+=i),e<o&&t>r&&(n+=a.slice(Math.max(0,e-r),t-r)),r=o+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let r of e)i.push(r),n+=r.length+1,32==i.length&&(t.push(new Hb(i,n)),i=[],n=-1);return n>-1&&t.push(new Hb(i,n)),t}}class Kb extends Gb{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let r=0;;r++){let s=this.children[r],a=n+s.length,o=i+s.lines-1;if((t?o:a)>=e)return s.lineInner(e,t,i,n);n=a+1,i=o+1}}decompose(e,t,i,n){for(let r=0,s=0;s<=t&&r<this.children.length;r++){let a=this.children[r],o=s+a.length;if(e<=o&&t>=s){let r=n&((s<=e?1:0)|(o>=t?2:0));s>=e&&o<=t&&!r?i.push(a):a.decompose(e-s,t-s,i,r)}s=o+1}}replace(e,t,i){if([e,t]=sw(this,e,t),i.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let s=this.children[n],a=r+s.length;if(e>=r&&t<=a){let o=s.replace(e-r,t-r,i),l=this.lines-s.lines+o.lines;if(o.lines<l>>4&&o.lines>l>>6){let r=this.children.slice();return r[n]=o,new Kb(r,this.length-(t-e)+i.length)}return super.replace(r,a,o)}r=a+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i="\n"){[e,t]=sw(this,e,t);let n="";for(let r=0,s=0;r<this.children.length&&s<=t;r++){let a=this.children[r],o=s+a.length;s>e&&r&&(n+=i),e<o&&t>s&&(n+=a.sliceString(e-s,t-s,i)),s=o+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Kb))return 0;let i=0,[n,r,s,a]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,r+=t){if(n==s||r==a)return i;let o=this.children[n],l=e.children[r];if(o!=l)return i+o.scanIdentical(l,t);i+=o.length+1}}static from(e,t=e.reduce((e,t)=>e+t.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let i=[];for(let t of e)t.flatten(i);return new Hb(i,t)}let n=Math.max(32,i>>5),r=n<<1,s=n>>1,a=[],o=0,l=-1,c=[];function h(e){let t;if(e.lines>r&&e instanceof Kb)for(let i of e.children)h(i);else e.lines>s&&(o>s||!o)?(u(),a.push(e)):e instanceof Hb&&o&&(t=c[c.length-1])instanceof Hb&&e.lines+t.lines<=32?(o+=e.lines,l+=e.length+1,c[c.length-1]=new Hb(t.text.concat(e.text),t.length+1+e.length)):(o+e.lines>n&&u(),o+=e.lines,l+=e.length+1,c.push(e))}function u(){0!=o&&(a.push(1==c.length?c[0]:Kb.from(c,l)),l=-1,o=c.length=0)}for(let d of e)h(d);return u(),1==a.length?a[0]:new Kb(a,t)}}function Jb(e,t,i=0,n=1e9){for(let r=0,s=0,a=!0;s<e.length&&r<=n;s++){let o=e[s],l=r+o.length;l>=i&&(l>n&&(o=o.slice(0,n-r)),r<i&&(o=o.slice(i-r)),a?(t[t.length-1]+=o,a=!1):t.push(o)),r=l+1}return t}function ew(e,t,i){return Jb(e,[""],t,i)}Gb.empty=new Hb([""],0);class tw{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof Hb?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],s=r>>1,a=n instanceof Hb?n.text.length:n.children.length;if(s==(t>0?a:0)){if(0==i)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(t>0?0:1)){if(this.offsets[i]+=t,0==e)return this.lineBreak=!0,this.value="\n",this;e--}else if(n instanceof Hb){let r=n.text[s+(t<0?-1:0)];if(this.offsets[i]+=t,r.length>Math.max(0,e))return this.value=0==e?r:t>0?r.slice(e):r.slice(0,r.length-e),this;e-=r.length}else{let r=n.children[s+(t<0?-1:0)];e>r.length?(e-=r.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(r),this.offsets.push(t>0?1:(r instanceof Hb?r.text.length:r.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class iw{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new tw(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class nw{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(Gb.prototype[Symbol.iterator]=function(){return this.iter()},tw.prototype[Symbol.iterator]=iw.prototype[Symbol.iterator]=nw.prototype[Symbol.iterator]=function(){return this});class rw{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}function sw(e,t,i){return[t=Math.max(0,Math.min(e.length,t)),Math.max(t,Math.min(e.length,i))]}function aw(e,t,i=!0,n=!0){return qb(e,t,i,n)}function ow(e,t){let i=e.charCodeAt(t);if(!(n=i,n>=55296&&n<56320&&t+1!=e.length))return i;var n;let r=e.charCodeAt(t+1);return function(e){return e>=56320&&e<57344}(r)?r-56320+(i-55296<<10)+65536:i}function lw(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10),56320+(1023&e)))}function cw(e){return e<65536?1:2}const hw=/\r\n?|\n/;var uw=function(e){return e[e.Simple=0]="Simple",e[e.TrackDel=1]="TrackDel",e[e.TrackBefore=2]="TrackBefore",e[e.TrackAfter=3]="TrackAfter",e}(uw||(uw={}));class dw{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return 0==this.sections.length||2==this.sections.length&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],s=this.sections[t++];s<0?(e(i,n,r),n+=r):n+=s,i+=r}}iterChangedRanges(e,t=!1){gw(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new dw(e)}composeDesc(e){return this.empty?e:e.empty?this:vw(this,e)}mapDesc(e,t=!1){return e.empty?this:Ow(this,e,t)}mapPos(e,t=-1,i=uw.Simple){let n=0,r=0;for(let s=0;s<this.sections.length;){let a=this.sections[s++],o=this.sections[s++],l=n+a;if(o<0){if(l>e)return r+(e-n);r+=a}else{if(i!=uw.Simple&&l>=e&&(i==uw.TrackDel&&n<e&&l>e||i==uw.TrackBefore&&n<e||i==uw.TrackAfter&&l>e))return null;if(l>e||l==e&&t<0&&!a)return e==n||t<0?r:r+o;r+=o}n=l}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return r}touchesRange(e,t=e){for(let i=0,n=0;i<this.sections.length&&n<=t;){let r=n+this.sections[i++];if(this.sections[i++]>=0&&n<=t&&r>=e)return!(n<e&&r>t)||"cover";n=r}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(e=>"number"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeDesc");return new dw(e)}static create(e){return new dw(e)}}class pw extends dw{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return gw(this,(t,i,n,r,s)=>e=e.replace(n,n+(i-t),s),!1),e}mapDesc(e,t=!1){return Ow(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let s=t[n],a=t[n+1];if(a>=0){t[n]=a,t[n+1]=s;let o=n>>1;for(;i.length<o;)i.push(Gb.empty);i.push(s?e.slice(r,r+s):Gb.empty)}r+=s}return new pw(t,i)}compose(e){return this.empty?e:e.empty?this:vw(this,e,!0)}map(e,t=!1){return e.empty?this:Ow(this,e,t,!0)}iterChanges(e,t=!1){gw(this,e,t)}get desc(){return dw.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new yw(this);e:for(let s=0,a=0;;){let o=s==e.length?1e9:e[s++];for(;a<o||a==o&&0==r.len;){if(r.done)break e;let e=Math.min(r.len,o-a);fw(n,e,-1);let s=-1==r.ins?-1:0==r.off?r.ins:0;fw(t,e,s),s>0&&mw(i,t,r.text),r.forward(e),a+=e}let l=e[s++];for(;a<l;){if(r.done)break e;let e=Math.min(r.len,l-a);fw(t,e,-1),fw(n,e,-1==r.ins?-1:0==r.off?r.ins:0),r.forward(e),a+=e}}return{changes:new pw(t,i),filtered:dw.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):0==n?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],s=0,a=null;function o(e=!1){if(!e&&!n.length)return;s<t&&fw(n,t-s,-1);let i=new pw(n,r);a=a?a.compose(i.map(a)):i,n=[],r=[],s=0}return function e(l){if(Array.isArray(l))for(let t of l)e(t);else if(l instanceof pw){if(l.length!=t)throw new RangeError(`Mismatched change set length (got ${l.length}, expected ${t})`);o(),a=a?a.compose(l.map(a)):l}else{let{from:e,to:a=e,insert:c}=l;if(e>a||e<0||a>t)throw new RangeError(`Invalid change range ${e} to ${a} (in doc of length ${t})`);let h=c?"string"==typeof c?Gb.of(c.split(i||hw)):c:Gb.empty,u=h.length;if(e==a&&0==u)return;e<s&&o(),e>s&&fw(n,e-s,-1),fw(n,a-e,u),mw(r,n,h),s=a}}(e),o(!a),a}static empty(e){return new pw(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if("number"==typeof r)t.push(r,-1);else{if(!Array.isArray(r)||"number"!=typeof r[0]||r.some((e,t)=>t&&"string"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)t.push(r[0],0);else{for(;i.length<n;)i.push(Gb.empty);i[n]=Gb.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new pw(t,i)}static createSet(e,t){return new pw(e,t)}}function fw(e,t,i,n=!1){if(0==t&&i<=0)return;let r=e.length-2;r>=0&&i<=0&&i==e[r+1]?e[r]+=t:r>=0&&0==t&&0==e[r]?e[r+1]+=i:n?(e[r]+=t,e[r+1]+=i):e.push(t,i)}function mw(e,t,i){if(0==i.length)return;let n=t.length-2>>1;if(n<e.length)e[e.length-1]=e[e.length-1].append(i);else{for(;e.length<n;)e.push(Gb.empty);e.push(i)}}function gw(e,t,i){let n=e.inserted;for(let r=0,s=0,a=0;a<e.sections.length;){let o=e.sections[a++],l=e.sections[a++];if(l<0)r+=o,s+=o;else{let c=r,h=s,u=Gb.empty;for(;c+=o,h+=l,l&&n&&(u=u.append(n[a-2>>1])),!(i||a==e.sections.length||e.sections[a+1]<0);)o=e.sections[a++],l=e.sections[a++];t(r,c,s,h,u),r=c,s=h}}}function Ow(e,t,i,n=!1){let r=[],s=n?[]:null,a=new yw(e),o=new yw(t);for(let l=-1;;){if(a.done&&o.len||o.done&&a.len)throw new Error("Mismatched change set lengths");if(-1==a.ins&&-1==o.ins){let e=Math.min(a.len,o.len);fw(r,e,-1),a.forward(e),o.forward(e)}else if(o.ins>=0&&(a.ins<0||l==a.i||0==a.off&&(o.len<a.len||o.len==a.len&&!i))){let e=o.len;for(fw(r,o.ins,-1);e;){let t=Math.min(a.len,e);a.ins>=0&&l<a.i&&a.len<=t&&(fw(r,0,a.ins),s&&mw(s,r,a.text),l=a.i),a.forward(t),e-=t}o.next()}else{if(!(a.ins>=0)){if(a.done&&o.done)return s?pw.createSet(r,s):dw.create(r);throw new Error("Mismatched change set lengths")}{let e=0,t=a.len;for(;t;)if(-1==o.ins){let i=Math.min(t,o.len);e+=i,t-=i,o.forward(i)}else{if(!(0==o.ins&&o.len<t))break;t-=o.len,o.next()}fw(r,e,l<a.i?a.ins:0),s&&l<a.i&&mw(s,r,a.text),l=a.i,a.forward(a.len-t)}}}}function vw(e,t,i=!1){let n=[],r=i?[]:null,s=new yw(e),a=new yw(t);for(let o=!1;;){if(s.done&&a.done)return r?pw.createSet(n,r):dw.create(n);if(0==s.ins)fw(n,s.len,0,o),s.next();else if(0!=a.len||a.done){if(s.done||a.done)throw new Error("Mismatched change set lengths");{let e=Math.min(s.len2,a.len),t=n.length;if(-1==s.ins){let t=-1==a.ins?-1:a.off?0:a.ins;fw(n,e,t,o),r&&t&&mw(r,n,a.text)}else-1==a.ins?(fw(n,s.off?0:s.len,e,o),r&&mw(r,n,s.textBit(e))):(fw(n,s.off?0:s.len,a.off?0:a.ins,o),r&&!a.off&&mw(r,n,a.text));o=(s.ins>e||a.ins>=0&&a.len>e)&&(o||n.length>t),s.forward2(e),a.forward(e)}}else fw(n,0,a.ins,o),r&&mw(r,n,a.text),a.next()}}class yw{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return-2==this.ins}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?Gb.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?Gb.empty:t[i].slice(this.off,null==e?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){-1==this.ins?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class bw{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let e=7&this.flags;return 7==e?null:e}get goalColumn(){let e=this.flags>>6;return 16777215==e?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new bw(i,n,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return ww.range(e,t,void 0,void 0,i);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return ww.range(this.anchor,n,void 0,void 0,i)}eq(e,t=!1){return!(this.anchor!=e.anchor||this.head!=e.head||this.goalColumn!=e.goalColumn||t&&this.empty&&this.assoc!=e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||"number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid JSON representation for SelectionRange");return ww.range(e.anchor,e.head)}static create(e,t,i){return new bw(e,t,i)}}class ww{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:ww.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return 1==this.ranges.length?this:new ww([this.main],0)}addRange(e,t=!0){return ww.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,ww.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||"number"!=typeof e.main||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new ww(e.ranges.map(e=>bw.fromJSON(e)),e.main)}static single(e,t=e){return new ww([ww.range(e,t)],0)}static create(e,t=0){if(0==e.length)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return ww.normalized(e.slice(),t);i=r.to}return new ww(e,t)}static cursor(e,t=0,i,n){return bw.create(e,e,(0==t?0:t<0?8:16)|(null==i?7:Math.min(6,i))|(null!=n?n:16777215)<<6)}static range(e,t,i,n,r){let s=(null!=i?i:16777215)<<6|(null==n?7:Math.min(6,n));return r||e==t||(r=t<e?1:-1),t<e?bw.create(t,e,48|s):bw.create(e,t,(r?r<0?8:16:0)|s)}static normalized(e,t=0){let i=e[t];e.sort((e,t)=>e.from-t.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let i=e[n],r=e[n-1];if(i.empty?i.from<=r.to:i.from<r.to){let s=r.from,a=Math.max(i.to,r.to);n<=t&&t--,e.splice(--n,2,i.anchor>i.head?ww.range(a,s):ww.range(s,a))}}return new ww(e,t)}}function _w(e,t){for(let i of e.ranges)if(i.to>t)throw new RangeError("Selection points outside of document")}let xw=0;class Sw{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=xw++,this.default=e([]),this.extensions="function"==typeof r?r(this):r}get reader(){return this}static define(e={}){return new Sw(e.combine||(e=>e),e.compareInput||((e,t)=>e===t),e.compare||(e.combine?(e,t)=>e===t:kw),!!e.static,e.enables)}of(e){return new Pw([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Pw(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Pw(e,this,2,t)}from(e,t){return t||(t=e=>e),this.compute([e],i=>t(i.field(e)))}}function kw(e,t){return e==t||e.length==t.length&&e.every((e,i)=>e===t[i])}class Pw{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=xw++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,r=this.id,s=e[r]>>1,a=2==this.type,o=!1,l=!1,c=[];for(let h of this.dependencies)"doc"==h?o=!0:"selection"==h?l=!0:1&(null!==(t=e[h.id])&&void 0!==t?t:1)||c.push(e[h.id]);return{create:e=>(e.values[s]=i(e),1),update(e,t){if(o&&t.docChanged||l&&(t.docChanged||t.selection)||$w(e,c)){let t=i(e);if(a?!Tw(t,e.values[s],n):!n(t,e.values[s]))return e.values[s]=t,1}return 0},reconfigure:(e,t)=>{let o,l=t.config.address[r];if(null!=l){let r=qw(t,l);if(this.dependencies.every(i=>i instanceof Sw?t.facet(i)===e.facet(i):!(i instanceof Cw)||t.field(i,!1)==e.field(i,!1))||(a?Tw(o=i(e),r,n):n(o=i(e),r)))return e.values[s]=r,0}else o=i(e);return e.values[s]=o,1}}}}function Tw(e,t,i){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!i(e[n],t[n]))return!1;return!0}function $w(e,t){let i=!1;for(let n of t)1&Uw(e,n)&&(i=!0);return i}function Ew(e,t,i){let n=i.map(t=>e[t.id]),r=i.map(e=>e.type),s=n.filter(e=>!(1&e)),a=e[t.id]>>1;function o(e){let i=[];for(let t=0;t<n.length;t++){let s=qw(e,n[t]);if(2==r[t])for(let e of s)i.push(e);else i.push(s)}return t.combine(i)}return{create(e){for(let t of n)Uw(e,t);return e.values[a]=o(e),1},update(e,i){if(!$w(e,s))return 0;let n=o(e);return t.compare(n,e.values[a])?0:(e.values[a]=n,1)},reconfigure(e,r){let s=$w(e,n),l=r.config.facets[t.id],c=r.facet(t);if(l&&!s&&kw(i,l))return e.values[a]=c,0;let h=o(e);return t.compare(h,c)?(e.values[a]=c,0):(e.values[a]=h,1)}}}const Aw=Sw.define({static:!0});class Cw{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new Cw(xw++,e.create,e.update,e.compare||((e,t)=>e===t),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Aw).find(e=>e.field==this);return((null==t?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,i)=>{let n=e.values[t],r=this.updateF(n,i);return this.compareF(n,r)?0:(e.values[t]=r,1)},reconfigure:(e,i)=>{let n,r=e.facet(Aw),s=i.facet(Aw);return(n=r.find(e=>e.field==this))&&n!=s.find(e=>e.field==this)?(e.values[t]=n.create(e),1):null!=i.config.address[this.id]?(e.values[t]=i.field(this),0):(e.values[t]=this.create(e),1)}}}init(e){return[this,Aw.of({field:this,create:e})]}get extension(){return this}}const Rw=4,Qw=3,Iw=2,jw=1;function Mw(e){return t=>new Lw(t,e)}const Nw={highest:Mw(0),high:Mw(jw),default:Mw(Iw),low:Mw(Qw),lowest:Mw(Rw)};class Lw{constructor(e,t){this.inner=e,this.prec=t}}class Zw{of(e){return new Dw(this,e)}reconfigure(e){return Zw.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Dw{constructor(e,t){this.compartment=e,this.inner=t}}class zw{constructor(e,t,i,n,r,s){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=s,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return null==t?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],r=Object.create(null),s=new Map;for(let u of function(e,t,i){let n=[[],[],[],[],[]],r=new Map;function s(e,a){let o=r.get(e);if(null!=o){if(o<=a)return;let t=n[o].indexOf(e);t>-1&&n[o].splice(t,1),e instanceof Dw&&i.delete(e.compartment)}if(r.set(e,a),Array.isArray(e))for(let t of e)s(t,a);else if(e instanceof Dw){if(i.has(e.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=t.get(e.compartment)||e.inner;i.set(e.compartment,n),s(n,a)}else if(e instanceof Lw)s(e.inner,e.prec);else if(e instanceof Cw)n[a].push(e),e.provides&&s(e.provides,a);else if(e instanceof Pw)n[a].push(e),e.facet.extensions&&s(e.facet.extensions,Iw);else{let t=e.extension;if(!t)throw new Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(t,a)}}return s(e,Iw),n.reduce((e,t)=>e.concat(t))}(e,t,s))u instanceof Cw?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let a=Object.create(null),o=[],l=[];for(let u of n)a[u.id]=l.length<<1,l.push(e=>u.slot(e));let c=null==i?void 0:i.config.facets;for(let u in r){let e=r[u],t=e[0].facet,n=c&&c[u]||[];if(e.every(e=>0==e.type))if(a[t.id]=o.length<<1|1,kw(n,e))o.push(i.facet(t));else{let n=t.combine(e.map(e=>e.value));o.push(i&&t.compare(n,i.facet(t))?i.facet(t):n)}else{for(let t of e)0==t.type?(a[t.id]=o.length<<1|1,o.push(t.value)):(a[t.id]=l.length<<1,l.push(e=>t.dynamicSlot(e)));a[t.id]=l.length<<1,l.push(i=>Ew(i,t,e))}}let h=l.map(e=>e(a));return new zw(e,s,h,a,o,r)}}function Uw(e,t){if(1&t)return 2;let i=t>>1,n=e.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;e.status[i]=4;let r=e.computeSlot(e,e.config.dynamicSlots[i]);return e.status[i]=2|r}function qw(e,t){return 1&t?e.config.staticValues[t>>1]:e.values[t>>1]}const Xw=Sw.define(),Bw=Sw.define({combine:e=>e.some(e=>e),static:!0}),Ww=Sw.define({combine:e=>e.length?e[0]:void 0,static:!0}),Vw=Sw.define(),Fw=Sw.define(),Yw=Sw.define(),Gw=Sw.define({combine:e=>!!e.length&&e[0]});class Hw{constructor(e,t){this.type=e,this.value=t}static define(){return new Kw}}class Kw{of(e){return new Hw(this,e)}}class Jw{constructor(e){this.map=e}of(e){return new e_(this,e)}}class e_{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return void 0===t?void 0:t==this.value?this:new e_(this.type,t)}is(e){return this.type==e}static define(e={}){return new Jw(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let e=n.map(t);e&&i.push(e)}return i}}e_.reconfigure=e_.define(),e_.appendConfig=e_.define();class t_{constructor(e,t,i,n,r,s){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=s,this._doc=null,this._state=null,i&&_w(i,t.newLength),r.some(e=>e.type==t_.time)||(this.annotations=r.concat(t_.time.of(Date.now())))}static create(e,t,i,n,r,s){return new t_(e,t,i,n,r,s)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(t_.userEvent);return!(!t||!(t==e||t.length>e.length&&t.slice(0,e.length)==e&&"."==t[e.length]))}}function i_(e,t){let i=[];for(let n=0,r=0;;){let s,a;if(n<e.length&&(r==t.length||t[r]>=e[n]))s=e[n++],a=e[n++];else{if(!(r<t.length))return i;s=t[r++],a=t[r++]}!i.length||i[i.length-1]<s?i.push(s,a):i[i.length-1]<a&&(i[i.length-1]=a)}}function n_(e,t,i){var n;let r,s,a;return i?(r=t.changes,s=pw.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),s=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(s):null===(n=e.selection)||void 0===n?void 0:n.map(r),effects:e_.mapEffects(e.effects,r).concat(e_.mapEffects(t.effects,s)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function r_(e,t,i){let n=t.selection,r=o_(t.annotations);return t.userEvent&&(r=r.concat(t_.userEvent.of(t.userEvent))),{changes:t.changes instanceof pw?t.changes:pw.of(t.changes||[],i,e.facet(Ww)),selection:n&&(n instanceof ww?n:ww.single(n.anchor,n.head)),effects:o_(t.effects),annotations:r,scrollIntoView:!!t.scrollIntoView}}function s_(e,t,i){let n=r_(e,t.length?t[0]:{},e.doc.length);t.length&&!1===t[0].filter&&(i=!1);for(let s=1;s<t.length;s++){!1===t[s].filter&&(i=!1);let r=!!t[s].sequential;n=n_(n,r_(e,t[s],r?n.changes.newLength:e.doc.length),r)}let r=t_.create(e,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return function(e){let t=e.startState,i=t.facet(Yw),n=e;for(let r=i.length-1;r>=0;r--){let s=i[r](e);s&&Object.keys(s).length&&(n=n_(n,r_(t,s,e.changes.newLength),!0))}return n==e?e:t_.create(t,e.changes,e.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(e){let t=e.startState,i=!0;for(let r of t.facet(Vw)){let t=r(e);if(!1===t){i=!1;break}Array.isArray(t)&&(i=!0===i?t:i_(i,t))}if(!0!==i){let n,r;if(!1===i)r=e.changes.invertedDesc,n=pw.empty(t.doc.length);else{let t=e.changes.filter(i);n=t.changes,r=t.filtered.mapDesc(t.changes).invertedDesc}e=t_.create(t,n,e.selection&&e.selection.map(r),e_.mapEffects(e.effects,r),e.annotations,e.scrollIntoView)}let n=t.facet(Fw);for(let r=n.length-1;r>=0;r--){let i=n[r](e);e=i instanceof t_?i:Array.isArray(i)&&1==i.length&&i[0]instanceof t_?i[0]:s_(t,o_(i),!1)}return e}(r):r)}t_.time=Hw.define(),t_.userEvent=Hw.define(),t_.addToHistory=Hw.define(),t_.remote=Hw.define();const a_=[];function o_(e){return null==e?a_:Array.isArray(e)?e:[e]}var l_=function(e){return e[e.Word=0]="Word",e[e.Space=1]="Space",e[e.Other=2]="Other",e}(l_||(l_={}));const c_=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let h_;try{h_=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(EM){}function u_(e){return t=>{if(!/\S/.test(t))return l_.Space;if(function(e){if(h_)return h_.test(e);for(let t=0;t<e.length;t++){let i=e[t];if(/\w/.test(i)||i>""&&(i.toUpperCase()!=i.toLowerCase()||c_.test(i)))return!0}return!1}(t))return l_.Word;for(let i=0;i<e.length;i++)if(t.indexOf(e[i])>-1)return l_.Word;return l_.Other}}class d_{constructor(e,t,i,n,r,s){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,s&&(s._state=this);for(let a=0;a<this.config.dynamicSlots.length;a++)Uw(this,a<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(null!=i)return Uw(this,i),qw(this,i);if(t)throw new RangeError("Field is not present in this state")}update(...e){return s_(this,e,!0)}applyTransaction(e){let t,i=this.config,{base:n,compartments:r}=i;for(let a of e.effects)a.is(Zw.reconfigure)?(i&&(r=new Map,i.compartments.forEach((e,t)=>r.set(t,e)),i=null),r.set(a.value.compartment,a.value.extension)):a.is(e_.reconfigure)?(i=null,n=a.value):a.is(e_.appendConfig)&&(i=null,n=o_(n).concat(a.value));if(i)t=e.startState.values.slice();else{i=zw.resolve(n,r,this),t=new d_(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values}let s=e.startState.facet(Bw)?e.newSelection:e.newSelection.asSingle();new d_(i,e.newDoc,s,t,(t,i)=>i.update(t,e),e)}replaceSelection(e){return"string"==typeof e&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:ww.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],s=o_(i.effects);for(let a=1;a<t.ranges.length;a++){let i=e(t.ranges[a]),o=this.changes(i.changes),l=o.map(n);for(let e=0;e<a;e++)r[e]=r[e].map(l);let c=n.mapDesc(o,!0);r.push(i.range.map(c)),n=n.compose(l),s=e_.mapEffects(s,l).concat(e_.mapEffects(o_(i.effects),c))}return{changes:n,selection:ww.create(r,t.mainIndex),effects:s}}changes(e=[]){return e instanceof pw?e:pw.of(e,this.doc.length,this.facet(d_.lineSeparator))}toText(e){return Gb.of(e.split(this.facet(d_.lineSeparator)||hw))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return null==t?e.default:(Uw(this,t),qw(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof Cw&&null!=this.config.address[n.id]&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||"string"!=typeof e.doc)throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i)for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let t=i[r],s=e[r];n.push(t.init(e=>t.spec.fromJSON(s,e)))}return d_.create({doc:e.doc,selection:ww.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=zw.resolve(e.extensions||[],new Map),i=e.doc instanceof Gb?e.doc:Gb.of((e.doc||"").split(t.staticFacet(d_.lineSeparator)||hw)),n=e.selection?e.selection instanceof ww?e.selection:ww.single(e.selection.anchor,e.selection.head):ww.single(0);return _w(n,i.length),t.staticFacet(Bw)||(n=n.asSingle()),new d_(t,i,n,t.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(d_.tabSize)}get lineBreak(){return this.facet(d_.lineSeparator)||"\n"}get readOnly(){return this.facet(Gw)}phrase(e,...t){for(let i of this.facet(d_.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(e,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>t.length?e:t[n-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let r of this.facet(Xw))for(let s of r(this,t,i))Object.prototype.hasOwnProperty.call(s,e)&&n.push(s[e]);return n}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return u_(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),r=this.charCategorizer(e),s=e-i,a=e-i;for(;s>0;){let e=aw(t,s,!1);if(r(t.slice(e,s))!=l_.Word)break;s=e}for(;a<n;){let e=aw(t,a);if(r(t.slice(a,e))!=l_.Word)break;a=e}return s==a?null:ww.range(s+i,a+i)}}function p_(e,t,i={}){let n={};for(let r of e)for(let e of Object.keys(r)){let t=r[e],s=n[e];if(void 0===s)n[e]=t;else if(s===t||void 0===t);else{if(!Object.hasOwnProperty.call(i,e))throw new Error("Config merge conflict for field "+e);n[e]=i[e](s,t)}}for(let r in t)void 0===n[r]&&(n[r]=t[r]);return n}d_.allowMultipleSelections=Bw,d_.tabSize=Sw.define({combine:e=>e.length?e[0]:4}),d_.lineSeparator=Ww,d_.readOnly=Gw,d_.phrases=Sw.define({compare(e,t){let i=Object.keys(e),n=Object.keys(t);return i.length==n.length&&i.every(i=>e[i]==t[i])}}),d_.languageData=Xw,d_.changeFilter=Vw,d_.transactionFilter=Fw,d_.transactionExtender=Yw,Zw.reconfigure=e_.define();class f_{eq(e){return this==e}range(e,t=e){return g_.create(e,t,this)}}function m_(e,t){return e==t||e.constructor==t.constructor&&e.eq(t)}f_.prototype.startSide=f_.prototype.endSide=0,f_.prototype.point=!1,f_.prototype.mapMode=uw.TrackDel;let g_=class e{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(t,i,n){return new e(t,i,n)}};function O_(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}class v_{constructor(e,t,i,n){this.from=e,this.to=t,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,n=0){let r=i?this.to:this.from;for(let s=n,a=r.length;;){if(s==a)return s;let n=s+a>>1,o=r[n]-e||(i?this.value[n].endSide:this.value[n].startSide)-t;if(n==s)return o>=0?s:a;o>=0?a=n:s=n+1}}between(e,t,i,n){for(let r=this.findIndex(t,-1e9,!0),s=this.findIndex(i,1e9,!1,r);r<s;r++)if(!1===n(this.from[r]+e,this.to[r]+e,this.value[r]))return!1}map(e,t){let i=[],n=[],r=[],s=-1,a=-1;for(let o=0;o<this.value.length;o++){let l,c,h=this.value[o],u=this.from[o]+e,d=this.to[o]+e;if(u==d){let e=t.mapPos(u,h.startSide,h.mapMode);if(null==e)continue;if(l=c=e,h.startSide!=h.endSide&&(c=t.mapPos(u,h.endSide),c<l))continue}else if(l=t.mapPos(u,h.startSide),c=t.mapPos(d,h.endSide),l>c||l==c&&h.startSide>0&&h.endSide<=0)continue;(c-l||h.endSide-h.startSide)<0||(s<0&&(s=l),h.point&&(a=Math.max(a,c-l)),i.push(h),n.push(l-s),r.push(c-s))}return{mapped:i.length?new v_(n,r,i,a):null,pos:s}}}class y_{constructor(e,t,i,n){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=n}static create(e,t,i,n){return new y_(e,t,i,n)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:n=0,filterTo:r=this.length}=e,s=e.filter;if(0==t.length&&!s)return this;if(i&&(t=t.slice().sort(O_)),this.isEmpty)return t.length?y_.of(t):this;let a=new __(this,null,-1).goto(0),o=0,l=[],c=new b_;for(;a.value||o<t.length;)if(o<t.length&&(a.from-t[o].from||a.startSide-t[o].value.startSide)>=0){let e=t[o++];c.addInner(e.from,e.to,e.value)||l.push(e)}else 1==a.rangeIndex&&a.chunkIndex<this.chunk.length&&(o==t.length||this.chunkEnd(a.chunkIndex)<t[o].from)&&(!s||n>this.chunkEnd(a.chunkIndex)||r<this.chunkPos[a.chunkIndex])&&c.addChunk(this.chunkPos[a.chunkIndex],this.chunk[a.chunkIndex])?a.nextChunk():((!s||n>a.to||r<a.from||s(a.from,a.to,a.value))&&(c.addInner(a.from,a.to,a.value)||l.push(g_.create(a.from,a.to,a.value))),a.next());return c.finishInner(this.nextLayer.isEmpty&&!l.length?y_.empty:this.nextLayer.update({add:l,filter:s,filterFrom:n,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],a=this.chunk[s],o=e.touchesRange(r,r+a.length);if(!1===o)n=Math.max(n,a.maxPoint),t.push(a),i.push(e.mapPos(r));else if(!0===o){let{mapped:s,pos:o}=a.map(r,e);s&&(n=Math.max(n,s.maxPoint),t.push(s),i.push(o))}}let r=this.nextLayer.map(e);return 0==t.length?r:new y_(i,t,r||y_.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],s=this.chunk[n];if(t>=r&&e<=r+s.length&&!1===s.between(r,e-r,t-r,i))return}this.nextLayer.between(e,t,i)}}iter(e=0){return x_.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return x_.from(e).goto(t)}static compare(e,t,i,n,r=-1){let s=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=r),a=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=r),o=w_(s,a,i),l=new k_(s,o,r),c=new k_(a,o,r);i.iterGaps((e,t,i)=>P_(l,e,c,t,i,n)),i.empty&&0==i.length&&P_(l,0,c,0,0,n)}static eq(e,t,i=0,n){null==n&&(n=999999999);let r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(r.length!=s.length)return!1;if(!r.length)return!0;let a=w_(r,s),o=new k_(r,a,0).goto(i),l=new k_(s,a,0).goto(i);for(;;){if(o.to!=l.to||!T_(o.active,l.active)||o.point&&(!l.point||!m_(o.point,l.point)))return!1;if(o.to>n)return!0;o.next(),l.next()}}static spans(e,t,i,n,r=-1){let s=new k_(e,null,r).goto(t),a=t,o=s.openStart;for(;;){let e=Math.min(s.to,i);if(s.point){let i=s.activeForPoint(s.to),r=s.pointFrom<t?i.length+1:s.point.startSide<0?i.length:Math.min(i.length,o);n.point(a,e,s.point,i,r,s.pointRank),o=Math.min(s.openEnd(e),i.length)}else e>a&&(n.span(a,e,s.active,o),o=s.openEnd(e));if(s.to>i)return o+(s.point&&s.to>i?1:0);a=s.to,s.next()}}static of(e,t=!1){let i=new b_;for(let n of e instanceof g_?[e]:t?function(e){if(e.length>1)for(let t=e[0],i=1;i<e.length;i++){let n=e[i];if(O_(t,n)>0)return e.slice().sort(O_);t=n}return e}(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return y_.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=y_.empty;n=n.nextLayer)t=new y_(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}y_.empty=new y_([],[],null,-1),y_.empty.nextLayer=y_.empty;class b_{finishChunk(e){this.chunks.push(new v_(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new b_)).add(e,t,i)}addInner(e,t,i){let n=e-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(y_.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return e;let t=y_.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function w_(e,t,i){let n=new Map;for(let s of e)for(let e=0;e<s.chunk.length;e++)s.chunk[e].maxPoint<=0&&n.set(s.chunk[e],s.chunkPos[e]);let r=new Set;for(let s of t)for(let e=0;e<s.chunk.length;e++){let t=n.get(s.chunk[e]);null==t||(i?i.mapPos(t):t)!=s.chunkPos[e]||(null==i?void 0:i.touchesRange(t,t+s.chunk[e].length))||r.add(s.chunk[e])}return r}class __{constructor(e,t,i,n=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let t=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(t)||this.layer.chunkEnd(this.chunkIndex)<e||t.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class x_{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let r=0;r<e.length;r++)for(let s=e[r];!s.isEmpty;s=s.nextLayer)s.maxPoint>=i&&n.push(new __(s,t,i,r));return 1==n.length?n[0]:new x_(n)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)S_(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)S_(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),S_(this.heap,0)}}}function S_(e,t){for(let i=e[t];;){let n=1+(t<<1);if(n>=e.length)break;let r=e[n];if(n+1<e.length&&r.compare(e[n+1])>=0&&(r=e[n+1],n++),i.compare(r)<0)break;e[n]=i,e[t]=r,t=n}}class k_{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=x_.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){$_(this.active,e),$_(this.activeTo,e),$_(this.activeRank,e),this.minActive=A_(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||n-this.activeTo[t])>0;)t++;E_(this.active,t,i),E_(this.activeTo,t,n),E_(this.activeRank,t,r),e&&E_(e,t,this.cursor.from),this.minActive=A_(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&$_(i,n)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let e=this.cursor.value;if(e.point){if(!(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){this.point=e,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=e.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}this.cursor.next()}else this.addActive(i),this.cursor.next()}}}if(i){this.openStart=0;for(let t=i.length-1;t>=0&&i[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function P_(e,t,i,n,r,s){e.goto(t),i.goto(n);let a=n+r,o=n,l=n-t,c=!!s.boundChange;for(let h=!1;;){let t=e.to+l-i.to,n=t||e.endSide-i.endSide,r=n<0?e.to+l:i.to,u=Math.min(r,a);if(e.point||i.point?(e.point&&i.point&&m_(e.point,i.point)&&T_(e.activeForPoint(e.to),i.activeForPoint(i.to))||s.comparePoint(o,u,e.point,i.point),h=!1):(h&&s.boundChange(o),u>o&&!T_(e.active,i.active)&&s.compareRange(o,u,e.active,i.active),c&&u<a&&(t||e.openEnd(r)!=i.openEnd(r))&&(h=!0)),r>a)break;o=r,n<=0&&e.next(),n>=0&&i.next()}}function T_(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(e[i]!=t[i]&&!m_(e[i],t[i]))return!1;return!0}function $_(e,t){for(let i=t,n=e.length-1;i<n;i++)e[i]=e[i+1];e.pop()}function E_(e,t,i){for(let n=e.length-1;n>=t;n--)e[n+1]=e[n];e[t]=i}function A_(e,t){let i=-1,n=1e9;for(let r=0;r<t.length;r++)(t[r]-n||e[r].endSide-e[i].endSide)<0&&(i=r,n=t[r]);return i}function C_(e,t,i=e.length){let n=0;for(let r=0;r<i&&r<e.length;)9==e.charCodeAt(r)?(n+=t-n%t,r++):(n++,r=aw(e,r));return n}const R_="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Q_="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),I_="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class j_{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function r(e,t,s,a){let o=[],l=/^@(\w+)\b/.exec(e[0]),c=l&&"keyframes"==l[1];if(l&&null==t)return s.push(e[0]+";");for(let i in t){let a=t[i];if(/&/.test(i))r(i.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),a,s);else if(a&&"object"==typeof a){if(!l)throw new RangeError("The value of a property ("+i+") should be a primitive value.");r(n(i),a,o,c)}else null!=a&&o.push(i.replace(/_.*/,"").replace(/[A-Z]/g,e=>"-"+e.toLowerCase())+": "+a+";")}(o.length||c)&&s.push((!i||l||a?e:e.map(i)).join(", ")+" {"+o.join(" ")+"}")}for(let s in e)r(n(s),e[s],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let e=I_[R_]||1;return I_[R_]=e+1,"ͼ"+e.toString(36)}static mount(e,t,i){let n=e[Q_],r=i&&i.nonce;n?r&&n.setNonce(r):n=new N_(e,r),n.mount(Array.isArray(t)?t:[t],e)}}let M_=new Map;class N_{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let t=M_.get(i);if(t)return e[Q_]=t;this.sheet=new n.CSSStyleSheet,M_.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[Q_]=this}mount(e,t){let i=this.sheet,n=0,r=0;for(let s=0;s<e.length;s++){let t=e[s],a=this.modules.indexOf(t);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),-1==a){if(this.modules.splice(r++,0,t),i)for(let e=0;e<t.rules.length;e++)i.insertRule(t.rules[e],n++)}else{for(;r<a;)n+=this.modules[r++].rules.length;n+=t.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let e="";for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+"\n";this.styleTag.textContent=e;let i=t.head||t;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}for(var L_={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Z_={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},D_="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),z_="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),U_=0;U_<10;U_++)L_[48+U_]=L_[96+U_]=String(U_);for(U_=1;U_<=24;U_++)L_[U_+111]="F"+U_;for(U_=65;U_<=90;U_++)L_[U_]=String.fromCharCode(U_+32),Z_[U_]=String.fromCharCode(U_);for(var q_ in L_)Z_.hasOwnProperty(q_)||(Z_[q_]=L_[q_]);function X_(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var r=i[n];"string"==typeof r?e.setAttribute(n,r):null!=r&&(e[n]=r)}t++}for(;t<arguments.length;t++)B_(e,arguments[t]);return e}function B_(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var i=0;i<t.length;i++)B_(e,t[i])}}let W_="undefined"!=typeof navigator?navigator:{userAgent:"",vendor:"",platform:""},V_="undefined"!=typeof document?document:{documentElement:{style:{}}};const F_=/Edge\/(\d+)/.exec(W_.userAgent),Y_=/MSIE \d/.test(W_.userAgent),G_=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(W_.userAgent),H_=!!(Y_||G_||F_),K_=!H_&&/gecko\/(\d+)/i.test(W_.userAgent),J_=!H_&&/Chrome\/(\d+)/.exec(W_.userAgent),ex="webkitFontSmoothing"in V_.documentElement.style,tx=!H_&&/Apple Computer/.test(W_.vendor),ix=tx&&(/Mobile\/\w+/.test(W_.userAgent)||W_.maxTouchPoints>2);var nx={mac:ix||/Mac/.test(W_.platform),windows:/Win/.test(W_.platform),linux:/Linux|X11/.test(W_.platform),ie:H_,ie_version:Y_?V_.documentMode||6:G_?+G_[1]:F_?+F_[1]:0,gecko:K_,gecko_version:K_?+(/Firefox\/(\d+)/.exec(W_.userAgent)||[0,0])[1]:0,chrome:!!J_,chrome_version:J_?+J_[1]:0,ios:ix,android:/Android\b/.test(W_.userAgent),webkit:ex,webkit_version:ex?+(/\bAppleWebKit\/(\d+)/.exec(W_.userAgent)||[0,0])[1]:0,safari:tx,safari_version:tx?+(/\bVersion\/(\d+(\.\d+)?)/.exec(W_.userAgent)||[0,0])[1]:0,tabSize:null!=V_.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function rx(e,t){for(let i in e)"class"==i&&t.class?t.class+=" "+e.class:"style"==i&&t.style?t.style+=";"+e.style:t[i]=e[i];return t}const sx=Object.create(null);function ax(e,t,i){if(e==t)return!0;e||(e=sx),t||(t=sx);let n=Object.keys(e),r=Object.keys(t);if(n.length-0!=r.length-0)return!1;for(let s of n)if(s!=i&&(-1==r.indexOf(s)||e[s]!==t[s]))return!1;return!0}function ox(e,t,i){let n=!1;if(t)for(let r in t)i&&r in i||(n=!0,"style"==r?e.style.cssText="":e.removeAttribute(r));if(i)for(let r in i)t&&t[r]==i[r]||(n=!0,"style"==r?e.style.cssText=i[r]:e.setAttribute(r,i[r]));return n}function lx(e){let t=Object.create(null);for(let i=0;i<e.attributes.length;i++){let n=e.attributes[i];t[n.name]=n.value}return t}class cx{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var hx=function(e){return e[e.Text=0]="Text",e[e.WidgetBefore=1]="WidgetBefore",e[e.WidgetAfter=2]="WidgetAfter",e[e.WidgetRange=3]="WidgetRange",e}(hx||(hx={}));class ux extends f_{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new dx(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new fx(e,t,t,i,e.widget||null,!1)}static replace(e){let t,i,n=!!e.block;if(e.isBlockGap)t=-5e8,i=4e8;else{let{start:r,end:s}=mx(e,n);t=(r?n?-3e8:-1:5e8)-1,i=1+(s?n?2e8:1:-6e8)}return new fx(e,t,i,n,e.widget||null,!0)}static line(e){return new px(e)}static set(e,t=!1){return y_.of(e,t)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ux.none=y_.empty;class dx extends ux{constructor(e){let{start:t,end:i}=mx(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?rx(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||sx}eq(e){return this==e||e instanceof dx&&this.tagName==e.tagName&&ax(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}dx.prototype.point=!1;class px extends ux{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof px&&this.spec.class==e.spec.class&&ax(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}px.prototype.mapMode=uw.TrackBefore,px.prototype.point=!0;class fx extends ux{constructor(e,t,i,n,r,s){super(t,i,r,e),this.block=n,this.isReplace=s,this.mapMode=n?t<=0?uw.TrackBefore:uw.TrackAfter:uw.TrackDel}get type(){return this.startSide!=this.endSide?hx.WidgetRange:this.startSide<=0?hx.WidgetBefore:hx.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof fx&&(t=this.widget,i=e.widget,t==i||!!(t&&i&&t.compare(i)))&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide;var t,i}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}function mx(e,t=!1){let{inclusiveStart:i,inclusiveEnd:n}=e;return null==i&&(i=e.inclusive),null==n&&(n=e.inclusive),{start:null!=i?i:t,end:null!=n?n:t}}function gx(e,t,i,n=0){let r=i.length-1;r>=0&&i[r]+n>=e?i[r]=Math.max(i[r],t):i.push(e,t)}fx.prototype.point=!0;class Ox extends f_{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof Ox&&this.tagName==e.tagName&&ax(this.attributes,e.attributes)}static create(e){return new Ox(e.tagName,e.attributes||sx)}static set(e,t=!1){return y_.of(e,t)}}function vx(e){let t;return t=11==e.nodeType?e.getSelection?e:e.ownerDocument:e,t.getSelection()}function yx(e,t){return!!t&&(e==t||e.contains(1!=t.nodeType?t.parentNode:t))}function bx(e,t){if(!t.anchorNode)return!1;try{return yx(e,t.anchorNode)}catch(EM){return!1}}function wx(e){return 3==e.nodeType?jx(e,0,e.nodeValue.length).getClientRects():1==e.nodeType?e.getClientRects():[]}function _x(e,t,i,n){return!!i&&(kx(e,t,i,n,-1)||kx(e,t,i,n,1))}function xx(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t}function Sx(e){return 1==e.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}function kx(e,t,i,n,r){for(;;){if(e==i&&t==n)return!0;if(t==(r<0?0:Px(e))){if("DIV"==e.nodeName)return!1;let i=e.parentNode;if(!i||1!=i.nodeType)return!1;t=xx(e)+(r<0?0:1),e=i}else{if(1!=e.nodeType)return!1;if(1==(e=e.childNodes[t+(r<0?-1:0)]).nodeType&&"false"==e.contentEditable)return!1;t=r<0?Px(e):0}}}function Px(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Tx(e,t){let i=t?e.left:e.right;return{left:i,right:i,top:e.top,bottom:e.bottom}}function $x(e){let t=e.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.innerWidth,top:0,bottom:e.innerHeight}}function Ex(e,t){let i=t.width/e.offsetWidth,n=t.height/e.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.width-e.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(t.height-e.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}function Ax(e,t=!0){let i=e.ownerDocument,n=null,r=null;for(let s=e.parentNode;s&&(s!=i.body&&(t&&!n||!r));)if(1==s.nodeType)!r&&s.scrollHeight>s.clientHeight&&(r=s),t&&!n&&s.scrollWidth>s.clientWidth&&(n=s),s=s.assignedSlot||s.parentNode;else{if(11!=s.nodeType)break;s=s.host}return{x:n,y:r}}Ox.prototype.startSide=Ox.prototype.endSide=-1;class Cx{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Px(t):0),i,Math.min(e.focusOffset,i?Px(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let Rx,Qx=null;function Ix(e){if(e.setActive)return e.setActive();if(Qx)return e.focus(Qx);let t=[];for(let i=e;i&&(t.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(e.focus(null==Qx?{get preventScroll(){return Qx={preventScroll:!0},!0}}:void 0),!Qx){Qx=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}function jx(e,t,i=t){let n=Rx||(Rx=document.createRange());return n.setEnd(e,i),n.setStart(e,t),n}function Mx(e,t,i,n){let r={key:t,code:t,keyCode:i,which:i,cancelable:!0};n&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=n);let s=new KeyboardEvent("keydown",r);s.synthetic=!0,e.dispatchEvent(s);let a=new KeyboardEvent("keyup",r);return a.synthetic=!0,e.dispatchEvent(a),s.defaultPrevented||a.defaultPrevented}function Nx(e){return e instanceof Window?e.pageYOffset>Math.max(0,e.document.documentElement.scrollHeight-e.innerHeight-4):e.scrollTop>Math.max(1,e.scrollHeight-e.clientHeight-4)}function Lx(e,t){for(let i=e,n=t;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=Px(i)}else{if(!i.parentNode||Sx(i))return null;n=xx(i),i=i.parentNode}}}function Zx(e,t){for(let i=e,n=t;;){if(3==i.nodeType&&n<i.nodeValue.length)return{node:i,offset:n};if(1==i.nodeType&&n<i.childNodes.length){if("false"==i.contentEditable)return null;i=i.childNodes[n],n=0}else{if(!i.parentNode||Sx(i))return null;n=xx(i)+1,i=i.parentNode}}}nx.safari&&nx.safari_version>=26&&(Qx=!1);class Dx{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Dx(e.parentNode,xx(e),t)}static after(e,t){return new Dx(e.parentNode,xx(e)+1,t)}}var zx=function(e){return e[e.LTR=0]="LTR",e[e.RTL=1]="RTL",e}(zx||(zx={}));const Ux=zx.LTR,qx=zx.RTL;function Xx(e){let t=[];for(let i=0;i<e.length;i++)t.push(1<<+e[i]);return t}const Bx=Xx("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Wx=Xx("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Vx=Object.create(null),Fx=[];for(let AM of["()","[]","{}"]){let e=AM.charCodeAt(0),t=AM.charCodeAt(1);Vx[e]=t,Vx[t]=-e}function Yx(e){return e<=247?Bx[e]:1424<=e&&e<=1524?2:1536<=e&&e<=1785?Wx[e-1536]:1774<=e&&e<=2220?4:8192<=e&&e<=8204?256:64336<=e&&e<=65023?4:1}const Gx=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Hx{get dir(){return this.level%2?qx:Ux}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let s=0;s<e.length;s++){let a=e[s];if(a.from<=t&&a.to>=t){if(a.level==i)return s;(r<0||(0!=n?n<0?a.from<t:a.to>t:e[r].level>a.level))&&(r=s)}}if(r<0)throw new RangeError("Index out of range");return r}}function Kx(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.direction!=r.direction||!Kx(n.inner,r.inner))return!1}return!0}const Jx=[];function eS(e,t,i,n,r,s,a){let o=n%2?2:1;if(n%2==r%2)for(let l=t,c=0;l<i;){let t=!0,h=!1;if(c==s.length||l<s[c].from){let e=Jx[l];e!=o&&(t=!1,h=16==e)}let u=t||1!=o?null:[],d=t?n:n+1,p=l;e:for(;;)if(c<s.length&&p==s[c].from){if(h)break e;let f=s[c];if(!t)for(let e=f.to,t=c+1;;){if(e==i)break e;if(!(t<s.length&&s[t].from==e)){if(Jx[e]==o)break e;break}e=s[t++].to}if(c++,u)u.push(f);else{f.from>l&&a.push(new Hx(l,f.from,d)),tS(e,f.direction==Ux!=!(d%2)?n+1:n,r,f.inner,f.from,f.to,a),l=f.to}p=f.to}else{if(p==i||(t?Jx[p]!=o:Jx[p]==o))break;p++}u?eS(e,l,p,n+1,r,u,a):l<p&&a.push(new Hx(l,p,d)),l=p}else for(let l=i,c=s.length;l>t;){let i=!0,h=!1;if(!c||l>s[c-1].to){let e=Jx[l-1];e!=o&&(i=!1,h=16==e)}let u=i||1!=o?null:[],d=i?n:n+1,p=l;e:for(;;)if(c&&p==s[c-1].to){if(h)break e;let f=s[--c];if(!i)for(let e=f.from,i=c;;){if(e==t)break e;if(!i||s[i-1].to!=e){if(Jx[e-1]==o)break e;break}e=s[--i].from}if(u)u.push(f);else{f.to<l&&a.push(new Hx(f.to,l,d)),tS(e,f.direction==Ux!=!(d%2)?n+1:n,r,f.inner,f.from,f.to,a),l=f.from}p=f.from}else{if(p==t||(i?Jx[p-1]!=o:Jx[p-1]==o))break;p--}u?eS(e,p,l,n+1,r,u,a):p<l&&a.push(new Hx(p,l,d)),l=p}}function tS(e,t,i,n,r,s,a){let o=t%2?2:1;!function(e,t,i,n,r){for(let s=0;s<=n.length;s++){let a=s?n[s-1].to:t,o=s<n.length?n[s].from:i,l=s?256:r;for(let t=a,i=l,n=l;t<o;t++){let r=Yx(e.charCodeAt(t));512==r?r=i:8==r&&4==n&&(r=16),Jx[t]=4==r?2:r,7&r&&(n=r),i=r}for(let e=a,t=l,n=l;e<o;e++){let r=Jx[e];if(128==r)e<o-1&&t==Jx[e+1]&&24&t?r=Jx[e]=t:Jx[e]=256;else if(64==r){let r=e+1;for(;r<o&&64==Jx[r];)r++;let s=e&&8==t||r<i&&8==Jx[r]?1==n?1:8:256;for(let t=e;t<r;t++)Jx[t]=s;e=r-1}else 8==r&&1==n&&(Jx[e]=1);t=r,7&r&&(n=r)}}}(e,r,s,n,o),function(e,t,i,n,r){let s=1==r?2:1;for(let a=0,o=0,l=0;a<=n.length;a++){let c=a?n[a-1].to:t,h=a<n.length?n[a].from:i;for(let t,i,n,a=c;a<h;a++)if(i=Vx[t=e.charCodeAt(a)])if(i<0){for(let e=o-3;e>=0;e-=3)if(Fx[e+1]==-i){let t=Fx[e+2],i=2&t?r:4&t?1&t?s:r:0;i&&(Jx[a]=Jx[Fx[e]]=i),o=e;break}}else{if(189==Fx.length)break;Fx[o++]=a,Fx[o++]=t,Fx[o++]=l}else if(2==(n=Jx[a])||1==n){let e=n==r;l=e?0:1;for(let t=o-3;t>=0;t-=3){let i=Fx[t+2];if(2&i)break;if(e)Fx[t+2]|=2;else{if(4&i)break;Fx[t+2]|=4}}}}}(e,r,s,n,o),function(e,t,i,n){for(let r=0,s=n;r<=i.length;r++){let a=r?i[r-1].to:e,o=r<i.length?i[r].from:t;for(let l=a;l<o;){let a=Jx[l];if(256==a){let a=l+1;for(;;)if(a==o){if(r==i.length)break;a=i[r++].to,o=r<i.length?i[r].from:t}else{if(256!=Jx[a])break;a++}let c=1==s,h=c==(1==(a<t?Jx[a]:n))?c?1:2:n;for(let t=a,n=r,s=n?i[n-1].to:e;t>l;)t==s&&(t=i[--n].from,s=n?i[n-1].to:e),Jx[--t]=h;l=a}else s=a,l++}}}(r,s,n,o),eS(e,r,s,t,i,n,a)}function iS(e){return[new Hx(0,e,0)]}let nS="";function rS(e,t,i,n,r){var s;let a=n.head-e.from,o=Hx.find(t,a,null!==(s=n.bidiLevel)&&void 0!==s?s:-1,n.assoc),l=t[o],c=l.side(r,i);if(a==c){let e=o+=r?1:-1;if(e<0||e>=t.length)return null;l=t[o=e],a=l.side(!r,i),c=l.side(r,i)}let h=aw(e.text,a,l.forward(r,i));(h<l.from||h>l.to)&&(h=c),nS=e.text.slice(Math.min(a,h),Math.max(a,h));let u=o==(r?t.length-1:0)?null:t[o+(r?1:-1)];return u&&h==c&&u.level+(r?0:1)<l.level?ww.cursor(u.side(!r,i)+e.from,u.forward(r,i)?1:-1,u.level):ww.cursor(h+e.from,l.forward(r,i)?-1:1,l.level)}function sS(e,t,i){for(let n=t;n<i;n++){let t=Yx(e.charCodeAt(n));if(1==t)return Ux;if(2==t||4==t)return qx}return Ux}const aS=Sw.define(),oS=Sw.define(),lS=Sw.define(),cS=Sw.define(),hS=Sw.define(),uS=Sw.define(),dS=Sw.define(),pS=Sw.define(),fS=Sw.define(),mS=Sw.define({combine:e=>e.some(e=>e)}),gS=Sw.define({combine:e=>e.some(e=>e)}),OS=Sw.define();class vS{constructor(e,t,i,n,r,s=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=s}map(e){return e.empty?this:new vS(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new vS(ww.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const yS=e_.define({map:(e,t)=>e.map(t)}),bS=e_.define();function wS(e,t,i){let n=e.facet(cS);n.length?n[0](t):window.onerror&&window.onerror(String(t),i,void 0,void 0,t)}const _S=Sw.define({combine:e=>!e.length||e[0]});let xS=0;const SS=Sw.define({combine:e=>e.filter((t,i)=>{for(let n=0;n<i;n++)if(e[n].plugin==t.plugin)return!1;return!0})});class kS{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(SS.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(SS.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:s}=t||{};return new kS(xS++,e,i,n,e=>{let t=[];return s&&t.push(ES.of(t=>{let i=t.plugin(e);return i?s(i):ux.none})),r&&t.push(r(e)),t})}static fromClass(e,t){return kS.define((t,i)=>new e(t,i),t)}}class PS{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(wS(e.state,t,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(EM){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){wS(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(null===(t=this.value)||void 0===t?void 0:t.destroy)try{this.value.destroy()}catch(i){wS(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const TS=Sw.define(),$S=Sw.define(),ES=Sw.define(),AS=Sw.define(),CS=Sw.define(),RS=Sw.define(),QS=Sw.define();function IS(e,t){let i=e.state.facet(QS);if(!i.length)return i;let n=i.map(t=>t instanceof Function?t(e):t),r=[];return y_.spans(n,t.from,t.to,{point(){},span(e,i,n,s){let a=e-t.from,o=i-t.from,l=r;for(let r=n.length-1;r>=0;r--,s--){let e,i=n[r].spec.bidiIsolate;if(null==i&&(i=sS(t.text,a,o)),s>0&&l.length&&(e=l[l.length-1]).to==a&&e.direction==i)e.to=o,l=e.inner;else{let e={from:a,to:o,direction:i,inner:[]};l.push(e),l=e.inner}}}}),r}const jS=Sw.define();function MS(e){let t=0,i=0,n=0,r=0;for(let s of e.state.facet(jS)){let a=s(e);a&&(null!=a.left&&(t=Math.max(t,a.left)),null!=a.right&&(i=Math.max(i,a.right)),null!=a.top&&(n=Math.max(n,a.top)),null!=a.bottom&&(r=Math.max(r,a.bottom)))}return{left:t,right:i,top:n,bottom:r}}const NS=Sw.define();class LS{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new LS(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(0==t.length)return e;let i=[];for(let n=0,r=0,s=0;;){let a=n<e.length?e[n].fromB:1e9,o=r<t.length?t[r]:1e9,l=Math.min(a,o);if(1e9==l)break;let c=l+s,h=l,u=c;for(;;)if(r<t.length&&t[r]<=h){let i=t[r+1];r+=2,h=Math.max(h,i);for(let t=n;t<e.length&&e[t].fromB<=h;t++)s=e[t].toA-e[t].toB;u=Math.max(u,i+s)}else{if(!(n<e.length&&e[n].fromB<=h))break;{let t=e[n++];h=Math.max(h,t.toB),u=Math.max(u,t.toA),s=t.toA-t.toB}}i.push(new LS(c,u,l,h))}return i}}class ZS{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=pw.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((e,t,i,r)=>n.push(new LS(e,t,i,r))),this.changedRanges=n}static create(e,t,i){return new ZS(e,t,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}const DS=[];class zS{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return 1&this.flags}get children(){return DS}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,4&this.flags){this.flags&=-5;let e=this.domAttrs;e&&function(e,t){for(let i=e.attributes.length-1;i>=0;i--){let n=e.attributes[i].name;null==t[n]&&e.removeAttribute(n)}for(let i in t){let n=t[i];"style"==i?e.style.cssText=n:e.getAttribute(i)!=n&&e.setAttribute(i,n)}}(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let n of this.children){if(n==e)return i;i+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=xx(this.dom),n=this.length?e>0:t>0;return new Dx(this.parent.dom,i+(n?1:0),0==e||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&2&this.parent.flags&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof XS)return e;return null}static get(e){return e.cmTile}}class US extends zS{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(2&this.flags)return;super.sync(e);let t,i=this.dom,n=null,r=(null==e?void 0:e.node)==i?e:null,s=0;for(let a of this.children){if(a.sync(e),s+=a.length+a.breakAfter,t=n?n.nextSibling:i.firstChild,r&&t!=a.dom&&(r.written=!0),a.dom.parentNode==i)for(;t&&t!=a.dom;)t=qS(t);else i.insertBefore(a.dom,t);n=a.dom}for(t=n?n.nextSibling:i.firstChild,r&&t&&(r.written=!0);t;)t=qS(t);this.length=s}}function qS(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class XS extends US{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=zS.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,n=0,r=0;;)if(n==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,n=t.pop()}else{let s=i.children[n++];if(s instanceof BS)t.push(n),i=s,n=0;else{let t=r+s.length,i=e(s,r);if(void 0!==i)return i;r=t+s.breakAfter}}}resolveBlock(e,t){let i,n,r=-1,s=-1;if(this.blockTiles((a,o)=>{let l=o+a.length;if(e>=o&&e<=l){if(a.isWidget()&&t>=-1&&t<=1){if(32&a.flags)return!0;16&a.flags&&(i=void 0)}(o<e||e==l&&(t<-1?a.length:a.covers(1)))&&(!i||!a.isWidget()&&i.isWidget())&&(i=a,r=e-o),(l>e||e==o&&(t>1?a.length:a.covers(-1)))&&(!n||!a.isWidget()&&n.isWidget())&&(n=a,s=e-o)}}),!i&&!n)throw new Error("No tile at position "+e);return i&&t<0||!n?{tile:i,offset:r}:{tile:n,offset:s}}}class BS extends US{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return!!this.children.length&&(e<0?this.children[0].covers(-1):this.lastChild.covers(1))}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new BS(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class WS extends US{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let n=new WS(t||document.createElement("div"),e);return t&&i||(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(e,t,i){let n=null,r=-1,s=null,a=-1;!function e(o,l){for(let c=0,h=0;c<o.children.length&&h<=l;c++){let u=o.children[c],d=h+u.length;d>=l&&(u.isComposite()?e(u,l-h):(!s||s.isHidden&&(t>0||i&&VS(s,u)))&&(d>l||32&u.flags)?(s=u,a=l-h):(h<l||16&u.flags&&!u.isHidden)&&(n=u,r=l-h)),h=d}}(this,e);let o=(t<0?n:s)||n||s;return o?{tile:o,offset:o==n?r:a}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):function(e){let t=e.dom.lastChild;if(!t)return e.dom.getBoundingClientRect();let i=wx(t);return i[i.length-1]||null}(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:e,offset:n}=i;if(this.dom.contains(e.dom))return e.isText()?new Dx(e.dom,Math.min(e.dom.nodeValue.length,n)):e.domPosFor(n,16&e.flags?1:32&e.flags?-1:t);let r=i.tile.parent,s=!1;for(let t of r.children){if(s)return new Dx(t.dom,0);t==i.tile&&(s=!0)}}return new Dx(this.dom,0)}}function VS(e,t){let i=e.coordsIn(0,1),n=t.coordsIn(0,1);return i&&n&&n.top<i.bottom}class FS extends US{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new FS(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class YS extends zS{constructor(e,t){super(e,t.length),this.text=t}sync(e){2&this.flags||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let n=e,r=e,s=0;0==e&&t<0||e==i&&t>=0?nx.chrome||nx.gecko||(e?(n--,s=1):r<i&&(r++,s=-1)):t<0?n--:r<i&&r++;let a=jx(this.dom,n,r).getClientRects();if(!a.length)return null;let o=a[(s?s<0:t>=0)?0:a.length-1];return nx.safari&&!s&&0==o.width&&(o=Array.prototype.find.call(a,e=>e.width)||o),s?Tx(o,s<0):o||null}static of(e,t){let i=new YS(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class GS extends zS{constructor(e,t,i,n){super(e,t,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return!(48&this.flags)&&(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;if(i)return Tx(this.dom.getBoundingClientRect(),this.length?0==e:t<=0);{let t=this.dom.getClientRects(),i=null;if(!t.length)return null;let n=!!(16&this.flags)||!(32&this.flags)&&e>0;for(let r=n?t.length-1:0;i=t[r],!(e>0?0==r:r==t.length-1||i.top<i.bottom);r+=n?-1:1);return Tx(i,!n)}}get overrideDOMText(){if(!this.length)return Gb.empty;let{root:e}=this;if(!e)return Gb.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,n,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new GS(r,i,e,n)}}class HS extends zS{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return Gb.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class KS{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:n,index:r,beforeBreak:s,parents:a}=this;for(;e||t>0;)if(n.isComposite())if(s){if(!e)break;i&&i.break(),e--,s=!1}else if(r==n.children.length){if(!e&&!a.length)break;i&&i.leave(n),s=!!n.breakAfter,({tile:n,index:r}=a.pop()),r++}else{let o=n.children[r],l=o.breakAfter;!(t>0?o.length<=e:o.length<e)||i&&!1===i.skip(o,0,o.length)&&o.isComposite?(a.push({tile:n,index:r}),n=o,r=0,i&&o.isComposite()&&i.enter(o)):(s=!!l,r++,e-=o.length)}else if(r==n.length)s=!!n.breakAfter,({tile:n,index:r}=a.pop()),r++;else{if(!e)break;{let t=Math.min(e,n.length-r);i&&i.skip(n,r,r+t),e-=t,r+=t}}return this.tile=n,this.index=r,this.beforeBreak=s,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class JS{constructor(e,t,i,n){this.from=e,this.to=t,this.wrapper=i,this.rank=n}}class ek{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,n){var r;this.flushBuffer();let s=this.ensureMarks(t,i),a=s.lastChild;if(a&&a.isText()&&!(8&a.flags)&&a.length+e.length<512){this.cache.reused.set(a,2),(s.children[s.children.length-1]=new YS(a.dom,a.text+e)).parent=s}else s.append(n||YS.of(e,null===(r=this.cache.find(YS))||void 0===r?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?ok(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let n=i;for(let a=t.marks.length-1;a>=0;a--){let e=t.marks[a],i=n.lastChild;if(i instanceof FS&&i.mark.eq(e.mark))i.dom!=e.dom&&i.setDOM(ok(e.dom)),n=i;else{if(this.cache.reused.get(e)){let t=zS.get(e.dom);t&&t.setDOM(ok(e.dom))}let t=FS.of(e.mark,e.dom);n.append(t),n=t}this.cache.reused.set(e,2)}let r=zS.get(e.text);r&&this.cache.reused.set(r,2);let s=new YS(e.text,e.text.nodeValue);s.flags|=8,n.append(s)}addInlineWidget(e,t,i){let n=this.afterWidget&&48&e.flags&&(48&this.afterWidget.flags)==(48&e.flags);n||this.flushBuffer();let r=this.ensureMarks(t,i);n||16&e.flags||r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){(this.afterWidget||this.lastBlock).length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=ak);let n=WS.start(e,t||(null===(i=this.cache.find(WS))||void 0===i?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let n=this.curLine;for(let r=e.length-1;r>=0;r--){let s,a=e[r];if(t>0&&(s=n.lastChild)&&s instanceof FS&&s.mark.eq(a))n=s,t--;else{let e=FS.of(a,null===(i=this.cache.find(FS,e=>e.mark.eq(a)))||void 0===i?void 0:i.dom);n.append(e),n=e,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;e&&sk(this.curLine,!1)&&("BR"==e.dom.nodeName||!e.isWidget()||nx.ios&&sk(this.curLine,!0))||this.curLine.append(this.cache.findWidget(ck,0,32)||new GS(ck.toDOM(),0,ck,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new JS(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let n=t.lastChild;if(i.from<this.pos&&n instanceof BS&&n.wrapper.eq(i.wrapper))t=n;else{let n=BS.of(i.wrapper,null===(e=this.cache.find(BS,e=>e.wrapper.eq(i.wrapper)))||void 0===e?void 0:e.dom);t.append(n),t=n}}return t}blockPosCovered(){let e=this.lastBlock;return null!=e&&!e.breakAfter&&(!e.isWidget()||(160&e.flags)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(HS,void 0,1);return i&&(i.flags=t),i||new HS(t)}flushBuffer(){!this.afterWidget||32&this.afterWidget.flags||(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class tk{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:t,lineBreak:i,done:n}=this.cursor.next(this.skipCount);if(this.skipCount=0,n)throw new Error("Ran out of text content when drawing inline views");this.text=t;let r=this.textOff=Math.min(e,t.length);return i?null:t.slice(0,r)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const ik=[GS,WS,YS,FS,HS,BS,XS];for(let AM=0;AM<ik.length;AM++)ik[AM].bucket=AM;class nk{constructor(e){this.view=e,this.buckets=ik.map(()=>[]),this.index=ik.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let n=e.bucket,r=this.buckets[n],s=this.index[n];for(let a=r.length-1;a>=0;a--){let e=(a+s)%r.length,o=r[e];if((!t||t(o))&&!this.reused.has(o))return r.splice(e,1),e<s&&this.index[n]--,this.reused.set(o,i),o}return null}findWidget(e,t,i){let n=this.buckets[0];if(n.length)for(let r=0,s=0;;r++){if(r==n.length){if(s)return null;s=1,r=0}let a=n[r];if(!this.reused.has(a)&&(0==s?a.widget.compare(e):a.widget.constructor==e.constructor&&e.updateDOM(a.dom,this.view,a.widget)))return n.splice(r,1),r<this.index[0]&&this.index[0]--,a.widget==e&&a.length==t&&(497&a.flags)==i?(this.reused.set(a,1),a):(this.reused.set(a,2),new GS(a.dom,t,e,-498&a.flags|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class rk{constructor(e,t,i,n,r){this.view=e,this.decorations=n,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new nk(e),this.text=new tk(e.state.doc),this.builder=new ek(this.cache,new XS(e,e.contentDOM),y_.iter(i)),this.cache.reused.set(t,2),this.old=new KS(t),this.reuseWalker={skip:(e,t,i)=>{if(this.cache.add(e),e.isComposite())return!1},enter:e=>this.cache.add(e),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let n=0,r=0,s=0;;){let a=s<e.length?e[s++]:null,o=a?a.fromA:this.old.root.length;if(o>n){let e=o-n;this.preserve(e,!s,!a),n=o,r+=e}if(!a)break;t&&a.fromA<=t.range.fromA&&a.toA>=t.range.toA?(this.forward(a.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,a.toA),this.emit(t.range.toB,a.toB)):(this.forward(a.fromA,a.toA),this.emit(r,a.toB)),r=a.toB,n=a.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let n=function(e){let t=[];for(let i=e.parents.length;i>1;i--){let n=i==e.parents.length?e.tile:e.parents[i].tile;n instanceof FS&&t.push(n.mark)}return t}(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(e,t,i)=>{if(e.isWidget())if(this.openWidget)this.builder.continueWidget(i-t);else{let s=i>0||t<e.length?GS.of(e.widget,this.view,i-t,496&e.flags,this.cache.maybeReuse(e)):this.cache.reuse(e);256&s.flags?(s.flags&=-2,this.builder.addBlockWidget(s)):(this.builder.ensureLine(null),this.builder.addInlineWidget(s,n,r),r=n.length)}else if(e.isText())this.builder.ensureLine(null),t||i!=e.length||this.cache.reused.has(e)?(this.cache.add(e),this.builder.addText(e.text.slice(t,i),n,r)):this.builder.addText(e.text,n,r,this.cache.reuse(e)),r=n.length;else if(e.isLine())e.flags&=-2,this.cache.reused.set(e,1),this.builder.addLine(e);else if(e instanceof HS)this.cache.add(e);else{if(!(e instanceof FS))return!1;this.builder.ensureLine(null),this.builder.addMark(e,n,r),this.cache.reused.set(e,1),r=n.length}this.openWidget=!1},enter:e=>{e.isLine()?this.builder.addLineStart(e.attrs,this.cache.maybeReuse(e)):(this.cache.add(e),e instanceof FS&&n.unshift(e.mark)),this.openWidget=!1},leave:e=>{e.isLine()?n.length&&(n.length=r=0):e instanceof FS&&(n.shift(),r=Math.min(r,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,n=this.builder,r=0,s=y_.spans(this.decorations,e,t,{point:(e,t,s,a,o,l)=>{if(s instanceof fx){if(this.disallowBlockEffectsFor[l]){if(s.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.view.state.doc.lineAt(e).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=a.length,o>a.length)n.continueWidget(t-e);else{let r=s.widget||(s.block?lk.block:lk.inline),l=function(e){let t=e.isReplace?(e.startSide<0?64:0)|(e.endSide>0?128:0):e.startSide>0?32:16;e.block&&(t|=256);return t}(s),c=this.cache.findWidget(r,t-e,l)||GS.of(r,this.view,t-e,l);s.block?(s.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(c)):(n.ensureLine(i),n.addInlineWidget(c,a,o))}i=null}else i=function(e,t){let i=t.spec.attributes,n=t.spec.class;if(!i&&!n)return e;e||(e={class:"cm-line"});i&&rx(i,e);n&&(e.class+=" "+n);return e}(i,s);t>e&&this.text.skip(t-e)},span:(e,t,r,s)=>{for(let a=e;a<t;){let o=this.text.next(Math.min(512,t-a));null==o?(n.addLineStartIfNotCovered(i),n.addBreak(),a++):(n.ensureLine(i),n.addText(o,r,a==e?s:r.length),a+=o.length),i=null}}});n.addLineStartIfNotCovered(i),this.openWidget=s>r,this.openMarks=s}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let n=e.parentNode;;n=n.parentNode){let e=zS.get(n);if(n==this.view.contentDOM)break;e instanceof FS?t.push(e):(null==e?void 0:e.isLine())?i=e:e instanceof BS||("DIV"!=n.nodeName||i||n==this.view.contentDOM?i||t.push(FS.of(new dx({tagName:n.nodeName.toLowerCase(),attributes:lx(n)}),n)):i=new WS(n,ak))}return{line:i,marks:t}}}function sk(e,t){let i=e=>{for(let n of e.children)if((t?n.isText():n.length)||i(n))return!0;return!1};return i(e)}const ak={class:"cm-line"};function ok(e){let t=zS.get(e);return t&&t.setDOM(e.cloneNode()),e}class lk extends cx{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}lk.inline=new lk("span"),lk.block=new lk("div");const ck=new class extends cx{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class hk{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=ux.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new XS(e,e.contentDOM),this.updateInner([new LS(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:e,toA:t})=>t<this.minWidthFrom||e>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(t=this.domChanged)||void 0===t?void 0:t.newSel)?n=this.domChanged.newSel.head:function(e,t){let i=!1;t&&e.iterChangedRanges((e,n)=>{e<t.to&&n>t.from&&(i=!0)});return i}(e.changes,this.hasComposition)||e.selectionSet||(n=e.state.selection.main.head));let r=n>-1?function(e,t,i){let n=dk(e,i);if(!n)return null;let{node:r,from:s,to:a}=n,o=r.nodeValue;if(/[\n\r]/.test(o))return null;if(e.state.doc.sliceString(n.from,n.to)!=o)return null;let l=t.invertedDesc;return{range:new LS(l.mapPos(s),l.mapPos(a),s,a),text:r}}(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:t,to:n}=this.hasComposition;i=new LS(t,n,e.changes.mapPos(t,-1),e.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(nx.ie||nx.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let s=this.decorations,a=this.blockWrappers;this.updateDeco();let o=function(e,t,i){let n=new pk;return y_.compare(e,t,i,n),n.changes}(s,this.decorations,e.changes);o.length&&(i=LS.extendWithRanges(i,o));let l=function(e,t,i){let n=new fk;return y_.compare(e,t,i,n),n.changes}(a,this.blockWrappers,e.changes);return l.length&&(i=LS.extendWithRanges(i,l)),r&&!i.some(e=>e.fromA<=r.range.fromA&&e.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),!(2&this.tile.flags&&0==i.length)&&(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let i=this.tile,n=new rk(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&zS.get(t.text)&&n.cache.reused.set(zS.get(t.text),2),this.tile=n.run(e,t),uk(i,n.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let n=nx.chrome||nx.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(n),!n||!n.written&&i.selectionRange.focusNode==n.node&&this.tile.dom.contains(n.node)||(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof mk&&n.push(r.dom);i.updateGaps(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(bS)&&(this.editContextFormatting=e.value)}updateSelection(e=!1,t=!1){!e&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let{dom:i}=this.tile,n=this.view.root.activeElement,r=n==i,s=!r&&!(this.view.state.facet(_S)||i.tabIndex>-1)&&bx(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(r||t||s))return;let a=this.forceSelection;this.forceSelection=!1;let o,l,c=this.view.state.selection.main;if(c.empty?l=o=this.inlineDOMNearPos(c.anchor,c.assoc||1):(l=this.inlineDOMNearPos(c.head,c.head==c.from?1:-1),o=this.inlineDOMNearPos(c.anchor,c.anchor==c.from?1:-1)),nx.gecko&&c.empty&&!this.hasComposition&&(1==(h=o).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable))){let e=document.createTextNode("");this.view.observer.ignore(()=>o.node.insertBefore(e,o.node.childNodes[o.offset]||null)),o=l=new Dx(e,0),a=!0}var h;let u=this.view.observer.selectionRange;!a&&u.focusNode&&(_x(o.node,o.offset,u.anchorNode,u.anchorOffset)&&_x(l.node,l.offset,u.focusNode,u.focusOffset)||this.suppressWidgetCursorChange(u,c))||(this.view.observer.ignore(()=>{nx.android&&nx.chrome&&i.contains(u.focusNode)&&function(e,t){for(let i=e;i&&i!=t;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(u.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let e=vx(this.view.root);if(e)if(c.empty){if(nx.gecko){let e=(t=o.node,r=o.offset,1!=t.nodeType?0:(r&&"false"==t.childNodes[r-1].contentEditable?1:0)|(r<t.childNodes.length&&"false"==t.childNodes[r].contentEditable?2:0));if(e&&3!=e){let t=(1==e?Lx:Zx)(o.node,o.offset);t&&(o=new Dx(t.node,t.offset))}}e.collapse(o.node,o.offset),null!=c.bidiLevel&&void 0!==e.caretBidiLevel&&(e.caretBidiLevel=c.bidiLevel)}else if(e.extend){e.collapse(o.node,o.offset);try{e.extend(l.node,l.offset)}catch(EM){}}else{let t=document.createRange();c.anchor>c.head&&([o,l]=[l,o]),t.setEnd(l.node,l.offset),t.setStart(o.node,o.offset),e.removeAllRanges(),e.addRange(t)}else;var t,r;s&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(o,l)),this.impreciseAnchor=o.precise?null:new Dx(u.anchorNode,u.anchorOffset),this.impreciseHead=l.precise?null:new Dx(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&_x(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=vx(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!(i&&t.empty&&t.assoc&&i.modify))return;let s=this.lineAt(t.head,t.assoc);if(!s)return;let a=s.posAtStart;if(t.head==a||t.head==a+s.length)return;let o=this.coordsAt(t.head,-1),l=this.coordsAt(t.head,1);if(!o||!l||o.bottom>l.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let h=e.observer.selectionRange;e.docView.posFromDOM(h.anchorNode,h.anchorOffset)!=t.from&&i.collapse(n,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return 2&this.tile.dom.compareDocumentPosition(e)?0:this.view.state.doc.length;let n=i.posAtStart;if(!i.isComposite())return i.isText()?e==i.dom?n+t:n+(t?i.length:0):n;{let r;if(e==i.dom)r=i.dom.childNodes[t];else{let n=0==Px(e)?0:0==t?-1:1;for(;;){let t=e.parentNode;if(t==i.dom)break;0==n&&t.firstChild!=t.lastChild&&(n=e==t.firstChild?-1:1),e=t}r=n<0?e:e.nextSibling}if(r==i.dom.firstChild)return n;for(;r&&!zS.get(r);)r=r.nextSibling;if(!r)return n+i.length;for(let e=0,t=n;;e++){let n=i.children[e];if(n.dom==r)return t;t+=n.length+n.breakAfter}}}domAtPos(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(n,t)}inlineDOMNearPos(e,t){let i,n,r=-1,s=!1,a=-1,o=!1;return this.tile.blockTiles((t,l)=>{if(t.isWidget()){if(32&t.flags&&l>=e)return!0;16&t.flags&&(s=!0)}else{let c=l+t.length;if(l<=e&&(i=t,r=e-l,s=c<e),c>=e&&!n&&(n=t,a=e-l,o=l>e),l>e&&n)return!0}}),i||n?(s&&n?i=null:o&&i&&(n=null),i&&t<0||!n?i.domIn(r,t):n.domIn(a,t)):this.domAtPos(e,t)}coordsAt(e,t){let{tile:i,offset:n}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof mk?null:i.coordsInWidget(n,t,!0):i.coordsIn(n,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;return function e(t,i){if(t.isComposite())for(let n of t.children){if(n.length>=i){let t=e(n,i);if(t)return t}if((i-=n.length)<0)break}else if(t.isText()&&i<t.length){let e=aw(t.text,i);if(e==i)return null;let n=jx(t.dom,i,e).getClientRects();for(let t=0;t<n.length;t++){let e=n[t];if(t==n.length-1||e.top<e.bottom&&e.left<e.right)return e}}return null}(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,r=this.view.contentDOM.clientWidth,s=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,a=-1,o=this.view.textDirection==zx.LTR,l=0,c=(e,h,u)=>{for(let d=0;d<e.children.length&&!(h>n);d++){let n=e.children[d],p=h+n.length,f=n.dom.getBoundingClientRect(),{height:m}=f;if(u&&!d&&(l+=f.top-u.top),n instanceof BS)p>i&&c(n,h,f);else if(h>=i&&(l>0&&t.push(-l),t.push(m+l),l=0,s)){let e=n.dom.lastChild,t=e?wx(e):[];if(t.length){let e=t[t.length-1],i=o?e.right-f.left:f.right-e.left;i>a&&(a=i,this.minWidth=r,this.minWidthFrom=h,this.minWidthTo=p)}}u&&d==e.children.length-1&&(l+=u.bottom-f.bottom),h=p+n.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return"rtl"==getComputedStyle(t.dom).direction?zx.RTL:zx.LTR}measureTextSize(){let e=this.tile.blockTiles(e=>{if(e.isLine()&&e.children.length&&e.length<=20){let t,i=0;for(let n of e.children){if(!n.isText()||/[^ -~]/.test(n.text))return;let e=wx(n.dom);if(1!=e.length)return;i+=e[0].width,t=e[0].height}if(i)return{lineHeight:e.dom.getBoundingClientRect().height,charWidth:i/e.length,textHeight:t}}});if(e)return e;let t,i,n,r=document.createElement("div");return r.className="cm-line",r.style.width="99999px",r.style.position="absolute",r.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(r);let e=wx(r.firstChild)[0];t=r.getBoundingClientRect().height,i=e&&e.width?e.width/27:7,n=e&&e.height?e.height:t,r.remove()}),{lineHeight:t,charWidth:i,textHeight:n}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],s=r?r.from-1:this.view.state.doc.length;if(s>i){let n=(t.lineBlockAt(s).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(ux.replace({widget:new mk(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,s))}if(!r)break;i=r.to+1}return ux.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ES).map(t=>(this.dynamicDecorationMap[e++]="function"==typeof t)?t(this.view):t),i=!1,n=this.view.state.facet(CS).map((e,t)=>{let n="function"==typeof e;return n&&(i=!0),n?e(this.view):e});for(n.length&&(this.dynamicDecorationMap[e++]=i,t.push(y_.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(AS).map(e=>"function"==typeof e?e(this.view):e)}scrollIntoView(e){var t;if(e.isSnapshot){let t=this.view.viewState.lineBlockAt(e.range.head);return this.view.scrollDOM.scrollTop=t.top-e.yMargin,void(this.view.scrollDOM.scrollLeft=e.xMargin)}for(let h of this.view.state.facet(OS))try{if(h(this.view,e.range,e))return!0}catch(c){wS(this.view.state,c,"scroll handler")}let i,{range:n}=e,r=this.coordsAt(n.head,null!==(t=n.assoc)&&void 0!==t?t:n.empty?0:n.head>n.anchor?-1:1);if(!r)return;!n.empty&&(i=this.coordsAt(n.anchor,n.anchor>n.head?-1:1))&&(r={left:Math.min(r.left,i.left),top:Math.min(r.top,i.top),right:Math.max(r.right,i.right),bottom:Math.max(r.bottom,i.bottom)});let s=MS(this.view),a={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(function(e,t,i,n,r,s,a,o){let l=e.ownerDocument,c=l.defaultView||window;for(let h=e,u=!1;h&&!u;)if(1==h.nodeType){let e,d=h==l.body,p=1,f=1;if(d)e=$x(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(u=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let t=h.getBoundingClientRect();({scaleX:p,scaleY:f}=Ex(h,t)),e={left:t.left,right:t.left+h.clientWidth*p,top:t.top,bottom:t.top+h.clientHeight*f}}let m=0,g=0;if("nearest"==r)t.top<e.top+a?(g=t.top-(e.top+a),i>0&&t.bottom>e.bottom+g&&(g=t.bottom-e.bottom+a)):t.bottom>e.bottom-a&&(g=t.bottom-e.bottom+a,i<0&&t.top-g<e.top&&(g=t.top-(e.top+a)));else{let n=t.bottom-t.top,s=e.bottom-e.top;g=("center"==r&&n<=s?t.top+n/2-s/2:"start"==r||"center"==r&&i<0?t.top-a:t.bottom-s+a)-e.top}if("nearest"==n?t.left<e.left+s?(m=t.left-(e.left+s),i>0&&t.right>e.right+m&&(m=t.right-e.right+s)):t.right>e.right-s&&(m=t.right-e.right+s,i<0&&t.left<e.left+m&&(m=t.left-(e.left+s))):m=("center"==n?t.left+(t.right-t.left)/2-(e.right-e.left)/2:"start"==n==o?t.left-s:t.right-(e.right-e.left)+s)-e.left,m||g)if(d)c.scrollBy(m,g);else{let e=0,i=0;if(g){let e=h.scrollTop;h.scrollTop+=g/f,i=(h.scrollTop-e)*f}if(m){let t=h.scrollLeft;h.scrollLeft+=m/p,e=(h.scrollLeft-t)*p}t={left:t.left-e,top:t.top-i,right:t.right-e,bottom:t.bottom-i},e&&Math.abs(e-m)<1&&(n="nearest"),i&&Math.abs(i-g)<1&&(r="nearest")}if(d)break;(t.top<e.top||t.bottom>e.bottom||t.left<e.left||t.right>e.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),h=h.assignedSlot||h.parentNode}else{if(11!=h.nodeType)break;h=h.host}}(this.view.scrollDOM,a,n.head<n.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==zx.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let e=this.view.docView.lineAt(n.head,1);e&&e.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=e=>e.isWidget()||e.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){uk(this.tile)}}function uk(e,t){let i=null==t?void 0:t.get(e);if(1!=i){null==i&&e.destroy();for(let i of e.children)uk(i,t)}}function dk(e,t){let i=e.observer.selectionRange;if(!i.focusNode)return null;let n=Lx(i.focusNode,i.focusOffset),r=Zx(i.focusNode,i.focusOffset),s=n||r;if(r&&n&&r.node!=n.node){let t=zS.get(r.node);if(!t||t.isText()&&t.text!=r.node.nodeValue)s=r;else if(e.docView.lastCompositionAfterCursor){let e=zS.get(n.node);!e||e.isText()&&e.text!=n.node.nodeValue||(s=r)}}if(e.docView.lastCompositionAfterCursor=s!=n,!s)return null;let a=t-s.offset;return{from:a,to:a+s.node.nodeValue.length,node:s.node}}let pk=class{constructor(){this.changes=[]}compareRange(e,t){gx(e,t,this.changes)}comparePoint(e,t){gx(e,t,this.changes)}boundChange(e){gx(e,e,this.changes)}};class fk{constructor(){this.changes=[]}compareRange(e,t){gx(e,t,this.changes)}comparePoint(){}boundChange(e){gx(e,e,this.changes)}}class mk extends cx{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function gk(e,t,i,n,r){let s=Math.round((n-t.left)*e.defaultCharacterWidth);if(e.lineWrapping&&i.height>1.5*e.defaultLineHeight){let t=e.viewState.heightOracle.textHeight;s+=Math.floor((r-i.top-.5*(e.defaultLineHeight-t))/t)*e.viewState.heightOracle.lineLength}let a=e.state.sliceDoc(i.from,i.to);return i.from+function(e,t,i){for(let n=0,r=0;;){if(r>=t)return n;if(n==e.length)break;r+=9==e.charCodeAt(n)?i-r%i:1,n=aw(e,n)}return e.length}(a,s,e.state.tabSize)}function Ok(e,t,i){let n=e.lineBlockAt(t);if(Array.isArray(n.type)){let e;for(let r of n.type){if(r.from>t)break;if(!(r.to<t)){if(r.from<t&&r.to>t)return r;e&&(r.type!=hx.Text||e.type==r.type&&!(i<0?r.from<t:r.to>t))||(e=r)}}return e||n}return n}function vk(e,t,i,n){let r=e.state.doc.lineAt(t.head),s=e.bidiSpans(r),a=e.textDirectionAt(r.from);for(let o=t,l=null;;){let t=rS(r,s,a,o,i),c=nS;if(!t){if(r.number==(i?e.state.doc.lines:1))return o;c="\n",r=e.state.doc.line(r.number+(i?1:-1)),s=e.bidiSpans(r),t=e.visualLineSide(r,!i)}if(l){if(!l(c))return o}else{if(!n)return t;l=n(c)}o=t}}function yk(e,t,i){for(;;){let n=0;for(let r of e)r.between(t-1,t+1,(e,r,s)=>{if(t>e&&t<r){let s=n||i||(t-e<r-t?-1:1);t=s<0?e:r,n=s}});if(!n)return t}}function bk(e,t){let i=null;for(let n=0;n<t.ranges.length;n++){let r=t.ranges[n],s=null;if(r.empty){let t=yk(e,r.from,0);t!=r.from&&(s=ww.cursor(t,-1))}else{let t=yk(e,r.from,-1),i=yk(e,r.to,1);t==r.from&&i==r.to||(s=ww.range(r.from==r.anchor?t:i,r.from==r.head?t:i))}s&&(i||(i=t.ranges.slice()),i[n]=s)}return i?ww.create(i,t.mainIndex):t}function wk(e,t,i){let n=yk(e.state.facet(RS).map(t=>t(e)),i.from,t.head>i.from?-1:1);return n==i.from?i:ww.cursor(n,n<i.from?1:-1)}class _k{constructor(e,t){this.pos=e,this.assoc=t}}function xk(e,t,i,n){let r,s=e.contentDOM.getBoundingClientRect(),a=s.top+e.viewState.paddingTop,{x:o,y:l}=t,c=l-a;for(;;){if(c<0)return new _k(0,1);if(c>e.viewState.docHeight)return new _k(e.state.doc.length,-1);if(r=e.elementAtHeight(c),null==n)break;if(r.type==hx.Text){if(n<0?r.to<e.viewport.from:r.from>e.viewport.to)break;let t=e.docView.coordsAt(n<0?r.from:r.to,n>0?-1:1);if(t&&(n<0?t.top<=c+a:t.bottom>=c+a))break}let t=e.viewState.heightOracle.textHeight/2;c=n>0?r.bottom+t:r.top-t}if(e.viewport.from>=r.to||e.viewport.to<=r.from){if(i)return null;if(r.type==hx.Text){let t=gk(e,s,r,o,l);return new _k(t,t==r.from?1:-1)}}if(r.type!=hx.Text)return c<(r.top+r.bottom)/2?new _k(r.from,1):new _k(r.to,-1);let h=e.docView.lineAt(r.from,2);return h&&h.length==r.length||(h=e.docView.lineAt(r.from,-2)),new Sk(e,o,l,e.textDirectionAt(r.from)).scanTile(h,r.from)}class Sk{constructor(e,t,i,n){this.view=e,this.x=t,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Hx.find(n,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:n}=this.bidiSpansAt(e);return n[Hx.find(n,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:n}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from<t)}scan(e,t){let i,n,r,s=0,a=e.length-1,o=new Set,l=this.bidiIn(e[0],e[a]),c=-1,h=1e9;e:for(;s<a;){let u=a-s,d=s+a>>1;t:if(o.has(d)){let e=s+Math.floor(Math.random()*u);for(let t=0;t<u;t++){if(!o.has(e)){d=e;break t}e++,e==a&&(e=s)}break e}o.add(d);let p=t(d);if(p)for(let t=0;t<p.length;t++){let o=p[t],u=0;if(!(0==o.width&&p.length>1)){if(o.bottom<this.y)(!i||i.bottom<o.bottom)&&(i=o),u=1;else if(o.top>this.y)(!n||n.top>o.top)&&(n=o),u=-1;else{let e=o.left>this.x?this.x-o.left:o.right<this.x?this.x-o.right:0,t=Math.abs(e);t<h&&(c=d,h=t,r=o),e&&(u=e<0==(this.baseDir==zx.LTR)?-1:1)}-1!=u||l&&!this.baseDirAt(e[d],1)?1!=u||l&&!this.baseDirAt(e[d+1],-1)||(s=d+1):a=d}}}if(!r){let r=i&&(!n||this.y-i.bottom<n.top-this.y)?i:n;return this.y=(r.top+r.bottom)/2,this.scan(e,t)}if(h){if(i&&i.bottom>r.top)return this.y=i.bottom-1,this.scan(e,t);if(n&&n.top<r.bottom)return this.y=n.top+1,this.scan(e,t)}let u=(l?this.dirAt(e[c],1):this.baseDir)==zx.LTR;return{i:c,after:this.x>(r.left+r.right)/2==u}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=aw(e.text,r))i.push(t+r);i.push(t+e.length);let n=this.scan(i,n=>{let r=i[n]-t,s=i[n+1]-t;return jx(e.dom,r,s).getClientRects()});return n.after?new _k(i[n.i+1],-1):new _k(i[n.i],1)}scanTile(e,t){if(!e.length)return new _k(t,1);if(1==e.children.length){let i=e.children[0];if(i.isText())return this.scanText(i,t);if(i.isComposite())return this.scanTile(i,t)}let i=[t];for(let a=0,o=t;a<e.children.length;a++)i.push(o+=e.children[a].length);let n=this.scan(i,t=>{let i=e.children[t];return 48&i.flags?null:(1==i.dom.nodeType?i.dom:jx(i.dom,0,i.length)).getClientRects()}),r=e.children[n.i],s=i[n.i];return r.isText()?this.scanText(r,s):r.isComposite()?this.scanTile(r,s):n.after?new _k(i[n.i+1],-1):new _k(s,1)}}const kk="";class Pk{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(d_.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=kk}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let e=this.text.length;this.readNode(n);let r=zS.get(n),s=n.nextSibling;if(s==t){(null==r?void 0:r.breakAfter)&&!s&&i!=this.view.contentDOM&&this.lineBreak();break}let a=zS.get(s);(r&&a?r.breakAfter:(r?r.breakAfter:Sx(n))||Sx(s)&&("BR"!=n.nodeName||(null==r?void 0:r.isWidget()))&&this.text.length>e)&&!$k(s,t)&&this.lineBreak(),n=s}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r,s=-1,a=1;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,i),a=this.lineSeparator.length):(r=n.exec(t))&&(s=r.index,a=r[0].length),this.append(t.slice(i,s<0?t.length:s)),s<0)break;if(this.lineBreak(),a>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=a-1);i=s+a}}readNode(e){let t=zS.get(e),i=t&&t.overrideDOMText;if(null!=i){this.findPointInside(e,i.length);for(let e=i.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else 3==e.nodeType?this.readTextNode(e):"BR"==e.nodeName?e.nextSibling&&this.lineBreak():1==e.nodeType&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(3==e.nodeType?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(Tk(e,i.node,i.offset)?t:0))}}function Tk(e,t,i){for(;;){if(!t||i<Px(t))return!1;if(t==e)return!0;i=xx(t)+1,t=t.parentNode}}function $k(e,t){let i;for(;e!=t&&e;e=e.nextSibling){let t=zS.get(e);if(!(null==t?void 0:t.isWidget()))return!1;t&&(i||(i=[])).push(t)}if(i)for(let n of i){let e=n.overrideDOMText;if(null==e?void 0:e.length)return!1}return!0}class Ek{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Ak{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:s}=e.docView,a=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Ck(e.docView.tile,t,i,0))){let t=r||s?[]:function(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:s}=e.observer.selectionRange;i&&(t.push(new Ek(i,n)),r==i&&s==n||t.push(new Ek(r,s)));return t}(e),i=new Pk(t,e);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(e,t){if(0==e.length)return null;let i=e[0].pos,n=2==e.length?e[1].pos:i;return i>-1&&n>-1?ww.single(i+t,n+t):null}(t,this.bounds.from)}else{let t=e.observer.selectionRange,i=r&&r.node==t.focusNode&&r.offset==t.focusOffset||!yx(e.contentDOM,t.focusNode)?a.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),n=s&&s.node==t.anchorNode&&s.offset==t.anchorOffset||!yx(e.contentDOM,t.anchorNode)?a.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),o=e.viewport;if((nx.ios||nx.chrome)&&a.main.empty&&i!=n&&(o.from>0||o.to<e.state.doc.length)){let t=Math.min(i,n),r=Math.max(i,n),s=o.from-t,a=o.to-r;0!=s&&1!=s&&0!=t||0!=a&&-1!=a&&r!=e.state.doc.length||(i=0,n=e.state.doc.length)}if(e.inputState.composing>-1&&a.ranges.length>1)this.newSel=a.replaceRange(ww.range(n,i));else if(e.lineWrapping&&n==i&&(!a.main.empty||a.main.head!=i)&&e.inputState.lastTouchTime>Date.now()-100){let t=e.coordsAtPos(i,-1),n=0;t&&(n=e.inputState.lastTouchY<=t.bottom?-1:1),this.newSel=ww.create([ww.cursor(i,n)])}else this.newSel=ww.single(n,i)}}}function Ck(e,t,i,n){if(e.isComposite()){let r=-1,s=-1,a=-1,o=-1;for(let l=0,c=n,h=n;l<e.children.length;l++){let n=e.children[l],u=c+n.length;if(c<t&&u>i)return Ck(n,t,i,c);if(u>=t&&-1==r&&(r=l,s=c),c>i&&n.dom.parentNode==e.dom){a=l,o=h;break}h=u,c=u+n.breakAfter}return{from:s,to:o<0?n+e.length:o,startDOM:(r?e.children[r-1].dom.nextSibling:null)||e.dom.firstChild,endDOM:a<e.children.length&&a>=0?e.children[a].dom:null}}return e.isText()?{from:n,to:n+e.length,startDOM:e.dom,endDOM:e.dom.nextSibling}:null}function Rk(e,t){let i,{newSel:n}=t,{state:r}=e,s=r.selection.main,a=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:e,to:n}=t.bounds,o=s.from,l=null;(8===a||nx.android&&t.text.length<n-e)&&(o=s.to,l="end");let c,h,u=r.doc.sliceString(e,n,kk);!s.empty&&s.from>=e&&s.to<=n&&(t.typeOver||u!=t.text)&&u.slice(0,s.from-e)==t.text.slice(0,s.from-e)&&u.slice(s.to-e)==t.text.slice(c=t.text.length-(u.length-(s.to-e)))?i={from:s.from,to:s.to,insert:Gb.of(t.text.slice(s.from-e,c).split(kk))}:(h=Ik(u,t.text,o-e,l))&&(nx.chrome&&13==a&&h.toB==h.from+2&&t.text.slice(h.from,h.toB)==kk+kk&&h.toB--,i={from:e+h.from,to:e+h.toA,insert:Gb.of(t.text.slice(h.from,h.toB).split(kk))})}else n&&(!e.hasFocus&&r.facet(_S)||jk(n,s))&&(n=null);if(!i&&!n)return!1;if((nx.mac||nx.android)&&i&&i.from==i.to&&i.from==s.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=ww.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:Gb.of([i.insert.toString().replace("."," ")])}):r.doc.lineAt(s.from).to<s.to&&e.docView.lineHasWidget(s.to)&&e.inputState.insertingTextAt>Date.now()-50?i={from:s.from,to:s.to,insert:r.toText(e.inputState.insertingText)}:nx.chrome&&i&&i.from==i.to&&i.from==s.head&&"\n "==i.insert.toString()&&e.lineWrapping&&(n&&(n=ww.single(n.main.anchor-1,n.main.head-1)),i={from:s.from,to:s.to,insert:Gb.of([" "])}),i)return Qk(e,i,n,a);if(n&&!jk(n,s)){let t=!1,i="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),i=e.inputState.lastSelectionOrigin,"select.pointer"==i&&(n=bk(r.facet(RS).map(t=>t(e)),n))),e.dispatch({selection:n,scrollIntoView:t,userEvent:i}),!0}return!1}function Qk(e,t,i,n=-1){if(nx.ios&&e.inputState.flushIOSKey(t))return!0;let r=e.state.selection.main;if(nx.android&&(t.to==r.to&&(t.from==r.from||t.from==r.from-1&&" "==e.state.sliceDoc(t.from,r.from))&&1==t.insert.length&&2==t.insert.lines&&Mx(e.contentDOM,"Enter",13)||(t.from==r.from-1&&t.to==r.to&&0==t.insert.length||8==n&&t.insert.length<t.to-t.from&&t.to>r.head)&&Mx(e.contentDOM,"Backspace",8)||t.from==r.from&&t.to==r.to+1&&0==t.insert.length&&Mx(e.contentDOM,"Delete",46)))return!0;let s,a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o=()=>s||(s=function(e,t,i){let n,r=e.state,s=r.selection.main,a=-1;if(t.from==t.to&&t.from<s.from||t.from>s.to){let i=t.from<s.from?-1:1,n=i<0?s.from:s.to,o=yk(r.facet(RS).map(t=>t(e)),n,i);t.from==o&&(a=o)}if(a>-1)n={changes:t,selection:ww.cursor(t.from+t.insert.length,-1)};else if(t.from>=s.from&&t.to<=s.to&&t.to-t.from>=(s.to-s.from)/3&&(!i||i.main.empty&&i.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let i=s.from<t.from?r.sliceDoc(s.from,t.from):"",a=s.to>t.to?r.sliceDoc(t.to,s.to):"";n=r.replaceSelection(e.state.toText(i+t.insert.sliceString(0,void 0,e.state.lineBreak)+a))}else{let a=r.changes(t),o=i&&i.main.to<=a.newLength?i.main:void 0;if(r.selection.ranges.length>1&&(e.inputState.composing>=0||e.inputState.compositionPendingChange)&&t.to<=s.to+10&&t.to>=s.to-10){let l,c=e.state.sliceDoc(t.from,t.to),h=i&&dk(e,i.main.head);if(h){let e=t.insert.length-(t.to-t.from);l={from:h.from,to:h.to-e}}else l=e.state.doc.lineAt(s.head);let u=s.to-t.to;n=r.changeByRange(i=>{if(i.from==s.from&&i.to==s.to)return{changes:a,range:o||i.map(a)};let n=i.to-u,h=n-c.length;if(e.state.sliceDoc(h,n)!=c||n>=l.from&&h<=l.to)return{range:i};let d=r.changes({from:h,to:n,insert:t.insert}),p=i.to-s.to;return{changes:d,range:o?ww.range(Math.max(0,o.anchor+p),Math.max(0,o.head+p)):i.map(d)}})}else n={changes:a,selection:o&&r.selection.replaceRange(o)}}let o="input.type";(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,o+=".compose",e.inputState.compositionFirstChange&&(o+=".start",e.inputState.compositionFirstChange=!1));return r.update(n,{userEvent:o,scrollIntoView:!0})}(e,t,i));return e.state.facet(uS).some(i=>i(e,t.from,t.to,a,o))||e.dispatch(o()),!0}function Ik(e,t,i,n){let r=Math.min(e.length,t.length),s=0;for(;s<r&&e.charCodeAt(s)==t.charCodeAt(s);)s++;if(s==r&&e.length==t.length)return null;let a=e.length,o=t.length;for(;a>0&&o>0&&e.charCodeAt(a-1)==t.charCodeAt(o-1);)a--,o--;if("end"==n){i-=a+Math.max(0,s-Math.min(a,o))-s}if(a<s&&e.length<t.length){s-=i<=s&&i>=a?s-i:0,o=s+(o-a),a=s}else if(o<s){s-=i<=s&&i>=o?s-i:0,a=s+(a-o),o=s}return{from:s,toA:a,toB:o}}function jk(e,t){return t.head==e.main.head&&t.anchor==e.main.anchor}class Mk{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){var t;this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,nx.safari&&e.contentDOM.addEventListener("input",()=>null),nx.gecko&&(t=e.contentDOM.ownerDocument,sP.has(t)||(sP.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{})))}handleEvent(e){(function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let i,n=t.target;n!=e.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=zS.get(n))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0})(this.view,e)&&!this.ignoreDuringComposition(e)&&("keydown"==e.type&&this.keydown(e)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e)))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let e of i.observers)e(this.view,t);for(let e of i.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=function(e){let t=Object.create(null);function i(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let n of e){let e=n.spec,t=e&&e.plugin.domEventHandlers,r=e&&e.plugin.domEventObservers;if(t)for(let s in t){let e=t[s];e&&i(s).handlers.push(Nk(n.value,e))}if(r)for(let s in r){let e=r[s];e&&i(s).observers.push(Nk(n.value,e))}}for(let n in qk)i(n).handlers.push(qk[n]);for(let n in Xk)i(n).observers.push(Xk[n]);return t}(e),i=this.handlers,n=this.view.contentDOM;for(let r in t)if("scroll"!=r){let e=!t[r].handlers.length,s=i[r];s&&e!=!s.handlers.length&&(n.removeEventListener(r,this.handleEvent),s=null),s||n.addEventListener(r,this.handleEvent,{passive:e})}for(let r in i)"scroll"==r||t[r]||n.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=e.keyCode&&Dk.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),nx.android&&nx.chrome&&!e.synthetic&&(13==e.keyCode||8==e.keyCode))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return!nx.ios||e.synthetic||e.altKey||e.metaKey||e.shiftKey||!((t=Lk.find(t=>t.keyCode==e.keyCode))&&!e.ctrlKey||Zk.indexOf(e.key)>-1&&e.ctrlKey)?(229!=e.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(e){let t=this.pendingIOSKey;return!!t&&(!("Enter"==t.key&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString()))&&(this.pendingIOSKey=void 0,Mx(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0)))}ignoreDuringComposition(e){return!(!/^key/.test(e.type)||e.synthetic)&&(this.composing>0||!!(nx.safari&&!nx.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Nk(e,t){return(i,n)=>{try{return t.call(e,n,i)}catch(r){wS(i.state,r)}}}const Lk=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Zk="dthko",Dk=[16,17,18,20,91,92,224,225];function zk(e){return.7*Math.max(0,e)+8}class Uk{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Ax(e.contentDOM),this.atoms=e.state.facet(RS).map(t=>t(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(d_.allowMultipleSelections)&&function(e,t){let i=e.state.facet(aS);return i.length?i[0](t):nx.mac?t.metaKey:t.ctrlKey}(e,t),this.dragging=!(!function(e,t){let{main:i}=e.state.selection;if(i.empty)return!1;let n=vx(e.root);if(!n||0==n.rangeCount)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s<r.length;s++){let e=r[s];if(e.left<=t.clientX&&e.right>=t.clientX&&e.top<=t.clientY&&e.bottom>=t.clientY)return!0}return!1}(e,t)||1!=Jk(t))&&null}start(e){!1===this.dragging&&this.select(e)}move(e){if(0==e.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(t=this.startEvent,i=e,Math.max(Math.abs(t.clientX-i.clientX),Math.abs(t.clientY-i.clientY))<10))return;var t,i;this.select(this.lastEvent=e);let n=0,r=0,s=0,a=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:a,bottom:l}=this.scrollParents.y.getBoundingClientRect());let c=MS(this.view);e.clientX-c.left<=s+6?n=-zk(s-e.clientX):e.clientX+c.right>=o-6&&(n=zk(e.clientX-o)),e.clientY-c.top<=a+6?r=-zk(a-e.clientY):e.clientY+c.bottom>=l-6&&(r=zk(e.clientY-l)),this.setScrollSpeed(n,r)}up(e){null==this.dragging&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),!1===this.dragging&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=bk(this.atoms,this.style.get(e,this.extend,this.multiple));!this.mustSelect&&i.eq(t.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}const qk=Object.create(null),Xk=Object.create(null),Bk=nx.ie&&nx.ie_version<15||nx.ios&&nx.webkit_version<604;function Wk(e,t,i){for(let n of e.facet(t))i=n(i,e);return i}function Vk(e,t){t=Wk(e.state,pS,t);let i,{state:n}=e,r=1,s=n.toText(t),a=s.lines==n.selection.ranges.length;if(null!=tP&&n.selection.ranges.every(e=>e.empty)&&tP==s.toString()){let e=-1;i=n.changeByRange(i=>{let o=n.doc.lineAt(i.from);if(o.from==e)return{range:i};e=o.from;let l=n.toText((a?s.line(r++).text:t)+n.lineBreak);return{changes:{from:o.from,insert:l},range:ww.cursor(i.from+l.length)}})}else i=a?n.changeByRange(e=>{let t=s.line(r++);return{changes:{from:e.from,to:e.to,insert:t.text},range:ww.cursor(e.from+t.length)}}):n.replaceSelection(s);e.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function Fk(e,t,i,n){if(1==n)return ww.cursor(t,i);if(2==n)return function(e,t,i=1){let n=e.charCategorizer(t),r=e.doc.lineAt(t),s=t-r.from;if(0==r.length)return ww.cursor(t);0==s?i=1:s==r.length&&(i=-1);let a=s,o=s;i<0?a=aw(r.text,s,!1):o=aw(r.text,s);let l=n(r.text.slice(a,o));for(;a>0;){let e=aw(r.text,a,!1);if(n(r.text.slice(e,a))!=l)break;a=e}for(;o<r.length;){let e=aw(r.text,o);if(n(r.text.slice(o,e))!=l)break;o=e}return ww.range(a+r.from,o+r.from)}(e.state,t,i);{let n=e.docView.lineAt(t,i),r=e.state.doc.lineAt(n?n.posAtEnd:t),s=n?n.posAtStart:r.from,a=n?n.posAtEnd:r.to;return a<e.state.doc.length&&a==r.to&&a++,ww.range(s,a)}}Xk.scroll=e=>{e.inputState.lastScrollTop=e.scrollDOM.scrollTop,e.inputState.lastScrollLeft=e.scrollDOM.scrollLeft},Xk.wheel=Xk.mousewheel=e=>{e.inputState.lastWheelEvent=Date.now()},qk.keydown=(e,t)=>(e.inputState.setSelectionOrigin("select"),27==t.keyCode&&0!=e.inputState.tabFocusMode&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),Xk.touchstart=(e,t)=>{let i=e.inputState,n=t.targetTouches[0];i.lastTouchTime=Date.now(),n&&(i.lastTouchX=n.clientX,i.lastTouchY=n.clientY),i.setSelectionOrigin("select.pointer")},Xk.touchmove=e=>{e.inputState.setSelectionOrigin("select.pointer")},qk.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of e.state.facet(lS))if(i=n(e,t),i)break;if(i||0!=t.button||(i=function(e,t){let i=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),n=Jk(t),r=e.state.selection;return{update(e){e.docChanged&&(i.pos=e.changes.mapPos(i.pos),r=r.map(e.changes))},get(t,s,a){let o,l=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),c=Fk(e,l.pos,l.assoc,n);if(i.pos!=l.pos&&!s){let t=Fk(e,i.pos,i.assoc,n),r=Math.min(t.from,c.from),s=Math.max(t.to,c.to);c=r<c.from?ww.range(r,s,c.assoc):ww.range(s,r,c.assoc)}return s?r.replaceRange(r.main.extend(c.from,c.to,c.assoc)):a&&1==n&&r.ranges.length>1&&(o=function(e,t){for(let i=0;i<e.ranges.length;i++){let{from:n,to:r}=e.ranges[i];if(n<=t&&r>=t)return ww.create(e.ranges.slice(0,i).concat(e.ranges.slice(i+1)),e.mainIndex==i?0:e.mainIndex-(e.mainIndex>i?1:0))}return null}(r,l.pos))?o:a?r.addRange(c):ww.create([c])}}}(e,t)),i){let n=!e.hasFocus;e.inputState.startMouseSelection(new Uk(e,t,i,n)),n&&e.observer.ignore(()=>{Ix(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()});let r=e.inputState.mouseSelection;if(r)return r.start(t),!1===r.dragging}else e.inputState.setSelectionOrigin("select.pointer");return!1};const Yk=nx.ie&&nx.ie_version<=11;let Gk=null,Hk=0,Kk=0;function Jk(e){if(!Yk)return e.detail;let t=Gk,i=Kk;return Gk=e,Kk=Date.now(),Hk=!t||i>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(Hk+1)%3:1}function eP(e,t,i,n){if(!(i=Wk(e.state,pS,i)))return;let r=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:s}=e.inputState,a=n&&s&&function(e,t){let i=e.state.facet(oS);return i.length?i[0](t):nx.mac?!t.altKey:!t.ctrlKey}(e,t)?{from:s.from,to:s.to}:null,o={from:r,insert:i},l=e.state.changes(a?[a,o]:o);e.focus(),e.dispatch({changes:l,selection:{anchor:l.mapPos(r,-1),head:l.mapPos(r,1)},userEvent:a?"move.drop":"input.drop"}),e.inputState.draggedContent=null}qk.dragstart=(e,t)=>{let{selection:{main:i}}=e.state;if(t.target.draggable){let n=e.docView.tile.nearest(t.target);if(n&&n.isWidget()){let e=n.posAtStart,t=e+n.length;(e>=i.to||t<=i.from)&&(i=ww.range(e,t))}}let{inputState:n}=e;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,t.dataTransfer&&(t.dataTransfer.setData("Text",Wk(e.state,fS,e.state.sliceDoc(i.from,i.to))),t.dataTransfer.effectAllowed="copyMove"),!1},qk.dragend=e=>(e.inputState.draggedContent=null,!1),qk.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let i=t.dataTransfer.files;if(i&&i.length){let n=Array(i.length),r=0,s=()=>{++r==i.length&&eP(e,t,n.filter(e=>null!=e).join(e.state.lineBreak),!1)};for(let e=0;e<i.length;e++){let t=new FileReader;t.onerror=s,t.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(n[e]=t.result),s()},t.readAsText(i[e])}return!0}{let i=t.dataTransfer.getData("Text");if(i)return eP(e,t,i,!0),!0}return!1},qk.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let i=Bk?null:t.clipboardData;return i?(Vk(e,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(e){let t=e.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{e.focus(),i.remove(),Vk(e,i.value)},50)}(e),!1)};let tP=null;qk.copy=qk.cut=(e,t)=>{if(!bx(e.contentDOM,e.observer.selectionRange))return!1;let{text:i,ranges:n,linewise:r}=function(e){let t=[],i=[],n=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),i.push(r));if(!t.length){let r=-1;for(let{from:n}of e.selection.ranges){let s=e.doc.lineAt(n);s.number>r&&(t.push(s.text),i.push({from:s.from,to:Math.min(e.doc.length,s.to+1)})),r=s.number}n=!0}return{text:Wk(e,fS,t.join(e.lineBreak)),ranges:i,linewise:n}}(e.state);if(!i&&!r)return!1;tP=r?i:null,"cut"!=t.type||e.state.readOnly||e.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=Bk?null:t.clipboardData;return s?(s.clearData(),s.setData("text/plain",i),!0):(function(e,t){let i=e.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=t,n.focus(),n.selectionEnd=t.length,n.selectionStart=0,setTimeout(()=>{n.remove(),e.focus()},50)}(e,i),!1)};const iP=Hw.define();function nP(e,t){let i=[];for(let n of e.facet(dS)){let r=n(e,t);r&&i.push(r)}return i.length?e.update({effects:i,annotations:iP.of(!0)}):null}function rP(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let i=nP(e.state,t);i?e.dispatch(i):e.update([])}},10)}Xk.focus=e=>{e.inputState.lastFocusTime=Date.now(),e.scrollDOM.scrollTop||!e.inputState.lastScrollTop&&!e.inputState.lastScrollLeft||(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),rP(e)},Xk.blur=e=>{e.observer.clearSelectionRange(),rP(e)},Xk.compositionstart=Xk.compositionupdate=e=>{e.observer.editContext||(null==e.inputState.compositionFirstChange&&(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},Xk.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,nx.chrome&&nx.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then(()=>e.observer.flush()):setTimeout(()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])},50))},Xk.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},qk.beforeinput=(e,t)=>{var i,n;if("insertText"!=t.inputType&&"insertCompositionText"!=t.inputType||(e.inputState.insertingText=t.data,e.inputState.insertingTextAt=Date.now()),"insertReplacementText"==t.inputType&&e.observer.editContext){let n=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),r=t.getTargetRanges();if(n&&r.length){let t=r[0],i=e.posAtDOM(t.startContainer,t.startOffset),s=e.posAtDOM(t.endContainer,t.endOffset);return Qk(e,{from:i,to:s,insert:e.state.toText(n)},null),!0}}let r;if(nx.chrome&&nx.android&&(r=Lk.find(e=>e.inputType==t.inputType))&&(e.observer.delayAndroidKey(r.key,r.keyCode),"Backspace"==r.key||"Delete"==r.key)){let t=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())},100)}return nx.ios&&"deleteContentForward"==t.inputType&&e.observer.flushSoon(),nx.safari&&"insertText"==t.inputType&&e.inputState.composing>=0&&setTimeout(()=>Xk.compositionend(e,t),20),!1};const sP=new Set;const aP=["pre-wrap","normal","pre-line","break-spaces"];let oP=!1;function lP(){oP=!1}class cP{constructor(e){this.lineWrapping=e,this.doc=Gb.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return aP.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(10*n)]||(t=!0,this.heightSamples[Math.floor(10*n)]=!0)}return t}refresh(e,t,i,n,r,s){let a=aP.indexOf(e)>-1,o=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=a||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=a,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,o){this.heightSamples={};for(let e=0;e<s.length;e++){let t=s[e];t<0?e++:this.heightSamples[Math.floor(10*t)]=!0}}return o}}class hP{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class uP{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return"number"==typeof this._content?hx.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof fx?this._content.widget:null}get widgetLineBreaks(){return"number"==typeof this._content?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new uP(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var dP=function(e){return e[e.ByPos=0]="ByPos",e[e.ByHeight=1]="ByHeight",e[e.ByPosNoHeight=2]="ByPosNoHeight",e}(dP||(dP={}));const pP=.001;class fP{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(2&this.flags)>0}set outdated(e){this.flags=(e?2:0)|-3&this.flags}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>pP&&(oP=!0),this.height=e)}replace(e,t,i){return fP.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let r=this,s=i.doc;for(let a=n.length-1;a>=0;a--){let{fromA:o,toA:l,fromB:c,toB:h}=n[a],u=r.lineAt(o,dP.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=l?u:r.lineAt(l,dP.ByPosNoHeight,i,0,0);for(h+=d.to-l,l=d.to;a>0&&u.from<=n[a-1].toA;)o=n[a-1].fromA,c=n[a-1].fromB,a--,o<u.from&&(u=r.lineAt(o,dP.ByPosNoHeight,i,0,0));c+=u.from-o,o=u.from;let p=_P.build(i.setDoc(s),e,c,h);r=mP(r,r.replace(o,l,p))}return r.updateHeight(i,0)}static empty(){return new vP(0,0,0)}static of(e){if(1==e.length)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>2*r){let r=e[t-1];r.break?e.splice(--t,1,r.left,null,r.right):e.splice(--t,1,r.left,r.right),i+=1+r.break,n-=r.size}else{if(!(r>2*n))break;{let t=e[i];t.break?e.splice(i,1,t.left,null,t.right):e.splice(i,1,t.left,t.right),i+=2+t.break,r-=t.size}}else if(n<r){let i=e[t++];i&&(n+=i.size)}else{let t=e[--i];t&&(r+=t.size)}let s=0;return null==e[t-1]?(s=1,t--):null==e[t]&&(s=1,i++),new bP(fP.of(e.slice(0,t)),s,fP.of(e.slice(i)))}}function mP(e,t){return e==t?e:(e.constructor!=t.constructor&&(oP=!0),t)}fP.prototype.size=1;const gP=ux.replace({});class OP extends fP{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new uP(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,n){return this.spaceAbove&&e<i+this.spaceAbove?new uP(n,0,i,this.spaceAbove,gP):this.mainBlock(i,n)}lineAt(e,t,i,n,r){let s=this.mainBlock(n,r);return this.spaceAbove?this.blockAt(0,i,n,r).join(s):s}forEachLine(e,t,i,n,r,s){e<=r+this.length&&t>=r&&s(this.lineAt(0,dP.ByPos,i,n,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class vP extends OP{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new uP(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let n=i[0];return 1==i.length&&(n instanceof vP||n instanceof yP&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof yP?n=new vP(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):fP.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class yP extends fP{constructor(e){super(e,0)}heightMetrics(e,t){let i,n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,a=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*s);i=t/s,this.length>s+1&&(a=(this.height-t)/(this.length-s-1))}else i=this.height/s;return{firstLine:n,lastLine:r,perLine:i,perChar:a}}blockAt(e,t,i,n){let{firstLine:r,lastLine:s,perLine:a,perChar:o}=this.heightMetrics(t,n);if(t.lineWrapping){let r=n+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),s=t.doc.lineAt(r),l=a+s.length*o,c=Math.max(i,e-l/2);return new uP(s.from,s.length,c,l,0)}{let n=Math.max(0,Math.min(s-r,Math.floor((e-i)/a))),{from:o,length:l}=t.doc.line(r+n);return new uP(o,l,i+a*n,a,0)}}lineAt(e,t,i,n,r){if(t==dP.ByHeight)return this.blockAt(e,i,n,r);if(t==dP.ByPosNoHeight){let{from:t,to:n}=i.doc.lineAt(e);return new uP(t,n-t,0,0,0)}let{firstLine:s,perLine:a,perChar:o}=this.heightMetrics(i,r),l=i.doc.lineAt(e),c=a+l.length*o,h=l.number-s,u=n+a*h+o*(l.from-r-h);return new uP(l.from,l.length,Math.max(n,Math.min(u,n+this.height-c)),c,0)}forEachLine(e,t,i,n,r,s){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:a,perLine:o,perChar:l}=this.heightMetrics(i,r);for(let c=e,h=n;c<=t;){let t=i.doc.lineAt(c);if(c==e){let i=t.number-a;h+=o*i+l*(e-r-i)}let n=o+l*t.length;s(new uP(t.from,t.length,h,n,0)),h+=n,c=t.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let e=i[i.length-1];e instanceof yP?i[i.length-1]=new yP(e.length+n):i.push(null,new yP(n-1))}if(e>0){let t=i[0];t instanceof yP?i[0]=new yP(e+t.length):i.unshift(new yP(e-1),null)}return fP.of(i)}decomposeLeft(e,t){t.push(new yP(e-1),null)}decomposeRight(e,t){t.push(null,new yP(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let r=t+this.length;if(n&&n.from<=t+this.length&&n.more){let i=[],s=Math.max(t,n.from),a=-1;for(n.from>t&&i.push(new yP(n.from-t-1).updateHeight(e,t));s<=r&&n.more;){let t=e.doc.lineAt(s).length;i.length&&i.push(null);let r=n.heights[n.index++],o=0;r<0&&(o=-r,r=n.heights[n.index++]),-1==a?a=r:Math.abs(r-a)>=pP&&(a=-2);let l=new vP(t,r,o);l.outdated=!1,i.push(l),s+=t+1}s<=r&&i.push(null,new yP(r-s).updateHeight(e,s));let o=fP.of(i);return(a<0||Math.abs(o.height-this.height)>=pP||Math.abs(a-this.heightMetrics(e,t).perLine)>=pP)&&(oP=!0),mP(this,o)}return(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class bP extends fP{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return 1&this.flags}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let s=n+this.left.height,a=r+this.left.length+this.break,o=t==dP.ByHeight?e<s:e<a,l=o?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,s,a);if(this.break||(o?l.to<a:l.from>a))return l;let c=t==dP.ByPosNoHeight?dP.ByPosNoHeight:dP.ByPos;return o?l.join(this.right.lineAt(a,c,i,s,a)):this.left.lineAt(a,c,i,n,r).join(l)}forEachLine(e,t,i,n,r,s){let a=n+this.left.height,o=r+this.left.length+this.break;if(this.break)e<o&&this.left.forEachLine(e,t,i,n,r,s),t>=o&&this.right.forEachLine(e,t,i,a,o,s);else{let l=this.lineAt(o,dP.ByPos,i,n,r);e<l.from&&this.left.forEachLine(e,l.from-1,i,n,r,s),l.to>=e&&l.from<=t&&s(l),t>l.to&&this.right.forEachLine(l.to+1,t,i,a,o,s)}}replace(e,t,i){let n=this.left.length+this.break;if(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let s=r.length;for(let a of i)r.push(a);if(e>0&&wP(r,s-1),t<this.length){let e=r.length;this.decomposeRight(t,r),wP(r,e)}return fP.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?fP.of(this.break?[e,null,t]:[e,t]):(this.left=mP(this.left,e),this.right=mP(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:r,right:s}=this,a=t+r.length+this.break,o=null;return n&&n.from<=t+r.length&&n.more?o=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=a+s.length&&n.more?o=s=s.updateHeight(e,a,i,n):s.updateHeight(e,a,i),o?this.balanced(r,s):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function wP(e,t){let i,n;null==e[t]&&(i=e[t-1])instanceof yP&&(n=e[t+1])instanceof yP&&e.splice(t-1,3,new yP(i.length+1+n.length))}class _P{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof vP?i.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new vP(e-this.pos,-1,0)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let s=t-e;i.block?this.addBlock(new OP(s,n,i)):(s||r||n>=5)&&this.addLineDeco(n,r,s)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||null==this.nodes[this.nodes.length-1])&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new vP(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new yP(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof vP)return e;let t=new vP(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||t instanceof vP||this.isCovered?(this.writtenTo<this.pos||null==t)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos)):this.nodes.push(new vP(0,-1,0));let i=e;for(let n of this.nodes)n instanceof vP&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new _P(i,e);return y_.spans(t,i,n,r,0),r.finish(i)}}class xP{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&gx(e,t,this.changes,5)}}function SP(e,t){let i=e.getBoundingClientRect(),n=e.ownerDocument,r=n.defaultView||window,s=Math.max(0,i.left),a=Math.min(r.innerWidth,i.right),o=Math.max(0,i.top),l=Math.min(r.innerHeight,i.bottom);for(let c=e.parentNode;c&&c!=n.body;)if(1==c.nodeType){let t=c,i=window.getComputedStyle(t);if((t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&"visible"!=i.overflow){let i=t.getBoundingClientRect();s=Math.max(s,i.left),a=Math.min(a,i.right),o=Math.max(o,i.top),l=Math.min(c==e.parentNode?r.innerHeight:l,i.bottom)}c="absolute"==i.position||"fixed"==i.position?t.offsetParent:t.parentNode}else{if(11!=c.nodeType)break;c=c.host}return{left:s-i.left,right:Math.max(s,a)-i.left,top:o-(i.top+t),bottom:Math.max(o,l)-(i.top+t)}}function kP(e,t){let i=e.getBoundingClientRect();return{left:0,right:i.right-i.left,top:t,bottom:i.bottom-(i.top+t)}}class PP{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return ux.replace({widget:new TP(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class TP extends cx{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class $P{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=RP,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=zx.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet($S).some(e=>"function"!=typeof e&&"cm-lineWrapping"==e.class);this.heightOracle=new cP(i),this.stateDeco=QP(t),this.heightMap=fP.empty().applyChanges(this.stateDeco,Gb.empty,this.heightOracle.setDoc(t.doc),[new LS(0,0,0,t.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ux.set(this.lineGaps.map(e=>e.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:e,to:t})=>n>=e&&n<=t)){let{from:t,to:i}=this.lineBlockAt(n);e.push(new EP(t,i))}}return this.viewports=e.sort((e,t)=>e.from-t.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?RP:new IP(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(jP(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=QP(this.state);let n=e.changedRanges,r=LS.extendWithRanges(n,function(e,t,i){let n=new xP;return y_.compare(e,t,i,n,0),n.changes}(i,this.stateDeco,e?e.changes:pw.empty(this.state.doc.length))),s=this.heightMap.height,a=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);lP(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=s||oP)&&(e.flags|=2),a?(this.scrollAnchorPos=e.changes.mapPos(a.from,-1),this.scrollAnchorHeight=a.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=s);let o=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<o.from||t.range.head>o.to)||!this.viewportIsAppropriate(o))&&(o=this.getViewport(0,t));let l=o.from!=this.viewport.from||o.to!=this.viewport.to;this.viewport=o,e.flags|=this.updateForViewport(),(l||!e.changes.empty||2&e.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(gS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?zx.RTL:zx.LTR;let s=this.heightOracle.mustRefreshForWrapping(r)||"refresh"===this.mustMeasureContent,a=t.getBoundingClientRect(),o=s||this.mustMeasureContent||this.contentDOMHeight!=a.height;this.contentDOMHeight=a.height,this.mustMeasureContent=!1;let l=0,c=0;if(a.width&&a.height){let{scaleX:e,scaleY:i}=Ex(t,a);(e>.005&&Math.abs(this.scaleX-e)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=e,this.scaleY=i,l|=16,s=o=!0)}let h=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==h&&this.paddingBottom==u||(this.paddingTop=h,this.paddingBottom=u,l|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(o=!0),this.editorWidth=e.scrollDOM.clientWidth,l|=16);let d=Ax(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Nx(this.scrollParent||e.win);let f=(this.printing?kP:SP)(t,this.paddingTop),m=f.top-this.pixelViewport.top,g=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let O=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(O!=this.inView&&(this.inView=O,O&&(o=!0)),!this.inView&&!this.scrollTarget&&!function(e){let t=e.getBoundingClientRect(),i=e.ownerDocument.defaultView||window;return t.left<i.innerWidth&&t.right>0&&t.top<i.innerHeight&&t.bottom>0}(e.dom))return 0;let v=a.width;if(this.contentDOMWidth==v&&this.editorHeight==e.scrollDOM.clientHeight||(this.contentDOMWidth=a.width,this.editorHeight=e.scrollDOM.clientHeight,l|=16),o){let t=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(t)&&(s=!0),s||n.lineWrapping&&Math.abs(v-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:a,textHeight:o}=e.docView.measureTextSize();s=i>0&&n.refresh(r,i,a,o,Math.max(5,v/a),t),s&&(e.docView.minWidth=0,l|=16)}m>0&&g>0?c=Math.max(m,g):m<0&&g<0&&(c=Math.min(m,g)),lP();for(let i of this.viewports){let r=i.from==this.viewport.from?t:e.docView.measureVisibleLineHeights(i);this.heightMap=(s?fP.empty().applyChanges(this.stateDeco,Gb.empty,this.heightOracle,[new LS(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,s,new hP(i.from,r))}oP&&(l|=2)}let y=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return y&&(2&l&&(l|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),l|=this.updateForViewport()),(2&l||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(s?[]:this.lineGaps,e)),l|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),l}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:s,visibleBottom:a}=this,o=new EP(n.lineAt(s-1e3*i,dP.ByHeight,r,0,0).from,n.lineAt(a+1e3*(1-i),dP.ByHeight,r,0,0).to);if(t){let{head:e}=t.range;if(e<o.from||e>o.to){let i,s=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),a=n.lineAt(e,dP.ByPos,r,0,0);i="center"==t.y?(a.top+a.bottom)/2-s/2:"start"==t.y||"nearest"==t.y&&e<o.from?a.top:a.bottom-s,o=new EP(n.lineAt(i-500,dP.ByHeight,r,0,0).from,n.lineAt(i+s+500,dP.ByHeight,r,0,0).to)}}return o}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new EP(this.heightMap.lineAt(i,dP.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,dP.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,dP.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,dP.ByPos,this.heightOracle,0,0),{visibleTop:s,visibleBottom:a}=this;return(0==e||n<=s-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=a+Math.max(10,Math.min(i,250)))&&n>s-2e3&&r<a+2e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new PP(t.mapPos(n.from),t.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,s=n<<1;if(this.defaultTextDirection!=zx.LTR&&!i)return[];let a=[],o=(n,s,l,c)=>{if(s-n<r)return;let h=this.state.selection.main,u=[h.from];h.empty||u.push(h.to);for(let e of u)if(e>n&&e<s)return o(n,e-10,l,c),void o(e+10,s,l,c);let d=function(e,t){for(let i of e)if(t(i))return i;return}(e,e=>e.from>=l.from&&e.to<=l.to&&Math.abs(e.from-n)<r&&Math.abs(e.to-s)<r&&!u.some(t=>e.from<t&&e.to>t));if(!d){if(s<l.to&&t&&i&&t.visibleRanges.some(e=>e.from<=s&&e.to>=s)){let e=t.moveToLineBoundary(ww.cursor(s),!1,!0).head;e>n&&(s=e)}let e=this.gapSize(l,n,s,c);d=new PP(n,s,e,i||e<2e6?e:2e6)}a.push(d)},l=t=>{if(t.length<s||t.type!=hx.Text)return;let r=function(e,t,i){let n=[],r=e,s=0;y_.spans(i,e,t,{span(){},point(e,t){e>r&&(n.push({from:r,to:e}),s+=e-r),r=t}},20),r<t&&(n.push({from:r,to:t}),s+=t-r);return{total:s,ranges:n}}(t.from,t.to,this.stateDeco);if(r.total<s)return;let a,l,c=this.scrollTarget?this.scrollTarget.range.head:null;if(i){let e,i,s=n/this.heightOracle.lineLength*this.heightOracle.lineHeight;if(null!=c){let n=CP(r,c),a=((this.visibleBottom-this.visibleTop)/2+s)/t.height;e=n-a,i=n+a}else e=(this.visibleTop-t.top-s)/t.height,i=(this.visibleBottom-t.top+s)/t.height;a=AP(r,e),l=AP(r,i)}else{let i=r.total*this.heightOracle.charWidth,s=n*this.heightOracle.charWidth,o=0;if(i>2e6)for(let n of e)n.from>=t.from&&n.from<t.to&&n.size!=n.displaySize&&n.from*this.heightOracle.charWidth+o<this.pixelViewport.left&&(o=n.size-n.displaySize);let h,u,d=this.pixelViewport.left+o,p=this.pixelViewport.right+o;if(null!=c){let e=CP(r,c),t=((p-d)/2+s)/i;h=e-t,u=e+t}else h=(d-s)/i,u=(p+s)/i;a=AP(r,h),l=AP(r,u)}a>t.from&&o(t.from,a,t,r),l<t.to&&o(l,t.to,t,r)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(l):l(c);return a}gapSize(e,t,i,n){let r=CP(n,i)-CP(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){PP.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=ux.set(e.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];y_.spans(t,this.viewport.from,this.viewport.to,{span(e,t){i.push({from:e,to:t})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let r=0;r<i.length&&!(8&n);r++){let t=this.visibleRanges[r],s=i[r];t.from==s.from&&t.to==s.to||(n|=4,e&&e.mapPos(t.from,-1)==s.from&&e.mapPos(t.to,1)==s.to||(n|=8))}return this.visibleRanges=i,n}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||jP(this.heightMap.lineAt(e,dP.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||jP(this.heightMap.lineAt(this.scaler.fromDOM(e),dP.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return jP(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class EP{constructor(e,t){this.from=e,this.to=t}}function AP({total:e,ranges:t},i){if(i<=0)return t[0].from;if(i>=1)return t[t.length-1].to;let n=Math.floor(e*i);for(let r=0;;r++){let{from:e,to:i}=t[r],s=i-e;if(n<=s)return e+n;n-=s}}function CP(e,t){let i=0;for(let{from:n,to:r}of e.ranges){if(t<=r){i+=t-n;break}i+=r-n}return i/e.total}const RP={toDOM:e=>e,fromDOM:e=>e,scale:1,eq(e){return e==this}};function QP(e){let t=e.facet(ES).filter(e=>"function"!=typeof e),i=e.facet(CS).filter(e=>"function"!=typeof e);return i.length&&t.push(y_.join(i)),t}class IP{constructor(e,t,i){let n=0,r=0,s=0;this.viewports=i.map(({from:i,to:r})=>{let s=t.lineAt(i,dP.ByPos,e,0,0).top,a=t.lineAt(r,dP.ByPos,e,0,0).bottom;return n+=a-s,{from:i,to:r,top:s,bottom:a,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let a of this.viewports)a.domTop=s+(a.top-r)*this.scale,s=a.domBottom=a.domTop+(a.bottom-a.top),r=a.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}eq(e){return e instanceof IP&&(this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to))}}function jP(e,t){if(1==t.scale)return e;let i=t.toDOM(e.top),n=t.toDOM(e.bottom);return new uP(e.from,e.length,i,n-i,Array.isArray(e._content)?e._content.map(e=>jP(e,t)):e._content)}const MP=Sw.define({combine:e=>e.join(" ")}),NP=Sw.define({combine:e=>e.indexOf(!0)>-1}),LP=j_.newName(),ZP=j_.newName(),DP=j_.newName(),zP={"&light":"."+ZP,"&dark":"."+DP};function UP(e,t,i){return new j_(t,{finish:t=>/&/.test(t)?t.replace(/&\w*/,t=>{if("&"==t)return e;if(!i||!i[t])throw new RangeError(`Unsupported selector: ${t}`);return i[t]}):e+" "+t})}const qP=UP("."+LP,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},zP),XP={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},BP=nx.ie&&nx.ie_version<=11;class WP{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Cx,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let e of t)this.queue.push(e);(nx.ie&&nx.ie_version<=11||nx.ios&&e.composing)&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!nx.android||!1===e.constructor.EDIT_CONTEXT||nx.chrome&&nx.chrome_version<126||(this.editContext=new YP(e),e.state.facet(_S)&&(e.contentDOM.editContext=this.editContext.editContext)),BP&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var e;(null===(e=this.view.docView)||void 0===e?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){("change"!=e.type&&e.type||e.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(_S)?i.root.activeElement!=this.dom:!bx(this.dom,n))return;let r=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);r&&r.isWidget()&&r.widget.ignoreEvent(e)?t||(this.selectionChanged=!1):(nx.ie&&nx.ie_version<=11||nx.android&&nx.chrome)&&!i.state.selection.main.empty&&n.focusNode&&_x(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=vx(e.root);if(!t)return!1;let i=nx.safari&&11==e.root.nodeType&&e.root.activeElement==this.dom&&function(e,t){if(t.getComposedRanges){let i=t.getComposedRanges(e.root)[0];if(i)return FP(e,i)}let i=null;function n(e){e.preventDefault(),e.stopImmediatePropagation(),i=e.getTargetRanges()[0]}return e.contentDOM.addEventListener("beforeinput",n,!0),e.dom.ownerDocument.execCommand("indent"),e.contentDOM.removeEventListener("beforeinput",n,!0),i?FP(e,i):null}(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let n=bx(this.dom,i);return n&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&function(e,t){let i=t.focusNode,n=t.focusOffset;if(!i||t.anchorNode!=i||t.anchorOffset!=n)return!1;for(n=Math.min(n,Px(i));;)if(n){if(1!=i.nodeType)return!1;let e=i.childNodes[n-1];"false"==e.contentEditable?n--:(i=e,n=Px(i))}else{if(i==e)return!0;n=xx(i),i=i.parentNode}}(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(1==i.nodeType)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else{if(11!=i.nodeType)break;i=i.host}if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let e of this.scrollTargets)e.removeEventListener("scroll",this.onScroll);for(let e of this.scrollTargets=t)e.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,XP),BP&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),BP&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let e=()=>{let e=this.delayedAndroidKey;if(e){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&Mx(this.dom,e.key,e.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}this.delayedAndroidKey&&"Enter"!=e||(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(null===(i=this.delayedAndroidKey)||void 0===i?void 0:i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let e=this.readMutation(r);e&&(e.typeOver&&(n=!0),-1==t?({from:t,to:i}=e):(t=Math.min(e.from,t),i=Math.max(e.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&bx(this.dom,this.selectionRange);if(e<0&&!n)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Ak(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,n=Rk(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!jk(this.view.state.selection,t.newSel.main))&&this.view.update([]),n}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty("attributes"==e.type),"childList"==e.type){let i=VP(t,e.previousSibling||e.target.previousSibling,-1),n=VP(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}return"characterData"==e.type?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(_S)!=e.state.facet(_S)&&(e.view.contentDOM.editContext=e.state.facet(_S)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),null===(e=this.intersection)||void 0===e||e.disconnect(),null===(t=this.gapIntersection)||void 0===t||t.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function VP(e,t,i){for(;t;){let n=zS.get(t);if(n&&n.parent==e)return n;let r=t.parentNode;t=r!=e.dom?r:i>0?t.nextSibling:t.previousSibling}return null}function FP(e,t){let i=t.startContainer,n=t.startOffset,r=t.endContainer,s=t.endOffset,a=e.docView.domAtPos(e.state.selection.main.anchor,1);return _x(a.node,a.offset,r,s)&&([i,n,r,s]=[r,s,i,n]),{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:s}}class YP{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let n=e.state.selection.main,{anchor:r,head:s}=n,a=this.toEditorPos(i.updateRangeStart),o=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:a,drifted:!1});let l=o-a>i.text.length;a==this.from&&r<this.from?a=r:o==this.to&&r>this.to&&(o=r);let c=Ik(e.state.sliceDoc(a,o),i.text,(l?n.from:n.to)-a,l?"end":null);if(!c){let t=ww.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(jk(t,n)||e.dispatch({selection:t,userEvent:"select"}))}let h={from:c.from+a,to:c.toA+a,insert:Gb.of(i.text.slice(c.from,c.toB).split("\n"))};if((nx.mac||nx.android)&&h.from==s-1&&/^\. ?$/.test(i.text)&&"off"==e.contentDOM.getAttribute("autocorrect")&&(h={from:a,to:o,insert:Gb.of([i.text.replace("."," ")])}),this.pendingContextChange=h,!e.state.readOnly){let t=this.to-this.from+(h.to-h.from+h.insert.length);Qk(e,h,ww.single(this.toEditorPos(i.selectionStart,t),this.toEditorPos(i.selectionEnd,t)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),h.from<h.to&&!h.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let t=this.toEditorPos(i.rangeStart),s=this.toEditorPos(i.rangeEnd);t<s;t++){let i=e.coordsForChar(t);r=i&&new DOMRect(i.left,i.top,i.right-i.left,i.bottom-i.top)||r||new DOMRect,n.push(r)}t.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=t=>{let i=[];for(let e of t.getTextFormats()){let t=e.underlineStyle,n=e.underlineThickness;if(!/none/i.test(t)&&!/none/i.test(n)){let r=this.toEditorPos(e.rangeStart),s=this.toEditorPos(e.rangeEnd);if(r<s){let e=`text-decoration: underline ${/^[a-z]/.test(t)?t+" ":"Dashed"==t?"dashed ":"Squiggle"==t?"wavy ":""}${/thin/i.test(n)?1:2}px`;i.push(ux.mark({attributes:{style:e}}).range(r,s))}}}e.dispatch({effects:bS.of(ux.set(i))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:t}=this.composing;this.composing=null,t&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:e=>{this.editContext.updateControlBounds(e.contentDOM.getBoundingClientRect());let t=vx(e.root);t&&t.rangeCount&&this.editContext.updateSelectionBounds(t.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,n=this.pendingContextChange;return e.changes.iterChanges((r,s,a,o,l)=>{if(i)return;let c=l.length-(s-r);if(n&&s>=n.to){if(n.from==r&&n.to==s&&n.insert.eq(l))return n=this.pendingContextChange=null,t+=c,void(this.to+=c);n=null,this.revertPending(e.state)}if(r+=t,(s+=t)<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||s>this.to||this.to-this.from+l.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(r),this.toContextPos(s),l.toString()),this.to+=c}t+=c}),n&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(e=>!e.isUserEvent("input.type")&&e.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):this.applyEdits(e)&&this.rangeIsValid(e.state)?(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state):(this.pendingContextChange=null,this.reset(e.state)),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),n=this.toContextPos(t.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>3e4)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class GP{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(e=>e.forEach(e=>i(e,this)))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||function(e){for(;e;){if(e&&(9==e.nodeType||11==e.nodeType&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}(e.parent)||document,this.viewState=new $P(this,e.state||d_.create(e)),e.scrollTo&&e.scrollTo.is(yS)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(SS).map(e=>new PS(e));for(let n of this.plugins)n.update(this);this.observer=new WP(this),this.inputState=new Mk(this),this.inputState.ensureHandlers(this.plugins),this.docView=new hk(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(t=document.fonts)||void 0===t?void 0:t.ready)&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=1==e.length&&e[0]instanceof t_?e:1==e.length&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t,i=!1,n=!1,r=this.state;for(let d of e){if(d.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=d.state}if(this.destroyed)return void(this.viewState.state=r);let s=this.hasFocus,a=0,o=null;e.some(e=>e.annotation(iP))?(this.inputState.notifiedFocused=s,a=1):s!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=s,o=nP(r,s),o||(a=1));let l=this.observer.delayedAndroidKey,c=null;if(l?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(d_.phrases)!=this.state.facet(d_.phrases))return this.setState(r);t=ZS.create(this,r,e),t.flags|=a;let h=this.viewState.scrollTarget;try{this.updateState=2;for(let t of e){if(h&&(h=h.map(t.changes)),t.scrollIntoView){let{main:e}=t.state.selection,{x:i,y:n}=this.state.facet(GP.cursorScrollMargin);h=new vS(e.empty?e:ww.cursor(e.head,e.head>e.anchor?-1:1),"nearest","nearest",n,i)}for(let e of t.effects)e.is(yS)&&(h=e.value.clip(this.state))}this.viewState.update(t,h),this.bidiCache=JP.update(this.bidiCache,t.changes),t.empty||(this.updatePlugins(t),this.inputState.update(t)),i=this.docView.update(t),this.state.facet(NS)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(i,e.some(e=>e.isUserEvent("select.pointer")))}finally{this.updateState=0}if(t.startState.facet(MP)!=t.state.facet(MP)&&(this.viewState.mustMeasureContent=!0),(i||n||h||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!t.empty)for(let d of this.state.facet(hS))try{d(t)}catch(u){wS(this.state,u,"update listener")}(o||c)&&Promise.resolve().then(()=>{o&&this.state==o.startState&&this.dispatch(o),c&&!Rk(this,c)&&l.force&&Mx(this.contentDOM,l.key,l.keyCode)})}setState(e){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=e);this.updateState=2;let t=this.hasFocus;try{for(let e of this.plugins)e.destroy(this);this.viewState=new $P(this,e),this.plugins=e.facet(SS).map(e=>new PS(e)),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView.destroy(),this.docView=new hk(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(SS),i=e.state.facet(SS);if(t!=i){let n=[];for(let r of i){let i=t.indexOf(r);if(i<0)n.push(new PS(r));else{let t=this.plugins[i];t.mustUpdate=e,n.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let i=t.value;if(i&&i.docViewUpdate)try{i.docViewUpdate(this)}catch(e){wS(this.state,e,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:s}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(s=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(s<0)if(Nx(i||this.win))r=-1,s=this.viewState.heightMap.height;else{let e=this.viewState.scrollAnchorAt(n);r=e.from,s=e.top}this.updateState=1;let o=this.viewState.measure();if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(e>5)break;let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let c=l.map(e=>{try{return e.read(this)}catch(t){return wS(this.state,t),KP}}),h=ZS.create(this,this.state,[]),u=!1;h.flags|=o,t?t.flags|=o:t=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),u=this.docView.update(h),u&&this.docViewUpdate());for(let e=0;e<l.length;e++)if(c[e]!=KP)try{let t=l[e];t.write&&t.write(c[e],this)}catch(a){wS(this.state,a)}if(u&&this.docView.updateSelection(!0),!h.viewportChanged&&0==this.measureRequests.length){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,s=-1;continue}{let e=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-s)/this.scaleY;if((e>1||e<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n+=e,i?i.scrollTop+=e:this.win.scrollBy(0,e),s=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let o of this.state.facet(hS))o(t)}get themeClasses(){return LP+" "+(this.state.facet(NP)?DP:ZP)+" "+this.state.facet(MP)}updateAttrs(){let e=eT(this,TS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(_S)?"true":"false",class:"cm-content",style:`${nx.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),eT(this,$S,t);let i=this.observer.ignore(()=>{let i=ox(this.contentDOM,this.contentAttrs,t),n=ox(this.dom,this.editorAttrs,e);return i||n});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let e of i.effects)if(e.is(GP.announce)){t&&(this.announceDOM.textContent=""),t=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=e.value}}mountStyles(){this.styleModules=this.state.facet(NS);let e=this.state.facet(GP.cspNonce);j_.mount(this.root,this.styleModules.concat(qP).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(null!=e.key)for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key)return void(this.measureRequests[t]=e);this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(void 0===t||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(t=>t.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return wk(this,e,vk(this,e,t,i))}moveByGroup(e,t){return wk(this,e,vk(this,e,t,t=>function(e,t,i){let n=e.state.charCategorizer(t),r=n(i);return e=>{let t=n(e);return r==l_.Space&&(r=t),r==t}}(this,e.head,t)))}visualLineSide(e,t){let i=this.bidiSpans(e),n=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return ww.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return function(e,t,i,n){let r=Ok(e,t.head,t.assoc||-1),s=n&&r.type==hx.Text&&(e.lineWrapping||r.widgetLineBreaks)?e.coordsAtPos(t.assoc<0&&t.head>r.from?t.head-1:t.head):null;if(s){let t=e.dom.getBoundingClientRect(),n=e.textDirectionAt(r.from),a=e.posAtCoords({x:i==(n==zx.LTR)?t.right-1:t.left+1,y:(s.top+s.bottom)/2});if(null!=a)return ww.cursor(a,i?-1:1)}return ww.cursor(i?r.to:r.from,i?-1:1)}(this,e,t,i)}moveVertically(e,t,i){return wk(this,e,function(e,t,i,n){let r=t.head,s=i?1:-1;if(r==(i?e.state.doc.length:0))return ww.cursor(r,t.assoc);let a,o=t.goalColumn,l=e.contentDOM.getBoundingClientRect(),c=e.coordsAtPos(r,t.assoc||((t.empty?i:t.head==t.from)?1:-1)),h=e.documentTop;if(c)null==o&&(o=c.left-l.left),a=s<0?c.top:c.bottom;else{let t=e.viewState.lineBlockAt(r);null==o&&(o=Math.min(l.right-l.left,e.defaultCharacterWidth*(r-t.from))),a=(s<0?t.top:t.bottom)+h}let u=l.left+o,d=e.viewState.heightOracle.textHeight>>1,p=null!=n?n:d;for(let f=0;;f+=d){let t=a+(p+f)*s,n=xk(e,{x:u,y:t},!1,s);if(i?t>l.bottom:t<l.top)return ww.cursor(n.pos,n.assoc);let r=e.coordsAtPos(n.pos,n.assoc),c=r?(r.top+r.bottom)/2:0;if(!r||(i?c>a:c<a))return ww.cursor(n.pos,n.assoc,void 0,o)}}(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=xk(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),xk(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(e),r=this.bidiSpans(n);return Tx(i,r[Hx.find(r,e-n.from,-1,t)].dir==zx.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(mS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>HP)return iS(e.length);let t,i=this.textDirectionAt(e.from);for(let r of this.bidiCache)if(r.from==e.from&&r.dir==i&&(r.fresh||Kx(r.isolates,t=IS(this,e))))return r.order;t||(t=IS(this,e));let n=function(e,t,i){if(!e)return[new Hx(0,0,t==qx?1:0)];if(t==Ux&&!i.length&&!Gx.test(e))return iS(e.length);if(i.length)for(;e.length>Jx.length;)Jx[Jx.length]=256;let n=[],r=t==Ux?0:1;return tS(e,r,r,i,0,e.length,n),n}(e.text,i,t);return this.bidiCache.push(new JP(e.from,e.to,i,t,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||nx.safari&&(null===(e=this.inputState)||void 0===e?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ix(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((9==e.nodeType?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var i,n,r,s;return yS.of(new vS("number"==typeof e?ww.cursor(e):e,null!==(i=t.y)&&void 0!==i?i:"nearest",null!==(n=t.x)&&void 0!==n?n:"nearest",null!==(r=t.yMargin)&&void 0!==r?r:5,null!==(s=t.xMargin)&&void 0!==s?s:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return yS.of(new vS(ww.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){null==e?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof e?this.inputState.tabFocusMode=e?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return kS.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return kS.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=j_.newName(),n=[MP.of(i),NS.of(UP(`.${i}`,e))];return t&&t.dark&&n.push(NP.of(!0)),n}static baseTheme(e){return Nw.lowest(NS.of(UP("."+LP,e,zP)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&zS.get(i)||zS.get(e);return(null===(t=null==n?void 0:n.root)||void 0===t?void 0:t.view)||null}}GP.styleModule=NS,GP.inputHandler=uS,GP.clipboardInputFilter=pS,GP.clipboardOutputFilter=fS,GP.scrollHandler=OS,GP.focusChangeEffect=dS,GP.perLineTextDirection=mS,GP.exceptionSink=cS,GP.updateListener=hS,GP.editable=_S,GP.mouseSelectionStyle=lS,GP.dragMovesSelection=oS,GP.clickAddsSelectionRange=aS,GP.decorations=ES,GP.blockWrappers=AS,GP.outerDecorations=CS,GP.atomicRanges=RS,GP.bidiIsolatedRanges=QS,GP.cursorScrollMargin=Sw.define({combine:e=>{let t=5,i=5;for(let n of e)"number"==typeof n?t=i=n:({x:t,y:i}=n);return{x:t,y:i}}}),GP.scrollMargins=jS,GP.darkTheme=NP,GP.cspNonce=Sw.define({combine:e=>e.length?e[0]:""}),GP.contentAttributes=$S,GP.editorAttributes=TS,GP.lineWrapping=GP.contentAttributes.of({class:"cm-lineWrapping"}),GP.announce=e_.define();const HP=4096,KP={};class JP{constructor(e,t,i,n,r,s){this.from=e,this.to=t,this.dir=i,this.isolates=n,this.fresh=r,this.order=s}static update(e,t){if(t.empty&&!e.some(e=>e.fresh))return e;let i=[],n=e.length?e[e.length-1].dir:zx.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let s=e[r];s.dir!=n||t.touchesRange(s.from,s.to)||i.push(new JP(t.mapPos(s.from,1),t.mapPos(s.to,-1),s.dir,s.isolates,!1,s.order))}return i}}function eT(e,t,i){for(let n=e.state.facet(t),r=n.length-1;r>=0;r--){let t=n[r],s="function"==typeof t?t(e):t;s&&rx(s,i)}return i}const tT=nx.mac?"mac":nx.windows?"win":nx.linux?"linux":"key";function iT(e,t,i){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),!1!==i&&t.shiftKey&&(e="Shift-"+e),e}const nT=Nw.default(GP.domEventHandlers({keydown:(e,t)=>hT(aT(t.state),e,t,"editor")})),rT=Sw.define({enables:nT}),sT=new WeakMap;function aT(e){let t=e.facet(rT),i=sT.get(t);return i||sT.set(t,i=function(e,t=tT){let i=Object.create(null),n=Object.create(null),r=(e,t)=>{let i=n[e];if(null==i)n[e]=t;else if(i!=t)throw new Error("Key binding "+e+" is used both as a regular binding and as a multi-stroke prefix")},s=(e,n,s,a,o)=>{var l,c;let h=i[e]||(i[e]=Object.create(null)),u=n.split(/ (?!$)/).map(e=>function(e,t){const i=e.split(/-(?!$)/);let n,r,s,a,o=i[i.length-1];"Space"==o&&(o=" ");for(let l=0;l<i.length-1;++l){const e=i[l];if(/^(cmd|meta|m)$/i.test(e))a=!0;else if(/^a(lt)?$/i.test(e))n=!0;else if(/^(c|ctrl|control)$/i.test(e))r=!0;else if(/^s(hift)?$/i.test(e))s=!0;else{if(!/^mod$/i.test(e))throw new Error("Unrecognized modifier name: "+e);"mac"==t?a=!0:r=!0}}return n&&(o="Alt-"+o),r&&(o="Ctrl-"+o),a&&(o="Meta-"+o),s&&(o="Shift-"+o),o}(e,t));for(let t=1;t<u.length;t++){let i=u.slice(0,t).join(" ");r(i,!0),h[i]||(h[i]={preventDefault:!0,stopPropagation:!1,run:[t=>{let n=oT={view:t,prefix:i,scope:e};return setTimeout(()=>{oT==n&&(oT=null)},lT),!0}]})}let d=u.join(" ");r(d,!1);let p=h[d]||(h[d]={preventDefault:!1,stopPropagation:!1,run:(null===(c=null===(l=h._any)||void 0===l?void 0:l.run)||void 0===c?void 0:c.slice())||[]});s&&p.run.push(s),a&&(p.preventDefault=!0),o&&(p.stopPropagation=!0)};for(let a of e){let e=a.scope?a.scope.split(" "):["editor"];if(a.any)for(let t of e){let e=i[t]||(i[t]=Object.create(null));e._any||(e._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:n}=a;for(let t in e)e[t].run.push(e=>n(e,cT))}let n=a[t]||a.key;if(n)for(let t of e)s(t,n,a.run,a.preventDefault,a.stopPropagation),a.shift&&s(t,"Shift-"+n,a.shift,a.preventDefault,a.stopPropagation)}return i}(t.reduce((e,t)=>e.concat(t),[]))),i}let oT=null;const lT=4e3;let cT=null;function hT(e,t,i,n){cT=t;let r=function(e){var t=!(D_&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||z_&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?Z_:L_)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}(t),s=cw(ow(r,0))==r.length&&" "!=r,a="",o=!1,l=!1,c=!1;oT&&oT.view==i&&oT.scope==n&&(a=oT.prefix+" ",Dk.indexOf(t.keyCode)<0&&(l=!0,oT=null));let h,u,d=new Set,p=e=>{if(e){for(let t of e.run)if(!d.has(t)&&(d.add(t),t(i)))return e.stopPropagation&&(c=!0),!0;e.preventDefault&&(e.stopPropagation&&(c=!0),l=!0)}return!1},f=e[n];return f&&(p(f[a+iT(r,t,!s)])?o=!0:!s||!(t.altKey||t.metaKey||t.ctrlKey)||nx.windows&&t.ctrlKey&&t.altKey||nx.mac&&t.altKey&&!t.ctrlKey&&!t.metaKey||!(h=L_[t.keyCode])||h==r?s&&t.shiftKey&&p(f[a+iT(r,t,!0)])&&(o=!0):(p(f[a+iT(h,t,!0)])||t.shiftKey&&(u=Z_[t.keyCode])!=r&&u!=h&&p(f[a+iT(u,t,!1)]))&&(o=!0),!o&&p(f._any)&&(o=!0)),l&&(o=!0),o&&c&&t.stopPropagation(),cT=null,o}class uT{constructor(e,t,i,n,r){this.className=e,this.left=t,this.top=i,this.width=n,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className==this.className&&(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",null!=this.width&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let n=e.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let r=dT(e);return[new uT(t,n.left-r.left,n.top-r.top,null,n.bottom-n.top)]}return function(e,t,i){if(i.to<=e.viewport.from||i.from>=e.viewport.to)return[];let n=Math.max(i.from,e.viewport.from),r=Math.min(i.to,e.viewport.to),s=e.textDirection==zx.LTR,a=e.contentDOM,o=a.getBoundingClientRect(),l=dT(e),c=a.querySelector(".cm-line"),h=c&&window.getComputedStyle(c),u=o.left+(h?parseInt(h.paddingLeft)+Math.min(0,parseInt(h.textIndent)):0),d=o.right-(h?parseInt(h.paddingRight):0),p=Ok(e,n,1),f=Ok(e,r,-1),m=p.type==hx.Text?p:null,g=f.type==hx.Text?f:null;m&&(e.lineWrapping||p.widgetLineBreaks)&&(m=pT(e,n,1,m));g&&(e.lineWrapping||f.widgetLineBreaks)&&(g=pT(e,r,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return v(y(i.from,i.to,m));{let t=m?y(i.from,null,m):b(p,!1),n=g?y(null,i.to,g):b(f,!0),r=[];return(m||p).to<(g||f).from-(m&&g?1:0)||p.widgetLineBreaks>1&&t.bottom+e.defaultLineHeight/2<n.top?r.push(O(u,t.bottom,d,n.top)):t.bottom<n.top&&e.elementAtHeight((t.bottom+n.top)/2).type==hx.Text&&(t.bottom=n.top=(t.bottom+n.top)/2),v(t).concat(r).concat(v(n))}function O(e,i,n,r){return new uT(t,e-l.left,i-l.top,Math.max(0,n-e),r-i)}function v({top:e,bottom:t,horizontal:i}){let n=[];for(let r=0;r<i.length;r+=2)n.push(O(i[r],e,i[r+1],t));return n}function y(t,i,n){let r=1e9,a=-1e9,o=[];function l(t,i,l,c,h){let p=e.coordsAtPos(t,t==n.to?-2:2),f=e.coordsAtPos(l,l==n.from?2:-2);p&&f&&(r=Math.min(p.top,f.top,r),a=Math.max(p.bottom,f.bottom,a),h==zx.LTR?o.push(s&&i?u:p.left,s&&c?d:f.right):o.push(!s&&c?u:f.left,!s&&i?d:p.right))}let c=null!=t?t:n.from,h=null!=i?i:n.to;for(let s of e.visibleRanges)if(s.to>c&&s.from<h)for(let n=Math.max(s.from,c),r=Math.min(s.to,h);;){let s=e.state.doc.lineAt(n);for(let a of e.bidiSpans(s)){let e=a.from+s.from,o=a.to+s.from;if(e>=r)break;o>n&&l(Math.max(e,n),null==t&&e<=c,Math.min(o,r),null==i&&o>=h,a.dir)}if(n=s.to+1,n>=r)break}return 0==o.length&&l(c,null==t,h,null==i,e.textDirection),{top:r,bottom:a,horizontal:o}}function b(e,t){let i=o.top+(t?e.top:e.bottom);return{top:i,bottom:i,horizontal:[]}}}(e,t,i)}}function dT(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==zx.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function pT(e,t,i,n){let r=e.coordsAtPos(t,2*i);if(!r)return n;let s=e.dom.getBoundingClientRect(),a=(r.top+r.bottom)/2,o=e.posAtCoords({x:s.left+1,y:a}),l=e.posAtCoords({x:s.right-1,y:a});return null==o||null==l?n:{from:Math.max(n.from,Math.min(o,l)),to:Math.min(n.to,Math.max(o,l))}}class fT{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(mT)!=e.state.facet(mT)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){!1!==this.layer.updateOnDocViewUpdate&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(mT);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;e==this.scaleX&&t==this.scaleY||(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((e,t)=>{return i=e,n=this.drawn[t],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let t=this.dom.firstChild,i=0;for(let n of e)n.update&&t&&n.constructor&&this.drawn[i].constructor&&n.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(n.draw(),t);for(;t;){let e=t.nextSibling;t.remove(),t=e}this.drawn=e,nx.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const mT=Sw.define();function gT(e){return[kS.define(t=>new fT(t,e)),mT.of(e)]}const OT=Sw.define({combine:e=>p_(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})});function vT(e={}){return[OT.of(e),bT,_T,xT,gS.of(!0)]}function yT(e){return e.startState.facet(OT)!=e.state.facet(OT)}const bT=gT({above:!0,markers(e){let{state:t}=e,i=t.facet(OT),n=[];for(let r of t.selection.ranges){let s=r==t.selection.main;if(r.empty||i.drawRangeCursor&&!(s&&nx.ios&&i.iosSelectionHandles)){let t=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=r.empty?r:ww.cursor(r.head,r.assoc);for(let r of uT.forRange(e,t,i))n.push(r)}}return n},update(e,t){e.transactions.some(e=>e.selection)&&(t.style.animationName="cm-blink"==t.style.animationName?"cm-blink2":"cm-blink");let i=yT(e);return i&&wT(e.state,t),e.docChanged||e.selectionSet||i},mount(e,t){wT(t.state,e)},class:"cm-cursorLayer"});function wT(e,t){t.style.animationDuration=e.facet(OT).cursorBlinkRate+"ms"}const _T=gT({above:!1,markers(e){let t=[],{main:i,ranges:n}=e.state.selection;for(let r of n)if(!r.empty)for(let i of uT.forRange(e,"cm-selectionBackground",r))t.push(i);if(nx.ios&&!i.empty&&e.state.facet(OT).iosSelectionHandles){for(let n of uT.forRange(e,"cm-selectionHandle cm-selectionHandle-start",ww.cursor(i.from,1)))t.push(n);for(let n of uT.forRange(e,"cm-selectionHandle cm-selectionHandle-end",ww.cursor(i.to,1)))t.push(n)}return t},update:(e,t)=>e.docChanged||e.selectionSet||e.viewportChanged||yT(e),class:"cm-selectionLayer"}),xT=Nw.highest(GP.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),ST=e_.define({map:(e,t)=>null==e?null:t.mapPos(e)}),kT=Cw.define({create:()=>null,update:(e,t)=>(null!=e&&(e=t.changes.mapPos(e)),t.effects.reduce((e,t)=>t.is(ST)?t.value:e,e))}),PT=kS.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let i=e.state.field(kT);null==i?null!=this.cursor&&(null===(t=this.cursor)||void 0===t||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(kT)!=i||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:e}=this,t=e.state.field(kT),i=null!=t&&e.coordsAtPos(t);if(!i)return null;let n=e.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+e.scrollDOM.scrollLeft*e.scaleX,top:i.top-n.top+e.scrollDOM.scrollTop*e.scaleY,height:i.bottom-i.top}}drawCursor(e){if(this.cursor){let{scaleX:t,scaleY:i}=this.view;e?(this.cursor.style.left=e.left/t+"px",this.cursor.style.top=e.top/i+"px",this.cursor.style.height=e.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(kT)!=e&&this.view.dispatch({effects:ST.of(e)})}},{eventObservers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){e.target!=this.view.contentDOM&&this.view.contentDOM.contains(e.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function TT(e,t,i,n,r){t.lastIndex=0;for(let s,a=e.iterRange(i,n),o=i;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;s=t.exec(a.value);)r(o+s.index,s)}class $T{constructor(e){const{regexp:t,decoration:i,decorate:n,boundary:r,maxLength:s=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,n)this.addMatch=(e,t,i,r)=>n(r,i,i+e[0].length,e,t);else if("function"==typeof i)this.addMatch=(e,t,n,r)=>{let s=i(e,t,n);s&&r(n,n+e[0].length,s)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(e,t,n,r)=>r(n,n+e[0].length,i)}this.boundary=r,this.maxLength=s}createDeco(e){let t=new b_,i=t.add.bind(t);for(let{from:n,to:r}of function(e,t){let i=e.visibleRanges;if(1==i.length&&i[0].from==e.viewport.from&&i[0].to==e.viewport.to)return i;let n=[];for(let{from:r,to:s}of i)r=Math.max(e.state.doc.lineAt(r).from,r-t),s=Math.min(e.state.doc.lineAt(s).to,s+t),n.length&&n[n.length-1].to>=r?n[n.length-1].to=s:n.push({from:r,to:s});return n}(e,this.maxLength))TT(e.state.doc,this.regexp,n,r,(t,n)=>this.addMatch(n,e,t,i));return t.finish()}updateDeco(e,t){let i=1e9,n=-1;return e.docChanged&&e.changes.iterChanges((t,r,s,a)=>{a>=e.view.viewport.from&&s<=e.view.viewport.to&&(i=Math.min(s,i),n=Math.max(a,n))}),e.viewportMoved||n-i>1e3?this.createDeco(e.view):n>-1?this.updateRange(e.view,t.map(e.changes),i,n):t}updateRange(e,t,i,n){for(let r of e.visibleRanges){let s=Math.max(r.from,i),a=Math.min(r.to,n);if(a>=s){let i=e.state.doc.lineAt(s),n=i.to<a?e.state.doc.lineAt(a):i,o=Math.max(r.from,i.from),l=Math.min(r.to,n.to);if(this.boundary){for(;s>i.from;s--)if(this.boundary.test(i.text[s-1-i.from])){o=s;break}for(;a<n.to;a++)if(this.boundary.test(n.text[a-n.from])){l=a;break}}let c,h=[],u=(e,t,i)=>h.push(i.range(e,t));if(i==n)for(this.regexp.lastIndex=o-i.from;(c=this.regexp.exec(i.text))&&c.index<l-i.from;)this.addMatch(c,e,c.index+i.from,u);else TT(e.state.doc,this.regexp,o,l,(t,i)=>this.addMatch(i,e,t,u));t=t.update({filterFrom:o,filterTo:l,filter:(e,t)=>e<o||t>l,add:h})}}return t}}const ET=null!=/x/.unicode?"gu":"g",AT=new RegExp("[\0-\b\n--\u2028\u2029\ufeff-]",ET),CT={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let RT=null;const QT=Sw.define({combine(e){let t=p_(e,{render:null,specialChars:AT,addSpecialChars:null});return(t.replaceTabs=!function(){var e;if(null==RT&&"undefined"!=typeof document&&document.body){let t=document.body.style;RT=null!=(null!==(e=t.tabSize)&&void 0!==e?e:t.MozTabSize)}return RT||!1}())&&(t.specialChars=new RegExp("\t|"+t.specialChars.source,ET)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,ET)),t}});function IT(e={}){return[QT.of(e),jT||(jT=kS.fromClass(class{constructor(e){this.view=e,this.decorations=ux.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(QT)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new $T({regexp:e.specialChars,decoration:(t,i,n)=>{let{doc:r}=i.state,s=ow(t[0],0);if(9==s){let e=r.lineAt(n),t=i.state.tabSize,s=C_(e.text,t,n-e.from);return ux.replace({widget:new NT((t-s%t)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[s]||(this.decorationCache[s]=ux.replace({widget:new MT(e,s)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(QT);e.startState.facet(QT)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))]}let jT=null;class MT extends cx{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=(i=this.code)>=32?"•":10==i?"":String.fromCharCode(9216+i);var i;let n=e.state.phrase("Control character")+" "+(CT[this.code]||"0x"+this.code.toString(16)),r=this.options.render&&this.options.render(this.code,n,t);if(r)return r;let s=document.createElement("span");return s.textContent=t,s.title=n,s.setAttribute("aria-label",n),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class NT extends cx{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent="\t",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}const LT=ux.line({class:"cm-activeLine"}),ZT=kS.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,i=[];for(let n of e.state.selection.ranges){let r=e.lineBlockAt(n.head);r.from>t&&(i.push(LT.range(r.from)),t=r.from)}return ux.set(i)}},{decorations:e=>e.decorations}),DT="-10000px";class zT{constructor(e,t,i,n){this.facet=t,this.createTooltipView=i,this.removeTooltipView=n,this.input=e.state.facet(t),this.tooltips=this.input.filter(e=>e);let r=null;this.tooltipViews=this.tooltips.map(e=>r=i(e,r))}update(e,t){var i;let n=e.state.facet(this.facet),r=n.filter(e=>e);if(n===this.input){for(let t of this.tooltipViews)t.update&&t.update(e);return!1}let s=[],a=t?[]:null;for(let o=0;o<r.length;o++){let i=r[o],n=-1;if(i){for(let e=0;e<this.tooltips.length;e++){let t=this.tooltips[e];t&&t.create==i.create&&(n=e)}if(n<0)s[o]=this.createTooltipView(i,o?s[o-1]:null),a&&(a[o]=!!i.above);else{let i=s[o]=this.tooltipViews[n];a&&(a[o]=t[n]),i.update&&i.update(e)}}}for(let o of this.tooltipViews)s.indexOf(o)<0&&(this.removeTooltipView(o),null===(i=o.destroy)||void 0===i||i.call(o));return t&&(a.forEach((e,i)=>t[i]=e),t.length=a.length),this.input=n,this.tooltips=r,this.tooltipViews=s,!0}}function UT(e){let t=e.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const qT=Sw.define({combine:e=>{var t,i,n;return{position:nx.ios?"absolute":(null===(t=e.find(e=>e.position))||void 0===t?void 0:t.position)||"fixed",parent:(null===(i=e.find(e=>e.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(n=e.find(e=>e.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||UT}}}),XT=new WeakMap,BT=kS.fromClass(class{constructor(e){this.view=e,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(qT);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new zT(e,YT,(e,t)=>this.createTooltip(e,t),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),e.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e,this.above);t&&this.observeIntersection();let i=t||e.geometryChanged,n=e.state.facet(qT);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let e of this.manager.tooltipViews)e.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let e of this.manager.tooltipViews)this.container.appendChild(e.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(e,t){let i=e.create(this.view),n=t?t.dom:null;if(i.dom.classList.add("cm-tooltip"),e.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let e=document.createElement("div");e.className="cm-tooltip-arrow",i.dom.appendChild(e)}return i.dom.style.position=this.position,i.dom.style.top=DT,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var e,t,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let n of this.manager.tooltipViews)n.dom.remove(),null===(e=n.destroy)||void 0===e||e.call(n);this.parent&&this.container.remove(),null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=1,t=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:e}=this.manager.tooltipViews[0];if(nx.safari){let t=e.getBoundingClientRect();i=Math.abs(t.top+1e4)>1||Math.abs(t.left)>1}else i=!!e.offsetParent&&e.offsetParent!=this.container.ownerDocument.body}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(e=i.width/this.parent.offsetWidth,t=i.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),r=MS(this.view);return{visible:{left:n.left+r.left,top:n.top+r.top,right:n.right-r.right,bottom:n.bottom-r.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((e,t)=>{let i=this.manager.tooltipViews[t];return i.getCoords?i.getCoords(e.pos):this.view.coordsAtPos(e.pos)}),size:this.manager.tooltipViews.map(({dom:e})=>e.getBoundingClientRect()),space:this.view.state.facet(qT).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:i}}writeMeasure(e){var t;if(e.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let e of this.manager.tooltipViews)e.dom.style.position="absolute"}let{visible:i,space:n,scaleX:r,scaleY:s}=e,a=[];for(let o=0;o<this.manager.tooltips.length;o++){let l=this.manager.tooltips[o],c=this.manager.tooltipViews[o],{dom:h}=c,u=e.pos[o],d=e.size[o];if(!u||!1!==l.clip&&(u.bottom<=Math.max(i.top,n.top)||u.top>=Math.min(i.bottom,n.bottom)||u.right<Math.max(i.left,n.left)-.1||u.left>Math.min(i.right,n.right)+.1)){h.style.top=DT;continue}let p=l.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,f=p?7:0,m=d.right-d.left,g=null!==(t=XT.get(c))&&void 0!==t?t:d.bottom-d.top,O=c.offset||FT,v=this.view.textDirection==zx.LTR,y=d.width>n.right-n.left?v?n.left:n.right-d.width:v?Math.max(n.left,Math.min(u.left-(p?14:0)+O.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(p?14:0)-O.x),n.right-m),b=this.above[o];!l.strictSide&&(b?u.top-g-f-O.y<n.top:u.bottom+g+f+O.y>n.bottom)&&b==n.bottom-u.bottom>u.top-n.top&&(b=this.above[o]=!b);let w=(b?u.top-n.top:n.bottom-u.bottom)-f;if(w<g&&!1!==c.resize){if(w<this.view.defaultLineHeight){h.style.top=DT;continue}XT.set(c,g),h.style.height=(g=w)/s+"px"}else h.style.height&&(h.style.height="");let _=b?u.top-g-f-O.y:u.bottom+f+O.y,x=y+m;if(!0!==c.overlap)for(let e of a)e.left<x&&e.right>y&&e.top<_+g&&e.bottom>_&&(_=b?e.top-g-2-f:e.bottom+f+2);if("absolute"==this.position?(h.style.top=(_-e.parent.top)/s+"px",WT(h,(y-e.parent.left)/r)):(h.style.top=_/s+"px",WT(h,y/r)),p){let e=u.left+(v?O.x:-O.x)-(y+14-7);p.style.left=e/r+"px"}!0!==c.overlap&&a.push({left:y,top:_,right:x,bottom:_+g}),h.classList.toggle("cm-tooltip-above",b),h.classList.toggle("cm-tooltip-below",!b),c.positioned&&c.positioned(e.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let e of this.manager.tooltipViews)e.dom.style.top=DT}},{eventObservers:{scroll(){this.maybeMeasure()}}});function WT(e,t){let i=parseInt(e.style.left,10);(isNaN(i)||Math.abs(t-i)>1)&&(e.style.left=t+"px")}const VT=GP.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),FT={x:0,y:0},YT=Sw.define({enables:[BT,VT]}),GT=Sw.define({combine:e=>e.reduce((e,t)=>e.concat(t),[])});class HT{static create(e){return new HT(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new zT(e,GT,(e,t)=>this.createHostedView(e,t),e=>e.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)null===(e=t.destroy)||void 0===e||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let n=i[e];if(void 0!==n)if(void 0===t)t=n;else if(t!==n)return}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const KT=YT.compute([GT],e=>{let t=e.facet(GT);return 0===t.length?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var t;return null!==(t=e.end)&&void 0!==t?t:e.pos})),create:HT.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class JT{constructor(e,t,i,n,r){this.view=e,this.source=t,this.field=i,this.setHover=n,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,i=e.docView.tile.nearest(t.target);if(!i)return;let n,r=1;if(i.isWidget())n=i.posAtStart;else{if(n=e.posAtCoords(t),null==n)return;let i=e.coordsAtPos(n);if(!i||t.y<i.top||t.y>i.bottom||t.x<i.left-e.defaultCharacterWidth||t.x>i.right+e.defaultCharacterWidth)return;let s=e.bidiSpans(e.state.doc.lineAt(n)).find(e=>e.from<=n&&e.to>=n),a=s&&s.dir==zx.RTL?-1:1;r=t.x<i.left?-a:a}let s=this.source(e,n,r);if(null==s?void 0:s.then){let t=this.pending={pos:n};s.then(i=>{this.pending==t&&(this.pending=null,!i||Array.isArray(i)&&!i.length||e.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},t=>wS(e.state,t,"hover tooltip"))}else!s||Array.isArray(s)&&!s.length||e.dispatch({effects:this.setHover.of(Array.isArray(s)?s:[s])})}get tooltip(){let e=this.view.plugin(BT),t=e?e.manager.tooltips.findIndex(e=>e.create==HT.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&r&&!function(e,t){let i,{left:n,right:r,top:s,bottom:a}=e.getBoundingClientRect();if(i=e.querySelector(".cm-tooltip-arrow")){let e=i.getBoundingClientRect();s=Math.min(e.top,s),a=Math.max(e.bottom,a)}return t.clientX>=n-e$&&t.clientX<=r+e$&&t.clientY>=s-e$&&t.clientY<=a+e$}(r.dom,e)||this.pending){let{pos:r}=n[0]||this.pending,s=null!==(i=null===(t=n[0])||void 0===t?void 0:t.end)&&void 0!==i?i:r;(r==s?this.view.posAtCoords(this.lastMove)==r:function(e,t,i,n,r){let s=e.scrollDOM.getBoundingClientRect(),a=e.documentTop+e.documentPadding.top+e.contentHeight;if(s.left>n||s.right<n||s.top>r||Math.min(s.bottom,a)<r)return!1;let o=e.posAtCoords({x:n,y:r},!1);return o>=t&&o<=i}(this.view,r,s,e.clientX,e.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length){let{tooltip:t}=this;t&&t.dom.contains(e.relatedTarget)?this.watchTooltipLeave(t.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const e$=4;function t$(e,t={}){let i=e_.define(),n=Cw.define({create:()=>[],update(e,n){if(e.length&&(t.hideOnChange&&(n.docChanged||n.selection)?e=[]:t.hideOn&&(e=e.filter(e=>!t.hideOn(n,e))),n.docChanged)){let t=[];for(let i of e){let e=n.changes.mapPos(i.pos,-1,uw.TrackDel);if(null!=e){let r=Object.assign(Object.create(null),i);r.pos=e,null!=r.end&&(r.end=n.changes.mapPos(r.end)),t.push(r)}}e=t}for(let t of n.effects)t.is(i)&&(e=t.value),t.is(n$)&&(e=[]);return e},provide:e=>GT.from(e)});return{active:n,extension:[n,kS.define(r=>new JT(r,e,n,i,t.hoverTime||300)),KT]}}function i$(e,t){let i=e.plugin(BT);if(!i)return null;let n=i.manager.tooltips.indexOf(t);return n<0?null:i.manager.tooltipViews[n]}const n$=e_.define(),r$=Sw.define({combine(e){let t,i;for(let n of e)t=t||n.topContainer,i=i||n.bottomContainer;return{topContainer:t,bottomContainer:i}}});function s$(e,t){let i=e.plugin(a$),n=i?i.specs.indexOf(t):-1;return n>-1?i.panels[n]:null}const a$=kS.fromClass(class{constructor(e){this.input=e.state.facet(c$),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(t=>t(e));let t=e.state.facet(r$);this.top=new o$(e,!0,t.topContainer),this.bottom=new o$(e,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let i of this.panels)i.dom.classList.add("cm-panel"),i.mount&&i.mount()}update(e){let t=e.state.facet(r$);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new o$(e.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new o$(e.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=e.state.facet(c$);if(i!=this.input){let t=i.filter(e=>e),n=[],r=[],s=[],a=[];for(let i of t){let t,o=this.specs.indexOf(i);o<0?(t=i(e.view),a.push(t)):(t=this.panels[o],t.update&&t.update(e)),n.push(t),(t.top?r:s).push(t)}this.specs=t,this.panels=n,this.top.sync(r),this.bottom.sync(s);for(let e of a)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}else for(let n of this.panels)n.update&&n.update(e)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:e=>GP.scrollMargins.of(t=>{let i=t.plugin(e);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class o${constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=l$(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=l$(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(this.container&&this.classes!=this.view.themeClasses){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function l$(e){let t=e.nextSibling;return e.remove(),t}const c$=Sw.define({enables:a$});function h$(e,t){let i,n=new Promise(e=>i=e),r=e=>function(e,t,i){let n=t.content?t.content(e,()=>a(null)):null;if(!n){if(n=X_("form"),t.input){let e=X_("input",t.input);/^(text|password|number|email|tel|url)$/.test(e.type)&&e.classList.add("cm-textfield"),e.name||(e.name="input"),n.appendChild(X_("label",(t.label||"")+": ",e))}else n.appendChild(document.createTextNode(t.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(X_("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let r="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let o=0;o<r.length;o++){let e=r[o];e.addEventListener("keydown",t=>{27==t.keyCode?(t.preventDefault(),a(null)):13==t.keyCode&&(t.preventDefault(),a(e))}),e.addEventListener("submit",t=>{t.preventDefault(),a(e)})}let s=X_("div",n,X_("button",{onclick:()=>a(null),"aria-label":e.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(s.className=t.class);function a(t){s.contains(s.ownerDocument.activeElement)&&e.focus(),i(t)}return s.classList.add("cm-dialog"),{dom:s,top:t.top,mount:()=>{if(t.focus){let e;e="string"==typeof t.focus?n.querySelector(t.focus):n.querySelector("input")||n.querySelector("button"),e&&"select"in e?e.select():e&&"focus"in e&&e.focus()}}}}(e,t,i);e.state.field(u$,!1)?e.dispatch({effects:d$.of(r)}):e.dispatch({effects:e_.appendConfig.of(u$.init(()=>[r]))});let s=p$.of(r);return{close:s,result:n.then(t=>((e.win.queueMicrotask||(t=>e.win.setTimeout(t,10)))(()=>{e.state.field(u$).indexOf(r)>-1&&e.dispatch({effects:s})}),t))}}const u$=Cw.define({create:()=>[],update(e,t){for(let i of t.effects)i.is(d$)?e=[i.value].concat(e):i.is(p$)&&(e=e.filter(e=>e!=i.value));return e},provide:e=>c$.computeN([e],t=>t.field(e))}),d$=e_.define(),p$=e_.define();class f$ extends f_{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}f$.prototype.elementClass="",f$.prototype.toDOM=void 0,f$.prototype.mapMode=uw.TrackBefore,f$.prototype.startSide=f$.prototype.endSide=-1,f$.prototype.point=!0;const m$=Sw.define(),g$=Sw.define(),O$=Sw.define(),v$=Sw.define({combine:e=>e.some(e=>e)});const y$=kS.fromClass(class{constructor(e){this.view=e,this.domAfter=null,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=e.state.facet(O$).map(t=>new x$(e,t)),this.fixed=!e.state.facet(v$);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(e){if(this.updateGutters(e)){let t=this.prevViewport,i=e.view.viewport,n=Math.min(t.to,i.to)-Math.max(t.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(e.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(v$)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=y_.iter(this.view.state.facet(m$),this.view.viewport.from),n=[],r=this.gutters.map(e=>new _$(e,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(s.type)){let e=!0;for(let t of s.type)if(t.type==hx.Text&&e){w$(i,n,t.from);for(let e of r)e.line(this.view,t,n);e=!1}else if(t.widget)for(let e of r)e.widget(this.view,t)}else if(s.type==hx.Text){w$(i,n,s.from);for(let e of r)e.line(this.view,s,n)}else if(s.widget)for(let e of r)e.widget(this.view,s);for(let s of r)s.finish();e&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(e){let t=e.startState.facet(O$),i=e.state.facet(O$),n=e.docChanged||e.heightChanged||e.viewportChanged||!y_.eq(e.startState.facet(m$),e.state.facet(m$),e.view.viewport.from,e.view.viewport.to);if(t==i)for(let r of this.gutters)r.update(e)&&(n=!0);else{n=!0;let r=[];for(let n of i){let i=t.indexOf(n);i<0?r.push(new x$(this.view,n)):(this.gutters[i].update(e),r.push(this.gutters[i]))}for(let e of this.gutters)e.dom.remove(),r.indexOf(e)<0&&e.destroy();for(let e of r)"after"==e.config.side?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.gutters=r}return n}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:e=>GP.scrollMargins.of(t=>{let i=t.plugin(e);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*t.scaleX,r=i.domAfter?i.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==zx.LTR?{left:n,right:r}:{right:n,left:r}})});function b$(e){return Array.isArray(e)?e:[e]}function w$(e,t,i){for(;e.value&&e.from<=i;)e.from==i&&t.push(e.value),e.next()}class _${constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=y_.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:n}=this,r=(t.top-this.height)/e.scaleY,s=t.height/e.scaleY;if(this.i==n.elements.length){let t=new S$(e,s,r,i);n.elements.push(t),n.dom.appendChild(t.dom)}else n.elements[this.i].update(e,s,r,i);this.height=t.bottom,this.i++}line(e,t,i){let n=[];w$(this.cursor,n,t.from),i.length&&(n=n.concat(i));let r=this.gutter.config.lineMarker(e,t,n);r&&n.unshift(r);let s=this.gutter;(0!=n.length||s.config.renderEmptyElements)&&this.addElement(e,t,n)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),n=i?[i]:null;for(let r of e.state.facet(g$)){let i=r(e,t.widget,t);i&&(n||(n=[])).push(i)}n&&this.addElement(e,t,n)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class x${constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,n=>{let r,s=n.target;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let e=s.getBoundingClientRect();r=(e.top+e.bottom)/2}else r=n.clientY;let a=e.lineBlockAtHeight(r-e.documentTop);t.domEventHandlers[i](e,a,n)&&n.preventDefault()});this.markers=b$(t.markers(e)),t.initialSpacer&&(this.spacer=new S$(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=b$(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let t=this.config.updateSpacer(this.spacer.markers[0],e);t!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[t])}let i=e.view.viewport;return!y_.eq(this.markers,t,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(e)}destroy(){for(let e of this.elements)e.destroy()}}class S${constructor(e,t,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,n)}update(e,t,i,n){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].compare(t[i]))return!1;return!0}(this.markers,n)||this.setMarkers(e,n)}setMarkers(e,t){let i="cm-gutterElement",n=this.dom.firstChild;for(let r=0,s=0;;){let a=s,o=r<t.length?t[r++]:null,l=!1;if(o){let e=o.elementClass;e&&(i+=" "+e);for(let t=s;t<this.markers.length;t++)if(this.markers[t].compare(o)){a=t,l=!0;break}}else a=this.markers.length;for(;s<a;){let e=this.markers[s++];if(e.toDOM){e.destroy(n);let t=n.nextSibling;n.remove(),n=t}}if(!o)break;o.toDOM&&(l?n=n.nextSibling:this.dom.insertBefore(o.toDOM(e),n)),l&&s++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}const k$=Sw.define(),P$=Sw.define(),T$=Sw.define({combine:e=>p_(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let n in t){let e=i[n],r=t[n];i[n]=e?(t,i,n)=>e(t,i,n)||r(t,i,n):r}return i}})});class $$ extends f${constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function E$(e,t){return e.state.facet(T$).formatNumber(t,e.state)}const A$=O$.compute([T$],e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:e=>e.state.facet(k$),lineMarker:(e,t,i)=>i.some(e=>e.toDOM)?null:new $$(E$(e,e.state.doc.lineAt(t.from).number)),widgetMarker:(e,t,i)=>{for(let n of e.state.facet(P$)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(T$)!=e.state.facet(T$),initialSpacer:e=>new $$(E$(e,R$(e.state.doc.lines))),updateSpacer(e,t){let i=E$(t.view,R$(t.view.state.doc.lines));return i==e.number?e:new $$(i)},domEventHandlers:e.facet(T$).domEventHandlers,side:"before"}));function C$(e={}){return[T$.of(e),[y$],A$]}function R$(e){let t=9;for(;t<e;)t=10*t+9;return t}const Q$=new class extends f${constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},I$=m$.compute(["selection"],e=>{let t=[],i=-1;for(let n of e.selection.ranges){let r=e.doc.lineAt(n.head).from;r>i&&(i=r,t.push(Q$.range(r)))}return y_.of(t)});const j$=1024;let M$=0;class N${constructor(e,t){this.from=e,this.to=t}}class L${constructor(e={}){this.id=M$++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof e&&(e=z$.match(e)),t=>{let i=e(t);return void 0===i?null:[this,i]}}}L$.closedBy=new L$({deserialize:e=>e.split(" ")}),L$.openedBy=new L$({deserialize:e=>e.split(" ")}),L$.group=new L$({deserialize:e=>e.split(" ")}),L$.isolate=new L$({deserialize:e=>{if(e&&"rtl"!=e&&"ltr"!=e&&"auto"!=e)throw new RangeError("Invalid value for isolate: "+e);return e||"auto"}}),L$.contextHash=new L$({perNode:!0}),L$.lookAhead=new L$({perNode:!0}),L$.mounted=new L$({perNode:!0});class Z${constructor(e,t,i,n=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=n}static get(e){return e&&e.props&&e.props[L$.mounted.id]}}const D$=Object.create(null);class z${constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):D$,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(null==e.name?8:0),n=new z$(e.name||"",t,e.id,i);if(e.props)for(let r of e.props)if(Array.isArray(r)||(r=r(n)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}return n}prop(e){return this.props[e.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(e){if("string"==typeof e){if(this.name==e)return!0;let t=this.prop(L$.group);return!!t&&t.indexOf(e)>-1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return e=>{for(let i=e.prop(L$.group),n=-1;n<(i?i.length:0);n++){let r=t[n<0?e.name:i[n]];if(r)return r}}}}z$.none=new z$("",Object.create(null),0,8);class U${constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let t of e){let e=t(i);if(e){n||(n=Object.assign({},i.props));let t=e[1],r=e[0];r.combine&&r.id in n&&(t=r.combine(n[r.id],t)),n[r.id]=t}}t.push(n?new z$(i.name,n,i.id,i.flags):i)}return new U$(t)}}const q$=new WeakMap,X$=new WeakMap;var B$,W$;(W$=B$||(B$={}))[W$.ExcludeBuffers=1]="ExcludeBuffers",W$[W$.IncludeAnonymous=2]="IncludeAnonymous",W$[W$.IgnoreMounts=4]="IgnoreMounts",W$[W$.IgnoreOverlays=8]="IgnoreOverlays",W$[W$.EnterBracketed=16]="EnterBracketed";class V${constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[e,t]of r)this.props["number"==typeof e?e:e.id]=t}}toString(){let e=Z$.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let e=i.toString();e&&(t&&(t+=","),t+=e)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new aE(this.topNode,e)}cursorAt(e,t=0,i=0){let n=q$.get(this)||this.topNode,r=new aE(n);return r.moveTo(e,t),q$.set(this,r._tree),r}get topNode(){return new J$(this,0,0,null)}resolve(e,t=0){let i=H$(q$.get(this)||this.topNode,e,t,!1);return q$.set(this,i),i}resolveInner(e,t=0){let i=H$(X$.get(this)||this.topNode,e,t,!0);return X$.set(this,i),i}resolveStack(e,t=0){return function(e,t,i){let n=e.resolveInner(t,i),r=null;for(let s=n instanceof J$?n:n.context.parent;s;s=s.parent)if(s.index<0){let e=s.parent;(r||(r=[n])).push(e.resolve(t,i)),s=e}else{let e=Z$.get(s.tree);if(e&&e.overlay&&e.overlay[0].from<=t&&e.overlay[e.overlay.length-1].to>=t){let a=new J$(e.tree,e.overlay[0].from+s.from,-1,s);(r||(r=[n])).push(H$(a,t,i,!1))}}return r?rE(r):n}(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,s=e.mode||0,a=(s&B$.IncludeAnonymous)>0;for(let o=this.cursor(s|B$.IncludeAnonymous);;){let e=!1;if(o.from<=r&&o.to>=n&&(!a&&o.type.isAnonymous||!1!==t(o))){if(o.firstChild())continue;e=!0}for(;e&&i&&(a||!o.type.isAnonymous)&&i(o),!o.nextSibling();){if(!o.parent())return;e=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:hE(z$.none,this.children,this.positions,0,this.children.length,0,this.length,(e,t,i)=>new V$(this.type,e,t,i,this.propValues),e.makeTree||((e,t,i)=>new V$(z$.none,e,t,i)))}static build(e){return function(e){var t;let{buffer:i,nodeSet:n,maxBufferLength:r=j$,reused:s=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(i)?new F$(i,i.length):i,l=n.types,c=0,h=0;function u(e,t,i,v,y,b){let{id:w,start:_,end:x,size:S}=o,k=h,P=c;if(S<0){if(o.next(),-1==S){let t=s[w];return i.push(t),void v.push(_-e)}if(-3==S)return void(c=w);if(-4==S)return void(h=w);throw new RangeError(`Unrecognized record size: ${S}`)}let T,$,E=l[w],A=_-e;if(x-_<=r&&($=g(o.pos-t,y))){let t=new Uint16Array($.size-$.skip),i=o.pos-$.size,r=t.length;for(;o.pos>i;)r=O($.start,t,r);T=new Y$(t,x-$.start,n),A=$.start-e}else{let e=o.pos-S;o.next();let t=[],i=[],n=w>=a?w:-1,s=0,l=x;for(;o.pos>e;)n>=0&&o.id==n&&o.size>=0?(o.end<=l-r&&(f(t,i,_,s,o.end,l,n,k,P),s=t.length,l=o.end),o.next()):b>2500?d(_,e,t,i):u(_,e,t,i,n,b+1);if(n>=0&&s>0&&s<t.length&&f(t,i,_,s,_,l,n,k,P),t.reverse(),i.reverse(),n>-1&&s>0){let e=p(E,P);T=hE(E,t,i,0,t.length,0,x-_,e,e)}else T=m(E,t,i,x-_,k-x,P)}i.push(T),v.push(A)}function d(e,t,i,s){let a=[],l=0,c=-1;for(;o.pos>t;){let{id:e,start:t,end:i,size:n}=o;if(n>4)o.next();else{if(c>-1&&t<c)break;c<0&&(c=i-r),a.push(e,t,i),l++,o.next()}}if(l){let t=new Uint16Array(4*l),r=a[a.length-2];for(let e=a.length-3,i=0;e>=0;e-=3)t[i++]=a[e],t[i++]=a[e+1]-r,t[i++]=a[e+2]-r,t[i++]=i;i.push(new Y$(t,a[2]-r,n)),s.push(r-e)}}function p(e,t){return(i,n,r)=>{let s,a,o=0,l=i.length-1;if(l>=0&&(s=i[l])instanceof V$){if(!l&&s.type==e&&s.length==r)return s;(a=s.prop(L$.lookAhead))&&(o=n[l]+s.length+a)}return m(e,i,n,r,o,t)}}function f(e,t,i,r,s,a,o,l,c){let h=[],u=[];for(;e.length>r;)h.push(e.pop()),u.push(t.pop()+i-s);e.push(m(n.types[o],h,u,a-s,l-a,c)),t.push(s-i)}function m(e,t,i,n,r,s,a){if(s){let e=[L$.contextHash,s];a=a?[e].concat(a):[e]}if(r>25){let e=[L$.lookAhead,r];a=a?[e].concat(a):[e]}return new V$(e,t,i,n,a)}function g(e,t){let i=o.fork(),n=0,s=0,l=0,c=i.end-r,h={size:0,start:0,skip:0};e:for(let r=i.pos-e;i.pos>r;){let e=i.size;if(i.id==t&&e>=0){h.size=n,h.start=s,h.skip=l,l+=4,n+=4,i.next();continue}let o=i.pos-e;if(e<0||o<r||i.start<c)break;let u=i.id>=a?4:0,d=i.start;for(i.next();i.pos>o;){if(i.size<0){if(-3!=i.size&&-4!=i.size)break e;u+=4}else i.id>=a&&(u+=4);i.next()}s=d,n+=e,l+=u}return(t<0||n==e)&&(h.size=n,h.start=s,h.skip=l),h.size>4?h:void 0}function O(e,t,i){let{id:n,start:r,end:s,size:l}=o;if(o.next(),l>=0&&n<a){let a=i;if(l>4){let n=o.pos-(l-4);for(;o.pos>n;)i=O(e,t,i)}t[--i]=a,t[--i]=s-e,t[--i]=r-e,t[--i]=n}else-3==l?c=n:-4==l&&(h=n);return i}let v=[],y=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,v,y,-1,0);let b=null!==(t=e.length)&&void 0!==t?t:v.length?y[0]+v[0].length:0;return new V$(l[e.topID],v.reverse(),y.reverse(),b)}(e)}}V$.empty=new V$(z$.none,[],[],0);class F${constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new F$(this.buffer,this.index)}}class Y${constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return z$.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),i==(e+=4))return r;let s=[];for(;e<i;)s.push(this.childString(e)),e=this.buffer[e+3];return r+"("+s.join(",")+")"}findChild(e,t,i,n,r){let{buffer:s}=this,a=-1;for(let o=e;o!=t&&!(G$(r,n,s[o+1],s[o+2])&&(a=o,i>0));o=s[o+3]);return a}slice(e,t,i){let n=this.buffer,r=new Uint16Array(t-e),s=0;for(let a=e,o=0;a<t;){r[o++]=n[a++],r[o++]=n[a++]-i;let t=r[o++]=n[a++]-i;r[o++]=n[a++]-e,s=Math.max(s,t)}return new Y$(r,s,this.set)}}function G$(e,t,i,n){switch(e){case-2:return i<t;case-1:return n>=t&&i<t;case 0:return i<t&&n>t;case 1:return i<=t&&n>t;case 2:return n>t;case 4:return!0}}function H$(e,t,i,n){for(var r;e.from==e.to||(i<1?e.from>=t:e.from>t)||(i>-1?e.to<=t:e.to<t);){let t=!n&&e instanceof J$&&e.index<0?null:e.parent;if(!t)return e;e=t}let s=n?0:B$.IgnoreOverlays;if(n)for(let a=e,o=a.parent;o;a=o,o=a.parent)a instanceof J$&&a.index<0&&(null===(r=o.enter(t,i,s))||void 0===r?void 0:r.from)!=a.from&&(e=o);for(;;){let n=e.enter(t,i,s);if(!n)return e;e=n}}class K${cursor(e=0){return new aE(this,e)}getChild(e,t=null,i=null){let n=eE(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return eE(this,e,t,i)}resolve(e,t=0){return H$(this,e,t,!1)}resolveInner(e,t=0){return H$(this,e,t,!0)}matchContext(e){return tE(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(i=t,t=e.prevSibling):t=e}return i}get node(){return this}get next(){return this.parent}}class J$ extends K${constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let s=this;;){for(let{children:a,positions:o}=s._tree,l=t>0?a.length:-1;e!=l;e+=t){let l,c=a[e],h=o[e]+s.from;if(r&B$.EnterBracketed&&c instanceof V$&&(l=Z$.get(c))&&!l.overlay&&l.bracketed&&i>=h&&i<=h+c.length||G$(n,i,h,h+c.length))if(c instanceof Y$){if(r&B$.ExcludeBuffers)continue;let a=c.findChild(0,c.buffer.length,t,i-h,n);if(a>-1)return new nE(new iE(s,c,e,h),null,a)}else if(r&B$.IncludeAnonymous||!c.type.isAnonymous||oE(c)){let a;if(!(r&B$.IgnoreMounts)&&(a=Z$.get(c))&&!a.overlay)return new J$(a.tree,h,e,s);let o=new J$(c,h,e,s);return r&B$.IncludeAnonymous||!o.type.isAnonymous?o:o.nextChild(t<0?c.children.length-1:0,t,i,n,r)}}if(r&B$.IncludeAnonymous||!s.type.isAnonymous)return null;if(e=s.index>=0?s.index+t:t<0?-1:s._parent._tree.children.length,s=s._parent,!s)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let n;if(!(i&B$.IgnoreOverlays)&&(n=Z$.get(this._tree))&&n.overlay){let r=e-this.from,s=i&B$.EnterBracketed&&n.bracketed;for(let{from:e,to:i}of n.overlay)if((t>0||s?e<=r:e<r)&&(t<0||s?i>=r:i>r))return new J$(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function eE(e,t,i,n){let r=e.cursor(),s=[];if(!r.firstChild())return s;if(null!=i)for(let a=!1;!a;)if(a=r.type.is(i),!r.nextSibling())return s;for(;;){if(null!=n&&r.type.is(n))return s;if(r.type.is(t)&&s.push(r.node),!r.nextSibling())return null==n?s:[]}}function tE(e,t,i=t.length-1){for(let n=e;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(t[i]&&t[i]!=n.name)return!1;i--}}return!0}class iE{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class nE extends K${get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new nE(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&B$.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new nE(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new nE(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new nE(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let s=i.buffer[this.index+1];e.push(i.slice(n,r,s)),t.push(0)}return new V$(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function rE(e){if(!e.length)return null;let t=0,i=e[0];for(let s=1;s<e.length;s++){let n=e[s];(n.from>i.from||n.to<i.to)&&(i=n,t=s)}let n=i instanceof J$&&i.index<0?null:i.parent,r=e.slice();return n?r[t]=n:r.splice(t,1),new sE(r,i)}class sE{constructor(e,t){this.heads=e,this.node=t}get next(){return rE(this.heads)}}class aE{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~B$.EnterBracketed,e instanceof J$)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return!!e&&(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0)}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return!!e&&(e instanceof J$?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return!(r<0)&&(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?!(i&B$.ExcludeBuffers)&&this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&B$.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&B$.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode));let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let e=i<0?0:this.stack[i]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(e)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(n.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;({index:t,_parent:i}=i))if(t>-1)for(let n=t+e,r=e<0?-1:i._tree.children.length;n!=r;n+=e){let e=i._tree.children[n];if(this.mode&B$.IncludeAnonymous||e instanceof Y$||!e.type.isAnonymous||oE(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let s=e;s;s=s._parent)if(s.index==n){if(n==this.index)return s;t=s,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new nE(this.buffer,t,this.stack[n]);return this.bufferNode=new nE(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||!1!==e(this)){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return tE(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return tE(this._tree,e,n);let s=i[t.buffer[this.stack[r]]];if(!s.isAnonymous){if(e[n]&&e[n]!=s.name)return!1;n--}}return!0}}function oE(e){return e.children.some(e=>e instanceof Y$||!e.type.isAnonymous||oE(e))}const lE=new WeakMap;function cE(e,t){if(!e.isAnonymous||t instanceof Y$||t.type!=e)return 1;let i=lE.get(t);if(null==i){i=1;for(let n of t.children){if(n.type!=e||!(n instanceof V$)){i=1;break}i+=cE(e,n)}lE.set(t,i)}return i}function hE(e,t,i,n,r,s,a,o,l){let c=0;for(let p=n;p<r;p++)c+=cE(e,t[p]);let h=Math.ceil(1.5*c/8),u=[],d=[];return function t(i,n,r,a,o){for(let c=r;c<a;){let r=c,p=n[c],f=cE(e,i[c]);for(c++;c<a;c++){let t=cE(e,i[c]);if(f+t>=h)break;f+=t}if(c==r+1){if(f>h){let e=i[r];t(e.children,e.positions,0,e.children.length,n[r]+o);continue}u.push(i[r])}else{let t=n[c-1]+i[c-1].length-p;u.push(hE(e,i,n,r,c,p,t,null,l))}d.push(p+o-s)}}(t,i,n,r,0),(o||l)(u,d,a)}class uE{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof nE?this.setBuffer(e.context.buffer,e.index,t):e instanceof J$&&this.map.set(e.tree,t)}get(e){return e instanceof nE?this.getBuffer(e.context.buffer,e.index):e instanceof J$?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class dE{constructor(e,t,i,n,r=!1,s=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(r?1:0)|(s?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(e,t=[],i=!1){let n=[new dE(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&n.push(r);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],r=1,s=e.length?e[0]:null;for(let a=0,o=0,l=0;;a++){let c=a<t.length?t[a]:null,h=c?c.fromA:1e9;if(h-o>=i)for(;s&&s.from<h;){let t=s;if(o>=t.from||h<=t.to||l){let e=Math.max(t.from,o)-l,i=Math.min(t.to,h)-l;t=e>=i?null:new dE(e,i,t.tree,t.offset+l,a>0,!!c)}if(t&&n.push(t),s.to>h)break;s=r<e.length?e[r++]:null}if(!c)break;o=c.toA,l=c.toA-c.toB}return n}}class pE{startParse(e,t,i){return"string"==typeof e&&(e=new fE(e)),i=i?i.length?i.map(e=>new N$(e.from,e.to)):[new N$(0,0)]:[new N$(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let e=n.advance();if(e)return e}}}class fE{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new L$({perNode:!0});let mE=0;class gE{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=mE++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i="string"==typeof e?e:"?";if(e instanceof gE&&(t=e),null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let n=new gE(i,[],null,[]);if(n.set.push(n),t)for(let r of t.set)n.set.push(r);return n}static defineModifier(e){let t=new vE(e);return e=>e.modified.indexOf(t)>-1?e:vE.get(e.base||e,e.modified.concat(t).sort((e,t)=>e.id-t.id))}}let OE=0;class vE{constructor(e){this.name=e,this.instances=[],this.id=OE++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(i=>{return i.base==e&&(n=t,r=i.modified,n.length==r.length&&n.every((e,t)=>e==r[t]));var n,r});if(i)return i;let n=[],r=new gE(e.name,n,e,t);for(let a of t)a.instances.push(r);let s=function(e){let t=[[]];for(let i=0;i<e.length;i++)for(let n=0,r=t.length;n<r;n++)t.push(t[n].concat(e[i]));return t.sort((e,t)=>t.length-e.length)}(t);for(let a of e.set)if(!a.modified.length)for(let e of s)n.push(vE.get(a,e));return r}}function yE(e){let t=Object.create(null);for(let i in e){let n=e[i];Array.isArray(n)||(n=[n]);for(let e of i.split(" "))if(e){let i=[],r=2,s=e;for(let t=0;;){if("..."==s&&t>0&&t+3==e.length){r=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(s);if(!n)throw new RangeError("Invalid path: "+e);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),t+=n[0].length,t==e.length)break;let a=e[t++];if(t==e.length&&"!"==a){r=0;break}if("/"!=a)throw new RangeError("Invalid path: "+e);s=e.slice(t)}let a=i.length-1,o=i[a];if(!o)throw new RangeError("Invalid path: "+e);let l=new wE(n,r,a>0?i.slice(0,a):null);t[o]=l.sort(t[o])}}return bE.add(t)}const bE=new L$({combine(e,t){let i,n,r;for(;e||t;){if(!e||t&&e.depth>=t.depth?(r=t,t=t.next):(r=e,e=e.next),i&&i.mode==r.mode&&!r.context&&!i.context)continue;let s=new wE(r.tags,r.mode,r.context);i?i.next=s:n=s,i=s}return n}});class wE{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}function _E(e,t){let i=Object.create(null);for(let s of e)if(Array.isArray(s.tag))for(let e of s.tag)i[e.id]=s.class;else i[s.tag.id]=s.class;let{scope:n,all:r=null}=t||{};return{style:e=>{let t=r;for(let n of e)for(let e of n.set){let n=i[e.id];if(n){t=t?t+" "+n:n;break}}return t},scope:n}}function xE(e,t,i,n=0,r=e.length){let s=new SE(n,Array.isArray(t)?t:[t],i);s.highlightRange(e.cursor(),n,r,"",s.highlighters),s.flush(r)}wE.empty=new wE([],2,null);class SE{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,n,r){let{type:s,from:a,to:o}=e;if(a>=i||o<=t)return;s.isTop&&(r=this.highlighters.filter(e=>!e.scope||e.scope(s)));let l=n,c=function(e){let t=e.type.prop(bE);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}(e)||wE.empty,h=function(e,t){let i=null;for(let n of e){let e=n.style(t);e&&(i=i?i+" "+e:e)}return i}(r,c.tags);if(h&&(l&&(l+=" "),l+=h,1==c.mode&&(n+=(n?" ":"")+h)),this.startSpan(Math.max(t,a),l),c.opaque)return;let u=e.tree&&e.tree.prop(L$.mounted);if(u&&u.overlay){let s=e.node.enter(u.overlay[0].from+a,1),c=this.highlighters.filter(e=>!e.scope||e.scope(u.tree.type)),h=e.firstChild();for(let d=0,p=a;;d++){let f=d<u.overlay.length?u.overlay[d]:null,m=f?f.from+a:o,g=Math.max(t,p),O=Math.min(i,m);if(g<O&&h)for(;e.from<O&&(this.highlightRange(e,g,O,n,r),this.startSpan(Math.min(O,e.to),l),!(e.to>=m)&&e.nextSibling()););if(!f||m>i)break;p=f.to+a,p>t&&(this.highlightRange(s.cursor(),Math.max(t,f.from+a),Math.min(i,p),"",c),this.startSpan(Math.min(i,p),l))}h&&e.parent()}else if(e.firstChild()){u&&(n="");do{if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,n,r),this.startSpan(Math.min(i,e.to),l)}}while(e.nextSibling());e.parent()}}}const kE=gE.define,PE=kE(),TE=kE(),$E=kE(TE),EE=kE(TE),AE=kE(),CE=kE(AE),RE=kE(AE),QE=kE(),IE=kE(QE),jE=kE(),ME=kE(),NE=kE(),LE=kE(NE),ZE=kE(),DE={comment:PE,lineComment:kE(PE),blockComment:kE(PE),docComment:kE(PE),name:TE,variableName:kE(TE),typeName:$E,tagName:kE($E),propertyName:EE,attributeName:kE(EE),className:kE(TE),labelName:kE(TE),namespace:kE(TE),macroName:kE(TE),literal:AE,string:CE,docString:kE(CE),character:kE(CE),attributeValue:kE(CE),number:RE,integer:kE(RE),float:kE(RE),bool:kE(AE),regexp:kE(AE),escape:kE(AE),color:kE(AE),url:kE(AE),keyword:jE,self:kE(jE),null:kE(jE),atom:kE(jE),unit:kE(jE),modifier:kE(jE),operatorKeyword:kE(jE),controlKeyword:kE(jE),definitionKeyword:kE(jE),moduleKeyword:kE(jE),operator:ME,derefOperator:kE(ME),arithmeticOperator:kE(ME),logicOperator:kE(ME),bitwiseOperator:kE(ME),compareOperator:kE(ME),updateOperator:kE(ME),definitionOperator:kE(ME),typeOperator:kE(ME),controlOperator:kE(ME),punctuation:NE,separator:kE(NE),bracket:LE,angleBracket:kE(LE),squareBracket:kE(LE),paren:kE(LE),brace:kE(LE),content:QE,heading:IE,heading1:kE(IE),heading2:kE(IE),heading3:kE(IE),heading4:kE(IE),heading5:kE(IE),heading6:kE(IE),contentSeparator:kE(QE),list:kE(QE),quote:kE(QE),emphasis:kE(QE),strong:kE(QE),link:kE(QE),monospace:kE(QE),strikethrough:kE(QE),inserted:kE(),deleted:kE(),changed:kE(),invalid:kE(),meta:ZE,documentMeta:kE(ZE),annotation:kE(ZE),processingInstruction:kE(ZE),definition:gE.defineModifier("definition"),constant:gE.defineModifier("constant"),function:gE.defineModifier("function"),standard:gE.defineModifier("standard"),local:gE.defineModifier("local"),special:gE.defineModifier("special")};for(let AM in DE){let e=DE[AM];e instanceof gE&&(e.name=AM)}var zE;_E([{tag:DE.link,class:"tok-link"},{tag:DE.heading,class:"tok-heading"},{tag:DE.emphasis,class:"tok-emphasis"},{tag:DE.strong,class:"tok-strong"},{tag:DE.keyword,class:"tok-keyword"},{tag:DE.atom,class:"tok-atom"},{tag:DE.bool,class:"tok-bool"},{tag:DE.url,class:"tok-url"},{tag:DE.labelName,class:"tok-labelName"},{tag:DE.inserted,class:"tok-inserted"},{tag:DE.deleted,class:"tok-deleted"},{tag:DE.literal,class:"tok-literal"},{tag:DE.string,class:"tok-string"},{tag:DE.number,class:"tok-number"},{tag:[DE.regexp,DE.escape,DE.special(DE.string)],class:"tok-string2"},{tag:DE.variableName,class:"tok-variableName"},{tag:DE.local(DE.variableName),class:"tok-variableName tok-local"},{tag:DE.definition(DE.variableName),class:"tok-variableName tok-definition"},{tag:DE.special(DE.variableName),class:"tok-variableName2"},{tag:DE.definition(DE.propertyName),class:"tok-propertyName tok-definition"},{tag:DE.typeName,class:"tok-typeName"},{tag:DE.namespace,class:"tok-namespace"},{tag:DE.className,class:"tok-className"},{tag:DE.macroName,class:"tok-macroName"},{tag:DE.propertyName,class:"tok-propertyName"},{tag:DE.operator,class:"tok-operator"},{tag:DE.comment,class:"tok-comment"},{tag:DE.meta,class:"tok-meta"},{tag:DE.invalid,class:"tok-invalid"},{tag:DE.punctuation,class:"tok-punctuation"}]);const UE=new L$;function qE(e){return Sw.define({combine:e?t=>t.concat(e):void 0})}const XE=new L$;class BE{constructor(e,t,i=[],n=""){this.data=e,this.name=n,d_.prototype.hasOwnProperty("tree")||Object.defineProperty(d_.prototype,"tree",{get(){return FE(this)}}),this.parser=t,this.extension=[nA.of(this),d_.languageData.of((e,t,i)=>{let n=WE(e,t,i),r=n.type.prop(UE);if(!r)return[];let s=e.facet(r),a=n.type.prop(XE);if(a){let r=n.resolve(t-n.from,i);for(let t of a)if(t.test(r,e)){let i=e.facet(t.facet);return"replace"==t.type?i:i.concat(s)}}return s})].concat(i)}isActiveAt(e,t,i=-1){return WE(e,t,i).type.prop(UE)==this.data}findRegions(e){let t=e.facet(nA);if((null==t?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(e,t)=>{if(e.prop(UE)==this.data)return void i.push({from:t,to:t+e.length});let r=e.prop(L$.mounted);if(r){if(r.tree.prop(UE)==this.data){if(r.overlay)for(let e of r.overlay)i.push({from:e.from+t,to:e.to+t});else i.push({from:t,to:t+e.length});return}if(r.overlay){let e=i.length;if(n(r.tree,r.overlay[0].from+t),i.length>e)return}}for(let i=0;i<e.children.length;i++){let r=e.children[i];r instanceof V$&&n(r,e.positions[i]+t)}};return n(FE(e),0),i}get allowsNesting(){return!0}}function WE(e,t,i){let n=e.facet(nA),r=FE(e).topNode;if(!n||n.allowsNesting)for(let s=r;s;s=s.enter(t,i,B$.ExcludeBuffers|B$.EnterBracketed))s.type.isTop&&(r=s);return r}BE.setState=e_.define();class VE extends BE{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=qE(e.languageData);return new VE(t,e.parser.configure({props:[UE.add(e=>e.isTop?t:void 0)]}),e.name)}configure(e,t){return new VE(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function FE(e){let t=e.field(BE.state,!1);return t?t.tree:V$.empty}class YE{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let GE=null;class HE{constructor(e,t,i=[],n,r,s,a,o){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=s,this.skipped=a,this.scheduleOn=o,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new HE(e,t,[],V$.empty,0,i,[],null)}startParse(){return this.parser.startParse(new YE(this.state.doc),this.fragments)}work(e,t){return null!=t&&t>=this.state.doc.length&&(t=void 0),this.tree!=V$.empty&&this.isDone(null!=t?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if("number"==typeof e){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||(this.parse=this.startParse()),null!=t&&(null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n){if(this.fragments=this.withoutTempSkipped(dE.addTree(n,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(i=this.parse.stoppedAt)&&void 0!==i?i:this.state.doc.length,this.tree=n,this.parse=null,!(this.treeLen<(null!=t?t:this.state.doc.length)))return!0;this.parse=this.startParse()}if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(dE.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=GE;GE=this;try{return e()}finally{GE=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=KE(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:r,viewport:s,skipped:a}=this;if(this.takeTree(),!e.empty){let t=[];if(e.iterChangedRanges((e,i,n,r)=>t.push({fromA:e,toA:i,fromB:n,toB:r})),i=dE.applyChanges(i,t),n=V$.empty,r=0,s={from:e.mapPos(s.from,-1),to:e.mapPos(s.to,1)},this.skipped.length){a=[];for(let t of this.skipped){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);i<n&&a.push({from:i,to:n})}}}return new HE(this.parser,t,i,n,r,s,a,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:t,to:n}=this.skipped[i];t<e.to&&n>e.from&&(this.fragments=KE(this.fragments,t,n),this.skipped.splice(i--,1))}return!(this.skipped.length>=t)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends pE{createParse(t,i,n){let r=n[0].from,s=n[n.length-1].to;return{parsedPos:r,advance(){let t=GE;if(t){for(let e of n)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=s,new V$(z$.none,[],[],s-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&0==t[0].from&&t[0].to>=e}static get(){return GE}}function KE(e,t,i){return dE.applyChanges(e,[{fromA:t,toA:i,fromB:t,toB:i}])}class JE{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new JE(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=HE.create(e.facet(nA).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new JE(i)}}BE.state=Cw.define({create:JE.init,update(e,t){for(let i of t.effects)if(i.is(BE.setState))return i.value;return t.startState.facet(nA)!=t.state.facet(nA)?JE.init(t.state):e.apply(t)}});let eA=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};"undefined"!=typeof requestIdleCallback&&(eA=e=>{let t=-1,i=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(i):cancelIdleCallback(t)});const tA="undefined"!=typeof navigator&&(null===(zE=navigator.scheduling)||void 0===zE?void 0:zE.isInputPending)?()=>navigator.scheduling.isInputPending():null,iA=kS.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(BE.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(BE.state);t.tree==t.context.tree&&t.context.isDone(e.doc.length)||(this.working=eA(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(BE.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let s=Date.now()+Math.min(this.chunkBudget,100,e&&!tA?Math.max(25,e.timeRemaining()-5):1e9),a=r.context.treeLen<n&&i.doc.length>n+1e3,o=r.context.work(()=>tA&&tA()||Date.now()>s,n+(a?0:1e5));this.chunkBudget-=Date.now()-t,(o||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:BE.setState.of(new JE(r.context))})),this.chunkBudget>0&&(!o||a)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(e=>wS(this.view.state,e)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),nA=Sw.define({combine:e=>e.length?e[0]:null,enables:e=>[BE.state,iA,GP.contentAttributes.compute([e],t=>{let i=t.facet(e);return i&&i.name?{"data-language":i.name}:{}})]});class rA{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const sA=Sw.define(),aA=Sw.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function oA(e){let t=e.facet(aA);return 9==t.charCodeAt(0)?e.tabSize*t.length:t.length}function lA(e,t){let i="",n=e.tabSize,r=e.facet(aA)[0];if("\t"==r){for(;t>=n;)i+="\t",t-=n;r=" "}for(let s=0;s<t;s++)i+=r;return i}function cA(e,t){e instanceof d_&&(e=new hA(e));for(let n of e.state.facet(sA)){let i=n(e,t);if(void 0!==i)return i}let i=FE(e.state);return i.length>=t?function(e,t,i){let n=t.resolveStack(i),r=t.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(r!=n.node){let e=[];for(let t=r;t&&!(t.from<n.node.from||t.to>n.node.to||t.from==n.node.from&&t.type==n.node.type);t=t.parent)e.push(t);for(let t=e.length-1;t>=0;t--)n={node:e[t],next:n}}return dA(n,e,i)}(e,i,t):null}class hA{constructor(e,t={}){this.state=e,this.options=t,this.unit=oA(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return null!=n&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),s=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return s>-1&&(r+=s-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return C_(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let e=r(n);if(e>-1)return e}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const uA=new L$;function dA(e,t,i){for(let n=e;n;n=n.next){let e=pA(n.node);if(e)return e(mA.create(t,i,n))}return 0}function pA(e){let t=e.type.prop(uA);if(t)return t;let i,n=e.firstChild;if(n&&(i=n.type.prop(L$.closedBy))){let t=e.lastChild,n=t&&i.indexOf(t.name)>-1;return e=>vA(e,!0,1,void 0,n&&!function(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}(e)?t.from:void 0)}return null==e.parent?fA:null}function fA(){return 0}class mA extends hA{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new mA(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(gA(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return dA(this.context.next,this.base,this.pos)}}function gA(e,t){for(let i=t;i;i=i.parent)if(e==i)return!0;return!1}function OA({closing:e,align:t=!0,units:i=1}){return n=>vA(n,t,i,e)}function vA(e,t,i,n,r){let s=e.textAfter,a=s.match(/^\s*/)[0].length,o=n&&s.slice(a,a+n.length)==n||r==e.pos+a,l=t?function(e){let t=e.node,i=t.childAfter(t.from),n=t.lastChild;if(!i)return null;let r=e.options.simulateBreak,s=e.state.doc.lineAt(i.from),a=null==r||r<=s.from?s.to:Math.min(s.to,r);for(let o=i.to;;){let e=t.childAfter(o);if(!e||e==n)return null;if(!e.type.isSkipped){if(e.from>=a)return null;let t=/^ */.exec(s.text.slice(i.to-s.from))[0].length;return{from:i.from,to:i.to+t}}o=e.to}}(e):null;return l?o?e.column(l.from):e.column(l.to):e.baseIndent+(o?0:e.unit*i)}function yA({except:e,units:t=1}={}){return i=>{let n=e&&e.test(i.textAfter);return i.baseIndent+(n?0:t*i.unit)}}const bA=new L$;class wA{constructor(e,t){let i;function n(e){let t=j_.newName();return(i||(i=Object.create(null)))["."+t]=e,t}this.specs=e;const r="string"==typeof t.all?t.all:t.all?n(t.all):void 0,s=t.scope;this.scope=s instanceof BE?e=>e.prop(UE)==s.data:s?e=>e==s:void 0,this.style=_E(e.map(e=>({tag:e.tag,class:e.class||n(Object.assign({},e,{tag:null}))})),{all:r}).style,this.module=i?new j_(i):null,this.themeType=t.themeType}static define(e,t){return new wA(e,t||{})}}const _A=Sw.define(),xA=Sw.define({combine:e=>e.length?[e[0]]:null});function SA(e){let t=e.facet(_A);return t.length?t:e.facet(xA)}function kA(e,t){let i,n=[TA];return e instanceof wA&&(e.module&&n.push(GP.styleModule.of(e.module)),i=e.themeType),i?n.push(_A.computeN([GP.darkTheme],t=>t.facet(GP.darkTheme)==("dark"==i)?[e]:[])):n.push(_A.of(e)),n}class PA{constructor(e){this.markCache=Object.create(null),this.tree=FE(e.state),this.decorations=this.buildDeco(e,SA(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=FE(e.state),i=SA(e.state),n=i!=SA(e.startState),{viewport:r}=e.view,s=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&s>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=s):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return ux.none;let i=new b_;for(let{from:n,to:r}of e.visibleRanges)xE(this.tree,t,(e,t,n)=>{i.add(e,t,this.markCache[n]||(this.markCache[n]=ux.mark({class:n})))},n,r);return i.finish()}}const TA=Nw.high(kS.fromClass(PA,{decorations:e=>e.decorations})),$A=wA.define([{tag:DE.meta,color:"#404740"},{tag:DE.link,textDecoration:"underline"},{tag:DE.heading,textDecoration:"underline",fontWeight:"bold"},{tag:DE.emphasis,fontStyle:"italic"},{tag:DE.strong,fontWeight:"bold"},{tag:DE.strikethrough,textDecoration:"line-through"},{tag:DE.keyword,color:"#708"},{tag:[DE.atom,DE.bool,DE.url,DE.contentSeparator,DE.labelName],color:"#219"},{tag:[DE.literal,DE.inserted],color:"#164"},{tag:[DE.string,DE.deleted],color:"#a11"},{tag:[DE.regexp,DE.escape,DE.special(DE.string)],color:"#e40"},{tag:DE.definition(DE.variableName),color:"#00f"},{tag:DE.local(DE.variableName),color:"#30a"},{tag:[DE.typeName,DE.namespace],color:"#085"},{tag:DE.className,color:"#167"},{tag:[DE.special(DE.variableName),DE.macroName],color:"#256"},{tag:DE.definition(DE.propertyName),color:"#00c"},{tag:DE.comment,color:"#940"},{tag:DE.invalid,color:"#f00"}]),EA=GP.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),AA="()[]{}",CA=Sw.define({combine:e=>p_(e,{afterCursor:!0,brackets:AA,maxScanDistance:1e4,renderMatch:IA})}),RA=ux.mark({class:"cm-matchingBracket"}),QA=ux.mark({class:"cm-nonmatchingBracket"});function IA(e){let t=[],i=e.matched?RA:QA;return t.push(i.range(e.start.from,e.start.to)),e.end&&t.push(i.range(e.end.from,e.end.to)),t}function jA(e){let t=[],i=e.facet(CA);for(let n of e.selection.ranges){if(!n.empty)continue;let r=zA(e,n.head,-1,i)||n.head>0&&zA(e,n.head-1,1,i)||i.afterCursor&&(zA(e,n.head,1,i)||n.head<e.doc.length&&zA(e,n.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e)))}return ux.set(t,!0)}const MA=[kS.fromClass(class{constructor(e){this.paused=!1,this.decorations=jA(e.state)}update(e){(e.docChanged||e.selectionSet||this.paused)&&(e.view.composing?(this.decorations=this.decorations.map(e.changes),this.paused=!0):(this.decorations=jA(e.state),this.paused=!1))}},{decorations:e=>e.decorations}),EA];function NA(e={}){return[CA.of(e),MA]}const LA=new L$;function ZA(e,t,i){let n=e.prop(t<0?L$.openedBy:L$.closedBy);if(n)return n;if(1==e.name.length){let n=i.indexOf(e.name);if(n>-1&&n%2==(t<0?1:0))return[i[n+t]]}return null}function DA(e){let t=e.type.prop(LA);return t?t(e.node):e}function zA(e,t,i,n={}){let r=n.maxScanDistance||1e4,s=n.brackets||AA,a=FE(e),o=a.resolveInner(t,i);for(let l=o;l;l=l.parent){let n=ZA(l.type,i,s);if(n&&l.from<l.to){let r=DA(l);if(r&&(i>0?t>=r.from&&t<r.to:t>r.from&&t<=r.to))return UA(e,t,i,l,r,n,s)}}return function(e,t,i,n,r,s,a){if(i<0?!t:t==e.doc.length)return null;let o=i<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),l=a.indexOf(o);if(l<0||l%2==0!=i>0)return null;let c={from:i<0?t-1:t,to:i>0?t+1:t},h=e.doc.iterRange(t,i>0?e.doc.length:0),u=0;for(let d=0;!h.next().done&&d<=s;){let e=h.value;i<0&&(d+=e.length);let s=t+d*i;for(let t=i>0?0:e.length-1,o=i>0?e.length:-1;t!=o;t+=i){let o=a.indexOf(e[t]);if(!(o<0||n.resolveInner(s+t,1).type!=r))if(o%2==0==i>0)u++;else{if(1==u)return{start:c,end:{from:s+t,to:s+t+1},matched:o>>1==l>>1};u--}}i>0&&(d+=e.length)}return h.done?{start:c,matched:!1}:null}(e,t,i,a,o.type,r,s)}function UA(e,t,i,n,r,s,a){let o=n.parent,l={from:r.from,to:r.to},c=0,h=null==o?void 0:o.cursor();if(h&&(i<0?h.childBefore(n.from):h.childAfter(n.to)))do{if(i<0?h.to<=n.from:h.from>=n.to){if(0==c&&s.indexOf(h.type.name)>-1&&h.from<h.to){let e=DA(h);return{start:l,end:e?{from:e.from,to:e.to}:void 0,matched:!0}}if(ZA(h.type,i,a))c++;else if(ZA(h.type,-i,a)){if(0==c){let e=DA(h);return{start:l,end:e&&e.from<e.to?{from:e.from,to:e.to}:void 0,matched:!1}}c--}}}while(i<0?h.prevSibling():h.nextSibling());return{start:l,matched:!1}}const qA=Object.create(null),XA=[z$.none],BA=[],WA=Object.create(null),VA=Object.create(null);for(let[AM,CM]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])VA[AM]=YA(qA,CM);function FA(e,t){BA.indexOf(e)>-1||BA.push(e)}function YA(e,t){let i=[];for(let o of t.split(" ")){let t=[];for(let i of o.split(".")){let n=e[i]||DE[i];n?"function"==typeof n?t.length?t=t.map(n):FA(i):t.length?FA(i):t=Array.isArray(n)?n:[n]:FA(i)}for(let e of t)i.push(e)}if(!i.length)return 0;let n=t.replace(/ /g,"_"),r=n+" "+i.map(e=>e.id),s=WA[r];if(s)return s.id;let a=WA[r]=z$.define({id:XA.length,name:n,props:[yE({[n]:i})]});return XA.push(a),a.id}zx.RTL,zx.LTR;function GA(e,t){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let r=e(t,i);return!!r&&(n(i.update(r)),!0)}}const HA=GA(nC,0),KA=GA(iC,0),JA=GA((e,t)=>iC(e,t,function(e){let t=[];for(let i of e.selection.ranges){let n=e.doc.lineAt(i.from),r=i.to<=n.to?n:e.doc.lineAt(i.to);r.from>n.from&&r.from==i.to&&(r=i.to==n.to+1?n:e.doc.lineAt(i.to-1));let s=t.length-1;s>=0&&t[s].to>n.from?t[s].to=r.to:t.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:r.to})}return t}(t)),0);function eC(e,t){let i=e.languageDataAt("commentTokens",t,1);return i.length?i[0]:{}}const tC=50;function iC(e,t,i=t.selection.ranges){let n=i.map(e=>eC(t,e.from).block);if(!n.every(e=>e))return null;let r=i.map((e,i)=>function(e,{open:t,close:i},n,r){let s,a,o=e.sliceDoc(n-tC,n),l=e.sliceDoc(r,r+tC),c=/\s*$/.exec(o)[0].length,h=/^\s*/.exec(l)[0].length,u=o.length-c;if(o.slice(u-t.length,u)==t&&l.slice(h,h+i.length)==i)return{open:{pos:n-c,margin:c&&1},close:{pos:r+h,margin:h&&1}};r-n<=2*tC?s=a=e.sliceDoc(n,r):(s=e.sliceDoc(n,n+tC),a=e.sliceDoc(r-tC,r));let d=/^\s*/.exec(s)[0].length,p=/\s*$/.exec(a)[0].length,f=a.length-p-i.length;return s.slice(d,d+t.length)==t&&a.slice(f,f+i.length)==i?{open:{pos:n+d+t.length,margin:/\s/.test(s.charAt(d+t.length))?1:0},close:{pos:r-p-i.length,margin:/\s/.test(a.charAt(f-1))?1:0}}:null}(t,n[i],e.from,e.to));if(2!=e&&!r.every(e=>e))return{changes:t.changes(i.map((e,t)=>r[t]?[]:[{from:e.from,insert:n[t].open+" "},{from:e.to,insert:" "+n[t].close}]))};if(1!=e&&r.some(e=>e)){let e=[];for(let t,i=0;i<r.length;i++)if(t=r[i]){let r=n[i],{open:s,close:a}=t;e.push({from:s.pos-r.open.length,to:s.pos+s.margin},{from:a.pos-a.margin,to:a.pos+r.close.length})}return{changes:e}}return null}function nC(e,t,i=t.selection.ranges){let n=[],r=-1;e:for(let{from:s,to:a}of i){let e,i=n.length,o=1e9;for(let l=s;l<=a;){let i=t.doc.lineAt(l);if(null==e&&(e=eC(t,i.from).line,!e))continue e;if(i.from>r&&(s==a||a>i.from)){r=i.from;let t=/^\s*/.exec(i.text)[0].length,s=t==i.length,a=i.text.slice(t,t+e.length)==e?t:-1;t<i.text.length&&t<o&&(o=t),n.push({line:i,comment:a,token:e,indent:t,empty:s,single:!1})}l=i.to+1}if(o<1e9)for(let t=i;t<n.length;t++)n[t].indent<n[t].line.text.length&&(n[t].indent=o);n.length==i+1&&(n[i].single=!0)}if(2!=e&&n.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:r,indent:s,empty:a,single:o}of n)!o&&a||e.push({from:t.from+s,insert:r+" "});let i=t.changes(e);return{changes:i,selection:t.selection.map(i,1)}}if(1!=e&&n.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:i,token:r}of n)if(i>=0){let n=t.from+i,s=n+r.length;" "==t.text[s-t.from]&&s++,e.push({from:n,to:s})}return{changes:e}}return null}const rC=Hw.define(),sC=Hw.define(),aC=Sw.define(),oC=Sw.define({combine:e=>p_(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,n)=>e(i,n)||t(i,n)})}),lC=Cw.define({create:()=>kC.empty,update(e,t){let i=t.state.facet(oC),n=t.annotation(rC);if(n){let r=mC.fromTransaction(t,n.selection),s=n.side,a=0==s?e.undone:e.done;return a=r?gC(a,a.length,i.minDepth,r):bC(a,t.startState.selection),new kC(0==s?n.rest:a,0==s?a:n.rest)}let r=t.annotation(sC);if("full"!=r&&"before"!=r||(e=e.isolate()),!1===t.annotation(t_.addToHistory))return t.changes.empty?e:e.addMapping(t.changes.desc);let s=mC.fromTransaction(t),a=t.annotation(t_.time),o=t.annotation(t_.userEvent);return s?e=e.addChanges(s,a,o,i,t):t.selection&&(e=e.addSelection(t.startState.selection,a,o,i.newGroupDelay)),"full"!=r&&"after"!=r||(e=e.isolate()),e},toJSON:e=>({done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}),fromJSON:e=>new kC(e.done.map(mC.fromJSON),e.undone.map(mC.fromJSON))});function cC(e={}){return[lC,oC.of(e),GP.domEventHandlers({beforeinput(e,t){let i="historyUndo"==e.inputType?uC:"historyRedo"==e.inputType?dC:null;return!!i&&(e.preventDefault(),i(t))}})]}function hC(e,t){return function({state:i,dispatch:n}){if(!t&&i.readOnly)return!1;let r=i.field(lC,!1);if(!r)return!1;let s=r.pop(e,i,t);return!!s&&(n(s),!0)}}const uC=hC(0,!1),dC=hC(1,!1),pC=hC(0,!0),fC=hC(1,!0);class mC{constructor(e,t,i,n,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(e){return new mC(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:null===(e=this.changes)||void 0===e?void 0:e.toJSON(),mapped:null===(t=this.mapped)||void 0===t?void 0:t.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(e){return new mC(e.changes&&pw.fromJSON(e.changes),[],e.mapped&&dw.fromJSON(e.mapped),e.startSelection&&ww.fromJSON(e.startSelection),e.selectionsAfter.map(ww.fromJSON))}static fromTransaction(e,t){let i=vC;for(let n of e.startState.facet(aC)){let t=n(e);t.length&&(i=i.concat(t))}return!i.length&&e.changes.empty?null:new mC(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,vC)}static selection(e){return new mC(void 0,vC,void 0,void 0,e)}}function gC(e,t,i,n){let r=t+1>i+20?t-i-1:0,s=e.slice(r,t);return s.push(n),s}function OC(e,t){return e.length?t.length?e.concat(t):e:t}const vC=[],yC=200;function bC(e,t){if(e.length){let i=e[e.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-yC));return n.length&&n[n.length-1].eq(t)?e:(n.push(t),gC(e,e.length-1,1e9,i.setSelAfter(n)))}return[mC.selection([t])]}function wC(e){let t=e[e.length-1],i=e.slice();return i[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),i}function _C(e,t){if(!e.length)return e;let i=e.length,n=vC;for(;i;){let r=xC(e[i-1],t,n);if(r.changes&&!r.changes.empty||r.effects.length){let t=e.slice(0,i);return t[i-1]=r,t}t=r.mapped,i--,n=r.selectionsAfter}return n.length?[mC.selection(n)]:vC}function xC(e,t,i){let n=OC(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):vC,i);if(!e.changes)return mC.selection(n);let r=e.changes.map(t),s=t.mapDesc(e.changes,!0),a=e.mapped?e.mapped.composeDesc(s):s;return new mC(r,e_.mapEffects(e.effects,t),a,e.startSelection.map(s),n)}const SC=/^(input\.type|delete)($|\.)/;class kC{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new kC(this.done,this.undone):this}addChanges(e,t,i,n,r){let s=this.done,a=s[s.length-1];return s=a&&a.changes&&!a.changes.empty&&e.changes&&(!i||SC.test(i))&&(!a.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,function(e,t){let i=[],n=!1;return e.iterChangedRanges((e,t)=>i.push(e,t)),t.iterChangedRanges((e,t,r,s)=>{for(let a=0;a<i.length;){let e=i[a++],t=i[a++];s>=e&&r<=t&&(n=!0)}}),n}(a.changes,e.changes))||"input.type.compose"==i)?gC(s,s.length-1,n.minDepth,new mC(e.changes.compose(a.changes),OC(e_.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,vC)):gC(s,s.length,n.minDepth,e),new kC(s,vC,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:vC;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&(s=r[r.length-1],a=e,s.ranges.length==a.ranges.length&&0===s.ranges.filter((e,t)=>e.empty!=a.ranges[t].empty).length)?this:new kC(bC(this.done,e),this.undone,t,i);var s,a}addMapping(e){return new kC(_C(this.done,e),_C(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=0==e?this.done:this.undone;if(0==n.length)return null;let r=n[n.length-1],s=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:rC.of({side:e,rest:wC(n),selection:s}),userEvent:0==e?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let i=1==n.length?vC:n.slice(0,n.length-1);return r.mapped&&(i=_C(i,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:rC.of({side:e,rest:i,selection:s}),filter:!1,userEvent:0==e?"undo":"redo",scrollIntoView:!0})}return null}}kC.empty=new kC(vC,vC);const PC=[{key:"Mod-z",run:uC,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:dC,preventDefault:!0},{linux:"Ctrl-Shift-z",run:dC,preventDefault:!0},{key:"Mod-u",run:pC,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:fC,preventDefault:!0}];function TC(e,t){return ww.create(e.ranges.map(t),e.mainIndex)}function $C(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function EC({state:e,dispatch:t},i){let n=TC(e.selection,i);return!n.eq(e.selection,!0)&&(t($C(e,n)),!0)}function AC(e,t){return ww.cursor(t?e.to:e.from)}function CC(e,t){return EC(e,i=>i.empty?e.moveByChar(i,t):AC(i,t))}function RC(e){return e.textDirectionAt(e.state.selection.main.head)==zx.LTR}const QC=e=>CC(e,!RC(e)),IC=e=>CC(e,RC(e));function jC(e,t){return EC(e,i=>i.empty?e.moveByGroup(i,t):AC(i,t))}function MC(e,t,i){if(t.type.prop(i))return!0;let n=t.to-t.from;return n&&(n>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function NC(e,t,i){let n,r,s=FE(e).resolveInner(t.head),a=i?L$.closedBy:L$.openedBy;for(let o=t.head;;){let t=i?s.childAfter(o):s.childBefore(o);if(!t)break;MC(e,t,a)?s=t:o=i?t.to:t.from}return r=s.type.prop(a)&&(n=i?zA(e,s.from,1):zA(e,s.to,-1))&&n.matched?i?n.end.to:n.end.from:i?s.to:s.from,ww.cursor(r,i?-1:1)}function LC(e,t){return EC(e,i=>{if(!i.empty)return AC(i,t);let n=e.moveVertically(i,t);return n.head!=i.head?n:e.moveToLineBoundary(i,t)})}const ZC=e=>LC(e,!1),DC=e=>LC(e,!0);function zC(e){let t,i=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0;if(i){for(let t of e.state.facet(GP.scrollMargins)){let i=t(e);(null==i?void 0:i.top)&&(n=Math.max(null==i?void 0:i.top,n)),(null==i?void 0:i.bottom)&&(r=Math.max(null==i?void 0:i.bottom,r))}t=e.scrollDOM.clientHeight-n-r}else t=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:i,height:Math.max(e.defaultLineHeight,t-5)}}function UC(e,t){let i,n=zC(e),{state:r}=e,s=TC(r.selection,i=>i.empty?e.moveVertically(i,t,n.height):AC(i,t));if(s.eq(r.selection))return!1;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),a=e.scrollDOM.getBoundingClientRect(),o=a.top+n.marginTop,l=a.bottom-n.marginBottom;t&&t.top>o&&t.bottom<l&&(i=GP.scrollIntoView(s.main.head,{y:"start",yMargin:t.top-o}))}return e.dispatch($C(r,s),{effects:i}),!0}const qC=e=>UC(e,!1),XC=e=>UC(e,!0);function BC(e,t,i){let n=e.lineBlockAt(t.head),r=e.moveToLineBoundary(t,i);if(r.head==t.head&&r.head!=(i?n.to:n.from)&&(r=e.moveToLineBoundary(t,i,!1)),!i&&r.head==n.from&&n.length){let i=/^\s*/.exec(e.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&t.head!=n.from+i&&(r=ww.cursor(n.from+i))}return r}function WC(e,t){let i=TC(e.state.selection,e=>{let i=t(e);return ww.range(e.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return!i.eq(e.state.selection)&&(e.dispatch($C(e.state,i)),!0)}function VC(e,t){return WC(e,i=>e.moveByChar(i,t))}const FC=e=>VC(e,!RC(e)),YC=e=>VC(e,RC(e));function GC(e,t){return WC(e,i=>e.moveByGroup(i,t))}function HC(e,t){return WC(e,i=>e.moveVertically(i,t))}const KC=e=>HC(e,!1),JC=e=>HC(e,!0);function eR(e,t){return WC(e,i=>e.moveVertically(i,t,zC(e).height))}const tR=e=>eR(e,!1),iR=e=>eR(e,!0),nR=({state:e,dispatch:t})=>(t($C(e,{anchor:0})),!0),rR=({state:e,dispatch:t})=>(t($C(e,{anchor:e.doc.length})),!0),sR=({state:e,dispatch:t})=>(t($C(e,{anchor:e.selection.main.anchor,head:0})),!0),aR=({state:e,dispatch:t})=>(t($C(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),oR=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0);function lR(e,t){let{state:i}=e,n=i.selection,r=i.selection.ranges.slice();for(let s of i.selection.ranges){let n=i.doc.lineAt(s.head);if(t?n.to<e.state.doc.length:n.from>0)for(let i=s;;){let s=e.moveVertically(i,t);if(s.head<n.from||s.head>n.to){r.some(e=>e.head==s.head)||r.push(s);break}if(s.head==i.head)break;i=s}}return r.length!=n.ranges.length&&(e.dispatch($C(i,ww.create(r,r.length-1))),!0)}function cR(e,t){if(e.state.readOnly)return!1;let i="delete.selection",{state:n}=e,r=n.changeByRange(n=>{let{from:r,to:s}=n;if(r==s){let a=t(n);a<r?(i="delete.backward",a=hR(e,a,!1)):a>r&&(i="delete.forward",a=hR(e,a,!0)),r=Math.min(r,a),s=Math.max(s,a)}else r=hR(e,r,!1),s=hR(e,s,!0);return r==s?{range:n}:{changes:{from:r,to:s},range:ww.cursor(r,r<n.head?-1:1)}});return!r.changes.empty&&(e.dispatch(n.update(r,{scrollIntoView:!0,userEvent:i,effects:"delete.selection"==i?GP.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function hR(e,t,i){if(e instanceof GP)for(let n of e.state.facet(GP.atomicRanges).map(t=>t(e)))n.between(t,t,(e,n)=>{e<t&&n>t&&(t=i?n:e)});return t}const uR=(e,t,i)=>cR(e,n=>{let r,s,a=n.from,{state:o}=e,l=o.doc.lineAt(a);if(i&&!t&&a>l.from&&a<l.from+200&&!/[^ \t]/.test(r=l.text.slice(0,a-l.from))){if("\t"==r[r.length-1])return a-1;let e=C_(r,o.tabSize)%oA(o)||oA(o);for(let t=0;t<e&&" "==r[r.length-1-t];t++)a--;s=a}else s=aw(l.text,a-l.from,t,t)+l.from,s==a&&l.number!=(t?o.doc.lines:1)?s+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(l.text.slice(s-l.from,a-l.from))&&(s=aw(l.text,s-l.from,!1,!1)+l.from);return s}),dR=e=>uR(e,!1,!0),pR=e=>uR(e,!0,!1),fR=(e,t)=>cR(e,i=>{let n=i.head,{state:r}=e,s=r.doc.lineAt(n),a=r.charCategorizer(n);for(let e=null;;){if(n==(t?s.to:s.from)){n==i.head&&s.number!=(t?r.doc.lines:1)&&(n+=t?1:-1);break}let o=aw(s.text,n-s.from,t)+s.from,l=s.text.slice(Math.min(n,o)-s.from,Math.max(n,o)-s.from),c=a(l);if(null!=e&&c!=e)break;" "==l&&n==i.head||(e=c),n=o}return n}),mR=e=>fR(e,!1);function gR(e){let t=[],i=-1;for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),s=e.doc.lineAt(n.to);if(n.empty||n.to!=s.from||(s=e.doc.lineAt(n.to-1)),i>=r.number){let e=t[t.length-1];e.to=s.to,e.ranges.push(n)}else t.push({from:r.from,to:s.to,ranges:[n]});i=s.number+1}return t}function OR(e,t,i){if(e.readOnly)return!1;let n=[],r=[];for(let s of gR(e)){if(i?s.to==e.doc.length:0==s.from)continue;let t=e.doc.lineAt(i?s.to+1:s.from-1),a=t.length+1;if(i){n.push({from:s.to,to:t.to},{from:s.from,insert:t.text+e.lineBreak});for(let t of s.ranges)r.push(ww.range(Math.min(e.doc.length,t.anchor+a),Math.min(e.doc.length,t.head+a)))}else{n.push({from:t.from,to:s.from},{from:s.to,insert:e.lineBreak+t.text});for(let e of s.ranges)r.push(ww.range(e.anchor-a,e.head-a))}}return!!n.length&&(t(e.update({changes:n,scrollIntoView:!0,selection:ww.create(r,e.selection.mainIndex),userEvent:"move.line"})),!0)}function vR(e,t,i){if(e.readOnly)return!1;let n=[];for(let s of gR(e))i?n.push({from:s.from,insert:e.doc.slice(s.from,s.to)+e.lineBreak}):n.push({from:s.to,insert:e.lineBreak+e.doc.slice(s.from,s.to)});let r=e.changes(n);return t(e.update({changes:r,selection:e.selection.map(r,i?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const yR=bR(!1);function bR(e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=t.changeByRange(i=>{let{from:n,to:r}=i,s=t.doc.lineAt(n),a=!e&&n==r&&function(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let i,n=FE(e).resolveInner(t),r=n.childBefore(t),s=n.childAfter(t);return r&&s&&r.to<=t&&s.from>=t&&(i=r.type.prop(L$.closedBy))&&i.indexOf(s.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(s.from).from&&!/\S/.test(e.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}(t,n);e&&(n=r=(r<=s.to?s:t.doc.lineAt(r)).to);let o=new hA(t,{simulateBreak:n,simulateDoubleBreak:!!a}),l=cA(o,n);for(null==l&&(l=C_(/^\s*/.exec(t.doc.lineAt(n).text)[0],t.tabSize));r<s.to&&/\s/.test(s.text[r-s.from]);)r++;a?({from:n,to:r}=a):n>s.from&&n<s.from+100&&!/\S/.test(s.text.slice(0,n))&&(n=s.from);let c=["",lA(t,l)];return a&&c.push(lA(t,o.lineIndent(s.from,-1))),{changes:{from:n,to:r,insert:Gb.of(c)},range:ww.cursor(n+1+c[1].length)}});return i(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function wR(e,t){let i=-1;return e.changeByRange(n=>{let r=[];for(let a=n.from;a<=n.to;){let s=e.doc.lineAt(a);s.number>i&&(n.empty||n.to>s.from)&&(t(s,r,n),i=s.number),a=s.to+1}let s=e.changes(r);return{changes:r,range:ww.range(s.mapPos(n.anchor,1),s.mapPos(n.head,1))}})}const _R=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(wR(e,(t,i)=>{i.push({from:t.from,insert:e.facet(aA)})}),{userEvent:"input.indent"})),!0),xR=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(wR(e,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=C_(n,e.tabSize),s=0,a=lA(e,Math.max(0,r-oA(e)));for(;s<n.length&&s<a.length&&n.charCodeAt(s)==a.charCodeAt(s);)s++;i.push({from:t.from+s,to:t.from+n.length,insert:a.slice(s)})}),{userEvent:"delete.dedent"})),!0),SR=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:e=>EC(e,t=>NC(e.state,t,!RC(e))),shift:e=>WC(e,t=>NC(e.state,t,!RC(e)))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:e=>EC(e,t=>NC(e.state,t,RC(e))),shift:e=>WC(e,t=>NC(e.state,t,RC(e)))},{key:"Alt-ArrowUp",run:({state:e,dispatch:t})=>OR(e,t,!1)},{key:"Shift-Alt-ArrowUp",run:({state:e,dispatch:t})=>vR(e,t,!1)},{key:"Alt-ArrowDown",run:({state:e,dispatch:t})=>OR(e,t,!0)},{key:"Shift-Alt-ArrowDown",run:({state:e,dispatch:t})=>vR(e,t,!0)},{key:"Mod-Alt-ArrowUp",run:e=>lR(e,!1)},{key:"Mod-Alt-ArrowDown",run:e=>lR(e,!0)},{key:"Escape",run:({state:e,dispatch:t})=>{let i=e.selection,n=null;return i.ranges.length>1?n=ww.create([i.main]):i.main.empty||(n=ww.create([ww.cursor(i.main.head)])),!!n&&(t($C(e,n)),!0)}},{key:"Mod-Enter",run:bR(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:e,dispatch:t})=>{let i=gR(e).map(({from:t,to:i})=>ww.range(t,Math.min(i+1,e.doc.length)));return t(e.update({selection:ww.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:e,dispatch:t})=>{let i=TC(e.selection,t=>{let i=FE(e),n=i.resolveStack(t.from,1);if(t.empty){let e=i.resolveStack(t.from,-1);e.node.from>=n.node.from&&e.node.to<=n.node.to&&(n=e)}for(let e=n;e;e=e.next){let{node:i}=e;if((i.from<t.from&&i.to>=t.to||i.to>t.to&&i.from<=t.from)&&e.next)return ww.range(i.to,i.from)}return t});return!i.eq(e.selection)&&(t($C(e,i)),!0)},preventDefault:!0},{key:"Mod-[",run:xR},{key:"Mod-]",run:_R},{key:"Mod-Alt-\\",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=Object.create(null),n=new hA(e,{overrideIndentation:e=>{let t=i[e];return null==t?-1:t}}),r=wR(e,(t,r,s)=>{let a=cA(n,t.from);if(null==a)return;/\S/.test(t.text)||(a=0);let o=/^\s*/.exec(t.text)[0],l=lA(e,a);(o!=l||s.from<t.from+o.length)&&(i[t.from]=a,r.push({from:t.from,to:t.from+o.length,insert:l}))});return r.changes.empty||t(e.update(r,{userEvent:"indent"})),!0}},{key:"Shift-Mod-k",run:e=>{if(e.state.readOnly)return!1;let{state:t}=e,i=t.changes(gR(t).map(({from:e,to:i})=>(e>0?e--:i<t.doc.length&&i++,{from:e,to:i}))),n=TC(t.selection,t=>{let i;if(e.lineWrapping){let n=e.lineBlockAt(t.head),r=e.coordsAtPos(t.head,t.assoc||1);r&&(i=n.bottom+e.documentTop-r.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,i)}).map(i);return e.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:e,dispatch:t})=>function(e,t){let i=!1,n=TC(e.selection,t=>{let n=zA(e,t.head,-1)||zA(e,t.head,1)||t.head>0&&zA(e,t.head-1,1)||t.head<e.doc.length&&zA(e,t.head+1,-1);if(!n||!n.end)return t;i=!0;let r=n.start.from==t.head?n.end.to:n.end.from;return ww.cursor(r)});return!!i&&(t($C(e,n)),!0)}(e,t)},{key:"Mod-/",run:e=>{let{state:t}=e,i=t.doc.lineAt(t.selection.main.from),n=eC(e.state,i.from);return n.line?HA(e):!!n.block&&JA(e)}},{key:"Alt-A",run:KA},{key:"Ctrl-m",mac:"Shift-Alt-m",run:e=>(e.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:QC,shift:FC,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e=>jC(e,!RC(e)),shift:e=>GC(e,!RC(e)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:e=>EC(e,t=>BC(e,t,!RC(e))),shift:e=>WC(e,t=>BC(e,t,!RC(e))),preventDefault:!0},{key:"ArrowRight",run:IC,shift:YC,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:e=>jC(e,RC(e)),shift:e=>GC(e,RC(e)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:e=>EC(e,t=>BC(e,t,RC(e))),shift:e=>WC(e,t=>BC(e,t,RC(e))),preventDefault:!0},{key:"ArrowUp",run:ZC,shift:KC,preventDefault:!0},{mac:"Cmd-ArrowUp",run:nR,shift:sR},{mac:"Ctrl-ArrowUp",run:qC,shift:tR},{key:"ArrowDown",run:DC,shift:JC,preventDefault:!0},{mac:"Cmd-ArrowDown",run:rR,shift:aR},{mac:"Ctrl-ArrowDown",run:XC,shift:iR},{key:"PageUp",run:qC,shift:tR},{key:"PageDown",run:XC,shift:iR},{key:"Home",run:e=>EC(e,t=>BC(e,t,!1)),shift:e=>WC(e,t=>BC(e,t,!1)),preventDefault:!0},{key:"Mod-Home",run:nR,shift:sR},{key:"End",run:e=>EC(e,t=>BC(e,t,!0)),shift:e=>WC(e,t=>BC(e,t,!0)),preventDefault:!0},{key:"Mod-End",run:rR,shift:aR},{key:"Enter",run:yR,shift:yR},{key:"Mod-a",run:oR},{key:"Backspace",run:dR,shift:dR,preventDefault:!0},{key:"Delete",run:pR,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:mR,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:e=>fR(e,!0),preventDefault:!0},{mac:"Mod-Backspace",run:e=>cR(e,t=>{let i=e.moveToLineBoundary(t,!1).head;return t.head>i?i:Math.max(0,t.head-1)}),preventDefault:!0},{mac:"Mod-Delete",run:e=>cR(e,t=>{let i=e.moveToLineBoundary(t,!0).head;return t.head<i?i:Math.min(e.state.doc.length,t.head+1)}),preventDefault:!0}].concat([{key:"Ctrl-b",run:QC,shift:FC,preventDefault:!0},{key:"Ctrl-f",run:IC,shift:YC},{key:"Ctrl-p",run:ZC,shift:KC},{key:"Ctrl-n",run:DC,shift:JC},{key:"Ctrl-a",run:e=>EC(e,t=>ww.cursor(e.lineBlockAt(t.head).from,1)),shift:e=>WC(e,t=>ww.cursor(e.lineBlockAt(t.head).from))},{key:"Ctrl-e",run:e=>EC(e,t=>ww.cursor(e.lineBlockAt(t.head).to,-1)),shift:e=>WC(e,t=>ww.cursor(e.lineBlockAt(t.head).to))},{key:"Ctrl-d",run:pR},{key:"Ctrl-h",run:dR},{key:"Ctrl-k",run:e=>cR(e,t=>{let i=e.lineBlockAt(t.head).to;return t.head<i?i:Math.min(e.state.doc.length,t.head+1)})},{key:"Ctrl-Alt-h",run:mR},{key:"Ctrl-o",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:Gb.of(["",""])},range:ww.cursor(e.from)}));return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(t=>{if(!t.empty||0==t.from||t.from==e.doc.length)return{range:t};let i=t.from,n=e.doc.lineAt(i),r=i==n.from?i-1:aw(n.text,i-n.from,!1)+n.from,s=i==n.to?i+1:aw(n.text,i-n.from,!0)+n.from;return{changes:{from:r,to:s,insert:e.doc.slice(i,s).append(e.doc.slice(r,i))},range:ww.cursor(s)}});return!i.changes.empty&&(t(e.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:XC}].map(e=>({mac:e.key,run:e.run,shift:e.shift})))),kR={key:"Tab",run:_R,shift:xR},PR="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class TR{constructor(e,t,i=0,n=e.length,r,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?e=>r(PR(e)):PR,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ow(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=lw(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=cw(e);let n=this.normalize(t);if(n.length)for(let r=0,s=i;;r++){let e=n.charCodeAt(r),a=this.match(e,s,this.bufferPos+this.bufferStart);if(r==n.length-1){if(a)return this.value=a,this;break}s==i&&r<t.length&&t.charCodeAt(r)==e&&s++}}}match(e,t,i){let n=null;for(let r=0;r<this.matches.length;r+=2){let t=this.matches[r],s=!1;this.query.charCodeAt(t)==e&&(t==this.query.length-1?n={from:this.matches[r+1],to:i}:(this.matches[r]++,s=!0)),s||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(1==this.query.length?n={from:t,to:i}:this.matches.push(1,t)),n&&this.test&&!this.test(n.from,n.to,this.buffer,this.bufferStart)&&(n=null),n}}"undefined"!=typeof Symbol&&(TR.prototype[Symbol.iterator]=function(){return this});const $R={from:-1,to:-1,match:/.*/.exec("")},ER="gm"+(null==/x/.unicode?"":"u");class AR{constructor(e,t,i,n=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=$R,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new QR(e,t,i,n,r);this.re=new RegExp(t,ER+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.iter=e.iter();let s=e.lineAt(n);this.curLineStart=s.from,this.matchPos=IR(e,n),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,n=i+t[0].length;if(this.matchPos=IR(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,match:t},this;e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),e=0}}}}const CR=new WeakMap;class RR{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let n=CR.get(e);if(!n||n.from>=i||n.to<=t){let n=new RR(t,e.sliceString(t,i));return CR.set(e,n),n}if(n.from==t&&n.to==i)return n;let{text:r,from:s}=n;return s>t&&(r=e.sliceString(t,s)+r,s=t),n.to<i&&(r+=e.sliceString(n.to,i)),CR.set(e,new RR(s,r)),new RR(t,r.slice(t-s,i-s))}}class QR{constructor(e,t,i,n,r){this.text=e,this.to=r,this.done=!1,this.value=$R,this.matchPos=IR(e,n),this.re=new RegExp(t,ER+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.flat=RR.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,i=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,i,t)))return this.value={from:e,to:i,match:t},this.matchPos=IR(this.text,i+(e==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=RR.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function IR(e,t){if(t>=e.length)return t;let i,n=e.lineAt(t);for(;t<n.to&&(i=n.text.charCodeAt(t-n.from))>=56320&&i<57344;)t++;return t}"undefined"!=typeof Symbol&&(AR.prototype[Symbol.iterator]=QR.prototype[Symbol.iterator]=function(){return this});const jR={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},MR=Sw.define({combine:e=>p_(e,jR,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});const NR=ux.mark({class:"cm-selectionMatch"}),LR=ux.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ZR(e,t,i,n){return!(0!=i&&e(t.sliceDoc(i-1,i))==l_.Word||n!=t.doc.length&&e(t.sliceDoc(n,n+1))==l_.Word)}const DR=kS.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(MR),{state:i}=e,n=i.selection;if(n.ranges.length>1)return ux.none;let r,s=n.main,a=null;if(s.empty){if(!t.highlightWordAroundCursor)return ux.none;let e=i.wordAt(s.head);if(!e)return ux.none;a=i.charCategorizer(s.head),r=i.sliceDoc(e.from,e.to)}else{let e=s.to-s.from;if(e<t.minSelectionLength||e>200)return ux.none;if(t.wholeWords){if(r=i.sliceDoc(s.from,s.to),a=i.charCategorizer(s.head),!ZR(a,i,s.from,s.to)||!function(e,t,i,n){return e(t.sliceDoc(i,i+1))==l_.Word&&e(t.sliceDoc(n-1,n))==l_.Word}(a,i,s.from,s.to))return ux.none}else if(r=i.sliceDoc(s.from,s.to),!r)return ux.none}let o=[];for(let l of e.visibleRanges){let e=new TR(i.doc,r,l.from,l.to);for(;!e.next().done;){let{from:n,to:r}=e.value;if((!a||ZR(a,i,n,r))&&(s.empty&&n<=s.from&&r>=s.to?o.push(LR.range(n,r)):(n>=s.to||r<=s.from)&&o.push(NR.range(n,r)),o.length>t.maxMatches))return ux.none}}return ux.set(o)}},{decorations:e=>e.decorations}),zR=GP.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const UR=Sw.define({combine:e=>p_(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new OQ(e),scrollToMatch:e=>GP.scrollIntoView(e)})});class qR{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||function(e){try{return new RegExp(e,ER),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>"n"==t?"\n":"r"==t?"\r":"t"==t?"\t":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new GR(this):new WR(this)}getCursor(e,t=0,i){let n=e.doc?e:d_.create({doc:e});return null==i&&(i=n.doc.length),this.regexp?VR(this,n,t,i):BR(this,n,t,i)}}class XR{constructor(e){this.spec=e}}function BR(e,t,i,n){let r;var s,a;return e.wholeWord&&(s=t.doc,a=t.charCategorizer(t.selection.main.head),r=(e,t,i,n)=>((n>e||n+i.length<t)&&(n=Math.max(0,e-2),i=s.sliceString(n,Math.min(s.length,t+2))),!(a(FR(i,e-n))==l_.Word&&a(YR(i,e-n))==l_.Word||a(YR(i,t-n))==l_.Word&&a(FR(i,t-n))==l_.Word))),e.test&&(r=function(e,t,i){return(n,r,s,a)=>{if(i&&!i(n,r,s,a))return!1;let o=n>=a&&r<=a+s.length?s.slice(n-a,r-a):t.doc.sliceString(n,r);return e(o,t,n,r)}}(e.test,t,r)),new TR(t.doc,e.unquoted,i,n,e.caseSensitive?void 0:e=>e.toLowerCase(),r)}class WR extends XR{constructor(e){super(e)}nextMatch(e,t,i){let n=BR(this.spec,e,i,e.doc.length).nextOverlapping();if(n.done){let i=Math.min(e.doc.length,t+this.spec.unquoted.length);n=BR(this.spec,e,0,i).nextOverlapping()}return n.done||n.value.from==t&&n.value.to==i?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let i=Math.max(t,n-1e4-this.spec.unquoted.length),r=BR(this.spec,e,i,n),s=null;for(;!r.nextOverlapping().done;)s=r.value;if(s)return s;if(i==t)return null;n-=1e4}}prevMatch(e,t,i){let n=this.prevMatchInRange(e,0,t);return n||(n=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),!n||n.from==t&&n.to==i?null:n}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=BR(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=BR(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function VR(e,t,i,n){let r;var s;return e.wholeWord&&(s=t.charCategorizer(t.selection.main.head),r=(e,t,i)=>!i[0].length||(s(FR(i.input,i.index))!=l_.Word||s(YR(i.input,i.index))!=l_.Word)&&(s(YR(i.input,i.index+i[0].length))!=l_.Word||s(FR(i.input,i.index+i[0].length))!=l_.Word)),e.test&&(r=function(e,t,i){return(n,r,s)=>(!i||i(n,r,s))&&e(s[0],t,n,r)}(e.test,t,r)),new AR(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:r},i,n)}function FR(e,t){return e.slice(aw(e,t,!1),t)}function YR(e,t){return e.slice(t,aw(e,t))}class GR extends XR{nextMatch(e,t,i){let n=VR(this.spec,e,i,e.doc.length).next();return n.done&&(n=VR(this.spec,e,0,t).next()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=1;;n++){let r=Math.max(t,i-1e4*n),s=VR(this.spec,e,r,i),a=null;for(;!s.next().done;)a=s.value;if(a&&(r==t||a.from>r+10))return a;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if("&"==i)return e.match[0];if("$"==i)return"$";for(let n=i.length;n>0;n--){let t=+i.slice(0,n);if(t>0&&t<e.match.length)return e.match[t]+i.slice(n)}return t})}matchAll(e,t){let i=VR(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=VR(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const HR=e_.define(),KR=e_.define(),JR=Cw.define({create:e=>new eQ(uQ(e).create(),null),update(e,t){for(let i of t.effects)i.is(HR)?e=new eQ(i.value.create(),e.panel):i.is(KR)&&(e=new eQ(e.query,i.value?hQ:null));return e},provide:e=>c$.from(e,e=>e.panel)});class eQ{constructor(e,t){this.query=e,this.panel=t}}const tQ=ux.mark({class:"cm-searchMatch"}),iQ=ux.mark({class:"cm-searchMatch cm-searchMatch-selected"}),nQ=kS.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(JR))}update(e){let t=e.state.field(JR);(t!=e.startState.field(JR)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return ux.none;let{view:i}=this,n=new b_;for(let r=0,s=i.visibleRanges,a=s.length;r<a;r++){let{from:t,to:o}=s[r];for(;r<a-1&&o>s[r+1].from-500;)o=s[++r].to;e.highlight(i.state,t,o,(e,t)=>{let r=i.state.selection.ranges.some(i=>i.from==e&&i.to==t);n.add(e,t,r?iQ:tQ)})}return n.finish()}},{decorations:e=>e.decorations});function rQ(e){return t=>{let i=t.state.field(JR,!1);return i&&i.query.spec.valid?e(t,i):fQ(t)}}const sQ=rQ((e,{query:t})=>{let{to:i}=e.state.selection.main,n=t.nextMatch(e.state,i,i);if(!n)return!1;let r=ww.single(n.from,n.to),s=e.state.facet(UR);return e.dispatch({selection:r,effects:[wQ(e,n),s.scrollToMatch(r.main,e)],userEvent:"select.search"}),pQ(e),!0}),aQ=rQ((e,{query:t})=>{let{state:i}=e,{from:n}=i.selection.main,r=t.prevMatch(i,n,n);if(!r)return!1;let s=ww.single(r.from,r.to),a=e.state.facet(UR);return e.dispatch({selection:s,effects:[wQ(e,r),a.scrollToMatch(s.main,e)],userEvent:"select.search"}),pQ(e),!0}),oQ=rQ((e,{query:t})=>{let i=t.matchAll(e.state,1e3);return!(!i||!i.length)&&(e.dispatch({selection:ww.create(i.map(e=>ww.range(e.from,e.to))),userEvent:"select.search.matches"}),!0)}),lQ=rQ((e,{query:t})=>{let{state:i}=e,{from:n,to:r}=i.selection.main;if(i.readOnly)return!1;let s=t.nextMatch(i,n,n);if(!s)return!1;let a,o,l=s,c=[],h=[];l.from==n&&l.to==r&&(o=i.toText(t.getReplacement(l)),c.push({from:l.from,to:l.to,insert:o}),l=t.nextMatch(i,l.from,l.to),h.push(GP.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+".")));let u=e.state.changes(c);return l&&(a=ww.single(l.from,l.to).map(u),h.push(wQ(e,l)),h.push(i.facet(UR).scrollToMatch(a.main,e))),e.dispatch({changes:u,selection:a,effects:h,userEvent:"input.replace"}),!0}),cQ=rQ((e,{query:t})=>{if(e.state.readOnly)return!1;let i=t.matchAll(e.state,1e9).map(e=>{let{from:i,to:n}=e;return{from:i,to:n,insert:t.getReplacement(e)}});if(!i.length)return!1;let n=e.state.phrase("replaced $ matches",i.length)+".";return e.dispatch({changes:i,effects:GP.announce.of(n),userEvent:"input.replace.all"}),!0});function hQ(e){return e.state.facet(UR).createPanel(e)}function uQ(e,t){var i,n,r,s,a;let o=e.selection.main,l=o.empty||o.to>o.from+100?"":e.sliceDoc(o.from,o.to);if(t&&!l)return t;let c=e.facet(UR);return new qR({search:(null!==(i=null==t?void 0:t.literal)&&void 0!==i?i:c.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==t?void 0:t.caseSensitive)&&void 0!==n?n:c.caseSensitive,literal:null!==(r=null==t?void 0:t.literal)&&void 0!==r?r:c.literal,regexp:null!==(s=null==t?void 0:t.regexp)&&void 0!==s?s:c.regexp,wholeWord:null!==(a=null==t?void 0:t.wholeWord)&&void 0!==a?a:c.wholeWord})}function dQ(e){let t=s$(e,hQ);return t&&t.dom.querySelector("[main-field]")}function pQ(e){let t=dQ(e);t&&t==e.root.activeElement&&t.select()}const fQ=e=>{let t=e.state.field(JR,!1);if(t&&t.panel){let i=dQ(e);if(i&&i!=e.root.activeElement){let n=uQ(e.state,t.query.spec);n.valid&&e.dispatch({effects:HR.of(n)}),i.focus(),i.select()}}else e.dispatch({effects:[KR.of(!0),t?HR.of(uQ(e.state,t.query.spec)):e_.appendConfig.of(xQ)]});return!0},mQ=e=>{let t=e.state.field(JR,!1);if(!t||!t.panel)return!1;let i=s$(e,hQ);return i&&i.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:KR.of(!1)}),!0},gQ=[{key:"Mod-f",run:fQ,scope:"editor search-panel"},{key:"F3",run:sQ,shift:aQ,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:sQ,shift:aQ,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:mQ,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:e,dispatch:t})=>{let i=e.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:n,to:r}=i.main,s=[],a=0;for(let o=new TR(e.doc,e.sliceDoc(n,r));!o.next().done;){if(s.length>1e3)return!1;o.value.from==n&&(a=s.length),s.push(ww.range(o.value.from,o.value.to))}return t(e.update({selection:ww.create(s,a),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:e=>{let{state:t}=e,i=String(t.doc.lineAt(e.state.selection.main.head).number),{close:n,result:r}=h$(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:i},focus:!0,submitLabel:t.phrase("go")});return r.then(i=>{let r=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!r)return void e.dispatch({effects:n});let s=t.doc.lineAt(t.selection.main.head),[,a,o,l,c]=r,h=l?+l.slice(1):0,u=o?+o:s.number;if(o&&c){let e=u/100;a&&(e=e*("-"==a?-1:1)+s.number/t.doc.lines),u=Math.round(t.doc.lines*e)}else o&&a&&(u=u*("-"==a?-1:1)+s.number);let d=t.doc.line(Math.max(1,Math.min(t.doc.lines,u))),p=ww.cursor(d.from+Math.max(0,Math.min(h,d.length)));e.dispatch({effects:[n,GP.scrollIntoView(p.from,{y:"center"})],selection:p})}),!0}},{key:"Mod-d",run:({state:e,dispatch:t})=>{let{ranges:i}=e.selection;if(i.some(e=>e.from===e.to))return(({state:e,dispatch:t})=>{let{selection:i}=e,n=ww.create(i.ranges.map(t=>e.wordAt(t.head)||ww.cursor(t.head)),i.mainIndex);return!n.eq(i)&&(t(e.update({selection:n})),!0)})({state:e,dispatch:t});let n=e.sliceDoc(i[0].from,i[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=n))return!1;let r=function(e,t){let{main:i,ranges:n}=e.selection,r=e.wordAt(i.head),s=r&&r.from==i.from&&r.to==i.to;for(let a=!1,o=new TR(e.doc,t,n[n.length-1].to);;){if(o.next(),!o.done){if(a&&n.some(e=>e.from==o.value.from))continue;if(s){let t=e.wordAt(o.value.from);if(!t||t.from!=o.value.from||t.to!=o.value.to)continue}return o.value}if(a)return null;o=new TR(e.doc,t,0,Math.max(0,n[n.length-1].from-1)),a=!0}}(e,n);return!!r&&(t(e.update({selection:e.selection.addRange(ww.range(r.from,r.to),!1),effects:GP.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class OQ{constructor(e){this.view=e;let t=this.query=e.state.field(JR).query.spec;function i(e,t,i){return X_("button",{class:"cm-button",name:e,onclick:t,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=X_("input",{value:t.search,placeholder:vQ(e,"Find"),"aria-label":vQ(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=X_("input",{value:t.replace,placeholder:vQ(e,"Replace"),"aria-label":vQ(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=X_("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=X_("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=X_("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=X_("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,i("next",()=>sQ(e),[vQ(e,"next")]),i("prev",()=>aQ(e),[vQ(e,"previous")]),i("select",()=>oQ(e),[vQ(e,"all")]),X_("label",null,[this.caseField,vQ(e,"match case")]),X_("label",null,[this.reField,vQ(e,"regexp")]),X_("label",null,[this.wordField,vQ(e,"by word")]),...e.state.readOnly?[]:[X_("br"),this.replaceField,i("replace",()=>lQ(e),[vQ(e,"replace")]),i("replaceAll",()=>cQ(e),[vQ(e,"replace all")])],X_("button",{name:"close",onclick:()=>mQ(e),"aria-label":vQ(e,"close"),type:"button"},["×"])])}commit(){let e=new qR({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:HR.of(e)}))}keydown(e){var t,i,n;t=this.view,i=e,n="search-panel",hT(aT(t.state),i,t,n)?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?aQ:sQ)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),lQ(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(HR)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(UR).top}}function vQ(e,t){return e.state.phrase(t)}const yQ=30,bQ=/[\s\.,:;?!]/;function wQ(e,{from:t,to:i}){let n=e.state.doc.lineAt(t),r=e.state.doc.lineAt(i).to,s=Math.max(n.from,t-yQ),a=Math.min(r,i+yQ),o=e.state.sliceDoc(s,a);if(s!=n.from)for(let l=0;l<yQ;l++)if(!bQ.test(o[l+1])&&bQ.test(o[l])){o=o.slice(l);break}if(a!=r)for(let l=o.length-1;l>o.length-yQ;l--)if(!bQ.test(o[l-1])&&bQ.test(o[l])){o=o.slice(0,l);break}return GP.announce.of(`${e.state.phrase("current match")}. ${o} ${e.state.phrase("on line")} ${n.number}.`)}const _Q=GP.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),xQ=[JR,Nw.low(nQ),_Q];class SQ{constructor(e,t,i,n,r,s,a,o,l,c=0,h){this.p=e,this.stack=t,this.state=i,this.reducePos=n,this.pos=r,this.score=s,this.buffer=a,this.bufferBase=o,this.curContext=l,this.lookAhead=c,this.parent=h}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let n=e.parser.context;return new SQ(e,[],t,i,i,0,[],0,n?new kQ(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,n=65535&e,{parser:r}=this.p,s=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),a=r.dynamicPrecedence(n);if(a&&(this.score+=a),0==i)return this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,s?8:4,!0),void this.reduceContext(n,this.reducePos);let o=this.stack.length-3*(i-1)-(262144&e?6:0),l=o?this.stack[o-2]:this.p.ranges[0].from,c=this.reducePos-l;c>=2e3&&!(null===(t=this.p.parser.nodeSet.types[n])||void 0===t?void 0:t.isAnonymous)&&(l==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=l,this.p.lastBigReductionSize=c));let h=o?this.stack[o-1]:0,u=this.bufferBase+this.buffer.length-h;if(n<r.minRepeatTerm||131072&e){let e=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,l,e,u+4,!0)}if(262144&e)this.state=this.stack[o];else{let e=this.stack[o-3];this.state=r.getGoto(e,n,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(n,l)}storeNode(e,t,i,n=4,r=!1){if(0==e&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let e=this,n=this.buffer.length;if(0==n&&e.parent&&(n=e.bufferBase-e.parent.bufferBase,e=e.parent),n>0&&0==e.buffer[n-4]&&e.buffer[n-1]>-1){if(t==i)return;if(e.buffer[n-2]>=t)return void(e.buffer[n-2]=i)}}if(r&&this.pos!=i){let r=this.buffer.length;if(r>0&&(0!=this.buffer[r-4]||this.buffer[r-1]<0)){let e=!1;for(let t=r;t>0&&this.buffer[t-2]>i;t-=4)if(this.buffer[t-1]>=0){e=!0;break}if(e)for(;r>0&&this.buffer[r-2]>i;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,n>4&&(n-=4)}this.buffer[r]=e,this.buffer[r+1]=t,this.buffer[r+2]=i,this.buffer[r+3]=n}else this.buffer.push(e,t,i,n)}shift(e,t,i,n){if(131072&e)this.pushState(65535&e,this.pos);else if(262144&e)this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4);else{let r=e,{parser:s}=this.p;this.pos=n;let a=s.stateFlag(r,1);!a&&(n>i||t<=s.maxNode)&&(this.reducePos=n),this.pushState(r,a?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=s.maxNode&&this.buffer.push(t,i,n,4)}}apply(e,t,i,n){65536&e?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new SQ(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new PQ(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(0==i)return!1;if(!(65536&i))return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let i=[];for(let n,r=0;r<t.length;r+=2)(n=t[r+1])!=this.state&&this.p.parser.hasAction(n,e)&&i.push(t[r],n);if(this.stack.length<120)for(let e=0;i.length<8&&e<t.length;e+=2){let n=t[e+1];i.some((e,t)=>1&t&&e==n)||i.push(t[e],n)}t=i}let i=[];for(let n=0;n<t.length&&i.length<4;n+=2){let e=t[n+1];if(e==this.state)continue;let r=this.split();r.pushState(e,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(t[n],this.pos),r.reducePos=this.pos,r.score-=200,i.push(r)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if(!(65536&t))return!1;if(!e.validAction(this.state,t)){let i=t>>19,n=65535&t,r=this.stack.length-3*i;if(r<0||e.getGoto(this.stack[r],n,!1)<0){let e=this.findForcedReduction();if(null==e)return!1;t=e}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(n,r)=>{if(!t.includes(n))return t.push(n),e.allActions(n,t=>{if(393216&t);else if(65536&t){let i=(t>>19)-r;if(i>1){let n=65535&t,r=this.stack.length-3*i;if(r>=0&&e.getGoto(this.stack[r],n,!1)>=0)return i<<19|65536|n}}else{let e=i(t,r+1);if(null!=e)return e}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:e}=this.p;return 65535==e.data[e.stateSlot(this.state,1)]&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||-3!=this.buffer[e])&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||-4!=this.buffer[e])&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new kQ(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return!(e<=this.lookAhead)&&(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class kQ{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class PQ{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=65535&e,i=e>>19;0==i?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(i-1);let n=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=n}}class TQ{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,0==this.index&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new TQ(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;null!=e&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new TQ(this.stack,this.pos,this.index)}}function $Q(e,t=Uint16Array){if("string"!=typeof e)return e;let i=null;for(let n=0,r=0;n<e.length;){let s=0;for(;;){let t=e.charCodeAt(n++),i=!1;if(126==t){s=65535;break}t>=92&&t--,t>=34&&t--;let r=t-32;if(r>=46&&(r-=46,i=!0),s+=r,i)break;s*=46}i?i[r++]=s:i=new t(s)}return i}class EQ{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const AQ=new EQ;class CQ{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=AQ,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,n=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!n)return null;let e=this.ranges[--n];r-=i.from-e.to,i=e}for(;t<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let e=this.ranges[++n];r+=e.from-i.to,i=e}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t,i,n=this.chunkOff+e;if(n>=0&&n<this.chunk.length)t=this.pos+e,i=this.chunk.charCodeAt(n);else{let n=this.resolveOffset(e,1);if(null==n)return-1;if(t=n,t>=this.chunk2Pos&&t<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(t-this.chunk2Pos);else{let e=this.rangeIndex,n=this.range;for(;n.to<=t;)n=this.ranges[++e];this.chunk2=this.input.chunk(this.chunk2Pos=t),t+this.chunk2.length>n.to&&(this.chunk2=this.chunk2.slice(0,n.to-t)),i=this.chunk2.charCodeAt(0)}}return t>=this.token.lookAhead&&(this.token.lookAhead=t+1),i}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(null==i||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=AQ,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let n of this.ranges){if(n.from>=t)break;n.to>e&&(i+=this.input.read(Math.max(n.from,e),Math.min(n.to,t)))}return i}}class RQ{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;jQ(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}RQ.prototype.contextual=RQ.prototype.fallback=RQ.prototype.extend=!1;class QQ{constructor(e,t,i){this.precTable=t,this.elseToken=i,this.data="string"==typeof e?$Q(e):e}token(e,t){let i=e.pos,n=0;for(;;){let i=e.next<0,r=e.resolveOffset(1,1);if(jQ(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(null==this.elseToken)return;if(i||n++,null==r)break;e.reset(r,e.token)}n&&(e.reset(i,e.token),e.acceptToken(this.elseToken,n))}}QQ.prototype.contextual=RQ.prototype.fallback=RQ.prototype.extend=!1;class IQ{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function jQ(e,t,i,n,r,s){let a=0,o=1<<n,{dialect:l}=i.p.parser;e:for(;0!=(o&e[a]);){let i=e[a+1];for(let u=a+3;u<i;u+=2)if((e[u+1]&o)>0){let i=e[u];if(l.allows(i)&&(-1==t.token.value||t.token.value==i||NQ(i,t.token.value,r,s))){t.acceptToken(i);break}}let n=t.next,c=0,h=e[a+2];if(!(t.next<0&&h>c&&65535==e[i+3*h-3])){for(;c<h;){let r=c+h>>1,s=i+r+(r<<1),o=e[s],l=e[s+1]||65536;if(n<o)h=r;else{if(!(n>=l)){a=e[s+2],t.advance();continue e}c=r+1}}break}a=e[i+3*h-1]}}function MQ(e,t,i){for(let n,r=t;65535!=(n=e[r]);r++)if(n==i)return r-t;return-1}function NQ(e,t,i,n){let r=MQ(i,n,t);return r<0||MQ(i,n,e)<r}const LQ="undefined"!=typeof process&&process.env&&/\bparse\b/.test(process.env.LOG);let ZQ=null;function DQ(e,t,i){let n=e.cursor(B$.IncludeAnonymous);for(n.moveTo(t);;)if(!(i<0?n.childBefore(t):n.childAfter(t)))for(;;){if((i<0?n.to<t:n.from>t)&&!n.type.isError)return i<0?Math.max(0,Math.min(n.to-1,t-25)):Math.min(e.length,Math.max(n.from+1,t+25));if(i<0?n.prevSibling():n.nextSibling())break;if(!n.parent())return i<0?0:e.length}}class zQ{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?DQ(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?DQ(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],n=this.index[t];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],s=this.start[t]+i.positions[n];if(s>e)return this.nextStart=s,null;if(r instanceof V$){if(s==e){if(s<this.safeFrom)return null;let e=s+r.length;if(e<=this.safeTo){let t=r.prop(L$.lookAhead);if(!t||e+t<this.fragment.to)return r}}this.index[t]++,s+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(s),this.index.push(0))}else this.index[t]++,this.nextStart=s+r.length}}}class UQ{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(e=>new EQ)}getActions(e){let t=0,i=null,{parser:n}=e.p,{tokenizers:r}=n,s=n.stateSlot(e.state,3),a=e.curContext?e.curContext.hash:0,o=0;for(let l=0;l<r.length;l++){if(!(1<<l&s))continue;let n=r[l],c=this.tokens[l];if((!i||n.fallback)&&((n.contextual||c.start!=e.pos||c.mask!=s||c.context!=a)&&(this.updateCachedToken(c,n,e),c.mask=s,c.context=a),c.lookAhead>c.end+25&&(o=Math.max(c.lookAhead,o)),0!=c.value)){let r=t;if(c.extended>-1&&(t=this.addActions(e,c.extended,c.end,t)),t=this.addActions(e,c.value,c.end,t),!n.extend&&(i=c,t>r))break}}for(;this.actions.length>t;)this.actions.pop();return o&&e.setLookAhead(o),i||e.pos!=this.stream.end||(i=new EQ,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new EQ,{pos:i,p:n}=e;return t.start=i,t.end=Math.min(i+1,n.stream.end),t.value=i==n.stream.end?n.parser.eofTerm:0,t}updateCachedToken(e,t,i){let n=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(n,e),i),e.value>-1){let{parser:t}=i.p;for(let n=0;n<t.specialized.length;n++)if(t.specialized[n]==e.value){let r=t.specializers[n](this.stream.read(e.start,e.end),i);if(r>=0&&i.p.parser.dialect.allows(r>>1)){1&r?e.extended=r>>1:e.value=r>>1;break}}}else e.value=0,e.end=this.stream.clipPos(n+1)}putAction(e,t,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==e)return n;return this.actions[n++]=e,this.actions[n++]=t,this.actions[n++]=i,n}addActions(e,t,i,n){let{state:r}=e,{parser:s}=e.p,{data:a}=s;for(let o=0;o<2;o++)for(let e=s.stateSlot(r,o?2:1);;e+=3){if(65535==a[e]){if(1!=a[e+1]){0==n&&2==a[e+1]&&(n=this.putAction(FQ(a,e+2),t,i,n));break}e=FQ(a,e+2)}a[e]==t&&(n=this.putAction(FQ(a,e+1),t,i,n))}return n}}class qQ{constructor(e,t,i,n){this.parser=e,this.input=t,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new CQ(t,n),this.tokens=new UQ(e,this.stream),this.topTerm=e.top[1];let{from:r}=n[0];this.stacks=[SQ.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>4*e.bufferLength?new zQ(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e,t,i=this.stacks,n=this.minStackPos,r=this.stacks=[];if(this.bigReductionCount>300&&1==i.length){let[e]=i;for(;e.forceReduce()&&e.stack.length&&e.stack[e.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let s=0;s<i.length;s++){let a=i[s];for(;;){if(this.tokens.mainToken=null,a.pos>n)r.push(a);else{if(this.advanceStack(a,r,i))continue;{e||(e=[],t=[]),e.push(a);let i=this.tokens.getMainToken(a);t.push(i.value,i.end)}}break}}if(!r.length){let t=e&&function(e){let t=null;for(let i of e){let e=i.p.stoppedAt;(i.pos==i.p.stream.end||null!=e&&i.pos>e)&&i.p.parser.stateFlag(i.state,2)&&(!t||t.score<i.score)&&(t=i)}return t}(e);if(t)return this.stackToTree(t);if(this.parser.strict)throw new SyntaxError("No parse at "+n);this.recovering||(this.recovering=5)}if(this.recovering&&e){let i=null!=this.stoppedAt&&e[0].pos>this.stoppedAt?e[0]:this.runRecovery(e,t,r);if(i)return this.stackToTree(i.forceAll())}if(this.recovering){let e=1==this.recovering?1:3*this.recovering;if(r.length>e)for(r.sort((e,t)=>t.score-e.score);r.length>e;)r.pop();r.some(e=>e.reducePos>n)&&this.recovering--}else if(r.length>1){e:for(let e=0;e<r.length-1;e++){let t=r[e];for(let i=e+1;i<r.length;i++){let n=r[i];if(t.sameState(n)||t.buffer.length>500&&n.buffer.length>500){if(!((t.score-n.score||t.buffer.length-n.buffer.length)>0)){r.splice(e--,1);continue e}r.splice(i--,1)}}}r.length>12&&(r.sort((e,t)=>t.score-e.score),r.splice(12,r.length-12))}this.minStackPos=r[0].pos;for(let s=1;s<r.length;s++)r[s].pos<this.minStackPos&&(this.minStackPos=r[s].pos);return null}stopAt(e){if(null!=this.stoppedAt&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let n=e.pos,{parser:r}=this;LQ&&this.stackID(e);if(null!=this.stoppedAt&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let t=e.curContext&&e.curContext.tracker.strict,i=t?e.curContext.hash:0;for(let s=this.fragments.nodeAt(n);s;){let n=this.parser.nodeSet.types[s.type.id]==s.type?r.getGoto(e.state,s.type.id):-1;if(n>-1&&s.length&&(!t||(s.prop(L$.contextHash)||0)==i))return e.useNode(s,n),!0;if(!(s instanceof V$)||0==s.children.length||s.positions[0]>0)break;let a=s.children[0];if(!(a instanceof V$&&0==s.positions[0]))break;s=a}}let s=r.stateSlot(e.state,4);if(s>0)return e.reduce(s),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let o=0;o<a.length;){let r=a[o++],s=a[o++],l=a[o++],c=o==a.length||!i,h=c?e:e.split(),u=this.tokens.mainToken;if(h.apply(r,s,u?u.start:h.pos,l),c)return!0;h.pos>n?t.push(h):i.push(h)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return XQ(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let s=0;s<e.length;s++){let a=e[s],o=t[s<<1],l=t[1+(s<<1)],c=LQ?this.stackID(a)+" -> ":"";if(a.deadEnd){if(r)continue;if(r=!0,a.restart(),this.advanceFully(a,i))continue}let h=a.split(),u=c;for(let e=0;e<10&&h.forceReduce();e++){if(this.advanceFully(h,i))break;LQ&&(u=this.stackID(h)+" -> ")}for(let e of a.recoverByInsert(o))this.advanceFully(e,i);this.stream.end>a.pos?(l==a.pos&&(l++,o=0),a.recoverByDelete(o,l),XQ(a,i)):(!n||n.score<h.score)&&(n=h)}return n}stackToTree(e){return e.close(),V$.build({buffer:TQ.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(ZQ||(ZQ=new WeakMap)).get(e);return t||ZQ.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function XQ(e,t){for(let i=0;i<t.length;i++){let n=t[i];if(n.pos==e.pos&&n.sameState(e))return void(t[i].score<e.score&&(t[i]=e))}t.push(e)}class BQ{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||0==this.disabled[e]}}const WQ=e=>e;class VQ extends pE{constructor(e){if(super(),this.wrappers=[],14!=e.version)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let a=0;a<e.repeatNodeCount;a++)t.push("");let i=Object.keys(e.topRules).map(t=>e.topRules[t][1]),n=[];for(let a=0;a<t.length;a++)n.push([]);function r(e,t,i){n[e].push([t,t.deserialize(String(i))])}if(e.nodeProps)for(let a of e.nodeProps){let e=a[0];"string"==typeof e&&(e=L$[e]);for(let t=1;t<a.length;){let i=a[t++];if(i>=0)r(i,e,a[t++]);else{let n=a[t+-i];for(let s=-i;s>0;s--)r(a[t++],e,n);t++}}}this.nodeSet=new U$(t.map((t,r)=>z$.define({name:r>=this.minRepeatTerm?void 0:t,id:r,props:n[r],top:i.indexOf(r)>-1,error:0==r,skipped:e.skippedNodes&&e.skippedNodes.indexOf(r)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=j$;let s=$Q(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let a=0;a<this.specializerSpecs.length;a++)this.specialized[a]=this.specializerSpecs[a].term;this.specializers=this.specializerSpecs.map(YQ),this.states=$Q(e.states,Uint32Array),this.data=$Q(e.stateData),this.goto=$Q(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(e=>"number"==typeof e?new RQ(s,e):e),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let n=new qQ(this,e,t,i);for(let r of this.wrappers)n=r(n,e,t,i);return n}getGoto(e,t,i=!1){let n=this.goto;if(t>=n[0])return-1;for(let r=n[t+1];;){let t=n[r++],s=1&t,a=n[r++];if(s&&i)return a;for(let i=r+(t>>1);r<i;r++)if(n[r]==e)return a;if(s)return-1}}hasAction(e,t){let i=this.data;for(let n=0;n<2;n++)for(let r,s=this.stateSlot(e,n?2:1);;s+=3){if(65535==(r=i[s])){if(1!=i[s+1]){if(2==i[s+1])return FQ(i,s+2);break}r=i[s=FQ(i,s+2)]}if(r==t||0==r)return FQ(i,s+1)}return 0}stateSlot(e,t){return this.states[6*e+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,e=>e==t||null)}allActions(e,t){let i=this.stateSlot(e,4),n=i?t(i):void 0;for(let r=this.stateSlot(e,1);null==n;r+=3){if(65535==this.data[r]){if(1!=this.data[r+1])break;r=FQ(this.data,r+2)}n=t(FQ(this.data,r+1))}return n}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=FQ(this.data,i+2)}if(!(1&this.data[i+2])){let e=this.data[i+1];t.some((t,i)=>1&i&&t==e)||t.push(this.data[i],e)}}return t}configure(e){let t=Object.assign(Object.create(VQ.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(t=>{let i=e.tokenizers.find(e=>e.from==t);return i?i.to:t})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=e.specializers.find(e=>e.from==i.external);if(!r)return i;let s=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[n]=YQ(s),s})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),null!=e.strict&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),null!=e.bufferLength&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return null==t?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let e=t.indexOf(r);e>=0&&(i[e]=!0)}let n=null;for(let r=0;r<t.length;r++)if(!i[r])for(let e,i=this.dialects[t[r]];65535!=(e=this.data[i++]);)(n||(n=new Uint8Array(this.maxTerm+1)))[e]=1;return new BQ(e,i,n)}static deserialize(e){return new VQ(e)}}function FQ(e,t){return e[t]|e[t+1]<<16}function YQ(e){if(e.external){let t=e.extend?1:0;return(i,n)=>e.external(i,n)<<1|t}return e.get}const GQ=[9,10,11,12,13,32,133,160,5760,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8232,8233,8239,8287,12288],HQ=new class{constructor(e){this.start=e.start,this.shift=e.shift||WQ,this.reduce=e.reduce||WQ,this.reuse=e.reuse||WQ,this.hash=e.hash||(()=>0),this.strict=!1!==e.strict}}({start:!1,shift:(e,t)=>5==t||6==t||320==t?e:321==t,strict:!1}),KQ=new IQ((e,t)=>{let{next:i}=e;(125==i||-1==i||t.context)&&e.acceptToken(318)},{contextual:!0,fallback:!0}),JQ=new IQ((e,t)=>{let i,{next:n}=e;GQ.indexOf(n)>-1||(47!=n||47!=(i=e.peek(1))&&42!=i)&&(125==n||59==n||-1==n||t.context||e.acceptToken(316))},{contextual:!0}),eI=new IQ((e,t)=>{91!=e.next||t.context||e.acceptToken(317)},{contextual:!0}),tI=new IQ((e,t)=>{let{next:i}=e;if(43==i||45==i){if(e.advance(),i==e.next){e.advance();let i=!t.context&&t.canShift(1);e.acceptToken(i?1:2)}}else 63==i&&46==e.peek(1)&&(e.advance(),e.advance(),(e.next<48||e.next>57)&&e.acceptToken(3))},{contextual:!0});function iI(e,t){return e>=65&&e<=90||e>=97&&e<=122||95==e||e>=192||!t&&e>=48&&e<=57}const nI=new IQ((e,t)=>{if(60!=e.next||!t.dialectEnabled(0))return;if(e.advance(),47==e.next)return;let i=0;for(;GQ.indexOf(e.next)>-1;)e.advance(),i++;if(iI(e.next,!0)){for(e.advance(),i++;iI(e.next,!1);)e.advance(),i++;for(;GQ.indexOf(e.next)>-1;)e.advance(),i++;if(44==e.next)return;for(let t=0;;t++){if(7==t){if(!iI(e.next,!0))return;break}if(e.next!="extends".charCodeAt(t))break;e.advance(),i++}}e.acceptToken(4,-i)}),rI=yE({"get set async static":DE.modifier,"for while do if else switch try catch finally return throw break continue default case defer":DE.controlKeyword,"in of await yield void typeof delete instanceof as satisfies":DE.operatorKeyword,"let var const using function class extends":DE.definitionKeyword,"import export from":DE.moduleKeyword,"with debugger new":DE.keyword,TemplateString:DE.special(DE.string),super:DE.atom,BooleanLiteral:DE.bool,this:DE.self,null:DE.null,Star:DE.modifier,VariableName:DE.variableName,"CallExpression/VariableName TaggedTemplateExpression/VariableName":DE.function(DE.variableName),VariableDefinition:DE.definition(DE.variableName),Label:DE.labelName,PropertyName:DE.propertyName,PrivatePropertyName:DE.special(DE.propertyName),"CallExpression/MemberExpression/PropertyName":DE.function(DE.propertyName),"FunctionDeclaration/VariableDefinition":DE.function(DE.definition(DE.variableName)),"ClassDeclaration/VariableDefinition":DE.definition(DE.className),"NewExpression/VariableName":DE.className,PropertyDefinition:DE.definition(DE.propertyName),PrivatePropertyDefinition:DE.definition(DE.special(DE.propertyName)),UpdateOp:DE.updateOperator,"LineComment Hashbang":DE.lineComment,BlockComment:DE.blockComment,Number:DE.number,String:DE.string,Escape:DE.escape,ArithOp:DE.arithmeticOperator,LogicOp:DE.logicOperator,BitOp:DE.bitwiseOperator,CompareOp:DE.compareOperator,RegExp:DE.regexp,Equals:DE.definitionOperator,Arrow:DE.function(DE.punctuation),": Spread":DE.punctuation,"( )":DE.paren,"[ ]":DE.squareBracket,"{ }":DE.brace,"InterpolationStart InterpolationEnd":DE.special(DE.brace),".":DE.derefOperator,", ;":DE.separator,"@":DE.meta,TypeName:DE.typeName,TypeDefinition:DE.definition(DE.typeName),"type enum interface implements namespace module declare":DE.definitionKeyword,"abstract global Privacy readonly override":DE.modifier,"is keyof unique infer asserts":DE.operatorKeyword,JSXAttributeValue:DE.attributeValue,JSXText:DE.content,"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag":DE.angleBracket,"JSXIdentifier JSXNameSpacedName":DE.tagName,"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName":DE.attributeName,"JSXBuiltin/JSXIdentifier":DE.standard(DE.tagName)}),sI={__proto__:null,export:20,as:25,from:33,default:36,async:41,function:42,in:52,out:55,const:56,extends:60,this:64,true:72,false:72,null:84,void:88,typeof:92,super:108,new:142,delete:154,yield:163,await:167,class:172,public:235,private:235,protected:235,readonly:237,instanceof:256,satisfies:259,import:292,keyof:349,unique:353,infer:359,asserts:395,is:397,abstract:417,implements:419,type:421,let:424,var:426,using:429,interface:435,enum:439,namespace:445,module:447,declare:451,global:455,defer:471,for:476,of:485,while:488,with:492,do:496,if:500,else:502,switch:506,case:512,try:518,catch:522,finally:526,return:530,throw:534,break:538,continue:542,debugger:546},aI={__proto__:null,async:129,get:131,set:133,declare:195,public:197,private:197,protected:197,static:199,abstract:201,override:203,readonly:209,accessor:211,new:401},oI={__proto__:null,"<":193},lI=VQ.deserialize({version:14,states:"$F|Q%TQlOOO%[QlOOO'_QpOOP(lO`OOO*zQ!0MxO'#CiO+RO#tO'#CjO+aO&jO'#CjO+oO#@ItO'#DaO.QQlO'#DgO.bQlO'#DrO%[QlO'#DzO0fQlO'#ESOOQ!0Lf'#E['#E[O1PQ`O'#EXOOQO'#Ep'#EpOOQO'#Il'#IlO1XQ`O'#GsO1dQ`O'#EoO1iQ`O'#EoO3hQ!0MxO'#JrO6[Q!0MxO'#JsO6uQ`O'#F]O6zQ,UO'#FtOOQ!0Lf'#Ff'#FfO7VO7dO'#FfO9XQMhO'#F|O9`Q`O'#F{OOQ!0Lf'#Js'#JsOOQ!0Lb'#Jr'#JrO9eQ`O'#GwOOQ['#K_'#K_O9pQ`O'#IYO9uQ!0LrO'#IZOOQ['#J`'#J`OOQ['#I_'#I_Q`QlOOQ`QlOOO9}Q!L^O'#DvO:UQlO'#EOO:]QlO'#EQO9kQ`O'#GsO:dQMhO'#CoO:rQ`O'#EnO:}Q`O'#EyO;hQMhO'#FeO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R9`7Td#^W#W#Z%h(T(^*Y+Z.T/mr#gZm#h#i#l%e(h(i(j+^.Z.[.]._3[3]7TS*]$x*bQ/t*^Q2U,oQ2l-VQ4`/pQ6q2dQ7s4aQ9W6rT=m'X+[V#aW%h*YU#`W%h*YS(U#W(^U(Z#Z+Z/mS-['X+[T.O(T.TV'^!e%i*ZQ$lfR)x$qT)m$l)nR4V/UT*_$x*bT*h${*YQ0w+fQ1g,VQ3_.fQ5t1iQ6P1qQ7X3cQ8r6SQ9c7WQ:^8qQ:p9bQ;Z:`Q;c:rQ;n;[R;q;dnqOXst!Z#d%m&r&t&u&w,s,x2[2_Q&l!VR,h&itmOXst!U!V!Z#d%m&i&r&t&u&w,s,x2[2_R,o&oT%lm,oR1k,XR,g&gQ&U|S+}&V&WR1^,OR+s&PT&p!W&sT&q!W&sT2^,x2_",nodeNames:"⚠ ArithOp ArithOp ?. JSXStartTag LineComment BlockComment Script Hashbang ExportDeclaration export Star as VariableName String Escape from ; default FunctionDeclaration async function VariableDefinition > < TypeParamList in out const TypeDefinition extends ThisType this LiteralType ArithOp Number BooleanLiteral TemplateType InterpolationEnd Interpolation InterpolationStart NullType null VoidType void TypeofType typeof MemberExpression . PropertyName [ TemplateString Escape Interpolation super RegExp ] ArrayExpression Spread , } { ObjectExpression Property async get set PropertyDefinition Block : NewTarget new NewExpression ) ( ArgList UnaryExpression delete LogicOp BitOp YieldExpression yield AwaitExpression await ParenthesizedExpression ClassExpression class ClassBody MethodDeclaration Decorator @ MemberExpression PrivatePropertyName CallExpression TypeArgList CompareOp < declare Privacy static abstract override PrivatePropertyDefinition PropertyDeclaration readonly accessor Optional TypeAnnotation Equals StaticBlock FunctionExpression ArrowFunction ParamList ParamList ArrayPattern ObjectPattern PatternProperty Privacy readonly Arrow MemberExpression BinaryExpression ArithOp ArithOp ArithOp ArithOp BitOp CompareOp instanceof satisfies CompareOp BitOp BitOp BitOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression UpdateOp PostfixExpression CallExpression InstantiationExpression TaggedTemplateExpression DynamicImport import ImportMeta JSXElement JSXSelfCloseEndTag JSXSelfClosingTag JSXIdentifier JSXBuiltin JSXIdentifier JSXNamespacedName JSXMemberExpression JSXSpreadAttribute JSXAttribute JSXAttributeValue JSXEscape JSXEndTag JSXOpenTag JSXFragmentTag JSXText JSXEscape JSXStartCloseTag JSXCloseTag PrefixCast < ArrowFunction TypeParamList SequenceExpression InstantiationExpression KeyofType keyof UniqueType unique ImportType InferredType infer TypeName ParenthesizedType FunctionSignature ParamList NewSignature IndexedType TupleType Label ArrayType ReadonlyType ObjectType MethodType PropertyType IndexSignature PropertyDefinition CallSignature TypePredicate asserts is NewSignature new UnionType LogicOp IntersectionType LogicOp ConditionalType ParameterizedType ClassDeclaration abstract implements type VariableDeclaration let var using TypeAliasDeclaration InterfaceDeclaration interface EnumDeclaration enum EnumBody NamespaceDeclaration namespace module AmbientDeclaration declare GlobalDeclaration global ClassDeclaration ClassBody AmbientFunctionDeclaration ExportGroup VariableName VariableName ImportDeclaration defer ImportGroup ForStatement for ForSpec ForInSpec ForOfSpec of WhileStatement while WithStatement with DoStatement do IfStatement if else SwitchStatement switch SwitchBody CaseLabel case DefaultLabel TryStatement try CatchClause catch FinallyClause finally ReturnStatement return ThrowStatement throw BreakStatement break ContinueStatement continue DebuggerStatement debugger LabeledStatement ExpressionStatement SingleExpression SingleClassItem",maxTerm:380,context:HQ,nodeProps:[["isolate",-8,5,6,14,37,39,51,53,55,""],["group",-26,9,17,19,68,207,211,215,216,218,221,224,234,237,243,245,247,249,252,258,264,266,268,270,272,274,275,"Statement",-34,13,14,32,35,36,42,51,54,55,57,62,70,72,76,80,82,84,85,110,111,120,121,136,139,141,142,143,144,145,147,148,167,169,171,"Expression",-23,31,33,37,41,43,45,173,175,177,178,180,181,182,184,185,186,188,189,190,201,203,205,206,"Type",-3,88,103,109,"ClassItem"],["openedBy",23,"<",38,"InterpolationStart",56,"[",60,"{",73,"(",160,"JSXStartCloseT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#jS!Q![#g!c!i#g#T#Z#g#q#r!P~#yP;=`<%l!P~$RO(c~~",141,340),new QQ("j~RQYZXz{^~^O(Q~~aP!P!Qd~iO(R~~",25,323)],topRules:{Script:[0,7],SingleExpression:[1,276],SingleClassItem:[2,277]},dialects:{jsx:0,ts:15175},dynamicPrecedences:{80:1,82:1,94:1,169:1,199:1},specialized:[{term:327,get:e=>sI[e]||-1},{term:343,get:e=>aI[e]||-1},{term:95,get:e=>oI[e]||-1}],tokenPrec:15201});class cI{constructor(e,t,i,n){this.state=e,this.pos=t,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=FE(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),n=t.text.slice(i-t.from,this.pos-t.from),r=n.search(fI(e,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return null==this.abortListeners}addEventListener(e,t,i){"abort"==e&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function hI(e){let t=Object.keys(e).join(""),i=/\w/.test(t);return i&&(t=t.replace(/\w/g,"")),`[${i?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function uI(e){let t=e.map(e=>"string"==typeof e?{label:e}:e),[i,n]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:function(e){let t=Object.create(null),i=Object.create(null);for(let{label:r}of e){t[r[0]]=!0;for(let e=1;e<r.length;e++)i[r[e]]=!0}let n=hI(t)+hI(i)+"*$";return[new RegExp("^"+n),new RegExp(n)]}(t);return e=>{let r=e.matchBefore(n);return r||e.explicit?{from:r?r.from:e.pos,options:t,validFor:i}:null}}class dI{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function pI(e){return e.selection.main.from}function fI(e,t){var i;let{source:n}=e,r=t&&"^"!=n[0],s="$"!=n[n.length-1];return r||s?new RegExp(`${r?"^":""}(?:${n})${s?"$":""}`,null!==(i=e.flags)&&void 0!==i?i:e.ignoreCase?"i":""):e}const mI=Hw.define();function gI(e,t,i,n){let{main:r}=e.selection,s=i-r.from,a=n-r.from;return{...e.changeByRange(o=>{if(o!=r&&i!=n&&e.sliceDoc(o.from+s,o.from+a)!=e.sliceDoc(i,n))return{range:o};let l=e.toText(t);return{changes:{from:o.from+s,to:n==r.from?o.to:o.from+a,insert:l},range:ww.cursor(o.from+s+l.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const OI=new WeakMap;function vI(e){if(!Array.isArray(e))return e;let t=OI.get(e);return t||OI.set(e,t=uI(e)),t}const yI=e_.define(),bI=e_.define();class wI{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=ow(e,t),n=cw(i);this.chars.push(i);let r=e.slice(t,t+n),s=r.toUpperCase();this.folded.push(ow(s==r?r.toLowerCase():s,0)),t+=n}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(0==this.pattern.length)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:n,precise:r,byWord:s}=this;if(1==t.length){let n=ow(e,0),r=cw(n),s=r==e.length?0:-100;if(n==t[0]);else{if(n!=i[0])return null;s+=-200}return this.ret(s,[0,r])}let a=e.indexOf(this.pattern);if(0==a)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let o=t.length,l=0;if(a<0){for(let r=0,s=Math.min(e.length,200);r<s&&l<o;){let s=ow(e,r);s!=t[l]&&s!=i[l]||(n[l++]=r),r+=cw(s)}if(l<o)return null}let c=0,h=0,u=!1,d=0,p=-1,f=-1,m=/[a-z]/.test(e),g=!0;for(let O=0,v=Math.min(e.length,200),y=0;O<v&&h<o;){let n=ow(e,O);a<0&&(c<o&&n==t[c]&&(r[c++]=O),d<o&&(n==t[d]||n==i[d]?(0==d&&(p=O),f=O+1,d++):d=0));let l,v=n<255?n>=48&&n<=57||n>=97&&n<=122?2:n>=65&&n<=90?1:0:(l=lw(n))!=l.toLowerCase()?1:l!=l.toUpperCase()?2:0;(!O||1==v&&m||0==y&&0!=v)&&(t[h]==n||i[h]==n&&(u=!0)?s[h++]=O:s.length&&(g=!1)),y=v,O+=cw(n)}return h==o&&0==s[0]&&g?this.result((u?-200:0)-100,s,e):d==o&&0==p?this.ret(-200-e.length+(f==e.length?0:-100),[0,f]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):d==o?this.ret(-900-e.length,[p,f]):h==o?this.result((u?-200:0)-100-700+(g?0:-1100),s,e):2==t.length?null:this.result((n[0]?-700:0)-200-1100,n,e)}result(e,t,i){let n=[],r=0;for(let s of t){let e=s+(this.astral?cw(ow(i,s)):1);r&&n[r-1]==s?n[r-1]=e:(n[r++]=s,n[r++]=e)}return this.ret(e-i.length,n)}}class _I{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return null==i?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const xI=Sw.define({combine:e=>p_(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:kI,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>SI(e(i),t(i)),optionClass:(e,t)=>i=>SI(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})});function SI(e,t){return e?t?e+" "+t:e:t}function kI(e,t,i,n,r,s){let a,o,l=e.textDirection==zx.RTL,c=l,h=!1,u="top",d=t.left-r.left,p=r.right-t.right,f=n.right-n.left,m=n.bottom-n.top;if(c&&d<Math.min(f,p)?c=!1:!c&&p<Math.min(f,d)&&(c=!0),f<=(c?d:p))a=Math.max(r.top,Math.min(i.top,r.bottom-m))-t.top,o=Math.min(400,c?d:p);else{h=!0,o=Math.min(400,(l?t.right:r.right-t.left)-30);let e=r.bottom-t.bottom;e>=m||e>t.top?a=i.bottom-t.top:(u="bottom",a=t.bottom-i.top)}return{style:`${u}: ${a/((t.bottom-t.top)/s.offsetHeight)}px; max-width: ${o/((t.right-t.left)/s.offsetWidth)}px`,class:"cm-completionInfo-"+(h?l?"left-narrow":"right-narrow":c?"left":"right")}}const PI=e_.define();function TI(e,t,i){if(e<=i)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let e=Math.floor(t/i);return{from:e*i,to:(e+1)*i}}let n=Math.floor((e-t)/i);return{from:e-(n+1)*i,to:e-n*i}}class $I{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:e=>this.placeInfo(e),key:this},this.space=null,this.currentClass="";let n=e.state.field(t),{options:r,selected:s}=n.open,a=e.state.facet(xI);this.optionContent=function(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(e){let t=document.createElement("div");return t.classList.add("cm-completionIcon"),e.type&&t.classList.add(...e.type.split(/\s+/g).map(e=>"cm-completionIcon-"+e)),t.setAttribute("aria-hidden","true"),t},position:20}),t.push({render(e,t,i,n){let r=document.createElement("span");r.className="cm-completionLabel";let s=e.displayLabel||e.label,a=0;for(let o=0;o<n.length;){let e=n[o++],t=n[o++];e>a&&r.appendChild(document.createTextNode(s.slice(a,e)));let i=r.appendChild(document.createElement("span"));i.appendChild(document.createTextNode(s.slice(e,t))),i.className="cm-completionMatchedText",a=t}return a<s.length&&r.appendChild(document.createTextNode(s.slice(a))),r},position:50},{render(e){if(!e.detail)return null;let t=document.createElement("span");return t.className="cm-completionDetail",t.textContent=e.detail,t},position:80}),t.sort((e,t)=>e.position-t.position).map(e=>e.render)}(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=TI(r.length,s,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=e.state.field(t).open;for(let t,r=i.target;r&&r!=this.dom;r=r.parentNode)if("LI"==r.nodeName&&(t=/-(\d+)$/.exec(r.id))&&+t[1]<n.length)return this.applyCompletion(e,n[+t[1]]),void i.preventDefault();if(i.target==this.list){let t=this.list.classList.contains("cm-completionListIncompleteTop")&&i.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&i.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;null!=t&&(e.dispatch({effects:PI.of(t)}),i.preventDefault())}}),this.dom.addEventListener("focusout",t=>{let i=e.state.field(this.stateField,!1);i&&i.tooltip&&e.state.facet(xI).closeOnBlur&&t.relatedTarget!=e.contentDOM&&e.dispatch({effects:bI.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=n){let{options:r,selected:s,disabled:a}=i.open;n.open&&n.open.options==r||(this.range=TI(r.length,s,e.state.facet(xI).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),a!=(null===(t=n.open)||void 0===t?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let e of this.currentClass.split(" "))e&&this.dom.classList.remove(e);for(let e of t.split(" "))e&&this.dom.classList.add(e);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=TI(t.options.length,t.selected,this.view.state.facet(xI).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:n}=t.options[t.selected],{info:r}=n;if(!r)return;let s="string"==typeof r?document.createTextNode(r):r(n);if(!s)return;"then"in s?s.then(t=>{t&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(t,n)}).catch(e=>wS(this.view.state,e,"completion info")):(this.addInfoPane(s,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=e.nodeType)i.appendChild(e),this.infoDestroy=null;else{let{dom:t,destroy:n}=e;i.appendChild(t),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby")):n--;return t&&function(e,t){let i=e.getBoundingClientRect(),n=t.getBoundingClientRect(),r=i.height/e.offsetHeight;n.top<i.top?e.scrollTop-=(i.top-n.top)/r:n.bottom>i.bottom&&(e.scrollTop+=(n.bottom-i.bottom)/r)}(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=e.getBoundingClientRect(),r=this.space;if(!r){let e=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:e.clientWidth,bottom:e.clientHeight}}return n.top>Math.min(r.bottom,t.bottom)-10||n.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(xI).positionInfo(this.view,t,n,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const n=document.createElement("ul");n.id=t,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",e=>{e.target==n&&e.preventDefault()});let r=null;for(let s=i.from;s<i.to;s++){let{completion:a,match:o}=e[s],{section:l}=a;if(l){let e="string"==typeof l?l:l.name;if(e!=r&&(s>i.from||0==i.from))if(r=e,"string"!=typeof l&&l.header)n.appendChild(l.header(l));else{n.appendChild(document.createElement("completion-section")).textContent=e}}const c=n.appendChild(document.createElement("li"));c.id=t+"-"+s,c.setAttribute("role","option");let h=this.optionClass(a);h&&(c.className=h);for(let e of this.optionContent){let t=e(a,this.view.state,this.view,o);t&&c.appendChild(t)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function EI(e,t){return i=>new $I(i,e,t)}function AI(e){return 100*(e.boost||0)+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}class CI{constructor(e,t,i,n,r,s){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=s}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new CI(this.options,jI(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,n,r,s){if(n&&!s&&e.some(e=>e.isPending))return n.setDisabled();let a=function(e,t){let i=[],n=null,r=null,s=e=>{i.push(e);let{section:t}=e.completion;if(t){n||(n=[]);let e="string"==typeof t?t:t.name;n.some(t=>t.name==e)||n.push("string"==typeof t?{name:e}:t)}},a=t.facet(xI);for(let h of e)if(h.hasResult()){let e=h.result.getMatch;if(!1===h.result.filter)for(let t of h.result.options)s(new dI(t,h.source,e?e(t):[],1e9-i.length));else{let i,n=t.sliceDoc(h.from,h.to),o=a.filterStrict?new _I(n):new wI(n);for(let t of h.result.options)if(i=o.match(t.label)){let n=t.displayLabel?e?e(t,i.matched):[]:i.matched,a=i.score+(t.boost||0);if(s(new dI(t,h.source,n,a)),"object"==typeof t.section&&"dynamic"===t.section.rank){let{name:e}=t.section;r||(r=Object.create(null)),r[e]=Math.max(a,r[e]||-1e9)}}}}if(n){let e=Object.create(null),t=0,s=(e,t)=>("dynamic"===e.rank&&"dynamic"===t.rank?r[t.name]-r[e.name]:0)||("number"==typeof e.rank?e.rank:1e9)-("number"==typeof t.rank?t.rank:1e9)||(e.name<t.name?-1:1);for(let i of n.sort(s))t-=1e5,e[i.name]=t;for(let n of i){let{section:t}=n.completion;t&&(n.score+=e["string"==typeof t?t:t.name])}}let o=[],l=null,c=a.compareCompletions;for(let h of i.sort((e,t)=>t.score-e.score||c(e.completion,t.completion))){let e=h.completion;!l||l.label!=e.label||l.detail!=e.detail||null!=l.type&&null!=e.type&&l.type!=e.type||l.apply!=e.apply||l.boost!=e.boost?o.push(h):AI(h.completion)>AI(l)&&(o[o.length-1]=h),l=h.completion}return o}(e,t);if(!a.length)return n&&e.some(e=>e.isPending)?n.setDisabled():null;let o=t.facet(xI).selectOnOpen?0:-1;if(n&&n.selected!=o&&-1!=n.selected){let e=n.options[n.selected].completion;for(let t=0;t<a.length;t++)if(a[t].completion==e){o=t;break}}return new CI(a,jI(i,o),{pos:e.reduce((e,t)=>t.hasResult()?Math.min(e,t.from):e,1e8),create:qI,above:r.aboveCursor},n?n.timestamp:Date.now(),o,!1)}map(e){return new CI(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new CI(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class RI{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new RI(MI,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(e){let{state:t}=e,i=t.facet(xI),n=(i.override||t.languageDataAt("autocomplete",pI(t)).map(vI)).map(t=>(this.active.find(e=>e.source==t)||new LI(t,this.active.some(e=>0!=e.state)?1:0)).update(e,i));n.length==this.active.length&&n.every((e,t)=>e==this.active[t])&&(n=this.active);let r=this.open,s=e.effects.some(e=>e.is(DI));r&&e.docChanged&&(r=r.map(e.changes)),e.selection||n.some(t=>t.hasResult()&&e.changes.touchesRange(t.from,t.to))||!function(e,t){if(e==t)return!0;for(let i=0,n=0;;){for(;i<e.length&&!e[i].hasResult();)i++;for(;n<t.length&&!t[n].hasResult();)n++;let r=i==e.length,s=n==t.length;if(r||s)return r==s;if(e[i++].result!=t[n++].result)return!1}}(n,this.active)||s?r=CI.build(n,t,this.id,r,i,s):r&&r.disabled&&!n.some(e=>e.isPending)&&(r=null),!r&&n.every(e=>!e.isPending)&&n.some(e=>e.hasResult())&&(n=n.map(e=>e.hasResult()?new LI(e.source,0):e));for(let a of e.effects)a.is(PI)&&(r=r&&r.setSelected(a.value,this.id));return n==this.active&&r==this.open?this:new RI(n,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?QI:II}}const QI={"aria-autocomplete":"list"},II={};function jI(e,t){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(i["aria-activedescendant"]=e+"-"+t),i}const MI=[];function NI(e,t){if(e.isUserEvent("input.complete")){let i=e.annotation(mI);if(i&&t.activateOnCompletion(i))return 12}let i=e.isUserEvent("input.type");return i&&t.activateOnTyping?5:i?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class LI{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(e,t){let i=NI(e,t),n=this;(8&i||16&i&&this.touches(e))&&(n=new LI(n.source,0)),4&i&&0==n.state&&(n=new LI(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(yI))n=new LI(n.source,1,r.value);else if(r.is(bI))n=new LI(n.source,0);else if(r.is(DI))for(let e of r.value)e.source==n.source&&(n=e);return n}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(pI(e.state))}}class ZI extends LI{constructor(e,t,i,n,r,s){super(e,3,t),this.limit=i,this.result=n,this.from=r,this.to=s}hasResult(){return!0}updateFor(e,t){var i;if(!(3&t))return this.map(e.changes);let n=this.result;n.map&&!e.changes.empty&&(n=n.map(n,e.changes));let r=e.changes.mapPos(this.from),s=e.changes.mapPos(this.to,1),a=pI(e.state);if(a>s||!n||2&t&&(pI(e.startState)==this.from||a<this.limit))return new LI(this.source,4&t?1:0);let o=e.changes.mapPos(this.limit);return function(e,t,i,n){if(!e)return!1;let r=t.sliceDoc(i,n);return"function"==typeof e?e(r,i,n,t):fI(e,!0).test(r)}(n.validFor,e.state,r,s)?new ZI(this.source,this.explicit,o,n,r,s):n.update&&(n=n.update(n,r,s,new cI(e.state,a,!1)))?new ZI(this.source,this.explicit,o,n,n.from,null!==(i=n.to)&&void 0!==i?i:pI(e.state)):new LI(this.source,1,this.explicit)}map(e){if(e.empty)return this;return(this.result.map?this.result.map(this.result,e):this.result)?new ZI(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new LI(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}const DI=e_.define({map:(e,t)=>e.map(e=>e.map(t))}),zI=Cw.define({create:()=>RI.start(),update:(e,t)=>e.update(t),provide:e=>[YT.from(e,e=>e.tooltip),GP.contentAttributes.from(e,e=>e.attrs)]});function UI(e,t){const i=t.completion.apply||t.completion.label;let n=e.state.field(zI).active.find(e=>e.source==t.source);return n instanceof ZI&&("string"==typeof i?e.dispatch({...gI(e.state,i,n.from,n.to),annotations:mI.of(t.completion)}):i(e,t.completion,n.from,n.to),!0)}const qI=EI(zI,UI);function XI(e,t="option"){return i=>{let n=i.state.field(zI,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp<i.state.facet(xI).interactionDelay)return!1;let r,s=1;"page"==t&&(r=i$(i,n.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:a}=n.open.options,o=n.open.selected>-1?n.open.selected+s*(e?1:-1):e?0:a-1;return o<0?o="page"==t?0:a-1:o>=a&&(o="page"==t?a-1:0),i.dispatch({effects:PI.of(o)}),!0}}const BI=e=>!!e.state.field(zI,!1)&&(e.dispatch({effects:yI.of(!0)}),!0);class WI{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const VI=kS.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(zI).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(zI),i=e.state.facet(xI);if(!e.selectionSet&&!e.docChanged&&e.startState.field(zI)==t)return;let n=e.transactions.some(e=>{let t=NI(e,i);return 8&t||(e.selection||e.docChanged)&&!(3&t)});for(let a=0;a<this.running.length;a++){let t=this.running[a];if(n||t.context.abortOnDocChange&&e.docChanged||t.updates.length+e.transactions.length>50&&Date.now()-t.time>1e3){for(let e of t.context.abortListeners)try{e()}catch(s){wS(this.view.state,s)}t.context.abortListeners=null,this.running.splice(a--,1)}else t.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(e=>e.effects.some(e=>e.is(yI)))&&(this.pendingStart=!0);let r=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(e=>e.isPending&&!this.running.some(t=>t.active.source==e.source))?setTimeout(()=>this.startUpdate(),r):-1,0!=this.composing)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:2==this.composing&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(zI);for(let i of t.active)i.isPending&&!this.running.some(e=>e.active.source==i.source)&&this.startQuery(i);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(xI).updateSyncTime))}startQuery(e){let{state:t}=this.view,i=pI(t),n=new cI(t,i,e.explicit,this.view),r=new WI(e,n);this.running.push(r),Promise.resolve(e.source(n)).then(e=>{r.context.aborted||(r.done=e||null,this.scheduleAccept())},e=>{this.view.dispatch({effects:bI.of(null)}),wS(this.view.state,e)})}scheduleAccept(){this.running.every(e=>void 0!==e.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(xI).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],i=this.view.state.facet(xI),n=this.view.state.field(zI);for(let r=0;r<this.running.length;r++){let s=this.running[r];if(void 0===s.done)continue;if(this.running.splice(r--,1),s.done){let n=pI(s.updates.length?s.updates[0].startState:this.view.state),r=Math.min(n,s.done.from+(s.active.explicit?0:1)),a=new ZI(s.active.source,s.active.explicit,r,s.done,s.done.from,null!==(e=s.done.to)&&void 0!==e?e:n);for(let e of s.updates)a=a.update(e,i);if(a.hasResult()){t.push(a);continue}}let a=n.active.find(e=>e.source==s.active.source);if(a&&a.isPending)if(null==s.done){let e=new LI(s.active.source,0);for(let t of s.updates)e=e.update(t,i);e.isPending||t.push(e)}else this.startQuery(a)}(t.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:DI.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(zI,!1);if(t&&t.tooltip&&this.view.state.facet(xI).closeOnBlur){let i=t.open&&i$(this.view,t.open.tooltip);i&&i.dom.contains(e.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:bI.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:yI.of(!1)}),20),this.composing=0}}}),FI="object"==typeof navigator&&/Win/.test(navigator.platform),YI=Nw.highest(GP.domEventHandlers({keydown(e,t){let i=t.state.field(zI,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||e.key.length>1||e.ctrlKey&&(!FI||!e.altKey)||e.metaKey)return!1;let n=i.open.options[i.open.selected],r=i.active.find(e=>e.source==n.source),s=n.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(e.key)>-1&&UI(t,n),!1}})),GI=GP.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class HI{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class KI{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,uw.TrackDel),i=e.mapPos(this.to,1,uw.TrackDel);return null==t||null==i?null:new KI(this.field,t,i)}}class JI{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),s=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let i=s,r=/^\t*/.exec(a)[0].length;for(let t=0;t<r;t++)i+=e.facet(aA);n.push(t+i.length-r),a=i+a.slice(r)}i.push(a),t+=a.length+1}return{text:i,ranges:this.fieldPositions.map(e=>new KI(e.field,n[e.line]+e.from,n[e.line]+e.to))}}static parse(e){let t,i=[],n=[],r=[];for(let s of e.split(/\r\n?|\n/)){for(;t=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(s);){let e=t[1]?+t[1]:null,a=t[2]||t[3]||"",o=-1,l=a.replace(/\\[{}]/g,e=>e[1]);for(let t=0;t<i.length;t++)(null!=e?i[t].seq==e:l&&i[t].name==l)&&(o=t);if(o<0){let t=0;for(;t<i.length&&(null==e||null!=i[t].seq&&i[t].seq<e);)t++;i.splice(t,0,{seq:e,name:l}),o=t;for(let e of r)e.field>=o&&e.field++}for(let i of r)if(i.line==n.length&&i.from>t.index){let e=t[2]?3+(t[1]||"").length:2;i.from-=e,i.to-=e}r.push(new HI(o,n.length,t.index,t.index+l.length)),s=s.slice(0,t.index)+a+s.slice(t.index+t[0].length)}s=s.replace(/\\([{}])/g,(e,t,i)=>{for(let s of r)s.line==n.length&&s.from>i&&(s.from--,s.to--);return t}),n.push(s)}return new JI(n,r)}}let ej=ux.widget({widget:new class extends cx{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),tj=ux.mark({class:"cm-snippetField"});class ij{constructor(e,t){this.ranges=e,this.active=t,this.deco=ux.set(e.map(e=>(e.from==e.to?ej:tj).range(e.from,e.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new ij(t,this.active)}selectionInsideField(e){return e.ranges.every(e=>this.ranges.some(t=>t.field==this.active&&t.from<=e.from&&t.to>=e.to))}}const nj=e_.define({map:(e,t)=>e&&e.map(t)}),rj=e_.define(),sj=Cw.define({create:()=>null,update(e,t){for(let i of t.effects){if(i.is(nj))return i.value;if(i.is(rj)&&e)return new ij(e.ranges,i.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>GP.decorations.from(e,e=>e?e.deco:ux.none)});function aj(e,t){return ww.create(e.filter(e=>e.field==t).map(e=>ww.range(e.from,e.to)))}function oj(e){let t=JI.parse(e);return(e,i,n,r)=>{let{text:s,ranges:a}=t.instantiate(e.state,n),{main:o}=e.state.selection,l={changes:{from:n,to:r==o.from?o.to:r,insert:Gb.of(s)},scrollIntoView:!0,annotations:i?[mI.of(i),t_.userEvent.of("input.complete")]:void 0};if(a.length&&(l.selection=aj(a,0)),a.some(e=>e.field>0)){let t=new ij(a,0),i=l.effects=[nj.of(t)];void 0===e.state.field(sj,!1)&&i.push(e_.appendConfig.of([sj,uj,pj,GI]))}e.dispatch(e.state.update(l))}}function lj(e){return({state:t,dispatch:i})=>{let n=t.field(sj,!1);if(!n||e<0&&0==n.active)return!1;let r=n.active+e,s=e>0&&!n.ranges.some(t=>t.field==r+e);return i(t.update({selection:aj(n.ranges,r),effects:nj.of(s?null:new ij(n.ranges,r)),scrollIntoView:!0})),!0}}const cj=[{key:"Tab",run:lj(1),shift:lj(-1)},{key:"Escape",run:({state:e,dispatch:t})=>!!e.field(sj,!1)&&(t(e.update({effects:nj.of(null)})),!0)}],hj=Sw.define({combine:e=>e.length?e[0]:cj}),uj=Nw.highest(rT.compute([hj],e=>e.facet(hj)));function dj(e,t){return{...t,apply:oj(e)}}const pj=GP.domEventHandlers({mousedown(e,t){let i,n=t.state.field(sj,!1);if(!n||null==(i=t.posAtCoords({x:e.clientX,y:e.clientY})))return!1;let r=n.ranges.find(e=>e.from<=i&&e.to>=i);return!(!r||r.field==n.active)&&(t.dispatch({selection:aj(n.ranges,r.field),effects:nj.of(n.ranges.some(e=>e.field>r.field)?new ij(n.ranges,r.field):null),scrollIntoView:!0}),!0)}}),fj=new class extends f_{};function mj(e={}){return[YI,zI,xI.of(e),VI,Oj,GI]}fj.startSide=1,fj.endSide=-1;const gj=[{key:"Ctrl-Space",run:BI},{mac:"Alt-`",run:BI},{mac:"Alt-i",run:BI},{key:"Escape",run:e=>{let t=e.state.field(zI,!1);return!(!t||!t.active.some(e=>0!=e.state))&&(e.dispatch({effects:bI.of(null)}),!0)}},{key:"ArrowDown",run:XI(!0)},{key:"ArrowUp",run:XI(!1)},{key:"PageDown",run:XI(!0,"page")},{key:"PageUp",run:XI(!1,"page")},{key:"Enter",run:e=>{let t=e.state.field(zI,!1);return!(e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(xI).interactionDelay)&&UI(e,t.open.options[t.open.selected])}}],Oj=Nw.highest(rT.computeN([xI],e=>e.facet(xI).defaultKeymap?[gj]:[])),vj=[dj("function ${name}(${params}) {\n\t${}\n}",{label:"function",detail:"definition",type:"keyword"}),dj("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n\t${}\n}",{label:"for",detail:"loop",type:"keyword"}),dj("for (let ${name} of ${collection}) {\n\t${}\n}",{label:"for",detail:"of loop",type:"keyword"}),dj("do {\n\t${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),dj("while (${}) {\n\t${}\n}",{label:"while",detail:"loop",type:"keyword"}),dj("try {\n\t${}\n} catch (${error}) {\n\t${}\n}",{label:"try",detail:"/ catch block",type:"keyword"}),dj("if (${}) {\n\t${}\n}",{label:"if",detail:"block",type:"keyword"}),dj("if (${}) {\n\t${}\n} else {\n\t${}\n}",{label:"if",detail:"/ else block",type:"keyword"}),dj("class ${name} {\n\tconstructor(${params}) {\n\t\t${}\n\t}\n}",{label:"class",detail:"definition",type:"keyword"}),dj('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),dj('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],yj=vj.concat([dj("interface ${name} {\n\t${}\n}",{label:"interface",detail:"definition",type:"keyword"}),dj("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),dj("enum ${name} {\n\t${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),bj=new uE,wj=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function _j(e){return(t,i)=>{let n=t.node.getChild("VariableDefinition");return n&&i(n,e),!0}}const xj=["FunctionDeclaration"],Sj={FunctionDeclaration:_j("function"),ClassDeclaration:_j("class"),ClassExpression:()=>!0,EnumDeclaration:_j("constant"),TypeAliasDeclaration:_j("type"),NamespaceDeclaration:_j("namespace"),VariableDefinition(e,t){e.matchContext(xj)||t(e,"variable")},TypeDefinition(e,t){t(e,"type")},__proto__:null};function kj(e,t){let i=bj.get(t);if(i)return i;let n=[],r=!0;function s(t,i){let r=e.sliceString(t.from,t.to);n.push({label:r,type:i})}return t.cursor(B$.IncludeAnonymous).iterate(t=>{if(r)r=!1;else if(t.name){let e=Sj[t.name];if(e&&e(t,s)||wj.has(t.name))return!1}else if(t.to-t.from>8192){for(let i of kj(e,t.node))n.push(i);return!1}}),bj.set(t,n),n}const Pj=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Tj=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function $j(e){let t=FE(e.state).resolveInner(e.pos,-1);if(Tj.indexOf(t.name)>-1)return null;let i="VariableName"==t.name||t.to-t.from<20&&Pj.test(e.state.sliceDoc(t.from,t.to));if(!i&&!e.explicit)return null;let n=[];for(let r=t;r;r=r.parent)wj.has(r.name)&&(n=n.concat(kj(e.state.doc,r)));return{options:n,from:i?t.from:e.pos,validFor:Pj}}const Ej=VE.define({name:"javascript",parser:lI.configure({props:[uA.add({IfStatement:yA({except:/^\s*({|else\b)/}),TryStatement:yA({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:e=>e.baseIndent,SwitchBody:e=>{let t=e.textAfter,i=/^\s*\}/.test(t),n=/^\s*(case|default)\b/.test(t);return e.baseIndent+(i?0:n?1:2)*e.unit},Block:OA({closing:"}"}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":yA({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag":e=>e.column(e.node.from)+e.unit}),bA.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":function(e){let t=e.firstChild,i=e.lastChild;return t&&t.to<i.from?{from:t.to,to:i.type.isError?e.to:i.from}:null},BlockComment:e=>({from:e.from+2,to:e.to-2}),JSXElement(e){let t=e.firstChild;if(!t||"JSXSelfClosingTag"==t.name)return null;let i=e.lastChild;return{from:t.to,to:i.type.isError?e.to:i.from}},"JSXSelfClosingTag JSXOpenTag"(e){var t;let i=null===(t=e.firstChild)||void 0===t?void 0:t.nextSibling,n=e.lastChild;return!i||i.type.isError?null:{from:i.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),Aj={test:e=>/^JSX/.test(e.name),facet:qE({commentTokens:{block:{open:"{/*",close:"*/}"}}})},Cj=Ej.configure({dialect:"ts"},"typescript"),Rj=Ej.configure({dialect:"jsx",props:[XE.add(e=>e.isTop?[Aj]:void 0)]}),Qj=Ej.configure({dialect:"jsx ts",props:[XE.add(e=>e.isTop?[Aj]:void 0)]},"typescript");let Ij=e=>({label:e,type:"keyword"});const jj="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(Ij),Mj=jj.concat(["declare","implements","private","protected","public"].map(Ij));function Nj(e={}){let t=e.jsx?e.typescript?Qj:Rj:e.typescript?Cj:Ej,i=e.typescript?yj.concat(Mj):vj.concat(jj);return new rA(t,[Ej.data.of({autocomplete:(n=Tj,r=uI(i),e=>{for(let t=FE(e.state).resolveInner(e.pos,-1);t;t=t.parent){if(n.indexOf(t.name)>-1)return null;if(t.type.isTop)break}return r(e)})}),Ej.data.of({autocomplete:$j}),e.jsx?Dj:[]]);var n,r}function Lj(e,t,i=e.length){for(let n=null==t?void 0:t.firstChild;n;n=n.nextSibling)if("JSXIdentifier"==n.name||"JSXBuiltin"==n.name||"JSXNamespacedName"==n.name||"JSXMemberExpression"==n.name)return e.sliceString(n.from,Math.min(n.to,i));return""}const Zj="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),Dj=GP.inputHandler.of((e,t,i,n,r)=>{if((Zj?e.composing:e.compositionStarted)||e.state.readOnly||t!=i||">"!=n&&"/"!=n||!Ej.isActiveAt(e.state,t,-1))return!1;let s=r(),{state:a}=s,o=a.changeByRange(e=>{var t;let i,{head:r}=e,s=FE(a).resolveInner(r-1,-1);if("JSXStartTag"==s.name&&(s=s.parent),a.doc.sliceString(r-1,r)!=n||"JSXAttributeValue"==s.name&&s.to>r);else{if(">"==n&&"JSXFragmentTag"==s.name)return{range:e,changes:{from:r,insert:"</>"}};if("/"==n&&"JSXStartCloseTag"==s.name){let e=s.parent,n=e.parent;if(n&&e.from==r-2&&((i=Lj(a.doc,n.firstChild,r))||"JSXFragmentTag"==(null===(t=n.firstChild)||void 0===t?void 0:t.name))){let e=`${i}>`;return{range:ww.cursor(r+e.length,-1),changes:{from:r,insert:e}}}}else if(">"==n){let t=function(e){for(;;){if("JSXOpenTag"==e.name||"JSXSelfClosingTag"==e.name||"JSXFragmentTag"==e.name)return e;if("JSXEscape"==e.name||!e.parent)return null;e=e.parent}}(s);if(t&&"JSXOpenTag"==t.name&&!/^\/?>|^<\//.test(a.doc.sliceString(r,r+2))&&(i=Lj(a.doc,t,r)))return{range:e,changes:{from:r,insert:`</${i}>`}}}}return{range:e}});return!o.changes.empty&&(e.dispatch([s,a.update(o,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});class zj{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class Uj{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(Jj).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((e,t)=>e.from-t.from||e.to-t.to),s=new b_,a=[],o=0,l=i.doc.iter(),c=0,h=i.doc.length;for(let d=0;;){let e,t,i=d==r.length?null:r[d];if(!i&&!a.length)break;if(a.length)e=o,t=a.reduce((e,t)=>Math.min(e,t.to),i&&i.from>e?i.from:1e8);else{if(e=i.from,e>h)break;t=i.to,a.push(i),d++}for(;d<r.length;){let i=r[d];if(i.from!=e||!(i.to>i.from||i.to==e)){t=Math.min(i.from,t);break}a.push(i),d++,t=Math.min(i.to,t)}t=Math.min(t,h);let n=!1;if(a.some(i=>i.from==e&&(i.to==t||t==h))&&(n=e==t,!n&&t-e<10)){let i=e-(c+l.value.length);i>0&&(l.next(i),c=e);for(let r=e;;){if(r>=t){n=!0;break}if(!l.lineBreak&&c+l.value.length>r)break;r=c+l.value.length,c+=l.value.length,l.next()}}let u=cM(a);if(n)s.add(e,e,ux.widget({widget:new nM(u),diagnostics:a.slice()}));else{let i=a.reduce((e,t)=>t.markClass?e+" "+t.markClass:e,"");s.add(e,t,ux.mark({class:"cm-lintRange cm-lintRange-"+u+i,diagnostics:a.slice(),inclusiveEnd:a.some(e=>e.to>t)}))}if(o=t,o==h)break;for(let r=0;r<a.length;r++)a[r].to<=o&&a.splice(r--,1)}let u=s.finish();return new Uj(u,t,qj(u))}}function qj(e,t=null,i=0){let n=null;return e.between(i,1e9,(e,i,{spec:r})=>{if(!(t&&r.diagnostics.indexOf(t)<0))if(n){if(r.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new zj(n.from,i,n.diagnostic)}else n=new zj(e,i,t||r.diagnostics[0])}),n}const Xj=e_.define(),Bj=e_.define(),Wj=e_.define(),Vj=Cw.define({create:()=>new Uj(ux.none,null,null),update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),n=null,r=e.panel;if(e.selected){let r=t.changes.mapPos(e.selected.from,1);n=qj(i,e.selected.diagnostic,r)||qj(i,null,r)}!i.size&&r&&t.state.facet(Jj).autoPanel&&(r=null),e=new Uj(i,r,n)}for(let i of t.effects)if(i.is(Xj)){let n=t.state.facet(Jj).autoPanel?i.value.length?sM.open:null:e.panel;e=Uj.init(i.value,n,t.state)}else i.is(Bj)?e=new Uj(e.diagnostics,i.value?sM.open:null,e.selected):i.is(Wj)&&(e=new Uj(e.diagnostics,e.panel,i.value));return e},provide:e=>[c$.from(e,e=>e.panel),GP.decorations.from(e,e=>e.diagnostics)]}),Fj=ux.mark({class:"cm-lintRange cm-lintRange-active"});function Yj(e,t,i){let n,{diagnostics:r}=e.state.field(Vj),s=-1,a=-1;r.between(t-(i<0?1:0),t+(i>0?1:0),(e,r,{spec:o})=>{if(t>=e&&t<=r&&(e==r||(t>e||i>0)&&(t<r||i<0)))return n=o.diagnostics,s=e,a=r,!1});let o=e.state.facet(Jj).tooltipFilter;return n&&o&&(n=o(n,e.state)),n?{pos:s,end:a,above:e.state.doc.lineAt(s).to<a,create:()=>({dom:Gj(e,n)})}:null}function Gj(e,t){return X_("ul",{class:"cm-tooltip-lint"},t.map(t=>iM(e,t,!1)))}const Hj=e=>{let t=e.state.field(Vj,!1);return!(!t||!t.panel)&&(e.dispatch({effects:Bj.of(!1)}),!0)},Kj=[{key:"Mod-Shift-m",run:e=>{let t=e.state.field(Vj,!1);var i,n;t&&t.panel||e.dispatch({effects:(i=e.state,n=[Bj.of(!0)],i.field(Vj,!1)?n:n.concat(e_.appendConfig.of(hM)))});let r=s$(e,sM.open);return r&&r.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:e=>{let t=e.state.field(Vj,!1);if(!t)return!1;let i=e.state.selection.main,n=qj(t.diagnostics,null,i.to+1);return!(!n&&(n=qj(t.diagnostics,null,0),!n||n.from==i.from&&n.to==i.to))&&(e.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)}}],Jj=Sw.define({combine:e=>({sources:e.map(e=>e.source).filter(e=>null!=e),...p_(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:eM,tooltipFilter:eM,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})})});function eM(e,t){return e?t?(i,n)=>t(e(i,n),n):e:t}function tM(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let n=i[e];if(/[a-zA-Z]/.test(n)&&!t.some(e=>e.toLowerCase()==n.toLowerCase())){t.push(n);continue e}}t.push("")}return t}function iM(e,t,i){var n;let r=i?tM(t.actions):[];return X_("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},X_("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),null===(n=t.actions)||void 0===n?void 0:n.map((i,n)=>{let s=!1,a=n=>{if(n.preventDefault(),s)return;s=!0;let r=qj(e.state.field(Vj).diagnostics,t);r&&i.apply(e,r.from,r.to)},{name:o}=i,l=r[n]?o.indexOf(r[n]):-1,c=l<0?o:[o.slice(0,l),X_("u",o.slice(l,l+1)),o.slice(l+1)];return X_("button",{type:"button",class:"cm-diagnosticAction"+(i.markClass?" "+i.markClass:""),onclick:a,onmousedown:a,"aria-label":` Action: ${o}${l<0?"":` (access key "${r[n]})"`}.`},c)}),t.source&&X_("div",{class:"cm-diagnosticSource"},t.source))}class nM extends cx{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return X_("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class rM{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=iM(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class sM{constructor(e){this.view=e,this.items=[];this.list=X_("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(27==t.keyCode)Hj(this.view),this.view.focus();else if(38==t.keyCode||33==t.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==t.keyCode||34==t.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==t.keyCode)this.moveSelection(0);else if(35==t.keyCode)this.moveSelection(this.items.length-1);else if(13==t.keyCode)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=tM(i.actions);for(let r=0;r<n.length;r++)if(n[r].toUpperCase().charCodeAt(0)==t.keyCode){let t=qj(this.view.state.field(Vj).diagnostics,i);t&&i.actions[r].apply(e,t.from,t.to)}}}t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=X_("div",{class:"cm-panel-lint"},this.list,X_("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Hj(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Vj).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Vj),i=0,n=!1,r=null,s=new Set;for(e.between(0,this.view.state.doc.length,(e,a,{spec:o})=>{for(let l of o.diagnostics){if(s.has(l))continue;s.add(l);let e,a=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==l){a=t;break}a<0?(e=new rM(this.view,l),this.items.splice(i,0,e),n=!0):(e=this.items[a],a>i&&(this.items.splice(i,a-i),n=!0)),t&&e.diagnostic==t.diagnostic?e.dom.hasAttribute("aria-selected")||(e.dom.setAttribute("aria-selected","true"),r=e):e.dom.hasAttribute("aria-selected")&&e.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();0==this.items.length&&(this.items.push(new rM(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let i=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/i:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=qj(this.view.state.field(Vj).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:Wj.of(t)})}static open(e){return new sM(e)}}function aM(e){return function(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const oM=GP.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:aM("#d11")},".cm-lintRange-warning":{backgroundImage:aM("orange")},".cm-lintRange-info":{backgroundImage:aM("#999")},".cm-lintRange-hint":{backgroundImage:aM("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function lM(e){return"error"==e?4:"warning"==e?3:"info"==e?2:1}function cM(e){let t="hint",i=1;for(let n of e){let e=lM(n.severity);e>i&&(i=e,t=n.severity)}return t}const hM=[Vj,GP.decorations.compute([Vj],e=>{let{selected:t,panel:i}=e.field(Vj);return t&&i&&t.from!=t.to?ux.set([Fj.range(t.from,t.to)]):ux.none}),t$(Yj,{hideOn:function(e,t){let i=t.pos,n=t.end||i,r=e.state.facet(Jj).hideOn(e,i,n);if(null!=r)return r;let s=e.startState.doc.lineAt(t.pos);return!(!e.effects.some(e=>e.is(Xj))&&!e.changes.touchesRange(s.from,Math.max(s.to,n)))}}),oM];var uM,dM={exports:{}};var pM,fM,mM,gM=(uM||(uM=1,pM=dM,mM=-1,(fM=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32}).Diff=function(e,t){return[e,t]},fM.prototype.diff_main=function(e,t,i,n){void 0===n&&(n=this.Diff_Timeout<=0?Number.MAX_VALUE:(new Date).getTime()+1e3*this.Diff_Timeout);var r=n;if(null==e||null==t)throw new Error("Null input. (diff_main)");if(e==t)return e?[new fM.Diff(0,e)]:[];void 0===i&&(i=!0);var s=i,a=this.diff_commonPrefix(e,t),o=e.substring(0,a);e=e.substring(a),t=t.substring(a),a=this.diff_commonSuffix(e,t);var l=e.substring(e.length-a);e=e.substring(0,e.length-a),t=t.substring(0,t.length-a);var c=this.diff_compute_(e,t,s,r);return o&&c.unshift(new fM.Diff(0,o)),l&&c.push(new fM.Diff(0,l)),this.diff_cleanupMerge(c),c},fM.prototype.diff_compute_=function(e,t,i,n){var r;if(!e)return[new fM.Diff(1,t)];if(!t)return[new fM.Diff(mM,e)];var s=e.length>t.length?e:t,a=e.length>t.length?t:e,o=s.indexOf(a);if(-1!=o)return r=[new fM.Diff(1,s.substring(0,o)),new fM.Diff(0,a),new fM.Diff(1,s.substring(o+a.length))],e.length>t.length&&(r[0][0]=r[2][0]=mM),r;if(1==a.length)return[new fM.Diff(mM,e),new fM.Diff(1,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],h=l[1],u=l[2],d=l[3],p=l[4],f=this.diff_main(c,u,i,n),m=this.diff_main(h,d,i,n);return f.concat([new fM.Diff(0,p)],m)}return i&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)},fM.prototype.diff_lineMode_=function(e,t,i){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var r=n.lineArray,s=this.diff_main(e,t,!1,i);this.diff_charsToLines_(s,r),this.diff_cleanupSemantic(s),s.push(new fM.Diff(0,""));for(var a=0,o=0,l=0,c="",h="";a<s.length;){switch(s[a][0]){case 1:l++,h+=s[a][1];break;case mM:o++,c+=s[a][1];break;case 0:if(o>=1&&l>=1){s.splice(a-o-l,o+l),a=a-o-l;for(var u=this.diff_main(c,h,!1,i),d=u.length-1;d>=0;d--)s.splice(a,0,u[d]);a+=u.length}l=0,o=0,c="",h=""}a++}return s.pop(),s},fM.prototype.diff_bisect_=function(e,t,i){for(var n=e.length,r=t.length,s=Math.ceil((n+r)/2),a=s,o=2*s,l=new Array(o),c=new Array(o),h=0;h<o;h++)l[h]=-1,c[h]=-1;l[a+1]=0,c[a+1]=0;for(var u=n-r,d=u%2!=0,p=0,f=0,m=0,g=0,O=0;O<s&&!((new Date).getTime()>i);O++){for(var v=-O+p;v<=O-f;v+=2){for(var y=a+v,b=(k=v==-O||v!=O&&l[y-1]<l[y+1]?l[y+1]:l[y-1]+1)-v;k<n&&b<r&&e.charAt(k)==t.charAt(b);)k++,b++;if(l[y]=k,k>n)f+=2;else if(b>r)p+=2;else if(d&&(x=a+u-v)>=0&&x<o&&-1!=c[x]&&k>=(_=n-c[x]))return this.diff_bisectSplit_(e,t,k,b,i)}for(var w=-O+m;w<=O-g;w+=2){for(var _,x=a+w,S=(_=w==-O||w!=O&&c[x-1]<c[x+1]?c[x+1]:c[x-1]+1)-w;_<n&&S<r&&e.charAt(n-_-1)==t.charAt(r-S-1);)_++,S++;if(c[x]=_,_>n)g+=2;else if(S>r)m+=2;else if(!d){var k;if((y=a+u-w)>=0&&y<o&&-1!=l[y]&&(b=a+(k=l[y])-y,k>=(_=n-_)))return this.diff_bisectSplit_(e,t,k,b,i)}}}return[new fM.Diff(mM,e),new fM.Diff(1,t)]},fM.prototype.diff_bisectSplit_=function(e,t,i,n,r){var s=e.substring(0,i),a=t.substring(0,n),o=e.substring(i),l=t.substring(n),c=this.diff_main(s,a,!1,r),h=this.diff_main(o,l,!1,r);return c.concat(h)},fM.prototype.diff_linesToChars_=function(e,t){var i=[],n={};function r(e){for(var t="",r=0,a=-1,o=i.length;a<e.length-1;){-1==(a=e.indexOf("\n",r))&&(a=e.length-1);var l=e.substring(r,a+1);(n.hasOwnProperty?n.hasOwnProperty(l):void 0!==n[l])?t+=String.fromCharCode(n[l]):(o==s&&(l=e.substring(r),a=e.length),t+=String.fromCharCode(o),n[l]=o,i[o++]=l),r=a+1}return t}i[0]="";var s=4e4,a=r(e);return s=65535,{chars1:a,chars2:r(t),lineArray:i}},fM.prototype.diff_charsToLines_=function(e,t){for(var i=0;i<e.length;i++){for(var n=e[i][1],r=[],s=0;s<n.length;s++)r[s]=t[n.charCodeAt(s)];e[i][1]=r.join("")}},fM.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var i=0,n=Math.min(e.length,t.length),r=n,s=0;i<r;)e.substring(s,r)==t.substring(s,r)?s=i=r:n=r,r=Math.floor((n-i)/2+i);return r},fM.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var i=0,n=Math.min(e.length,t.length),r=n,s=0;i<r;)e.substring(e.length-r,e.length-s)==t.substring(t.length-r,t.length-s)?s=i=r:n=r,r=Math.floor((n-i)/2+i);return r},fM.prototype.diff_commonOverlap_=function(e,t){var i=e.length,n=t.length;if(0==i||0==n)return 0;i>n?e=e.substring(i-n):i<n&&(t=t.substring(0,i));var r=Math.min(i,n);if(e==t)return r;for(var s=0,a=1;;){var o=e.substring(r-a),l=t.indexOf(o);if(-1==l)return s;a+=l,0!=l&&e.substring(r-a)!=t.substring(0,a)||(s=a,a++)}},fM.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var i=e.length>t.length?e:t,n=e.length>t.length?t:e;if(i.length<4||2*n.length<i.length)return null;var r=this;function s(e,t,i){for(var n,s,a,o,l=e.substring(i,i+Math.floor(e.length/4)),c=-1,h="";-1!=(c=t.indexOf(l,c+1));){var u=r.diff_commonPrefix(e.substring(i),t.substring(c)),d=r.diff_commonSuffix(e.substring(0,i),t.substring(0,c));h.length<d+u&&(h=t.substring(c-d,c)+t.substring(c,c+u),n=e.substring(0,i-d),s=e.substring(i+u),a=t.substring(0,c-d),o=t.substring(c+u))}return 2*h.length>=e.length?[n,s,a,o,h]:null}var a,o,l,c,h,u=s(i,n,Math.ceil(i.length/4)),d=s(i,n,Math.ceil(i.length/2));return u||d?(a=d?u&&u[4].length>d[4].length?u:d:u,e.length>t.length?(o=a[0],l=a[1],c=a[2],h=a[3]):(c=a[0],h=a[1],o=a[2],l=a[3]),[o,l,c,h,a[4]]):null},fM.prototype.diff_cleanupSemantic=function(e){for(var t=!1,i=[],n=0,r=null,s=0,a=0,o=0,l=0,c=0;s<e.length;)0==e[s][0]?(i[n++]=s,a=l,o=c,l=0,c=0,r=e[s][1]):(1==e[s][0]?l+=e[s][1].length:c+=e[s][1].length,r&&r.length<=Math.max(a,o)&&r.length<=Math.max(l,c)&&(e.splice(i[n-1],0,new fM.Diff(mM,r)),e[i[n-1]+1][0]=1,n--,s=--n>0?i[n-1]:-1,a=0,o=0,l=0,c=0,r=null,t=!0)),s++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),s=1;s<e.length;){if(e[s-1][0]==mM&&1==e[s][0]){var h=e[s-1][1],u=e[s][1],d=this.diff_commonOverlap_(h,u),p=this.diff_commonOverlap_(u,h);d>=p?(d>=h.length/2||d>=u.length/2)&&(e.splice(s,0,new fM.Diff(0,u.substring(0,d))),e[s-1][1]=h.substring(0,h.length-d),e[s+1][1]=u.substring(d),s++):(p>=h.length/2||p>=u.length/2)&&(e.splice(s,0,new fM.Diff(0,h.substring(0,p))),e[s-1][0]=1,e[s-1][1]=u.substring(0,u.length-p),e[s+1][0]=mM,e[s+1][1]=h.substring(p),s++),s++}s++}},fM.prototype.diff_cleanupSemanticLossless=function(e){function t(e,t){if(!e||!t)return 6;var i=e.charAt(e.length-1),n=t.charAt(0),r=i.match(fM.nonAlphaNumericRegex_),s=n.match(fM.nonAlphaNumericRegex_),a=r&&i.match(fM.whitespaceRegex_),o=s&&n.match(fM.whitespaceRegex_),l=a&&i.match(fM.linebreakRegex_),c=o&&n.match(fM.linebreakRegex_),h=l&&e.match(fM.blanklineEndRegex_),u=c&&t.match(fM.blanklineStartRegex_);return h||u?5:l||c?4:r&&!a&&o?3:a||o?2:r||s?1:0}for(var i=1;i<e.length-1;){if(0==e[i-1][0]&&0==e[i+1][0]){var n=e[i-1][1],r=e[i][1],s=e[i+1][1],a=this.diff_commonSuffix(n,r);if(a){var o=r.substring(r.length-a);n=n.substring(0,n.length-a),r=o+r.substring(0,r.length-a),s=o+s}for(var l=n,c=r,h=s,u=t(n,r)+t(r,s);r.charAt(0)===s.charAt(0);){n+=r.charAt(0),r=r.substring(1)+s.charAt(0),s=s.substring(1);var d=t(n,r)+t(r,s);d>=u&&(u=d,l=n,c=r,h=s)}e[i-1][1]!=l&&(l?e[i-1][1]=l:(e.splice(i-1,1),i--),e[i][1]=c,h?e[i+1][1]=h:(e.splice(i+1,1),i--))}i++}},fM.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,fM.whitespaceRegex_=/\s/,fM.linebreakRegex_=/[\r\n]/,fM.blanklineEndRegex_=/\n\r?\n$/,fM.blanklineStartRegex_=/^\r?\n\r?\n/,fM.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,i=[],n=0,r=null,s=0,a=!1,o=!1,l=!1,c=!1;s<e.length;)0==e[s][0]?(e[s][1].length<this.Diff_EditCost&&(l||c)?(i[n++]=s,a=l,o=c,r=e[s][1]):(n=0,r=null),l=c=!1):(e[s][0]==mM?c=!0:l=!0,r&&(a&&o&&l&&c||r.length<this.Diff_EditCost/2&&a+o+l+c==3)&&(e.splice(i[n-1],0,new fM.Diff(mM,r)),e[i[n-1]+1][0]=1,n--,r=null,a&&o?(l=c=!0,n=0):(s=--n>0?i[n-1]:-1,l=c=!1),t=!0)),s++;t&&this.diff_cleanupMerge(e)},fM.prototype.diff_cleanupMerge=function(e){e.push(new fM.Diff(0,""));for(var t,i=0,n=0,r=0,s="",a="";i<e.length;)switch(e[i][0]){case 1:r++,a+=e[i][1],i++;break;case mM:n++,s+=e[i][1],i++;break;case 0:n+r>1?(0!==n&&0!==r&&(0!==(t=this.diff_commonPrefix(a,s))&&(i-n-r>0&&0==e[i-n-r-1][0]?e[i-n-r-1][1]+=a.substring(0,t):(e.splice(0,0,new fM.Diff(0,a.substring(0,t))),i++),a=a.substring(t),s=s.substring(t)),0!==(t=this.diff_commonSuffix(a,s))&&(e[i][1]=a.substring(a.length-t)+e[i][1],a=a.substring(0,a.length-t),s=s.substring(0,s.length-t))),i-=n+r,e.splice(i,n+r),s.length&&(e.splice(i,0,new fM.Diff(mM,s)),i++),a.length&&(e.splice(i,0,new fM.Diff(1,a)),i++),i++):0!==i&&0==e[i-1][0]?(e[i-1][1]+=e[i][1],e.splice(i,1)):i++,r=0,n=0,s="",a=""}""===e[e.length-1][1]&&e.pop();var o=!1;for(i=1;i<e.length-1;)0==e[i-1][0]&&0==e[i+1][0]&&(e[i][1].substring(e[i][1].length-e[i-1][1].length)==e[i-1][1]?(e[i][1]=e[i-1][1]+e[i][1].substring(0,e[i][1].length-e[i-1][1].length),e[i+1][1]=e[i-1][1]+e[i+1][1],e.splice(i-1,1),o=!0):e[i][1].substring(0,e[i+1][1].length)==e[i+1][1]&&(e[i-1][1]+=e[i+1][1],e[i][1]=e[i][1].substring(e[i+1][1].length)+e[i+1][1],e.splice(i+1,1),o=!0)),i++;o&&this.diff_cleanupMerge(e)},fM.prototype.diff_xIndex=function(e,t){var i,n=0,r=0,s=0,a=0;for(i=0;i<e.length&&(1!==e[i][0]&&(n+=e[i][1].length),e[i][0]!==mM&&(r+=e[i][1].length),!(n>t));i++)s=n,a=r;return e.length!=i&&e[i][0]===mM?a:a+(t-s)},fM.prototype.diff_prettyHtml=function(e){for(var t=[],i=/&/g,n=/</g,r=/>/g,s=/\n/g,a=0;a<e.length;a++){var o=e[a][0],l=e[a][1].replace(i,"&").replace(n,"<").replace(r,">").replace(s,"¶<br>");switch(o){case 1:t[a]='<ins style="background:#e6ffe6;">'+l+"</ins>";break;case mM:t[a]='<del style="background:#ffe6e6;">'+l+"</del>";break;case 0:t[a]="<span>"+l+"</span>"}}return t.join("")},fM.prototype.diff_text1=function(e){for(var t=[],i=0;i<e.length;i++)1!==e[i][0]&&(t[i]=e[i][1]);return t.join("")},fM.prototype.diff_text2=function(e){for(var t=[],i=0;i<e.length;i++)e[i][0]!==mM&&(t[i]=e[i][1]);return t.join("")},fM.prototype.diff_levenshtein=function(e){for(var t=0,i=0,n=0,r=0;r<e.length;r++){var s=e[r][0],a=e[r][1];switch(s){case 1:i+=a.length;break;case mM:n+=a.length;break;case 0:t+=Math.max(i,n),i=0,n=0}}return t+=Math.max(i,n)},fM.prototype.diff_toDelta=function(e){for(var t=[],i=0;i<e.length;i++)switch(e[i][0]){case 1:t[i]="+"+encodeURI(e[i][1]);break;case mM:t[i]="-"+e[i][1].length;break;case 0:t[i]="="+e[i][1].length}return t.join("\t").replace(/%20/g," ")},fM.prototype.diff_fromDelta=function(e,t){for(var i=[],n=0,r=0,s=t.split(/\t/g),a=0;a<s.length;a++){var o=s[a].substring(1);switch(s[a].charAt(0)){case"+":try{i[n++]=new fM.Diff(1,decodeURI(o))}catch(h){throw new Error("Illegal escape in diff_fromDelta: "+o)}break;case"-":case"=":var l=parseInt(o,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+o);var c=e.substring(r,r+=l);"="==s[a].charAt(0)?i[n++]=new fM.Diff(0,c):i[n++]=new fM.Diff(mM,c);break;default:if(s[a])throw new Error("Invalid diff operation in diff_fromDelta: "+s[a])}}if(r!=e.length)throw new Error("Delta length ("+r+") does not equal source text length ("+e.length+").");return i},fM.prototype.match_main=function(e,t,i){if(null==e||null==t||null==i)throw new Error("Null input. (match_main)");return i=Math.max(0,Math.min(i,e.length)),e==t?0:e.length?e.substring(i,i+t.length)==t?i:this.match_bitap_(e,t,i):-1},fM.prototype.match_bitap_=function(e,t,i){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),r=this;function s(e,n){var s=e/t.length,a=Math.abs(i-n);return r.Match_Distance?s+a/r.Match_Distance:a?1:s}var a=this.Match_Threshold,o=e.indexOf(t,i);-1!=o&&(a=Math.min(s(0,o),a),-1!=(o=e.lastIndexOf(t,i+t.length))&&(a=Math.min(s(0,o),a)));var l,c,h=1<<t.length-1;o=-1;for(var u,d=t.length+e.length,p=0;p<t.length;p++){for(l=0,c=d;l<c;)s(p,i+c)<=a?l=c:d=c,c=Math.floor((d-l)/2+l);d=c;var f=Math.max(1,i-c+1),m=Math.min(i+c,e.length)+t.length,g=Array(m+2);g[m+1]=(1<<p)-1;for(var O=m;O>=f;O--){var v=n[e.charAt(O-1)];if(g[O]=0===p?(g[O+1]<<1|1)&v:(g[O+1]<<1|1)&v|(u[O+1]|u[O])<<1|1|u[O+1],g[O]&h){var y=s(p,O-1);if(y<=a){if(a=y,!((o=O-1)>i))break;f=Math.max(1,2*i-o)}}}if(s(p+1,i)>a)break;u=g}return o},fM.prototype.match_alphabet_=function(e){for(var t={},i=0;i<e.length;i++)t[e.charAt(i)]=0;for(i=0;i<e.length;i++)t[e.charAt(i)]|=1<<e.length-i-1;return t},fM.prototype.patch_addContext_=function(e,t){if(0!=t.length){if(null===e.start2)throw Error("patch not initialized");for(var i=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(i)!=t.lastIndexOf(i)&&i.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,i=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var r=t.substring(e.start2-n,e.start2);r&&e.diffs.unshift(new fM.Diff(0,r));var s=t.substring(e.start2+e.length1,e.start2+e.length1+n);s&&e.diffs.push(new fM.Diff(0,s)),e.start1-=r.length,e.start2-=r.length,e.length1+=r.length+s.length,e.length2+=r.length+s.length}},fM.prototype.patch_make=function(e,t,i){var n,r;if("string"==typeof e&&"string"==typeof t&&void 0===i)n=e,(r=this.diff_main(n,t,!0)).length>2&&(this.diff_cleanupSemantic(r),this.diff_cleanupEfficiency(r));else if(e&&"object"==typeof e&&void 0===t&&void 0===i)r=e,n=this.diff_text1(r);else if("string"==typeof e&&t&&"object"==typeof t&&void 0===i)n=e,r=t;else{if("string"!=typeof e||"string"!=typeof t||!i||"object"!=typeof i)throw new Error("Unknown call format to patch_make.");n=e,r=i}if(0===r.length)return[];for(var s=[],a=new fM.patch_obj,o=0,l=0,c=0,h=n,u=n,d=0;d<r.length;d++){var p=r[d][0],f=r[d][1];switch(o||0===p||(a.start1=l,a.start2=c),p){case 1:a.diffs[o++]=r[d],a.length2+=f.length,u=u.substring(0,c)+f+u.substring(c);break;case mM:a.length1+=f.length,a.diffs[o++]=r[d],u=u.substring(0,c)+u.substring(c+f.length);break;case 0:f.length<=2*this.Patch_Margin&&o&&r.length!=d+1?(a.diffs[o++]=r[d],a.length1+=f.length,a.length2+=f.length):f.length>=2*this.Patch_Margin&&o&&(this.patch_addContext_(a,h),s.push(a),a=new fM.patch_obj,o=0,h=u,l=c)}1!==p&&(l+=f.length),p!==mM&&(c+=f.length)}return o&&(this.patch_addContext_(a,h),s.push(a)),s},fM.prototype.patch_deepCopy=function(e){for(var t=[],i=0;i<e.length;i++){var n=e[i],r=new fM.patch_obj;r.diffs=[];for(var s=0;s<n.diffs.length;s++)r.diffs[s]=new fM.Diff(n.diffs[s][0],n.diffs[s][1]);r.start1=n.start1,r.start2=n.start2,r.length1=n.length1,r.length2=n.length2,t[i]=r}return t},fM.prototype.patch_apply=function(e,t){if(0==e.length)return[t,[]];e=this.patch_deepCopy(e);var i=this.patch_addPadding(e);t=i+t+i,this.patch_splitMax(e);for(var n=0,r=[],s=0;s<e.length;s++){var a,o,l=e[s].start2+n,c=this.diff_text1(e[s].diffs),h=-1;if(c.length>this.Match_MaxBits?-1!=(a=this.match_main(t,c.substring(0,this.Match_MaxBits),l))&&(-1==(h=this.match_main(t,c.substring(c.length-this.Match_MaxBits),l+c.length-this.Match_MaxBits))||a>=h)&&(a=-1):a=this.match_main(t,c,l),-1==a)r[s]=!1,n-=e[s].length2-e[s].length1;else if(r[s]=!0,n=a-l,c==(o=-1==h?t.substring(a,a+c.length):t.substring(a,h+this.Match_MaxBits)))t=t.substring(0,a)+this.diff_text2(e[s].diffs)+t.substring(a+c.length);else{var u=this.diff_main(c,o,!1);if(c.length>this.Match_MaxBits&&this.diff_levenshtein(u)/c.length>this.Patch_DeleteThreshold)r[s]=!1;else{this.diff_cleanupSemanticLossless(u);for(var d,p=0,f=0;f<e[s].diffs.length;f++){var m=e[s].diffs[f];0!==m[0]&&(d=this.diff_xIndex(u,p)),1===m[0]?t=t.substring(0,a+d)+m[1]+t.substring(a+d):m[0]===mM&&(t=t.substring(0,a+d)+t.substring(a+this.diff_xIndex(u,p+m[1].length))),m[0]!==mM&&(p+=m[1].length)}}}}return[t=t.substring(i.length,t.length-i.length),r]},fM.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,i="",n=1;n<=t;n++)i+=String.fromCharCode(n);for(n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var r=e[0],s=r.diffs;if(0==s.length||0!=s[0][0])s.unshift(new fM.Diff(0,i)),r.start1-=t,r.start2-=t,r.length1+=t,r.length2+=t;else if(t>s[0][1].length){var a=t-s[0][1].length;s[0][1]=i.substring(s[0][1].length)+s[0][1],r.start1-=a,r.start2-=a,r.length1+=a,r.length2+=a}return 0==(s=(r=e[e.length-1]).diffs).length||0!=s[s.length-1][0]?(s.push(new fM.Diff(0,i)),r.length1+=t,r.length2+=t):t>s[s.length-1][1].length&&(a=t-s[s.length-1][1].length,s[s.length-1][1]+=i.substring(0,a),r.length1+=a,r.length2+=a),i},fM.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,i=0;i<e.length;i++)if(!(e[i].length1<=t)){var n=e[i];e.splice(i--,1);for(var r=n.start1,s=n.start2,a="";0!==n.diffs.length;){var o=new fM.patch_obj,l=!0;for(o.start1=r-a.length,o.start2=s-a.length,""!==a&&(o.length1=o.length2=a.length,o.diffs.push(new fM.Diff(0,a)));0!==n.diffs.length&&o.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],h=n.diffs[0][1];1===c?(o.length2+=h.length,s+=h.length,o.diffs.push(n.diffs.shift()),l=!1):c===mM&&1==o.diffs.length&&0==o.diffs[0][0]&&h.length>2*t?(o.length1+=h.length,r+=h.length,l=!1,o.diffs.push(new fM.Diff(c,h)),n.diffs.shift()):(h=h.substring(0,t-o.length1-this.Patch_Margin),o.length1+=h.length,r+=h.length,0===c?(o.length2+=h.length,s+=h.length):l=!1,o.diffs.push(new fM.Diff(c,h)),h==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(h.length))}a=(a=this.diff_text2(o.diffs)).substring(a.length-this.Patch_Margin);var u=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);""!==u&&(o.length1+=u.length,o.length2+=u.length,0!==o.diffs.length&&0===o.diffs[o.diffs.length-1][0]?o.diffs[o.diffs.length-1][1]+=u:o.diffs.push(new fM.Diff(0,u))),l||e.splice(++i,0,o)}}},fM.prototype.patch_toText=function(e){for(var t=[],i=0;i<e.length;i++)t[i]=e[i];return t.join("")},fM.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var i=e.split("\n"),n=0,r=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<i.length;){var s=i[n].match(r);if(!s)throw new Error("Invalid patch string: "+i[n]);var a=new fM.patch_obj;for(t.push(a),a.start1=parseInt(s[1],10),""===s[2]?(a.start1--,a.length1=1):"0"==s[2]?a.length1=0:(a.start1--,a.length1=parseInt(s[2],10)),a.start2=parseInt(s[3],10),""===s[4]?(a.start2--,a.length2=1):"0"==s[4]?a.length2=0:(a.start2--,a.length2=parseInt(s[4],10)),n++;n<i.length;){var o=i[n].charAt(0);try{var l=decodeURI(i[n].substring(1))}catch(c){throw new Error("Illegal escape in patch_fromText: "+l)}if("-"==o)a.diffs.push(new fM.Diff(mM,l));else if("+"==o)a.diffs.push(new fM.Diff(1,l));else if(" "==o)a.diffs.push(new fM.Diff(0,l));else{if("@"==o)break;if(""!==o)throw new Error('Invalid patch mode "'+o+'" in: '+l)}n++}}return t},(fM.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0}).prototype.toString=function(){for(var e,t=["@@ -"+(0===this.length1?this.start1+",0":1==this.length1?this.start1+1:this.start1+1+","+this.length1)+" +"+(0===this.length2?this.start2+",0":1==this.length2?this.start2+1:this.start2+1+","+this.length2)+" @@\n"],i=0;i<this.diffs.length;i++){switch(this.diffs[i][0]){case 1:e="+";break;case mM:e="-";break;case 0:e=" "}t[i+1]=e+encodeURI(this.diffs[i][1])+"\n"}return t.join("").replace(/%20/g," ")},pM.exports=fM,pM.exports.diff_match_patch=fM,pM.exports.DIFF_DELETE=mM,pM.exports.DIFF_INSERT=1,pM.exports.DIFF_EQUAL=0),dM.exports);const OM=e_.define(),vM=e_.define(),yM=e_.define(),bM=e_.define(),wM=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(OM))return i.value;return e},provide:e=>GP.decorations.from(e)}),_M=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(vM))return i.value;return e},provide:e=>GP.decorations.from(e)}),xM=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(yM))return i.value;return e},provide:e=>GP.decorations.from(e)}),SM=Cw.define({create:()=>ux.none,update(e,t){e=e.map(t.changes);for(let i of t.effects)if(i.is(bM))return i.value;return e},provide:e=>GP.decorations.from(e)});class kM extends cx{constructor(e,t,i,n,r){super(),this.isAsisButton=e,this.textToApply=t,this.targetEditorView=i,this.diffRange=n,this.hostComponent=r}eq(e){return!1}toDOM(e){const t=document.createElement("button");this.isAsisButton?t.className="cm-merge-button revert":t.className="cm-merge-button accept",t.addEventListener("click",()=>{this.applyChanges(this.textToApply,this.targetEditorView,this.diffRange)});const i=document.createElement("div");return i.className="cm-merge-button-container",i.appendChild(t),i}applyChanges(e,t,i){t&&i&&(t.dispatch({changes:{from:i.from,to:i.to,insert:e}}),requestAnimationFrame(()=>{this.hostComponent.recalculateDiff()}))}}class PM extends HTMLElement{constructor(){super(),ge(this,W),ge(this,V),ge(this,F),ge(this,Y),ge(this,G,new Zw),ge(this,H,!1),pe(this,"_asisScrollHandler",null),pe(this,"_tobeScrollHandler",null),pe(this,"getContents",()=>me(this,V)?me(this,V).state.doc.toString():""),ge(this,K,()=>{if(Oe(this,F,this.shadowRoot.querySelector(".panel.asis")),Oe(this,Y,this.shadowRoot.querySelector(".panel.tobe")),!me(this,F)||!me(this,Y))return;const e=[C$(),IT(),cC(),vT(),[kT,PT],d_.allowMultipleSelections.of(!0),d_.transactionFilter.of(e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let i=e.newDoc,{head:n}=e.newSelection.main,r=i.lineAt(n);if(n>r.from+200)return e;let s=i.sliceString(r.from,n);if(!t.some(e=>e.test(s)))return e;let{state:a}=e,o=-1,l=[];for(let{head:c}of a.selection.ranges){let e=a.doc.lineAt(c);if(e.from==o)continue;o=e.from;let t=cA(a,e.from);if(null==t)continue;let i=/^\s*/.exec(e.text)[0],n=lA(a,t);i!=n&&l.push({from:e.from,to:e.from+i.length,insert:n})}return l.length?[e,{changes:l,sequential:!0}]:e}),NA(),ZT,I$,[zR,DR],rT.of([...SR,...gQ,...PC,...Kj,...gj,kR,oR]),kA($A),mj()];Oe(this,W,new GP({state:d_.create({doc:"",extensions:[e,me(this,G).of(Nj()),d_.readOnly.of(!1),wM,xM,GP.updateListener.of(e=>{e.view.contentDOM.firstChild&&!e.view._initialAsisContentLoaded&&(e.view._initialAsisContentLoaded=!0)})]}),parent:me(this,F)})),Oe(this,V,new GP({state:d_.create({doc:"",extensions:[e,me(this,G).of(Nj()),d_.readOnly.of(!0),_M,SM,GP.updateListener.of(e=>{e.view.contentDOM.firstChild&&!e.view._initialTobeContentLoaded&&(e.view._initialTobeContentLoaded=!0)})]}),parent:me(this,Y)})),me(this,J).call(this)}),ge(this,J,()=>{this._asisScrollHandler&&(me(this,W).scrollDOM.removeEventListener("scroll",this._asisScrollHandler),me(this,V).scrollDOM.removeEventListener("scroll",this._tobeScrollHandler));let e=!1,t=!1;this._asisScrollHandler=()=>{me(this,H)&&(t||(e=!0,me(this,V).scrollDOM.scrollTop=me(this,W).scrollDOM.scrollTop,me(this,V).scrollDOM.scrollLeft=me(this,W).scrollDOM.scrollLeft),t=!1)},this._tobeScrollHandler=()=>{me(this,H)&&(e||(t=!0,me(this,W).scrollDOM.scrollTop=me(this,V).scrollDOM.scrollTop,me(this,W).scrollDOM.scrollLeft=me(this,V).scrollDOM.scrollLeft),e=!1)},me(this,W).scrollDOM.addEventListener("scroll",this._asisScrollHandler),me(this,V).scrollDOM.addEventListener("scroll",this._tobeScrollHandler)}),ge(this,ee,(e,t)=>{const i=new gM.diff_match_patch,n=i.diff_linesToChars_(e,t),r=n.chars1,s=n.chars2,a=n.lineArray,o=i.diff_main(r,s,!0);i.diff_cleanupSemantic(o),i.diff_charsToLines_(o,a);const l=new b_,c=new b_,h=new b_,u=new b_;let d=0,p=0;const f=ux.line({class:"cm-inserted-line-bg"}),m=ux.line({class:"cm-deleted-line-bg"}),g=this;for(const[O,v]of o){const e=v.length,t=d,i=p;switch(O){case gM.diff_match_patch.DIFF_INSERT:const n=v.split("\n");for(let e=0;e<n.length;e++)e===n.length-1&&""===n[e]&&v.endsWith("\n")||c.add(p,p,f),p+=n[e].length+(e<n.length-1?1:0);u.add(i,i,ux.widget({widget:new kM(!1,v,me(g,W),{from:t,to:t+0},g),side:1}));break;case gM.diff_match_patch.DIFF_DELETE:const r=v.split("\n");for(let e=0;e<r.length;e++)e===r.length-1&&""===r[e]&&v.endsWith("\n")||l.add(d,d,m),d+=r[e].length+(e<r.length-1?1:0);h.add(t,t,ux.widget({widget:new kM(!0,"",me(g,W),{from:t,to:t+v.length},g),side:1}));break;case gM.diff_match_patch.DIFF_EQUAL:d+=e,p+=e}}return{asisDecorations:l.finish(),tobeDecorations:c.finish(),asisButtonDecorations:h.finish(),tobeButtonDecorations:u.finish()}}),pe(this,"recalculateDiff",()=>{const e=me(this,W).state.doc.toString(),t=me(this,V).state.doc.toString(),{asisDecorations:i,tobeDecorations:n,asisButtonDecorations:r,tobeButtonDecorations:s}=me(this,ee).call(this,e,t);me(this,W).dispatch({effects:[OM.of(i),yM.of(r)]}),me(this,V).dispatch({effects:[vM.of(n),bM.of(s)]})}),pe(this,"initialize",(e,t,i="javascript")=>{if(!me(this,W)||!me(this,V))return;let n;Oe(this,H,!1),n=Nj(),me(this,W).dispatch({changes:{from:0,to:me(this,W).state.doc.length,insert:e},effects:[me(this,G).reconfigure(n)]}),me(this,V).dispatch({changes:{from:0,to:me(this,V).state.doc.length,insert:t},effects:[me(this,G).reconfigure(n)]}),requestAnimationFrame(()=>{const{asisDecorations:i,tobeDecorations:n,asisButtonDecorations:r,tobeButtonDecorations:s}=me(this,ee).call(this,e,t);me(this,W).dispatch({effects:[OM.of(i),yM.of(r)]}),me(this,V).dispatch({effects:[vM.of(n),bM.of(s)]}),requestAnimationFrame(()=>{Oe(this,H,!0)})})}),this.attachShadow({mode:"open"})}get asisEditorView(){return me(this,W)}get tobeEditorView(){return me(this,V)}connectedCallback(){this.shadowRoot.innerHTML=`\n <style>\n /* ninegrid CSS 및 필요한 기본 스타일 임포트 */\n @import "https://cdn.jsdelivr.net/npm/ninegrid@${t.version}/dist/css/ideDiff.css";\n /* 새로 만든 ideDiff.css 파일 임포트 */\n ${t.getCustomPath(this,"ideDiff.css")}\n </style>\n\n <div class="wrapper">\n <div class="panel asis"></div>\n <nx-splitter></nx-splitter>\n <div class="panel tobe"></div>\n </div>\n `,requestAnimationFrame(()=>{me(this,K).call(this)})}disconnectedCallback(){this._asisScrollHandler&&(me(this,W).scrollDOM.removeEventListener("scroll",this._asisScrollHandler),me(this,V).scrollDOM.removeEventListener("scroll",this._tobeScrollHandler),this._asisScrollHandler=null,this._tobeScrollHandler=null),me(this,W)&&me(this,W).destroy(),me(this,V)&&me(this,V).destroy()}}W=new WeakMap,V=new WeakMap,F=new WeakMap,Y=new WeakMap,G=new WeakMap,H=new WeakMap,K=new WeakMap,J=new WeakMap,ee=new WeakMap,customElements.define("ide-diff",PM);class TM extends HTMLElement{constructor(){super(),ge(this,te),ge(this,ie),ge(this,ne),ge(this,re),ge(this,se),pe(this,"initialize",e=>{Oe(this,re,e.selectFunc),Oe(this,te,e.apiKey),Oe(this,ie,e.xmlPath),Oe(this,ne,e.queryId)}),ge(this,ae,async e=>{if("Enter"===e.key&&!e.isComposing&&me(this,re)){if(me(this,se).disabled=!0,t.loading.show(),me(this,se).value){const e=await gb.generateWhereCause(me(this,ie),me(this,ne),me(this,se).value,me(this,te));!0===e.result?me(this,re).call(this,{_whereClause:e.condition}):(t.loading.hide(),t.alert(e.condition,null,{class:"rgb",animation:"shake"}))}else me(this,re).call(this,{});me(this,se).disabled=!1}}),ge(this,oe,()=>{const e=this.getAttribute("placeholder")||"자연어 검색어를 입력하세요 (ex: 작성자가 홍길동인 데이타를 찾아줘)";this.innerHTML=`\n\t\t\t<input type="text" placeholder="${e}" style="width: 100%;" />\n\t\t`,Oe(this,se,this.querySelector("input")),me(this,se).addEventListener("keydown",me(this,ae))})}connectedCallback(){me(this,oe).call(this)}set selectFunc(e){Oe(this,re,e)}}te=new WeakMap,ie=new WeakMap,ne=new WeakMap,re=new WeakMap,se=new WeakMap,ae=new WeakMap,oe=new WeakMap,customElements.define("ai-natual-input",TM),e.IdeAssi=Ib,e.ai=gb,e.api=Iu,e.default=Ib,e.defineCustomElements=function(){customElements.get("nine-ai")||customElements.define("nine-ai",Ib)},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
237
237
|
//# sourceMappingURL=nine-ai.umd.cjs.map
|