@origintrail-official/dkg-node-ui 0.0.1-dev.1773506972.23bf9c0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +49 -0
  3. package/dist/api.d.ts +30 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +805 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/chat-assistant.d.ts +68 -0
  8. package/dist/chat-assistant.d.ts.map +1 -0
  9. package/dist/chat-assistant.js +663 -0
  10. package/dist/chat-assistant.js.map +1 -0
  11. package/dist/chat-memory.d.ts +171 -0
  12. package/dist/chat-memory.d.ts.map +1 -0
  13. package/dist/chat-memory.js +985 -0
  14. package/dist/chat-memory.js.map +1 -0
  15. package/dist/chat-persistence-queue.d.ts +67 -0
  16. package/dist/chat-persistence-queue.d.ts.map +1 -0
  17. package/dist/chat-persistence-queue.js +245 -0
  18. package/dist/chat-persistence-queue.js.map +1 -0
  19. package/dist/db.d.ts +402 -0
  20. package/dist/db.d.ts.map +1 -0
  21. package/dist/db.js +887 -0
  22. package/dist/db.js.map +1 -0
  23. package/dist/gelf-push-worker.d.ts +67 -0
  24. package/dist/gelf-push-worker.d.ts.map +1 -0
  25. package/dist/gelf-push-worker.js +147 -0
  26. package/dist/gelf-push-worker.js.map +1 -0
  27. package/dist/index.d.ts +20 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +12 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/llm/capability-resolver.d.ts +3 -0
  32. package/dist/llm/capability-resolver.d.ts.map +1 -0
  33. package/dist/llm/capability-resolver.js +21 -0
  34. package/dist/llm/capability-resolver.js.map +1 -0
  35. package/dist/llm/client.d.ts +23 -0
  36. package/dist/llm/client.d.ts.map +1 -0
  37. package/dist/llm/client.js +91 -0
  38. package/dist/llm/client.js.map +1 -0
  39. package/dist/llm/provider-adapter.d.ts +16 -0
  40. package/dist/llm/provider-adapter.d.ts.map +1 -0
  41. package/dist/llm/provider-adapter.js +199 -0
  42. package/dist/llm/provider-adapter.js.map +1 -0
  43. package/dist/llm/types.d.ts +64 -0
  44. package/dist/llm/types.d.ts.map +1 -0
  45. package/dist/llm/types.js +2 -0
  46. package/dist/llm/types.js.map +1 -0
  47. package/dist/metrics-collector.d.ts +36 -0
  48. package/dist/metrics-collector.d.ts.map +1 -0
  49. package/dist/metrics-collector.js +155 -0
  50. package/dist/metrics-collector.js.map +1 -0
  51. package/dist/operation-tracker.d.ts +43 -0
  52. package/dist/operation-tracker.d.ts.map +1 -0
  53. package/dist/operation-tracker.js +195 -0
  54. package/dist/operation-tracker.js.map +1 -0
  55. package/dist/structured-logger.d.ts +16 -0
  56. package/dist/structured-logger.d.ts.map +1 -0
  57. package/dist/structured-logger.js +41 -0
  58. package/dist/structured-logger.js.map +1 -0
  59. package/dist/telemetry.d.ts +35 -0
  60. package/dist/telemetry.d.ts.map +1 -0
  61. package/dist/telemetry.js +45 -0
  62. package/dist/telemetry.js.map +1 -0
  63. package/dist-ui/assets/3d-force-graph-nMUNmvtB.js +964 -0
  64. package/dist-ui/assets/AgentHub-XKCM9uYQ.js +65 -0
  65. package/dist-ui/assets/AppHost-DoLIi89g.js +1 -0
  66. package/dist-ui/assets/Apps-Cc8HfqfD.js +1 -0
  67. package/dist-ui/assets/Dashboard-D5q6MK78.js +2 -0
  68. package/dist-ui/assets/Explorer-B80RVksc.js +64 -0
  69. package/dist-ui/assets/N3Parser-Q_-1ZY5E.js +7 -0
  70. package/dist-ui/assets/Settings-CG7-7GM-.js +71 -0
  71. package/dist-ui/assets/hooks-BLTFNmyP.js +1 -0
  72. package/dist-ui/assets/index-8_35CUX2.js +192 -0
  73. package/dist-ui/assets/index-CKZq_ZB-.css +1 -0
  74. package/dist-ui/assets/index-DH-l6lM0.js +76 -0
  75. package/dist-ui/assets/jsonld-32FQRO67-DhbO8O6B.js +2 -0
  76. package/dist-ui/assets/jsonld-BFI4wECl.js +62 -0
  77. package/dist-ui/assets/ntriples-ZWBY2WET-nIpilpjf.js +1 -0
  78. package/dist-ui/assets/ordinal-DIohFSkg.js +1 -0
  79. package/dist-ui/assets/renderer-3d-2EVDZII7-DsxBsJvs.js +2 -0
  80. package/dist-ui/assets/three.module-uCjFke6H.js +4019 -0
  81. package/dist-ui/assets/turtle-JJPK7LJ5-zezDJZEp.js +1 -0
  82. package/dist-ui/favicon.png +0 -0
  83. package/dist-ui/index.html +14 -0
  84. package/package.json +58 -0
