diff --git a/NEWS.md b/NEWS.md
index fea9f0d..fd53ea4 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -16,6 +16,8 @@
* Better handle `echo: false` and `include: false` cell options (#62).
+* Fixed applying the `completion` cell option to `pyodide` cells (#2).
+
# Quarto Live 0.1.1
Initial release.
diff --git a/_extensions/live/resources/live-runtime.js b/_extensions/live/resources/live-runtime.js
index 697b2e8..9f45467 100644
--- a/_extensions/live/resources/live-runtime.js
+++ b/_extensions/live/resources/live-runtime.js
@@ -9,25 +9,25 @@ var vO=Object.defineProperty;var ci=(i=>typeof require<"u"?require:typeof Proxy<
`});var sO=jt((QP,Gk)=>{Gk.exports=``});var fO=jt((sC,Kk)=>{Kk.exports="CmltcG9ydCBweW9kaWRlICMgdHlwZTogaWdub3JlW2F0dHItZGVmaW5lZF0KaW1wb3J0IHN5cwoKIyBDbGVhbnVwIGFueSBsZWZ0b3ZlciBtYXRwbG90bGliIHBsb3RzCnRyeToKICBpbXBvcnQgbWF0cGxvdGxpYi5weXBsb3QgYXMgcGx0CiAgcGx0LmNsb3NlKCJhbGwiKQogIHBsdC5yY1BhcmFtc1siZmlndXJlLmZpZ3NpemUiXSA9ICh3aWR0aCwgaGVpZ2h0KSAjIHR5cGU6IGlnbm9yZVthdHRyLWRlZmluZWRdCiAgcGx0LnJjUGFyYW1zWyJmaWd1cmUuZHBpIl0gPSBkcGkgIyB0eXBlOiBpZ25vcmVbYXR0ci1kZWZpbmVkXQpleGNlcHQgTW9kdWxlTm90Rm91bmRFcnJvcjoKICBwYXNzCgpmcm9tIElQeXRob24udXRpbHMgaW1wb3J0IGNhcHR1cmUKZnJvbSBJUHl0aG9uLmRpc3BsYXkgaW1wb3J0IGRpc3BsYXkKZnJvbSBJUHl0aG9uLmNvcmUuaW50ZXJhY3RpdmVzaGVsbCBpbXBvcnQgSW50ZXJhY3RpdmVTaGVsbApJbnRlcmFjdGl2ZVNoZWxsKCkuaW5zdGFuY2UoKQoKd2l0aCBjYXB0dXJlLm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AgICBkZWYgc2V0X2NhcHN0eWxlKHNlbGYsIGNzKToKICAgICAgICBpZiBjcyBpbiBbImJ1dHQiLCAicm91bmQiLCAicHJvamVjdGluZyJdOgogICAgICAgICAgICBzZWxmLl9jYXBzdHlsZSA9IGNzCiAgICAgICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LmxpbmVDYXAgPSBfY2Fwc3R5bGVfZFtjc10KICAgICAgICBlbHNlOgogICAgICAgICAgICByYWlzZSBWYWx1ZUVycm9yKGYiVW5yZWNvZ25pemVkIGNhcCBzdHlsZS4gRm91bmQge2NzfSIpCgogICAgZGVmIHNldF9jbGlwX3JlY3RhbmdsZShzZWxmLCByZWN0YW5nbGUpOgogICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LnNhdmUoKQogICAgICAgIGlmIG5vdCByZWN0YW5nbGU6CiAgICAgICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LnJlc3RvcmUoKQogICAgICAgICAgICByZXR1cm4KICAgICAgICB4LCB5LCB3LCBoID0gbnAucm91bmQocmVjdGFuZ2xlLmJvdW5kcykKICAgICAgICBzZWxmLnJlbmRlcmVyLmN0eC5iZWdpblBhdGgoKQogICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LnJlY3QoeCwgc2VsZi5yZW5kZXJlci5oZWlnaHQgLSB5IC0gaCwgdywgaCkKICAgICAgICBzZWxmLnJlbmRlcmVyLmN0eC5jbGlwKCkKCiAgICBkZWYgc2V0X2NsaXBfcGF0aChzZWxmLCBwYXRoKToKICAgICAgICBzZWxmLnJlbmRlcmVyLmN0eC5zYXZlKCkKICAgICAgICBpZiBub3QgcGF0aDoKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHgucmVzdG9yZSgpCiAgICAgICAgICAgIHJldHVybgogICAgICAgIHRwYXRoLCBhZmZpbmUgPSBwYXRoLmdldF90cmFuc2Zvcm1lZF9wYXRoX2FuZF9hZmZpbmUoKQogICAgICAgIGFmZmluZSA9IGFmZmluZSArIEFmZmluZTJEKCkuc2NhbGUoMSwgLTEpLnRyYW5zbGF0ZSgwLCBzZWxmLnJlbmRlcmVyLmhlaWdodCkKICAgICAgICBzZWxmLnJlbmRlcmVyLl9wYXRoX2hlbHBlcihzZWxmLnJlbmRlcmVyLmN0eCwgdHBhdGgsIGFmZmluZSkKICAgICAgICBzZWxmLnJlbmRlcmVyLmN0eC5jbGlwKCkKCiAgICBkZWYgc2V0X2Rhc2hlcyhzZWxmLCBkYXNoX29mZnNldCwgZGFzaF9saXN0KToKICAgICAgICBzZWxmLl9kYXNoZXMgPSBkYXNoX29mZnNldCwgZGFzaF9saXN0CiAgICAgICAgaWYgZGFzaF9vZmZzZXQgaXMgbm90IE5vbmU6CiAgICAgICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LmxpbmVEYXNoT2Zmc2V0ID0gZGFzaF9vZmZzZXQKICAgICAgICBpZiBkYXNoX2xpc3QgaXMgTm9uZToKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHguc2V0TGluZURhc2goW10pCiAgICAgICAgZWxzZToKICAgICAgICAgICAgZGxuID0gbnAuYXNhcnJheShkYXNoX2xpc3QpCiAgICAgICAgICAgIGRsID0gbGlzdChzZWxmLnJlbmRlcmVyLnBvaW50c190b19waXhlbHMoZGxuKSkKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHguc2V0TGluZURhc2goZGwpCgogICAgZGVmIHNldF9qb2luc3R5bGUoc2VsZiwganMpOgogICAgICAgIGlmIGpzIGluIFsibWl0ZXIiLCAicm91bmQiLCAiYmV2ZWwiXToKICAgICAgICAgICAgc2VsZi5fam9pbnN0eWxlID0ganMKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHgubGluZUpvaW4gPSBqcwogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJhaXNlIFZhbHVlRXJyb3IoZiJVbnJlY29nbml6ZWQgam9pbiBzdHlsZS4gRm91bmQge2pzfSIpCgogICAgZGVmIHNldF9saW5ld2lkdGgoc2V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G9fQ1NTKHNlbGYsIGNvbG9yLCBhbHBoYSwgYWxwaGFfb3ZlcnJpZGVzLCBpc19SR0I9VHJ1ZSk6CiAgICAgICAgaWYgbm90IGlzX1JHQjoKICAgICAgICAgICAgUiwgRywgQiwgYWxwaGEgPSBjb2xvckNvbnZlcnRlci50b19yZ2JhKGNvbG9yKQogICAgICAgICAgICBjb2xvciA9IChSLCBHLCBCKQoKICAgICAgICBpZiAobGVuKGNvbG9yKSA9PSA0KSBhbmQgKGFscGhhIGlzIE5vbmUpOgogICAgICAgICAgICBhbHBoYSA9IGNvbG9yWzNdCgogICAgICAgIGlmIGFscGhhIGlzIE5vbmU6CiAgICAgICAgICAgIENTU19jb2xvciA9IHJnYjJoZXgoY29sb3JbOjNdKQoKICAgICAgICBlbHNlOgogICAgICAgICAgICBSID0gaW50KGNvbG9yWzBdICogMjU1KQogICAgICAgICAgICBHID0gaW50KGNvbG9yWzFdICogMjU1KQogICAgICAgICAgICBCID0gaW50KGNvbG9yWzJdICogMjU1KQogICAgICAgICAgICBpZiBsZW4oY29sb3IpID09IDMgb3IgYWxwaGFfb3ZlcnJpZGVzOgogICAgICAgICAgICAgICAgQ1NTX2NvbG9yID0gZiIiInJnYmEoe1I6ZH0sIHtHOmR9LCB7QjpkfSwge2FscGhhOi4zZ30pIiIiCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBDU1NfY29sb3IgPSAiIiJyZ2JhKHs6ZH0sIHs6ZH0sIHs6ZH0sIHs6LjNnfSkiIiIuZm9ybWF0KAogICAgICAgICAgICAgICAgICAgIFIsIEcsIEIsIGNvbG9yWzNdCiAgICAgICAgICAgICAgICApCgogICAgICAgIHJldHVybiBDU1NfY29sb3IKCiAgICBkZWYgX3NldF9zdHlsZShzZWxmLCBnYywgcmdiRmFjZT1Ob25lKToKICAgICAgICBpZiByZ2JGYWNlIGlzIG5vdCBOb25lOgogICAgICAgICAgICBzZWxmLmN0eC5maWxsU3R5bGUgPSBzZWxmLl9tYXRwbG90bGliX2NvbG9yX3RvX0NTUygKICAgICAgICAgICAgICAgIHJnYkZhY2UsIGdjLmdldF9hbHBoYSgpLCBnYy5nZXRfZm9yY2VkX2FscGhhKCkKICAgICAgICAgICAgKQoKICAgICAgICBpZiBnYy5nZXRfY2Fwc3R5bGUoKToKICAgICAgICAgICAgc2VsZi5jdHgubGluZUNhcCA9IF9jYXBzdHlsZV9kW2djLmdldF9jYXBzdHlsZSgpXQoKICAgICAgICBzZWxmLmN0eC5zdHJva2VTdHlsZSA9IHNlbGYuX21hdHBsb3RsaWJfY29sb3JfdG9fQ1NTKAogICAgICAgICAgICBnYy5nZXRfcmdiKCksIGdjLmdldF9hbHBoYSgpLCBnYy5nZXRfZm9yY2VkX2FscGhhKCkKICAgICAgICApCgogICAgICAgIHNlbGYuY3R4LmxpbmVXaWR0aCA9IHNlbGYucG9pbnRzX3RvX3BpeGVscyhnYy5nZXRfbGluZXdpZHRoKCkpCgogICAgZGVmIF9wYXRoX2hlbHBlcihzZWxmLCBjdHgsIHBhdGgsIHRyYW5zZm9ybSwgY2xpcD1Ob25lKToKICAgICAgICBjdHguYmVnaW5QYXRoKCkKICAgICAgICBmb3IgcG9pbnRzLCBjb2RlIGluIHBhdGguaXRlcl9zZWdtZW50cyh0cmFuc2Zvcm0sIHJlbW92ZV9uYW5zPVRydWUsIGNsaXA9Y2xpcCk6CiAgICAgICAgICAgIGlmIGNvZGUgPT0gUGF0aC5NT1ZFVE86CiAgICAgICAgICAgICAgICBjdHgubW92ZVRvKHBvaW50c1swXSwgcG9pbnRzWzFdKQogICAgICAgICAgICBlbGlmIGNvZGUgPT0gUGF0aC5MSU5FVE86CiAgICAgICAgICAgICAgICBjdHgubGluZVRvKHBvaW50c1swXSwgcG9pbnRzWzFdKQogICAgICAgICAgICBlbGlmIGNvZGUgPT0gUGF0aC5DVVJWRTM6CiAgICAgICAgICAgICAgICBjdHgucXVhZHJhdGljQ3VydmVUbygqcG9pbnRzKQogICAgICAgICAgICBlbG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0aCwgbWFya2VyX3RyYW5zLCBwYXRoLCB0cmFucywgcmdiRmFjZSkKCiAgICBkZWYgX2dldF9mb250KHNlbGYsIHByb3ApOgogICAgICAgIGtleSA9IGhhc2gocHJvcCkKICAgICAgICBmb250X3ZhbHVlID0gc2VsZi5mb250ZC5nZXQoa2V5KQogICAgICAgIGlmIGZvbnRfdmFsdWUgaXMgTm9uZToKICAgICAgICAgICAgZm5hbWUgPSBmaW5kZm9udChwcm9wKQogICAgICAgICAgICBmb250X3ZhbHVlID0gc2VsZi5mb250ZC5nZXQoZm5hbWUpCiAgICAgICAgICAgIGlmIGZvbnRfdmFsdWUgaXMgTm9uZToKICAgICAgICAgICAgICAgIGZvbnQgPSBGVDJGb250KHN0cihmbmFtZSkpCiAgICAgICAgICAgICAgICBmb250X2ZpbGVfbmFtZSA9IGZuYW1lW2ZuYW1lLnJmaW5kKCIvIikgKyAxIDpdCiAgICAgICAgICAgICAgICBmb250X3ZhbHVlID0gZm9udCwgZm9udF9maWxlX25hbWUKICAgICAgICAgICAgICAgIHNlbGYuZm9udGRbZm5hbWVdID0gZm9udF92YWx1ZQogICAgICAgICAgICBzZWxmLmZvbnRkW2tleV0gPSBmb250X3ZhbHVlCiAgICAgICAgZm9udCwgZm9udF9maWxlX25hbWUgPSBmb250X3ZhbHVlCiAgICAgICAgZm9udC5jbGVhcigpCiAgICAgICAgZm9udC5zZXRfc2l6ZShwcm9wLmdldF9zaXplX2luX3BvaW50cygpLCBzZWxmLmRwaSkKICAgICAgICByZXR1cm4gZm9udCwgZm9udF9maWxlX25hbWUKCiAgICBkZWYgZ2V0X3RleHRfd2lkdGhfaGVpZ2h0X2Rlc2NlbnQoc2VsZiwgcywgcHJvcCwgaXNtYXRoKToKICAgICAgICB3OiBmbG9hdAogICAgICAgIGg6IGZsb2F0CiAgICAgICAgaWYgaXNtYXRoOgogICAgICAgICAgICBpbWFnZSwgZCA9IHNlbGYubWF0aHRleHRfcGFyc2VyLnBhcnNlKHMsIHNlbGY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gRmlndXJlTWFuYWdlciA9IEZpZ3VyZU1hbmFnZXJIVE1MQ2FudmFzCgogICAgQHN0YXRpY21ldGhvZAogICAgZGVmIHNob3coKmFyZ3MsICoqa3dhcmdzKToKICAgICAgICBmcm9tIG1hdHBsb3RsaWIgaW1wb3J0IHB5cGxvdCBhcyBwbHQKICAgICAgICBwbHQuZ2NmKCkuY2FudmFzLnNob3coKmFyZ3MsICoqa3dhcmdzKQoKICAgIEBzdGF0aWNtZXRob2QKICAgIGRlZiBkZXN0cm95KCphcmdzLCAqKmt3YXJncyk6CiAgICAgICAgZnJvbSBtYXRwbG90bGliIGltcG9ydCBweXBsb3QgYXMgcGx0CiAgICAgICAgcGx0LmdjZigpLmNhbnZhcy5kZXN0cm95KCphcmdzLCAqKmt3YXJncykK"});var Ka={};xO(Ka,{ChannelType:()=>Qt,Console:()=>M0,Shelter:()=>Ba,WebR:()=>Uf,WebRChannelError:()=>pt,WebRError:()=>di,WebRPayloadError:()=>Bn,WebRWorkerError:()=>wf,isRCall:()=>ms,isRCharacter:()=>Ui,isRComplex:()=>R0,isRDouble:()=>C0,isREnvironment:()=>S0,isRFunction:()=>gs,isRInteger:()=>P0,isRList:()=>ot,isRLogical:()=>T0,isRNull:()=>Re,isRObject:()=>ee,isRPairlist:()=>k0,isRRaw:()=>Ja,isRSymbol:()=>x0});var kO=Object.create,pf=Object.defineProperty,SO=Object.getOwnPropertyDescriptor,TO=Object.getOwnPropertyNames,PO=Object.getPrototypeOf,CO=Object.prototype.hasOwnProperty,Bi=(i=>typeof ci<"u"?ci:typeof Proxy<"u"?new Proxy(i,{get:(e,t)=>(typeof ci<"u"?ci:e)[t]}):i)(function(i){if(typeof ci<"u")return ci.apply(this,arguments);throw new Error('Dynamic require of "'+i+'" is not supported')}),ke=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),RO=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of TO(e))!CO.call(i,r)&&r!==t&&pf(i,r,{get:()=>e[r],enumerable:!(n=SO(e,r))||n.enumerable});return i},Xi=(i,e,t)=>(t=i!=null?kO(PO(i)):{},RO(e||!i||!i.__esModule?pf(t,"default",{value:i,enumerable:!0}):t,i)),Xa=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)},k=(i,e,t)=>(Xa(i,e,"read from private field"),t?t.call(i):e.get(i)),L=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)},me=(i,e,t,n)=>(Xa(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);var Je=(i,e,t)=>(Xa(i,e,"access private method"),t),hs=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.getUint64=i.getInt64=i.setInt64=i.setUint64=i.UINT32_MAX=void 0,i.UINT32_MAX=4294967295;function e(s,o,a){let l=a/4294967296,h=a;s.setUint32(o,l),s.setUint32(o+4,h)}i.setUint64=e;function t(s,o,a){let l=Math.floor(a/4294967296),h=a;s.setUint32(o,l),s.setUint32(o+4,h)}i.setInt64=t;function n(s,o){let a=s.getInt32(o),l=s.getUint32(o+4);return a*4294967296+l}i.getInt64=n;function r(s,o){let a=s.getUint32(o),l=s.getUint32(o+4);return a*4294967296+l}i.getUint64=r}),Wa=ke(i=>{"use strict";var e,t,n;Object.defineProperty(i,"__esModule",{value:!0}),i.utf8DecodeTD=i.TEXT_DECODER_THRESHOLD=i.utf8DecodeJs=i.utf8EncodeTE=i.TEXT_ENCODER_THRESHOLD=i.utf8EncodeJs=i.utf8Count=void 0;var r=hs(),s=(typeof process>"u"||((e=process==null?void 0:process.env)===null||e===void 0?void 0:e.TEXT_ENCODING)!=="never")&&typeof TextEncoder<"u"&&typeof TextDecoder<"u";function o(p){let g=p.length,O=0,y=0;for(;y=55296&&v<=56319&&y>6&31|192;else{if(w>=55296&&w<=56319&&x>18&7|240,g[v++]=w>>12&63|128,g[v++]=w>>6&63|128):(g[v++]=w>>12&15|224,g[v++]=w>>6&63|128)}else{g[v++]=w;continue}g[v++]=w&63|128}}i.utf8EncodeJs=a;var l=s?new TextEncoder:void 0;i.TEXT_ENCODER_THRESHOLD=s?typeof process<"u"&&((t=process==null?void 0:process.env)===null||t===void 0?void 0:t.TEXT_ENCODING)!=="force"?200:0:r.UINT32_MAX;function h(p,g,O){g.set(l.encode(p),O)}function c(p,g,O){l.encodeInto(p,g.subarray(O))}i.utf8EncodeTE=l!=null&&l.encodeInto?c:h;var f=4096;function u(p,g,O){let y=g,v=y+O,x=[],w="";for(;y65535&&(V-=65536,x.push(V>>>10&1023|55296),V=56320|V&1023),x.push(V)}else x.push(P);x.length>=f&&(w+=String.fromCharCode(...x),x.length=0)}return x.length>0&&(w+=String.fromCharCode(...x)),w}i.utf8DecodeJs=u;var d=s?new TextDecoder:null;i.TEXT_DECODER_THRESHOLD=s?typeof process<"u"&&((n=process==null?void 0:process.env)===null||n===void 0?void 0:n.TEXT_DECODER)!=="force"?200:0:r.UINT32_MAX;function m(p,g,O){let y=p.subarray(g,g+O);return d.decode(y)}i.utf8DecodeTD=m}),mf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ExtData=void 0;var e=class{constructor(t,n){this.type=t,this.data=n}};i.ExtData=e}),Ia=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DecodeError=void 0;var e=class extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:e.name})}};i.DecodeError=e}),gf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.timestampExtension=i.decodeTimestampExtension=i.decodeTimestampToTimeSpec=i.encodeTimestampExtension=i.encodeDateToTimeSpec=i.encodeTimeSpecToTimestamp=i.EXT_TIMESTAMP=void 0;var e=Ia(),t=hs();i.EXT_TIMESTAMP=-1;var n=4294967296-1,r=17179869184-1;function s({sec:c,nsec:f}){if(c>=0&&f>=0&&c<=r)if(f===0&&c<=n){let u=new Uint8Array(4);return new DataView(u.buffer).setUint32(0,c),u}else{let u=c/4294967296,d=c&4294967295,m=new Uint8Array(8),p=new DataView(m.buffer);return p.setUint32(0,f<<2|u&3),p.setUint32(4,d),m}else{let u=new Uint8Array(12),d=new DataView(u.buffer);return d.setUint32(0,f),(0,t.setInt64)(d,4,c),u}}i.encodeTimeSpecToTimestamp=s;function o(c){let f=c.getTime(),u=Math.floor(f/1e3),d=(f-u*1e3)*1e6,m=Math.floor(d/1e9);return{sec:u+m,nsec:d-m*1e9}}i.encodeDateToTimeSpec=o;function a(c){if(c instanceof Date){let f=o(c);return s(f)}else return null}i.encodeTimestampExtension=a;function l(c){let f=new DataView(c.buffer,c.byteOffset,c.byteLength);switch(c.byteLength){case 4:return{sec:f.getUint32(0),nsec:0};case 8:{let u=f.getUint32(0),d=f.getUint32(4),m=(u&3)*4294967296+d,p=u>>>2;return{sec:m,nsec:p}}case 12:{let u=(0,t.getInt64)(f,4),d=f.getUint32(0);return{sec:u,nsec:d}}default:throw new e.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${c.length}`)}}i.decodeTimestampToTimeSpec=l;function h(c){let f=l(c);return new Date(f.sec*1e3+f.nsec/1e6)}i.decodeTimestampExtension=h,i.timestampExtension={type:i.EXT_TIMESTAMP,encode:a,decode:h}}),Na=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ExtensionCodec=void 0;var e=mf(),t=gf(),n=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(t.timestampExtension)}register({type:r,encode:s,decode:o}){if(r>=0)this.encoders[r]=s,this.decoders[r]=o;else{let a=1+r;this.builtInEncoders[a]=s,this.builtInDecoders[a]=o}}tryToEncode(r,s){for(let o=0;o{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.createDataView=i.ensureUint8Array=void 0;function e(n){return n instanceof Uint8Array?n:ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):n instanceof ArrayBuffer?new Uint8Array(n):Uint8Array.from(n)}i.ensureUint8Array=e;function t(n){if(n instanceof ArrayBuffer)return new DataView(n);let r=e(n);return new DataView(r.buffer,r.byteOffset,r.byteLength)}i.createDataView=t}),yf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Encoder=i.DEFAULT_INITIAL_BUFFER_SIZE=i.DEFAULT_MAX_DEPTH=void 0;var e=Wa(),t=Na(),n=hs(),r=Of();i.DEFAULT_MAX_DEPTH=100,i.DEFAULT_INITIAL_BUFFER_SIZE=2048;var s=class{constructor(o=t.ExtensionCodec.defaultCodec,a=void 0,l=i.DEFAULT_MAX_DEPTH,h=i.DEFAULT_INITIAL_BUFFER_SIZE,c=!1,f=!1,u=!1,d=!1){this.extensionCodec=o,this.context=a,this.maxDepth=l,this.initialBufferSize=h,this.sortKeys=c,this.forceFloat32=f,this.ignoreUndefined=u,this.forceIntegerToFloat=d,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}reinitializeState(){this.pos=0}encodeSharedRef(o){return this.reinitializeState(),this.doEncode(o,1),this.bytes.subarray(0,this.pos)}encode(o){return this.reinitializeState(),this.doEncode(o,1),this.bytes.slice(0,this.pos)}doEncode(o,a){if(a>this.maxDepth)throw new Error(`Too deep objects in depth ${a}`);o==null?this.encodeNil():typeof o=="boolean"?this.encodeBoolean(o):typeof o=="number"?this.encodeNumber(o):typeof o=="string"?this.encodeString(o):this.encodeObject(o,a)}ensureBufferSizeToWrite(o){let a=this.pos+o;this.view.byteLength=0?o<128?this.writeU8(o):o<256?(this.writeU8(204),this.writeU8(o)):o<65536?(this.writeU8(205),this.writeU16(o)):o<4294967296?(this.writeU8(206),this.writeU32(o)):(this.writeU8(207),this.writeU64(o)):o>=-32?this.writeU8(224|o+32):o>=-128?(this.writeU8(208),this.writeI8(o)):o>=-32768?(this.writeU8(209),this.writeI16(o)):o>=-2147483648?(this.writeU8(210),this.writeI32(o)):(this.writeU8(211),this.writeI64(o)):this.forceFloat32?(this.writeU8(202),this.writeF32(o)):(this.writeU8(203),this.writeF64(o))}writeStringHeader(o){if(o<32)this.writeU8(160+o);else if(o<256)this.writeU8(217),this.writeU8(o);else if(o<65536)this.writeU8(218),this.writeU16(o);else if(o<4294967296)this.writeU8(219),this.writeU32(o);else throw new Error(`Too long string: ${o} bytes in UTF-8`)}encodeString(o){if(o.length>e.TEXT_ENCODER_THRESHOLD){let a=(0,e.utf8Count)(o);this.ensureBufferSizeToWrite(5+a),this.writeStringHeader(a),(0,e.utf8EncodeTE)(o,this.bytes,this.pos),this.pos+=a}else{let a=(0,e.utf8Count)(o);this.ensureBufferSizeToWrite(5+a),this.writeStringHeader(a),(0,e.utf8EncodeJs)(o,this.bytes,this.pos),this.pos+=a}}encodeObject(o,a){let l=this.extensionCodec.tryToEncode(o,this.context);if(l!=null)this.encodeExtension(l);else if(Array.isArray(o))this.encodeArray(o,a);else if(ArrayBuffer.isView(o))this.encodeBinary(o);else if(typeof o=="object")this.encodeMap(o,a);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(o)}`)}encodeBinary(o){let a=o.byteLength;if(a<256)this.writeU8(196),this.writeU8(a);else if(a<65536)this.writeU8(197),this.writeU16(a);else if(a<4294967296)this.writeU8(198),this.writeU32(a);else throw new Error(`Too large binary: ${a}`);let l=(0,r.ensureUint8Array)(o);this.writeU8a(l)}encodeArray(o,a){let l=o.length;if(l<16)this.writeU8(144+l);else if(l<65536)this.writeU8(220),this.writeU16(l);else if(l<4294967296)this.writeU8(221),this.writeU32(l);else throw new Error(`Too large array: ${l}`);for(let h of o)this.doEncode(h,a+1)}countWithoutUndefined(o,a){let l=0;for(let h of a)o[h]!==void 0&&l++;return l}encodeMap(o,a){let l=Object.keys(o);this.sortKeys&&l.sort();let h=this.ignoreUndefined?this.countWithoutUndefined(o,l):l.length;if(h<16)this.writeU8(128+h);else if(h<65536)this.writeU8(222),this.writeU16(h);else if(h<4294967296)this.writeU8(223),this.writeU32(h);else throw new Error(`Too large map object: ${h}`);for(let c of l){let f=o[c];this.ignoreUndefined&&f===void 0||(this.encodeString(c),this.doEncode(f,a+1))}}encodeExtension(o){let a=o.data.length;if(a===1)this.writeU8(212);else if(a===2)this.writeU8(213);else if(a===4)this.writeU8(214);else if(a===8)this.writeU8(215);else if(a===16)this.writeU8(216);else if(a<256)this.writeU8(199),this.writeU8(a);else if(a<65536)this.writeU8(200),this.writeU16(a);else if(a<4294967296)this.writeU8(201),this.writeU32(a);else throw new Error(`Too large extension object: ${a}`);this.writeI8(o.type),this.writeU8a(o.data)}writeU8(o){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,o),this.pos++}writeU8a(o){let a=o.length;this.ensureBufferSizeToWrite(a),this.bytes.set(o,this.pos),this.pos+=a}writeI8(o){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,o),this.pos++}writeU16(o){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,o),this.pos+=2}writeI16(o){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,o),this.pos+=2}writeU32(o){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,o),this.pos+=4}writeI32(o){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,o),this.pos+=4}writeF32(o){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,o),this.pos+=4}writeF64(o){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,o),this.pos+=8}writeU64(o){this.ensureBufferSizeToWrite(8),(0,n.setUint64)(this.view,this.pos,o),this.pos+=8}writeI64(o){this.ensureBufferSizeToWrite(8),(0,n.setInt64)(this.view,this.pos,o),this.pos+=8}};i.Encoder=s}),EO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.encode=void 0;var e=yf(),t={};function n(r,s=t){return new e.Encoder(s.extensionCodec,s.context,s.maxDepth,s.initialBufferSize,s.sortKeys,s.forceFloat32,s.ignoreUndefined,s.forceIntegerToFloat).encodeSharedRef(r)}i.encode=n}),AO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.prettyByte=void 0;function e(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}i.prettyByte=e}),QO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CachedKeyDecoder=void 0;var e=Wa(),t=16,n=16,r=class{constructor(s=t,o=n){this.maxKeyLength=s,this.maxLengthPerKey=o,this.hit=0,this.miss=0,this.caches=[];for(let a=0;a0&&s<=this.maxKeyLength}find(s,o,a){let l=this.caches[a-1];e:for(let h of l){let c=h.bytes;for(let f=0;f=this.maxLengthPerKey?a[Math.random()*a.length|0]=l:a.push(l)}decode(s,o,a){let l=this.find(s,o,a);if(l!=null)return this.hit++,l;this.miss++;let h=(0,e.utf8DecodeJs)(s,o,a),c=Uint8Array.prototype.slice.call(s,o,o+a);return this.store(c,h),h}};i.CachedKeyDecoder=r}),ja=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Decoder=i.DataViewIndexOutOfBoundsError=void 0;var e=AO(),t=Na(),n=hs(),r=Wa(),s=Of(),o=QO(),a=Ia(),l=p=>{let g=typeof p;return g==="string"||g==="number"},h=-1,c=new DataView(new ArrayBuffer(0)),f=new Uint8Array(c.buffer);i.DataViewIndexOutOfBoundsError=(()=>{try{c.getInt8(0)}catch(p){return p.constructor}throw new Error("never reached")})();var u=new i.DataViewIndexOutOfBoundsError("Insufficient data"),d=new o.CachedKeyDecoder,m=class{constructor(p=t.ExtensionCodec.defaultCodec,g=void 0,O=n.UINT32_MAX,y=n.UINT32_MAX,v=n.UINT32_MAX,x=n.UINT32_MAX,w=n.UINT32_MAX,P=d){this.extensionCodec=p,this.context=g,this.maxStrLength=O,this.maxBinLength=y,this.maxArrayLength=v,this.maxMapLength=x,this.maxExtLength=w,this.keyDecoder=P,this.totalPos=0,this.pos=0,this.view=c,this.bytes=f,this.headByte=h,this.stack=[]}reinitializeState(){this.totalPos=0,this.headByte=h,this.stack.length=0}setBuffer(p){this.bytes=(0,s.ensureUint8Array)(p),this.view=(0,s.createDataView)(this.bytes),this.pos=0}appendBuffer(p){if(this.headByte===h&&!this.hasRemaining(1))this.setBuffer(p);else{let g=this.bytes.subarray(this.pos),O=(0,s.ensureUint8Array)(p),y=new Uint8Array(g.length+O.length);y.set(g),y.set(O,g.length),this.setBuffer(y)}}hasRemaining(p){return this.view.byteLength-this.pos>=p}createExtraByteError(p){let{view:g,pos:O}=this;return new RangeError(`Extra ${g.byteLength-O} of ${g.byteLength} byte(s) found at buffer[${p}]`)}decode(p){this.reinitializeState(),this.setBuffer(p);let g=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return g}*decodeMulti(p){for(this.reinitializeState(),this.setBuffer(p);this.hasRemaining(1);)yield this.doDecodeSync()}async decodeAsync(p){let g=!1,O;for await(let w of p){if(g)throw this.createExtraByteError(this.totalPos);this.appendBuffer(w);try{O=this.doDecodeSync(),g=!0}catch(P){if(!(P instanceof i.DataViewIndexOutOfBoundsError))throw P}this.totalPos+=this.pos}if(g){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return O}let{headByte:y,pos:v,totalPos:x}=this;throw new RangeError(`Insufficient data in parsing ${(0,e.prettyByte)(y)} at ${x} (${v} in the current buffer)`)}decodeArrayStream(p){return this.decodeMultiAsync(p,!0)}decodeStream(p){return this.decodeMultiAsync(p,!1)}async*decodeMultiAsync(p,g){let O=g,y=-1;for await(let v of p){if(g&&y===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(v),O&&(y=this.readArraySize(),O=!1,this.complete());try{for(;yield this.doDecodeSync(),--y!==0;);}catch(x){if(!(x instanceof i.DataViewIndexOutOfBoundsError))throw x}this.totalPos+=this.pos}}doDecodeSync(){e:for(;;){let p=this.readHeadByte(),g;if(p>=224)g=p-256;else if(p<192)if(p<128)g=p;else if(p<144){let y=p-128;if(y!==0){this.pushMapState(y),this.complete();continue e}else g={}}else if(p<160){let y=p-144;if(y!==0){this.pushArrayState(y),this.complete();continue e}else g=[]}else{let y=p-160;g=this.decodeUtf8String(y,0)}else if(p===192)g=null;else if(p===194)g=!1;else if(p===195)g=!0;else if(p===202)g=this.readF32();else if(p===203)g=this.readF64();else if(p===204)g=this.readU8();else if(p===205)g=this.readU16();else if(p===206)g=this.readU32();else if(p===207)g=this.readU64();else if(p===208)g=this.readI8();else if(p===209)g=this.readI16();else if(p===210)g=this.readI32();else if(p===211)g=this.readI64();else if(p===217){let y=this.lookU8();g=this.decodeUtf8String(y,1)}else if(p===218){let y=this.lookU16();g=this.decodeUtf8String(y,2)}else if(p===219){let y=this.lookU32();g=this.decodeUtf8String(y,4)}else if(p===220){let y=this.readU16();if(y!==0){this.pushArrayState(y),this.complete();continue e}else g=[]}else if(p===221){let y=this.readU32();if(y!==0){this.pushArrayState(y),this.complete();continue e}else g=[]}else if(p===222){let y=this.readU16();if(y!==0){this.pushMapState(y),this.complete();continue e}else g={}}else if(p===223){let y=this.readU32();if(y!==0){this.pushMapState(y),this.complete();continue e}else g={}}else if(p===196){let y=this.lookU8();g=this.decodeBinary(y,1)}else if(p===197){let y=this.lookU16();g=this.decodeBinary(y,2)}else if(p===198){let y=this.lookU32();g=this.decodeBinary(y,4)}else if(p===212)g=this.decodeExtension(1,0);else if(p===213)g=this.decodeExtension(2,0);else if(p===214)g=this.decodeExtension(4,0);else if(p===215)g=this.decodeExtension(8,0);else if(p===216)g=this.decodeExtension(16,0);else if(p===199){let y=this.lookU8();g=this.decodeExtension(y,1)}else if(p===200){let y=this.lookU16();g=this.decodeExtension(y,2)}else if(p===201){let y=this.lookU32();g=this.decodeExtension(y,4)}else throw new a.DecodeError(`Unrecognized type byte: ${(0,e.prettyByte)(p)}`);this.complete();let O=this.stack;for(;O.length>0;){let y=O[O.length-1];if(y.type===0)if(y.array[y.position]=g,y.position++,y.position===y.size)O.pop(),g=y.array;else continue e;else if(y.type===1){if(!l(g))throw new a.DecodeError("The type of key must be string or number but "+typeof g);if(g==="__proto__")throw new a.DecodeError("The key __proto__ is not allowed");y.key=g,y.type=2;continue e}else if(y.map[y.key]=g,y.readCount++,y.readCount===y.size)O.pop(),g=y.map;else{y.key=null,y.type=1;continue e}}return g}}readHeadByte(){return this.headByte===h&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=h}readArraySize(){let p=this.readHeadByte();switch(p){case 220:return this.readU16();case 221:return this.readU32();default:{if(p<160)return p-144;throw new a.DecodeError(`Unrecognized array type byte: ${(0,e.prettyByte)(p)}`)}}}pushMapState(p){if(p>this.maxMapLength)throw new a.DecodeError(`Max length exceeded: map length (${p}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.push({type:1,size:p,key:null,readCount:0,map:{}})}pushArrayState(p){if(p>this.maxArrayLength)throw new a.DecodeError(`Max length exceeded: array length (${p}) > maxArrayLength (${this.maxArrayLength})`);this.stack.push({type:0,size:p,array:new Array(p),position:0})}decodeUtf8String(p,g){var O;if(p>this.maxStrLength)throw new a.DecodeError(`Max length exceeded: UTF-8 byte length (${p}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLengthr.TEXT_DECODER_THRESHOLD?v=(0,r.utf8DecodeTD)(this.bytes,y,p):v=(0,r.utf8DecodeJs)(this.bytes,y,p),this.pos+=g+p,v}stateIsMapKey(){return this.stack.length>0?this.stack[this.stack.length-1].type===1:!1}decodeBinary(p,g){if(p>this.maxBinLength)throw new a.DecodeError(`Max length exceeded: bin length (${p}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(p+g))throw u;let O=this.pos+g,y=this.bytes.subarray(O,O+p);return this.pos+=g+p,y}decodeExtension(p,g){if(p>this.maxExtLength)throw new a.DecodeError(`Max length exceeded: ext length (${p}) > maxExtLength (${this.maxExtLength})`);let O=this.view.getInt8(this.pos+g),y=this.decodeBinary(p,g+1);return this.extensionCodec.decode(y,O,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let p=this.view.getUint8(this.pos);return this.pos++,p}readI8(){let p=this.view.getInt8(this.pos);return this.pos++,p}readU16(){let p=this.view.getUint16(this.pos);return this.pos+=2,p}readI16(){let p=this.view.getInt16(this.pos);return this.pos+=2,p}readU32(){let p=this.view.getUint32(this.pos);return this.pos+=4,p}readI32(){let p=this.view.getInt32(this.pos);return this.pos+=4,p}readU64(){let p=(0,n.getUint64)(this.view,this.pos);return this.pos+=8,p}readI64(){let p=(0,n.getInt64)(this.view,this.pos);return this.pos+=8,p}readF32(){let p=this.view.getFloat32(this.pos);return this.pos+=4,p}readF64(){let p=this.view.getFloat64(this.pos);return this.pos+=8,p}};i.Decoder=m}),bf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.decodeMulti=i.decode=i.defaultDecodeOptions=void 0;var e=ja();i.defaultDecodeOptions={};function t(r,s=i.defaultDecodeOptions){return new e.Decoder(s.extensionCodec,s.context,s.maxStrLength,s.maxBinLength,s.maxArrayLength,s.maxMapLength,s.maxExtLength).decode(r)}i.decode=t;function n(r,s=i.defaultDecodeOptions){return new e.Decoder(s.extensionCodec,s.context,s.maxStrLength,s.maxBinLength,s.maxArrayLength,s.maxMapLength,s.maxExtLength).decodeMulti(r)}i.decodeMulti=n}),MO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ensureAsyncIterable=i.asyncIterableFromStream=i.isAsyncIterable=void 0;function e(s){return s[Symbol.asyncIterator]!=null}i.isAsyncIterable=e;function t(s){if(s==null)throw new Error("Assertion Failure: value must not be null nor undefined")}async function*n(s){let o=s.getReader();try{for(;;){let{done:a,value:l}=await o.read();if(a)return;t(l),yield l}}finally{o.releaseLock()}}i.asyncIterableFromStream=n;function r(s){return e(s)?s:n(s)}i.ensureAsyncIterable=r}),_O=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.decodeStream=i.decodeMultiStream=i.decodeArrayStream=i.decodeAsync=void 0;var e=ja(),t=MO(),n=bf();async function r(l,h=n.defaultDecodeOptions){let c=(0,t.ensureAsyncIterable)(l);return new e.Decoder(h.extensionCodec,h.context,h.maxStrLength,h.maxBinLength,h.maxArrayLength,h.maxMapLength,h.maxExtLength).decodeAsync(c)}i.decodeAsync=r;function s(l,h=n.defaultDecodeOptions){let c=(0,t.ensureAsyncIterable)(l);return new e.Decoder(h.extensionCodec,h.context,h.maxStrLength,h.maxBinLength,h.maxArrayLength,h.maxMapLength,h.maxExtLength).decodeArrayStream(c)}i.decodeArrayStream=s;function o(l,h=n.defaultDecodeOptions){let c=(0,t.ensureAsyncIterable)(l);return new e.Decoder(h.extensionCodec,h.context,h.maxStrLength,h.maxBinLength,h.maxArrayLength,h.maxMapLength,h.maxExtLength).decodeStream(c)}i.decodeMultiStream=o;function a(l,h=n.defaultDecodeOptions){return o(l,h)}i.decodeStream=a}),za=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.decodeTimestampExtension=i.encodeTimestampExtension=i.decodeTimestampToTimeSpec=i.encodeTimeSpecToTimestamp=i.encodeDateToTimeSpec=i.EXT_TIMESTAMP=i.ExtData=i.ExtensionCodec=i.Encoder=i.DataViewIndexOutOfBoundsError=i.DecodeError=i.Decoder=i.decodeStream=i.decodeMultiStream=i.decodeArrayStream=i.decodeAsync=i.decodeMulti=i.decode=i.encode=void 0;var e=EO();Object.defineProperty(i,"encode",{enumerable:!0,get:function(){return e.encode}});var t=bf();Object.defineProperty(i,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(i,"decodeMulti",{enumerable:!0,get:function(){return t.decodeMulti}});var n=_O();Object.defineProperty(i,"decodeAsync",{enumerable:!0,get:function(){return n.decodeAsync}}),Object.defineProperty(i,"decodeArrayStream",{enumerable:!0,get:function(){return n.decodeArrayStream}}),Object.defineProperty(i,"decodeMultiStream",{enumerable:!0,get:function(){return n.decodeMultiStream}}),Object.defineProperty(i,"decodeStream",{enumerable:!0,get:function(){return n.decodeStream}});var r=ja();Object.defineProperty(i,"Decoder",{enumerable:!0,get:function(){return r.Decoder}}),Object.defineProperty(i,"DataViewIndexOutOfBoundsError",{enumerable:!0,get:function(){return r.DataViewIndexOutOfBoundsError}});var s=Ia();Object.defineProperty(i,"DecodeError",{enumerable:!0,get:function(){return s.DecodeError}});var o=yf();Object.defineProperty(i,"Encoder",{enumerable:!0,get:function(){return o.Encoder}});var a=Na();Object.defineProperty(i,"ExtensionCodec",{enumerable:!0,get:function(){return a.ExtensionCodec}});var l=mf();Object.defineProperty(i,"ExtData",{enumerable:!0,get:function(){return l.ExtData}});var h=gf();Object.defineProperty(i,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return h.EXT_TIMESTAMP}}),Object.defineProperty(i,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return h.encodeDateToTimeSpec}}),Object.defineProperty(i,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return h.encodeTimeSpecToTimestamp}}),Object.defineProperty(i,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return h.decodeTimestampToTimeSpec}}),Object.defineProperty(i,"encodeTimestampExtension",{enumerable:!0,get:function(){return h.encodeTimestampExtension}}),Object.defineProperty(i,"decodeTimestampExtension",{enumerable:!0,get:function(){return h.decodeTimestampExtension}})}),di=class extends Error{constructor(i){super(i),this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}},wf=class extends di{},pt=class extends di{},Bn=class extends di{},Ie=typeof process<"u"&&process.release&&process.release.name==="node",ga;if(globalThis.document)ga=i=>new Promise((e,t)=>{let n=document.createElement("script");n.src=i,n.onload=()=>e(),n.onerror=t,document.head.appendChild(n)});else if(globalThis.importScripts)ga=async i=>{try{globalThis.importScripts(i)}catch(e){if(e instanceof TypeError)await Promise.resolve().then(()=>Xi(Bi(i)));else throw e}};else if(Ie)ga=async i=>{let e=(await Promise.resolve().then(()=>Xi(Bi("path")))).default;await Promise.resolve().then(()=>Xi(Bi(e.resolve(i))))};else throw new di("Cannot determine runtime environment");var T={};function DO(i){Object.keys(i).forEach(e=>T._free(i[e]))}var mt={null:0,symbol:1,pairlist:2,closure:3,environment:4,promise:5,call:6,special:7,builtin:8,string:9,logical:10,integer:13,double:14,complex:15,character:16,dots:17,any:18,list:19,expression:20,bytecode:21,pointer:22,weakref:23,raw:24,s4:25,new:30,free:31,function:99};function vf(i){return!!i&&typeof i=="object"&&Object.keys(mt).includes(i.type)}function cs(i){return!!i&&typeof i=="object"&&"re"in i&&"im"in i}function Gr(i){return T._Rf_protect(Mt(i)),i}function ae(i,e){return T._Rf_protect(Mt(i)),++e.n,i}function $O(i){let e=T._malloc(4);return T._R_ProtectWithIndex(Mt(i),e),{loc:T.getValue(e,"i32"),ptr:e}}function VO(i){T._Rf_unprotect(1),T._free(i.ptr)}function LO(i,e){return T._R_Reprotect(Mt(i),e.loc),i}function Oe(i){T._Rf_unprotect(i)}function af(i,e,t){T._Rf_defineVar(Mt(e),Mt(t),Mt(i))}function lf(i,e){let t={},n={n:0};try{let r=new Tf(e);ae(r,n),t.code=T.allocateUTF8(i);let s=T._R_ParseEvalString(t.code,r.ptr);return z.wrap(s)}finally{DO(t),Oe(n.n)}}function fs(i,e){return T.getWasmTableEntry(T.GOT.ffi_safe_eval.value)(Mt(i),Mt(e))}var qO=new WeakMap;function BO(i,e){return qO.set(i,e),i}var XO=63;function xf(){let i=Array.from({length:4},WO).join("-");if(i.length!==XO)throw new Error("comlink internal error: UUID has the wrong length");return i}function WO(){let i=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16),e=15-i.length;return e>0&&(i=Array.from({length:e},()=>0).join("")+i),i}function Mt(i){return ns(i)?i.ptr:i}function pi(i,e){if(T._TYPEOF(i.ptr)!==mt[e])throw new Error(`Unexpected object type "${i.type()}" when expecting type "${e}"`)}function kf(i){if(vf(i))return new(_f(i.type))(i);if(i&&typeof i=="object"&&"type"in i&&i.type==="null")return new Sf;if(i===null)return new Ni({type:"logical",names:null,values:[null]});if(typeof i=="boolean")return new Ni(i);if(typeof i=="number")return new ds(i);if(typeof i=="string")return new zt(i);if(cs(i))return new Fa(i);if(ArrayBuffer.isView(i)||i instanceof ArrayBuffer)return new Ha(i);if(Array.isArray(i))return IO(i);if(typeof i=="object")return Xn.fromObject(i);throw new Error("Robj construction for this JS object is not yet supported")}function IO(i){let e={n:0};if(i.every(t=>t&&typeof t=="object"&&!ns(t)&&!cs(t))){let t=i,n=t.every(s=>Object.keys(s).filter(o=>!Object.keys(t[0]).includes(o)).length===0&&Object.keys(t[0]).filter(o=>!Object.keys(s).includes(o)).length===0),r=t.every(s=>Object.values(s).every(o=>$f(o)||Df(o)));if(n&&r)return Xn.fromD3(t)}if(i.every(t=>typeof t=="boolean"||t===null))return new Ni(i);if(i.every(t=>typeof t=="number"||t===null))return new ds(i);if(i.every(t=>typeof t=="string"||t===null))return new zt(i);try{let t=new ui([new gt("c"),...i]);return ae(t,e),t.eval()}finally{Oe(e.n)}}var ye=class{constructor(i){this.ptr=i}type(){let i=T._TYPEOF(this.ptr);return Object.keys(mt).find(e=>mt[e]===i)}},_n,Yr,Wi=class extends ye{constructor(i){if(!(i instanceof ye))return kf(i);super(i.ptr),L(this,_n)}static wrap(i){let e=T._TYPEOF(i),t=Object.keys(mt)[Object.values(mt).indexOf(e)];return new(_f(t))(new ye(i))}get[Symbol.toStringTag](){return`RObject:${this.type()}`}static getPersistentObject(i){return xe[i]}getPropertyValue(i){return this[i]}inspect(){lf(".Internal(inspect(x))",{x:this})}isNull(){return T._TYPEOF(this.ptr)===mt.null}isNa(){try{let i=lf("is.na(x)",{x:this});return Gr(i),i.toBoolean()}finally{Oe(1)}}isUnbound(){return this.ptr===xe.unboundValue.ptr}attrs(){return us.wrap(T._ATTRIB(this.ptr))}class(){let i={n:0},e=new ui([new gt("class"),this]);ae(e,i);try{return e.eval()}finally{Oe(i.n)}}setNames(i){let e;if(i===null)e=xe.null;else if(Array.isArray(i)&&i.every(t=>typeof t=="string"||t===null))e=new zt(i);else throw new Error("Argument to setNames must be null or an Array of strings or null");return T._Rf_setAttrib(this.ptr,xe.namesSymbol.ptr,e.ptr),this}names(){let i=zt.wrap(T._Rf_getAttrib(this.ptr,xe.namesSymbol.ptr));return i.isNull()?null:i.toArray()}includes(i){let e=this.names();return e&&e.includes(i)}toJs(i={depth:0},e=1){throw new Error("This R object cannot be converted to JS")}subset(i){return Je(this,_n,Yr).call(this,i,xe.bracketSymbol.ptr)}get(i){return Je(this,_n,Yr).call(this,i,xe.bracket2Symbol.ptr)}getDollar(i){return Je(this,_n,Yr).call(this,i,xe.dollarSymbol.ptr)}pluck(...i){let e=$O(xe.null);try{let t=(r,s)=>{let o=r.get(s);return LO(o,e)},n=i.reduce(t,this);return n.isNull()?void 0:n}finally{VO(e)}}set(i,e){let t={n:0};try{let n=new Wi(i);ae(n,t);let r=new Wi(e);ae(r,t);let s=new gt("[[<-"),o=T._Rf_lang4(s.ptr,this.ptr,n.ptr,r.ptr);return ae(o,t),Wi.wrap(fs(o,xe.baseEnv))}finally{Oe(t.n)}}static getMethods(i){let e=new Set,t=i;do Object.getOwnPropertyNames(t).map(n=>e.add(n));while(t=Object.getPrototypeOf(t));return[...e.keys()].filter(n=>typeof i[n]=="function")}},z=Wi;_n=new WeakSet,Yr=function(i,e){let t={n:0};try{let n=new Wi(i);ae(n,t);let r=T._Rf_lang3(e,this.ptr,n.ptr);return ae(r,t),Wi.wrap(fs(r,xe.baseEnv))}finally{Oe(t.n)}};var Sf=class extends z{constructor(){return super(new ye(T.getValue(T._R_NilValue,"*"))),this}toJs(){return{type:"null"}}},gt=class extends z{constructor(i){if(i instanceof ye){pi(i,"symbol"),super(i);return}let e=T.allocateUTF8(i);try{super(new ye(T._Rf_install(e)))}finally{T._free(e)}}toJs(){let i=this.toObject();return{type:"symbol",printname:i.printname,symvalue:i.symvalue,internal:i.internal}}toObject(){return{printname:this.printname().isUnbound()?null:this.printname().toString(),symvalue:this.symvalue().isUnbound()?null:this.symvalue().ptr,internal:this.internal().isNull()?null:this.internal().ptr}}toString(){return this.printname().toString()}printname(){return Ua.wrap(T._PRINTNAME(this.ptr))}symvalue(){return z.wrap(T._SYMVALUE(this.ptr))}internal(){return z.wrap(T._INTERNAL(this.ptr))}},us=class extends z{constructor(i){if(i instanceof ye)return pi(i,"pairlist"),super(i),this;let e={n:0};try{let{names:t,values:n}=zi(i),r=us.wrap(T._Rf_allocList(n.length));ae(r,e);for(let[s,o]=[0,r];!o.isNull();[s,o]=[s+1,o.cdr()])o.setcar(new z(n[s]));r.setNames(t),super(r)}finally{Oe(e.n)}}get length(){return this.toArray().length}toArray(i={depth:1}){return this.toJs(i).values}toObject({allowDuplicateKey:i=!0,allowEmptyKey:e=!1,depth:t=-1}={}){let n=this.entries({depth:t}),r=n.map(([s])=>s);if(!i&&new Set(r).size!==r.length)throw new Error("Duplicate key when converting pairlist without allowDuplicateKey enabled");if(!e&&r.some(s=>!s))throw new Error("Empty or null key when converting pairlist without allowEmptyKey enabled");return Object.fromEntries(n.filter((s,o)=>n.findIndex(a=>a[0]===s[0])===o))}entries(i={depth:1}){let e=this.toJs(i);return e.values.map((t,n)=>[e.names?e.names[n]:null,t])}toJs(i={depth:0},e=1){let t=[],n=!1,r=[];for(let s=this;!s.isNull();s=s.cdr()){let o=s.tag();o.isNull()?t.push(""):(n=!0,t.push(o.toString())),i.depth&&e>=i.depth?r.push(s.car()):r.push(s.car().toJs(i,e+1))}return{type:"pairlist",names:n?t:null,values:r}}includes(i){return i in this.toObject()}setcar(i){T._SETCAR(this.ptr,i.ptr)}car(){return z.wrap(T._CAR(this.ptr))}cdr(){return z.wrap(T._CDR(this.ptr))}tag(){return z.wrap(T._TAG(this.ptr))}},ui=class extends z{constructor(i){if(i instanceof ye)return pi(i,"call"),super(i),this;let e={n:0};try{let{values:t}=zi(i),n=t.map(s=>ae(new z(s),e)),r=ui.wrap(T._Rf_allocVector(mt.call,t.length));ae(r,e);for(let[s,o]=[0,r];!o.isNull();[s,o]=[s+1,o.cdr()])o.setcar(n[s]);super(r)}finally{Oe(e.n)}}setcar(i){T._SETCAR(this.ptr,i.ptr)}car(){return z.wrap(T._CAR(this.ptr))}cdr(){return z.wrap(T._CDR(this.ptr))}eval(){return T.webr.evalR(this,{env:xe.baseEnv})}capture(i={}){return T.webr.captureR(this,i)}deparse(){let i={n:0};try{let e=T._Rf_lang2(new gt("deparse1").ptr,T._Rf_lang2(new gt("quote").ptr,this.ptr));ae(e,i);let t=zt.wrap(fs(e,xe.baseEnv));return ae(t,i),t.toString()}finally{Oe(i.n)}}},ya=class extends z{constructor(i,e=null){if(i instanceof ye){if(pi(i,"list"),super(i),e){if(e.length!==this.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");this.setNames(e)}return this}let t={n:0};try{let n=zi(i),r=T._Rf_allocVector(mt.list,n.values.length);ae(r,t),n.values.forEach((o,a)=>{T._SET_VECTOR_ELT(r,a,new z(o).ptr)});let s=e||n.names;if(s&&s.length!==n.values.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");z.wrap(r).setNames(s),super(new ye(r))}finally{Oe(t.n)}}get length(){return T._LENGTH(this.ptr)}isDataFrame(){let i=us.wrap(T._ATTRIB(this.ptr)).get("class");return!i.isNull()&&i.toArray().includes("data.frame")}toArray(i={depth:1}){return this.toJs(i).values}toObject({allowDuplicateKey:i=!0,allowEmptyKey:e=!1,depth:t=-1}={}){let n=this.entries({depth:t}),r=n.map(([s])=>s);if(!i&&new Set(r).size!==r.length)throw new Error("Duplicate key when converting list without allowDuplicateKey enabled");if(!e&&r.some(s=>!s))throw new Error("Empty or null key when converting list without allowEmptyKey enabled");return Object.fromEntries(n.filter((s,o)=>n.findIndex(a=>a[0]===s[0])===o))}toD3(){if(!this.isDataFrame())throw new Error("Can't convert R list object to D3 format. Object must be of class 'data.frame'.");return this.entries().reduce((i,e)=>(e[1].forEach((t,n)=>i[n]=Object.assign(i[n]||{},{[e[0]]:t})),i),[])}entries(i={depth:-1}){let e=this.toJs(i);return this.isDataFrame()&&i.depth<0&&(e.values=e.values.map(t=>t.toArray())),e.values.map((t,n)=>[e.names?e.names[n]:null,t])}toJs(i={depth:0},e=1){return{type:"list",names:this.names(),values:[...Array(this.length).keys()].map(t=>i.depth&&e>=i.depth?this.get(t+1):this.get(t+1).toJs(i,e+1))}}},Xn=class extends ya{constructor(i){if(i instanceof ye){if(super(i),!this.isDataFrame())throw new Error("Can't construct `RDataFrame`. Supplied R object is not a `data.frame`.");return this}return Xn.fromObject(i)}static fromObject(i){let{names:e,values:t}=zi(i),n={n:0};try{let r=!!e&&e.length>0&&e.every(o=>o),s=t.length>0&&t.every(o=>Array.isArray(o)||ArrayBuffer.isView(o)||o instanceof ArrayBuffer);if(r&&s){let o=t,a=o.every(h=>h.length===o[0].length),l=o.every(h=>$f(h[0])||Df(h[0]));if(a&&l){let h=new ya({type:"list",names:e,values:o.map(f=>kf(f))});ae(h,n);let c=new ui([new gt("as.data.frame"),h]);return ae(c,n),new Xn(c.eval())}}}finally{Oe(n.n)}throw new Error("Can't construct `data.frame`. Source object is not eligible.")}static fromD3(i){return this.fromObject(Object.fromEntries(Object.keys(i[0]).map(e=>[e,i.map(t=>t[e])])))}},Hr=class extends z{exec(...i){let e={n:0};try{let t=new ui([this,...i]);return ae(t,e),t.eval()}finally{Oe(e.n)}}capture(i={},...e){let t={n:0};try{let n=new ui([this,...e]);return ae(n,t),n.capture(i)}finally{Oe(t.n)}}},Ua=class extends z{constructor(i){if(i instanceof ye){pi(i,"string"),super(i);return}let e=T.allocateUTF8(i);try{super(new ye(T._Rf_mkChar(e)))}finally{T._free(e)}}toString(){return T.UTF8ToString(T._R_CHAR(this.ptr))}toJs(){return{type:"string",value:this.toString()}}},Tf=class extends z{constructor(i={}){if(i instanceof ye)return pi(i,"environment"),super(i),this;let e=0;try{let{names:t,values:n}=zi(i),r=Gr(T._R_NewEnv(xe.globalEnv.ptr,0,0));++e,n.forEach((s,o)=>{let a=t?t[o]:null;if(!a)throw new Error("Can't create object in new environment with empty symbol name");let l=new gt(a),h=Gr(new z(s));try{af(r,l,h)}finally{Oe(1)}}),super(new ye(r))}finally{Oe(e)}}ls(i=!1,e=!0){return zt.wrap(T._R_lsInternal3(this.ptr,Number(i),Number(e))).toArray()}bind(i,e){let t=new gt(i),n=Gr(new z(e));try{af(this,t,n)}finally{Oe(1)}}names(){return this.ls(!0,!0)}frame(){return z.wrap(T._FRAME(this.ptr))}subset(i){if(typeof i=="number")throw new Error("Object of type environment is not subsettable");return this.getDollar(i)}toObject({depth:i=-1}={}){let e=this.names();return Object.fromEntries([...Array(e.length).keys()].map(t=>{let n=this.getDollar(e[t]);return[e[t],i<0?n:n.toJs({depth:i})]}))}toJs(i={depth:0},e=1){let t=this.names(),n=[...Array(t.length).keys()].map(r=>i.depth&&e>=i.depth?this.getDollar(t[r]):this.getDollar(t[r]).toJs(i,e+1));return{type:"environment",names:t,values:n}}},ji=class extends z{constructor(i,e,t){if(i instanceof ye)return pi(i,e),super(i),this;let n={n:0};try{let{names:r,values:s}=zi(i),o=T._Rf_allocVector(mt[e],s.length);ae(o,n),s.forEach(t(o)),z.wrap(o).setNames(r),super(new ye(o))}finally{Oe(n.n)}}get length(){return T._LENGTH(this.ptr)}get(i){return super.get(i)}subset(i){return super.subset(i)}getDollar(){throw new Error("$ operator is invalid for atomic vectors")}detectMissing(){let i={n:0};try{let e=T._Rf_lang2(new gt("is.na").ptr,this.ptr);ae(e,i);let t=Ni.wrap(fs(e,xe.baseEnv));ae(t,i);let n=t.toTypedArray();return Array.from(n).map(r=>!!r)}finally{Oe(i.n)}}toArray(){let i=this.toTypedArray();return this.detectMissing().map((e,t)=>e?null:i[t])}toObject({allowDuplicateKey:i=!0,allowEmptyKey:e=!1}={}){let t=this.entries(),n=t.map(([r])=>r);if(!i&&new Set(n).size!==n.length)throw new Error("Duplicate key when converting atomic vector without allowDuplicateKey enabled");if(!e&&n.some(r=>!r))throw new Error("Empty or null key when converting atomic vector without allowEmptyKey enabled");return Object.fromEntries(t.filter((r,s)=>t.findIndex(o=>o[0]===r[0])===s))}entries(){let i=this.toArray(),e=this.names();return i.map((t,n)=>[e?e[n]:null,t])}toJs(){return{type:this.type(),names:this.names(),values:this.toArray()}}},ba,Pf=class extends ji{constructor(i){super(i,"logical",k(Pf,ba))}getBoolean(i){return this.get(i).toArray()[0]}toBoolean(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getBoolean(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS boolean");return i}toTypedArray(){return new Int32Array(T.HEAP32.subarray(T._LOGICAL(this.ptr)/4,T._LOGICAL(this.ptr)/4+this.length))}toArray(){let i=this.toTypedArray();return this.detectMissing().map((e,t)=>e?null:!!i[t])}},Ni=Pf;ba=new WeakMap,L(Ni,ba,i=>{let e=T._LOGICAL(i),t=T.getValue(T._R_NaInt,"i32");return(n,r)=>{T.setValue(e+4*r,n===null?t:!!n,"i32")}});var wa,Cf=class extends ji{constructor(i){super(i,"integer",k(Cf,wa))}getNumber(i){return this.get(i).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getNumber(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS number");return i}toTypedArray(){return new Int32Array(T.HEAP32.subarray(T._INTEGER(this.ptr)/4,T._INTEGER(this.ptr)/4+this.length))}},Rf=Cf;wa=new WeakMap,L(Rf,wa,i=>{let e=T._INTEGER(i),t=T.getValue(T._R_NaInt,"i32");return(n,r)=>{T.setValue(e+4*r,n===null?t:Math.round(Number(n)),"i32")}});var va,Ef=class extends ji{constructor(i){super(i,"double",k(Ef,va))}getNumber(i){return this.get(i).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getNumber(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS number");return i}toTypedArray(){return new Float64Array(T.HEAPF64.subarray(T._REAL(this.ptr)/8,T._REAL(this.ptr)/8+this.length))}},ds=Ef;va=new WeakMap,L(ds,va,i=>{let e=T._REAL(i),t=T.getValue(T._R_NaReal,"double");return(n,r)=>{T.setValue(e+8*r,n===null?t:n,"double")}});var xa,Af=class extends ji{constructor(i){super(i,"complex",k(Af,xa))}getComplex(i){return this.get(i).toArray()[0]}toComplex(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getComplex(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS object");return i}toTypedArray(){return new Float64Array(T.HEAPF64.subarray(T._COMPLEX(this.ptr)/8,T._COMPLEX(this.ptr)/8+2*this.length))}toArray(){let i=this.toTypedArray();return this.detectMissing().map((e,t)=>e?null:{re:i[2*t],im:i[2*t+1]})}},Fa=Af;xa=new WeakMap,L(Fa,xa,i=>{let e=T._COMPLEX(i),t=T.getValue(T._R_NaReal,"double");return(n,r)=>{T.setValue(e+8*(2*r),n===null?t:n.re,"double"),T.setValue(e+8*(2*r+1),n===null?t:n.im,"double")}});var ka,Qf=class extends ji{constructor(i){super(i,"character",k(Qf,ka))}getString(i){return this.get(i).toArray()[0]}toString(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getString(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS string");return i}toTypedArray(){return new Uint32Array(T.HEAPU32.subarray(T._STRING_PTR(this.ptr)/4,T._STRING_PTR(this.ptr)/4+this.length))}toArray(){return this.detectMissing().map((i,e)=>i?null:T.UTF8ToString(T._R_CHAR(T._STRING_ELT(this.ptr,e))))}},zt=Qf;ka=new WeakMap,L(zt,ka,i=>(e,t)=>{e===null?T._SET_STRING_ELT(i,t,xe.naString.ptr):T._SET_STRING_ELT(i,t,new Ua(e).ptr)});var Sa,Mf=class extends ji{constructor(i){i instanceof ArrayBuffer&&(i=new Uint8Array(i)),super(i,"raw",k(Mf,Sa))}getNumber(i){return this.get(i).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getNumber(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS number");return i}toTypedArray(){return new Uint8Array(T.HEAPU8.subarray(T._RAW(this.ptr),T._RAW(this.ptr)+this.length))}},Ha=Mf;Sa=new WeakMap,L(Ha,Sa,i=>{let e=T._RAW(i);return(t,n)=>{T.setValue(e+n,Number(t),"i8")}});function zi(i){return vf(i)?i:Array.isArray(i)||ArrayBuffer.isView(i)?{names:null,values:i}:i&&typeof i=="object"&&!cs(i)?{names:Object.keys(i),values:Object.values(i)}:{names:null,values:[i]}}function _f(i){let e={object:z,null:Sf,symbol:gt,pairlist:us,closure:Hr,environment:Tf,call:ui,special:Hr,builtin:Hr,string:Ua,logical:Ni,integer:Rf,double:ds,complex:Fa,character:zt,list:ya,raw:Ha,function:Hr,dataframe:Xn};return i in e?e[i]:z}function ns(i){return i instanceof z}function Df(i){let e=["logical","integer","double","complex","character"];return ns(i)&&e.includes(i.type())||ns(i)&&i.isNa()}function $f(i){return i===null||typeof i=="number"||typeof i=="boolean"||typeof i=="string"||cs(i)}var xe;function ps(){let i={resolve:()=>{},reject:()=>{},promise:Promise.resolve()},e=new Promise((t,n)=>{i.resolve=t,i.reject=n});return i.promise=e,i}function NO(i){return new Promise(e=>setTimeout(e,i))}function Ut(i,e,t,...n){return i==null||jO(i)?i:i instanceof ArrayBuffer?new Uint8Array(i):e(i)?t(i,...n):Array.isArray(i)||ArrayBuffer.isView(i)?i.map(r=>Ut(r,e,t,...n)):i instanceof ye?i:typeof i=="object"?Object.fromEntries(Object.entries(i).map(([r,s])=>[r,Ut(s,e,t,...n)])):i}function Ga(i,e){let t=new XMLHttpRequest;t.open("get",i,!0),t.onload=()=>{let n=new Worker(URL.createObjectURL(new Blob([t.responseText])));e(n)},t.send()}function Ya(i){if(Ie)return!1;let e=new URL(location.href),t=new URL(i,location.origin);return!(e.host===t.host&&e.port===t.port&&e.protocol===t.protocol)}function jO(i){return typeof ImageBitmap<"u"&&i instanceof ImageBitmap}var zO=Xi(za()),UO=new TextEncoder;async function FO(i,e,t){try{let{taskId:n,sizeBuffer:r,dataBuffer:s,signalBuffer:o}=e,a=(0,zO.encode)(t),l=a.length<=s.length;if(Atomics.store(r,0,a.length),Atomics.store(r,1,+l),!l){let[h,c]=HO(i);s.set(UO.encode(h)),await hf(o,n),s=(await c).dataBuffer}s.set(a),Atomics.store(r,1,1),await hf(o,n)}catch(n){console.warn(n)}}function HO(i){let e=xf();return[e,new Promise(t=>{Ie?i.once("message",n=>{!n.id||n.id!==e||t(n)}):i.addEventListener("message",function n(r){!r.data||!r.data.id||r.data.id!==e||(i.removeEventListener("message",n),t(r.data))}),i.start&&i.start()})]}async function hf(i,e){let t=(e>>1)%32,n=1;for(;Atomics.compareExchange(i,t+1,0,e)!==0;)await NO(n),n<32&&(n*=2);Atomics.or(i,0,1<{k(this,At).push(i)}))};function GO(i,e){return Vf({type:"request",data:{uuid:xf(),msg:i}},e)}function Pa(i,e,t){return Vf({type:"response",data:{uuid:i,resp:e}},t)}function Vf(i,e){return e&&BO(i,e),i}function YO(i){let e=new wf(i.obj.message);return i.obj.name!=="Error"&&(e.name=i.obj.name),e.stack=i.obj.stack,e}function ZO(i){return!!i&&typeof i=="object"&&"payloadType"in i&&"obj"in i}function Lf(i){return ZO(i)&&i.payloadType==="ptr"}var Dn,Za=class{constructor(){this.inputQueue=new Oa,this.outputQueue=new Oa,this.systemQueue=new Oa,L(this,Dn,new Map)}async read(){return await this.outputQueue.get()}async flush(){let i=[];for(;!this.outputQueue.isEmpty();)i.push(await this.read());return i}async readSystem(){return await this.systemQueue.get()}write(i){this.inputQueue.put(i)}async request(i,e){let t=GO(i,e),{resolve:n,reject:r,promise:s}=ps();return k(this,Dn).set(t.data.uuid,{resolve:n,reject:r}),this.write(t),s}putClosedMessage(){this.outputQueue.put({type:"closed"})}resolveResponse(i){let e=i.data.uuid,t=k(this,Dn).get(e);if(t){let n=i.data.resp;k(this,Dn).delete(e),n.payloadType==="err"?t.reject(YO(n)):t.resolve(n)}else console.warn("Can't find request.")}};Dn=new WeakMap;var cS=Xi(za()),fS=new TextDecoder("utf-8"),JO,KO,e0,t0,i0;JO=new WeakMap,KO=new WeakMap,e0=new WeakMap,t0=new WeakMap,i0=new WeakMap;var uS=new Int32Array(new ArrayBuffer(4));Ie&&(globalThis.Worker=Bi("worker_threads").Worker);var $n,Ca,qf,Jr,cf=class extends Za{constructor(i){super(),L(this,Ca),L(this,$n,void 0),this.close=()=>{},L(this,Jr,async(t,n)=>{if(!(!n||!n.type))switch(n.type){case"resolve":me(this,$n,new Int32Array(n.data)),this.resolve();return;case"response":this.resolveResponse(n);return;case"system":this.systemQueue.put(n.data);return;default:this.outputQueue.put(n);return;case"sync-request":{let r=n,s=r.data.msg,o=r.data.reqData;switch(s.type){case"read":{let a=await this.inputQueue.get();await FO(t,o,a);break}default:throw new pt(`Unsupported request type '${s.type}'.`)}return}case"request":throw new pt("Can't send messages of type 'request' from a worker. Please Use 'sync-request' instead.")}});let e=t=>{Je(this,Ca,qf).call(this,t),this.close=()=>{t.terminate(),this.putClosedMessage()};let n={type:"init",data:{config:i,channelType:Qt.SharedArrayBuffer}};t.postMessage(n)};if(Ya(i.baseUrl))Ga(`${i.baseUrl}webr-worker.js`,t=>e(t));else{let t=new Worker(`${i.baseUrl}webr-worker.js`);e(t)}({resolve:this.resolve,promise:this.initialised}=ps())}interrupt(){if(!k(this,$n))throw new pt("Failed attempt to interrupt before initialising interruptBuffer");this.inputQueue.reset(),k(this,$n)[0]=1}};$n=new WeakMap,Ca=new WeakSet,qf=function(i){Ie?i.on("message",e=>{k(this,Jr).call(this,i,e)}):i.onmessage=e=>k(this,Jr).call(this,i,e.data)},Jr=new WeakMap;var n0,r0,s0,o0;n0=new WeakMap,r0=new WeakMap,s0=new WeakMap,o0=new WeakMap;var dS=Xi(za());Ie&&(globalThis.Worker=Bi("worker_threads").Worker);var Ln,Ii,qn,Ra,Bf,Ea,ff,Aa,Xf,Kr,a0=class extends Za{constructor(i){super(),L(this,Ra),L(this,Ea),L(this,Aa),this.close=()=>{},L(this,Ln,new Map),L(this,Ii,void 0),L(this,qn,!1),L(this,Kr,(t,n)=>{if(!(!n||!n.type))switch(n.type){case"resolve":this.resolve();return;case"response":this.resolveResponse(n);return;case"system":this.systemQueue.put(n.data);return;default:this.outputQueue.put(n);return;case"sync-request":{let r=n.data;k(this,Ln).set(r.data.uuid,r.data.msg);return}case"request":throw new pt("Can't send messages of type 'request' from a worker.Use service worker fetch request instead.")}}),console.warn("The ServiceWorker communication channel is deprecated and will be removed in a future version of webR. Consider using the PostMessage channel instead. If blocking input is required (for example, `browser()`) the SharedArrayBuffer channel should be used. See https://docs.r-wasm.org/webr/latest/serving.html for further information.");let e=t=>{Je(this,Aa,Xf).call(this,t),this.close=()=>{t.terminate(),this.putClosedMessage()},Je(this,Ra,Bf).call(this,`${i.serviceWorkerUrl}webr-serviceworker.js`).then(n=>{let r={type:"init",data:{config:i,channelType:Qt.ServiceWorker,clientId:n,location:window.location.href}};t.postMessage(r)})};if(Ya(i.serviceWorkerUrl))Ga(`${i.serviceWorkerUrl}webr-worker.js`,t=>e(t));else{let t=new Worker(`${i.serviceWorkerUrl}webr-worker.js`);e(t)}({resolve:this.resolve,promise:this.initialised}=ps())}activeRegistration(){var i;if(!((i=k(this,Ii))!=null&&i.active))throw new pt("Attempted to obtain a non-existent active registration.");return k(this,Ii).active}interrupt(){me(this,qn,!0)}};Ln=new WeakMap,Ii=new WeakMap,qn=new WeakMap,Ra=new WeakSet,Bf=async function(i){me(this,Ii,await navigator.serviceWorker.register(i)),await navigator.serviceWorker.ready,window.addEventListener("beforeunload",()=>{var t;(t=k(this,Ii))==null||t.unregister()});let e=await new Promise(t=>{navigator.serviceWorker.addEventListener("message",function n(r){r.data.type==="registration-successful"&&(navigator.serviceWorker.removeEventListener("message",n),t(r.data.clientId))}),this.activeRegistration().postMessage({type:"register-client-main"})});return navigator.serviceWorker.addEventListener("message",t=>{Je(this,Ea,ff).call(this,t)}),e},Ea=new WeakSet,ff=async function(i){if(i.data.type==="request"){let e=i.data.data,t=k(this,Ln).get(e);if(!t)throw new pt("Request not found during service worker XHR request");switch(k(this,Ln).delete(e),t.type){case"read":{let n=await this.inputQueue.get();this.activeRegistration().postMessage({type:"wasm-webr-fetch-response",uuid:e,response:Pa(e,n)});break}case"interrupt":{let n=k(this,qn);this.activeRegistration().postMessage({type:"wasm-webr-fetch-response",uuid:e,response:Pa(e,n)}),this.inputQueue.reset(),me(this,qn,!1);break}default:throw new pt(`Unsupported request type '${t.type}'.`)}return}},Aa=new WeakSet,Xf=function(i){Ie?i.on("message",e=>{k(this,Kr).call(this,i,e)}):i.onmessage=e=>k(this,Kr).call(this,i,e.data)},Kr=new WeakMap;var l0,h0,c0,f0,u0,d0;l0=new WeakMap,h0=new WeakMap,c0=new WeakMap,f0=new WeakMap,u0=new WeakMap,d0=new WeakMap;Ie&&(globalThis.Worker=Bi("worker_threads").Worker);var Vn,Qa,Wf,es,uf=class extends Za{constructor(i){super(),L(this,Qa),this.close=()=>{},L(this,Vn,void 0),L(this,es,async(t,n)=>{if(!(!n||!n.type))switch(n.type){case"resolve":this.resolve();return;case"response":this.resolveResponse(n);return;case"system":this.systemQueue.put(n.data);return;default:this.outputQueue.put(n);return;case"request":{let r=n,s=r.data.msg;switch(s.type){case"read":{let o=await this.inputQueue.get();if(k(this,Vn)){let a=Pa(r.data.uuid,o);k(this,Vn).postMessage(a)}break}default:throw new pt(`Unsupported request type '${s.type}'.`)}return}case"sync-request":throw new pt("Can't send messages of type 'sync-request' in PostMessage mode. Use 'request' instead.")}});let e=t=>{me(this,Vn,t),Je(this,Qa,Wf).call(this,t),this.close=()=>t.terminate();let n={type:"init",data:{config:i,channelType:Qt.PostMessage}};t.postMessage(n)};if(Ya(i.baseUrl))Ga(`${i.baseUrl}webr-worker.js`,t=>e(t));else{let t=new Worker(`${i.baseUrl}webr-worker.js`);e(t)}({resolve:this.resolve,promise:this.initialised}=ps())}interrupt(){console.error("Interrupting R execution is not available when using the PostMessage channel")}};Vn=new WeakMap,Qa=new WeakSet,Wf=function(i){Ie?i.on("message",e=>{k(this,es).call(this,i,e)}):i.onmessage=e=>k(this,es).call(this,i,e.data)},es=new WeakMap;var p0,m0,g0,O0,y0;p0=new WeakMap,m0=new WeakMap,g0=new WeakMap,O0=new WeakMap,y0=new WeakMap;var Qt={Automatic:0,SharedArrayBuffer:1,ServiceWorker:2,PostMessage:3};function b0(i){switch(i.channelType){case Qt.SharedArrayBuffer:return new cf(i);case Qt.ServiceWorker:return new a0(i);case Qt.PostMessage:return new uf(i);case Qt.Automatic:default:return typeof SharedArrayBuffer<"u"?new cf(i):new uf(i)}}var w0=Ie?__dirname+"/":"https://webr.r-wasm.org/v0.4.0/",v0="https://repo.r-wasm.org",If="0.4.0";function ee(i){return!!i&&(typeof i=="object"||typeof i=="function")&&"payloadType"in i&&Lf(i._payload)}function Re(i){return ee(i)&&i._payload.obj.type==="null"}function x0(i){return ee(i)&&i._payload.obj.type==="symbol"}function k0(i){return ee(i)&&i._payload.obj.type==="pairlist"}function S0(i){return ee(i)&&i._payload.obj.type==="environment"}function T0(i){return ee(i)&&i._payload.obj.type==="logical"}function P0(i){return ee(i)&&i._payload.obj.type==="integer"}function C0(i){return ee(i)&&i._payload.obj.type==="double"}function R0(i){return ee(i)&&i._payload.obj.type==="complex"}function Ui(i){return ee(i)&&i._payload.obj.type==="character"}function ot(i){return ee(i)&&i._payload.obj.type==="list"}function Ja(i){return ee(i)&&i._payload.obj.type==="raw"}function ms(i){return ee(i)&&i._payload.obj.type==="call"}function gs(i){var e;return!!(ee(i)&&(e=i._payload.obj.methods)!=null&&e.includes("exec"))}function E0(){}function A0(i,e){return async function*(){let t={type:"callRObjectMethod",data:{payload:e._payload,prop:"getPropertyValue",args:[{payloadType:"raw",obj:"length"}],shelter:void 0}},n=await i.request(t);if(typeof n.obj!="number")throw new di("Cannot iterate over object, unexpected type for length property.");for(let r=1;r<=n.obj;r++)yield e.get(r)}}function Nf(i,e,t){return async(...n)=>{let r=n.map(a=>ee(a)?a._payload:{obj:Ut(a,ee,l=>l._payload),payloadType:"raw"}),s={type:"callRObjectMethod",data:{payload:t,prop:e,args:r}},o=await i.request(s);switch(o.payloadType){case"ptr":return fi(i,o);case"raw":return Ut(o,Lf,(a,l)=>fi(l,a),i).obj}}}async function Q0(i,e,t,...n){let r={type:"newRObject",data:{objType:e,args:Ut(n,ee,o=>o._payload),shelter:t}},s=await i.request(r);switch(s.payloadType){case"raw":throw new Bn("Unexpected raw payload type returned from newRObject");case"ptr":return fi(i,s)}}function fi(i,e){var t;let n=new Proxy((t=e.obj.methods)!=null&&t.includes("exec")?Object.assign(E0,{...e}):e,{get:(r,s)=>{var o;if(s==="_payload")return e;if(s===Symbol.asyncIterator)return A0(i,n);if((o=e.obj.methods)!=null&&o.includes(s.toString()))return Nf(i,s.toString(),e)},apply:async(r,s,o)=>{let a=await fi(i,e).exec(...o);return gs(a)?a:a.toJs()}});return n}function Ve(i,e,t){return new Proxy(z,{construct:(n,r)=>Q0(i,t,e,...r),get:(n,r)=>Nf(i,r.toString())})}var rs,ss,os,as,ls,Ma,_a,Da,$a,Va,La,jf,M0=class{constructor(i={},e={REnv:{R_HOME:"/usr/lib/R",FONTCONFIG_PATH:"/etc/fonts",R_ENABLE_JIT:"0"}}){L(this,La),L(this,rs,void 0),L(this,ss,void 0),L(this,os,void 0),L(this,as,void 0),L(this,ls,void 0),L(this,Ma,t=>{console.log(t)}),L(this,_a,t=>{console.error(t)}),L(this,Da,t=>{let n=prompt(t);n&&this.stdin(`${n}
-`)}),L(this,$a,t=>{if(Ie)throw new Error("Plotting with HTML canvas is not yet supported under Node");this.canvas.getContext("2d").drawImage(t,0,0)}),L(this,Va,()=>{if(Ie)throw new Error("Plotting with HTML canvas is not yet supported under Node");this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height)}),this.webR=new Uf(e),Ie||(this.canvas=document.createElement("canvas"),this.canvas.setAttribute("width","1008"),this.canvas.setAttribute("height","1008")),me(this,rs,i.stdout||k(this,Ma)),me(this,ss,i.stderr||k(this,_a)),me(this,os,i.prompt||k(this,Da)),me(this,as,i.canvasImage||k(this,$a)),me(this,ls,i.canvasNewPage||k(this,Va)),this.webR.evalRVoid("options(device=webr::canvas)")}stdin(i){this.webR.writeConsole(i)}interrupt(){this.webR.interrupt()}run(){Je(this,La,jf).call(this)}};rs=new WeakMap,ss=new WeakMap,os=new WeakMap,as=new WeakMap,ls=new WeakMap,Ma=new WeakMap,_a=new WeakMap,Da=new WeakMap,$a=new WeakMap,Va=new WeakMap,La=new WeakSet,jf=async function(){for(;;){let i=await this.webR.read();switch(i.type){case"stdout":k(this,rs).call(this,i.data);break;case"stderr":k(this,ss).call(this,i.data);break;case"prompt":k(this,os).call(this,i.data);break;case"canvas":i.data.event==="canvasImage"?k(this,as).call(this,i.data.image):i.data.event==="canvasNewPage"&&k(this,ls).call(this);break;case"closed":return;default:console.warn(`Unhandled output type for webR Console: ${i.type}.`)}}};var _0={FONTCONFIG_PATH:"/etc/fonts",R_HOME:"/usr/lib/R",R_ENABLE_JIT:"0",WEBR:"1",WEBR_VERSION:If},df={RArgs:[],REnv:_0,baseUrl:w0,serviceWorkerUrl:"",repoUrl:v0,homedir:"/home/web_user",interactive:!0,channelType:Qt.Automatic,createLazyFilesystem:!0},ne,ts,qa,zf,Uf=class{constructor(i={}){L(this,qa),L(this,ne,void 0),L(this,ts,void 0),this.version=If,this.FS={lookupPath:async t=>{let n={type:"lookupPath",data:{path:t}};return(await k(this,ne).request(n)).obj},mkdir:async t=>{let n={type:"mkdir",data:{path:t}};return(await k(this,ne).request(n)).obj},mount:async(t,n,r)=>{let s={type:"mount",data:{type:t,options:n,mountpoint:r}};await k(this,ne).request(s)},syncfs:async t=>{let n={type:"syncfs",data:{populate:t}};await k(this,ne).request(n)},readFile:async(t,n)=>{let r={type:"readFile",data:{path:t,flags:n}};return(await k(this,ne).request(r)).obj},rmdir:async t=>{let n={type:"rmdir",data:{path:t}};await k(this,ne).request(n)},writeFile:async(t,n,r)=>{let s={type:"writeFile",data:{path:t,data:n,flags:r}};await k(this,ne).request(s)},unlink:async t=>{let n={type:"unlink",data:{path:t}};await k(this,ne).request(n)},unmount:async t=>{let n={type:"unmount",data:{path:t}};await k(this,ne).request(n)}};let e={...df,...i,REnv:{...df.REnv,...i.REnv}};me(this,ne,b0(e)),this.objs={},this.Shelter=D0(k(this,ne)),me(this,ts,k(this,ne).initialised.then(async()=>{this.globalShelter=await new this.Shelter,this.RObject=this.globalShelter.RObject,this.RLogical=this.globalShelter.RLogical,this.RInteger=this.globalShelter.RInteger,this.RDouble=this.globalShelter.RDouble,this.RComplex=this.globalShelter.RComplex,this.RCharacter=this.globalShelter.RCharacter,this.RRaw=this.globalShelter.RRaw,this.RList=this.globalShelter.RList,this.RDataFrame=this.globalShelter.RDataFrame,this.RPairlist=this.globalShelter.RPairlist,this.REnvironment=this.globalShelter.REnvironment,this.RSymbol=this.globalShelter.RSymbol,this.RString=this.globalShelter.RString,this.RCall=this.globalShelter.RCall,this.objs={baseEnv:await this.RObject.getPersistentObject("baseEnv"),globalEnv:await this.RObject.getPersistentObject("globalEnv"),null:await this.RObject.getPersistentObject("null"),true:await this.RObject.getPersistentObject("true"),false:await this.RObject.getPersistentObject("false"),na:await this.RObject.getPersistentObject("na")},Je(this,qa,zf).call(this)}))}async init(){return k(this,ts)}close(){k(this,ne).close()}async read(){return await k(this,ne).read()}async flush(){return await k(this,ne).flush()}write(i){k(this,ne).write(i)}writeConsole(i){this.write({type:"stdin",data:i+`
-`})}interrupt(){k(this,ne).interrupt()}async installPackages(i,e){let t=Object.assign({quiet:!1,mount:!0},e),n={type:"installPackages",data:{name:i,options:t}};await k(this,ne).request(n)}async destroy(i){await this.globalShelter.destroy(i)}async evalR(i,e){return this.globalShelter.evalR(i,e)}async evalRVoid(i,e){return this.evalRRaw(i,"void",e)}async evalRBoolean(i,e){return this.evalRRaw(i,"boolean",e)}async evalRNumber(i,e){return this.evalRRaw(i,"number",e)}async evalRString(i,e){return this.evalRRaw(i,"string",e)}async evalRRaw(i,e,t={}){let n=Ut(t,ee,o=>o._payload),r={type:"evalRRaw",data:{code:i,options:n,outputType:e}},s=await k(this,ne).request(r);switch(s.payloadType){case"raw":return s.obj;case"ptr":throw new Bn("Unexpected ptr payload type returned from evalRVoid")}}async invokeWasmFunction(i,...e){let t={type:"invokeWasmFunction",data:{ptr:i,args:e}};return(await k(this,ne).request(t)).obj}};ne=new WeakMap,ts=new WeakMap,qa=new WeakSet,zf=async function(){for(;;){let i=await k(this,ne).readSystem();switch(i.type){case"setTimeoutWasm":setTimeout((e,t)=>{this.invokeWasmFunction(e,...t)},i.data.delay,i.data.ptr,i.data.args);break;case"console.log":console.log(i.data);break;case"console.warn":console.warn(i.data);break;case"console.error":console.error(i.data);break;default:throw new di("Unknown system message type `"+i.type+"`")}}};var se,Z,is,Ba=class{constructor(i){L(this,se,""),L(this,Z,void 0),L(this,is,!1),me(this,Z,i)}async init(){if(k(this,is))return;let i={type:"newShelter"},e=await k(this,Z).request(i);me(this,se,e.obj),this.RObject=Ve(k(this,Z),k(this,se),"object"),this.RLogical=Ve(k(this,Z),k(this,se),"logical"),this.RInteger=Ve(k(this,Z),k(this,se),"integer"),this.RDouble=Ve(k(this,Z),k(this,se),"double"),this.RComplex=Ve(k(this,Z),k(this,se),"complex"),this.RCharacter=Ve(k(this,Z),k(this,se),"character"),this.RRaw=Ve(k(this,Z),k(this,se),"raw"),this.RList=Ve(k(this,Z),k(this,se),"list"),this.RDataFrame=Ve(k(this,Z),k(this,se),"dataframe"),this.RPairlist=Ve(k(this,Z),k(this,se),"pairlist"),this.REnvironment=Ve(k(this,Z),k(this,se),"environment"),this.RSymbol=Ve(k(this,Z),k(this,se),"symbol"),this.RString=Ve(k(this,Z),k(this,se),"string"),this.RCall=Ve(k(this,Z),k(this,se),"call"),me(this,is,!0)}async purge(){let i={type:"shelterPurge",data:k(this,se)};await k(this,Z).request(i)}async destroy(i){let e={type:"shelterDestroy",data:{id:k(this,se),obj:i._payload}};await k(this,Z).request(e)}async size(){let i={type:"shelterSize",data:k(this,se)};return(await k(this,Z).request(i)).obj}async evalR(i,e={}){let t=Ut(e,ee,s=>s._payload),n={type:"evalR",data:{code:i,options:t,shelter:k(this,se)}},r=await k(this,Z).request(n);switch(r.payloadType){case"raw":throw new Bn("Unexpected payload type returned from evalR");default:return fi(k(this,Z),r)}}async captureR(i,e={}){let t=Ut(e,ee,s=>s._payload),n={type:"captureR",data:{code:i,options:t,shelter:k(this,se)}},r=await k(this,Z).request(n);switch(r.payloadType){case"ptr":throw new Bn("Unexpected payload type returned from evalR");case"raw":{let s=r.obj,o=fi(k(this,Z),s.result),a=s.output,l=s.images;for(let h=0;h{let e=new Ba(i);return await e.init(),e}})}var Hf=Symbol("Comlink.proxy"),il=Symbol("Comlink.endpoint"),$0=Symbol("Comlink.releaseProxy"),el=Symbol("Comlink.finalizer"),ys=Symbol("Comlink.thrown"),Gf=i=>typeof i=="object"&&i!==null||typeof i=="function",V0={canHandle:i=>Gf(i)&&i[Hf],serialize(i){let{port1:e,port2:t}=new MessageChannel;return xs(i,e),[t,[t]]},deserialize(i){return i.start(),Wn(i)}},L0={canHandle:i=>Gf(i)&&ys in i,serialize({value:i}){let e;return i instanceof Error?e={isError:!0,value:{message:i.message,name:i.name,stack:i.stack}}:e={isError:!1,value:i},[e,[]]},deserialize(i){throw i.isError?Object.assign(new Error(i.value.message),i.value):i.value}},gi=new Map([["proxy",V0],["throw",L0]]);function q0(i,e){for(let t of i)if(e===t||t==="*"||t instanceof RegExp&&t.test(e))return!0;return!1}function xs(i,e=globalThis,t=["*"]){e.addEventListener("message",function n(r){if(!r||!r.data)return;if(!q0(t,r.origin)){console.warn(`Invalid origin '${r.origin}' for comlink proxy`);return}let{id:s,type:o,path:a}=Object.assign({path:[]},r.data),l=(r.data.argumentList||[]).map(mi),h;try{let c=a.slice(0,-1).reduce((u,d)=>u[d],i),f=a.reduce((u,d)=>u[d],i);switch(o){case"GET":h=f;break;case"SET":c[a.slice(-1)[0]]=mi(r.data.value),h=!0;break;case"APPLY":h=f.apply(c,l);break;case"CONSTRUCT":{let u=new f(...l);h=j0(u)}break;case"ENDPOINT":{let{port1:u,port2:d}=new MessageChannel;xs(i,d),h=N0(u,[u])}break;case"RELEASE":h=void 0;break;default:return}}catch(c){h={value:c,[ys]:0}}Promise.resolve(h).catch(c=>({value:c,[ys]:0})).then(c=>{let[f,u]=vs(c);e.postMessage(Object.assign(Object.assign({},f),{id:s}),u),o==="RELEASE"&&(e.removeEventListener("message",n),Yf(e),el in i&&typeof i[el]=="function"&&i[el]())}).catch(c=>{let[f,u]=vs({value:new TypeError("Unserializable return value"),[ys]:0});e.postMessage(Object.assign(Object.assign({},f),{id:s}),u)})}),e.start&&e.start()}function B0(i){return i.constructor.name==="MessagePort"}function Yf(i){B0(i)&&i.close()}function Wn(i,e){return tl(i,[],e)}function Os(i){if(i)throw new Error("Proxy has been released and is not useable")}function Zf(i){return Fi(i,{type:"RELEASE"}).then(()=>{Yf(i)})}var bs=new WeakMap,ws="FinalizationRegistry"in globalThis&&new FinalizationRegistry(i=>{let e=(bs.get(i)||0)-1;bs.set(i,e),e===0&&Zf(i)});function X0(i,e){let t=(bs.get(e)||0)+1;bs.set(e,t),ws&&ws.register(i,e,i)}function W0(i){ws&&ws.unregister(i)}function tl(i,e=[],t=function(){}){let n=!1,r=new Proxy(t,{get(s,o){if(Os(n),o===$0)return()=>{W0(r),Zf(i),n=!0};if(o==="then"){if(e.length===0)return{then:()=>r};let a=Fi(i,{type:"GET",path:e.map(l=>l.toString())}).then(mi);return a.then.bind(a)}return tl(i,[...e,o])},set(s,o,a){Os(n);let[l,h]=vs(a);return Fi(i,{type:"SET",path:[...e,o].map(c=>c.toString()),value:l},h).then(mi)},apply(s,o,a){Os(n);let l=e[e.length-1];if(l===il)return Fi(i,{type:"ENDPOINT"}).then(mi);if(l==="bind")return tl(i,e.slice(0,-1));let[h,c]=Ff(a);return Fi(i,{type:"APPLY",path:e.map(f=>f.toString()),argumentList:h},c).then(mi)},construct(s,o){Os(n);let[a,l]=Ff(o);return Fi(i,{type:"CONSTRUCT",path:e.map(h=>h.toString()),argumentList:a},l).then(mi)}});return X0(r,i),r}function I0(i){return Array.prototype.concat.apply([],i)}function Ff(i){let e=i.map(vs);return[e.map(t=>t[0]),I0(e.map(t=>t[1]))]}var Jf=new WeakMap;function N0(i,e){return Jf.set(i,e),i}function j0(i){return Object.assign(i,{[Hf]:!0})}function vs(i){for(let[e,t]of gi)if(t.canHandle(i)){let[n,r]=t.serialize(i);return[{type:"HANDLER",name:e,value:n},r]}return[{type:"RAW",value:i},Jf.get(i)||[]]}function mi(i){switch(i.type){case"HANDLER":return gi.get(i.name).deserialize(i.value);case"RAW":return i.value}}function Fi(i,e,t){return new Promise(n=>{let r=z0();i.addEventListener("message",function s(o){!o.data||!o.data.id||o.data.id!==r||(i.removeEventListener("message",s),n(o.data))}),i.start&&i.start(),i.postMessage(Object.assign({id:r},e),t)})}function z0(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var Hi=[],Ke=class{constructor(e){this.isRunning=!1;this.isDestroyed=!1;Hi.push(this),e?this.callbacks=e:this.callbacks={busyCallback:()=>{},idleCallback:()=>{},runningCallback:()=>{},finishedCallback:()=>{}}}running(){this.isRunning=!0,Hi.forEach(e=>e.callbacks.busyCallback()),this.callbacks.runningCallback()}finished(){this.isRunning=!1,this.callbacks.finishedCallback(),this.status().busy||Hi.forEach(e=>e.callbacks.idleCallback())}status(){let e=this.isRunning,t=this.isDestroyed,n=Hi.some(r=>r.isRunning);return{running:e,busy:n,destroyed:t}}destroy(){this.isDestroyed=!0;let e=Hi.indexOf(this);Hi.splice(e,1)}};var W=class i{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,n){[e,t]=en(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Yi.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=en(this,e,t);let n=[];return this.decompose(e,t,n,0),Yi.from(n,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),n=this.length-this.scanIdentical(e,-1),r=new bi(this),s=new bi(e);for(let o=t,a=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new bi(this,e)}iterRange(e,t=this.length){return new Ps(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Cs(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?i.empty:e.length<=32?new Ne(e):Yi.from(Ne.split(e,[]))}},Ne=class i extends W{constructor(e,t=U0(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.text[s],a=r+o.length;if((t?n:a)>=e)return new rl(r,a,n,o);r=a+1,n++}}decompose(e,t,n,r){let s=e<=0&&t>=this.length?this:new i(eu(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){let o=n.pop(),a=Ts(s.text,o.text.slice(),0,s.length);if(a.length<=32)n.push(new i(a,o.length+s.length));else{let l=a.length>>1;n.push(new i(a.slice(0,l)),new i(a.slice(l)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof i))return super.replace(e,t,n);[e,t]=en(this,e,t);let r=Ts(this.text,Ts(n.text,eu(this.text,0,e)),t),s=this.length+n.length-(t-e);return r.length<=32?new i(r,s):Yi.from(i.split(r,[]),s)}sliceString(e,t=this.length,n=`
+`});var fO=jt((sC,Kk)=>{Kk.exports="CmltcG9ydCBweW9kaWRlICMgdHlwZTogaWdub3JlW2F0dHItZGVmaW5lZF0KaW1wb3J0IHN5cwoKIyBDbGVhbnVwIGFueSBsZWZ0b3ZlciBtYXRwbG90bGliIHBsb3RzCnRyeToKICBpbXBvcnQgbWF0cGxvdGxpYi5weXBsb3QgYXMgcGx0CiAgcGx0LmNsb3NlKCJhbGwiKQogIHBsdC5yY1BhcmFtc1siZmlndXJlLmZpZ3NpemUiXSA9ICh3aWR0aCwgaGVpZ2h0KSAjIHR5cGU6IGlnbm9yZVthdHRyLWRlZmluZWRdCiAgcGx0LnJjUGFyYW1zWyJmaWd1cmUuZHBpIl0gPSBkcGkgIyB0eXBlOiBpZ25vcmVbYXR0ci1kZWZpbmVkXQpleGNlcHQgTW9kdWxlTm90Rm91bmRFcnJvcjoKICBwYXNzCgpmcm9tIElQeXRob24udXRpbHMgaW1wb3J0IGNhcHR1cmUKZnJvbSBJUHl0aG9uLmRpc3BsYXkgaW1wb3J0IGRpc3BsYXkKZnJvbSBJUHl0aG9uLmNvcmUuaW50ZXJhY3RpdmVzaGVsbCBpbXBvcnQgSW50ZXJhY3RpdmVTaGVsbApJbnRlcmFjdGl2ZVNoZWxsKCkuaW5zdGFuY2UoKQoKd2l0aCBjYXB0dXJlLmNhcHR1cmVfb3V0cHV0KCkgYXMgb3V0cHV0OgogIHZhbHVlID0gTm9uZQogIHRyeToKICAgIHZhbHVlID0gYXdhaXQgcHlvZGlkZS5jb2RlLmV2YWxfY29kZV9hc3luYyhjb2RlLCBnbG9iYWxzID0gZW52aXJvbm1lbnQpICMgdHlwZTogaWdub3JlW2F0dHItZGVmaW5lZF0KICBleGNlcHQgRXhjZXB0aW9uIGFzIGV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wIHBhZ2VzCm9wdGlvbnMocGFnZXIgPSBmdW5jdGlvbihmaWxlcywgLi4uKSB7CiAgd3JpdGVMaW5lcyhnc3ViKCIuW1xiXSIsICIiLCByZWFkTGluZXMoZmlsZXMpKSkKfSkKCiMgQ3VzdG9tIHZhbHVlIGhhbmRsZXIgYW5kIHJlbmRlcmluZyBmb3IgZXZhbHVhdGUgYW5kIGtuaXRyCm9wdGlvbnMoIndlYnIuZXZhbHVhdGUuaGFuZGxlciIgPSBldmFsdWF0ZTo6bmV3X291dHB1dF9oYW5kbGVyKAogIHZhbHVlID0gZnVuY3Rpb24oeCwgdmlzaWJsZSkgewogICAga25pdF9vcHRpb25zID0gbGlzdChzY3JlZW5zaG90LmZvcmNlID0gRkFMU0UpCiAgICByZXMgPC0gaWYgKHZpc2libGUpIHsKICAgICAgd2l0aFZpc2libGUoCiAgICAgICAga25pdHI6OmtuaXRfcHJpbnQoCiAgICAgICAgICBpZiAoaW5oZXJpdHMoeCwgImRhdGEuZnJhbWUiKSkgewogICAgICAgICAgICBzd2l0Y2goCiAgICAgICAgICAgICAgZ2V0T3B0aW9uKCJ3ZWJyLnJlbmRlci5kZiIsICJkZWZhdWx0IiksCiAgICAgICAgICAgICAgImthYmxlIiA9IGtuaXRyOjprYWJsZSh4KSwKICAgICAgICAgICAgICAiZHQiID0gRFQ6OmRhdGF0YWJsZSh4KSwKICAgICAgICAgICAgICAicGFnZWQtdGFibGUiID0gcm1hcmtkb3duOjpwYWdlZF90YWJsZSh4KSwKICAgICAgICAgICAgICAiZ3QiID0gZ3Q6Omd0KHgpLAogICAgICAgICAgICAgICJndC1pbnRlcmFjdGl2ZSIgPSBndDo6b3B0X2ludGVyYWN0aXZlKGd0OjpndCh4KSksCiAgICAgICAgICAgICAgInJlYWN0YWJsZSIgPSByZWFjdGFibGU6OnJlYWN0YWJsZSh4KSwKICAgICAgICAgICAgICB4CiAgICAgICAgICAgICkKICAgICAgICAgIH0gZWxzZSB4LAogICAgICAgIG9wdGl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2hlcyhzZWxmLCBkYXNoX29mZnNldCwgZGFzaF9saXN0KToKICAgICAgICBzZWxmLl9kYXNoZXMgPSBkYXNoX29mZnNldCwgZGFzaF9saXN0CiAgICAgICAgaWYgZGFzaF9vZmZzZXQgaXMgbm90IE5vbmU6CiAgICAgICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LmxpbmVEYXNoT2Zmc2V0ID0gZGFzaF9vZmZzZXQKICAgICAgICBpZiBkYXNoX2xpc3QgaXMgTm9uZToKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHguc2V0TGluZURhc2goW10pCiAgICAgICAgZWxzZToKICAgICAgICAgICAgZGxuID0gbnAuYXNhcnJheShkYXNoX2xpc3QpCiAgICAgICAgICAgIGRsID0gbGlzdChzZWxmLnJlbmRlcmVyLnBvaW50c190b19waXhlbHMoZGxuKSkKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHguc2V0TGluZURhc2goZGwpCgogICAgZGVmIHNldF9qb2luc3R5bGUoc2VsZiwganMpOgogICAgICAgIGlmIGpzIGluIFsibWl0ZXIiLCAicm91bmQiLCAiYmV2ZWwiXToKICAgICAgICAgICAgc2VsZi5fam9pbnN0eWxlID0ganMKICAgICAgICAgICAgc2VsZi5yZW5kZXJlci5jdHgubGluZUpvaW4gPSBqcwogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJhaXNlIFZhbHVlRXJyb3IoZiJVbnJlY29nbml6ZWQgam9pbiBzdHlsZS4gRm91bmQge2pzfSIpCgogICAgZGVmIHNldF9saW5ld2lkdGgoc2VsZiwgdyk6CiAgICAgICAgc2VsZi5zdHJva2UgPSB3ICE9IDAKICAgICAgICBzZWxmLl9saW5ld2lkdGggPSBmbG9hdCh3KQogICAgICAgIHNlbGYucmVuZGVyZXIuY3R4LmxpbmVXaWR0aCA9IHNlbGYucmVuZGVyZXIucG9pbnRzX3RvX3BpeGVscyhmbG9hdCh3KSkKCmNsYXNzIFJlbmRlcmVySFRNTENhbnZhc1dvcmtlcihSZW5kZXJlckJhc2UpOgogICAgZGVmIF9faW5pdF9fKHNlbGYsIGN0eCwgd2lkdGgsIGhlaWdodCwgZHBpLCBmaWcpOgogICAgICAgIHN1cGVyKCkuX19pbml0X18oKQogICAgICAgIHNlbGYuZmlnID0gZmlnCiAgICAgICAgc2VsZi5jdHggPSBjdHgKICAgICAgICBzZWxmLndpZHRoID0gd2lkdGgKICAgICAgICBzZWxmLmhlaWdodCA9IGhlaWdodAogICAgICAgIHNlbGYuY3R4LndpZHRoID0gc2VsZi53aWR0aAogICAgICAgIHNlbGYuY3R4LmhlaWdodCA9IHNlbGYuaGVpZ2h0CiAgICAgICAgc2VsZi5kcGkgPSBkcGkKICAgICAgICBzZWxmLmZvbnRkID0gbWF4ZGljdCg1MCkKICAgICAgICBzZWxmLm1hdGh0ZXh0X3BhcnNlciA9IE1hdGhUZXh0UGFyc2VyKCJiaXRtYXAiKQoKICAgICAgICAjIEtlZXAgdGhlIHN0YXRlIG9mIGZvbnRmYWNlcyB0aGF0IGFyZSBsb2FkaW5nCiAgICAgICAgc2VsZi5mb250c19sb2FkaW5nID0ge30KCiAgICBkZWYgbmV3X2djKHNlbGYpOgogICAgICAgIHJldHVybiBHcmFwaGljc0NvbnRleHRIVE1MQ2FudmFzKHJlbmRlcmVyPXNlbGYpCgogICAgZGVmIHBvaW50c190b19waXhlbHMoc2VsZiwgcG9pbnRzKToKICAgICAgICByZXR1cm4gKHBvaW50cyAvIDcyLjApICogc2VsZi5kcGkKCiAgICBkZWYgX21hdHBsb3RsaWJfY29sb3JfdG9fQ1NTKHNlbGYsIGNvbG9yLCBhbHBoYSwgYWxwaGFfb3ZlcnJpZGVzLCBpc19SR0I9VHJ1ZSk6CiAgICAgICAgaWYgbm90IGlzX1JHQjoKICAgICAgICAgICAgUiwgRywgQiwgYWxwaGEgPSBjb2xvckNvbnZlcnRlci50b19yZ2JhKGNvbG9yKQogICAgICAgICAgICBjb2xvciA9IChSLCBHLCBCKQoKICAgICAgICBpZiAobGVuKGNvbG9yKSA9PSA0KSBhbmQgKGFscGhhIGlzIE5vbmUpOgogICAgICAgICAgICBhbHBoYSA9IGNvbG9yWzNdCgogICAgICAgIGlmIGFscGhhIGlzIE5vbmU6CiAgICAgICAgICAgIENTU19jb2xvciA9IHJnYjJoZXgoY29sb3JbOjNdKQoKICAgICAgICBlbHNlOgogICAgICAgICAgICBSID0gaW50KGNvbG9yWzBdICogMjU1KQogICAgICAgICAgICBHID0gaW50KGNvbG9yWzFdICogMjU1KQogICAgICAgICAgICBCID0gaW50KGNvbG9yWzJdICogMjU1KQogICAgICAgICAgICBpZiBsZW4oY29sb3IpID09IDMgb3IgYWxwaGFfb3ZlcnJpZGVzOgogICAgICAgICAgICAgICAgQ1NTX2NvbG9yID0gZiIiInJnYmEoe1I6ZH0sIHtHOmR9LCB7QjpkfSwge2FscGhhOi4zZ30pIiIiCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBDU1NfY29sb3IgPSAiIiJyZ2JhKHs6ZH0sIHs6ZH0sIHs6ZH0sIHs6LjNnfSkiIiIuZm9ybWF0KAogICAgICAgICAgICAgICAgICAgIFIsIEcsIEIsIGNvbG9yWzNdCiAgICAgICAgICAgICAgICApCgogICAgICAgIHJldHVybiBDU1NfY29sb3IKCiAgICBkZWYgX3NldF9zdHlsZShzZWxmLCBnYywgcmdiRmFjZT1Ob25lKToKICAgICAgICBpZiByZ2JGYWNlIGlzIG5vdCBOb25lOgogICAgICAgICAgICBzZWxmLmN0eC5maWxsU3R5bGUgPSBzZWxmLl9tYXRwbG90bGliX2NvbG9yX3RvX0NTUygKICAgICAgICAgICAgICAgIHJnYkZhY2UsIGdjLmdldF9hbHBoYSgpLCBnYy5nZXRfZm9yY2VkX2FscGhhKCkKICAgICAgICAgICAgKQoKICAgICAgICBpZiBnYy5nZXRfY2Fwc3R5bGUoKToKICAgICAgICAgICAgc2VsZi5jdHgubGluZUNhcCA9IF9jYXBzdHlsZV9kW2djLmdldF9jYXB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gPSBmaW5kZm9udChwcm9wKQogICAgICAgICAgICBmb250X3ZhbHVlID0gc2VsZi5mb250ZC5nZXQoZm5hbWUpCiAgICAgICAgICAgIGlmIGZvbnRfdmFsdWUgaXMgTm9uZToKICAgICAgICAgICAgICAgIGZvbnQgPSBGVDJGb250KHN0cihmbmFtZSkpCiAgICAgICAgICAgICAgICBmb250X2ZpbGVfbmFtZSA9IGZuYW1lW2ZuYW1lLnJmaW5kKCIvIikgKyAxIDpdCiAgICAgICAgICAgICAgICBmb250X3ZhbHVlID0gZm9udCwgZm9udF9maWxlX25hbWUKICAgICAgICAgICAgICAgIHNlbGYuZm9udGRbZm5hbWVdID0gZm9udF92YWx1ZQogICAgICAgICAgICBzZWxmLmZvbnRkW2tleV0gPSBmb250X3ZhbHVlCiAgICAgICAgZm9udCwgZm9udF9maWxlX25hbWUgPSBmb250X3ZhbHVlCiAgICAgICAgZm9udC5jbGVhcigpCiAgICAgICAgZm9udC5zZXRfc2l6ZShwcm9wLmdldF9zaXplX2luX3BvaW50cygpLCBzZWxmLmRwaSkKICAgICAgICByZXR1cm4gZm9udCwgZm9udF9maWxlX25hbWUKCiAgICBkZWYgZ2V0X3RleHRfd2lkdGhfaGVpZ2h0X2Rlc2NlbnQoc2VsZiwgcywgcHJvcCwgaXNtYXRoKToKICAgICAgICB3OiBmbG9hdAogICAgICAgIGg6IGZsb2F0CiAgICAgICAgaWYgaXNtYXRoOgogICAgICAgICAgICBpbWFnZSwgZCA9IHNlbGYubWF0aHRleHRfcGFyc2VyLnBhcnNlKHMsIHNlbGYuZHBpLCBwcm9wKQogICAgICAgICAgICBpbWFnZV9hcnIgPSBucC5hc2FycmF5KGltYWdlKQogICAgICAgICAgICBoLCB3ID0gaW1hZ2VfYXJyLnNoYXBlCiAgICAgICAgZWxzZToKICAgICAgICAgICAgZm9udCwgXyA9IHNlbGYuX2dldF9mb250KHByb3ApCiAgICAgICAgICAgIGZvbnQuc2V0X3RleHQocywgMC4wLCBmbGFncz1MT0F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mdzKQoKICAgIEBzdGF0aWNtZXRob2QKICAgIGRlZiBkZXN0cm95KCphcmdzLCAqKmt3YXJncyk6CiAgICAgICAgZnJvbSBtYXRwbG90bGliIGltcG9ydCBweXBsb3QgYXMgcGx0CiAgICAgICAgcGx0LmdjZigpLmNhbnZhcy5kZXN0cm95KCphcmdzLCAqKmt3YXJncykK"});var Ka={};xO(Ka,{ChannelType:()=>Qt,Console:()=>M0,Shelter:()=>Ba,WebR:()=>Uf,WebRChannelError:()=>pt,WebRError:()=>di,WebRPayloadError:()=>Bn,WebRWorkerError:()=>wf,isRCall:()=>gs,isRCharacter:()=>Ui,isRComplex:()=>R0,isRDouble:()=>C0,isREnvironment:()=>S0,isRFunction:()=>Os,isRInteger:()=>P0,isRList:()=>ot,isRLogical:()=>T0,isRNull:()=>Re,isRObject:()=>ee,isRPairlist:()=>k0,isRRaw:()=>Ja,isRSymbol:()=>x0});var kO=Object.create,pf=Object.defineProperty,SO=Object.getOwnPropertyDescriptor,TO=Object.getOwnPropertyNames,PO=Object.getPrototypeOf,CO=Object.prototype.hasOwnProperty,Bi=(i=>typeof ci<"u"?ci:typeof Proxy<"u"?new Proxy(i,{get:(e,t)=>(typeof ci<"u"?ci:e)[t]}):i)(function(i){if(typeof ci<"u")return ci.apply(this,arguments);throw new Error('Dynamic require of "'+i+'" is not supported')}),ke=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),RO=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of TO(e))!CO.call(i,r)&&r!==t&&pf(i,r,{get:()=>e[r],enumerable:!(n=SO(e,r))||n.enumerable});return i},Xi=(i,e,t)=>(t=i!=null?kO(PO(i)):{},RO(e||!i||!i.__esModule?pf(t,"default",{value:i,enumerable:!0}):t,i)),Xa=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)},k=(i,e,t)=>(Xa(i,e,"read from private field"),t?t.call(i):e.get(i)),L=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)},me=(i,e,t,n)=>(Xa(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);var Je=(i,e,t)=>(Xa(i,e,"access private method"),t),cs=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.getUint64=i.getInt64=i.setInt64=i.setUint64=i.UINT32_MAX=void 0,i.UINT32_MAX=4294967295;function e(s,o,a){let l=a/4294967296,h=a;s.setUint32(o,l),s.setUint32(o+4,h)}i.setUint64=e;function t(s,o,a){let l=Math.floor(a/4294967296),h=a;s.setUint32(o,l),s.setUint32(o+4,h)}i.setInt64=t;function n(s,o){let a=s.getInt32(o),l=s.getUint32(o+4);return a*4294967296+l}i.getInt64=n;function r(s,o){let a=s.getUint32(o),l=s.getUint32(o+4);return a*4294967296+l}i.getUint64=r}),Wa=ke(i=>{"use strict";var e,t,n;Object.defineProperty(i,"__esModule",{value:!0}),i.utf8DecodeTD=i.TEXT_DECODER_THRESHOLD=i.utf8DecodeJs=i.utf8EncodeTE=i.TEXT_ENCODER_THRESHOLD=i.utf8EncodeJs=i.utf8Count=void 0;var r=cs(),s=(typeof process>"u"||((e=process==null?void 0:process.env)===null||e===void 0?void 0:e.TEXT_ENCODING)!=="never")&&typeof TextEncoder<"u"&&typeof TextDecoder<"u";function o(p){let g=p.length,O=0,y=0;for(;y=55296&&v<=56319&&y>6&31|192;else{if(w>=55296&&w<=56319&&x>18&7|240,g[v++]=w>>12&63|128,g[v++]=w>>6&63|128):(g[v++]=w>>12&15|224,g[v++]=w>>6&63|128)}else{g[v++]=w;continue}g[v++]=w&63|128}}i.utf8EncodeJs=a;var l=s?new TextEncoder:void 0;i.TEXT_ENCODER_THRESHOLD=s?typeof process<"u"&&((t=process==null?void 0:process.env)===null||t===void 0?void 0:t.TEXT_ENCODING)!=="force"?200:0:r.UINT32_MAX;function h(p,g,O){g.set(l.encode(p),O)}function c(p,g,O){l.encodeInto(p,g.subarray(O))}i.utf8EncodeTE=l!=null&&l.encodeInto?c:h;var f=4096;function u(p,g,O){let y=g,v=y+O,x=[],w="";for(;y65535&&(V-=65536,x.push(V>>>10&1023|55296),V=56320|V&1023),x.push(V)}else x.push(P);x.length>=f&&(w+=String.fromCharCode(...x),x.length=0)}return x.length>0&&(w+=String.fromCharCode(...x)),w}i.utf8DecodeJs=u;var d=s?new TextDecoder:null;i.TEXT_DECODER_THRESHOLD=s?typeof process<"u"&&((n=process==null?void 0:process.env)===null||n===void 0?void 0:n.TEXT_DECODER)!=="force"?200:0:r.UINT32_MAX;function m(p,g,O){let y=p.subarray(g,g+O);return d.decode(y)}i.utf8DecodeTD=m}),mf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ExtData=void 0;var e=class{constructor(t,n){this.type=t,this.data=n}};i.ExtData=e}),Ia=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DecodeError=void 0;var e=class extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:e.name})}};i.DecodeError=e}),gf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.timestampExtension=i.decodeTimestampExtension=i.decodeTimestampToTimeSpec=i.encodeTimestampExtension=i.encodeDateToTimeSpec=i.encodeTimeSpecToTimestamp=i.EXT_TIMESTAMP=void 0;var e=Ia(),t=cs();i.EXT_TIMESTAMP=-1;var n=4294967296-1,r=17179869184-1;function s({sec:c,nsec:f}){if(c>=0&&f>=0&&c<=r)if(f===0&&c<=n){let u=new Uint8Array(4);return new DataView(u.buffer).setUint32(0,c),u}else{let u=c/4294967296,d=c&4294967295,m=new Uint8Array(8),p=new DataView(m.buffer);return p.setUint32(0,f<<2|u&3),p.setUint32(4,d),m}else{let u=new Uint8Array(12),d=new DataView(u.buffer);return d.setUint32(0,f),(0,t.setInt64)(d,4,c),u}}i.encodeTimeSpecToTimestamp=s;function o(c){let f=c.getTime(),u=Math.floor(f/1e3),d=(f-u*1e3)*1e6,m=Math.floor(d/1e9);return{sec:u+m,nsec:d-m*1e9}}i.encodeDateToTimeSpec=o;function a(c){if(c instanceof Date){let f=o(c);return s(f)}else return null}i.encodeTimestampExtension=a;function l(c){let f=new DataView(c.buffer,c.byteOffset,c.byteLength);switch(c.byteLength){case 4:return{sec:f.getUint32(0),nsec:0};case 8:{let u=f.getUint32(0),d=f.getUint32(4),m=(u&3)*4294967296+d,p=u>>>2;return{sec:m,nsec:p}}case 12:{let u=(0,t.getInt64)(f,4),d=f.getUint32(0);return{sec:u,nsec:d}}default:throw new e.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${c.length}`)}}i.decodeTimestampToTimeSpec=l;function h(c){let f=l(c);return new Date(f.sec*1e3+f.nsec/1e6)}i.decodeTimestampExtension=h,i.timestampExtension={type:i.EXT_TIMESTAMP,encode:a,decode:h}}),Na=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ExtensionCodec=void 0;var e=mf(),t=gf(),n=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(t.timestampExtension)}register({type:r,encode:s,decode:o}){if(r>=0)this.encoders[r]=s,this.decoders[r]=o;else{let a=1+r;this.builtInEncoders[a]=s,this.builtInDecoders[a]=o}}tryToEncode(r,s){for(let o=0;o{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.createDataView=i.ensureUint8Array=void 0;function e(n){return n instanceof Uint8Array?n:ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):n instanceof ArrayBuffer?new Uint8Array(n):Uint8Array.from(n)}i.ensureUint8Array=e;function t(n){if(n instanceof ArrayBuffer)return new DataView(n);let r=e(n);return new DataView(r.buffer,r.byteOffset,r.byteLength)}i.createDataView=t}),yf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Encoder=i.DEFAULT_INITIAL_BUFFER_SIZE=i.DEFAULT_MAX_DEPTH=void 0;var e=Wa(),t=Na(),n=cs(),r=Of();i.DEFAULT_MAX_DEPTH=100,i.DEFAULT_INITIAL_BUFFER_SIZE=2048;var s=class{constructor(o=t.ExtensionCodec.defaultCodec,a=void 0,l=i.DEFAULT_MAX_DEPTH,h=i.DEFAULT_INITIAL_BUFFER_SIZE,c=!1,f=!1,u=!1,d=!1){this.extensionCodec=o,this.context=a,this.maxDepth=l,this.initialBufferSize=h,this.sortKeys=c,this.forceFloat32=f,this.ignoreUndefined=u,this.forceIntegerToFloat=d,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}reinitializeState(){this.pos=0}encodeSharedRef(o){return this.reinitializeState(),this.doEncode(o,1),this.bytes.subarray(0,this.pos)}encode(o){return this.reinitializeState(),this.doEncode(o,1),this.bytes.slice(0,this.pos)}doEncode(o,a){if(a>this.maxDepth)throw new Error(`Too deep objects in depth ${a}`);o==null?this.encodeNil():typeof o=="boolean"?this.encodeBoolean(o):typeof o=="number"?this.encodeNumber(o):typeof o=="string"?this.encodeString(o):this.encodeObject(o,a)}ensureBufferSizeToWrite(o){let a=this.pos+o;this.view.byteLength=0?o<128?this.writeU8(o):o<256?(this.writeU8(204),this.writeU8(o)):o<65536?(this.writeU8(205),this.writeU16(o)):o<4294967296?(this.writeU8(206),this.writeU32(o)):(this.writeU8(207),this.writeU64(o)):o>=-32?this.writeU8(224|o+32):o>=-128?(this.writeU8(208),this.writeI8(o)):o>=-32768?(this.writeU8(209),this.writeI16(o)):o>=-2147483648?(this.writeU8(210),this.writeI32(o)):(this.writeU8(211),this.writeI64(o)):this.forceFloat32?(this.writeU8(202),this.writeF32(o)):(this.writeU8(203),this.writeF64(o))}writeStringHeader(o){if(o<32)this.writeU8(160+o);else if(o<256)this.writeU8(217),this.writeU8(o);else if(o<65536)this.writeU8(218),this.writeU16(o);else if(o<4294967296)this.writeU8(219),this.writeU32(o);else throw new Error(`Too long string: ${o} bytes in UTF-8`)}encodeString(o){if(o.length>e.TEXT_ENCODER_THRESHOLD){let a=(0,e.utf8Count)(o);this.ensureBufferSizeToWrite(5+a),this.writeStringHeader(a),(0,e.utf8EncodeTE)(o,this.bytes,this.pos),this.pos+=a}else{let a=(0,e.utf8Count)(o);this.ensureBufferSizeToWrite(5+a),this.writeStringHeader(a),(0,e.utf8EncodeJs)(o,this.bytes,this.pos),this.pos+=a}}encodeObject(o,a){let l=this.extensionCodec.tryToEncode(o,this.context);if(l!=null)this.encodeExtension(l);else if(Array.isArray(o))this.encodeArray(o,a);else if(ArrayBuffer.isView(o))this.encodeBinary(o);else if(typeof o=="object")this.encodeMap(o,a);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(o)}`)}encodeBinary(o){let a=o.byteLength;if(a<256)this.writeU8(196),this.writeU8(a);else if(a<65536)this.writeU8(197),this.writeU16(a);else if(a<4294967296)this.writeU8(198),this.writeU32(a);else throw new Error(`Too large binary: ${a}`);let l=(0,r.ensureUint8Array)(o);this.writeU8a(l)}encodeArray(o,a){let l=o.length;if(l<16)this.writeU8(144+l);else if(l<65536)this.writeU8(220),this.writeU16(l);else if(l<4294967296)this.writeU8(221),this.writeU32(l);else throw new Error(`Too large array: ${l}`);for(let h of o)this.doEncode(h,a+1)}countWithoutUndefined(o,a){let l=0;for(let h of a)o[h]!==void 0&&l++;return l}encodeMap(o,a){let l=Object.keys(o);this.sortKeys&&l.sort();let h=this.ignoreUndefined?this.countWithoutUndefined(o,l):l.length;if(h<16)this.writeU8(128+h);else if(h<65536)this.writeU8(222),this.writeU16(h);else if(h<4294967296)this.writeU8(223),this.writeU32(h);else throw new Error(`Too large map object: ${h}`);for(let c of l){let f=o[c];this.ignoreUndefined&&f===void 0||(this.encodeString(c),this.doEncode(f,a+1))}}encodeExtension(o){let a=o.data.length;if(a===1)this.writeU8(212);else if(a===2)this.writeU8(213);else if(a===4)this.writeU8(214);else if(a===8)this.writeU8(215);else if(a===16)this.writeU8(216);else if(a<256)this.writeU8(199),this.writeU8(a);else if(a<65536)this.writeU8(200),this.writeU16(a);else if(a<4294967296)this.writeU8(201),this.writeU32(a);else throw new Error(`Too large extension object: ${a}`);this.writeI8(o.type),this.writeU8a(o.data)}writeU8(o){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,o),this.pos++}writeU8a(o){let a=o.length;this.ensureBufferSizeToWrite(a),this.bytes.set(o,this.pos),this.pos+=a}writeI8(o){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,o),this.pos++}writeU16(o){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,o),this.pos+=2}writeI16(o){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,o),this.pos+=2}writeU32(o){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,o),this.pos+=4}writeI32(o){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,o),this.pos+=4}writeF32(o){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,o),this.pos+=4}writeF64(o){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,o),this.pos+=8}writeU64(o){this.ensureBufferSizeToWrite(8),(0,n.setUint64)(this.view,this.pos,o),this.pos+=8}writeI64(o){this.ensureBufferSizeToWrite(8),(0,n.setInt64)(this.view,this.pos,o),this.pos+=8}};i.Encoder=s}),EO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.encode=void 0;var e=yf(),t={};function n(r,s=t){return new e.Encoder(s.extensionCodec,s.context,s.maxDepth,s.initialBufferSize,s.sortKeys,s.forceFloat32,s.ignoreUndefined,s.forceIntegerToFloat).encodeSharedRef(r)}i.encode=n}),AO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.prettyByte=void 0;function e(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}i.prettyByte=e}),QO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CachedKeyDecoder=void 0;var e=Wa(),t=16,n=16,r=class{constructor(s=t,o=n){this.maxKeyLength=s,this.maxLengthPerKey=o,this.hit=0,this.miss=0,this.caches=[];for(let a=0;a0&&s<=this.maxKeyLength}find(s,o,a){let l=this.caches[a-1];e:for(let h of l){let c=h.bytes;for(let f=0;f=this.maxLengthPerKey?a[Math.random()*a.length|0]=l:a.push(l)}decode(s,o,a){let l=this.find(s,o,a);if(l!=null)return this.hit++,l;this.miss++;let h=(0,e.utf8DecodeJs)(s,o,a),c=Uint8Array.prototype.slice.call(s,o,o+a);return this.store(c,h),h}};i.CachedKeyDecoder=r}),ja=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Decoder=i.DataViewIndexOutOfBoundsError=void 0;var e=AO(),t=Na(),n=cs(),r=Wa(),s=Of(),o=QO(),a=Ia(),l=p=>{let g=typeof p;return g==="string"||g==="number"},h=-1,c=new DataView(new ArrayBuffer(0)),f=new Uint8Array(c.buffer);i.DataViewIndexOutOfBoundsError=(()=>{try{c.getInt8(0)}catch(p){return p.constructor}throw new Error("never reached")})();var u=new i.DataViewIndexOutOfBoundsError("Insufficient data"),d=new o.CachedKeyDecoder,m=class{constructor(p=t.ExtensionCodec.defaultCodec,g=void 0,O=n.UINT32_MAX,y=n.UINT32_MAX,v=n.UINT32_MAX,x=n.UINT32_MAX,w=n.UINT32_MAX,P=d){this.extensionCodec=p,this.context=g,this.maxStrLength=O,this.maxBinLength=y,this.maxArrayLength=v,this.maxMapLength=x,this.maxExtLength=w,this.keyDecoder=P,this.totalPos=0,this.pos=0,this.view=c,this.bytes=f,this.headByte=h,this.stack=[]}reinitializeState(){this.totalPos=0,this.headByte=h,this.stack.length=0}setBuffer(p){this.bytes=(0,s.ensureUint8Array)(p),this.view=(0,s.createDataView)(this.bytes),this.pos=0}appendBuffer(p){if(this.headByte===h&&!this.hasRemaining(1))this.setBuffer(p);else{let g=this.bytes.subarray(this.pos),O=(0,s.ensureUint8Array)(p),y=new Uint8Array(g.length+O.length);y.set(g),y.set(O,g.length),this.setBuffer(y)}}hasRemaining(p){return this.view.byteLength-this.pos>=p}createExtraByteError(p){let{view:g,pos:O}=this;return new RangeError(`Extra ${g.byteLength-O} of ${g.byteLength} byte(s) found at buffer[${p}]`)}decode(p){this.reinitializeState(),this.setBuffer(p);let g=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return g}*decodeMulti(p){for(this.reinitializeState(),this.setBuffer(p);this.hasRemaining(1);)yield this.doDecodeSync()}async decodeAsync(p){let g=!1,O;for await(let w of p){if(g)throw this.createExtraByteError(this.totalPos);this.appendBuffer(w);try{O=this.doDecodeSync(),g=!0}catch(P){if(!(P instanceof i.DataViewIndexOutOfBoundsError))throw P}this.totalPos+=this.pos}if(g){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return O}let{headByte:y,pos:v,totalPos:x}=this;throw new RangeError(`Insufficient data in parsing ${(0,e.prettyByte)(y)} at ${x} (${v} in the current buffer)`)}decodeArrayStream(p){return this.decodeMultiAsync(p,!0)}decodeStream(p){return this.decodeMultiAsync(p,!1)}async*decodeMultiAsync(p,g){let O=g,y=-1;for await(let v of p){if(g&&y===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(v),O&&(y=this.readArraySize(),O=!1,this.complete());try{for(;yield this.doDecodeSync(),--y!==0;);}catch(x){if(!(x instanceof i.DataViewIndexOutOfBoundsError))throw x}this.totalPos+=this.pos}}doDecodeSync(){e:for(;;){let p=this.readHeadByte(),g;if(p>=224)g=p-256;else if(p<192)if(p<128)g=p;else if(p<144){let y=p-128;if(y!==0){this.pushMapState(y),this.complete();continue e}else g={}}else if(p<160){let y=p-144;if(y!==0){this.pushArrayState(y),this.complete();continue e}else g=[]}else{let y=p-160;g=this.decodeUtf8String(y,0)}else if(p===192)g=null;else if(p===194)g=!1;else if(p===195)g=!0;else if(p===202)g=this.readF32();else if(p===203)g=this.readF64();else if(p===204)g=this.readU8();else if(p===205)g=this.readU16();else if(p===206)g=this.readU32();else if(p===207)g=this.readU64();else if(p===208)g=this.readI8();else if(p===209)g=this.readI16();else if(p===210)g=this.readI32();else if(p===211)g=this.readI64();else if(p===217){let y=this.lookU8();g=this.decodeUtf8String(y,1)}else if(p===218){let y=this.lookU16();g=this.decodeUtf8String(y,2)}else if(p===219){let y=this.lookU32();g=this.decodeUtf8String(y,4)}else if(p===220){let y=this.readU16();if(y!==0){this.pushArrayState(y),this.complete();continue e}else g=[]}else if(p===221){let y=this.readU32();if(y!==0){this.pushArrayState(y),this.complete();continue e}else g=[]}else if(p===222){let y=this.readU16();if(y!==0){this.pushMapState(y),this.complete();continue e}else g={}}else if(p===223){let y=this.readU32();if(y!==0){this.pushMapState(y),this.complete();continue e}else g={}}else if(p===196){let y=this.lookU8();g=this.decodeBinary(y,1)}else if(p===197){let y=this.lookU16();g=this.decodeBinary(y,2)}else if(p===198){let y=this.lookU32();g=this.decodeBinary(y,4)}else if(p===212)g=this.decodeExtension(1,0);else if(p===213)g=this.decodeExtension(2,0);else if(p===214)g=this.decodeExtension(4,0);else if(p===215)g=this.decodeExtension(8,0);else if(p===216)g=this.decodeExtension(16,0);else if(p===199){let y=this.lookU8();g=this.decodeExtension(y,1)}else if(p===200){let y=this.lookU16();g=this.decodeExtension(y,2)}else if(p===201){let y=this.lookU32();g=this.decodeExtension(y,4)}else throw new a.DecodeError(`Unrecognized type byte: ${(0,e.prettyByte)(p)}`);this.complete();let O=this.stack;for(;O.length>0;){let y=O[O.length-1];if(y.type===0)if(y.array[y.position]=g,y.position++,y.position===y.size)O.pop(),g=y.array;else continue e;else if(y.type===1){if(!l(g))throw new a.DecodeError("The type of key must be string or number but "+typeof g);if(g==="__proto__")throw new a.DecodeError("The key __proto__ is not allowed");y.key=g,y.type=2;continue e}else if(y.map[y.key]=g,y.readCount++,y.readCount===y.size)O.pop(),g=y.map;else{y.key=null,y.type=1;continue e}}return g}}readHeadByte(){return this.headByte===h&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=h}readArraySize(){let p=this.readHeadByte();switch(p){case 220:return this.readU16();case 221:return this.readU32();default:{if(p<160)return p-144;throw new a.DecodeError(`Unrecognized array type byte: ${(0,e.prettyByte)(p)}`)}}}pushMapState(p){if(p>this.maxMapLength)throw new a.DecodeError(`Max length exceeded: map length (${p}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.push({type:1,size:p,key:null,readCount:0,map:{}})}pushArrayState(p){if(p>this.maxArrayLength)throw new a.DecodeError(`Max length exceeded: array length (${p}) > maxArrayLength (${this.maxArrayLength})`);this.stack.push({type:0,size:p,array:new Array(p),position:0})}decodeUtf8String(p,g){var O;if(p>this.maxStrLength)throw new a.DecodeError(`Max length exceeded: UTF-8 byte length (${p}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLengthr.TEXT_DECODER_THRESHOLD?v=(0,r.utf8DecodeTD)(this.bytes,y,p):v=(0,r.utf8DecodeJs)(this.bytes,y,p),this.pos+=g+p,v}stateIsMapKey(){return this.stack.length>0?this.stack[this.stack.length-1].type===1:!1}decodeBinary(p,g){if(p>this.maxBinLength)throw new a.DecodeError(`Max length exceeded: bin length (${p}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(p+g))throw u;let O=this.pos+g,y=this.bytes.subarray(O,O+p);return this.pos+=g+p,y}decodeExtension(p,g){if(p>this.maxExtLength)throw new a.DecodeError(`Max length exceeded: ext length (${p}) > maxExtLength (${this.maxExtLength})`);let O=this.view.getInt8(this.pos+g),y=this.decodeBinary(p,g+1);return this.extensionCodec.decode(y,O,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let p=this.view.getUint8(this.pos);return this.pos++,p}readI8(){let p=this.view.getInt8(this.pos);return this.pos++,p}readU16(){let p=this.view.getUint16(this.pos);return this.pos+=2,p}readI16(){let p=this.view.getInt16(this.pos);return this.pos+=2,p}readU32(){let p=this.view.getUint32(this.pos);return this.pos+=4,p}readI32(){let p=this.view.getInt32(this.pos);return this.pos+=4,p}readU64(){let p=(0,n.getUint64)(this.view,this.pos);return this.pos+=8,p}readI64(){let p=(0,n.getInt64)(this.view,this.pos);return this.pos+=8,p}readF32(){let p=this.view.getFloat32(this.pos);return this.pos+=4,p}readF64(){let p=this.view.getFloat64(this.pos);return this.pos+=8,p}};i.Decoder=m}),bf=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.decodeMulti=i.decode=i.defaultDecodeOptions=void 0;var e=ja();i.defaultDecodeOptions={};function t(r,s=i.defaultDecodeOptions){return new e.Decoder(s.extensionCodec,s.context,s.maxStrLength,s.maxBinLength,s.maxArrayLength,s.maxMapLength,s.maxExtLength).decode(r)}i.decode=t;function n(r,s=i.defaultDecodeOptions){return new e.Decoder(s.extensionCodec,s.context,s.maxStrLength,s.maxBinLength,s.maxArrayLength,s.maxMapLength,s.maxExtLength).decodeMulti(r)}i.decodeMulti=n}),MO=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ensureAsyncIterable=i.asyncIterableFromStream=i.isAsyncIterable=void 0;function e(s){return s[Symbol.asyncIterator]!=null}i.isAsyncIterable=e;function t(s){if(s==null)throw new Error("Assertion Failure: value must not be null nor undefined")}async function*n(s){let o=s.getReader();try{for(;;){let{done:a,value:l}=await o.read();if(a)return;t(l),yield l}}finally{o.releaseLock()}}i.asyncIterableFromStream=n;function r(s){return e(s)?s:n(s)}i.ensureAsyncIterable=r}),_O=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.decodeStream=i.decodeMultiStream=i.decodeArrayStream=i.decodeAsync=void 0;var e=ja(),t=MO(),n=bf();async function r(l,h=n.defaultDecodeOptions){let c=(0,t.ensureAsyncIterable)(l);return new e.Decoder(h.extensionCodec,h.context,h.maxStrLength,h.maxBinLength,h.maxArrayLength,h.maxMapLength,h.maxExtLength).decodeAsync(c)}i.decodeAsync=r;function s(l,h=n.defaultDecodeOptions){let c=(0,t.ensureAsyncIterable)(l);return new e.Decoder(h.extensionCodec,h.context,h.maxStrLength,h.maxBinLength,h.maxArrayLength,h.maxMapLength,h.maxExtLength).decodeArrayStream(c)}i.decodeArrayStream=s;function o(l,h=n.defaultDecodeOptions){let c=(0,t.ensureAsyncIterable)(l);return new e.Decoder(h.extensionCodec,h.context,h.maxStrLength,h.maxBinLength,h.maxArrayLength,h.maxMapLength,h.maxExtLength).decodeStream(c)}i.decodeMultiStream=o;function a(l,h=n.defaultDecodeOptions){return o(l,h)}i.decodeStream=a}),za=ke(i=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.decodeTimestampExtension=i.encodeTimestampExtension=i.decodeTimestampToTimeSpec=i.encodeTimeSpecToTimestamp=i.encodeDateToTimeSpec=i.EXT_TIMESTAMP=i.ExtData=i.ExtensionCodec=i.Encoder=i.DataViewIndexOutOfBoundsError=i.DecodeError=i.Decoder=i.decodeStream=i.decodeMultiStream=i.decodeArrayStream=i.decodeAsync=i.decodeMulti=i.decode=i.encode=void 0;var e=EO();Object.defineProperty(i,"encode",{enumerable:!0,get:function(){return e.encode}});var t=bf();Object.defineProperty(i,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(i,"decodeMulti",{enumerable:!0,get:function(){return t.decodeMulti}});var n=_O();Object.defineProperty(i,"decodeAsync",{enumerable:!0,get:function(){return n.decodeAsync}}),Object.defineProperty(i,"decodeArrayStream",{enumerable:!0,get:function(){return n.decodeArrayStream}}),Object.defineProperty(i,"decodeMultiStream",{enumerable:!0,get:function(){return n.decodeMultiStream}}),Object.defineProperty(i,"decodeStream",{enumerable:!0,get:function(){return n.decodeStream}});var r=ja();Object.defineProperty(i,"Decoder",{enumerable:!0,get:function(){return r.Decoder}}),Object.defineProperty(i,"DataViewIndexOutOfBoundsError",{enumerable:!0,get:function(){return r.DataViewIndexOutOfBoundsError}});var s=Ia();Object.defineProperty(i,"DecodeError",{enumerable:!0,get:function(){return s.DecodeError}});var o=yf();Object.defineProperty(i,"Encoder",{enumerable:!0,get:function(){return o.Encoder}});var a=Na();Object.defineProperty(i,"ExtensionCodec",{enumerable:!0,get:function(){return a.ExtensionCodec}});var l=mf();Object.defineProperty(i,"ExtData",{enumerable:!0,get:function(){return l.ExtData}});var h=gf();Object.defineProperty(i,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return h.EXT_TIMESTAMP}}),Object.defineProperty(i,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return h.encodeDateToTimeSpec}}),Object.defineProperty(i,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return h.encodeTimeSpecToTimestamp}}),Object.defineProperty(i,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return h.decodeTimestampToTimeSpec}}),Object.defineProperty(i,"encodeTimestampExtension",{enumerable:!0,get:function(){return h.encodeTimestampExtension}}),Object.defineProperty(i,"decodeTimestampExtension",{enumerable:!0,get:function(){return h.decodeTimestampExtension}})}),di=class extends Error{constructor(i){super(i),this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}},wf=class extends di{},pt=class extends di{},Bn=class extends di{},Ie=typeof process<"u"&&process.release&&process.release.name==="node",ga;if(globalThis.document)ga=i=>new Promise((e,t)=>{let n=document.createElement("script");n.src=i,n.onload=()=>e(),n.onerror=t,document.head.appendChild(n)});else if(globalThis.importScripts)ga=async i=>{try{globalThis.importScripts(i)}catch(e){if(e instanceof TypeError)await Promise.resolve().then(()=>Xi(Bi(i)));else throw e}};else if(Ie)ga=async i=>{let e=(await Promise.resolve().then(()=>Xi(Bi("path")))).default;await Promise.resolve().then(()=>Xi(Bi(e.resolve(i))))};else throw new di("Cannot determine runtime environment");var T={};function DO(i){Object.keys(i).forEach(e=>T._free(i[e]))}var mt={null:0,symbol:1,pairlist:2,closure:3,environment:4,promise:5,call:6,special:7,builtin:8,string:9,logical:10,integer:13,double:14,complex:15,character:16,dots:17,any:18,list:19,expression:20,bytecode:21,pointer:22,weakref:23,raw:24,s4:25,new:30,free:31,function:99};function vf(i){return!!i&&typeof i=="object"&&Object.keys(mt).includes(i.type)}function fs(i){return!!i&&typeof i=="object"&&"re"in i&&"im"in i}function Yr(i){return T._Rf_protect(Mt(i)),i}function ae(i,e){return T._Rf_protect(Mt(i)),++e.n,i}function $O(i){let e=T._malloc(4);return T._R_ProtectWithIndex(Mt(i),e),{loc:T.getValue(e,"i32"),ptr:e}}function VO(i){T._Rf_unprotect(1),T._free(i.ptr)}function LO(i,e){return T._R_Reprotect(Mt(i),e.loc),i}function Oe(i){T._Rf_unprotect(i)}function af(i,e,t){T._Rf_defineVar(Mt(e),Mt(t),Mt(i))}function lf(i,e){let t={},n={n:0};try{let r=new Tf(e);ae(r,n),t.code=T.allocateUTF8(i);let s=T._R_ParseEvalString(t.code,r.ptr);return z.wrap(s)}finally{DO(t),Oe(n.n)}}function us(i,e){return T.getWasmTableEntry(T.GOT.ffi_safe_eval.value)(Mt(i),Mt(e))}var qO=new WeakMap;function BO(i,e){return qO.set(i,e),i}var XO=63;function xf(){let i=Array.from({length:4},WO).join("-");if(i.length!==XO)throw new Error("comlink internal error: UUID has the wrong length");return i}function WO(){let i=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16),e=15-i.length;return e>0&&(i=Array.from({length:e},()=>0).join("")+i),i}function Mt(i){return rs(i)?i.ptr:i}function pi(i,e){if(T._TYPEOF(i.ptr)!==mt[e])throw new Error(`Unexpected object type "${i.type()}" when expecting type "${e}"`)}function kf(i){if(vf(i))return new(_f(i.type))(i);if(i&&typeof i=="object"&&"type"in i&&i.type==="null")return new Sf;if(i===null)return new Ni({type:"logical",names:null,values:[null]});if(typeof i=="boolean")return new Ni(i);if(typeof i=="number")return new ps(i);if(typeof i=="string")return new zt(i);if(fs(i))return new Fa(i);if(ArrayBuffer.isView(i)||i instanceof ArrayBuffer)return new Ha(i);if(Array.isArray(i))return IO(i);if(typeof i=="object")return Xn.fromObject(i);throw new Error("Robj construction for this JS object is not yet supported")}function IO(i){let e={n:0};if(i.every(t=>t&&typeof t=="object"&&!rs(t)&&!fs(t))){let t=i,n=t.every(s=>Object.keys(s).filter(o=>!Object.keys(t[0]).includes(o)).length===0&&Object.keys(t[0]).filter(o=>!Object.keys(s).includes(o)).length===0),r=t.every(s=>Object.values(s).every(o=>$f(o)||Df(o)));if(n&&r)return Xn.fromD3(t)}if(i.every(t=>typeof t=="boolean"||t===null))return new Ni(i);if(i.every(t=>typeof t=="number"||t===null))return new ps(i);if(i.every(t=>typeof t=="string"||t===null))return new zt(i);try{let t=new ui([new gt("c"),...i]);return ae(t,e),t.eval()}finally{Oe(e.n)}}var ye=class{constructor(i){this.ptr=i}type(){let i=T._TYPEOF(this.ptr);return Object.keys(mt).find(e=>mt[e]===i)}},_n,Zr,Wi=class extends ye{constructor(i){if(!(i instanceof ye))return kf(i);super(i.ptr),L(this,_n)}static wrap(i){let e=T._TYPEOF(i),t=Object.keys(mt)[Object.values(mt).indexOf(e)];return new(_f(t))(new ye(i))}get[Symbol.toStringTag](){return`RObject:${this.type()}`}static getPersistentObject(i){return xe[i]}getPropertyValue(i){return this[i]}inspect(){lf(".Internal(inspect(x))",{x:this})}isNull(){return T._TYPEOF(this.ptr)===mt.null}isNa(){try{let i=lf("is.na(x)",{x:this});return Yr(i),i.toBoolean()}finally{Oe(1)}}isUnbound(){return this.ptr===xe.unboundValue.ptr}attrs(){return ds.wrap(T._ATTRIB(this.ptr))}class(){let i={n:0},e=new ui([new gt("class"),this]);ae(e,i);try{return e.eval()}finally{Oe(i.n)}}setNames(i){let e;if(i===null)e=xe.null;else if(Array.isArray(i)&&i.every(t=>typeof t=="string"||t===null))e=new zt(i);else throw new Error("Argument to setNames must be null or an Array of strings or null");return T._Rf_setAttrib(this.ptr,xe.namesSymbol.ptr,e.ptr),this}names(){let i=zt.wrap(T._Rf_getAttrib(this.ptr,xe.namesSymbol.ptr));return i.isNull()?null:i.toArray()}includes(i){let e=this.names();return e&&e.includes(i)}toJs(i={depth:0},e=1){throw new Error("This R object cannot be converted to JS")}subset(i){return Je(this,_n,Zr).call(this,i,xe.bracketSymbol.ptr)}get(i){return Je(this,_n,Zr).call(this,i,xe.bracket2Symbol.ptr)}getDollar(i){return Je(this,_n,Zr).call(this,i,xe.dollarSymbol.ptr)}pluck(...i){let e=$O(xe.null);try{let t=(r,s)=>{let o=r.get(s);return LO(o,e)},n=i.reduce(t,this);return n.isNull()?void 0:n}finally{VO(e)}}set(i,e){let t={n:0};try{let n=new Wi(i);ae(n,t);let r=new Wi(e);ae(r,t);let s=new gt("[[<-"),o=T._Rf_lang4(s.ptr,this.ptr,n.ptr,r.ptr);return ae(o,t),Wi.wrap(us(o,xe.baseEnv))}finally{Oe(t.n)}}static getMethods(i){let e=new Set,t=i;do Object.getOwnPropertyNames(t).map(n=>e.add(n));while(t=Object.getPrototypeOf(t));return[...e.keys()].filter(n=>typeof i[n]=="function")}},z=Wi;_n=new WeakSet,Zr=function(i,e){let t={n:0};try{let n=new Wi(i);ae(n,t);let r=T._Rf_lang3(e,this.ptr,n.ptr);return ae(r,t),Wi.wrap(us(r,xe.baseEnv))}finally{Oe(t.n)}};var Sf=class extends z{constructor(){return super(new ye(T.getValue(T._R_NilValue,"*"))),this}toJs(){return{type:"null"}}},gt=class extends z{constructor(i){if(i instanceof ye){pi(i,"symbol"),super(i);return}let e=T.allocateUTF8(i);try{super(new ye(T._Rf_install(e)))}finally{T._free(e)}}toJs(){let i=this.toObject();return{type:"symbol",printname:i.printname,symvalue:i.symvalue,internal:i.internal}}toObject(){return{printname:this.printname().isUnbound()?null:this.printname().toString(),symvalue:this.symvalue().isUnbound()?null:this.symvalue().ptr,internal:this.internal().isNull()?null:this.internal().ptr}}toString(){return this.printname().toString()}printname(){return Ua.wrap(T._PRINTNAME(this.ptr))}symvalue(){return z.wrap(T._SYMVALUE(this.ptr))}internal(){return z.wrap(T._INTERNAL(this.ptr))}},ds=class extends z{constructor(i){if(i instanceof ye)return pi(i,"pairlist"),super(i),this;let e={n:0};try{let{names:t,values:n}=zi(i),r=ds.wrap(T._Rf_allocList(n.length));ae(r,e);for(let[s,o]=[0,r];!o.isNull();[s,o]=[s+1,o.cdr()])o.setcar(new z(n[s]));r.setNames(t),super(r)}finally{Oe(e.n)}}get length(){return this.toArray().length}toArray(i={depth:1}){return this.toJs(i).values}toObject({allowDuplicateKey:i=!0,allowEmptyKey:e=!1,depth:t=-1}={}){let n=this.entries({depth:t}),r=n.map(([s])=>s);if(!i&&new Set(r).size!==r.length)throw new Error("Duplicate key when converting pairlist without allowDuplicateKey enabled");if(!e&&r.some(s=>!s))throw new Error("Empty or null key when converting pairlist without allowEmptyKey enabled");return Object.fromEntries(n.filter((s,o)=>n.findIndex(a=>a[0]===s[0])===o))}entries(i={depth:1}){let e=this.toJs(i);return e.values.map((t,n)=>[e.names?e.names[n]:null,t])}toJs(i={depth:0},e=1){let t=[],n=!1,r=[];for(let s=this;!s.isNull();s=s.cdr()){let o=s.tag();o.isNull()?t.push(""):(n=!0,t.push(o.toString())),i.depth&&e>=i.depth?r.push(s.car()):r.push(s.car().toJs(i,e+1))}return{type:"pairlist",names:n?t:null,values:r}}includes(i){return i in this.toObject()}setcar(i){T._SETCAR(this.ptr,i.ptr)}car(){return z.wrap(T._CAR(this.ptr))}cdr(){return z.wrap(T._CDR(this.ptr))}tag(){return z.wrap(T._TAG(this.ptr))}},ui=class extends z{constructor(i){if(i instanceof ye)return pi(i,"call"),super(i),this;let e={n:0};try{let{values:t}=zi(i),n=t.map(s=>ae(new z(s),e)),r=ui.wrap(T._Rf_allocVector(mt.call,t.length));ae(r,e);for(let[s,o]=[0,r];!o.isNull();[s,o]=[s+1,o.cdr()])o.setcar(n[s]);super(r)}finally{Oe(e.n)}}setcar(i){T._SETCAR(this.ptr,i.ptr)}car(){return z.wrap(T._CAR(this.ptr))}cdr(){return z.wrap(T._CDR(this.ptr))}eval(){return T.webr.evalR(this,{env:xe.baseEnv})}capture(i={}){return T.webr.captureR(this,i)}deparse(){let i={n:0};try{let e=T._Rf_lang2(new gt("deparse1").ptr,T._Rf_lang2(new gt("quote").ptr,this.ptr));ae(e,i);let t=zt.wrap(us(e,xe.baseEnv));return ae(t,i),t.toString()}finally{Oe(i.n)}}},ya=class extends z{constructor(i,e=null){if(i instanceof ye){if(pi(i,"list"),super(i),e){if(e.length!==this.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");this.setNames(e)}return this}let t={n:0};try{let n=zi(i),r=T._Rf_allocVector(mt.list,n.values.length);ae(r,t),n.values.forEach((o,a)=>{T._SET_VECTOR_ELT(r,a,new z(o).ptr)});let s=e||n.names;if(s&&s.length!==n.values.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");z.wrap(r).setNames(s),super(new ye(r))}finally{Oe(t.n)}}get length(){return T._LENGTH(this.ptr)}isDataFrame(){let i=ds.wrap(T._ATTRIB(this.ptr)).get("class");return!i.isNull()&&i.toArray().includes("data.frame")}toArray(i={depth:1}){return this.toJs(i).values}toObject({allowDuplicateKey:i=!0,allowEmptyKey:e=!1,depth:t=-1}={}){let n=this.entries({depth:t}),r=n.map(([s])=>s);if(!i&&new Set(r).size!==r.length)throw new Error("Duplicate key when converting list without allowDuplicateKey enabled");if(!e&&r.some(s=>!s))throw new Error("Empty or null key when converting list without allowEmptyKey enabled");return Object.fromEntries(n.filter((s,o)=>n.findIndex(a=>a[0]===s[0])===o))}toD3(){if(!this.isDataFrame())throw new Error("Can't convert R list object to D3 format. Object must be of class 'data.frame'.");return this.entries().reduce((i,e)=>(e[1].forEach((t,n)=>i[n]=Object.assign(i[n]||{},{[e[0]]:t})),i),[])}entries(i={depth:-1}){let e=this.toJs(i);return this.isDataFrame()&&i.depth<0&&(e.values=e.values.map(t=>t.toArray())),e.values.map((t,n)=>[e.names?e.names[n]:null,t])}toJs(i={depth:0},e=1){return{type:"list",names:this.names(),values:[...Array(this.length).keys()].map(t=>i.depth&&e>=i.depth?this.get(t+1):this.get(t+1).toJs(i,e+1))}}},Xn=class extends ya{constructor(i){if(i instanceof ye){if(super(i),!this.isDataFrame())throw new Error("Can't construct `RDataFrame`. Supplied R object is not a `data.frame`.");return this}return Xn.fromObject(i)}static fromObject(i){let{names:e,values:t}=zi(i),n={n:0};try{let r=!!e&&e.length>0&&e.every(o=>o),s=t.length>0&&t.every(o=>Array.isArray(o)||ArrayBuffer.isView(o)||o instanceof ArrayBuffer);if(r&&s){let o=t,a=o.every(h=>h.length===o[0].length),l=o.every(h=>$f(h[0])||Df(h[0]));if(a&&l){let h=new ya({type:"list",names:e,values:o.map(f=>kf(f))});ae(h,n);let c=new ui([new gt("as.data.frame"),h]);return ae(c,n),new Xn(c.eval())}}}finally{Oe(n.n)}throw new Error("Can't construct `data.frame`. Source object is not eligible.")}static fromD3(i){return this.fromObject(Object.fromEntries(Object.keys(i[0]).map(e=>[e,i.map(t=>t[e])])))}},Gr=class extends z{exec(...i){let e={n:0};try{let t=new ui([this,...i]);return ae(t,e),t.eval()}finally{Oe(e.n)}}capture(i={},...e){let t={n:0};try{let n=new ui([this,...e]);return ae(n,t),n.capture(i)}finally{Oe(t.n)}}},Ua=class extends z{constructor(i){if(i instanceof ye){pi(i,"string"),super(i);return}let e=T.allocateUTF8(i);try{super(new ye(T._Rf_mkChar(e)))}finally{T._free(e)}}toString(){return T.UTF8ToString(T._R_CHAR(this.ptr))}toJs(){return{type:"string",value:this.toString()}}},Tf=class extends z{constructor(i={}){if(i instanceof ye)return pi(i,"environment"),super(i),this;let e=0;try{let{names:t,values:n}=zi(i),r=Yr(T._R_NewEnv(xe.globalEnv.ptr,0,0));++e,n.forEach((s,o)=>{let a=t?t[o]:null;if(!a)throw new Error("Can't create object in new environment with empty symbol name");let l=new gt(a),h=Yr(new z(s));try{af(r,l,h)}finally{Oe(1)}}),super(new ye(r))}finally{Oe(e)}}ls(i=!1,e=!0){return zt.wrap(T._R_lsInternal3(this.ptr,Number(i),Number(e))).toArray()}bind(i,e){let t=new gt(i),n=Yr(new z(e));try{af(this,t,n)}finally{Oe(1)}}names(){return this.ls(!0,!0)}frame(){return z.wrap(T._FRAME(this.ptr))}subset(i){if(typeof i=="number")throw new Error("Object of type environment is not subsettable");return this.getDollar(i)}toObject({depth:i=-1}={}){let e=this.names();return Object.fromEntries([...Array(e.length).keys()].map(t=>{let n=this.getDollar(e[t]);return[e[t],i<0?n:n.toJs({depth:i})]}))}toJs(i={depth:0},e=1){let t=this.names(),n=[...Array(t.length).keys()].map(r=>i.depth&&e>=i.depth?this.getDollar(t[r]):this.getDollar(t[r]).toJs(i,e+1));return{type:"environment",names:t,values:n}}},ji=class extends z{constructor(i,e,t){if(i instanceof ye)return pi(i,e),super(i),this;let n={n:0};try{let{names:r,values:s}=zi(i),o=T._Rf_allocVector(mt[e],s.length);ae(o,n),s.forEach(t(o)),z.wrap(o).setNames(r),super(new ye(o))}finally{Oe(n.n)}}get length(){return T._LENGTH(this.ptr)}get(i){return super.get(i)}subset(i){return super.subset(i)}getDollar(){throw new Error("$ operator is invalid for atomic vectors")}detectMissing(){let i={n:0};try{let e=T._Rf_lang2(new gt("is.na").ptr,this.ptr);ae(e,i);let t=Ni.wrap(us(e,xe.baseEnv));ae(t,i);let n=t.toTypedArray();return Array.from(n).map(r=>!!r)}finally{Oe(i.n)}}toArray(){let i=this.toTypedArray();return this.detectMissing().map((e,t)=>e?null:i[t])}toObject({allowDuplicateKey:i=!0,allowEmptyKey:e=!1}={}){let t=this.entries(),n=t.map(([r])=>r);if(!i&&new Set(n).size!==n.length)throw new Error("Duplicate key when converting atomic vector without allowDuplicateKey enabled");if(!e&&n.some(r=>!r))throw new Error("Empty or null key when converting atomic vector without allowEmptyKey enabled");return Object.fromEntries(t.filter((r,s)=>t.findIndex(o=>o[0]===r[0])===s))}entries(){let i=this.toArray(),e=this.names();return i.map((t,n)=>[e?e[n]:null,t])}toJs(){return{type:this.type(),names:this.names(),values:this.toArray()}}},ba,Pf=class extends ji{constructor(i){super(i,"logical",k(Pf,ba))}getBoolean(i){return this.get(i).toArray()[0]}toBoolean(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getBoolean(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS boolean");return i}toTypedArray(){return new Int32Array(T.HEAP32.subarray(T._LOGICAL(this.ptr)/4,T._LOGICAL(this.ptr)/4+this.length))}toArray(){let i=this.toTypedArray();return this.detectMissing().map((e,t)=>e?null:!!i[t])}},Ni=Pf;ba=new WeakMap,L(Ni,ba,i=>{let e=T._LOGICAL(i),t=T.getValue(T._R_NaInt,"i32");return(n,r)=>{T.setValue(e+4*r,n===null?t:!!n,"i32")}});var wa,Cf=class extends ji{constructor(i){super(i,"integer",k(Cf,wa))}getNumber(i){return this.get(i).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getNumber(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS number");return i}toTypedArray(){return new Int32Array(T.HEAP32.subarray(T._INTEGER(this.ptr)/4,T._INTEGER(this.ptr)/4+this.length))}},Rf=Cf;wa=new WeakMap,L(Rf,wa,i=>{let e=T._INTEGER(i),t=T.getValue(T._R_NaInt,"i32");return(n,r)=>{T.setValue(e+4*r,n===null?t:Math.round(Number(n)),"i32")}});var va,Ef=class extends ji{constructor(i){super(i,"double",k(Ef,va))}getNumber(i){return this.get(i).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getNumber(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS number");return i}toTypedArray(){return new Float64Array(T.HEAPF64.subarray(T._REAL(this.ptr)/8,T._REAL(this.ptr)/8+this.length))}},ps=Ef;va=new WeakMap,L(ps,va,i=>{let e=T._REAL(i),t=T.getValue(T._R_NaReal,"double");return(n,r)=>{T.setValue(e+8*r,n===null?t:n,"double")}});var xa,Af=class extends ji{constructor(i){super(i,"complex",k(Af,xa))}getComplex(i){return this.get(i).toArray()[0]}toComplex(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getComplex(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS object");return i}toTypedArray(){return new Float64Array(T.HEAPF64.subarray(T._COMPLEX(this.ptr)/8,T._COMPLEX(this.ptr)/8+2*this.length))}toArray(){let i=this.toTypedArray();return this.detectMissing().map((e,t)=>e?null:{re:i[2*t],im:i[2*t+1]})}},Fa=Af;xa=new WeakMap,L(Fa,xa,i=>{let e=T._COMPLEX(i),t=T.getValue(T._R_NaReal,"double");return(n,r)=>{T.setValue(e+8*(2*r),n===null?t:n.re,"double"),T.setValue(e+8*(2*r+1),n===null?t:n.im,"double")}});var ka,Qf=class extends ji{constructor(i){super(i,"character",k(Qf,ka))}getString(i){return this.get(i).toArray()[0]}toString(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getString(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS string");return i}toTypedArray(){return new Uint32Array(T.HEAPU32.subarray(T._STRING_PTR(this.ptr)/4,T._STRING_PTR(this.ptr)/4+this.length))}toArray(){return this.detectMissing().map((i,e)=>i?null:T.UTF8ToString(T._R_CHAR(T._STRING_ELT(this.ptr,e))))}},zt=Qf;ka=new WeakMap,L(zt,ka,i=>(e,t)=>{e===null?T._SET_STRING_ELT(i,t,xe.naString.ptr):T._SET_STRING_ELT(i,t,new Ua(e).ptr)});var Sa,Mf=class extends ji{constructor(i){i instanceof ArrayBuffer&&(i=new Uint8Array(i)),super(i,"raw",k(Mf,Sa))}getNumber(i){return this.get(i).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let i=this.getNumber(1);if(i===null)throw new Error("Can't convert missing value `NA` to a JS number");return i}toTypedArray(){return new Uint8Array(T.HEAPU8.subarray(T._RAW(this.ptr),T._RAW(this.ptr)+this.length))}},Ha=Mf;Sa=new WeakMap,L(Ha,Sa,i=>{let e=T._RAW(i);return(t,n)=>{T.setValue(e+n,Number(t),"i8")}});function zi(i){return vf(i)?i:Array.isArray(i)||ArrayBuffer.isView(i)?{names:null,values:i}:i&&typeof i=="object"&&!fs(i)?{names:Object.keys(i),values:Object.values(i)}:{names:null,values:[i]}}function _f(i){let e={object:z,null:Sf,symbol:gt,pairlist:ds,closure:Gr,environment:Tf,call:ui,special:Gr,builtin:Gr,string:Ua,logical:Ni,integer:Rf,double:ps,complex:Fa,character:zt,list:ya,raw:Ha,function:Gr,dataframe:Xn};return i in e?e[i]:z}function rs(i){return i instanceof z}function Df(i){let e=["logical","integer","double","complex","character"];return rs(i)&&e.includes(i.type())||rs(i)&&i.isNa()}function $f(i){return i===null||typeof i=="number"||typeof i=="boolean"||typeof i=="string"||fs(i)}var xe;function ms(){let i={resolve:()=>{},reject:()=>{},promise:Promise.resolve()},e=new Promise((t,n)=>{i.resolve=t,i.reject=n});return i.promise=e,i}function NO(i){return new Promise(e=>setTimeout(e,i))}function Ut(i,e,t,...n){return i==null||jO(i)?i:i instanceof ArrayBuffer?new Uint8Array(i):e(i)?t(i,...n):Array.isArray(i)||ArrayBuffer.isView(i)?i.map(r=>Ut(r,e,t,...n)):i instanceof ye?i:typeof i=="object"?Object.fromEntries(Object.entries(i).map(([r,s])=>[r,Ut(s,e,t,...n)])):i}function Ga(i,e){let t=new XMLHttpRequest;t.open("get",i,!0),t.onload=()=>{let n=new Worker(URL.createObjectURL(new Blob([t.responseText])));e(n)},t.send()}function Ya(i){if(Ie)return!1;let e=new URL(location.href),t=new URL(i,location.origin);return!(e.host===t.host&&e.port===t.port&&e.protocol===t.protocol)}function jO(i){return typeof ImageBitmap<"u"&&i instanceof ImageBitmap}var zO=Xi(za()),UO=new TextEncoder;async function FO(i,e,t){try{let{taskId:n,sizeBuffer:r,dataBuffer:s,signalBuffer:o}=e,a=(0,zO.encode)(t),l=a.length<=s.length;if(Atomics.store(r,0,a.length),Atomics.store(r,1,+l),!l){let[h,c]=HO(i);s.set(UO.encode(h)),await hf(o,n),s=(await c).dataBuffer}s.set(a),Atomics.store(r,1,1),await hf(o,n)}catch(n){console.warn(n)}}function HO(i){let e=xf();return[e,new Promise(t=>{Ie?i.once("message",n=>{!n.id||n.id!==e||t(n)}):i.addEventListener("message",function n(r){!r.data||!r.data.id||r.data.id!==e||(i.removeEventListener("message",n),t(r.data))}),i.start&&i.start()})]}async function hf(i,e){let t=(e>>1)%32,n=1;for(;Atomics.compareExchange(i,t+1,0,e)!==0;)await NO(n),n<32&&(n*=2);Atomics.or(i,0,1<{k(this,At).push(i)}))};function GO(i,e){return Vf({type:"request",data:{uuid:xf(),msg:i}},e)}function Pa(i,e,t){return Vf({type:"response",data:{uuid:i,resp:e}},t)}function Vf(i,e){return e&&BO(i,e),i}function YO(i){let e=new wf(i.obj.message);return i.obj.name!=="Error"&&(e.name=i.obj.name),e.stack=i.obj.stack,e}function ZO(i){return!!i&&typeof i=="object"&&"payloadType"in i&&"obj"in i}function Lf(i){return ZO(i)&&i.payloadType==="ptr"}var Dn,Za=class{constructor(){this.inputQueue=new Oa,this.outputQueue=new Oa,this.systemQueue=new Oa,L(this,Dn,new Map)}async read(){return await this.outputQueue.get()}async flush(){let i=[];for(;!this.outputQueue.isEmpty();)i.push(await this.read());return i}async readSystem(){return await this.systemQueue.get()}write(i){this.inputQueue.put(i)}async request(i,e){let t=GO(i,e),{resolve:n,reject:r,promise:s}=ms();return k(this,Dn).set(t.data.uuid,{resolve:n,reject:r}),this.write(t),s}putClosedMessage(){this.outputQueue.put({type:"closed"})}resolveResponse(i){let e=i.data.uuid,t=k(this,Dn).get(e);if(t){let n=i.data.resp;k(this,Dn).delete(e),n.payloadType==="err"?t.reject(YO(n)):t.resolve(n)}else console.warn("Can't find request.")}};Dn=new WeakMap;var cS=Xi(za()),fS=new TextDecoder("utf-8"),JO,KO,e0,t0,i0;JO=new WeakMap,KO=new WeakMap,e0=new WeakMap,t0=new WeakMap,i0=new WeakMap;var uS=new Int32Array(new ArrayBuffer(4));Ie&&(globalThis.Worker=Bi("worker_threads").Worker);var $n,Ca,qf,Kr,cf=class extends Za{constructor(i){super(),L(this,Ca),L(this,$n,void 0),this.close=()=>{},L(this,Kr,async(t,n)=>{if(!(!n||!n.type))switch(n.type){case"resolve":me(this,$n,new Int32Array(n.data)),this.resolve();return;case"response":this.resolveResponse(n);return;case"system":this.systemQueue.put(n.data);return;default:this.outputQueue.put(n);return;case"sync-request":{let r=n,s=r.data.msg,o=r.data.reqData;switch(s.type){case"read":{let a=await this.inputQueue.get();await FO(t,o,a);break}default:throw new pt(`Unsupported request type '${s.type}'.`)}return}case"request":throw new pt("Can't send messages of type 'request' from a worker. Please Use 'sync-request' instead.")}});let e=t=>{Je(this,Ca,qf).call(this,t),this.close=()=>{t.terminate(),this.putClosedMessage()};let n={type:"init",data:{config:i,channelType:Qt.SharedArrayBuffer}};t.postMessage(n)};if(Ya(i.baseUrl))Ga(`${i.baseUrl}webr-worker.js`,t=>e(t));else{let t=new Worker(`${i.baseUrl}webr-worker.js`);e(t)}({resolve:this.resolve,promise:this.initialised}=ms())}interrupt(){if(!k(this,$n))throw new pt("Failed attempt to interrupt before initialising interruptBuffer");this.inputQueue.reset(),k(this,$n)[0]=1}};$n=new WeakMap,Ca=new WeakSet,qf=function(i){Ie?i.on("message",e=>{k(this,Kr).call(this,i,e)}):i.onmessage=e=>k(this,Kr).call(this,i,e.data)},Kr=new WeakMap;var n0,r0,s0,o0;n0=new WeakMap,r0=new WeakMap,s0=new WeakMap,o0=new WeakMap;var dS=Xi(za());Ie&&(globalThis.Worker=Bi("worker_threads").Worker);var Ln,Ii,qn,Ra,Bf,Ea,ff,Aa,Xf,es,a0=class extends Za{constructor(i){super(),L(this,Ra),L(this,Ea),L(this,Aa),this.close=()=>{},L(this,Ln,new Map),L(this,Ii,void 0),L(this,qn,!1),L(this,es,(t,n)=>{if(!(!n||!n.type))switch(n.type){case"resolve":this.resolve();return;case"response":this.resolveResponse(n);return;case"system":this.systemQueue.put(n.data);return;default:this.outputQueue.put(n);return;case"sync-request":{let r=n.data;k(this,Ln).set(r.data.uuid,r.data.msg);return}case"request":throw new pt("Can't send messages of type 'request' from a worker.Use service worker fetch request instead.")}}),console.warn("The ServiceWorker communication channel is deprecated and will be removed in a future version of webR. Consider using the PostMessage channel instead. If blocking input is required (for example, `browser()`) the SharedArrayBuffer channel should be used. See https://docs.r-wasm.org/webr/latest/serving.html for further information.");let e=t=>{Je(this,Aa,Xf).call(this,t),this.close=()=>{t.terminate(),this.putClosedMessage()},Je(this,Ra,Bf).call(this,`${i.serviceWorkerUrl}webr-serviceworker.js`).then(n=>{let r={type:"init",data:{config:i,channelType:Qt.ServiceWorker,clientId:n,location:window.location.href}};t.postMessage(r)})};if(Ya(i.serviceWorkerUrl))Ga(`${i.serviceWorkerUrl}webr-worker.js`,t=>e(t));else{let t=new Worker(`${i.serviceWorkerUrl}webr-worker.js`);e(t)}({resolve:this.resolve,promise:this.initialised}=ms())}activeRegistration(){var i;if(!((i=k(this,Ii))!=null&&i.active))throw new pt("Attempted to obtain a non-existent active registration.");return k(this,Ii).active}interrupt(){me(this,qn,!0)}};Ln=new WeakMap,Ii=new WeakMap,qn=new WeakMap,Ra=new WeakSet,Bf=async function(i){me(this,Ii,await navigator.serviceWorker.register(i)),await navigator.serviceWorker.ready,window.addEventListener("beforeunload",()=>{var t;(t=k(this,Ii))==null||t.unregister()});let e=await new Promise(t=>{navigator.serviceWorker.addEventListener("message",function n(r){r.data.type==="registration-successful"&&(navigator.serviceWorker.removeEventListener("message",n),t(r.data.clientId))}),this.activeRegistration().postMessage({type:"register-client-main"})});return navigator.serviceWorker.addEventListener("message",t=>{Je(this,Ea,ff).call(this,t)}),e},Ea=new WeakSet,ff=async function(i){if(i.data.type==="request"){let e=i.data.data,t=k(this,Ln).get(e);if(!t)throw new pt("Request not found during service worker XHR request");switch(k(this,Ln).delete(e),t.type){case"read":{let n=await this.inputQueue.get();this.activeRegistration().postMessage({type:"wasm-webr-fetch-response",uuid:e,response:Pa(e,n)});break}case"interrupt":{let n=k(this,qn);this.activeRegistration().postMessage({type:"wasm-webr-fetch-response",uuid:e,response:Pa(e,n)}),this.inputQueue.reset(),me(this,qn,!1);break}default:throw new pt(`Unsupported request type '${t.type}'.`)}return}},Aa=new WeakSet,Xf=function(i){Ie?i.on("message",e=>{k(this,es).call(this,i,e)}):i.onmessage=e=>k(this,es).call(this,i,e.data)},es=new WeakMap;var l0,h0,c0,f0,u0,d0;l0=new WeakMap,h0=new WeakMap,c0=new WeakMap,f0=new WeakMap,u0=new WeakMap,d0=new WeakMap;Ie&&(globalThis.Worker=Bi("worker_threads").Worker);var Vn,Qa,Wf,ts,uf=class extends Za{constructor(i){super(),L(this,Qa),this.close=()=>{},L(this,Vn,void 0),L(this,ts,async(t,n)=>{if(!(!n||!n.type))switch(n.type){case"resolve":this.resolve();return;case"response":this.resolveResponse(n);return;case"system":this.systemQueue.put(n.data);return;default:this.outputQueue.put(n);return;case"request":{let r=n,s=r.data.msg;switch(s.type){case"read":{let o=await this.inputQueue.get();if(k(this,Vn)){let a=Pa(r.data.uuid,o);k(this,Vn).postMessage(a)}break}default:throw new pt(`Unsupported request type '${s.type}'.`)}return}case"sync-request":throw new pt("Can't send messages of type 'sync-request' in PostMessage mode. Use 'request' instead.")}});let e=t=>{me(this,Vn,t),Je(this,Qa,Wf).call(this,t),this.close=()=>t.terminate();let n={type:"init",data:{config:i,channelType:Qt.PostMessage}};t.postMessage(n)};if(Ya(i.baseUrl))Ga(`${i.baseUrl}webr-worker.js`,t=>e(t));else{let t=new Worker(`${i.baseUrl}webr-worker.js`);e(t)}({resolve:this.resolve,promise:this.initialised}=ms())}interrupt(){console.error("Interrupting R execution is not available when using the PostMessage channel")}};Vn=new WeakMap,Qa=new WeakSet,Wf=function(i){Ie?i.on("message",e=>{k(this,ts).call(this,i,e)}):i.onmessage=e=>k(this,ts).call(this,i,e.data)},ts=new WeakMap;var p0,m0,g0,O0,y0;p0=new WeakMap,m0=new WeakMap,g0=new WeakMap,O0=new WeakMap,y0=new WeakMap;var Qt={Automatic:0,SharedArrayBuffer:1,ServiceWorker:2,PostMessage:3};function b0(i){switch(i.channelType){case Qt.SharedArrayBuffer:return new cf(i);case Qt.ServiceWorker:return new a0(i);case Qt.PostMessage:return new uf(i);case Qt.Automatic:default:return typeof SharedArrayBuffer<"u"?new cf(i):new uf(i)}}var w0=Ie?__dirname+"/":"https://webr.r-wasm.org/v0.4.0/",v0="https://repo.r-wasm.org",If="0.4.0";function ee(i){return!!i&&(typeof i=="object"||typeof i=="function")&&"payloadType"in i&&Lf(i._payload)}function Re(i){return ee(i)&&i._payload.obj.type==="null"}function x0(i){return ee(i)&&i._payload.obj.type==="symbol"}function k0(i){return ee(i)&&i._payload.obj.type==="pairlist"}function S0(i){return ee(i)&&i._payload.obj.type==="environment"}function T0(i){return ee(i)&&i._payload.obj.type==="logical"}function P0(i){return ee(i)&&i._payload.obj.type==="integer"}function C0(i){return ee(i)&&i._payload.obj.type==="double"}function R0(i){return ee(i)&&i._payload.obj.type==="complex"}function Ui(i){return ee(i)&&i._payload.obj.type==="character"}function ot(i){return ee(i)&&i._payload.obj.type==="list"}function Ja(i){return ee(i)&&i._payload.obj.type==="raw"}function gs(i){return ee(i)&&i._payload.obj.type==="call"}function Os(i){var e;return!!(ee(i)&&(e=i._payload.obj.methods)!=null&&e.includes("exec"))}function E0(){}function A0(i,e){return async function*(){let t={type:"callRObjectMethod",data:{payload:e._payload,prop:"getPropertyValue",args:[{payloadType:"raw",obj:"length"}],shelter:void 0}},n=await i.request(t);if(typeof n.obj!="number")throw new di("Cannot iterate over object, unexpected type for length property.");for(let r=1;r<=n.obj;r++)yield e.get(r)}}function Nf(i,e,t){return async(...n)=>{let r=n.map(a=>ee(a)?a._payload:{obj:Ut(a,ee,l=>l._payload),payloadType:"raw"}),s={type:"callRObjectMethod",data:{payload:t,prop:e,args:r}},o=await i.request(s);switch(o.payloadType){case"ptr":return fi(i,o);case"raw":return Ut(o,Lf,(a,l)=>fi(l,a),i).obj}}}async function Q0(i,e,t,...n){let r={type:"newRObject",data:{objType:e,args:Ut(n,ee,o=>o._payload),shelter:t}},s=await i.request(r);switch(s.payloadType){case"raw":throw new Bn("Unexpected raw payload type returned from newRObject");case"ptr":return fi(i,s)}}function fi(i,e){var t;let n=new Proxy((t=e.obj.methods)!=null&&t.includes("exec")?Object.assign(E0,{...e}):e,{get:(r,s)=>{var o;if(s==="_payload")return e;if(s===Symbol.asyncIterator)return A0(i,n);if((o=e.obj.methods)!=null&&o.includes(s.toString()))return Nf(i,s.toString(),e)},apply:async(r,s,o)=>{let a=await fi(i,e).exec(...o);return Os(a)?a:a.toJs()}});return n}function Ve(i,e,t){return new Proxy(z,{construct:(n,r)=>Q0(i,t,e,...r),get:(n,r)=>Nf(i,r.toString())})}var ss,os,as,ls,hs,Ma,_a,Da,$a,Va,La,jf,M0=class{constructor(i={},e={REnv:{R_HOME:"/usr/lib/R",FONTCONFIG_PATH:"/etc/fonts",R_ENABLE_JIT:"0"}}){L(this,La),L(this,ss,void 0),L(this,os,void 0),L(this,as,void 0),L(this,ls,void 0),L(this,hs,void 0),L(this,Ma,t=>{console.log(t)}),L(this,_a,t=>{console.error(t)}),L(this,Da,t=>{let n=prompt(t);n&&this.stdin(`${n}
+`)}),L(this,$a,t=>{if(Ie)throw new Error("Plotting with HTML canvas is not yet supported under Node");this.canvas.getContext("2d").drawImage(t,0,0)}),L(this,Va,()=>{if(Ie)throw new Error("Plotting with HTML canvas is not yet supported under Node");this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height)}),this.webR=new Uf(e),Ie||(this.canvas=document.createElement("canvas"),this.canvas.setAttribute("width","1008"),this.canvas.setAttribute("height","1008")),me(this,ss,i.stdout||k(this,Ma)),me(this,os,i.stderr||k(this,_a)),me(this,as,i.prompt||k(this,Da)),me(this,ls,i.canvasImage||k(this,$a)),me(this,hs,i.canvasNewPage||k(this,Va)),this.webR.evalRVoid("options(device=webr::canvas)")}stdin(i){this.webR.writeConsole(i)}interrupt(){this.webR.interrupt()}run(){Je(this,La,jf).call(this)}};ss=new WeakMap,os=new WeakMap,as=new WeakMap,ls=new WeakMap,hs=new WeakMap,Ma=new WeakMap,_a=new WeakMap,Da=new WeakMap,$a=new WeakMap,Va=new WeakMap,La=new WeakSet,jf=async function(){for(;;){let i=await this.webR.read();switch(i.type){case"stdout":k(this,ss).call(this,i.data);break;case"stderr":k(this,os).call(this,i.data);break;case"prompt":k(this,as).call(this,i.data);break;case"canvas":i.data.event==="canvasImage"?k(this,ls).call(this,i.data.image):i.data.event==="canvasNewPage"&&k(this,hs).call(this);break;case"closed":return;default:console.warn(`Unhandled output type for webR Console: ${i.type}.`)}}};var _0={FONTCONFIG_PATH:"/etc/fonts",R_HOME:"/usr/lib/R",R_ENABLE_JIT:"0",WEBR:"1",WEBR_VERSION:If},df={RArgs:[],REnv:_0,baseUrl:w0,serviceWorkerUrl:"",repoUrl:v0,homedir:"/home/web_user",interactive:!0,channelType:Qt.Automatic,createLazyFilesystem:!0},ne,is,qa,zf,Uf=class{constructor(i={}){L(this,qa),L(this,ne,void 0),L(this,is,void 0),this.version=If,this.FS={lookupPath:async t=>{let n={type:"lookupPath",data:{path:t}};return(await k(this,ne).request(n)).obj},mkdir:async t=>{let n={type:"mkdir",data:{path:t}};return(await k(this,ne).request(n)).obj},mount:async(t,n,r)=>{let s={type:"mount",data:{type:t,options:n,mountpoint:r}};await k(this,ne).request(s)},syncfs:async t=>{let n={type:"syncfs",data:{populate:t}};await k(this,ne).request(n)},readFile:async(t,n)=>{let r={type:"readFile",data:{path:t,flags:n}};return(await k(this,ne).request(r)).obj},rmdir:async t=>{let n={type:"rmdir",data:{path:t}};await k(this,ne).request(n)},writeFile:async(t,n,r)=>{let s={type:"writeFile",data:{path:t,data:n,flags:r}};await k(this,ne).request(s)},unlink:async t=>{let n={type:"unlink",data:{path:t}};await k(this,ne).request(n)},unmount:async t=>{let n={type:"unmount",data:{path:t}};await k(this,ne).request(n)}};let e={...df,...i,REnv:{...df.REnv,...i.REnv}};me(this,ne,b0(e)),this.objs={},this.Shelter=D0(k(this,ne)),me(this,is,k(this,ne).initialised.then(async()=>{this.globalShelter=await new this.Shelter,this.RObject=this.globalShelter.RObject,this.RLogical=this.globalShelter.RLogical,this.RInteger=this.globalShelter.RInteger,this.RDouble=this.globalShelter.RDouble,this.RComplex=this.globalShelter.RComplex,this.RCharacter=this.globalShelter.RCharacter,this.RRaw=this.globalShelter.RRaw,this.RList=this.globalShelter.RList,this.RDataFrame=this.globalShelter.RDataFrame,this.RPairlist=this.globalShelter.RPairlist,this.REnvironment=this.globalShelter.REnvironment,this.RSymbol=this.globalShelter.RSymbol,this.RString=this.globalShelter.RString,this.RCall=this.globalShelter.RCall,this.objs={baseEnv:await this.RObject.getPersistentObject("baseEnv"),globalEnv:await this.RObject.getPersistentObject("globalEnv"),null:await this.RObject.getPersistentObject("null"),true:await this.RObject.getPersistentObject("true"),false:await this.RObject.getPersistentObject("false"),na:await this.RObject.getPersistentObject("na")},Je(this,qa,zf).call(this)}))}async init(){return k(this,is)}close(){k(this,ne).close()}async read(){return await k(this,ne).read()}async flush(){return await k(this,ne).flush()}write(i){k(this,ne).write(i)}writeConsole(i){this.write({type:"stdin",data:i+`
+`})}interrupt(){k(this,ne).interrupt()}async installPackages(i,e){let t=Object.assign({quiet:!1,mount:!0},e),n={type:"installPackages",data:{name:i,options:t}};await k(this,ne).request(n)}async destroy(i){await this.globalShelter.destroy(i)}async evalR(i,e){return this.globalShelter.evalR(i,e)}async evalRVoid(i,e){return this.evalRRaw(i,"void",e)}async evalRBoolean(i,e){return this.evalRRaw(i,"boolean",e)}async evalRNumber(i,e){return this.evalRRaw(i,"number",e)}async evalRString(i,e){return this.evalRRaw(i,"string",e)}async evalRRaw(i,e,t={}){let n=Ut(t,ee,o=>o._payload),r={type:"evalRRaw",data:{code:i,options:n,outputType:e}},s=await k(this,ne).request(r);switch(s.payloadType){case"raw":return s.obj;case"ptr":throw new Bn("Unexpected ptr payload type returned from evalRVoid")}}async invokeWasmFunction(i,...e){let t={type:"invokeWasmFunction",data:{ptr:i,args:e}};return(await k(this,ne).request(t)).obj}};ne=new WeakMap,is=new WeakMap,qa=new WeakSet,zf=async function(){for(;;){let i=await k(this,ne).readSystem();switch(i.type){case"setTimeoutWasm":setTimeout((e,t)=>{this.invokeWasmFunction(e,...t)},i.data.delay,i.data.ptr,i.data.args);break;case"console.log":console.log(i.data);break;case"console.warn":console.warn(i.data);break;case"console.error":console.error(i.data);break;default:throw new di("Unknown system message type `"+i.type+"`")}}};var se,Z,ns,Ba=class{constructor(i){L(this,se,""),L(this,Z,void 0),L(this,ns,!1),me(this,Z,i)}async init(){if(k(this,ns))return;let i={type:"newShelter"},e=await k(this,Z).request(i);me(this,se,e.obj),this.RObject=Ve(k(this,Z),k(this,se),"object"),this.RLogical=Ve(k(this,Z),k(this,se),"logical"),this.RInteger=Ve(k(this,Z),k(this,se),"integer"),this.RDouble=Ve(k(this,Z),k(this,se),"double"),this.RComplex=Ve(k(this,Z),k(this,se),"complex"),this.RCharacter=Ve(k(this,Z),k(this,se),"character"),this.RRaw=Ve(k(this,Z),k(this,se),"raw"),this.RList=Ve(k(this,Z),k(this,se),"list"),this.RDataFrame=Ve(k(this,Z),k(this,se),"dataframe"),this.RPairlist=Ve(k(this,Z),k(this,se),"pairlist"),this.REnvironment=Ve(k(this,Z),k(this,se),"environment"),this.RSymbol=Ve(k(this,Z),k(this,se),"symbol"),this.RString=Ve(k(this,Z),k(this,se),"string"),this.RCall=Ve(k(this,Z),k(this,se),"call"),me(this,ns,!0)}async purge(){let i={type:"shelterPurge",data:k(this,se)};await k(this,Z).request(i)}async destroy(i){let e={type:"shelterDestroy",data:{id:k(this,se),obj:i._payload}};await k(this,Z).request(e)}async size(){let i={type:"shelterSize",data:k(this,se)};return(await k(this,Z).request(i)).obj}async evalR(i,e={}){let t=Ut(e,ee,s=>s._payload),n={type:"evalR",data:{code:i,options:t,shelter:k(this,se)}},r=await k(this,Z).request(n);switch(r.payloadType){case"raw":throw new Bn("Unexpected payload type returned from evalR");default:return fi(k(this,Z),r)}}async captureR(i,e={}){let t=Ut(e,ee,s=>s._payload),n={type:"captureR",data:{code:i,options:t,shelter:k(this,se)}},r=await k(this,Z).request(n);switch(r.payloadType){case"ptr":throw new Bn("Unexpected payload type returned from evalR");case"raw":{let s=r.obj,o=fi(k(this,Z),s.result),a=s.output,l=s.images;for(let h=0;h{let e=new Ba(i);return await e.init(),e}})}var Hf=Symbol("Comlink.proxy"),il=Symbol("Comlink.endpoint"),$0=Symbol("Comlink.releaseProxy"),el=Symbol("Comlink.finalizer"),bs=Symbol("Comlink.thrown"),Gf=i=>typeof i=="object"&&i!==null||typeof i=="function",V0={canHandle:i=>Gf(i)&&i[Hf],serialize(i){let{port1:e,port2:t}=new MessageChannel;return ks(i,e),[t,[t]]},deserialize(i){return i.start(),Wn(i)}},L0={canHandle:i=>Gf(i)&&bs in i,serialize({value:i}){let e;return i instanceof Error?e={isError:!0,value:{message:i.message,name:i.name,stack:i.stack}}:e={isError:!1,value:i},[e,[]]},deserialize(i){throw i.isError?Object.assign(new Error(i.value.message),i.value):i.value}},gi=new Map([["proxy",V0],["throw",L0]]);function q0(i,e){for(let t of i)if(e===t||t==="*"||t instanceof RegExp&&t.test(e))return!0;return!1}function ks(i,e=globalThis,t=["*"]){e.addEventListener("message",function n(r){if(!r||!r.data)return;if(!q0(t,r.origin)){console.warn(`Invalid origin '${r.origin}' for comlink proxy`);return}let{id:s,type:o,path:a}=Object.assign({path:[]},r.data),l=(r.data.argumentList||[]).map(mi),h;try{let c=a.slice(0,-1).reduce((u,d)=>u[d],i),f=a.reduce((u,d)=>u[d],i);switch(o){case"GET":h=f;break;case"SET":c[a.slice(-1)[0]]=mi(r.data.value),h=!0;break;case"APPLY":h=f.apply(c,l);break;case"CONSTRUCT":{let u=new f(...l);h=j0(u)}break;case"ENDPOINT":{let{port1:u,port2:d}=new MessageChannel;ks(i,d),h=N0(u,[u])}break;case"RELEASE":h=void 0;break;default:return}}catch(c){h={value:c,[bs]:0}}Promise.resolve(h).catch(c=>({value:c,[bs]:0})).then(c=>{let[f,u]=xs(c);e.postMessage(Object.assign(Object.assign({},f),{id:s}),u),o==="RELEASE"&&(e.removeEventListener("message",n),Yf(e),el in i&&typeof i[el]=="function"&&i[el]())}).catch(c=>{let[f,u]=xs({value:new TypeError("Unserializable return value"),[bs]:0});e.postMessage(Object.assign(Object.assign({},f),{id:s}),u)})}),e.start&&e.start()}function B0(i){return i.constructor.name==="MessagePort"}function Yf(i){B0(i)&&i.close()}function Wn(i,e){return tl(i,[],e)}function ys(i){if(i)throw new Error("Proxy has been released and is not useable")}function Zf(i){return Fi(i,{type:"RELEASE"}).then(()=>{Yf(i)})}var ws=new WeakMap,vs="FinalizationRegistry"in globalThis&&new FinalizationRegistry(i=>{let e=(ws.get(i)||0)-1;ws.set(i,e),e===0&&Zf(i)});function X0(i,e){let t=(ws.get(e)||0)+1;ws.set(e,t),vs&&vs.register(i,e,i)}function W0(i){vs&&vs.unregister(i)}function tl(i,e=[],t=function(){}){let n=!1,r=new Proxy(t,{get(s,o){if(ys(n),o===$0)return()=>{W0(r),Zf(i),n=!0};if(o==="then"){if(e.length===0)return{then:()=>r};let a=Fi(i,{type:"GET",path:e.map(l=>l.toString())}).then(mi);return a.then.bind(a)}return tl(i,[...e,o])},set(s,o,a){ys(n);let[l,h]=xs(a);return Fi(i,{type:"SET",path:[...e,o].map(c=>c.toString()),value:l},h).then(mi)},apply(s,o,a){ys(n);let l=e[e.length-1];if(l===il)return Fi(i,{type:"ENDPOINT"}).then(mi);if(l==="bind")return tl(i,e.slice(0,-1));let[h,c]=Ff(a);return Fi(i,{type:"APPLY",path:e.map(f=>f.toString()),argumentList:h},c).then(mi)},construct(s,o){ys(n);let[a,l]=Ff(o);return Fi(i,{type:"CONSTRUCT",path:e.map(h=>h.toString()),argumentList:a},l).then(mi)}});return X0(r,i),r}function I0(i){return Array.prototype.concat.apply([],i)}function Ff(i){let e=i.map(xs);return[e.map(t=>t[0]),I0(e.map(t=>t[1]))]}var Jf=new WeakMap;function N0(i,e){return Jf.set(i,e),i}function j0(i){return Object.assign(i,{[Hf]:!0})}function xs(i){for(let[e,t]of gi)if(t.canHandle(i)){let[n,r]=t.serialize(i);return[{type:"HANDLER",name:e,value:n},r]}return[{type:"RAW",value:i},Jf.get(i)||[]]}function mi(i){switch(i.type){case"HANDLER":return gi.get(i.name).deserialize(i.value);case"RAW":return i.value}}function Fi(i,e,t){return new Promise(n=>{let r=z0();i.addEventListener("message",function s(o){!o.data||!o.data.id||o.data.id!==r||(i.removeEventListener("message",s),n(o.data))}),i.start&&i.start(),i.postMessage(Object.assign({id:r},e),t)})}function z0(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var Hi=[],Ke=class{constructor(e){this.isRunning=!1;this.isDestroyed=!1;Hi.push(this),e?this.callbacks=e:this.callbacks={busyCallback:()=>{},idleCallback:()=>{},runningCallback:()=>{},finishedCallback:()=>{}}}running(){this.isRunning=!0,Hi.forEach(e=>e.callbacks.busyCallback()),this.callbacks.runningCallback()}finished(){this.isRunning=!1,this.callbacks.finishedCallback(),this.status().busy||Hi.forEach(e=>e.callbacks.idleCallback())}status(){let e=this.isRunning,t=this.isDestroyed,n=Hi.some(r=>r.isRunning);return{running:e,busy:n,destroyed:t}}destroy(){this.isDestroyed=!0;let e=Hi.indexOf(this);Hi.splice(e,1)}};var W=class i{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,n){[e,t]=en(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Yi.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=en(this,e,t);let n=[];return this.decompose(e,t,n,0),Yi.from(n,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),n=this.length-this.scanIdentical(e,-1),r=new bi(this),s=new bi(e);for(let o=t,a=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new bi(this,e)}iterRange(e,t=this.length){return new Cs(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Rs(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?i.empty:e.length<=32?new Ne(e):Yi.from(Ne.split(e,[]))}},Ne=class i extends W{constructor(e,t=U0(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.text[s],a=r+o.length;if((t?n:a)>=e)return new rl(r,a,n,o);r=a+1,n++}}decompose(e,t,n,r){let s=e<=0&&t>=this.length?this:new i(eu(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){let o=n.pop(),a=Ps(s.text,o.text.slice(),0,s.length);if(a.length<=32)n.push(new i(a,o.length+s.length));else{let l=a.length>>1;n.push(new i(a.slice(0,l)),new i(a.slice(l)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof i))return super.replace(e,t,n);[e,t]=en(this,e,t);let r=Ps(this.text,Ps(n.text,eu(this.text,0,e)),t),s=this.length+n.length-(t-e);return r.length<=32?new i(r,s):Yi.from(i.split(r,[]),s)}sliceString(e,t=this.length,n=`
`){[e,t]=en(this,e,t);let r="";for(let s=0,o=0;s<=t&&oe&&o&&(r+=n),es&&(r+=a.slice(Math.max(0,e-s),t-s)),s=l+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],r=-1;for(let s of e)n.push(s),r+=s.length+1,n.length==32&&(t.push(new i(n,r)),n=[],r=-1);return r>-1&&t.push(new i(n,r)),t}},Yi=class i extends W{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let n of e)this.lines+=n.lines}lineInner(e,t,n,r){for(let s=0;;s++){let o=this.children[s],a=r+o.length,l=n+o.lines-1;if((t?l:a)>=e)return o.lineInner(e,t,n,r);r=a+1,n=l+1}}decompose(e,t,n,r){for(let s=0,o=0;o<=t&&s=o){let h=r&((o<=e?1:0)|(l>=t?2:0));o>=e&&l<=t&&!h?n.push(a):a.decompose(e-o,t-o,n,h)}o=l+1}}replace(e,t,n){if([e,t]=en(this,e,t),n.lines=s&&t<=a){let l=o.replace(e-s,t-s,n),h=this.lines-o.lines+l.lines;if(l.lines>4&&l.lines>h>>6){let c=this.children.slice();return c[r]=l,new i(c,this.length-(t-e)+n.length)}return super.replace(s,a,l)}s=a+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n=`
-`){[e,t]=en(this,e,t);let r="";for(let s=0,o=0;se&&s&&(r+=n),eo&&(r+=a.sliceString(e-o,t-o,n)),o=l+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof i))return 0;let n=0,[r,s,o,a]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;r+=t,s+=t){if(r==o||s==a)return n;let l=this.children[r],h=e.children[s];if(l!=h)return n+l.scanIdentical(h,t);n+=l.length+1}}static from(e,t=e.reduce((n,r)=>n+r.length+1,-1)){let n=0;for(let d of e)n+=d.lines;if(n<32){let d=[];for(let m of e)m.flatten(d);return new Ne(d,t)}let r=Math.max(32,n>>5),s=r<<1,o=r>>1,a=[],l=0,h=-1,c=[];function f(d){let m;if(d.lines>s&&d instanceof i)for(let p of d.children)f(p);else d.lines>o&&(l>o||!l)?(u(),a.push(d)):d instanceof Ne&&l&&(m=c[c.length-1])instanceof Ne&&d.lines+m.lines<=32?(l+=d.lines,h+=d.length+1,c[c.length-1]=new Ne(m.text.concat(d.text),m.length+1+d.length)):(l+d.lines>r&&u(),l+=d.lines,h+=d.length+1,c.push(d))}function u(){l!=0&&(a.push(c.length==1?c[0]:i.from(c,h)),h=-1,l=c.length=0)}for(let d of e)f(d);return u(),a.length==1?a[0]:new i(a,t)}};W.empty=new Ne([""],0);function U0(i){let e=-1;for(let t of i)e+=t.length+1;return e}function Ts(i,e,t=0,n=1e9){for(let r=0,s=0,o=!0;s=t&&(l>n&&(a=a.slice(0,n-r)),r0?1:(e instanceof Ne?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],s=this.offsets[n],o=s>>1,a=r instanceof Ne?r.text.length:r.children.length;if(o==(t>0?a:0)){if(n==0)return this.done=!0,this.value="",this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
-`,this;e--}else if(r instanceof Ne){let l=r.text[o+(t<0?-1:0)];if(this.offsets[n]+=t,l.length>Math.max(0,e))return this.value=e==0?l:t>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=r.children[o+(t<0?-1:0)];e>l.length?(e-=l.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(l),this.offsets.push(t>0?1:(l instanceof Ne?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Ps=class{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new bi(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}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 n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),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!=""}},Cs=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(W.prototype[Symbol.iterator]=function(){return this.iter()},bi.prototype[Symbol.iterator]=Ps.prototype[Symbol.iterator]=Cs.prototype[Symbol.iterator]=function(){return this});var rl=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function en(i,e,t){return e=Math.max(0,Math.min(i.length,e)),[e,Math.max(e,Math.min(i.length,t))]}var Zi="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(i=>i?parseInt(i,36):1);for(let i=1;ii)return Zi[e-1]<=i;return!1}function tu(i){return i>=127462&&i<=127487}var iu=8205;function ue(i,e,t=!0,n=!0){return(t?lu:H0)(i,e,n)}function lu(i,e,t){if(e==i.length)return e;e&&hu(i.charCodeAt(e))&&cu(i.charCodeAt(e-1))&&e--;let n=ce(i,e);for(e+=Ee(n);e=0&&tu(ce(i,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function H0(i,e,t){for(;e>0;){let n=lu(i,e-2,t);if(n=56320&&i<57344}function cu(i){return i>=55296&&i<56320}function ce(i,e){let t=i.charCodeAt(e);if(!cu(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return hu(n)?(t-55296<<10)+(n-56320)+65536:t}function Fn(i){return i<=65535?String.fromCharCode(i):(i-=65536,String.fromCharCode((i>>10)+55296,(i&1023)+56320))}function Ee(i){return i<65536?1:2}var sl=/\r\n?|\n/,ge=function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i}(ge||(ge={})),_t=class i{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;te)return s+(e-r);s+=a}else{if(n!=ge.Simple&&h>=e&&(n==ge.TrackDel&&re||n==ge.TrackBefore&&re))return null;if(h>e||h==e&&t<0&&!a)return e==r||t<0?s:s+l;s+=l}r=h}if(e>r)throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);return s}touchesRange(e,t=e){for(let n=0,r=0;n=0&&r<=t&&a>=e)return rt?"cover":!0;r=a}return!1}toString(){let e="";for(let t=0;t=0?":"+r:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new i(e)}static create(e){return new i(e)}},Ae=class i extends _t{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 ol(this,(t,n,r,s,o)=>e=e.replace(r,r+(n-t),o),!1),e}mapDesc(e,t=!1){return al(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let r=0,s=0;r=0){t[r]=a,t[r+1]=o;let l=r>>1;for(;n.length0&&Ft(n,t,s.text),s.forward(c),a+=c}let h=e[o++];for(;a>1].toJSON()))}return e}static of(e,t,n){let r=[],s=[],o=0,a=null;function l(c=!1){if(!c&&!r.length)return;ou||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let m=d?typeof d=="string"?W.of(d.split(n||sl)):d:W.empty,p=m.length;if(f==u&&p==0)return;fo&&Se(r,f-o,-1),Se(r,u-f,p),Ft(s,r,m),o=u}}return h(e),l(!a),a}static empty(e){return new i(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let r=0;ra&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;n.length=0&&t<=0&&t==i[r+1]?i[r]+=e:e==0&&i[r]==0?i[r+1]+=t:n?(i[r]+=e,i[r+1]+=t):i.push(e,t)}function Ft(i,e,t){if(t.length==0)return;let n=e.length-2>>1;if(n>1])),!(t||o==i.sections.length||i.sections[o+1]<0);)a=i.sections[o++],l=i.sections[o++];e(r,h,s,c,f),r=h,s=c}}}function al(i,e,t,n=!1){let r=[],s=n?[]:null,o=new wi(i),a=new wi(e);for(let l=-1;;)if(o.ins==-1&&a.ins==-1){let h=Math.min(o.len,a.len);Se(r,h,-1),o.forward(h),a.forward(h)}else if(a.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(a.len=0&&l=0){let h=0,c=o.len;for(;c;)if(a.ins==-1){let f=Math.min(c,a.len);h+=f,c-=f,a.forward(f)}else if(a.ins==0&&a.lenl||o.ins>=0&&o.len>l)&&(a||n.length>h),s.forward2(l),o.forward(l)}}}}var wi=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i>1;return t>=e.length?W.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?W.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},Gi=class i{constructor(e,t,n){this.from=e,this.to=t,this.flags=n}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let n,r;return this.empty?n=r=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),r=e.mapPos(this.to,-1)),n==this.from&&r==this.to?this:new i(n,r,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return S.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return S.range(this.anchor,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return S.range(e.anchor,e.head)}static create(e,t,n){return new i(e,t,n)}},S=class i{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:i.create(this.ranges.map(n=>n.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;ne.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new i(e.ranges.map(t=>Gi.fromJSON(t)),e.main)}static single(e,t=e){return new i([i.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,r=0;re?8:0)|s)}static normalized(e,t=0){let n=e[t];e.sort((r,s)=>r.from-s.from),t=e.indexOf(n);for(let r=1;rs.head?i.range(l,a):i.range(a,l))}}return new i(e,t)}};function uu(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var Ol=0,A=class i{constructor(e,t,n,r,s){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=Ol++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new i(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:yl),!!e.static,e.enables)}of(e){return new Ji([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}};function yl(i,e){return i==e||i.length==e.length&&i.every((t,n)=>t===e[n])}var Ji=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=Ol++}dynamicSlot(e){var t;let n=this.value,r=this.facet.compareInput,s=this.id,o=e[s]>>1,a=this.type==2,l=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?l=!0:f=="selection"?h=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||c.push(e[f.id]);return{create(f){return f.values[o]=n(f),1},update(f,u){if(l&&u.docChanged||h&&(u.docChanged||u.selection)||ll(f,c)){let d=n(f);if(a?!nu(d,f.values[o],r):!r(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,m=u.config.address[s];if(m!=null){let p=As(u,m);if(this.dependencies.every(g=>g instanceof A?u.facet(g)===f.facet(g):g instanceof te?u.field(g,!1)==f.field(g,!1):!0)||(a?nu(d=n(f),p,r):r(d=n(f),p)))return f.values[o]=p,0}else d=n(f);return f.values[o]=d,1}}}};function nu(i,e,t){if(i.length!=e.length)return!1;for(let n=0;ni[l.id]),r=t.map(l=>l.type),s=n.filter(l=>!(l&1)),o=i[e.id]>>1;function a(l){let h=[];for(let c=0;cn===r),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(ru).find(n=>n.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:n=>(n.values[t]=this.create(n),1),update:(n,r)=>{let s=n.values[t],o=this.updateF(s,r);return this.compareF(s,o)?0:(n.values[t]=o,1)},reconfigure:(n,r)=>r.config.address[this.id]!=null?(n.values[t]=r.field(this),0):(n.values[t]=this.create(n),1)}}init(e){return[this,ru.of({field:this,create:e})]}get extension(){return this}},Oi={lowest:4,low:3,default:2,high:1,highest:0};function In(i){return e=>new Rs(e,i)}var Qe={highest:In(Oi.highest),high:In(Oi.high),default:In(Oi.default),low:In(Oi.low),lowest:In(Oi.lowest)},Rs=class{constructor(e,t){this.inner=e,this.prec=t}},Dt=class i{of(e){return new jn(this,e)}reconfigure(e){return i.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},jn=class{constructor(e,t){this.compartment=e,this.inner=t}},Es=class i{constructor(e,t,n,r,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(e,t,n){let r=[],s=Object.create(null),o=new Map;for(let u of Y0(e,t,o))u instanceof te?r.push(u):(s[u.facet.id]||(s[u.facet.id]=[])).push(u);let a=Object.create(null),l=[],h=[];for(let u of r)a[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=n?.config.facets;for(let u in s){let d=s[u],m=d[0].facet,p=c&&c[u]||[];if(d.every(g=>g.type==0))if(a[m.id]=l.length<<1|1,yl(p,d))l.push(n.facet(m));else{let g=m.combine(d.map(O=>O.value));l.push(n&&m.compare(g,n.facet(m))?n.facet(m):g)}else{for(let g of d)g.type==0?(a[g.id]=l.length<<1|1,l.push(g.value)):(a[g.id]=h.length<<1,h.push(O=>g.dynamicSlot(O)));a[m.id]=h.length<<1,h.push(g=>G0(g,m,d))}}let f=h.map(u=>u(a));return new i(e,o,f,a,l,s)}};function Y0(i,e,t){let n=[[],[],[],[],[]],r=new Map;function s(o,a){let l=r.get(o);if(l!=null){if(l<=a)return;let h=n[l].indexOf(o);h>-1&&n[l].splice(h,1),o instanceof jn&&t.delete(o.compartment)}if(r.set(o,a),Array.isArray(o))for(let h of o)s(h,a);else if(o instanceof jn){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),s(h,a)}else if(o instanceof Rs)s(o.inner,o.prec);else if(o instanceof te)n[a].push(o),o.provides&&s(o.provides,a);else if(o instanceof Ji)n[a].push(o),o.facet.extensions&&s(o.facet.extensions,Oi.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,a)}}return s(i,Oi.default),n.reduce((o,a)=>o.concat(a))}function Nn(i,e){if(e&1)return 2;let t=e>>1,n=i.status[t];if(n==4)throw new Error("Cyclic dependency between fields and/or facets");if(n&2)return n;i.status[t]=4;let r=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|r}function As(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}var du=A.define(),hl=A.define({combine:i=>i.some(e=>e),static:!0}),pu=A.define({combine:i=>i.length?i[0]:void 0,static:!0}),mu=A.define(),gu=A.define(),Ou=A.define(),yu=A.define({combine:i=>i.length?i[0]:!1}),Le=class{constructor(e,t){this.type=e,this.value=t}static define(){return new cl}},cl=class{of(e){return new Le(this,e)}},fl=class{constructor(e){this.map=e}of(e){return new _(this,e)}},_=class i{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new i(this.type,t)}is(e){return this.type==e}static define(e={}){return new fl(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let s=r.map(t);s&&n.push(s)}return n}};_.reconfigure=_.define();_.appendConfig=_.define();var fe=class i{constructor(e,t,n,r,s,o){this.startState=e,this.changes=t,this.selection=n,this.effects=r,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,n&&uu(n,t.newLength),s.some(a=>a.type==i.time)||(this.annotations=s.concat(i.time.of(Date.now())))}static create(e,t,n,r,s,o){return new i(e,t,n,r,s,o)}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(i.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};fe.time=Le.define();fe.userEvent=Le.define();fe.addToHistory=Le.define();fe.remote=Le.define();function Z0(i,e){let t=[];for(let n=0,r=0;;){let s,o;if(n=i[n]))s=i[n++],o=i[n++];else if(r=0;r--){let s=n[r](i);s instanceof fe?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof fe?i=s[0]:i=wu(e,Ki(s),!1)}return i}function K0(i){let e=i.startState,t=e.facet(Ou),n=i;for(let r=t.length-1;r>=0;r--){let s=t[r](i);s&&Object.keys(s).length&&(n=bu(n,ul(e,s,i.changes.newLength),!0))}return n==i?i:fe.create(e,i.changes,i.selection,n.effects,n.annotations,n.scrollIntoView)}var ey=[];function Ki(i){return i==null?ey:Array.isArray(i)?i:[i]}var F=function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i}(F||(F={})),ty=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,dl;try{dl=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function iy(i){if(dl)return dl.test(i);for(let e=0;e"\x80"&&(t.toUpperCase()!=t.toLowerCase()||ty.test(t)))return!0}return!1}function ny(i){return e=>{if(!/\S/.test(e))return F.Space;if(iy(e))return F.Word;for(let t=0;t-1)return F.Word;return F.Other}}var N=class i{constructor(e,t,n,r,s,o){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let a=0;ar.set(h,l)),t=null),r.set(a.value.compartment,a.value.extension)):a.is(_.reconfigure)?(t=null,n=a.value):a.is(_.appendConfig)&&(t=null,n=Ki(n).concat(a.value));let s;t?s=e.startState.values.slice():(t=Es.resolve(n,r,this),s=new i(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,h)=>h.reconfigure(l,this),null).values);let o=e.startState.facet(hl)?e.newSelection:e.newSelection.asSingle();new i(t,e.newDoc,o,s,(a,l)=>l.update(a,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:S.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),s=[n.range],o=Ki(n.effects);for(let a=1;ao.spec.fromJSON(a,l)))}}return i.create({doc:e.doc,selection:S.fromJSON(e.selection),extensions:t.extensions?r.concat([t.extensions]):r})}static create(e={}){let t=Es.resolve(e.extensions||[],new Map),n=e.doc instanceof W?e.doc:W.of((e.doc||"").split(t.staticFacet(i.lineSeparator)||sl)),r=e.selection?e.selection instanceof S?e.selection:S.single(e.selection.anchor,e.selection.head):S.single(0);return uu(r,n.length),t.staticFacet(hl)||(r=r.asSingle()),new i(t,n,r,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(i.tabSize)}get lineBreak(){return this.facet(i.lineSeparator)||`
-`}get readOnly(){return this.facet(yu)}phrase(e,...t){for(let n of this.facet(i.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,r)=>{if(r=="$")return"$";let s=+(r||1);return!s||s>t.length?n:t[s-1]})),e}languageDataAt(e,t,n=-1){let r=[];for(let s of this.facet(du))for(let o of s(this,t,n))Object.prototype.hasOwnProperty.call(o,e)&&r.push(o[e]);return r}charCategorizer(e){return ny(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-n,a=e-n;for(;o>0;){let l=ue(t,o,!1);if(s(t.slice(l,o))!=F.Word)break;o=l}for(;ai.length?i[0]:4});N.lineSeparator=pu;N.readOnly=yu;N.phrases=A.define({compare(i,e){let t=Object.keys(i),n=Object.keys(e);return t.length==n.length&&t.every(r=>i[r]==e[r])}});N.languageData=du;N.changeFilter=mu;N.transactionFilter=gu;N.transactionExtender=Ou;Dt.reconfigure=_.define();function Te(i,e,t={}){let n={};for(let r of i)for(let s of Object.keys(r)){let o=r[s],a=n[s];if(a===void 0)n[s]=o;else if(!(a===o||o===void 0))if(Object.hasOwnProperty.call(t,s))n[s]=t[s](a,o);else throw new Error("Config merge conflict for field "+s)}for(let r in e)n[r]===void 0&&(n[r]=e[r]);return n}var at=class{eq(e){return this==e}range(e,t=e){return zn.create(e,t,this)}};at.prototype.startSide=at.prototype.endSide=0;at.prototype.point=!1;at.prototype.mapMode=ge.TrackDel;var zn=class i{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new i(e,t,n)}};function pl(i,e){return i.from-e.from||i.value.startSide-e.value.startSide}var ml=class i{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return this.to[this.to.length-1]}findIndex(e,t,n,r=0){let s=n?this.to:this.from;for(let o=r,a=s.length;;){if(o==a)return o;let l=o+a>>1,h=s[l]-e||(n?this.value[l].endSide:this.value[l].startSide)-t;if(l==o)return h>=0?o:a;h>=0?a=l:o=l+1}}between(e,t,n,r){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(n,1e9,!1,s);sd||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(a=Math.max(a,d-u)),n.push(h),r.push(u-o),s.push(d-o))}return{mapped:n.length?new i(r,s,n,a):null,pos:o}}},j=class i{constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(e,t,n,r){return new i(e,t,n,r)}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:n=!1,filterFrom:r=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(n&&(t=t.slice().sort(pl)),this.isEmpty)return t.length?i.of(t):this;let a=new Qs(this,null,-1).goto(0),l=0,h=[],c=new lt;for(;a.value||l=0){let f=t[l++];c.addInner(f.from,f.to,f.value)||h.push(f)}else a.rangeIndex==1&&a.chunkIndexthis.chunkEnd(a.chunkIndex)||sa.to||s=s&&e<=s+o.length&&o.between(s,e-s,t-s,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return Un.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Un.from(e).goto(t)}static compare(e,t,n,r,s=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),a=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),l=su(o,a,n),h=new yi(o,l,s),c=new yi(a,l,s);n.iterGaps((f,u,d)=>ou(h,f,c,u,d,r)),n.empty&&n.length==0&&ou(h,0,c,0,0,r)}static eq(e,t,n=0,r){r==null&&(r=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let a=su(s,o),l=new yi(s,a,0).goto(n),h=new yi(o,a,0).goto(n);for(;;){if(l.to!=h.to||!gl(l.active,h.active)||l.point&&(!h.point||!l.point.eq(h.point)))return!1;if(l.to>r)return!0;l.next(),h.next()}}static spans(e,t,n,r,s=-1){let o=new yi(e,null,s).goto(t),a=t,l=o.openStart;for(;;){let h=Math.min(o.to,n);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFroma&&(r.span(a,h,o.active,l),l=o.openEnd(h));if(o.to>n)return l+(o.point&&o.to>n?1:0);a=o.to,o.next()}}static of(e,t=!1){let n=new lt;for(let r of e instanceof zn?[e]:t?ry(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(e){if(!e.length)return i.empty;let t=e[e.length-1];for(let n=e.length-2;n>=0;n--)for(let r=e[n];r!=i.empty;r=r.nextLayer)t=new i(r.chunkPos,r.chunk,t,Math.max(r.maxPoint,t.maxPoint));return t}};j.empty=new j([],[],null,-1);function ry(i){if(i.length>1)for(let e=i[0],t=1;t0)return i.slice().sort(pl);e=n}return i}j.empty.nextLayer=j.empty;var lt=class i{finishChunk(e){this.chunks.push(new ml(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,n){this.addInner(e,t,n)||(this.nextLayer||(this.nextLayer=new i)).add(e,t,n)}addInner(e,t,n){let r=e-this.lastTo||n.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.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 n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(j.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=j.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function su(i,e,t){let n=new Map;for(let s of i)for(let o=0;o=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=n&&r.push(new Qs(o,t,n,s));return r.length==1?r[0]:new i(r)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let n=this.heap.length>>1;n>=0;n--)nl(this.heap,n);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let n=this.heap.length>>1;n>=0;n--)nl(this.heap,n);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)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(),nl(this.heap,0)}}};function nl(i,e){for(let t=i[e];;){let n=(e<<1)+1;if(n>=i.length)break;let r=i[n];if(n+1=0&&(r=i[n+1],n++),t.compare(r)<0)break;i[n]=t,i[e]=r,e=n}}var yi=class{constructor(e,t,n){this.minPoint=n,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=Un.from(e,t,n)}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){ks(this.active,e),ks(this.activeTo,e),ks(this.activeRank,e),this.minActive=au(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:s}=this.cursor;for(;t0;)t++;Ss(this.active,t,n),Ss(this.activeTo,t,r),Ss(this.activeRank,t,s),e&&Ss(e,t,this.cursor.from),this.minActive=au(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&ks(n,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from=0&&n[r]=0&&!(this.activeRank[n]e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}};function ou(i,e,t,n,r,s){i.goto(e),t.goto(n);let o=n+r,a=n,l=n-e;for(;;){let h=i.to+l-t.to||i.endSide-t.endSide,c=h<0?i.to+l:t.to,f=Math.min(c,o);if(i.point||t.point?i.point&&t.point&&(i.point==t.point||i.point.eq(t.point))&&gl(i.activeForPoint(i.to),t.activeForPoint(t.to))||s.comparePoint(a,f,i.point,t.point):f>a&&!gl(i.active,t.active)&&s.compareRange(a,f,i.active,t.active),c>o)break;a=c,h<=0&&i.next(),h>=0&&t.next()}}function gl(i,e){if(i.length!=e.length)return!1;for(let t=0;t=e;n--)i[n+1]=i[n];i[e]=t}function au(i,e){let t=-1,n=1e9;for(let r=0;r=e)return r;if(r==i.length)break;s+=i.charCodeAt(r)==9?t-s%t:1,r=ue(i,r)}return n===!0?-1:i.length}var bl="\u037C",vu=typeof Symbol>"u"?"__"+bl:Symbol.for(bl),wl=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),xu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},et=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,a,l,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&a==null)return l.push(o[0]+";");for(let d in a){let m=a[d];if(/&/.test(d))s(d.split(/,\s*/).map(p=>o.map(g=>p.replace(/&/,g))).reduce((p,g)=>p.concat(g)),m,l);else if(m&&typeof m=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");s(r(d),m,c,u)}else m!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,p=>"-"+p.toLowerCase())+": "+m+";")}(c.length||u)&&l.push((n&&!f&&!h?o.map(n):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(r(o),e[o],this.rules)}getRules(){return this.rules.join(`
+`){[e,t]=en(this,e,t);let r="";for(let s=0,o=0;se&&s&&(r+=n),eo&&(r+=a.sliceString(e-o,t-o,n)),o=l+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof i))return 0;let n=0,[r,s,o,a]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;r+=t,s+=t){if(r==o||s==a)return n;let l=this.children[r],h=e.children[s];if(l!=h)return n+l.scanIdentical(h,t);n+=l.length+1}}static from(e,t=e.reduce((n,r)=>n+r.length+1,-1)){let n=0;for(let d of e)n+=d.lines;if(n<32){let d=[];for(let m of e)m.flatten(d);return new Ne(d,t)}let r=Math.max(32,n>>5),s=r<<1,o=r>>1,a=[],l=0,h=-1,c=[];function f(d){let m;if(d.lines>s&&d instanceof i)for(let p of d.children)f(p);else d.lines>o&&(l>o||!l)?(u(),a.push(d)):d instanceof Ne&&l&&(m=c[c.length-1])instanceof Ne&&d.lines+m.lines<=32?(l+=d.lines,h+=d.length+1,c[c.length-1]=new Ne(m.text.concat(d.text),m.length+1+d.length)):(l+d.lines>r&&u(),l+=d.lines,h+=d.length+1,c.push(d))}function u(){l!=0&&(a.push(c.length==1?c[0]:i.from(c,h)),h=-1,l=c.length=0)}for(let d of e)f(d);return u(),a.length==1?a[0]:new i(a,t)}};W.empty=new Ne([""],0);function U0(i){let e=-1;for(let t of i)e+=t.length+1;return e}function Ps(i,e,t=0,n=1e9){for(let r=0,s=0,o=!0;s=t&&(l>n&&(a=a.slice(0,n-r)),r0?1:(e instanceof Ne?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],s=this.offsets[n],o=s>>1,a=r instanceof Ne?r.text.length:r.children.length;if(o==(t>0?a:0)){if(n==0)return this.done=!0,this.value="",this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
+`,this;e--}else if(r instanceof Ne){let l=r.text[o+(t<0?-1:0)];if(this.offsets[n]+=t,l.length>Math.max(0,e))return this.value=e==0?l:t>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=r.children[o+(t<0?-1:0)];e>l.length?(e-=l.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(l),this.offsets.push(t>0?1:(l instanceof Ne?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Cs=class{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new bi(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}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 n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),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!=""}},Rs=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(W.prototype[Symbol.iterator]=function(){return this.iter()},bi.prototype[Symbol.iterator]=Cs.prototype[Symbol.iterator]=Rs.prototype[Symbol.iterator]=function(){return this});var rl=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function en(i,e,t){return e=Math.max(0,Math.min(i.length,e)),[e,Math.max(e,Math.min(i.length,t))]}var Zi="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,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31,7,240,5,gx7k,2o,3k,6o".split(",").map(i=>i?parseInt(i,36):1);for(let i=1;ii)return Zi[e-1]<=i;return!1}function tu(i){return i>=127462&&i<=127487}var iu=8205;function ue(i,e,t=!0,n=!0){return(t?lu:H0)(i,e,n)}function lu(i,e,t){if(e==i.length)return e;e&&hu(i.charCodeAt(e))&&cu(i.charCodeAt(e-1))&&e--;let n=ce(i,e);for(e+=Ee(n);e=0&&tu(ce(i,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function H0(i,e,t){for(;e>0;){let n=lu(i,e-2,t);if(n=56320&&i<57344}function cu(i){return i>=55296&&i<56320}function ce(i,e){let t=i.charCodeAt(e);if(!cu(t)||e+1==i.length)return t;let n=i.charCodeAt(e+1);return hu(n)?(t-55296<<10)+(n-56320)+65536:t}function Fn(i){return i<=65535?String.fromCharCode(i):(i-=65536,String.fromCharCode((i>>10)+55296,(i&1023)+56320))}function Ee(i){return i<65536?1:2}var sl=/\r\n?|\n/,ge=function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i}(ge||(ge={})),_t=class i{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;te)return s+(e-r);s+=a}else{if(n!=ge.Simple&&h>=e&&(n==ge.TrackDel&&re||n==ge.TrackBefore&&re))return null;if(h>e||h==e&&t<0&&!a)return e==r||t<0?s:s+l;s+=l}r=h}if(e>r)throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);return s}touchesRange(e,t=e){for(let n=0,r=0;n=0&&r<=t&&a>=e)return rt?"cover":!0;r=a}return!1}toString(){let e="";for(let t=0;t=0?":"+r:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new i(e)}static create(e){return new i(e)}},Ae=class i extends _t{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 ol(this,(t,n,r,s,o)=>e=e.replace(r,r+(n-t),o),!1),e}mapDesc(e,t=!1){return al(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let r=0,s=0;r=0){t[r]=a,t[r+1]=o;let l=r>>1;for(;n.length0&&Ft(n,t,s.text),s.forward(c),a+=c}let h=e[o++];for(;a>1].toJSON()))}return e}static of(e,t,n){let r=[],s=[],o=0,a=null;function l(c=!1){if(!c&&!r.length)return;ou||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let m=d?typeof d=="string"?W.of(d.split(n||sl)):d:W.empty,p=m.length;if(f==u&&p==0)return;fo&&Se(r,f-o,-1),Se(r,u-f,p),Ft(s,r,m),o=u}}return h(e),l(!a),a}static empty(e){return new i(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let r=0;ra&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;n.length=0&&t<=0&&t==i[r+1]?i[r]+=e:e==0&&i[r]==0?i[r+1]+=t:n?(i[r]+=e,i[r+1]+=t):i.push(e,t)}function Ft(i,e,t){if(t.length==0)return;let n=e.length-2>>1;if(n>1])),!(t||o==i.sections.length||i.sections[o+1]<0);)a=i.sections[o++],l=i.sections[o++];e(r,h,s,c,f),r=h,s=c}}}function al(i,e,t,n=!1){let r=[],s=n?[]:null,o=new wi(i),a=new wi(e);for(let l=-1;;)if(o.ins==-1&&a.ins==-1){let h=Math.min(o.len,a.len);Se(r,h,-1),o.forward(h),a.forward(h)}else if(a.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(a.len=0&&l=0){let h=0,c=o.len;for(;c;)if(a.ins==-1){let f=Math.min(c,a.len);h+=f,c-=f,a.forward(f)}else if(a.ins==0&&a.lenl||o.ins>=0&&o.len>l)&&(a||n.length>h),s.forward2(l),o.forward(l)}}}}var wi=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i>1;return t>=e.length?W.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?W.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},Gi=class i{constructor(e,t,n){this.from=e,this.to=t,this.flags=n}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let n,r;return this.empty?n=r=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),r=e.mapPos(this.to,-1)),n==this.from&&r==this.to?this:new i(n,r,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return S.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return S.range(this.anchor,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return S.range(e.anchor,e.head)}static create(e,t,n){return new i(e,t,n)}},S=class i{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:i.create(this.ranges.map(n=>n.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;ne.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new i(e.ranges.map(t=>Gi.fromJSON(t)),e.main)}static single(e,t=e){return new i([i.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,r=0;re?8:0)|s)}static normalized(e,t=0){let n=e[t];e.sort((r,s)=>r.from-s.from),t=e.indexOf(n);for(let r=1;rs.head?i.range(l,a):i.range(a,l))}}return new i(e,t)}};function uu(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var Ol=0,A=class i{constructor(e,t,n,r,s){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=Ol++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new i(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:yl),!!e.static,e.enables)}of(e){return new Ji([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}};function yl(i,e){return i==e||i.length==e.length&&i.every((t,n)=>t===e[n])}var Ji=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=Ol++}dynamicSlot(e){var t;let n=this.value,r=this.facet.compareInput,s=this.id,o=e[s]>>1,a=this.type==2,l=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?l=!0:f=="selection"?h=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||c.push(e[f.id]);return{create(f){return f.values[o]=n(f),1},update(f,u){if(l&&u.docChanged||h&&(u.docChanged||u.selection)||ll(f,c)){let d=n(f);if(a?!nu(d,f.values[o],r):!r(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,m=u.config.address[s];if(m!=null){let p=Qs(u,m);if(this.dependencies.every(g=>g instanceof A?u.facet(g)===f.facet(g):g instanceof te?u.field(g,!1)==f.field(g,!1):!0)||(a?nu(d=n(f),p,r):r(d=n(f),p)))return f.values[o]=p,0}else d=n(f);return f.values[o]=d,1}}}};function nu(i,e,t){if(i.length!=e.length)return!1;for(let n=0;ni[l.id]),r=t.map(l=>l.type),s=n.filter(l=>!(l&1)),o=i[e.id]>>1;function a(l){let h=[];for(let c=0;cn===r),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(ru).find(n=>n.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:n=>(n.values[t]=this.create(n),1),update:(n,r)=>{let s=n.values[t],o=this.updateF(s,r);return this.compareF(s,o)?0:(n.values[t]=o,1)},reconfigure:(n,r)=>r.config.address[this.id]!=null?(n.values[t]=r.field(this),0):(n.values[t]=this.create(n),1)}}init(e){return[this,ru.of({field:this,create:e})]}get extension(){return this}},Oi={lowest:4,low:3,default:2,high:1,highest:0};function In(i){return e=>new Es(e,i)}var Qe={highest:In(Oi.highest),high:In(Oi.high),default:In(Oi.default),low:In(Oi.low),lowest:In(Oi.lowest)},Es=class{constructor(e,t){this.inner=e,this.prec=t}},Dt=class i{of(e){return new jn(this,e)}reconfigure(e){return i.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},jn=class{constructor(e,t){this.compartment=e,this.inner=t}},As=class i{constructor(e,t,n,r,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(e,t,n){let r=[],s=Object.create(null),o=new Map;for(let u of Y0(e,t,o))u instanceof te?r.push(u):(s[u.facet.id]||(s[u.facet.id]=[])).push(u);let a=Object.create(null),l=[],h=[];for(let u of r)a[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=n?.config.facets;for(let u in s){let d=s[u],m=d[0].facet,p=c&&c[u]||[];if(d.every(g=>g.type==0))if(a[m.id]=l.length<<1|1,yl(p,d))l.push(n.facet(m));else{let g=m.combine(d.map(O=>O.value));l.push(n&&m.compare(g,n.facet(m))?n.facet(m):g)}else{for(let g of d)g.type==0?(a[g.id]=l.length<<1|1,l.push(g.value)):(a[g.id]=h.length<<1,h.push(O=>g.dynamicSlot(O)));a[m.id]=h.length<<1,h.push(g=>G0(g,m,d))}}let f=h.map(u=>u(a));return new i(e,o,f,a,l,s)}};function Y0(i,e,t){let n=[[],[],[],[],[]],r=new Map;function s(o,a){let l=r.get(o);if(l!=null){if(l<=a)return;let h=n[l].indexOf(o);h>-1&&n[l].splice(h,1),o instanceof jn&&t.delete(o.compartment)}if(r.set(o,a),Array.isArray(o))for(let h of o)s(h,a);else if(o instanceof jn){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),s(h,a)}else if(o instanceof Es)s(o.inner,o.prec);else if(o instanceof te)n[a].push(o),o.provides&&s(o.provides,a);else if(o instanceof Ji)n[a].push(o),o.facet.extensions&&s(o.facet.extensions,Oi.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,a)}}return s(i,Oi.default),n.reduce((o,a)=>o.concat(a))}function Nn(i,e){if(e&1)return 2;let t=e>>1,n=i.status[t];if(n==4)throw new Error("Cyclic dependency between fields and/or facets");if(n&2)return n;i.status[t]=4;let r=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|r}function Qs(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}var du=A.define(),hl=A.define({combine:i=>i.some(e=>e),static:!0}),pu=A.define({combine:i=>i.length?i[0]:void 0,static:!0}),mu=A.define(),gu=A.define(),Ou=A.define(),yu=A.define({combine:i=>i.length?i[0]:!1}),Le=class{constructor(e,t){this.type=e,this.value=t}static define(){return new cl}},cl=class{of(e){return new Le(this,e)}},fl=class{constructor(e){this.map=e}of(e){return new _(this,e)}},_=class i{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new i(this.type,t)}is(e){return this.type==e}static define(e={}){return new fl(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let s=r.map(t);s&&n.push(s)}return n}};_.reconfigure=_.define();_.appendConfig=_.define();var fe=class i{constructor(e,t,n,r,s,o){this.startState=e,this.changes=t,this.selection=n,this.effects=r,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,n&&uu(n,t.newLength),s.some(a=>a.type==i.time)||(this.annotations=s.concat(i.time.of(Date.now())))}static create(e,t,n,r,s,o){return new i(e,t,n,r,s,o)}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(i.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};fe.time=Le.define();fe.userEvent=Le.define();fe.addToHistory=Le.define();fe.remote=Le.define();function Z0(i,e){let t=[];for(let n=0,r=0;;){let s,o;if(n=i[n]))s=i[n++],o=i[n++];else if(r=0;r--){let s=n[r](i);s instanceof fe?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof fe?i=s[0]:i=wu(e,Ki(s),!1)}return i}function K0(i){let e=i.startState,t=e.facet(Ou),n=i;for(let r=t.length-1;r>=0;r--){let s=t[r](i);s&&Object.keys(s).length&&(n=bu(n,ul(e,s,i.changes.newLength),!0))}return n==i?i:fe.create(e,i.changes,i.selection,n.effects,n.annotations,n.scrollIntoView)}var ey=[];function Ki(i){return i==null?ey:Array.isArray(i)?i:[i]}var F=function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i}(F||(F={})),ty=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,dl;try{dl=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function iy(i){if(dl)return dl.test(i);for(let e=0;e"\x80"&&(t.toUpperCase()!=t.toLowerCase()||ty.test(t)))return!0}return!1}function ny(i){return e=>{if(!/\S/.test(e))return F.Space;if(iy(e))return F.Word;for(let t=0;t-1)return F.Word;return F.Other}}var N=class i{constructor(e,t,n,r,s,o){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let a=0;ar.set(h,l)),t=null),r.set(a.value.compartment,a.value.extension)):a.is(_.reconfigure)?(t=null,n=a.value):a.is(_.appendConfig)&&(t=null,n=Ki(n).concat(a.value));let s;t?s=e.startState.values.slice():(t=As.resolve(n,r,this),s=new i(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,h)=>h.reconfigure(l,this),null).values);let o=e.startState.facet(hl)?e.newSelection:e.newSelection.asSingle();new i(t,e.newDoc,o,s,(a,l)=>l.update(a,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:S.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),s=[n.range],o=Ki(n.effects);for(let a=1;ao.spec.fromJSON(a,l)))}}return i.create({doc:e.doc,selection:S.fromJSON(e.selection),extensions:t.extensions?r.concat([t.extensions]):r})}static create(e={}){let t=As.resolve(e.extensions||[],new Map),n=e.doc instanceof W?e.doc:W.of((e.doc||"").split(t.staticFacet(i.lineSeparator)||sl)),r=e.selection?e.selection instanceof S?e.selection:S.single(e.selection.anchor,e.selection.head):S.single(0);return uu(r,n.length),t.staticFacet(hl)||(r=r.asSingle()),new i(t,n,r,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(i.tabSize)}get lineBreak(){return this.facet(i.lineSeparator)||`
+`}get readOnly(){return this.facet(yu)}phrase(e,...t){for(let n of this.facet(i.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,r)=>{if(r=="$")return"$";let s=+(r||1);return!s||s>t.length?n:t[s-1]})),e}languageDataAt(e,t,n=-1){let r=[];for(let s of this.facet(du))for(let o of s(this,t,n))Object.prototype.hasOwnProperty.call(o,e)&&r.push(o[e]);return r}charCategorizer(e){return ny(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-n,a=e-n;for(;o>0;){let l=ue(t,o,!1);if(s(t.slice(l,o))!=F.Word)break;o=l}for(;ai.length?i[0]:4});N.lineSeparator=pu;N.readOnly=yu;N.phrases=A.define({compare(i,e){let t=Object.keys(i),n=Object.keys(e);return t.length==n.length&&t.every(r=>i[r]==e[r])}});N.languageData=du;N.changeFilter=mu;N.transactionFilter=gu;N.transactionExtender=Ou;Dt.reconfigure=_.define();function Te(i,e,t={}){let n={};for(let r of i)for(let s of Object.keys(r)){let o=r[s],a=n[s];if(a===void 0)n[s]=o;else if(!(a===o||o===void 0))if(Object.hasOwnProperty.call(t,s))n[s]=t[s](a,o);else throw new Error("Config merge conflict for field "+s)}for(let r in e)n[r]===void 0&&(n[r]=e[r]);return n}var at=class{eq(e){return this==e}range(e,t=e){return zn.create(e,t,this)}};at.prototype.startSide=at.prototype.endSide=0;at.prototype.point=!1;at.prototype.mapMode=ge.TrackDel;var zn=class i{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new i(e,t,n)}};function pl(i,e){return i.from-e.from||i.value.startSide-e.value.startSide}var ml=class i{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return this.to[this.to.length-1]}findIndex(e,t,n,r=0){let s=n?this.to:this.from;for(let o=r,a=s.length;;){if(o==a)return o;let l=o+a>>1,h=s[l]-e||(n?this.value[l].endSide:this.value[l].startSide)-t;if(l==o)return h>=0?o:a;h>=0?a=l:o=l+1}}between(e,t,n,r){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(n,1e9,!1,s);sd||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(a=Math.max(a,d-u)),n.push(h),r.push(u-o),s.push(d-o))}return{mapped:n.length?new i(r,s,n,a):null,pos:o}}},j=class i{constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(e,t,n,r){return new i(e,t,n,r)}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:n=!1,filterFrom:r=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(n&&(t=t.slice().sort(pl)),this.isEmpty)return t.length?i.of(t):this;let a=new Ms(this,null,-1).goto(0),l=0,h=[],c=new lt;for(;a.value||l=0){let f=t[l++];c.addInner(f.from,f.to,f.value)||h.push(f)}else a.rangeIndex==1&&a.chunkIndexthis.chunkEnd(a.chunkIndex)||sa.to||s=s&&e<=s+o.length&&o.between(s,e-s,t-s,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return Un.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Un.from(e).goto(t)}static compare(e,t,n,r,s=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),a=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=s),l=su(o,a,n),h=new yi(o,l,s),c=new yi(a,l,s);n.iterGaps((f,u,d)=>ou(h,f,c,u,d,r)),n.empty&&n.length==0&&ou(h,0,c,0,0,r)}static eq(e,t,n=0,r){r==null&&(r=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let a=su(s,o),l=new yi(s,a,0).goto(n),h=new yi(o,a,0).goto(n);for(;;){if(l.to!=h.to||!gl(l.active,h.active)||l.point&&(!h.point||!l.point.eq(h.point)))return!1;if(l.to>r)return!0;l.next(),h.next()}}static spans(e,t,n,r,s=-1){let o=new yi(e,null,s).goto(t),a=t,l=o.openStart;for(;;){let h=Math.min(o.to,n);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFroma&&(r.span(a,h,o.active,l),l=o.openEnd(h));if(o.to>n)return l+(o.point&&o.to>n?1:0);a=o.to,o.next()}}static of(e,t=!1){let n=new lt;for(let r of e instanceof zn?[e]:t?ry(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(e){if(!e.length)return i.empty;let t=e[e.length-1];for(let n=e.length-2;n>=0;n--)for(let r=e[n];r!=i.empty;r=r.nextLayer)t=new i(r.chunkPos,r.chunk,t,Math.max(r.maxPoint,t.maxPoint));return t}};j.empty=new j([],[],null,-1);function ry(i){if(i.length>1)for(let e=i[0],t=1;t0)return i.slice().sort(pl);e=n}return i}j.empty.nextLayer=j.empty;var lt=class i{finishChunk(e){this.chunks.push(new ml(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,n){this.addInner(e,t,n)||(this.nextLayer||(this.nextLayer=new i)).add(e,t,n)}addInner(e,t,n){let r=e-this.lastTo||n.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.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 n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(j.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=j.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function su(i,e,t){let n=new Map;for(let s of i)for(let o=0;o=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=n&&r.push(new Ms(o,t,n,s));return r.length==1?r[0]:new i(r)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let n=this.heap.length>>1;n>=0;n--)nl(this.heap,n);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let n=this.heap.length>>1;n>=0;n--)nl(this.heap,n);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)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(),nl(this.heap,0)}}};function nl(i,e){for(let t=i[e];;){let n=(e<<1)+1;if(n>=i.length)break;let r=i[n];if(n+1=0&&(r=i[n+1],n++),t.compare(r)<0)break;i[n]=t,i[e]=r,e=n}}var yi=class{constructor(e,t,n){this.minPoint=n,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=Un.from(e,t,n)}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){Ss(this.active,e),Ss(this.activeTo,e),Ss(this.activeRank,e),this.minActive=au(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:s}=this.cursor;for(;t0;)t++;Ts(this.active,t,n),Ts(this.activeTo,t,r),Ts(this.activeRank,t,s),e&&Ts(e,t,this.cursor.from),this.minActive=au(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&Ss(n,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from=0&&n[r]=0&&!(this.activeRank[n]e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}};function ou(i,e,t,n,r,s){i.goto(e),t.goto(n);let o=n+r,a=n,l=n-e;for(;;){let h=i.to+l-t.to||i.endSide-t.endSide,c=h<0?i.to+l:t.to,f=Math.min(c,o);if(i.point||t.point?i.point&&t.point&&(i.point==t.point||i.point.eq(t.point))&&gl(i.activeForPoint(i.to),t.activeForPoint(t.to))||s.comparePoint(a,f,i.point,t.point):f>a&&!gl(i.active,t.active)&&s.compareRange(a,f,i.active,t.active),c>o)break;a=c,h<=0&&i.next(),h>=0&&t.next()}}function gl(i,e){if(i.length!=e.length)return!1;for(let t=0;t=e;n--)i[n+1]=i[n];i[e]=t}function au(i,e){let t=-1,n=1e9;for(let r=0;r=e)return r;if(r==i.length)break;s+=i.charCodeAt(r)==9?t-s%t:1,r=ue(i,r)}return n===!0?-1:i.length}var bl="\u037C",vu=typeof Symbol>"u"?"__"+bl:Symbol.for(bl),wl=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),xu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},et=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,a,l,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&a==null)return l.push(o[0]+";");for(let d in a){let m=a[d];if(/&/.test(d))s(d.split(/,\s*/).map(p=>o.map(g=>p.replace(/&/,g))).reduce((p,g)=>p.concat(g)),m,l);else if(m&&typeof m=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");s(r(d),m,c,u)}else m!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,p=>"-"+p.toLowerCase())+": "+m+";")}(c.length||u)&&l.push((n&&!f&&!h?o.map(n):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(r(o),e[o],this.rules)}getRules(){return this.rules.join(`
`)}static newName(){let e=xu[vu]||1;return xu[vu]=e+1,bl+e.toString(36)}static mount(e,t,n){let r=e[wl],s=n&&n.nonce;r?s&&r.setNonce(s):r=new vl(e,s),r.mount(Array.isArray(t)?t:[t],e)}},ku=new Map,vl=class{constructor(e,t){let n=e.ownerDocument||e,r=n.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let s=ku.get(n);if(s)return e[wl]=s;this.sheet=new r.CSSStyleSheet,ku.set(n,this)}else this.styleTag=n.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[wl]=this}mount(e,t){let n=this.sheet,r=0,s=0;for(let o=0;o-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,a),n)for(let h=0;h",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},sy=typeof navigator<"u"&&/Mac/.test(navigator.platform),oy=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(de=0;de<10;de++)Vt[48+de]=Vt[96+de]=String(de);var de;for(de=1;de<=24;de++)Vt[de+111]="F"+de;var de;for(de=65;de<=90;de++)Vt[de]=String.fromCharCode(de+32),tn[de]=String.fromCharCode(de);var de;for(_s in Vt)tn.hasOwnProperty(_s)||(tn[_s]=Vt[_s]);var _s;function Su(i){var e=sy&&i.metaKey&&i.shiftKey&&!i.ctrlKey&&!i.altKey||oy&&i.shiftKey&&i.key&&i.key.length==1||i.key=="Unidentified",t=!e&&i.key||(i.shiftKey?tn:Vt)[i.keyCode]||i.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function ar(i){let e;return i.nodeType==11?e=i.getSelection?i:i.ownerDocument:e=i,e.getSelection()}function El(i,e){return e?i==e||i.contains(e.nodeType!=1?e.parentNode:e):!1}function ay(i){let e=i.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Ns(i,e){if(!e.anchorNode)return!1;try{return El(i,e.anchorNode)}catch{return!1}}function lr(i){return i.nodeType==3?ki(i,0,i.nodeValue.length).getClientRects():i.nodeType==1?i.getClientRects():[]}function er(i,e,t,n){return t?Tu(i,e,t,n,-1)||Tu(i,e,t,n,1):!1}function xi(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e}function Gs(i){return i.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(i.nodeName)}function Tu(i,e,t,n,r){for(;;){if(i==t&&e==n)return!0;if(e==(r<0?0:Lt(i))){if(i.nodeName=="DIV")return!1;let s=i.parentNode;if(!s||s.nodeType!=1)return!1;e=xi(i)+(r<0?0:1),i=s}else if(i.nodeType==1){if(i=i.childNodes[e+(r<0?-1:0)],i.nodeType==1&&i.contentEditable=="false")return!1;e=r<0?Lt(i):0}else return!1}}function Lt(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}function yh(i,e){let t=e?i.left:i.right;return{left:t,right:t,top:i.top,bottom:i.bottom}}function ly(i){let e=i.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function fd(i,e){let t=e.width/i.offsetWidth,n=e.height/i.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-i.offsetWidth)<1)&&(t=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-i.offsetHeight)<1)&&(n=1),{scaleX:t,scaleY:n}}function hy(i,e,t,n,r,s,o,a){let l=i.ownerDocument,h=l.defaultView||window;for(let c=i,f=!1;c&&!f;)if(c.nodeType==1){let u,d=c==l.body,m=1,p=1;if(d)u=ly(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let y=c.getBoundingClientRect();({scaleX:m,scaleY:p}=fd(c,y)),u={left:y.left,right:y.left+c.clientWidth*m,top:y.top,bottom:y.top+c.clientHeight*p}}let g=0,O=0;if(r=="nearest")e.top0&&e.bottom>u.bottom+O&&(O=e.bottom-u.bottom+O+o)):e.bottom>u.bottom&&(O=e.bottom-u.bottom+o,t<0&&e.top-O0&&e.right>u.right+g&&(g=e.right-u.right+g+s)):e.right>u.right&&(g=e.right-u.right+s,t<0&&e.leftt.clientHeight||t.scrollWidth>t.clientWidth)return t;t=t.assignedSlot||t.parentNode}else if(t.nodeType==11)t=t.host;else break;return null}var Al=class{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:n}=e;this.set(t,Math.min(e.anchorOffset,t?Lt(t):0),n,Math.min(e.focusOffset,n?Lt(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}},nn=null;function ud(i){if(i.setActive)return i.setActive();if(nn)return i.focus(nn);let e=[];for(let t=i;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(i.focus(nn==null?{get preventScroll(){return nn={preventScroll:!0},!0}}:void 0),!nn){nn=!1;for(let t=0;tMath.max(1,i.scrollHeight-i.clientHeight-4)}function md(i,e){for(let t=i,n=e;;){if(t.nodeType==3&&n>0)return{node:t,offset:n};if(t.nodeType==1&&n>0){if(t.contentEditable=="false")return null;t=t.childNodes[n-1],n=Lt(t)}else if(t.parentNode&&!Gs(t))n=xi(t),t=t.parentNode;else return null}}function gd(i,e){for(let t=i,n=e;;){if(t.nodeType==3&&nt)return f.domBoundsAround(e,t,h);if(u>=e&&r==-1&&(r=l,s=h),h>t&&f.dom.parentNode==this.dom){o=l,a=c;break}c=u,h=u+f.breakAfter}return{from:s,to:a<0?n+this.length:a,startDOM:(r?this.children[r-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,n=bh){this.markDirty();for(let r=e;rthis.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let n=this.children[--this.i];this.pos-=n.length+n.breakAfter}}};function Od(i,e,t,n,r,s,o,a,l){let{children:h}=i,c=h.length?h[e]:null,f=s.length?s[s.length-1]:null,u=f?f.breakAfter:o;if(!(e==n&&c&&!o&&!u&&s.length<2&&c.merge(t,r,s.length?f:null,t==0,a,l))){if(n0&&(!o&&s.length&&c.merge(t,c.length,s[0],!1,a,0)?c.breakAfter=s.shift().breakAfter:(t2),Q={mac:Au||/Mac/.test(qe.platform),windows:/Win/.test(qe.platform),linux:/Linux|X11/.test(qe.platform),ie:co,ie_version:bd?Ql.documentMode||6:_l?+_l[1]:Ml?+Ml[1]:0,gecko:Ru,gecko_version:Ru?+(/Firefox\/(\d+)/.exec(qe.userAgent)||[0,0])[1]:0,chrome:!!xl,chrome_version:xl?+xl[1]:0,ios:Au,android:/Android\b/.test(qe.userAgent),webkit:Eu,safari:wd,webkit_version:Eu?+(/\bAppleWebKit\/(\d+)/.exec(qe.userAgent)||[0,0])[1]:0,tabSize:Ql.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"},dy=256,vt=class i extends J{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,n){return this.flags&8||n&&(!(n instanceof i)||this.length-(t-e)+n.length>dy||n.flags&8)?!1:(this.text=this.text.slice(0,e)+(n?n.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new i(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new Me(this.dom,e)}domBoundsAround(e,t,n){return{from:n,to:n+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return py(this.dom,e,t)}},Zt=class i extends J{constructor(e,t=[],n=0){super(),this.mark=e,this.children=t,this.length=n;for(let r of t)r.setParent(this)}setAttrs(e){if(dd(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,n,r,s,o){return n&&(!(n instanceof i&&n.mark.eq(this.mark))||e&&s<=0||te&&t.push(n=e&&(r=s),n=l,s++}let o=this.length-e;return this.length=e,r>-1&&(this.children.length=r,this.markDirty()),new i(this.mark,t,o)}domAtPos(e){return vd(this,e)}coordsAt(e,t){return kd(this,e,t)}};function py(i,e,t){let n=i.nodeValue.length;e>n&&(e=n);let r=e,s=e,o=0;e==0&&t<0||e==n&&t>=0?Q.chrome||Q.gecko||(e?(r--,o=1):s=0)?0:a.length-1];return Q.safari&&!o&&l.width==0&&(l=Array.prototype.find.call(a,h=>h.width)||l),o?yh(l,o<0):l||null}var hr=class i extends J{static create(e,t,n){return new i(e,t,n)}constructor(e,t,n){super(),this.widget=e,this.length=t,this.side=n,this.prevWidget=null}split(e){let t=i.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(e,t,n,r,s,o){return n&&(!(n instanceof i)||!this.widget.compare(n.widget)||e>0&&s<=0||t0)?Me.before(this.dom):Me.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;let r=this.dom.getClientRects(),s=null;if(!r.length)return null;let o=this.side?this.side<0:e>0;for(let a=o?r.length-1:0;s=r[a],!(e>0?a==0:a==r.length-1||s.top0?Me.before(this.dom):Me.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return W.empty}get isHidden(){return!0}};vt.prototype.children=hr.prototype.children=cr.prototype.children=bh;function vd(i,e){let t=i.dom,{children:n}=i,r=0;for(let s=0;rs&&e0;s--){let o=n[s-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let s=r;s0&&e instanceof Zt&&r.length&&(n=r[r.length-1])instanceof Zt&&n.mark.eq(e.mark)?xd(n,e.children[0],t-1):(r.push(e),e.setParent(i)),i.length+=e.length}function kd(i,e,t){let n=null,r=-1,s=null,o=-1;function a(h,c){for(let f=0,u=0;f=c&&(d.children.length?a(d,c-u):(!s||s.isHidden&&t>0)&&(m>c||u==m&&d.getSide()>0)?(s=d,o=c-u):(u-1?1:0)!=r.length-(t&&r.indexOf(t)>-1?1:0))return!1;for(let s of n)if(s!=t&&(r.indexOf(s)==-1||i[s]!==e[s]))return!1;return!0}function $l(i,e,t){let n=!1;if(e)for(let r in e)t&&r in t||(n=!0,r=="style"?i.style.cssText="":i.removeAttribute(r));if(t)for(let r in t)e&&e[r]==t[r]||(n=!0,r=="style"?i.style.cssText=t[r]:i.setAttribute(r,t[r]));return n}function gy(i){let e=Object.create(null);for(let t=0;t0&&this.children[n-1].length==0;)this.children[--n].destroy();return this.children.length=n,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Zs(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){xd(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=Dl(t,this.attrs||{})),n&&(this.attrs=Dl({class:n},this.attrs||{}))}domAtPos(e){return vd(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var n;this.dom?this.flags&4&&(dd(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&($l(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let r=this.dom.lastChild;for(;r&&J.get(r)instanceof Zt;)r=r.lastChild;if(!r||!this.length||r.nodeName!="BR"&&((n=J.get(r))===null||n===void 0?void 0:n.isEditable)==!1&&(!Q.ios||!this.children.some(s=>s instanceof vt))){let s=document.createElement("BR");s.cmIgnore=!0,this.dom.appendChild(s)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let n of this.children){if(!(n instanceof vt)||/[^ -~]/.test(n.text))return null;let r=lr(n.dom);if(r.length!=1)return null;e+=r[0].width,t=r[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let n=kd(this,e,t);if(!this.children.length&&n&&this.parent){let{heightOracle:r}=this.parent.view.viewState,s=n.bottom-n.top;if(Math.abs(s-r.lineHeight)<2&&r.textHeight=t){if(s instanceof i)return s;if(o>t)break}r=o+s.breakAfter}return null}},vi=class i extends J{constructor(e,t,n){super(),this.widget=e,this.length=t,this.deco=n,this.breakAfter=0,this.prevWidget=null}merge(e,t,n,r,s,o){return n&&(!(n instanceof i)||!this.widget.compare(n.widget)||e>0&&s<=0||t0}},Be=class{eq(e){return!1}updateDOM(e,t){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,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},_e=function(i){return i[i.Text=0]="Text",i[i.WidgetBefore=1]="WidgetBefore",i[i.WidgetAfter=2]="WidgetAfter",i[i.WidgetRange=3]="WidgetRange",i}(_e||(_e={})),M=class extends at{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new fr(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Jt(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:s,end:o}=Sd(e,t);n=(s?t?-3e8:-1:5e8)-1,r=(o?t?2e8:1:-6e8)+1}return new Jt(e,n,r,t,e.widget||null,!0)}static line(e){return new ur(e)}static set(e,t=!1){return j.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};M.none=j.empty;var fr=class i extends M{constructor(e){let{start:t,end:n}=Sd(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,n;return this==e||e instanceof i&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((n=e.attrs)===null||n===void 0?void 0:n.class))&&Zs(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}};fr.prototype.point=!1;var ur=class i extends M{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof i&&this.spec.class==e.spec.class&&Zs(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)}};ur.prototype.mapMode=ge.TrackBefore;ur.prototype.point=!0;var Jt=class i extends M{constructor(e,t,n,r,s,o){super(t,n,s,e),this.block=r,this.isReplace=o,this.mapMode=r?t<=0?ge.TrackBefore:ge.TrackAfter:ge.TrackDel}get type(){return this.startSide!=this.endSide?_e.WidgetRange:this.startSide<=0?_e.WidgetBefore:_e.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof i&&Oy(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}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)}};Jt.prototype.point=!0;function Sd(i,e=!1){let{inclusiveStart:t,inclusiveEnd:n}=i;return t==null&&(t=i.inclusive),n==null&&(n=i.inclusive),{start:t??e,end:n??e}}function Oy(i,e){return i==e||!!(i&&e&&i.compare(e))}function Vl(i,e,t,n=0){let r=t.length-1;r>=0&&t[r]+n>=i?t[r]=Math.max(t[r],e):t.push(i,e)}var tr=class i{constructor(e,t,n,r){this.doc=e,this.pos=t,this.end=n,this.disallowBlockEffectsFor=r,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof vi&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new be),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ds(new cr(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof vi)&&this.getLine()}buildText(e,t,n){for(;e>0;){if(this.textOff==this.text.length){let{value:s,lineBreak:o,done:a}=this.cursor.next(this.skip);if(this.skip=0,a)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=s,this.textOff=0}let r=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-n)),this.getLine().append(Ds(new vt(this.text.slice(this.textOff,this.textOff+r)),t),n),this.atCursorPos=!0,this.textOff+=r,e-=r,n=0}}span(e,t,n,r){this.buildText(t-e,n,r),this.pos=t,this.openStart<0&&(this.openStart=r)}point(e,t,n,r,s,o){if(this.disallowBlockEffectsFor[o]&&n instanceof Jt){if(n.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let a=t-e;if(n instanceof Jt)if(n.block)n.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new vi(n.widget||Kt.block,a,n));else{let l=hr.create(n.widget||Kt.inline,a,a?0:n.startSide),h=this.atCursorPos&&!l.isEditable&&s<=r.length&&(e0),c=!l.isEditable&&(er.length||n.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!h&&!l.isEditable&&(this.pendingBuffer=0),this.flushBuffer(r),h&&(f.append(Ds(new cr(1),r),s),s=r.length+Math.max(0,s-r.length)),f.append(Ds(l,r),s),this.atCursorPos=c,this.pendingBuffer=c?er.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=r.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(n);a&&(this.textOff+a<=this.text.length?this.textOff+=a:(this.skip+=a-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=s)}static build(e,t,n,r,s){let o=new i(e,t,n,s);return o.openEnd=j.spans(r,t,n,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function Ds(i,e){for(let t of e)i=new Zt(t,[i],i.length);return i}var Kt=class extends Be{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}};Kt.inline=new Kt("span");Kt.block=new Kt("div");var H=function(i){return i[i.LTR=0]="LTR",i[i.RTL=1]="RTL",i}(H||(H={})),Si=H.LTR,wh=H.RTL;function Td(i){let e=[];for(let t=0;t=t){if(a.level==n)return o;(s<0||(r!=0?r<0?a.fromt:e[s].level>a.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}};function Cd(i,e){if(i.length!=e.length)return!1;for(let t=0;t=0;p-=3)if(Ot[p+1]==-d){let g=Ot[p+2],O=g&2?r:g&4?g&1?s:r:0;O&&(Y[f]=Y[Ot[p]]=O),a=p;break}}else{if(Ot.length==189)break;Ot[a++]=f,Ot[a++]=u,Ot[a++]=l}else if((m=Y[f])==2||m==1){let p=m==r;l=p?0:1;for(let g=a-3;g>=0;g-=3){let O=Ot[g+2];if(O&2)break;if(p)Ot[g+2]|=2;else{if(O&4)break;Ot[g+2]|=4}}}}}function ky(i,e,t,n){for(let r=0,s=n;r<=t.length;r++){let o=r?t[r-1].to:i,a=rl;)m==g&&(m=t[--p].from,g=p?t[p-1].to:i),Y[--m]=d;l=c}else s=h,l++}}}function ql(i,e,t,n,r,s,o){let a=n%2?2:1;if(n%2==r%2)for(let l=e,h=0;ll&&o.push(new bt(l,p.from,d));let g=p.direction==Si!=!(d%2);Bl(i,g?n+1:n,r,p.inner,p.from,p.to,o),l=p.to}m=p.to}else{if(m==t||(c?Y[m]!=a:Y[m]==a))break;m++}u?ql(i,l,m,n+1,r,u,o):le;){let c=!0,f=!1;if(!h||l>s[h-1].to){let p=Y[l-1];p!=a&&(c=!1,f=p==16)}let u=!c&&a==1?[]:null,d=c?n:n+1,m=l;e:for(;;)if(h&&m==s[h-1].to){if(f)break e;let p=s[--h];if(!c)for(let g=p.from,O=h;;){if(g==e)break e;if(O&&s[O-1].to==g)g=s[--O].from;else{if(Y[g-1]==a)break e;break}}if(u)u.push(p);else{p.toY.length;)Y[Y.length]=256;let n=[],r=e==Si?0:1;return Bl(i,r,r,t,0,i.length,n),n}function Rd(i){return[new bt(0,i,0)]}var Ed="";function Ty(i,e,t,n,r){var s;let o=n.head-i.from,a=bt.find(e,o,(s=n.bidiLevel)!==null&&s!==void 0?s:-1,n.assoc),l=e[a],h=l.side(r,t);if(o==h){let u=a+=r?1:-1;if(u<0||u>=e.length)return null;l=e[a=u],o=l.side(!r,t),h=l.side(r,t)}let c=ue(i.text,o,l.forward(r,t));(cl.to)&&(c=h),Ed=i.text.slice(Math.min(o,c),Math.max(o,c));let f=a==(r?e.length-1:0)?null:e[a+(r?1:-1)];return f&&c==h&&f.level+(r?0:1)i.some(e=>e)}),Ld=A.define({combine:i=>i.some(e=>e)}),qd=A.define(),ir=class i{constructor(e,t="nearest",n="nearest",r=5,s=5,o=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new i(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 i(S.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},$s=_.define({map:(i,e)=>i.map(e)}),Bd=_.define();function we(i,e,t){let n=i.facet(_d);n.length?n[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}var Ht=A.define({combine:i=>i.length?i[0]:!0}),Cy=0,Gn=A.define(),re=class i{constructor(e,t,n,r,s){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.extension=s(this)}static define(e,t){let{eventHandlers:n,eventObservers:r,provide:s,decorations:o}=t||{};return new i(Cy++,e,n,r,a=>{let l=[Gn.of(a)];return o&&l.push(dr.of(h=>{let c=h.plugin(a);return c?o(c):M.none})),s&&l.push(s(a)),l})}static fromClass(e,t){return i.define(n=>new e(n),t)}},nr=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(n){if(we(t.state,n,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){we(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(n){we(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},Xd=A.define(),vh=A.define(),dr=A.define(),Wd=A.define(),xh=A.define(),Id=A.define();function Mu(i,e){let t=i.state.facet(Id);if(!t.length)return t;let n=t.map(s=>s instanceof Function?s(i):s),r=[];return j.spans(n,e.from,e.to,{point(){},span(s,o,a,l){let h=s-e.from,c=o-e.from,f=r;for(let u=a.length-1;u>=0;u--,l--){let d=a[u].spec.bidiIsolate,m;if(d==null&&(d=Py(e.text,h,c)),l>0&&f.length&&(m=f[f.length-1]).to==h&&m.direction==d)m.to=c,f=m.inner;else{let p={from:h,to:c,direction:d,inner:[]};f.push(p),f=p.inner}}}}),r}var Nd=A.define();function jd(i){let e=0,t=0,n=0,r=0;for(let s of i.state.facet(Nd)){let o=s(i);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(n=Math.max(n,o.top)),o.bottom!=null&&(r=Math.max(r,o.bottom)))}return{left:e,right:t,top:n,bottom:r}}var Yn=A.define(),wt=class i{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(e){return new i(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,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toAc)break;s+=2}if(!l)return n;new i(l.fromA,l.toA,l.fromB,l.toB).addToSet(n),o=l.toA,a=l.toB}}},Js=class i{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=Ae.empty(this.startState.doc.length);for(let s of n)this.changes=this.changes.compose(s.changes);let r=[];this.changes.iterChangedRanges((s,o,a,l)=>r.push(new wt(s,o,a,l))),this.changedRanges=r}static create(e,t,n){return new i(e,t,n)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},Ks=class extends J{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=M.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.setDOM(e.contentDOM),this.children=[new be],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new wt(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let n=e.changedRanges;this.minWidth>0&&n.length&&(n.every(({fromA:h,toA:c})=>cthis.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 r=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?r=this.domChanged.newSel.head:!Dy(e.changes,this.hasComposition)&&!e.selectionSet&&(r=e.state.selection.main.head));let s=r>-1?Ey(this.view,e.changes,r):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:h,to:c}=this.hasComposition;n=new wt(h,c,e.changes.mapPos(h,-1),e.changes.mapPos(c,1)).addToSet(n.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(Q.ie||Q.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,a=this.updateDeco(),l=My(o,a,e.changes);return n=wt.extendWithRanges(n,l),!(this.flags&7)&&n.length==0?!1:(this.updateInner(n,e.startState.doc.length,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,n){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,n);let{observer:r}=this.view;r.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=Q.chrome||Q.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||r.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let s=[];if(this.view.viewport.from||this.view.viewport.to=0?r[o]:null;if(!a)break;let{fromA:l,toA:h,fromB:c,toB:f}=a,u,d,m,p;if(n&&n.range.fromBc){let x=tr.build(this.view.state.doc,c,n.range.fromB,this.decorations,this.dynamicDecorationMap),w=tr.build(this.view.state.doc,n.range.toB,f,this.decorations,this.dynamicDecorationMap);d=x.breakAtStart,m=x.openStart,p=w.openEnd;let P=this.compositionView(n);w.breakAtStart?P.breakAfter=1:w.content.length&&P.merge(P.length,P.length,w.content[0],!1,w.openStart,0)&&(P.breakAfter=w.content[0].breakAfter,w.content.shift()),x.content.length&&P.merge(0,0,x.content[x.content.length-1],!0,0,x.openEnd)&&x.content.pop(),u=x.content.concat(P).concat(w.content)}else({content:u,breakAtStart:d,openStart:m,openEnd:p}=tr.build(this.view.state.doc,c,f,this.decorations,this.dynamicDecorationMap));let{i:g,off:O}=s.findPos(h,1),{i:y,off:v}=s.findPos(l,-1);Od(this,y,v,g,O,u,d,m,p)}n&&this.fixCompositionDOM(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let n of t.effects)n.is(Bd)&&(this.editContextFormatting=n.value)}compositionView(e){let t=new vt(e.text.nodeValue);t.flags|=8;for(let{deco:r}of e.marks)t=new Zt(r,[t],t.length);let n=new be;return n.append(t,0),n}fixCompositionDOM(e){let t=(s,o)=>{o.flags|=8|(o.children.some(l=>l.flags&7)?1:0),this.markedForComposition.add(o);let a=J.get(s);a&&a!=o&&(a.dom=null),o.setDOM(s)},n=this.childPos(e.range.fromB,1),r=this.children[n.i];t(e.line,r);for(let s=e.marks.length-1;s>=-1;s--)n=r.childPos(n.off,1),r=r.children[n.i],t(s>=0?e.marks[s].node:e.text,r)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let n=this.view.root.activeElement,r=n==this.dom,s=!r&&Ns(this.dom,this.view.observer.selectionRange)&&!(n&&this.dom.contains(n));if(!(r||t||s))return;let o=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,l=this.moveToLine(this.domAtPos(a.anchor)),h=a.empty?l:this.moveToLine(this.domAtPos(a.head));if(Q.gecko&&a.empty&&!this.hasComposition&&Ry(l)){let f=document.createTextNode("");this.view.observer.ignore(()=>l.node.insertBefore(f,l.node.childNodes[l.offset]||null)),l=h=new Me(f,0),o=!0}let c=this.view.observer.selectionRange;(o||!c.focusNode||(!er(l.node,l.offset,c.anchorNode,c.anchorOffset)||!er(h.node,h.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,a))&&(this.view.observer.ignore(()=>{Q.android&&Q.chrome&&this.dom.contains(c.focusNode)&&_y(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=ar(this.view.root);if(f)if(a.empty){if(Q.gecko){let u=Ay(l.node,l.offset);if(u&&u!=3){let d=(u==1?md:gd)(l.node,l.offset);d&&(l=new Me(d.node,d.offset))}}f.collapse(l.node,l.offset),a.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=a.bidiLevel)}else if(f.extend){f.collapse(l.node,l.offset);try{f.extend(h.node,h.offset)}catch{}}else{let u=document.createRange();a.anchor>a.head&&([l,h]=[h,l]),u.setEnd(h.node,h.offset),u.setStart(l.node,l.offset),f.removeAllRanges(),f.addRange(u)}s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(l,h)),this.impreciseAnchor=l.precise?null:new Me(c.anchorNode,c.anchorOffset),this.impreciseHead=h.precise?null:new Me(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&er(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,n=ar(e.root),{anchorNode:r,anchorOffset:s}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=be.find(this,t.head);if(!o)return;let a=o.posAtStart;if(t.head==a||t.head==a+o.length)return;let l=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!l||!h||l.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc);n.collapse(c.node,c.offset),n.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&n.collapse(r,s)}moveToLine(e){let t=this.dom,n;if(e.node!=t)return e;for(let r=e.offset;!n&&r=0;r--){let s=J.get(t.childNodes[r]);s instanceof be&&(n=s.domAtPos(s.length))}return n?new Me(n.node,n.offset,!0):e}nearest(e){for(let t=e;t;){let n=J.get(t);if(n&&n.rootView==this)return n;t=t.parentNode}return null}posFromDOM(e,t){let n=this.nearest(e);if(!n)throw new RangeError("Trying to find position for a DOM position outside of the document");return n.localPosFromDOM(e,t)+n.posAtStart}domAtPos(e){let{i:t,off:n}=this.childCursor().findPos(e,-1);for(;t=0;o--){let a=this.children[o],l=s-a.breakAfter,h=l-a.length;if(le||a.covers(1))&&(!n||a instanceof be&&!(n instanceof be&&t>=0)))n=a,r=h;else if(n&&h==e&&l==e&&a instanceof vi&&Math.abs(t)<2){if(a.deco.startSide<0)break;o&&(n=null)}s=h}return n?n.coordsAt(e-r,t):null}coordsForChar(e){let{i:t,off:n}=this.childPos(e,1),r=this.children[t];if(!(r instanceof be))return null;for(;r.children.length;){let{i:a,off:l}=r.childPos(n,1);for(;;a++){if(a==r.children.length)return null;if((r=r.children[a]).length)break}n=l}if(!(r instanceof vt))return null;let s=ue(r.text,n);if(s==n)return null;let o=ki(r.dom,n,s).getClientRects();for(let a=0;aMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,a=-1,l=this.view.textDirection==H.LTR;for(let h=0,c=0;cr)break;if(h>=n){let d=f.dom.getBoundingClientRect();if(t.push(d.height),o){let m=f.dom.lastChild,p=m?lr(m):[];if(p.length){let g=p[p.length-1],O=l?g.right-d.left:d.right-g.left;O>a&&(a=O,this.minWidth=s,this.minWidthFrom=h,this.minWidthTo=u)}}}h=u+f.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?H.RTL:H.LTR}measureTextSize(){for(let s of this.children)if(s instanceof be){let o=s.measureTextSize();if(o)return o}let e=document.createElement("div"),t,n,r;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let s=lr(e.firstChild)[0];t=e.getBoundingClientRect().height,n=s?s.width/27:7,r=s?s.height:t,e.remove()}),{lineHeight:t,charWidth:n,textHeight:r}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Ys(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let s=r==t.viewports.length?null:t.viewports[r],o=s?s.from-1:this.length;if(o>n){let a=(t.lineBlockAt(o).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(M.replace({widget:new eo(a),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!s)break;n=s.to+1}return M.set(e)}updateDeco(){let e=1,t=this.view.state.facet(dr).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),n=!1,r=this.view.state.facet(Wd).map((s,o)=>{let a=typeof s=="function";return a&&(n=!0),a?s(this.view):s});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push(j.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];et.anchor?-1:1),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let s=jd(this.view),o={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:a,offsetHeight:l}=this.view.scrollDOM;hy(this.view.scrollDOM,o,t.head{ne.from&&(t=!0)}),t}function $y(i,e,t=1){let n=i.charCategorizer(e),r=i.doc.lineAt(e),s=e-r.from;if(r.length==0)return S.cursor(e);s==0?t=1:s==r.length&&(t=-1);let o=s,a=s;t<0?o=ue(r.text,s,!1):a=ue(r.text,s);let l=n(r.text.slice(o,a));for(;o>0;){let h=ue(r.text,o,!1);if(n(r.text.slice(h,o))!=l)break;o=h}for(;ai?e.left-i:Math.max(0,i-e.right)}function Ly(i,e){return e.top>i?e.top-i:Math.max(0,i-e.bottom)}function kl(i,e){return i.tope.top+1}function _u(i,e){return ei.bottom?{top:i.top,left:i.left,right:i.right,bottom:e}:i}function Wl(i,e,t){let n,r,s,o,a=!1,l,h,c,f;for(let m=i.firstChild;m;m=m.nextSibling){let p=lr(m);for(let g=0;gv||o==v&&s>y){n=m,r=O,s=y,o=v;let x=v?t0?g0)}y==0?t>O.bottom&&(!c||c.bottomO.top)&&(h=m,f=O):c&&kl(c,O)?c=Du(c,O.bottom):f&&kl(f,O)&&(f=_u(f,O.top))}}if(c&&c.bottom>=t?(n=l,r=c):f&&f.top<=t&&(n=h,r=f),!n)return{node:i,offset:0};let u=Math.max(r.left,Math.min(r.right,e));if(n.nodeType==3)return $u(n,u,t);if(a&&n.contentEditable!="false")return Wl(n,u,t);let d=Array.prototype.indexOf.call(i.childNodes,n)+(e>=(r.left+r.right)/2?1:0);return{node:i,offset:d}}function $u(i,e,t){let n=i.nodeValue.length,r=-1,s=1e9,o=0;for(let a=0;at?c.top-t:t-c.bottom)-1;if(c.left-1<=e&&c.right+1>=e&&f=(c.left+c.right)/2,d=u;if((Q.chrome||Q.gecko)&&ki(i,a).getBoundingClientRect().left==c.right&&(d=!u),f<=0)return{node:i,offset:a+(d?1:0)};r=a+(d?1:0),s=f}}}return{node:i,offset:r>-1?r:o>0?i.nodeValue.length:0}}function Ud(i,e,t,n=-1){var r,s;let o=i.contentDOM.getBoundingClientRect(),a=o.top+i.viewState.paddingTop,l,{docHeight:h}=i.viewState,{x:c,y:f}=e,u=f-a;if(u<0)return 0;if(u>h)return i.state.doc.length;for(let x=i.viewState.heightOracle.textHeight/2,w=!1;l=i.elementAtHeight(u),l.type!=_e.Text;)for(;u=n>0?l.bottom+x:l.top-x,!(u>=0&&u<=h);){if(w)return t?null:0;w=!0,n=-n}f=a+u;let d=l.from;if(di.viewport.to)return i.viewport.to==i.state.doc.length?i.state.doc.length:t?null:Vu(i,o,l,c,f);let m=i.dom.ownerDocument,p=i.root.elementFromPoint?i.root:m,g=p.elementFromPoint(c,f);g&&!i.contentDOM.contains(g)&&(g=null),g||(c=Math.max(o.left+1,Math.min(o.right-1,c)),g=p.elementFromPoint(c,f),g&&!i.contentDOM.contains(g)&&(g=null));let O,y=-1;if(g&&((r=i.docView.nearest(g))===null||r===void 0?void 0:r.isEditable)!=!1){if(m.caretPositionFromPoint){let x=m.caretPositionFromPoint(c,f);x&&({offsetNode:O,offset:y}=x)}else if(m.caretRangeFromPoint){let x=m.caretRangeFromPoint(c,f);x&&({startContainer:O,startOffset:y}=x,(!i.contentDOM.contains(O)||Q.safari&&qy(O,y,c)||Q.chrome&&By(O,y,c))&&(O=void 0))}}if(!O||!i.docView.dom.contains(O)){let x=be.find(i.docView,d);if(!x)return u>l.top+l.height/2?l.to:l.from;({node:O,offset:y}=Wl(x.dom,c,f))}let v=i.docView.nearest(O);if(!v)return null;if(v.isWidget&&((s=v.dom)===null||s===void 0?void 0:s.nodeType)==1){let x=v.dom.getBoundingClientRect();return e.yi.defaultLineHeight*1.5){let a=i.viewState.heightOracle.textHeight,l=Math.floor((r-t.top-(i.defaultLineHeight-a)*.5)/a);s+=l*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+Ms(o,s,i.state.tabSize)}function qy(i,e,t){let n;if(i.nodeType!=3||e!=(n=i.nodeValue.length))return!1;for(let r=i.nextSibling;r;r=r.nextSibling)if(r.nodeType!=1||r.nodeName!="BR")return!1;return ki(i,n-1,n).getBoundingClientRect().left>t}function By(i,e,t){if(e!=0)return!1;for(let r=i;;){let s=r.parentNode;if(!s||s.nodeType!=1||s.firstChild!=r)return!1;if(s.classList.contains("cm-line"))break;r=s}let n=i.nodeType==1?i.getBoundingClientRect():ki(i,0,Math.max(i.nodeValue.length,1)).getBoundingClientRect();return t-n.left>5}function Il(i,e){let t=i.lineBlockAt(e);if(Array.isArray(t.type)){for(let n of t.type)if(n.to>e||n.to==e&&(n.to==t.to||n.type==_e.Text))return n}return t}function Xy(i,e,t,n){let r=Il(i,e.head),s=!n||r.type!=_e.Text||!(i.lineWrapping||r.widgetLineBreaks)?null:i.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head);if(s){let o=i.dom.getBoundingClientRect(),a=i.textDirectionAt(r.from),l=i.posAtCoords({x:t==(a==H.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(l!=null)return S.cursor(l,t?-1:1)}return S.cursor(t?r.to:r.from,t?-1:1)}function Lu(i,e,t,n){let r=i.state.doc.lineAt(e.head),s=i.bidiSpans(r),o=i.textDirectionAt(r.from);for(let a=e,l=null;;){let h=Ty(r,s,o,a,t),c=Ed;if(!h){if(r.number==(t?i.state.doc.lines:1))return a;c=`
-`,r=i.state.doc.line(r.number+(t?1:-1)),s=i.bidiSpans(r),h=i.visualLineSide(r,!t)}if(l){if(!l(c))return a}else{if(!n)return h;l=n(c)}a=h}}function Wy(i,e,t){let n=i.state.charCategorizer(e),r=n(t);return s=>{let o=n(s);return r==F.Space&&(r=o),r==o}}function Iy(i,e,t,n){let r=e.head,s=t?1:-1;if(r==(t?i.state.doc.length:0))return S.cursor(r,e.assoc);let o=e.goalColumn,a,l=i.contentDOM.getBoundingClientRect(),h=i.coordsAtPos(r,e.assoc||-1),c=i.documentTop;if(h)o==null&&(o=h.left-l.left),a=s<0?h.top:h.bottom;else{let d=i.viewState.lineBlockAt(r);o==null&&(o=Math.min(l.right-l.left,i.defaultCharacterWidth*(r-d.from))),a=(s<0?d.top:d.bottom)+c}let f=l.left+o,u=n??i.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let m=a+(u+d)*s,p=Ud(i,{x:f,y:m},!1,s);if(ml.bottom||(s<0?pr)){let g=i.docView.coordsForChar(p),O=!g||m{if(e>s&&er(i)),t.from,e.head>t.from?-1:1);return n==t.from?t:S.cursor(n,nnull),Q.gecko&&nb(e.contentDOM.ownerDocument)}handleEvent(e){!Gy(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||this.runHandlers(e.type,e)}runHandlers(e,t){let n=this.handlers[e];if(n){for(let r of n.observers)r(this.view,t);for(let r of n.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Ny(e),n=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,a=n[s];a&&o!=!a.handlers.length&&(r.removeEventListener(s,this.handleEvent),a=null),a||r.addEventListener(s,this.handleEvent,{passive:o})}for(let s in n)s!="scroll"&&!t[s]&&r.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Hd.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),Q.android&&Q.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return Q.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=Fd.find(n=>n.keyCode==e.keyCode))&&!e.ctrlKey||jy.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from0?!0:Q.safari&&!Q.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}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 qu(i,e){return(t,n)=>{try{return e.call(i,n,t)}catch(r){we(t.state,r)}}}function Ny(i){let e=Object.create(null);function t(n){return e[n]||(e[n]={observers:[],handlers:[]})}for(let n of i){let r=n.spec;if(r&&r.domEventHandlers)for(let s in r.domEventHandlers){let o=r.domEventHandlers[s];o&&t(s).handlers.push(qu(n.value,o))}if(r&&r.domEventObservers)for(let s in r.domEventObservers){let o=r.domEventObservers[s];o&&t(s).observers.push(qu(n.value,o))}}for(let n in ht)t(n).handlers.push(ht[n]);for(let n in it)t(n).observers.push(it[n]);return e}var Fd=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],jy="dthko",Hd=[16,17,18,20,91,92,224,225],Vs=6;function Ls(i){return Math.max(0,i)*.7+8}function zy(i,e){return Math.max(Math.abs(i.clientX-e.clientX),Math.abs(i.clientY-e.clientY))}var jl=class{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=cy(e.contentDOM),this.atoms=e.state.facet(xh).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(N.allowMultipleSelections)&&Uy(e,t),this.dragging=Hy(e,t)&&Jd(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){var t;if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&zy(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let n=0,r=0,s=((t=this.scrollParent)===null||t===void 0?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=jd(this.view);e.clientX-o.left<=s.left+Vs?n=-Ls(s.left-e.clientX):e.clientX+o.right>=s.right-Vs&&(n=Ls(e.clientX-s.right)),e.clientY-o.top<=s.top+Vs?r=-Ls(s.top-e.clientY):e.clientY+o.bottom>=s.bottom-Vs&&(r=Ls(e.clientY-s.bottom)),this.setScrollSpeed(n,r)}up(e){this.dragging==null&&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(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let n=0;nt.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Uy(i,e){let t=i.state.facet(Ad);return t.length?t[0](e):Q.mac?e.metaKey:e.ctrlKey}function Fy(i,e){let t=i.state.facet(Qd);return t.length?t[0](e):Q.mac?!e.altKey:!e.ctrlKey}function Hy(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=ar(i.root);if(!n||n.rangeCount==0)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Gy(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,n;t!=i.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(n=J.get(t))&&n.ignoreEvent(e))return!1;return!0}var ht=Object.create(null),it=Object.create(null),Gd=Q.ie&&Q.ie_version<15||Q.ios&&Q.webkit_version<604;function Yy(i){let e=i.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{i.focus(),t.remove(),Yd(i,t.value)},50)}function Yd(i,e){let{state:t}=i,n,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(zl!=null&&t.selection.ranges.every(l=>l.empty)&&zl==s.toString()){let l=-1;n=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==l)return{range:h};l=c.from;let f=t.toText((o?s.line(r++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:S.cursor(h.from+f.length)}})}else o?n=t.changeByRange(l=>{let h=s.line(r++);return{changes:{from:l.from,to:l.to,insert:h.text},range:S.cursor(l.from+h.length)}}):n=t.replaceSelection(s);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}it.scroll=i=>{i.inputState.lastScrollTop=i.scrollDOM.scrollTop,i.inputState.lastScrollLeft=i.scrollDOM.scrollLeft};ht.keydown=(i,e)=>(i.inputState.setSelectionOrigin("select"),e.keyCode==27&&i.inputState.tabFocusMode!=0&&(i.inputState.tabFocusMode=Date.now()+2e3),!1);it.touchstart=(i,e)=>{i.inputState.lastTouchTime=Date.now(),i.inputState.setSelectionOrigin("select.pointer")};it.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};ht.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let n of i.state.facet(Md))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=Ky(i,e)),t){let n=!i.hasFocus;i.inputState.startMouseSelection(new jl(i,e,t,n)),n&&i.observer.ignore(()=>{ud(i.contentDOM);let s=i.root.activeElement;s&&!s.contains(i.contentDOM)&&s.blur()});let r=i.inputState.mouseSelection;if(r)return r.start(e),r.dragging===!1}return!1};function Bu(i,e,t,n){if(n==1)return S.cursor(e,t);if(n==2)return $y(i.state,e,t);{let r=be.find(i.docView,e),s=i.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,a=r?r.posAtEnd:s.to;return ai>=e.top&&i<=e.bottom,Xu=(i,e,t)=>Zd(e,t)&&i>=t.left&&i<=t.right;function Zy(i,e,t,n){let r=be.find(i.docView,e);if(!r)return 1;let s=e-r.posAtStart;if(s==0)return 1;if(s==r.length)return-1;let o=r.coordsAt(s,-1);if(o&&Xu(t,n,o))return-1;let a=r.coordsAt(s,1);return a&&Xu(t,n,a)?1:o&&Zd(n,o)?-1:1}function Wu(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Zy(i,t,e.clientX,e.clientY)}}var Jy=Q.ie&&Q.ie_version<=11,Iu=null,Nu=0,ju=0;function Jd(i){if(!Jy)return i.detail;let e=Iu,t=ju;return Iu=i,ju=Date.now(),Nu=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?(Nu+1)%3:1}function Ky(i,e){let t=Wu(i,e),n=Jd(e),r=i.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),r=r.map(s.changes))},get(s,o,a){let l=Wu(i,s),h,c=Bu(i,l.pos,l.bias,n);if(t.pos!=l.pos&&!o){let f=Bu(i,t.pos,t.bias,n),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u1&&(h=eb(r,l.pos))?h:a?r.addRange(c):S.create([c])}}}function eb(i,e){for(let t=0;t=e)return S.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}return null}ht.dragstart=(i,e)=>{let{selection:{main:t}}=i.state;if(e.target.draggable){let r=i.docView.nearest(e.target);if(r&&r.isWidget){let s=r.posAtStart,o=s+r.length;(s>=t.to||o<=t.from)&&(t=S.range(s,o))}}let{inputState:n}=i;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",i.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove"),!1};ht.dragend=i=>(i.inputState.draggedContent=null,!1);function zu(i,e,t,n){if(!t)return;let r=i.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=i.inputState,o=n&&s&&Fy(i,e)?{from:s.from,to:s.to}:null,a={from:r,insert:t},l=i.state.changes(o?[o,a]:a);i.focus(),i.dispatch({changes:l,selection:{anchor:l.mapPos(r,-1),head:l.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),i.inputState.draggedContent=null}ht.drop=(i,e)=>{if(!e.dataTransfer)return!1;if(i.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let n=Array(t.length),r=0,s=()=>{++r==t.length&&zu(i,e,n.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(a.result)||(n[o]=a.result),s()},a.readAsText(t[o])}return!0}else{let n=e.dataTransfer.getData("Text");if(n)return zu(i,e,n,!0),!0}return!1};ht.paste=(i,e)=>{if(i.state.readOnly)return!0;i.observer.flush();let t=Gd?null:e.clipboardData;return t?(Yd(i,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Yy(i),!1)};function tb(i,e){let t=i.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),i.focus()},50)}function ib(i){let e=[],t=[],n=!1;for(let r of i.selection.ranges)r.empty||(e.push(i.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of i.selection.ranges){let o=i.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),r=o.number}n=!0}return{text:e.join(i.lineBreak),ranges:t,linewise:n}}var zl=null;ht.copy=ht.cut=(i,e)=>{let{text:t,ranges:n,linewise:r}=ib(i.state);if(!t&&!r)return!1;zl=r?t:null,e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=Gd?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(tb(i,t),!1)};var Kd=Le.define();function ep(i,e){let t=[];for(let n of i.facet($d)){let r=n(i,e);r&&t.push(r)}return t?i.update({effects:t,annotations:Kd.of(!0)}):null}function tp(i){setTimeout(()=>{let e=i.hasFocus;if(e!=i.inputState.notifiedFocused){let t=ep(i.state,e);t?i.dispatch(t):i.update([])}},10)}it.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),tp(i)};it.blur=i=>{i.observer.clearSelectionRange(),tp(i)};it.compositionstart=it.compositionupdate=i=>{i.observer.editContext||(i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0&&(i.inputState.composing=0))};it.compositionend=i=>{i.observer.editContext||(i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionPendingKey=!0,i.inputState.compositionPendingChange=i.observer.pendingRecords().length>0,i.inputState.compositionFirstChange=null,Q.chrome&&Q.android?i.observer.flushSoon():i.inputState.compositionPendingChange?Promise.resolve().then(()=>i.observer.flush()):setTimeout(()=>{i.inputState.composing<0&&i.docView.hasComposition&&i.update([])},50))};it.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};ht.beforeinput=(i,e)=>{var t;let n;if(Q.chrome&&Q.android&&(n=Fd.find(r=>r.inputType==e.inputType))&&(i.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var s;(((s=window.visualViewport)===null||s===void 0?void 0:s.height)||0)>r+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}return Q.ios&&e.inputType=="deleteContentForward"&&i.observer.flushSoon(),Q.safari&&e.inputType=="insertText"&&i.inputState.composing>=0&&setTimeout(()=>it.compositionend(i,e),20),!1};var Uu=new Set;function nb(i){Uu.has(i)||(Uu.add(i),i.addEventListener("copy",()=>{}),i.addEventListener("cut",()=>{}))}var Fu=["pre-wrap","normal","pre-line","break-spaces"],Ul=class{constructor(e){this.lineWrapping=e,this.doc=W.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Fu.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n-1,l=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=a;if(this.lineWrapping=a,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=s,l){this.heightSamples={};for(let h=0;h0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>zs&&(e.heightChanged=!0),this.height=t)}replace(e,t,n){return i.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let s=this,o=n.doc;for(let a=r.length-1;a>=0;a--){let{fromA:l,toA:h,fromB:c,toB:f}=r[a],u=s.lineAt(l,K.ByPosNoHeight,n.setDoc(t),0,0),d=u.to>=h?u:s.lineAt(h,K.ByPosNoHeight,n,0,0);for(f+=d.to-h,h=d.to;a>0&&u.from<=r[a-1].toA;)l=r[a-1].fromA,c=r[a-1].fromB,a--,ls*2){let a=e[t-1];a.break?e.splice(--t,1,a.left,null,a.right):e.splice(--t,1,a.left,a.right),n+=1+a.break,r-=a.size}else if(s>r*2){let a=e[n];a.break?e.splice(n,1,a.left,null,a.right):e.splice(n,1,a.left,a.right),n+=2+a.break,s-=a.size}else break;else if(r=s&&o(this.blockAt(0,n,r,s))}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setHeight(e,r.heights[r.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},tt=class i extends to{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,n,r){return new yt(r,this.length,n,this.height,this.breaks)}replace(e,t,n){let r=n[0];return n.length==1&&(r instanceof i||r instanceof Yt&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof Yt?r=new i(r.length,this.height):r.height=this.height,this.outdated||(r.outdated=!1),r):je.of(n)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setHeight(e,r.heights[r.index++]):(n||this.outdated)&&this.setHeight(e,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:""})`}},Yt=class i extends je{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,o,a=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);o=l/s,this.length>s+1&&(a=(this.height-l)/(this.length-s-1))}else o=this.height/s;return{firstLine:n,lastLine:r,perLine:o,perChar:a}}blockAt(e,t,n,r){let{firstLine:s,lastLine:o,perLine:a,perChar:l}=this.heightMetrics(t,r);if(t.lineWrapping){let h=r+(e0){let s=n[n.length-1];s instanceof i?n[n.length-1]=new i(s.length+r):n.push(null,new i(r-1))}if(e>0){let s=n[0];s instanceof i?n[0]=new i(e+s.length):n.unshift(new i(e-1),null)}return je.of(n)}decomposeLeft(e,t){t.push(new i(e-1),null)}decomposeRight(e,t){t.push(null,new i(this.length-e-1))}updateHeight(e,t=0,n=!1,r){let s=t+this.length;if(r&&r.from<=t+this.length&&r.more){let o=[],a=Math.max(t,r.from),l=-1;for(r.from>t&&o.push(new i(r.from-t-1).updateHeight(e,t));a<=s&&r.more;){let c=e.doc.lineAt(a).length;o.length&&o.push(null);let f=r.heights[r.index++];l==-1?l=f:Math.abs(f-l)>=zs&&(l=-2);let u=new tt(c,f);u.outdated=!1,o.push(u),a+=c+1}a<=s&&o.push(null,new i(s-a).updateHeight(e,a));let h=je.of(o);return(l<0||Math.abs(h.height-this.height)>=zs||Math.abs(l-this.heightMetrics(e,t).perLine)>=zs)&&(e.heightChanged=!0),h}else(n||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Hl=class extends je{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let s=n+this.left.height;return ea))return h;let c=t==K.ByPosNoHeight?K.ByPosNoHeight:K.ByPos;return l?h.join(this.right.lineAt(a,c,n,o,a)):this.left.lineAt(a,c,n,r,s).join(h)}forEachLine(e,t,n,r,s,o){let a=r+this.left.height,l=s+this.left.length+this.break;if(this.break)e=l&&this.right.forEachLine(e,t,n,a,l,o);else{let h=this.lineAt(l,K.ByPos,n,r,s);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,n,a,l,o)}}replace(e,t,n){let r=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let a of n)s.push(a);if(e>0&&Hu(s,o-1),t=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e2*t.size||t.size>2*e.size?je.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=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,n=!1,r){let{left:s,right:o}=this,a=t+s.length+this.break,l=null;return r&&r.from<=t+s.length&&r.more?l=s=s.updateHeight(e,t,n,r):s.updateHeight(e,t,n),r&&r.from<=a+o.length&&r.more?l=o=o.updateHeight(e,a,n,r):o.updateHeight(e,a,n),l?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Hu(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof Yt&&(n=i[e+1])instanceof Yt&&i.splice(e-1,3,new Yt(t.length+1+n.length))}var rb=5,Gl=class i{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 n=Math.min(t,this.lineEnd),r=this.nodes[this.nodes.length-1];r instanceof tt?r.length+=n-this.pos:(n>this.pos||!this.isCovered)&&this.nodes.push(new tt(n-this.pos,-1)),this.writtenTo=n,t>n&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e=rb)&&this.addLineDeco(r,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new tt(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let n=new Yt(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof tt)return e;let t=new tt(0,-1);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,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos=this.pos+n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof tt)&&!this.isCovered?this.nodes.push(new tt(0,-1)):(this.writtenToc.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let u=c.getBoundingClientRect();s=Math.max(s,u.left),o=Math.min(o,u.right),a=Math.max(a,u.top),l=h==i.parentNode?u.bottom:Math.min(l,u.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:a-(t.top+e),bottom:Math.max(a,l)-(t.top+e)}}function ab(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var rr=class{constructor(e,t,n){this.from=e,this.to=t,this.size=n}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;ntypeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Ul(t),this.stateDeco=e.facet(dr).filter(n=>typeof n!="function"),this.heightMap=je.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle.setDoc(e.doc),[new wt(0,0,0,e.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=M.set(this.lineGaps.map(n=>n.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:s,to:o})=>r>=s&&r<=o)){let{from:s,to:o}=this.lineBlockAt(r);e.push(new rn(s,o))}}return this.viewports=e.sort((n,r)=>n.from-r.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Gu:new Jl(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(Zn(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=this.state.facet(dr).filter(c=>typeof c!="function");let r=e.changedRanges,s=wt.extendWithRanges(r,sb(n,this.stateDeco,e?e.changes:Ae.empty(this.state.doc.length))),o=this.heightMap.height,a=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),this.heightMap.height!=o&&(e.flags|=2),a?(this.scrollAnchorPos=e.changes.mapPos(a.from,-1),this.scrollAnchorHeight=a.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let h=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&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(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Ld)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,s=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?H.RTL:H.LTR;let o=this.heightOracle.mustRefreshForWrapping(s),a=t.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=a.height;this.contentDOMHeight=a.height,this.mustMeasureContent=!1;let h=0,c=0;if(a.width&&a.height){let{scaleX:x,scaleY:w}=fd(t,a);(x>.005&&Math.abs(this.scaleX-x)>.005||w>.005&&Math.abs(this.scaleY-w)>.005)&&(this.scaleX=x,this.scaleY=w,h|=8,o=l=!0)}let f=(parseInt(n.paddingTop)||0)*this.scaleY,u=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=pd(e.scrollDOM);let m=(this.printing?ab:ob)(t,this.paddingTop),p=m.top-this.pixelViewport.top,g=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let O=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(O!=this.inView&&(this.inView=O,O&&(l=!0)),!this.inView&&!this.scrollTarget)return 0;let y=a.width;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=a.width,this.editorHeight=e.scrollDOM.clientHeight,h|=8),l){let x=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(x)&&(o=!0),o||r.lineWrapping&&Math.abs(y-this.contentDOMWidth)>r.charWidth){let{lineHeight:w,charWidth:P,textHeight:C}=e.docView.measureTextSize();o=w>0&&r.refresh(s,w,P,C,y/P,x),o&&(e.docView.minWidth=0,h|=8)}p>0&&g>0?c=Math.max(p,g):p<0&&g<0&&(c=Math.min(p,g)),r.heightChanged=!1;for(let w of this.viewports){let P=w.from==this.viewport.from?x:e.docView.measureVisibleLineHeights(w);this.heightMap=(o?je.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle,[new wt(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new Fl(w.from,P))}r.heightChanged&&(h|=2)}let v=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return v&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:a}=this,l=new rn(r.lineAt(o-n*1e3,K.ByHeight,s,0,0).from,r.lineAt(a+(1-n)*1e3,K.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(hl.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=r.lineAt(h,K.ByPos,s,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h=a+Math.max(10,Math.min(n,250)))&&r>o-2*1e3&&s>1,o=r<<1;if(this.defaultTextDirection!=H.LTR&&!n)return[];let a=[],l=(c,f,u,d)=>{if(f-cc&&OO.from>=u.from&&O.to<=u.to&&Math.abs(O.from-c)O.fromy));if(!g){if(fO.from<=f&&O.to>=f)){let O=t.moveToLineBoundary(S.cursor(f),!1,!0).head;O>c&&(f=O)}g=new rr(c,f,this.gapSize(u,c,f,d))}a.push(g)},h=c=>{if(c.lengthc.from&&l(c.from,d,c,f),mt.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];j.spans(e,this.viewport.from,this.viewport.to,{span(r,s){t.push({from:r,to:s})},point(){}},20);let n=t.length!=this.visibleRanges.length||this.visibleRanges.some((r,s)=>r.from!=t[s].from||r.to!=t[s].to);return this.visibleRanges=t,n?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Zn(this.heightMap.lineAt(e,K.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)||Zn(this.heightMap.lineAt(this.scaler.fromDOM(e),K.ByHeight,this.heightOracle,0,0),this.scaler)}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 Zn(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}},rn=class{constructor(e,t){this.from=e,this.to=t}};function lb(i,e,t){let n=[],r=i,s=0;return j.spans(t,i,e,{span(){},point(o,a){o>r&&(n.push({from:r,to:o}),s+=o-r),r=a}},20),r=1)return e[e.length-1].to;let n=Math.floor(i*t);for(let r=0;;r++){let{from:s,to:o}=e[r],a=o-s;if(n<=a)return s+n;n-=a}}function Bs(i,e){let t=0;for(let{from:n,to:r}of i.ranges){if(e<=r){t+=e-n;break}t+=r-n}return t/i.total}function hb(i,e){for(let t of i)if(e(t))return t}var Gu={toDOM(i){return i},fromDOM(i){return i},scale:1,eq(i){return i==this}},Jl=class i{constructor(e,t,n){let r=0,s=0,o=0;this.viewports=n.map(({from:a,to:l})=>{let h=t.lineAt(a,K.ByPos,e,0,0).top,c=t.lineAt(l,K.ByPos,e,0,0).bottom;return r+=c-h,{from:a,to:l,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let a of this.viewports)a.domTop=o+(a.top-s)*this.scale,o=a.domBottom=a.domTop+(a.bottom-a.top),s=a.bottom}toDOM(e){for(let t=0,n=0,r=0;;t++){let s=tt.from==e.viewports[n].from&&t.to==e.viewports[n].to):!1}};function Zn(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new yt(i.from,i.length,t,n-t,Array.isArray(i._content)?i._content.map(r=>Zn(r,e)):i._content)}var Xs=A.define({combine:i=>i.join(" ")}),Kl=A.define({combine:i=>i.indexOf(!0)>-1}),eh=et.newName(),ip=et.newName(),np=et.newName(),rp={"&light":"."+ip,"&dark":"."+np};function th(i,e,t){return new et(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,r=>{if(r=="&")return i;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):i+" "+n}})}var cb=th("."+eh,{"&":{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},".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:"#444"},".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",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&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},"&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-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"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,')`,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"}},rp),Jn="\uFFFF",ih=class{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(N.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Jn}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r);let s=this.text.length;this.readNode(r);let o=r.nextSibling;if(o==t)break;let a=J.get(r),l=J.get(o);(a&&l?a.breakAfter:(a?a.breakAfter:Gs(r))||Gs(o)&&(r.nodeName!="BR"||r.cmIgnore)&&this.text.length>s)&&this.lineBreak(),r=o}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,a;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(a=r.exec(t))&&(s=a.index,o=a[0].length),this.append(t.slice(n,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=o-1);n=s+o}}readNode(e){if(e.cmIgnore)return;let t=J.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let r=n.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(fb(e,n.node,n.offset)?t:0))}};function fb(i,e,t){for(;;){if(!e||t-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,n,0))){let a=s||o?[]:pb(e),l=new ih(a,e.state);l.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=l.text,this.newSel=mb(a,this.bounds.from)}else{let a=e.observer.selectionRange,l=s&&s.node==a.focusNode&&s.offset==a.focusOffset||!El(e.contentDOM,a.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),h=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!El(e.contentDOM,a.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),c=e.viewport;if((Q.ios||Q.chrome)&&e.state.selection.main.empty&&l!=h&&(c.from>0||c.toDate.now()-100?i.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:a}=e.bounds,l=r.from,h=null;(s===8||Q.android&&e.text.length=r.from&&t.to<=r.to&&(t.from!=r.from||t.to!=r.to)&&r.to-r.from-(t.to-t.from)<=4?t={from:r.from,to:r.to,insert:i.state.doc.slice(r.from,t.from).append(t.insert).append(i.state.doc.slice(t.to,r.to))}:(Q.mac||Q.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&i.contentDOM.getAttribute("autocorrect")=="off"?(n&&t.insert.length==2&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:r.from,to:r.to,insert:W.of([" "])}):Q.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
- `&&i.lineWrapping&&(n&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:r.from,to:r.to,insert:W.of([" "])}),t)return op(i,t,n,s);if(n&&!n.main.eq(r)){let o=!1,a="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(o=!0),a=i.inputState.lastSelectionOrigin),i.dispatch({selection:n,scrollIntoView:o,userEvent:a}),!0}else return!1}function op(i,e,t,n=-1){if(Q.ios&&i.inputState.flushIOSKey(e))return!0;let r=i.state.selection.main;if(Q.android&&(e.to==r.to&&(e.from==r.from||e.from==r.from-1&&i.state.sliceDoc(e.from,r.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&an(i.contentDOM,"Enter",13)||(e.from==r.from-1&&e.to==r.to&&e.insert.length==0||n==8&&e.insert.lengthr.head)&&an(i.contentDOM,"Backspace",8)||e.from==r.from&&e.to==r.to+1&&e.insert.length==0&&an(i.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();i.inputState.composing>=0&&i.inputState.composing++;let o,a=()=>o||(o=ub(i,e,t));return i.state.facet(Dd).some(l=>l(i,e.from,e.to,s,a))||i.dispatch(a()),!0}function ub(i,e,t){let n,r=i.state,s=r.selection.main;if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&i.inputState.composing<0){let a=s.frome.to?r.sliceDoc(e.to,s.to):"";n=r.replaceSelection(i.state.toText(a+e.insert.sliceString(0,void 0,i.state.lineBreak)+l))}else{let a=r.changes(e),l=t&&t.main.to<=a.newLength?t.main:void 0;if(r.selection.ranges.length>1&&i.inputState.composing>=0&&e.to<=s.to&&e.to>=s.to-10){let h=i.state.sliceDoc(e.from,e.to),c,f=t&&zd(i,t.main.head);if(f){let m=e.insert.length-(e.to-e.from);c={from:f.from,to:f.to-m}}else c=i.state.doc.lineAt(s.head);let u=s.to-e.to,d=s.to-s.from;n=r.changeByRange(m=>{if(m.from==s.from&&m.to==s.to)return{changes:a,range:l||m.map(a)};let p=m.to-u,g=p-h.length;if(m.to-m.from!=d||i.state.sliceDoc(g,p)!=h||m.to>=c.from&&m.from<=c.to)return{range:m};let O=r.changes({from:g,to:p,insert:e.insert}),y=m.to-s.to;return{changes:O,range:l?S.range(Math.max(0,l.anchor+y),Math.max(0,l.head+y)):m.map(O)}})}else n={changes:a,selection:l&&r.selection.replaceRange(l)}}let o="input.type";return(i.composing||i.inputState.compositionPendingChange&&i.inputState.compositionEndedAt>Date.now()-50)&&(i.inputState.compositionPendingChange=!1,o+=".compose",i.inputState.compositionFirstChange&&(o+=".start",i.inputState.compositionFirstChange=!1)),r.update(n,{userEvent:o,scrollIntoView:!0})}function db(i,e,t,n){let r=Math.min(i.length,e.length),s=0;for(;s0&&a>0&&i.charCodeAt(o-1)==e.charCodeAt(a-1);)o--,a--;if(n=="end"){let l=Math.max(0,s-Math.min(o,a));t-=o+l-s}if(o=o?s-t:0;s-=l,a=s+(a-o),o=s}else if(a=a?s-t:0;s-=l,o=s+(o-a),a=s}return{from:s,toA:o,toB:a}}function pb(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}=i.observer.selectionRange;return t&&(e.push(new no(t,n)),(r!=t||s!=n)&&e.push(new no(r,s))),e}function mb(i,e){if(i.length==0)return null;let t=i[0].pos,n=i.length==2?i[1].pos:t;return t>-1&&n>-1?S.single(t+e,n+e):null}var gb={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Tl=Q.ie&&Q.ie_version<=11,rh=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Al,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 n of t)this.queue.push(n);(Q.ie&&Q.ie_version<=11||Q.ios&&e.composing)&&t.some(n=>n.type=="childList"&&n.removedNodes.length||n.type=="characterData"&&n.oldValue.length>n.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&e.constructor.EDIT_CONTEXT!==!1&&!(Q.chrome&&Q.chrome_version<126)&&(this.editContext=new sh(e),e.state.facet(Ht)&&(e.contentDOM.editContext=this.editContext.editContext)),Tl&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.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")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.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(t=>{t.length>0&&t[t.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){e.type=="change"&&!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,n)=>t!=e[n]))){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:n}=this,r=this.selectionRange;if(n.state.facet(Ht)?n.root.activeElement!=this.dom:!Ns(n.dom,r))return;let s=r.anchorNode&&n.docView.nearest(r.anchorNode);if(s&&s.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(Q.ie&&Q.ie_version<=11||Q.android&&Q.chrome)&&!n.state.selection.main.empty&&r.focusNode&&er(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=ar(e.root);if(!t)return!1;let n=Q.safari&&e.root.nodeType==11&&ay(this.dom.ownerDocument)==this.dom&&Ob(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=Ns(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&an(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{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,n=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!0),t==-1?{from:t,to:n}=o:(t=Math.min(o.from,t),n=Math.max(o.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&Ns(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new nh(this.view,e,t,n);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}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 n=this.view.state,r=sp(this.view,t);return this.view.state==n&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),r}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let n=Yu(t,e.previousSibling||e.target.previousSibling,-1),r=Yu(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{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("change",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("change",this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Ht)!=e.state.facet(Ht)&&(e.view.contentDOM.editContext=e.state.facet(Ht)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resizeScroll)===null||n===void 0||n.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}};function Yu(i,e,t){for(;e;){let n=J.get(e);if(n&&n.parent==i)return n;let r=e.parentNode;e=r!=i.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function Zu(i,e){let t=e.startContainer,n=e.startOffset,r=e.endContainer,s=e.endOffset,o=i.docView.domAtPos(i.state.selection.main.anchor);return er(o.node,o.offset,r,s)&&([t,n,r,s]=[r,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}}function Ob(i,e){if(e.getComposedRanges){let r=e.getComposedRanges(i.root)[0];if(r)return Zu(i,r)}let t=null;function n(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return i.contentDOM.addEventListener("beforeinput",n,!0),i.dom.ownerDocument.execCommand("indent"),i.contentDOM.removeEventListener("beforeinput",n,!0),t?Zu(i,t):null}var sh=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=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)});t.addEventListener("textupdate",n=>{let{anchor:r}=e.state.selection.main,s={from:this.toEditorPos(n.updateRangeStart),to:this.toEditorPos(n.updateRangeEnd),insert:W.of(n.text.split(`
-`))};s.from==this.from&&rthis.to&&(s.to=r),!(s.from==s.to&&!s.insert.length)&&(this.pendingContextChange=s,op(e,s,S.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd))),this.pendingContextChange&&this.revertPending(e.state))}),t.addEventListener("characterboundsupdate",n=>{let r=[],s=null;for(let o=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);o{let r=[];for(let s of n.getTextFormats()){let o=s.underlineStyle,a=s.underlineThickness;if(o!="None"&&a!="None"){let l=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${a=="Thin"?1:2}px`;r.push(M.mark({attributes:{style:l}}).range(this.toEditorPos(s.rangeStart),this.toEditorPos(s.rangeEnd)))}}e.dispatch({effects:Bd.of(M.set(r))})}),t.addEventListener("compositionstart",()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)}),t.addEventListener("compositionend",()=>{e.inputState.composing=-1,e.inputState.compositionFirstChange=null}),this.measureReq={read:n=>{this.editContext.updateControlBounds(n.contentDOM.getBoundingClientRect());let r=ar(n.root);r&&r.rangeCount&&this.editContext.updateSelectionBounds(r.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((s,o,a,l,h)=>{if(n)return;let c=h.length-(o-s);if(r&&o>=r.to)if(r.from==s&&r.to==o&&r.insert.eq(h)){r=this.pendingContextChange=null,t+=c;return}else r=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(sthis.to||this.to-this.from+h.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),r&&!n&&this.revertPending(e.state),!n}update(e){!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.resetRange(e.state),this.editContext.updateText(0,this.editContext.text.length,e.state.doc.sliceString(this.from,this.to)),this.setSelection(e.state)):(e.docChanged||e.selectionSet)&&this.setSelection(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)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.to+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to1e4*3)}toEditorPos(e){return e+this.from}toContextPos(e){return e-this.from}},E=class i{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.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){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:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(n=>n.forEach(r=>t(r,this)))||(n=>this.update(n)),this.dispatch=this.dispatch.bind(this),this._root=e.root||fy(e.parent)||document,this.viewState=new io(e.state||N.create(e)),e.scrollTo&&e.scrollTo.is($s)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Gn).map(n=>new nr(n));for(let n of this.plugins)n.update(this);this.observer=new rh(this),this.inputState=new Nl(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ks(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...e){let t=e.length==1&&e[0]instanceof fe?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,n=!1,r,s=this.state;for(let u of e){if(u.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=u.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,a=0,l=null;e.some(u=>u.annotation(Kd))?(this.inputState.notifiedFocused=o,a=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,l=ep(s,o),l||(a=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(N.phrases)!=this.state.facet(N.phrases))return this.setState(s);r=Js.create(this,s,e),r.flags|=a;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new ir(d.empty?d:S.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is($s)&&(f=d.value.clip(this.state))}this.viewState.update(r,f),this.bidiCache=ro.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(Yn)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(Xs)!=r.state.facet(Xs)&&(this.viewState.mustMeasureContent=!0),(t||n||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let u of this.state.facet(Xl))try{u(r)}catch(d){we(this.state,d,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!sp(this,c)&&h.force&&an(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let n of this.plugins)n.destroy(this);this.viewState=new io(e),this.plugins=e.facet(Gn).map(n=>new nr(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView.destroy(),this.docView=new Ks(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(Gn),n=e.state.facet(Gn);if(t!=n){let r=[];for(let s of n){let o=t.indexOf(s);if(o<0)r.push(new nr(s));else{let a=this.plugins[o];a.mustUpdate=e,r.push(a)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.scrollDOM,r=n.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:o}=this.viewState;Math.abs(r-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0)if(pd(n))s=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(r);s=d.from,o=d.top}this.updateState=1;let l=this.viewState.measure(this);if(!l&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];l&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(d=>{try{return d.read(this)}catch(m){return we(this.state,m),Ju}}),f=Js.create(this,this.state,[]),u=!1;f.flags|=l,t?t.flags|=l:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f),u&&this.docViewUpdate());for(let d=0;d1||m<-1){r=r+m,n.scrollTop=r/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let a of this.state.facet(Xl))a(t)}get themeClasses(){return eh+" "+(this.state.facet(Kl)?np:ip)+" "+this.state.facet(Xs)}updateAttrs(){let e=Ku(this,Xd,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Ht)?"true":"false",class:"cm-content",style:`${Q.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Ku(this,vh,t);let n=this.observer.ignore(()=>{let r=$l(this.contentDOM,this.contentAttrs,t),s=$l(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let r of n.effects)if(r.is(i.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(Yn);let e=this.state.facet(i.cspNonce);et.mount(this.root,this.styleModules.concat(cb).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&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(e.key!=null){for(let t=0;tn.spec==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,n){return Sl(this,e,Lu(this,e,t,n))}moveByGroup(e,t){return Sl(this,e,Lu(this,e,t,n=>Wy(this,e.head,n)))}visualLineSide(e,t){let n=this.bidiSpans(e),r=this.textDirectionAt(e.from),s=n[t?n.length-1:0];return S.cursor(s.side(t,r)+e.from,s.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,n=!0){return Xy(this,e,t,n)}moveVertically(e,t,n){return Sl(this,e,Iy(this,e,t,n))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Ud(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.docView.coordsAt(e,t);if(!n||n.left==n.right)return n;let r=this.state.doc.lineAt(e),s=this.bidiSpans(r),o=s[bt.find(s,e-r.from,-1,t)];return yh(n,o.dir==H.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(Vd)||e