UNPKG

thebe-core

Version:

Typescript based core functionality for Thebe

2 lines 599 kB
/*! For license information please see 2817.thebe-core.min.js.LICENSE.txt */ (self.webpackChunkthebe_core=self.webpackChunkthebe_core||[]).push([[2817],{22817:(e,t,n)=>{"use strict";n.d(t,{Component:()=>Hr});var i=n(14830),s=n(83173),r=n(29587),o=n(79066);function a(e,t){return({state:n,dispatch:i})=>{if(n.readOnly)return!1;let s=e(t,n);return!!s&&(i(n.update(s)),!0)}}const l=a(p,0),h=a(d,0),c=a(((e,t)=>d(e,t,function(e){let t=[];for(let n of e.selection.ranges){let i=e.doc.lineAt(n.from),s=n.to<=i.to?i:e.doc.lineAt(n.to),r=t.length-1;r>=0&&t[r].to>i.from?t[r].to=s.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return t}(t))),0);function u(e,t){let n=e.languageDataAt("commentTokens",t);return n.length?n[0]:{}}const f=50;function d(e,t,n=t.selection.ranges){let i=n.map((e=>u(t,e.from).block));if(!i.every((e=>e)))return null;let s=n.map(((e,n)=>function(e,{open:t,close:n},i,s){let r,o,a=e.sliceDoc(i-f,i),l=e.sliceDoc(s,s+f),h=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(l)[0].length,u=a.length-h;if(a.slice(u-t.length,u)==t&&l.slice(c,c+n.length)==n)return{open:{pos:i-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};s-i<=2*f?r=o=e.sliceDoc(i,s):(r=e.sliceDoc(i,i+f),o=e.sliceDoc(s-f,s));let d=/^\s*/.exec(r)[0].length,p=/\s*$/.exec(o)[0].length,m=o.length-p-n.length;return r.slice(d,d+t.length)==t&&o.slice(m,m+n.length)==n?{open:{pos:i+d+t.length,margin:/\s/.test(r.charAt(d+t.length))?1:0},close:{pos:s-p-n.length,margin:/\s/.test(o.charAt(m-1))?1:0}}:null}(t,i[n],e.from,e.to)));if(2!=e&&!s.every((e=>e)))return{changes:t.changes(n.map(((e,t)=>s[t]?[]:[{from:e.from,insert:i[t].open+" "},{from:e.to,insert:" "+i[t].close}])))};if(1!=e&&s.some((e=>e))){let e=[];for(let t,n=0;n<s.length;n++)if(t=s[n]){let s=i[n],{open:r,close:o}=t;e.push({from:r.pos-s.open.length,to:r.pos+r.margin},{from:o.pos-o.margin,to:o.pos+s.close.length})}return{changes:e}}return null}function p(e,t,n=t.selection.ranges){let i=[],s=-1;for(let{from:e,to:r}of n){let n=i.length,o=1e9,a=u(t,e).line;if(a){for(let n=e;n<=r;){let l=t.doc.lineAt(n);if(l.from>s&&(e==r||r>l.from)){s=l.from;let e=/^\s*/.exec(l.text)[0].length,t=e==l.length,n=l.text.slice(e,e+a.length)==a?e:-1;e<l.text.length&&e<o&&(o=e),i.push({line:l,comment:n,token:a,indent:e,empty:t,single:!1})}n=l.to+1}if(o<1e9)for(let e=n;e<i.length;e++)i[e].indent<i[e].line.text.length&&(i[e].indent=o);i.length==n+1&&(i[n].single=!0)}}if(2!=e&&i.some((e=>e.comment<0&&(!e.empty||e.single)))){let e=[];for(let{line:t,token:n,indent:s,empty:r,single:o}of i)!o&&r||e.push({from:t.from+s,insert:n+" "});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(1!=e&&i.some((e=>e.comment>=0))){let e=[];for(let{line:t,comment:n,token:s}of i)if(n>=0){let i=t.from+n,r=i+s.length;" "==t.text[r-t.from]&&r++,e.push({from:i,to:r})}return{changes:e}}return null}const m=i.YH.define(),g=i.sj.define();class b{constructor(e,t,n,i,s){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=i,this.selectionsAfter=s}setSelAfter(e){return new b(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:null===(e=this.changes)||void 0===e?void 0:e.toJSON(),mapped:null===(t=this.mapped)||void 0===t?void 0:t.toJSON(),startSelection:null===(n=this.startSelection)||void 0===n?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map((e=>e.toJSON()))}}static fromJSON(e){return new b(e.changes&&i.VR.fromJSON(e.changes),[],e.mapped&&i.Gu.fromJSON(e.mapped),e.startSelection&&i.OF.fromJSON(e.startSelection),e.selectionsAfter.map(i.OF.fromJSON))}static fromTransaction(e,t){let n=x;for(let t of e.startState.facet(g)){let i=t(e);i.length&&(n=n.concat(i))}return!n.length&&e.changes.empty?null:new b(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,x)}static selection(e){return new b(void 0,x,void 0,void 0,e)}}function y(e,t,n,i){let s=t+1>n+20?t-n-1:0,r=e.slice(s,t);return r.push(i),r}function v(e,t){return e.length?t.length?e.concat(t):e:t}const x=[];function w(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function k(e,t){if(!e.length)return e;let n=e.length,i=x;for(;n;){let s=S(e[n-1],t,i);if(s.changes&&!s.changes.empty||s.effects.length){let t=e.slice(0,n);return t[n-1]=s,t}t=s.mapped,n--,i=s.selectionsAfter}return i.length?[b.selection(i)]:x}function S(e,t,n){let s=v(e.selectionsAfter.length?e.selectionsAfter.map((e=>e.map(t))):x,n);if(!e.changes)return b.selection(s);let r=e.changes.map(t),o=t.mapDesc(e.changes,!0),a=e.mapped?e.mapped.composeDesc(o):o;return new b(r,i.Pe.mapEffects(e.effects,t),a,e.startSelection.map(o),s)}const C=/^(input\.type|delete)($|\.)/;class A{constructor(e,t,n=0,i=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=i}isolate(){return this.prevTime?new A(this.done,this.undone):this}addChanges(e,t,n,s,r){let o=this.done,a=o[o.length-1];return o=a&&a.changes&&!a.changes.empty&&e.changes&&(!n||C.test(n))&&(!a.selectionsAfter.length&&t-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,function(e,t){let n=[],i=!1;return e.iterChangedRanges(((e,t)=>n.push(e,t))),t.iterChangedRanges(((e,t,s,r)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];r>=t&&s<=o&&(i=!0)}})),i}(a.changes,e.changes))||"input.type.compose"==n)?y(o,o.length-1,s.minDepth,new b(e.changes.compose(a.changes),v(i.Pe.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,x)):y(o,o.length,s.minDepth,e),new A(o,x,t,n)}addSelection(e,t,n,i){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:x;return s.length>0&&t-this.prevTime<i&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&(r=s[s.length-1],o=e,r.ranges.length==o.ranges.length&&0===r.ranges.filter(((e,t)=>e.empty!=o.ranges[t].empty)).length)?this:new A(function(e,t){if(e.length){let n=e[e.length-1],i=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-200));return i.length&&i[i.length-1].eq(t)?e:(i.push(t),y(e,e.length-1,1e9,n.setSelAfter(i)))}return[b.selection([t])]}(this.done,e),this.undone,t,n);var r,o}addMapping(e){return new A(k(this.done,e),k(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let i=0==e?this.done:this.undone;if(0==i.length)return null;let s=i[i.length-1],r=s.selectionsAfter[0]||t.selection;if(n&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:m.of({side:e,rest:w(i),selection:r}),userEvent:0==e?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let n=1==i.length?x:i.slice(0,i.length-1);return s.mapped&&(n=k(n,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:m.of({side:e,rest:n,selection:r}),filter:!1,userEvent:0==e?"undo":"redo",scrollIntoView:!0})}return null}}function O(e,t){return i.OF.create(e.ranges.map(t),e.mainIndex)}function M(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function _({state:e,dispatch:t},n){let i=O(e.selection,n);return!i.eq(e.selection,!0)&&(t(M(e,i)),!0)}function T(e,t){return i.OF.cursor(t?e.to:e.from)}function E(e,t){return _(e,(n=>n.empty?e.moveByChar(n,t):T(n,t)))}function N(e){return e.textDirectionAt(e.state.selection.main.head)==s.OP.LTR}A.empty=new A(x,x);const D=e=>E(e,!N(e)),P=e=>E(e,N(e));function R(e,t){return _(e,(n=>n.empty?e.moveByGroup(n,t):T(n,t)))}function j(e,t,n){if(t.type.prop(n))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function L(e,t,n){let s,a,l=(0,r.mv)(e).resolveInner(t.head),h=n?o.uY.closedBy:o.uY.openedBy;for(let i=t.head;;){let t=n?l.childAfter(i):l.childBefore(i);if(!t)break;j(e,t,h)?l=t:i=n?t.to:t.from}return a=l.type.prop(h)&&(s=n?(0,r.jU)(e,l.from,1):(0,r.jU)(e,l.to,-1))&&s.matched?n?s.end.to:s.end.from:n?l.to:l.from,i.OF.cursor(a,n?-1:1)}function B(e,t){return _(e,(n=>{if(!n.empty)return T(n,t);let i=e.moveVertically(n,t);return i.head!=n.head?i:e.moveToLineBoundary(n,t)}))}"undefined"!=typeof Intl&&Intl.Segmenter;const I=e=>B(e,!1),F=e=>B(e,!0);function $(e){let t,n=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,i=0,r=0;if(n){for(let t of e.state.facet(s.Lz.scrollMargins)){let n=t(e);(null==n?void 0:n.top)&&(i=Math.max(null==n?void 0:n.top,i)),(null==n?void 0:n.bottom)&&(r=Math.max(null==n?void 0:n.bottom,r))}t=e.scrollDOM.clientHeight-i-r}else t=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:i,marginBottom:r,selfScroll:n,height:Math.max(e.defaultLineHeight,t-5)}}function z(e,t){let n,i=$(e),{state:r}=e,o=O(r.selection,(n=>n.empty?e.moveVertically(n,t,i.height):T(n,t)));if(o.eq(r.selection))return!1;if(i.selfScroll){let t=e.coordsAtPos(r.selection.main.head),a=e.scrollDOM.getBoundingClientRect(),l=a.top+i.marginTop,h=a.bottom-i.marginBottom;t&&t.top>l&&t.bottom<h&&(n=s.Lz.scrollIntoView(o.main.head,{y:"start",yMargin:t.top-l}))}return e.dispatch(M(r,o),{effects:n}),!0}const H=e=>z(e,!1),q=e=>z(e,!0);function V(e,t,n){let s=e.lineBlockAt(t.head),r=e.moveToLineBoundary(t,n);if(r.head==t.head&&r.head!=(n?s.to:s.from)&&(r=e.moveToLineBoundary(t,n,!1)),!n&&r.head==s.from&&s.length){let n=/^\s*/.exec(e.state.sliceDoc(s.from,Math.min(s.from+100,s.to)))[0].length;n&&t.head!=s.from+n&&(r=i.OF.cursor(s.from+n))}return r}function W(e,t){let n=O(e.state.selection,(e=>{let n=t(e);return i.OF.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)}));return!n.eq(e.state.selection)&&(e.dispatch(M(e.state,n)),!0)}function G(e,t){return W(e,(n=>e.moveByChar(n,t)))}const U=e=>G(e,!N(e)),K=e=>G(e,N(e));function J(e,t){return W(e,(n=>e.moveByGroup(n,t)))}function Y(e,t){return W(e,(n=>e.moveVertically(n,t)))}const X=e=>Y(e,!1),Q=e=>Y(e,!0);function Z(e,t){return W(e,(n=>e.moveVertically(n,t,$(e).height)))}const ee=e=>Z(e,!1),te=e=>Z(e,!0),ne=({state:e,dispatch:t})=>(t(M(e,{anchor:0})),!0),ie=({state:e,dispatch:t})=>(t(M(e,{anchor:e.doc.length})),!0),se=({state:e,dispatch:t})=>(t(M(e,{anchor:e.selection.main.anchor,head:0})),!0),re=({state:e,dispatch:t})=>(t(M(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),oe=({state:e,dispatch:t})=>{let n=e.selection,s=null;return n.ranges.length>1?s=i.OF.create([n.main]):n.main.empty||(s=i.OF.create([i.OF.cursor(n.main.head)])),!!s&&(t(M(e,s)),!0)};function ae(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,o=r.changeByRange((s=>{let{from:r,to:o}=s;if(r==o){let i=t(s);i<r?(n="delete.backward",i=le(e,i,!1)):i>r&&(n="delete.forward",i=le(e,i,!0)),r=Math.min(r,i),o=Math.max(o,i)}else r=le(e,r,!1),o=le(e,o,!0);return r==o?{range:s}:{changes:{from:r,to:o},range:i.OF.cursor(r,r<s.head?-1:1)}}));return!o.changes.empty&&(e.dispatch(r.update(o,{scrollIntoView:!0,userEvent:n,effects:"delete.selection"==n?s.Lz.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function le(e,t,n){if(e instanceof s.Lz)for(let i of e.state.facet(s.Lz.atomicRanges).map((t=>t(e))))i.between(t,t,((e,i)=>{e<t&&i>t&&(t=n?i:e)}));return t}const he=(e,t,n)=>ae(e,(s=>{let o,a,l=s.from,{state:h}=e,c=h.doc.lineAt(l);if(n&&!t&&l>c.from&&l<c.from+200&&!/[^ \t]/.test(o=c.text.slice(0,l-c.from))){if("\t"==o[o.length-1])return l-1;let e=(0,i.y$)(o,h.tabSize)%(0,r.tp)(h)||(0,r.tp)(h);for(let t=0;t<e&&" "==o[o.length-1-t];t++)l--;a=l}else a=(0,i.zK)(c.text,l-c.from,t,t)+c.from,a==l&&c.number!=(t?h.doc.lines:1)?a+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(c.text.slice(a-c.from,l-c.from))&&(a=(0,i.zK)(c.text,a-c.from,!1,!1)+c.from);return a})),ce=e=>he(e,!1,!0),ue=e=>he(e,!0,!1),fe=(e,t)=>ae(e,(n=>{let s=n.head,{state:r}=e,o=r.doc.lineAt(s),a=r.charCategorizer(s);for(let e=null;;){if(s==(t?o.to:o.from)){s==n.head&&o.number!=(t?r.doc.lines:1)&&(s+=t?1:-1);break}let l=(0,i.zK)(o.text,s-o.from,t)+o.from,h=o.text.slice(Math.min(s,l)-o.from,Math.max(s,l)-o.from),c=a(h);if(null!=e&&c!=e)break;" "==h&&s==n.head||(e=c),s=l}return s})),de=e=>fe(e,!1);function pe(e){let t=[],n=-1;for(let i of e.selection.ranges){let s=e.doc.lineAt(i.from),r=e.doc.lineAt(i.to);if(i.empty||i.to!=r.from||(r=e.doc.lineAt(i.to-1)),n>=s.number){let e=t[t.length-1];e.to=r.to,e.ranges.push(i)}else t.push({from:s.from,to:r.to,ranges:[i]});n=r.number+1}return t}function me(e,t,n){if(e.readOnly)return!1;let s=[],r=[];for(let t of pe(e)){if(n?t.to==e.doc.length:0==t.from)continue;let o=e.doc.lineAt(n?t.to+1:t.from-1),a=o.length+1;if(n){s.push({from:t.to,to:o.to},{from:t.from,insert:o.text+e.lineBreak});for(let n of t.ranges)r.push(i.OF.range(Math.min(e.doc.length,n.anchor+a),Math.min(e.doc.length,n.head+a)))}else{s.push({from:o.from,to:t.from},{from:t.to,insert:e.lineBreak+o.text});for(let e of t.ranges)r.push(i.OF.range(e.anchor-a,e.head-a))}}return!!s.length&&(t(e.update({changes:s,scrollIntoView:!0,selection:i.OF.create(r,e.selection.mainIndex),userEvent:"move.line"})),!0)}function ge(e,t,n){if(e.readOnly)return!1;let i=[];for(let t of pe(e))n?i.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):i.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});return t(e.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const be=ve(!1),ye=ve(!0);function ve(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let s=t.changeByRange((n=>{let{from:s,to:a}=n,l=t.doc.lineAt(s),h=!e&&s==a&&function(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n,i=(0,r.mv)(e).resolveInner(t),s=i.childBefore(t),a=i.childAfter(t);return s&&a&&s.to<=t&&a.from>=t&&(n=s.type.prop(o.uY.closedBy))&&n.indexOf(a.name)>-1&&e.doc.lineAt(s.to).from==e.doc.lineAt(a.from).from&&!/\S/.test(e.sliceDoc(s.to,a.from))?{from:s.to,to:a.from}:null}(t,s);e&&(s=a=(a<=l.to?l:t.doc.lineAt(a)).to);let c=new r.KB(t,{simulateBreak:s,simulateDoubleBreak:!!h}),u=(0,r._v)(c,s);for(null==u&&(u=(0,i.y$)(/^\s*/.exec(t.doc.lineAt(s).text)[0],t.tabSize));a<l.to&&/\s/.test(l.text[a-l.from]);)a++;h?({from:s,to:a}=h):s>l.from&&s<l.from+100&&!/\S/.test(l.text.slice(0,s))&&(s=l.from);let f=["",(0,r.EI)(t,u)];return h&&f.push((0,r.EI)(t,c.lineIndent(l.from,-1))),{changes:{from:s,to:a,insert:i.EY.of(f)},range:i.OF.cursor(s+1+f[1].length)}}));return n(t.update(s,{scrollIntoView:!0,userEvent:"input"})),!0}}function xe(e,t){let n=-1;return e.changeByRange((s=>{let r=[];for(let i=s.from;i<=s.to;){let o=e.doc.lineAt(i);o.number>n&&(s.empty||s.to>o.from)&&(t(o,r,s),n=o.number),i=o.to+1}let o=e.changes(r);return{changes:r,range:i.OF.range(o.mapPos(s.anchor,1),o.mapPos(s.head,1))}}))}const we=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(xe(e,((t,n)=>{n.push({from:t.from,insert:e.facet(r.Xt)})})),{userEvent:"input.indent"})),!0),ke=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(xe(e,((t,n)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let o=(0,i.y$)(s,e.tabSize),a=0,l=(0,r.EI)(e,Math.max(0,o-(0,r.tp)(e)));for(;a<s.length&&a<l.length&&s.charCodeAt(a)==l.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+s.length,insert:l.slice(a)})})),{userEvent:"delete.dedent"})),!0),Se=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:e=>_(e,(t=>L(e.state,t,!N(e)))),shift:e=>W(e,(t=>L(e.state,t,!N(e))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:e=>_(e,(t=>L(e.state,t,N(e)))),shift:e=>W(e,(t=>L(e.state,t,N(e))))},{key:"Alt-ArrowUp",run:({state:e,dispatch:t})=>me(e,t,!1)},{key:"Shift-Alt-ArrowUp",run:({state:e,dispatch:t})=>ge(e,t,!1)},{key:"Alt-ArrowDown",run:({state:e,dispatch:t})=>me(e,t,!0)},{key:"Shift-Alt-ArrowDown",run:({state:e,dispatch:t})=>ge(e,t,!0)},{key:"Escape",run:oe},{key:"Mod-Enter",run:ye},{key:"Alt-l",mac:"Ctrl-l",run:({state:e,dispatch:t})=>{let n=pe(e).map((({from:t,to:n})=>i.OF.range(t,Math.min(n+1,e.doc.length))));return t(e.update({selection:i.OF.create(n),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:e,dispatch:t})=>{let n=O(e.selection,(t=>{var n;for(let s=(0,r.mv)(e).resolveStack(t.from,1);s;s=s.next){let{node:e}=s;if((e.from<t.from&&e.to>=t.to||e.to>t.to&&e.from<=t.from)&&(null===(n=e.parent)||void 0===n?void 0:n.parent))return i.OF.range(e.to,e.from)}return t}));return t(M(e,n)),!0},preventDefault:!0},{key:"Mod-[",run:ke},{key:"Mod-]",run:we},{key:"Mod-Alt-\\",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),i=new r.KB(e,{overrideIndentation:e=>{let t=n[e];return null==t?-1:t}}),s=xe(e,((t,s,o)=>{let a=(0,r._v)(i,t.from);if(null==a)return;/\S/.test(t.text)||(a=0);let l=/^\s*/.exec(t.text)[0],h=(0,r.EI)(e,a);(l!=h||o.from<t.from+l.length)&&(n[t.from]=a,s.push({from:t.from,to:t.from+l.length,insert:h}))}));return s.changes.empty||t(e.update(s,{userEvent:"indent"})),!0}},{key:"Shift-Mod-k",run:e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(pe(t).map((({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n})))),i=O(t.selection,(t=>{let n;if(e.lineWrapping){let i=e.lineBlockAt(t.head),s=e.coordsAtPos(t.head,t.assoc||1);s&&(n=i.bottom+e.documentTop-s.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)})).map(n);return e.dispatch({changes:n,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:e,dispatch:t})=>function(e,t,n){let s=!1,o=O(e.selection,(t=>{let o=(0,r.jU)(e,t.head,-1)||(0,r.jU)(e,t.head,1)||t.head>0&&(0,r.jU)(e,t.head-1,1)||t.head<e.doc.length&&(0,r.jU)(e,t.head+1,-1);if(!o||!o.end)return t;s=!0;let a=o.start.from==t.head?o.end.to:o.end.from;return n?i.OF.range(t.anchor,a):i.OF.cursor(a)}));return!!s&&(t(M(e,o)),!0)}(e,t,!1)},{key:"Mod-/",run:e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),i=u(e.state,n.from);return i.line?l(e):!!i.block&&c(e)}},{key:"Alt-A",run:h},{key:"Ctrl-m",mac:"Shift-Alt-m",run:e=>(e.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:D,shift:U,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e=>R(e,!N(e)),shift:e=>J(e,!N(e)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:e=>_(e,(t=>V(e,t,!N(e)))),shift:e=>W(e,(t=>V(e,t,!N(e)))),preventDefault:!0},{key:"ArrowRight",run:P,shift:K,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:e=>R(e,N(e)),shift:e=>J(e,N(e)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:e=>_(e,(t=>V(e,t,N(e)))),shift:e=>W(e,(t=>V(e,t,N(e)))),preventDefault:!0},{key:"ArrowUp",run:I,shift:X,preventDefault:!0},{mac:"Cmd-ArrowUp",run:ne,shift:se},{mac:"Ctrl-ArrowUp",run:H,shift:ee},{key:"ArrowDown",run:F,shift:Q,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ie,shift:re},{mac:"Ctrl-ArrowDown",run:q,shift:te},{key:"PageUp",run:H,shift:ee},{key:"PageDown",run:q,shift:te},{key:"Home",run:e=>_(e,(t=>V(e,t,!1))),shift:e=>W(e,(t=>V(e,t,!1))),preventDefault:!0},{key:"Mod-Home",run:ne,shift:se},{key:"End",run:e=>_(e,(t=>V(e,t,!0))),shift:e=>W(e,(t=>V(e,t,!0))),preventDefault:!0},{key:"Mod-End",run:ie,shift:re},{key:"Enter",run:be},{key:"Mod-a",run:({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:ce,shift:ce},{key:"Delete",run:ue},{key:"Mod-Backspace",mac:"Alt-Backspace",run:de},{key:"Mod-Delete",mac:"Alt-Delete",run:e=>fe(e,!0)},{mac:"Mod-Backspace",run:e=>ae(e,(t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}))},{mac:"Mod-Delete",run:e=>ae(e,(t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}))}].concat([{key:"Ctrl-b",run:D,shift:U,preventDefault:!0},{key:"Ctrl-f",run:P,shift:K},{key:"Ctrl-p",run:I,shift:X},{key:"Ctrl-n",run:F,shift:Q},{key:"Ctrl-a",run:e=>_(e,(t=>i.OF.cursor(e.lineBlockAt(t.head).from,1))),shift:e=>W(e,(t=>i.OF.cursor(e.lineBlockAt(t.head).from)))},{key:"Ctrl-e",run:e=>_(e,(t=>i.OF.cursor(e.lineBlockAt(t.head).to,-1))),shift:e=>W(e,(t=>i.OF.cursor(e.lineBlockAt(t.head).to)))},{key:"Ctrl-d",run:ue},{key:"Ctrl-h",run:ce},{key:"Ctrl-k",run:e=>ae(e,(t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}))},{key:"Ctrl-Alt-h",run:de},{key:"Ctrl-o",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:i.EY.of(["",""])},range:i.OF.cursor(e.from)})));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange((t=>{if(!t.empty||0==t.from||t.from==e.doc.length)return{range:t};let n=t.from,s=e.doc.lineAt(n),r=n==s.from?n-1:(0,i.zK)(s.text,n-s.from,!1)+s.from,o=n==s.to?n+1:(0,i.zK)(s.text,n-s.from,!0)+s.from;return{changes:{from:r,to:o,insert:e.doc.slice(n,o).append(e.doc.slice(r,n))},range:i.OF.cursor(o)}}));return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:q}].map((e=>({mac:e.key,run:e.run,shift:e.shift})))));var Ce=n(75764);new Ce.Token("@jupyterlab/codeeditor:IEditorServices","A service for the text editor provider\n for the application. Use this to create new text editors and host them in your\n UI elements."),new Ce.Token("@jupyterlab/codeeditor:IPositionModel","A service to handle an code editor cursor position.");const Ae="[data-jp-code-runner]";var Oe;!function(e){e.indentMoreOrInsertTab=function(e){var t;if(null===(t=e.dom.parentElement)||void 0===t?void 0:t.classList.contains("jp-mod-completer-enabled"))return!1;const n={state:e.state,dispatch:e.dispatch},i=e.state.selection.main.from;if(i!=e.state.selection.main.to)return we(n);const s=e.state.doc.lineAt(i),r=e.state.doc.slice(s.from,i).toString();return/^\s*$/.test(r)?we(n):(({state:e,dispatch:t})=>e.selection.ranges.some((e=>!e.empty))?we({state:e,dispatch:t}):(t(e.update(e.replaceSelection("\t"),{scrollIntoView:!0,userEvent:"input"})),!0))(n)},e.completerOrInsertNewLine=function(e){var t;if(null===(t=e.dom.parentElement)||void 0===t?void 0:t.classList.contains("jp-mod-completer-active"))return!1;if(e.dom.closest('[data-jp-interaction-mode="terminal"]'))return!1;const n={state:e.state,dispatch:e.dispatch};return be(n)},e.preventNewLineOnRun=function(e){return!!e.dom.closest(Ae)},e.insertBlankLineOnRun=function(e){if(e.dom.closest(Ae))return!1;{const t={state:e.state,dispatch:e.dispatch};return ye(t)}},e.simplifySelectionAndMaybeSwitchToCommandMode=function(e){const t={state:e.state,dispatch:e.dispatch},n=oe(t);return!e.dom.closest(".jp-mod-editMode .jp-Cell.jp-mod-active")&&n},e.dedentIfNotLaunchingTooltip=function(e){return!e.dom.closest(".jp-CodeMirrorEditor:not(.jp-mod-has-primary-selection):not(.jp-mod-in-leading-whitespace):not(.jp-mod-completer-active)")&&ke(e)}}(Oe||(Oe={}));var Me=n(38571),_e=n(77213),Te=n(10509);const Ee=i.sj.define({combine:e=>(0,i.QR)(e,{fontFamily:null,fontSize:null,lineHeight:null},{fontFamily:(e,t)=>null!=e?e:t,fontSize:(e,t)=>null!=e?e:t,lineHeight:(e,t)=>null!=e?e:t})});function Ne(e){const{fontFamily:t,fontSize:n,lineHeight:i}=e.state.facet(Ee);let s="";return n&&(s+=`font-size: ${n}px !important;`),t&&(s+=`font-family: ${t} !important;`),i&&(s+=`line-height: ${i.toString()} !important`),{style:s}}var De=n(49913);const Pe="InlineMathDollar",Re="InlineMathBracket",je="BlockMathDollar",Le="BlockMathBracket",Be={[Pe]:1,[Re]:3,[je]:2,[Le]:3};Object.keys(Be).reduce(((e,t)=>(e[t]={mark:`${t}Mark`,resolve:t},e)),{});const Ie="cm-rulers",Fe=s.Lz.baseTheme({[`.${Ie}`]:{borderRight:"1px dotted gray",opacity:.7}}),$e=i.sj.define({combine:e=>e.reduce(((e,t)=>e.concat(t.filter(((n,i)=>!e.includes(n)&&i==t.lastIndexOf(n))))),[])}),ze=s.Z9.fromClass(class{constructor(e){var t,n;this.rulersContainer=e.dom.appendChild(document.createElement("div")),this.rulersContainer.style.cssText="\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n overflow: hidden;\n ";const i=e.defaultCharacterWidth,s=e.state.facet($e),r=null!==(n=null===(t=e.scrollDOM.querySelector(".cm-gutters"))||void 0===t?void 0:t.clientWidth)&&void 0!==n?n:0;this.rulers=s.map((e=>{const t=this.rulersContainer.appendChild(document.createElement("div"));return t.classList.add(Ie),t.style.cssText=`\n position: absolute;\n left: ${r+e*i}px;\n height: 100%;\n `,t.style.width="6px",t}))}update(e){var t,n;const i=e.view.state.facet($e);if(e.viewportChanged||e.geometryChanged||!Ce.JSONExt.deepEqual(i,e.startState.facet($e))){const s=null!==(n=null===(t=e.view.scrollDOM.querySelector(".cm-gutters"))||void 0===t?void 0:t.clientWidth)&&void 0!==n?n:0,r=e.view.defaultCharacterWidth;this.rulers.forEach(((e,t)=>{e.style.left=`${s+i[t]*r}px`}))}}destroy(){this.rulers.forEach((e=>{e.remove()})),this.rulersContainer.remove()}}),He=i.sj.define({combine:e=>e[e.length-1]}),qe=i.YH.define();function Ve(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,n=arguments[1];if(n&&"object"==typeof n&&null==n.nodeType&&!Array.isArray(n)){for(var i in n)if(Object.prototype.hasOwnProperty.call(n,i)){var s=n[i];"string"==typeof s?e.setAttribute(i,s):null!=s&&(e[i]=s)}t++}for(;t<arguments.length;t++)We(e,arguments[t]);return e}function We(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var n=0;n<t.length;n++)We(e,t[n])}}s.Z9.fromClass(class{constructor(e){this.conf=e.state.facet(He),this._observer=(t,n)=>{var i;if(n.origin!==this.conf){const n=t.delta,s=[];let r=0;for(let e=0;e<n.length;e++){const t=n[e];null!=t.insert?s.push({from:r,to:r,insert:t.insert}):null!=t.delete?(s.push({from:r,to:r+t.delete,insert:""}),r+=t.delete):r+=null!==(i=t.retain)&&void 0!==i?i:0}e.dispatch({changes:s,annotations:[qe.of(this.conf)]})}},this._ytext=this.conf.ytext,this._ytext.observe(this._observer)}update(e){if(!e.docChanged||e.transactions.length>0&&e.transactions[0].annotation(qe)===this.conf)return;const t=this.conf.ytext;t.doc.transact((()=>{let n=0;e.changes.iterChanges(((e,i,s,r,o)=>{const a=o.sliceString(0,o.length,"\n");e!==i&&t.delete(e+n,i-e),a.length>0&&t.insert(e+n,a),n+=a.length-(i-e)}))}),this.conf)}destroy(){this._ytext.unobserve(this._observer)}});const Ge="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class Ue{constructor(e,t,n=0,i=e.length,s,r){this.test=r,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=s?e=>s(Ge(e)):Ge,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return(0,i.vS)(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=(0,i.MK)(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=(0,i.Fh)(e);let s=this.normalize(t);for(let e=0,i=n;;e++){let r=s.charCodeAt(e),o=this.match(r,i,this.bufferPos+this.bufferStart);if(e==s.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==r&&i++}}}match(e,t,n){let i=null;for(let t=0;t<this.matches.length;t+=2){let s=this.matches[t],r=!1;this.query.charCodeAt(s)==e&&(s==this.query.length-1?i={from:this.matches[t+1],to:n}:(this.matches[t]++,r=!0)),r||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(1==this.query.length?i={from:t,to:n}:this.matches.push(1,t)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}"undefined"!=typeof Symbol&&(Ue.prototype[Symbol.iterator]=function(){return this});const Ke={from:-1,to:-1,match:/.*/.exec("")},Je="gm"+(null==/x/.unicode?"":"u");class Ye{constructor(e,t,n,i=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=Ke,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Ze(e,t,n,i,s);this.re=new RegExp(t,Je+((null==n?void 0:n.ignoreCase)?"i":"")),this.test=null==n?void 0:n.test,this.iter=e.iter();let r=e.lineAt(i);this.curLineStart=r.from,this.matchPos=et(e,i),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,i=n+t[0].length;if(this.matchPos=et(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this;e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),e=0}}}}const Xe=new WeakMap;class Qe{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,n){let i=Xe.get(e);if(!i||i.from>=n||i.to<=t){let i=new Qe(t,e.sliceString(t,n));return Xe.set(e,i),i}if(i.from==t&&i.to==n)return i;let{text:s,from:r}=i;return r>t&&(s=e.sliceString(t,r)+s,r=t),i.to<n&&(s+=e.sliceString(i.to,n)),Xe.set(e,new Qe(r,s)),new Qe(t,s.slice(t-r,n-r))}}class Ze{constructor(e,t,n,i,s){this.text=e,this.to=s,this.done=!1,this.value=Ke,this.matchPos=et(e,i),this.re=new RegExp(t,Je+((null==n?void 0:n.ignoreCase)?"i":"")),this.test=null==n?void 0:n.test,this.flat=Qe.get(e,i,this.chunkEnd(i+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=et(this.text,n+(e==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Qe.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function et(e,t){if(t>=e.length)return t;let n,i=e.lineAt(t);for(;t<i.to&&(n=i.text.charCodeAt(t-i.from))>=56320&&n<57344;)t++;return t}"undefined"!=typeof Symbol&&(Ye.prototype[Symbol.iterator]=Ze.prototype[Symbol.iterator]=function(){return this});const tt=i.sj.define({combine:e=>(0,i.QR)(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Et(e),scrollToMatch:e=>s.Lz.scrollIntoView(e)})});class nt{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||function(e){try{return new RegExp(e,Je),!0}catch(e){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,((e,t)=>"n"==t?"\n":"r"==t?"\r":"t"==t?"\t":"\\"))}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new ht(this):new rt(this)}getCursor(e,t=0,n){let s=e.doc?e:i.$t.create({doc:e});return null==n&&(n=s.doc.length),this.regexp?ot(this,s,t,n):st(this,s,t,n)}}class it{constructor(e){this.spec=e}}function st(e,t,n,s){return new Ue(t.doc,e.unquoted,n,s,e.caseSensitive?void 0:e=>e.toLowerCase(),e.wholeWord?(r=t.doc,o=t.charCategorizer(t.selection.main.head),(e,t,n,s)=>((s>e||s+n.length<t)&&(s=Math.max(0,e-2),n=r.sliceString(s,Math.min(r.length,t+2))),!(o(at(n,e-s))==i.Je.Word&&o(lt(n,e-s))==i.Je.Word||o(lt(n,t-s))==i.Je.Word&&o(at(n,t-s))==i.Je.Word))):void 0);var r,o}class rt extends it{constructor(e){super(e)}nextMatch(e,t,n){let i=st(this.spec,e,n,e.doc.length).nextOverlapping();return i.done&&(i=st(this.spec,e,0,t).nextOverlapping()),i.done?null:i.value}prevMatchInRange(e,t,n){for(let i=n;;){let n=Math.max(t,i-1e4-this.spec.unquoted.length),s=st(this.spec,e,n,i),r=null;for(;!s.nextOverlapping().done;)r=s.value;if(r)return r;if(n==t)return null;i-=1e4}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=st(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=st(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}function ot(e,t,n,s){return new Ye(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?(r=t.charCategorizer(t.selection.main.head),(e,t,n)=>!n[0].length||(r(at(n.input,n.index))!=i.Je.Word||r(lt(n.input,n.index))!=i.Je.Word)&&(r(lt(n.input,n.index+n[0].length))!=i.Je.Word||r(at(n.input,n.index+n[0].length))!=i.Je.Word)):void 0},n,s);var r}function at(e,t){return e.slice((0,i.zK)(e,t,!1),t)}function lt(e,t){return e.slice(t,(0,i.zK)(e,t))}class ht extends it{nextMatch(e,t,n){let i=ot(this.spec,e,n,e.doc.length).next();return i.done&&(i=ot(this.spec,e,0,t).next()),i.done?null:i.value}prevMatchInRange(e,t,n){for(let i=1;;i++){let s=Math.max(t,n-1e4*i),r=ot(this.spec,e,s,n),o=null;for(;!r.next().done;)o=r.value;if(o&&(s==t||o.from>s+10))return o;if(s==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,((t,n)=>"$"==n?"$":"&"==n?e.match[0]:"0"!=n&&+n<e.match.length?e.match[n]:t))}matchAll(e,t){let n=ot(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=ot(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}const ct=i.Pe.define(),ut=i.Pe.define(),ft=i.sU.define({create:e=>new dt(At(e).create(),null),update(e,t){for(let n of t.effects)n.is(ct)?e=new dt(n.value.create(),e.panel):n.is(ut)&&(e=new dt(e.query,n.value?Ct:null));return e},provide:e=>s.S7.from(e,(e=>e.panel))});class dt{constructor(e,t){this.query=e,this.panel=t}}const pt=s.NZ.mark({class:"cm-searchMatch"}),mt=s.NZ.mark({class:"cm-searchMatch cm-searchMatch-selected"}),gt=s.Z9.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(ft))}update(e){let t=e.state.field(ft);(t!=e.startState.field(ft)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return s.NZ.none;let{view:n}=this,r=new i.vB;for(let t=0,i=n.visibleRanges,s=i.length;t<s;t++){let{from:o,to:a}=i[t];for(;t<s-1&&a>i[t+1].from-500;)a=i[++t].to;e.highlight(n.state,o,a,((e,t)=>{let i=n.state.selection.ranges.some((n=>n.from==e&&n.to==t));r.add(e,t,i?mt:pt)}))}return r.finish()}},{decorations:e=>e.decorations});function bt(e){return t=>{let n=t.state.field(ft,!1);return n&&n.query.spec.valid?e(t,n):_t(t)}}const yt=bt(((e,{query:t})=>{let{to:n}=e.state.selection.main,s=t.nextMatch(e.state,n,n);if(!s)return!1;let r=i.OF.single(s.from,s.to),o=e.state.facet(tt);return e.dispatch({selection:r,effects:[Rt(e,s),o.scrollToMatch(r.main,e)],userEvent:"select.search"}),Mt(e),!0})),vt=bt(((e,{query:t})=>{let{state:n}=e,{from:s}=n.selection.main,r=t.prevMatch(n,s,s);if(!r)return!1;let o=i.OF.single(r.from,r.to),a=e.state.facet(tt);return e.dispatch({selection:o,effects:[Rt(e,r),a.scrollToMatch(o.main,e)],userEvent:"select.search"}),Mt(e),!0})),xt=bt(((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!(!n||!n.length||(e.dispatch({selection:i.OF.create(n.map((e=>i.OF.range(e.from,e.to)))),userEvent:"select.search.matches"}),0))})),wt=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:s,to:r}=n.main,o=[],a=0;for(let t=new Ue(e.doc,e.sliceDoc(s,r));!t.next().done;){if(o.length>1e3)return!1;t.value.from==s&&(a=o.length),o.push(i.OF.range(t.value.from,t.value.to))}return t(e.update({selection:i.OF.create(o,a),userEvent:"select.search.matches"})),!0},kt=bt(((e,{query:t})=>{let{state:n}=e,{from:r,to:o}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let l,h,c=[],u=[];if(a.from==r&&a.to==o&&(h=n.toText(t.getReplacement(a)),c.push({from:a.from,to:a.to,insert:h}),a=t.nextMatch(n,a.from,a.to),u.push(s.Lz.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+"."))),a){let t=0==c.length||c[0].from>=a.to?0:a.to-a.from-h.length;l=i.OF.single(a.from-t,a.to-t),u.push(Rt(e,a)),u.push(n.facet(tt).scrollToMatch(l.main,e))}return e.dispatch({changes:c,selection:l,effects:u,userEvent:"input.replace"}),!0})),St=bt(((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map((e=>{let{from:n,to:i}=e;return{from:n,to:i,insert:t.getReplacement(e)}}));if(!n.length)return!1;let i=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:s.Lz.announce.of(i),userEvent:"input.replace.all"}),!0}));function Ct(e){return e.state.facet(tt).createPanel(e)}function At(e,t){var n,i,s,r,o;let a=e.selection.main,l=a.empty||a.to>a.from+100?"":e.sliceDoc(a.from,a.to);if(t&&!l)return t;let h=e.facet(tt);return new nt({search:(null!==(n=null==t?void 0:t.literal)&&void 0!==n?n:h.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:null!==(i=null==t?void 0:t.caseSensitive)&&void 0!==i?i:h.caseSensitive,literal:null!==(s=null==t?void 0:t.literal)&&void 0!==s?s:h.literal,regexp:null!==(r=null==t?void 0:t.regexp)&&void 0!==r?r:h.regexp,wholeWord:null!==(o=null==t?void 0:t.wholeWord)&&void 0!==o?o:h.wholeWord})}function Ot(e){let t=(0,s.ld)(e,Ct);return t&&t.dom.querySelector("[main-field]")}function Mt(e){let t=Ot(e);t&&t==e.root.activeElement&&t.select()}const _t=e=>{let t=e.state.field(ft,!1);if(t&&t.panel){let n=Ot(e);if(n&&n!=e.root.activeElement){let i=At(e.state,t.query.spec);i.valid&&e.dispatch({effects:ct.of(i)}),n.focus(),n.select()}}else e.dispatch({effects:[ut.of(!0),t?ct.of(At(e.state,t.query.spec)):i.Pe.appendConfig.of(Lt)]});return!0},Tt=e=>{let t=e.state.field(ft,!1);if(!t||!t.panel)return!1;let n=(0,s.ld)(e,Ct);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:ut.of(!1)}),!0};class Et{constructor(e){this.view=e;let t=this.query=e.state.field(ft).query.spec;function n(e,t,n){return Ve("button",{class:"cm-button",name:e,onclick:t,type:"button"},n)}this.commit=this.commit.bind(this),this.searchField=Ve("input",{value:t.search,placeholder:Nt(e,"Find"),"aria-label":Nt(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ve("input",{value:t.replace,placeholder:Nt(e,"Replace"),"aria-label":Nt(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Ve("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=Ve("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=Ve("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=Ve("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,n("next",(()=>yt(e)),[Nt(e,"next")]),n("prev",(()=>vt(e)),[Nt(e,"previous")]),n("select",(()=>xt(e)),[Nt(e,"all")]),Ve("label",null,[this.caseField,Nt(e,"match case")]),Ve("label",null,[this.reField,Nt(e,"regexp")]),Ve("label",null,[this.wordField,Nt(e,"by word")]),...e.state.readOnly?[]:[Ve("br"),this.replaceField,n("replace",(()=>kt(e)),[Nt(e,"replace")]),n("replaceAll",(()=>St(e)),[Nt(e,"replace all")])],Ve("button",{name:"close",onclick:()=>Tt(e),"aria-label":Nt(e,"close"),type:"button"},["×"])])}commit(){let e=new nt({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:ct.of(e)}))}keydown(e){(0,s.TS)(this.view,e,"search-panel")?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?vt:yt)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),kt(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(ct)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(tt).top}}function Nt(e,t){return e.state.phrase(t)}const Dt=30,Pt=/[\s\.,:;?!]/;function Rt(e,{from:t,to:n}){let i=e.state.doc.lineAt(t),r=e.state.doc.lineAt(n).to,o=Math.max(i.from,t-Dt),a=Math.min(r,n+Dt),l=e.state.sliceDoc(o,a);if(o!=i.from)for(let e=0;e<Dt;e++)if(!Pt.test(l[e+1])&&Pt.test(l[e])){l=l.slice(e);break}if(a!=r)for(let e=l.length-1;e>l.length-Dt;e--)if(!Pt.test(l[e-1])&&Pt.test(l[e])){l=l.slice(0,e);break}return s.Lz.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${i.number}.`)}const jt=s.Lz.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"}}),Lt=[ft,i.Nb.low(gt),jt];class Bt{constructor({baseConfiguration:e,config:t,defaultExtensions:n}={}){this._configChanged=new Me.Signal(this),this._disposed=new Me.Signal(this),this._isDisposed=!1,this._immutables=new Set,this._baseConfig=null!=e?e:{},this._config=null!=t?t:{},this._configurableBuilderMap=new Map(n);const i=Object.keys(this._config).concat(Object.keys(this._baseConfig));this._immutables=new Set([...this._configurableBuilderMap.keys()].filter((e=>!i.includes(e))))}get configChanged(){return this._configChanged}get disposed(){return this._disposed}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,this._disposed.emit(),Me.Signal.clearData(this))}getOption(e){var t;return null!==(t=this._config[e])&&void 0!==t?t:this._baseConfig[e]}hasOption(e){return Object.keys(this._config).includes(e)||Object.keys(this._baseConfig).includes(e)}setOption(e,t){this._config[e]!==t&&(this._config[e]=t,this._configChanged.emit({[e]:t}))}setBaseOptions(e){const t=this._getChangedOptions(e,this._baseConfig);if(t.length>0){this._baseConfig=e;const n=Object.keys(this._config),i=t.filter((e=>!n.includes(e)));i.length>0&&this._configChanged.emit(i.reduce(((e,t)=>(e[t]=this._baseConfig[t],e)),{}))}}setOptions(e){const t=this._getChangedOptions(e,this._config);t.length>0&&(this._config={...e},this._configChanged.emit(t.reduce(((e,t)=>{var n;return e[t]=null!==(n=this._config[t])&&void 0!==n?n:this._baseConfig[t],e}),{})))}reconfigureExtension(e,t,n){const i=this.getEffect(e.state,t,n);i&&e.dispatch({effects:[i]})}reconfigureExtensions(e,t){const n=Object.keys(t).filter((e=>this.has(e))).map((n=>this.getEffect(e.state,n,t[n])));e.dispatch({effects:n.filter((e=>null!==e))})}injectExtension(e,t){e.dispatch({effects:i.Pe.appendConfig.of(t)})}getInitialExtensions(){const e={...this._baseConfig,...this._config},t=[...this._immutables].map((e=>{var t;return null===(t=this.get(e))||void 0===t?void 0:t.instance(void 0)})).filter((e=>e));for(const n of Object.keys(e)){const i=this.get(n);if(i){const s=e[n];t.push(i.instance(s))}}return t}get(e){return this._configurableBuilderMap.get(e)}has(e){return this._configurableBuilderMap.has(e)}getEffect(e,t,n){var i;const s=this.get(t);return null!==(i=null==s?void 0:s.reconfigure(n))&&void 0!==i?i:null}_getChangedOptions(e,t){const n=new Array,i=new Array;for(const[s,r]of Object.entries(e))i.push(s),t[s]!==r&&n.push(s);return n.push(...Object.keys(t).filter((e=>!i.includes(e)))),n}}class It{constructor(){this.configurationBuilder=new Map,this.configurationSchema={},this.defaultOptions={},this.handlers=new Set,this.immutableExtensions=new Set,this._baseConfiguration={}}get baseConfiguration(){return{...this.defaultOptions,...this._baseConfiguration}}set baseConfiguration(e){if(!Ce.JSONExt.deepEqual(e,this._baseConfiguration)){this._baseConfiguration=e;for(const e of this.handlers)e.setBaseOptions(this.baseConfiguration)}}get defaultConfiguration(){return Object.freeze({...this.defaultOptions})}get settingsSchema(){return Object.freeze(Ce.JSONExt.deepCopy(this.configurationSchema))}addExtension(e){var t;if(this.configurationBuilder.has(e.name))throw new Error(`Extension named ${e.name} is already registered.`);this.configurationBuilder.set(e.name,e),void 0!==e.default&&(this.defaultOptions[e.name]=e.default),e.schema&&(this.configurationSchema[e.name]={default:null!==(t=e.default)&&void 0!==t?t:null,...e.schema},this.defaultOptions[e.name]=this.configurationSchema[e.name].default)}createNew(e){const t=new Array;for(const[n,i]of this.configurationBuilder.entries()){const s=i.factory(e);s&&t.push([n,s])}const n=new Bt({baseConfiguration:this.baseConfiguration,config:e.config,defaultExtensions:t});return this.handlers.add(n),n.disposed.connect((()=>{this.handlers.delete(n)})),n}}var Ft;!function(e){class t{constructor(e){this._compartment=new i.xx,this._builder=e}instance(e){return this._compartment.of(this._builder(e))}reconfigure(e){return this._compartment.reconfigure(this._builder(e))}}class n{constructor(e){this._extension=e}instance(){return this._extension}reconfigure(){return null}}function o(e){return new t(e)}function a(e,n=[]){return new t((t=>t?e:n))}function l(e){return new n(e)}e.createConfigurableExtension=o,e.createConditionalExtension=a,e.createImmutableExtension=l,e.getDefaultExtensions=function(e={}){const{themes:t,translator:n}=e,h=(null!=n?n:Te.wK).load("jupyterlab"),c=[Object.freeze({name:"autoClosingBrackets",default:!1,factory:()=>a((0,_e.wm)()),schema:{type:"boolean",title:h.__("Auto Closing Brackets")}}),Object.freeze({name:"codeFolding",default:!1,factory:()=>a((0,r.Lv)()),schema:{type:"boolean",title:h.__("Code Folding")}}),Object.freeze({name:"cursorBlinkRate",default:1200,factory:()=>o((e=>(0,s.VH)({cursorBlinkRate:e}))),schema:{type:"number",title:h.__("Cursor blinking rate"),description:h.__("Half-period in milliseconds used for cursor blinking. The default blink rate is 1200ms. By setting this to zero, blinking can be disabled.")}}),Object.freeze({name:"highlightActiveLine",default:!1,factory:()=>a((0,s.dz)()),schema:{type:"boolean",title:h.__("Highlight the active line")}}),Object.freeze({name:"highlightSpecialCharacters",default:!0,factory:()=>a((0,s.N$)()),schema:{type:"boolean",title:h.__("Highlight special characters")}}),Object.freeze({name:"highlightTrailingWhitespace",default:!1,factory:()=>a((0,s.wu)()),schema:{type:"boolean",title:h.__("Highlight trailing white spaces")}}),Object.freeze({name:"highlightWhitespace",default:!1,factory:()=>a((0,s.Yq)()),schema:{type:"boolean",title:h.__("Highlight white spaces")}}),Object.freeze({name:"indentUnit",default:"4",factory:()=>o((e=>"Tab"==e?r.Xt.of("\t"):r.Xt.of(" ".repeat(parseInt(e,10))))),schema:{type:"string",title:h.__("Indentation unit"),description:h.__("The indentation is a `Tab` or the number of spaces. This defaults to 4 spaces."),enum:["Tab","1","2","4","8"]}}),Object.freeze({name:"keymap",default:[{key:"Mod-Enter",run:Oe.insertBlankLineOnRun},{key:"Enter",run:Oe.completerOrInsertNewLine},{key:"Escape",run:Oe.simplifySelectionAndMaybeSwitchToCommandMode},...Se.filter((e=>!["Mod-Enter","Shift-Mod-k","Mod-/","Alt-A","Escape","Enter"].includes(e.key))),{key:"Tab",run:Oe.indentMoreOrInsertTab,shift:Oe.dedentIfNotLaunchingTooltip}],factory:()=>o((e=>s.w4.of(e)))}),Object.freeze({name:"lineNumbers",default:!0,factory:()=>a((0,s.$K)()),schema:{type:"boolean",title:h.__("Line Numbers")}}),Object.freeze({name:"lineWrap",factory:()=>a(s.Lz.lineWrapping),default:!0,schema:{type:"boolean",title:h.__("Line Wrap")}}),Object.freeze({name:"matchBrackets",default:!0,factory:()=>a([(0,r.SG)(),i.Nb.high(s.w4.of(_e.Bc))]),schema:{type:"boolean",title:h.__("Match Brackets")}}),Object.freeze({name:"rectangularSelection",default:!0,factory:()=>a([(0,s.D4)(),(0,s.HJ)()]),schema:{type:"boolean",title:h.__("Rectangular selection"),description:h.__("Rectangular (block) selection can be created by dragging the mouse pointer while holding the left mouse button and the Alt key. When the Alt key is pressed, a crosshair cursor will appear, indicating that the rectangular selection mode is active.")}}),Object.freeze({name:"readOnly",default:!1,factory:()=>o((e=>[i.$t.readOnly.of(e),e?s.Lz.editorAttributes.of({class:"jp-mod-readOnly"}):[]]))}),Object.freeze({name:"rulers",default:[],factory:()=>o((e=>e.length>0?function(e){return[Fe,$e.of(e),ze]}(e):[])),schema:{type:"array",title:h.__("Rulers"),items:{type:"number",minimum:0}}}),Object.freeze({name:"extendSelection",default:!0,factory:()=>a(s.w4.of([{key:"Mod-Shift-l",run:wt,preventDefault:!0}]))}),Object.freeze({name:"searchWithCM",default:!1,factory:()=>a(s.w4.of([{key:"Mod-f",run:_t,scope:"editor search-panel"},{key:"F3",run:yt,shift:vt,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:yt,shift:vt,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Tt,scope:"editor search-panel"}]))}),Object.freeze({name:"scrollPastEnd",default:!1,factory:e=>e.inline?null:a((0,s.BE)())}),Object.freeze({name:"smartIndent",default:!0,factory:()=>a((0,r.WD)()),schema:{type:"boolean",title:h.__("Smart Indentation")}}),Object.freeze({name:"tabFocusable",default:!0,