arize-phoenix 5.2.2__py3-none-any.whl → 5.3.1__py3-none-any.whl

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 (38) hide show
  1. {arize_phoenix-5.2.2.dist-info → arize_phoenix-5.3.1.dist-info}/METADATA +3 -1
  2. {arize_phoenix-5.2.2.dist-info → arize_phoenix-5.3.1.dist-info}/RECORD +36 -29
  3. phoenix/core/model_schema_adapter.py +2 -2
  4. phoenix/db/migrations/versions/10460e46d750_datasets.py +1 -1
  5. phoenix/db/migrations/versions/3be8647b87d8_add_token_columns_to_spans_table.py +1 -1
  6. phoenix/db/migrations/versions/cf03bd6bae1d_init.py +1 -1
  7. phoenix/db/models.py +6 -6
  8. phoenix/server/api/input_types/ChatCompletionMessageInput.py +12 -0
  9. phoenix/server/api/input_types/InvocationParameters.py +20 -0
  10. phoenix/server/api/openapi/main.py +8 -13
  11. phoenix/server/api/queries.py +74 -0
  12. phoenix/server/api/schema.py +2 -0
  13. phoenix/server/api/subscriptions.py +449 -0
  14. phoenix/server/api/types/ChatCompletionMessageRole.py +11 -0
  15. phoenix/server/api/types/GenerativeModel.py +9 -0
  16. phoenix/server/api/types/GenerativeProvider.py +16 -0
  17. phoenix/server/app.py +36 -7
  18. phoenix/server/bearer_auth.py +12 -4
  19. phoenix/server/main.py +2 -2
  20. phoenix/server/static/.vite/manifest.json +35 -35
  21. phoenix/server/static/assets/{components-CPkaHQZs.js → components-CeBEsPFA.js} +153 -130
  22. phoenix/server/static/assets/{index-D4G-kYL9.js → index-CRTTIb3y.js} +2 -2
  23. phoenix/server/static/assets/{pages-B3HCyYqg.js → pages-vHjpYRiN.js} +361 -256
  24. phoenix/server/static/assets/vendor-D-NIjePD.js +872 -0
  25. phoenix/server/static/assets/{vendor-arizeai-D0FocbYu.js → vendor-arizeai-DoY5jUTO.js} +30 -28
  26. phoenix/server/static/assets/vendor-codemirror-CIhY_nEU.js +24 -0
  27. phoenix/server/static/assets/{vendor-recharts-JMOLUxWG.js → vendor-recharts-Dgcm35Jq.js} +1 -1
  28. phoenix/trace/fixtures.py +7 -9
  29. phoenix/utilities/client.py +2 -2
  30. phoenix/utilities/json.py +11 -0
  31. phoenix/utilities/template_formatters.py +70 -0
  32. phoenix/version.py +1 -1
  33. phoenix/server/static/assets/vendor-c0HJYYGN.js +0 -641
  34. phoenix/server/static/assets/vendor-codemirror-BbCMI-_D.js +0 -30
  35. {arize_phoenix-5.2.2.dist-info → arize_phoenix-5.3.1.dist-info}/WHEEL +0 -0
  36. {arize_phoenix-5.2.2.dist-info → arize_phoenix-5.3.1.dist-info}/entry_points.txt +0 -0
  37. {arize_phoenix-5.2.2.dist-info → arize_phoenix-5.3.1.dist-info}/licenses/IP_NOTICE +0 -0
  38. {arize_phoenix-5.2.2.dist-info → arize_phoenix-5.3.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,30 +0,0 @@
1
- import{bL as lt,bM as Za,bN as th,bO as eh,bP as C,bQ as ih,bR as $b,bS as Ti,bT as jt,bU as Nb,bV as nh,bW as lr,bX as Hb,bY as Fb,bZ as Ib,b_ as ud,b$ as dd,c0 as G,c1 as L,r as zt,c2 as Vb,c3 as Wb,c4 as zb,c5 as Kb}from"./vendor-c0HJYYGN.js";class B{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=Ki(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),ye.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=Ki(this,t,e);let i=[];return this.decompose(t,e,i,0),ye.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=new Nn(this),r=new Nn(t);for(let o=e,l=e;;){if(n.next(o),r.next(o),o=0,n.lineBreak!=r.lineBreak||n.done!=r.done||n.value!=r.value)return!1;if(l+=n.value.length,n.done||l>=i)return!0}}iter(t=1){return new Nn(this,t)}iterRange(t,e=this.length){return new pd(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new gd(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?B.empty:t.length<=32?new st(t):ye.from(st.split(t,[]))}}class st extends B{constructor(t,e=qb(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((e?i:l)>=t)return new jb(n,l,i,o);n=l+1,i++}}decompose(t,e,i,n){let r=t<=0&&e>=this.length?this:new st(tc(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(n&1){let o=i.pop(),l=ar(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new st(l,o.length+r.length));else{let a=l.length>>1;i.push(new st(l.slice(0,a)),new st(l.slice(a)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof st))return super.replace(t,e,i);[t,e]=Ki(this,t,e);let n=ar(this.text,ar(i.text,tc(this.text,0,t)),e),r=this.length+i.length-(e-t);return n.length<=32?new st(n,r):ye.from(st.split(n,[]),r)}sliceString(t,e=this.length,i=`
2
- `){[t,e]=Ki(this,t,e);let n="";for(let r=0,o=0;r<=e&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>t&&o&&(n+=i),t<a&&e>r&&(n+=l.slice(Math.max(0,t-r),e-r)),r=a+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let r of t)i.push(r),n+=r.length+1,i.length==32&&(e.push(new st(i,n)),i=[],n=-1);return n>-1&&e.push(new st(i,n)),e}}class ye extends B{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,n){for(let r=0;;r++){let o=this.children[r],l=n+o.length,a=i+o.lines-1;if((e?a:l)>=t)return o.lineInner(t,e,i,n);n=l+1,i=a+1}}decompose(t,e,i,n){for(let r=0,o=0;o<=e&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(t<=a&&e>=o){let c=n&((o<=t?1:0)|(a>=e?2:0));o>=t&&a<=e&&!c?i.push(l):l.decompose(t-o,e-o,i,c)}o=a+1}}replace(t,e,i){if([t,e]=Ki(this,t,e),i.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let o=this.children[n],l=r+o.length;if(t>=r&&e<=l){let a=o.replace(t-r,e-r,i),c=this.lines-o.lines+a.lines;if(a.lines<c>>4&&a.lines>c>>6){let h=this.children.slice();return h[n]=a,new ye(h,this.length-(e-t)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
3
- `){[t,e]=Ki(this,t,e);let n="";for(let r=0,o=0;r<this.children.length&&o<=e;r++){let l=this.children[r],a=o+l.length;o>t&&r&&(n+=i),t<a&&e>o&&(n+=l.sliceString(t-o,e-o,i)),o=a+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof ye))return 0;let i=0,[n,r,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,r+=e){if(n==o||r==l)return i;let a=this.children[n],c=t.children[r];if(a!=c)return i+a.scanIdentical(c,e);i+=a.length+1}}static from(t,e=t.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let d of t)i+=d.lines;if(i<32){let d=[];for(let p of t)p.flatten(d);return new st(d,e)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,c=-1,h=[];function f(d){let p;if(d.lines>r&&d instanceof ye)for(let g of d.children)f(g);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof st&&a&&(p=h[h.length-1])instanceof st&&d.lines+p.lines<=32?(a+=d.lines,c+=d.length+1,h[h.length-1]=new st(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,c+=d.length+1,h.push(d))}function u(){a!=0&&(l.push(h.length==1?h[0]:ye.from(h,c)),c=-1,a=h.length=0)}for(let d of t)f(d);return u(),l.length==1?l[0]:new ye(l,e)}}B.empty=new st([""],0);function qb(s){let t=-1;for(let e of s)t+=e.length+1;return t}function ar(s,t,e=0,i=1e9){for(let n=0,r=0,o=!0;r<s.length&&n<=i;r++){let l=s[r],a=n+l.length;a>=e&&(a>i&&(l=l.slice(0,i-n)),n<e&&(l=l.slice(e-n)),o?(t[t.length-1]+=l,o=!1):t.push(l)),n=a+1}return t}function tc(s,t,e){return ar(s,[""],t,e)}class Nn{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof st?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],o=r>>1,l=n instanceof st?n.text.length:n.children.length;if(o==(e>0?l:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
4
- `,this;t--}else if(n instanceof st){let a=n.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,a.length>Math.max(0,t))return this.value=t==0?a:e>0?a.slice(t):a.slice(0,a.length-t),this;t-=a.length}else{let a=n.children[o+(e<0?-1:0)];t>a.length?(t-=a.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(e>0?1:(a instanceof st?a.text.length:a.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class pd{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new Nn(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class gd{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(B.prototype[Symbol.iterator]=function(){return this.iter()},Nn.prototype[Symbol.iterator]=pd.prototype[Symbol.iterator]=gd.prototype[Symbol.iterator]=function(){return this});class jb{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function Ki(s,t,e){return t=Math.max(0,Math.min(s.length,t)),[t,Math.max(t,Math.min(s.length,e))]}let Li="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(s=>s?parseInt(s,36):1);for(let s=1;s<Li.length;s++)Li[s]+=Li[s-1];function Gb(s){for(let t=1;t<Li.length;t+=2)if(Li[t]>s)return Li[t-1]<=s;return!1}function ec(s){return s>=127462&&s<=127487}const ic=8205;function V(s,t,e=!0,i=!0){return(e?md:Ub)(s,t,i)}function md(s,t,e){if(t==s.length)return t;t&&bd(s.charCodeAt(t))&&yd(s.charCodeAt(t-1))&&t--;let i=ht(s,t);for(t+=Rt(i);t<s.length;){let n=ht(s,t);if(i==ic||n==ic||e&&Gb(n))t+=Rt(n),i=n;else if(ec(n)){let r=0,o=t-2;for(;o>=0&&ec(ht(s,o));)r++,o-=2;if(r%2==0)break;t+=2}else break}return t}function Ub(s,t,e){for(;t>0;){let i=md(s,t-2,e);if(i<t)return i;t--}return 0}function bd(s){return s>=56320&&s<57344}function yd(s){return s>=55296&&s<56320}function ht(s,t){let e=s.charCodeAt(t);if(!yd(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return bd(i)?(e-55296<<10)+(i-56320)+65536:e}function sh(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function Rt(s){return s<65536?1:2}const al=/\r\n?|\n/;var I=function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s}(I||(I={}));class ke{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,n=0;e<this.sections.length;){let r=this.sections[e++],o=this.sections[e++];o<0?(t(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(t,e=!1){hl(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],n=this.sections[e++];n<0?t.push(i,n):t.push(n,i)}return new ke(t)}composeDesc(t){return this.empty?t:t.empty?this:wd(this,t)}mapDesc(t,e=!1){return t.empty?this:cl(this,t,e)}mapPos(t,e=-1,i=I.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],c=n+l;if(a<0){if(c>t)return r+(t-n);r+=l}else{if(i!=I.Simple&&c>=t&&(i==I.TrackDel&&n<t&&c>t||i==I.TrackBefore&&n<t||i==I.TrackAfter&&c>t))return null;if(c>t||c==t&&e<0&&!l)return t==n||e<0?r:r+a;r+=a}n=c}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return r}touchesRange(t,e=t){for(let i=0,n=0;i<this.sections.length&&n<=e;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=e&&l>=t)return n<t&&l>e?"cover":!0;n=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],n=this.sections[e++];t+=(t?" ":"")+i+(n>=0?":"+n:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new ke(t)}static create(t){return new ke(t)}}class et extends ke{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return hl(this,(e,i,n,r,o)=>t=t.replace(n,n+(i-e),o),!1),t}mapDesc(t,e=!1){return cl(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,r=0;n<e.length;n+=2){let o=e[n],l=e[n+1];if(l>=0){e[n]=l,e[n+1]=o;let a=n>>1;for(;i.length<a;)i.push(B.empty);i.push(o?t.slice(r,r+o):B.empty)}r+=o}return new et(e,i)}compose(t){return this.empty?t:t.empty?this:wd(this,t,!0)}map(t,e=!1){return t.empty?this:cl(this,t,e,!0)}iterChanges(t,e=!1){hl(this,t,e)}get desc(){return ke.create(this.sections)}filter(t){let e=[],i=[],n=[],r=new Gn(this);t:for(let o=0,l=0;;){let a=o==t.length?1e9:t[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break t;let h=Math.min(r.len,a-l);gt(n,h,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;gt(e,h,f),f>0&&Ye(i,e,r.text),r.forward(h),l+=h}let c=t[o++];for(;l<c;){if(r.done)break t;let h=Math.min(r.len,c-l);gt(e,h,-1),gt(n,h,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(h),l+=h}}return{changes:new et(e,i),filtered:ke.create(n)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],n=this.sections[e+1];n<0?t.push(i):n==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let n=[],r=[],o=0,l=null;function a(h=!1){if(!h&&!n.length)return;o<e&&gt(n,e-o,-1);let f=new et(n,r);l=l?l.compose(f.map(l)):f,n=[],r=[],o=0}function c(h){if(Array.isArray(h))for(let f of h)c(f);else if(h instanceof et){if(h.length!=e)throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${e})`);a(),l=l?l.compose(h.map(l)):h}else{let{from:f,to:u=f,insert:d}=h;if(f>u||f<0||u>e)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${e})`);let p=d?typeof d=="string"?B.of(d.split(i||al)):d:B.empty,g=p.length;if(f==u&&g==0)return;f<o&&a(),f>o&&gt(n,f-o,-1),gt(n,u-f,g),Ye(r,n,p),o=u}}return c(t),a(!l),l}static empty(t){return new et(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;n<t.length;n++){let r=t[n];if(typeof r=="number")e.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)e.push(r[0],0);else{for(;i.length<n;)i.push(B.empty);i[n]=B.of(r.slice(1)),e.push(r[0],i[n].length)}}}return new et(e,i)}static createSet(t,e){return new et(t,e)}}function gt(s,t,e,i=!1){if(t==0&&e<=0)return;let n=s.length-2;n>=0&&e<=0&&e==s[n+1]?s[n]+=t:t==0&&s[n]==0?s[n+1]+=e:i?(s[n]+=t,s[n+1]+=e):s.push(t,e)}function Ye(s,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(e);else{for(;s.length<i;)s.push(B.empty);s.push(e)}}function hl(s,t,e){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],a=s.sections[o++];if(a<0)n+=l,r+=l;else{let c=n,h=r,f=B.empty;for(;c+=l,h+=a,a&&i&&(f=f.append(i[o-2>>1])),!(e||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],a=s.sections[o++];t(n,c,r,h,f),n=c,r=h}}}function cl(s,t,e,i=!1){let n=[],r=i?[]:null,o=new Gn(s),l=new Gn(t);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let c=Math.min(o.len,l.len);gt(n,c,-1),o.forward(c),l.forward(c)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!e))){let c=l.len;for(gt(n,l.ins,-1);c;){let h=Math.min(o.len,c);o.ins>=0&&a<o.i&&o.len<=h&&(gt(n,0,o.ins),r&&Ye(r,n,o.text),a=o.i),o.forward(h),c-=h}l.next()}else if(o.ins>=0){let c=0,h=o.len;for(;h;)if(l.ins==-1){let f=Math.min(h,l.len);c+=f,h-=f,l.forward(f)}else if(l.ins==0&&l.len<h)h-=l.len,l.next();else break;gt(n,c,a<o.i?o.ins:0),r&&a<o.i&&Ye(r,n,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return r?et.createSet(n,r):ke.create(n);throw new Error("Mismatched change set lengths")}}function wd(s,t,e=!1){let i=[],n=e?[]:null,r=new Gn(s),o=new Gn(t);for(let l=!1;;){if(r.done&&o.done)return n?et.createSet(i,n):ke.create(i);if(r.ins==0)gt(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)gt(i,0,o.ins,l),n&&Ye(n,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),c=i.length;if(r.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;gt(i,a,h,l),n&&h&&Ye(n,i,o.text)}else o.ins==-1?(gt(i,r.off?0:r.len,a,l),n&&Ye(n,i,r.textBit(a))):(gt(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&Ye(n,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>c),r.forward2(a),o.forward(a)}}}}class Gn{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[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:t}=this.set,e=this.i-2>>1;return e>=t.length?B.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?B.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class ci{constructor(t,e,i){this.from=t,this.to=e,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 t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new ci(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return w.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return w.range(this.anchor,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return w.range(t.anchor,t.head)}static create(t,e,i){return new ci(t,e,i)}}class w{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:w.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new w([this.main],0)}addRange(t,e=!0){return w.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,w.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new w(t.ranges.map(e=>ci.fromJSON(e)),t.main)}static single(t,e=t){return new w([w.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<t.length;n++){let r=t[n];if(r.empty?r.from<=i:r.from<i)return w.normalized(t.slice(),e);i=r.to}return new w(t,e)}static cursor(t,e=0,i,n){return ci.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(t,e,i,n){let r=(i??16777215)<<6|(n==null?7:Math.min(6,n));return e<t?ci.create(e,t,48|r):ci.create(t,e,(e>t?8:0)|r)}static normalized(t,e=0){let i=t[e];t.sort((n,r)=>n.from-r.from),e=t.indexOf(i);for(let n=1;n<t.length;n++){let r=t[n],o=t[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);n<=e&&e--,t.splice(--n,2,r.anchor>r.head?w.range(a,l):w.range(l,a))}}return new w(t,e)}}function xd(s,t){for(let e of s.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}let rh=0;class v{constructor(t,e,i,n,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=rh++,this.default=t([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(t={}){return new v(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:oh),!!t.static,t.enables)}of(t){return new hr([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new hr(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new hr(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}}function oh(s,t){return s==t||s.length==t.length&&s.every((e,i)=>e===t[i])}class hr{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=rh++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,r=this.id,o=t[r]>>1,l=this.type==2,a=!1,c=!1,h=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?c=!0:((e=t[f.id])!==null&&e!==void 0?e:1)&1||h.push(t[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||c&&(u.docChanged||u.selection)||fl(f,h)){let d=i(f);if(l?!nc(d,f.values[o],n):!n(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 g=Er(u,p);if(this.dependencies.every(b=>b instanceof v?u.facet(b)===f.facet(b):b instanceof ct?u.field(b,!1)==f.field(b,!1):!0)||(l?nc(d=i(f),g,n):n(d=i(f),g)))return f.values[o]=g,0}else d=i(f);return f.values[o]=d,1}}}}function nc(s,t,e){if(s.length!=t.length)return!1;for(let i=0;i<s.length;i++)if(!e(s[i],t[i]))return!1;return!0}function fl(s,t){let e=!1;for(let i of t)Hn(s,i)&1&&(e=!0);return e}function Yb(s,t,e){let i=e.map(a=>s[a.id]),n=e.map(a=>a.type),r=i.filter(a=>!(a&1)),o=s[t.id]>>1;function l(a){let c=[];for(let h=0;h<i.length;h++){let f=Er(a,i[h]);if(n[h]==2)for(let u of f)c.push(u);else c.push(f)}return t.combine(c)}return{create(a){for(let c of i)Hn(a,c);return a.values[o]=l(a),1},update(a,c){if(!fl(a,r))return 0;let h=l(a);return t.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,c){let h=fl(a,i),f=c.config.facets[t.id],u=c.facet(t);if(f&&!h&&oh(e,f))return a.values[o]=u,0;let d=l(a);return t.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const sc=v.define({static:!0});class ct{constructor(t,e,i,n,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(t){let e=new ct(rh++,t.create,t.update,t.compare||((i,n)=>i===n),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(sc).find(i=>i.field==this);return((e==null?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,n)=>{let r=i.values[e],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[e]=o,1)},reconfigure:(i,n)=>n.config.address[this.id]!=null?(i.values[e]=n.field(this),0):(i.values[e]=this.create(i),1)}}init(t){return[this,sc.of({field:this,create:t})]}get extension(){return this}}const ai={lowest:4,low:3,default:2,high:1,highest:0};function dn(s){return t=>new Sd(t,s)}const _t={highest:dn(ai.highest),high:dn(ai.high),default:dn(ai.default),low:dn(ai.low),lowest:dn(ai.lowest)};class Sd{constructor(t,e){this.inner=t,this.prec=e}}class no{of(t){return new ul(this,t)}reconfigure(t){return no.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class ul{constructor(t,e){this.compartment=t,this.inner=e}}class Br{constructor(t,e,i,n,r,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let n=[],r=Object.create(null),o=new Map;for(let u of Xb(t,e,o))u instanceof ct?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],c=[];for(let u of n)l[u.id]=c.length<<1,c.push(d=>u.slot(d));let h=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=h&&h[u]||[];if(d.every(b=>b.type==0))if(l[p.id]=a.length<<1|1,oh(g,d))a.push(i.facet(p));else{let b=p.combine(d.map(m=>m.value));a.push(i&&p.compare(b,i.facet(p))?i.facet(p):b)}else{for(let b of d)b.type==0?(l[b.id]=a.length<<1|1,a.push(b.value)):(l[b.id]=c.length<<1,c.push(m=>b.dynamicSlot(m)));l[p.id]=c.length<<1,c.push(b=>Yb(b,p,d))}}let f=c.map(u=>u(l));return new Br(t,o,f,l,a,r)}}function Xb(s,t,e){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let c=i[a].indexOf(o);c>-1&&i[a].splice(c,1),o instanceof ul&&e.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let c of o)r(c,l);else if(o instanceof ul){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let c=t.get(o.compartment)||o.inner;e.set(o.compartment,c),r(c,l)}else if(o instanceof Sd)r(o.inner,o.prec);else if(o instanceof ct)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof hr)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,ai.default);else{let c=o.extension;if(!c)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(c,l)}}return r(s,ai.default),i.reduce((o,l)=>o.concat(l))}function Hn(s,t){if(t&1)return 2;let e=t>>1,i=s.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[e]=4;let n=s.computeSlot(s,s.config.dynamicSlots[e]);return s.status[e]=2|n}function Er(s,t){return t&1?s.config.staticValues[t>>1]:s.values[t>>1]}const vd=v.define(),dl=v.define({combine:s=>s.some(t=>t),static:!0}),kd=v.define({combine:s=>s.length?s[0]:void 0,static:!0}),Cd=v.define(),Md=v.define(),Ad=v.define(),Dd=v.define({combine:s=>s.length?s[0]:!1});class Vt{constructor(t,e){this.type=t,this.value=e}static define(){return new _b}}class _b{of(t){return new Vt(this,t)}}class Jb{constructor(t){this.map=t}of(t){return new R(this,t)}}class R{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new R(this.type,e)}is(t){return this.type==t}static define(t={}){return new Jb(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let r=n.map(e);r&&i.push(r)}return i}}R.reconfigure=R.define();R.appendConfig=R.define();class it{constructor(t,e,i,n,r,o){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&xd(i,e.newLength),r.some(l=>l.type==it.time)||(this.annotations=r.concat(it.time.of(Date.now())))}static create(t,e,i,n,r,o){return new it(t,e,i,n,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(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(it.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}}it.time=Vt.define();it.userEvent=Vt.define();it.addToHistory=Vt.define();it.remote=Vt.define();function Qb(s,t){let e=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==t.length||t[n]>=s[i]))r=s[i++],o=s[i++];else if(n<t.length)r=t[n++],o=t[n++];else return e;!e.length||e[e.length-1]<r?e.push(r,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function Od(s,t,e){var i;let n,r,o;return e?(n=t.changes,r=et.empty(t.changes.length),o=s.changes.compose(t.changes)):(n=t.changes.map(s.changes),r=s.changes.mapDesc(t.changes,!0),o=s.changes.compose(n)),{changes:o,selection:t.selection?t.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:R.mapEffects(s.effects,n).concat(R.mapEffects(t.effects,r)),annotations:s.annotations.length?s.annotations.concat(t.annotations):t.annotations,scrollIntoView:s.scrollIntoView||t.scrollIntoView}}function pl(s,t,e){let i=t.selection,n=Pi(t.annotations);return t.userEvent&&(n=n.concat(it.userEvent.of(t.userEvent))),{changes:t.changes instanceof et?t.changes:et.of(t.changes||[],e,s.facet(kd)),selection:i&&(i instanceof w?i:w.single(i.anchor,i.head)),effects:Pi(t.effects),annotations:n,scrollIntoView:!!t.scrollIntoView}}function Td(s,t,e){let i=pl(s,t.length?t[0]:{},s.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let r=1;r<t.length;r++){t[r].filter===!1&&(e=!1);let o=!!t[r].sequential;i=Od(i,pl(s,t[r],o?i.changes.newLength:s.doc.length),o)}let n=it.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return ty(e?Zb(n):n)}function Zb(s){let t=s.startState,e=!0;for(let n of t.facet(Cd)){let r=n(s);if(r===!1){e=!1;break}Array.isArray(r)&&(e=e===!0?r:Qb(e,r))}if(e!==!0){let n,r;if(e===!1)r=s.changes.invertedDesc,n=et.empty(t.doc.length);else{let o=s.changes.filter(e);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=it.create(t,n,s.selection&&s.selection.map(r),R.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=t.facet(Md);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof it?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof it?s=r[0]:s=Td(t,Pi(r),!1)}return s}function ty(s){let t=s.startState,e=t.facet(Ad),i=s;for(let n=e.length-1;n>=0;n--){let r=e[n](s);r&&Object.keys(r).length&&(i=Od(i,pl(t,r,s.changes.newLength),!0))}return i==s?s:it.create(t,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const ey=[];function Pi(s){return s==null?ey:Array.isArray(s)?s:[s]}var Y=function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s}(Y||(Y={}));const iy=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let gl;try{gl=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function ny(s){if(gl)return gl.test(s);for(let t=0;t<s.length;t++){let e=s[t];if(/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||iy.test(e)))return!0}return!1}function sy(s){return t=>{if(!/\S/.test(t))return Y.Space;if(ny(t))return Y.Word;for(let e=0;e<s.length;e++)if(t.indexOf(s[e])>-1)return Y.Word;return Y.Other}}class ${constructor(t,e,i,n,r,o){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)Hn(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return Hn(this,i),Er(this,i)}update(...t){return Td(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:n}=e;for(let l of t.effects)l.is(no.reconfigure)?(e&&(n=new Map,e.compartments.forEach((a,c)=>n.set(c,a)),e=null),n.set(l.value.compartment,l.value.extension)):l.is(R.reconfigure)?(e=null,i=l.value):l.is(R.appendConfig)&&(e=null,i=Pi(i).concat(l.value));let r;e?r=t.startState.values.slice():(e=Br.resolve(i,n,this),r=new $(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(a,c)=>c.reconfigure(a,this),null).values);let o=t.startState.facet(dl)?t.newSelection:t.newSelection.asSingle();new $(e,t.newDoc,o,r,(l,a)=>a.update(l,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:w.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Pi(i.effects);for(let l=1;l<e.ranges.length;l++){let a=t(e.ranges[l]),c=this.changes(a.changes),h=c.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(h);let f=n.mapDesc(c,!0);r.push(a.range.map(f)),n=n.compose(h),o=R.mapEffects(o,h).concat(R.mapEffects(Pi(a.effects),f))}return{changes:n,selection:w.create(r,e.mainIndex),effects:o}}changes(t=[]){return t instanceof et?t:et.of(t,this.doc.length,this.facet($.lineSeparator))}toText(t){return B.of(t.split(this.facet($.lineSeparator)||al))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(Hn(this,e),Er(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let n=t[i];n instanceof ct&&this.config.address[n.id]!=null&&(e[i]=n.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(t,r)){let o=i[r],l=t[r];n.push(o.init(a=>o.spec.fromJSON(l,a)))}}return $.create({doc:t.doc,selection:w.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=Br.resolve(t.extensions||[],new Map),i=t.doc instanceof B?t.doc:B.of((t.doc||"").split(e.staticFacet($.lineSeparator)||al)),n=t.selection?t.selection instanceof w?t.selection:w.single(t.selection.anchor,t.selection.head):w.single(0);return xd(n,i.length),e.staticFacet(dl)||(n=n.asSingle()),new $(e,i,n,e.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet($.tabSize)}get lineBreak(){return this.facet($.lineSeparator)||`
5
- `}get readOnly(){return this.facet(Dd)}phrase(t,...e){for(let i of this.facet($.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>e.length?i:e[r-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let r of this.facet(vd))for(let o of r(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&n.push(o[t]);return n}charCategorizer(t){return sy(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),r=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let a=V(e,o,!1);if(r(e.slice(a,o))!=Y.Word)break;o=a}for(;l<n;){let a=V(e,l);if(r(e.slice(l,a))!=Y.Word)break;l=a}return o==l?null:w.range(o+i,l+i)}}$.allowMultipleSelections=dl;$.tabSize=v.define({combine:s=>s.length?s[0]:4});$.lineSeparator=kd;$.readOnly=Dd;$.phrases=v.define({compare(s,t){let e=Object.keys(s),i=Object.keys(t);return e.length==i.length&&e.every(n=>s[n]==t[n])}});$.languageData=vd;$.changeFilter=Cd;$.transactionFilter=Md;$.transactionExtender=Ad;no.reconfigure=R.define();function De(s,t,e={}){let i={};for(let n of s)for(let r of Object.keys(n)){let o=n[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(e,r))i[r]=e[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let n in t)i[n]===void 0&&(i[n]=t[n]);return i}class Gt{eq(t){return this==t}range(t,e=t){return Un.create(t,e,this)}}Gt.prototype.startSide=Gt.prototype.endSide=0;Gt.prototype.point=!1;Gt.prototype.mapMode=I.TrackDel;class Un{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new Un(t,e,i)}}function ml(s,t){return s.from-t.from||s.value.startSide-t.value.startSide}class lh{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let r=i?this.to:this.from;for(let o=n,l=r.length;;){if(o==l)return o;let a=o+l>>1,c=r[a]-t||(i?this.value[a].endSide:this.value[a].startSide)-e;if(a==o)return c>=0?o:l;c>=0?l=a:o=a+1}}between(t,e,i,n){for(let r=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(n(this.from[r]+t,this.to[r]+t,this.value[r])===!1)return!1}map(t,e){let i=[],n=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let c=this.value[a],h=this.from[a]+t,f=this.to[a]+t,u,d;if(h==f){let p=e.mapPos(h,c.startSide,c.mapMode);if(p==null||(u=d=p,c.startSide!=c.endSide&&(d=e.mapPos(h,c.endSide),d<u)))continue}else if(u=e.mapPos(h,c.startSide),d=e.mapPos(f,c.endSide),u>d||u==d&&c.startSide>0&&c.endSide<=0)continue;(d-u||c.endSide-c.startSide)<0||(o<0&&(o=u),c.point&&(l=Math.max(l,d-u)),i.push(c),n.push(u-o),r.push(d-o))}return{mapped:i.length?new lh(n,r,i,l):null,pos:o}}}class E{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new E(t,e,i,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:n=0,filterTo:r=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(ml)),this.isEmpty)return e.length?E.of(e):this;let l=new Bd(this,null,-1).goto(0),a=0,c=[],h=new ii;for(;l.value||a<e.length;)if(a<e.length&&(l.from-e[a].from||l.startSide-e[a].value.startSide)>=0){let f=e[a++];h.addInner(f.from,f.to,f.value)||c.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==e.length||this.chunkEnd(l.chunkIndex)<e[a].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&h.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||n>l.to||r<l.from||o(l.from,l.to,l.value))&&(h.addInner(l.from,l.to,l.value)||c.push(Un.create(l.from,l.to,l.value))),l.next());return h.finishInner(this.nextLayer.isEmpty&&!c.length?E.empty:this.nextLayer.update({add:c,filter:o,filterFrom:n,filterTo:r}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],c=t.touchesRange(l,l+a.length);if(c===!1)n=Math.max(n,a.maxPoint),e.push(a),i.push(t.mapPos(l));else if(c===!0){let{mapped:h,pos:f}=a.map(l,t);h&&(n=Math.max(n,h.maxPoint),e.push(h),i.push(f))}}let r=this.nextLayer.map(t);return e.length==0?r:new E(i,e,r||E.empty,n)}between(t,e,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(e>=r&&t<=r+o.length&&o.between(r,t-r,e-r,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return Yn.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Yn.from(t).goto(e)}static compare(t,e,i,n,r=-1){let o=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=rc(o,l,i),c=new pn(o,a,r),h=new pn(l,a,r);i.iterGaps((f,u,d)=>oc(c,f,h,u,d,n)),i.empty&&i.length==0&&oc(c,0,h,0,0,n)}static eq(t,e,i=0,n){n==null&&(n=999999999);let r=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0),o=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=rc(r,o),a=new pn(r,l,0).goto(i),c=new pn(o,l,0).goto(i);for(;;){if(a.to!=c.to||!bl(a.active,c.active)||a.point&&(!c.point||!a.point.eq(c.point)))return!1;if(a.to>n)return!0;a.next(),c.next()}}static spans(t,e,i,n,r=-1){let o=new pn(t,null,r).goto(e),l=e,a=o.openStart;for(;;){let c=Math.min(o.to,i);if(o.point){let h=o.activeForPoint(o.to),f=o.pointFrom<e?h.length+1:o.point.startSide<0?h.length:Math.min(h.length,a);n.point(l,c,o.point,h,f,o.pointRank),a=Math.min(o.openEnd(c),h.length)}else c>l&&(n.span(l,c,o.active,a),a=o.openEnd(c));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(t,e=!1){let i=new ii;for(let n of t instanceof Un?[t]:e?ry(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return E.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=E.empty;n=n.nextLayer)e=new E(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}E.empty=new E([],[],null,-1);function ry(s){if(s.length>1)for(let t=s[0],e=1;e<s.length;e++){let i=s[e];if(ml(t,i)>0)return s.slice().sort(ml);t=i}return s}E.empty.nextLayer=E.empty;class ii{finishChunk(t){this.chunks.push(new lh(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,t&&(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(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new ii)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return n<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(E.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=E.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function rc(s,t,e){let i=new Map;for(let r of s)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let n=new Set;for(let r of t)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(e?e.mapPos(l):l)==r.chunkPos[o]&&!(e!=null&&e.touchesRange(l,l+r.chunk[o].length))&&n.add(r.chunk[o])}return n}class Bd{constructor(t,e,i,n=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<t||n.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==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=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class Yn{constructor(t){this.heap=t}static from(t,e=null,i=-1){let n=[];for(let r=0;r<t.length;r++)for(let o=t[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new Bd(o,e,i,r));return n.length==1?n[0]:new Yn(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)ko(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)ko(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),ko(this.heap,0)}}}function ko(s,t){for(let e=s[t];;){let i=(t<<1)+1;if(i>=s.length)break;let n=s[i];if(i+1<s.length&&n.compare(s[i+1])>=0&&(n=s[i+1],i++),e.compare(n)<0)break;s[i]=e,s[t]=n,t=i}}class pn{constructor(t,e,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=Yn.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){ks(this.active,t),ks(this.activeTo,t),ks(this.activeRank,t),this.minActive=lc(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:r}=this.cursor;for(;e<this.activeRank.length&&(r-this.activeRank[e]||n-this.activeTo[e])>0;)e++;Cs(this.active,e,i),Cs(this.activeTo,e,n),Cs(this.activeRank,e,r),t&&Cs(t,e,this.cursor.from),this.minActive=lc(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&ks(i,n)}else if(this.cursor.value)if(this.cursor.from>t){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(e&&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 n=i.length-1;n>=0&&i[n]<t;n--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function oc(s,t,e,i,n,r){s.goto(t),e.goto(i);let o=i+n,l=i,a=i-t;for(;;){let c=s.to+a-e.to||s.endSide-e.endSide,h=c<0?s.to+a:e.to,f=Math.min(h,o);if(s.point||e.point?s.point&&e.point&&(s.point==e.point||s.point.eq(e.point))&&bl(s.activeForPoint(s.to),e.activeForPoint(e.to))||r.comparePoint(l,f,s.point,e.point):f>l&&!bl(s.active,e.active)&&r.compareRange(l,f,s.active,e.active),h>o)break;l=h,c<=0&&s.next(),c>=0&&e.next()}}function bl(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++)if(s[e]!=t[e]&&!s[e].eq(t[e]))return!1;return!0}function ks(s,t){for(let e=t,i=s.length-1;e<i;e++)s[e]=s[e+1];s.pop()}function Cs(s,t,e){for(let i=s.length-1;i>=t;i--)s[i+1]=s[i];s[t]=e}function lc(s,t){let e=-1,i=1e9;for(let n=0;n<t.length;n++)(t[n]-i||s[n].endSide-s[e].endSide)<0&&(e=n,i=t[n]);return e}function ln(s,t,e=s.length){let i=0;for(let n=0;n<e;)s.charCodeAt(n)==9?(i+=t-i%t,n++):(i++,n=V(s,n));return i}function Xn(s,t,e,i){for(let n=0,r=0;;){if(r>=t)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?e-r%e:1,n=V(s,n)}return i===!0?-1:s.length}function _n(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function yl(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function oy(s){let t=s.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function cr(s,t){if(!t.anchorNode)return!1;try{return yl(s,t.anchorNode)}catch{return!1}}function qi(s){return s.nodeType==3?gi(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function Fn(s,t,e,i){return e?ac(s,t,e,i,-1)||ac(s,t,e,i,1):!1}function pi(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function Rr(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function ac(s,t,e,i,n){for(;;){if(s==e&&t==i)return!0;if(t==(n<0?0:$e(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;t=pi(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[t+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;t=n<0?$e(s):0}else return!1}}function $e(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function so(s,t){let e=t?s.left:s.right;return{left:e,right:e,top:s.top,bottom:s.bottom}}function ly(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function Ed(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function ay(s,t,e,i,n,r,o,l){let a=s.ownerDocument,c=a.defaultView||window;for(let h=s,f=!1;h&&!f;)if(h.nodeType==1){let u,d=h==a.body,p=1,g=1;if(d)u=ly(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(f=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let y=h.getBoundingClientRect();({scaleX:p,scaleY:g}=Ed(h,y)),u={left:y.left,right:y.left+h.clientWidth*p,top:y.top,bottom:y.top+h.clientHeight*g}}let b=0,m=0;if(n=="nearest")t.top<u.top?(m=-(u.top-t.top+o),e>0&&t.bottom>u.bottom+m&&(m=t.bottom-u.bottom+m+o)):t.bottom>u.bottom&&(m=t.bottom-u.bottom+o,e<0&&t.top-m<u.top&&(m=-(u.top+m-t.top+o)));else{let y=t.bottom-t.top,S=u.bottom-u.top;m=(n=="center"&&y<=S?t.top+y/2-S/2:n=="start"||n=="center"&&e<0?t.top-o:t.bottom-S+o)-u.top}if(i=="nearest"?t.left<u.left?(b=-(u.left-t.left+r),e>0&&t.right>u.right+b&&(b=t.right-u.right+b+r)):t.right>u.right&&(b=t.right-u.right+r,e<0&&t.left<u.left+b&&(b=-(u.left+b-t.left+r))):b=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-r:t.right-(u.right-u.left)+r)-u.left,b||m)if(d)c.scrollBy(b,m);else{let y=0,S=0;if(m){let x=h.scrollTop;h.scrollTop+=m/g,S=(h.scrollTop-x)*g}if(b){let x=h.scrollLeft;h.scrollLeft+=b/p,y=(h.scrollLeft-x)*p}t={left:t.left-y,top:t.top-S,right:t.right-y,bottom:t.bottom-S},y&&Math.abs(y-b)<1&&(i="nearest"),S&&Math.abs(S-m)<1&&(n="nearest")}if(d)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function hy(s){let t=s.ownerDocument,e,i;for(let n=s.parentNode;n&&!(n==t.body||e&&i);)if(n.nodeType==1)!i&&n.scrollHeight>n.clientHeight&&(i=n),!e&&n.scrollWidth>n.clientWidth&&(e=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:e,y:i}}let cy=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?$e(e):0),i,Math.min(t.focusOffset,i?$e(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}},Ci=null;function Rd(s){if(s.setActive)return s.setActive();if(Ci)return s.focus(Ci);let t=[];for(let e=s;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(s.focus(Ci==null?{get preventScroll(){return Ci={preventScroll:!0},!0}}:void 0),!Ci){Ci=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let hc;function gi(s,t,e=t){let i=hc||(hc=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function $i(s,t,e,i){let n={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function fy(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Ld(s){for(;s.attributes.length;)s.removeAttributeNode(s.attributes[0])}function uy(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,$e(e));;)if(i){if(e.nodeType!=1)return!1;let n=e.childNodes[i-1];n.contentEditable=="false"?i--:(e=n,i=$e(e))}else{if(e==s)return!0;i=pi(e),e=e.parentNode}}function Pd(s){return s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function $d(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=$e(e)}else if(e.parentNode&&!Rr(e))i=pi(e),e=e.parentNode;else return null}}function Nd(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!Rr(e))i=pi(e)+1,e=e.parentNode;else return null}}let Ht=class wl{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new wl(t.parentNode,pi(t),e)}static after(t,e){return new wl(t.parentNode,pi(t)+1,e)}};const ah=[];let Z=class xl{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,n=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=n?n.nextSibling:i.firstChild)){let l=xl.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=n?n.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=cc(r);else i.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=cc(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let n=$e(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;n==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?n=-1:n=1),t=r}n<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!xl.get(i);)i=i.nextSibling;if(!i)return this.length;for(let n=0,r=0;;n++){let o=this.children[n];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(t,e,i=0){let n=-1,r=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<this.children.length;a++){let f=this.children[a],u=c+f.length;if(c<t&&u>e)return f.domBoundsAround(t,e,c);if(u>=t&&n==-1&&(n=a,r=c),c>e&&f.dom.parentNode==this.dom){o=a,l=h;break}h=u,c=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=ah){this.markDirty();for(let n=t;n<e;n++){let r=this.children[n];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(t,e-t,...i);for(let n=0;n<i.length;n++)i[n].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new Hd(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,n,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}};Z.prototype.breakAfter=0;function cc(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}let Hd=class{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}};function Fd(s,t,e,i,n,r,o,l,a){let{children:c}=s,h=c.length?c[t]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(t==i&&h&&!o&&!u&&r.length<2&&h.merge(e,n,r.length?f:null,e==0,l,a))){if(i<c.length){let d=c[i];d&&(n<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(t==i&&(d=d.split(n),n=0),!u&&f&&d.merge(0,n,f,!0,0,a)?r[r.length-1]=d:((n||d.children.length&&!d.children[0].length)&&d.merge(0,n,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(h&&(h.breakAfter=o,e>0&&(!o&&r.length&&h.merge(e,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(e<h.length||h.children.length&&h.children[h.children.length-1].length==0)&&h.merge(e,h.length,null,!1,l,0),t++));t<i&&r.length;)if(c[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(c[t].become(r[0]))t++,r.shift(),l=r.length?0:a;else break;!r.length&&t&&i<c.length&&!c[t-1].breakAfter&&c[i].merge(0,0,c[t-1],!1,l,a)&&t--,(t<i||r.length)&&s.replaceChildren(t,i,r)}}function Id(s,t,e,i,n,r){let o=s.childCursor(),{i:l,off:a}=o.findPos(e,1),{i:c,off:h}=o.findPos(t,-1),f=t-e;for(let u of i)f+=u.length;s.length+=f,Fd(s,c,h,l,a,i,0,n,r)}let Ot=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Sl=typeof document<"u"?document:{documentElement:{style:{}}};const vl=/Edge\/(\d+)/.exec(Ot.userAgent),Vd=/MSIE \d/.test(Ot.userAgent),kl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ot.userAgent),ro=!!(Vd||kl||vl),fc=!ro&&/gecko\/(\d+)/i.test(Ot.userAgent),Co=!ro&&/Chrome\/(\d+)/.exec(Ot.userAgent),uc="webkitFontSmoothing"in Sl.documentElement.style,Wd=!ro&&/Apple Computer/.test(Ot.vendor),dc=Wd&&(/Mobile\/\w+/.test(Ot.userAgent)||Ot.maxTouchPoints>2);var A={mac:dc||/Mac/.test(Ot.platform),windows:/Win/.test(Ot.platform),linux:/Linux|X11/.test(Ot.platform),ie:ro,ie_version:Vd?Sl.documentMode||6:kl?+kl[1]:vl?+vl[1]:0,gecko:fc,gecko_version:fc?+(/Firefox\/(\d+)/.exec(Ot.userAgent)||[0,0])[1]:0,chrome:!!Co,chrome_version:Co?+Co[1]:0,ios:dc,android:/Android\b/.test(Ot.userAgent),webkit:uc,safari:Wd,webkit_version:uc?+(/\bAppleWebKit\/(\d+)/.exec(Ot.userAgent)||[0,0])[1]:0,tabSize:Sl.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const dy=256;let ni=class Cl extends Z{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof Cl)||this.length-(e-t)+i.length>dy||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Cl(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Ht(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return py(this.dom,t,e)}},ji=class Ml extends Z{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let n of e)n.setParent(this)}setAttrs(t){if(Ld(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,r,o){return i&&(!(i instanceof Ml&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(Id(this,t,e,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,n=-1,r=0;for(let l of this.children){let a=i+l.length;a>t&&e.push(i<t?l.split(t-i):l),n<0&&i>=t&&(n=r),i=a,r++}let o=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Ml(this.mark,e,o)}domAtPos(t){return zd(this,t)}coordsAt(t,e){return qd(this,t,e)}};function py(s,t,e){let i=s.nodeValue.length;t>i&&(t=i);let n=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?A.chrome||A.gecko||(t?(n--,o=1):r<i&&(r++,o=-1)):e<0?n--:r<i&&r++;let l=gi(s,n,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:e>=0)?0:l.length-1];return A.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,c=>c.width)||a),o?so(a,o<0):a||null}let hh=class wn extends Z{static create(t,e,i){return new wn(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=wn.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,r,o){return i&&(!(i instanceof wn)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof wn&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return B.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,n=this.posAtStart;return i?i.slice(n,n+this.length):B.empty}domAtPos(t){return(this.length?t==0:this.side>0)?Ht.before(this.dom):Ht.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?n.length-1:0;r=n[l],!(t>0?l==0:l==n.length-1||r.top<r.bottom);l+=o?-1:1);return so(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},Al=class Dl extends Z{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof Dl&&t.side==this.side}split(){return new Dl(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?Ht.before(this.dom):Ht.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return B.empty}get isHidden(){return!0}};ni.prototype.children=hh.prototype.children=Al.prototype.children=ah;function zd(s,t){let e=s.dom,{children:i}=s,n=0;for(let r=0;n<i.length;n++){let o=i[n],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=n;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=n;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new Ht(e,0)}function Kd(s,t,e){let i,{children:n}=s;e>0&&t instanceof ji&&n.length&&(i=n[n.length-1])instanceof ji&&i.mark.eq(t.mark)?Kd(i,t.children[0],e-1):(n.push(t),t.setParent(s)),s.length+=t.length}function qd(s,t,e){let i=null,n=-1,r=null,o=-1;function l(c,h){for(let f=0,u=0;f<c.children.length&&u<=h;f++){let d=c.children[f],p=u+d.length;p>=h&&(d.children.length?l(d,h-u):(!r||r.isHidden&&e>0)&&(p>h||u==p&&d.getSide()>0)?(r=d,o=h-u):(u<h||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,n=h-u)),u=p}}l(s,t);let a=(e<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?n:o),e):gy(s)}function gy(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=qi(t);return e[e.length-1]||null}function Ol(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}const pc=Object.create(null);function Lr(s,t,e){if(s==t)return!0;s||(s=pc),t||(t=pc);let i=Object.keys(s),n=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=n.length-(e&&n.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(n.indexOf(r)==-1||s[r]!==t[r]))return!1;return!0}function Tl(s,t,e){let i=!1;if(t)for(let n in t)e&&n in e||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(i=!0,n=="style"?s.style.cssText=e[n]:s.setAttribute(n,e[n]));return i}function my(s){let t=Object.create(null);for(let e=0;e<s.attributes.length;e++){let i=s.attributes[e];t[i.name]=i.value}return t}let yt=class xn extends Z{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,r,o){if(i){if(!(i instanceof xn))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Id(this,t,e,i?i.children.slice():[],r,o),!0}split(t){let e=new xn;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:n}=this.childPos(t);n&&(e.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Lr(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Kd(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Ol(e,this.attrs||{})),i&&(this.attrs=Ol({class:i},this.attrs||{}))}domAtPos(t){return zd(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(Ld(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(Tl(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&Z.get(n)instanceof ji;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=Z.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!A.ios||!this.children.some(r=>r instanceof ni))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof ni)||/[^ -~]/.test(i.text))return null;let n=qi(i.dom);if(n.length!=1)return null;t+=n[0].width,e=n[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=qd(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:n}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-n.lineHeight)<2&&n.textHeight<r){let o=(r-n.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(t){return t instanceof xn&&this.children.length==0&&t.children.length==0&&Lr(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,n=0;i<t.children.length;i++){let r=t.children[i],o=n+r.length;if(o>=e){if(r instanceof xn)return r;if(o>e)break}n=o+r.breakAfter}return null}},In=class fr extends Z{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,r,o){return i&&(!(i instanceof fr)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?Ht.before(this.dom):Ht.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new fr(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return ah}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):B.empty}domBoundsAround(){return null}become(t){return t instanceof fr&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}},Oe=class{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}};var kt=function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s}(kt||(kt={}));let P=class extends Gt{constructor(t,e,i,n){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(t){return new ch(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new Gi(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,n;if(t.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=Yd(t,e);i=(r?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new Gi(t,i,n,e,t.widget||null,!0)}static line(t){return new fh(t)}static set(t,e=!1){return E.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};P.none=E.empty;let ch=class jd extends P{constructor(t){let{start:e,end:i}=Yd(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof jd&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&Lr(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}};ch.prototype.point=!1;let fh=class Gd extends P{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Gd&&this.spec.class==t.spec.class&&Lr(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}};fh.prototype.mapMode=I.TrackBefore;fh.prototype.point=!0;let Gi=class Ud extends P{constructor(t,e,i,n,r,o){super(e,i,r,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?I.TrackBefore:I.TrackAfter:I.TrackDel}get type(){return this.startSide!=this.endSide?kt.WidgetRange:this.startSide<=0?kt.WidgetBefore:kt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Ud&&by(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}};Gi.prototype.point=!0;function Yd(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function by(s,t){return s==t||!!(s&&t&&s.compare(t))}function Bl(s,t,e,i=0){let n=e.length-1;n>=0&&e[n]+i>=s?e[n]=Math.max(e[n],t):e.push(s,t)}let Mo=class Xd{constructor(t,e,i,n){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof In&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new yt),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ms(new Al(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof In)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Ms(new ni(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof Gi){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof Gi)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new In(i.widget||Ui.block,l,i));else{let a=hh.create(i.widget||Ui.inline,l,l?0:i.startSide),c=this.atCursorPos&&!a.isEditable&&r<=n.length&&(t<e||i.startSide>0),h=!a.isEditable&&(t<e||r>n.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!c&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),c&&(f.append(Ms(new Al(1),n),r),r=n.length+Math.max(0,r-n.length)),f.append(Ms(a,n),r),this.atCursorPos=h,this.pendingBuffer=h?t<e||r>n.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,n,r){let o=new Xd(t,e,i,r);return o.openEnd=E.spans(n,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function Ms(s,t){for(let e of t)s=new ji(e,[s],s.length);return s}let Ui=class extends Oe{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};Ui.inline=new Ui("span");Ui.block=new Ui("div");var Q=function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s}(Q||(Q={}));const mi=Q.LTR,uh=Q.RTL;function _d(s){let t=[];for(let e=0;e<s.length;e++)t.push(1<<+s[e]);return t}const yy=_d("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),wy=_d("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),El=Object.create(null),de=[];for(let s of["()","[]","{}"]){let t=s.charCodeAt(0),e=s.charCodeAt(1);El[t]=e,El[e]=-t}function Jd(s){return s<=247?yy[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?wy[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const xy=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;let Xe=class{get dir(){return this.level%2?uh:mi}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,n){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}};function Qd(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++){let i=s[e],n=t[e];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!Qd(i.inner,n.inner))return!1}return!0}const z=[];function Sy(s,t,e,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,a=r?256:n;for(let c=o,h=a,f=a;c<l;c++){let u=Jd(s.charCodeAt(c));u==512?u=h:u==8&&f==4&&(u=16),z[c]=u==4?2:u,u&7&&(f=u),h=u}for(let c=o,h=a,f=a;c<l;c++){let u=z[c];if(u==128)c<l-1&&h==z[c+1]&&h&24?u=z[c]=h:z[c]=256;else if(u==64){let d=c+1;for(;d<l&&z[d]==64;)d++;let p=c&&h==8||d<e&&z[d]==8?f==1?1:8:256;for(let g=c;g<d;g++)z[g]=p;c=d-1}else u==8&&f==1&&(z[c]=1);h=u,u&7&&(f=u)}}}function vy(s,t,e,i,n){let r=n==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let c=o?i[o-1].to:t,h=o<i.length?i[o].from:e;for(let f=c,u,d,p;f<h;f++)if(d=El[u=s.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(de[g+1]==-d){let b=de[g+2],m=b&2?n:b&4?b&1?r:n:0;m&&(z[f]=z[de[g]]=m),l=g;break}}else{if(de.length==189)break;de[l++]=f,de[l++]=u,de[l++]=a}else if((p=z[f])==2||p==1){let g=p==n;a=g?0:1;for(let b=l-3;b>=0;b-=3){let m=de[b+2];if(m&2)break;if(g)de[b+2]|=2;else{if(m&4)break;de[b+2]|=4}}}}}function ky(s,t,e,i){for(let n=0,r=i;n<=e.length;n++){let o=n?e[n-1].to:s,l=n<e.length?e[n].from:t;for(let a=o;a<l;){let c=z[a];if(c==256){let h=a+1;for(;;)if(h==l){if(n==e.length)break;h=e[n++].to,l=n<e.length?e[n].from:t}else if(z[h]==256)h++;else break;let f=r==1,u=(h<t?z[h]:i)==1,d=f==u?f?1:2:i;for(let p=h,g=n,b=g?e[g-1].to:s;p>a;)p==b&&(p=e[--g].from,b=g?e[g-1].to:s),z[--p]=d;a=h}else r=c,a++}}}function Rl(s,t,e,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=t,c=0;a<e;){let h=!0,f=!1;if(c==r.length||a<r[c].from){let g=z[a];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;t:for(;;)if(c<r.length&&p==r[c].from){if(f)break t;let g=r[c];if(!h)for(let b=g.to,m=c+1;;){if(b==e)break t;if(m<r.length&&r[m].from==b)b=r[m++].to;else{if(z[b]==l)break t;break}}if(c++,u)u.push(g);else{g.from>a&&o.push(new Xe(a,g.from,d));let b=g.direction==mi!=!(d%2);Ll(s,b?i+1:i,n,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==e||(h?z[p]!=l:z[p]==l))break;p++}u?Rl(s,a,p,i+1,n,u,o):a<p&&o.push(new Xe(a,p,d)),a=p}else for(let a=e,c=r.length;a>t;){let h=!0,f=!1;if(!c||a>r[c-1].to){let g=z[a-1];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;t:for(;;)if(c&&p==r[c-1].to){if(f)break t;let g=r[--c];if(!h)for(let b=g.from,m=c;;){if(b==t)break t;if(m&&r[m-1].to==b)b=r[--m].from;else{if(z[b-1]==l)break t;break}}if(u)u.push(g);else{g.to<a&&o.push(new Xe(g.to,a,d));let b=g.direction==mi!=!(d%2);Ll(s,b?i+1:i,n,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==t||(h?z[p-1]!=l:z[p-1]==l))break;p--}u?Rl(s,p,a,i+1,n,u,o):p<a&&o.push(new Xe(p,a,d)),a=p}}function Ll(s,t,e,i,n,r,o){let l=t%2?2:1;Sy(s,n,r,i,l),vy(s,n,r,i,l),ky(n,r,i,l),Rl(s,n,r,t,e,i,o)}function Cy(s,t,e){if(!s)return[new Xe(0,0,t==uh?1:0)];if(t==mi&&!e.length&&!xy.test(s))return Zd(s.length);if(e.length)for(;s.length>z.length;)z[z.length]=256;let i=[],n=t==mi?0:1;return Ll(s,n,n,e,0,s.length,i),i}function Zd(s){return[new Xe(0,s,0)]}let tp="";function My(s,t,e,i,n){var r;let o=i.head-s.from,l=Xe.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=t[l],c=a.side(n,e);if(o==c){let u=l+=n?1:-1;if(u<0||u>=t.length)return null;a=t[l=u],o=a.side(!n,e),c=a.side(n,e)}let h=V(s.text,o,a.forward(n,e));(h<a.from||h>a.to)&&(h=c),tp=s.text.slice(Math.min(o,h),Math.max(o,h));let f=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];return f&&h==c&&f.level+(n?0:1)<a.level?w.cursor(f.side(!n,e)+s.from,f.forward(n,e)?1:-1,f.level):w.cursor(h+s.from,a.forward(n,e)?-1:1,a.level)}function Ay(s,t,e){for(let i=t;i<e;i++){let n=Jd(s.charCodeAt(i));if(n==1)return mi;if(n==2||n==4)return uh}return mi}const ep=v.define(),ip=v.define(),np=v.define(),sp=v.define(),Pl=v.define(),rp=v.define(),op=v.define(),lp=v.define({combine:s=>s.some(t=>t)}),ap=v.define({combine:s=>s.some(t=>t)}),hp=v.define();let Ao=class $l{constructor(t,e="nearest",i="nearest",n=5,r=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new $l(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new $l(w.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}};const As=R.define({map:(s,t)=>s.map(t)}),cp=R.define();function xt(s,t,e){let i=s.facet(sp);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const Ve=v.define({combine:s=>s.length?s[0]:!0});let Dy=0;const Sn=v.define();let pt=class Nl{constructor(t,e,i,n,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=e||{};return new Nl(Dy++,t,i,n,l=>{let a=[Sn.of(l)];return o&&a.push(Jn.of(c=>{let h=c.plugin(l);return h?o(h):P.none})),r&&a.push(r(l)),a})}static fromClass(t,e){return Nl.define(i=>new t(i),e)}},Do=class{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(xt(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){xt(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){xt(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}};const fp=v.define(),dh=v.define(),Jn=v.define(),up=v.define(),ph=v.define(),dp=v.define();function gc(s,t){let e=s.state.facet(dp);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(s):r),n=[];return E.spans(i,t.from,t.to,{point(){},span(r,o,l,a){let c=r-t.from,h=o-t.from,f=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Ay(t.text,c,h)),a>0&&f.length&&(p=f[f.length-1]).to==c&&p.direction==d)p.to=h,f=p.inner;else{let g={from:c,to:h,direction:d,inner:[]};f.push(g),f=g.inner}}}}),n}const pp=v.define();function gp(s){let t=0,e=0,i=0,n=0;for(let r of s.state.facet(pp)){let o=r(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:i,bottom:n}}const vn=v.define();let Qe=class ur{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new ur(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let n=0,r=0,o=0,l=0;;n++){let a=n==t.length?null:t[n],c=o-l,h=a?a.fromB:1e9;for(;r<e.length&&e[r]<h;){let f=e[r],u=e[r+1],d=Math.max(l,f),p=Math.min(h,u);if(d<=p&&new ur(d+c,p+c,d,p).addToSet(i),u>h)break;r+=2}if(!a)return i;new ur(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}},mc=class mp{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=et.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,a)=>n.push(new Qe(r,o,l,a))),this.changedRanges=n}static create(t,e,i){return new mp(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},bc=class extends Z{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=P.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new yt],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Qe(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:h})=>h<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!Py(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let r=n>-1?Ty(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:c,to:h}=this.hasComposition;i=new Qe(c,h,t.changes.mapPos(c,-1),t.changes.mapPos(h,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(A.ie||A.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=Ry(o,l,t.changes);return i=Qe.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=A.chrome||A.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||n.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof In&&o.widget instanceof yc&&r.push(o.dom);n.updateGaps(r)}updateChildren(t,e,i){let n=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let o=n.length-1;;o--){let l=o>=0?n[o]:null;if(!l)break;let{fromA:a,toA:c,fromB:h,toB:f}=l,u,d,p,g;if(i&&i.range.fromB<f&&i.range.toB>h){let x=Mo.build(this.view.state.doc,h,i.range.fromB,this.decorations,this.dynamicDecorationMap),k=Mo.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=x.breakAtStart,p=x.openStart,g=k.openEnd;let M=this.compositionView(i);k.breakAtStart?M.breakAfter=1:k.content.length&&M.merge(M.length,M.length,k.content[0],!1,k.openStart,0)&&(M.breakAfter=k.content[0].breakAfter,k.content.shift()),x.content.length&&M.merge(0,0,x.content[x.content.length-1],!0,0,x.openEnd)&&x.content.pop(),u=x.content.concat(M).concat(k.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=Mo.build(this.view.state.doc,h,f,this.decorations,this.dynamicDecorationMap));let{i:b,off:m}=r.findPos(c,1),{i:y,off:S}=r.findPos(a,-1);Fd(this,y,S,b,m,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(cp)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new ni(t.text.nodeValue);e.flags|=8;for(let{deco:n}of t.marks)e=new ji(n,[e],e.length);let i=new yt;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=Z.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let r=t.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],e(r>=0?t.marks[r].node:t.text,n)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&cr(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),c=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(A.gecko&&l.empty&&!this.hasComposition&&Oy(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=c=new Ht(f,0),o=!0}let h=this.view.observer.selectionRange;(o||!h.focusNode||(!Fn(a.node,a.offset,h.anchorNode,h.anchorOffset)||!Fn(c.node,c.offset,h.focusNode,h.focusOffset))&&!this.suppressWidgetCursorChange(h,l))&&(this.view.observer.ignore(()=>{A.android&&A.chrome&&this.dom.contains(h.focusNode)&&Ly(h.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=_n(this.view.root);if(f)if(l.empty){if(A.gecko){let u=By(a.node,a.offset);if(u&&u!=3){let d=(u==1?$d:Nd)(a.node,a.offset);d&&(a=new Ht(d.node,d.offset))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,c]=[c,a]),u.setEnd(c.node,c.offset),u.setStart(a.node,a.offset),f.removeAllRanges(),f.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,c)),this.impreciseAnchor=a.precise?null:new Ht(h.anchorNode,h.anchorOffset),this.impreciseHead=c.precise?null:new Ht(h.focusNode,h.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Fn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=_n(t.root),{anchorNode:n,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=yt.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let a=this.coordsAt(e.head,-1),c=this.coordsAt(e.head,1);if(!a||!c||a.bottom>c.top)return;let h=this.domAtPos(e.head+e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(n,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let n=t.offset;!i&&n<e.childNodes.length;n++){let r=Z.get(e.childNodes[n]);r instanceof yt&&(i=r.domAtPos(0))}for(let n=t.offset-1;!i&&n>=0;n--){let r=Z.get(e.childNodes[n]);r instanceof yt&&(i=r.domAtPos(r.length))}return i?new Ht(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=Z.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let n=this.children[e];if(i<n.length||n instanceof yt)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,n=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,c=a-l.length;if(a<t)break;if(c<=t&&(c<t||l.covers(-1))&&(a>t||l.covers(1))&&(!i||l instanceof yt&&!(i instanceof yt&&e>=0)))i=l,n=c;else if(i&&c==t&&a==t&&l instanceof In&&Math.abs(e)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=c}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof yt))return null;for(;n.children.length;){let{i:l,off:a}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=a}if(!(n instanceof ni))return null;let r=V(n.text,i);if(r==i)return null;let o=gi(n.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:n}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==Q.LTR;for(let c=0,h=0;h<this.children.length;h++){let f=this.children[h],u=c+f.length;if(u>n)break;if(c>=i){let d=f.dom.getBoundingClientRect();if(e.push(d.height),o){let p=f.dom.lastChild,g=p?qi(p):[];if(g.length){let b=g[g.length-1],m=a?b.right-d.left:d.right-b.left;m>l&&(l=m,this.minWidth=r,this.minWidthFrom=c,this.minWidthTo=u)}}}c=u+f.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?Q.RTL:Q.LTR}measureTextSize(){for(let r of this.children)if(r instanceof yt){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,n;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.dom.appendChild(t);let r=qi(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Hd(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let r=n==e.viewports.length?null:e.viewports[n],o=r?r.from-1:this.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(P.replace({widget:new yc(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return P.set(t)}updateDeco(){let t=1,e=this.view.state.facet(Jn).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(up).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(E.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let c=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=c.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let c of this.view.state.facet(hp))try{if(c(this.view,t.range,t))return!0}catch(h){xt(this.view.state,h,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),n;if(!i)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let r=gp(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;ay(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==Q.LTR)}};function Oy(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}let yc=class extends Oe{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function bp(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=$d(e.focusNode,e.focusOffset),n=Nd(e.focusNode,e.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=Z.get(n.node);if(!l||l instanceof ni&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=Z.get(i.node);!a||a instanceof ni&&a.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Ty(s,t,e){let i=bp(s,e);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc,c=new Qe(a.mapPos(r),a.mapPos(o),r,o),h=[];for(let f=n.parentNode;;f=f.parentNode){let u=Z.get(f);if(u instanceof ji)h.push({node:f,deco:u.mark});else{if(u instanceof yt||f.nodeName=="DIV"&&f.parentNode==s.contentDOM)return{range:c,text:n,marks:h,line:f};if(f!=s.contentDOM)h.push({node:f,deco:new ch({inclusive:!0,attributes:my(f),tagName:f.tagName.toLowerCase()})});else return null}}}function By(s,t){return s.nodeType!=1?0:(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t<s.childNodes.length&&s.childNodes[t].contentEditable=="false"?2:0)}let Ey=class{constructor(){this.changes=[]}compareRange(t,e){Bl(t,e,this.changes)}comparePoint(t,e){Bl(t,e,this.changes)}};function Ry(s,t,e){let i=new Ey;return E.compare(s,t,e,i),i.changes}function Ly(s,t){for(let e=s;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Py(s,t){let e=!1;return t&&s.iterChangedRanges((i,n)=>{i<t.to&&n>t.from&&(e=!0)}),e}function $y(s,t,e=1){let i=s.charCategorizer(t),n=s.doc.lineAt(t),r=t-n.from;if(n.length==0)return w.cursor(t);r==0?e=1:r==n.length&&(e=-1);let o=r,l=r;e<0?o=V(n.text,r,!1):l=V(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let c=V(n.text,o,!1);if(i(n.text.slice(c,o))!=a)break;o=c}for(;l<n.length;){let c=V(n.text,l);if(i(n.text.slice(l,c))!=a)break;l=c}return w.range(o+n.from,l+n.from)}function Ny(s,t){return t.left>s?t.left-s:Math.max(0,s-t.right)}function Hy(s,t){return t.top>s?t.top-s:Math.max(0,s-t.bottom)}function Oo(s,t){return s.top<t.bottom-1&&s.bottom>t.top+1}function wc(s,t){return t<s.top?{top:t,left:s.left,right:s.right,bottom:s.bottom}:s}function xc(s,t){return t>s.bottom?{top:s.top,left:s.left,right:s.right,bottom:t}:s}function Hl(s,t,e){let i,n,r,o,l=!1,a,c,h,f;for(let p=s.firstChild;p;p=p.nextSibling){let g=qi(p);for(let b=0;b<g.length;b++){let m=g[b];n&&Oo(n,m)&&(m=wc(xc(m,n.bottom),n.top));let y=Ny(t,m),S=Hy(e,m);if(y==0&&S==0)return p.nodeType==3?Sc(p,t,e):Hl(p,t,e);if(!i||o>S||o==S&&r>y){i=p,n=m,r=y,o=S;let x=S?e<m.top?-1:1:y?t<m.left?-1:1:0;l=!x||(x>0?b<g.length-1:b>0)}y==0?e>m.bottom&&(!h||h.bottom<m.bottom)?(a=p,h=m):e<m.top&&(!f||f.top>m.top)&&(c=p,f=m):h&&Oo(h,m)?h=xc(h,m.bottom):f&&Oo(f,m)&&(f=wc(f,m.top))}}if(h&&h.bottom>=e?(i=a,n=h):f&&f.top<=e&&(i=c,n=f),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,t));if(i.nodeType==3)return Sc(i,u,e);if(l&&i.contentEditable!="false")return Hl(i,u,e);let d=Array.prototype.indexOf.call(s.childNodes,i)+(t>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function Sc(s,t,e){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=gi(s,l,l+1).getClientRects();for(let c=0;c<a.length;c++){let h=a[c];if(h.top==h.bottom)continue;o||(o=t-h.left);let f=(h.top>e?h.top-e:e-h.bottom)-1;if(h.left-1<=t&&h.right+1>=t&&f<r){let u=t>=(h.left+h.right)/2,d=u;if((A.chrome||A.gecko)&&gi(s,l).getBoundingClientRect().left==h.right&&(d=!u),f<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=f}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function yp(s,t,e,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,a,{docHeight:c}=s.viewState,{x:h,y:f}=t,u=f-l;if(u<0)return 0;if(u>c)return s.state.doc.length;for(let x=s.viewState.heightOracle.textHeight/2,k=!1;a=s.elementAtHeight(u),a.type!=kt.Text;)for(;u=i>0?a.bottom+x:a.top-x,!(u>=0&&u<=c);){if(k)return e?null:0;k=!0,i=-i}f=l+u;let d=a.from;if(d<s.viewport.from)return s.viewport.from==0?0:e?null:vc(s,o,a,h,f);if(d>s.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:e?null:vc(s,o,a,h,f);let p=s.dom.ownerDocument,g=s.root.elementFromPoint?s.root:p,b=g.elementFromPoint(h,f);b&&!s.contentDOM.contains(b)&&(b=null),b||(h=Math.max(o.left+1,Math.min(o.right-1,h)),b=g.elementFromPoint(h,f),b&&!s.contentDOM.contains(b)&&(b=null));let m,y=-1;if(b&&((n=s.docView.nearest(b))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let x=p.caretPositionFromPoint(h,f);x&&({offsetNode:m,offset:y}=x)}else if(p.caretRangeFromPoint){let x=p.caretRangeFromPoint(h,f);x&&({startContainer:m,startOffset:y}=x,(!s.contentDOM.contains(m)||A.safari&&Fy(m,y,h)||A.chrome&&Iy(m,y,h))&&(m=void 0))}}if(!m||!s.docView.dom.contains(m)){let x=yt.find(s.docView,d);if(!x)return u>a.top+a.height/2?a.to:a.from;({node:m,offset:y}=Hl(x.dom,h,f))}let S=s.docView.nearest(m);if(!S)return null;if(S.isWidget&&((r=S.dom)===null||r===void 0?void 0:r.nodeType)==1){let x=S.dom.getBoundingClientRect();return t.y<x.top||t.y<=x.bottom&&t.x<=(x.left+x.right)/2?S.posAtStart:S.posAtEnd}else return S.localPosFromDOM(m,y)+S.posAtStart}function vc(s,t,e,i,n){let r=Math.round((i-t.left)*s.defaultCharacterWidth);if(s.lineWrapping&&e.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,a=Math.floor((n-e.top-(s.defaultLineHeight-l)*.5)/l);r+=a*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+Xn(o,r,s.state.tabSize)}function Fy(s,t,e){let i;if(s.nodeType!=3||t!=(i=s.nodeValue.length))return!1;for(let n=s.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!="BR")return!1;return gi(s,i-1,i).getBoundingClientRect().left>e}function Iy(s,t,e){if(t!=0)return!1;for(let n=s;;){let r=n.parentNode;if(!r||r.nodeType!=1||r.firstChild!=n)return!1;if(r.classList.contains("cm-line"))break;n=r}let i=s.nodeType==1?s.getBoundingClientRect():gi(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function Fl(s,t){let e=s.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==kt.Text))return i}return e}function Vy(s,t,e,i){let n=Fl(s,t.head),r=!i||n.type!=kt.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),a=s.posAtCoords({x:e==(l==Q.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return w.cursor(a,e?-1:1)}return w.cursor(e?n.to:n.from,e?-1:1)}function kc(s,t,e,i){let n=s.state.doc.lineAt(t.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=t,a=null;;){let c=My(n,r,o,l,e),h=tp;if(!c){if(n.number==(e?s.state.doc.lines:1))return l;h=`
6
- `,n=s.state.doc.line(n.number+(e?1:-1)),r=s.bidiSpans(n),c=s.visualLineSide(n,!e)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function Wy(s,t,e){let i=s.state.charCategorizer(t),n=i(e);return r=>{let o=i(r);return n==Y.Space&&(n=o),n==o}}function zy(s,t,e,i){let n=t.head,r=e?1:-1;if(n==(e?s.state.doc.length:0))return w.cursor(n,t.assoc);let o=t.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),c=s.coordsAtPos(n,t.assoc||-1),h=s.documentTop;if(c)o==null&&(o=c.left-a.left),l=r<0?c.top:c.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+h}let f=a.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=yp(s,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<n:g>n)){let b=s.docView.coordsForChar(g),m=!b||p<b.top?-1:1;return w.cursor(g,m,void 0,o)}}}function dr(s,t,e){for(;;){let i=0;for(let n of s)n.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let a=i||e||(t-r<o-t?-1:1);t=a<0?r:o,i=a}});if(!i)return t}}function To(s,t,e){let i=dr(s.state.facet(ph).map(n=>n(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:w.cursor(i,i<e.from?1:-1)}let Ky=class{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,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.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,A.safari&&t.contentDOM.addEventListener("input",()=>null),A.gecko&&r1(t.contentDOM.ownerDocument)}handleEvent(t){!Jy(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let n of i.observers)n(this.view,e);for(let n of i.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=qy(t),i=this.handlers,n=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&xp.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),A.android&&A.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return A.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=wp.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||jy.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,$i(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:A.safari&&!A.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function Cc(s,t){return(e,i)=>{try{return t.call(s,i,e)}catch(n){xt(e.state,n)}}}function qy(s){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec;if(n&&n.domEventHandlers)for(let r in n.domEventHandlers){let o=n.domEventHandlers[r];o&&e(r).handlers.push(Cc(i.value,o))}if(n&&n.domEventObservers)for(let r in n.domEventObservers){let o=n.domEventObservers[r];o&&e(r).observers.push(Cc(i.value,o))}}for(let i in le)e(i).handlers.push(le[i]);for(let i in Ut)e(i).observers.push(Ut[i]);return t}const wp=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],jy="dthko",xp=[16,17,18,20,91,92,224,225],Ds=6;function Os(s){return Math.max(0,s)*.7+8}function Gy(s,t){return Math.max(Math.abs(s.clientX-t.clientX),Math.abs(s.clientY-t.clientY))}let Uy=class{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=hy(t.contentDOM),this.atoms=t.state.facet(ph).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet($.allowMultipleSelections)&&Yy(t,e),this.dragging=_y(t,e)&&Cp(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Gy(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=gp(this.view);t.clientX-a.left<=n+Ds?e=-Os(n-t.clientX):t.clientX+a.right>=o-Ds&&(e=Os(t.clientX-o)),t.clientY-a.top<=r+Ds?i=-Os(r-t.clientY):t.clientY+a.bottom>=l-Ds&&(i=Os(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let n=t.ranges[i],r=null;if(n.empty){let o=dr(this.atoms,n.from,0);o!=n.from&&(r=w.cursor(o,-1))}else{let o=dr(this.atoms,n.from,-1),l=dr(this.atoms,n.to,1);(o!=n.from||l!=n.to)&&(r=w.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?w.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Yy(s,t){let e=s.state.facet(ep);return e.length?e[0](t):A.mac?t.metaKey:t.ctrlKey}function Xy(s,t){let e=s.state.facet(ip);return e.length?e[0](t):A.mac?!t.altKey:!t.ctrlKey}function _y(s,t){let{main:e}=s.state.selection;if(e.empty)return!1;let i=_n(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function Jy(s,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=s.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=Z.get(e))&&i.ignoreEvent(t))return!1;return!0}const le=Object.create(null),Ut=Object.create(null),Sp=A.ie&&A.ie_version<15||A.ios&&A.webkit_version<604;function Qy(s){let t=s.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{s.focus(),e.remove(),vp(s,e.value)},50)}function vp(s,t){let{state:e}=s,i,n=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(Il!=null&&e.selection.ranges.every(a=>a.empty)&&Il==r.toString()){let a=-1;i=e.changeByRange(c=>{let h=e.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let f=e.toText((o?r.line(n++).text:t)+e.lineBreak);return{changes:{from:h.from,insert:f},range:w.cursor(c.from+f.length)}})}else o?i=e.changeByRange(a=>{let c=r.line(n++);return{changes:{from:a.from,to:a.to,insert:c.text},range:w.cursor(a.from+c.length)}}):i=e.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Ut.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};le.keydown=(s,t)=>(s.inputState.setSelectionOrigin("select"),t.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);Ut.touchstart=(s,t)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Ut.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};le.mousedown=(s,t)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of s.state.facet(np))if(e=i(s,t),e)break;if(!e&&t.button==0&&(e=e1(s,t)),e){let i=!s.hasFocus;s.inputState.startMouseSelection(new Uy(s,t,e,i)),i&&s.observer.ignore(()=>{Rd(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}return!1};function Mc(s,t,e,i){if(i==1)return w.cursor(t,e);if(i==2)return $y(s.state,t,e);{let n=yt.find(s.docView,t),r=s.state.doc.lineAt(n?n.posAtEnd:t),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,w.range(o,l)}}let kp=(s,t)=>s>=t.top&&s<=t.bottom,Ac=(s,t,e)=>kp(t,e)&&s>=e.left&&s<=e.right;function Zy(s,t,e,i){let n=yt.find(s.docView,t);if(!n)return 1;let r=t-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&Ac(e,i,o))return-1;let l=n.coordsAt(r,1);return l&&Ac(e,i,l)?1:o&&kp(i,o)?-1:1}function Dc(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:Zy(s,e,t.clientX,t.clientY)}}const t1=A.ie&&A.ie_version<=11;let Oc=null,Tc=0,Bc=0;function Cp(s){if(!t1)return s.detail;let t=Oc,e=Bc;return Oc=s,Bc=Date.now(),Tc=!t||e>Date.now()-400&&Math.abs(t.clientX-s.clientX)<2&&Math.abs(t.clientY-s.clientY)<2?(Tc+1)%3:1}function e1(s,t){let e=Dc(s,t),i=Cp(t),n=s.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),n=n.map(r.changes))},get(r,o,l){let a=Dc(s,r),c,h=Mc(s,a.pos,a.bias,i);if(e.pos!=a.pos&&!o){let f=Mc(s,e.pos,e.bias,i),u=Math.min(f.from,h.from),d=Math.max(f.to,h.to);h=u<h.from?w.range(u,d):w.range(d,u)}return o?n.replaceRange(n.main.extend(h.from,h.to)):l&&i==1&&n.ranges.length>1&&(c=i1(n,a.pos))?c:l?n.addRange(h):w.create([h])}}}function i1(s,t){for(let e=0;e<s.ranges.length;e++){let{from:i,to:n}=s.ranges[e];if(i<=t&&n>=t)return w.create(s.ranges.slice(0,e).concat(s.ranges.slice(e+1)),s.mainIndex==e?0:s.mainIndex-(s.mainIndex>e?1:0))}return null}le.dragstart=(s,t)=>{let{selection:{main:e}}=s.state;if(t.target.draggable){let n=s.docView.nearest(t.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=e.to||o<=e.from)&&(e=w.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",s.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed="copyMove"),!1};le.dragend=s=>(s.inputState.draggedContent=null,!1);function Ec(s,t,e,i){if(!e)return;let n=s.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Xy(s,t)?{from:r.from,to:r.to}:null,l={from:n,insert:e},a=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}le.drop=(s,t)=>{if(!t.dataTransfer)return!1;if(s.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),n=0,r=()=>{++n==e.length&&Ec(s,t,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<e.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(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Ec(s,t,i,!0),!0}return!1};le.paste=(s,t)=>{if(s.state.readOnly)return!0;s.observer.flush();let e=Sp?null:t.clipboardData;return e?(vp(s,e.getData("text/plain")||e.getData("text/uri-list")),!0):(Qy(s),!1)};function n1(s,t){let e=s.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function s1(s){let t=[],e=[],i=!1;for(let n of s.selection.ranges)n.empty||(t.push(s.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:t.join(s.lineBreak),ranges:e,linewise:i}}let Il=null;le.copy=le.cut=(s,t)=>{let{text:e,ranges:i,linewise:n}=s1(s.state);if(!e&&!n)return!1;Il=n?e:null,t.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Sp?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(n1(s,e),!1)};const Mp=Vt.define();function Ap(s,t){let e=[];for(let i of s.facet(op)){let n=i(s,t);n&&e.push(n)}return e?s.update({effects:e,annotations:Mp.of(!0)}):null}function Dp(s){setTimeout(()=>{let t=s.hasFocus;if(t!=s.inputState.notifiedFocused){let e=Ap(s.state,t);e?s.dispatch(e):s.update([])}},10)}Ut.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),Dp(s)};Ut.blur=s=>{s.observer.clearSelectionRange(),Dp(s)};Ut.compositionstart=Ut.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};Ut.compositionend=s=>{s.observer.editContext||(s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,A.chrome&&A.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};Ut.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};le.beforeinput=(s,t)=>{var e;let i;if(A.chrome&&A.android&&(i=wp.find(n=>n.inputType==t.inputType))&&(s.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let n=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>n+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return A.ios&&t.inputType=="deleteContentForward"&&s.observer.flushSoon(),A.safari&&t.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>Ut.compositionend(s,t),20),!1};const Rc=new Set;function r1(s){Rc.has(s)||(Rc.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const Lc=["pre-wrap","normal","pre-line","break-spaces"];let o1=class{constructor(t){this.lineWrapping=t,this.doc=B.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Lc.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let n=t[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(e=!0,this.heightSamples[Math.floor(n*10)]=!0)}return e}refresh(t,e,i,n,r,o){let l=Lc.indexOf(t)>-1,a=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}},l1=class{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}},We=class Op{constructor(t,e,i,n,r){this.from=t,this.length=e,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?kt.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 Gi?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new Op(this.from,this.length+t.length,this.top,this.height+t.height,e)}};var X=function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s}(X||(X={}));const pr=.001;let re=class gr{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>pr&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return gr.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:f}=n[l],u=r.lineAt(a,X.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=c?u:r.lineAt(c,X.ByPosNoHeight,i,0,0);for(f+=d.to-c,c=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,h=n[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,X.ByPosNoHeight,i,0,0));h+=u.from-a,a=u.from;let p=c1.build(i.setDoc(o),t,h,f);r=r.replace(a,c,p)}return r.updateHeight(i,0)}static empty(){return new me(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,n=0,r=0;for(;;)if(e==i)if(n>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=t[e++];l&&(n+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new a1(gr.of(t.slice(0,e)),o,gr.of(t.slice(i)))}};re.prototype.size=1;let Tp=class extends re{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,n){return new We(n,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,n,r){return this.blockAt(0,i,n,r)}forEachLine(t,e,i,n,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,n,r))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(t,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},me=class Vl extends Tp{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new We(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return i.length==1&&(n instanceof Vl||n instanceof Ni&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Ni?n=new Vl(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):re.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(t,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Ni=class ie extends re{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,r=n-i+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.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:n,perLine:o,perChar:l}}blockAt(t,e,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,n);if(e.lineWrapping){let c=n+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),h=e.doc.lineAt(c),f=l+h.length*a,u=Math.max(i,t-f/2);return new We(h.from,h.length,u,f,0)}else{let c=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:h,length:f}=e.doc.line(r+c);return new We(h,f,i+l*c,l,0)}}lineAt(t,e,i,n,r){if(e==X.ByHeight)return this.blockAt(t,i,n,r);if(e==X.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new We(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),c=i.doc.lineAt(t),h=l+c.length*a,f=c.number-o,u=n+l*f+a*(c.from-r-f);return new We(c.from,c.length,Math.max(n,Math.min(u,n+this.height-h)),h,0)}forEachLine(t,e,i,n,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,r);for(let h=t,f=n;h<=e;){let u=i.doc.lineAt(h);if(h==t){let p=u.number-l;f+=a*p+c*(t-r-p)}let d=a+c*u.length;o(new We(u.from,u.length,f,d,0)),f+=d,h=u.to+1}}replace(t,e,i){let n=this.length-e;if(n>0){let r=i[i.length-1];r instanceof ie?i[i.length-1]=new ie(r.length+n):i.push(null,new ie(n-1))}if(t>0){let r=i[0];r instanceof ie?i[0]=new ie(t+r.length):i.unshift(new ie(t-1),null)}return re.of(i)}decomposeLeft(t,e){e.push(new ie(t-1),null)}decomposeRight(t,e){e.push(null,new ie(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let r=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),a=-1;for(n.from>e&&o.push(new ie(n.from-e-1).updateHeight(t,e));l<=r&&n.more;){let h=t.doc.lineAt(l).length;o.length&&o.push(null);let f=n.heights[n.index++];a==-1?a=f:Math.abs(f-a)>=pr&&(a=-2);let u=new me(h,f);u.outdated=!1,o.push(u),l+=h+1}l<=r&&o.push(null,new ie(r-l).updateHeight(t,l));let c=re.of(o);return(a<0||Math.abs(c.height-this.height)>=pr||Math.abs(a-this.heightMetrics(t,e).perLine)>=pr)&&(t.heightChanged=!0),c}else(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},a1=class extends re{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,n){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,n):this.right.blockAt(t,e,r,n+this.left.length+this.break)}lineAt(t,e,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,a=e==X.ByHeight?t<o:t<l,c=a?this.left.lineAt(t,e,i,n,r):this.right.lineAt(t,e,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=e==X.ByPosNoHeight?X.ByPosNoHeight:X.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,n,r).join(c)}forEachLine(t,e,i,n,r,o){let l=n+this.left.height,a=r+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,n,r,o),e>=a&&this.right.forEachLine(t,e,i,l,a,o);else{let c=this.lineAt(a,X.ByPos,i,n,r);t<c.from&&this.left.forEachLine(t,c.from-1,i,n,r,o),c.to>=t&&c.from<=e&&o(c),e>c.to&&this.right.forEachLine(c.to+1,e,i,l,a,o)}}replace(t,e,i){let n=this.left.length+this.break;if(e<n)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&Pc(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),Pc(r,l)}return re.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<n&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?re.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:r,right:o}=this,l=e+r.length+this.break,a=null;return n&&n.from<=e+r.length&&n.more?a=r=r.updateHeight(t,e,i,n):r.updateHeight(t,e,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(t,l,i,n):o.updateHeight(t,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 Pc(s,t){let e,i;s[t]==null&&(e=s[t-1])instanceof Ni&&(i=s[t+1])instanceof Ni&&s.splice(t-1,3,new Ni(e.length+1+i.length))}const h1=5;let c1=class Bp{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof me?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new me(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new Tp(o,n,i)):(o||r||n>=h1)&&this.addLineDeco(n,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new me(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Ni(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof me)return t;let e=new me(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof me)&&!this.isCovered?this.nodes.push(new me(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let n of this.nodes)n instanceof me&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(t,e,i,n){let r=new Bp(i,t);return E.spans(e,i,n,r,0),r.finish(i)}};function f1(s,t,e){let i=new u1;return E.compare(s,t,e,i,0),i.changes}let u1=class{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,n){(t<e||i&&i.heightRelevant||n&&n.heightRelevant)&&Bl(t,e,this.changes,5)}};function d1(s,t){let e=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(n.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(n.innerHeight,e.bottom);for(let c=s.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,f=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&f.overflow!="visible"){let u=h.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=c==s.parentNode?u.bottom:Math.min(a,u.bottom)}c=f.position=="absolute"||f.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function p1(s,t){let e=s.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}let Bo=class{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let n=t[i],r=e[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(t,e){return P.replace({widget:new g1(this.size*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}},g1=class extends Oe{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}},$c=class{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Nc,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Q.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(dh).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new o1(e),this.stateDeco=t.facet(Jn).filter(i=>typeof i!="function"),this.heightMap=re.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle.setDoc(t.doc),[new Qe(0,0,0,t.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=P.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);t.push(new Ts(r,o))}}return this.viewports=t.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Nc:new y1(this.heightOracle,this.heightMap,this.viewports),t.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,t=>{this.viewportLines.push(kn(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Jn).filter(h=>typeof h!="function");let n=t.changedRanges,r=Qe.extendWithRanges(n,f1(i,this.stateDeco,t?t.changes:et.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(c||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(ap)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Q.RTL:Q.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,h=0;if(l.width&&l.height){let{scaleX:x,scaleY:k}=Ed(e,l);(x>.005&&Math.abs(this.scaleX-x)>.005||k>.005&&Math.abs(this.scaleY-k)>.005)&&(this.scaleX=x,this.scaleY=k,c|=8,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,c|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,c|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Pd(t.scrollDOM);let p=(this.printing?p1:d1)(e,this.paddingTop),g=p.top-this.pixelViewport.top,b=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let m=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(m!=this.inView&&(this.inView=m,m&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let y=l.width;if((this.contentDOMWidth!=y||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,c|=8),a){let x=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(x)&&(o=!0),o||n.lineWrapping&&Math.abs(y-this.contentDOMWidth)>n.charWidth){let{lineHeight:k,charWidth:M,textHeight:N}=t.docView.measureTextSize();o=k>0&&n.refresh(r,k,M,N,y/M,x),o&&(t.docView.minWidth=0,c|=8)}g>0&&b>0?h=Math.max(g,b):g<0&&b<0&&(h=Math.min(g,b)),n.heightChanged=!1;for(let k of this.viewports){let M=k.from==this.viewport.from?x:t.docView.measureVisibleLineHeights(k);this.heightMap=(o?re.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle,[new Qe(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new l1(k.from,M))}n.heightChanged&&(c|=2)}let S=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Ts(n.lineAt(o-i*1e3,X.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,X.ByHeight,r,0,0).to);if(e){let{head:c}=e.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=n.lineAt(c,X.ByPos,r,0,0),u;e.y=="center"?u=(f.top+f.bottom)/2-h/2:e.y=="start"||e.y=="nearest"&&c<a.from?u=f.top:u=f.bottom-h,a=new Ts(n.lineAt(u-1e3/2,X.ByHeight,r,0,0).from,n.lineAt(u+h+1e3/2,X.ByHeight,r,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),n=e.mapPos(t.to,1);return new Ts(this.heightMap.lineAt(i,X.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,X.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(t,X.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,X.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||n<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let n of t)e.touchesRange(n.from,n.to)||i.push(new Bo(e.mapPos(n.from),e.mapPos(n.to),n.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=Q.LTR&&!i)return[];let l=[],a=(h,f,u,d)=>{if(f-h<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let m of g)if(m>h&&m<f){a(h,m-10,u,d),a(m+10,f,u,d);return}let b=b1(t,m=>m.from>=u.from&&m.to<=u.to&&Math.abs(m.from-h)<r&&Math.abs(m.to-f)<r&&!g.some(y=>m.from<y&&m.to>y));if(!b){if(f<u.to&&e&&i&&e.visibleRanges.some(m=>m.from<=f&&m.to>=f)){let m=e.moveToLineBoundary(w.cursor(f),!1,!0).head;m>h&&(f=m)}b=new Bo(h,f,this.gapSize(u,h,f,d))}l.push(b)},c=h=>{if(h.length<o||h.type!=kt.Text)return;let f=m1(h.from,h.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,m;if(u!=null){let y=Es(f,u),S=((this.visibleBottom-this.visibleTop)/2+g)/h.height;b=y-S,m=y+S}else b=(this.visibleTop-h.top-g)/h.height,m=(this.visibleBottom-h.top+g)/h.height;d=Bs(f,b),p=Bs(f,m)}else{let g=f.total*this.heightOracle.charWidth,b=n*this.heightOracle.charWidth,m,y;if(u!=null){let S=Es(f,u),x=((this.pixelViewport.right-this.pixelViewport.left)/2+b)/g;m=S-x,y=S+x}else m=(this.pixelViewport.left-b)/g,y=(this.pixelViewport.right+b)/g;d=Bs(f,m),p=Bs(f,y)}d>h.from&&a(h.from,d,h,f),p<h.to&&a(p,h.to,h,f)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(t,e,i,n){let r=Es(n,i)-Es(n,e);return this.heightOracle.lineWrapping?t.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(t){Bo.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=P.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];E.spans(t,this.viewport.from,this.viewport.to,{span(n,r){e.push({from:n,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((n,r)=>n.from!=e[r].from||n.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||kn(this.heightMap.lineAt(t,X.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||kn(this.heightMap.lineAt(this.scaler.fromDOM(t),X.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return kn(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Ts=class{constructor(t,e){this.from=t,this.to=e}};function m1(s,t,e){let i=[],n=s,r=0;return E.spans(e,s,t,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<t&&(i.push({from:n,to:t}),r+=t-n),{total:r,ranges:i}}function Bs({total:s,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(s*e);for(let n=0;;n++){let{from:r,to:o}=t[n],l=o-r;if(i<=l)return r+i;i-=l}}function Es(s,t){let e=0;for(let{from:i,to:n}of s.ranges){if(t<=n){e+=t-i;break}e+=n-i}return e/s.total}function b1(s,t){for(let e of s)if(t(e))return e}const Nc={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};let y1=class Ep{constructor(t,e,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=e.lineAt(l,X.ByPos,t,0,0).top,h=e.lineAt(a,X.ByPos,t,0,0).bottom;return n+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);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(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return n+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,n=r.domBottom}}fromDOM(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-n)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,n=r.domBottom}}eq(t){return t instanceof Ep?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}};function kn(s,t){if(t.scale==1)return s;let e=t.toDOM(s.top),i=t.toDOM(s.bottom);return new We(s.from,s.length,e,i-e,Array.isArray(s._content)?s._content.map(n=>kn(n,t)):s._content)}const Rs=v.define({combine:s=>s.join(" ")}),Wl=v.define({combine:s=>s.indexOf(!0)>-1}),zl=lt.newName(),Rp=lt.newName(),Lp=lt.newName(),Pp={"&light":"."+Rp,"&dark":"."+Lp};function Kl(s,t,e){return new lt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):s+" "+i}})}const w1=Kl("."+zl,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<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"}},Pp),Cn="￿";let x1=class{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet($.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Cn}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==e)break;let l=Z.get(n),a=Z.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:Rr(n))||Rr(o)&&(n.nodeName!="BR"||n.cmIgnore)&&this.text.length>r)&&this.lineBreak(),n=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=Z.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(S1(t,i.node,i.offset)?e:0))}};function S1(s,t,e){for(;;){if(!t||e<$e(t))return!1;if(t==s)return!0;e=pi(t)+1,t=t.parentNode}}let Hc=class{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}},v1=class{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:M1(t),a=new x1(l,t.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=A1(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!yl(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!yl(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=t.viewport;if((A.ios||A.chrome)&&t.state.selection.main.empty&&a!=c&&(h.from>0||h.to<t.state.doc.length)){let f=Math.min(a,c),u=Math.max(a,c),d=h.from-f,p=h.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==t.state.doc.length)&&(a=0,c=t.state.doc.length)}this.newSel=w.single(c,a)}}};function $p(s,t){let e,{newSel:i}=t,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,a=n.from,c=null;(r===8||A.android&&t.text.length<l-o)&&(a=n.to,c="end");let h=C1(s.state.doc.sliceString(o,l,Cn),t.text,a-o,c);h&&(A.chrome&&r==13&&h.toB==h.from+2&&t.text.slice(h.from,h.toB)==Cn+Cn&&h.toB--,e={from:o+h.from,to:o+h.toA,insert:B.of(t.text.slice(h.from,h.toB).split(Cn))})}else i&&(!s.hasFocus&&s.state.facet(Ve)||i.main.eq(n))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!n.empty&&i&&i.main.empty?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,n.to)}:e&&e.from>=n.from&&e.to<=n.to&&(e.from!=n.from||e.to!=n.to)&&n.to-n.from-(e.to-e.from)<=4?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,e.from).append(e.insert).append(s.state.doc.slice(e.to,n.to))}:(A.mac||A.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:B.of([" "])}):A.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`
7
- `&&s.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:B.of([" "])}),e)return Np(s,e,i,r);if(i&&!i.main.eq(n)){let o=!1,l="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(o=!0),l=s.inputState.lastSelectionOrigin),s.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Np(s,t,e,i=-1){if(A.ios&&s.inputState.flushIOSKey(t))return!0;let n=s.state.selection.main;if(A.android&&(t.to==n.to&&(t.from==n.from||t.from==n.from-1&&s.state.sliceDoc(t.from,n.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&$i(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>n.head)&&$i(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&$i(s.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=k1(s,t,e));return s.state.facet(rp).some(a=>a(s,t.from,t.to,r,l))||s.dispatch(l()),!0}function k1(s,t,e){let i,n=s.state,r=n.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&s.inputState.composing<0){let l=r.from<t.from?n.sliceDoc(r.from,t.from):"",a=r.to>t.to?n.sliceDoc(t.to,r.to):"";i=n.replaceSelection(s.state.toText(l+t.insert.sliceString(0,void 0,s.state.lineBreak)+a))}else{let l=n.changes(t),a=e&&e.main.to<=l.newLength?e.main:void 0;if(n.selection.ranges.length>1&&s.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let c=s.state.sliceDoc(t.from,t.to),h,f=e&&bp(s,e.main.head);if(f){let p=t.insert.length-(t.to-t.from);h={from:f.from,to:f.to-p}}else h=s.state.doc.lineAt(r.head);let u=r.to-t.to,d=r.to-r.from;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let g=p.to-u,b=g-c.length;if(p.to-p.from!=d||s.state.sliceDoc(b,g)!=c||p.to>=h.from&&p.from<=h.to)return{range:p};let m=n.changes({from:b,to:g,insert:t.insert}),y=p.to-r.to;return{changes:m,range:a?w.range(Math.max(0,a.anchor+y),Math.max(0,a.head+y)):p.map(m)}})}else i={changes:l,selection:a&&n.selection.replaceRange(a)}}let o="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,o+=".compose",s.inputState.compositionFirstChange&&(o+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:o,scrollIntoView:!0})}function C1(s,t,e,i){let n=Math.min(s.length,t.length),r=0;for(;r<n&&s.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==n&&s.length==t.length)return null;let o=s.length,l=t.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));e-=o+a-r}if(o<r&&s.length<t.length){let a=e<=r&&e>=o?r-e:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=e<=r&&e>=l?r-e:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function M1(s){let t=[];if(s.root.activeElement!=s.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return e&&(t.push(new Hc(e,i)),(n!=e||r!=i)&&t.push(new Hc(n,r))),t}function A1(s,t){if(s.length==0)return null;let e=s[0].pos,i=s.length==2?s[1].pos:e;return e>-1&&i>-1?w.single(e+t,i+t):null}const D1={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Eo=A.ie&&A.ie_version<=11;let O1=class{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new cy,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=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(A.ie&&A.ie_version<=11||A.ios&&t.composing)&&e.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.constructor.EDIT_CONTEXT!==!1&&!(A.chrome&&A.chrome_version<126)&&(this.editContext=new B1(t),t.state.facet(Ve)&&(t.contentDOM.editContext=this.editContext.editContext)),Eo&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){t.type=="change"&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Ve)?i.root.activeElement!=this.dom:!cr(i.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(A.ie&&A.ie_version<=11||A.android&&A.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Fn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=_n(t.root);if(!e)return!1;let i=A.safari&&t.root.nodeType==11&&oy(this.dom.ownerDocument)==this.dom&&T1(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=cr(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&uy(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,D1),Eo&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Eo&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&$i(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,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 t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&cr(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new v1(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=$p(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=Fc(e,t.previousSibling||t.target.previousSibling,-1),n=Fc(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Ve)!=t.state.facet(Ve)&&(t.view.contentDOM.editContext=t.state.facet(Ve)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function Fc(s,t,e){for(;t;){let i=Z.get(t);if(i&&i.parent==s)return i;let n=t.parentNode;t=n!=s.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function Ic(s,t){let e=t.startContainer,i=t.startOffset,n=t.endContainer,r=t.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor);return Fn(o.node,o.offset,n,r)&&([e,i,n,r]=[n,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}}function T1(s,t){if(t.getComposedRanges){let n=t.getComposedRanges(s.root)[0];if(n)return Ic(s,n)}let e=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),e=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),e?Ic(s,e):null}let B1=class{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:n}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:B.of(i.text.split(`
8
- `))};r.from==this.from&&n<this.from?r.from=n:r.to==this.to&&n>this.to&&(r.to=n),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,Np(t,r,w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&this.revertPending(t.state))},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=t.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,n.push(r)}e.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;n.push(P.mark({attributes:{style:a}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:cp.of(P.set(n))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=_n(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((r,o,l,a,c)=>{if(i)return;let h=c.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(c)){n=this.pendingContextChange=null,e+=h,this.to+=h;return}else n=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=h,this.to+=h;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),c.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.to+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}},T=class ql{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(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),t.parent&&t.parent.appendChild(this.dom);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(i=>i.forEach(n=>e(n,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||fy(t.parent)||document,this.viewState=new $c(t.state||$.create(t)),t.scrollTo&&t.scrollTo.is(As)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Sn).map(i=>new Do(i));for(let i of this.plugins)i.update(this);this.observer=new O1(this),this.inputState=new Ky(this),this.inputState.ensureHandlers(this.plugins),this.docView=new bc(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=t.length==1&&t[0]instanceof it?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,n,r=this.state;for(let u of t){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;t.some(u=>u.annotation(Mp))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Ap(r,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(h=null)):this.observer.clear(),r.facet($.phrases)!=this.state.facet($.phrases))return this.setState(r);n=mc.create(this,r,t),n.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new Ao(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(As)&&(f=d.value.clip(this.state))}this.viewState.update(n,f),this.bidiCache=Wc.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(vn)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Rs)!=n.state.facet(Rs)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Pl))try{u(n)}catch(d){xt(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!$p(this,h)&&c.force&&$i(this.contentDOM,c.key,c.keyCode)})}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new $c(t),this.plugins=t.facet(Sn).map(i=>new Do(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new bc(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Sn),i=t.state.facet(Sn);if(e!=i){let n=[];for(let r of i){let o=e.indexOf(r);if(o<0)n.push(new Do(r));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){xt(this.state,i,"doc view update listener")}}}measure(t=!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,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Pd(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);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 c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return xt(this.state,p),Vc}}),f=mc.create(this,this.state,[]),u=!1;f.flags|=a,e?e.flags|=a:e=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<c.length;d++)if(h[d]!=Vc)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){xt(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){n=n+p,i.scrollTop=n/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Pl))l(e)}get themeClasses(){return zl+" "+(this.state.facet(Wl)?Lp:Rp)+" "+this.state.facet(Rs)}updateAttrs(){let t=zc(this,fp,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Ve)?"true":"false",class:"cm-content",style:`${A.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),zc(this,dh,e);let i=this.observer.ignore(()=>{let n=Tl(this.contentDOM,this.contentAttrs,e),r=Tl(this.dom,this.editorAttrs,t);return n||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let n of i.effects)if(n.is(ql.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(vn);let t=this.state.facet(ql.cspNonce);lt.mount(this.root,this.styleModules.concat(w1).reverse(),t?{nonce:t}: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(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.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(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return To(this,t,kc(this,t,e,i))}moveByGroup(t,e){return To(this,t,kc(this,t,e,i=>Wy(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return w.cursor(r.side(e,n)+t.from,r.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return Vy(this,t,e,i)}moveVertically(t,e,i){return To(this,t,zy(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),yp(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(t),r=this.bidiSpans(n),o=r[Xe.find(r,t-n.from,-1,e)];return so(i,o.dir==Q.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(lp)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>E1)return Zd(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||Qd(r.isolates,i=gc(this,t))))return r.order;i||(i=gc(this,t));let n=Cy(t.text,e,i);return this.bidiCache.push(new Wc(t.from,t.to,e,i,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||A.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Rd(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.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(t,e={}){return As.of(new Ao(typeof t=="number"?w.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return As.of(new Ao(w.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return pt.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return pt.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=lt.newName(),n=[Rs.of(i),vn.of(Kl(`.${i}`,t))];return e&&e.dark&&n.push(Wl.of(!0)),n}static baseTheme(t){return _t.lowest(vn.of(Kl("."+zl,t,Pp)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&Z.get(i)||Z.get(t);return((e=n==null?void 0:n.rootView)===null||e===void 0?void 0:e.view)||null}};T.styleModule=vn;T.inputHandler=rp;T.scrollHandler=hp;T.focusChangeEffect=op;T.perLineTextDirection=lp;T.exceptionSink=sp;T.updateListener=Pl;T.editable=Ve;T.mouseSelectionStyle=np;T.dragMovesSelection=ip;T.clickAddsSelectionRange=ep;T.decorations=Jn;T.outerDecorations=up;T.atomicRanges=ph;T.bidiIsolatedRanges=dp;T.scrollMargins=pp;T.darkTheme=Wl;T.cspNonce=v.define({combine:s=>s.length?s[0]:""});T.contentAttributes=dh;T.editorAttributes=fp;T.lineWrapping=T.contentAttributes.of({class:"cm-lineWrapping"});T.announce=R.define();const E1=4096,Vc={};let Wc=class Hp{constructor(t,e,i,n,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:Q.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==n&&!e.touchesRange(o.from,o.to)&&i.push(new Hp(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}};function zc(s,t,e){for(let i=s.state.facet(t),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Ol(o,e)}return e}const R1=A.mac?"mac":A.windows?"win":A.linux?"linux":"key";function L1(s,t){const e=s.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;a<e.length-1;++a){const c=e[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))n=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Ls(s,t,e){return t.altKey&&(s="Alt-"+s),t.ctrlKey&&(s="Ctrl-"+s),t.metaKey&&(s="Meta-"+s),e!==!1&&t.shiftKey&&(s="Shift-"+s),s}const P1=_t.default(T.domEventHandlers({keydown(s,t){return F1($1(t.state),s,t,"editor")}})),ps=v.define({enables:P1}),Kc=new WeakMap;function $1(s){let t=s.facet(ps),e=Kc.get(t);return e||Kc.set(t,e=H1(t.reduce((i,n)=>i.concat(n),[]))),e}let ze=null;const N1=4e3;function H1(s,t=R1){let e=Object.create(null),i=Object.create(null),n=(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,c,h)=>{var f,u;let d=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(m=>L1(m,t));for(let m=1;m<p.length;m++){let y=p.slice(0,m).join(" ");n(y,!0),d[y]||(d[y]={preventDefault:!0,stopPropagation:!1,run:[S=>{let x=ze={view:S,prefix:y,scope:o};return setTimeout(()=>{ze==x&&(ze=null)},N1),!0}]})}let g=p.join(" ");n(g,!1);let b=d[g]||(d[g]={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&&b.run.push(a),c&&(b.preventDefault=!0),h&&(b.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=e[c]||(e[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in h)h[u].run.push(d=>f(d,jl))}let a=o[t]||o.key;if(a)for(let c of l)r(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return e}let jl=null;function F1(s,t,e,i){jl=t;let n=Za(t),r=ht(n,0),o=Rt(r)==n.length&&n!=" ",l="",a=!1,c=!1,h=!1;ze&&ze.view==e&&ze.scope==i&&(l=ze.prefix+" ",xp.indexOf(t.keyCode)<0&&(c=!0,ze=null));let f=new Set,u=b=>{if(b){for(let m of b.run)if(!f.has(m)&&(f.add(m),m(e)))return b.stopPropagation&&(h=!0),!0;b.preventDefault&&(b.stopPropagation&&(h=!0),c=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+Ls(n,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(A.windows&&t.ctrlKey&&t.altKey)&&(p=th[t.keyCode])&&p!=n?(u(d[l+Ls(p,t,!0)])||t.shiftKey&&(g=eh[t.keyCode])!=n&&g!=p&&u(d[l+Ls(g,t,!1)]))&&(a=!0):o&&t.shiftKey&&u(d[l+Ls(n,t,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),c&&(a=!0),a&&h&&t.stopPropagation(),jl=null,a}class gs{constructor(t,e,i,n,r){this.className=t,this.left=e,this.top=i,this.width=n,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let r=Fp(t);return[new gs(e,n.left-r.left,n.top-r.top,null,n.bottom-n.top)]}else return I1(t,e,i)}}function Fp(s){let t=s.scrollDOM.getBoundingClientRect();return{left:(s.textDirection==Q.LTR?t.left:t.right-s.scrollDOM.clientWidth*s.scaleX)-s.scrollDOM.scrollLeft*s.scaleX,top:t.top-s.scrollDOM.scrollTop*s.scaleY}}function qc(s,t,e,i){let n=s.coordsAtPos(t,e*2);if(!n)return i;let r=s.dom.getBoundingClientRect(),o=(n.top+n.bottom)/2,l=s.posAtCoords({x:r.left+1,y:o}),a=s.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 I1(s,t,e){if(e.to<=s.viewport.from||e.from>=s.viewport.to)return[];let i=Math.max(e.from,s.viewport.from),n=Math.min(e.to,s.viewport.to),r=s.textDirection==Q.LTR,o=s.contentDOM,l=o.getBoundingClientRect(),a=Fp(s),c=o.querySelector(".cm-line"),h=c&&window.getComputedStyle(c),f=l.left+(h?parseInt(h.paddingLeft)+Math.min(0,parseInt(h.textIndent)):0),u=l.right-(h?parseInt(h.paddingRight):0),d=Fl(s,i),p=Fl(s,n),g=d.type==kt.Text?d:null,b=p.type==kt.Text?p:null;if(g&&(s.lineWrapping||d.widgetLineBreaks)&&(g=qc(s,i,1,g)),b&&(s.lineWrapping||p.widgetLineBreaks)&&(b=qc(s,n,-1,b)),g&&b&&g.from==b.from&&g.to==b.to)return y(S(e.from,e.to,g));{let k=g?S(e.from,null,g):x(d,!1),M=b?S(null,e.to,b):x(p,!0),N=[];return(g||d).to<(b||p).from-(g&&b?1:0)||d.widgetLineBreaks>1&&k.bottom+s.defaultLineHeight/2<M.top?N.push(m(f,k.bottom,u,M.top)):k.bottom<M.top&&s.elementAtHeight((k.bottom+M.top)/2).type==kt.Text&&(k.bottom=M.top=(k.bottom+M.top)/2),y(k).concat(N).concat(y(M))}function m(k,M,N,nt){return new gs(t,k-a.left,M-a.top-.01,N-k,nt-M+.01)}function y({top:k,bottom:M,horizontal:N}){let nt=[];for(let W=0;W<N.length;W+=2)nt.push(m(N[W],k,N[W+1],M));return nt}function S(k,M,N){let nt=1e9,W=-1e9,Mt=[];function Be(Zt,ue,Wt,at,te){let At=s.coordsAtPos(Zt,Zt==N.to?-2:2),ee=s.coordsAtPos(Wt,Wt==N.from?2:-2);!At||!ee||(nt=Math.min(At.top,ee.top,nt),W=Math.max(At.bottom,ee.bottom,W),te==Q.LTR?Mt.push(r&&ue?f:At.left,r&&at?u:ee.right):Mt.push(!r&&at?f:ee.left,!r&&ue?u:At.right))}let Qt=k??N.from,Ie=M??N.to;for(let Zt of s.visibleRanges)if(Zt.to>Qt&&Zt.from<Ie)for(let ue=Math.max(Zt.from,Qt),Wt=Math.min(Zt.to,Ie);;){let at=s.state.doc.lineAt(ue);for(let te of s.bidiSpans(at)){let At=te.from+at.from,ee=te.to+at.from;if(At>=Wt)break;ee>ue&&Be(Math.max(At,ue),k==null&&At<=Qt,Math.min(ee,Wt),M==null&&ee>=Ie,te.dir)}if(ue=at.to+1,ue>=Wt)break}return Mt.length==0&&Be(Qt,k==null,Ie,M==null,s.textDirection),{top:nt,bottom:W,horizontal:Mt}}function x(k,M){let N=l.top+(M?k.top:k.bottom);return{top:N,bottom:N,horizontal:[]}}}function V1(s,t){return s.constructor==t.constructor&&s.eq(t)}class W1{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(mr)!=t.state.facet(mr)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(mr);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;(t!=this.scaleX||e!=this.scaleY)&&(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!V1(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let n=e.nextSibling;e.remove(),e=n}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const mr=v.define();function Ip(s){return[pt.define(t=>new W1(t,s)),mr.of(s)]}const Vp=!A.ios,Qn=v.define({combine(s){return De(s,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function z1(s={}){return[Qn.of(s),K1,q1,j1,ap.of(!0)]}function Wp(s){return s.startState.facet(Qn)!=s.state.facet(Qn)}const K1=Ip({above:!0,markers(s){let{state:t}=s,e=t.facet(Qn),i=[];for(let n of t.selection.ranges){let r=n==t.selection.main;if(n.empty?!r||Vp:e.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=n.empty?n:w.cursor(n.head,n.head>n.anchor?-1:1);for(let a of gs.forRange(s,o,l))i.push(a)}}return i},update(s,t){s.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=Wp(s);return e&&jc(s.state,t),s.docChanged||s.selectionSet||e},mount(s,t){jc(t.state,s)},class:"cm-cursorLayer"});function jc(s,t){t.style.animationDuration=s.facet(Qn).cursorBlinkRate+"ms"}const q1=Ip({above:!1,markers(s){return s.state.selection.ranges.map(t=>t.empty?[]:gs.forRange(s,"cm-selectionBackground",t)).reduce((t,e)=>t.concat(e))},update(s,t){return s.docChanged||s.selectionSet||s.viewportChanged||Wp(s)},class:"cm-selectionLayer"}),Gl={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};Vp&&(Gl[".cm-line"].caretColor=Gl[".cm-content"].caretColor="transparent !important");const j1=_t.highest(T.theme(Gl)),zp=R.define({map(s,t){return s==null?null:t.mapPos(s)}}),Mn=ct.define({create(){return null},update(s,t){return s!=null&&(s=t.changes.mapPos(s)),t.effects.reduce((e,i)=>i.is(zp)?i.value:e,s)}}),G1=pt.fromClass(class{constructor(s){this.view=s,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(s){var t;let e=s.state.field(Mn);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(s.startState.field(Mn)!=e||s.docChanged||s.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:s}=this,t=s.state.field(Mn),e=t!=null&&s.coordsAtPos(t);if(!e)return null;let i=s.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+s.scrollDOM.scrollLeft*s.scaleX,top:e.top-i.top+s.scrollDOM.scrollTop*s.scaleY,height:e.bottom-e.top}}drawCursor(s){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;s?(this.cursor.style.left=s.left/t+"px",this.cursor.style.top=s.top/e+"px",this.cursor.style.height=s.height/e+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(s){this.view.state.field(Mn)!=s&&this.view.dispatch({effects:zp.of(s)})}},{eventObservers:{dragover(s){this.setDropPos(this.view.posAtCoords({x:s.clientX,y:s.clientY}))},dragleave(s){(s.target==this.view.contentDOM||!this.view.contentDOM.contains(s.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function U1(){return[Mn,G1]}function Gc(s,t,e,i,n){t.lastIndex=0;for(let r=s.iterRange(e,i),o=e,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=t.exec(r.value);)n(o+l.index,l)}function Y1(s,t){let e=s.visibleRanges;if(e.length==1&&e[0].from==s.viewport.from&&e[0].to==s.viewport.to)return e;let i=[];for(let{from:n,to:r}of e)n=Math.max(s.state.doc.lineAt(n).from,n-t),r=Math.min(s.state.doc.lineAt(r).to,r+t),i.length&&i[i.length-1].to>=n?i[i.length-1].to=r:i.push({from:n,to:r});return i}class X1{constructor(t){const{regexp:e,decoration:i,decorate:n,boundary:r,maxLength:o=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(l,a,c,h)=>n(h,c,c+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,c,h)=>{let f=i(l,a,c);f&&h(c,c+l[0].length,f)};else if(i)this.addMatch=(l,a,c,h)=>h(c,c+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(t){let e=new ii,i=e.add.bind(e);for(let{from:n,to:r}of Y1(t,this.maxLength))Gc(t.state.doc,this.regexp,n,r,(o,l)=>this.addMatch(l,t,o,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((r,o,l,a)=>{a>t.view.viewport.from&&l<t.view.viewport.to&&(i=Math.min(l,i),n=Math.max(a,n))}),t.viewportChanged||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let r of t.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,n);if(l>o){let a=t.state.doc.lineAt(o),c=a.to<l?t.state.doc.lineAt(l):a,h=Math.max(r.from,a.from),f=Math.min(r.to,c.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){h=o;break}for(;l<c.to;l++)if(this.boundary.test(c.text[l-c.from])){f=l;break}}let u=[],d,p=(g,b,m)=>u.push(m.range(g,b));if(a==c)for(this.regexp.lastIndex=h-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,t,d.index+a.from,p);else Gc(t.state.doc,this.regexp,h,f,(g,b)=>this.addMatch(b,t,g,p));e=e.update({filterFrom:h,filterTo:f,filter:(g,b)=>g<h||b>f,add:u})}}return e}}const Ul=/x/.unicode!=null?"gu":"g",_1=new RegExp(`[\0-\b
9
- --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Ul),J1={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Ro=null;function Q1(){var s;if(Ro==null&&typeof document<"u"&&document.body){let t=document.body.style;Ro=((s=t.tabSize)!==null&&s!==void 0?s:t.MozTabSize)!=null}return Ro||!1}const br=v.define({combine(s){let t=De(s,{render:null,specialChars:_1,addSpecialChars:null});return(t.replaceTabs=!Q1())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,Ul)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,Ul)),t}});function Z1(s={}){return[br.of(s),tw()]}let Uc=null;function tw(){return Uc||(Uc=pt.fromClass(class{constructor(s){this.view=s,this.decorations=P.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(s.state.facet(br)),this.decorations=this.decorator.createDeco(s)}makeDecorator(s){return new X1({regexp:s.specialChars,decoration:(t,e,i)=>{let{doc:n}=e.state,r=ht(t[0],0);if(r==9){let o=n.lineAt(i),l=e.state.tabSize,a=ln(o.text,l,i-o.from);return P.replace({widget:new sw((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=P.replace({widget:new nw(s,r)}))},boundary:s.replaceTabs?void 0:/[^]/})}update(s){let t=s.state.facet(br);s.startState.facet(br)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(s.view)):this.decorations=this.decorator.updateDeco(s,this.decorations)}},{decorations:s=>s.decorations}))}const ew="•";function iw(s){return s>=32?ew:s==10?"␤":String.fromCharCode(9216+s)}class nw extends Oe{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=iw(this.code),i=t.state.phrase("Control character")+" "+(J1[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,e);if(n)return n;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class sw extends Oe{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function rw(){return lw}const ow=P.line({class:"cm-activeLine"}),lw=pt.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.docChanged||s.selectionSet)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let t=-1,e=[];for(let i of s.state.selection.ranges){let n=s.lineBlockAt(i.head);n.from>t&&(e.push(ow.range(n.from)),t=n.from)}return P.set(e)}},{decorations:s=>s.decorations});class aw extends Oe{constructor(t){super(),this.content=t}toDOM(){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?t.setAttribute("aria-label","placeholder "+this.content):t.setAttribute("aria-hidden","true"),t}coordsAt(t){let e=t.firstChild?qi(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),n=so(e[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return n.bottom-n.top>r*1.5?{left:n.left,right:n.right,top:n.top,bottom:n.top+r}:n}ignoreEvent(){return!1}}function hw(s){return pt.fromClass(class{constructor(t){this.view=t,this.placeholder=s?P.set([P.widget({widget:new aw(s),side:1}).range(0)]):P.none}get decorations(){return this.view.state.doc.length?P.none:this.placeholder}},{decorations:t=>t.decorations})}const Yl=2e3;function cw(s,t,e){let i=Math.min(t.line,e.line),n=Math.max(t.line,e.line),r=[];if(t.off>Yl||e.off>Yl||t.col<0||e.col<0){let o=Math.min(t.off,e.off),l=Math.max(t.off,e.off);for(let a=i;a<=n;a++){let c=s.doc.line(a);c.length<=l&&r.push(w.range(c.from+o,c.to+l))}}else{let o=Math.min(t.col,e.col),l=Math.max(t.col,e.col);for(let a=i;a<=n;a++){let c=s.doc.line(a),h=Xn(c.text,o,s.tabSize,!0);if(h<0)r.push(w.cursor(c.to));else{let f=Xn(c.text,l,s.tabSize);r.push(w.range(c.from+h,c.from+f))}}}return r}function fw(s,t){let e=s.coordsAtPos(s.viewport.from);return e?Math.round(Math.abs((e.left-t)/s.defaultCharacterWidth)):-1}function Yc(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1),i=s.state.doc.lineAt(e),n=e-i.from,r=n>Yl?-1:n==i.length?fw(s,t.clientX):ln(i.text,s.state.tabSize,e-i.from);return{line:i.number,col:r,off:n}}function uw(s,t){let e=Yc(s,t),i=s.state.selection;return e?{update(n){if(n.docChanged){let r=n.changes.mapPos(n.startState.doc.line(e.line).from),o=n.state.doc.lineAt(r);e={line:o.number,col:e.col,off:Math.min(e.off,o.length)},i=i.map(n.changes)}},get(n,r,o){let l=Yc(s,n);if(!l)return i;let a=cw(s.state,e,l);return a.length?o?w.create(a.concat(i.ranges)):w.create(a):i}}:null}function dw(s){let t=e=>e.altKey&&e.button==0;return T.mouseSelectionStyle.of((e,i)=>t(i)?uw(e,i):null)}const pw={Alt:[18,s=>!!s.altKey],Control:[17,s=>!!s.ctrlKey],Shift:[16,s=>!!s.shiftKey],Meta:[91,s=>!!s.metaKey]},gw={style:"cursor: crosshair"};function mw(s={}){let[t,e]=pw[s.key||"Alt"],i=pt.fromClass(class{constructor(n){this.view=n,this.isDown=!1}set(n){this.isDown!=n&&(this.isDown=n,this.view.update([]))}},{eventObservers:{keydown(n){this.set(n.keyCode==t||e(n))},keyup(n){(n.keyCode==t||!e(n))&&this.set(!1)},mousemove(n){this.set(e(n))}}});return[i,T.contentAttributes.of(n=>{var r;return!((r=n.plugin(i))===null||r===void 0)&&r.isDown?gw:null})]}const gn="-10000px";class Kp{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(t,e){var i;let n=t.state.facet(this.facet),r=n.filter(a=>a);if(n===this.input){for(let a of this.tooltipViews)a.update&&a.update(t);return!1}let o=[],l=e?[]:null;for(let a=0;a<r.length;a++){let c=r[a],h=-1;if(c){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==c.create&&(h=f)}if(h<0)o[a]=this.createTooltipView(c,a?o[a-1]:null),l&&(l[a]=!!c.above);else{let f=o[a]=this.tooltipViews[h];l&&(l[a]=e[h]),f.update&&f.update(t)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return e&&(l.forEach((a,c)=>e[c]=a),e.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function bw(s){let{win:t}=s;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const Lo=v.define({combine:s=>{var t,e,i;return{position:A.ios?"absolute":((t=s.find(n=>n.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=s.find(n=>n.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||bw}}}),Xc=new WeakMap,gh=pt.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=s.state.facet(Lo);this.position=t.position,this.parent=t.parent,this.classes=s.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Kp(s,mh,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),s.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let s of this.manager.tooltipViews)this.intersectionObserver.observe(s.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(s){s.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(s,this.above);t&&this.observeIntersection();let e=t||s.geometryChanged,i=s.state.facet(Lo);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(s,t){let e=s.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),s.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let n=document.createElement("div");n.className="cm-tooltip-arrow",e.dom.appendChild(n)}return e.dom.style.position=this.position,e.dom.style.top=gn,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var s,t,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(s=i.destroy)===null||s===void 0||s.call(i);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=this.view.dom.getBoundingClientRect(),t=1,e=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:n}=this.manager.tooltipViews[0];if(A.gecko)i=n.offsetParent!=this.container.ownerDocument.body;else if(n.style.top==gn&&n.style.left=="0px"){let r=n.getBoundingClientRect();i=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}}if(i||this.position=="absolute")if(this.parent){let n=this.parent.getBoundingClientRect();n.width&&n.height&&(t=n.width/this.parent.offsetWidth,e=n.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);return{editor:s,parent:this.parent?this.container.getBoundingClientRect():s,pos:this.manager.tooltips.map((n,r)=>{let o=this.manager.tooltipViews[r];return o.getCoords?o.getCoords(n.pos):this.view.coordsAtPos(n.pos)}),size:this.manager.tooltipViews.map(({dom:n})=>n.getBoundingClientRect()),space:this.view.state.facet(Lo).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(s){var t;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:e,space:i,scaleX:n,scaleY:r}=s,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],c=this.manager.tooltipViews[l],{dom:h}=c,f=s.pos[l],u=s.size[l];if(!f||f.bottom<=Math.max(e.top,i.top)||f.top>=Math.min(e.bottom,i.bottom)||f.right<Math.max(e.left,i.left)-.1||f.left>Math.min(e.right,i.right)+.1){h.style.top=gn;continue}let d=a.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,b=(t=Xc.get(c))!==null&&t!==void 0?t:u.bottom-u.top,m=c.offset||ww,y=this.view.textDirection==Q.LTR,S=u.width>i.right-i.left?y?i.left:i.right-u.width:y?Math.min(f.left-(d?14:0)+m.x,i.right-g):Math.max(i.left,f.left-g+(d?14:0)-m.x),x=this.above[l];!a.strictSide&&(x?f.top-(u.bottom-u.top)-m.y<i.top:f.bottom+(u.bottom-u.top)+m.y>i.bottom)&&x==i.bottom-f.bottom>f.top-i.top&&(x=this.above[l]=!x);let k=(x?f.top-i.top:i.bottom-f.bottom)-p;if(k<b&&c.resize!==!1){if(k<this.view.defaultLineHeight){h.style.top=gn;continue}Xc.set(c,b),h.style.height=(b=k)/r+"px"}else h.style.height&&(h.style.height="");let M=x?f.top-b-p-m.y:f.bottom+p+m.y,N=S+g;if(c.overlap!==!0)for(let nt of o)nt.left<N&&nt.right>S&&nt.top<M+b&&nt.bottom>M&&(M=x?nt.top-b-2-p:nt.bottom+p+2);if(this.position=="absolute"?(h.style.top=(M-s.parent.top)/r+"px",h.style.left=(S-s.parent.left)/n+"px"):(h.style.top=M/r+"px",h.style.left=S/n+"px"),d){let nt=f.left+(y?m.x:-m.x)-(S+14-7);d.style.left=nt/n+"px"}c.overlap!==!0&&o.push({left:S,top:M,right:N,bottom:M+b}),h.classList.toggle("cm-tooltip-above",x),h.classList.toggle("cm-tooltip-below",!x),c.positioned&&c.positioned(s.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let s of this.manager.tooltipViews)s.dom.style.top=gn}},{eventObservers:{scroll(){this.maybeMeasure()}}}),yw=T.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),ww={x:0,y:0},mh=v.define({enables:[gh,yw]}),Pr=v.define({combine:s=>s.reduce((t,e)=>t.concat(e),[])});class oo{static create(t){return new oo(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Kp(t,Pr,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(n!==void 0){if(e===void 0)e=n;else if(e!==n)return}}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const xw=mh.compute([Pr],s=>{let t=s.facet(Pr);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:oo.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class Sw{constructor(t,e,i,n,r){this.view=t,this.source=e,this.field=i,this.setHover=n,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this,i=t.docView.nearest(e.target);if(!i)return;let n,r=1;if(i instanceof hh)n=i.posAtStart;else{if(n=t.posAtCoords(e),n==null)return;let l=t.coordsAtPos(n);if(!l||e.y<l.top||e.y>l.bottom||e.x<l.left-t.defaultCharacterWidth||e.x>l.right+t.defaultCharacterWidth)return;let a=t.bidiSpans(t.state.doc.lineAt(n)).find(h=>h.from<=n&&h.to>=n),c=a&&a.dir==Q.RTL?-1:1;r=e.x<l.left?-c:c}let o=this.source(t,n,r);if(o!=null&&o.then){let l=this.pending={pos:n};o.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>xt(t.state,a,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(gh),e=t?t.manager.tooltips.findIndex(i=>i.create==oo.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&r&&!vw(r.dom,t)||this.pending){let{pos:o}=n[0]||this.pending,l=(i=(e=n[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!kw(this.view,o,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Ps=4;function vw(s,t){let e=s.getBoundingClientRect();return t.clientX>=e.left-Ps&&t.clientX<=e.right+Ps&&t.clientY>=e.top-Ps&&t.clientY<=e.bottom+Ps}function kw(s,t,e,i,n,r){let o=s.scrollDOM.getBoundingClientRect(),l=s.documentTop+s.documentPadding.top+s.contentHeight;if(o.left>i||o.right<i||o.top>n||Math.min(o.bottom,l)<n)return!1;let a=s.posAtCoords({x:i,y:n},!1);return a>=t&&a<=e}function Cw(s,t={}){let e=R.define(),i=ct.define({create(){return[]},update(n,r){if(n.length&&(t.hideOnChange&&(r.docChanged||r.selection)?n=[]:t.hideOn&&(n=n.filter(o=>!t.hideOn(r,o))),r.docChanged)){let o=[];for(let l of n){let a=r.changes.mapPos(l.pos,-1,I.TrackDel);if(a!=null){let c=Object.assign(Object.create(null),l);c.pos=a,c.end!=null&&(c.end=r.changes.mapPos(c.end)),o.push(c)}}n=o}for(let o of r.effects)o.is(e)&&(n=o.value),o.is(Mw)&&(n=[]);return n},provide:n=>Pr.from(n)});return[i,pt.define(n=>new Sw(n,s,i,e,t.hoverTime||300)),xw]}function qp(s,t){let e=s.plugin(gh);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const Mw=R.define(),_c=v.define({combine(s){let t,e;for(let i of s)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function Aw(s,t){let e=s.plugin(jp),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const jp=pt.fromClass(class{constructor(s){this.input=s.state.facet(Xl),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(s));let t=s.state.facet(_c);this.top=new $s(s,!0,t.topContainer),this.bottom=new $s(s,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(s){let t=s.state.facet(_c);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new $s(s.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new $s(s.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=s.state.facet(Xl);if(e!=this.input){let i=e.filter(a=>a),n=[],r=[],o=[],l=[];for(let a of i){let c=this.specs.indexOf(a),h;c<0?(h=a(s.view),l.push(h)):(h=this.panels[c],h.update&&h.update(s)),n.push(h),(h.top?r:o).push(h)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>T.scrollMargins.of(t=>{let e=t.plugin(s);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});let $s=class{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Jc(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Jc(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}};function Jc(s){let t=s.nextSibling;return s.remove(),t}const Xl=v.define({enables:jp});let Ne=class extends Gt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}};Ne.prototype.elementClass="";Ne.prototype.toDOM=void 0;Ne.prototype.mapMode=I.TrackBefore;Ne.prototype.startSide=Ne.prototype.endSide=-1;Ne.prototype.point=!0;const yr=v.define(),Dw={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>E.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},Vn=v.define();function Ow(s){return[Gp(),Vn.of(Object.assign(Object.assign({},Dw),s))]}const Qc=v.define({combine:s=>s.some(t=>t)});function Gp(s){return[Tw]}const Tw=pt.fromClass(class{constructor(s){this.view=s,this.prevViewport=s.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=s.state.facet(Vn).map(t=>new tf(s,t));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!s.state.facet(Qc),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),s.scrollDOM.insertBefore(this.dom,s.contentDOM)}update(s){if(this.updateGutters(s)){let t=this.prevViewport,e=s.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}s.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(Qc)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=s.view.viewport}syncGutters(s){let t=this.dom.nextSibling;s&&this.dom.remove();let e=E.iter(this.view.state.facet(yr),this.view.viewport.from),i=[],n=this.gutters.map(r=>new Bw(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==kt.Text&&o){_l(e,i,l.from);for(let a of n)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of n)a.widget(this.view,l)}else if(r.type==kt.Text){_l(e,i,r.from);for(let o of n)o.line(this.view,r,i)}else if(r.widget)for(let o of n)o.widget(this.view,r);for(let r of n)r.finish();s&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(s){let t=s.startState.facet(Vn),e=s.state.facet(Vn),i=s.docChanged||s.heightChanged||s.viewportChanged||!E.eq(s.startState.facet(yr),s.state.facet(yr),s.view.viewport.from,s.view.viewport.to);if(t==e)for(let n of this.gutters)n.update(s)&&(i=!0);else{i=!0;let n=[];for(let r of e){let o=t.indexOf(r);o<0?n.push(new tf(this.view,r)):(this.gutters[o].update(s),n.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),n.indexOf(r)<0&&r.destroy();for(let r of n)this.dom.appendChild(r.dom);this.gutters=n}return i}destroy(){for(let s of this.gutters)s.destroy();this.dom.remove()}},{provide:s=>T.scrollMargins.of(t=>{let e=t.plugin(s);return!e||e.gutters.length==0||!e.fixed?null:t.textDirection==Q.LTR?{left:e.dom.offsetWidth*t.scaleX}:{right:e.dom.offsetWidth*t.scaleX}})});function Zc(s){return Array.isArray(s)?s:[s]}function _l(s,t,e){for(;s.value&&s.from<=e;)s.from==e&&t.push(s.value),s.next()}class Bw{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=E.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,r=(e.top-this.height)/t.scaleY,o=e.height/t.scaleY;if(this.i==n.elements.length){let l=new Up(t,o,r,i);n.elements.push(l),n.dom.appendChild(l.dom)}else n.elements[this.i].update(t,o,r,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];_l(this.cursor,n,e.from),i.length&&(n=n.concat(i));let r=this.gutter.config.lineMarker(t,e,n);r&&n.unshift(r);let o=this.gutter;n.length==0&&!o.config.renderEmptyElements||this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e);i&&this.addElement(t,e,[i])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class tf{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,n=>{let r=n.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=n.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[i](t,l,n)&&n.preventDefault()});this.markers=Zc(e.markers(t)),e.initialSpacer&&(this.spacer=new Up(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=Zc(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let n=this.config.updateSpacer(this.spacer.markers[0],t);n!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[n])}let i=t.view.viewport;return!E.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class Up{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),Ew(this.markers,n)||this.setMarkers(t,n)}setMarkers(t,e){let i="cm-gutterElement",n=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<e.length?e[r++]:null,c=!1;if(a){let h=a.elementClass;h&&(i+=" "+h);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,c=!0;break}}else l=this.markers.length;for(;o<l;){let h=this.markers[o++];if(h.toDOM){h.destroy(n);let f=n.nextSibling;n.remove(),n=f}}if(!a)break;a.toDOM&&(c?n=n.nextSibling:this.dom.insertBefore(a.toDOM(t),n)),c&&o++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}function Ew(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++)if(!s[e].compare(t[e]))return!1;return!0}const Rw=v.define(),Bi=v.define({combine(s){return De(s,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let n in e){let r=i[n],o=e[n];i[n]=r?(l,a,c)=>r(l,a,c)||o(l,a,c):o}return i}})}});class Po extends Ne{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function $o(s,t){return s.state.facet(Bi).formatNumber(t,s.state)}const Lw=Vn.compute([Bi],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(Rw)},lineMarker(t,e,i){return i.some(n=>n.toDOM)?null:new Po($o(t,t.state.doc.lineAt(e.from).number))},widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(Bi)!=t.state.facet(Bi),initialSpacer(t){return new Po($o(t,ef(t.state.doc.lines)))},updateSpacer(t,e){let i=$o(e.view,ef(e.view.state.doc.lines));return i==t.number?t:new Po(i)},domEventHandlers:s.facet(Bi).domEventHandlers}));function Pw(s={}){return[Bi.of(s),Gp(),Lw]}function ef(s){let t=9;for(;t<s;)t=t*10+9;return t}const $w=new class extends Ne{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Nw=yr.compute(["selection"],s=>{let t=[],e=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.head).from;n>e&&(e=n,t.push($w.range(n)))}return E.of(t)});function Hw(){return Nw}var No;const Ei=new jt;function Yp(s){return v.define({combine:s?t=>t.concat(s):void 0})}const bh=new jt;class se{constructor(t,e,i=[],n=""){this.data=t,this.name=n,$.prototype.hasOwnProperty("tree")||Object.defineProperty($.prototype,"tree",{get(){return rt(this)}}),this.parser=e,this.extension=[si.of(this),$.languageData.of((r,o,l)=>{let a=nf(r,o,l),c=a.type.prop(Ei);if(!c)return[];let h=r.facet(c),f=a.type.prop(bh);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(h)}}return h})].concat(i)}isActiveAt(t,e,i=-1){return nf(t,e,i).type.prop(Ei)==this.data}findRegions(t){let e=t.facet(si);if((e==null?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(Ei)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(jt.mounted);if(l){if(l.tree.prop(Ei)==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(n(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let c=r.children[a];c instanceof Ti&&n(c,r.positions[a]+o)}};return n(rt(t),0),i}get allowsNesting(){return!0}}se.setState=R.define();function nf(s,t,e){let i=s.facet(si),n=rt(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(t,e,nh.ExcludeBuffers))r.type.isTop&&(n=r);return n}class Yi extends se{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=Yp(t.languageData);return new Yi(e,t.parser.configure({props:[Ei.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new Yi(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function rt(s){let t=s.field(se.state,!1);return t?t.tree:Ti.empty}class Fw{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let mn=null;class $r{constructor(t,e,i=[],n,r,o,l,a){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new $r(t,e,[],Ti.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Fw(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=Ti.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let n=Date.now()+t;t=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(lr.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=n,this.parse=null,this.treeLen<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(lr.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=mn;mn=this;try{return t()}finally{mn=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=sf(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let a=[];if(t.iterChangedRanges((c,h,f,u)=>a.push({fromA:c,toA:h,fromB:f,toB:u})),i=lr.applyChanges(i,a),n=Ti.empty,r=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let h=t.mapPos(c.from,1),f=t.mapPos(c.to,-1);h<f&&l.push({from:h,to:f})}}}return new $r(this.parser,e,i,n,r,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<t.to&&r>t.from&&(this.fragments=sf(this.fragments,n,r),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Hb{createParse(e,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=mn;if(a){for(let c of n)a.tempSkipped.push(c);t&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,t]):t)}return this.parsedPos=o,new Ti(ih.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return mn}}function sf(s,t,e){return lr.applyChanges(s,[{fromA:t,toA:e,fromB:t,toB:e}])}class Xi{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Xi(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=$r.create(t.facet(si).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Xi(i)}}se.state=ct.define({create:Xi.init,update(s,t){for(let e of t.effects)if(e.is(se.setState))return e.value;return t.startState.facet(si)!=t.state.facet(si)?Xi.init(t.state):s.apply(t)}});let Xp=s=>{let t=setTimeout(()=>s(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(Xp=s=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(s,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const Ho=typeof navigator<"u"&&(!((No=navigator.scheduling)===null||No===void 0)&&No.isInputPending)?()=>navigator.scheduling.isInputPending():null,Iw=pt.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(se.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(se.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=Xp(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(se.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!Ho?Math.max(25,t.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,a=r.context.work(()=>Ho&&Ho()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-e,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:se.setState.of(new Xi(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>xt(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),si=v.define({combine(s){return s.length?s[0]:null},enables:s=>[se.state,Iw,T.contentAttributes.compute([s],t=>{let e=t.facet(s);return e&&e.name?{"data-language":e.name}:{}})]});class yh{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Vw=v.define(),an=v.define({combine:s=>{if(!s.length)return" ";let t=s[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(s[0]));return t}});function Nr(s){let t=s.facet(an);return t.charCodeAt(0)==9?s.tabSize*t.length:t.length}function Zn(s,t){let e="",i=s.tabSize,n=s.facet(an)[0];if(n==" "){for(;t>=i;)e+=" ",t-=i;n=" "}for(let r=0;r<t;r++)e+=n;return e}function wh(s,t){s instanceof $&&(s=new lo(s));for(let i of s.state.facet(Vw)){let n=i(s,t);if(n!==void 0)return n}let e=rt(s.state);return e.length>=t?Ww(s,e,t):null}class lo{constructor(t,e={}){this.state=t,this.options=e,this.unit=Nr(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==t?{text:"",from:t}:(e<0?n<t:n<=t)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(t,e);return i.slice(t-n,Math.min(i.length,t+100-n))}column(t,e=1){let{text:i,from:n}=this.lineAt(t,e),r=this.countColumn(i,t-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return ln(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),r=this.options.overrideIndentation;if(r){let o=r(n);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const ao=new jt;function Ww(s,t,e){let i=t.resolveStack(e),n=i.node.enterUnfinishedNodesBefore(e);if(n!=i.node){let r=[];for(let o=n;o!=i.node;o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return _p(i,s,e)}function _p(s,t,e){for(let i=s;i;i=i.next){let n=Kw(i.node);if(n)return n(xh.create(t,e,i))}return 0}function zw(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function Kw(s){let t=s.type.prop(ao);if(t)return t;let e=s.firstChild,i;if(e&&(i=e.type.prop(jt.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>Jp(o,!0,1,void 0,r&&!zw(o)?n.from:void 0)}return s.parent==null?qw:null}function qw(){return 0}class xh extends lo{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new xh(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(jw(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return _p(this.context.next,this.base,this.pos)}}function jw(s,t){for(let e=t;e;e=e.parent)if(s==e)return!0;return!1}function Gw(s){let t=s.node,e=t.childAfter(t.from),i=t.lastChild;if(!e)return null;let n=s.options.simulateBreak,r=s.state.doc.lineAt(e.from),o=n==null||n<=r.from?r.to:Math.min(r.to,n);for(let l=e.to;;){let a=t.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.from<o?e:null;l=a.to}}function wr({closing:s,align:t=!0,units:e=1}){return i=>Jp(i,t,e,s)}function Jp(s,t,e,i,n){let r=s.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||n==s.pos+o,a=t?Gw(s):null;return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*e)}const Uw=s=>s.baseIndent;function Wn({except:s,units:t=1}={}){return e=>{let i=s&&s.test(e.textAfter);return e.baseIndent+(i?0:t*e.unit)}}const Yw=200;function Xw(){return $.transactionFilter.of(s=>{if(!s.docChanged||!s.isUserEvent("input.type")&&!s.isUserEvent("input.complete"))return s;let t=s.startState.languageDataAt("indentOnInput",s.startState.selection.main.head);if(!t.length)return s;let e=s.newDoc,{head:i}=s.newSelection.main,n=e.lineAt(i);if(i>n.from+Yw)return s;let r=e.sliceString(n.from,i);if(!t.some(c=>c.test(r)))return s;let{state:o}=s,l=-1,a=[];for(let{head:c}of o.selection.ranges){let h=o.doc.lineAt(c);if(h.from==l)continue;l=h.from;let f=wh(o,h.from);if(f==null)continue;let u=/^\s*/.exec(h.text)[0],d=Zn(o,f);u!=d&&a.push({from:h.from,to:h.from+u.length,insert:d})}return a.length?[s,{changes:a,sequential:!0}]:s})}const _w=v.define(),ho=new jt;function Sh(s){let t=s.firstChild,e=s.lastChild;return t&&t.to<e.from?{from:t.to,to:e.type.isError?s.to:e.from}:null}function Jw(s,t,e){let i=rt(s);if(i.length<e)return null;let n=i.resolveStack(e,1),r=null;for(let o=n;o;o=o.next){let l=o.node;if(l.to<=e||l.from>e)continue;if(r&&l.from<t)break;let a=l.type.prop(ho);if(a&&(l.to<i.length-50||i.length==s.doc.length||!Qw(l))){let c=a(l,s);c&&c.from<=e&&c.from>=t&&c.to>e&&(r=c)}}return r}function Qw(s){let t=s.lastChild;return t&&t.to==s.to&&t.type.isError}function Hr(s,t,e){for(let i of s.facet(_w)){let n=i(s,t,e);if(n)return n}return Jw(s,t,e)}function Qp(s,t){let e=t.mapPos(s.from,1),i=t.mapPos(s.to,-1);return e>=i?void 0:{from:e,to:i}}const co=R.define({map:Qp}),ms=R.define({map:Qp});function Zp(s){let t=[];for(let{head:e}of s.state.selection.ranges)t.some(i=>i.from<=e&&i.to>=e)||t.push(s.lineBlockAt(e));return t}const bi=ct.define({create(){return P.none},update(s,t){s=s.map(t.changes);for(let e of t.effects)if(e.is(co)&&!Zw(s,e.value.from,e.value.to)){let{preparePlaceholder:i}=t.state.facet(ig),n=i?P.replace({widget:new ox(i(t.state,e.value))}):rf;s=s.update({add:[n.range(e.value.from,e.value.to)]})}else e.is(ms)&&(s=s.update({filter:(i,n)=>e.value.from!=i||e.value.to!=n,filterFrom:e.value.from,filterTo:e.value.to}));if(t.selection){let e=!1,{head:i}=t.selection.main;s.between(i,i,(n,r)=>{n<i&&r>i&&(e=!0)}),e&&(s=s.update({filterFrom:i,filterTo:i,filter:(n,r)=>r<=i||n>=i}))}return s},provide:s=>T.decorations.from(s),toJSON(s,t){let e=[];return s.between(0,t.doc.length,(i,n)=>{e.push(i,n)}),e},fromJSON(s){if(!Array.isArray(s)||s.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let e=0;e<s.length;){let i=s[e++],n=s[e++];if(typeof i!="number"||typeof n!="number")throw new RangeError("Invalid JSON for fold state");t.push(rf.range(i,n))}return P.set(t,!0)}});function Fr(s,t,e){var i;let n=null;return(i=s.field(bi,!1))===null||i===void 0||i.between(t,e,(r,o)=>{(!n||n.from>r)&&(n={from:r,to:o})}),n}function Zw(s,t,e){let i=!1;return s.between(t,t,(n,r)=>{n==t&&r==e&&(i=!0)}),i}function tg(s,t){return s.field(bi,!1)?t:t.concat(R.appendConfig.of(ng()))}const tx=s=>{for(let t of Zp(s)){let e=Hr(s.state,t.from,t.to);if(e)return s.dispatch({effects:tg(s.state,[co.of(e),eg(s,e)])}),!0}return!1},ex=s=>{if(!s.state.field(bi,!1))return!1;let t=[];for(let e of Zp(s)){let i=Fr(s.state,e.from,e.to);i&&t.push(ms.of(i),eg(s,i,!1))}return t.length&&s.dispatch({effects:t}),t.length>0};function eg(s,t,e=!0){let i=s.state.doc.lineAt(t.from).number,n=s.state.doc.lineAt(t.to).number;return T.announce.of(`${s.state.phrase(e?"Folded lines":"Unfolded lines")} ${i} ${s.state.phrase("to")} ${n}.`)}const ix=s=>{let{state:t}=s,e=[];for(let i=0;i<t.doc.length;){let n=s.lineBlockAt(i),r=Hr(t,n.from,n.to);r&&e.push(co.of(r)),i=(r?s.lineBlockAt(r.to):n).to+1}return e.length&&s.dispatch({effects:tg(s.state,e)}),!!e.length},nx=s=>{let t=s.state.field(bi,!1);if(!t||!t.size)return!1;let e=[];return t.between(0,s.state.doc.length,(i,n)=>{e.push(ms.of({from:i,to:n}))}),s.dispatch({effects:e}),!0},sx=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:tx},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:ex},{key:"Ctrl-Alt-[",run:ix},{key:"Ctrl-Alt-]",run:nx}],rx={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},ig=v.define({combine(s){return De(s,rx)}});function ng(s){return[bi,hx]}function sg(s,t){let{state:e}=s,i=e.facet(ig),n=o=>{let l=s.lineBlockAt(s.posAtDOM(o.target)),a=Fr(s.state,l.from,l.to);a&&s.dispatch({effects:ms.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(s,n,t);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",e.phrase("folded code")),r.title=e.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=n,r}const rf=P.replace({widget:new class extends Oe{toDOM(s){return sg(s,null)}}});class ox extends Oe{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return sg(t,this.value)}}const lx={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class Fo extends Ne{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function ax(s={}){let t=Object.assign(Object.assign({},lx),s),e=new Fo(t,!0),i=new Fo(t,!1),n=pt.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(si)!=o.state.facet(si)||o.startState.field(bi,!1)!=o.state.field(bi,!1)||rt(o.startState)!=rt(o.state)||t.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new ii;for(let a of o.viewportLineBlocks){let c=Fr(o.state,a.from,a.to)?i:Hr(o.state,a.from,a.to)?e:null;c&&l.add(a.from,a.from,c)}return l.finish()}}),{domEventHandlers:r}=t;return[n,Ow({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(n))===null||l===void 0?void 0:l.markers)||E.empty},initialSpacer(){return new Fo(t,!1)},domEventHandlers:Object.assign(Object.assign({},r),{click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let c=Fr(o.state,l.from,l.to);if(c)return o.dispatch({effects:ms.of(c)}),!0;let h=Hr(o.state,l.from,l.to);return h?(o.dispatch({effects:co.of(h)}),!0):!1}})}),ng()]}const hx=T.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class hn{constructor(t,e){this.specs=t;let i;function n(l){let a=lt.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof e.all=="string"?e.all:e.all?n(e.all):void 0,o=e.scope;this.scope=o instanceof se?l=>l.prop(Ei)==o.data:o?l=>l==o:void 0,this.style=Nb(t.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new lt(i):null,this.themeType=e.themeType}static define(t,e){return new hn(t,e||{})}}const Jl=v.define(),rg=v.define({combine(s){return s.length?[s[0]]:null}});function Io(s){let t=s.facet(Jl);return t.length?t:s.facet(rg)}function vh(s,t){let e=[fx],i;return s instanceof hn&&(s.module&&e.push(T.styleModule.of(s.module)),i=s.themeType),t!=null&&t.fallback?e.push(rg.of(s)):i?e.push(Jl.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(i=="dark")?[s]:[])):e.push(Jl.of(s)),e}class cx{constructor(t){this.markCache=Object.create(null),this.tree=rt(t.state),this.decorations=this.buildDeco(t,Io(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=rt(t.state),i=Io(t.state),n=i!=Io(t.startState),{viewport:r}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!n&&e.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return P.none;let i=new ii;for(let{from:n,to:r}of t.visibleRanges)Fb(this.tree,e,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=P.mark({class:a})))},n,r);return i.finish()}}const fx=_t.high(pt.fromClass(cx,{decorations:s=>s.decorations})),ux=hn.define([{tag:C.meta,color:"#404740"},{tag:C.link,textDecoration:"underline"},{tag:C.heading,textDecoration:"underline",fontWeight:"bold"},{tag:C.emphasis,fontStyle:"italic"},{tag:C.strong,fontWeight:"bold"},{tag:C.strikethrough,textDecoration:"line-through"},{tag:C.keyword,color:"#708"},{tag:[C.atom,C.bool,C.url,C.contentSeparator,C.labelName],color:"#219"},{tag:[C.literal,C.inserted],color:"#164"},{tag:[C.string,C.deleted],color:"#a11"},{tag:[C.regexp,C.escape,C.special(C.string)],color:"#e40"},{tag:C.definition(C.variableName),color:"#00f"},{tag:C.local(C.variableName),color:"#30a"},{tag:[C.typeName,C.namespace],color:"#085"},{tag:C.className,color:"#167"},{tag:[C.special(C.variableName),C.macroName],color:"#256"},{tag:C.definition(C.propertyName),color:"#00c"},{tag:C.comment,color:"#940"},{tag:C.invalid,color:"#f00"}]),dx=T.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),og=1e4,lg="()[]{}",ag=v.define({combine(s){return De(s,{afterCursor:!0,brackets:lg,maxScanDistance:og,renderMatch:mx})}}),px=P.mark({class:"cm-matchingBracket"}),gx=P.mark({class:"cm-nonmatchingBracket"});function mx(s){let t=[],e=s.matched?px:gx;return t.push(e.range(s.start.from,s.start.to)),s.end&&t.push(e.range(s.end.from,s.end.to)),t}const bx=ct.define({create(){return P.none},update(s,t){if(!t.docChanged&&!t.selection)return s;let e=[],i=t.state.facet(ag);for(let n of t.state.selection.ranges){if(!n.empty)continue;let r=xe(t.state,n.head,-1,i)||n.head>0&&xe(t.state,n.head-1,1,i)||i.afterCursor&&(xe(t.state,n.head,1,i)||n.head<t.state.doc.length&&xe(t.state,n.head+1,-1,i));r&&(e=e.concat(i.renderMatch(r,t.state)))}return P.set(e,!0)},provide:s=>T.decorations.from(s)}),yx=[bx,dx];function wx(s={}){return[ag.of(s),yx]}const xx=new jt;function Ql(s,t,e){let i=s.prop(t<0?jt.openedBy:jt.closedBy);if(i)return i;if(s.name.length==1){let n=e.indexOf(s.name);if(n>-1&&n%2==(t<0?1:0))return[e[n+t]]}return null}function Zl(s){let t=s.type.prop(xx);return t?t(s.node):s}function xe(s,t,e,i={}){let n=i.maxScanDistance||og,r=i.brackets||lg,o=rt(s),l=o.resolveInner(t,e);for(let a=l;a;a=a.parent){let c=Ql(a.type,e,r);if(c&&a.from<a.to){let h=Zl(a);if(h&&(e>0?t>=h.from&&t<h.to:t>h.from&&t<=h.to))return Sx(s,t,e,a,h,c,r)}}return vx(s,t,e,o,l.type,n,r)}function Sx(s,t,e,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},c=0,h=l==null?void 0:l.cursor();if(h&&(e<0?h.childBefore(i.from):h.childAfter(i.to)))do if(e<0?h.to<=i.from:h.from>=i.to){if(c==0&&r.indexOf(h.type.name)>-1&&h.from<h.to){let f=Zl(h);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(Ql(h.type,e,o))c++;else if(Ql(h.type,-e,o)){if(c==0){let f=Zl(h);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}c--}}while(e<0?h.prevSibling():h.nextSibling());return{start:a,matched:!1}}function vx(s,t,e,i,n,r,o){let l=e<0?s.sliceDoc(t-1,t):s.sliceDoc(t,t+1),a=o.indexOf(l);if(a<0||a%2==0!=e>0)return null;let c={from:e<0?t-1:t,to:e>0?t+1:t},h=s.doc.iterRange(t,e>0?s.doc.length:0),f=0;for(let u=0;!h.next().done&&u<=r;){let d=h.value;e<0&&(u+=d.length);let p=t+u*e;for(let g=e>0?0:d.length-1,b=e>0?d.length:-1;g!=b;g+=e){let m=o.indexOf(d[g]);if(!(m<0||i.resolveInner(p+g,1).type!=n))if(m%2==0==e>0)f++;else{if(f==1)return{start:c,end:{from:p+g,to:p+g+1},matched:m>>1==a>>1};f--}}e>0&&(u+=d.length)}return h.done?{start:c,matched:!1}:null}const kx=Object.create(null),of=[ih.none],lf=[],af=Object.create(null),Cx=Object.create(null);for(let[s,t]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"]])Cx[s]=Mx(kx,t);function Vo(s,t){lf.indexOf(s)>-1||(lf.push(s),console.warn(t))}function Mx(s,t){let e=[];for(let l of t.split(" ")){let a=[];for(let c of l.split(".")){let h=s[c]||C[c];h?typeof h=="function"?a.length?a=a.map(h):Vo(c,`Modifier ${c} used at start of tag`):a.length?Vo(c,`Tag ${c} used as modifier`):a=Array.isArray(h)?h:[h]:Vo(c,`Unknown highlighting tag ${c}`)}for(let c of a)e.push(c)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),n=i+" "+e.map(l=>l.id),r=af[n];if(r)return r.id;let o=af[n]=ih.define({id:of.length,name:i,props:[$b({[i]:e})]});return of.push(o),o.id}Q.RTL,Q.LTR;class hg{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=rt(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),n=e.text.slice(i-e.from,this.pos-e.from),r=n.search(fg(t,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(t,e){t=="abort"&&this.abortListeners&&this.abortListeners.push(e)}}function hf(s){let t=Object.keys(s).join(""),e=/\w/.test(t);return e&&(t=t.replace(/\w/g,"")),`[${e?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Ax(s){let t=Object.create(null),e=Object.create(null);for(let{label:n}of s){t[n[0]]=!0;for(let r=1;r<n.length;r++)e[n[r]]=!0}let i=hf(t)+hf(e)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function cg(s){let t=s.map(n=>typeof n=="string"?{label:n}:n),[e,i]=t.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:Ax(t);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:t,validFor:e}:null}}function Dx(s,t){return e=>{for(let i=rt(e.state).resolveInner(e.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return t(e)}}class cf{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function Ze(s){return s.selection.main.from}function fg(s,t){var e;let{source:i}=s,n=t&&i[0]!="^",r=i[i.length-1]!="$";return!n&&!r?s:new RegExp(`${n?"^":""}(?:${i})${r?"$":""}`,(e=s.flags)!==null&&e!==void 0?e:s.ignoreCase?"i":"")}const ug=Vt.define();function Ox(s,t,e,i){let{main:n}=s.selection,r=e-n.from,o=i-n.from;return Object.assign(Object.assign({},s.changeByRange(l=>l!=n&&e!=i&&s.sliceDoc(l.from+r,l.from+o)!=s.sliceDoc(e,i)?{range:l}:{changes:{from:l.from+r,to:i==n.from?l.to:l.from+o,insert:t},range:w.cursor(l.from+r+t.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const ff=new WeakMap;function Tx(s){if(!Array.isArray(s))return s;let t=ff.get(s);return t||ff.set(s,t=cg(s)),t}const Ir=R.define(),ts=R.define();class Bx{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e<t.length;){let i=ht(t,e),n=Rt(i);this.chars.push(i);let r=t.slice(e,e+n),o=r.toUpperCase();this.folded.push(ht(o==r?r.toLowerCase():o,0)),e+=n}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,!0}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return!1;let{chars:e,folded:i,any:n,precise:r,byWord:o}=this;if(e.length==1){let y=ht(t,0),S=Rt(y),x=S==t.length?0:-100;if(y!=e[0])if(y==i[0])x+=-200;else return!1;return this.ret(x,[0,S])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=e.length,c=0;if(l<0){for(let y=0,S=Math.min(t.length,200);y<S&&c<a;){let x=ht(t,y);(x==e[c]||x==i[c])&&(n[c++]=y),y+=Rt(x)}if(c<a)return!1}let h=0,f=0,u=!1,d=0,p=-1,g=-1,b=/[a-z]/.test(t),m=!0;for(let y=0,S=Math.min(t.length,200),x=0;y<S&&f<a;){let k=ht(t,y);l<0&&(h<a&&k==e[h]&&(r[h++]=y),d<a&&(k==e[d]||k==i[d]?(d==0&&(p=y),g=y+1,d++):d=0));let M,N=k<255?k>=48&&k<=57||k>=97&&k<=122?2:k>=65&&k<=90?1:0:(M=sh(k))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!y||N==1&&b||x==0&&N!=0)&&(e[f]==k||i[f]==k&&(u=!0)?o[f++]=y:o.length&&(m=!1)),x=N,y+=Rt(k)}return f==a&&o[0]==0&&m?this.result(-100+(u?-200:0),o,t):d==a&&p==0?this.ret(-200-t.length+(g==t.length?0:-100),[0,g]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):d==a?this.ret(-900-t.length,[p,g]):f==a?this.result(-100+(u?-200:0)+-700+(m?0:-1100),o,t):e.length==2?!1:this.result((n[0]?-700:0)+-200+-1100,n,t)}result(t,e,i){let n=[],r=0;for(let o of e){let l=o+(this.astral?Rt(ht(i,o)):1);r&&n[r-1]==o?n[r-1]=l:(n[r++]=o,n[r++]=l)}return this.ret(t-i.length,n)}}const ut=v.define({combine(s){return De(s,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Ex,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>uf(t(i),e(i)),optionClass:(t,e)=>i=>uf(t(i),e(i)),addToOptions:(t,e)=>t.concat(e)})}});function uf(s,t){return s?t?s+" "+t:s:t}function Ex(s,t,e,i,n,r){let o=s.textDirection==Q.RTL,l=o,a=!1,c="top",h,f,u=t.left-n.left,d=n.right-t.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))h=Math.max(n.top,Math.min(e.top,n.bottom-g))-t.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?t.right:n.right-t.left)-30);let y=n.bottom-t.bottom;y>=g||y>t.top?h=e.bottom-t.top:(c="bottom",h=t.bottom-e.top)}let b=(t.bottom-t.top)/r.offsetHeight,m=(t.right-t.left)/r.offsetWidth;return{style:`${c}: ${h/b}px; max-width: ${f/m}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function Rx(s){let t=s.addToOptions.slice();return s.icons&&t.push({render(e){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),e.type&&i.classList.add(...e.type.split(/\s+/g).map(n=>"cm-completionIcon-"+n)),i.setAttribute("aria-hidden","true"),i},position:20}),t.push({render(e,i,n,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=e.displayLabel||e.label,a=0;for(let c=0;c<r.length;){let h=r[c++],f=r[c++];h>a&&o.appendChild(document.createTextNode(l.slice(a,h)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(h,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(e){if(!e.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=e.detail,i},position:80}),t.sort((e,i)=>e.position-i.position).map(e=>e.render)}function Wo(s,t,e){if(s<=e)return{from:0,to:s};if(t<0&&(t=0),t<=s>>1){let n=Math.floor(t/e);return{from:n*e,to:(n+1)*e}}let i=Math.floor((s-t)/e);return{from:s-(i+1)*e,to:s-i*e}}class Lx{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:r,selected:o}=n.open,l=t.state.facet(ut);this.optionContent=Rx(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Wo(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",a=>{let{options:c}=t.state.field(e).open;for(let h=a.target,f;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(f=/-(\d+)$/.exec(h.id))&&+f[1]<c.length){this.applyCompletion(t,c[+f[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let c=t.state.field(this.stateField,!1);c&&c.tooltip&&t.state.facet(ut).closeOnBlur&&a.relatedTarget!=t.contentDOM&&t.dispatch({effects:ts.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:r,selected:o,disabled:l}=i.open;(!n.open||n.open.options!=r)&&(this.range=Wo(r.length,o,t.state.facet(ut).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((e=n.open)===null||e===void 0?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of e.split(" "))i&&this.dom.classList.add(i);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=Wo(e.options.length,e.selected,this.view.state.facet(ut).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:n}=i;if(!n)return;let r=typeof n=="string"?document.createTextNode(n):n(i);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(o,i)}).catch(o=>xt(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",t.nodeType!=null)i.appendChild(t),this.infoDestroy=null;else{let{dom:n,destroy:r}=t;i.appendChild(n),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)i.nodeName!="LI"||!i.id?n--:n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return e&&$x(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return n.top>Math.min(r.bottom,e.bottom)-10||n.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(ut).positionInfo(this.view,e,n,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const n=document.createElement("ul");n.id=e,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=t[o],{section:c}=l;if(c){let u=typeof c=="string"?c:c.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof c!="string"&&c.header)n.appendChild(c.header(c));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const h=n.appendChild(document.createElement("li"));h.id=e+"-"+o,h.setAttribute("role","option");let f=this.optionClass(l);f&&(h.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Px(s,t){return e=>new Lx(e,s,t)}function $x(s,t){let e=s.getBoundingClientRect(),i=t.getBoundingClientRect(),n=e.height/s.offsetHeight;i.top<e.top?s.scrollTop-=(e.top-i.top)/n:i.bottom>e.bottom&&(s.scrollTop+=(i.bottom-e.bottom)/n)}function df(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function Nx(s,t){let e=[],i=null,n=a=>{e.push(a);let{section:c}=a.completion;if(c){i||(i=[]);let h=typeof c=="string"?c:c.name;i.some(f=>f.name==h)||i.push(typeof c=="string"?{name:h}:c)}};for(let a of s)if(a.hasResult()){let c=a.result.getMatch;if(a.result.filter===!1)for(let h of a.result.options)n(new cf(h,a.source,c?c(h):[],1e9-e.length));else{let h=new Bx(t.sliceDoc(a.from,a.to));for(let f of a.result.options)if(h.match(f.label)){let u=f.displayLabel?c?c(f,h.matched):[]:h.matched;n(new cf(f,a.source,u,h.score+(f.boost||0)))}}}if(i){let a=Object.create(null),c=0,h=(f,u)=>{var d,p;return((d=f.rank)!==null&&d!==void 0?d:1e9)-((p=u.rank)!==null&&p!==void 0?p:1e9)||(f.name<u.name?-1:1)};for(let f of i.sort(h))c-=1e5,a[f.name]=c;for(let f of e){let{section:u}=f.completion;u&&(f.score+=a[typeof u=="string"?u:u.name])}}let r=[],o=null,l=t.facet(ut).compareCompletions;for(let a of e.sort((c,h)=>h.score-c.score||l(c.completion,h.completion))){let c=a.completion;!o||o.label!=c.label||o.detail!=c.detail||o.type!=null&&c.type!=null&&o.type!=c.type||o.apply!=c.apply||o.boost!=c.boost?r.push(a):df(a.completion)>df(o)&&(r[r.length-1]=a),o=a.completion}return r}class Ri{constructor(t,e,i,n,r,o){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=o}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Ri(this.options,pf(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,r){let o=Nx(t,e);if(!o.length)return n&&t.some(a=>a.state==1)?new Ri(n.options,n.attrs,n.tooltip,n.timestamp,n.selected,!0):null;let l=e.facet(ut).selectOnOpen?0:-1;if(n&&n.selected!=l&&n.selected!=-1){let a=n.options[n.selected].completion;for(let c=0;c<o.length;c++)if(o[c].completion==a){l=c;break}}return new Ri(o,pf(i,l),{pos:t.reduce((a,c)=>c.hasResult()?Math.min(a,c.from):a,1e8),create:Wx,above:r.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new Ri(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Vr{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Vr(Ix,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:e}=t,i=e.facet(ut),r=(i.override||e.languageDataAt("autocomplete",Ze(e)).map(Tx)).map(l=>(this.active.find(c=>c.source==l)||new Tt(l,this.active.some(c=>c.state!=0)?1:0)).update(t,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&t.docChanged&&(o=o.map(t.changes)),t.selection||r.some(l=>l.hasResult()&&t.changes.touchesRange(l.from,l.to))||!Hx(r,this.active)?o=Ri.build(r,e,this.id,o,i):o&&o.disabled&&!r.some(l=>l.state==1)&&(o=null),!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new Tt(l.source,0):l));for(let l of t.effects)l.is(pg)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new Vr(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Fx}}function Hx(s,t){if(s==t)return!0;for(let e=0,i=0;;){for(;e<s.length&&!s[e].hasResult;)e++;for(;i<t.length&&!t[i].hasResult;)i++;let n=e==s.length,r=i==t.length;if(n||r)return n==r;if(s[e++].result!=t[i++].result)return!1}}const Fx={"aria-autocomplete":"list"};function pf(s,t){let e={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return t>-1&&(e["aria-activedescendant"]=s+"-"+t),e}const Ix=[];function ta(s){return s.isUserEvent("input.type")?"input":s.isUserEvent("delete.backward")?"delete":null}class Tt{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=ta(t),n=this;i?n=n.handleUserEvent(t,i,e):t.docChanged?n=n.handleChange(t):t.selection&&n.state!=0&&(n=new Tt(n.source,0));for(let r of t.effects)if(r.is(Ir))n=new Tt(n.source,1,r.value?Ze(t.state):-1);else if(r.is(ts))n=new Tt(n.source,0);else if(r.is(dg))for(let o of r.value)o.source==n.source&&(n=o);return n}handleUserEvent(t,e,i){return e=="delete"||!i.activateOnTyping?this.map(t.changes):new Tt(this.source,1)}handleChange(t){return t.changes.touchesRange(Ze(t.startState))?new Tt(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new Tt(this.source,this.state,t.mapPos(this.explicitPos))}}class Hi extends Tt{constructor(t,e,i,n,r){super(t,2,e),this.result=i,this.from=n,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var n;let r=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=Ze(t.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||e=="delete"&&Ze(t.startState)==this.from)return new Tt(this.source,e=="input"&&i.activateOnTyping?1:0);let a=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos),c;return Vx(this.result.validFor,t.state,r,o)?new Hi(this.source,a,this.result,r,o):this.result.update&&(c=this.result.update(this.result,r,o,new hg(t.state,l,a>=0)))?new Hi(this.source,a,c,c.from,(n=c.to)!==null&&n!==void 0?n:Ze(t.state)):new Tt(this.source,1,a)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new Tt(this.source,0):this.map(t.changes)}map(t){return t.empty?this:new Hi(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1))}}function Vx(s,t,e,i){if(!s)return!1;let n=t.sliceDoc(e,i);return typeof s=="function"?s(n,e,i,t):fg(s,!0).test(n)}const dg=R.define({map(s,t){return s.map(e=>e.map(t))}}),pg=R.define(),Nt=ct.define({create(){return Vr.start()},update(s,t){return s.update(t)},provide:s=>[mh.from(s,t=>t.tooltip),T.contentAttributes.from(s,t=>t.attrs)]});function gg(s,t){const e=t.completion.apply||t.completion.label;let i=s.state.field(Nt).active.find(n=>n.source==t.source);return i instanceof Hi?(typeof e=="string"?s.dispatch(Object.assign(Object.assign({},Ox(s.state,e,i.from,i.to)),{annotations:ug.of(t.completion)})):e(s,t.completion,i.from,i.to),!0):!1}const Wx=Px(Nt,gg);function Ns(s,t="option"){return e=>{let i=e.state.field(Nt,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<e.state.facet(ut).interactionDelay)return!1;let n=1,r;t=="page"&&(r=qp(e,i.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+n*(s?1:-1):s?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),e.dispatch({effects:pg.of(l)}),!0}}const zx=s=>{let t=s.state.field(Nt,!1);return s.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<s.state.facet(ut).interactionDelay?!1:gg(s,t.open.options[t.open.selected])},Kx=s=>s.state.field(Nt,!1)?(s.dispatch({effects:Ir.of(!0)}),!0):!1,qx=s=>{let t=s.state.field(Nt,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(s.dispatch({effects:ts.of(null)}),!0)};class jx{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Gx=50,Ux=1e3,Yx=pt.fromClass(class{constructor(s){this.view=s,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of s.state.field(Nt).active)t.state==1&&this.startQuery(t)}update(s){let t=s.state.field(Nt);if(!s.selectionSet&&!s.docChanged&&s.startState.field(Nt)==t)return;let e=s.transactions.some(n=>(n.selection||n.docChanged)&&!ta(n));for(let n=0;n<this.running.length;n++){let r=this.running[n];if(e||r.updates.length+s.transactions.length>Gx&&Date.now()-r.time>Ux){for(let o of r.context.abortListeners)try{o()}catch(l){xt(this.view.state,l)}r.context.abortListeners=null,this.running.splice(n--,1)}else r.updates.push(...s.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),s.transactions.some(n=>n.effects.some(r=>r.is(Ir)))&&(this.pendingStart=!0);let i=this.pendingStart?50:s.state.facet(ut).activateOnTypingDelay;if(this.debounceUpdate=t.active.some(n=>n.state==1&&!this.running.some(r=>r.active.source==n.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let n of s.transactions)ta(n)=="input"?this.composing=2:this.composing==2&&n.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:s}=this.view,t=s.field(Nt);for(let e of t.active)e.state==1&&!this.running.some(i=>i.active.source==e.source)&&this.startQuery(e)}startQuery(s){let{state:t}=this.view,e=Ze(t),i=new hg(t,e,s.explicitPos==e),n=new jx(s,i);this.running.push(n),Promise.resolve(s.source(i)).then(r=>{n.context.aborted||(n.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:ts.of(null)}),xt(this.view.state,r)})}scheduleAccept(){this.running.every(s=>s.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ut).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],e=this.view.state.facet(ut);for(let i=0;i<this.running.length;i++){let n=this.running[i];if(n.done===void 0)continue;if(this.running.splice(i--,1),n.done){let o=new Hi(n.active.source,n.active.explicitPos,n.done,n.done.from,(s=n.done.to)!==null&&s!==void 0?s:Ze(n.updates.length?n.updates[0].startState:this.view.state));for(let l of n.updates)o=o.update(l,e);if(o.hasResult()){t.push(o);continue}}let r=this.view.state.field(Nt).active.find(o=>o.source==n.active.source);if(r&&r.state==1)if(n.done==null){let o=new Tt(n.active.source,0);for(let l of n.updates)o=o.update(l,e);o.state!=1&&t.push(o)}else this.startQuery(r)}t.length&&this.view.dispatch({effects:dg.of(t)})}},{eventHandlers:{blur(s){let t=this.view.state.field(Nt,!1);if(t&&t.tooltip&&this.view.state.facet(ut).closeOnBlur){let e=t.open&&qp(this.view,t.open.tooltip);(!e||!e.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:ts.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Ir.of(!1)}),20),this.composing=0}}}),mg=T.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});let Xx=class{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}},_x=class bg{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,I.TrackDel),i=t.mapPos(this.to,1,I.TrackDel);return e==null||i==null?null:new bg(this.field,e,i)}},Jx=class yg{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],r=t.doc.lineAt(e),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let f=0;f<h;f++)c+=t.facet(an);n.push(e+c.length-h),a=c+a.slice(h)}i.push(a),e+=a.length+1}let l=this.fieldPositions.map(a=>new _x(a.field,n[a.line]+a.from,n[a.line]+a.to));return{text:i,ranges:l}}static parse(t){let e=[],i=[],n=[],r;for(let o of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",c=-1;for(let h=0;h<e.length;h++)(l!=null?e[h].seq==l:a&&e[h].name==a)&&(c=h);if(c<0){let h=0;for(;h<e.length&&(l==null||e[h].seq!=null&&e[h].seq<l);)h++;e.splice(h,0,{seq:l,name:a}),c=h;for(let f of n)f.field>=c&&f.field++}n.push(new Xx(c,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of n)a.line==i.length&&a.from>l.index&&(a.from--,a.to--)}i.push(o)}return new yg(i,n)}},Qx=P.widget({widget:new class extends Oe{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),Zx=P.mark({class:"cm-snippetField"}),fo=class wg{constructor(t,e){this.ranges=t,this.active=e,this.deco=P.set(t.map(i=>(i.from==i.to?Qx:Zx).range(i.from,i.to)))}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new wg(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}};const bs=R.define({map(s,t){return s&&s.map(t)}}),tS=R.define(),es=ct.define({create(){return null},update(s,t){for(let e of t.effects){if(e.is(bs))return e.value;if(e.is(tS)&&s)return new fo(s.ranges,e.value)}return s&&t.docChanged&&(s=s.map(t.changes)),s&&t.selection&&!s.selectionInsideField(t.selection)&&(s=null),s},provide:s=>T.decorations.from(s,t=>t?t.deco:P.none)});function kh(s,t){return w.create(s.filter(e=>e.field==t).map(e=>w.range(e.from,e.to)))}function eS(s){let t=Jx.parse(s);return(e,i,n,r)=>{let{text:o,ranges:l}=t.instantiate(e.state,n),a={changes:{from:n,to:r,insert:B.of(o)},scrollIntoView:!0,annotations:i?[ug.of(i),it.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=kh(l,0)),l.some(c=>c.field>0)){let c=new fo(l,0),h=a.effects=[bs.of(c)];e.state.field(es,!1)===void 0&&h.push(R.appendConfig.of([es,oS,lS,mg]))}e.dispatch(e.state.update(a))}}function xg(s){return({state:t,dispatch:e})=>{let i=t.field(es,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return e(t.update({selection:kh(i.ranges,n),effects:bs.of(r?null:new fo(i.ranges,n)),scrollIntoView:!0})),!0}}const iS=({state:s,dispatch:t})=>s.field(es,!1)?(t(s.update({effects:bs.of(null)})),!0):!1,nS=xg(1),sS=xg(-1),rS=[{key:"Tab",run:nS,shift:sS},{key:"Escape",run:iS}],gf=v.define({combine(s){return s.length?s[0]:rS}}),oS=_t.highest(ps.compute([gf],s=>s.facet(gf)));function Ee(s,t){return Object.assign(Object.assign({},t),{apply:eS(s)})}const lS=T.domEventHandlers({mousedown(s,t){let e=t.state.field(es,!1),i;if(!e||(i=t.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=e.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==e.active?!1:(t.dispatch({selection:kh(e.ranges,n.field),effects:bs.of(e.ranges.some(r=>r.field>n.field)?new fo(e.ranges,n.field):null),scrollIntoView:!0}),!0)}}),is={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},fi=R.define({map(s,t){let e=t.mapPos(s,-1,I.TrackAfter);return e??void 0}}),Ch=new class extends Gt{};Ch.startSide=1;Ch.endSide=-1;const Sg=ct.define({create(){return E.empty},update(s,t){if(s=s.map(t.changes),t.selection){let e=t.state.doc.lineAt(t.selection.main.head);s=s.update({filter:i=>i>=e.from&&i<=e.to})}for(let e of t.effects)e.is(fi)&&(s=s.update({add:[Ch.range(e.value,e.value+1)]}));return s}});function aS(){return[cS,Sg]}const zo="()[]{}<>";function vg(s){for(let t=0;t<zo.length;t+=2)if(zo.charCodeAt(t)==s)return zo.charAt(t+1);return sh(s<128?s:s+1)}function kg(s,t){return s.languageDataAt("closeBrackets",t)[0]||is}const hS=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),cS=T.inputHandler.of((s,t,e,i)=>{if((hS?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&Rt(ht(i,0))==1||t!=n.from||e!=n.to)return!1;let r=dS(s.state,i);return r?(s.dispatch(r),!0):!1}),fS=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let i=kg(s,s.selection.main.head).brackets||is.brackets,n=null,r=s.changeByRange(o=>{if(o.empty){let l=pS(s.doc,o.head);for(let a of i)if(a==l&&uo(s.doc,o.head)==vg(ht(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:w.cursor(o.head-a.length)}}return{range:n=o}});return n||t(s.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!n},uS=[{key:"Backspace",run:fS}];function dS(s,t){let e=kg(s,s.selection.main.head),i=e.brackets||is.brackets;for(let n of i){let r=vg(ht(n,0));if(t==n)return r==n?bS(s,n,i.indexOf(n+n+n)>-1,e):gS(s,n,r,e.before||is.before);if(t==r&&Cg(s,s.selection.main.from))return mS(s,n,r)}return null}function Cg(s,t){let e=!1;return s.field(Sg).between(0,s.doc.length,i=>{i==t&&(e=!0)}),e}function uo(s,t){let e=s.sliceString(t,t+2);return e.slice(0,Rt(ht(e,0)))}function pS(s,t){let e=s.sliceString(t-2,t);return Rt(ht(e,0))==e.length?e:e.slice(1)}function gS(s,t,e,i){let n=null,r=s.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:e,from:o.to}],effects:fi.of(o.to+t.length),range:w.range(o.anchor+t.length,o.head+t.length)};let l=uo(s.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:t+e,from:o.head},effects:fi.of(o.head+t.length),range:w.cursor(o.head+t.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function mS(s,t,e){let i=null,n=s.changeByRange(r=>r.empty&&uo(s.doc,r.head)==e?{changes:{from:r.head,to:r.head+e.length,insert:e},range:w.cursor(r.head+e.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function bS(s,t,e,i){let n=i.stringPrefixes||is.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:fi.of(l.to+t.length),range:w.range(l.anchor+t.length,l.head+t.length)};let a=l.head,c=uo(s.doc,a),h;if(c==t){if(mf(s,a))return{changes:{insert:t+t,from:a},effects:fi.of(a+t.length),range:w.cursor(a+t.length)};if(Cg(s,a)){let u=e&&s.sliceDoc(a,a+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:a,to:a+u.length,insert:u},range:w.cursor(a+u.length)}}}else{if(e&&s.sliceDoc(a-2*t.length,a)==t+t&&(h=bf(s,a-2*t.length,n))>-1&&mf(s,h))return{changes:{insert:t+t+t+t,from:a},effects:fi.of(a+t.length),range:w.cursor(a+t.length)};if(s.charCategorizer(a)(c)!=Y.Word&&bf(s,a,n)>-1&&!yS(s,a,t,n))return{changes:{insert:t+t,from:a},effects:fi.of(a+t.length),range:w.cursor(a+t.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function mf(s,t){let e=rt(s).resolveInner(t+1);return e.parent&&e.from==t}function yS(s,t,e,i){let n=rt(s).resolveInner(t,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=s.sliceDoc(n.from,Math.min(n.to,n.from+e.length+r)),a=l.indexOf(e);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=n.firstChild;for(;h&&h.from==n.from&&h.to-h.from>e.length+a;){if(s.sliceDoc(h.to-e.length,h.to)==e)return!1;h=h.firstChild}return!0}let c=n.to==t&&n.parent;if(!c)break;n=c}return!1}function bf(s,t,e){let i=s.charCategorizer(t);if(i(s.sliceDoc(t-1,t))!=Y.Word)return t;for(let n of e){let r=t-n.length;if(s.sliceDoc(r,t)==n&&i(s.sliceDoc(r-1,r))!=Y.Word)return r}return-1}function wS(s={}){return[Nt,ut.of(s),Yx,xS,mg]}const Mg=[{key:"Ctrl-Space",run:Kx},{key:"Escape",run:qx},{key:"ArrowDown",run:Ns(!0)},{key:"ArrowUp",run:Ns(!1)},{key:"PageDown",run:Ns(!0,"page")},{key:"PageUp",run:Ns(!1,"page")},{key:"Enter",run:zx}],xS=_t.highest(ps.computeN([ut],s=>s.facet(ut).defaultKeymap?[Mg]:[])),yf=new ud,Ag=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function Hs(s){return(t,e,i)=>{if(i)return!1;let n=t.node.getChild("VariableName");return n&&e(n,s),!0}}const SS={FunctionDefinition:Hs("function"),ClassDefinition:Hs("class"),ForStatement(s,t,e){if(e){for(let i=s.node.firstChild;i;i=i.nextSibling)if(i.name=="VariableName")t(i,"variable");else if(i.name=="in")break}},ImportStatement(s,t){var e,i;let{node:n}=s,r=((e=n.firstChild)===null||e===void 0?void 0:e.name)=="from";for(let o=n.getChild("import");o;o=o.nextSibling)o.name=="VariableName"&&((i=o.nextSibling)===null||i===void 0?void 0:i.name)!="as"&&t(o,r?"variable":"namespace")},AssignStatement(s,t){for(let e=s.node.firstChild;e;e=e.nextSibling)if(e.name=="VariableName")t(e,"variable");else if(e.name==":"||e.name=="AssignOp")break},ParamList(s,t){for(let e=null,i=s.node.firstChild;i;i=i.nextSibling)i.name=="VariableName"&&(!e||!/\*|AssignOp/.test(e.name))&&t(i,"variable"),e=i},CapturePattern:Hs("variable"),AsPattern:Hs("variable"),__proto__:null};function Dg(s,t){let e=yf.get(t);if(e)return e;let i=[],n=!0;function r(o,l){let a=s.sliceString(o.from,o.to);i.push({label:a,type:l})}return t.cursor(nh.IncludeAnonymous).iterate(o=>{if(o.name){let l=SS[o.name];if(l&&l(o,r,n)||!n&&Ag.has(o.name))return!1;n=!1}else if(o.to-o.from>8192){for(let l of Dg(s,o.node))i.push(l);return!1}}),yf.set(t,i),i}const wf=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,Og=["String","FormatString","Comment","PropertyName"];function vS(s){let t=rt(s.state).resolveInner(s.pos,-1);if(Og.indexOf(t.name)>-1)return null;let e=t.name=="VariableName"||t.to-t.from<20&&wf.test(s.state.sliceDoc(t.from,t.to));if(!e&&!s.explicit)return null;let i=[];for(let n=t;n;n=n.parent)Ag.has(n.name)&&(i=i.concat(Dg(s.state.doc,n)));return{options:i,from:e?t.from:s.pos,validFor:wf}}const kS=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(s=>({label:s,type:"constant"})).concat(["ArithmeticError","AssertionError","AttributeError","BaseException","BlockingIOError","BrokenPipeError","BufferError","BytesWarning","ChildProcessError","ConnectionAbortedError","ConnectionError","ConnectionRefusedError","ConnectionResetError","DeprecationWarning","EOFError","Ellipsis","EncodingWarning","EnvironmentError","Exception","FileExistsError","FileNotFoundError","FloatingPointError","FutureWarning","GeneratorExit","IOError","ImportError","ImportWarning","IndentationError","IndexError","InterruptedError","IsADirectoryError","KeyError","KeyboardInterrupt","LookupError","MemoryError","ModuleNotFoundError","NameError","NotADirectoryError","NotImplemented","NotImplementedError","OSError","OverflowError","PendingDeprecationWarning","PermissionError","ProcessLookupError","RecursionError","ReferenceError","ResourceWarning","RuntimeError","RuntimeWarning","StopAsyncIteration","StopIteration","SyntaxError","SyntaxWarning","SystemError","SystemExit","TabError","TimeoutError","TypeError","UnboundLocalError","UnicodeDecodeError","UnicodeEncodeError","UnicodeError","UnicodeTranslateError","UnicodeWarning","UserWarning","ValueError","Warning","ZeroDivisionError"].map(s=>({label:s,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(s=>({label:s,type:"class"}))).concat(["abs","aiter","all","anext","any","ascii","bin","breakpoint","callable","chr","compile","delattr","dict","dir","divmod","enumerate","eval","exec","exit","filter","format","getattr","globals","hasattr","hash","help","hex","id","input","isinstance","issubclass","iter","len","license","locals","max","min","next","oct","open","ord","pow","print","property","quit","repr","reversed","round","setattr","slice","sorted","sum","vars","zip"].map(s=>({label:s,type:"function"}))),CS=[Ee("def ${name}(${params}):\n ${}",{label:"def",detail:"function",type:"keyword"}),Ee("for ${name} in ${collection}:\n ${}",{label:"for",detail:"loop",type:"keyword"}),Ee("while ${}:\n ${}",{label:"while",detail:"loop",type:"keyword"}),Ee("try:\n ${}\nexcept ${error}:\n ${}",{label:"try",detail:"/ except block",type:"keyword"}),Ee(`if \${}:
10
-
11
- `,{label:"if",detail:"block",type:"keyword"}),Ee("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),Ee("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),Ee("import ${module}",{label:"import",detail:"statement",type:"keyword"}),Ee("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],MS=Dx(Og,cg(kS.concat(CS)));function xf(s,t){let e=s.baseIndentFor(t),i=s.lineAt(s.pos,-1),n=i.from+i.text.length;return/^\s*($|#)/.test(i.text)&&s.node.to<n+100&&!/\S/.test(s.state.sliceDoc(n,s.node.to))&&s.lineIndent(s.pos,-1)<=e||/^\s*(else:|elif |except |finally:)/.test(s.textAfter)&&s.lineIndent(s.pos,-1)>e?null:e+s.unit}const Ko=Yi.define({name:"python",parser:Ib.configure({props:[ao.add({Body:s=>{var t;return(t=xf(s,s.node))!==null&&t!==void 0?t:s.continue()},IfStatement:s=>/^\s*(else:|elif )/.test(s.textAfter)?s.baseIndent:s.continue(),TryStatement:s=>/^\s*(except |finally:|else:)/.test(s.textAfter)?s.baseIndent:s.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":wr({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":wr({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":wr({closing:"]"}),"String FormatString":()=>null,Script:s=>{if(s.pos+/\s*/.exec(s.textAfter)[0].length>=s.node.to){let t=null;for(let e=s.node,i=e.to;e=e.lastChild,!(!e||e.to!=i);)e.type.name=="Body"&&(t=e);if(t){let e=xf(s,t);if(e!=null)return e}}return s.continue()}}),ho.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":Sh,Body:(s,t)=>({from:s.from+1,to:s.to-(s.to==t.doc.length?0:1)})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""'],stringPrefixes:["f","fr","rf","r","u","b","br","rb","F","FR","RF","R","U","B","BR","RB"]},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:)$/}});function pD(){return new yh(Ko,[Ko.data.of({autocomplete:vS}),Ko.data.of({autocomplete:MS})])}var AS=s=>{var{theme:t,settings:e={},styles:i=[]}=s,n={".cm-gutters":{}},r={};e.background&&(r.backgroundColor=e.background),e.backgroundImage&&(r.backgroundImage=e.backgroundImage),e.foreground&&(r.color=e.foreground),e.fontSize&&(r.fontSize=e.fontSize),(e.background||e.foreground)&&(n["&"]=r),e.fontFamily&&(n["&.cm-editor .cm-scroller"]={fontFamily:e.fontFamily}),e.gutterBackground&&(n[".cm-gutters"].backgroundColor=e.gutterBackground),e.gutterForeground&&(n[".cm-gutters"].color=e.gutterForeground),e.gutterBorder&&(n[".cm-gutters"].borderRightColor=e.gutterBorder),e.caret&&(n[".cm-content"]={caretColor:e.caret},n[".cm-cursor, .cm-dropCursor"]={borderLeftColor:e.caret});var o={};e.gutterActiveForeground&&(o.color=e.gutterActiveForeground),e.lineHighlight&&(n[".cm-activeLine"]={backgroundColor:e.lineHighlight},o.backgroundColor=e.lineHighlight),n[".cm-activeLineGutter"]=o,e.selection&&(n["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:e.selection+" !important"}),e.selectionMatch&&(n["& .cm-selectionMatch"]={backgroundColor:e.selectionMatch});var l=T.theme(n,{dark:t==="dark"}),a=hn.define(i),c=[l,vh(a)];return c},DS={background:"#2e3440",foreground:"#FFFFFF",caret:"#FFFFFF",selection:"#00000073",selectionMatch:"#00000073",gutterBackground:"#2e3440",gutterForeground:"#4c566a",gutterActiveForeground:"#d8dee9",lineHighlight:"#4c566a29"},OS=[{tag:C.keyword,color:"#5e81ac"},{tag:[C.name,C.deleted,C.character,C.propertyName,C.macroName],color:"#88c0d0"},{tag:[C.variableName],color:"#8fbcbb"},{tag:[C.function(C.variableName)],color:"#8fbcbb"},{tag:[C.labelName],color:"#81a1c1"},{tag:[C.color,C.constant(C.name),C.standard(C.name)],color:"#5e81ac"},{tag:[C.definition(C.name),C.separator],color:"#a3be8c"},{tag:[C.brace],color:"#8fbcbb"},{tag:[C.annotation],color:"#d30102"},{tag:[C.number,C.changed,C.annotation,C.modifier,C.self,C.namespace],color:"#b48ead"},{tag:[C.typeName,C.className],color:"#ebcb8b"},{tag:[C.operator,C.operatorKeyword],color:"#a3be8c"},{tag:[C.tagName],color:"#b48ead"},{tag:[C.squareBracket],color:"#bf616a"},{tag:[C.angleBracket],color:"#d08770"},{tag:[C.attributeName],color:"#ebcb8b"},{tag:[C.regexp],color:"#5e81ac"},{tag:[C.quote],color:"#b48ead"},{tag:[C.string],color:"#a3be8c"},{tag:C.link,color:"#a3be8c",textDecoration:"underline",textUnderlinePosition:"under"},{tag:[C.url,C.escape,C.special(C.string)],color:"#8fbcbb"},{tag:[C.meta],color:"#88c0d0"},{tag:[C.monospace],color:"#d8dee9",fontStyle:"italic"},{tag:[C.comment],color:"#4c566a",fontStyle:"italic"},{tag:C.strong,fontWeight:"bold",color:"#5e81ac"},{tag:C.emphasis,fontStyle:"italic",color:"#5e81ac"},{tag:C.strikethrough,textDecoration:"line-through"},{tag:C.heading,fontWeight:"bold",color:"#5e81ac"},{tag:C.special(C.heading1),fontWeight:"bold",color:"#5e81ac"},{tag:C.heading1,fontWeight:"bold",color:"#5e81ac"},{tag:[C.heading2,C.heading3,C.heading4],fontWeight:"bold",color:"#5e81ac"},{tag:[C.heading5,C.heading6],color:"#5e81ac"},{tag:[C.atom,C.bool,C.special(C.variableName)],color:"#d08770"},{tag:[C.processingInstruction,C.inserted],color:"#8fbcbb"},{tag:[C.contentSeparator],color:"#ebcb8b"},{tag:C.invalid,color:"#434c5e",borderBottom:"1px dotted #d30102"}],TS=s=>{var{theme:t="dark",settings:e={},styles:i=[]}={};return AS({theme:t,settings:dd({},DS,e),styles:[...OS,...i]})},gD=TS();const BS=s=>{let{state:t}=s,e=t.doc.lineAt(t.selection.main.from),i=Ah(s.state,e.from);return i.line?ES(s):i.block?LS(s):!1};function Mh(s,t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=s(t,e);return n?(i(e.update(n)),!0):!1}}const ES=Mh(NS,0),RS=Mh(Tg,0),LS=Mh((s,t)=>Tg(s,t,$S(t)),0);function Ah(s,t){let e=s.languageDataAt("commentTokens",t);return e.length?e[0]:{}}const bn=50;function PS(s,{open:t,close:e},i,n){let r=s.sliceDoc(i-bn,i),o=s.sliceDoc(n,n+bn),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,c=r.length-l;if(r.slice(c-t.length,c)==t&&o.slice(a,a+e.length)==e)return{open:{pos:i-l,margin:l&&1},close:{pos:n+a,margin:a&&1}};let h,f;n-i<=2*bn?h=f=s.sliceDoc(i,n):(h=s.sliceDoc(i,i+bn),f=s.sliceDoc(n-bn,n));let u=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-e.length;return h.slice(u,u+t.length)==t&&f.slice(p,p+e.length)==e?{open:{pos:i+u+t.length,margin:/\s/.test(h.charAt(u+t.length))?1:0},close:{pos:n-d-e.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function $S(s){let t=[];for(let e of s.selection.ranges){let i=s.doc.lineAt(e.from),n=e.to<=i.to?i:s.doc.lineAt(e.to),r=t.length-1;r>=0&&t[r].to>i.from?t[r].to=n.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return t}function Tg(s,t,e=t.selection.ranges){let i=e.map(r=>Ah(t,r.from).block);if(!i.every(r=>r))return null;let n=e.map((r,o)=>PS(t,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:t.changes(e.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let a=i[o],{open:c,close:h}=l;r.push({from:c.pos-a.open.length,to:c.pos+c.margin},{from:h.pos-h.margin,to:h.pos+a.close.length})}return{changes:r}}return null}function NS(s,t,e=t.selection.ranges){let i=[],n=-1;for(let{from:r,to:o}of e){let l=i.length,a=1e9,c=Ah(t,r).line;if(c){for(let h=r;h<=o;){let f=t.doc.lineAt(h);if(f.from>n&&(r==o||o>f.from)){n=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+c.length)==c?u:-1;u<f.text.length&&u<a&&(a=u),i.push({line:f,comment:p,token:c,indent:u,empty:d,single:!1})}h=f.to+1}if(a<1e9)for(let h=l;h<i.length;h++)i[h].indent<i[h].line.text.length&&(i[h].indent=a);i.length==l+1&&(i[l].single=!0)}}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:c,empty:h,single:f}of i)(f||!h)&&r.push({from:l.from+c,insert:a+" "});let o=t.changes(r);return{changes:o,selection:t.selection.map(o,1)}}else if(s!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let c=o.from+l,h=c+a.length;o.text[h-o.from]==" "&&h++,r.push({from:c,to:h})}return{changes:r}}return null}const ea=Vt.define(),HS=Vt.define(),FS=v.define(),Bg=v.define({combine(s){return De(s,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}}),Eg=ct.define({create(){return Se.empty},update(s,t){let e=t.state.facet(Bg),i=t.annotation(ea);if(i){let a=Lt.fromTransaction(t,i.selection),c=i.side,h=c==0?s.undone:s.done;return a?h=Wr(h,h.length,e.minDepth,a):h=Pg(h,t.startState.selection),new Se(c==0?i.rest:h,c==0?h:i.rest)}let n=t.annotation(HS);if((n=="full"||n=="before")&&(s=s.isolate()),t.annotation(it.addToHistory)===!1)return t.changes.empty?s:s.addMapping(t.changes.desc);let r=Lt.fromTransaction(t),o=t.annotation(it.time),l=t.annotation(it.userEvent);return r?s=s.addChanges(r,o,l,e,t):t.selection&&(s=s.addSelection(t.startState.selection,o,l,e.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(t=>t.toJSON()),undone:s.undone.map(t=>t.toJSON())}},fromJSON(s){return new Se(s.done.map(Lt.fromJSON),s.undone.map(Lt.fromJSON))}});function IS(s={}){return[Eg,Bg.of(s),T.domEventHandlers({beforeinput(t,e){let i=t.inputType=="historyUndo"?Rg:t.inputType=="historyRedo"?ia:null;return i?(t.preventDefault(),i(e)):!1}})]}function po(s,t){return function({state:e,dispatch:i}){if(!t&&e.readOnly)return!1;let n=e.field(Eg,!1);if(!n)return!1;let r=n.pop(s,e,t);return r?(i(r),!0):!1}}const Rg=po(0,!1),ia=po(1,!1),VS=po(0,!0),WS=po(1,!0);class Lt{constructor(t,e,i,n,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(t){return new Lt(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(e=this.mapped)===null||e===void 0?void 0:e.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(t){return new Lt(t.changes&&et.fromJSON(t.changes),[],t.mapped&&ke.fromJSON(t.mapped),t.startSelection&&w.fromJSON(t.startSelection),t.selectionsAfter.map(w.fromJSON))}static fromTransaction(t,e){let i=Kt;for(let n of t.startState.facet(FS)){let r=n(t);r.length&&(i=i.concat(r))}return!i.length&&t.changes.empty?null:new Lt(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Kt)}static selection(t){return new Lt(void 0,Kt,void 0,void 0,t)}}function Wr(s,t,e,i){let n=t+1>e+20?t-e-1:0,r=s.slice(n,t);return r.push(i),r}function zS(s,t){let e=[],i=!1;return s.iterChangedRanges((n,r)=>e.push(n,r)),t.iterChangedRanges((n,r,o,l)=>{for(let a=0;a<e.length;){let c=e[a++],h=e[a++];l>=c&&o<=h&&(i=!0)}}),i}function KS(s,t){return s.ranges.length==t.ranges.length&&s.ranges.filter((e,i)=>e.empty!=t.ranges[i].empty).length===0}function Lg(s,t){return s.length?t.length?s.concat(t):s:t}const Kt=[],qS=200;function Pg(s,t){if(s.length){let e=s[s.length-1],i=e.selectionsAfter.slice(Math.max(0,e.selectionsAfter.length-qS));return i.length&&i[i.length-1].eq(t)?s:(i.push(t),Wr(s,s.length-1,1e9,e.setSelAfter(i)))}else return[Lt.selection([t])]}function jS(s){let t=s[s.length-1],e=s.slice();return e[s.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),e}function qo(s,t){if(!s.length)return s;let e=s.length,i=Kt;for(;e;){let n=GS(s[e-1],t,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,e);return r[e-1]=n,r}else t=n.mapped,e--,i=n.selectionsAfter}return i.length?[Lt.selection(i)]:Kt}function GS(s,t,e){let i=Lg(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(t)):Kt,e);if(!s.changes)return Lt.selection(i);let n=s.changes.map(t),r=t.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new Lt(n,R.mapEffects(s.effects,t),o,s.startSelection.map(r),i)}const US=/^(input\.type|delete)($|\.)/;class Se{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Se(this.done,this.undone):this}addChanges(t,e,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!i||US.test(i))&&(!l.selectionsAfter.length&&e-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,zS(l.changes,t.changes))||i=="input.type.compose")?o=Wr(o,o.length-1,n.minDepth,new Lt(t.changes.compose(l.changes),Lg(t.effects,l.effects),l.mapped,l.startSelection,Kt)):o=Wr(o,o.length,n.minDepth,t),new Se(o,Kt,e,i)}addSelection(t,e,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Kt;return r.length>0&&e-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&KS(r[r.length-1],t)?this:new Se(Pg(this.done,t),this.undone,e,i)}addMapping(t){return new Se(qo(this.done,t),qo(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=t==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:ea.of({side:t,rest:jS(n),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?Kt:n.slice(0,n.length-1);return r.mapped&&(l=qo(l,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:ea.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}Se.empty=new Se(Kt,Kt);const YS=[{key:"Mod-z",run:Rg,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:ia,preventDefault:!0},{linux:"Ctrl-Shift-z",run:ia,preventDefault:!0},{key:"Mod-u",run:VS,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:WS,preventDefault:!0}];function cn(s,t){return w.create(s.ranges.map(t),s.mainIndex)}function Te(s,t){return s.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function fe({state:s,dispatch:t},e){let i=cn(s.selection,e);return i.eq(s.selection,!0)?!1:(t(Te(s,i)),!0)}function go(s,t){return w.cursor(t?s.to:s.from)}function $g(s,t){return fe(s,e=>e.empty?s.moveByChar(e,t):go(e,t))}function bt(s){return s.textDirectionAt(s.state.selection.main.head)==Q.LTR}const Ng=s=>$g(s,!bt(s)),Hg=s=>$g(s,bt(s));function Fg(s,t){return fe(s,e=>e.empty?s.moveByGroup(e,t):go(e,t))}const XS=s=>Fg(s,!bt(s)),_S=s=>Fg(s,bt(s));function JS(s,t,e){if(t.type.prop(e))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(t.from,t.to)))||t.firstChild}function mo(s,t,e){let i=rt(s).resolveInner(t.head),n=e?jt.closedBy:jt.openedBy;for(let a=t.head;;){let c=e?i.childAfter(a):i.childBefore(a);if(!c)break;JS(s,c,n)?i=c:a=e?c.to:c.from}let r=i.type.prop(n),o,l;return r&&(o=e?xe(s,i.from,1):xe(s,i.to,-1))&&o.matched?l=e?o.end.to:o.end.from:l=e?i.to:i.from,w.cursor(l,e?-1:1)}const QS=s=>fe(s,t=>mo(s.state,t,!bt(s))),ZS=s=>fe(s,t=>mo(s.state,t,bt(s)));function Ig(s,t){return fe(s,e=>{if(!e.empty)return go(e,t);let i=s.moveVertically(e,t);return i.head!=e.head?i:s.moveToLineBoundary(e,t)})}const Vg=s=>Ig(s,!1),Wg=s=>Ig(s,!0);function zg(s){let t=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,e=0,i=0,n;if(t){for(let r of s.state.facet(T.scrollMargins)){let o=r(s);o!=null&&o.top&&(e=Math.max(o==null?void 0:o.top,e)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}n=s.scrollDOM.clientHeight-e-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:e,marginBottom:i,selfScroll:t,height:Math.max(s.defaultLineHeight,n-5)}}function Kg(s,t){let e=zg(s),{state:i}=s,n=cn(i.selection,o=>o.empty?s.moveVertically(o,t,e.height):go(o,t));if(n.eq(i.selection))return!1;let r;if(e.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),a=l.top+e.marginTop,c=l.bottom-e.marginBottom;o&&o.top>a&&o.bottom<c&&(r=T.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-a}))}return s.dispatch(Te(i,n),{effects:r}),!0}const Sf=s=>Kg(s,!1),na=s=>Kg(s,!0);function li(s,t,e){let i=s.lineBlockAt(t.head),n=s.moveToLineBoundary(t,e);if(n.head==t.head&&n.head!=(e?i.to:i.from)&&(n=s.moveToLineBoundary(t,e,!1)),!e&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&t.head!=i.from+r&&(n=w.cursor(i.from+r))}return n}const tv=s=>fe(s,t=>li(s,t,!0)),ev=s=>fe(s,t=>li(s,t,!1)),iv=s=>fe(s,t=>li(s,t,!bt(s))),nv=s=>fe(s,t=>li(s,t,bt(s))),sv=s=>fe(s,t=>w.cursor(s.lineBlockAt(t.head).from,1)),rv=s=>fe(s,t=>w.cursor(s.lineBlockAt(t.head).to,-1));function ov(s,t,e){let i=!1,n=cn(s.selection,r=>{let o=xe(s,r.head,-1)||xe(s,r.head,1)||r.head>0&&xe(s,r.head-1,1)||r.head<s.doc.length&&xe(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return w.cursor(l)});return i?(t(Te(s,n)),!0):!1}const lv=({state:s,dispatch:t})=>ov(s,t);function Jt(s,t){let e=cn(s.state.selection,i=>{let n=t(i);return w.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)});return e.eq(s.state.selection)?!1:(s.dispatch(Te(s.state,e)),!0)}function qg(s,t){return Jt(s,e=>s.moveByChar(e,t))}const jg=s=>qg(s,!bt(s)),Gg=s=>qg(s,bt(s));function Ug(s,t){return Jt(s,e=>s.moveByGroup(e,t))}const av=s=>Ug(s,!bt(s)),hv=s=>Ug(s,bt(s)),cv=s=>Jt(s,t=>mo(s.state,t,!bt(s))),fv=s=>Jt(s,t=>mo(s.state,t,bt(s)));function Yg(s,t){return Jt(s,e=>s.moveVertically(e,t))}const Xg=s=>Yg(s,!1),_g=s=>Yg(s,!0);function Jg(s,t){return Jt(s,e=>s.moveVertically(e,t,zg(s).height))}const vf=s=>Jg(s,!1),kf=s=>Jg(s,!0),uv=s=>Jt(s,t=>li(s,t,!0)),dv=s=>Jt(s,t=>li(s,t,!1)),pv=s=>Jt(s,t=>li(s,t,!bt(s))),gv=s=>Jt(s,t=>li(s,t,bt(s))),mv=s=>Jt(s,t=>w.cursor(s.lineBlockAt(t.head).from)),bv=s=>Jt(s,t=>w.cursor(s.lineBlockAt(t.head).to)),Cf=({state:s,dispatch:t})=>(t(Te(s,{anchor:0})),!0),Mf=({state:s,dispatch:t})=>(t(Te(s,{anchor:s.doc.length})),!0),Af=({state:s,dispatch:t})=>(t(Te(s,{anchor:s.selection.main.anchor,head:0})),!0),Df=({state:s,dispatch:t})=>(t(Te(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),yv=({state:s,dispatch:t})=>(t(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),wv=({state:s,dispatch:t})=>{let e=bo(s).map(({from:i,to:n})=>w.range(i,Math.min(n+1,s.doc.length)));return t(s.update({selection:w.create(e),userEvent:"select"})),!0},xv=({state:s,dispatch:t})=>{let e=cn(s.selection,i=>{var n;let r=rt(s).resolveStack(i.from,1);for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&(!((n=l.parent)===null||n===void 0)&&n.parent))return w.range(l.to,l.from)}return i});return t(Te(s,e)),!0},Sv=({state:s,dispatch:t})=>{let e=s.selection,i=null;return e.ranges.length>1?i=w.create([e.main]):e.main.empty||(i=w.create([w.cursor(e.main.head)])),i?(t(Te(s,i)),!0):!1};function ys(s,t){if(s.state.readOnly)return!1;let e="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=t(r);a<o?(e="delete.backward",a=Fs(s,a,!1)):a>o&&(e="delete.forward",a=Fs(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Fs(s,o,!1),l=Fs(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:w.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:e,effects:e=="delete.selection"?T.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Fs(s,t,e){if(s instanceof T)for(let i of s.state.facet(T.atomicRanges).map(n=>n(s)))i.between(t,t,(n,r)=>{n<t&&r>t&&(t=e?r:n)});return t}const Qg=(s,t,e)=>ys(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,a;if(e&&!t&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let c=ln(l,r.tabSize),h=c%Nr(r)||Nr(r);for(let f=0;f<h&&l[l.length-1-f]==" ";f++)n--;a=n}else a=V(o.text,n-o.from,t,t)+o.from,a==n&&o.number!=(t?r.doc.lines:1)?a+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,n-o.from))&&(a=V(o.text,a-o.from,!1,!1)+o.from);return a}),sa=s=>Qg(s,!1,!0),Zg=s=>Qg(s,!0,!1),tm=(s,t)=>ys(s,e=>{let i=e.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(t?r.to:r.from)){i==e.head&&r.number!=(t?n.doc.lines:1)&&(i+=t?1:-1);break}let a=V(r.text,i-r.from,t)+r.from,c=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),h=o(c);if(l!=null&&h!=l)break;(c!=" "||i!=e.head)&&(l=h),i=a}return i}),em=s=>tm(s,!1),vv=s=>tm(s,!0),kv=s=>ys(s,t=>{let e=s.lineBlockAt(t.head).to;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),Cv=s=>ys(s,t=>{let e=s.moveToLineBoundary(t,!1).head;return t.head>e?e:Math.max(0,t.head-1)}),Mv=s=>ys(s,t=>{let e=s.moveToLineBoundary(t,!0).head;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),Av=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:B.of(["",""])},range:w.cursor(i.from)}));return t(s.update(e,{scrollIntoView:!0,userEvent:"input"})),!0},Dv=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=s.changeByRange(i=>{if(!i.empty||i.from==0||i.from==s.doc.length)return{range:i};let n=i.from,r=s.doc.lineAt(n),o=n==r.from?n-1:V(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:V(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:w.cursor(l)}});return e.changes.empty?!1:(t(s.update(e,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function bo(s){let t=[],e=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.from),r=s.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=s.doc.lineAt(i.to-1)),e>=n.number){let o=t[t.length-1];o.to=r.to,o.ranges.push(i)}else t.push({from:n.from,to:r.to,ranges:[i]});e=r.number+1}return t}function im(s,t,e){if(s.readOnly)return!1;let i=[],n=[];for(let r of bo(s)){if(e?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(e?r.to+1:r.from-1),l=o.length+1;if(e){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let a of r.ranges)n.push(w.range(Math.min(s.doc.length,a.anchor+l),Math.min(s.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let a of r.ranges)n.push(w.range(a.anchor-l,a.head-l))}}return i.length?(t(s.update({changes:i,scrollIntoView:!0,selection:w.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Ov=({state:s,dispatch:t})=>im(s,t,!1),Tv=({state:s,dispatch:t})=>im(s,t,!0);function nm(s,t,e){if(s.readOnly)return!1;let i=[];for(let n of bo(s))e?i.push({from:n.from,insert:s.doc.slice(n.from,n.to)+s.lineBreak}):i.push({from:n.to,insert:s.lineBreak+s.doc.slice(n.from,n.to)});return t(s.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Bv=({state:s,dispatch:t})=>nm(s,t,!1),Ev=({state:s,dispatch:t})=>nm(s,t,!0),Rv=s=>{if(s.state.readOnly)return!1;let{state:t}=s,e=t.changes(bo(t).map(({from:n,to:r})=>(n>0?n--:r<t.doc.length&&r++,{from:n,to:r}))),i=cn(t.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(e);return s.dispatch({changes:e,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Lv(s,t){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(t-1,t+1)))return{from:t,to:t};let e=rt(s).resolveInner(t),i=e.childBefore(t),n=e.childAfter(t),r;return i&&n&&i.to<=t&&n.from>=t&&(r=i.type.prop(jt.closedBy))&&r.indexOf(n.name)>-1&&s.doc.lineAt(i.to).from==s.doc.lineAt(n.from).from&&!/\S/.test(s.sliceDoc(i.to,n.from))?{from:i.to,to:n.from}:null}const Pv=sm(!1),$v=sm(!0);function sm(s){return({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(n=>{let{from:r,to:o}=n,l=t.doc.lineAt(r),a=!s&&r==o&&Lv(t,r);s&&(r=o=(o<=l.to?l:t.doc.lineAt(o)).to);let c=new lo(t,{simulateBreak:r,simulateDoubleBreak:!!a}),h=wh(c,r);for(h==null&&(h=ln(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",Zn(t,h)];return a&&f.push(Zn(t,c.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:B.of(f)},range:w.cursor(r+1+f[1].length)}});return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Dh(s,t){let e=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>e&&(i.empty||i.to>l.from)&&(t(l,n,i),e=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:w.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Nv=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=Object.create(null),i=new lo(s,{overrideIndentation:r=>{let o=e[r];return o??-1}}),n=Dh(s,(r,o,l)=>{let a=wh(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let c=/^\s*/.exec(r.text)[0],h=Zn(s,a);(c!=h||l.from<r.from+c.length)&&(e[r.from]=a,o.push({from:r.from,to:r.from+c.length,insert:h}))});return n.changes.empty||t(s.update(n,{userEvent:"indent"})),!0},rm=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Dh(s,(e,i)=>{i.push({from:e.from,insert:s.facet(an)})}),{userEvent:"input.indent"})),!0),om=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Dh(s,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let r=ln(n,s.tabSize),o=0,l=Zn(s,Math.max(0,r-Nr(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:e.from+o,to:e.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Hv=s=>(s.setTabFocusMode(),!0),Fv=[{key:"Ctrl-b",run:Ng,shift:jg,preventDefault:!0},{key:"Ctrl-f",run:Hg,shift:Gg},{key:"Ctrl-p",run:Vg,shift:Xg},{key:"Ctrl-n",run:Wg,shift:_g},{key:"Ctrl-a",run:sv,shift:mv},{key:"Ctrl-e",run:rv,shift:bv},{key:"Ctrl-d",run:Zg},{key:"Ctrl-h",run:sa},{key:"Ctrl-k",run:kv},{key:"Ctrl-Alt-h",run:em},{key:"Ctrl-o",run:Av},{key:"Ctrl-t",run:Dv},{key:"Ctrl-v",run:na}],Iv=[{key:"ArrowLeft",run:Ng,shift:jg,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:XS,shift:av,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:iv,shift:pv,preventDefault:!0},{key:"ArrowRight",run:Hg,shift:Gg,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:_S,shift:hv,preventDefault:!0},{mac:"Cmd-ArrowRight",run:nv,shift:gv,preventDefault:!0},{key:"ArrowUp",run:Vg,shift:Xg,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Cf,shift:Af},{mac:"Ctrl-ArrowUp",run:Sf,shift:vf},{key:"ArrowDown",run:Wg,shift:_g,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Mf,shift:Df},{mac:"Ctrl-ArrowDown",run:na,shift:kf},{key:"PageUp",run:Sf,shift:vf},{key:"PageDown",run:na,shift:kf},{key:"Home",run:ev,shift:dv,preventDefault:!0},{key:"Mod-Home",run:Cf,shift:Af},{key:"End",run:tv,shift:uv,preventDefault:!0},{key:"Mod-End",run:Mf,shift:Df},{key:"Enter",run:Pv},{key:"Mod-a",run:yv},{key:"Backspace",run:sa,shift:sa},{key:"Delete",run:Zg},{key:"Mod-Backspace",mac:"Alt-Backspace",run:em},{key:"Mod-Delete",mac:"Alt-Delete",run:vv},{mac:"Mod-Backspace",run:Cv},{mac:"Mod-Delete",run:Mv}].concat(Fv.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),Vv=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:QS,shift:cv},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:ZS,shift:fv},{key:"Alt-ArrowUp",run:Ov},{key:"Shift-Alt-ArrowUp",run:Bv},{key:"Alt-ArrowDown",run:Tv},{key:"Shift-Alt-ArrowDown",run:Ev},{key:"Escape",run:Sv},{key:"Mod-Enter",run:$v},{key:"Alt-l",mac:"Ctrl-l",run:wv},{key:"Mod-i",run:xv,preventDefault:!0},{key:"Mod-[",run:om},{key:"Mod-]",run:rm},{key:"Mod-Alt-\\",run:Nv},{key:"Shift-Mod-k",run:Rv},{key:"Shift-Mod-\\",run:lv},{key:"Mod-/",run:BS},{key:"Alt-A",run:RS},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Hv}].concat(Iv),Wv={key:"Tab",run:rm,shift:om};function ns(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function ra(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function xr(s,t){if(!t.anchorNode)return!1;try{return ra(s,t.anchorNode)}catch{return!1}}function ss(s){return s.nodeType==3?wi(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function zn(s,t,e,i){return e?Of(s,t,e,i,-1)||Of(s,t,e,i,1):!1}function yi(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function zr(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Of(s,t,e,i,n){for(;;){if(s==e&&t==i)return!0;if(t==(n<0?0:Ae(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;t=yi(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[t+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;t=n<0?Ae(s):0}else return!1}}function Ae(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function yo(s,t){let e=t?s.left:s.right;return{left:e,right:e,top:s.top,bottom:s.bottom}}function zv(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function lm(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function Kv(s,t,e,i,n,r,o,l){let a=s.ownerDocument,c=a.defaultView||window;for(let h=s,f=!1;h&&!f;)if(h.nodeType==1){let u,d=h==a.body,p=1,g=1;if(d)u=zv(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(f=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let y=h.getBoundingClientRect();({scaleX:p,scaleY:g}=lm(h,y)),u={left:y.left,right:y.left+h.clientWidth*p,top:y.top,bottom:y.top+h.clientHeight*g}}let b=0,m=0;if(n=="nearest")t.top<u.top?(m=-(u.top-t.top+o),e>0&&t.bottom>u.bottom+m&&(m=t.bottom-u.bottom+m+o)):t.bottom>u.bottom&&(m=t.bottom-u.bottom+o,e<0&&t.top-m<u.top&&(m=-(u.top+m-t.top+o)));else{let y=t.bottom-t.top,S=u.bottom-u.top;m=(n=="center"&&y<=S?t.top+y/2-S/2:n=="start"||n=="center"&&e<0?t.top-o:t.bottom-S+o)-u.top}if(i=="nearest"?t.left<u.left?(b=-(u.left-t.left+r),e>0&&t.right>u.right+b&&(b=t.right-u.right+b+r)):t.right>u.right&&(b=t.right-u.right+r,e<0&&t.left<u.left+b&&(b=-(u.left+b-t.left+r))):b=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-r:t.right-(u.right-u.left)+r)-u.left,b||m)if(d)c.scrollBy(b,m);else{let y=0,S=0;if(m){let x=h.scrollTop;h.scrollTop+=m/g,S=(h.scrollTop-x)*g}if(b){let x=h.scrollLeft;h.scrollLeft+=b/p,y=(h.scrollLeft-x)*p}t={left:t.left-y,top:t.top-S,right:t.right-y,bottom:t.bottom-S},y&&Math.abs(y-b)<1&&(i="nearest"),S&&Math.abs(S-m)<1&&(n="nearest")}if(d)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function qv(s){let t=s.ownerDocument,e,i;for(let n=s.parentNode;n&&!(n==t.body||e&&i);)if(n.nodeType==1)!i&&n.scrollHeight>n.clientHeight&&(i=n),!e&&n.scrollWidth>n.clientWidth&&(e=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:e,y:i}}let jv=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?Ae(e):0),i,Math.min(t.focusOffset,i?Ae(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}},Mi=null;function am(s){if(s.setActive)return s.setActive();if(Mi)return s.focus(Mi);let t=[];for(let e=s;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(s.focus(Mi==null?{get preventScroll(){return Mi={preventScroll:!0},!0}}:void 0),!Mi){Mi=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Tf;function wi(s,t,e=t){let i=Tf||(Tf=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function Fi(s,t,e,i){let n={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Gv(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function hm(s){for(;s.attributes.length;)s.removeAttributeNode(s.attributes[0])}function Uv(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,Ae(e));;)if(i){if(e.nodeType!=1)return!1;let n=e.childNodes[i-1];n.contentEditable=="false"?i--:(e=n,i=Ae(e))}else{if(e==s)return!0;i=yi(e),e=e.parentNode}}function cm(s){return s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function fm(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=Ae(e)}else if(e.parentNode&&!zr(e))i=yi(e),e=e.parentNode;else return null}}function um(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!zr(e))i=yi(e)+1,e=e.parentNode;else return null}}let Ft=class oa{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new oa(t.parentNode,yi(t),e)}static after(t,e){return new oa(t.parentNode,yi(t)+1,e)}};const Oh=[];let tt=class la{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,n=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=n?n.nextSibling:i.firstChild)){let l=la.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=n?n.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=Bf(r);else i.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=Bf(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let n=Ae(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;n==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?n=-1:n=1),t=r}n<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!la.get(i);)i=i.nextSibling;if(!i)return this.length;for(let n=0,r=0;;n++){let o=this.children[n];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(t,e,i=0){let n=-1,r=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<this.children.length;a++){let f=this.children[a],u=c+f.length;if(c<t&&u>e)return f.domBoundsAround(t,e,c);if(u>=t&&n==-1&&(n=a,r=c),c>e&&f.dom.parentNode==this.dom){o=a,l=h;break}h=u,c=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=Oh){this.markDirty();for(let n=t;n<e;n++){let r=this.children[n];r.parent==this&&i.indexOf(r)<0&&r.destroy()}i.length<250?this.children.splice(t,e-t,...i):this.children=[].concat(this.children.slice(0,t),i,this.children.slice(e));for(let n=0;n<i.length;n++)i[n].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new dm(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,n,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}};tt.prototype.breakAfter=0;function Bf(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}let dm=class{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}};function pm(s,t,e,i,n,r,o,l,a){let{children:c}=s,h=c.length?c[t]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(t==i&&h&&!o&&!u&&r.length<2&&h.merge(e,n,r.length?f:null,e==0,l,a))){if(i<c.length){let d=c[i];d&&(n<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(t==i&&(d=d.split(n),n=0),!u&&f&&d.merge(0,n,f,!0,0,a)?r[r.length-1]=d:((n||d.children.length&&!d.children[0].length)&&d.merge(0,n,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(h&&(h.breakAfter=o,e>0&&(!o&&r.length&&h.merge(e,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(e<h.length||h.children.length&&h.children[h.children.length-1].length==0)&&h.merge(e,h.length,null,!1,l,0),t++));t<i&&r.length;)if(c[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(c[t].become(r[0]))t++,r.shift(),l=r.length?0:a;else break;!r.length&&t&&i<c.length&&!c[t-1].breakAfter&&c[i].merge(0,0,c[t-1],!1,l,a)&&t--,(t<i||r.length)&&s.replaceChildren(t,i,r)}}function gm(s,t,e,i,n,r){let o=s.childCursor(),{i:l,off:a}=o.findPos(e,1),{i:c,off:h}=o.findPos(t,-1),f=t-e;for(let u of i)f+=u.length;s.length+=f,pm(s,c,h,l,a,i,0,n,r)}let Bt=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},aa=typeof document<"u"?document:{documentElement:{style:{}}};const ha=/Edge\/(\d+)/.exec(Bt.userAgent),mm=/MSIE \d/.test(Bt.userAgent),ca=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Bt.userAgent),wo=!!(mm||ca||ha),Ef=!wo&&/gecko\/(\d+)/i.test(Bt.userAgent),jo=!wo&&/Chrome\/(\d+)/.exec(Bt.userAgent),Rf="webkitFontSmoothing"in aa.documentElement.style,bm=!wo&&/Apple Computer/.test(Bt.vendor),Lf=bm&&(/Mobile\/\w+/.test(Bt.userAgent)||Bt.maxTouchPoints>2);var D={mac:Lf||/Mac/.test(Bt.platform),windows:/Win/.test(Bt.platform),linux:/Linux|X11/.test(Bt.platform),ie:wo,ie_version:mm?aa.documentMode||6:ca?+ca[1]:ha?+ha[1]:0,gecko:Ef,gecko_version:Ef?+(/Firefox\/(\d+)/.exec(Bt.userAgent)||[0,0])[1]:0,chrome:!!jo,chrome_version:jo?+jo[1]:0,ios:Lf,android:/Android\b/.test(Bt.userAgent),webkit:Rf,safari:bm,webkit_version:Rf?+(/\bAppleWebKit\/(\d+)/.exec(Bt.userAgent)||[0,0])[1]:0,tabSize:aa.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const Yv=256;let ri=class fa extends tt{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof fa)||this.length-(e-t)+i.length>Yv||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new fa(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Ft(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return Xv(this.dom,t,e)}},_i=class ua extends tt{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let n of e)n.setParent(this)}setAttrs(t){if(hm(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,r,o){return i&&(!(i instanceof ua&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(gm(this,t,e,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,n=-1,r=0;for(let l of this.children){let a=i+l.length;a>t&&e.push(i<t?l.split(t-i):l),n<0&&i>=t&&(n=r),i=a,r++}let o=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new ua(this.mark,e,o)}domAtPos(t){return wm(this,t)}coordsAt(t,e){return Sm(this,t,e)}};function Xv(s,t,e){let i=s.nodeValue.length;t>i&&(t=i);let n=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?D.chrome||D.gecko||(t?(n--,o=1):r<i&&(r++,o=-1)):e<0?n--:r<i&&r++;let l=wi(s,n,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:e>=0)?0:l.length-1];return D.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,c=>c.width)||a),o?yo(a,o<0):a||null}let ym=class An extends tt{static create(t,e,i){return new An(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=An.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,r,o){return i&&(!(i instanceof An)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof An&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return B.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,n=this.posAtStart;return i?i.slice(n,n+this.length):B.empty}domAtPos(t){return(this.length?t==0:this.side>0)?Ft.before(this.dom):Ft.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?n.length-1:0;r=n[l],!(t>0?l==0:l==n.length-1||r.top<r.bottom);l+=o?-1:1);return yo(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},da=class pa extends tt{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof pa&&t.side==this.side}split(){return new pa(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?Ft.before(this.dom):Ft.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return B.empty}get isHidden(){return!0}};ri.prototype.children=ym.prototype.children=da.prototype.children=Oh;function wm(s,t){let e=s.dom,{children:i}=s,n=0;for(let r=0;n<i.length;n++){let o=i[n],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=n;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=n;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new Ft(e,0)}function xm(s,t,e){let i,{children:n}=s;e>0&&t instanceof _i&&n.length&&(i=n[n.length-1])instanceof _i&&i.mark.eq(t.mark)?xm(i,t.children[0],e-1):(n.push(t),t.setParent(s)),s.length+=t.length}function Sm(s,t,e){let i=null,n=-1,r=null,o=-1;function l(c,h){for(let f=0,u=0;f<c.children.length&&u<=h;f++){let d=c.children[f],p=u+d.length;p>=h&&(d.children.length?l(d,h-u):(!r||r.isHidden&&e>0)&&(p>h||u==p&&d.getSide()>0)?(r=d,o=h-u):(u<h||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,n=h-u)),u=p}}l(s,t);let a=(e<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?n:o),e):_v(s)}function _v(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=ss(t);return e[e.length-1]||null}function ga(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}const Pf=Object.create(null);function Kr(s,t,e){if(s==t)return!0;s||(s=Pf),t||(t=Pf);let i=Object.keys(s),n=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=n.length-(e&&n.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(n.indexOf(r)==-1||s[r]!==t[r]))return!1;return!0}function ma(s,t,e){let i=!1;if(t)for(let n in t)e&&n in e||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(i=!0,n=="style"?s.style.cssText=e[n]:s.setAttribute(n,e[n]));return i}function Jv(s){let t=Object.create(null);for(let e=0;e<s.attributes.length;e++){let i=s.attributes[e];t[i.name]=i.value}return t}let Th=class{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}};var Ce=function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s}(Ce||(Ce={}));let U=class extends Gt{constructor(t,e,i,n){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(t){return new Bh(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new Ji(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,n;if(t.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=Mm(t,e);i=(r?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new Ji(t,i,n,e,t.widget||null,!0)}static line(t){return new Eh(t)}static set(t,e=!1){return E.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};U.none=E.empty;let Bh=class vm extends U{constructor(t){let{start:e,end:i}=Mm(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof vm&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&Kr(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}};Bh.prototype.point=!1;let Eh=class km extends U{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof km&&this.spec.class==t.spec.class&&Kr(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}};Eh.prototype.mapMode=I.TrackBefore;Eh.prototype.point=!0;let Ji=class Cm extends U{constructor(t,e,i,n,r,o){super(e,i,r,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?I.TrackBefore:I.TrackAfter:I.TrackDel}get type(){return this.startSide!=this.endSide?Ce.WidgetRange:this.startSide<=0?Ce.WidgetBefore:Ce.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Cm&&Qv(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}};Ji.prototype.point=!0;function Mm(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function Qv(s,t){return s==t||!!(s&&t&&s.compare(t))}function ba(s,t,e,i=0){let n=e.length-1;n>=0&&e[n]+i>=s?e[n]=Math.max(e[n],t):e.push(s,t)}let wt=class Dn extends tt{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,r,o){if(i){if(!(i instanceof Dn))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),gm(this,t,e,i?i.children.slice():[],r,o),!0}split(t){let e=new Dn;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:n}=this.childPos(t);n&&(e.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Kr(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){xm(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=ga(e,this.attrs||{})),i&&(this.attrs=ga({class:i},this.attrs||{}))}domAtPos(t){return wm(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(hm(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(ma(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&tt.get(n)instanceof _i;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=tt.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!D.ios||!this.children.some(r=>r instanceof ri))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof ri)||/[^ -~]/.test(i.text))return null;let n=ss(i.dom);if(n.length!=1)return null;t+=n[0].width,e=n[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=Sm(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:n}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-n.lineHeight)<2&&n.textHeight<r){let o=(r-n.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(t){return t instanceof Dn&&this.children.length==0&&t.children.length==0&&Kr(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,n=0;i<t.children.length;i++){let r=t.children[i],o=n+r.length;if(o>=e){if(r instanceof Dn)return r;if(o>e)break}n=o+r.breakAfter}return null}},Kn=class Sr extends tt{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,r,o){return i&&(!(i instanceof Sr)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?Ft.before(this.dom):Ft.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new Sr(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Oh}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):B.empty}domBoundsAround(){return null}become(t){return t instanceof Sr&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);return i||(this.widget instanceof ya?null:yo(this.dom.getBoundingClientRect(),this.length?t==0:e<=0))}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}},ya=class extends Th{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},Go=class Am{constructor(t,e,i,n){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof Kn&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new wt),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Is(new da(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof Kn)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Is(new ri(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof Ji){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof Ji)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Kn(i.widget||Qi.block,l,i));else{let a=ym.create(i.widget||Qi.inline,l,l?0:i.startSide),c=this.atCursorPos&&!a.isEditable&&r<=n.length&&(t<e||i.startSide>0),h=!a.isEditable&&(t<e||r>n.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!c&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),c&&(f.append(Is(new da(1),n),r),r=n.length+Math.max(0,r-n.length)),f.append(Is(a,n),r),this.atCursorPos=h,this.pendingBuffer=h?t<e||r>n.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,n,r){let o=new Am(t,e,i,r);return o.openEnd=E.spans(n,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function Is(s,t){for(let e of t)s=new _i(e,[s],s.length);return s}let Qi=class extends Th{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};Qi.inline=new Qi("span");Qi.block=new Qi("div");var St=function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s}(St||(St={}));const xi=St.LTR,Rh=St.RTL;function Dm(s){let t=[];for(let e=0;e<s.length;e++)t.push(1<<+s[e]);return t}const Zv=Dm("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),tk=Dm("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),wa=Object.create(null),pe=[];for(let s of["()","[]","{}"]){let t=s.charCodeAt(0),e=s.charCodeAt(1);wa[t]=e,wa[e]=-t}function Om(s){return s<=247?Zv[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?tk[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const ek=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;let _e=class{get dir(){return this.level%2?Rh:xi}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,n){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}};function Tm(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++){let i=s[e],n=t[e];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!Tm(i.inner,n.inner))return!1}return!0}const K=[];function ik(s,t,e,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,a=r?256:n;for(let c=o,h=a,f=a;c<l;c++){let u=Om(s.charCodeAt(c));u==512?u=h:u==8&&f==4&&(u=16),K[c]=u==4?2:u,u&7&&(f=u),h=u}for(let c=o,h=a,f=a;c<l;c++){let u=K[c];if(u==128)c<l-1&&h==K[c+1]&&h&24?u=K[c]=h:K[c]=256;else if(u==64){let d=c+1;for(;d<l&&K[d]==64;)d++;let p=c&&h==8||d<e&&K[d]==8?f==1?1:8:256;for(let g=c;g<d;g++)K[g]=p;c=d-1}else u==8&&f==1&&(K[c]=1);h=u,u&7&&(f=u)}}}function nk(s,t,e,i,n){let r=n==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let c=o?i[o-1].to:t,h=o<i.length?i[o].from:e;for(let f=c,u,d,p;f<h;f++)if(d=wa[u=s.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(pe[g+1]==-d){let b=pe[g+2],m=b&2?n:b&4?b&1?r:n:0;m&&(K[f]=K[pe[g]]=m),l=g;break}}else{if(pe.length==189)break;pe[l++]=f,pe[l++]=u,pe[l++]=a}else if((p=K[f])==2||p==1){let g=p==n;a=g?0:1;for(let b=l-3;b>=0;b-=3){let m=pe[b+2];if(m&2)break;if(g)pe[b+2]|=2;else{if(m&4)break;pe[b+2]|=4}}}}}function sk(s,t,e,i){for(let n=0,r=i;n<=e.length;n++){let o=n?e[n-1].to:s,l=n<e.length?e[n].from:t;for(let a=o;a<l;){let c=K[a];if(c==256){let h=a+1;for(;;)if(h==l){if(n==e.length)break;h=e[n++].to,l=n<e.length?e[n].from:t}else if(K[h]==256)h++;else break;let f=r==1,u=(h<t?K[h]:i)==1,d=f==u?f?1:2:i;for(let p=h,g=n,b=g?e[g-1].to:s;p>a;)p==b&&(p=e[--g].from,b=g?e[g-1].to:s),K[--p]=d;a=h}else r=c,a++}}}function xa(s,t,e,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=t,c=0;a<e;){let h=!0,f=!1;if(c==r.length||a<r[c].from){let g=K[a];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;t:for(;;)if(c<r.length&&p==r[c].from){if(f)break t;let g=r[c];if(!h)for(let b=g.to,m=c+1;;){if(b==e)break t;if(m<r.length&&r[m].from==b)b=r[m++].to;else{if(K[b]==l)break t;break}}if(c++,u)u.push(g);else{g.from>a&&o.push(new _e(a,g.from,d));let b=g.direction==xi!=!(d%2);Sa(s,b?i+1:i,n,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==e||(h?K[p]!=l:K[p]==l))break;p++}u?xa(s,a,p,i+1,n,u,o):a<p&&o.push(new _e(a,p,d)),a=p}else for(let a=e,c=r.length;a>t;){let h=!0,f=!1;if(!c||a>r[c-1].to){let g=K[a-1];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;t:for(;;)if(c&&p==r[c-1].to){if(f)break t;let g=r[--c];if(!h)for(let b=g.from,m=c;;){if(b==t)break t;if(m&&r[m-1].to==b)b=r[--m].from;else{if(K[b-1]==l)break t;break}}if(u)u.push(g);else{g.to<a&&o.push(new _e(g.to,a,d));let b=g.direction==xi!=!(d%2);Sa(s,b?i+1:i,n,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==t||(h?K[p-1]!=l:K[p-1]==l))break;p--}u?xa(s,p,a,i+1,n,u,o):p<a&&o.push(new _e(p,a,d)),a=p}}function Sa(s,t,e,i,n,r,o){let l=t%2?2:1;ik(s,n,r,i,l),nk(s,n,r,i,l),sk(n,r,i,l),xa(s,n,r,t,e,i,o)}function rk(s,t,e){if(!s)return[new _e(0,0,t==Rh?1:0)];if(t==xi&&!e.length&&!ek.test(s))return Bm(s.length);if(e.length)for(;s.length>K.length;)K[K.length]=256;let i=[],n=t==xi?0:1;return Sa(s,n,n,e,0,s.length,i),i}function Bm(s){return[new _e(0,s,0)]}let Em="";function ok(s,t,e,i,n){var r;let o=i.head-s.from,l=_e.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=t[l],c=a.side(n,e);if(o==c){let u=l+=n?1:-1;if(u<0||u>=t.length)return null;a=t[l=u],o=a.side(!n,e),c=a.side(n,e)}let h=V(s.text,o,a.forward(n,e));(h<a.from||h>a.to)&&(h=c),Em=s.text.slice(Math.min(o,h),Math.max(o,h));let f=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];return f&&h==c&&f.level+(n?0:1)<a.level?w.cursor(f.side(!n,e)+s.from,f.forward(n,e)?1:-1,f.level):w.cursor(h+s.from,a.forward(n,e)?-1:1,a.level)}function lk(s,t,e){for(let i=t;i<e;i++){let n=Om(s.charCodeAt(i));if(n==1)return xi;if(n==2||n==4)return Rh}return xi}const Rm=v.define(),Lm=v.define(),Pm=v.define(),$m=v.define(),va=v.define(),Nm=v.define(),Hm=v.define(),Lh=v.define(),Ph=v.define(),Fm=v.define({combine:s=>s.some(t=>t)}),ak=v.define({combine:s=>s.some(t=>t)}),Im=v.define();let Uo=class ka{constructor(t,e="nearest",i="nearest",n=5,r=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new ka(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new ka(w.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}};const Vs=R.define({map:(s,t)=>s.map(t)}),Vm=R.define();function Re(s,t,e){let i=s.facet($m);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const Ke=v.define({combine:s=>s.length?s[0]:!0});let hk=0;const On=v.define();let rs=class Ca{constructor(t,e,i,n,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=e||{};return new Ca(hk++,t,i,n,l=>{let a=[On.of(l)];return o&&a.push(os.of(c=>{let h=c.plugin(l);return h?o(h):U.none})),r&&a.push(r(l)),a})}static fromClass(t,e){return Ca.define(i=>new t(i),e)}},Yo=class{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Re(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Re(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Re(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}};const Wm=v.define(),$h=v.define(),os=v.define(),zm=v.define(),Nh=v.define(),Km=v.define();function $f(s,t){let e=s.state.facet(Km);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(s):r),n=[];return E.spans(i,t.from,t.to,{point(){},span(r,o,l,a){let c=r-t.from,h=o-t.from,f=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=lk(t.text,c,h)),a>0&&f.length&&(p=f[f.length-1]).to==c&&p.direction==d)p.to=h,f=p.inner;else{let g={from:c,to:h,direction:d,inner:[]};f.push(g),f=g.inner}}}}),n}const qm=v.define();function jm(s){let t=0,e=0,i=0,n=0;for(let r of s.state.facet(qm)){let o=r(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:i,bottom:n}}const Tn=v.define();let ti=class vr{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new vr(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let n=0,r=0,o=0,l=0;;n++){let a=n==t.length?null:t[n],c=o-l,h=a?a.fromB:1e9;for(;r<e.length&&e[r]<h;){let f=e[r],u=e[r+1],d=Math.max(l,f),p=Math.min(h,u);if(d<=p&&new vr(d+c,p+c,d,p).addToSet(i),u>h)break;r+=2}if(!a)return i;new vr(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}},Nf=class Gm{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=et.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,a)=>n.push(new ti(r,o,l,a))),this.changedRanges=n}static create(t,e,i){return new Gm(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},Hf=class extends tt{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=U.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new wt],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new ti(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:h})=>h<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!mk(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let r=n>-1?fk(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:c,to:h}=this.hasComposition;i=new ti(c,h,t.changes.mapPos(c,-1),t.changes.mapPos(h,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(D.ie||D.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=pk(o,l,t.changes);return i=ti.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=D.chrome||D.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||n.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof Kn&&o.widget instanceof ya&&r.push(o.dom);n.updateGaps(r)}updateChildren(t,e,i){let n=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let o=n.length-1;;o--){let l=o>=0?n[o]:null;if(!l)break;let{fromA:a,toA:c,fromB:h,toB:f}=l,u,d,p,g;if(i&&i.range.fromB<f&&i.range.toB>h){let x=Go.build(this.view.state.doc,h,i.range.fromB,this.decorations,this.dynamicDecorationMap),k=Go.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=x.breakAtStart,p=x.openStart,g=k.openEnd;let M=this.compositionView(i);k.breakAtStart?M.breakAfter=1:k.content.length&&M.merge(M.length,M.length,k.content[0],!1,k.openStart,0)&&(M.breakAfter=k.content[0].breakAfter,k.content.shift()),x.content.length&&M.merge(0,0,x.content[x.content.length-1],!0,0,x.openEnd)&&x.content.pop(),u=x.content.concat(M).concat(k.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=Go.build(this.view.state.doc,h,f,this.decorations,this.dynamicDecorationMap));let{i:b,off:m}=r.findPos(c,1),{i:y,off:S}=r.findPos(a,-1);pm(this,y,S,b,m,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(Vm)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new ri(t.text.nodeValue);e.flags|=8;for(let{deco:n}of t.marks)e=new _i(n,[e],e.length);let i=new wt;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=tt.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let r=t.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],e(r>=0?t.marks[r].node:t.text,n)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&xr(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),c=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(D.gecko&&l.empty&&!this.hasComposition&&ck(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=c=new Ft(f,0),o=!0}let h=this.view.observer.selectionRange;(o||!h.focusNode||(!zn(a.node,a.offset,h.anchorNode,h.anchorOffset)||!zn(c.node,c.offset,h.focusNode,h.focusOffset))&&!this.suppressWidgetCursorChange(h,l))&&(this.view.observer.ignore(()=>{D.android&&D.chrome&&this.dom.contains(h.focusNode)&&gk(h.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=ns(this.view.root);if(f)if(l.empty){if(D.gecko){let u=uk(a.node,a.offset);if(u&&u!=3){let d=(u==1?fm:um)(a.node,a.offset);d&&(a=new Ft(d.node,d.offset))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,c]=[c,a]),u.setEnd(c.node,c.offset),u.setStart(a.node,a.offset),f.removeAllRanges(),f.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,c)),this.impreciseAnchor=a.precise?null:new Ft(h.anchorNode,h.anchorOffset),this.impreciseHead=c.precise?null:new Ft(h.focusNode,h.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&zn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=ns(t.root),{anchorNode:n,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=wt.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let a=this.coordsAt(e.head,-1),c=this.coordsAt(e.head,1);if(!a||!c||a.bottom>c.top)return;let h=this.domAtPos(e.head+e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(n,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let n=t.offset;!i&&n<e.childNodes.length;n++){let r=tt.get(e.childNodes[n]);r instanceof wt&&(i=r.domAtPos(0))}for(let n=t.offset-1;!i&&n>=0;n--){let r=tt.get(e.childNodes[n]);r instanceof wt&&(i=r.domAtPos(r.length))}return i?new Ft(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=tt.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let n=this.children[e];if(i<n.length||n instanceof wt)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,n=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,c=a-l.length;if(a<t)break;if(c<=t&&(c<t||l.covers(-1))&&(a>t||l.covers(1))&&(!i||l instanceof wt&&!(i instanceof wt&&e>=0)))i=l,n=c;else if(i&&c==t&&a==t&&l instanceof Kn&&Math.abs(e)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=c}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof wt))return null;for(;n.children.length;){let{i:l,off:a}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=a}if(!(n instanceof ri))return null;let r=V(n.text,i);if(r==i)return null;let o=wi(n.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:n}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==St.LTR;for(let c=0,h=0;h<this.children.length;h++){let f=this.children[h],u=c+f.length;if(u>n)break;if(c>=i){let d=f.dom.getBoundingClientRect();if(e.push(d.height),o){let p=f.dom.lastChild,g=p?ss(p):[];if(g.length){let b=g[g.length-1],m=a?b.right-d.left:d.right-b.left;m>l&&(l=m,this.minWidth=r,this.minWidthFrom=c,this.minWidthTo=u)}}}c=u+f.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?St.RTL:St.LTR}measureTextSize(){for(let r of this.children)if(r instanceof wt){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,n;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.dom.appendChild(t);let r=ss(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new dm(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let r=n==e.viewports.length?null:e.viewports[n],o=r?r.from-1:this.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(U.replace({widget:new ya(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return U.set(t)}updateDeco(){let t=1,e=this.view.state.facet(os).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(zm).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(E.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let c=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=c.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let c of this.view.state.facet(Im))try{if(c(this.view,t.range,t))return!0}catch(h){Re(this.view.state,h,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),n;if(!i)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let r=jm(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;Kv(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==St.LTR)}};function ck(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}function Um(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=fm(e.focusNode,e.focusOffset),n=um(e.focusNode,e.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=tt.get(n.node);if(!l||l instanceof ri&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=tt.get(i.node);!a||a instanceof ri&&a.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function fk(s,t,e){let i=Um(s,e);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc,c=new ti(a.mapPos(r),a.mapPos(o),r,o),h=[];for(let f=n.parentNode;;f=f.parentNode){let u=tt.get(f);if(u instanceof _i)h.push({node:f,deco:u.mark});else{if(u instanceof wt||f.nodeName=="DIV"&&f.parentNode==s.contentDOM)return{range:c,text:n,marks:h,line:f};if(f!=s.contentDOM)h.push({node:f,deco:new Bh({inclusive:!0,attributes:Jv(f),tagName:f.tagName.toLowerCase()})});else return null}}}function uk(s,t){return s.nodeType!=1?0:(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t<s.childNodes.length&&s.childNodes[t].contentEditable=="false"?2:0)}let dk=class{constructor(){this.changes=[]}compareRange(t,e){ba(t,e,this.changes)}comparePoint(t,e){ba(t,e,this.changes)}};function pk(s,t,e){let i=new dk;return E.compare(s,t,e,i),i.changes}function gk(s,t){for(let e=s;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function mk(s,t){let e=!1;return t&&s.iterChangedRanges((i,n)=>{i<t.to&&n>t.from&&(e=!0)}),e}function bk(s,t,e=1){let i=s.charCategorizer(t),n=s.doc.lineAt(t),r=t-n.from;if(n.length==0)return w.cursor(t);r==0?e=1:r==n.length&&(e=-1);let o=r,l=r;e<0?o=V(n.text,r,!1):l=V(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let c=V(n.text,o,!1);if(i(n.text.slice(c,o))!=a)break;o=c}for(;l<n.length;){let c=V(n.text,l);if(i(n.text.slice(l,c))!=a)break;l=c}return w.range(o+n.from,l+n.from)}function yk(s,t){return t.left>s?t.left-s:Math.max(0,s-t.right)}function wk(s,t){return t.top>s?t.top-s:Math.max(0,s-t.bottom)}function Xo(s,t){return s.top<t.bottom-1&&s.bottom>t.top+1}function Ff(s,t){return t<s.top?{top:t,left:s.left,right:s.right,bottom:s.bottom}:s}function If(s,t){return t>s.bottom?{top:s.top,left:s.left,right:s.right,bottom:t}:s}function Ma(s,t,e){let i,n,r,o,l=!1,a,c,h,f;for(let p=s.firstChild;p;p=p.nextSibling){let g=ss(p);for(let b=0;b<g.length;b++){let m=g[b];n&&Xo(n,m)&&(m=Ff(If(m,n.bottom),n.top));let y=yk(t,m),S=wk(e,m);if(y==0&&S==0)return p.nodeType==3?Vf(p,t,e):Ma(p,t,e);if(!i||o>S||o==S&&r>y){i=p,n=m,r=y,o=S;let x=S?e<m.top?-1:1:y?t<m.left?-1:1:0;l=!x||(x>0?b<g.length-1:b>0)}y==0?e>m.bottom&&(!h||h.bottom<m.bottom)?(a=p,h=m):e<m.top&&(!f||f.top>m.top)&&(c=p,f=m):h&&Xo(h,m)?h=If(h,m.bottom):f&&Xo(f,m)&&(f=Ff(f,m.top))}}if(h&&h.bottom>=e?(i=a,n=h):f&&f.top<=e&&(i=c,n=f),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,t));if(i.nodeType==3)return Vf(i,u,e);if(l&&i.contentEditable!="false")return Ma(i,u,e);let d=Array.prototype.indexOf.call(s.childNodes,i)+(t>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function Vf(s,t,e){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=wi(s,l,l+1).getClientRects();for(let c=0;c<a.length;c++){let h=a[c];if(h.top==h.bottom)continue;o||(o=t-h.left);let f=(h.top>e?h.top-e:e-h.bottom)-1;if(h.left-1<=t&&h.right+1>=t&&f<r){let u=t>=(h.left+h.right)/2,d=u;if((D.chrome||D.gecko)&&wi(s,l).getBoundingClientRect().left==h.right&&(d=!u),f<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=f}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function Ym(s,t,e,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,a,{docHeight:c}=s.viewState,{x:h,y:f}=t,u=f-l;if(u<0)return 0;if(u>c)return s.state.doc.length;for(let x=s.viewState.heightOracle.textHeight/2,k=!1;a=s.elementAtHeight(u),a.type!=Ce.Text;)for(;u=i>0?a.bottom+x:a.top-x,!(u>=0&&u<=c);){if(k)return e?null:0;k=!0,i=-i}f=l+u;let d=a.from;if(d<s.viewport.from)return s.viewport.from==0?0:e?null:Wf(s,o,a,h,f);if(d>s.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:e?null:Wf(s,o,a,h,f);let p=s.dom.ownerDocument,g=s.root.elementFromPoint?s.root:p,b=g.elementFromPoint(h,f);b&&!s.contentDOM.contains(b)&&(b=null),b||(h=Math.max(o.left+1,Math.min(o.right-1,h)),b=g.elementFromPoint(h,f),b&&!s.contentDOM.contains(b)&&(b=null));let m,y=-1;if(b&&((n=s.docView.nearest(b))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let x=p.caretPositionFromPoint(h,f);x&&({offsetNode:m,offset:y}=x)}else if(p.caretRangeFromPoint){let x=p.caretRangeFromPoint(h,f);x&&({startContainer:m,startOffset:y}=x,(!s.contentDOM.contains(m)||D.safari&&xk(m,y,h)||D.chrome&&Sk(m,y,h))&&(m=void 0))}m&&(y=Math.min(Ae(m),y))}if(!m||!s.docView.dom.contains(m)){let x=wt.find(s.docView,d);if(!x)return u>a.top+a.height/2?a.to:a.from;({node:m,offset:y}=Ma(x.dom,h,f))}let S=s.docView.nearest(m);if(!S)return null;if(S.isWidget&&((r=S.dom)===null||r===void 0?void 0:r.nodeType)==1){let x=S.dom.getBoundingClientRect();return t.y<x.top||t.y<=x.bottom&&t.x<=(x.left+x.right)/2?S.posAtStart:S.posAtEnd}else return S.localPosFromDOM(m,y)+S.posAtStart}function Wf(s,t,e,i,n){let r=Math.round((i-t.left)*s.defaultCharacterWidth);if(s.lineWrapping&&e.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,a=Math.floor((n-e.top-(s.defaultLineHeight-l)*.5)/l);r+=a*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+Xn(o,r,s.state.tabSize)}function xk(s,t,e){let i;if(s.nodeType!=3||t!=(i=s.nodeValue.length))return!1;for(let n=s.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!="BR")return!1;return wi(s,i-1,i).getBoundingClientRect().left>e}function Sk(s,t,e){if(t!=0)return!1;for(let n=s;;){let r=n.parentNode;if(!r||r.nodeType!=1||r.firstChild!=n)return!1;if(r.classList.contains("cm-line"))break;n=r}let i=s.nodeType==1?s.getBoundingClientRect():wi(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function vk(s,t){let e=s.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==Ce.Text))return i}return e}function kk(s,t,e,i){let n=vk(s,t.head),r=!i||n.type!=Ce.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),a=s.posAtCoords({x:e==(l==St.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return w.cursor(a,e?-1:1)}return w.cursor(e?n.to:n.from,e?-1:1)}function zf(s,t,e,i){let n=s.state.doc.lineAt(t.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=t,a=null;;){let c=ok(n,r,o,l,e),h=Em;if(!c){if(n.number==(e?s.state.doc.lines:1))return l;h=`
12
- `,n=s.state.doc.line(n.number+(e?1:-1)),r=s.bidiSpans(n),c=s.visualLineSide(n,!e)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function Ck(s,t,e){let i=s.state.charCategorizer(t),n=i(e);return r=>{let o=i(r);return n==Y.Space&&(n=o),n==o}}function Mk(s,t,e,i){let n=t.head,r=e?1:-1;if(n==(e?s.state.doc.length:0))return w.cursor(n,t.assoc);let o=t.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),c=s.coordsAtPos(n,t.assoc||-1),h=s.documentTop;if(c)o==null&&(o=c.left-a.left),l=r<0?c.top:c.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+h}let f=a.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=Ym(s,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<n:g>n)){let b=s.docView.coordsForChar(g),m=!b||p<b.top?-1:1;return w.cursor(g,m,void 0,o)}}}function kr(s,t,e){for(;;){let i=0;for(let n of s)n.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let a=i||e||(t-r<o-t?-1:1);t=a<0?r:o,i=a}});if(!i)return t}}function _o(s,t,e){let i=kr(s.state.facet(Nh).map(n=>n(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:w.cursor(i,i<e.from?1:-1)}const Bn="￿";let Ak=class{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet($.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Bn}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==e)break;let l=tt.get(n),a=tt.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:zr(n))||zr(o)&&(n.nodeName!="BR"||n.cmIgnore)&&this.text.length>r)&&this.lineBreak(),n=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=tt.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Dk(t,i.node,i.offset)?e:0))}};function Dk(s,t,e){for(;;){if(!t||e<Ae(t))return!1;if(t==s)return!0;e=yi(t)+1,t=t.parentNode}}let Kf=class{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}},Ok=class{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:Ek(t),a=new Ak(l,t.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Rk(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!ra(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!ra(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=t.viewport;if((D.ios||D.chrome)&&t.state.selection.main.empty&&a!=c&&(h.from>0||h.to<t.state.doc.length)){let f=Math.min(a,c),u=Math.max(a,c),d=h.from-f,p=h.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==t.state.doc.length)&&(a=0,c=t.state.doc.length)}this.newSel=w.single(c,a)}}};function Xm(s,t){let e,{newSel:i}=t,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,a=n.from,c=null;(r===8||D.android&&t.text.length<l-o)&&(a=n.to,c="end");let h=Bk(s.state.doc.sliceString(o,l,Bn),t.text,a-o,c);h&&(D.chrome&&r==13&&h.toB==h.from+2&&t.text.slice(h.from,h.toB)==Bn+Bn&&h.toB--,e={from:o+h.from,to:o+h.toA,insert:B.of(t.text.slice(h.from,h.toB).split(Bn))})}else i&&(!s.hasFocus&&s.state.facet(Ke)||i.main.eq(n))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!n.empty&&i&&i.main.empty?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,n.to)}:e&&e.from>=n.from&&e.to<=n.to&&(e.from!=n.from||e.to!=n.to)&&n.to-n.from-(e.to-e.from)<=4?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,e.from).append(e.insert).append(s.state.doc.slice(e.to,n.to))}:(D.mac||D.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:B.of([" "])}):D.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`
13
- `&&s.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:B.of([" "])}),e)return Hh(s,e,i,r);if(i&&!i.main.eq(n)){let o=!1,l="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(o=!0),l=s.inputState.lastSelectionOrigin),s.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Hh(s,t,e,i=-1){if(D.ios&&s.inputState.flushIOSKey(t))return!0;let n=s.state.selection.main;if(D.android&&(t.to==n.to&&(t.from==n.from||t.from==n.from-1&&s.state.sliceDoc(t.from,n.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Fi(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>n.head)&&Fi(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Fi(s.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=Tk(s,t,e));return s.state.facet(Nm).some(a=>a(s,t.from,t.to,r,l))||s.dispatch(l()),!0}function Tk(s,t,e){let i,n=s.state,r=n.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&s.inputState.composing<0){let l=r.from<t.from?n.sliceDoc(r.from,t.from):"",a=r.to>t.to?n.sliceDoc(t.to,r.to):"";i=n.replaceSelection(s.state.toText(l+t.insert.sliceString(0,void 0,s.state.lineBreak)+a))}else{let l=n.changes(t),a=e&&e.main.to<=l.newLength?e.main:void 0;if(n.selection.ranges.length>1&&s.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let c=s.state.sliceDoc(t.from,t.to),h,f=e&&Um(s,e.main.head);if(f){let p=t.insert.length-(t.to-t.from);h={from:f.from,to:f.to-p}}else h=s.state.doc.lineAt(r.head);let u=r.to-t.to,d=r.to-r.from;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let g=p.to-u,b=g-c.length;if(p.to-p.from!=d||s.state.sliceDoc(b,g)!=c||p.to>=h.from&&p.from<=h.to)return{range:p};let m=n.changes({from:b,to:g,insert:t.insert}),y=p.to-r.to;return{changes:m,range:a?w.range(Math.max(0,a.anchor+y),Math.max(0,a.head+y)):p.map(m)}})}else i={changes:l,selection:a&&n.selection.replaceRange(a)}}let o="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,o+=".compose",s.inputState.compositionFirstChange&&(o+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:o,scrollIntoView:!0})}function Bk(s,t,e,i){let n=Math.min(s.length,t.length),r=0;for(;r<n&&s.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==n&&s.length==t.length)return null;let o=s.length,l=t.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));e-=o+a-r}if(o<r&&s.length<t.length){let a=e<=r&&e>=o?r-e:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=e<=r&&e>=l?r-e:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Ek(s){let t=[];if(s.root.activeElement!=s.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return e&&(t.push(new Kf(e,i)),(n!=e||r!=i)&&t.push(new Kf(n,r))),t}function Rk(s,t){if(s.length==0)return null;let e=s[0].pos,i=s.length==2?s[1].pos:e;return e>-1&&i>-1?w.single(e+t,i+t):null}let Lk=class{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,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.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,D.safari&&t.contentDOM.addEventListener("input",()=>null),D.gecko&&Xk(t.contentDOM.ownerDocument)}handleEvent(t){!Wk(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let n of i.observers)n(this.view,e);for(let n of i.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Pk(t),i=this.handlers,n=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Jm.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),D.android&&D.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return D.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=_m.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||$k.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,Fi(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:D.safari&&!D.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function qf(s,t){return(e,i)=>{try{return t.call(s,i,e)}catch(n){Re(e.state,n)}}}function Pk(s){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec;if(n&&n.domEventHandlers)for(let r in n.domEventHandlers){let o=n.domEventHandlers[r];o&&e(r).handlers.push(qf(i.value,o))}if(n&&n.domEventObservers)for(let r in n.domEventObservers){let o=n.domEventObservers[r];o&&e(r).observers.push(qf(i.value,o))}}for(let i in ae)e(i).handlers.push(ae[i]);for(let i in Yt)e(i).observers.push(Yt[i]);return t}const _m=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],$k="dthko",Jm=[16,17,18,20,91,92,224,225],Ws=6;function zs(s){return Math.max(0,s)*.7+8}function Nk(s,t){return Math.max(Math.abs(s.clientX-t.clientX),Math.abs(s.clientY-t.clientY))}let Hk=class{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=qv(t.contentDOM),this.atoms=t.state.facet(Nh).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet($.allowMultipleSelections)&&Fk(t,e),this.dragging=Vk(t,e)&&t0(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Nk(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=jm(this.view);t.clientX-a.left<=n+Ws?e=-zs(n-t.clientX):t.clientX+a.right>=o-Ws&&(e=zs(t.clientX-o)),t.clientY-a.top<=r+Ws?i=-zs(r-t.clientY):t.clientY+a.bottom>=l-Ws&&(i=zs(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let n=t.ranges[i],r=null;if(n.empty){let o=kr(this.atoms,n.from,0);o!=n.from&&(r=w.cursor(o,-1))}else{let o=kr(this.atoms,n.from,-1),l=kr(this.atoms,n.to,1);(o!=n.from||l!=n.to)&&(r=w.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?w.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Fk(s,t){let e=s.state.facet(Rm);return e.length?e[0](t):D.mac?t.metaKey:t.ctrlKey}function Ik(s,t){let e=s.state.facet(Lm);return e.length?e[0](t):D.mac?!t.altKey:!t.ctrlKey}function Vk(s,t){let{main:e}=s.state.selection;if(e.empty)return!1;let i=ns(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function Wk(s,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=s.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=tt.get(e))&&i.ignoreEvent(t))return!1;return!0}const ae=Object.create(null),Yt=Object.create(null),Qm=D.ie&&D.ie_version<15||D.ios&&D.webkit_version<604;function zk(s){let t=s.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{s.focus(),e.remove(),Zm(s,e.value)},50)}function xo(s,t,e){for(let i of s.facet(t))e=i(e,s);return e}function Zm(s,t){t=xo(s.state,Lh,t);let{state:e}=s,i,n=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(Aa!=null&&e.selection.ranges.every(a=>a.empty)&&Aa==r.toString()){let a=-1;i=e.changeByRange(c=>{let h=e.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let f=e.toText((o?r.line(n++).text:t)+e.lineBreak);return{changes:{from:h.from,insert:f},range:w.cursor(c.from+f.length)}})}else o?i=e.changeByRange(a=>{let c=r.line(n++);return{changes:{from:a.from,to:a.to,insert:c.text},range:w.cursor(a.from+c.length)}}):i=e.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Yt.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};ae.keydown=(s,t)=>(s.inputState.setSelectionOrigin("select"),t.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);Yt.touchstart=(s,t)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Yt.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};ae.mousedown=(s,t)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of s.state.facet(Pm))if(e=i(s,t),e)break;if(!e&&t.button==0&&(e=jk(s,t)),e){let i=!s.hasFocus;s.inputState.startMouseSelection(new Hk(s,t,e,i)),i&&s.observer.ignore(()=>{am(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}return!1};function jf(s,t,e,i){if(i==1)return w.cursor(t,e);if(i==2)return bk(s.state,t,e);{let n=wt.find(s.docView,t),r=s.state.doc.lineAt(n?n.posAtEnd:t),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,w.range(o,l)}}let Gf=(s,t,e)=>t>=e.top&&t<=e.bottom&&s>=e.left&&s<=e.right;function Kk(s,t,e,i){let n=wt.find(s.docView,t);if(!n)return 1;let r=t-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&Gf(e,i,o))return-1;let l=n.coordsAt(r,1);return l&&Gf(e,i,l)?1:o&&o.bottom>=i?-1:1}function Uf(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:Kk(s,e,t.clientX,t.clientY)}}const qk=D.ie&&D.ie_version<=11;let Yf=null,Xf=0,_f=0;function t0(s){if(!qk)return s.detail;let t=Yf,e=_f;return Yf=s,_f=Date.now(),Xf=!t||e>Date.now()-400&&Math.abs(t.clientX-s.clientX)<2&&Math.abs(t.clientY-s.clientY)<2?(Xf+1)%3:1}function jk(s,t){let e=Uf(s,t),i=t0(t),n=s.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),n=n.map(r.changes))},get(r,o,l){let a=Uf(s,r),c,h=jf(s,a.pos,a.bias,i);if(e.pos!=a.pos&&!o){let f=jf(s,e.pos,e.bias,i),u=Math.min(f.from,h.from),d=Math.max(f.to,h.to);h=u<h.from?w.range(u,d):w.range(d,u)}return o?n.replaceRange(n.main.extend(h.from,h.to)):l&&i==1&&n.ranges.length>1&&(c=Gk(n,a.pos))?c:l?n.addRange(h):w.create([h])}}}function Gk(s,t){for(let e=0;e<s.ranges.length;e++){let{from:i,to:n}=s.ranges[e];if(i<=t&&n>=t)return w.create(s.ranges.slice(0,e).concat(s.ranges.slice(e+1)),s.mainIndex==e?0:s.mainIndex-(s.mainIndex>e?1:0))}return null}ae.dragstart=(s,t)=>{let{selection:{main:e}}=s.state;if(t.target.draggable){let n=s.docView.nearest(t.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=e.to||o<=e.from)&&(e=w.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",xo(s.state,Ph,s.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};ae.dragend=s=>(s.inputState.draggedContent=null,!1);function Jf(s,t,e,i){if(e=xo(s.state,Lh,e),!e)return;let n=s.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Ik(s,t)?{from:r.from,to:r.to}:null,l={from:n,insert:e},a=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}ae.drop=(s,t)=>{if(!t.dataTransfer)return!1;if(s.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),n=0,r=()=>{++n==e.length&&Jf(s,t,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<e.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(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Jf(s,t,i,!0),!0}return!1};ae.paste=(s,t)=>{if(s.state.readOnly)return!0;s.observer.flush();let e=Qm?null:t.clipboardData;return e?(Zm(s,e.getData("text/plain")||e.getData("text/uri-list")),!0):(zk(s),!1)};function Uk(s,t){let e=s.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function Yk(s){let t=[],e=[],i=!1;for(let n of s.selection.ranges)n.empty||(t.push(s.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:xo(s,Ph,t.join(s.lineBreak)),ranges:e,linewise:i}}let Aa=null;ae.copy=ae.cut=(s,t)=>{let{text:e,ranges:i,linewise:n}=Yk(s.state);if(!e&&!n)return!1;Aa=n?e:null,t.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Qm?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(Uk(s,e),!1)};const e0=Vt.define();function i0(s,t){let e=[];for(let i of s.facet(Hm)){let n=i(s,t);n&&e.push(n)}return e?s.update({effects:e,annotations:e0.of(!0)}):null}function n0(s){setTimeout(()=>{let t=s.hasFocus;if(t!=s.inputState.notifiedFocused){let e=i0(s.state,t);e?s.dispatch(e):s.update([])}},10)}Yt.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),n0(s)};Yt.blur=s=>{s.observer.clearSelectionRange(),n0(s)};Yt.compositionstart=Yt.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};Yt.compositionend=s=>{s.observer.editContext||(s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,D.chrome&&D.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};Yt.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};ae.beforeinput=(s,t)=>{var e,i;if(t.inputType=="insertReplacementText"&&s.observer.editContext){let r=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(r&&o.length){let l=o[0],a=s.posAtDOM(l.startContainer,l.startOffset),c=s.posAtDOM(l.endContainer,l.endOffset);return Hh(s,{from:a,to:c,insert:s.state.toText(r)},null),!0}}let n;if(D.chrome&&D.android&&(n=_m.find(r=>r.inputType==t.inputType))&&(s.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.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&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return D.ios&&t.inputType=="deleteContentForward"&&s.observer.flushSoon(),D.safari&&t.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>Yt.compositionend(s,t),20),!1};const Qf=new Set;function Xk(s){Qf.has(s)||(Qf.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const Zf=["pre-wrap","normal","pre-line","break-spaces"];let Zi=!1;function tu(){Zi=!1}let _k=class{constructor(t){this.lineWrapping=t,this.doc=B.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Zf.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let n=t[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(e=!0,this.heightSamples[Math.floor(n*10)]=!0)}return e}refresh(t,e,i,n,r,o){let l=Zf.indexOf(t)>-1,a=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}},Jk=class{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}},qe=class s0{constructor(t,e,i,n,r){this.from=t,this.length=e,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?Ce.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 Ji?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new s0(this.from,this.length+t.length,this.top,this.height+t.height,e)}};var _=function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s}(_||(_={}));const Cr=.001;let oe=class Mr{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>Cr&&(Zi=!0),this.height=t)}replace(t,e,i){return Mr.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:f}=n[l],u=r.lineAt(a,_.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=c?u:r.lineAt(c,_.ByPosNoHeight,i,0,0);for(f+=d.to-c,c=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,h=n[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,_.ByPosNoHeight,i,0,0));h+=u.from-a,a=u.from;let p=tC.build(i.setDoc(o),t,h,f);r=qr(r,r.replace(a,c,p))}return r.updateHeight(i,0)}static empty(){return new be(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,n=0,r=0;for(;;)if(e==i)if(n>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=t[e++];l&&(n+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new Qk(Mr.of(t.slice(0,e)),o,Mr.of(t.slice(i)))}};function qr(s,t){return s==t?s:(s.constructor!=t.constructor&&(Zi=!0),t)}oe.prototype.size=1;let r0=class extends oe{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,n){return new qe(n,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,n,r){return this.blockAt(0,i,n,r)}forEachLine(t,e,i,n,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,n,r))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},be=class Da extends r0{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new qe(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return i.length==1&&(n instanceof Da||n instanceof Ii&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Ii?n=new Da(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):oe.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Ii=class ne extends oe{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,r=n-i+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.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:n,perLine:o,perChar:l}}blockAt(t,e,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,n);if(e.lineWrapping){let c=n+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),h=e.doc.lineAt(c),f=l+h.length*a,u=Math.max(i,t-f/2);return new qe(h.from,h.length,u,f,0)}else{let c=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:h,length:f}=e.doc.line(r+c);return new qe(h,f,i+l*c,l,0)}}lineAt(t,e,i,n,r){if(e==_.ByHeight)return this.blockAt(t,i,n,r);if(e==_.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new qe(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),c=i.doc.lineAt(t),h=l+c.length*a,f=c.number-o,u=n+l*f+a*(c.from-r-f);return new qe(c.from,c.length,Math.max(n,Math.min(u,n+this.height-h)),h,0)}forEachLine(t,e,i,n,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,r);for(let h=t,f=n;h<=e;){let u=i.doc.lineAt(h);if(h==t){let p=u.number-l;f+=a*p+c*(t-r-p)}let d=a+c*u.length;o(new qe(u.from,u.length,f,d,0)),f+=d,h=u.to+1}}replace(t,e,i){let n=this.length-e;if(n>0){let r=i[i.length-1];r instanceof ne?i[i.length-1]=new ne(r.length+n):i.push(null,new ne(n-1))}if(t>0){let r=i[0];r instanceof ne?i[0]=new ne(t+r.length):i.unshift(new ne(t-1),null)}return oe.of(i)}decomposeLeft(t,e){e.push(new ne(t-1),null)}decomposeRight(t,e){e.push(null,new ne(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let r=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),a=-1;for(n.from>e&&o.push(new ne(n.from-e-1).updateHeight(t,e));l<=r&&n.more;){let h=t.doc.lineAt(l).length;o.length&&o.push(null);let f=n.heights[n.index++];a==-1?a=f:Math.abs(f-a)>=Cr&&(a=-2);let u=new be(h,f);u.outdated=!1,o.push(u),l+=h+1}l<=r&&o.push(null,new ne(r-l).updateHeight(t,l));let c=oe.of(o);return(a<0||Math.abs(c.height-this.height)>=Cr||Math.abs(a-this.heightMetrics(t,e).perLine)>=Cr)&&(Zi=!0),qr(this,c)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Qk=class extends oe{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,n){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,n):this.right.blockAt(t,e,r,n+this.left.length+this.break)}lineAt(t,e,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,a=e==_.ByHeight?t<o:t<l,c=a?this.left.lineAt(t,e,i,n,r):this.right.lineAt(t,e,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=e==_.ByPosNoHeight?_.ByPosNoHeight:_.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,n,r).join(c)}forEachLine(t,e,i,n,r,o){let l=n+this.left.height,a=r+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,n,r,o),e>=a&&this.right.forEachLine(t,e,i,l,a,o);else{let c=this.lineAt(a,_.ByPos,i,n,r);t<c.from&&this.left.forEachLine(t,c.from-1,i,n,r,o),c.to>=t&&c.from<=e&&o(c),e>c.to&&this.right.forEachLine(c.to+1,e,i,l,a,o)}}replace(t,e,i){let n=this.left.length+this.break;if(e<n)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&eu(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),eu(r,l)}return oe.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<n&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?oe.of(this.break?[t,null,e]:[t,e]):(this.left=qr(this.left,t),this.right=qr(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:r,right:o}=this,l=e+r.length+this.break,a=null;return n&&n.from<=e+r.length&&n.more?a=r=r.updateHeight(t,e,i,n):r.updateHeight(t,e,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(t,l,i,n):o.updateHeight(t,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 eu(s,t){let e,i;s[t]==null&&(e=s[t-1])instanceof Ii&&(i=s[t+1])instanceof Ii&&s.splice(t-1,3,new Ii(e.length+1+i.length))}const Zk=5;let tC=class o0{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof be?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new be(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new r0(o,n,i)):(o||r||n>=Zk)&&this.addLineDeco(n,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new be(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Ii(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof be)return t;let e=new be(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof be)&&!this.isCovered?this.nodes.push(new be(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let n of this.nodes)n instanceof be&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(t,e,i,n){let r=new o0(i,t);return E.spans(e,i,n,r,0),r.finish(i)}};function eC(s,t,e){let i=new iC;return E.compare(s,t,e,i,0),i.changes}let iC=class{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,n){(t<e||i&&i.heightRelevant||n&&n.heightRelevant)&&ba(t,e,this.changes,5)}};function nC(s,t){let e=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(n.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(n.innerHeight,e.bottom);for(let c=s.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,f=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&f.overflow!="visible"){let u=h.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(c==s.parentNode?n.innerHeight:a,u.bottom)}c=f.position=="absolute"||f.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function sC(s,t){let e=s.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}let Jo=class{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let n=t[i],r=e[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(t,e){return U.replace({widget:new rC(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}},rC=class extends Th{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}},iu=class{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=nu,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=St.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet($h).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new _k(e),this.stateDeco=t.facet(os).filter(i=>typeof i!="function"),this.heightMap=oe.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle.setDoc(t.doc),[new ti(0,0,0,t.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=U.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);t.push(new Ks(r,o))}}return this.viewports=t.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?nu:new aC(this.heightOracle,this.heightMap,this.viewports),t.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,t=>{this.viewportLines.push(En(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(os).filter(h=>typeof h!="function");let n=t.changedRanges,r=ti.extendWithRanges(n,eC(i,this.stateDeco,t?t.changes:et.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);tu(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Zi)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(c||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(ak)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?St.RTL:St.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,h=0;if(l.width&&l.height){let{scaleX:x,scaleY:k}=lm(e,l);(x>.005&&Math.abs(this.scaleX-x)>.005||k>.005&&Math.abs(this.scaleY-k)>.005)&&(this.scaleX=x,this.scaleY=k,c|=8,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,c|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,c|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=cm(t.scrollDOM);let p=(this.printing?sC:nC)(e,this.paddingTop),g=p.top-this.pixelViewport.top,b=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let m=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(m!=this.inView&&(this.inView=m,m&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let y=l.width;if((this.contentDOMWidth!=y||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,c|=8),a){let x=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(x)&&(o=!0),o||n.lineWrapping&&Math.abs(y-this.contentDOMWidth)>n.charWidth){let{lineHeight:k,charWidth:M,textHeight:N}=t.docView.measureTextSize();o=k>0&&n.refresh(r,k,M,N,y/M,x),o&&(t.docView.minWidth=0,c|=8)}g>0&&b>0?h=Math.max(g,b):g<0&&b<0&&(h=Math.min(g,b)),tu();for(let k of this.viewports){let M=k.from==this.viewport.from?x:t.docView.measureVisibleLineHeights(k);this.heightMap=(o?oe.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle,[new ti(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Jk(k.from,M))}Zi&&(c|=2)}let S=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Ks(n.lineAt(o-i*1e3,_.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,_.ByHeight,r,0,0).to);if(e){let{head:c}=e.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=n.lineAt(c,_.ByPos,r,0,0),u;e.y=="center"?u=(f.top+f.bottom)/2-h/2:e.y=="start"||e.y=="nearest"&&c<a.from?u=f.top:u=f.bottom-h,a=new Ks(n.lineAt(u-1e3/2,_.ByHeight,r,0,0).from,n.lineAt(u+h+1e3/2,_.ByHeight,r,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),n=e.mapPos(t.to,1);return new Ks(this.heightMap.lineAt(i,_.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,_.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(t,_.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,_.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||n<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let n of t)e.touchesRange(n.from,n.to)||i.push(new Jo(e.mapPos(n.from),e.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=St.LTR&&!i)return[];let l=[],a=(h,f,u,d)=>{if(f-h<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let m of g)if(m>h&&m<f){a(h,m-10,u,d),a(m+10,f,u,d);return}let b=lC(t,m=>m.from>=u.from&&m.to<=u.to&&Math.abs(m.from-h)<r&&Math.abs(m.to-f)<r&&!g.some(y=>m.from<y&&m.to>y));if(!b){if(f<u.to&&e&&i&&e.visibleRanges.some(S=>S.from<=f&&S.to>=f)){let S=e.moveToLineBoundary(w.cursor(f),!1,!0).head;S>h&&(f=S)}let m=this.gapSize(u,h,f,d),y=i||m<2e6?m:2e6;b=new Jo(h,f,m,y)}l.push(b)},c=h=>{if(h.length<o||h.type!=Ce.Text)return;let f=oC(h.from,h.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,m;if(u!=null){let y=js(f,u),S=((this.visibleBottom-this.visibleTop)/2+g)/h.height;b=y-S,m=y+S}else b=(this.visibleTop-h.top-g)/h.height,m=(this.visibleBottom-h.top+g)/h.height;d=qs(f,b),p=qs(f,m)}else{let g=f.total*this.heightOracle.charWidth,b=n*this.heightOracle.charWidth,m=0;if(g>2e6)for(let M of t)M.from>=h.from&&M.from<h.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+m<this.pixelViewport.left&&(m=M.size-M.displaySize);let y=this.pixelViewport.left+m,S=this.pixelViewport.right+m,x,k;if(u!=null){let M=js(f,u),N=((S-y)/2+b)/g;x=M-N,k=M+N}else x=(y-b)/g,k=(S+b)/g;d=qs(f,x),p=qs(f,k)}d>h.from&&a(h.from,d,h,f),p<h.to&&a(p,h.to,h,f)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(t,e,i,n){let r=js(n,i)-js(n,e);return this.heightOracle.lineWrapping?t.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(t){Jo.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=U.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];E.spans(t,this.viewport.from,this.viewport.to,{span(n,r){e.push({from:n,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((n,r)=>n.from!=e[r].from||n.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||En(this.heightMap.lineAt(t,_.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||En(this.heightMap.lineAt(this.scaler.fromDOM(t),_.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return En(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Ks=class{constructor(t,e){this.from=t,this.to=e}};function oC(s,t,e){let i=[],n=s,r=0;return E.spans(e,s,t,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<t&&(i.push({from:n,to:t}),r+=t-n),{total:r,ranges:i}}function qs({total:s,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(s*e);for(let n=0;;n++){let{from:r,to:o}=t[n],l=o-r;if(i<=l)return r+i;i-=l}}function js(s,t){let e=0;for(let{from:i,to:n}of s.ranges){if(t<=n){e+=t-i;break}e+=n-i}return e/s.total}function lC(s,t){for(let e of s)if(t(e))return e}const nu={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};let aC=class l0{constructor(t,e,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=e.lineAt(l,_.ByPos,t,0,0).top,h=e.lineAt(a,_.ByPos,t,0,0).bottom;return n+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);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(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return n+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,n=r.domBottom}}fromDOM(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-n)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,n=r.domBottom}}eq(t){return t instanceof l0?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}};function En(s,t){if(t.scale==1)return s;let e=t.toDOM(s.top),i=t.toDOM(s.bottom);return new qe(s.from,s.length,e,i-e,Array.isArray(s._content)?s._content.map(n=>En(n,t)):s._content)}const Gs=v.define({combine:s=>s.join(" ")}),Oa=v.define({combine:s=>s.indexOf(!0)>-1}),Ta=lt.newName(),a0=lt.newName(),h0=lt.newName(),c0={"&light":"."+a0,"&dark":"."+h0};function Ba(s,t,e){return new lt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):s+" "+i}})}const hC=Ba("."+Ta,{"&":{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:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,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-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace":{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"}},c0),cC={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Qo=D.ie&&D.ie_version<=11;let fC=class{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new jv,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=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(D.ie&&D.ie_version<=11||D.ios&&t.composing)&&e.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.constructor.EDIT_CONTEXT!==!1&&!(D.chrome&&D.chrome_version<126)&&(this.editContext=new dC(t),t.state.facet(Ke)&&(t.contentDOM.editContext=this.editContext.editContext)),Qo&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Ke)?i.root.activeElement!=this.dom:!xr(this.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(D.ie&&D.ie_version<=11||D.android&&D.chrome)&&!i.state.selection.main.empty&&n.focusNode&&zn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ns(t.root);if(!e)return!1;let i=D.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&uC(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=xr(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&Uv(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,cC),Qo&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Qo&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Fi(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,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 t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&xr(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Ok(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=Xm(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=su(e,t.previousSibling||t.target.previousSibling,-1),n=su(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Ke)!=t.state.facet(Ke)&&(t.view.contentDOM.editContext=t.state.facet(Ke)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function su(s,t,e){for(;t;){let i=tt.get(t);if(i&&i.parent==s)return i;let n=t.parentNode;t=n!=s.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function ru(s,t){let e=t.startContainer,i=t.startOffset,n=t.endContainer,r=t.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor);return zn(o.node,o.offset,n,r)&&([e,i,n,r]=[n,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}}function uC(s,t){if(t.getComposedRanges){let n=t.getComposedRanges(s.root)[0];if(n)return ru(s,n)}let e=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),e=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),e?ru(s,e):null}let dC=class{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:n}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:B.of(i.text.split(`
14
- `))};r.from==this.from&&n<this.from?r.from=n:r.to==this.to&&n>this.to&&(r.to=n),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,t.state.readOnly||Hh(t,r,w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)))},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=t.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,n.push(r)}e.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;n.push(U.mark({attributes:{style:a}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:Vm.of(U.set(n))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=ns(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((r,o,l,a,c)=>{if(i)return;let h=c.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(c)){n=this.pendingContextChange=null,e+=h,this.to+=h;return}else n=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=h,this.to+=h;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),c.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange;!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}},H=class Ea{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(n=>n.forEach(r=>i(r,this)))||(n=>this.update(n)),this.dispatch=this.dispatch.bind(this),this._root=t.root||Gv(t.parent)||document,this.viewState=new iu(t.state||$.create(t)),t.scrollTo&&t.scrollTo.is(Vs)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(On).map(n=>new Yo(n));for(let n of this.plugins)n.update(this);this.observer=new fC(this),this.inputState=new Lk(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Hf(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=t.length==1&&t[0]instanceof it?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,n,r=this.state;for(let u of t){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;t.some(u=>u.annotation(e0))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=i0(r,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(h=null)):this.observer.clear(),r.facet($.phrases)!=this.state.facet($.phrases))return this.setState(r);n=Nf.create(this,r,t),n.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new Uo(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Vs)&&(f=d.value.clip(this.state))}this.viewState.update(n,f),this.bidiCache=lu.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(Tn)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Gs)!=n.state.facet(Gs)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(va))try{u(n)}catch(d){Re(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!Xm(this,h)&&c.force&&Fi(this.contentDOM,c.key,c.keyCode)})}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new iu(t),this.plugins=t.facet(On).map(i=>new Yo(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Hf(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(On),i=t.state.facet(On);if(e!=i){let n=[];for(let r of i){let o=e.indexOf(r);if(o<0)n.push(new Yo(r));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Re(this.state,i,"doc view update listener")}}}measure(t=!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,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(cm(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);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 c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return Re(this.state,p),ou}}),f=Nf.create(this,this.state,[]),u=!1;f.flags|=a,e?e.flags|=a:e=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<c.length;d++)if(h[d]!=ou)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){Re(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){n=n+p,i.scrollTop=n/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(va))l(e)}get themeClasses(){return Ta+" "+(this.state.facet(Oa)?h0:a0)+" "+this.state.facet(Gs)}updateAttrs(){let t=au(this,Wm,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Ke)?"true":"false",class:"cm-content",style:`${D.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),au(this,$h,e);let i=this.observer.ignore(()=>{let n=ma(this.contentDOM,this.contentAttrs,e),r=ma(this.dom,this.editorAttrs,t);return n||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let n of i.effects)if(n.is(Ea.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(Tn);let t=this.state.facet(Ea.cspNonce);lt.mount(this.root,this.styleModules.concat(hC).reverse(),t?{nonce:t}: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(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.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(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return _o(this,t,zf(this,t,e,i))}moveByGroup(t,e){return _o(this,t,zf(this,t,e,i=>Ck(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return w.cursor(r.side(e,n)+t.from,r.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return kk(this,t,e,i)}moveVertically(t,e,i){return _o(this,t,Mk(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),Ym(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(t),r=this.bidiSpans(n),o=r[_e.find(r,t-n.from,-1,e)];return yo(i,o.dir==St.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Fm)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>pC)return Bm(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||Tm(r.isolates,i=$f(this,t))))return r.order;i||(i=$f(this,t));let n=rk(t.text,e,i);return this.bidiCache.push(new lu(t.from,t.to,e,i,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||D.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{am(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.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(t,e={}){return Vs.of(new Uo(typeof t=="number"?w.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Vs.of(new Uo(w.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return rs.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return rs.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=lt.newName(),n=[Gs.of(i),Tn.of(Ba(`.${i}`,t))];return e&&e.dark&&n.push(Oa.of(!0)),n}static baseTheme(t){return _t.lowest(Tn.of(Ba("."+Ta,t,c0)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&tt.get(i)||tt.get(t);return((e=n==null?void 0:n.rootView)===null||e===void 0?void 0:e.view)||null}};H.styleModule=Tn;H.inputHandler=Nm;H.clipboardInputFilter=Lh;H.clipboardOutputFilter=Ph;H.scrollHandler=Im;H.focusChangeEffect=Hm;H.perLineTextDirection=Fm;H.exceptionSink=$m;H.updateListener=va;H.editable=Ke;H.mouseSelectionStyle=Pm;H.dragMovesSelection=Lm;H.clickAddsSelectionRange=Rm;H.decorations=os;H.outerDecorations=zm;H.atomicRanges=Nh;H.bidiIsolatedRanges=Km;H.scrollMargins=qm;H.darkTheme=Oa;H.cspNonce=v.define({combine:s=>s.length?s[0]:""});H.contentAttributes=$h;H.editorAttributes=Wm;H.lineWrapping=H.contentAttributes.of({class:"cm-lineWrapping"});H.announce=R.define();const pC=4096,ou={};let lu=class f0{constructor(t,e,i,n,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:St.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==n&&!e.touchesRange(o.from,o.to)&&i.push(new f0(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}};function au(s,t,e){for(let i=s.state.facet(t),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&ga(o,e)}return e}const gC=D.mac?"mac":D.windows?"win":D.linux?"linux":"key";function mC(s,t){const e=s.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;a<e.length-1;++a){const c=e[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))n=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Us(s,t,e){return t.altKey&&(s="Alt-"+s),t.ctrlKey&&(s="Ctrl-"+s),t.metaKey&&(s="Meta-"+s),e!==!1&&t.shiftKey&&(s="Shift-"+s),s}const bC=_t.default(H.domEventHandlers({keydown(s,t){return d0(u0(t.state),s,t,"editor")}})),yC=v.define({enables:bC}),hu=new WeakMap;function u0(s){let t=s.facet(yC),e=hu.get(t);return e||hu.set(t,e=SC(t.reduce((i,n)=>i.concat(n),[]))),e}function wC(s,t,e){return d0(u0(s.state),t,s,e)}let je=null;const xC=4e3;function SC(s,t=gC){let e=Object.create(null),i=Object.create(null),n=(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,c,h)=>{var f,u;let d=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(m=>mC(m,t));for(let m=1;m<p.length;m++){let y=p.slice(0,m).join(" ");n(y,!0),d[y]||(d[y]={preventDefault:!0,stopPropagation:!1,run:[S=>{let x=je={view:S,prefix:y,scope:o};return setTimeout(()=>{je==x&&(je=null)},xC),!0}]})}let g=p.join(" ");n(g,!1);let b=d[g]||(d[g]={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&&b.run.push(a),c&&(b.preventDefault=!0),h&&(b.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=e[c]||(e[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in h)h[u].run.push(d=>f(d,Ra))}let a=o[t]||o.key;if(a)for(let c of l)r(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return e}let Ra=null;function d0(s,t,e,i){Ra=t;let n=Za(t),r=ht(n,0),o=Rt(r)==n.length&&n!=" ",l="",a=!1,c=!1,h=!1;je&&je.view==e&&je.scope==i&&(l=je.prefix+" ",Jm.indexOf(t.keyCode)<0&&(c=!0,je=null));let f=new Set,u=b=>{if(b){for(let m of b.run)if(!f.has(m)&&(f.add(m),m(e)))return b.stopPropagation&&(h=!0),!0;b.preventDefault&&(b.stopPropagation&&(h=!0),c=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+Us(n,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(D.windows&&t.ctrlKey&&t.altKey)&&(p=th[t.keyCode])&&p!=n?(u(d[l+Us(p,t,!0)])||t.shiftKey&&(g=eh[t.keyCode])!=n&&g!=p&&u(d[l+Us(g,t,!1)]))&&(a=!0):o&&t.shiftKey&&u(d[l+Us(n,t,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),c&&(a=!0),a&&h&&t.stopPropagation(),Ra=null,a}const vC=!D.ios,cu={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};vC&&(cu[".cm-line"].caretColor=cu[".cm-content"].caretColor="transparent !important");const fu=v.define({combine(s){let t,e;for(let i of s)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function jr(s,t){let e=s.plugin(p0),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const p0=rs.fromClass(class{constructor(s){this.input=s.state.facet(Gr),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(s));let t=s.state.facet(fu);this.top=new Ys(s,!0,t.topContainer),this.bottom=new Ys(s,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(s){let t=s.state.facet(fu);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new Ys(s.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ys(s.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=s.state.facet(Gr);if(e!=this.input){let i=e.filter(a=>a),n=[],r=[],o=[],l=[];for(let a of i){let c=this.specs.indexOf(a),h;c<0?(h=a(s.view),l.push(h)):(h=this.panels[c],h.update&&h.update(s)),n.push(h),(h.top?r:o).push(h)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>H.scrollMargins.of(t=>{let e=t.plugin(s);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class Ys{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=uu(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=uu(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function uu(s){let t=s.nextSibling;return s.remove(),t}const Gr=v.define({enables:p0});let tn=class extends Gt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}};tn.prototype.elementClass="";tn.prototype.toDOM=void 0;tn.prototype.mapMode=I.TrackBefore;tn.prototype.startSide=tn.prototype.endSide=-1;tn.prototype.point=!0;const du=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class en{constructor(t,e,i=0,n=t.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(du(l)):du,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ht(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=sh(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=Rt(t);let n=this.normalize(e);for(let r=0,o=i;;r++){let l=n.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==n.length-1){if(a)return this.value=a,this;break}o==i&&r<e.length&&e.charCodeAt(r)==l&&o++}}}match(t,e,i){let n=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?n={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?n={from:e,to:i}:this.matches.push(1,e)),n&&this.test&&!this.test(n.from,n.to,this.buffer,this.bufferStart)&&(n=null),n}}typeof Symbol<"u"&&(en.prototype[Symbol.iterator]=function(){return this});const g0={from:-1,to:-1,match:/.*/.exec("")},Fh="gm"+(/x/.unicode==null?"":"u");class m0{constructor(t,e,i,n=0,r=t.length){if(this.text=t,this.to=r,this.curLine="",this.done=!1,this.value=g0,/\\[sWDnr]|\n|\r|\[\^/.test(e))return new b0(t,e,i,n,r);this.re=new RegExp(e,Fh+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=t.iter();let o=t.lineAt(n);this.curLineStart=o.from,this.matchPos=Ur(t,n),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,n=i+e[0].length;if(this.matchPos=Ur(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,match:e},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const Zo=new WeakMap;class Vi{constructor(t,e){this.from=t,this.text=e}get to(){return this.from+this.text.length}static get(t,e,i){let n=Zo.get(t);if(!n||n.from>=i||n.to<=e){let l=new Vi(e,t.sliceString(e,i));return Zo.set(t,l),l}if(n.from==e&&n.to==i)return n;let{text:r,from:o}=n;return o>e&&(r=t.sliceString(e,o)+r,o=e),n.to<i&&(r+=t.sliceString(n.to,i)),Zo.set(t,new Vi(o,r)),new Vi(e,r.slice(e-o,i-o))}}class b0{constructor(t,e,i,n,r){this.text=t,this.to=r,this.done=!1,this.value=g0,this.matchPos=Ur(t,n),this.re=new RegExp(e,Fh+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Vi.get(t,n,this.chunkEnd(n+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let i=this.flat.from+e.index,n=i+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,match:e},this.matchPos=Ur(this.text,n+(i==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Vi.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(m0.prototype[Symbol.iterator]=b0.prototype[Symbol.iterator]=function(){return this});function kC(s){try{return new RegExp(s,Fh),!0}catch{return!1}}function Ur(s,t){if(t>=s.length)return t;let e=s.lineAt(t),i;for(;t<e.to&&(i=e.text.charCodeAt(t-e.from))>=56320&&i<57344;)t++;return t}function La(s){let t=String(s.state.doc.lineAt(s.state.selection.main.head).number),e=G("input",{class:"cm-textfield",name:"line",value:t}),i=G("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),s.dispatch({effects:Yr.of(!1)}),s.focus()):r.keyCode==13&&(r.preventDefault(),n())},onsubmit:r=>{r.preventDefault(),n()}},G("label",s.state.phrase("Go to line"),": ",e)," ",G("button",{class:"cm-button",type:"submit"},s.state.phrase("go")));function n(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!r)return;let{state:o}=s,l=o.doc.lineAt(o.selection.main.head),[,a,c,h,f]=r,u=h?+h.slice(1):0,d=c?+c:l.number;if(c&&f){let b=d/100;a&&(b=b*(a=="-"?-1:1)+l.number/o.doc.lines),d=Math.round(o.doc.lines*b)}else c&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=o.doc.line(Math.max(1,Math.min(o.doc.lines,d))),g=w.cursor(p.from+Math.max(0,Math.min(u,p.length)));s.dispatch({effects:[Yr.of(!1),H.scrollIntoView(g.from,{y:"center"})],selection:g}),s.focus()}return{dom:i}}const Yr=R.define(),pu=ct.define({create(){return!0},update(s,t){for(let e of t.effects)e.is(Yr)&&(s=e.value);return s},provide:s=>Gr.from(s,t=>t?La:null)}),CC=s=>{let t=jr(s,La);if(!t){let e=[Yr.of(!0)];s.state.field(pu,!1)==null&&e.push(R.appendConfig.of([pu,MC])),s.dispatch({effects:e}),t=jr(s,La)}return t&&t.dom.querySelector("input").select(),!0},MC=H.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),AC={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},DC=v.define({combine(s){return De(s,AC,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})}});function OC(s){return[LC,RC]}const TC=U.mark({class:"cm-selectionMatch"}),BC=U.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function gu(s,t,e,i){return(e==0||s(t.sliceDoc(e-1,e))!=Y.Word)&&(i==t.doc.length||s(t.sliceDoc(i,i+1))!=Y.Word)}function EC(s,t,e,i){return s(t.sliceDoc(e,e+1))==Y.Word&&s(t.sliceDoc(i-1,i))==Y.Word}const RC=rs.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.selectionSet||s.docChanged||s.viewportChanged)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let t=s.state.facet(DC),{state:e}=s,i=e.selection;if(i.ranges.length>1)return U.none;let n=i.main,r,o=null;if(n.empty){if(!t.highlightWordAroundCursor)return U.none;let a=e.wordAt(n.head);if(!a)return U.none;o=e.charCategorizer(n.head),r=e.sliceDoc(a.from,a.to)}else{let a=n.to-n.from;if(a<t.minSelectionLength||a>200)return U.none;if(t.wholeWords){if(r=e.sliceDoc(n.from,n.to),o=e.charCategorizer(n.head),!(gu(o,e,n.from,n.to)&&EC(o,e,n.from,n.to)))return U.none}else if(r=e.sliceDoc(n.from,n.to),!r)return U.none}let l=[];for(let a of s.visibleRanges){let c=new en(e.doc,r,a.from,a.to);for(;!c.next().done;){let{from:h,to:f}=c.value;if((!o||gu(o,e,h,f))&&(n.empty&&h<=n.from&&f>=n.to?l.push(BC.range(h,f)):(h>=n.to||f<=n.from)&&l.push(TC.range(h,f)),l.length>t.maxMatches))return U.none}}return U.set(l)}},{decorations:s=>s.decorations}),LC=H.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),PC=({state:s,dispatch:t})=>{let{selection:e}=s,i=w.create(e.ranges.map(n=>s.wordAt(n.head)||w.cursor(n.head)),e.mainIndex);return i.eq(e)?!1:(t(s.update({selection:i})),!0)};function $C(s,t){let{main:e,ranges:i}=s.selection,n=s.wordAt(e.head),r=n&&n.from==e.from&&n.to==e.to;for(let o=!1,l=new en(s.doc,t,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new en(s.doc,t,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=s.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const NC=({state:s,dispatch:t})=>{let{ranges:e}=s.selection;if(e.some(r=>r.from===r.to))return PC({state:s,dispatch:t});let i=s.sliceDoc(e[0].from,e[0].to);if(s.selection.ranges.some(r=>s.sliceDoc(r.from,r.to)!=i))return!1;let n=$C(s,i);return n?(t(s.update({selection:s.selection.addRange(w.range(n.from,n.to),!1),effects:H.scrollIntoView(n.to)})),!0):!1},fn=v.define({combine(s){return De(s,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new YC(t),scrollToMatch:t=>H.scrollIntoView(t)})}});class y0{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||kC(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(e,i)=>i=="n"?`
15
- `:i=="r"?"\r":i=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new VC(this):new FC(this)}getCursor(t,e=0,i){let n=t.doc?t:$.create({doc:t});return i==null&&(i=n.doc.length),this.regexp?Oi(this,n,e,i):Di(this,n,e,i)}}let w0=class{constructor(t){this.spec=t}};function Di(s,t,e,i){return new en(t.doc,s.unquoted,e,i,s.caseSensitive?void 0:n=>n.toLowerCase(),s.wholeWord?HC(t.doc,t.charCategorizer(t.selection.main.head)):void 0)}function HC(s,t){return(e,i,n,r)=>((r>e||r+n.length<i)&&(r=Math.max(0,e-2),n=s.sliceString(r,Math.min(s.length,i+2))),(t(Xr(n,e-r))!=Y.Word||t(_r(n,e-r))!=Y.Word)&&(t(_r(n,i-r))!=Y.Word||t(Xr(n,i-r))!=Y.Word))}class FC extends w0{constructor(t){super(t)}nextMatch(t,e,i){let n=Di(this.spec,t,i,t.doc.length).nextOverlapping();return n.done&&(n=Di(this.spec,t,0,e).nextOverlapping()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=i;;){let r=Math.max(e,n-1e4-this.spec.unquoted.length),o=Di(this.spec,t,r,n),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==e)return null;n-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Di(this.spec,t,0,t.doc.length),n=[];for(;!i.next().done;){if(n.length>=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let r=Di(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function Oi(s,t,e,i){return new m0(t.doc,s.search,{ignoreCase:!s.caseSensitive,test:s.wholeWord?IC(t.charCategorizer(t.selection.main.head)):void 0},e,i)}function Xr(s,t){return s.slice(V(s,t,!1),t)}function _r(s,t){return s.slice(t,V(s,t))}function IC(s){return(t,e,i)=>!i[0].length||(s(Xr(i.input,i.index))!=Y.Word||s(_r(i.input,i.index))!=Y.Word)&&(s(_r(i.input,i.index+i[0].length))!=Y.Word||s(Xr(i.input,i.index+i[0].length))!=Y.Word)}class VC extends w0{nextMatch(t,e,i){let n=Oi(this.spec,t,i,t.doc.length).next();return n.done&&(n=Oi(this.spec,t,0,e).next()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=1;;n++){let r=Math.max(e,i-n*1e4),o=Oi(this.spec,t,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==e||l.from>r+10))return l;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(e,i)=>i=="$"?"$":i=="&"?t.match[0]:i!="0"&&+i<t.match.length?t.match[i]:e)}matchAll(t,e){let i=Oi(this.spec,t,0,t.doc.length),n=[];for(;!i.next().done;){if(n.length>=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let r=Oi(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const ls=R.define(),Ih=R.define(),ei=ct.define({create(s){return new tl(Pa(s).create(),null)},update(s,t){for(let e of t.effects)e.is(ls)?s=new tl(e.value.create(),s.panel):e.is(Ih)&&(s=new tl(s.query,e.value?Vh:null));return s},provide:s=>Gr.from(s,t=>t.panel)});class tl{constructor(t,e){this.query=t,this.panel=e}}const WC=U.mark({class:"cm-searchMatch"}),zC=U.mark({class:"cm-searchMatch cm-searchMatch-selected"}),KC=rs.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(ei))}update(s){let t=s.state.field(ei);(t!=s.startState.field(ei)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:s,panel:t}){if(!t||!s.spec.valid)return U.none;let{view:e}=this,i=new ii;for(let n=0,r=e.visibleRanges,o=r.length;n<o;n++){let{from:l,to:a}=r[n];for(;n<o-1&&a>r[n+1].from-2*250;)a=r[++n].to;s.highlight(e.state,l,a,(c,h)=>{let f=e.state.selection.ranges.some(u=>u.from==c&&u.to==h);i.add(c,h,f?zC:WC)})}return i.finish()}},{decorations:s=>s.decorations});function ws(s){return t=>{let e=t.state.field(ei,!1);return e&&e.query.spec.valid?s(t,e):v0(t)}}const Jr=ws((s,{query:t})=>{let{to:e}=s.state.selection.main,i=t.nextMatch(s.state,e,e);if(!i)return!1;let n=w.single(i.from,i.to),r=s.state.facet(fn);return s.dispatch({selection:n,effects:[Wh(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),S0(s),!0}),Qr=ws((s,{query:t})=>{let{state:e}=s,{from:i}=e.selection.main,n=t.prevMatch(e,i,i);if(!n)return!1;let r=w.single(n.from,n.to),o=s.state.facet(fn);return s.dispatch({selection:r,effects:[Wh(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),S0(s),!0}),qC=ws((s,{query:t})=>{let e=t.matchAll(s.state,1e3);return!e||!e.length?!1:(s.dispatch({selection:w.create(e.map(i=>w.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),jC=({state:s,dispatch:t})=>{let e=s.selection;if(e.ranges.length>1||e.main.empty)return!1;let{from:i,to:n}=e.main,r=[],o=0;for(let l=new en(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(w.range(l.value.from,l.value.to))}return t(s.update({selection:w.create(r,o),userEvent:"select.search.matches"})),!0},mu=ws((s,{query:t})=>{let{state:e}=s,{from:i,to:n}=e.selection.main;if(e.readOnly)return!1;let r=t.nextMatch(e,i,i);if(!r)return!1;let o=[],l,a,c=[];if(r.from==i&&r.to==n&&(a=e.toText(t.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=t.nextMatch(e,r.from,r.to),c.push(H.announce.of(e.phrase("replaced match on line $",e.doc.lineAt(i).number)+"."))),r){let h=o.length==0||o[0].from>=r.to?0:r.to-r.from-a.length;l=w.single(r.from-h,r.to-h),c.push(Wh(s,r)),c.push(e.facet(fn).scrollToMatch(l.main,s))}return s.dispatch({changes:o,selection:l,effects:c,userEvent:"input.replace"}),!0}),GC=ws((s,{query:t})=>{if(s.state.readOnly)return!1;let e=t.matchAll(s.state,1e9).map(n=>{let{from:r,to:o}=n;return{from:r,to:o,insert:t.getReplacement(n)}});if(!e.length)return!1;let i=s.state.phrase("replaced $ matches",e.length)+".";return s.dispatch({changes:e,effects:H.announce.of(i),userEvent:"input.replace.all"}),!0});function Vh(s){return s.state.facet(fn).createPanel(s)}function Pa(s,t){var e,i,n,r,o;let l=s.selection.main,a=l.empty||l.to>l.from+100?"":s.sliceDoc(l.from,l.to);if(t&&!a)return t;let c=s.facet(fn);return new y0({search:((e=t==null?void 0:t.literal)!==null&&e!==void 0?e:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=t==null?void 0:t.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(n=t==null?void 0:t.literal)!==null&&n!==void 0?n:c.literal,regexp:(r=t==null?void 0:t.regexp)!==null&&r!==void 0?r:c.regexp,wholeWord:(o=t==null?void 0:t.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function x0(s){let t=jr(s,Vh);return t&&t.dom.querySelector("[main-field]")}function S0(s){let t=x0(s);t&&t==s.root.activeElement&&t.select()}const v0=s=>{let t=s.state.field(ei,!1);if(t&&t.panel){let e=x0(s);if(e&&e!=s.root.activeElement){let i=Pa(s.state,t.query.spec);i.valid&&s.dispatch({effects:ls.of(i)}),e.focus(),e.select()}}else s.dispatch({effects:[Ih.of(!0),t?ls.of(Pa(s.state,t.query.spec)):R.appendConfig.of(_C)]});return!0},k0=s=>{let t=s.state.field(ei,!1);if(!t||!t.panel)return!1;let e=jr(s,Vh);return e&&e.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:Ih.of(!1)}),!0},UC=[{key:"Mod-f",run:v0,scope:"editor search-panel"},{key:"F3",run:Jr,shift:Qr,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Jr,shift:Qr,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:k0,scope:"editor search-panel"},{key:"Mod-Shift-l",run:jC},{key:"Mod-Alt-g",run:CC},{key:"Mod-d",run:NC,preventDefault:!0}];class YC{constructor(t){this.view=t;let e=this.query=t.state.field(ei).query.spec;this.commit=this.commit.bind(this),this.searchField=G("input",{value:e.search,placeholder:Pt(t,"Find"),"aria-label":Pt(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=G("input",{value:e.replace,placeholder:Pt(t,"Replace"),"aria-label":Pt(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=G("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=G("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=G("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit});function i(n,r,o){return G("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=G("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>Jr(t),[Pt(t,"next")]),i("prev",()=>Qr(t),[Pt(t,"previous")]),i("select",()=>qC(t),[Pt(t,"all")]),G("label",null,[this.caseField,Pt(t,"match case")]),G("label",null,[this.reField,Pt(t,"regexp")]),G("label",null,[this.wordField,Pt(t,"by word")]),...t.state.readOnly?[]:[G("br"),this.replaceField,i("replace",()=>mu(t),[Pt(t,"replace")]),i("replaceAll",()=>GC(t),[Pt(t,"replace all")])],G("button",{name:"close",onclick:()=>k0(t),"aria-label":Pt(t,"close"),type:"button"},["×"])])}commit(){let t=new y0({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:ls.of(t)}))}keydown(t){wC(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Qr:Jr)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),mu(this.view))}update(t){for(let e of t.transactions)for(let i of e.effects)i.is(ls)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(fn).top}}function Pt(s,t){return s.state.phrase(t)}const Xs=30,_s=/[\s\.,:;?!]/;function Wh(s,{from:t,to:e}){let i=s.state.doc.lineAt(t),n=s.state.doc.lineAt(e).to,r=Math.max(i.from,t-Xs),o=Math.min(n,e+Xs),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<Xs;a++)if(!_s.test(l[a+1])&&_s.test(l[a])){l=l.slice(a);break}}if(o!=n){for(let a=l.length-1;a>l.length-Xs;a--)if(!_s.test(l[a-1])&&_s.test(l[a])){l=l.slice(0,a);break}}return H.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const XC=H.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),_C=[ei,_t.low(KC),XC];class JC{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class hi{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=t,r=i.facet(ve).markerFilter;r&&(n=r(n,i));let o=P.set(n.map(l=>l.from==l.to||l.from==l.to-1&&i.doc.lineAt(l.from).to==l.from?P.widget({widget:new lM(l),diagnostic:l}).range(l.from):P.mark({attributes:{class:"cm-lintRange cm-lintRange-"+l.severity+(l.markClass?" "+l.markClass:"")},diagnostic:l}).range(l.from,l.to)),!0);return new hi(o,e,nn(o))}}function nn(s,t=null,e=0){let i=null;return s.between(e,1e9,(n,r,{spec:o})=>{if(!(t&&o.diagnostic!=t))return i=new JC(n,r,o.diagnostic),!1}),i}function QC(s,t){let e=t.pos,i=t.end||e,n=s.state.facet(ve).hideOn(s,e,i);if(n!=null)return n;let r=s.startState.doc.lineAt(t.pos);return!!(s.effects.some(o=>o.is(zh))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function C0(s,t){return s.field(It,!1)?t:t.concat(R.appendConfig.of(O0))}function ZC(s,t){return{effects:C0(s,[zh.of(t)])}}const zh=R.define(),Kh=R.define(),M0=R.define(),It=ct.define({create(){return new hi(P.none,null,null)},update(s,t){if(t.docChanged&&s.diagnostics.size){let e=s.diagnostics.map(t.changes),i=null,n=s.panel;if(s.selected){let r=t.changes.mapPos(s.selected.from,1);i=nn(e,s.selected.diagnostic,r)||nn(e,null,r)}!e.size&&n&&t.state.facet(ve).autoPanel&&(n=null),s=new hi(e,n,i)}for(let e of t.effects)if(e.is(zh)){let i=t.state.facet(ve).autoPanel?e.value.length?as.open:null:s.panel;s=hi.init(e.value,i,t.state)}else e.is(Kh)?s=new hi(s.diagnostics,e.value?as.open:null,s.selected):e.is(M0)&&(s=new hi(s.diagnostics,s.panel,e.value));return s},provide:s=>[Xl.from(s,t=>t.panel),T.decorations.from(s,t=>t.diagnostics)]}),tM=P.mark({class:"cm-lintRange cm-lintRange-active"});function eM(s,t,e){let{diagnostics:i}=s.state.field(It),n=[],r=2e8,o=0;i.between(t-(e<0?1:0),t+(e>0?1:0),(a,c,{spec:h})=>{t>=a&&t<=c&&(a==c||(t>a||e>0)&&(t<c||e<0))&&(n.push(h.diagnostic),r=Math.min(a,r),o=Math.max(c,o))});let l=s.state.facet(ve).tooltipFilter;return l&&(n=l(n,s.state)),n.length?{pos:r,end:o,above:s.state.doc.lineAt(r).to<o,create(){return{dom:iM(s,n)}}}:null}function iM(s,t){return G("ul",{class:"cm-tooltip-lint"},t.map(e=>D0(s,e,!1)))}const nM=s=>{let t=s.state.field(It,!1);(!t||!t.panel)&&s.dispatch({effects:C0(s.state,[Kh.of(!0)])});let e=Aw(s,as.open);return e&&e.dom.querySelector(".cm-panel-lint ul").focus(),!0},bu=s=>{let t=s.state.field(It,!1);return!t||!t.panel?!1:(s.dispatch({effects:Kh.of(!1)}),!0)},sM=s=>{let t=s.state.field(It,!1);if(!t)return!1;let e=s.state.selection.main,i=t.diagnostics.iter(e.to+1);return!i.value&&(i=t.diagnostics.iter(0),!i.value||i.from==e.from&&i.to==e.to)?!1:(s.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},rM=[{key:"Mod-Shift-m",run:nM,preventDefault:!0},{key:"F8",run:sM}],oM=pt.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:t}=s.state.facet(ve);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:t}=this.view,{sources:e}=t.facet(ve);e.length&&Promise.all(e.map(i=>Promise.resolve(i(this.view)))).then(i=>{let n=i.reduce((r,o)=>r.concat(o));this.view.state.doc==t.doc&&this.view.dispatch(ZC(this.view.state,n))},i=>{xt(this.view.state,i)})}}update(s){let t=s.state.facet(ve);(s.docChanged||t!=s.startState.facet(ve)||t.needsRefresh&&t.needsRefresh(s))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}}),ve=v.define({combine(s){return Object.assign({sources:s.map(t=>t.source).filter(t=>t!=null)},De(s.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e}))}});function qD(s,t={}){return[ve.of({source:s,config:t}),oM,O0]}function A0(s){let t=[];if(s)t:for(let{name:e}of s){for(let i=0;i<e.length;i++){let n=e[i];if(/[a-zA-Z]/.test(n)&&!t.some(r=>r.toLowerCase()==n.toLowerCase())){t.push(n);continue t}}t.push("")}return t}function D0(s,t,e){var i;let n=e?A0(t.actions):[];return G("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},G("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(s):t.message),(i=t.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=u=>{if(u.preventDefault(),l)return;l=!0;let d=nn(s.state.field(It).diagnostics,t);d&&r.apply(s,d.from,d.to)},{name:c}=r,h=n[o]?c.indexOf(n[o]):-1,f=h<0?c:[c.slice(0,h),G("u",c.slice(h,h+1)),c.slice(h+1)];return G("button",{type:"button",class:"cm-diagnosticAction",onclick:a,onmousedown:a,"aria-label":` Action: ${c}${h<0?"":` (access key "${n[o]})"`}.`},f)}),t.source&&G("div",{class:"cm-diagnosticSource"},t.source))}class lM extends Oe{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return G("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class yu{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=D0(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class as{constructor(t){this.view=t,this.items=[];let e=n=>{if(n.keyCode==27)bu(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=A0(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==n.keyCode){let a=nn(this.view.state.field(It).diagnostics,r);a&&r.actions[l].apply(t,a.from,a.to)}}else return;n.preventDefault()},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=G("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e,onclick:i}),this.dom=G("div",{class:"cm-panel-lint"},this.list,G("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>bu(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(It).selected;if(!t)return-1;for(let e=0;e<this.items.length;e++)if(this.items[e].diagnostic==t.diagnostic)return e;return-1}update(){let{diagnostics:t,selected:e}=this.view.state.field(It),i=0,n=!1,r=null;for(t.between(0,this.view.state.doc.length,(o,l,{spec:a})=>{let c=-1,h;for(let f=i;f<this.items.length;f++)if(this.items[f].diagnostic==a.diagnostic){c=f;break}c<0?(h=new yu(this.view,a.diagnostic),this.items.splice(i,0,h),n=!0):(h=this.items[c],c>i&&(this.items.splice(i,c-i),n=!0)),e&&h.diagnostic==e.diagnostic?h.dom.hasAttribute("aria-selected")||(h.dom.setAttribute("aria-selected","true"),r=h):h.dom.hasAttribute("aria-selected")&&h.dom.removeAttribute("aria-selected"),i++});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new yu(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:o,panel:l})=>{let a=l.height/this.list.offsetHeight;o.top<l.top?this.list.scrollTop-=(l.top-o.top)/a:o.bottom>l.bottom&&(this.list.scrollTop+=(o.bottom-l.bottom)/a)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let t=this.list.firstChild;function e(){let i=t;t=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=this.view.state.field(It),i=nn(e.diagnostics,this.items[t].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:M0.of(i)})}static open(t){return new as(t)}}function aM(s,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(s)}</svg>')`}function Js(s){return aM(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const hM=T.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Js("#d11")},".cm-lintRange-warning":{backgroundImage:Js("orange")},".cm-lintRange-info":{backgroundImage:Js("#999")},".cm-lintRange-hint":{backgroundImage:Js("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}}),O0=[It,T.decorations.compute([It],s=>{let{selected:t,panel:e}=s.field(It);return!t||!e||t.from==t.to?P.none:P.set([tM.range(t.from,t.to)])}),Cw(eM,{hideOn:QC}),hM];var wu=function(t){t===void 0&&(t={});var{crosshairCursor:e=!1}=t,i=[];t.closeBracketsKeymap!==!1&&(i=i.concat(uS)),t.defaultKeymap!==!1&&(i=i.concat(Vv)),t.searchKeymap!==!1&&(i=i.concat(UC)),t.historyKeymap!==!1&&(i=i.concat(YS)),t.foldKeymap!==!1&&(i=i.concat(sx)),t.completionKeymap!==!1&&(i=i.concat(Mg)),t.lintKeymap!==!1&&(i=i.concat(rM));var n=[];return t.lineNumbers!==!1&&n.push(Pw()),t.highlightActiveLineGutter!==!1&&n.push(Hw()),t.highlightSpecialChars!==!1&&n.push(Z1()),t.history!==!1&&n.push(IS()),t.foldGutter!==!1&&n.push(ax()),t.drawSelection!==!1&&n.push(z1()),t.dropCursor!==!1&&n.push(U1()),t.allowMultipleSelections!==!1&&n.push($.allowMultipleSelections.of(!0)),t.indentOnInput!==!1&&n.push(Xw()),t.syntaxHighlighting!==!1&&n.push(vh(ux,{fallback:!0})),t.bracketMatching!==!1&&n.push(wx()),t.closeBrackets!==!1&&n.push(aS()),t.autocompletion!==!1&&n.push(wS()),t.rectangularSelection!==!1&&n.push(dw()),e!==!1&&n.push(mw()),t.highlightActiveLine!==!1&&n.push(rw()),t.highlightSelectionMatches!==!1&&n.push(OC()),t.tabSize&&typeof t.tabSize=="number"&&n.push(an.of(" ".repeat(t.tabSize))),n.concat([ps.of(i.flat())]).filter(Boolean)};const cM="#e5c07b",xu="#e06c75",fM="#56b6c2",uM="#ffffff",Ar="#abb2bf",$a="#7d8799",dM="#61afef",pM="#98c379",Su="#d19a66",gM="#c678dd",mM="#21252b",vu="#2c313a",ku="#282c34",el="#353a42",bM="#3E4451",Cu="#528bff",yM=H.theme({"&":{color:Ar,backgroundColor:ku},".cm-content":{caretColor:Cu},".cm-cursor, .cm-dropCursor":{borderLeftColor:Cu},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:bM},".cm-panels":{backgroundColor:mM,color:Ar},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:ku,color:$a,border:"none"},".cm-activeLineGutter":{backgroundColor:vu},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:el},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:el,borderBottomColor:el},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:vu,color:Ar}}},{dark:!0}),wM=hn.define([{tag:L.keyword,color:gM},{tag:[L.name,L.deleted,L.character,L.propertyName,L.macroName],color:xu},{tag:[L.function(L.variableName),L.labelName],color:dM},{tag:[L.color,L.constant(L.name),L.standard(L.name)],color:Su},{tag:[L.definition(L.name),L.separator],color:Ar},{tag:[L.typeName,L.className,L.number,L.changed,L.annotation,L.modifier,L.self,L.namespace],color:cM},{tag:[L.operator,L.operatorKeyword,L.url,L.escape,L.regexp,L.link,L.special(L.string)],color:fM},{tag:[L.meta,L.comment],color:$a},{tag:L.strong,fontWeight:"bold"},{tag:L.emphasis,fontStyle:"italic"},{tag:L.strikethrough,textDecoration:"line-through"},{tag:L.link,color:$a,textDecoration:"underline"},{tag:L.heading,fontWeight:"bold",color:xu},{tag:[L.atom,L.bool,L.special(L.variableName)],color:Su},{tag:[L.processingInstruction,L.string,L.inserted],color:pM},{tag:L.invalid,color:uM}]),xM=[yM,vh(wM)];var SM=T.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),vM=function(t){t===void 0&&(t={});var{indentWithTab:e=!0,editable:i=!0,readOnly:n=!1,theme:r="light",placeholder:o="",basicSetup:l=!0}=t,a=[];switch(e&&a.unshift(ps.of([Wv])),l&&(typeof l=="boolean"?a.unshift(wu()):a.unshift(wu(l))),o&&a.unshift(hw(o)),r){case"light":a.push(SM);break;case"dark":a.push(xM);break;case"none":break;default:a.push(r);break}return i===!1&&a.push(T.editable.of(!1)),n&&a.push($.readOnly.of(!0)),[...a]},kM=s=>({line:s.state.doc.lineAt(s.state.selection.main.from),lineCount:s.state.doc.lines,lineBreak:s.state.lineBreak,length:s.state.doc.length,readOnly:s.state.readOnly,tabSize:s.state.tabSize,selection:s.state.selection,selectionAsSingle:s.state.selection.asSingle().main,ranges:s.state.selection.ranges,selectionCode:s.state.sliceDoc(s.state.selection.main.from,s.state.selection.main.to),selections:s.state.selection.ranges.map(t=>s.state.sliceDoc(t.from,t.to)),selectedText:s.state.selection.ranges.some(t=>!t.empty)}),Mu=Vt.define(),CM=[];function MM(s){var{value:t,selection:e,onChange:i,onStatistics:n,onCreateEditor:r,onUpdate:o,extensions:l=CM,autoFocus:a,theme:c="light",height:h=null,minHeight:f=null,maxHeight:u=null,width:d=null,minWidth:p=null,maxWidth:g=null,placeholder:b="",editable:m=!0,readOnly:y=!1,indentWithTab:S=!0,basicSetup:x=!0,root:k,initialState:M}=s,[N,nt]=zt.useState(),[W,Mt]=zt.useState(),[Be,Qt]=zt.useState(),Ie=T.theme({"&":{height:h,minHeight:f,maxHeight:u,width:d,minWidth:p,maxWidth:g},"& .cm-scroller":{height:"100% !important"}}),Zt=T.updateListener.of(at=>{if(at.docChanged&&typeof i=="function"&&!at.transactions.some(ee=>ee.annotation(Mu))){var te=at.state.doc,At=te.toString();i(At,at)}n&&n(kM(at))}),ue=vM({theme:c,editable:m,readOnly:y,placeholder:b,indentWithTab:S,basicSetup:x}),Wt=[Zt,Ie,...ue];return o&&typeof o=="function"&&Wt.push(T.updateListener.of(o)),Wt=Wt.concat(l),zt.useEffect(()=>{if(N&&!Be){var at={doc:t,selection:e,extensions:Wt},te=M?$.fromJSON(M.json,at,M.fields):$.create(at);if(Qt(te),!W){var At=new T({state:te,parent:N,root:k});Mt(At),r&&r(At,te)}}return()=>{W&&(Qt(void 0),Mt(void 0))}},[N,Be]),zt.useEffect(()=>nt(s.container),[s.container]),zt.useEffect(()=>()=>{W&&(W.destroy(),Mt(void 0))},[W]),zt.useEffect(()=>{a&&W&&W.focus()},[a,W]),zt.useEffect(()=>{W&&W.dispatch({effects:R.reconfigure.of(Wt)})},[c,l,h,f,u,d,p,g,b,m,y,S,x,i,o]),zt.useEffect(()=>{if(t!==void 0){var at=W?W.state.doc.toString():"";W&&t!==at&&W.dispatch({changes:{from:0,to:at.length,insert:t||""},annotations:[Mu.of(!0)]})}},[t,W]),{state:Be,setState:Qt,view:W,setView:Mt,container:N,setContainer:nt}}var AM=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],DM=zt.forwardRef((s,t)=>{var{className:e,value:i="",selection:n,extensions:r=[],onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:c,autoFocus:h,theme:f="light",height:u,minHeight:d,maxHeight:p,width:g,minWidth:b,maxWidth:m,basicSetup:y,placeholder:S,indentWithTab:x,editable:k,readOnly:M,root:N,initialState:nt}=s,W=Vb(s,AM),Mt=zt.useRef(null),{state:Be,view:Qt,container:Ie}=MM({container:Mt.current,root:N,value:i,autoFocus:h,theme:f,height:u,minHeight:d,maxHeight:p,width:g,minWidth:b,maxWidth:m,basicSetup:y,placeholder:S,indentWithTab:x,editable:k,readOnly:M,selection:n,onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:c,extensions:r,initialState:nt});if(zt.useImperativeHandle(t,()=>({editor:Mt.current,state:Be,view:Qt}),[Mt,Ie,Be,Qt]),typeof i!="string")throw new Error("value must be typeof string but got "+typeof i);var Zt=typeof f=="string"?"cm-theme-"+f:"cm-theme";return Wb.jsx("div",dd({ref:Mt,className:""+Zt+(e?" "+e:"")},W))});DM.displayName="CodeMirror";const jD=()=>s=>{try{JSON.parse(s.state.doc.toString())}catch(t){if(!(t instanceof SyntaxError))throw t;const e=OM(t,s.state.doc);return[{from:e,message:t.message,severity:"error",to:e}]}return[]};function OM(s,t){let e;return(e=s.message.match(/at position (\d+)/))?Math.min(+e[1],t.length):(e=s.message.match(/at line (\d+) column (\d+)/))?Math.min(t.line(+e[1]).from+ +e[2]-1,t.length):0}const TM=Yi.define({name:"json",parser:zb.configure({props:[ao.add({Object:Wn({except:/^\s*\}/}),Array:Wn({except:/^\s*\]/})}),ho.add({"Object Array":Sh})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function GD(){return new yh(TM)}function hs(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function Na(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function BM(s){let t=s.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function Dr(s,t){if(!t.anchorNode)return!1;try{return Na(s,t.anchorNode)}catch{return!1}}function cs(s){return s.nodeType==3?vi(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function qn(s,t,e,i){return e?Au(s,t,e,i,-1)||Au(s,t,e,i,1):!1}function Si(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function Zr(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Au(s,t,e,i,n){for(;;){if(s==e&&t==i)return!0;if(t==(n<0?0:He(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;t=Si(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[t+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;t=n<0?He(s):0}else return!1}}function He(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function qh(s,t){let e=t?s.left:s.right;return{left:e,right:e,top:s.top,bottom:s.bottom}}function EM(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function T0(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function RM(s,t,e,i,n,r,o,l){let a=s.ownerDocument,c=a.defaultView||window;for(let h=s,f=!1;h&&!f;)if(h.nodeType==1){let u,d=h==a.body,p=1,g=1;if(d)u=EM(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(f=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let y=h.getBoundingClientRect();({scaleX:p,scaleY:g}=T0(h,y)),u={left:y.left,right:y.left+h.clientWidth*p,top:y.top,bottom:y.top+h.clientHeight*g}}let b=0,m=0;if(n=="nearest")t.top<u.top?(m=-(u.top-t.top+o),e>0&&t.bottom>u.bottom+m&&(m=t.bottom-u.bottom+m+o)):t.bottom>u.bottom&&(m=t.bottom-u.bottom+o,e<0&&t.top-m<u.top&&(m=-(u.top+m-t.top+o)));else{let y=t.bottom-t.top,S=u.bottom-u.top;m=(n=="center"&&y<=S?t.top+y/2-S/2:n=="start"||n=="center"&&e<0?t.top-o:t.bottom-S+o)-u.top}if(i=="nearest"?t.left<u.left?(b=-(u.left-t.left+r),e>0&&t.right>u.right+b&&(b=t.right-u.right+b+r)):t.right>u.right&&(b=t.right-u.right+r,e<0&&t.left<u.left+b&&(b=-(u.left+b-t.left+r))):b=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-r:t.right-(u.right-u.left)+r)-u.left,b||m)if(d)c.scrollBy(b,m);else{let y=0,S=0;if(m){let x=h.scrollTop;h.scrollTop+=m/g,S=(h.scrollTop-x)*g}if(b){let x=h.scrollLeft;h.scrollLeft+=b/p,y=(h.scrollLeft-x)*p}t={left:t.left-y,top:t.top-S,right:t.right-y,bottom:t.bottom-S},y&&Math.abs(y-b)<1&&(i="nearest"),S&&Math.abs(S-m)<1&&(n="nearest")}if(d)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function LM(s){let t=s.ownerDocument,e,i;for(let n=s.parentNode;n&&!(n==t.body||e&&i);)if(n.nodeType==1)!i&&n.scrollHeight>n.clientHeight&&(i=n),!e&&n.scrollWidth>n.clientWidth&&(e=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:e,y:i}}class PM{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?He(e):0),i,Math.min(t.focusOffset,i?He(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let Ai=null;function B0(s){if(s.setActive)return s.setActive();if(Ai)return s.focus(Ai);let t=[];for(let e=s;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(s.focus(Ai==null?{get preventScroll(){return Ai={preventScroll:!0},!0}}:void 0),!Ai){Ai=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Du;function vi(s,t,e=t){let i=Du||(Du=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function Wi(s,t,e,i){let n={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function $M(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function E0(s){for(;s.attributes.length;)s.removeAttributeNode(s.attributes[0])}function NM(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,He(e));;)if(i){if(e.nodeType!=1)return!1;let n=e.childNodes[i-1];n.contentEditable=="false"?i--:(e=n,i=He(e))}else{if(e==s)return!0;i=Si(e),e=e.parentNode}}function R0(s){return s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function L0(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=He(e)}else if(e.parentNode&&!Zr(e))i=Si(e),e=e.parentNode;else return null}}function P0(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!Zr(e))i=Si(e)+1,e=e.parentNode;else return null}}class mt{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new mt(t.parentNode,Si(t),e)}static after(t,e){return new mt(t.parentNode,Si(t)+1,e)}}const jh=[];class j{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,n=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=n?n.nextSibling:i.firstChild)){let l=j.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=n?n.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=Ou(r);else i.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=Ou(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let n=He(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;n==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?n=-1:n=1),t=r}n<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!j.get(i);)i=i.nextSibling;if(!i)return this.length;for(let n=0,r=0;;n++){let o=this.children[n];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(t,e,i=0){let n=-1,r=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<this.children.length;a++){let f=this.children[a],u=c+f.length;if(c<t&&u>e)return f.domBoundsAround(t,e,c);if(u>=t&&n==-1&&(n=a,r=c),c>e&&f.dom.parentNode==this.dom){o=a,l=h;break}h=u,c=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=jh){this.markDirty();for(let n=t;n<e;n++){let r=this.children[n];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(t,e-t,...i);for(let n=0;n<i.length;n++)i[n].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new $0(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,n,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}j.prototype.breakAfter=0;function Ou(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}class $0{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function N0(s,t,e,i,n,r,o,l,a){let{children:c}=s,h=c.length?c[t]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(t==i&&h&&!o&&!u&&r.length<2&&h.merge(e,n,r.length?f:null,e==0,l,a))){if(i<c.length){let d=c[i];d&&(n<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(t==i&&(d=d.split(n),n=0),!u&&f&&d.merge(0,n,f,!0,0,a)?r[r.length-1]=d:((n||d.children.length&&!d.children[0].length)&&d.merge(0,n,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(h&&(h.breakAfter=o,e>0&&(!o&&r.length&&h.merge(e,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(e<h.length||h.children.length&&h.children[h.children.length-1].length==0)&&h.merge(e,h.length,null,!1,l,0),t++));t<i&&r.length;)if(c[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(c[t].become(r[0]))t++,r.shift(),l=r.length?0:a;else break;!r.length&&t&&i<c.length&&!c[t-1].breakAfter&&c[i].merge(0,0,c[t-1],!1,l,a)&&t--,(t<i||r.length)&&s.replaceChildren(t,i,r)}}function H0(s,t,e,i,n,r){let o=s.childCursor(),{i:l,off:a}=o.findPos(e,1),{i:c,off:h}=o.findPos(t,-1),f=t-e;for(let u of i)f+=u.length;s.length+=f,N0(s,c,h,l,a,i,0,n,r)}let Et=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ha=typeof document<"u"?document:{documentElement:{style:{}}};const Fa=/Edge\/(\d+)/.exec(Et.userAgent),F0=/MSIE \d/.test(Et.userAgent),Ia=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Et.userAgent),So=!!(F0||Ia||Fa),Tu=!So&&/gecko\/(\d+)/i.test(Et.userAgent),il=!So&&/Chrome\/(\d+)/.exec(Et.userAgent),Bu="webkitFontSmoothing"in Ha.documentElement.style,I0=!So&&/Apple Computer/.test(Et.vendor),Eu=I0&&(/Mobile\/\w+/.test(Et.userAgent)||Et.maxTouchPoints>2);var O={mac:Eu||/Mac/.test(Et.platform),windows:/Win/.test(Et.platform),linux:/Linux|X11/.test(Et.platform),ie:So,ie_version:F0?Ha.documentMode||6:Ia?+Ia[1]:Fa?+Fa[1]:0,gecko:Tu,gecko_version:Tu?+(/Firefox\/(\d+)/.exec(Et.userAgent)||[0,0])[1]:0,chrome:!!il,chrome_version:il?+il[1]:0,ios:Eu,android:/Android\b/.test(Et.userAgent),webkit:Bu,safari:I0,webkit_version:Bu?+(/\bAppleWebKit\/(\d+)/.exec(Et.userAgent)||[0,0])[1]:0,tabSize:Ha.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const HM=256;class he extends j{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof he)||this.length-(e-t)+i.length>HM||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new he(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new mt(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return FM(this.dom,t,e)}}class Fe extends j{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let n of e)n.setParent(this)}setAttrs(t){if(E0(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,r,o){return i&&(!(i instanceof Fe&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(H0(this,t,e,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,n=-1,r=0;for(let l of this.children){let a=i+l.length;a>t&&e.push(i<t?l.split(t-i):l),n<0&&i>=t&&(n=r),i=a,r++}let o=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Fe(this.mark,e,o)}domAtPos(t){return V0(this,t)}coordsAt(t,e){return z0(this,t,e)}}function FM(s,t,e){let i=s.nodeValue.length;t>i&&(t=i);let n=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?O.chrome||O.gecko||(t?(n--,o=1):r<i&&(r++,o=-1)):e<0?n--:r<i&&r++;let l=vi(s,n,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:e>=0)?0:l.length-1];return O.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,c=>c.width)||a),o?qh(a,o<0):a||null}class ui extends j{static create(t,e,i){return new ui(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=ui.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,r,o){return i&&(!(i instanceof ui)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof ui&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return B.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,n=this.posAtStart;return i?i.slice(n,n+this.length):B.empty}domAtPos(t){return(this.length?t==0:this.side>0)?mt.before(this.dom):mt.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?n.length-1:0;r=n[l],!(t>0?l==0:l==n.length-1||r.top<r.bottom);l+=o?-1:1);return qh(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class sn extends j{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof sn&&t.side==this.side}split(){return new sn(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?mt.before(this.dom):mt.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return B.empty}get isHidden(){return!0}}he.prototype.children=ui.prototype.children=sn.prototype.children=jh;function V0(s,t){let e=s.dom,{children:i}=s,n=0;for(let r=0;n<i.length;n++){let o=i[n],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=n;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=n;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new mt(e,0)}function W0(s,t,e){let i,{children:n}=s;e>0&&t instanceof Fe&&n.length&&(i=n[n.length-1])instanceof Fe&&i.mark.eq(t.mark)?W0(i,t.children[0],e-1):(n.push(t),t.setParent(s)),s.length+=t.length}function z0(s,t,e){let i=null,n=-1,r=null,o=-1;function l(c,h){for(let f=0,u=0;f<c.children.length&&u<=h;f++){let d=c.children[f],p=u+d.length;p>=h&&(d.children.length?l(d,h-u):(!r||r.isHidden&&e>0)&&(p>h||u==p&&d.getSide()>0)?(r=d,o=h-u):(u<h||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,n=h-u)),u=p}}l(s,t);let a=(e<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?n:o),e):IM(s)}function IM(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=cs(t);return e[e.length-1]||null}function Va(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}const Ru=Object.create(null);function to(s,t,e){if(s==t)return!0;s||(s=Ru),t||(t=Ru);let i=Object.keys(s),n=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=n.length-(e&&n.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(n.indexOf(r)==-1||s[r]!==t[r]))return!1;return!0}function Wa(s,t,e){let i=!1;if(t)for(let n in t)e&&n in e||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(i=!0,n=="style"?s.style.cssText=e[n]:s.setAttribute(n,e[n]));return i}function VM(s){let t=Object.create(null);for(let e=0;e<s.attributes.length;e++){let i=s.attributes[e];t[i.name]=i.value}return t}class ot extends j{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,r,o){if(i){if(!(i instanceof ot))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),H0(this,t,e,i?i.children.slice():[],r,o),!0}split(t){let e=new ot;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:n}=this.childPos(t);n&&(e.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){to(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){W0(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Va(e,this.attrs||{})),i&&(this.attrs=Va({class:i},this.attrs||{}))}domAtPos(t){return V0(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(E0(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(Wa(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&j.get(n)instanceof Fe;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=j.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!O.ios||!this.children.some(r=>r instanceof he))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof he)||/[^ -~]/.test(i.text))return null;let n=cs(i.dom);if(n.length!=1)return null;t+=n[0].width,e=n[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=z0(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:n}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-n.lineHeight)<2&&n.textHeight<r){let o=(r-n.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(t){return t instanceof ot&&this.children.length==0&&t.children.length==0&&to(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,n=0;i<t.children.length;i++){let r=t.children[i],o=n+r.length;if(o>=e){if(r instanceof ot)return r;if(o>e)break}n=o+r.breakAfter}return null}}class Pe extends j{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,r,o){return i&&(!(i instanceof Pe)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?mt.before(this.dom):mt.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new Pe(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return jh}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):B.empty}domBoundsAround(){return null}become(t){return t instanceof Pe&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}}class vo{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var Me=function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s}(Me||(Me={}));class dt extends Gt{constructor(t,e,i,n){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(t){return new xs(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new oi(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,n;if(t.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=K0(t,e);i=(r?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new oi(t,i,n,e,t.widget||null,!0)}static line(t){return new Ss(t)}static set(t,e=!1){return E.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}dt.none=E.empty;class xs extends dt{constructor(t){let{start:e,end:i}=K0(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof xs&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&to(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}xs.prototype.point=!1;class Ss extends dt{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Ss&&this.spec.class==t.spec.class&&to(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Ss.prototype.mapMode=I.TrackBefore;Ss.prototype.point=!0;class oi extends dt{constructor(t,e,i,n,r,o){super(e,i,r,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?I.TrackBefore:I.TrackAfter:I.TrackDel}get type(){return this.startSide!=this.endSide?Me.WidgetRange:this.startSide<=0?Me.WidgetBefore:Me.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof oi&&WM(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}oi.prototype.point=!0;function K0(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function WM(s,t){return s==t||!!(s&&t&&s.compare(t))}function za(s,t,e,i=0){let n=e.length-1;n>=0&&e[n]+i>=s?e[n]=Math.max(e[n],t):e.push(s,t)}class jn{constructor(t,e,i,n){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof Pe&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new ot),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Qs(new sn(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof Pe)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Qs(new he(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof oi){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof oi)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Pe(i.widget||rn.block,l,i));else{let a=ui.create(i.widget||rn.inline,l,l?0:i.startSide),c=this.atCursorPos&&!a.isEditable&&r<=n.length&&(t<e||i.startSide>0),h=!a.isEditable&&(t<e||r>n.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!c&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),c&&(f.append(Qs(new sn(1),n),r),r=n.length+Math.max(0,r-n.length)),f.append(Qs(a,n),r),this.atCursorPos=h,this.pendingBuffer=h?t<e||r>n.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,n,r){let o=new jn(t,e,i,r);return o.openEnd=E.spans(n,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Qs(s,t){for(let e of t)s=new Fe(e,[s],s.length);return s}class rn extends vo{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}rn.inline=new rn("span");rn.block=new rn("div");var vt=function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s}(vt||(vt={}));const ki=vt.LTR,Gh=vt.RTL;function q0(s){let t=[];for(let e=0;e<s.length;e++)t.push(1<<+s[e]);return t}const zM=q0("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),KM=q0("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ka=Object.create(null),ge=[];for(let s of["()","[]","{}"]){let t=s.charCodeAt(0),e=s.charCodeAt(1);Ka[t]=e,Ka[e]=-t}function j0(s){return s<=247?zM[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?KM[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const qM=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Je{get dir(){return this.level%2?Gh:ki}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,n){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function G0(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++){let i=s[e],n=t[e];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!G0(i.inner,n.inner))return!1}return!0}const q=[];function jM(s,t,e,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,a=r?256:n;for(let c=o,h=a,f=a;c<l;c++){let u=j0(s.charCodeAt(c));u==512?u=h:u==8&&f==4&&(u=16),q[c]=u==4?2:u,u&7&&(f=u),h=u}for(let c=o,h=a,f=a;c<l;c++){let u=q[c];if(u==128)c<l-1&&h==q[c+1]&&h&24?u=q[c]=h:q[c]=256;else if(u==64){let d=c+1;for(;d<l&&q[d]==64;)d++;let p=c&&h==8||d<e&&q[d]==8?f==1?1:8:256;for(let g=c;g<d;g++)q[g]=p;c=d-1}else u==8&&f==1&&(q[c]=1);h=u,u&7&&(f=u)}}}function GM(s,t,e,i,n){let r=n==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let c=o?i[o-1].to:t,h=o<i.length?i[o].from:e;for(let f=c,u,d,p;f<h;f++)if(d=Ka[u=s.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(ge[g+1]==-d){let b=ge[g+2],m=b&2?n:b&4?b&1?r:n:0;m&&(q[f]=q[ge[g]]=m),l=g;break}}else{if(ge.length==189)break;ge[l++]=f,ge[l++]=u,ge[l++]=a}else if((p=q[f])==2||p==1){let g=p==n;a=g?0:1;for(let b=l-3;b>=0;b-=3){let m=ge[b+2];if(m&2)break;if(g)ge[b+2]|=2;else{if(m&4)break;ge[b+2]|=4}}}}}function UM(s,t,e,i){for(let n=0,r=i;n<=e.length;n++){let o=n?e[n-1].to:s,l=n<e.length?e[n].from:t;for(let a=o;a<l;){let c=q[a];if(c==256){let h=a+1;for(;;)if(h==l){if(n==e.length)break;h=e[n++].to,l=n<e.length?e[n].from:t}else if(q[h]==256)h++;else break;let f=r==1,u=(h<t?q[h]:i)==1,d=f==u?f?1:2:i;for(let p=h,g=n,b=g?e[g-1].to:s;p>a;)p==b&&(p=e[--g].from,b=g?e[g-1].to:s),q[--p]=d;a=h}else r=c,a++}}}function qa(s,t,e,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=t,c=0;a<e;){let h=!0,f=!1;if(c==r.length||a<r[c].from){let g=q[a];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;t:for(;;)if(c<r.length&&p==r[c].from){if(f)break t;let g=r[c];if(!h)for(let b=g.to,m=c+1;;){if(b==e)break t;if(m<r.length&&r[m].from==b)b=r[m++].to;else{if(q[b]==l)break t;break}}if(c++,u)u.push(g);else{g.from>a&&o.push(new Je(a,g.from,d));let b=g.direction==ki!=!(d%2);ja(s,b?i+1:i,n,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==e||(h?q[p]!=l:q[p]==l))break;p++}u?qa(s,a,p,i+1,n,u,o):a<p&&o.push(new Je(a,p,d)),a=p}else for(let a=e,c=r.length;a>t;){let h=!0,f=!1;if(!c||a>r[c-1].to){let g=q[a-1];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;t:for(;;)if(c&&p==r[c-1].to){if(f)break t;let g=r[--c];if(!h)for(let b=g.from,m=c;;){if(b==t)break t;if(m&&r[m-1].to==b)b=r[--m].from;else{if(q[b-1]==l)break t;break}}if(u)u.push(g);else{g.to<a&&o.push(new Je(g.to,a,d));let b=g.direction==ki!=!(d%2);ja(s,b?i+1:i,n,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==t||(h?q[p-1]!=l:q[p-1]==l))break;p--}u?qa(s,p,a,i+1,n,u,o):p<a&&o.push(new Je(p,a,d)),a=p}}function ja(s,t,e,i,n,r,o){let l=t%2?2:1;jM(s,n,r,i,l),GM(s,n,r,i,l),UM(n,r,i,l),qa(s,n,r,t,e,i,o)}function YM(s,t,e){if(!s)return[new Je(0,0,t==Gh?1:0)];if(t==ki&&!e.length&&!qM.test(s))return U0(s.length);if(e.length)for(;s.length>q.length;)q[q.length]=256;let i=[],n=t==ki?0:1;return ja(s,n,n,e,0,s.length,i),i}function U0(s){return[new Je(0,s,0)]}let Y0="";function XM(s,t,e,i,n){var r;let o=i.head-s.from,l=Je.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=t[l],c=a.side(n,e);if(o==c){let u=l+=n?1:-1;if(u<0||u>=t.length)return null;a=t[l=u],o=a.side(!n,e),c=a.side(n,e)}let h=V(s.text,o,a.forward(n,e));(h<a.from||h>a.to)&&(h=c),Y0=s.text.slice(Math.min(o,h),Math.max(o,h));let f=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];return f&&h==c&&f.level+(n?0:1)<a.level?w.cursor(f.side(!n,e)+s.from,f.forward(n,e)?1:-1,f.level):w.cursor(h+s.from,a.forward(n,e)?-1:1,a.level)}function _M(s,t,e){for(let i=t;i<e;i++){let n=j0(s.charCodeAt(i));if(n==1)return ki;if(n==2||n==4)return Gh}return ki}const X0=v.define(),_0=v.define(),J0=v.define(),Q0=v.define(),Ga=v.define(),Z0=v.define(),tb=v.define(),eb=v.define({combine:s=>s.some(t=>t)}),JM=v.define({combine:s=>s.some(t=>t)}),ib=v.define();class zi{constructor(t,e="nearest",i="nearest",n=5,r=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new zi(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new zi(w.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Zs=R.define({map:(s,t)=>s.map(t)}),nb=R.define();function Le(s,t,e){let i=s.facet(Q0);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const Ge=v.define({combine:s=>s.length?s[0]:!0});let QM=0;const Rn=v.define();class fs{constructor(t,e,i,n,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=e||{};return new fs(QM++,t,i,n,l=>{let a=[Rn.of(l)];return o&&a.push(us.of(c=>{let h=c.plugin(l);return h?o(h):dt.none})),r&&a.push(r(l)),a})}static fromClass(t,e){return fs.define(i=>new t(i),e)}}class nl{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Le(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Le(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Le(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const sb=v.define(),Uh=v.define(),us=v.define(),rb=v.define(),Yh=v.define(),ob=v.define();function Lu(s,t){let e=s.state.facet(ob);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(s):r),n=[];return E.spans(i,t.from,t.to,{point(){},span(r,o,l,a){let c=r-t.from,h=o-t.from,f=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=_M(t.text,c,h)),a>0&&f.length&&(p=f[f.length-1]).to==c&&p.direction==d)p.to=h,f=p.inner;else{let g={from:c,to:h,direction:d,inner:[]};f.push(g),f=g.inner}}}}),n}const lb=v.define();function ab(s){let t=0,e=0,i=0,n=0;for(let r of s.state.facet(lb)){let o=r(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:i,bottom:n}}const Ln=v.define();class qt{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new qt(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let n=0,r=0,o=0,l=0;;n++){let a=n==t.length?null:t[n],c=o-l,h=a?a.fromB:1e9;for(;r<e.length&&e[r]<h;){let f=e[r],u=e[r+1],d=Math.max(l,f),p=Math.min(h,u);if(d<=p&&new qt(d+c,p+c,d,p).addToSet(i),u>h)break;r+=2}if(!a)return i;new qt(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class eo{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=et.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,a)=>n.push(new qt(r,o,l,a))),this.changedRanges=n}static create(t,e,i){return new eo(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class Pu extends j{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=dt.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new ot],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new qt(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:h})=>h<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!rA(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let r=n>-1?tA(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:c,to:h}=this.hasComposition;i=new qt(c,h,t.changes.mapPos(c,-1),t.changes.mapPos(h,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(O.ie||O.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=nA(o,l,t.changes);return i=qt.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=O.chrome||O.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||n.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof Pe&&o.widget instanceof $u&&r.push(o.dom);n.updateGaps(r)}updateChildren(t,e,i){let n=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let o=n.length-1;;o--){let l=o>=0?n[o]:null;if(!l)break;let{fromA:a,toA:c,fromB:h,toB:f}=l,u,d,p,g;if(i&&i.range.fromB<f&&i.range.toB>h){let x=jn.build(this.view.state.doc,h,i.range.fromB,this.decorations,this.dynamicDecorationMap),k=jn.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=x.breakAtStart,p=x.openStart,g=k.openEnd;let M=this.compositionView(i);k.breakAtStart?M.breakAfter=1:k.content.length&&M.merge(M.length,M.length,k.content[0],!1,k.openStart,0)&&(M.breakAfter=k.content[0].breakAfter,k.content.shift()),x.content.length&&M.merge(0,0,x.content[x.content.length-1],!0,0,x.openEnd)&&x.content.pop(),u=x.content.concat(M).concat(k.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=jn.build(this.view.state.doc,h,f,this.decorations,this.dynamicDecorationMap));let{i:b,off:m}=r.findPos(c,1),{i:y,off:S}=r.findPos(a,-1);N0(this,y,S,b,m,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(nb)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new he(t.text.nodeValue);e.flags|=8;for(let{deco:n}of t.marks)e=new Fe(n,[e],e.length);let i=new ot;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=j.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let r=t.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],e(r>=0?t.marks[r].node:t.text,n)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&Dr(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),c=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(O.gecko&&l.empty&&!this.hasComposition&&ZM(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=c=new mt(f,0),o=!0}let h=this.view.observer.selectionRange;(o||!h.focusNode||(!qn(a.node,a.offset,h.anchorNode,h.anchorOffset)||!qn(c.node,c.offset,h.focusNode,h.focusOffset))&&!this.suppressWidgetCursorChange(h,l))&&(this.view.observer.ignore(()=>{O.android&&O.chrome&&this.dom.contains(h.focusNode)&&sA(h.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=hs(this.view.root);if(f)if(l.empty){if(O.gecko){let u=eA(a.node,a.offset);if(u&&u!=3){let d=(u==1?L0:P0)(a.node,a.offset);d&&(a=new mt(d.node,d.offset))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,c]=[c,a]),u.setEnd(c.node,c.offset),u.setStart(a.node,a.offset),f.removeAllRanges(),f.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,c)),this.impreciseAnchor=a.precise?null:new mt(h.anchorNode,h.anchorOffset),this.impreciseHead=c.precise?null:new mt(h.focusNode,h.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&qn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=hs(t.root),{anchorNode:n,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=ot.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let a=this.coordsAt(e.head,-1),c=this.coordsAt(e.head,1);if(!a||!c||a.bottom>c.top)return;let h=this.domAtPos(e.head+e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(n,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let n=t.offset;!i&&n<e.childNodes.length;n++){let r=j.get(e.childNodes[n]);r instanceof ot&&(i=r.domAtPos(0))}for(let n=t.offset-1;!i&&n>=0;n--){let r=j.get(e.childNodes[n]);r instanceof ot&&(i=r.domAtPos(r.length))}return i?new mt(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=j.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let n=this.children[e];if(i<n.length||n instanceof ot)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,n=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,c=a-l.length;if(a<t)break;if(c<=t&&(c<t||l.covers(-1))&&(a>t||l.covers(1))&&(!i||l instanceof ot&&!(i instanceof ot&&e>=0)))i=l,n=c;else if(i&&c==t&&a==t&&l instanceof Pe&&Math.abs(e)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=c}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof ot))return null;for(;n.children.length;){let{i:l,off:a}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=a}if(!(n instanceof he))return null;let r=V(n.text,i);if(r==i)return null;let o=vi(n.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:n}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==vt.LTR;for(let c=0,h=0;h<this.children.length;h++){let f=this.children[h],u=c+f.length;if(u>n)break;if(c>=i){let d=f.dom.getBoundingClientRect();if(e.push(d.height),o){let p=f.dom.lastChild,g=p?cs(p):[];if(g.length){let b=g[g.length-1],m=a?b.right-d.left:d.right-b.left;m>l&&(l=m,this.minWidth=r,this.minWidthFrom=c,this.minWidthTo=u)}}}c=u+f.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?vt.RTL:vt.LTR}measureTextSize(){for(let r of this.children)if(r instanceof ot){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,n;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.dom.appendChild(t);let r=cs(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new $0(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let r=n==e.viewports.length?null:e.viewports[n],o=r?r.from-1:this.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(dt.replace({widget:new $u(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return dt.set(t)}updateDeco(){let t=1,e=this.view.state.facet(us).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(rb).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(E.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let c=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=c.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let c of this.view.state.facet(ib))try{if(c(this.view,t.range,t))return!0}catch(h){Le(this.view.state,h,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),n;if(!i)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let r=ab(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;RM(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==vt.LTR)}}function ZM(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}class $u extends vo{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function hb(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=L0(e.focusNode,e.focusOffset),n=P0(e.focusNode,e.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=j.get(n.node);if(!l||l instanceof he&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let a=j.get(i.node);!a||a instanceof he&&a.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function tA(s,t,e){let i=hb(s,e);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc,c=new qt(a.mapPos(r),a.mapPos(o),r,o),h=[];for(let f=n.parentNode;;f=f.parentNode){let u=j.get(f);if(u instanceof Fe)h.push({node:f,deco:u.mark});else{if(u instanceof ot||f.nodeName=="DIV"&&f.parentNode==s.contentDOM)return{range:c,text:n,marks:h,line:f};if(f!=s.contentDOM)h.push({node:f,deco:new xs({inclusive:!0,attributes:VM(f),tagName:f.tagName.toLowerCase()})});else return null}}}function eA(s,t){return s.nodeType!=1?0:(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t<s.childNodes.length&&s.childNodes[t].contentEditable=="false"?2:0)}let iA=class{constructor(){this.changes=[]}compareRange(t,e){za(t,e,this.changes)}comparePoint(t,e){za(t,e,this.changes)}};function nA(s,t,e){let i=new iA;return E.compare(s,t,e,i),i.changes}function sA(s,t){for(let e=s;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function rA(s,t){let e=!1;return t&&s.iterChangedRanges((i,n)=>{i<t.to&&n>t.from&&(e=!0)}),e}function oA(s,t,e=1){let i=s.charCategorizer(t),n=s.doc.lineAt(t),r=t-n.from;if(n.length==0)return w.cursor(t);r==0?e=1:r==n.length&&(e=-1);let o=r,l=r;e<0?o=V(n.text,r,!1):l=V(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let c=V(n.text,o,!1);if(i(n.text.slice(c,o))!=a)break;o=c}for(;l<n.length;){let c=V(n.text,l);if(i(n.text.slice(l,c))!=a)break;l=c}return w.range(o+n.from,l+n.from)}function lA(s,t){return t.left>s?t.left-s:Math.max(0,s-t.right)}function aA(s,t){return t.top>s?t.top-s:Math.max(0,s-t.bottom)}function sl(s,t){return s.top<t.bottom-1&&s.bottom>t.top+1}function Nu(s,t){return t<s.top?{top:t,left:s.left,right:s.right,bottom:s.bottom}:s}function Hu(s,t){return t>s.bottom?{top:s.top,left:s.left,right:s.right,bottom:t}:s}function Ua(s,t,e){let i,n,r,o,l=!1,a,c,h,f;for(let p=s.firstChild;p;p=p.nextSibling){let g=cs(p);for(let b=0;b<g.length;b++){let m=g[b];n&&sl(n,m)&&(m=Nu(Hu(m,n.bottom),n.top));let y=lA(t,m),S=aA(e,m);if(y==0&&S==0)return p.nodeType==3?Fu(p,t,e):Ua(p,t,e);if(!i||o>S||o==S&&r>y){i=p,n=m,r=y,o=S;let x=S?e<m.top?-1:1:y?t<m.left?-1:1:0;l=!x||(x>0?b<g.length-1:b>0)}y==0?e>m.bottom&&(!h||h.bottom<m.bottom)?(a=p,h=m):e<m.top&&(!f||f.top>m.top)&&(c=p,f=m):h&&sl(h,m)?h=Hu(h,m.bottom):f&&sl(f,m)&&(f=Nu(f,m.top))}}if(h&&h.bottom>=e?(i=a,n=h):f&&f.top<=e&&(i=c,n=f),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,t));if(i.nodeType==3)return Fu(i,u,e);if(l&&i.contentEditable!="false")return Ua(i,u,e);let d=Array.prototype.indexOf.call(s.childNodes,i)+(t>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function Fu(s,t,e){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=vi(s,l,l+1).getClientRects();for(let c=0;c<a.length;c++){let h=a[c];if(h.top==h.bottom)continue;o||(o=t-h.left);let f=(h.top>e?h.top-e:e-h.bottom)-1;if(h.left-1<=t&&h.right+1>=t&&f<r){let u=t>=(h.left+h.right)/2,d=u;if((O.chrome||O.gecko)&&vi(s,l).getBoundingClientRect().left==h.right&&(d=!u),f<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=f}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function cb(s,t,e,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,a,{docHeight:c}=s.viewState,{x:h,y:f}=t,u=f-l;if(u<0)return 0;if(u>c)return s.state.doc.length;for(let x=s.viewState.heightOracle.textHeight/2,k=!1;a=s.elementAtHeight(u),a.type!=Me.Text;)for(;u=i>0?a.bottom+x:a.top-x,!(u>=0&&u<=c);){if(k)return e?null:0;k=!0,i=-i}f=l+u;let d=a.from;if(d<s.viewport.from)return s.viewport.from==0?0:e?null:Iu(s,o,a,h,f);if(d>s.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:e?null:Iu(s,o,a,h,f);let p=s.dom.ownerDocument,g=s.root.elementFromPoint?s.root:p,b=g.elementFromPoint(h,f);b&&!s.contentDOM.contains(b)&&(b=null),b||(h=Math.max(o.left+1,Math.min(o.right-1,h)),b=g.elementFromPoint(h,f),b&&!s.contentDOM.contains(b)&&(b=null));let m,y=-1;if(b&&((n=s.docView.nearest(b))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let x=p.caretPositionFromPoint(h,f);x&&({offsetNode:m,offset:y}=x)}else if(p.caretRangeFromPoint){let x=p.caretRangeFromPoint(h,f);x&&({startContainer:m,startOffset:y}=x,(!s.contentDOM.contains(m)||O.safari&&hA(m,y,h)||O.chrome&&cA(m,y,h))&&(m=void 0))}}if(!m||!s.docView.dom.contains(m)){let x=ot.find(s.docView,d);if(!x)return u>a.top+a.height/2?a.to:a.from;({node:m,offset:y}=Ua(x.dom,h,f))}let S=s.docView.nearest(m);if(!S)return null;if(S.isWidget&&((r=S.dom)===null||r===void 0?void 0:r.nodeType)==1){let x=S.dom.getBoundingClientRect();return t.y<x.top||t.y<=x.bottom&&t.x<=(x.left+x.right)/2?S.posAtStart:S.posAtEnd}else return S.localPosFromDOM(m,y)+S.posAtStart}function Iu(s,t,e,i,n){let r=Math.round((i-t.left)*s.defaultCharacterWidth);if(s.lineWrapping&&e.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,a=Math.floor((n-e.top-(s.defaultLineHeight-l)*.5)/l);r+=a*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+Xn(o,r,s.state.tabSize)}function hA(s,t,e){let i;if(s.nodeType!=3||t!=(i=s.nodeValue.length))return!1;for(let n=s.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!="BR")return!1;return vi(s,i-1,i).getBoundingClientRect().left>e}function cA(s,t,e){if(t!=0)return!1;for(let n=s;;){let r=n.parentNode;if(!r||r.nodeType!=1||r.firstChild!=n)return!1;if(r.classList.contains("cm-line"))break;n=r}let i=s.nodeType==1?s.getBoundingClientRect():vi(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function fA(s,t){let e=s.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==Me.Text))return i}return e}function uA(s,t,e,i){let n=fA(s,t.head),r=!i||n.type!=Me.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),a=s.posAtCoords({x:e==(l==vt.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return w.cursor(a,e?-1:1)}return w.cursor(e?n.to:n.from,e?-1:1)}function Vu(s,t,e,i){let n=s.state.doc.lineAt(t.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=t,a=null;;){let c=XM(n,r,o,l,e),h=Y0;if(!c){if(n.number==(e?s.state.doc.lines:1))return l;h=`
16
- `,n=s.state.doc.line(n.number+(e?1:-1)),r=s.bidiSpans(n),c=s.visualLineSide(n,!e)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function dA(s,t,e){let i=s.state.charCategorizer(t),n=i(e);return r=>{let o=i(r);return n==Y.Space&&(n=o),n==o}}function pA(s,t,e,i){let n=t.head,r=e?1:-1;if(n==(e?s.state.doc.length:0))return w.cursor(n,t.assoc);let o=t.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),c=s.coordsAtPos(n,t.assoc||-1),h=s.documentTop;if(c)o==null&&(o=c.left-a.left),l=r<0?c.top:c.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+h}let f=a.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=cb(s,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<n:g>n)){let b=s.docView.coordsForChar(g),m=!b||p<b.top?-1:1;return w.cursor(g,m,void 0,o)}}}function Or(s,t,e){for(;;){let i=0;for(let n of s)n.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let a=i||e||(t-r<o-t?-1:1);t=a<0?r:o,i=a}});if(!i)return t}}function rl(s,t,e){let i=Or(s.state.facet(Yh).map(n=>n(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:w.cursor(i,i<e.from?1:-1)}class gA{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,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.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,O.safari&&t.contentDOM.addEventListener("input",()=>null),O.gecko&&EA(t.contentDOM.ownerDocument)}handleEvent(t){!kA(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let n of i.observers)n(this.view,e);for(let n of i.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=mA(t),i=this.handlers,n=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&ub.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),O.android&&O.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return O.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=fb.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||bA.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,Wi(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:O.safari&&!O.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Wu(s,t){return(e,i)=>{try{return t.call(s,i,e)}catch(n){Le(e.state,n)}}}function mA(s){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec;if(n&&n.domEventHandlers)for(let r in n.domEventHandlers){let o=n.domEventHandlers[r];o&&e(r).handlers.push(Wu(i.value,o))}if(n&&n.domEventObservers)for(let r in n.domEventObservers){let o=n.domEventObservers[r];o&&e(r).observers.push(Wu(i.value,o))}}for(let i in ce)e(i).handlers.push(ce[i]);for(let i in Xt)e(i).observers.push(Xt[i]);return t}const fb=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],bA="dthko",ub=[16,17,18,20,91,92,224,225],tr=6;function er(s){return Math.max(0,s)*.7+8}function yA(s,t){return Math.max(Math.abs(s.clientX-t.clientX),Math.abs(s.clientY-t.clientY))}class wA{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=LM(t.contentDOM),this.atoms=t.state.facet(Yh).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet($.allowMultipleSelections)&&xA(t,e),this.dragging=vA(t,e)&&gb(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&yA(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=ab(this.view);t.clientX-a.left<=n+tr?e=-er(n-t.clientX):t.clientX+a.right>=o-tr&&(e=er(t.clientX-o)),t.clientY-a.top<=r+tr?i=-er(r-t.clientY):t.clientY+a.bottom>=l-tr&&(i=er(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let n=t.ranges[i],r=null;if(n.empty){let o=Or(this.atoms,n.from,0);o!=n.from&&(r=w.cursor(o,-1))}else{let o=Or(this.atoms,n.from,-1),l=Or(this.atoms,n.to,1);(o!=n.from||l!=n.to)&&(r=w.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?w.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function xA(s,t){let e=s.state.facet(X0);return e.length?e[0](t):O.mac?t.metaKey:t.ctrlKey}function SA(s,t){let e=s.state.facet(_0);return e.length?e[0](t):O.mac?!t.altKey:!t.ctrlKey}function vA(s,t){let{main:e}=s.state.selection;if(e.empty)return!1;let i=hs(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function kA(s,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=s.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=j.get(e))&&i.ignoreEvent(t))return!1;return!0}const ce=Object.create(null),Xt=Object.create(null),db=O.ie&&O.ie_version<15||O.ios&&O.webkit_version<604;function CA(s){let t=s.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{s.focus(),e.remove(),pb(s,e.value)},50)}function pb(s,t){let{state:e}=s,i,n=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(Ya!=null&&e.selection.ranges.every(a=>a.empty)&&Ya==r.toString()){let a=-1;i=e.changeByRange(c=>{let h=e.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let f=e.toText((o?r.line(n++).text:t)+e.lineBreak);return{changes:{from:h.from,insert:f},range:w.cursor(c.from+f.length)}})}else o?i=e.changeByRange(a=>{let c=r.line(n++);return{changes:{from:a.from,to:a.to,insert:c.text},range:w.cursor(a.from+c.length)}}):i=e.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Xt.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};ce.keydown=(s,t)=>(s.inputState.setSelectionOrigin("select"),t.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);Xt.touchstart=(s,t)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Xt.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};ce.mousedown=(s,t)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of s.state.facet(J0))if(e=i(s,t),e)break;if(!e&&t.button==0&&(e=DA(s,t)),e){let i=!s.hasFocus;s.inputState.startMouseSelection(new wA(s,t,e,i)),i&&s.observer.ignore(()=>{B0(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}return!1};function zu(s,t,e,i){if(i==1)return w.cursor(t,e);if(i==2)return oA(s.state,t,e);{let n=ot.find(s.docView,t),r=s.state.doc.lineAt(n?n.posAtEnd:t),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,w.range(o,l)}}let Ku=(s,t,e)=>t>=e.top&&t<=e.bottom&&s>=e.left&&s<=e.right;function MA(s,t,e,i){let n=ot.find(s.docView,t);if(!n)return 1;let r=t-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&Ku(e,i,o))return-1;let l=n.coordsAt(r,1);return l&&Ku(e,i,l)?1:o&&o.bottom>=i?-1:1}function qu(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:MA(s,e,t.clientX,t.clientY)}}const AA=O.ie&&O.ie_version<=11;let ju=null,Gu=0,Uu=0;function gb(s){if(!AA)return s.detail;let t=ju,e=Uu;return ju=s,Uu=Date.now(),Gu=!t||e>Date.now()-400&&Math.abs(t.clientX-s.clientX)<2&&Math.abs(t.clientY-s.clientY)<2?(Gu+1)%3:1}function DA(s,t){let e=qu(s,t),i=gb(t),n=s.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),n=n.map(r.changes))},get(r,o,l){let a=qu(s,r),c,h=zu(s,a.pos,a.bias,i);if(e.pos!=a.pos&&!o){let f=zu(s,e.pos,e.bias,i),u=Math.min(f.from,h.from),d=Math.max(f.to,h.to);h=u<h.from?w.range(u,d):w.range(d,u)}return o?n.replaceRange(n.main.extend(h.from,h.to)):l&&i==1&&n.ranges.length>1&&(c=OA(n,a.pos))?c:l?n.addRange(h):w.create([h])}}}function OA(s,t){for(let e=0;e<s.ranges.length;e++){let{from:i,to:n}=s.ranges[e];if(i<=t&&n>=t)return w.create(s.ranges.slice(0,e).concat(s.ranges.slice(e+1)),s.mainIndex==e?0:s.mainIndex-(s.mainIndex>e?1:0))}return null}ce.dragstart=(s,t)=>{let{selection:{main:e}}=s.state;if(t.target.draggable){let n=s.docView.nearest(t.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=e.to||o<=e.from)&&(e=w.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",s.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed="copyMove"),!1};ce.dragend=s=>(s.inputState.draggedContent=null,!1);function Yu(s,t,e,i){if(!e)return;let n=s.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&SA(s,t)?{from:r.from,to:r.to}:null,l={from:n,insert:e},a=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}ce.drop=(s,t)=>{if(!t.dataTransfer)return!1;if(s.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),n=0,r=()=>{++n==e.length&&Yu(s,t,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<e.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(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Yu(s,t,i,!0),!0}return!1};ce.paste=(s,t)=>{if(s.state.readOnly)return!0;s.observer.flush();let e=db?null:t.clipboardData;return e?(pb(s,e.getData("text/plain")||e.getData("text/uri-list")),!0):(CA(s),!1)};function TA(s,t){let e=s.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function BA(s){let t=[],e=[],i=!1;for(let n of s.selection.ranges)n.empty||(t.push(s.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:t.join(s.lineBreak),ranges:e,linewise:i}}let Ya=null;ce.copy=ce.cut=(s,t)=>{let{text:e,ranges:i,linewise:n}=BA(s.state);if(!e&&!n)return!1;Ya=n?e:null,t.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=db?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(TA(s,e),!1)};const mb=Vt.define();function bb(s,t){let e=[];for(let i of s.facet(tb)){let n=i(s,t);n&&e.push(n)}return e?s.update({effects:e,annotations:mb.of(!0)}):null}function yb(s){setTimeout(()=>{let t=s.hasFocus;if(t!=s.inputState.notifiedFocused){let e=bb(s.state,t);e?s.dispatch(e):s.update([])}},10)}Xt.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),yb(s)};Xt.blur=s=>{s.observer.clearSelectionRange(),yb(s)};Xt.compositionstart=Xt.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};Xt.compositionend=s=>{s.observer.editContext||(s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,O.chrome&&O.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};Xt.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};ce.beforeinput=(s,t)=>{var e;let i;if(O.chrome&&O.android&&(i=fb.find(n=>n.inputType==t.inputType))&&(s.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let n=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>n+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return O.ios&&t.inputType=="deleteContentForward"&&s.observer.flushSoon(),O.safari&&t.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>Xt.compositionend(s,t),20),!1};const Xu=new Set;function EA(s){Xu.has(s)||(Xu.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const _u=["pre-wrap","normal","pre-line","break-spaces"];class RA{constructor(t){this.lineWrapping=t,this.doc=B.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return _u.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let n=t[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(e=!0,this.heightSamples[Math.floor(n*10)]=!0)}return e}refresh(t,e,i,n,r,o){let l=_u.indexOf(t)>-1,a=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}}class LA{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class we{constructor(t,e,i,n,r){this.from=t,this.length=e,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?Me.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 oi?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new we(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var J=function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s}(J||(J={}));const Tr=.001;class Ct{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>Tr&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return Ct.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:f}=n[l],u=r.lineAt(a,J.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=c?u:r.lineAt(c,J.ByPosNoHeight,i,0,0);for(f+=d.to-c,c=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,h=n[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,J.ByPosNoHeight,i,0,0));h+=u.from-a,a=u.from;let p=Xh.build(i.setDoc(o),t,h,f);r=r.replace(a,c,p)}return r.updateHeight(i,0)}static empty(){return new $t(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,n=0,r=0;for(;;)if(e==i)if(n>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=t[e++];l&&(n+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new PA(Ct.of(t.slice(0,e)),o,Ct.of(t.slice(i)))}}Ct.prototype.size=1;class wb extends Ct{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,n){return new we(n,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,n,r){return this.blockAt(0,i,n,r)}forEachLine(t,e,i,n,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,n,r))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(t,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class $t extends wb{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new we(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return i.length==1&&(n instanceof $t||n instanceof ft&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof ft?n=new $t(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Ct.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(t,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ft extends Ct{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,r=n-i+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.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:n,perLine:o,perChar:l}}blockAt(t,e,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,n);if(e.lineWrapping){let c=n+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),h=e.doc.lineAt(c),f=l+h.length*a,u=Math.max(i,t-f/2);return new we(h.from,h.length,u,f,0)}else{let c=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:h,length:f}=e.doc.line(r+c);return new we(h,f,i+l*c,l,0)}}lineAt(t,e,i,n,r){if(e==J.ByHeight)return this.blockAt(t,i,n,r);if(e==J.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new we(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),c=i.doc.lineAt(t),h=l+c.length*a,f=c.number-o,u=n+l*f+a*(c.from-r-f);return new we(c.from,c.length,Math.max(n,Math.min(u,n+this.height-h)),h,0)}forEachLine(t,e,i,n,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,r);for(let h=t,f=n;h<=e;){let u=i.doc.lineAt(h);if(h==t){let p=u.number-l;f+=a*p+c*(t-r-p)}let d=a+c*u.length;o(new we(u.from,u.length,f,d,0)),f+=d,h=u.to+1}}replace(t,e,i){let n=this.length-e;if(n>0){let r=i[i.length-1];r instanceof ft?i[i.length-1]=new ft(r.length+n):i.push(null,new ft(n-1))}if(t>0){let r=i[0];r instanceof ft?i[0]=new ft(t+r.length):i.unshift(new ft(t-1),null)}return Ct.of(i)}decomposeLeft(t,e){e.push(new ft(t-1),null)}decomposeRight(t,e){e.push(null,new ft(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let r=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),a=-1;for(n.from>e&&o.push(new ft(n.from-e-1).updateHeight(t,e));l<=r&&n.more;){let h=t.doc.lineAt(l).length;o.length&&o.push(null);let f=n.heights[n.index++];a==-1?a=f:Math.abs(f-a)>=Tr&&(a=-2);let u=new $t(h,f);u.outdated=!1,o.push(u),l+=h+1}l<=r&&o.push(null,new ft(r-l).updateHeight(t,l));let c=Ct.of(o);return(a<0||Math.abs(c.height-this.height)>=Tr||Math.abs(a-this.heightMetrics(t,e).perLine)>=Tr)&&(t.heightChanged=!0),c}else(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class PA extends Ct{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,n){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,n):this.right.blockAt(t,e,r,n+this.left.length+this.break)}lineAt(t,e,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,a=e==J.ByHeight?t<o:t<l,c=a?this.left.lineAt(t,e,i,n,r):this.right.lineAt(t,e,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=e==J.ByPosNoHeight?J.ByPosNoHeight:J.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,n,r).join(c)}forEachLine(t,e,i,n,r,o){let l=n+this.left.height,a=r+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,n,r,o),e>=a&&this.right.forEachLine(t,e,i,l,a,o);else{let c=this.lineAt(a,J.ByPos,i,n,r);t<c.from&&this.left.forEachLine(t,c.from-1,i,n,r,o),c.to>=t&&c.from<=e&&o(c),e>c.to&&this.right.forEachLine(c.to+1,e,i,l,a,o)}}replace(t,e,i){let n=this.left.length+this.break;if(e<n)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&Ju(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),Ju(r,l)}return Ct.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<n&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?Ct.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:r,right:o}=this,l=e+r.length+this.break,a=null;return n&&n.from<=e+r.length&&n.more?a=r=r.updateHeight(t,e,i,n):r.updateHeight(t,e,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(t,l,i,n):o.updateHeight(t,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 Ju(s,t){let e,i;s[t]==null&&(e=s[t-1])instanceof ft&&(i=s[t+1])instanceof ft&&s.splice(t-1,3,new ft(e.length+1+i.length))}const $A=5;class Xh{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof $t?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new $t(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new wb(o,n,i)):(o||r||n>=$A)&&this.addLineDeco(n,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new $t(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new ft(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof $t)return t;let e=new $t(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof $t)&&!this.isCovered?this.nodes.push(new $t(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let n of this.nodes)n instanceof $t&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(t,e,i,n){let r=new Xh(i,t);return E.spans(e,i,n,r,0),r.finish(i)}}function NA(s,t,e){let i=new HA;return E.compare(s,t,e,i,0),i.changes}class HA{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,n){(t<e||i&&i.heightRelevant||n&&n.heightRelevant)&&za(t,e,this.changes,5)}}function FA(s,t){let e=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(n.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(n.innerHeight,e.bottom);for(let c=s.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,f=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&f.overflow!="visible"){let u=h.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=c==s.parentNode?u.bottom:Math.min(a,u.bottom)}c=f.position=="absolute"||f.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function IA(s,t){let e=s.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class ol{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let n=t[i],r=e[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(t,e){return dt.replace({widget:new VA(this.size*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class VA extends vo{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class Qu{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Zu,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=vt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(Uh).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new RA(e),this.stateDeco=t.facet(us).filter(i=>typeof i!="function"),this.heightMap=Ct.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle.setDoc(t.doc),[new qt(0,0,0,t.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=dt.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);t.push(new ir(r,o))}}return this.viewports=t.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Zu:new _h(this.heightOracle,this.heightMap,this.viewports),t.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,t=>{this.viewportLines.push(Pn(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(us).filter(h=>typeof h!="function");let n=t.changedRanges,r=qt.extendWithRanges(n,NA(i,this.stateDeco,t?t.changes:et.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(c||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(JM)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?vt.RTL:vt.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,h=0;if(l.width&&l.height){let{scaleX:x,scaleY:k}=T0(e,l);(x>.005&&Math.abs(this.scaleX-x)>.005||k>.005&&Math.abs(this.scaleY-k)>.005)&&(this.scaleX=x,this.scaleY=k,c|=8,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,c|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,c|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=R0(t.scrollDOM);let p=(this.printing?IA:FA)(e,this.paddingTop),g=p.top-this.pixelViewport.top,b=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let m=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(m!=this.inView&&(this.inView=m,m&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let y=l.width;if((this.contentDOMWidth!=y||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,c|=8),a){let x=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(x)&&(o=!0),o||n.lineWrapping&&Math.abs(y-this.contentDOMWidth)>n.charWidth){let{lineHeight:k,charWidth:M,textHeight:N}=t.docView.measureTextSize();o=k>0&&n.refresh(r,k,M,N,y/M,x),o&&(t.docView.minWidth=0,c|=8)}g>0&&b>0?h=Math.max(g,b):g<0&&b<0&&(h=Math.min(g,b)),n.heightChanged=!1;for(let k of this.viewports){let M=k.from==this.viewport.from?x:t.docView.measureVisibleLineHeights(k);this.heightMap=(o?Ct.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle,[new qt(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new LA(k.from,M))}n.heightChanged&&(c|=2)}let S=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new ir(n.lineAt(o-i*1e3,J.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,J.ByHeight,r,0,0).to);if(e){let{head:c}=e.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=n.lineAt(c,J.ByPos,r,0,0),u;e.y=="center"?u=(f.top+f.bottom)/2-h/2:e.y=="start"||e.y=="nearest"&&c<a.from?u=f.top:u=f.bottom-h,a=new ir(n.lineAt(u-1e3/2,J.ByHeight,r,0,0).from,n.lineAt(u+h+1e3/2,J.ByHeight,r,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),n=e.mapPos(t.to,1);return new ir(this.heightMap.lineAt(i,J.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,J.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(t,J.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,J.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||n<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let n of t)e.touchesRange(n.from,n.to)||i.push(new ol(e.mapPos(n.from),e.mapPos(n.to),n.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=vt.LTR&&!i)return[];let l=[],a=(h,f,u,d)=>{if(f-h<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let m of g)if(m>h&&m<f){a(h,m-10,u,d),a(m+10,f,u,d);return}let b=zA(t,m=>m.from>=u.from&&m.to<=u.to&&Math.abs(m.from-h)<r&&Math.abs(m.to-f)<r&&!g.some(y=>m.from<y&&m.to>y));if(!b){if(f<u.to&&e&&i&&e.visibleRanges.some(m=>m.from<=f&&m.to>=f)){let m=e.moveToLineBoundary(w.cursor(f),!1,!0).head;m>h&&(f=m)}b=new ol(h,f,this.gapSize(u,h,f,d))}l.push(b)},c=h=>{if(h.length<o||h.type!=Me.Text)return;let f=WA(h.from,h.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,m;if(u!=null){let y=sr(f,u),S=((this.visibleBottom-this.visibleTop)/2+g)/h.height;b=y-S,m=y+S}else b=(this.visibleTop-h.top-g)/h.height,m=(this.visibleBottom-h.top+g)/h.height;d=nr(f,b),p=nr(f,m)}else{let g=f.total*this.heightOracle.charWidth,b=n*this.heightOracle.charWidth,m,y;if(u!=null){let S=sr(f,u),x=((this.pixelViewport.right-this.pixelViewport.left)/2+b)/g;m=S-x,y=S+x}else m=(this.pixelViewport.left-b)/g,y=(this.pixelViewport.right+b)/g;d=nr(f,m),p=nr(f,y)}d>h.from&&a(h.from,d,h,f),p<h.to&&a(p,h.to,h,f)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(t,e,i,n){let r=sr(n,i)-sr(n,e);return this.heightOracle.lineWrapping?t.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(t){ol.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=dt.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];E.spans(t,this.viewport.from,this.viewport.to,{span(n,r){e.push({from:n,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((n,r)=>n.from!=e[r].from||n.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Pn(this.heightMap.lineAt(t,J.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Pn(this.heightMap.lineAt(this.scaler.fromDOM(t),J.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Pn(this.heightMap.blockAt(this.scaler.fromDOM(t),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 ir{constructor(t,e){this.from=t,this.to=e}}function WA(s,t,e){let i=[],n=s,r=0;return E.spans(e,s,t,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<t&&(i.push({from:n,to:t}),r+=t-n),{total:r,ranges:i}}function nr({total:s,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(s*e);for(let n=0;;n++){let{from:r,to:o}=t[n],l=o-r;if(i<=l)return r+i;i-=l}}function sr(s,t){let e=0;for(let{from:i,to:n}of s.ranges){if(t<=n){e+=t-i;break}e+=n-i}return e/s.total}function zA(s,t){for(let e of s)if(t(e))return e}const Zu={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};class _h{constructor(t,e,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=e.lineAt(l,J.ByPos,t,0,0).top,h=e.lineAt(a,J.ByPos,t,0,0).bottom;return n+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);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(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return n+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,n=r.domBottom}}fromDOM(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-n)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,n=r.domBottom}}eq(t){return t instanceof _h?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function Pn(s,t){if(t.scale==1)return s;let e=t.toDOM(s.top),i=t.toDOM(s.bottom);return new we(s.from,s.length,e,i-e,Array.isArray(s._content)?s._content.map(n=>Pn(n,t)):s._content)}const rr=v.define({combine:s=>s.join(" ")}),Xa=v.define({combine:s=>s.indexOf(!0)>-1}),_a=lt.newName(),xb=lt.newName(),Sb=lt.newName(),vb={"&light":"."+xb,"&dark":"."+Sb};function Ja(s,t,e){return new lt(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):s+" "+i}})}const KA=Ja("."+_a,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<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"}},vb),$n="￿";class qA{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet($.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=$n}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==e)break;let l=j.get(n),a=j.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:Zr(n))||Zr(o)&&(n.nodeName!="BR"||n.cmIgnore)&&this.text.length>r)&&this.lineBreak(),n=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=j.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(jA(t,i.node,i.offset)?e:0))}}function jA(s,t,e){for(;;){if(!t||e<He(t))return!1;if(t==s)return!0;e=Si(t)+1,t=t.parentNode}}class td{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class GA{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:XA(t),a=new qA(l,t.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=_A(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!Na(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Na(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=t.viewport;if((O.ios||O.chrome)&&t.state.selection.main.empty&&a!=c&&(h.from>0||h.to<t.state.doc.length)){let f=Math.min(a,c),u=Math.max(a,c),d=h.from-f,p=h.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==t.state.doc.length)&&(a=0,c=t.state.doc.length)}this.newSel=w.single(c,a)}}}function kb(s,t){let e,{newSel:i}=t,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,a=n.from,c=null;(r===8||O.android&&t.text.length<l-o)&&(a=n.to,c="end");let h=YA(s.state.doc.sliceString(o,l,$n),t.text,a-o,c);h&&(O.chrome&&r==13&&h.toB==h.from+2&&t.text.slice(h.from,h.toB)==$n+$n&&h.toB--,e={from:o+h.from,to:o+h.toA,insert:B.of(t.text.slice(h.from,h.toB).split($n))})}else i&&(!s.hasFocus&&s.state.facet(Ge)||i.main.eq(n))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!n.empty&&i&&i.main.empty?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,n.to)}:e&&e.from>=n.from&&e.to<=n.to&&(e.from!=n.from||e.to!=n.to)&&n.to-n.from-(e.to-e.from)<=4?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,e.from).append(e.insert).append(s.state.doc.slice(e.to,n.to))}:(O.mac||O.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:B.of([" "])}):O.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`
17
- `&&s.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:B.of([" "])}),e)return Cb(s,e,i,r);if(i&&!i.main.eq(n)){let o=!1,l="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(o=!0),l=s.inputState.lastSelectionOrigin),s.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Cb(s,t,e,i=-1){if(O.ios&&s.inputState.flushIOSKey(t))return!0;let n=s.state.selection.main;if(O.android&&(t.to==n.to&&(t.from==n.from||t.from==n.from-1&&s.state.sliceDoc(t.from,n.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Wi(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>n.head)&&Wi(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Wi(s.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=UA(s,t,e));return s.state.facet(Z0).some(a=>a(s,t.from,t.to,r,l))||s.dispatch(l()),!0}function UA(s,t,e){let i,n=s.state,r=n.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&s.inputState.composing<0){let l=r.from<t.from?n.sliceDoc(r.from,t.from):"",a=r.to>t.to?n.sliceDoc(t.to,r.to):"";i=n.replaceSelection(s.state.toText(l+t.insert.sliceString(0,void 0,s.state.lineBreak)+a))}else{let l=n.changes(t),a=e&&e.main.to<=l.newLength?e.main:void 0;if(n.selection.ranges.length>1&&s.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let c=s.state.sliceDoc(t.from,t.to),h,f=e&&hb(s,e.main.head);if(f){let p=t.insert.length-(t.to-t.from);h={from:f.from,to:f.to-p}}else h=s.state.doc.lineAt(r.head);let u=r.to-t.to,d=r.to-r.from;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let g=p.to-u,b=g-c.length;if(p.to-p.from!=d||s.state.sliceDoc(b,g)!=c||p.to>=h.from&&p.from<=h.to)return{range:p};let m=n.changes({from:b,to:g,insert:t.insert}),y=p.to-r.to;return{changes:m,range:a?w.range(Math.max(0,a.anchor+y),Math.max(0,a.head+y)):p.map(m)}})}else i={changes:l,selection:a&&n.selection.replaceRange(a)}}let o="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,o+=".compose",s.inputState.compositionFirstChange&&(o+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:o,scrollIntoView:!0})}function YA(s,t,e,i){let n=Math.min(s.length,t.length),r=0;for(;r<n&&s.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==n&&s.length==t.length)return null;let o=s.length,l=t.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));e-=o+a-r}if(o<r&&s.length<t.length){let a=e<=r&&e>=o?r-e:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=e<=r&&e>=l?r-e:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function XA(s){let t=[];if(s.root.activeElement!=s.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return e&&(t.push(new td(e,i)),(n!=e||r!=i)&&t.push(new td(n,r))),t}function _A(s,t){if(s.length==0)return null;let e=s[0].pos,i=s.length==2?s[1].pos:e;return e>-1&&i>-1?w.single(e+t,i+t):null}const JA={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},ll=O.ie&&O.ie_version<=11;class QA{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new PM,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=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(O.ie&&O.ie_version<=11||O.ios&&t.composing)&&e.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.constructor.EDIT_CONTEXT!==!1&&!(O.chrome&&O.chrome_version<126)&&(this.editContext=new t2(t),t.state.facet(Ge)&&(t.contentDOM.editContext=this.editContext.editContext)),ll&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){t.type=="change"&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Ge)?i.root.activeElement!=this.dom:!Dr(i.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(O.ie&&O.ie_version<=11||O.android&&O.chrome)&&!i.state.selection.main.empty&&n.focusNode&&qn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=hs(t.root);if(!e)return!1;let i=O.safari&&t.root.nodeType==11&&BM(this.dom.ownerDocument)==this.dom&&ZA(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=Dr(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&NM(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,JA),ll&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),ll&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Wi(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,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 t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Dr(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new GA(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=kb(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=ed(e,t.previousSibling||t.target.previousSibling,-1),n=ed(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Ge)!=t.state.facet(Ge)&&(t.view.contentDOM.editContext=t.state.facet(Ge)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function ed(s,t,e){for(;t;){let i=j.get(t);if(i&&i.parent==s)return i;let n=t.parentNode;t=n!=s.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function id(s,t){let e=t.startContainer,i=t.startOffset,n=t.endContainer,r=t.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor);return qn(o.node,o.offset,n,r)&&([e,i,n,r]=[n,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}}function ZA(s,t){if(t.getComposedRanges){let n=t.getComposedRanges(s.root)[0];if(n)return id(s,n)}let e=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),e=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),e?id(s,e):null}class t2{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:n}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:B.of(i.text.split(`
18
- `))};r.from==this.from&&n<this.from?r.from=n:r.to==this.to&&n>this.to&&(r.to=n),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,t.state.readOnly||Cb(t,r,w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)))},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=t.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,n.push(r)}e.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;n.push(dt.mark({attributes:{style:a}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:nb.of(dt.set(n))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=hs(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((r,o,l,a,c)=>{if(i)return;let h=c.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(c)){n=this.pendingContextChange=null,e+=h,this.to+=h;return}else n=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=h,this.to+=h;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),c.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange;!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}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.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(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),t.parent&&t.parent.appendChild(this.dom);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(i=>i.forEach(n=>e(n,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||$M(t.parent)||document,this.viewState=new Qu(t.state||$.create(t)),t.scrollTo&&t.scrollTo.is(Zs)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Rn).map(i=>new nl(i));for(let i of this.plugins)i.update(this);this.observer=new QA(this),this.inputState=new gA(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Pu(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=t.length==1&&t[0]instanceof it?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,n,r=this.state;for(let u of t){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;t.some(u=>u.annotation(mb))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=bb(r,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(h=null)):this.observer.clear(),r.facet($.phrases)!=this.state.facet($.phrases))return this.setState(r);n=eo.create(this,r,t),n.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new zi(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Zs)&&(f=d.value.clip(this.state))}this.viewState.update(n,f),this.bidiCache=io.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(Ln)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(rr)!=n.state.facet(rr)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Ga))try{u(n)}catch(d){Le(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!kb(this,h)&&c.force&&Wi(this.contentDOM,c.key,c.keyCode)})}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Qu(t),this.plugins=t.facet(Rn).map(i=>new nl(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Pu(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Rn),i=t.state.facet(Rn);if(e!=i){let n=[];for(let r of i){let o=e.indexOf(r);if(o<0)n.push(new nl(r));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Le(this.state,i,"doc view update listener")}}}measure(t=!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,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(R0(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);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 c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return Le(this.state,p),nd}}),f=eo.create(this,this.state,[]),u=!1;f.flags|=a,e?e.flags|=a:e=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<c.length;d++)if(h[d]!=nd)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){Le(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){n=n+p,i.scrollTop=n/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Ga))l(e)}get themeClasses(){return _a+" "+(this.state.facet(Xa)?Sb:xb)+" "+this.state.facet(rr)}updateAttrs(){let t=sd(this,sb,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Ge)?"true":"false",class:"cm-content",style:`${O.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),sd(this,Uh,e);let i=this.observer.ignore(()=>{let n=Wa(this.contentDOM,this.contentAttrs,e),r=Wa(this.dom,this.editorAttrs,t);return n||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let n of i.effects)if(n.is(F.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(Ln);let t=this.state.facet(F.cspNonce);lt.mount(this.root,this.styleModules.concat(KA).reverse(),t?{nonce:t}: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(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.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(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return rl(this,t,Vu(this,t,e,i))}moveByGroup(t,e){return rl(this,t,Vu(this,t,e,i=>dA(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return w.cursor(r.side(e,n)+t.from,r.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return uA(this,t,e,i)}moveVertically(t,e,i){return rl(this,t,pA(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),cb(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(t),r=this.bidiSpans(n),o=r[Je.find(r,t-n.from,-1,e)];return qh(i,o.dir==vt.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(eb)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>e2)return U0(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||G0(r.isolates,i=Lu(this,t))))return r.order;i||(i=Lu(this,t));let n=YM(t.text,e,i);return this.bidiCache.push(new io(t.from,t.to,e,i,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||O.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{B0(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.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(t,e={}){return Zs.of(new zi(typeof t=="number"?w.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Zs.of(new zi(w.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return fs.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return fs.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=lt.newName(),n=[rr.of(i),Ln.of(Ja(`.${i}`,t))];return e&&e.dark&&n.push(Xa.of(!0)),n}static baseTheme(t){return _t.lowest(Ln.of(Ja("."+_a,t,vb)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&j.get(i)||j.get(t);return((e=n==null?void 0:n.rootView)===null||e===void 0?void 0:e.view)||null}}F.styleModule=Ln;F.inputHandler=Z0;F.scrollHandler=ib;F.focusChangeEffect=tb;F.perLineTextDirection=eb;F.exceptionSink=Q0;F.updateListener=Ga;F.editable=Ge;F.mouseSelectionStyle=J0;F.dragMovesSelection=_0;F.clickAddsSelectionRange=X0;F.decorations=us;F.outerDecorations=rb;F.atomicRanges=Yh;F.bidiIsolatedRanges=ob;F.scrollMargins=lb;F.darkTheme=Xa;F.cspNonce=v.define({combine:s=>s.length?s[0]:""});F.contentAttributes=Uh;F.editorAttributes=sb;F.lineWrapping=F.contentAttributes.of({class:"cm-lineWrapping"});F.announce=R.define();const e2=4096,nd={};class io{constructor(t,e,i,n,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:vt.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==n&&!e.touchesRange(o.from,o.to)&&i.push(new io(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function sd(s,t,e){for(let i=s.state.facet(t),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Va(o,e)}return e}const i2=O.mac?"mac":O.windows?"win":O.linux?"linux":"key";function n2(s,t){const e=s.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;a<e.length-1;++a){const c=e[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))n=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function or(s,t,e){return t.altKey&&(s="Alt-"+s),t.ctrlKey&&(s="Ctrl-"+s),t.metaKey&&(s="Meta-"+s),e!==!1&&t.shiftKey&&(s="Shift-"+s),s}const s2=_t.default(F.domEventHandlers({keydown(s,t){return a2(r2(t.state),s,t,"editor")}})),Mb=v.define({enables:s2}),rd=new WeakMap;function r2(s){let t=s.facet(Mb),e=rd.get(t);return e||rd.set(t,e=l2(t.reduce((i,n)=>i.concat(n),[]))),e}let Ue=null;const o2=4e3;function l2(s,t=i2){let e=Object.create(null),i=Object.create(null),n=(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,c,h)=>{var f,u;let d=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(m=>n2(m,t));for(let m=1;m<p.length;m++){let y=p.slice(0,m).join(" ");n(y,!0),d[y]||(d[y]={preventDefault:!0,stopPropagation:!1,run:[S=>{let x=Ue={view:S,prefix:y,scope:o};return setTimeout(()=>{Ue==x&&(Ue=null)},o2),!0}]})}let g=p.join(" ");n(g,!1);let b=d[g]||(d[g]={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&&b.run.push(a),c&&(b.preventDefault=!0),h&&(b.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=e[c]||(e[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in h)h[u].run.push(d=>f(d,Qa))}let a=o[t]||o.key;if(a)for(let c of l)r(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return e}let Qa=null;function a2(s,t,e,i){Qa=t;let n=Za(t),r=ht(n,0),o=Rt(r)==n.length&&n!=" ",l="",a=!1,c=!1,h=!1;Ue&&Ue.view==e&&Ue.scope==i&&(l=Ue.prefix+" ",ub.indexOf(t.keyCode)<0&&(c=!0,Ue=null));let f=new Set,u=b=>{if(b){for(let m of b.run)if(!f.has(m)&&(f.add(m),m(e)))return b.stopPropagation&&(h=!0),!0;b.preventDefault&&(b.stopPropagation&&(h=!0),c=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+or(n,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(O.windows&&t.ctrlKey&&t.altKey)&&(p=th[t.keyCode])&&p!=n?(u(d[l+or(p,t,!0)])||t.shiftKey&&(g=eh[t.keyCode])!=n&&g!=p&&u(d[l+or(g,t,!1)]))&&(a=!0):o&&t.shiftKey&&u(d[l+or(n,t,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),c&&(a=!0),a&&h&&t.stopPropagation(),Qa=null,a}const h2=!O.ios,od={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};h2&&(od[".cm-line"].caretColor=od[".cm-content"].caretColor="transparent !important");class on extends Gt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}on.prototype.elementClass="";on.prototype.toDOM=void 0;on.prototype.mapMode=I.TrackBefore;on.prototype.startSide=on.prototype.endSide=-1;on.prototype.point=!0;function ld(s){let t=Object.keys(s).join(""),e=/\w/.test(t);return e&&(t=t.replace(/\w/g,"")),`[${e?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function c2(s){let t=Object.create(null),e=Object.create(null);for(let{label:n}of s){t[n[0]]=!0;for(let r=1;r<n.length;r++)e[n[r]]=!0}let i=ld(t)+ld(e)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function f2(s){let t=s.map(n=>typeof n=="string"?{label:n}:n),[e,i]=t.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:c2(t);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:t,validFor:e}:null}}function u2(s,t){return e=>{for(let i=rt(e.state).resolveInner(e.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return t(e)}}const d2=Vt.define(),p2=F.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class g2{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}}class Jh{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,I.TrackDel),i=t.mapPos(this.to,1,I.TrackDel);return e==null||i==null?null:new Jh(this.field,e,i)}}class Qh{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],r=t.doc.lineAt(e),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let f=0;f<h;f++)c+=t.facet(an);n.push(e+c.length-h),a=c+a.slice(h)}i.push(a),e+=a.length+1}let l=this.fieldPositions.map(a=>new Jh(a.field,n[a.line]+a.from,n[a.line]+a.to));return{text:i,ranges:l}}static parse(t){let e=[],i=[],n=[],r;for(let o of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",c=-1;for(let h=0;h<e.length;h++)(l!=null?e[h].seq==l:a&&e[h].name==a)&&(c=h);if(c<0){let h=0;for(;h<e.length&&(l==null||e[h].seq!=null&&e[h].seq<l);)h++;e.splice(h,0,{seq:l,name:a}),c=h;for(let f of n)f.field>=c&&f.field++}n.push(new g2(c,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of n)a.line==i.length&&a.from>l.index&&(a.from--,a.to--)}i.push(o)}return new Qh(i,n)}}let m2=dt.widget({widget:new class extends vo{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),b2=dt.mark({class:"cm-snippetField"});class un{constructor(t,e){this.ranges=t,this.active=e,this.deco=dt.set(t.map(i=>(i.from==i.to?m2:b2).range(i.from,i.to)))}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new un(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}}const vs=R.define({map(s,t){return s&&s.map(t)}}),y2=R.define(),ds=ct.define({create(){return null},update(s,t){for(let e of t.effects){if(e.is(vs))return e.value;if(e.is(y2)&&s)return new un(s.ranges,e.value)}return s&&t.docChanged&&(s=s.map(t.changes)),s&&t.selection&&!s.selectionInsideField(t.selection)&&(s=null),s},provide:s=>F.decorations.from(s,t=>t?t.deco:dt.none)});function Zh(s,t){return w.create(s.filter(e=>e.field==t).map(e=>w.range(e.from,e.to)))}function w2(s){let t=Qh.parse(s);return(e,i,n,r)=>{let{text:o,ranges:l}=t.instantiate(e.state,n),a={changes:{from:n,to:r,insert:B.of(o)},scrollIntoView:!0,annotations:i?[d2.of(i),it.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=Zh(l,0)),l.some(c=>c.field>0)){let c=new un(l,0),h=a.effects=[vs.of(c)];e.state.field(ds,!1)===void 0&&h.push(R.appendConfig.of([ds,C2,M2,p2]))}e.dispatch(e.state.update(a))}}function Ab(s){return({state:t,dispatch:e})=>{let i=t.field(ds,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return e(t.update({selection:Zh(i.ranges,n),effects:vs.of(r?null:new un(i.ranges,n)),scrollIntoView:!0})),!0}}const x2=({state:s,dispatch:t})=>s.field(ds,!1)?(t(s.update({effects:vs.of(null)})),!0):!1,S2=Ab(1),v2=Ab(-1),k2=[{key:"Tab",run:S2,shift:v2},{key:"Escape",run:x2}],ad=v.define({combine(s){return s.length?s[0]:k2}}),C2=_t.highest(Mb.compute([ad],s=>s.facet(ad)));function Dt(s,t){return Object.assign(Object.assign({},t),{apply:w2(s)})}const M2=F.domEventHandlers({mousedown(s,t){let e=t.state.field(ds,!1),i;if(!e||(i=t.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=e.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==e.active?!1:(t.dispatch({selection:Zh(e.ranges,n.field),effects:vs.of(e.ranges.some(r=>r.field>n.field)?new un(e.ranges,n.field):null),scrollIntoView:!0}),!0)}}),Db=new class extends Gt{};Db.startSide=1;Db.endSide=-1;const Ob=[Dt("function ${name}(${params}) {\n ${}\n}",{label:"function",detail:"definition",type:"keyword"}),Dt("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n ${}\n}",{label:"for",detail:"loop",type:"keyword"}),Dt("for (let ${name} of ${collection}) {\n ${}\n}",{label:"for",detail:"of loop",type:"keyword"}),Dt("do {\n ${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),Dt("while (${}) {\n ${}\n}",{label:"while",detail:"loop",type:"keyword"}),Dt(`try {
19
- \${}
20
- } catch (\${error}) {
21
- \${}
22
- }`,{label:"try",detail:"/ catch block",type:"keyword"}),Dt("if (${}) {\n ${}\n}",{label:"if",detail:"block",type:"keyword"}),Dt(`if (\${}) {
23
- \${}
24
- } else {
25
- \${}
26
- }`,{label:"if",detail:"/ else block",type:"keyword"}),Dt(`class \${name} {
27
- constructor(\${params}) {
28
- \${}
29
- }
30
- }`,{label:"class",detail:"definition",type:"keyword"}),Dt('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),Dt('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],A2=Ob.concat([Dt("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),Dt("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),Dt("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),hd=new ud,Tb=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function yn(s){return(t,e)=>{let i=t.node.getChild("VariableDefinition");return i&&e(i,s),!0}}const D2=["FunctionDeclaration"],O2={FunctionDeclaration:yn("function"),ClassDeclaration:yn("class"),ClassExpression:()=>!0,EnumDeclaration:yn("constant"),TypeAliasDeclaration:yn("type"),NamespaceDeclaration:yn("namespace"),VariableDefinition(s,t){s.matchContext(D2)||t(s,"variable")},TypeDefinition(s,t){t(s,"type")},__proto__:null};function Bb(s,t){let e=hd.get(t);if(e)return e;let i=[],n=!0;function r(o,l){let a=s.sliceString(o.from,o.to);i.push({label:a,type:l})}return t.cursor(nh.IncludeAnonymous).iterate(o=>{if(n)n=!1;else if(o.name){let l=O2[o.name];if(l&&l(o,r)||Tb.has(o.name))return!1}else if(o.to-o.from>8192){for(let l of Bb(s,o.node))i.push(l);return!1}}),hd.set(t,i),i}const cd=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Eb=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName",".","?."];function T2(s){let t=rt(s.state).resolveInner(s.pos,-1);if(Eb.indexOf(t.name)>-1)return null;let e=t.name=="VariableName"||t.to-t.from<20&&cd.test(s.state.sliceDoc(t.from,t.to));if(!e&&!s.explicit)return null;let i=[];for(let n=t;n;n=n.parent)Tb.has(n.name)&&(i=i.concat(Bb(s.state.doc,n)));return{options:i,from:e?t.from:s.pos,validFor:cd}}const di=Yi.define({name:"javascript",parser:Kb.configure({props:[ao.add({IfStatement:Wn({except:/^\s*({|else\b)/}),TryStatement:Wn({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Uw,SwitchBody:s=>{let t=s.textAfter,e=/^\s*\}/.test(t),i=/^\s*(case|default)\b/.test(t);return s.baseIndent+(e?0:i?1:2)*s.unit},Block:wr({closing:"}"}),ArrowFunction:s=>s.baseIndent+s.unit,"TemplateString BlockComment":()=>null,"Statement Property":Wn({except:/^{/}),JSXElement(s){let t=/^\s*<\//.test(s.textAfter);return s.lineIndent(s.node.from)+(t?0:s.unit)},JSXEscape(s){let t=/\s*\}/.test(s.textAfter);return s.lineIndent(s.node.from)+(t?0:s.unit)},"JSXOpenTag JSXSelfClosingTag"(s){return s.column(s.node.from)+s.unit}}),ho.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Sh,BlockComment(s){return{from:s.from+2,to:s.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),Rb={test:s=>/^JSX/.test(s.name),facet:Yp({commentTokens:{block:{open:"{/*",close:"*/}"}}})},B2=di.configure({dialect:"ts"},"typescript"),E2=di.configure({dialect:"jsx",props:[bh.add(s=>s.isTop?[Rb]:void 0)]}),R2=di.configure({dialect:"jsx ts",props:[bh.add(s=>s.isTop?[Rb]:void 0)]},"typescript");let Lb=s=>({label:s,type:"keyword"});const Pb="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(Lb),L2=Pb.concat(["declare","implements","private","protected","public"].map(Lb));function YD(s={}){let t=s.jsx?s.typescript?R2:E2:s.typescript?B2:di,e=s.typescript?A2.concat(L2):Ob.concat(Pb);return new yh(t,[di.data.of({autocomplete:u2(Eb,f2(e))}),di.data.of({autocomplete:T2}),s.jsx?N2:[]])}function P2(s){for(;;){if(s.name=="JSXOpenTag"||s.name=="JSXSelfClosingTag"||s.name=="JSXFragmentTag")return s;if(s.name=="JSXEscape"||!s.parent)return null;s=s.parent}}function fd(s,t,e=s.length){for(let i=t==null?void 0:t.firstChild;i;i=i.nextSibling)if(i.name=="JSXIdentifier"||i.name=="JSXBuiltin"||i.name=="JSXNamespacedName"||i.name=="JSXMemberExpression")return s.sliceString(i.from,Math.min(i.to,e));return""}const $2=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),N2=F.inputHandler.of((s,t,e,i,n)=>{if(($2?s.composing:s.compositionStarted)||s.state.readOnly||t!=e||i!=">"&&i!="/"||!di.isActiveAt(s.state,t,-1))return!1;let r=n(),{state:o}=r,l=o.changeByRange(a=>{var c;let{head:h}=a,f=rt(o).resolveInner(h-1,-1),u;if(f.name=="JSXStartTag"&&(f=f.parent),!(o.doc.sliceString(h-1,h)!=i||f.name=="JSXAttributeValue"&&f.to>h)){if(i==">"&&f.name=="JSXFragmentTag")return{range:a,changes:{from:h,insert:"</>"}};if(i=="/"&&f.name=="JSXStartCloseTag"){let d=f.parent,p=d.parent;if(p&&d.from==h-2&&((u=fd(o.doc,p.firstChild,h))||((c=p.firstChild)===null||c===void 0?void 0:c.name)=="JSXFragmentTag")){let g=`${u}>`;return{range:w.cursor(h+g.length,-1),changes:{from:h,insert:g}}}}else if(i==">"){let d=P2(f);if(d&&d.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(h,h+2))&&(u=fd(o.doc,d,h)))return{range:a,changes:{from:h,insert:`</${u}>`}}}}return{range:a}});return l.changes.empty?!1:(s.dispatch([r,o.update(l,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});export{T as E,DM as R,jD as a,YD as b,wS as c,GD as j,ps as k,qD as l,gD as n,pD as p};