@@ -0,0 +1,64 @@
1
+ import{j as g,N as Cs,m as pa,n as Nt,o as As,f as So,r as P,p as ga,q as Bt,s as ma,u as xa}from"./index-DH-l6lM0.js";import{u as vo,s as ya}from"./hooks-BLTFNmyP.js";import{R as Co,u as ba}from"./index-8_35CUX2.js";import"./ordinal-DIohFSkg.js";let Ys=[],Ao=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?Ao:Ys).push(t=t+n[e])})();function ka(n){if(n<768)return!1;for(let e=0,t=Ys.length;;){let i=e+t>>1;if(n<Ys[i])t=i;else if(n>=Ao[i])e=i+1;else return!0;if(e==t)return!1}}function or(n){return n>=127462&&n<=127487}const lr=8205;function wa(n,e,t=!0,i=!0){return(t?Oo:Sa)(n,e,i)}function Oo(n,e,t){if(e==n.length)return e;e&&To(n.charCodeAt(e))&&Mo(n.charCodeAt(e-1))&&e--;let i=Os(n,e);for(e+=ar(i);e<n.length;){let s=Os(n,e);if(i==lr||s==lr||t&&ka(s))e+=ar(s),i=s;else if(or(s)){let r=0,o=e-2;for(;o>=0&&or(Os(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Sa(n,e,t){for(;e>0;){let i=Oo(n,e-2,t);if(i<e)return i;e--}return 0}function Os(n,e){let t=n.charCodeAt(e);if(!Mo(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return To(i)?(t-55296<<10)+(i-56320)+65536:t}function To(n){return n>=56320&&n<57344}function Mo(n){return n>=55296&&n<56320}function ar(n){return n<65536?1:2}class Q{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=zt(this,e,t);let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),qe.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=zt(this,e,t);let i=[];return this.decompose(e,t,i,0),qe.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new si(this),r=new si(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new si(this,e)}iterRange(e,t=this.length){return new Ro(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Po(i)}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]?Q.empty:e.length<=32?new re(e):qe.from(re.split(e,[]))}}class re extends Q{constructor(e,t=va(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new Ca(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new re(hr(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=zi(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new re(l,o.length+r.length));else{let a=l.length>>1;i.push(new re(l.slice(0,a)),new re(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof re))return super.replace(e,t,i);[e,t]=zt(this,e,t);let s=zi(this.text,zi(i.text,hr(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new re(s,r):qe.from(re.split(s,[]),r)}sliceString(e,t=this.length,i=`
2
+ `){[e,t]=zt(this,e,t);let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new re(i,s)),i=[],s=-1);return s>-1&&t.push(new re(i,s)),t}}class qe extends Q{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=zt(this,e,t),i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[s]=a,new qe(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
3
+ `){[e,t]=zt(this,e,t);let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof qe))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new re(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>r&&d instanceof qe)for(let m of d.children)f(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof re&&a&&(p=c[c.length-1])instanceof re&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new re(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:qe.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new qe(l,t)}}Q.empty=new re([""],0);function va(n){let e=-1;for(let t of n)e+=t.length+1;return e}function zi(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function hr(n,e,t){return zi(n,[""],e,t)}class si{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof re?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof re?s.text.length:s.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
4
+ `,this;e--}else if(s instanceof re){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof re?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Ro{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new si(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class Po{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(Q.prototype[Symbol.iterator]=function(){return this.iter()},si.prototype[Symbol.iterator]=Ro.prototype[Symbol.iterator]=Po.prototype[Symbol.iterator]=function(){return this});class Ca{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}}function zt(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Ue(n,e,t=!0,i=!0){return wa(n,e,t,i)}function Aa(n){return n>=56320&&n<57344}function Oa(n){return n>=55296&&n<56320}function Ta(n,e){let t=n.charCodeAt(e);if(!Oa(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Aa(i)?(t-55296<<10)+(i-56320)+65536:t}function Ma(n){return n<65536?1:2}const Zs=/\r\n?|\n/;var Pe=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(Pe||(Pe={}));class Je{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){Js(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new Je(e)}composeDesc(e){return this.empty?e:e.empty?this:No(this,e)}mapDesc(e,t=!1){return e.empty?this:en(this,e,t)}mapPos(e,t=-1,i=Pe.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=s+l;if(a<0){if(h>e)return r+(e-s);r+=l}else{if(i!=Pe.Simple&&h>=e&&(i==Pe.TrackDel&&s<e&&h>e||i==Pe.TrackBefore&&s<e||i==Pe.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=h}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}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 Je(e)}static create(e){return new Je(e)}}class de extends Je{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 Js(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return en(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(Q.empty);i.push(o?e.slice(r,r+o):Q.empty)}r+=o}return new de(t,i)}compose(e){return this.empty?e:e.empty?this:No(this,e,!0)}map(e,t=!1){return e.empty?this:en(this,e,t,!0)}iterChanges(e,t=!1){Js(this,e,t)}get desc(){return Je.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new hi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);ye(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;ye(t,c,f),f>0&&at(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);ye(t,c,-1),ye(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new de(t,i),filtered:Je.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<t&&ye(s,t-o,-1);let f=new de(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof de){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?Q.of(d.split(i||Zs)):d:Q.empty,m=p.length;if(f==u&&m==0)return;f<o&&a(),f>o&&ye(s,f-o,-1),ye(s,u-f,m),at(r,s,p),o=u}}return h(e),a(!l),l}static empty(e){return new de(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(Q.empty);i[s]=Q.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new de(t,i)}static createSet(e,t){return new de(e,t)}}function ye(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:s>=0&&e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function at(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(Q.empty);n.push(t)}}function Js(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let h=s,c=r,f=Q.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,h,r,c,f),s=h,r=c}}}function en(n,e,t,i=!1){let s=[],r=i?[]:null,o=new hi(n),l=new hi(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);ye(s,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(ye(s,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(ye(s,0,o.ins),r&&at(r,s,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;ye(s,h,a<o.i?o.ins:0),r&&a<o.i&&at(r,s,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?de.createSet(s,r):Je.create(s);throw new Error("Mismatched change set lengths")}}}function No(n,e,t=!1){let i=[],s=t?[]:null,r=new hi(n),o=new hi(e);for(let l=!1;;){if(r.done&&o.done)return s?de.createSet(i,s):Je.create(i);if(r.ins==0)ye(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)ye(i,0,o.ins,l),s&&at(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;ye(i,a,c,l),s&&c&&at(s,i,o.text)}else o.ins==-1?(ye(i,r.off?0:r.len,a,l),s&&at(s,i,r.textBit(a))):(ye(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&at(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class hi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?Q.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?Q.empty:t[i].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)}}class St{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}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 i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new St(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return M.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return M.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return M.range(e.anchor,e.head)}static create(e,t,i){return new St(e,t,i)}}class M{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:M.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new M([this.main],0)}addRange(e,t=!0){return M.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,M.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new M(e.ranges.map(t=>St.fromJSON(t)),e.main)}static single(e,t=e){return new M([M.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 i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return M.normalized(e.slice(),t);i=r.to}return new M(e,t)}static cursor(e,t=0,i,s){return St.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(e,t,i,s){let r=(i??16777215)<<6|(s==null?7:Math.min(6,s));return t<e?St.create(t,e,48|r):St.create(e,t,(t>e?8:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?M.range(a,l):M.range(l,a))}}return new M(e,t)}}function Eo(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Fn=0;class L{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=Fn++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new L(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Hn),!!e.static,e.enables)}of(e){return new Vi([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Vi(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Vi(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Hn(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class Vi{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Fn++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||tn(f,c)){let d=i(f);if(l?!cr(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[r];if(p!=null){let m=_i(u,p);if(this.dependencies.every(x=>x instanceof L?u.facet(x)===f.facet(x):x instanceof Rt?u.field(x,!1)==f.field(x,!1):!0)||(l?cr(d=i(f),m,s):s(d=i(f),m)))return f.values[o]=m,0}else d=i(f);return f.values[o]=d,1}}}}function cr(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function tn(n,e){let t=!1;for(let i of e)ni(n,i)&1&&(t=!0);return t}function Ra(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=_i(a,i[c]);if(s[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of i)ni(a,h);return a.values[o]=l(a),1},update(a,h){if(!tn(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=tn(a,i),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&Hn(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Ai=L.define({static:!0});class Rt{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new Rt(Fn++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Ai).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>{let r=i.facet(Ai),o=s.facet(Ai),l;return(l=r.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(i.values[t]=l.create(i),1):s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,Ai.of({field:this,create:e})]}get extension(){return this}}const kt={lowest:4,low:3,default:2,high:1,highest:0};function _t(n){return e=>new Do(e,n)}const gs={highest:_t(kt.highest),high:_t(kt.high),default:_t(kt.default),low:_t(kt.low),lowest:_t(kt.lowest)};class Do{constructor(e,t){this.inner=e,this.prec=t}}class ms{of(e){return new sn(this,e)}reconfigure(e){return ms.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class sn{constructor(e,t){this.compartment=e,this.inner=t}}class Gi{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let u of Pa(e,t,o))u instanceof Rt?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of s)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,m=c&&c[u]||[];if(d.every(x=>x.type==0))if(l[p.id]=a.length<<1|1,Hn(m,d))a.push(i.facet(p));else{let x=p.combine(d.map(y=>y.value));a.push(i&&p.compare(x,i.facet(p))?i.facet(p):x)}else{for(let x of d)x.type==0?(l[x.id]=a.length<<1|1,a.push(x.value)):(l[x.id]=h.length<<1,h.push(y=>x.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(x=>Ra(x,p,d))}}let f=h.map(u=>u(l));return new Gi(e,o,f,l,a,r)}}function Pa(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof sn&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof sn){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),r(h,l)}else if(o instanceof Do)r(o.inner,o.prec);else if(o instanceof Rt)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Vi)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,kt.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.`);r(h,l)}}return r(n,kt.default),i.reduce((o,l)=>o.concat(l))}function ni(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function _i(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const Lo=L.define(),nn=L.define({combine:n=>n.some(e=>e),static:!0}),Bo=L.define({combine:n=>n.length?n[0]:void 0,static:!0}),Io=L.define(),jo=L.define(),Wo=L.define(),Fo=L.define({combine:n=>n.length?n[0]:!1});class Gt{constructor(e,t){this.type=e,this.value=t}static define(){return new Na}}class Na{of(e){return new Gt(this,e)}}class Ea{constructor(e){this.map=e}of(e){return new ue(this,e)}}class ue{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 ue(this.type,t)}is(e){return this.type==e}static define(e={}){return new Ea(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}}ue.reconfigure=ue.define();ue.appendConfig=ue.define();class be{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Eo(i,t.newLength),r.some(l=>l.type==be.time)||(this.annotations=r.concat(be.time.of(Date.now())))}static create(e,t,i,s,r,o){return new be(e,t,i,s,r,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(be.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}be.time=Gt.define();be.userEvent=Gt.define();be.addToHistory=Gt.define();be.remote=Gt.define();function Da(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Ho(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=de.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:ue.mapEffects(n.effects,s).concat(ue.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function rn(n,e,t){let i=e.selection,s=It(e.annotations);return e.userEvent&&(s=s.concat(be.userEvent.of(e.userEvent))),{changes:e.changes instanceof de?e.changes:de.of(e.changes||[],t,n.facet(Bo)),selection:i&&(i instanceof M?i:M.single(i.anchor,i.head)),effects:It(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function zo(n,e,t){let i=rn(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Ho(i,rn(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=be.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Ba(t?La(s):s)}function La(n){let e=n.startState,t=!0;for(let s of e.facet(Io)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:Da(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=de.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=be.create(e,s,n.selection&&n.selection.map(r),ue.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(jo);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof be?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof be?n=r[0]:n=zo(e,It(r),!1)}return n}function Ba(n){let e=n.startState,t=e.facet(Wo),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=Ho(i,rn(e,r,n.changes.newLength),!0))}return i==n?n:be.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const Ia=[];function It(n){return n==null?Ia:Array.isArray(n)?n:[n]}var Ze=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(Ze||(Ze={}));const ja=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let on;try{on=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Wa(n){if(on)return on.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||ja.test(t)))return!0}return!1}function Fa(n){return e=>{if(!/\S/.test(e))return Ze.Space;if(Wa(e))return Ze.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return Ze.Word;return Ze.Other}}class U{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)ni(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return ni(this,i),_i(this,i)}update(...e){return zo(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let l of e.effects)l.is(ms.reconfigure)?(t&&(s=new Map,t.compartments.forEach((a,h)=>s.set(h,a)),t=null),s.set(l.value.compartment,l.value.extension)):l.is(ue.reconfigure)?(t=null,i=l.value):l.is(ue.appendConfig)&&(t=null,i=It(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=Gi.resolve(i,s,this),r=new U(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(nn)?e.newSelection:e.newSelection.asSingle();new U(t,e.newDoc,o,r,(l,a)=>a.update(l,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:M.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=It(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=s.mapDesc(h,!0);r.push(a.range.map(f)),s=s.compose(c),o=ue.mapEffects(o,c).concat(ue.mapEffects(It(a.effects),f))}return{changes:s,selection:M.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof de?e:de.of(e,this.doc.length,this.facet(U.lineSeparator))}toText(e){return Q.of(e.split(this.facet(U.lineSeparator)||Zs))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(ni(this,t),_i(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof Rt&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return U.create({doc:e.doc,selection:M.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=Gi.resolve(e.extensions||[],new Map),i=e.doc instanceof Q?e.doc:Q.of((e.doc||"").split(t.staticFacet(U.lineSeparator)||Zs)),s=e.selection?e.selection instanceof M?e.selection:M.single(e.selection.anchor,e.selection.head):M.single(0);return Eo(s,i.length),t.staticFacet(nn)||(s=s.asSingle()),new U(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(U.tabSize)}get lineBreak(){return this.facet(U.lineSeparator)||`
5
+ `}get readOnly(){return this.facet(Fo)}phrase(e,...t){for(let i of this.facet(U.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let s=[];for(let r of this.facet(Lo))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return Fa(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=Ue(t,o,!1);if(r(t.slice(a,o))!=Ze.Word)break;o=a}for(;l<s;){let a=Ue(t,l);if(r(t.slice(l,a))!=Ze.Word)break;l=a}return o==l?null:M.range(o+i,l+i)}}U.allowMultipleSelections=nn;U.tabSize=L.define({combine:n=>n.length?n[0]:4});U.lineSeparator=Bo;U.readOnly=Fo;U.phrases=L.define({compare(n,e){let t=Object.keys(n),i=Object.keys(e);return t.length==i.length&&t.every(s=>n[s]==e[s])}});U.languageData=Lo;U.changeFilter=Io;U.transactionFilter=jo;U.transactionExtender=Wo;ms.reconfigure=ue.define();function Ha(n,e,t={}){let i={};for(let s of n)for(let r of Object.keys(s)){let o=s[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)i[s]===void 0&&(i[s]=e[s]);return i}class ct{eq(e){return this==e}range(e,t=e){return ln.create(e,t,this)}}ct.prototype.startSide=ct.prototype.endSide=0;ct.prototype.point=!1;ct.prototype.mapMode=Pe.TrackDel;function zn(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}let ln=class Vo{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Vo(e,t,i)}};function an(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class Vn{constructor(e,t,i,s){this.from=e,this.to=t,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],c=this.from[a]+e,f=this.to[a]+e,u,d;if(c==f){let p=t.mapPos(c,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=t.mapPos(c,h.endSide),d<u)))continue}else if(u=t.mapPos(c,h.startSide),d=t.mapPos(f,h.endSide),u>d||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(l=Math.max(l,d-u)),i.push(h),s.push(u-o),r.push(d-o))}return{mapped:i.length?new Vn(s,r,i,l):null,pos:o}}}class K{constructor(e,t,i,s){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=s}static create(e,t,i,s){return new K(e,t,i,s)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(an)),this.isEmpty)return t.length?K.of(t):this;let l=new $o(this,null,-1).goto(0),a=0,h=[],c=new ci;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];c.addInner(f.from,f.to,f.value)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value)||h.push(ln.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?K.empty:this.nextLayer.update({add:h,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:c,pos:f}=a.map(l,e);c&&(s=Math.max(s,c.maxPoint),t.push(c),i.push(f))}}let r=this.nextLayer.map(e);return t.length==0?r:new K(i,t,r||K.empty,s)}between(e,t,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return fi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return fi.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=fr(o,l,i),h=new Xt(o,a,r),c=new Xt(l,a,r);i.iterGaps((f,u,d)=>ur(h,f,c,u,d,s)),i.empty&&i.length==0&&ur(h,0,c,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=999999999);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=fr(r,o),a=new Xt(r,l,0).goto(i),h=new Xt(o,l,0).goto(i);for(;;){if(a.to!=h.to||!hn(a.active,h.active)||a.point&&(!h.point||!zn(a.point,h.point)))return!1;if(a.to>s)return!0;a.next(),h.next()}}static spans(e,t,i,s,r=-1){let o=new Xt(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,a);s.point(l,h,o.point,c,f,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(s.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new ci;for(let s of e instanceof ln?[e]:t?za(e):e)i.add(s.from,s.to,s.value);return i.finish()}static join(e){if(!e.length)return K.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let s=e[i];s!=K.empty;s=s.nextLayer)t=new K(s.chunkPos,s.chunk,t,Math.max(s.maxPoint,t.maxPoint));return t}}K.empty=new K([],[],null,-1);function za(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(an(e,i)>0)return n.slice().sort(an);e=i}return n}K.empty.nextLayer=K.empty;class ci{finishChunk(e){this.chunks.push(new Vn(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new ci)).add(e,t,i)}addInner(e,t,i){let s=e-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<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=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(K.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=K.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function fr(n,e,t){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}class $o{constructor(e,t,i,s=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class fi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new $o(o,t,i,r));return s.length==1?s[0]:new fi(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)Ts(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)Ts(this.heap,i);(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(),Ts(this.heap,0)}}}function Ts(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let s=n[i];if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),t.compare(s)<0)break;n[i]=t,n[e]=s,e=i}}class Xt{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=fi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Oi(this.active,e),Oi(this.activeTo,e),Oi(this.activeRank,e),this.minActive=dr(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||s-this.activeTo[t])>0;)t++;Ti(this.active,t,i),Ti(this.activeTo,t,s),Ti(this.activeRank,t,r),e&&Ti(e,t,this.cursor.from),this.minActive=dr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&Oi(i,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function ur(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e,h=!!r.boundChange;for(let c=!1;;){let f=n.to+a-t.to,u=f||n.endSide-t.endSide,d=u<0?n.to+a:t.to,p=Math.min(d,o);if(n.point||t.point?(n.point&&t.point&&zn(n.point,t.point)&&hn(n.activeForPoint(n.to),t.activeForPoint(t.to))||r.comparePoint(l,p,n.point,t.point),c=!1):(c&&r.boundChange(l),p>l&&!hn(n.active,t.active)&&r.compareRange(l,p,n.active,t.active),h&&p<o&&(f||n.openEnd(d)!=t.openEnd(d))&&(c=!0)),d>o)break;l=d,u<=0&&n.next(),u>=0&&t.next()}}function hn(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!zn(n[t],e[t]))return!1;return!0}function Oi(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function Ti(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function dr(n,e){let t=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||n[s].endSide-n[t].endSide)<0&&(t=s,i=e[s]);return t}function Va(n,e,t,i){for(let s=0,r=0;;){if(r>=e)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?t-r%t:1,s=Ue(n,s)}return n.length}const cn="ͼ",pr=typeof Symbol>"u"?"__"+cn:Symbol.for(cn),fn=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),gr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class ft{constructor(e,t){this.rules=[];let{finish:i}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(m=>o.map(x=>m.replace(/&/,x))).reduce((m,x)=>m.concat(x)),p,a);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(s(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||u)&&a.push((i&&!f&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(s(o),e[o],this.rules)}getRules(){return this.rules.join(`
6
+ `)}static newName(){let e=gr[pr]||1;return gr[pr]=e+1,cn+e.toString(36)}static mount(e,t,i){let s=e[fn],r=i&&i.nonce;s?r&&s.setNonce(r):s=new $a(e,r),s.mount(Array.isArray(t)?t:[t],e)}}let mr=new Map;class $a{constructor(e,t){let i=e.ownerDocument||e,s=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&s.CSSStyleSheet){let r=mr.get(i);if(r)return e[fn]=r;this.sheet=new s.CSSStyleSheet,mr.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[fn]=this}mount(e,t){let i=this.sheet,s=0,r=0;for(let o=0;o<e.length;o++){let l=e[o],a=this.modules.indexOf(l);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),a==-1){if(this.modules.splice(r++,0,l),i)for(let h=0;h<l.rules.length;h++)i.insertRule(l.rules[h],s++)}else{for(;r<a;)s+=this.modules[r++].rules.length;s+=l.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let o="";for(let a=0;a<this.modules.length;a++)o+=this.modules[a].getRules()+`
7
+ `;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var ut={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ui={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},qa=typeof navigator<"u"&&/Mac/.test(navigator.platform),Qa=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ge=0;ge<10;ge++)ut[48+ge]=ut[96+ge]=String(ge);for(var ge=1;ge<=24;ge++)ut[ge+111]="F"+ge;for(var ge=65;ge<=90;ge++)ut[ge]=String.fromCharCode(ge+32),ui[ge]=String.fromCharCode(ge);for(var Ms in ut)ui.hasOwnProperty(Ms)||(ui[Ms]=ut[Ms]);function Ua(n){var e=qa&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Qa&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ui:ut)[n.keyCode]||n.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}let we=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},un=typeof document<"u"?document:{documentElement:{style:{}}};const dn=/Edge\/(\d+)/.exec(we.userAgent),qo=/MSIE \d/.test(we.userAgent),pn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(we.userAgent),xs=!!(qo||pn||dn),xr=!xs&&/gecko\/(\d+)/i.test(we.userAgent),Rs=!xs&&/Chrome\/(\d+)/.exec(we.userAgent),Ka="webkitFontSmoothing"in un.documentElement.style,gn=!xs&&/Apple Computer/.test(we.vendor),yr=gn&&(/Mobile\/\w+/.test(we.userAgent)||we.maxTouchPoints>2);var T={mac:yr||/Mac/.test(we.platform),windows:/Win/.test(we.platform),linux:/Linux|X11/.test(we.platform),ie:xs,ie_version:qo?un.documentMode||6:pn?+pn[1]:dn?+dn[1]:0,gecko:xr,gecko_version:xr?+(/Firefox\/(\d+)/.exec(we.userAgent)||[0,0])[1]:0,chrome:!!Rs,chrome_version:Rs?+Rs[1]:0,ios:yr,android:/Android\b/.test(we.userAgent),webkit_version:Ka?+(/\bAppleWebKit\/(\d+)/.exec(we.userAgent)||[0,0])[1]:0,safari:gn,safari_version:gn?+(/\bVersion\/(\d+(\.\d+)?)/.exec(we.userAgent)||[0,0])[1]:0,tabSize:un.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function $n(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const Xi=Object.create(null);function qn(n,e,t){if(n==e)return!0;n||(n=Xi),e||(e=Xi);let i=Object.keys(n),s=Object.keys(e);if(i.length-0!=s.length-0)return!1;for(let r of i)if(r!=t&&(s.indexOf(r)==-1||n[r]!==e[r]))return!1;return!0}function Ga(n,e){for(let t=n.attributes.length-1;t>=0;t--){let i=n.attributes[t].name;e[i]==null&&n.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?n.style.cssText=i:n.getAttribute(t)!=i&&n.setAttribute(t,i)}}function br(n,e,t){let i=!1;if(e)for(let s in e)t&&s in t||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(i=!0,s=="style"?n.style.cssText=t[s]:n.setAttribute(s,t[s]));return i}function _a(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class ys{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,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var Se=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(Se||(Se={}));class he extends ct{constructor(e,t,i,s){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(e){return new ki(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new At(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,s;if(e.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Qo(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new At(e,i,s,t,e.widget||null,!0)}static line(e){return new wi(e)}static set(e,t=!1){return K.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}he.none=K.empty;class ki extends he{constructor(e){let{start:t,end:i}=Qo(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?$n(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Xi}eq(e){return this==e||e instanceof ki&&this.tagName==e.tagName&&qn(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}ki.prototype.point=!1;class wi extends he{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof wi&&this.spec.class==e.spec.class&&qn(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)}}wi.prototype.mapMode=Pe.TrackBefore;wi.prototype.point=!0;class At extends he{constructor(e,t,i,s,r,o){super(t,i,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?Pe.TrackBefore:Pe.TrackAfter:Pe.TrackDel}get type(){return this.startSide!=this.endSide?Se.WidgetRange:this.startSide<=0?Se.WidgetBefore:Se.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof At&&Xa(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)}}At.prototype.point=!0;function Qo(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function Xa(n,e){return n==e||!!(n&&e&&n.compare(e))}function jt(n,e,t,i=0){let s=t.length-1;s>=0&&t[s]+i>=n?t[s]=Math.max(t[s],e):t.push(n,e)}class di extends ct{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof di&&this.tagName==e.tagName&&qn(this.attributes,e.attributes)}static create(e){return new di(e.tagName,e.attributes||Xi)}static set(e,t=!1){return K.of(e,t)}}di.prototype.startSide=di.prototype.endSide=-1;function pi(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function mn(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function ri(n,e){if(!e.anchorNode)return!1;try{return mn(n,e.anchorNode)}catch{return!1}}function $i(n){return n.nodeType==3?gi(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function oi(n,e,t,i){return t?kr(n,e,t,i,-1)||kr(n,e,t,i,1):!1}function dt(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Yi(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function kr(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:tt(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=dt(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=s<0?tt(n):0}else return!1}}function tt(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Zi(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Ya(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Uo(n,e){let t=e.width/n.offsetWidth,i=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-n.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Za(n,e,t,i,s,r,o,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,f=!1;c&&!f;)if(c.nodeType==1){let u,d=c==a.body,p=1,m=1;if(d)u=Ya(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 w=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Uo(c,w)),u={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*m}}let x=0,y=0;if(s=="nearest")e.top<u.top?(y=e.top-(u.top+o),t>0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+o)):e.bottom>u.bottom&&(y=e.bottom-u.bottom+o,t<0&&e.top-y<u.top&&(y=e.top-(u.top+o)));else{let w=e.bottom-e.top,A=u.bottom-u.top;y=(s=="center"&&w<=A?e.top+w/2-A/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-A+o)-u.top}if(i=="nearest"?e.left<u.left?(x=e.left-(u.left+r),t>0&&e.right>u.right+x&&(x=e.right-u.right+r)):e.right>u.right&&(x=e.right-u.right+r,t<0&&e.left<u.left+x&&(x=e.left-(u.left+r))):x=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,x||y)if(d)h.scrollBy(x,y);else{let w=0,A=0;if(y){let N=c.scrollTop;c.scrollTop+=y/m,A=(c.scrollTop-N)*m}if(x){let N=c.scrollLeft;c.scrollLeft+=x/p,w=(c.scrollLeft-N)*p}e={left:e.left-w,top:e.top-A,right:e.right-w,bottom:e.bottom-A},w&&Math.abs(w-x)<1&&(i="nearest"),A&&Math.abs(A-y)<1&&(s="nearest")}if(d)break;(e.top<u.top||e.bottom>u.bottom||e.left<u.left||e.right>u.right)&&(e={left:Math.max(e.left,u.left),right:Math.min(e.right,u.right),top:Math.max(e.top,u.top),bottom:Math.min(e.bottom,u.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Ja(n){let e=n.ownerDocument,t,i;for(let s=n.parentNode;s&&!(s==e.body||t&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!t&&s.scrollWidth>s.clientWidth&&(t=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:t,y:i}}class eh{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?tt(t):0),i,Math.min(e.focusOffset,i?tt(i):0))}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let yt=null;T.safari&&T.safari_version>=26&&(yt=!1);function Ko(n){if(n.setActive)return n.setActive();if(yt)return n.focus(yt);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(yt==null?{get preventScroll(){return yt={preventScroll:!0},!0}}:void 0),!yt){yt=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let wr;function gi(n,e,t=e){let i=wr||(wr=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function Wt(n,e,t,i){let s={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function th(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function ih(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,tt(t));;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=tt(t))}else{if(t==n)return!0;i=dt(t),t=t.parentNode}}function Go(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function _o(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=tt(t)}else if(t.parentNode&&!Yi(t))i=dt(t),t=t.parentNode;else return null}}function Xo(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!Yi(t))i=dt(t)+1,t=t.parentNode;else return null}}class Ie{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Ie(e.parentNode,dt(e),t)}static after(e,t){return new Ie(e.parentNode,dt(e)+1,t)}}var se=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(se||(se={}));const Ot=se.LTR,Qn=se.RTL;function Yo(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const sh=Yo("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),nh=Yo("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),xn=Object.create(null),Fe=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);xn[e]=t,xn[t]=-e}function Zo(n){return n<=247?sh[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?nh[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const rh=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Ke{get dir(){return this.level%2?Qn:Ot}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Jo(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],s=e[t];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!Jo(i.inner,s.inner))return!1}return!0}const _=[];function oh(n,e,t,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:s;for(let h=o,c=a,f=a;h<l;h++){let u=Zo(n.charCodeAt(h));u==512?u=c:u==8&&f==4&&(u=16),_[h]=u==4?2:u,u&7&&(f=u),c=u}for(let h=o,c=a,f=a;h<l;h++){let u=_[h];if(u==128)h<l-1&&c==_[h+1]&&c&24?u=_[h]=c:_[h]=256;else if(u==64){let d=h+1;for(;d<l&&_[d]==64;)d++;let p=h&&c==8||d<t&&_[d]==8?f==1?1:8:256;for(let m=h;m<d;m++)_[m]=p;h=d-1}else u==8&&f==1&&(_[h]=1);c=u,u&7&&(f=u)}}}function lh(n,e,t,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,c=o<i.length?i[o].from:t;for(let f=h,u,d,p;f<c;f++)if(d=xn[u=n.charCodeAt(f)])if(d<0){for(let m=l-3;m>=0;m-=3)if(Fe[m+1]==-d){let x=Fe[m+2],y=x&2?s:x&4?x&1?r:s:0;y&&(_[f]=_[Fe[m]]=y),l=m;break}}else{if(Fe.length==189)break;Fe[l++]=f,Fe[l++]=u,Fe[l++]=a}else if((p=_[f])==2||p==1){let m=p==s;a=m?0:1;for(let x=l-3;x>=0;x-=3){let y=Fe[x+2];if(y&2)break;if(m)Fe[x+2]|=2;else{if(y&4)break;Fe[x+2]|=4}}}}}function ah(n,e,t,i){for(let s=0,r=i;s<=t.length;s++){let o=s?t[s-1].to:n,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let h=_[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==t.length)break;c=t[s++].to,l=s<t.length?t[s].from:e}else if(_[c]==256)c++;else break;let f=r==1,u=(c<e?_[c]:i)==1,d=f==u?f?1:2:i;for(let p=c,m=s,x=m?t[m-1].to:n;p>a;)p==x&&(p=t[--m].from,x=m?t[m-1].to:n),_[--p]=d;a=c}else r=h,a++}}}function yn(n,e,t,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=e,h=0;a<t;){let c=!0,f=!1;if(h==r.length||a<r[h].from){let m=_[a];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(f)break e;let m=r[h];if(!c)for(let x=m.to,y=h+1;;){if(x==t)break e;if(y<r.length&&r[y].from==x)x=r[y++].to;else{if(_[x]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new Ke(a,m.from,d));let x=m.direction==Ot!=!(d%2);bn(n,x?i+1:i,s,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?_[p]!=l:_[p]==l))break;p++}u?yn(n,a,p,i+1,s,u,o):a<p&&o.push(new Ke(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let c=!0,f=!1;if(!h||a>r[h-1].to){let m=_[a-1];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(f)break e;let m=r[--h];if(!c)for(let x=m.from,y=h;;){if(x==e)break e;if(y&&r[y-1].to==x)x=r[--y].from;else{if(_[x-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new Ke(m.to,a,d));let x=m.direction==Ot!=!(d%2);bn(n,x?i+1:i,s,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(c?_[p-1]!=l:_[p-1]==l))break;p--}u?yn(n,p,a,i+1,s,u,o):p<a&&o.push(new Ke(p,a,d)),a=p}}function bn(n,e,t,i,s,r,o){let l=e%2?2:1;oh(n,s,r,i,l),lh(n,s,r,i,l),ah(s,r,i,l),yn(n,s,r,e,t,i,o)}function hh(n,e,t){if(!n)return[new Ke(0,0,e==Qn?1:0)];if(e==Ot&&!t.length&&!rh.test(n))return el(n.length);if(t.length)for(;n.length>_.length;)_[_.length]=256;let i=[],s=e==Ot?0:1;return bn(n,s,s,t,0,n.length,i),i}function el(n){return[new Ke(0,n,0)]}let tl="";function ch(n,e,t,i,s){var r;let o=i.head-n.from,l=Ke.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],h=a.side(s,t);if(o==h){let u=l+=s?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!s,t),h=a.side(s,t)}let c=Ue(n.text,o,a.forward(s,t));(c<a.from||c>a.to)&&(c=h),tl=n.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return f&&c==h&&f.level+(s?0:1)<a.level?M.cursor(f.side(!s,t)+n.from,f.forward(s,t)?1:-1,f.level):M.cursor(c+n.from,a.forward(s,t)?-1:1,a.level)}function fh(n,e,t){for(let i=e;i<t;i++){let s=Zo(n.charCodeAt(i));if(s==1)return Ot;if(s==2||s==4)return Qn}return Ot}const il=L.define(),sl=L.define(),nl=L.define(),rl=L.define(),kn=L.define(),ol=L.define(),ll=L.define(),Un=L.define(),Kn=L.define(),al=L.define({combine:n=>n.some(e=>e)}),hl=L.define({combine:n=>n.some(e=>e)}),cl=L.define();class Ft{constructor(e,t="nearest",i="nearest",s=5,r=5,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Ft(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 Ft(M.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Mi=ue.define({map:(n,e)=>n.map(e)}),fl=ue.define();function Ge(n,e,t){let i=n.facet(rl);i.length?i[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const Ye=L.define({combine:n=>n.length?n[0]:!0});let uh=0;const Dt=L.define({combine(n){return n.filter((e,t)=>{for(let i=0;i<t;i++)if(n[i].plugin==e.plugin)return!1;return!0})}});class it{constructor(e,t,i,s,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(Dt.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Dt.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=t||{};return new it(uh++,e,i,s,l=>{let a=[];return o&&a.push(bs.of(h=>{let c=h.plugin(l);return c?o(c):he.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return it.define((i,s)=>new e(i,s),t)}}class Ps{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(Ge(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Ge(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(i){Ge(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const ul=L.define(),Gn=L.define(),bs=L.define(),dl=L.define(),_n=L.define(),Si=L.define(),pl=L.define();function Sr(n,e){let t=n.state.facet(pl);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(n):r),s=[];return K.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,c=o-e.from,f=s;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=fh(e.text,h,c)),a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==d)p.to=c,f=p.inner;else{let m={from:h,to:c,direction:d,inner:[]};f.push(m),f=m.inner}}}}),s}const gl=L.define();function ml(n){let e=0,t=0,i=0,s=0;for(let r of n.state.facet(gl)){let o=r(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:i,bottom:s}}const ei=L.define();class Ee{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new Ee(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0;;){let l=s<e.length?e[s].fromB:1e9,a=r<t.length?t[r]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+o,f=h,u=c;for(;;)if(r<t.length&&t[r]<=f){let d=t[r+1];r+=2,f=Math.max(f,d);for(let p=s;p<e.length&&e[p].fromB<=f;p++)o=e[p].toA-e[p].toB;u=Math.max(u,d+o)}else if(s<e.length&&e[s].fromB<=f){let d=e[s++];f=Math.max(f,d.toB),u=Math.max(u,d.toA),o=d.toA-d.toB}else break;i.push(new Ee(c,u,h,f))}return i}}class Ji{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=de.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new Ee(r,o,l,a))),this.changedRanges=s}static create(e,t,i){return new Ji(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>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}}const dh=[];class ce{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return dh}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&Ga(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let s of this.children){if(s==e)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=dt(this.dom),s=this.length?e>0:t>0;return new Ie(this.parent.dom,i+(s?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof ws)return e;return null}static get(e){return e.cmTile}}class ks extends ce{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,s,r=(e==null?void 0:e.node)==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,s=i?i.nextSibling:t.firstChild,r&&s!=l.dom&&(r.written=!0),l.dom.parentNode==t)for(;s&&s!=l.dom;)s=vr(s);else t.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:t.firstChild,r&&s&&(r.written=!0);s;)s=vr(s);this.length=o}}function vr(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class ws extends ks{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=ce.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,s=0,r=0;;)if(s==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,s=t.pop()}else{let o=i.children[s++];if(o instanceof et)t.push(s),i=o,s=0;else{let l=r+o.length,a=e(o,r);if(a!==void 0)return a;r=l+o.breakAfter}}}resolveBlock(e,t){let i,s=-1,r,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(e>=a&&e<=h){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=e-a),(h>e||e==a&&(t>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=e-a)}}),!i&&!r)throw new Error("No tile at position "+e);return i&&t<0||!r?{tile:i,offset:s}:{tile:r,offset:o}}}class et extends ks{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new et(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class Vt extends ks{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let s=new Vt(t||document.createElement("div"),e);return(!t||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(e,t,i){let s=null,r=-1,o=null,l=-1;function a(c,f){for(let u=0,d=0;u<c.children.length&&d<=f;u++){let p=c.children[u],m=d+p.length;m>=f&&(p.isComposite()?a(p,f-d):(!o||o.isHidden&&(t>0||i&&gh(o,p)))&&(m>f||p.flags&32)?(o=p,l=f-d):(d<f||p.flags&16&&!p.isHidden)&&(s=p,r=f-d)),d=m}}a(this,e);let h=(t<0?s:o)||s||o;return h?{tile:h,offset:h==s?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):ph(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:s,offset:r}=i;if(this.dom.contains(s.dom))return s.isText()?new Ie(s.dom,Math.min(s.dom.nodeValue.length,r)):s.domPosFor(r,s.flags&16?1:s.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new Ie(a.dom,0);a==i.tile&&(l=!0)}}return new Ie(this.dom,0)}}function ph(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=$i(e);return t[t.length-1]||null}function gh(n,e){let t=n.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class Oe extends ks{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new Oe(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class vt extends ce{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let s=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?T.chrome||T.gecko||(e?(s--,o=1):r<i&&(r++,o=-1)):t<0?s--:r<i&&r++;let l=gi(this.dom,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return T.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Zi(a,o<0):a||null}static of(e,t){let i=new vt(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class Tt extends ce{constructor(e,t,i,s){super(e,t,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let s=this.widget.coordsAt(this.dom,e,t);if(s)return s;if(i)return Zi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?r.length-1:0;o=r[a],!(e>0?a==0:a==r.length-1||o.top<o.bottom);a+=l?-1:1);return Zi(o,!l)}}get overrideDOMText(){if(!this.length)return Q.empty;let{root:e}=this;if(!e)return Q.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,s,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new Tt(r,i,e,s)}}class es extends ce{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return Q.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class mh{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:s,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(s.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==s.children.length){if(!e&&!l.length)break;i&&i.leave(s),o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++}else{let a=s.children[r],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,r++,e-=a.length):(l.push({tile:s,index:r}),s=a,r=0,i&&a.isComposite()&&i.enter(a))}else if(r==s.length)o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++;else if(e){let a=Math.min(e,s.length-r);i&&i.skip(s,r,r+a),e-=a,r+=a}else break;return this.tile=s,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class xh{constructor(e,t,i,s){this.from=e,this.to=t,this.wrapper=i,this.rank=s}}class yh{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,s){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new vt(l.dom,l.text+e);a.parent=o}else o.append(s||vt.of(e,(r=this.cache.find(vt))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?Ns(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let s=i;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],h=s.lastChild;if(h instanceof Oe&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(Ns(a.dom)),s=h;else{if(this.cache.reused.get(a)){let f=ce.get(a.dom);f&&f.setDOM(Ns(a.dom))}let c=Oe.of(a.mark,a.dom);s.append(c),s=c}this.cache.reused.set(a,2)}let r=ce.get(e.text);r&&this.cache.reused.set(r,2);let o=new vt(e.text,e.text.nodeValue);o.flags|=8,s.append(o)}addInlineWidget(e,t,i){let s=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);s||this.flushBuffer();let r=this.ensureMarks(t,i);!s&&!(e.flags&16)&&r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=xl);let s=Vt.start(e,t||((i=this.cache.find(Vt))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let s=this.curLine;for(let r=e.length-1;r>=0;r--){let o=e[r],l;if(t>0&&(l=s.lastChild)&&l instanceof Oe&&l.mark.eq(o))s=l,t--;else{let a=Oe.of(o,(i=this.cache.find(Oe,h=>h.mark.eq(o)))===null||i===void 0?void 0:i.dom);s.append(a),s=a,t=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Cr(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(T.ios&&Cr(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Es,0,32)||new Tt(Es.toDOM(),0,Es,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new xh(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let s=t.lastChild;if(i.from<this.pos&&s instanceof et&&s.wrapper.eq(i.wrapper))t=s;else{let r=et.of(i.wrapper,(e=this.cache.find(et,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(es,void 0,1);return i&&(i.flags=t),i||new es(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class bh{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:s,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(e,s.length);return r?null:s.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const ts=[Tt,Vt,vt,Oe,es,et,ws];for(let n=0;n<ts.length;n++)ts[n].bucket=n;class kh{constructor(e){this.view=e,this.buckets=ts.map(()=>[]),this.index=ts.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let s=e.bucket,r=this.buckets[s],o=this.index[s];for(let l=r.length-1;l>=0;l--){let a=(l+o)%r.length,h=r[a];if((!t||t(h))&&!this.reused.has(h))return r.splice(a,1),a<o&&this.index[s]--,this.reused.set(h,i),h}return null}findWidget(e,t,i){let s=this.buckets[0];if(s.length)for(let r=0,o=0;;r++){if(r==s.length){if(o)return null;o=1,r=0}let l=s[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view)))return s.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new Tt(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class wh{constructor(e,t,i,s,r){this.view=e,this.decorations=s,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new kh(e),this.text=new bh(e.state.doc),this.builder=new yh(this.cache,new ws(e,e.contentDOM),K.iter(i)),this.cache.reused.set(t,2),this.old=new mh(t),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let s=0,r=0,o=0;;){let l=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>s){let h=a-s;this.preserve(h,!o,!l),s=a,r+=h}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let s=Ch(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?Tt.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,s,r),r=s.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length?this.builder.addText(o.text,s,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),s,r)),r=s.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof es)this.cache.add(o);else if(o instanceof Oe)this.builder.ensureLine(null),this.builder.addMark(o,s,r),this.cache.reused.set(o,1),r=s.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof Oe&&s.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?s.length&&(s.length=r=0):o instanceof Oe&&(s.shift(),r=Math.min(r,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,s=this.builder,r=0,o=K.spans(this.decorations,e,t,{point:(l,a,h,c,f,u)=>{if(h instanceof At){if(this.disallowBlockEffectsFor[u]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=c.length,f>c.length)s.continueWidget(a-l);else{let d=h.widget||(h.block?$t.block:$t.inline),p=Sh(h),m=this.cache.findWidget(d,a-l,p)||Tt.of(d,this.view,a-l,p);h.block?(h.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(m)):(s.ensureLine(i),s.addInlineWidget(m,c,f))}i=null}else i=vh(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let u=this.text.next(Math.min(512,a-f));u==null?(s.addLineStartIfNotCovered(i),s.addBreak(),f++):(s.ensureLine(i),s.addText(u,h,f==l?c:h.length),f+=u.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let s=e.parentNode;;s=s.parentNode){let r=ce.get(s);if(s==this.view.contentDOM)break;r instanceof Oe?t.push(r):r!=null&&r.isLine()?i=r:r instanceof et||(s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new Vt(s,xl):i||t.push(Oe.of(new ki({tagName:s.nodeName.toLowerCase(),attributes:_a(s)}),s)))}return{line:i,marks:t}}}function Cr(n,e){let t=i=>{for(let s of i.children)if((e?s.isText():s.length)||t(s))return!0;return!1};return t(n)}function Sh(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}const xl={class:"cm-line"};function vh(n,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(n||(n={class:"cm-line"}),t&&$n(t,n),i&&(n.class+=" "+i)),n}function Ch(n){let e=[];for(let t=n.parents.length;t>1;t--){let i=t==n.parents.length?n.tile:n.parents[t].tile;i instanceof Oe&&e.push(i.mark)}return e}function Ns(n){let e=ce.get(n);return e&&e.setDOM(n.cloneNode()),n}class $t extends ys{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}}$t.inline=new $t("span");$t.block=new $t("div");const Es=new class extends ys{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Ar{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=he.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new ws(e,e.contentDOM),this.updateInner([new Ee(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?s=this.domChanged.newSel.head:!Dh(e.changes,this.hasComposition)&&!e.selectionSet&&(s=e.state.selection.main.head));let r=s>-1?Oh(this.view,e.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new Ee(c,f,e.changes.mapPos(c,-1),e.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(T.ie||T.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=Rh(o,this.decorations,e.changes);a.length&&(i=Ee.extendWithRanges(i,a));let h=Nh(l,this.blockWrappers,e.changes);return h.length&&(i=Ee.extendWithRanges(i,h)),r&&!i.some(c=>c.fromA<=r.range.fromA&&c.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new wh(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(e,t),wn(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=T.chrome||T.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof Ds&&s.push(r.dom);i.updateGaps(s)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(fl)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,r=s==i,o=!r&&!(this.view.state.facet(Ye)||i.tabIndex>-1)&&ri(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(r||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),T.gecko&&a.empty&&!this.hasComposition&&Ah(h)){let u=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(u,h.node.childNodes[h.offset]||null)),h=c=new Ie(u,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!oi(h.node,h.offset,f.anchorNode,f.anchorOffset)||!oi(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{T.android&&T.chrome&&i.contains(f.focusNode)&&Eh(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let u=pi(this.view.root);if(u)if(a.empty){if(T.gecko){let d=Th(h.node,h.offset);if(d&&d!=3){let p=(d==1?_o:Xo)(h.node,h.offset);p&&(h=new Ie(p.node,p.offset))}}u.collapse(h.node,h.offset),a.bidiLevel!=null&&u.caretBidiLevel!==void 0&&(u.caretBidiLevel=a.bidiLevel)}else if(u.extend){u.collapse(h.node,h.offset);try{u.extend(c.node,c.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),d.setEnd(c.node,c.offset),d.setStart(h.node,h.offset),u.removeAllRanges(),u.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new Ie(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new Ie(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&oi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=pi(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(s,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=tt(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return s;for(;r&&!ce.get(r);)r=r.nextSibling;if(!r)return s+i.length;for(let o=0,l=s;;o++){let a=i.children[o];if(a.dom==r)return l;l+=a.length+a.breakAfter}}else return i.isText()?e==i.dom?s+t:s+(t?i.length:0):s}domAtPos(e,t){let{tile:i,offset:s}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(s,t)}inlineDOMNearPos(e,t){let i,s=-1,r=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=e)return!0;h.flags&16&&(r=!0)}else{let f=c+h.length;if(c<=e&&(i=h,s=e-c,r=f<e),f>=e&&!o&&(o=h,l=e-c,a=c>e),c>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(r&&o?i=null:a&&i&&(o=null),i&&t<0||!o?i.domIn(s,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:s}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof Ds?null:i.coordsInWidget(s,t,!0):i.coordsIn(s,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function s(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let a=s(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(r.isText()&&o<r.length){let l=Ue(r.text,o);if(l==o)return null;let a=gi(r.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return s(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==se.LTR,h=0,c=(f,u,d)=>{for(let p=0;p<f.children.length&&!(u>s);p++){let m=f.children[p],x=u+m.length,y=m.dom.getBoundingClientRect(),{height:w}=y;if(d&&!p&&(h+=y.top-d.top),m instanceof et)x>i&&c(m,u,y);else if(u>=i&&(h>0&&t.push(-h),t.push(w+h),h=0,o)){let A=m.dom.lastChild,N=A?$i(A):[];if(N.length){let v=N[N.length-1],C=a?v.right-y.left:y.right-v.left;C>l&&(l=C,this.minWidth=r,this.minWidthFrom=u,this.minWidthTo=x)}}d&&p==f.children.length-1&&(h+=d.bottom-y.bottom),u=x+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?se.RTL:se.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=$i(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),i,s,r;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=$i(t.firstChild)[0];i=t.getBoundingClientRect().height,s=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:s,textHeight:r}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(he.replace({widget:new Ds(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return he.set(e)}updateDeco(){let e=1,t=this.view.state.facet(bs).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(_n).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[e++]=i,t.push(K.join(s))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(dl).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){if(e.isSnapshot){let h=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=h.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let h of this.view.state.facet(cl))try{if(h(this.view,e.range,e))return!0}catch(c){Ge(this.view.state,c,"scroll handler")}let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!i)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=ml(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;if(Za(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==se.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(i.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||i.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let h=this.view.docView.lineAt(t.head,1);h&&h.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){wn(this.tile)}}function wn(n,e){let t=e==null?void 0:e.get(n);if(t!=1){t==null&&n.destroy();for(let i of n.children)wn(i,e)}}function Ah(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function yl(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let i=_o(t.focusNode,t.focusOffset),s=Xo(t.focusNode,t.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=ce.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=ce.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Oh(n,e,t){let i=yl(n,t);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc;return{range:new Ee(a.mapPos(r),a.mapPos(o),r,o),text:s}}function Th(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let Mh=class{constructor(){this.changes=[]}compareRange(e,t){jt(e,t,this.changes)}comparePoint(e,t){jt(e,t,this.changes)}boundChange(e){jt(e,e,this.changes)}};function Rh(n,e,t){let i=new Mh;return K.compare(n,e,t,i),i.changes}class Ph{constructor(){this.changes=[]}compareRange(e,t){jt(e,t,this.changes)}comparePoint(){}boundChange(e){jt(e,e,this.changes)}}function Nh(n,e,t){let i=new Ph;return K.compare(n,e,t,i),i.changes}function Eh(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function Dh(n,e){let t=!1;return e&&n.iterChangedRanges((i,s)=>{i<e.to&&s>e.from&&(t=!0)}),t}class Ds extends ys{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Lh(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return M.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=Ue(s.text,r,!1):l=Ue(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let h=Ue(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=Ue(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return M.range(o+s.from,l+s.from)}function Bh(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+Va(o,r,n.state.tabSize)}function Sn(n,e,t){let i=n.lineBlockAt(e);if(Array.isArray(i.type)){let s;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!s||r.type==Se.Text&&(s.type!=r.type||(t<0?r.from<e:r.to>e)))&&(s=r)}}return s||i}return i}function Ih(n,e,t,i){let s=Sn(n,e.head,e.assoc||-1),r=!i||s.type!=Se.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==se.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return M.cursor(a,t?-1:1)}return M.cursor(t?s.to:s.from,t?-1:1)}function Or(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let h=ch(s,r,o,l,t),c=tl;if(!h){if(s.number==(t?n.state.doc.lines:1))return l;c=`
8
+ `,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),h=n.visualLineSide(s,!t)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function jh(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==Ze.Space&&(s=o),s==o}}function Wh(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return M.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,(e.empty?e.assoc:0)||(t?1:-1)),c=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let p=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-p.from))),l=(r<0?p.top:p.bottom)+c}let f=a.left+o,u=i??n.viewState.heightOracle.textHeight>>1,d=vn(n,{x:f,y:l+u*r},!1,r);return M.cursor(d.pos,d.assoc,void 0,o)}function li(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function bl(n,e){let t=null;for(let i=0;i<e.ranges.length;i++){let s=e.ranges[i],r=null;if(s.empty){let o=li(n,s.from,0);o!=s.from&&(r=M.cursor(o,-1))}else{let o=li(n,s.from,-1),l=li(n,s.to,1);(o!=s.from||l!=s.to)&&(r=M.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?M.create(t,e.mainIndex):e}function Ls(n,e,t){let i=li(n.state.facet(Si).map(s=>s(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:M.cursor(i,i<t.from?1:-1)}class Qe{constructor(e,t){this.pos=e,this.assoc=t}}function vn(n,e,t,i){let s=n.contentDOM.getBoundingClientRect(),r=s.top+n.viewState.paddingTop,{x:o,y:l}=e,a=l-r,h;for(;;){if(a<0)return new Qe(0,1);if(a>n.viewState.docHeight)return new Qe(n.state.doc.length,-1);if(h=n.elementAtHeight(a),i==null)break;if(h.type==Se.Text){if(i<0?h.to<n.viewport.from:h.from>n.viewport.to)break;let u=n.docView.coordsAt(i<0?h.from:h.to,i>0?-1:1);if(u&&(i<0?u.top<=a+r:u.bottom>=a+r))break}let f=n.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(t)return null;if(h.type==Se.Text){let f=Bh(n,s,h,o,l);return new Qe(f,f==h.from?1:-1)}}if(h.type!=Se.Text)return a<(h.top+h.bottom)/2?new Qe(h.from,1):new Qe(h.to,-1);let c=n.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=n.docView.lineAt(h.from,-2)),new Fh(n,o,l,n.textDirectionAt(h.from)).scanTile(c,h.from)}class Fh{constructor(e,t,i,s){this.view=e,this.x=t,this.y=i,this.baseDir=s,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:s}=this.bidiSpansAt(e);return s[Ke.find(s,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:s}=this.bidiSpansAt(e);return s[Ke.find(s,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:s}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+s.from<t)}scan(e,t){let i=0,s=e.length-1,r=new Set,o=this.bidiIn(e[0],e[s]),l,a,h=-1,c=1e9,f;e:for(;i<s;){let d=s-i,p=i+s>>1;t:if(r.has(p)){let x=i+Math.floor(Math.random()*d);for(let y=0;y<d;y++){if(!r.has(x)){p=x;break t}x++,x==s&&(x=i)}break e}r.add(p);let m=t(p);if(m)for(let x=0;x<m.length;x++){let y=m[x],w=0;if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),w=1;else if(y.top>this.y)(!a||a.top>y.top)&&(a=y),w=-1;else{let A=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,N=Math.abs(A);N<c&&(h=p,c=N,f=y),A&&(w=A<0==(this.baseDir==se.LTR)?-1:1)}w==-1&&(!o||this.baseDirAt(e[p],1))?s=p:w==1&&(!o||this.baseDirAt(e[p+1],-1))&&(i=p+1)}}if(!f){let d=l&&(!a||this.y-l.bottom<a.top-this.y)?l:a;return this.y=(d.top+d.bottom)/2,this.scan(e,t)}let u=(o?this.dirAt(e[h],1):this.baseDir)==se.LTR;return{i:h,after:this.x>(f.left+f.right)/2==u}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=Ue(e.text,r))i.push(t+r);i.push(t+e.length);let s=this.scan(i,r=>{let o=i[r]-t,l=i[r+1]-t;return gi(e.dom,o,l).getClientRects()});return s.after?new Qe(i[s.i+1],-1):new Qe(i[s.i],1)}scanTile(e,t){if(!e.length)return new Qe(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let i=[t];for(let l=0,a=t;l<e.children.length;l++)i.push(a+=e.children[l].length);let s=this.scan(i,l=>{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:gi(a.dom,0,a.length)).getClientRects()}),r=e.children[s.i],o=i[s.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):s.after?new Qe(i[s.i+1],-1):new Qe(o,1)}}const ti="￿";class Hh{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(U.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=ti}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=ce.get(s),l=s.nextSibling;if(l==t){o!=null&&o.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=ce.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:Yi(s))||Yi(l)&&(s.nodeName!="BR"||o!=null&&o.isWidget())&&this.text.length>r)&&!Vh(l,t)&&this.lineBreak(),s=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){let t=ce.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.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 i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(zh(e,i.node,i.offset)?t:0))}}function zh(n,e,t){for(;;){if(!e||t<tt(e))return!1;if(e==n)return!0;t=dt(e)+1,e=e.parentNode}}function Vh(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let i=ce.get(n);if(!(i!=null&&i.isWidget()))return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let s=i.overrideDOMText;if(s!=null&&s.length)return!1}return!0}class Tr{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class $h{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=kl(e.docView.tile,t,i,0))){let l=r||o?[]:Qh(e),a=new Hh(l,e);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Uh(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!mn(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!mn(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=e.viewport;if((T.ios||T.chrome)&&e.state.selection.main.empty&&a!=h&&(c.from>0||c.to<e.state.doc.length)){let f=Math.min(a,h),u=Math.max(a,h),d=c.from-f,p=c.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==e.state.doc.length)&&(a=0,h=e.state.doc.length)}e.inputState.composing>-1&&e.state.selection.ranges.length>1?this.newSel=e.state.selection.replaceRange(M.range(h,a)):this.newSel=M.single(h,a)}}}function kl(n,e,t,i){if(n.isComposite()){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<n.children.length;a++){let f=n.children[a],u=h+f.length;if(h<e&&u>t)return kl(f,e,t,h);if(u>=e&&s==-1&&(s=a,r=h),h>t&&f.dom.parentNode==n.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:r,to:l<0?i+n.length:l,startDOM:(s?n.children[s-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function wl(n,e){let t,{newSel:i}=e,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,h=null;(r===8||T.android&&e.text.length<l-o)&&(a=s.to,h="end");let c=Sl(n.state.doc.sliceString(o,l,ti),e.text,a-o,h);c&&(T.chrome&&r==13&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==ti+ti&&c.toB--,t={from:o+c.from,to:o+c.toA,insert:Q.of(e.text.slice(c.from,c.toB).split(ti))})}else i&&(!n.hasFocus&&n.state.facet(Ye)||is(i,s))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!s.empty&&i&&i.main.empty?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:(T.mac||T.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=M.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:Q.of([t.insert.toString().replace("."," ")])}):t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,s.to))}:n.state.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:n.state.toText(n.inputState.insertingText)}:T.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
9
+ `&&n.lineWrapping&&(i&&(i=M.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:Q.of([" "])}),t)return Xn(n,t,i,r);if(i&&!is(i,s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=bl(n.state.facet(Si).map(a=>a(n)),i))),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Xn(n,e,t,i=-1){if(T.ios&&n.inputState.flushIOSKey(e))return!0;let s=n.state.selection.main;if(T.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&n.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Wt(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&Wt(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&Wt(n.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=qh(n,e,t));return n.state.facet(ol).some(a=>a(n,e.from,e.to,r,l))||n.dispatch(l()),!0}function qh(n,e,t){let i,s=n.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let a=e.from<r.from?-1:1,h=a<0?r.from:r.to,c=li(s.facet(Si).map(f=>f(n)),h,a);e.from==c&&(o=c)}if(o>-1)i={changes:e,selection:M.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let a=r.from<e.from?s.sliceDoc(r.from,e.from):"",h=r.to>e.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(a+e.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(e),h=t&&t.main.to<=a.newLength?t.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let c=n.state.sliceDoc(e.from,e.to),f,u=t&&yl(n,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);f={from:u.from,to:u.to-p}}else f=n.state.doc.lineAt(r.head);let d=r.to-e.to;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,x=m-c.length;if(n.state.sliceDoc(x,m)!=c||m>=f.from&&x<=f.to)return{range:p};let y=s.changes({from:x,to:m,insert:e.insert}),w=p.to-r.to;return{changes:y,range:h?M.range(Math.max(0,h.anchor+w),Math.max(0,h.head+w)):p.map(y)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function Sl(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&n.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Qh(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new Tr(t,i)),(s!=t||r!=i)&&e.push(new Tr(s,r))),e}function Uh(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?M.single(t+e,i+e):null}function is(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}class Kh{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,T.safari&&e.contentDOM.addEventListener("input",()=>null),T.gecko&&ac(e.contentDOM.ownerDocument)}handleEvent(e){!tc(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let s of i.observers)s(this.view,t);for(let s of i.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Gh(e),i=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&s.removeEventListener(r,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&&Cl.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),T.android&&T.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return T.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=vl.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||_h.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.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Wt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:T.safari&&!T.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!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 Mr(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(s){Ge(t.state,s)}}}function Gh(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,r=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&t(l).handlers.push(Mr(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(Mr(i.value,a))}}for(let i in We)t(i).handlers.push(We[i]);for(let i in Le)t(i).observers.push(Le[i]);return e}const vl=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],_h="dthko",Cl=[16,17,18,20,91,92,224,225],Ri=6;function Pi(n){return Math.max(0,n)*.7+8}function Xh(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class Yh{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Ja(e.contentDOM),this.atoms=e.state.facet(Si).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(U.allowMultipleSelections)&&Zh(e,t),this.dragging=ec(e,t)&&Tl(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Xh(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=ml(this.view);e.clientX-a.left<=s+Ri?t=-Pi(s-e.clientX):e.clientX+a.right>=o-Ri&&(t=Pi(e.clientX-o)),e.clientY-a.top<=r+Ri?i=-Pi(r-e.clientY):e.clientY+a.bottom>=l-Ri&&(i=Pi(e.clientY-l)),this.setScrollSpeed(t,i)}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(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=bl(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Zh(n,e){let t=n.state.facet(il);return t.length?t[0](e):T.mac?e.metaKey:e.ctrlKey}function Jh(n,e){let t=n.state.facet(sl);return t.length?t[0](e):T.mac?!e.altKey:!e.ctrlKey}function ec(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=pi(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function tc(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=ce.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const We=Object.create(null),Le=Object.create(null),Al=T.ie&&T.ie_version<15||T.ios&&T.webkit_version<604;function ic(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),Ol(n,t.value)},50)}function Ss(n,e,t){for(let i of n.facet(e))t=i(t,n);return t}function Ol(n,e){e=Ss(n.state,Un,e);let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Cn!=null&&t.selection.ranges.every(a=>a.empty)&&Cn==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:M.cursor(h.from+f.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:M.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Le.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};We.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);Le.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};Le.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};We.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(nl))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=nc(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new Yh(n,e,t,i)),i&&n.observer.ignore(()=>{Ko(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Rr(n,e,t,i){if(i==1)return M.cursor(e,t);if(i==2)return Lh(n.state,e,t);{let s=n.docView.lineAt(e,t),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,M.range(o,l)}}const sc=T.ie&&T.ie_version<=11;let Pr=null,Nr=0,Er=0;function Tl(n){if(!sc)return n.detail;let e=Pr,t=Er;return Pr=n,Er=Date.now(),Nr=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Nr+1)%3:1}function nc(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Tl(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=n.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,c=Rr(n,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let f=Rr(n,t.pos,t.assoc,i),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u<c.from?M.range(u,d):M.range(d,u)}return o?s.replaceRange(s.main.extend(c.from,c.to)):l&&i==1&&s.ranges.length>1&&(h=rc(s,a.pos))?h:l?s.addRange(c):M.create([c])}}}function rc(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:s}=n.ranges[t];if(i<=e&&s>=e)return M.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}We.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let s=n.docView.tile.nearest(e.target);if(s&&s.isWidget()){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=M.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Ss(n.state,Kn,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};We.dragend=n=>(n.inputState.draggedContent=null,!1);function Dr(n,e,t,i){if(t=Ss(n.state,Un,t),!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&Jh(n,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}We.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),s=0,r=()=>{++s==t.length&&Dr(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return Dr(n,e,i,!0),!0}return!1};We.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=Al?null:e.clipboardData;return t?(Ol(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(ic(n),!1)};function oc(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function lc(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:Ss(n,Kn,e.join(n.lineBreak)),ranges:t,linewise:i}}let Cn=null;We.copy=We.cut=(n,e)=>{if(!ri(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:s}=lc(n.state);if(!t&&!s)return!1;Cn=s?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Al?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(oc(n,t),!1)};const Ml=Gt.define();function Rl(n,e){let t=[];for(let i of n.facet(ll)){let s=i(n,e);s&&t.push(s)}return t.length?n.update({effects:t,annotations:Ml.of(!0)}):null}function Pl(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=Rl(n.state,e);t?n.dispatch(t):n.update([])}},10)}Le.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Pl(n)};Le.blur=n=>{n.observer.clearSelectionRange(),Pl(n)};Le.compositionstart=Le.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};Le.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,T.chrome&&T.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};Le.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};We.beforeinput=(n,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return Xn(n,{from:a,to:h,insert:n.state.toText(r)},null),!0}}let s;if(T.chrome&&T.android&&(s=vl.find(r=>r.inputType==e.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return T.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),T.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>Le.compositionend(n,e),20),!1};const Lr=new Set;function ac(n){Lr.has(n)||(Lr.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Br=["pre-wrap","normal","pre-line","break-spaces"];let qt=!1;function Ir(){qt=!1}class hc{constructor(e){this.lineWrapping=e,this.doc=Q.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Br.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=Br.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class cc{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Be{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?Se.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof At?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Be(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var X=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(X||(X={}));const qi=.001;class ve{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>qi&&(qt=!0),this.height=e)}replace(e,t,i){return ve.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=s[l],u=r.lineAt(a,X.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,X.ByPosNoHeight,i,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,X.ByPosNoHeight,i,0,0));c+=u.from-a,a=u.from;let p=Yn.build(i.setDoc(o),e,c,f);r=ss(r,r.replace(a,h,p))}return r.updateHeight(i,0)}static empty(){return new Re(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,s=0,r=0;for(;;)if(t==i)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new uc(ve.of(e.slice(0,t)),o,ve.of(e.slice(i)))}}function ss(n,e){return n==e?n:(n.constructor!=e.constructor&&(qt=!0),e)}ve.prototype.size=1;const fc=he.replace({});class Nl extends ve{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new Be(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,s){return this.spaceAbove&&e<i+this.spaceAbove?new Be(s,0,i,this.spaceAbove,fc):this.mainBlock(i,s)}lineAt(e,t,i,s,r){let o=this.mainBlock(s,r);return this.spaceAbove?this.blockAt(0,i,s,r).join(o):o}forEachLine(e,t,i,s,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,X.ByPos,i,s,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Re extends Nl{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new Be(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof Re||s instanceof pe&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof pe?s=new Re(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):ve.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class pe extends ve{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let h=s+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),c=t.doc.lineAt(h),f=l+c.length*a,u=Math.max(i,e-f/2);return new Be(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:c,length:f}=t.doc.line(r+h);return new Be(c,f,i+l*h,l,0)}}lineAt(e,t,i,s,r){if(t==X.ByHeight)return this.blockAt(e,i,s,r);if(t==X.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Be(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),c=l+h.length*a,f=h.number-o,u=s+l*f+a*(h.from-r-f);return new Be(h.from,h.length,Math.max(s,Math.min(u,s+this.height-c)),c,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=e,f=s;c<=t;){let u=i.doc.lineAt(c);if(c==e){let p=u.number-l;f+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new Be(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof pe?i[i.length-1]=new pe(r.length+s):i.push(null,new pe(s-1))}if(e>0){let r=i[0];r instanceof pe?i[0]=new pe(e+r.length):i.unshift(new pe(e-1),null)}return ve.of(i)}decomposeLeft(e,t){t.push(new pe(e-1),null)}decomposeRight(e,t){t.push(null,new pe(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new pe(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++],u=0;f<0&&(u=-f,f=s.heights[s.index++]),a==-1?a=f:Math.abs(f-a)>=qi&&(a=-2);let d=new Re(c,f,u);d.outdated=!1,o.push(d),l+=c+1}l<=r&&o.push(null,new pe(r-l).updateHeight(e,l));let h=ve.of(o);return(a<0||Math.abs(h.height-this.height)>=qi||Math.abs(a-this.heightMetrics(e,t).perLine)>=qi)&&(qt=!0),ss(this,h)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class uc extends ve{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==X.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==X.ByPosNoHeight?X.ByPosNoHeight:X.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,X.ByPos,i,s,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,s,r,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&jr(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),jr(r,l)}return ve.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?ve.of(this.break?[e,null,t]:[e,t]):(this.left=ss(this.left,e),this.right=ss(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function jr(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof pe&&(i=n[e+1])instanceof pe&&n.splice(e-1,3,new pe(t.length+1+i.length))}const dc=5;class Yn{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 i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Re?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Re(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Nl(o,s,i)):(o||r||s>=dc)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Re(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new pe(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Re)return e;let t=new Re(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Re)&&!this.isCovered?this.nodes.push(new Re(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let s of this.nodes)s instanceof Re&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new Yn(i,e);return K.spans(t,i,s,r,0),r.finish(i)}}function pc(n,e,t){let i=new gc;return K.compare(n,e,t,i,0),i.changes}class gc{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&jt(e,t,this.changes,5)}}function mc(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,f=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let u=c.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(h==n.parentNode?s.innerHeight:a,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:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function xc(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function yc(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Bs{constructor(e,t,i,s){this.from=e,this.to=t,this.size=i,this.displaySize=s}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let s=e[i],r=t[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e,t){return he.replace({widget:new bc(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class bc extends ys{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class Wr{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Fr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=se.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(Gn).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new hc(t),this.stateDeco=Hr(e),this.heightMap=ve.empty().applyChanges(this.stateDeco,Q.empty,this.heightOracle.setDoc(e.doc),[new Ee(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=he.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new Ni(r,o))}}return this.viewports=e.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Fr:new Zn(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(ii(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=Hr(this.state);let s=e.changedRanges,r=Ee.extendWithRanges(s,pc(i,this.stateDeco,e?e.changes:de.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Ir(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||qt)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,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(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(hl)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?se.RTL:se.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:N,scaleY:v}=Uo(t,l);(N>.005&&Math.abs(this.scaleX-N)>.005||v>.005&&Math.abs(this.scaleY-v)>.005)&&(this.scaleX=N,this.scaleY=v,h|=16,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Go(e.scrollDOM);let p=(this.printing?yc:mc)(t,this.paddingTop),m=p.top-this.pixelViewport.top,x=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget&&!xc(e.dom))return 0;let w=l.width;if((this.contentDOMWidth!=w||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let N=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(N)&&(o=!0),o||s.lineWrapping&&Math.abs(w-this.contentDOMWidth)>s.charWidth){let{lineHeight:v,charWidth:C,textHeight:k}=e.docView.measureTextSize();o=v>0&&s.refresh(r,v,C,k,Math.max(5,w/C),N),o&&(e.docView.minWidth=0,h|=16)}m>0&&x>0?c=Math.max(m,x):m<0&&x<0&&(c=Math.min(m,x)),Ir();for(let v of this.viewports){let C=v.from==this.viewport.from?N:e.docView.measureVisibleLineHeights(v);this.heightMap=(o?ve.empty().applyChanges(this.stateDeco,Q.empty,this.heightOracle,[new Ee(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new cc(v.from,C))}qt&&(h|=2)}let A=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return A&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||A)&&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 i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Ni(s.lineAt(o-i*1e3,X.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,X.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,X.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new Ni(s.lineAt(u-1e3/2,X.ByHeight,r,0,0).from,s.lineAt(u+c+1e3/2,X.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Ni(this.heightMap.lineAt(i,X.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,X.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,X.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,X.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new Bs(t.mapPos(s.from),t.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=se.LTR&&!i)return[];let l=[],a=(c,f,u,d)=>{if(f-c<r)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>c&&y<f){a(c,y-10,u,d),a(y+10,f,u,d);return}let x=wc(e,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-c)<r&&Math.abs(y.to-f)<r&&!m.some(w=>y.from<w&&y.to>w));if(!x){if(f<u.to&&t&&i&&t.visibleRanges.some(A=>A.from<=f&&A.to>=f)){let A=t.moveToLineBoundary(M.cursor(f),!1,!0).head;A>c&&(f=A)}let y=this.gapSize(u,c,f,d),w=i||y<2e6?y:2e6;x=new Bs(c,f,y,w)}l.push(x)},h=c=>{if(c.length<o||c.type!=Se.Text)return;let f=kc(c.from,c.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,x,y;if(u!=null){let w=Di(f,u),A=((this.visibleBottom-this.visibleTop)/2+m)/c.height;x=w-A,y=w+A}else x=(this.visibleTop-c.top-m)/c.height,y=(this.visibleBottom-c.top+m)/c.height;d=Ei(f,x),p=Ei(f,y)}else{let m=f.total*this.heightOracle.charWidth,x=s*this.heightOracle.charWidth,y=0;if(m>2e6)for(let C of e)C.from>=c.from&&C.from<c.to&&C.size!=C.displaySize&&C.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=C.size-C.displaySize);let w=this.pixelViewport.left+y,A=this.pixelViewport.right+y,N,v;if(u!=null){let C=Di(f,u),k=((A-w)/2+x)/m;N=C-k,v=C+k}else N=(w-x)/m,v=(A+x)/m;d=Ei(f,N),p=Ei(f,v)}d>c.from&&a(c.from,d,c,f),p<c.to&&a(p,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(e,t,i,s){let r=Di(s,i)-Di(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){Bs.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=he.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];K.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let r=0;r<i.length&&!(s&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(s|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||ii(this.heightMap.lineAt(e,X.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)||ii(this.heightMap.lineAt(this.scaler.fromDOM(e),X.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 ii(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Ni{constructor(e,t){this.from=e,this.to=t}}function kc(n,e,t){let i=[],s=n,r=0;return K.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(i.push({from:s,to:e}),r+=e-s),{total:r,ranges:i}}function Ei({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function Di(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function wc(n,e){for(let t of n)if(e(t))return t}const Fr={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Hr(n){let e=n.facet(bs).filter(i=>typeof i!="function"),t=n.facet(_n).filter(i=>typeof i!="function");return t.length&&e.push(K.join(t)),e}class Zn{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,X.ByPos,e,0,0).top,c=t.lineAt(a,X.ByPos,e,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,s=r.domBottom}}eq(e){return e instanceof Zn?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function ii(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new Be(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>ii(s,e)):n._content)}const Li=L.define({combine:n=>n.join(" ")}),An=L.define({combine:n=>n.indexOf(!0)>-1}),On=ft.newName(),El=ft.newName(),Dl=ft.newName(),Ll={"&light":"."+El,"&dark":"."+Dl};function Tn(n,e,t){return new ft(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}const Sc=Tn("."+On,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Ll),vc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Is=T.ie&&T.ie_version<=11;class Cc{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new eh,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 i of t)this.queue.push(i);(T.ie&&T.ie_version<=11||T.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&T.android&&e.constructor.EDIT_CONTEXT!==!1&&!(T.chrome&&T.chrome_version<126)&&(this.editContext=new Oc(e),e.state.facet(Ye)&&(e.contentDOM.editContext=this.editContext.editContext)),Is&&(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)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{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.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(Ye)?i.root.activeElement!=this.dom:!ri(this.dom,s))return;let r=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(T.ie&&T.ie_version<=11||T.android&&T.chrome)&&!i.state.selection.main.empty&&s.focusNode&&oi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=pi(e.root);if(!t)return!1;let i=T.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Ac(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let s=ri(this.dom,i);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&ih(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,vc),Is&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Is&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Wt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&ri(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new $h(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,s=wl(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!is(this.view.state.selection,t.newSel.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=zr(t,e.previousSibling||e.target.previousSibling,-1),s=zr(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):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?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Ye)!=e.state.facet(Ye)&&(e.view.contentDOM.editContext=e.state.facet(Ye)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function zr(n,e,t){for(;e;){let i=ce.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function Vr(n,e){let t=e.startContainer,i=e.startOffset,s=e.endContainer,r=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return oi(o.node,o.offset,s,r)&&([t,i,s,r]=[s,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}}function Ac(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return Vr(n,s)}let t=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?Vr(n,t):null}class Oc{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let s=e.state.selection.main,{anchor:r,head:o}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&r<this.from?l=r:a==this.to&&r>this.to&&(a=r);let c=Sl(e.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!c){let u=M.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));is(u,s)||e.dispatch({selection:u,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:Q.of(i.text.slice(c.from,c.toB).split(`
10
+ `))};if((T.mac||T.android)&&f.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:Q.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!e.state.readOnly){let u=this.to-this.from+(f.to-f.from+f.insert.length);Xn(e,f,M.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),f.from<f.to&&!f.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}t.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(he.mark({attributes:{style:c}}).range(a,h))}}}e.dispatch({effects:fl.of(he.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=pi(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let c=h.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(h)){s=this.pendingContextChange=null,t+=c,this.to+=c;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),s&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&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)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class F{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(s=>s.forEach(r=>i(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||th(e.parent)||document,this.viewState=new Wr(e.state||U.create(e)),e.scrollTo&&e.scrollTo.is(Mi)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Dt).map(s=>new Ps(s));for(let s of this.plugins)s.update(this);this.observer=new Cc(this),this.inputState=new Kh(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ar(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof be?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,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(Ml))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Rl(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(U.phrases)!=this.state.facet(U.phrases))return this.setState(r);s=Ji.create(this,r,e),s.flags|=l;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 Ft(d.empty?d:M.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Mi)&&(f=d.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=ns.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(ei)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Li)!=s.state.facet(Li)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(kn))try{u(s)}catch(d){Ge(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!wl(this,c)&&h.force&&Wt(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 i of this.plugins)i.destroy(this);this.viewState=new Wr(e),this.plugins=e.facet(Dt).map(i=>new Ps(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Ar(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(Dt),i=e.state.facet(Dt);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new Ps(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){Ge(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-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,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Go(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(d=>{try{return d.read(this)}catch(p){return Ge(this.state,p),$r}}),f=Ji.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a: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;d<h.length;d++)if(c[d]!=$r)try{let p=h[d];p.write&&p.write(c[d],this)}catch(p){Ge(this.state,p)}if(u&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(p>1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(kn))l(t)}get themeClasses(){return On+" "+(this.state.facet(An)?Dl:El)+" "+this.state.facet(Li)}updateAttrs(){let e=qr(this,ul,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Ye)?"true":"false",class:"cm-content",style:`${T.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),qr(this,Gn,t);let i=this.observer.ignore(()=>{let s=br(this.contentDOM,this.contentAttrs,t),r=br(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(F.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(ei);let e=this.state.facet(F.cspNonce);ft.mount(this.root,this.styleModules.concat(Sc).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;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Ls(this,e,Or(this,e,t,i))}moveByGroup(e,t){return Ls(this,e,Or(this,e,t,i=>jh(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return M.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,i=!0){return Ih(this,e,t,i)}moveVertically(e,t,i){return Ls(this,e,Wh(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=vn(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),vn(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[Ke.find(r,e-s.from,-1,t)];return Zi(i,o.dir==se.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(al)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Tc)return el(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Jo(r.isolates,i=Sr(this,e))))return r.order;i||(i=Sr(this,e));let s=hh(e.text,t,i);return this.bidiCache.push(new ns(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||T.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ko(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Mi.of(new Ft(typeof e=="number"?M.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Mi.of(new Ft(M.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return it.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return it.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ft.newName(),s=[Li.of(i),ei.of(Tn(`.${i}`,e))];return t&&t.dark&&s.push(An.of(!0)),s}static baseTheme(e){return gs.lowest(ei.of(Tn("."+On,e,Ll)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&ce.get(i)||ce.get(e);return((t=s==null?void 0:s.root)===null||t===void 0?void 0:t.view)||null}}F.styleModule=ei;F.inputHandler=ol;F.clipboardInputFilter=Un;F.clipboardOutputFilter=Kn;F.scrollHandler=cl;F.focusChangeEffect=ll;F.perLineTextDirection=al;F.exceptionSink=rl;F.updateListener=kn;F.editable=Ye;F.mouseSelectionStyle=nl;F.dragMovesSelection=sl;F.clickAddsSelectionRange=il;F.decorations=bs;F.blockWrappers=dl;F.outerDecorations=_n;F.atomicRanges=Si;F.bidiIsolatedRanges=pl;F.scrollMargins=gl;F.darkTheme=An;F.cspNonce=L.define({combine:n=>n.length?n[0]:""});F.contentAttributes=Gn;F.editorAttributes=ul;F.lineWrapping=F.contentAttributes.of({class:"cm-lineWrapping"});F.announce=ue.define();const Tc=4096,$r={};class ns{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:se.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&i.push(new ns(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function qr(n,e,t){for(let i=n.state.facet(e),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&$n(o,t)}return t}const Mc=T.mac?"mac":T.windows?"win":T.linux?"linux":"key";function Rc(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Bi(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const Pc=gs.default(F.domEventHandlers({keydown(n,e){return Lc(Nc(e.state),n,e,"editor")}})),Bl=L.define({enables:Pc}),Qr=new WeakMap;function Nc(n){let e=n.facet(Bl),t=Qr.get(e);return t||Qr.set(e,t=Dc(e.reduce((i,s)=>i.concat(s),[]))),t}let lt=null;const Ec=4e3;function Dc(n,e=Mc){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>Rc(y,e));for(let y=1;y<p.length;y++){let w=p.slice(0,y).join(" ");s(w,!0),d[w]||(d[w]={preventDefault:!0,stopPropagation:!1,run:[A=>{let N=lt={view:A,prefix:w,scope:o};return setTimeout(()=>{lt==N&&(lt=null)},Ec),!0}]})}let m=p.join(" ");s(m,!1);let x=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&x.run.push(a),h&&(x.preventDefault=!0),c&&(x.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in c)c[u].run.push(d=>f(d,Mn))}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let Mn=null;function Lc(n,e,t,i){Mn=e;let s=Ua(e),r=Ta(s,0),o=Ma(r)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;lt&&lt.view==t&&lt.scope==i&&(l=lt.prefix+" ",Cl.indexOf(e.keyCode)<0&&(h=!0,lt=null));let f=new Set,u=x=>{if(x){for(let y of x.run)if(!f.has(y)&&(f.add(y),y(t)))return x.stopPropagation&&(c=!0),!0;x.preventDefault&&(x.stopPropagation&&(c=!0),h=!0)}return!1},d=n[i],p,m;return d&&(u(d[l+Bi(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(T.windows&&e.ctrlKey&&e.altKey)&&!(T.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ut[e.keyCode])&&p!=s?(u(d[l+Bi(p,e,!0)])||e.shiftKey&&(m=ui[e.keyCode])!=s&&m!=p&&u(d[l+Bi(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Bi(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),Mn=null,a}class vi{constructor(e,t,i,s,r){this.className=e,this.left=t,this.top=i,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let s=e.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=Il(e);return[new vi(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Bc(e,t,i)}}function Il(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==se.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function Ur(n,e,t,i){let s=n.coordsAtPos(e,t*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=n.posAtCoords({x:r.left+1,y:o}),a=n.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Bc(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let i=Math.max(t.from,n.viewport.from),s=Math.min(t.to,n.viewport.to),r=n.textDirection==se.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=Il(n),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),d=Sn(n,i,1),p=Sn(n,s,-1),m=d.type==Se.Text?d:null,x=p.type==Se.Text?p:null;if(m&&(n.lineWrapping||d.widgetLineBreaks)&&(m=Ur(n,i,1,m)),x&&(n.lineWrapping||p.widgetLineBreaks)&&(x=Ur(n,s,-1,x)),m&&x&&m.from==x.from&&m.to==x.to)return w(A(t.from,t.to,m));{let v=m?A(t.from,null,m):N(d,!1),C=x?A(null,t.to,x):N(p,!0),k=[];return(m||d).to<(x||p).from-(m&&x?1:0)||d.widgetLineBreaks>1&&v.bottom+n.defaultLineHeight/2<C.top?k.push(y(f,v.bottom,u,C.top)):v.bottom<C.top&&n.elementAtHeight((v.bottom+C.top)/2).type==Se.Text&&(v.bottom=C.top=(v.bottom+C.top)/2),w(v).concat(k).concat(w(C))}function y(v,C,k,j){return new vi(e,v-a.left,C-a.top,Math.max(0,k-v),j-C)}function w({top:v,bottom:C,horizontal:k}){let j=[];for(let B=0;B<k.length;B+=2)j.push(y(k[B],v,k[B+1],C));return j}function A(v,C,k){let j=1e9,B=-1e9,H=[];function I(W,z,Z,le,ae){let ee=n.coordsAtPos(W,W==k.to?-2:2),ne=n.coordsAtPos(Z,Z==k.from?2:-2);!ee||!ne||(j=Math.min(ee.top,ne.top,j),B=Math.max(ee.bottom,ne.bottom,B),ae==se.LTR?H.push(r&&z?f:ee.left,r&&le?u:ne.right):H.push(!r&&le?f:ne.left,!r&&z?u:ee.right))}let R=v??k.from,E=C??k.to;for(let W of n.visibleRanges)if(W.to>R&&W.from<E)for(let z=Math.max(W.from,R),Z=Math.min(W.to,E);;){let le=n.state.doc.lineAt(z);for(let ae of n.bidiSpans(le)){let ee=ae.from+le.from,ne=ae.to+le.from;if(ee>=Z)break;ne>z&&I(Math.max(ee,z),v==null&&ee<=R,Math.min(ne,Z),C==null&&ne>=E,ae.dir)}if(z=le.to+1,z>=Z)break}return H.length==0&&I(R,v==null,E,C==null,n.textDirection),{top:j,bottom:B,horizontal:H}}function N(v,C){let k=l.top+(C?v.top:v.bottom);return{top:k,bottom:k,horizontal:[]}}}function Ic(n,e){return n.constructor==e.constructor&&n.eq(e)}class jc{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Qi)!=e.state.facet(Qi)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(Qi);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,i)=>!Ic(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[i].constructor&&s.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e,T.safari&&T.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Qi=L.define();function jl(n){return[it.define(e=>new jc(e,n)),Qi.of(n)]}const mi=L.define({combine(n){return Ha(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Wc(n={}){return[mi.of(n),Fc,Hc,zc,hl.of(!0)]}function Wl(n){return n.startState.facet(mi)!=n.state.facet(mi)}const Fc=jl({above:!0,markers(n){let{state:e}=n,t=e.facet(mi),i=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:M.cursor(s.head,s.head>s.anchor?-1:1);for(let a of vi.forRange(n,o,l))i.push(a)}}return i},update(n,e){n.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Wl(n);return t&&Kr(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){Kr(e.state,n)},class:"cm-cursorLayer"});function Kr(n,e){e.style.animationDuration=n.facet(mi).cursorBlinkRate+"ms"}const Hc=jl({above:!1,markers(n){return n.state.selection.ranges.map(e=>e.empty?[]:vi.forRange(n,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||Wl(n)},class:"cm-selectionLayer"}),zc=gs.highest(F.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));function Vc(){return qc}const $c=he.line({class:"cm-activeLine"}),qc=it.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>e&&(t.push($c.range(s.from)),e=s.from)}return he.set(t)}},{decorations:n=>n.decorations});class Qt extends ct{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Qt.prototype.elementClass="";Qt.prototype.toDOM=void 0;Qt.prototype.mapMode=Pe.TrackBefore;Qt.prototype.startSide=Qt.prototype.endSide=-1;Qt.prototype.point=!0;const Fl=1024;let Qc=0;class js{constructor(e,t){this.from=e,this.to=t}}class ${constructor(e={}){this.id=Qc++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Te.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}$.closedBy=new $({deserialize:n=>n.split(" ")});$.openedBy=new $({deserialize:n=>n.split(" ")});$.group=new $({deserialize:n=>n.split(" ")});$.isolate=new $({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});$.contextHash=new $({perNode:!0});$.lookAhead=new $({perNode:!0});$.mounted=new $({perNode:!0});class ai{constructor(e,t,i,s=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=s}static get(e){return e&&e.props&&e.props[$.mounted.id]}}const Uc=Object.create(null);class Te{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Uc,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new Te(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop($.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop($.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}}Te.none=new Te("",Object.create(null),0,8);class Jn{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let s=null;for(let r of e){let o=r(i);if(o){s||(s=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in s&&(l=a.combine(s[a.id],l)),s[a.id]=l}}t.push(s?new Te(i.name,s,i.id,i.flags):i)}return new Jn(t)}}const Ii=new WeakMap,Gr=new WeakMap;var ie;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(ie||(ie={}));class oe{constructor(e,t,i,s,r){if(this.type=e,this.children=t,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=ai.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let s=i.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Pn(this.topNode,e)}cursorAt(e,t=0,i=0){let s=Ii.get(this)||this.topNode,r=new Pn(s);return r.moveTo(e,t),Ii.set(this,r._tree),r}get topNode(){return new De(this,0,0,null)}resolve(e,t=0){let i=xi(Ii.get(this)||this.topNode,e,t,!1);return Ii.set(this,i),i}resolveInner(e,t=0){let i=xi(Gr.get(this)||this.topNode,e,t,!0);return Gr.set(this,i),i}resolveStack(e,t=0){return _c(this,e,t)}iterate(e){let{enter:t,leave:i,from:s=0,to:r=this.length}=e,o=e.mode||0,l=(o&ie.IncludeAnonymous)>0;for(let a=this.cursor(o|ie.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:ir(Te.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new oe(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new oe(Te.none,t,i,s)))}static build(e){return Xc(e)}}oe.empty=new oe(Te.none,[],[],0);class er{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new er(this.buffer,this.index)}}class pt{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return Te.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],s=this.set.types[t],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,s,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Hl(r,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=s[l++],r[a++]=s[l++]-i;let h=r[a++]=s[l++]-i;r[a++]=s[l++]-e,o=Math.max(o,h)}return new pt(r,o,this.set)}}function Hl(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function xi(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!i&&n instanceof De&&n.index<0?null:n.parent;if(!o)return n;n=o}let r=i?0:ie.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof De&&o.index<0&&((s=l.enter(e,t,r))===null||s===void 0?void 0:s.from)!=o.from&&(n=l);for(;;){let o=n.enter(e,t,r);if(!o)return n;n=o}}class zl{cursor(e=0){return new Pn(this,e)}getChild(e,t=null,i=null){let s=_r(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return _r(this,e,t,i)}resolve(e,t=0){return xi(this,e,t,!1)}resolveInner(e,t=0){return xi(this,e,t,!0)}matchContext(e){return Rn(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let s=t.lastChild;if(!s||s.to!=t.to)break;s.type.isError&&s.from==s.to?(i=t,t=s.prevSibling):t=s}return i}get node(){return this}get next(){return this.parent}}class De extends zl{constructor(e,t,i,s){super(),this._tree=e,this.from=t,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,s,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],f=a[e]+o.from,u;if(!(!(r&ie.EnterBracketed&&c instanceof oe&&(u=ai.get(c))&&!u.overlay&&u.bracketed&&i>=f&&i<=f+c.length)&&!Hl(s,i,f,f+c.length))){if(c instanceof pt){if(r&ie.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,i-f,s);if(d>-1)return new ht(new Kc(o,c,e,f),null,d)}else if(r&ie.IncludeAnonymous||!c.type.isAnonymous||tr(c)){let d;if(!(r&ie.IgnoreMounts)&&(d=ai.get(c))&&!d.overlay)return new De(d.tree,f,e,o);let p=new De(c,f,e,o);return r&ie.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,i,s,r)}}}if(r&ie.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let s;if(!(i&ie.IgnoreOverlays)&&(s=ai.get(this._tree))&&s.overlay){let r=e-this.from,o=i&ie.EnterBracketed&&s.bracketed;for(let{from:l,to:a}of s.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?a>=r:a>r))return new De(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function _r(n,e,t,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=s.type.is(t),!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function Rn(n,e,t=e.length-1){for(let i=n;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class Kc{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}}class ht extends zl{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new ht(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&ie.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new ht(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new ht(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new ht(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1];e.push(i.slice(s,r,o)),t.push(0)}return new oe(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Vl(n){if(!n.length)return null;let e=0,t=n[0];for(let r=1;r<n.length;r++){let o=n[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof De&&t.index<0?null:t.parent,s=n.slice();return i?s[e]=i:s.splice(e,1),new Gc(s,t)}class Gc{constructor(e,t){this.heads=e,this.node=t}get next(){return Vl(this.heads)}}function _c(n,e,t){let i=n.resolveInner(e,t),s=null;for(let r=i instanceof De?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(s||(s=[i])).push(o.resolve(e,t)),r=o}else{let o=ai.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new De(o.tree,o.overlay[0].from+r.from,-1,r);(s||(s=[i])).push(xi(l,e,t,!1))}}return s?Vl(s):i}class Pn{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~ie.EnterBracketed,e instanceof De)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof De?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&ie.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&ie.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&ie.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=s)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&ie.IncludeAnonymous||l instanceof pt||!l.type.isAnonymous||tr(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}for(let s=i;s<this.stack.length;s++)t=new ht(this.buffer,t,this.stack[s]);return this.bufferNode=new ht(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&t&&t(this),s=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,s=!0}}}matchContext(e){if(!this.buffer)return Rn(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let s=e.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Rn(this._tree,e,s);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}}function tr(n){return n.children.some(e=>e instanceof pt||!e.type.isAnonymous||tr(e))}function Xc(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=Fl,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new er(t,t.length):t,a=i.types,h=0,c=0;function f(v,C,k,j,B,H){let{id:I,start:R,end:E,size:W}=l,z=c,Z=h;if(W<0)if(l.next(),W==-1){let Ce=r[I];k.push(Ce),j.push(R-v);return}else if(W==-3){h=I;return}else if(W==-4){c=I;return}else throw new RangeError(`Unrecognized record size: ${W}`);let le=a[I],ae,ee,ne=R-v;if(E-R<=s&&(ee=x(l.pos-C,B))){let Ce=new Uint16Array(ee.size-ee.skip),q=l.pos-ee.size,fe=Ce.length;for(;l.pos>q;)fe=y(ee.start,Ce,fe);ae=new pt(Ce,E-ee.start,i),ne=ee.start-v}else{let Ce=l.pos-W;l.next();let q=[],fe=[],D=I>=o?I:-1,me=0,Ae=E;for(;l.pos>Ce;)D>=0&&l.id==D&&l.size>=0?(l.end<=Ae-s&&(p(q,fe,R,me,l.end,Ae,D,z,Z),me=q.length,Ae=l.end),l.next()):H>2500?u(R,Ce,q,fe):f(R,Ce,q,fe,D,H+1);if(D>=0&&me>0&&me<q.length&&p(q,fe,R,me,R,Ae,D,z,Z),q.reverse(),fe.reverse(),D>-1&&me>0){let xe=d(le,Z);ae=ir(le,q,fe,0,q.length,0,E-R,xe,xe)}else ae=m(le,q,fe,E-R,z-E,Z)}k.push(ae),j.push(ne)}function u(v,C,k,j){let B=[],H=0,I=-1;for(;l.pos>C;){let{id:R,start:E,end:W,size:z}=l;if(z>4)l.next();else{if(I>-1&&E<I)break;I<0&&(I=W-s),B.push(R,E,W),H++,l.next()}}if(H){let R=new Uint16Array(H*4),E=B[B.length-2];for(let W=B.length-3,z=0;W>=0;W-=3)R[z++]=B[W],R[z++]=B[W+1]-E,R[z++]=B[W+2]-E,R[z++]=z;k.push(new pt(R,B[2]-E,i)),j.push(E-v)}}function d(v,C){return(k,j,B)=>{let H=0,I=k.length-1,R,E;if(I>=0&&(R=k[I])instanceof oe){if(!I&&R.type==v&&R.length==B)return R;(E=R.prop($.lookAhead))&&(H=j[I]+R.length+E)}return m(v,k,j,B,H,C)}}function p(v,C,k,j,B,H,I,R,E){let W=[],z=[];for(;v.length>j;)W.push(v.pop()),z.push(C.pop()+k-B);v.push(m(i.types[I],W,z,H-B,R-H,E)),C.push(B-k)}function m(v,C,k,j,B,H,I){if(H){let R=[$.contextHash,H];I=I?[R].concat(I):[R]}if(B>25){let R=[$.lookAhead,B];I=I?[R].concat(I):[R]}return new oe(v,C,k,j,I)}function x(v,C){let k=l.fork(),j=0,B=0,H=0,I=k.end-s,R={size:0,start:0,skip:0};e:for(let E=k.pos-v;k.pos>E;){let W=k.size;if(k.id==C&&W>=0){R.size=j,R.start=B,R.skip=H,H+=4,j+=4,k.next();continue}let z=k.pos-W;if(W<0||z<E||k.start<I)break;let Z=k.id>=o?4:0,le=k.start;for(k.next();k.pos>z;){if(k.size<0)if(k.size==-3||k.size==-4)Z+=4;else break e;else k.id>=o&&(Z+=4);k.next()}B=le,j+=W,H+=Z}return(C<0||j==v)&&(R.size=j,R.start=B,R.skip=H),R.size>4?R:void 0}function y(v,C,k){let{id:j,start:B,end:H,size:I}=l;if(l.next(),I>=0&&j<o){let R=k;if(I>4){let E=l.pos-(I-4);for(;l.pos>E;)k=y(v,C,k)}C[--k]=R,C[--k]=H-v,C[--k]=B-v,C[--k]=j}else I==-3?h=j:I==-4&&(c=j);return k}let w=[],A=[];for(;l.pos>0;)f(n.start||0,n.bufferStart||0,w,A,-1,0);let N=(e=n.length)!==null&&e!==void 0?e:w.length?A[0]+w[0].length:0;return new oe(a[n.topID],w.reverse(),A.reverse(),N)}const Xr=new WeakMap;function Ui(n,e){if(!n.isAnonymous||e instanceof pt||e.type!=n)return 1;let t=Xr.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof oe)){t=1;break}t+=Ui(n,i)}Xr.set(e,t)}return t}function ir(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p<s;p++)h+=Ui(n,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,m,x,y,w){for(let A=x;A<y;){let N=A,v=m[A],C=Ui(n,p[A]);for(A++;A<y;A++){let k=Ui(n,p[A]);if(C+k>=c)break;C+=k}if(A==N+1){if(C>c){let k=p[N];d(k.children,k.positions,0,k.children.length,m[N]+w);continue}f.push(p[N])}else{let k=m[A-1]+p[A-1].length-v;f.push(ir(n,p,m,N,A,v,k,null,a))}u.push(v+w-r)}}return d(e,t,i,s,0),(l||a)(f,u,o)}class Ct{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new Ct(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=i)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new Ct(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&s.push(u),o.to>f)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return s}}class $l{startParse(e,t,i){return typeof e=="string"&&(e=new Yc(e)),i=i?i.length?i.map(s=>new js(s.from,s.to)):[new js(0,0)]:[new js(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}}class Yc{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new $({perNode:!0});let Zc=0;class Ne{constructor(e,t,i,s){this.name=e,this.set=t,this.base=i,this.modified=s,this.id=Zc++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof Ne&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let s=new Ne(i,[],null,[]);if(s.set.push(s),t)for(let r of t.set)s.set.push(r);return s}static defineModifier(e){let t=new rs(e);return i=>i.modified.indexOf(t)>-1?i:rs.get(i.base||i,i.modified.concat(t).sort((s,r)=>s.id-r.id))}}let Jc=0;class rs{constructor(e){this.name=e,this.instances=[],this.id=Jc++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&ef(t,l.modified));if(i)return i;let s=[],r=new Ne(e.name,s,e,t);for(let l of t)l.instances.push(r);let o=tf(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(rs.get(l,a));return r}}function ef(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function tf(n){let e=[[]];for(let t=0;t<n.length;t++)for(let i=0,s=e.length;i<s;i++)e.push(e[i].concat(n[t]));return e.sort((t,i)=>i.length-t.length)}function ql(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let f=0;;){if(l=="..."&&f>0&&f+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==s.length)break;let d=s[f++];if(f==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(f)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let c=new yi(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return Ql.add(e)}const Ql=new $({combine(n,e){let t,i,s;for(;n||e;){if(!n||e&&n.depth>=e.depth?(s=e,e=e.next):(s=n,n=n.next),t&&t.mode==s.mode&&!s.context&&!t.context)continue;let r=new yi(s.tags,s.mode,s.context);t?t.next=r:i=r,t=r}return i}});class yi{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}yi.empty=new yi([],2,null);function Ul(n,e){let t=Object.create(null);for(let r of n)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:s=null}=e||{};return{style:r=>{let o=s;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function sf(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function nf(n,e,t,i=0,s=n.length){let r=new rf(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}class rf{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,s,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,c=of(e)||yi.empty,f=sf(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(s+=(s?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop($.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(x=>!x.scope||x.scope(u.tree.type)),m=e.firstChild();for(let x=0,y=l;;x++){let w=x<u.overlay.length?u.overlay[x]:null,A=w?w.from+l:a,N=Math.max(t,y),v=Math.min(i,A);if(N<v&&m)for(;e.from<v&&(this.highlightRange(e,N,v,s,r),this.startSpan(Math.min(v,e.to),h),!(e.to>=A||!e.nextSibling())););if(!w||A>i)break;y=w.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,w.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),h))}m&&e.parent()}else if(e.firstChild()){u&&(s="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}}function of(n){let e=n.type.prop(Ql);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const S=Ne.define,ji=S(),nt=S(),Yr=S(nt),Zr=S(nt),rt=S(),Wi=S(rt),Ws=S(rt),Ve=S(),mt=S(Ve),He=S(),ze=S(),Nn=S(),Yt=S(Nn),Fi=S(),b={comment:ji,lineComment:S(ji),blockComment:S(ji),docComment:S(ji),name:nt,variableName:S(nt),typeName:Yr,tagName:S(Yr),propertyName:Zr,attributeName:S(Zr),className:S(nt),labelName:S(nt),namespace:S(nt),macroName:S(nt),literal:rt,string:Wi,docString:S(Wi),character:S(Wi),attributeValue:S(Wi),number:Ws,integer:S(Ws),float:S(Ws),bool:S(rt),regexp:S(rt),escape:S(rt),color:S(rt),url:S(rt),keyword:He,self:S(He),null:S(He),atom:S(He),unit:S(He),modifier:S(He),operatorKeyword:S(He),controlKeyword:S(He),definitionKeyword:S(He),moduleKeyword:S(He),operator:ze,derefOperator:S(ze),arithmeticOperator:S(ze),logicOperator:S(ze),bitwiseOperator:S(ze),compareOperator:S(ze),updateOperator:S(ze),definitionOperator:S(ze),typeOperator:S(ze),controlOperator:S(ze),punctuation:Nn,separator:S(Nn),bracket:Yt,angleBracket:S(Yt),squareBracket:S(Yt),paren:S(Yt),brace:S(Yt),content:Ve,heading:mt,heading1:S(mt),heading2:S(mt),heading3:S(mt),heading4:S(mt),heading5:S(mt),heading6:S(mt),contentSeparator:S(Ve),list:S(Ve),quote:S(Ve),emphasis:S(Ve),strong:S(Ve),link:S(Ve),monospace:S(Ve),strikethrough:S(Ve),inserted:S(),deleted:S(),changed:S(),invalid:S(),meta:Fi,documentMeta:S(Fi),annotation:S(Fi),processingInstruction:S(Fi),definition:Ne.defineModifier("definition"),constant:Ne.defineModifier("constant"),function:Ne.defineModifier("function"),standard:Ne.defineModifier("standard"),local:Ne.defineModifier("local"),special:Ne.defineModifier("special")};for(let n in b){let e=b[n];e instanceof Ne&&(e.name=n)}Ul([{tag:b.link,class:"tok-link"},{tag:b.heading,class:"tok-heading"},{tag:b.emphasis,class:"tok-emphasis"},{tag:b.strong,class:"tok-strong"},{tag:b.keyword,class:"tok-keyword"},{tag:b.atom,class:"tok-atom"},{tag:b.bool,class:"tok-bool"},{tag:b.url,class:"tok-url"},{tag:b.labelName,class:"tok-labelName"},{tag:b.inserted,class:"tok-inserted"},{tag:b.deleted,class:"tok-deleted"},{tag:b.literal,class:"tok-literal"},{tag:b.string,class:"tok-string"},{tag:b.number,class:"tok-number"},{tag:[b.regexp,b.escape,b.special(b.string)],class:"tok-string2"},{tag:b.variableName,class:"tok-variableName"},{tag:b.local(b.variableName),class:"tok-variableName tok-local"},{tag:b.definition(b.variableName),class:"tok-variableName tok-definition"},{tag:b.special(b.variableName),class:"tok-variableName2"},{tag:b.definition(b.propertyName),class:"tok-propertyName tok-definition"},{tag:b.typeName,class:"tok-typeName"},{tag:b.namespace,class:"tok-namespace"},{tag:b.className,class:"tok-className"},{tag:b.macroName,class:"tok-macroName"},{tag:b.propertyName,class:"tok-propertyName"},{tag:b.operator,class:"tok-operator"},{tag:b.comment,class:"tok-comment"},{tag:b.meta,class:"tok-meta"},{tag:b.invalid,class:"tok-invalid"},{tag:b.punctuation,class:"tok-punctuation"}]);var Fs;const Lt=new $;function lf(n){return L.define({combine:n?e=>e.concat(n):void 0})}const af=new $;class je{constructor(e,t,i=[],s=""){this.data=e,this.name=s,U.prototype.hasOwnProperty("tree")||Object.defineProperty(U.prototype,"tree",{get(){return Mt(this)}}),this.parser=t,this.extension=[Kt.of(this),U.languageData.of((r,o,l)=>{let a=Jr(r,o,l),h=a.type.prop(Lt);if(!h)return[];let c=r.facet(h),f=a.type.prop(af);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return Jr(e,t,i).type.prop(Lt)==this.data}findRegions(e){let t=e.facet(Kt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(Lt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop($.mounted);if(l){if(l.tree.prop(Lt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let h=r.children[a];h instanceof oe&&s(h,r.positions[a]+o)}};return s(Mt(e),0),i}get allowsNesting(){return!0}}je.setState=ue.define();function Jr(n,e,t){let i=n.facet(Kt),s=Mt(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,t,ie.ExcludeBuffers|ie.EnterBracketed))r.type.isTop&&(s=r);return s}class os extends je{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=lf(e.languageData);return new os(t,e.parser.configure({props:[Lt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new os(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Mt(n){let e=n.field(je.state,!1);return e?e.tree:oe.empty}class hf{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let Zt=null;class ls{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new ls(e,t,[],oe.empty,0,i,[],null)}startParse(){return this.parser.startParse(new hf(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=oe.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Ct.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Ct.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Zt;Zt=this;try{return e()}finally{Zt=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=eo(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=Ct.applyChanges(i,a),s=oe.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new ls(this.parser,t,i,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=eo(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends $l{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=Zt;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new oe(Te.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Zt}}function eo(n,e,t){return Ct.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class Ut{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new Ut(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=ls.create(e.facet(Kt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Ut(i)}}je.state=Rt.define({create:Ut.init,update(n,e){for(let t of e.effects)if(t.is(je.setState))return t.value;return e.startState.facet(Kt)!=e.state.facet(Kt)?Ut.init(e.state):n.apply(e)}});let Kl=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Kl=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Hs=typeof navigator<"u"&&(!((Fs=navigator.scheduling)===null||Fs===void 0)&&Fs.isInputPending)?()=>navigator.scheduling.isInputPending():null,cf=it.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(je.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(je.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Kl(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(je.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Hs?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>Hs&&Hs()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:je.setState.of(new Ut(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Ge(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Kt=L.define({combine(n){return n.length?n[0]:null},enables:n=>[je.state,cf,F.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class ff{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const uf=new $;function df({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const pf=new $;class vs{constructor(e,t){this.specs=e;let i;function s(l){let a=ft.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof je?l=>l.prop(Lt)==o.data:o?l=>l==o:void 0,this.style=Ul(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ft(i):null,this.themeType=t.themeType}static define(e,t){return new vs(e,t||{})}}const En=L.define(),Gl=L.define({combine(n){return n.length?[n[0]]:null}});function zs(n){let e=n.facet(En);return e.length?e:n.facet(Gl)}function gf(n,e){let t=[xf],i;return n instanceof vs&&(n.module&&t.push(F.styleModule.of(n.module)),i=n.themeType),e!=null&&e.fallback?t.push(Gl.of(n)):i?t.push(En.computeN([F.darkTheme],s=>s.facet(F.darkTheme)==(i=="dark")?[n]:[])):t.push(En.of(n)),t}class mf{constructor(e){this.markCache=Object.create(null),this.tree=Mt(e.state),this.decorations=this.buildDeco(e,zs(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Mt(e.state),i=zs(e.state),s=i!=zs(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!s&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return he.none;let i=new ci;for(let{from:s,to:r}of e.visibleRanges)nf(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=he.mark({class:a})))},s,r);return i.finish()}}const xf=gs.high(it.fromClass(mf,{decorations:n=>n.decorations})),yf=vs.define([{tag:b.meta,color:"#404740"},{tag:b.link,textDecoration:"underline"},{tag:b.heading,textDecoration:"underline",fontWeight:"bold"},{tag:b.emphasis,fontStyle:"italic"},{tag:b.strong,fontWeight:"bold"},{tag:b.strikethrough,textDecoration:"line-through"},{tag:b.keyword,color:"#708"},{tag:[b.atom,b.bool,b.url,b.contentSeparator,b.labelName],color:"#219"},{tag:[b.literal,b.inserted],color:"#164"},{tag:[b.string,b.deleted],color:"#a11"},{tag:[b.regexp,b.escape,b.special(b.string)],color:"#e40"},{tag:b.definition(b.variableName),color:"#00f"},{tag:b.local(b.variableName),color:"#30a"},{tag:[b.typeName,b.namespace],color:"#085"},{tag:b.className,color:"#167"},{tag:[b.special(b.variableName),b.macroName],color:"#256"},{tag:b.definition(b.propertyName),color:"#00c"},{tag:b.comment,color:"#940"},{tag:b.invalid,color:"#f00"}]),bf=Object.create(null),to=[Te.none],io=[],so=Object.create(null),kf=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])kf[n]=wf(bf,e);function Vs(n,e){io.indexOf(n)>-1||(io.push(n),console.warn(e))}function wf(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=n[h]||b[h];c?typeof c=="function"?a.length?a=a.map(c):Vs(h,`Modifier ${h} used at start of tag`):a.length?Vs(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:Vs(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=so[s];if(r)return r.id;let o=so[s]=Te.define({id:to.length,name:i,props:[ql({[i]:t})]});return to.push(o),o.id}se.RTL,se.LTR;var no={};class as{constructor(e,t,i,s,r,o,l,a,h,c=0,f){this.p=e,this.stack=t,this.state=i,this.reducePos=s,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=a,this.curContext=h,this.lookAhead=c,this.parent=f}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let s=e.parser.context;return new as(e,[],t,i,i,0,[],0,s?new ro(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,s=e&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(s);if(l&&(this.score+=l),i==0){this.pushState(r.getGoto(this.state,s,!0),this.reducePos),s<r.minRepeatTerm&&this.storeNode(s,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(s,this.reducePos);return}let a=this.stack.length-(i-1)*3-(e&262144?6:0),h=a?this.stack[a-2]:this.p.ranges[0].from,c=this.reducePos-h;c>=2e3&&!(!((t=this.p.parser.nodeSet.types[s])===null||t===void 0)&&t.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=c));let f=a?this.stack[a-1]:0,u=this.bufferBase+this.buffer.length-f;if(s<r.minRepeatTerm||e&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(s,h,d,u+4,!0)}if(e&262144)this.state=this.stack[a];else{let d=this.stack[a-3];this.state=r.getGoto(d,s,!0)}for(;this.stack.length>a;)this.stack.pop();this.reduceContext(s,h)}storeNode(e,t,i,s=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(t==i)return;if(o.buffer[l-2]>=t){o.buffer[l-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,s);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let a=o;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,s>4&&(s-=4)}this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=s}}shift(e,t,i,s){if(e&131072)this.pushState(e&65535,this.pos);else if((e&262144)==0){let r=e,{parser:o}=this.p;this.pos=s;let l=o.stateFlag(r,1);!l&&(s>i||t<=o.maxNode)&&(this.reducePos=s),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,s,4)}else this.pos=s,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,s,4)}apply(e,t,i,s){e&65536?this.reduce(e):this.shift(e,t,i,s)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let s=this.pos;this.reducePos=this.pos=s+e.length,this.pushState(t,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),s=e.bufferBase+t;for(;e&&s==e.bufferBase;)e=e.parent;return new as(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new Sf(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if((i&65536)==0)return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let s=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&s.push(t[r],o);if(this.stack.length<120)for(let r=0;s.length<8&&r<t.length;r+=2){let o=t[r+1];s.some((l,a)=>a&1&&l==o)||s.push(t[r],o)}t=s}let i=[];for(let s=0;s<t.length&&i.length<4;s+=2){let r=t[s+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[s],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if((t&65536)==0)return!1;if(!e.validAction(this.state,t)){let i=t>>19,s=t&65535,r=this.stack.length-i*3;if(r<0||e.getGoto(this.stack[r],s,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(s,r)=>{if(!t.includes(s))return t.push(s),e.allActions(s,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let a=o&65535,h=this.stack.length-l*3;if(h>=0&&e.getGoto(this.stack[h],a,!1)>=0)return l<<19|65536|a}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new ro(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class ro{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class Sf{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let s=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=s}}class hs{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new hs(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new hs(this.stack,this.pos,this.index)}}function Hi(n,e=Uint16Array){if(typeof n!="string")return n;let t=null;for(let i=0,s=0;i<n.length;){let r=0;for(;;){let o=n.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),r+=a,l)break;r*=46}t?t[s++]=r:t=new e(r)}return t}class Ki{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const oo=new Ki;class vf{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=oo,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,s=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!s)return null;let o=this.ranges[--s];r-=i.from-o.to,i=o}for(;t<0?r>i.to:r>=i.to;){if(s==this.ranges.length-1)return null;let o=this.ranges[++s];r+=o.from-i.to,i=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,s;if(t>=0&&t<this.chunk.length)i=this.pos+e,s=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),s=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),s}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=oo,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let s of this.ranges){if(s.from>=t)break;s.to>e&&(i+=this.input.read(Math.max(s.from,e),Math.min(s.to,t)))}return i}}class Ht{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;Af(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}Ht.prototype.contextual=Ht.prototype.fallback=Ht.prototype.extend=!1;Ht.prototype.fallback=Ht.prototype.extend=!1;class Cf{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function Af(n,e,t,i,s,r){let o=0,l=1<<i,{dialect:a}=t.p.parser;e:for(;(l&n[o])!=0;){let h=n[o+1];for(let d=o+3;d<h;d+=2)if((n[d+1]&l)>0){let p=n[d];if(a.allows(p)&&(e.token.value==-1||e.token.value==p||Of(p,e.token.value,s,r))){e.acceptToken(p);break}}let c=e.next,f=0,u=n[o+2];if(e.next<0&&u>f&&n[h+u*3-3]==65535){o=n[h+u*3-1];continue e}for(;f<u;){let d=f+u>>1,p=h+d+(d<<1),m=n[p],x=n[p+1]||65536;if(c<m)u=d;else if(c>=x)f=d+1;else{o=n[p+2],e.advance();continue e}}break}}function lo(n,e,t){for(let i=e,s;(s=n[i])!=65535;i++)if(s==t)return i-e;return-1}function Of(n,e,t,i){let s=lo(t,i,e);return s<0||lo(t,i,n)<s}const Me=typeof process<"u"&&no&&/\bparse\b/.test(no.LOG);let $s=null;function ao(n,e,t){let i=n.cursor(ie.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(n.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:n.length}}class Tf{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?ao(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?ao(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],s=this.index[t];if(s==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[s],o=this.start[t]+i.positions[s];if(o>e)return this.nextStart=o,null;if(r instanceof oe){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let a=r.prop($.lookAhead);if(!a||l+a<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}}class Mf{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new Ki)}getActions(e){let t=0,i=null,{parser:s}=e.p,{tokenizers:r}=s,o=s.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let h=0;h<r.length;h++){if((1<<h&o)==0)continue;let c=r[h],f=this.tokens[h];if(!(i&&!c.fallback)&&((c.contextual||f.start!=e.pos||f.mask!=o||f.context!=l)&&(this.updateCachedToken(f,c,e),f.mask=o,f.context=l),f.lookAhead>f.end+25&&(a=Math.max(f.lookAhead,a)),f.value!=0)){let u=t;if(f.extended>-1&&(t=this.addActions(e,f.extended,f.end,t)),t=this.addActions(e,f.value,f.end,t),!c.extend&&(i=f,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new Ki,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new Ki,{pos:i,p:s}=e;return t.start=i,t.end=Math.min(i+1,s.stream.end),t.value=i==s.stream.end?s.parser.eofTerm:0,t}updateCachedToken(e,t,i){let s=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(s,e),i),e.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?e.value=l>>1:e.extended=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(s+1)}putAction(e,t,i,s){for(let r=0;r<s;r+=3)if(this.actions[r]==e)return s;return this.actions[s++]=e,this.actions[s++]=t,this.actions[s++]=i,s}addActions(e,t,i,s){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let h=o.stateSlot(r,a?2:1);;h+=3){if(l[h]==65535)if(l[h+1]==1)h=Xe(l,h+2);else{s==0&&l[h+1]==2&&(s=this.putAction(Xe(l,h+2),t,i,s));break}l[h]==t&&(s=this.putAction(Xe(l,h+1),t,i,s))}return s}}class Rf{constructor(e,t,i,s){this.parser=e,this.input=t,this.ranges=s,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new vf(t,s),this.tokens=new Mf(e,this.stream),this.topTerm=e.top[1];let{from:r}=s[0];this.stacks=[as.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>e.bufferLength*4?new Tf(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],s,r;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{s||(s=[],r=[]),s.push(l);let a=this.tokens.getMainToken(l);r.push(a.value,a.end)}}break}}if(!i.length){let o=s&&Nf(s);if(o)return Me&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw Me&&s&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&s){let o=this.stoppedAt!=null&&s[0].pos>this.stoppedAt?s[0]:this.runRecovery(s,r,i);if(o)return Me&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,a)=>a.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let a=o+1;a<i.length;a++){let h=i[a];if(l.sameState(h)||l.buffer.length>500&&h.buffer.length>500)if((l.score-h.score||l.buffer.length-h.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let s=e.pos,{parser:r}=this,o=Me?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&s>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let h=e.curContext&&e.curContext.tracker.strict,c=h?e.curContext.hash:0;for(let f=this.fragments.nodeAt(s);f;){let u=this.parser.nodeSet.types[f.type.id]==f.type?r.getGoto(e.state,f.type.id):-1;if(u>-1&&f.length&&(!h||(f.prop($.contextHash)||0)==c))return e.useNode(f,u),Me&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(f.type.id)})`),!0;if(!(f instanceof oe)||f.children.length==0||f.positions[0]>0)break;let d=f.children[0];if(d instanceof oe&&f.positions[0]==0)f=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),Me&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let h=0;h<a.length;){let c=a[h++],f=a[h++],u=a[h++],d=h==a.length||!i,p=d?e:e.split(),m=this.tokens.mainToken;if(p.apply(c,f,m?m.start:p.pos,u),Me&&console.log(o+this.stackID(p)+` (via ${(c&65536)==0?"shift":`reduce of ${r.getName(c&65535)}`} for ${r.getName(f)} @ ${s}${p==e?"":", split"})`),d)return!0;p.pos>s?t.push(p):i.push(p)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return ho(e,t),!0}}runRecovery(e,t,i){let s=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],h=t[(o<<1)+1],c=Me?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),Me&&console.log(c+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let f=l.split(),u=c;for(let d=0;d<10&&f.forceReduce()&&(Me&&console.log(u+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,i));d++)Me&&(u=this.stackID(f)+" -> ");for(let d of l.recoverByInsert(a))Me&&console.log(c+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(h==l.pos&&(h++,a=0),l.recoverByDelete(a,h),Me&&console.log(c+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),ho(l,i)):(!s||s.score<f.score)&&(s=f)}return s}stackToTree(e){return e.close(),oe.build({buffer:hs.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=($s||($s=new WeakMap)).get(e);return t||$s.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function ho(n,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==n.pos&&i.sameState(n)){e[t].score<n.score&&(e[t]=n);return}}e.push(n)}class Pf{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}}class cs extends $l{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),s=[];for(let l=0;l<t.length;l++)s.push([]);function r(l,a,h){s[l].push([a,a.deserialize(String(h))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=$[a]);for(let h=1;h<l.length;){let c=l[h++];if(c>=0)r(c,a,l[h++]);else{let f=l[h+-c];for(let u=-c;u>0;u--)r(l[h++],a,f);h++}}}this.nodeSet=new Jn(t.map((l,a)=>Te.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:s[a],top:i.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Fl;let o=Hi(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(co),this.states=Hi(e.states,Uint32Array),this.data=Hi(e.stateData),this.goto=Hi(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new Ht(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let s=new Rf(this,e,t,i);for(let r of this.wrappers)s=r(s,e,t,i);return s}getGoto(e,t,i=!1){let s=this.goto;if(t>=s[0])return-1;for(let r=s[t+1];;){let o=s[r++],l=o&1,a=s[r++];if(l&&i)return a;for(let h=r+(o>>1);r<h;r++)if(s[r]==e)return a;if(l)return-1}}hasAction(e,t){let i=this.data;for(let s=0;s<2;s++)for(let r=this.stateSlot(e,s?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=Xe(i,r+2)];else{if(i[r+1]==2)return Xe(i,r+2);break}if(o==t||o==0)return Xe(i,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),s=i?t(i):void 0;for(let r=this.stateSlot(e,1);s==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=Xe(this.data,r+2);else break;s=t(Xe(this.data,r+1))}return s}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=Xe(this.data,i+2);else break;if((this.data[i+2]&1)==0){let s=this.data[i+1];t.some((r,o)=>o&1&&r==s)||t.push(this.data[i],s)}}return t}configure(e){let t=Object.assign(Object.create(cs.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let s=e.tokenizers.find(r=>r.from==i);return s?s.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,s)=>{let r=e.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[s]=co(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(i[o]=!0)}let s=null;for(let r=0;r<t.length;r++)if(!i[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(s||(s=new Uint8Array(this.maxTerm+1)))[l]=1;return new Pf(e,i,s)}static deserialize(e){return new cs(e)}}function Xe(n,e){return n[e]|n[e+1]<<16}function Nf(n){let e=null;for(let t of n){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function co(n){if(n.external){let e=n.extend?1:0;return(t,i)=>n.external(t,i)<<1|e}return n.get}function fo(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Ef(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let i=fo(e)+fo(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Df(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:Ef(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function Lf(n,e){return t=>{for(let i=Mt(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}const _l=new class extends ct{};_l.startSide=1;_l.endSide=-1;const Bf=36,uo=1,If=2,Et=3,qs=4,jf=5,Wf=6,Ff=7,Hf=8,zf=9,Vf=10,$f=11,qf=12,Qf=13,Uf=14,Kf=15,Gf=16,_f=17,po=18,Xf=19,Xl=20,Yl=21,go=22,Yf=23,Zf=24;function Dn(n){return n>=65&&n<=90||n>=97&&n<=122||n>=48&&n<=57}function Jf(n){return n>=48&&n<=57||n>=97&&n<=102||n>=65&&n<=70}function bt(n,e,t){for(let i=!1;;){if(n.next<0)return;if(n.next==e&&!i){n.advance();return}i=t&&!i&&n.next==92,n.advance()}}function eu(n,e){e:for(;;){if(n.next<0)return;if(n.next==36){n.advance();for(let t=0;t<e.length;t++){if(n.next!=e.charCodeAt(t))continue e;n.advance()}if(n.next==36){n.advance();return}}else n.advance()}}function tu(n,e){let t="[{<(".indexOf(String.fromCharCode(e)),i=t<0?e:"]}>)".charCodeAt(t);for(;;){if(n.next<0)return;if(n.next==i&&n.peek(1)==39){n.advance(2);return}n.advance()}}function Ln(n,e){for(;!(n.next!=95&&!Dn(n.next));)e!=null&&(e+=String.fromCharCode(n.next)),n.advance();return e}function iu(n){if(n.next==39||n.next==34||n.next==96){let e=n.next;n.advance(),bt(n,e,!1)}else Ln(n)}function mo(n,e){for(;n.next==48||n.next==49;)n.advance();e&&n.next==e&&n.advance()}function xo(n,e){for(;;){if(n.next==46){if(e)break;e=!0}else if(n.next<48||n.next>57)break;n.advance()}if(n.next==69||n.next==101)for(n.advance(),(n.next==43||n.next==45)&&n.advance();n.next>=48&&n.next<=57;)n.advance()}function yo(n){for(;!(n.next<0||n.next==10);)n.advance()}function xt(n,e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)==n)return!0;return!1}const Qs=` \r
11
+ `;function Zl(n,e,t){let i=Object.create(null);i.true=i.false=jf,i.null=i.unknown=Wf;for(let s of n.split(" "))s&&(i[s]=Xl);for(let s of e.split(" "))s&&(i[s]=Yl);for(let s of(t||"").split(" "))s&&(i[s]=Zf);return i}const su="array binary bit boolean char character clob date decimal double float int integer interval large national nchar nclob numeric object precision real smallint time timestamp varchar varying ",nu="absolute action add after all allocate alter and any are as asc assertion at authorization before begin between both breadth by call cascade cascaded case cast catalog check close collate collation column commit condition connect connection constraint constraints constructor continue corresponding count create cross cube current current_date current_default_transform_group current_transform_group_for_type current_path current_role current_time current_timestamp current_user cursor cycle data day deallocate declare default deferrable deferred delete depth deref desc describe descriptor deterministic diagnostics disconnect distinct do domain drop dynamic each else elseif end end-exec equals escape except exception exec execute exists exit external fetch first for foreign found from free full function general get global go goto grant group grouping handle having hold hour identity if immediate in indicator initially inner inout input insert intersect into is isolation join key language last lateral leading leave left level like limit local localtime localtimestamp locator loop map match method minute modifies module month names natural nesting new next no none not of old on only open option or order ordinality out outer output overlaps pad parameter partial path prepare preserve primary prior privileges procedure public read reads recursive redo ref references referencing relative release repeat resignal restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll search second section select session session_user set sets signal similar size some space specific specifictype sql sqlexception sqlstate sqlwarning start state static system_user table temporary then timezone_hour timezone_minute to trailing transaction translation treat trigger under undo union unique unnest until update usage user using value values view when whenever where while with without work write year zone ",Bn={backslashEscapes:!1,hashComments:!1,spaceAfterDashes:!1,slashComments:!1,doubleQuotedStrings:!1,doubleDollarQuotedStrings:!1,unquotedBitLiterals:!1,treatBitsAsBytes:!1,charSetCasts:!1,plsqlQuotingMechanism:!1,operatorChars:"*+-%<>!=&|~^/",specialVar:"?",identifierQuotes:'"',caseInsensitiveIdentifiers:!1,words:Zl(nu,su)};function ru(n,e,t,i){let s={};for(let r in Bn)s[r]=(n.hasOwnProperty(r)?n:Bn)[r];return e&&(s.words=Zl(e,t||"",i)),s}function Jl(n){return new Cf(e=>{var t;let{next:i}=e;if(e.advance(),xt(i,Qs)){for(;xt(e.next,Qs);)e.advance();e.acceptToken(Bf)}else if(i==36&&n.doubleDollarQuotedStrings){let s=Ln(e,"");e.next==36&&(e.advance(),eu(e,s),e.acceptToken(Et))}else if(i==39||i==34&&n.doubleQuotedStrings)bt(e,i,n.backslashEscapes),e.acceptToken(Et);else if(i==35&&n.hashComments||i==47&&e.next==47&&n.slashComments)yo(e),e.acceptToken(uo);else if(i==45&&e.next==45&&(!n.spaceAfterDashes||e.peek(1)==32))yo(e),e.acceptToken(uo);else if(i==47&&e.next==42){e.advance();for(let s=1;;){let r=e.next;if(e.next<0)break;if(e.advance(),r==42&&e.next==47){if(s--,e.advance(),!s)break}else r==47&&e.next==42&&(s++,e.advance())}e.acceptToken(If)}else if((i==101||i==69)&&e.next==39)e.advance(),bt(e,39,!0),e.acceptToken(Et);else if((i==110||i==78)&&e.next==39&&n.charSetCasts)e.advance(),bt(e,39,n.backslashEscapes),e.acceptToken(Et);else if(i==95&&n.charSetCasts)for(let s=0;;s++){if(e.next==39&&s>1){e.advance(),bt(e,39,n.backslashEscapes),e.acceptToken(Et);break}if(!Dn(e.next))break;e.advance()}else if(n.plsqlQuotingMechanism&&(i==113||i==81)&&e.next==39&&e.peek(1)>0&&!xt(e.peek(1),Qs)){let s=e.peek(1);e.advance(2),tu(e,s),e.acceptToken(Et)}else if(xt(i,n.identifierQuotes)){const s=i==91?93:i;bt(e,s,!1),e.acceptToken(Xf)}else if(i==40)e.acceptToken(Ff);else if(i==41)e.acceptToken(Hf);else if(i==123)e.acceptToken(zf);else if(i==125)e.acceptToken(Vf);else if(i==91)e.acceptToken($f);else if(i==93)e.acceptToken(qf);else if(i==59)e.acceptToken(Qf);else if(n.unquotedBitLiterals&&i==48&&e.next==98)e.advance(),mo(e),e.acceptToken(go);else if((i==98||i==66)&&(e.next==39||e.next==34)){const s=e.next;e.advance(),n.treatBitsAsBytes?(bt(e,s,n.backslashEscapes),e.acceptToken(Yf)):(mo(e,s),e.acceptToken(go))}else if(i==48&&(e.next==120||e.next==88)||(i==120||i==88)&&e.next==39){let s=e.next==39;for(e.advance();Jf(e.next);)e.advance();s&&e.next==39&&e.advance(),e.acceptToken(qs)}else if(i==46&&e.next>=48&&e.next<=57)xo(e,!0),e.acceptToken(qs);else if(i==46)e.acceptToken(Uf);else if(i>=48&&i<=57)xo(e,!1),e.acceptToken(qs);else if(xt(i,n.operatorChars)){for(;xt(e.next,n.operatorChars);)e.advance();e.acceptToken(Kf)}else if(xt(i,n.specialVar))e.next==i&&e.advance(),iu(e),e.acceptToken(_f);else if(i==58||i==44)e.acceptToken(Gf);else if(Dn(i)){let s=Ln(e,String.fromCharCode(i));e.acceptToken(e.next==46||e.peek(-s.length-1)==46?po:(t=n.words[s.toLowerCase()])!==null&&t!==void 0?t:po)}})}const ea=Jl(Bn),ou=cs.deserialize({version:14,states:"%vQ]QQOOO#wQRO'#DSO$OQQO'#CwO%eQQO'#CxO%lQQO'#CyO%sQQO'#CzOOQQ'#DS'#DSOOQQ'#C}'#C}O'UQRO'#C{OOQQ'#Cv'#CvOOQQ'#C|'#C|Q]QQOOQOQQOOO'`QQO'#DOO(xQRO,59cO)PQQO,59cO)UQQO'#DSOOQQ,59d,59dO)cQQO,59dOOQQ,59e,59eO)jQQO,59eOOQQ,59f,59fO)qQQO,59fOOQQ-E6{-E6{OOQQ,59b,59bOOQQ-E6z-E6zOOQQ,59j,59jOOQQ-E6|-E6|O+VQRO1G.}O+^QQO,59cOOQQ1G/O1G/OOOQQ1G/P1G/POOQQ1G/Q1G/QP+kQQO'#C}O+rQQO1G.}O)PQQO,59cO,PQQO'#Cw",stateData:",[~OtOSPOSQOS~ORUOSUOTUOUUOVROXSOZTO]XO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O^]ORvXSvXTvXUvXVvXXvXZvX]vX_vX`vXavXbvXcvXdvXevXfvXgvXhvX~OsvX~P!jOa_Ob_Oc_O~ORUOSUOTUOUUOVROXSOZTO^tO_UO`UOa`Ob`Oc`OdUOeUOfUOgUOhUO~OWaO~P$ZOYcO~P$ZO[eO~P$ZORUOSUOTUOUUOVROXSOZTO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O]hOsoX~P%zOajObjOcjO~O^]ORkaSkaTkaUkaVkaXkaZka]ka_ka`kaakabkackadkaekafkagkahka~Oska~P'kO^]O~OWvXYvX[vX~P!jOWnO~P$ZOYoO~P$ZO[pO~P$ZO^]ORkiSkiTkiUkiVkiXkiZki]ki_ki`kiakibkickidkiekifkigkihki~Oski~P)xOWkaYka[ka~P'kO]hO~P$ZOWkiYki[ki~P)xOasObsOcsO~O",goto:"#hwPPPPPPPPPPPPPPPPPPPPPPPPPPx||||!Y!^!d!xPPP#[TYOZeUORSTWZbdfqT[OZQZORiZSWOZQbRQdSQfTZgWbdfqQ^PWk^lmrQl_Qm`RrseVORSTWZbdfq",nodeNames:"⚠ LineComment BlockComment String Number Bool Null ( ) { } [ ] ; . Operator Punctuation SpecialVar Identifier QuotedIdentifier Keyword Type Bits Bytes Builtin Script Statement CompositeIdentifier Parens Braces Brackets Statement",maxTerm:38,nodeProps:[["isolate",-4,1,2,3,19,""]],skippedNodes:[0,1,2],repeatNodeCount:3,tokenData:"RORO",tokenizers:[0,ea],topRules:{Script:[0,25]},tokenPrec:0});function In(n){let e=n.cursor().moveTo(n.from,-1);for(;/Comment/.test(e.name);)e.moveTo(e.from,-1);return e.node}function bi(n,e){let t=n.sliceString(e.from,e.to),i=/^([`'"\[])(.*)([`'"\]])$/.exec(t);return i?i[2]:t}function fs(n){return n&&(n.name=="Identifier"||n.name=="QuotedIdentifier")}function lu(n,e){if(e.name=="CompositeIdentifier"){let t=[];for(let i=e.firstChild;i;i=i.nextSibling)fs(i)&&t.push(bi(n,i));return t}return[bi(n,e)]}function bo(n,e){for(let t=[];;){if(!e||e.name!=".")return t;let i=In(e);if(!fs(i))return t;t.unshift(bi(n,i)),e=In(i)}}function au(n,e){let t=Mt(n).resolveInner(e,-1),i=cu(n.doc,t);return t.name=="Identifier"||t.name=="QuotedIdentifier"||t.name=="Keyword"?{from:t.from,quoted:t.name=="QuotedIdentifier"?n.doc.sliceString(t.from,t.from+1):null,parents:bo(n.doc,In(t)),aliases:i}:t.name=="."?{from:e,quoted:null,parents:bo(n.doc,t),aliases:i}:{from:e,quoted:null,parents:[],empty:!0,aliases:i}}const hu=new Set("where group having order union intersect except all distinct limit offset fetch for".split(" "));function cu(n,e){let t;for(let s=e;!t;s=s.parent){if(!s)return null;s.name=="Statement"&&(t=s)}let i=null;for(let s=t.firstChild,r=!1,o=null;s;s=s.nextSibling){let l=s.name=="Keyword"?n.sliceString(s.from,s.to).toLowerCase():null,a=null;if(!r)r=l=="from";else if(l=="as"&&o&&fs(s.nextSibling))a=bi(n,s.nextSibling);else{if(l&&hu.has(l))break;o&&fs(s)&&(a=bi(n,s))}a&&(i||(i=Object.create(null)),i[a]=lu(n,o)),o=/Identifier$/.test(s.name)?s:null}return i}function fu(n,e,t){return t.map(i=>({...i,label:i.label[0]==n?i.label:n+i.label+e,apply:void 0}))}const uu=/^\w*$/,du=/^[`'"\[]?\w*[`'"\]]?$/;function ko(n){return n.self&&typeof n.self.label=="string"}class sr{constructor(e,t){this.idQuote=e,this.idCaseInsensitive=t,this.list=[],this.children=void 0}child(e){let t=this.children||(this.children=Object.create(null)),i=t[e];return i||(e&&!this.list.some(s=>s.label==e)&&this.list.push(wo(e,"type",this.idQuote,this.idCaseInsensitive)),t[e]=new sr(this.idQuote,this.idCaseInsensitive))}maybeChild(e){return this.children?this.children[e]:null}addCompletion(e){let t=this.list.findIndex(i=>i.label==e.label);t>-1?this.list[t]=e:this.list.push(e)}addCompletions(e){for(let t of e)this.addCompletion(typeof t=="string"?wo(t,"property",this.idQuote,this.idCaseInsensitive):t)}addNamespace(e){Array.isArray(e)?this.addCompletions(e):ko(e)?this.addNamespace(e.children):this.addNamespaceObject(e)}addNamespaceObject(e){for(let t of Object.keys(e)){let i=e[t],s=null,r=t.replace(/\\?\./g,l=>l=="."?"\0":l).split("\0"),o=this;ko(i)&&(s=i.self,i=i.children);for(let l=0;l<r.length;l++)s&&l==r.length-1&&o.addCompletion(s),o=o.child(r[l].replace(/\\\./g,"."));o.addNamespace(i)}}}function wo(n,e,t,i){return new RegExp("^[a-z_][a-z_\\d]*$",i?"i":"").test(n)?{label:n,type:e}:{label:n,type:e,apply:t+n+ta(t)}}function ta(n){return n==="["?"]":n}function pu(n,e,t,i,s,r){var o;let l=((o=r==null?void 0:r.spec.identifierQuotes)===null||o===void 0?void 0:o[0])||'"',a=new sr(l,!!(r!=null&&r.spec.caseInsensitiveIdentifiers)),h=s?a.child(s):null;return a.addNamespace(n),e&&(h||a).addCompletions(e),t&&a.addCompletions(t),h&&a.addCompletions(h.list),i&&a.addCompletions((h||a).child(i).list),c=>{let{parents:f,from:u,quoted:d,empty:p,aliases:m}=au(c.state,c.pos);if(p&&!c.explicit)return null;m&&f.length==1&&(f=m[f[0]]||f);let x=a;for(let w of f){for(;!x.children||!x.children[w];)if(x==a&&h)x=h;else if(x==h&&i)x=x.child(i);else return null;let A=x.maybeChild(w);if(!A)return null;x=A}let y=x.list;if(x==a&&m&&(y=y.concat(Object.keys(m).map(w=>({label:w,type:"constant"})))),d){let w=d[0],A=ta(w),N=c.state.sliceDoc(c.pos,c.pos+1)==A;return{from:u,to:N?c.pos+1:void 0,options:fu(w,A,y),validFor:du}}else return{from:u,options:y,validFor:uu}}}function gu(n){return n==Yl?"type":n==Xl?"keyword":"variable"}function mu(n,e,t){let i=Object.keys(n).map(s=>t(e?s.toUpperCase():s,gu(n[s])));return Lf(["QuotedIdentifier","String","LineComment","BlockComment","."],Df(i))}let xu=ou.configure({props:[uf.add({Statement:df()}),pf.add({Statement(n,e){return{from:Math.min(n.from+100,e.doc.lineAt(n.from).to),to:n.to}},BlockComment(n){return{from:n.from+2,to:n.to-2}}}),ql({Keyword:b.keyword,Type:b.typeName,Builtin:b.standard(b.name),Bits:b.number,Bytes:b.string,Bool:b.bool,Null:b.null,Number:b.number,String:b.string,Identifier:b.name,QuotedIdentifier:b.special(b.string),SpecialVar:b.special(b.name),LineComment:b.lineComment,BlockComment:b.blockComment,Operator:b.operator,"Semi Punctuation":b.punctuation,"( )":b.paren,"{ }":b.brace,"[ ]":b.squareBracket})]});class us{constructor(e,t,i){this.dialect=e,this.language=t,this.spec=i}get extension(){return this.language.extension}configureLanguage(e,t){return new us(this.dialect,this.language.configure(e,t),this.spec)}static define(e){let t=ru(e,e.keywords,e.types,e.builtin),i=os.define({name:"sql",parser:xu.configure({tokenizers:[{from:ea,to:Jl(t)}]}),languageData:{commentTokens:{line:"--",block:{open:"/*",close:"*/"}},closeBrackets:{brackets:["(","[","{","'",'"',"`"]}}});return new us(t,i,e)}}function yu(n,e){return{label:n,type:e,boost:-1}}function bu(n,e=!1,t){return mu(n.dialect.words,e,t||yu)}function ku(n){return n.schema?pu(n.schema,n.tables,n.schemas,n.defaultTable,n.defaultSchema,n.dialect||nr):()=>null}function wu(n){return n.schema?(n.dialect||nr).language.data.of({autocomplete:ku(n)}):[]}function Su(n={}){let e=n.dialect||nr;return new ff(e.language,[wu(n),e.language.data.of({autocomplete:bu(e,n.upperCaseKeywords,n.keywordCompletion)})])}const nr=us.define({}),vu="http://www.w3.org/1999/02/22-rdf-syntax-ns#type";function ia(n){let e="",t=!1,i=!1,s=!1,r=!1;for(let o=0;o<n.length;o++){const l=n[o];if(r){e+=l,r=!1;continue}if((i||s)&&l==="\\"){e+=l,r=!0;continue}if(!i&&!s){if(l==="<"){const a=o>0?n[o-1]:" ",h=n[o+1]??"",c=/\s|[({[;,=]/.test(a),f=h!==""&&!/\s/.test(h)&&h!=="="&&h!==">",u=n.indexOf(">",o+1)!==-1;if(!(c&&f&&u)){e+=l;continue}t=!0,e+=l;continue}if(l===">"&&t){t=!1,e+=l;continue}}if(!t&&!s&&l==="'"){i=!i,e+=l;continue}if(!t&&!i&&l==='"'){s=!s,e+=l;continue}if(!t&&!i&&!s&&l==="#"){for(;o<n.length&&n[o]!==`
12
+ `&&n[o]!=="\r";)o++;o<n.length&&(e+=n[o]);continue}e+=l}return e}function Cu(n){const e=ia(n),t=e.match(/where\s*\{([\s\S]+)\}/i),i=t?t[1]:e,s=String.raw`(?:<[^>]+>|_:[A-Za-z][\w-]*|\?[A-Za-z_][\w-]*|(?:[A-Za-z][\w+.-]*|):[^\s{};,.]+|a|"(?:[^"\\]|\\.)*"(?:@[A-Za-z-]+|\^\^(?:<[^>]+>|(?:[A-Za-z][\w+.-]*|):[^\s{};,.]+))?)`,o=new RegExp(`(${s})\\s+(${s})\\s+(${s})\\s*\\.?`,"ig").exec(i);return o?{s:o[1],p:o[2],o:o[3]}:null}function Au(n){const e=new Map,t=ia(n),i=/(?:^|\s)PREFIX\s+([A-Za-z][\w-]*)?\s*:\s*<([^>]+)>/gim;let s;for(;(s=i.exec(t))!==null;)e.set(s[1]??"",s[2]);return e}function Ou(n,e){const t=n.trim().replace(/[.;]$/,"");if(t==="a")return vu;if(t.startsWith("<")&&t.endsWith(">"))return t.slice(1,-1);const i=t.match(/^"((?:[^"\\]|\\.)*)"(?:(@[A-Za-z-]+)|\^\^(<[^>]+>|(?:[A-Za-z][\w+.-]*|):[^\s]+))?$/);if(i){const r=i[1],o=i[2]??"",l=i[3]??"";if(o)return`"${r}"${o}`;if(!l)return`"${r}"`;if(l.startsWith("<")&&l.endsWith(">"))return`"${r}"^^${l}`;const a=l.match(/^([A-Za-z][\w-]*|):(.+)$/);if(a){const h=e.get(a[1]);if(h)return`"${r}"^^<${h}${a[2]}>`}return`"${r}"^^${l}`}const s=t.match(/^([A-Za-z][\w-]*|):(.+)$/);if(s){const r=e.get(s[1]);if(r)return`${r}${s[2]}`}return t}function ot(n){return n==null?null:typeof n=="string"||typeof n=="number"||typeof n=="boolean"?String(n):n&&typeof n=="object"&&"value"in n?ot(n.value):String(n)}function Us(n,e,t){return e.startsWith("?")?ot(n[e.slice(1)]):Ou(e,t)}function sa(n,e){if(!Array.isArray(n)||n.length===0)return[];if("s"in n[0]&&"p"in n[0]&&"o"in n[0])return n.map(s=>({s:ot(s.s),p:ot(s.p),o:ot(s.o)})).filter(s=>s.s&&s.p&&s.o);if("subject"in n[0]&&"predicate"in n[0]&&"object"in n[0])return n.map(s=>({s:ot(s.subject),p:ot(s.predicate),o:ot(s.object)})).filter(s=>s.s&&s.p&&s.o);const t=Cu(e);if(!t)return[];const i=Au(e);return n.map(s=>({s:Us(s,t.s,i),p:Us(s,t.p,i),o:Us(s,t.o,i)})).filter(s=>s.s&&s.p&&s.o)}function Tu(n,e){var r;const t=new Map;for(const o of n){const l=`${o.s}\0${o.p}\0${o.o}`;t.has(l)||t.set(l,o)}const i=new Map;for(const o of e){const l=`${o.s}\0${o.p}\0${o.o}`,a=o.g||"__no_graph__";i.has(l)||i.set(l,new Map);const h=i.get(l);h.has(a)||h.set(a,o)}const s=[];for(const[o,l]of t.entries()){const a=Array.from(((r=i.get(o))==null?void 0:r.values())??[]);if(a.length===0){s.push({s:l.s,p:l.p,o:l.o,g:"",graphType:"",paranet:"",source:"",ual:"",txHash:"",timestamp:""});continue}for(const h of a)s.push({s:l.s,p:l.p,o:l.o,g:h.g||"",graphType:h.graphType||"",paranet:h.paranet||"",source:h.source||"",ual:h.ual||"",txHash:h.txHash||"",timestamp:h.timestamp||""})}return s}function nd(){return g.jsxs("div",{style:{padding:"28px 32px",height:"100%",overflow:"auto"},children:[g.jsx("h1",{className:"page-title",children:"Memory Explorer"}),g.jsxs("div",{className:"tab-group",children:[g.jsx(Cs,{to:"/explorer",end:!0,className:({isActive:n})=>`tab-item ${n?"active":""}`,children:"Graph"}),g.jsx(Cs,{to:"/explorer/sparql",className:({isActive:n})=>`tab-item ${n?"active":""}`,children:"SPARQL"}),g.jsx(Cs,{to:"/explorer/paranets",className:({isActive:n})=>`tab-item ${n?"active":""}`,children:"Paranets"})]}),g.jsxs(pa,{children:[g.jsx(Nt,{path:"/",element:g.jsx(ju,{})}),g.jsx(Nt,{path:"/sparql",element:g.jsx(Hu,{})}),g.jsx(Nt,{path:"/paranets",element:g.jsx(Yu,{})}),g.jsx(Nt,{path:"/publish",element:g.jsx(As,{to:"/explorer",replace:!0})}),g.jsx(Nt,{path:"/history",element:g.jsx(As,{to:"/explorer",replace:!0})}),g.jsx(Nt,{path:"/saved",element:g.jsx(As,{to:"/explorer",replace:!0})})]})]})}const Mu=[1e3,5e3,1e4,25e3,5e4],Ru="http://www.w3.org/2000/01/rdf-schema#label",na="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",ds=[{h:25,s:85,l:55},{h:210,s:80,l:55},{h:150,s:70,l:45},{h:280,s:70,l:60},{h:45,s:85,l:50},{h:340,s:75,l:55},{h:180,s:70,l:45},{h:90,s:65,l:45}];function ra(n,e,t){return`hsl(${n}, ${e}%, ${t}%)`}function Pu(n,e){const t=ds[n%ds.length],i=(e%5-2)*6;return ra(t.h,t.s,Math.max(30,Math.min(75,t.l+i)))}function Nu(n){const e=ds[n%ds.length];return ra(e.h,e.s,e.l)}const ps="#5f8598",jn="#22d3ee";function oa(n){return n.startsWith("http://")||n.startsWith("https://")||n.startsWith("urn:")||n.startsWith("_:")||n.startsWith("<")&&n.endsWith(">")}function la(n){const e=[];let t=0;for(const i of n){const s=i.object;if(oa(s))e.push({subject:i.subject,predicate:i.predicate,object:s});else{const r=`_:lit_${t++}`;e.push({subject:i.subject,predicate:i.predicate,object:r}),e.push({subject:r,predicate:Ru,object:s})}}return e}function Eu(n){const e=new Map;for(const t of n){if(t.predicate!==na)continue;const i=e.get(t.subject)||[];i.push(t.object),e.set(t.subject,i)}return e}function Wn(n){if(typeof n=="number"&&Number.isFinite(n))return n;if(typeof n=="string"){const e=Number(n);return Number.isFinite(e)?e:null}if(n&&typeof n=="object"){const e=n.value;return Wn(e)}return null}function Du(n){const e=Array.isArray(n==null?void 0:n.bindings)?n.bindings:Array.isArray(n)?n:null;if(!e||e.length===0)return null;const t=e[0];if(!t||typeof t!="object")return null;for(const i of["count","total","c"]){const s=Wn(t[i]);if(s!=null)return s}for(const i of Object.values(t)){const s=Wn(i);if(s!=null)return s}return null}function Ks(n){return n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}const Lu=/^[a-zA-Z][a-zA-Z0-9+\-.]*:[^\s<>"{}|\\^`]*$/;function Gs(n){return Lu.test(n)?n:null}function Bu(n,e=12){const t=new Map;for(const i of n)t.set(i.predicate,(t.get(i.predicate)??0)+1);return Array.from(t.entries()).map(([i,s])=>({predicate:i,count:s,label:wt(i)})).sort((i,s)=>s.count-i.count).slice(0,e)}function Iu(n,e){const t=new Map,i=new Map;for(const a of n){const h=String(a.g??"");if(!h||t.has(h))continue;const c=e.find(f=>h===f.uri||h.startsWith(f.uri+"/"));c&&(t.set(h,c.uri),i.has(c.uri)||i.set(c.uri,[]),i.get(c.uri).push(h))}const s=Array.from(i.keys()),r={},o=[];for(let a=0;a<s.length;a++){const h=s[a],c=e.find(u=>u.uri===h);o.push({name:(c==null?void 0:c.name)??wt(h),color:Nu(a)});const f=i.get(h);for(let u=0;u<f.length;u++)r[f[u]]=Pu(a,u)}const l=new Map;for(const a of n){const h=String(a.g??""),c=String(a.s??"");!h||!c||l.has(c)||l.set(c,h)}return{classColors:r,nodeGraphMap:l,legend:o}}function ju(){const{data:n}=vo(So,[],3e4),e=P.useMemo(()=>JSON.stringify(((n==null?void 0:n.paranets)??[]).map(O=>({id:O.id,uri:O.uri,name:O.name})).sort((O,V)=>String(O.id).localeCompare(String(V.id)))),[n]),t=P.useMemo(()=>(n==null?void 0:n.paranets)??[],[e]),[i,s]=P.useState(null),[r,o]=P.useState(null),[l,a]=P.useState(new Map),[h,c]=P.useState(!0),[f,u]=P.useState(null),[d,p]=P.useState(1e4),[m,x]=P.useState(0),[y,w]=P.useState(null),[A,N]=P.useState(""),[v,C]=P.useState([]),[k,j]=P.useState(new Set),[B,H]=P.useState({}),[I,R]=P.useState(new Map),[E,W]=P.useState([]),[z,Z]=P.useState(0),le=ga(),[ae,ee]=P.useState(()=>new URLSearchParams(le.search).get("paranet")??"");P.useEffect(()=>{const O=new URLSearchParams(le.search).get("paranet")??"";ee(O)},[le.search]);const[ne,Ce]=P.useState(!0),[q,fe]=P.useState(null),D=P.useMemo(()=>t.find(O=>O.id===ae)??null,[t,ae]),me=P.useMemo(()=>({name:"Explorer",palette:"dark",paletteOverrides:{edgeColor:ps,particleColor:"rgba(34, 211, 238, 0.5)"},animation:{fadeIn:!0,linkParticles:!1,linkParticleCount:0,linkParticleSpeed:.005,linkParticleColor:"rgba(34, 211, 238, 0.5)",linkParticleWidth:.8,drift:!1,hoverTrace:!1}}),[]),Ae=P.useCallback(async()=>{var O,V;c(!0),u(null),N(""),s(null),fe(null);try{let Y;if(D!=null&&D.uri){const te=Gs(D.uri);if(!te){u("Invalid paranet URI"),c(!1);return}const ke=Ks(te);Y=`CONSTRUCT { ?s ?p ?o } WHERE {
13
+ GRAPH ?g { ?s ?p ?o }
14
+ FILTER(?g = <${te}> || STRSTARTS(STR(?g), "${ke}/"))
15
+ } LIMIT ${d}`}else Y=`CONSTRUCT { ?s ?p ?o } WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } } LIMIT ${d}`;const J=await Bt(Y,D==null?void 0:D.id),G=Array.isArray((O=J==null?void 0:J.result)==null?void 0:O.quads)?J.result.quads:[];try{let te;if(D!=null&&D.uri){const _e=Gs(D.uri),Pt=_e?Ks(_e):"";te=_e?`SELECT (COUNT(*) AS ?count) WHERE { GRAPH ?g { ?s ?p ?o } FILTER(?g = <${_e}> || STRSTARTS(STR(?g), "${Pt}/")) }`:"SELECT (COUNT(*) AS ?count) WHERE { SELECT DISTINCT ?s ?p ?o WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } } }"}else te="SELECT (COUNT(*) AS ?count) WHERE { SELECT DISTINCT ?s ?p ?o WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } } }";const ke=await Bt(te,D==null?void 0:D.id);w(Du(ke==null?void 0:ke.result))}catch{w(null)}if(Array.isArray(G)&&G.length>0){const te=G.map(gt=>({subject:gt.subject,predicate:gt.predicate,object:gt.object}));let ke=[];try{let gt;if(D!=null&&D.uri){const Ci=Gs(D.uri),da=Ci?Ks(Ci):"";gt=Ci?`SELECT DISTINCT ?s ?g WHERE { GRAPH ?g { ?s ?p ?o } FILTER(?g = <${Ci}> || STRSTARTS(STR(?g), "${da}/")) } LIMIT ${d}`:`SELECT DISTINCT ?s ?g WHERE { GRAPH ?g { ?s ?p ?o } } LIMIT ${d}`}else gt=`SELECT DISTINCT ?s ?g WHERE { GRAPH ?g { ?s ?p ?o } } LIMIT ${d}`;const st=await Bt(gt,D==null?void 0:D.id);ke=Array.isArray((V=st==null?void 0:st.result)==null?void 0:V.bindings)?st.result.bindings:Array.isArray(st==null?void 0:st.result)?st.result:[]}catch{}const{classColors:_e,nodeGraphMap:Pt,legend:fa}=Iu(ke,t);H(_e),R(Pt),W(fa),o(te),a(Eu(te));const ua=Bu(te,20);C(ua),j(new Set),N("")}else o([]),a(new Map),C([]),j(new Set),H({}),R(new Map),W([]),N(D?"No triples found for this paranet. It may not be synced on this node yet.":"No triples found in any named graph on this node.")}catch(Y){u(Y.message),o([]),a(new Map),C([]),j(new Set)}finally{c(!1)}},[d,m,D==null?void 0:D.id,D==null?void 0:D.uri,t]);P.useEffect(()=>{if(!r)return;let O=r;k.size>0&&(O=O.filter(G=>k.has(G.predicate)));let V;ne?V=la(O):V=O.filter(G=>oa(G.object));const Y=new Set,J=[];for(const G of V)for(const te of[G.subject,G.object]){if(Y.has(te))continue;Y.add(te);const ke=I.get(te);ke&&B[ke]&&J.push({subject:te,predicate:na,object:ke})}Z(V.length),s([...V,...J])},[ne,r,k,I,B]),P.useEffect(()=>{Ae()},[Ae]);const xe=P.useCallback(O=>{if(!r)return;const V=O.id||O.uri||O;if(typeof V!="string")return;const Y=[],J=[];for(const G of r)G.subject===V&&Y.push({predicate:G.predicate,object:G.object}),G.object===V&&J.push({subject:G.subject,predicate:G.predicate});fe({uri:V,types:l.get(V)||[],outgoing:Y,incoming:J})},[r,l]);return g.jsxs("div",{className:"graph-explorer-layout",children:[g.jsx("div",{className:"graph-explorer-main",children:g.jsxs("div",{className:"card graph-shell",style:{padding:0,overflow:"hidden",display:"flex",flexDirection:"column",height:"100%"},children:[g.jsx("div",{className:"graph-toolbar",children:g.jsxs("div",{className:"graph-toolbar-row",children:[g.jsxs("select",{className:"input",value:ae,onChange:O=>{ee(O.target.value),x(V=>V+1)},style:{width:"auto",minWidth:200},children:[g.jsx("option",{value:"",children:"All Paranets"}),t.map(O=>g.jsx("option",{value:O.id,children:O.name},O.id))]}),g.jsxs("label",{className:"checkbox-label",children:[g.jsx("input",{type:"checkbox",checked:ne,onChange:O=>Ce(O.target.checked)}),"Show literals"]}),g.jsx("select",{className:"input",style:{width:"auto",minWidth:100},value:d,onChange:O=>{p(Number(O.target.value)),x(V=>V+1)},children:Mu.map(O=>g.jsxs("option",{value:O,children:["Limit ",O]},O))}),g.jsx("button",{className:"btn btn-ghost btn-sm",onClick:()=>x(O=>O+1),disabled:h,children:h?"Loading…":"Refresh"}),i&&!h&&g.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)"},children:[z.toLocaleString()," triples",r&&k.size>0&&z<r.length&&g.jsxs(g.Fragment,{children:[" (filtered from ",r.length.toLocaleString(),")"]}),y!=null&&r&&y>r.length&&g.jsxs(g.Fragment,{children:[" · ",y.toLocaleString()," total in store"]})]})]})}),E.length>0&&g.jsx("div",{className:"graph-legend",children:E.map(O=>g.jsxs("span",{className:"graph-legend-item",children:[g.jsx("span",{className:"graph-legend-dot",style:{background:O.color}}),O.name]},O.name))}),v.length>0&&g.jsxs("div",{className:"graph-predicate-filters",children:[v.map(O=>{const V=k.has(O.predicate);return g.jsxs("button",{type:"button",className:`graph-predicate-chip ${V?"active":""}`,onClick:()=>{j(Y=>{const J=new Set(Y);return J.has(O.predicate)?J.delete(O.predicate):J.add(O.predicate),J})},title:O.predicate,children:[O.label," (",O.count,")"]},O.predicate)}),g.jsx("button",{type:"button",className:`graph-predicate-chip ${k.size===0?"active":""}`,onClick:()=>j(new Set),children:"All"})]}),f&&g.jsx("div",{style:{padding:16,color:"var(--error)"},children:f}),h&&!i&&g.jsx("div",{className:"loading",style:{minHeight:400},children:"Loading graph…"}),i&&i.length===0&&!h&&g.jsxs("div",{className:"empty-state",style:{minHeight:400},children:[g.jsx("div",{className:"empty-state-icon",children:g.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[g.jsx("circle",{cx:"12",cy:"12",r:"3"}),g.jsx("circle",{cx:"19",cy:"5",r:"2"}),g.jsx("circle",{cx:"5",cy:"19",r:"2"}),g.jsx("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),g.jsx("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"})]})}),g.jsx("div",{className:"empty-state-title",children:A?"No triples found":"No matching triples"}),g.jsx("div",{className:"empty-state-desc",children:A||"Try adjusting the filters or selecting a different paranet."})]}),i&&i.length>0&&g.jsx("div",{className:"graph-viewport",style:{flex:1,minHeight:400},children:g.jsx(Co,{data:i,format:"triples",initialFit:!0,options:{labelMode:"humanized",renderer:"2d",style:{classColors:B,defaultNodeColor:jn,defaultEdgeColor:ps,edgeWidth:.9},hexagon:{baseSize:3,minSize:2,maxSize:5,scaleWithDegree:!0},focus:{maxNodes:5e4,hops:999},autoFitDisabled:!0},viewConfig:me,style:{width:"100%",height:"100%"},onNodeClick:xe})})]})}),q&&g.jsxs("div",{className:"graph-details-panel",children:[g.jsxs("div",{className:"graph-details-header",children:[g.jsx("h3",{children:"Node Details"}),g.jsx("button",{className:"btn btn-ghost btn-sm",onClick:()=>fe(null),children:"×"})]}),g.jsxs("div",{className:"graph-details-body",children:[g.jsxs("div",{className:"graph-details-section",children:[g.jsx("div",{className:"graph-details-label",children:"URI"}),g.jsx("div",{className:"graph-details-value mono",children:q.uri})]}),q.types.length>0&&g.jsxs("div",{className:"graph-details-section",children:[g.jsx("div",{className:"graph-details-label",children:"Types"}),q.types.map((O,V)=>g.jsxs("div",{className:"graph-details-value",children:[g.jsx("span",{className:"graph-legend-dot",style:{background:B[O]||jn}}),wt(O)]},V))]}),q.outgoing.length>0&&g.jsxs("div",{className:"graph-details-section",children:[g.jsxs("div",{className:"graph-details-label",children:["Properties (",q.outgoing.length,")"]}),g.jsxs("div",{className:"graph-details-triples",children:[q.outgoing.slice(0,20).map((O,V)=>g.jsxs("div",{className:"graph-details-triple",children:[g.jsx("span",{className:"predicate",children:wt(O.predicate)}),g.jsx("span",{className:"object",title:O.object,children:wt(O.object)})]},V)),q.outgoing.length>20&&g.jsxs("div",{className:"graph-details-more",children:["+",q.outgoing.length-20," more"]})]})]}),q.incoming.length>0&&g.jsxs("div",{className:"graph-details-section",children:[g.jsxs("div",{className:"graph-details-label",children:["Referenced by (",q.incoming.length,")"]}),g.jsxs("div",{className:"graph-details-triples",children:[q.incoming.slice(0,10).map((O,V)=>g.jsxs("div",{className:"graph-details-triple",children:[g.jsx("span",{className:"subject",title:O.subject,children:wt(O.subject)}),g.jsx("span",{className:"predicate",children:wt(O.predicate)})]},V)),q.incoming.length>10&&g.jsxs("div",{className:"graph-details-more",children:["+",q.incoming.length-10," more"]})]})]})]})]})]})}const Wu={"All triples + provenance (SPOG, limit 100)":`SELECT ?s ?p ?o ?g WHERE {
16
+ GRAPH ?g { ?s ?p ?o }
17
+ } LIMIT 100`},Fu=[{title:"All triples + provenance",description:"Reads triples from named graphs with graph URI included.",query:`SELECT ?s ?p ?o ?g WHERE {
18
+ GRAPH ?g { ?s ?p ?o }
19
+ } LIMIT 100`},{title:"OriginTrail Game Events",description:"Explore gameplay/activity triples from the game paranet.",query:`SELECT ?s ?p ?o ?g WHERE {
20
+ GRAPH ?g {
21
+ ?s ?p ?o .
22
+ FILTER(CONTAINS(LCASE(STR(?g)), "origin-trail-game"))
23
+ }
24
+ } LIMIT 100`},{title:"Agent Registry Snapshot",description:"Raw triples from the agents paranet graph.",query:`SELECT ?s ?p ?o WHERE {
25
+ GRAPH <did:dkg:paranet:agents> {
26
+ ?s ?p ?o
27
+ }
28
+ } LIMIT 100`},{title:"Ontology Paranet Concepts",description:"Browse classes/properties and related ontology triples.",query:`SELECT ?s ?p ?o ?g WHERE {
29
+ GRAPH ?g {
30
+ ?s ?p ?o .
31
+ FILTER(
32
+ CONTAINS(LCASE(STR(?g)), "ontology")
33
+ || CONTAINS(LCASE(STR(?s)), "ontology")
34
+ || CONTAINS(LCASE(STR(?o)), "ontology")
35
+ )
36
+ }
37
+ } LIMIT 100`}];function Hu(){const[n,e]=ma(),t=n.get("q")||Wu["All triples + provenance (SPOG, limit 100)"],[i,s]=P.useState(t),[r,o]=P.useState(t),[l,a]=P.useState(null),[h,c]=P.useState(null),[f,u]=P.useState(!1),[d,p]=P.useState(null),[m,x]=P.useState(!1),[y,w]=P.useState("triples"),[A,N]=P.useState([]),[v,C]=P.useState(!1),[k,j]=P.useState(null),B=P.useRef(0),H=P.useCallback(async E=>{const W=++B.current;u(!0),c(null);const z=performance.now();try{const Z=await Bt(E);if(W!==B.current)return;const le=Math.round(performance.now()-z);p(le);const ae=Z.result;a((ae==null?void 0:ae.bindings)??ae),o(E)}catch(Z){if(W!==B.current)return;c(Z.message),a(null)}finally{if(W!==B.current)return;u(!1)}},[]),I=P.useCallback(async()=>{await H(i)},[H,i]);P.useEffect(()=>{m||(x(!0),n.has("q")&&e(E=>(E.delete("q"),E),{replace:!0}),H(i))},[n,m,H,e,i]);const R=P.useMemo(()=>sa(l,r),[l,r]);return P.useEffect(()=>{let E=!1;return(async()=>{var z,Z;if(R.length===0){N([]),C(!1);return}C(!0);try{const ee=`SELECT ?s ?p ?o ?g WHERE {
38
+ VALUES (?s ?p ?o) {
39
+ ${ca(R).slice(0,100).map(D=>`(${Xs(D.s)} ${Xs(D.p)} ${Xs(D.o)})`).join(`
40
+ `)}
41
+ }
42
+ GRAPH ?g { ?s ?p ?o }
43
+ }`,ne=await Bt(ee),Ce=Array.isArray((z=ne==null?void 0:ne.result)==null?void 0:z.bindings)?ne.result.bindings:[],q=Array.from(new Set(Ce.map(D=>String(D.g??"")).filter(Boolean)));let fe=new Map;if(q.length>0){const Ae=`SELECT ?g ?metaGraph ?workspaceOwner ?creator ?publisherPeerId ?publisherAddress ?publisher ?ual ?txHash ?timestamp WHERE {
44
+ VALUES (?g ?metaGraph) { ${q.flatMap(xe=>qu(xe).map(O=>[xe,O])).map(([xe,O])=>`(<${xe}> <${O}>)`).join(" ")} }
45
+ OPTIONAL {
46
+ GRAPH ?metaGraph {
47
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/workspaceOwner> ?workspaceOwner }
48
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/creator> ?creator }
49
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/publisherPeerId> ?publisherPeerId }
50
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/publisherAddress> ?publisherAddress }
51
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/publisher> ?publisher }
52
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/ual> ?ual }
53
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/partOf> ?ual }
54
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/txHash> ?txHash }
55
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/transactionHash> ?txHash }
56
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/timestamp> ?timestamp }
57
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/publishedAt> ?timestamp }
58
+ OPTIONAL { ?metaEntity <http://dkg.io/ontology/createdAt> ?timestamp }
59
+ }
60
+ }
61
+ }`;try{const xe=await Bt(Ae),O=Array.isArray((Z=xe==null?void 0:xe.result)==null?void 0:Z.bindings)?xe.result.bindings:[];fe=new Map;const V=new Map;for(const Y of O){const J=String(Y.g??"");if(!J)continue;const G=V.get(J)??{source:new Set,ual:new Set,txHash:new Set,timestamp:new Set},te=Jt(String(Y.publisherPeerId??""))||Jt(String(Y.creator??""))||Jt(String(Y.workspaceOwner??""))||Jt(String(Y.publisher??""))||Jt(String(Y.publisherAddress??"")),ke=String(Y.ual??"").trim(),_e=String(Y.txHash??"").trim(),Pt=String(Y.timestamp??"").trim();te&&G.source.add(te),ke&&G.ual.add(ke),_e&&G.txHash.add(_e),Pt&&G.timestamp.add(Pt),V.set(J,G)}for(const[Y,J]of V.entries()){const G=te=>te.size===1?Array.from(te)[0]:"";fe.set(Y,{source:G(J.source),ual:G(J.ual),txHash:G(J.txHash),timestamp:G(J.timestamp)})}}catch{fe=new Map}}if(E)return;N(Ce.map(D=>{const me=String(D.g??""),Ae=fe.get(me)??{source:"",ual:"",txHash:"",timestamp:""},xe=me.startsWith("did:dkg:paranet:")?me.replace("did:dkg:paranet:","").split("/")[0]:"unknown",O=Ae.source||"unknown";return{s:String(D.s??""),p:String(D.p??""),o:String(D.o??""),g:me,graphType:me.endsWith("/_workspace")||me.includes("_workspace")?"workspace":"data",paranet:xe,source:O,ual:Ae.ual,txHash:Ae.txHash,timestamp:Ae.timestamp}}))}catch{E||N([])}finally{E||C(!1)}})(),()=>{E=!0}},[R]),g.jsxs("div",{className:"sparql-stack-layout",children:[g.jsxs("div",{className:"sparql-query-composer",children:[g.jsxs("div",{className:"sparql-query-editor-pane",children:[g.jsx($u,{value:i,onChange:s,onRun:I}),g.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",justifyContent:"flex-end",marginTop:8},children:[d!=null&&g.jsxs("span",{style:{fontSize:12,color:"var(--text-muted)"},children:[d,"ms"]}),g.jsx("button",{className:"btn btn-primary",onClick:I,disabled:f,children:f?"Running...":"Run Query"})]})]}),g.jsx("div",{className:"sparql-helper-grid",children:Fu.map(E=>g.jsxs("button",{type:"button",className:"sparql-helper-card",onClick:()=>{s(E.query),H(E.query)},title:"Use this query",children:[g.jsx("div",{className:"sparql-helper-title",children:E.title}),g.jsx("div",{className:"sparql-helper-desc",children:E.description}),g.jsx("pre",{className:"sparql-helper-code mono",children:E.query})]},E.title))})]}),h&&g.jsx("div",{className:"card",style:{borderColor:"var(--error)",marginTop:12},children:g.jsx("div",{style:{color:"var(--error)",fontFamily:"var(--font-mono)",fontSize:13},children:h})}),g.jsx("div",{className:"sparql-results-pane",children:g.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[g.jsxs("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[g.jsx("strong",{style:{fontSize:13},children:"Query Results"}),g.jsxs("div",{className:"result-tabs",style:{marginBottom:0},children:[g.jsx("button",{className:`result-tab ${y==="triples"?"active":""}`,onClick:()=>w("triples"),children:"Triples"}),g.jsx("button",{className:`result-tab ${y==="jsonld"?"active":""}`,onClick:()=>w("jsonld"),children:"JSON-LD"}),g.jsx("button",{className:`result-tab ${y==="nquads"?"active":""}`,onClick:()=>w("nquads"),children:"N-Quads"})]})]}),g.jsxs("div",{style:{minHeight:280,maxHeight:420,overflow:"auto"},children:[y==="triples"&&g.jsx(zu,{result:l,triples:R,rows:A,loading:v,onFocusSubject:j}),y==="jsonld"&&g.jsx(Ku,{triples:R,rawResult:l}),y==="nquads"&&g.jsx(Gu,{triples:R,rawResult:l})]})]})}),g.jsx("div",{className:"sparql-graph-pane",children:g.jsx(Xu,{result:l,sparql:r,focusedSubject:k})})]})}function zu({result:n,triples:e,rows:t,loading:i,onFocusSubject:s}){if(!Array.isArray(n)||n.length===0)return g.jsxs("div",{className:"empty-state empty-state--compact",children:[g.jsx("div",{className:"empty-state-icon",children:g.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[g.jsx("polyline",{points:"16 18 22 12 16 6"}),g.jsx("polyline",{points:"8 6 2 12 8 18"})]})}),g.jsx("div",{className:"empty-state-title",children:"Run a query to see triples"}),g.jsx("div",{className:"empty-state-desc",children:"Write a SPARQL query above and execute it to explore your knowledge graph."})]});if(!e.length)return g.jsx(Vu,{result:n});const r=Tu(e,t);return g.jsxs("div",{style:{overflow:"auto"},children:[i&&g.jsx("div",{className:"empty-state",style:{borderBottom:"1px solid var(--border)"},children:"Loading provenance metadata…"}),g.jsxs("table",{className:"data-table",children:[g.jsx("thead",{children:g.jsxs("tr",{children:[g.jsx("th",{children:"Subject"}),g.jsx("th",{children:"Predicate"}),g.jsx("th",{children:"Object"}),g.jsx("th",{children:"Graph"}),g.jsx("th",{children:"Graph Type"}),g.jsx("th",{children:"Paranet"}),g.jsx("th",{children:"Source"}),g.jsx("th",{children:"UAL"}),g.jsx("th",{children:"Transaction Hash"}),g.jsx("th",{children:"Timestamp"})]})}),g.jsx("tbody",{children:r.map((o,l)=>g.jsxs("tr",{children:[g.jsx($e,{value:o.s,clickable:!0,onClick:()=>s(o.s)}),g.jsx($e,{value:o.p}),g.jsx($e,{value:o.o}),g.jsx($e,{value:o.g}),g.jsx("td",{style:{fontSize:12},children:o.graphType||"-"}),g.jsx($e,{value:o.paranet}),g.jsx($e,{value:o.source}),g.jsx($e,{value:o.ual}),g.jsx($e,{value:o.txHash}),g.jsx($e,{value:o.timestamp})]},`${o.s}-${o.p}-${o.o}-${l}`))})]})]})}function aa(n){return n==null?"":typeof n=="string"||typeof n=="number"||typeof n=="boolean"?String(n):typeof n=="object"&&n&&"value"in n?aa(n.value):String(n)}function Vu({result:n}){if(!Array.isArray(n)||n.length===0)return g.jsxs("div",{className:"empty-state empty-state--compact",children:[g.jsx("div",{className:"empty-state-icon",children:g.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[g.jsx("polyline",{points:"16 18 22 12 16 6"}),g.jsx("polyline",{points:"8 6 2 12 8 18"})]})}),g.jsx("div",{className:"empty-state-title",children:"Run a query to inspect results"}),g.jsx("div",{className:"empty-state-desc",children:"Execute a SPARQL query to see the result bindings."})]});const e=n.find(i=>i&&typeof i=="object"&&!Array.isArray(i)),t=e?Object.keys(e):[];return t.length===0?g.jsx("div",{className:"json-view",children:JSON.stringify(n,null,2)}):g.jsxs("div",{style:{overflow:"auto"},children:[g.jsx("div",{className:"empty-state",style:{borderBottom:"1px solid var(--border)"},children:"Showing generic result rows (query is not triple-shaped)."}),g.jsxs("table",{className:"data-table",children:[g.jsx("thead",{children:g.jsx("tr",{children:t.map(i=>g.jsx("th",{children:i},i))})}),g.jsx("tbody",{children:n.map((i,s)=>g.jsx("tr",{children:t.map(r=>g.jsx($e,{value:aa(i==null?void 0:i[r])},r))},s))})]})]})}function $u({value:n,onChange:e,onRun:t}){const i=P.useRef(null),s=P.useRef(null),r=P.useRef(e),o=P.useRef(t);return P.useEffect(()=>{r.current=e},[e]),P.useEffect(()=>{o.current=t},[t]),P.useEffect(()=>{if(!i.current)return;const l=[F.lineWrapping,Wc(),Vc(),gf(yf,{fallback:!0}),Su(),Bl.of([{key:"Mod-Enter",run:()=>(o.current(),!0)}]),F.updateListener.of(c=>{c.docChanged&&r.current(c.state.doc.toString())})],a=U.create({doc:n,extensions:l}),h=new F({state:a,parent:i.current});return s.current=h,()=>{h.destroy(),s.current=null}},[]),P.useEffect(()=>{const l=s.current;if(!l)return;const a=l.state.doc.toString();a!==n&&l.dispatch({changes:{from:0,to:a.length,insert:n}})},[n]),g.jsx("div",{ref:i,className:"sparql-editor-cm","aria-label":"SPARQL editor"})}function rr(n){return n.startsWith("http://")||n.startsWith("https://")||n.startsWith("urn:")||n.startsWith("did:")||n.startsWith("_:")}function ha(n){return/^<[^>]+>$/.test(n)||/^_:[A-Za-z][\w-]*$/.test(n)||/^"((?:[^"\\]|\\.)*)"(?:@[A-Za-z-]+|\^\^(?:<[^>]+>|[A-Za-z][\w+.-]*:[^\s]+))?$/.test(n)}function _s(n){return ha(n)||n.startsWith("_:")?n:rr(n)?`<${n}>`:`"${n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function Xs(n){return ha(n)||n.startsWith("_:")?n:rr(n)?`<${n}>`:`"${n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function ca(n){const e=new Set,t=[];for(const i of n){const s=`${i.s}\0${i.p}\0${i.o}`;e.has(s)||(e.add(s),t.push(i))}return t}function Jt(n){const e=(n||"").trim();if(!e)return"";let t=e;const i=t.match(/^"((?:[^"\\]|\\.)*)"(?:@[A-Za-z-]+|\^\^(?:<[^>]+>|[A-Za-z][\w+.-]*:[^\s]+))?$/);return i?t=i[1].replace(/\\n/g,`
62
+ `).replace(/\\"/g,'"').replace(/\\\\/g,"\\"):t.startsWith("<")&&t.endsWith(">")&&(t=t.slice(1,-1)),t?t.startsWith("did:dkg:agent:")?t.replace("did:dkg:agent:",""):/^12D3[A-Za-z0-9]+/.test(t)||/^Qm[A-Za-z0-9]+/.test(t)||/^0x[a-fA-F0-9]{40}$/.test(t)?t:"":""}function qu(n){const e=(n||"").trim();if(!e)return[];const t=new Set;if(e.endsWith("/_workspace")){const i=e.slice(0,-11);t.add(`${i}/_workspace_meta`),t.add(`${i}/_meta`)}else t.add(`${e}/_meta`),t.add(`${e}/_workspace_meta`);return Array.from(t)}function Qu(n){const e=n.match(/^"((?:[^"\\]|\\.)*)"(?:(@[A-Za-z-]+)|\^\^<([^>]+)>)?$/);if(!e)return null;const t=e[1].replace(/\\n/g,`
63
+ `).replace(/\\"/g,'"').replace(/\\\\/g,"\\"),i=e[2]?e[2].slice(1):void 0,s=e[3]??void 0;return{value:t,language:i,type:s}}function Uu(n){const e=new Map;for(const t of n){e.has(t.s)||e.set(t.s,{"@id":t.s});const i=e.get(t.s),s=Array.isArray(i[t.p])?i[t.p]:[];if(rr(t.o))s.push({"@id":t.o});else{const r=Qu(t.o);if(r){const o={"@value":r.value};r.language&&(o["@language"]=r.language),r.type&&(o["@type"]=r.type),s.push(o)}else s.push({"@value":t.o})}i[t.p]=s}return Array.from(e.values())}function Ku({triples:n,rawResult:e}){return n.length?g.jsx("div",{className:"json-view",children:JSON.stringify(Uu(n),null,2)}):g.jsx("div",{className:"json-view",children:JSON.stringify(e??[],null,2)})}function Gu({triples:n,rawResult:e}){if(!n.length)return g.jsx("div",{className:"json-view",children:JSON.stringify(e??[],null,2)});const t=n.map(i=>`${_s(i.s)} ${_s(i.p)} ${_s(i.o)} .`).join(`
64
+ `);return g.jsx("div",{className:"json-view",children:t})}function $e({value:n,clickable:e=!1,onClick:t}){const i=n||"-",s=P.useCallback(async()=>{try{n&&await navigator.clipboard.writeText(n)}catch{}},[n]);return g.jsxs("td",{className:"mono sparql-cell-with-copy",style:{fontSize:12},children:[e?g.jsx("button",{type:"button",className:"sparql-cell-link",onClick:t,title:"Focus node in graph",children:i}):g.jsx("span",{children:i}),n&&g.jsx("button",{type:"button",className:"sparql-copy-btn",onClick:s,title:"Copy value",children:"Copy"})]})}function _u({focusedSubject:n}){const{viz:e}=ba();return P.useEffect(()=>{!e||!n||e.centerOnNode(n,{durationMs:500,zoomLevel:2.5})},[e,n]),null}function Xu({result:n,sparql:e,focusedSubject:t}){if(!Array.isArray(n)||n.length===0)return g.jsx("div",{className:"graph-container",children:"Run a query to visualize graph data"});const i=sa(n,e);if(i.length===0)return g.jsxs("div",{className:"graph-container",children:["Graph view needs a triple pattern with variables (for example: ",g.jsx("code",{children:"?s ?p ?o"})," or ",g.jsxs("code",{children:["<subject>"," ?p ?o"]}),")."]});const s=ca(i),r=s,o=la(r.map(a=>({subject:a.s,predicate:a.p,object:a.o}))),l={name:"SPARQL Result Graph",palette:"dark",paletteOverrides:{edgeColor:ps,particleColor:"rgba(34, 211, 238, 0.5)"},animation:{fadeIn:!0,linkParticles:!1,linkParticleCount:0,linkParticleSpeed:.005,linkParticleColor:"rgba(34, 211, 238, 0.5)",linkParticleWidth:.8,drift:!1,hoverTrace:!1}};return g.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden",height:"100%",width:"100%",display:"flex",flexDirection:"column"},children:[g.jsxs("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--border)",fontSize:12,color:"var(--text-muted)"},children:[r.length.toLocaleString()," shown of ",s.length.toLocaleString()," unique triples from ",i.length.toLocaleString()," rows"]}),g.jsx("div",{style:{width:"100%",flex:1,minHeight:0},children:g.jsx(Co,{data:o,format:"triples",initialFit:!0,options:{labelMode:"humanized",renderer:"2d",style:{defaultNodeColor:jn,defaultEdgeColor:ps,edgeWidth:.9},hexagon:{baseSize:3,minSize:2,maxSize:5,scaleWithDegree:!0},focus:{maxNodes:5e4,hops:999},autoFitDisabled:!0},viewConfig:l,style:{width:"100%",height:"100%"},children:g.jsx(_u,{focusedSubject:t})})})]})}function Yu(){const{data:n}=vo(So,[],3e4),e=(n==null?void 0:n.paranets)??[],t=xa();return g.jsx("div",{children:e.length===0?g.jsxs("div",{className:"empty-state empty-state--rich",children:[g.jsx("div",{className:"empty-state-icon",children:g.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:g.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"})})}),g.jsx("div",{className:"empty-state-title",children:"No paranets found"}),g.jsx("div",{className:"empty-state-desc",children:"Subscribe to a paranet in the Integrations page, then its data will be explorable here."})]}):g.jsx("div",{className:"paranet-list",children:e.map(i=>g.jsxs("div",{className:"paranet-card",onClick:()=>{t(`/explorer?paranet=${encodeURIComponent(i.id)}`)},children:[g.jsx("h3",{children:i.name}),g.jsx("p",{children:i.description||i.uri}),g.jsxs("div",{style:{marginTop:8,fontSize:11,color:"var(--text-muted)"},children:[i.isSystem&&g.jsx("span",{className:"badge badge-info",style:{marginRight:4},children:"system"}),g.jsx("span",{className:"mono",children:ya(i.id,16)})]})]},i.id))})})}function wt(n){if(n.includes("#"))return n.split("#").pop();const e=n.split("/");return e[e.length-1]||n}export{nd as ExplorerPage};