rails-playground 0.1.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +67 -0
- data/Rakefile +8 -0
- data/app/assets/javascripts/playground/application.js +17 -0
- data/app/assets/javascripts/playground/controllers/codemirror_controller.js +49 -0
- data/app/assets/javascripts/playground/controllers/hello_controller.js +7 -0
- data/app/assets/javascripts/playground/controllers/playground_controller.js +12 -0
- data/app/assets/javascripts/playground/controllers/search_scripts_controller.js +20 -0
- data/app/assets/javascripts/playground/controllers/select_script_controller.js +8 -0
- data/app/assets/stylesheets/playground/application.scss +28 -0
- data/app/controllers/playground/application_controller.rb +4 -0
- data/app/controllers/playground/consoles_controller.rb +7 -0
- data/app/controllers/playground/scripts_controller.rb +49 -0
- data/app/helpers/playground/application_helper.rb +4 -0
- data/app/helpers/playground/consoles_helper.rb +4 -0
- data/app/helpers/playground/scripts_helper.rb +34 -0
- data/app/jobs/playground/application_job.rb +4 -0
- data/app/mailers/playground/application_mailer.rb +6 -0
- data/app/models/playground/application_record.rb +5 -0
- data/app/views/layouts/playground/application.html.erb +14 -0
- data/app/views/playground/consoles/show.html.erb +20 -0
- data/app/views/playground/scripts/_script.html.erb +5 -0
- data/app/views/playground/scripts/_script_select_box.html.erb +3 -0
- data/app/views/playground/scripts/index.html.erb +1 -0
- data/app/views/playground/scripts/index.turbo_stream.erb +1 -0
- data/app/views/playground/scripts/show.html.erb +1 -0
- data/app/views/playground/scripts/show.turbo_stream.erb +1 -0
- data/config/routes.rb +6 -0
- data/lib/playground/engine.rb +14 -0
- data/lib/playground/templates/index.html.erb +22 -0
- data/lib/playground/version.rb +3 -0
- data/lib/playground.rb +20 -0
- data/lib/tasks/playground_tasks.rake +4 -0
- data/vendor/javascripts/playground/application.js +41 -0
- data/vendor/stylesheets/playground/application.css +57 -0
- data/vendor/stylesheets/playground/application.css.map +1 -0
- metadata +109 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
(()=>{var Bl=Object.defineProperty;var yp=(n,e,t)=>e in n?Bl(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Ze=(n,e)=>()=>(n&&(e=n(n=0)),e);var vp=(n,e)=>{for(var t in e)Bl(n,t,{get:e[t],enumerable:!0})};var Bi=(n,e,t)=>(yp(n,typeof e!="symbol"?e+"":e,t),t);var Tt,Nn=Ze(()=>{Tt={logger:self.console,WebSocket:self.WebSocket}});var H,ci=Ze(()=>{Nn();H={log(...n){this.enabled&&(n.push(Date.now()),Tt.logger.log("[ActionCable]",...n))}}});var Vi,Fn,Vn,Hn,fr=Ze(()=>{ci();Vi=()=>new Date().getTime(),Fn=n=>(Vi()-n)/1e3,Vn=class{constructor(e){this.visibilityDidChange=this.visibilityDidChange.bind(this),this.connection=e,this.reconnectAttempts=0}start(){this.isRunning()||(this.startedAt=Vi(),delete this.stoppedAt,this.startPolling(),addEventListener("visibilitychange",this.visibilityDidChange),H.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`))}stop(){this.isRunning()&&(this.stoppedAt=Vi(),this.stopPolling(),removeEventListener("visibilitychange",this.visibilityDidChange),H.log("ConnectionMonitor stopped"))}isRunning(){return this.startedAt&&!this.stoppedAt}recordPing(){this.pingedAt=Vi()}recordConnect(){this.reconnectAttempts=0,this.recordPing(),delete this.disconnectedAt,H.log("ConnectionMonitor recorded connect")}recordDisconnect(){this.disconnectedAt=Vi(),H.log("ConnectionMonitor recorded disconnect")}startPolling(){this.stopPolling(),this.poll()}stopPolling(){clearTimeout(this.pollTimeout)}poll(){this.pollTimeout=setTimeout(()=>{this.reconnectIfStale(),this.poll()},this.getPollInterval())}getPollInterval(){let{staleThreshold:e,reconnectionBackoffRate:t}=this.constructor,i=Math.pow(1+t,Math.min(this.reconnectAttempts,10)),r=(this.reconnectAttempts===0?1:t)*Math.random();return e*1e3*i*(1+r)}reconnectIfStale(){this.connectionIsStale()&&(H.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${Fn(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`),this.reconnectAttempts++,this.disconnectedRecently()?H.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${Fn(this.disconnectedAt)} s`):(H.log("ConnectionMonitor reopening"),this.connection.reopen()))}get refreshedAt(){return this.pingedAt?this.pingedAt:this.startedAt}connectionIsStale(){return Fn(this.refreshedAt)>this.constructor.staleThreshold}disconnectedRecently(){return this.disconnectedAt&&Fn(this.disconnectedAt)<this.constructor.staleThreshold}visibilityDidChange(){document.visibilityState==="visible"&&setTimeout(()=>{(this.connectionIsStale()||!this.connection.isOpen())&&(H.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`),this.connection.reopen())},200)}};Vn.staleThreshold=6;Vn.reconnectionBackoffRate=.15;Hn=Vn});var Hi,dr=Ze(()=>{Hi={message_types:{welcome:"welcome",disconnect:"disconnect",ping:"ping",confirmation:"confirm_subscription",rejection:"reject_subscription"},disconnect_reasons:{unauthorized:"unauthorized",invalid_request:"invalid_request",server_restart:"server_restart"},default_mount_path:"/cable",protocols:["actioncable-v1-json","actioncable-unsupported"]}});var qi,qn,um,da,Wn,zn,pr=Ze(()=>{Nn();fr();dr();ci();({message_types:qi,protocols:qn}=Hi),um=qn.slice(0,qn.length-1),da=[].indexOf,Wn=class{constructor(e){this.open=this.open.bind(this),this.consumer=e,this.subscriptions=this.consumer.subscriptions,this.monitor=new Hn(this),this.disconnected=!0}send(e){return this.isOpen()?(this.webSocket.send(JSON.stringify(e)),!0):!1}open(){return this.isActive()?(H.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`),!1):(H.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${qn}`),this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new Tt.WebSocket(this.consumer.url,qn),this.installEventHandlers(),this.monitor.start(),!0)}close({allowReconnect:e}={allowReconnect:!0}){if(e||this.monitor.stop(),this.isActive())return this.webSocket.close()}reopen(){if(H.log(`Reopening WebSocket, current state is ${this.getState()}`),this.isActive())try{return this.close()}catch(e){H.log("Failed to reopen WebSocket",e)}finally{H.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`),setTimeout(this.open,this.constructor.reopenDelay)}else return this.open()}getProtocol(){if(this.webSocket)return this.webSocket.protocol}isOpen(){return this.isState("open")}isActive(){return this.isState("open","connecting")}isProtocolSupported(){return da.call(um,this.getProtocol())>=0}isState(...e){return da.call(e,this.getState())>=0}getState(){if(this.webSocket){for(let e in Tt.WebSocket)if(Tt.WebSocket[e]===this.webSocket.readyState)return e.toLowerCase()}return null}installEventHandlers(){for(let e in this.events){let t=this.events[e].bind(this);this.webSocket[`on${e}`]=t}}uninstallEventHandlers(){for(let e in this.events)this.webSocket[`on${e}`]=function(){}}};Wn.reopenDelay=500;Wn.prototype.events={message(n){if(!this.isProtocolSupported())return;let{identifier:e,message:t,reason:i,reconnect:s,type:r}=JSON.parse(n.data);switch(r){case qi.welcome:return this.monitor.recordConnect(),this.subscriptions.reload();case qi.disconnect:return H.log(`Disconnecting. Reason: ${i}`),this.close({allowReconnect:s});case qi.ping:return this.monitor.recordPing();case qi.confirmation:return this.subscriptions.confirmSubscription(e),this.subscriptions.notify(e,"connected");case qi.rejection:return this.subscriptions.reject(e);default:return this.subscriptions.notify(e,"received",t)}},open(){if(H.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`),this.disconnected=!1,!this.isProtocolSupported())return H.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close(n){if(H.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error(){H.log("WebSocket onerror event")}};zn=Wn});var fm,ui,mr=Ze(()=>{fm=function(n,e){if(e!=null)for(let t in e){let i=e[t];n[t]=i}return n},ui=class{constructor(e,t={},i){this.consumer=e,this.identifier=JSON.stringify(t),fm(this,i)}perform(e,t={}){return t.action=e,this.send(t)}send(e){return this.consumer.send({command:"message",identifier:this.identifier,data:JSON.stringify(e)})}unsubscribe(){return this.consumer.subscriptions.remove(this)}}});var pa,$n,gr=Ze(()=>{ci();pa=class{constructor(e){this.subscriptions=e,this.pendingSubscriptions=[]}guarantee(e){this.pendingSubscriptions.indexOf(e)==-1?(H.log(`SubscriptionGuarantor guaranteeing ${e.identifier}`),this.pendingSubscriptions.push(e)):H.log(`SubscriptionGuarantor already guaranteeing ${e.identifier}`),this.startGuaranteeing()}forget(e){H.log(`SubscriptionGuarantor forgetting ${e.identifier}`),this.pendingSubscriptions=this.pendingSubscriptions.filter(t=>t!==e)}startGuaranteeing(){this.stopGuaranteeing(),this.retrySubscribing()}stopGuaranteeing(){clearTimeout(this.retryTimeout)}retrySubscribing(){this.retryTimeout=setTimeout(()=>{this.subscriptions&&typeof this.subscriptions.subscribe=="function"&&this.pendingSubscriptions.map(e=>{H.log(`SubscriptionGuarantor resubscribing ${e.identifier}`),this.subscriptions.subscribe(e)})},500)}},$n=pa});var fi,br=Ze(()=>{mr();gr();ci();fi=class{constructor(e){this.consumer=e,this.guarantor=new $n(this),this.subscriptions=[]}create(e,t){let i=e,s=typeof i=="object"?i:{channel:i},r=new ui(this.consumer,s,t);return this.add(r)}add(e){return this.subscriptions.push(e),this.consumer.ensureActiveConnection(),this.notify(e,"initialized"),this.subscribe(e),e}remove(e){return this.forget(e),this.findAll(e.identifier).length||this.sendCommand(e,"unsubscribe"),e}reject(e){return this.findAll(e).map(t=>(this.forget(t),this.notify(t,"rejected"),t))}forget(e){return this.guarantor.forget(e),this.subscriptions=this.subscriptions.filter(t=>t!==e),e}findAll(e){return this.subscriptions.filter(t=>t.identifier===e)}reload(){return this.subscriptions.map(e=>this.subscribe(e))}notifyAll(e,...t){return this.subscriptions.map(i=>this.notify(i,e,...t))}notify(e,t,...i){let s;return typeof e=="string"?s=this.findAll(e):s=[e],s.map(r=>typeof r[t]=="function"?r[t](...i):void 0)}subscribe(e){this.sendCommand(e,"subscribe")&&this.guarantor.guarantee(e)}confirmSubscription(e){H.log(`Subscription confirmed ${e}`),this.findAll(e).map(t=>this.guarantor.forget(t))}sendCommand(e,t){let{identifier:i}=e;return this.consumer.send({command:t,identifier:i})}}});function yr(n){if(typeof n=="function"&&(n=n()),n&&!/^wss?:/i.test(n)){let e=document.createElement("a");return e.href=n,e.href=e.href,e.protocol=e.protocol.replace("http","ws"),e.href}else return n}var Wi,ma=Ze(()=>{pr();br();Wi=class{constructor(e){this._url=e,this.subscriptions=new fi(this),this.connection=new zn(this)}get url(){return yr(this._url)}send(e){return this.connection.send(e)}connect(){return this.connection.open()}disconnect(){return this.connection.close({allowReconnect:!1})}ensureActiveConnection(){if(!this.connection.isActive())return this.connection.open()}}});var ba={};vp(ba,{Connection:()=>zn,ConnectionMonitor:()=>Hn,Consumer:()=>Wi,INTERNAL:()=>Hi,Subscription:()=>ui,SubscriptionGuarantor:()=>$n,Subscriptions:()=>fi,adapters:()=>Tt,createConsumer:()=>dm,createWebSocketURL:()=>yr,getConfig:()=>ga,logger:()=>H});function dm(n=ga("url")||Hi.default_mount_path){return new Wi(n)}function ga(n){let e=document.head.querySelector(`meta[name='action-cable-${n}']`);if(e)return e.getAttribute("content")}var ya=Ze(()=>{pr();fr();ma();dr();mr();br();gr();Nn();ci()});(function(){if(window.Reflect===void 0||window.customElements===void 0||window.customElements.polyfillWrapFlushCallback)return;let n=HTMLElement,e={HTMLElement:function(){return Reflect.construct(n,[],this.constructor)}};window.HTMLElement=e.HTMLElement,HTMLElement.prototype=n.prototype,HTMLElement.prototype.constructor=HTMLElement,Object.setPrototypeOf(HTMLElement,n)})();(function(n){if(typeof n.requestSubmit=="function")return;n.requestSubmit=function(i){i?(e(i,this),i.click()):(i=document.createElement("input"),i.type="submit",i.hidden=!0,this.appendChild(i),i.click(),this.removeChild(i))};function e(i,s){i instanceof HTMLElement||t(TypeError,"parameter 1 is not of type 'HTMLElement'"),i.type=="submit"||t(TypeError,"The specified element is not a submit button"),i.form==s||t(DOMException,"The specified element is not owned by this form element","NotFoundError")}function t(i,s,r){throw new i("Failed to execute 'requestSubmit' on 'HTMLFormElement': "+s+".",r)}})(HTMLFormElement.prototype);var ql=new WeakMap;function wp(n){let e=n instanceof Element?n:n instanceof Node?n.parentElement:null,t=e?e.closest("input, button"):null;return t?.type=="submit"?t:null}function Sp(n){let e=wp(n.target);e&&e.form&&ql.set(e.form,e)}(function(){if("submitter"in Event.prototype)return;let n;if("SubmitEvent"in window&&/Apple Computer/.test(navigator.vendor))n=window.SubmitEvent.prototype;else{if("SubmitEvent"in window)return;n=window.Event.prototype}addEventListener("click",Sp,!0),Object.defineProperty(n,"submitter",{get(){if(this.type=="submit"&&this.target instanceof HTMLFormElement)return ql.get(this.target)}})})();var Et;(function(n){n.eager="eager",n.lazy="lazy"})(Et||(Et={}));var dt=class extends HTMLElement{constructor(){super();this.loaded=Promise.resolve(),this.delegate=new dt.delegateConstructor(this)}static get observedAttributes(){return["disabled","loading","src"]}connectedCallback(){this.delegate.connect()}disconnectedCallback(){this.delegate.disconnect()}reload(){let{src:e}=this;this.src=null,this.src=e}attributeChangedCallback(e){e=="loading"?this.delegate.loadingStyleChanged():e=="src"?this.delegate.sourceURLChanged():this.delegate.disabledChanged()}get src(){return this.getAttribute("src")}set src(e){e?this.setAttribute("src",e):this.removeAttribute("src")}get loading(){return xp(this.getAttribute("loading")||"")}set loading(e){e?this.setAttribute("loading",e):this.removeAttribute("loading")}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get autoscroll(){return this.hasAttribute("autoscroll")}set autoscroll(e){e?this.setAttribute("autoscroll",""):this.removeAttribute("autoscroll")}get complete(){return!this.delegate.isLoading}get isActive(){return this.ownerDocument===document&&!this.isPreview}get isPreview(){var e,t;return(t=(e=this.ownerDocument)===null||e===void 0?void 0:e.documentElement)===null||t===void 0?void 0:t.hasAttribute("data-turbo-preview")}};function xp(n){switch(n.toLowerCase()){case"lazy":return Et.lazy;default:return Et.eager}}function we(n){return new URL(n.toString(),document.baseURI)}function Wt(n){let e;if(n.hash)return n.hash.slice(1);if(e=n.href.match(/#(.*)$/))return e[1]}function nr(n,e){let t=e?.getAttribute("formaction")||n.getAttribute("action")||n.action;return we(t)}function kp(n){return(Tp(n).match(/\.[^.]*$/)||[])[0]||""}function Cp(n){return!!kp(n).match(/^(?:|\.(?:htm|html|xhtml))$/)}function Ap(n,e){let t=Lp(e);return n.href===we(t).href||n.href.startsWith(t)}function Ii(n,e){return Ap(n,e)&&Cp(n)}function er(n){let e=Wt(n);return e!=null?n.href.slice(0,-(e.length+1)):n.href}function Pn(n){return er(n)}function Ep(n,e){return we(n).href==we(e).href}function Mp(n){return n.pathname.split("/").slice(1)}function Tp(n){return Mp(n).slice(-1)[0]}function Lp(n){return Rp(n.origin+n.pathname)}function Rp(n){return n.endsWith("/")?n:n+"/"}var sr=class{constructor(e){this.response=e}get succeeded(){return this.response.ok}get failed(){return!this.succeeded}get clientError(){return this.statusCode>=400&&this.statusCode<=499}get serverError(){return this.statusCode>=500&&this.statusCode<=599}get redirected(){return this.response.redirected}get location(){return we(this.response.url)}get isHTML(){return this.contentType&&this.contentType.match(/^(?:text\/([^\s;,]+\b)?html|application\/xhtml\+xml)\b/)}get statusCode(){return this.response.status}get contentType(){return this.header("Content-Type")}get responseText(){return this.response.clone().text()}get responseHTML(){return this.isHTML?this.response.clone().text():Promise.resolve(void 0)}header(e){return this.response.headers.get(e)}};function Ee(n,{target:e,cancelable:t,detail:i}={}){let s=new CustomEvent(n,{cancelable:t,bubbles:!0,detail:i});return e&&e.isConnected?e.dispatchEvent(s):document.documentElement.dispatchEvent(s),s}function On(){return new Promise(n=>requestAnimationFrame(()=>n()))}function Pp(){return new Promise(n=>setTimeout(()=>n(),0))}function Op(){return Promise.resolve()}function Wl(n=""){return new DOMParser().parseFromString(n,"text/html")}function zl(n,...e){let t=Dp(n,e).replace(/^\n/,"").split(`
|
2
|
+
`),i=t[0].match(/^\s+/),s=i?i[0].length:0;return t.map(r=>r.slice(s)).join(`
|
3
|
+
`)}function Dp(n,e){return n.reduce((t,i,s)=>{let r=e[s]==null?"":e[s];return t+i+r},"")}function Ni(){return Array.apply(null,{length:36}).map((n,e)=>e==8||e==13||e==18||e==23?"-":e==14?"4":e==19?(Math.floor(Math.random()*4)+8).toString(16):Math.floor(Math.random()*15).toString(16)).join("")}function Dn(n,...e){for(let t of e.map(i=>i?.getAttribute(n)))if(typeof t=="string")return t;return null}function tr(...n){for(let e of n)e.localName=="turbo-frame"&&e.setAttribute("busy",""),e.setAttribute("aria-busy","true")}function ir(...n){for(let e of n)e.localName=="turbo-frame"&&e.removeAttribute("busy"),e.removeAttribute("aria-busy")}var ye;(function(n){n[n.get=0]="get",n[n.post=1]="post",n[n.put=2]="put",n[n.patch=3]="patch",n[n.delete=4]="delete"})(ye||(ye={}));function Bp(n){switch(n.toLowerCase()){case"get":return ye.get;case"post":return ye.post;case"put":return ye.put;case"patch":return ye.patch;case"delete":return ye.delete}}var Bn=class{constructor(e,t,i,s=new URLSearchParams,r=null){this.abortController=new AbortController,this.resolveRequestPromise=o=>{},this.delegate=e,this.method=t,this.headers=this.defaultHeaders,this.body=s,this.url=i,this.target=r}get location(){return this.url}get params(){return this.url.searchParams}get entries(){return this.body?Array.from(this.body.entries()):[]}cancel(){this.abortController.abort()}async perform(){var e,t;let{fetchOptions:i}=this;(t=(e=this.delegate).prepareHeadersForRequest)===null||t===void 0||t.call(e,this.headers,this),await this.allowRequestToBeIntercepted(i);try{this.delegate.requestStarted(this);let s=await fetch(this.url.href,i);return await this.receive(s)}catch(s){if(s.name!=="AbortError")throw this.delegate.requestErrored(this,s),s}finally{this.delegate.requestFinished(this)}}async receive(e){let t=new sr(e);return Ee("turbo:before-fetch-response",{cancelable:!0,detail:{fetchResponse:t},target:this.target}).defaultPrevented?this.delegate.requestPreventedHandlingResponse(this,t):t.succeeded?this.delegate.requestSucceededWithResponse(this,t):this.delegate.requestFailedWithResponse(this,t),t}get fetchOptions(){var e;return{method:ye[this.method].toUpperCase(),credentials:"same-origin",headers:this.headers,redirect:"follow",body:this.isIdempotent?null:this.body,signal:this.abortSignal,referrer:(e=this.delegate.referrer)===null||e===void 0?void 0:e.href}}get defaultHeaders(){return{Accept:"text/html, application/xhtml+xml"}}get isIdempotent(){return this.method==ye.get}get abortSignal(){return this.abortController.signal}async allowRequestToBeIntercepted(e){let t=new Promise(s=>this.resolveRequestPromise=s);Ee("turbo:before-fetch-request",{cancelable:!0,detail:{fetchOptions:e,url:this.url,resume:this.resolveRequestPromise},target:this.target}).defaultPrevented&&await t}},$l=class{constructor(e,t){this.started=!1,this.intersect=i=>{let s=i.slice(-1)[0];s?.isIntersecting&&this.delegate.elementAppearedInViewport(this.element)},this.delegate=e,this.element=t,this.intersectionObserver=new IntersectionObserver(this.intersect)}start(){this.started||(this.started=!0,this.intersectionObserver.observe(this.element))}stop(){this.started&&(this.started=!1,this.intersectionObserver.unobserve(this.element))}},ai=class{constructor(e){this.templateElement=document.createElement("template"),this.templateElement.innerHTML=e}static wrap(e){return typeof e=="string"?new this(e):e}get fragment(){let e=document.createDocumentFragment();for(let t of this.foreignElements)e.appendChild(document.importNode(t,!0));return e}get foreignElements(){return this.templateChildren.reduce((e,t)=>t.tagName.toLowerCase()=="turbo-stream"?[...e,t]:e,[])}get templateChildren(){return Array.from(this.templateElement.content.children)}};ai.contentType="text/vnd.turbo-stream.html";var Ct;(function(n){n[n.initialized=0]="initialized",n[n.requesting=1]="requesting",n[n.waiting=2]="waiting",n[n.receiving=3]="receiving",n[n.stopping=4]="stopping",n[n.stopped=5]="stopped"})(Ct||(Ct={}));var At;(function(n){n.urlEncoded="application/x-www-form-urlencoded",n.multipart="multipart/form-data",n.plain="text/plain"})(At||(At={}));function Ip(n){switch(n.toLowerCase()){case At.multipart:return At.multipart;case At.plain:return At.plain;default:return At.urlEncoded}}var hi=class{constructor(e,t,i,s=!1){this.state=Ct.initialized,this.delegate=e,this.formElement=t,this.submitter=i,this.formData=Np(t,i),this.location=we(this.action),this.method==ye.get&&Hp(this.location,[...this.body.entries()]),this.fetchRequest=new Bn(this,this.method,this.location,this.body,this.formElement),this.mustRedirect=s}static confirmMethod(e,t){return confirm(e)}get method(){var e;let t=((e=this.submitter)===null||e===void 0?void 0:e.getAttribute("formmethod"))||this.formElement.getAttribute("method")||"";return Bp(t.toLowerCase())||ye.get}get action(){var e;let t=typeof this.formElement.action=="string"?this.formElement.action:null;return((e=this.submitter)===null||e===void 0?void 0:e.getAttribute("formaction"))||this.formElement.getAttribute("action")||t||""}get body(){return this.enctype==At.urlEncoded||this.method==ye.get?new URLSearchParams(this.stringFormData):this.formData}get enctype(){var e;return Ip(((e=this.submitter)===null||e===void 0?void 0:e.getAttribute("formenctype"))||this.formElement.enctype)}get isIdempotent(){return this.fetchRequest.isIdempotent}get stringFormData(){return[...this.formData].reduce((e,[t,i])=>e.concat(typeof i=="string"?[[t,i]]:[]),[])}get confirmationMessage(){return this.formElement.getAttribute("data-turbo-confirm")}get needsConfirmation(){return this.confirmationMessage!==null}async start(){let{initialized:e,requesting:t}=Ct;if(!(this.needsConfirmation&&!hi.confirmMethod(this.confirmationMessage,this.formElement))&&this.state==e)return this.state=t,this.fetchRequest.perform()}stop(){let{stopping:e,stopped:t}=Ct;if(this.state!=e&&this.state!=t)return this.state=e,this.fetchRequest.cancel(),!0}prepareHeadersForRequest(e,t){if(!t.isIdempotent){let i=Fp(Il("csrf-param"))||Il("csrf-token");i&&(e["X-CSRF-Token"]=i),e.Accept=[ai.contentType,e.Accept].join(", ")}}requestStarted(e){var t;this.state=Ct.waiting,(t=this.submitter)===null||t===void 0||t.setAttribute("disabled",""),Ee("turbo:submit-start",{target:this.formElement,detail:{formSubmission:this}}),this.delegate.formSubmissionStarted(this)}requestPreventedHandlingResponse(e,t){this.result={success:t.succeeded,fetchResponse:t}}requestSucceededWithResponse(e,t){if(t.clientError||t.serverError)this.delegate.formSubmissionFailedWithResponse(this,t);else if(this.requestMustRedirect(e)&&Vp(t)){let i=new Error("Form responses must redirect to another location");this.delegate.formSubmissionErrored(this,i)}else this.state=Ct.receiving,this.result={success:!0,fetchResponse:t},this.delegate.formSubmissionSucceededWithResponse(this,t)}requestFailedWithResponse(e,t){this.result={success:!1,fetchResponse:t},this.delegate.formSubmissionFailedWithResponse(this,t)}requestErrored(e,t){this.result={success:!1,error:t},this.delegate.formSubmissionErrored(this,t)}requestFinished(e){var t;this.state=Ct.stopped,(t=this.submitter)===null||t===void 0||t.removeAttribute("disabled"),Ee("turbo:submit-end",{target:this.formElement,detail:Object.assign({formSubmission:this},this.result)}),this.delegate.formSubmissionFinished(this)}requestMustRedirect(e){return!e.isIdempotent&&this.mustRedirect}};function Np(n,e){let t=new FormData(n),i=e?.getAttribute("name"),s=e?.getAttribute("value");return i&&s!=null&&t.get(i)!=s&&t.append(i,s),t}function Fp(n){if(n!=null){let t=(document.cookie?document.cookie.split("; "):[]).find(i=>i.startsWith(n));if(t){let i=t.split("=").slice(1).join("=");return i?decodeURIComponent(i):void 0}}}function Il(n){let e=document.querySelector(`meta[name="${n}"]`);return e&&e.content}function Vp(n){return n.statusCode==200&&!n.redirected}function Hp(n,e){let t=new URLSearchParams;for(let[i,s]of e)s instanceof File||t.append(i,s);return n.search=t.toString(),n}var Fi=class{constructor(e){this.element=e}get children(){return[...this.element.children]}hasAnchor(e){return this.getElementForAnchor(e)!=null}getElementForAnchor(e){return e?this.element.querySelector(`[id='${e}'], a[name='${e}']`):null}get isConnected(){return this.element.isConnected}get firstAutofocusableElement(){return this.element.querySelector("[autofocus]")}get permanentElements(){return[...this.element.querySelectorAll("[id][data-turbo-permanent]")]}getPermanentElementById(e){return this.element.querySelector(`#${e}[data-turbo-permanent]`)}getPermanentElementMapForSnapshot(e){let t={};for(let i of this.permanentElements){let{id:s}=i,r=e.getPermanentElementById(s);r&&(t[s]=[i,r])}return t}},rr=class{constructor(e,t){this.submitBubbled=i=>{let s=i.target;if(!i.defaultPrevented&&s instanceof HTMLFormElement&&s.closest("turbo-frame, html")==this.element){let r=i.submitter||void 0;(r?.getAttribute("formmethod")||s.method)!="dialog"&&this.delegate.shouldInterceptFormSubmission(s,r)&&(i.preventDefault(),i.stopImmediatePropagation(),this.delegate.formSubmissionIntercepted(s,r))}},this.delegate=e,this.element=t}start(){this.element.addEventListener("submit",this.submitBubbled)}stop(){this.element.removeEventListener("submit",this.submitBubbled)}},or=class{constructor(e,t){this.resolveRenderPromise=i=>{},this.resolveInterceptionPromise=i=>{},this.delegate=e,this.element=t}scrollToAnchor(e){let t=this.snapshot.getElementForAnchor(e);t?(this.scrollToElement(t),this.focusElement(t)):this.scrollToPosition({x:0,y:0})}scrollToAnchorFromLocation(e){this.scrollToAnchor(Wt(e))}scrollToElement(e){e.scrollIntoView()}focusElement(e){e instanceof HTMLElement&&(e.hasAttribute("tabindex")?e.focus():(e.setAttribute("tabindex","-1"),e.focus(),e.removeAttribute("tabindex")))}scrollToPosition({x:e,y:t}){this.scrollRoot.scrollTo(e,t)}scrollToTop(){this.scrollToPosition({x:0,y:0})}get scrollRoot(){return window}async render(e){let{isPreview:t,shouldRender:i,newSnapshot:s}=e;if(i)try{this.renderPromise=new Promise(l=>this.resolveRenderPromise=l),this.renderer=e,this.prepareToRenderSnapshot(e);let r=new Promise(l=>this.resolveInterceptionPromise=l);this.delegate.allowsImmediateRender(s,this.resolveInterceptionPromise)||await r,await this.renderSnapshot(e),this.delegate.viewRenderedSnapshot(s,t),this.finishRenderingSnapshot(e)}finally{delete this.renderer,this.resolveRenderPromise(void 0),delete this.renderPromise}else this.invalidate()}invalidate(){this.delegate.viewInvalidated()}prepareToRenderSnapshot(e){this.markAsPreview(e.isPreview),e.prepareToRender()}markAsPreview(e){e?this.element.setAttribute("data-turbo-preview",""):this.element.removeAttribute("data-turbo-preview")}async renderSnapshot(e){await e.render()}finishRenderingSnapshot(e){e.finishRendering()}},jl=class extends or{invalidate(){this.element.innerHTML=""}get snapshot(){return new Fi(this.element)}},lr=class{constructor(e,t){this.clickBubbled=i=>{this.respondsToEventTarget(i.target)?this.clickEvent=i:delete this.clickEvent},this.linkClicked=i=>{this.clickEvent&&this.respondsToEventTarget(i.target)&&i.target instanceof Element&&this.delegate.shouldInterceptLinkClick(i.target,i.detail.url)&&(this.clickEvent.preventDefault(),i.preventDefault(),this.delegate.linkClickIntercepted(i.target,i.detail.url)),delete this.clickEvent},this.willVisit=()=>{delete this.clickEvent},this.delegate=e,this.element=t}start(){this.element.addEventListener("click",this.clickBubbled),document.addEventListener("turbo:click",this.linkClicked),document.addEventListener("turbo:before-visit",this.willVisit)}stop(){this.element.removeEventListener("click",this.clickBubbled),document.removeEventListener("turbo:click",this.linkClicked),document.removeEventListener("turbo:before-visit",this.willVisit)}respondsToEventTarget(e){let t=e instanceof Element?e:e instanceof Node?e.parentElement:null;return t&&t.closest("turbo-frame, html")==this.element}},Ul=class{constructor(e){this.permanentElementMap=e}static preservingPermanentElements(e,t){let i=new this(e);i.enter(),t(),i.leave()}enter(){for(let e in this.permanentElementMap){let[,t]=this.permanentElementMap[e];this.replaceNewPermanentElementWithPlaceholder(t)}}leave(){for(let e in this.permanentElementMap){let[t]=this.permanentElementMap[e];this.replaceCurrentPermanentElementWithClone(t),this.replacePlaceholderWithPermanentElement(t)}}replaceNewPermanentElementWithPlaceholder(e){let t=qp(e);e.replaceWith(t)}replaceCurrentPermanentElementWithClone(e){let t=e.cloneNode(!0);e.replaceWith(t)}replacePlaceholderWithPermanentElement(e){let t=this.getPlaceholderById(e.id);t?.replaceWith(e)}getPlaceholderById(e){return this.placeholders.find(t=>t.content==e)}get placeholders(){return[...document.querySelectorAll("meta[name=turbo-permanent-placeholder][content]")]}};function qp(n){let e=document.createElement("meta");return e.setAttribute("name","turbo-permanent-placeholder"),e.setAttribute("content",n.id),e}var In=class{constructor(e,t,i,s=!0){this.currentSnapshot=e,this.newSnapshot=t,this.isPreview=i,this.willRender=s,this.promise=new Promise((r,o)=>this.resolvingFunctions={resolve:r,reject:o})}get shouldRender(){return!0}prepareToRender(){}finishRendering(){this.resolvingFunctions&&(this.resolvingFunctions.resolve(),delete this.resolvingFunctions)}createScriptElement(e){if(e.getAttribute("data-turbo-eval")=="false")return e;{let t=document.createElement("script");return this.cspNonce&&(t.nonce=this.cspNonce),t.textContent=e.textContent,t.async=!1,Wp(t,e),t}}preservingPermanentElements(e){Ul.preservingPermanentElements(this.permanentElementMap,e)}focusFirstAutofocusableElement(){let e=this.connectedSnapshot.firstAutofocusableElement;zp(e)&&e.focus()}get connectedSnapshot(){return this.newSnapshot.isConnected?this.newSnapshot:this.currentSnapshot}get currentElement(){return this.currentSnapshot.element}get newElement(){return this.newSnapshot.element}get permanentElementMap(){return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot)}get cspNonce(){var e;return(e=document.head.querySelector('meta[name="csp-nonce"]'))===null||e===void 0?void 0:e.getAttribute("content")}};function Wp(n,e){for(let{name:t,value:i}of[...e.attributes])n.setAttribute(t,i)}function zp(n){return n&&typeof n.focus=="function"}var Kl=class extends In{get shouldRender(){return!0}async render(){await On(),this.preservingPermanentElements(()=>{this.loadFrameElement()}),this.scrollFrameIntoView(),await On(),this.focusFirstAutofocusableElement(),await On(),this.activateScriptElements()}loadFrameElement(){var e;let t=document.createRange();t.selectNodeContents(this.currentElement),t.deleteContents();let i=this.newElement,s=(e=i.ownerDocument)===null||e===void 0?void 0:e.createRange();s&&(s.selectNodeContents(i),this.currentElement.appendChild(s.extractContents()))}scrollFrameIntoView(){if(this.currentElement.autoscroll||this.newElement.autoscroll){let e=this.currentElement.firstElementChild,t=$p(this.currentElement.getAttribute("data-autoscroll-block"),"end");if(e)return e.scrollIntoView({block:t}),!0}return!1}activateScriptElements(){for(let e of this.newScriptElements){let t=this.createScriptElement(e);e.replaceWith(t)}}get newScriptElements(){return this.currentElement.querySelectorAll("script")}};function $p(n,e){return n=="end"||n=="start"||n=="center"||n=="nearest"?n:e}var et=class{constructor(){this.hiding=!1,this.value=0,this.visible=!1,this.trickle=()=>{this.setValue(this.value+Math.random()/100)},this.stylesheetElement=this.createStylesheetElement(),this.progressElement=this.createProgressElement(),this.installStylesheetElement(),this.setValue(0)}static get defaultCSS(){return zl`
|
4
|
+
.turbo-progress-bar {
|
5
|
+
position: fixed;
|
6
|
+
display: block;
|
7
|
+
top: 0;
|
8
|
+
left: 0;
|
9
|
+
height: 3px;
|
10
|
+
background: #0076ff;
|
11
|
+
z-index: 9999;
|
12
|
+
transition:
|
13
|
+
width ${et.animationDuration}ms ease-out,
|
14
|
+
opacity ${et.animationDuration/2}ms ${et.animationDuration/2}ms ease-in;
|
15
|
+
transform: translate3d(0, 0, 0);
|
16
|
+
}
|
17
|
+
`}show(){this.visible||(this.visible=!0,this.installProgressElement(),this.startTrickling())}hide(){this.visible&&!this.hiding&&(this.hiding=!0,this.fadeProgressElement(()=>{this.uninstallProgressElement(),this.stopTrickling(),this.visible=!1,this.hiding=!1}))}setValue(e){this.value=e,this.refresh()}installStylesheetElement(){document.head.insertBefore(this.stylesheetElement,document.head.firstChild)}installProgressElement(){this.progressElement.style.width="0",this.progressElement.style.opacity="1",document.documentElement.insertBefore(this.progressElement,document.body),this.refresh()}fadeProgressElement(e){this.progressElement.style.opacity="0",setTimeout(e,et.animationDuration*1.5)}uninstallProgressElement(){this.progressElement.parentNode&&document.documentElement.removeChild(this.progressElement)}startTrickling(){this.trickleInterval||(this.trickleInterval=window.setInterval(this.trickle,et.animationDuration))}stopTrickling(){window.clearInterval(this.trickleInterval),delete this.trickleInterval}refresh(){requestAnimationFrame(()=>{this.progressElement.style.width=`${10+this.value*90}%`})}createStylesheetElement(){let e=document.createElement("style");return e.type="text/css",e.textContent=et.defaultCSS,e}createProgressElement(){let e=document.createElement("div");return e.className="turbo-progress-bar",e}};et.animationDuration=300;var _l=class extends Fi{constructor(){super(...arguments);this.detailsByOuterHTML=this.children.filter(e=>!_p(e)).map(e=>Yp(e)).reduce((e,t)=>{let{outerHTML:i}=t,s=i in e?e[i]:{type:jp(t),tracked:Up(t),elements:[]};return Object.assign(Object.assign({},e),{[i]:Object.assign(Object.assign({},s),{elements:[...s.elements,t]})})},{})}get trackedElementSignature(){return Object.keys(this.detailsByOuterHTML).filter(e=>this.detailsByOuterHTML[e].tracked).join("")}getScriptElementsNotInSnapshot(e){return this.getElementsMatchingTypeNotInSnapshot("script",e)}getStylesheetElementsNotInSnapshot(e){return this.getElementsMatchingTypeNotInSnapshot("stylesheet",e)}getElementsMatchingTypeNotInSnapshot(e,t){return Object.keys(this.detailsByOuterHTML).filter(i=>!(i in t.detailsByOuterHTML)).map(i=>this.detailsByOuterHTML[i]).filter(({type:i})=>i==e).map(({elements:[i]})=>i)}get provisionalElements(){return Object.keys(this.detailsByOuterHTML).reduce((e,t)=>{let{type:i,tracked:s,elements:r}=this.detailsByOuterHTML[t];return i==null&&!s?[...e,...r]:r.length>1?[...e,...r.slice(1)]:e},[])}getMetaValue(e){let t=this.findMetaElementByName(e);return t?t.getAttribute("content"):null}findMetaElementByName(e){return Object.keys(this.detailsByOuterHTML).reduce((t,i)=>{let{elements:[s]}=this.detailsByOuterHTML[i];return Jp(s,e)?s:t},void 0)}};function jp(n){if(Kp(n))return"script";if(Gp(n))return"stylesheet"}function Up(n){return n.getAttribute("data-turbo-track")=="reload"}function Kp(n){return n.tagName.toLowerCase()=="script"}function _p(n){return n.tagName.toLowerCase()=="noscript"}function Gp(n){let e=n.tagName.toLowerCase();return e=="style"||e=="link"&&n.getAttribute("rel")=="stylesheet"}function Jp(n,e){return n.tagName.toLowerCase()=="meta"&&n.getAttribute("name")==e}function Yp(n){return n.hasAttribute("nonce")&&n.setAttribute("nonce",""),n}var ft=class extends Fi{constructor(e,t){super(e);this.headSnapshot=t}static fromHTMLString(e=""){return this.fromDocument(Wl(e))}static fromElement(e){return this.fromDocument(e.ownerDocument)}static fromDocument({head:e,body:t}){return new this(t,new _l(e))}clone(){return new ft(this.element.cloneNode(!0),this.headSnapshot)}get headElement(){return this.headSnapshot.element}get rootLocation(){var e;let t=(e=this.getSetting("root"))!==null&&e!==void 0?e:"/";return we(t)}get cacheControlValue(){return this.getSetting("cache-control")}get isPreviewable(){return this.cacheControlValue!="no-preview"}get isCacheable(){return this.cacheControlValue!="no-cache"}get isVisitable(){return this.getSetting("visit-control")!="reload"}getSetting(e){return this.headSnapshot.getMetaValue(`turbo-${e}`)}},li;(function(n){n.visitStart="visitStart",n.requestStart="requestStart",n.requestEnd="requestEnd",n.visitEnd="visitEnd"})(li||(li={}));var He;(function(n){n.initialized="initialized",n.started="started",n.canceled="canceled",n.failed="failed",n.completed="completed"})(He||(He={}));var Xp={action:"advance",historyChanged:!1,visitCachedSnapshot:()=>{},willRender:!0},Mt;(function(n){n[n.networkFailure=0]="networkFailure",n[n.timeoutFailure=-1]="timeoutFailure",n[n.contentTypeMismatch=-2]="contentTypeMismatch"})(Mt||(Mt={}));var Gl=class{constructor(e,t,i,s={}){this.identifier=Ni(),this.timingMetrics={},this.followedRedirect=!1,this.historyChanged=!1,this.scrolled=!1,this.snapshotCached=!1,this.state=He.initialized,this.delegate=e,this.location=t,this.restorationIdentifier=i||Ni();let{action:r,historyChanged:o,referrer:l,snapshotHTML:a,response:h,visitCachedSnapshot:c,willRender:u}=Object.assign(Object.assign({},Xp),s);this.action=r,this.historyChanged=o,this.referrer=l,this.snapshotHTML=a,this.response=h,this.isSamePage=this.delegate.locationWithActionIsSamePage(this.location,this.action),this.visitCachedSnapshot=c,this.willRender=u,this.scrolled=!u}get adapter(){return this.delegate.adapter}get view(){return this.delegate.view}get history(){return this.delegate.history}get restorationData(){return this.history.getRestorationDataForIdentifier(this.restorationIdentifier)}get silent(){return this.isSamePage}start(){this.state==He.initialized&&(this.recordTimingMetric(li.visitStart),this.state=He.started,this.adapter.visitStarted(this),this.delegate.visitStarted(this))}cancel(){this.state==He.started&&(this.request&&this.request.cancel(),this.cancelRender(),this.state=He.canceled)}complete(){this.state==He.started&&(this.recordTimingMetric(li.visitEnd),this.state=He.completed,this.adapter.visitCompleted(this),this.delegate.visitCompleted(this),this.followRedirect())}fail(){this.state==He.started&&(this.state=He.failed,this.adapter.visitFailed(this))}changeHistory(){var e;if(!this.historyChanged){let t=this.location.href===((e=this.referrer)===null||e===void 0?void 0:e.href)?"replace":this.action,i=this.getHistoryMethodForAction(t);this.history.update(i,this.location,this.restorationIdentifier),this.historyChanged=!0}}issueRequest(){this.hasPreloadedResponse()?this.simulateRequest():this.shouldIssueRequest()&&!this.request&&(this.request=new Bn(this,ye.get,this.location),this.request.perform())}simulateRequest(){this.response&&(this.startRequest(),this.recordResponse(),this.finishRequest())}startRequest(){this.recordTimingMetric(li.requestStart),this.adapter.visitRequestStarted(this)}recordResponse(e=this.response){if(this.response=e,e){let{statusCode:t}=e;Nl(t)?this.adapter.visitRequestCompleted(this):this.adapter.visitRequestFailedWithStatusCode(this,t)}}finishRequest(){this.recordTimingMetric(li.requestEnd),this.adapter.visitRequestFinished(this)}loadResponse(){if(this.response){let{statusCode:e,responseHTML:t}=this.response;this.render(async()=>{this.cacheSnapshot(),this.view.renderPromise&&await this.view.renderPromise,Nl(e)&&t!=null?(await this.view.renderPage(ft.fromHTMLString(t),!1,this.willRender),this.adapter.visitRendered(this),this.complete()):(await this.view.renderError(ft.fromHTMLString(t)),this.adapter.visitRendered(this),this.fail())})}}getCachedSnapshot(){let e=this.view.getCachedSnapshotForLocation(this.location)||this.getPreloadedSnapshot();if(e&&(!Wt(this.location)||e.hasAnchor(Wt(this.location)))&&(this.action=="restore"||e.isPreviewable))return e}getPreloadedSnapshot(){if(this.snapshotHTML)return ft.fromHTMLString(this.snapshotHTML)}hasCachedSnapshot(){return this.getCachedSnapshot()!=null}loadCachedSnapshot(){let e=this.getCachedSnapshot();if(e){let t=this.shouldIssueRequest();this.render(async()=>{this.cacheSnapshot(),this.isSamePage?this.adapter.visitRendered(this):(this.view.renderPromise&&await this.view.renderPromise,await this.view.renderPage(e,t,this.willRender),this.adapter.visitRendered(this),t||this.complete())})}}followRedirect(){var e;this.redirectedToLocation&&!this.followedRedirect&&((e=this.response)===null||e===void 0?void 0:e.redirected)&&(this.adapter.visitProposedToLocation(this.redirectedToLocation,{action:"replace",response:this.response}),this.followedRedirect=!0)}goToSamePageAnchor(){this.isSamePage&&this.render(async()=>{this.cacheSnapshot(),this.adapter.visitRendered(this)})}requestStarted(){this.startRequest()}requestPreventedHandlingResponse(e,t){}async requestSucceededWithResponse(e,t){let i=await t.responseHTML,{redirected:s,statusCode:r}=t;i==null?this.recordResponse({statusCode:Mt.contentTypeMismatch,redirected:s}):(this.redirectedToLocation=t.redirected?t.location:void 0,this.recordResponse({statusCode:r,responseHTML:i,redirected:s}))}async requestFailedWithResponse(e,t){let i=await t.responseHTML,{redirected:s,statusCode:r}=t;i==null?this.recordResponse({statusCode:Mt.contentTypeMismatch,redirected:s}):this.recordResponse({statusCode:r,responseHTML:i,redirected:s})}requestErrored(e,t){this.recordResponse({statusCode:Mt.networkFailure,redirected:!1})}requestFinished(){this.finishRequest()}performScroll(){this.scrolled||(this.action=="restore"?this.scrollToRestoredPosition()||this.scrollToAnchor()||this.view.scrollToTop():this.scrollToAnchor()||this.view.scrollToTop(),this.isSamePage&&this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation,this.location),this.scrolled=!0)}scrollToRestoredPosition(){let{scrollPosition:e}=this.restorationData;if(e)return this.view.scrollToPosition(e),!0}scrollToAnchor(){let e=Wt(this.location);if(e!=null)return this.view.scrollToAnchor(e),!0}recordTimingMetric(e){this.timingMetrics[e]=new Date().getTime()}getTimingMetrics(){return Object.assign({},this.timingMetrics)}getHistoryMethodForAction(e){switch(e){case"replace":return history.replaceState;case"advance":case"restore":return history.pushState}}hasPreloadedResponse(){return typeof this.response=="object"}shouldIssueRequest(){return this.isSamePage?!1:this.action=="restore"?!this.hasCachedSnapshot():this.willRender}cacheSnapshot(){this.snapshotCached||(this.view.cacheSnapshot().then(e=>e&&this.visitCachedSnapshot(e)),this.snapshotCached=!0)}async render(e){this.cancelRender(),await new Promise(t=>{this.frame=requestAnimationFrame(()=>t())}),await e(),delete this.frame,this.performScroll()}cancelRender(){this.frame&&(cancelAnimationFrame(this.frame),delete this.frame)}};function Nl(n){return n>=200&&n<300}var Jl=class{constructor(e){this.progressBar=new et,this.showProgressBar=()=>{this.progressBar.show()},this.session=e}visitProposedToLocation(e,t){this.navigator.startVisit(e,Ni(),t)}visitStarted(e){e.loadCachedSnapshot(),e.issueRequest(),e.changeHistory(),e.goToSamePageAnchor()}visitRequestStarted(e){this.progressBar.setValue(0),e.hasCachedSnapshot()||e.action!="restore"?this.showVisitProgressBarAfterDelay():this.showProgressBar()}visitRequestCompleted(e){e.loadResponse()}visitRequestFailedWithStatusCode(e,t){switch(t){case Mt.networkFailure:case Mt.timeoutFailure:case Mt.contentTypeMismatch:return this.reload();default:return e.loadResponse()}}visitRequestFinished(e){this.progressBar.setValue(1),this.hideVisitProgressBar()}visitCompleted(e){}pageInvalidated(){this.reload()}visitFailed(e){}visitRendered(e){}formSubmissionStarted(e){this.progressBar.setValue(0),this.showFormProgressBarAfterDelay()}formSubmissionFinished(e){this.progressBar.setValue(1),this.hideFormProgressBar()}showVisitProgressBarAfterDelay(){this.visitProgressBarTimeout=window.setTimeout(this.showProgressBar,this.session.progressBarDelay)}hideVisitProgressBar(){this.progressBar.hide(),this.visitProgressBarTimeout!=null&&(window.clearTimeout(this.visitProgressBarTimeout),delete this.visitProgressBarTimeout)}showFormProgressBarAfterDelay(){this.formProgressBarTimeout==null&&(this.formProgressBarTimeout=window.setTimeout(this.showProgressBar,this.session.progressBarDelay))}hideFormProgressBar(){this.progressBar.hide(),this.formProgressBarTimeout!=null&&(window.clearTimeout(this.formProgressBarTimeout),delete this.formProgressBarTimeout)}reload(){window.location.reload()}get navigator(){return this.session.navigator}},Yl=class{constructor(){this.started=!1}start(){this.started||(this.started=!0,addEventListener("turbo:before-cache",this.removeStaleElements,!1))}stop(){this.started&&(this.started=!1,removeEventListener("turbo:before-cache",this.removeStaleElements,!1))}removeStaleElements(){let e=[...document.querySelectorAll('[data-turbo-cache="false"]')];for(let t of e)t.remove()}},Xl=class{constructor(e){this.started=!1,this.submitCaptured=()=>{removeEventListener("submit",this.submitBubbled,!1),addEventListener("submit",this.submitBubbled,!1)},this.submitBubbled=t=>{if(!t.defaultPrevented){let i=t.target instanceof HTMLFormElement?t.target:void 0,s=t.submitter||void 0;i&&(s?.getAttribute("formmethod")||i.getAttribute("method"))!="dialog"&&this.delegate.willSubmitForm(i,s)&&(t.preventDefault(),this.delegate.formSubmitted(i,s))}},this.delegate=e}start(){this.started||(addEventListener("submit",this.submitCaptured,!0),this.started=!0)}stop(){this.started&&(removeEventListener("submit",this.submitCaptured,!0),this.started=!1)}},Ql=class{constructor(e){this.element=e,this.linkInterceptor=new lr(this,e),this.formInterceptor=new rr(this,e)}start(){this.linkInterceptor.start(),this.formInterceptor.start()}stop(){this.linkInterceptor.stop(),this.formInterceptor.stop()}shouldInterceptLinkClick(e,t){return this.shouldRedirect(e)}linkClickIntercepted(e,t){let i=this.findFrameElement(e);i&&i.delegate.linkClickIntercepted(e,t)}shouldInterceptFormSubmission(e,t){return this.shouldSubmit(e,t)}formSubmissionIntercepted(e,t){let i=this.findFrameElement(e,t);i&&(i.removeAttribute("reloadable"),i.delegate.formSubmissionIntercepted(e,t))}shouldSubmit(e,t){var i;let s=nr(e,t),r=this.element.ownerDocument.querySelector('meta[name="turbo-root"]'),o=we((i=r?.content)!==null&&i!==void 0?i:"/");return this.shouldRedirect(e,t)&&Ii(s,o)}shouldRedirect(e,t){let i=this.findFrameElement(e,t);return i?i!=e.closest("turbo-frame"):!1}findFrameElement(e,t){let i=t?.getAttribute("data-turbo-frame")||e.getAttribute("data-turbo-frame");if(i&&i!="_top"){let s=this.element.querySelector(`#${i}:not([disabled])`);if(s instanceof dt)return s}}},Zl=class{constructor(e){this.restorationIdentifier=Ni(),this.restorationData={},this.started=!1,this.pageLoaded=!1,this.onPopState=t=>{if(this.shouldHandlePopState()){let{turbo:i}=t.state||{};if(i){this.location=new URL(window.location.href);let{restorationIdentifier:s}=i;this.restorationIdentifier=s,this.delegate.historyPoppedToLocationWithRestorationIdentifier(this.location,s)}}},this.onPageLoad=async t=>{await Op(),this.pageLoaded=!0},this.delegate=e}start(){this.started||(addEventListener("popstate",this.onPopState,!1),addEventListener("load",this.onPageLoad,!1),this.started=!0,this.replace(new URL(window.location.href)))}stop(){this.started&&(removeEventListener("popstate",this.onPopState,!1),removeEventListener("load",this.onPageLoad,!1),this.started=!1)}push(e,t){this.update(history.pushState,e,t)}replace(e,t){this.update(history.replaceState,e,t)}update(e,t,i=Ni()){let s={turbo:{restorationIdentifier:i}};e.call(history,s,"",t.href),this.location=t,this.restorationIdentifier=i}getRestorationDataForIdentifier(e){return this.restorationData[e]||{}}updateRestorationData(e){let{restorationIdentifier:t}=this,i=this.restorationData[t];this.restorationData[t]=Object.assign(Object.assign({},i),e)}assumeControlOfScrollRestoration(){var e;this.previousScrollRestoration||(this.previousScrollRestoration=(e=history.scrollRestoration)!==null&&e!==void 0?e:"auto",history.scrollRestoration="manual")}relinquishControlOfScrollRestoration(){this.previousScrollRestoration&&(history.scrollRestoration=this.previousScrollRestoration,delete this.previousScrollRestoration)}shouldHandlePopState(){return this.pageIsLoaded()}pageIsLoaded(){return this.pageLoaded||document.readyState=="complete"}},ea=class{constructor(e){this.started=!1,this.clickCaptured=()=>{removeEventListener("click",this.clickBubbled,!1),addEventListener("click",this.clickBubbled,!1)},this.clickBubbled=t=>{if(this.clickEventIsSignificant(t)){let i=t.composedPath&&t.composedPath()[0]||t.target,s=this.findLinkFromClickTarget(i);if(s){let r=this.getLocationForLink(s);this.delegate.willFollowLinkToLocation(s,r)&&(t.preventDefault(),this.delegate.followedLinkToLocation(s,r))}}},this.delegate=e}start(){this.started||(addEventListener("click",this.clickCaptured,!0),this.started=!0)}stop(){this.started&&(removeEventListener("click",this.clickCaptured,!0),this.started=!1)}clickEventIsSignificant(e){return!(e.target&&e.target.isContentEditable||e.defaultPrevented||e.which>1||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)}findLinkFromClickTarget(e){if(e instanceof Element)return e.closest("a[href]:not([target^=_]):not([download])")}getLocationForLink(e){return we(e.getAttribute("href")||"")}};function ar(n){return n=="advance"||n=="replace"||n=="restore"}var ta=class{constructor(e){this.delegate=e}proposeVisit(e,t={}){this.delegate.allowsVisitingLocationWithAction(e,t.action)&&(Ii(e,this.view.snapshot.rootLocation)?this.delegate.visitProposedToLocation(e,t):window.location.href=e.toString())}startVisit(e,t,i={}){this.stop(),this.currentVisit=new Gl(this,we(e),t,Object.assign({referrer:this.location},i)),this.currentVisit.start()}submitForm(e,t){this.stop(),this.formSubmission=new hi(this,e,t,!0),this.formSubmission.start()}stop(){this.formSubmission&&(this.formSubmission.stop(),delete this.formSubmission),this.currentVisit&&(this.currentVisit.cancel(),delete this.currentVisit)}get adapter(){return this.delegate.adapter}get view(){return this.delegate.view}get history(){return this.delegate.history}formSubmissionStarted(e){typeof this.adapter.formSubmissionStarted=="function"&&this.adapter.formSubmissionStarted(e)}async formSubmissionSucceededWithResponse(e,t){if(e==this.formSubmission){let i=await t.responseHTML;if(i){e.method!=ye.get&&this.view.clearSnapshotCache();let{statusCode:s,redirected:r}=t,l={action:this.getActionForFormSubmission(e),response:{statusCode:s,responseHTML:i,redirected:r}};this.proposeVisit(t.location,l)}}}async formSubmissionFailedWithResponse(e,t){let i=await t.responseHTML;if(i){let s=ft.fromHTMLString(i);t.serverError?await this.view.renderError(s):await this.view.renderPage(s),this.view.scrollToTop(),this.view.clearSnapshotCache()}}formSubmissionErrored(e,t){console.error(t)}formSubmissionFinished(e){typeof this.adapter.formSubmissionFinished=="function"&&this.adapter.formSubmissionFinished(e)}visitStarted(e){this.delegate.visitStarted(e)}visitCompleted(e){this.delegate.visitCompleted(e)}locationWithActionIsSamePage(e,t){let i=Wt(e),s=Wt(this.view.lastRenderedLocation),r=t==="restore"&&typeof i>"u";return t!=="replace"&&er(e)===er(this.view.lastRenderedLocation)&&(r||i!=null&&i!==s)}visitScrolledToSamePageLocation(e,t){this.delegate.visitScrolledToSamePageLocation(e,t)}get location(){return this.history.location}get restorationIdentifier(){return this.history.restorationIdentifier}getActionForFormSubmission(e){let{formElement:t,submitter:i}=e,s=Dn("data-turbo-action",i,t);return ar(s)?s:"advance"}},ut;(function(n){n[n.initial=0]="initial",n[n.loading=1]="loading",n[n.interactive=2]="interactive",n[n.complete=3]="complete"})(ut||(ut={}));var ia=class{constructor(e){this.stage=ut.initial,this.started=!1,this.interpretReadyState=()=>{let{readyState:t}=this;t=="interactive"?this.pageIsInteractive():t=="complete"&&this.pageIsComplete()},this.pageWillUnload=()=>{this.delegate.pageWillUnload()},this.delegate=e}start(){this.started||(this.stage==ut.initial&&(this.stage=ut.loading),document.addEventListener("readystatechange",this.interpretReadyState,!1),addEventListener("pagehide",this.pageWillUnload,!1),this.started=!0)}stop(){this.started&&(document.removeEventListener("readystatechange",this.interpretReadyState,!1),removeEventListener("pagehide",this.pageWillUnload,!1),this.started=!1)}pageIsInteractive(){this.stage==ut.loading&&(this.stage=ut.interactive,this.delegate.pageBecameInteractive())}pageIsComplete(){this.pageIsInteractive(),this.stage==ut.interactive&&(this.stage=ut.complete,this.delegate.pageLoaded())}get readyState(){return document.readyState}},na=class{constructor(e){this.started=!1,this.onScroll=()=>{this.updatePosition({x:window.pageXOffset,y:window.pageYOffset})},this.delegate=e}start(){this.started||(addEventListener("scroll",this.onScroll,!1),this.onScroll(),this.started=!0)}stop(){this.started&&(removeEventListener("scroll",this.onScroll,!1),this.started=!1)}updatePosition(e){this.delegate.scrollPositionChanged(e)}},sa=class{constructor(e){this.sources=new Set,this.started=!1,this.inspectFetchResponse=t=>{let i=Qp(t);i&&Zp(i)&&(t.preventDefault(),this.receiveMessageResponse(i))},this.receiveMessageEvent=t=>{this.started&&typeof t.data=="string"&&this.receiveMessageHTML(t.data)},this.delegate=e}start(){this.started||(this.started=!0,addEventListener("turbo:before-fetch-response",this.inspectFetchResponse,!1))}stop(){this.started&&(this.started=!1,removeEventListener("turbo:before-fetch-response",this.inspectFetchResponse,!1))}connectStreamSource(e){this.streamSourceIsConnected(e)||(this.sources.add(e),e.addEventListener("message",this.receiveMessageEvent,!1))}disconnectStreamSource(e){this.streamSourceIsConnected(e)&&(this.sources.delete(e),e.removeEventListener("message",this.receiveMessageEvent,!1))}streamSourceIsConnected(e){return this.sources.has(e)}async receiveMessageResponse(e){let t=await e.responseHTML;t&&this.receiveMessageHTML(t)}receiveMessageHTML(e){this.delegate.receivedMessageFromStream(new ai(e))}};function Qp(n){var e;let t=(e=n.detail)===null||e===void 0?void 0:e.fetchResponse;if(t instanceof sr)return t}function Zp(n){var e;return((e=n.contentType)!==null&&e!==void 0?e:"").startsWith(ai.contentType)}var ra=class extends In{async render(){this.replaceHeadAndBody(),this.activateScriptElements()}replaceHeadAndBody(){let{documentElement:e,head:t,body:i}=document;e.replaceChild(this.newHead,t),e.replaceChild(this.newElement,i)}activateScriptElements(){for(let e of this.scriptElements){let t=e.parentNode;if(t){let i=this.createScriptElement(e);t.replaceChild(i,e)}}}get newHead(){return this.newSnapshot.headSnapshot.element}get scriptElements(){return[...document.documentElement.querySelectorAll("script")]}},hr=class extends In{get shouldRender(){return this.newSnapshot.isVisitable&&this.trackedElementsAreIdentical}prepareToRender(){this.mergeHead()}async render(){this.willRender&&this.replaceBody()}finishRendering(){super.finishRendering(),this.isPreview||this.focusFirstAutofocusableElement()}get currentHeadSnapshot(){return this.currentSnapshot.headSnapshot}get newHeadSnapshot(){return this.newSnapshot.headSnapshot}get newElement(){return this.newSnapshot.element}mergeHead(){this.copyNewHeadStylesheetElements(),this.copyNewHeadScriptElements(),this.removeCurrentHeadProvisionalElements(),this.copyNewHeadProvisionalElements()}replaceBody(){this.preservingPermanentElements(()=>{this.activateNewBody(),this.assignNewBody()})}get trackedElementsAreIdentical(){return this.currentHeadSnapshot.trackedElementSignature==this.newHeadSnapshot.trackedElementSignature}copyNewHeadStylesheetElements(){for(let e of this.newHeadStylesheetElements)document.head.appendChild(e)}copyNewHeadScriptElements(){for(let e of this.newHeadScriptElements)document.head.appendChild(this.createScriptElement(e))}removeCurrentHeadProvisionalElements(){for(let e of this.currentHeadProvisionalElements)document.head.removeChild(e)}copyNewHeadProvisionalElements(){for(let e of this.newHeadProvisionalElements)document.head.appendChild(e)}activateNewBody(){document.adoptNode(this.newElement),this.activateNewBodyScriptElements()}activateNewBodyScriptElements(){for(let e of this.newBodyScriptElements){let t=this.createScriptElement(e);e.replaceWith(t)}}assignNewBody(){document.body&&this.newElement instanceof HTMLBodyElement?document.body.replaceWith(this.newElement):document.documentElement.appendChild(this.newElement)}get newHeadStylesheetElements(){return this.newHeadSnapshot.getStylesheetElementsNotInSnapshot(this.currentHeadSnapshot)}get newHeadScriptElements(){return this.newHeadSnapshot.getScriptElementsNotInSnapshot(this.currentHeadSnapshot)}get currentHeadProvisionalElements(){return this.currentHeadSnapshot.provisionalElements}get newHeadProvisionalElements(){return this.newHeadSnapshot.provisionalElements}get newBodyScriptElements(){return this.newElement.querySelectorAll("script")}},oa=class{constructor(e){this.keys=[],this.snapshots={},this.size=e}has(e){return Pn(e)in this.snapshots}get(e){if(this.has(e)){let t=this.read(e);return this.touch(e),t}}put(e,t){return this.write(e,t),this.touch(e),t}clear(){this.snapshots={}}read(e){return this.snapshots[Pn(e)]}write(e,t){this.snapshots[Pn(e)]=t}touch(e){let t=Pn(e),i=this.keys.indexOf(t);i>-1&&this.keys.splice(i,1),this.keys.unshift(t),this.trim()}trim(){for(let e of this.keys.splice(this.size))delete this.snapshots[e]}},la=class extends or{constructor(){super(...arguments);this.snapshotCache=new oa(10),this.lastRenderedLocation=new URL(location.href)}renderPage(e,t=!1,i=!0){let s=new hr(this.snapshot,e,t,i);return this.render(s)}renderError(e){let t=new ra(this.snapshot,e,!1);return this.render(t)}clearSnapshotCache(){this.snapshotCache.clear()}async cacheSnapshot(){if(this.shouldCacheSnapshot){this.delegate.viewWillCacheSnapshot();let{snapshot:e,lastRenderedLocation:t}=this;await Pp();let i=e.clone();return this.snapshotCache.put(t,i),i}}getCachedSnapshotForLocation(e){return this.snapshotCache.get(e)}get snapshot(){return ft.fromElement(this.element)}get shouldCacheSnapshot(){return this.snapshot.isCacheable}},aa=class{constructor(){this.navigator=new ta(this),this.history=new Zl(this),this.view=new la(this,document.documentElement),this.adapter=new Jl(this),this.pageObserver=new ia(this),this.cacheObserver=new Yl,this.linkClickObserver=new ea(this),this.formSubmitObserver=new Xl(this),this.scrollObserver=new na(this),this.streamObserver=new sa(this),this.frameRedirector=new Ql(document.documentElement),this.drive=!0,this.enabled=!0,this.progressBarDelay=500,this.started=!1}start(){this.started||(this.pageObserver.start(),this.cacheObserver.start(),this.linkClickObserver.start(),this.formSubmitObserver.start(),this.scrollObserver.start(),this.streamObserver.start(),this.frameRedirector.start(),this.history.start(),this.started=!0,this.enabled=!0)}disable(){this.enabled=!1}stop(){this.started&&(this.pageObserver.stop(),this.cacheObserver.stop(),this.linkClickObserver.stop(),this.formSubmitObserver.stop(),this.scrollObserver.stop(),this.streamObserver.stop(),this.frameRedirector.stop(),this.history.stop(),this.started=!1)}registerAdapter(e){this.adapter=e}visit(e,t={}){this.navigator.proposeVisit(we(e),t)}connectStreamSource(e){this.streamObserver.connectStreamSource(e)}disconnectStreamSource(e){this.streamObserver.disconnectStreamSource(e)}renderStreamMessage(e){document.documentElement.appendChild(ai.wrap(e).fragment)}clearCache(){this.view.clearSnapshotCache()}setProgressBarDelay(e){this.progressBarDelay=e}get location(){return this.history.location}get restorationIdentifier(){return this.history.restorationIdentifier}historyPoppedToLocationWithRestorationIdentifier(e,t){this.enabled?this.navigator.startVisit(e,t,{action:"restore",historyChanged:!0}):this.adapter.pageInvalidated()}scrollPositionChanged(e){this.history.updateRestorationData({scrollPosition:e})}willFollowLinkToLocation(e,t){return this.elementDriveEnabled(e)&&Ii(t,this.snapshot.rootLocation)&&this.applicationAllowsFollowingLinkToLocation(e,t)}followedLinkToLocation(e,t){let i=this.getActionForLink(e);this.convertLinkWithMethodClickToFormSubmission(e)||this.visit(t.href,{action:i})}convertLinkWithMethodClickToFormSubmission(e){let t=e.getAttribute("data-turbo-method");if(t){let i=document.createElement("form");i.method=t,i.action=e.getAttribute("href")||"undefined",i.hidden=!0,e.hasAttribute("data-turbo-confirm")&&i.setAttribute("data-turbo-confirm",e.getAttribute("data-turbo-confirm"));let s=this.getTargetFrameForLink(e);return s?(i.setAttribute("data-turbo-frame",s),i.addEventListener("turbo:submit-start",()=>i.remove())):i.addEventListener("submit",()=>i.remove()),document.body.appendChild(i),Ee("submit",{cancelable:!0,target:i})}else return!1}allowsVisitingLocationWithAction(e,t){return this.locationWithActionIsSamePage(e,t)||this.applicationAllowsVisitingLocation(e)}visitProposedToLocation(e,t){Fl(e),this.adapter.visitProposedToLocation(e,t)}visitStarted(e){Fl(e.location),e.silent||this.notifyApplicationAfterVisitingLocation(e.location,e.action)}visitCompleted(e){this.notifyApplicationAfterPageLoad(e.getTimingMetrics())}locationWithActionIsSamePage(e,t){return this.navigator.locationWithActionIsSamePage(e,t)}visitScrolledToSamePageLocation(e,t){this.notifyApplicationAfterVisitingSamePageLocation(e,t)}willSubmitForm(e,t){let i=nr(e,t);return this.elementDriveEnabled(e)&&(!t||this.elementDriveEnabled(t))&&Ii(we(i),this.snapshot.rootLocation)}formSubmitted(e,t){this.navigator.submitForm(e,t)}pageBecameInteractive(){this.view.lastRenderedLocation=this.location,this.notifyApplicationAfterPageLoad()}pageLoaded(){this.history.assumeControlOfScrollRestoration()}pageWillUnload(){this.history.relinquishControlOfScrollRestoration()}receivedMessageFromStream(e){this.renderStreamMessage(e)}viewWillCacheSnapshot(){var e;!((e=this.navigator.currentVisit)===null||e===void 0)&&e.silent||this.notifyApplicationBeforeCachingSnapshot()}allowsImmediateRender({element:e},t){return!this.notifyApplicationBeforeRender(e,t).defaultPrevented}viewRenderedSnapshot(e,t){this.view.lastRenderedLocation=this.history.location,this.notifyApplicationAfterRender()}viewInvalidated(){this.adapter.pageInvalidated()}frameLoaded(e){this.notifyApplicationAfterFrameLoad(e)}frameRendered(e,t){this.notifyApplicationAfterFrameRender(e,t)}applicationAllowsFollowingLinkToLocation(e,t){return!this.notifyApplicationAfterClickingLinkToLocation(e,t).defaultPrevented}applicationAllowsVisitingLocation(e){return!this.notifyApplicationBeforeVisitingLocation(e).defaultPrevented}notifyApplicationAfterClickingLinkToLocation(e,t){return Ee("turbo:click",{target:e,detail:{url:t.href},cancelable:!0})}notifyApplicationBeforeVisitingLocation(e){return Ee("turbo:before-visit",{detail:{url:e.href},cancelable:!0})}notifyApplicationAfterVisitingLocation(e,t){return tr(document.documentElement),Ee("turbo:visit",{detail:{url:e.href,action:t}})}notifyApplicationBeforeCachingSnapshot(){return Ee("turbo:before-cache")}notifyApplicationBeforeRender(e,t){return Ee("turbo:before-render",{detail:{newBody:e,resume:t},cancelable:!0})}notifyApplicationAfterRender(){return Ee("turbo:render")}notifyApplicationAfterPageLoad(e={}){return ir(document.documentElement),Ee("turbo:load",{detail:{url:this.location.href,timing:e}})}notifyApplicationAfterVisitingSamePageLocation(e,t){dispatchEvent(new HashChangeEvent("hashchange",{oldURL:e.toString(),newURL:t.toString()}))}notifyApplicationAfterFrameLoad(e){return Ee("turbo:frame-load",{target:e})}notifyApplicationAfterFrameRender(e,t){return Ee("turbo:frame-render",{detail:{fetchResponse:e},target:t,cancelable:!0})}elementDriveEnabled(e){let t=e?.closest("[data-turbo]");return this.drive?t?t.getAttribute("data-turbo")!="false":!0:t?t.getAttribute("data-turbo")=="true":!1}getActionForLink(e){let t=e.getAttribute("data-turbo-action");return ar(t)?t:"advance"}getTargetFrameForLink(e){let t=e.getAttribute("data-turbo-frame");if(t)return t;{let i=e.closest("turbo-frame");if(i)return i.id}}get snapshot(){return this.view.snapshot}};function Fl(n){Object.defineProperties(n,em)}var em={absoluteURL:{get(){return this.toString()}}},ve=new aa,{navigator:tm}=ve;function ha(){ve.start()}function im(n){ve.registerAdapter(n)}function nm(n,e){ve.visit(n,e)}function cr(n){ve.connectStreamSource(n)}function ur(n){ve.disconnectStreamSource(n)}function sm(n){ve.renderStreamMessage(n)}function rm(){ve.clearCache()}function om(n){ve.setProgressBarDelay(n)}function lm(n){hi.confirmMethod=n}var am=Object.freeze({__proto__:null,navigator:tm,session:ve,PageRenderer:hr,PageSnapshot:ft,start:ha,registerAdapter:im,visit:nm,connectStreamSource:cr,disconnectStreamSource:ur,renderStreamMessage:sm,clearCache:rm,setProgressBarDelay:om,setConfirmMethod:lm}),ca=class{constructor(e){this.fetchResponseLoaded=t=>{},this.currentFetchRequest=null,this.resolveVisitPromise=()=>{},this.connected=!1,this.hasBeenLoaded=!1,this.settingSourceURL=!1,this.element=e,this.view=new jl(this,this.element),this.appearanceObserver=new $l(this,this.element),this.linkInterceptor=new lr(this,this.element),this.formInterceptor=new rr(this,this.element)}connect(){this.connected||(this.connected=!0,this.reloadable=!1,this.loadingStyle==Et.lazy&&this.appearanceObserver.start(),this.linkInterceptor.start(),this.formInterceptor.start(),this.sourceURLChanged())}disconnect(){this.connected&&(this.connected=!1,this.appearanceObserver.stop(),this.linkInterceptor.stop(),this.formInterceptor.stop())}disabledChanged(){this.loadingStyle==Et.eager&&this.loadSourceURL()}sourceURLChanged(){(this.loadingStyle==Et.eager||this.hasBeenLoaded)&&this.loadSourceURL()}loadingStyleChanged(){this.loadingStyle==Et.lazy?this.appearanceObserver.start():(this.appearanceObserver.stop(),this.loadSourceURL())}async loadSourceURL(){if(!this.settingSourceURL&&this.enabled&&this.isActive&&(this.reloadable||this.sourceURL!=this.currentURL)){let e=this.currentURL;if(this.currentURL=this.sourceURL,this.sourceURL)try{this.element.loaded=this.visit(we(this.sourceURL)),this.appearanceObserver.stop(),await this.element.loaded,this.hasBeenLoaded=!0}catch(t){throw this.currentURL=e,t}}}async loadResponse(e){(e.redirected||e.succeeded&&e.isHTML)&&(this.sourceURL=e.response.url);try{let t=await e.responseHTML;if(t){let{body:i}=Wl(t),s=new Fi(await this.extractForeignFrameElement(i)),r=new Kl(this.view.snapshot,s,!1,!1);this.view.renderPromise&&await this.view.renderPromise,await this.view.render(r),ve.frameRendered(e,this.element),ve.frameLoaded(this.element),this.fetchResponseLoaded(e)}}catch(t){console.error(t),this.view.invalidate()}finally{this.fetchResponseLoaded=()=>{}}}elementAppearedInViewport(e){this.loadSourceURL()}shouldInterceptLinkClick(e,t){return e.hasAttribute("data-turbo-method")?!1:this.shouldInterceptNavigation(e)}linkClickIntercepted(e,t){this.reloadable=!0,this.navigateFrame(e,t)}shouldInterceptFormSubmission(e,t){return this.shouldInterceptNavigation(e,t)}formSubmissionIntercepted(e,t){this.formSubmission&&this.formSubmission.stop(),this.reloadable=!1,this.formSubmission=new hi(this,e,t);let{fetchRequest:i}=this.formSubmission;this.prepareHeadersForRequest(i.headers,i),this.formSubmission.start()}prepareHeadersForRequest(e,t){e["Turbo-Frame"]=this.id}requestStarted(e){tr(this.element)}requestPreventedHandlingResponse(e,t){this.resolveVisitPromise()}async requestSucceededWithResponse(e,t){await this.loadResponse(t),this.resolveVisitPromise()}requestFailedWithResponse(e,t){console.error(t),this.resolveVisitPromise()}requestErrored(e,t){console.error(t),this.resolveVisitPromise()}requestFinished(e){ir(this.element)}formSubmissionStarted({formElement:e}){tr(e,this.findFrameElement(e))}formSubmissionSucceededWithResponse(e,t){let i=this.findFrameElement(e.formElement,e.submitter);this.proposeVisitIfNavigatedWithAction(i,e.formElement,e.submitter),i.delegate.loadResponse(t)}formSubmissionFailedWithResponse(e,t){this.element.delegate.loadResponse(t)}formSubmissionErrored(e,t){console.error(t)}formSubmissionFinished({formElement:e}){ir(e,this.findFrameElement(e))}allowsImmediateRender(e,t){return!0}viewRenderedSnapshot(e,t){}viewInvalidated(){}async visit(e){var t;let i=new Bn(this,ye.get,e,new URLSearchParams,this.element);return(t=this.currentFetchRequest)===null||t===void 0||t.cancel(),this.currentFetchRequest=i,new Promise(s=>{this.resolveVisitPromise=()=>{this.resolveVisitPromise=()=>{},this.currentFetchRequest=null,s()},i.perform()})}navigateFrame(e,t,i){let s=this.findFrameElement(e,i);this.proposeVisitIfNavigatedWithAction(s,e,i),s.setAttribute("reloadable",""),s.src=t}proposeVisitIfNavigatedWithAction(e,t,i){let s=Dn("data-turbo-action",i,t,e);if(ar(s)){let{visitCachedSnapshot:r}=new ua(e);e.delegate.fetchResponseLoaded=o=>{if(e.src){let{statusCode:l,redirected:a}=o,h=e.ownerDocument.documentElement.outerHTML,c={statusCode:l,redirected:a,responseHTML:h};ve.visit(e.src,{action:s,response:c,visitCachedSnapshot:r,willRender:!1})}}}}findFrameElement(e,t){var i;let s=Dn("data-turbo-frame",t,e)||this.element.getAttribute("target");return(i=Vl(s))!==null&&i!==void 0?i:this.element}async extractForeignFrameElement(e){let t,i=CSS.escape(this.id);try{if(t=Hl(e.querySelector(`turbo-frame#${i}`),this.currentURL))return t;if(t=Hl(e.querySelector(`turbo-frame[src][recurse~=${i}]`),this.currentURL))return await t.loaded,await this.extractForeignFrameElement(t);console.error(`Response has no matching <turbo-frame id="${i}"> element`)}catch(s){console.error(s)}return new dt}formActionIsVisitable(e,t){let i=nr(e,t);return Ii(we(i),this.rootLocation)}shouldInterceptNavigation(e,t){let i=Dn("data-turbo-frame",t,e)||this.element.getAttribute("target");if(e instanceof HTMLFormElement&&!this.formActionIsVisitable(e,t)||!this.enabled||i=="_top")return!1;if(i){let s=Vl(i);if(s)return!s.disabled}return!(!ve.elementDriveEnabled(e)||t&&!ve.elementDriveEnabled(t))}get id(){return this.element.id}get enabled(){return!this.element.disabled}get sourceURL(){if(this.element.src)return this.element.src}get reloadable(){return this.findFrameElement(this.element).hasAttribute("reloadable")}set reloadable(e){let t=this.findFrameElement(this.element);e?t.setAttribute("reloadable",""):t.removeAttribute("reloadable")}set sourceURL(e){this.settingSourceURL=!0,this.element.src=e??null,this.currentURL=this.element.src,this.settingSourceURL=!1}get loadingStyle(){return this.element.loading}get isLoading(){return this.formSubmission!==void 0||this.resolveVisitPromise()!==void 0}get isActive(){return this.element.isActive&&this.connected}get rootLocation(){var e;let t=this.element.ownerDocument.querySelector('meta[name="turbo-root"]'),i=(e=t?.content)!==null&&e!==void 0?e:"/";return we(i)}},ua=class{constructor(e){this.visitCachedSnapshot=({element:t})=>{var i;let{id:s,clone:r}=this;(i=t.querySelector("#"+s))===null||i===void 0||i.replaceWith(r)},this.clone=e.cloneNode(!0),this.id=e.id}};function Vl(n){if(n!=null){let e=document.getElementById(n);if(e instanceof dt)return e}}function Hl(n,e){if(n){let t=n.getAttribute("src");if(t!=null&&e!=null&&Ep(t,e))throw new Error(`Matching <turbo-frame id="${n.id}"> element has a source URL which references itself`);if(n.ownerDocument!==document&&(n=document.importNode(n,!0)),n instanceof dt)return n.connectedCallback(),n.disconnectedCallback(),n}}var hm={after(){this.targetElements.forEach(n=>{var e;return(e=n.parentElement)===null||e===void 0?void 0:e.insertBefore(this.templateContent,n.nextSibling)})},append(){this.removeDuplicateTargetChildren(),this.targetElements.forEach(n=>n.append(this.templateContent))},before(){this.targetElements.forEach(n=>{var e;return(e=n.parentElement)===null||e===void 0?void 0:e.insertBefore(this.templateContent,n)})},prepend(){this.removeDuplicateTargetChildren(),this.targetElements.forEach(n=>n.prepend(this.templateContent))},remove(){this.targetElements.forEach(n=>n.remove())},replace(){this.targetElements.forEach(n=>n.replaceWith(this.templateContent))},update(){this.targetElements.forEach(n=>{n.innerHTML="",n.append(this.templateContent)})}},fa=class extends HTMLElement{async connectedCallback(){try{await this.render()}catch(e){console.error(e)}finally{this.disconnect()}}async render(){var e;return(e=this.renderPromise)!==null&&e!==void 0?e:this.renderPromise=(async()=>{this.dispatchEvent(this.beforeRenderEvent)&&(await On(),this.performAction())})()}disconnect(){try{this.remove()}catch{}}removeDuplicateTargetChildren(){this.duplicateChildren.forEach(e=>e.remove())}get duplicateChildren(){var e;let t=this.targetElements.flatMap(s=>[...s.children]).filter(s=>!!s.id),i=[...(e=this.templateContent)===null||e===void 0?void 0:e.children].filter(s=>!!s.id).map(s=>s.id);return t.filter(s=>i.includes(s.id))}get performAction(){if(this.action){let e=hm[this.action];if(e)return e;this.raise("unknown action")}this.raise("action attribute is missing")}get targetElements(){if(this.target)return this.targetElementsById;if(this.targets)return this.targetElementsByQuery;this.raise("target or targets attribute is missing")}get templateContent(){return this.templateElement.content.cloneNode(!0)}get templateElement(){if(this.firstElementChild instanceof HTMLTemplateElement)return this.firstElementChild;this.raise("first child element must be a <template> element")}get action(){return this.getAttribute("action")}get target(){return this.getAttribute("target")}get targets(){return this.getAttribute("targets")}raise(e){throw new Error(`${this.description}: ${e}`)}get description(){var e,t;return(t=((e=this.outerHTML.match(/<[^>]+>/))!==null&&e!==void 0?e:[])[0])!==null&&t!==void 0?t:"<turbo-stream>"}get beforeRenderEvent(){return new CustomEvent("turbo:before-stream-render",{bubbles:!0,cancelable:!0})}get targetElementsById(){var e;let t=(e=this.ownerDocument)===null||e===void 0?void 0:e.getElementById(this.target);return t!==null?[t]:[]}get targetElementsByQuery(){var e;let t=(e=this.ownerDocument)===null||e===void 0?void 0:e.querySelectorAll(this.targets);return t.length!==0?Array.prototype.slice.call(t):[]}};dt.delegateConstructor=ca;customElements.define("turbo-frame",dt);customElements.define("turbo-stream",fa);(()=>{let n=document.currentScript;if(!!n&&!n.hasAttribute("data-turbo-suppress-warning")){for(;n=n.parentElement;)if(n==document.body)return console.warn(zl`
|
18
|
+
You are loading Turbo from a <script> element inside the <body> element. This is probably not what you meant to do!
|
19
|
+
|
20
|
+
Load your application’s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change.
|
21
|
+
|
22
|
+
For more information, see: https://turbo.hotwired.dev/handbook/building#working-with-script-elements
|
23
|
+
|
24
|
+
——
|
25
|
+
Suppress this warning by adding a "data-turbo-suppress-warning" attribute to: %s
|
26
|
+
`,n.outerHTML)}})();window.Turbo=am;ha();var wa;async function pm(){return wa||va(mm().then(va))}function va(n){return wa=n}async function mm(){let{createConsumer:n}=await Promise.resolve().then(()=>(ya(),ba));return n()}async function Sa(n,e){let{subscriptions:t}=await pm();return t.create(n,e)}var xa=class extends HTMLElement{async connectedCallback(){cr(this),this.subscription=await Sa(this.channel,{received:this.dispatchMessageEvent.bind(this)})}disconnectedCallback(){ur(this),this.subscription&&this.subscription.unsubscribe()}dispatchMessageEvent(e){let t=new MessageEvent("message",{data:e});return this.dispatchEvent(t)}get channel(){let e=this.getAttribute("channel"),t=this.getAttribute("signed-stream-name");return{channel:e,signed_stream_name:t}}};customElements.define("turbo-cable-stream-source",xa);var jn=class{constructor(e){this.response=e}get statusCode(){return this.response.status}get redirected(){return this.response.redirected}get ok(){return this.response.ok}get unauthenticated(){return this.statusCode===401}get unprocessableEntity(){return this.statusCode===422}get authenticationURL(){return this.response.headers.get("WWW-Authenticate")}get contentType(){return(this.response.headers.get("Content-Type")||"").replace(/;.*$/,"")}get headers(){return this.response.headers}get html(){return this.contentType.match(/^(application|text)\/(html|xhtml\+xml)$/)?this.text:Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`))}get json(){return this.contentType.match(/^application\/.*json$/)?this.responseJson||(this.responseJson=this.response.json()):Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`))}get text(){return this.responseText||(this.responseText=this.response.text())}get isTurboStream(){return this.contentType.match(/^text\/vnd\.turbo-stream\.html/)}async renderTurboStream(){if(this.isTurboStream)window.Turbo?await window.Turbo.renderStreamMessage(await this.text):console.warn("You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js");else return Promise.reject(new Error(`Expected a Turbo Stream response but got "${this.contentType}" instead`))}};var Un=class{static register(e){this.interceptor=e}static get(){return this.interceptor}static reset(){this.interceptor=void 0}};function ka(n){let e=document.cookie?document.cookie.split("; "):[],t=`${encodeURIComponent(n)}=`,i=e.find(s=>s.startsWith(t));if(i){let s=i.split("=").slice(1).join("=");if(s)return decodeURIComponent(s)}}function Ca(n){let e={};for(let t in n){let i=n[t];i!==void 0&&(e[t]=i)}return e}function vr(n){let e=document.head.querySelector(`meta[name="${n}"]`);return e&&e.content}function Aa(n){return[...n].reduce((e,[t,i])=>e.concat(typeof i=="string"?[[t,i]]:[]),[])}function Ea(n,e){for(let[t,i]of e)i instanceof window.File||(n.has(t)?(n.delete(t),n.set(t,i)):n.append(t,i))}var Kn=class{constructor(e,t,i={}){this.method=e,this.options=i,this.originalUrl=t.toString()}async perform(){try{let t=Un.get();t&&await t(this)}catch(t){console.error(t)}let e=new jn(await window.fetch(this.url,this.fetchOptions));return e.unauthenticated&&e.authenticationURL?Promise.reject(window.location.href=e.authenticationURL):(e.ok&&e.isTurboStream&&await e.renderTurboStream(),e)}addHeader(e,t){let i=this.additionalHeaders;i[e]=t,this.options.headers=i}get fetchOptions(){return{method:this.method.toUpperCase(),headers:this.headers,body:this.formattedBody,signal:this.signal,credentials:"same-origin",redirect:this.redirect}}get headers(){return Ca(Object.assign({"X-Requested-With":"XMLHttpRequest","X-CSRF-Token":this.csrfToken,"Content-Type":this.contentType,Accept:this.accept},this.additionalHeaders))}get csrfToken(){return ka(vr("csrf-param"))||vr("csrf-token")}get contentType(){return this.options.contentType?this.options.contentType:this.body==null||this.body instanceof window.FormData?void 0:this.body instanceof window.File?this.body.type:"application/json"}get accept(){switch(this.responseKind){case"html":return"text/html, application/xhtml+xml";case"turbo-stream":return"text/vnd.turbo-stream.html, text/html, application/xhtml+xml";case"json":return"application/json, application/vnd.api+json";default:return"*/*"}}get body(){return this.options.body}get query(){let e=(this.originalUrl.split("?")[1]||"").split("#")[0],t=new URLSearchParams(e),i=this.options.query;i instanceof window.FormData?i=Aa(i):i instanceof window.URLSearchParams?i=i.entries():i=Object.entries(i||{}),Ea(t,i);let s=t.toString();return s.length>0?`?${s}`:""}get url(){return this.originalUrl.split("?")[0].split("#")[0]+this.query}get responseKind(){return this.options.responseKind||"html"}get signal(){return this.options.signal}get redirect(){return this.options.redirect||"follow"}get additionalHeaders(){return this.options.headers||{}}get formattedBody(){let e=Object.prototype.toString.call(this.body)==="[object String]";return this.headers["Content-Type"]==="application/json"&&!e?JSON.stringify(this.body):this.body}};async function zi(n,e){return new Kn("get",n,e).perform()}var Ra=class{constructor(e,t,i){this.eventTarget=e,this.eventName=t,this.eventOptions=i,this.unorderedBindings=new Set}connect(){this.eventTarget.addEventListener(this.eventName,this,this.eventOptions)}disconnect(){this.eventTarget.removeEventListener(this.eventName,this,this.eventOptions)}bindingConnected(e){this.unorderedBindings.add(e)}bindingDisconnected(e){this.unorderedBindings.delete(e)}handleEvent(e){let t=bm(e);for(let i of this.bindings){if(t.immediatePropagationStopped)break;i.handleEvent(t)}}get bindings(){return Array.from(this.unorderedBindings).sort((e,t)=>{let i=e.index,s=t.index;return i<s?-1:i>s?1:0})}};function bm(n){if("immediatePropagationStopped"in n)return n;{let{stopImmediatePropagation:e}=n;return Object.assign(n,{immediatePropagationStopped:!1,stopImmediatePropagation(){this.immediatePropagationStopped=!0,e.call(this)}})}}var Pa=class{constructor(e){this.application=e,this.eventListenerMaps=new Map,this.started=!1}start(){this.started||(this.started=!0,this.eventListeners.forEach(e=>e.connect()))}stop(){this.started&&(this.started=!1,this.eventListeners.forEach(e=>e.disconnect()))}get eventListeners(){return Array.from(this.eventListenerMaps.values()).reduce((e,t)=>e.concat(Array.from(t.values())),[])}bindingConnected(e){this.fetchEventListenerForBinding(e).bindingConnected(e)}bindingDisconnected(e){this.fetchEventListenerForBinding(e).bindingDisconnected(e)}handleError(e,t,i={}){this.application.handleError(e,`Error ${t}`,i)}fetchEventListenerForBinding(e){let{eventTarget:t,eventName:i,eventOptions:s}=e;return this.fetchEventListener(t,i,s)}fetchEventListener(e,t,i){let s=this.fetchEventListenerMapForEventTarget(e),r=this.cacheKey(t,i),o=s.get(r);return o||(o=this.createEventListener(e,t,i),s.set(r,o)),o}createEventListener(e,t,i){let s=new Ra(e,t,i);return this.started&&s.connect(),s}fetchEventListenerMapForEventTarget(e){let t=this.eventListenerMaps.get(e);return t||(t=new Map,this.eventListenerMaps.set(e,t)),t}cacheKey(e,t){let i=[e];return Object.keys(t).sort().forEach(s=>{i.push(`${t[s]?"":"!"}${s}`)}),i.join(":")}},ym=/^((.+?)(@(window|document))?->)?(.+?)(#([^:]+?))(:(.+))?$/;function vm(n){let t=n.trim().match(ym)||[];return{eventTarget:wm(t[4]),eventName:t[2],eventOptions:t[9]?Sm(t[9]):{},identifier:t[5],methodName:t[7]}}function wm(n){if(n=="window")return window;if(n=="document")return document}function Sm(n){return n.split(":").reduce((e,t)=>Object.assign(e,{[t.replace(/^!/,"")]:!/^!/.test(t)}),{})}function xm(n){if(n==window)return"window";if(n==document)return"document"}function Oa(n){return n.replace(/(?:[_-])([a-z0-9])/g,(e,t)=>t.toUpperCase())}function _n(n){return n.charAt(0).toUpperCase()+n.slice(1)}function Da(n){return n.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`)}function km(n){return n.match(/[^\s]+/g)||[]}var Ba=class{constructor(e,t,i){this.element=e,this.index=t,this.eventTarget=i.eventTarget||e,this.eventName=i.eventName||Cm(e)||wr("missing event name"),this.eventOptions=i.eventOptions||{},this.identifier=i.identifier||wr("missing identifier"),this.methodName=i.methodName||wr("missing method name")}static forToken(e){return new this(e.element,e.index,vm(e.content))}toString(){let e=this.eventTargetName?`@${this.eventTargetName}`:"";return`${this.eventName}${e}->${this.identifier}#${this.methodName}`}get params(){return this.eventTarget instanceof Element?this.getParamsFromEventTargetAttributes(this.eventTarget):{}}getParamsFromEventTargetAttributes(e){let t={},i=new RegExp(`^data-${this.identifier}-(.+)-param$`);return Array.from(e.attributes).forEach(({name:r,value:o})=>{let l=r.match(i),a=l&&l[1];a&&Object.assign(t,{[Oa(a)]:Am(o)})}),t}get eventTargetName(){return xm(this.eventTarget)}},Ma={a:n=>"click",button:n=>"click",form:n=>"submit",details:n=>"toggle",input:n=>n.getAttribute("type")=="submit"?"click":"input",select:n=>"change",textarea:n=>"input"};function Cm(n){let e=n.tagName.toLowerCase();if(e in Ma)return Ma[e](n)}function wr(n){throw new Error(n)}function Am(n){try{return JSON.parse(n)}catch{return n}}var Ia=class{constructor(e,t){this.context=e,this.action=t}get index(){return this.action.index}get eventTarget(){return this.action.eventTarget}get eventOptions(){return this.action.eventOptions}get identifier(){return this.context.identifier}handleEvent(e){this.willBeInvokedByEvent(e)&&this.invokeWithEvent(e)}get eventName(){return this.action.eventName}get method(){let e=this.controller[this.methodName];if(typeof e=="function")return e;throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`)}invokeWithEvent(e){let{target:t,currentTarget:i}=e;try{let{params:s}=this.action,r=Object.assign(e,{params:s});this.method.call(this.controller,r),this.context.logDebugActivity(this.methodName,{event:e,target:t,currentTarget:i,action:this.methodName})}catch(s){let{identifier:r,controller:o,element:l,index:a}=this,h={identifier:r,controller:o,element:l,index:a,event:e};this.context.handleError(s,`invoking action "${this.action}"`,h)}}willBeInvokedByEvent(e){let t=e.target;return this.element===t?!0:t instanceof Element&&this.element.contains(t)?this.scope.containsElement(t):this.scope.containsElement(this.action.element)}get controller(){return this.context.controller}get methodName(){return this.action.methodName}get element(){return this.scope.element}get scope(){return this.context.scope}},Na=class{constructor(e,t){this.mutationObserverInit={attributes:!0,childList:!0,subtree:!0},this.element=e,this.started=!1,this.delegate=t,this.elements=new Set,this.mutationObserver=new MutationObserver(i=>this.processMutations(i))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,this.mutationObserverInit),this.refresh())}pause(e){this.started&&(this.mutationObserver.disconnect(),this.started=!1),e(),this.started||(this.mutationObserver.observe(this.element,this.mutationObserverInit),this.started=!0)}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started){let e=new Set(this.matchElementsInTree());for(let t of Array.from(this.elements))e.has(t)||this.removeElement(t);for(let t of Array.from(e))this.addElement(t)}}processMutations(e){if(this.started)for(let t of e)this.processMutation(t)}processMutation(e){e.type=="attributes"?this.processAttributeChange(e.target,e.attributeName):e.type=="childList"&&(this.processRemovedNodes(e.removedNodes),this.processAddedNodes(e.addedNodes))}processAttributeChange(e,t){let i=e;this.elements.has(i)?this.delegate.elementAttributeChanged&&this.matchElement(i)?this.delegate.elementAttributeChanged(i,t):this.removeElement(i):this.matchElement(i)&&this.addElement(i)}processRemovedNodes(e){for(let t of Array.from(e)){let i=this.elementFromNode(t);i&&this.processTree(i,this.removeElement)}}processAddedNodes(e){for(let t of Array.from(e)){let i=this.elementFromNode(t);i&&this.elementIsActive(i)&&this.processTree(i,this.addElement)}}matchElement(e){return this.delegate.matchElement(e)}matchElementsInTree(e=this.element){return this.delegate.matchElementsInTree(e)}processTree(e,t){for(let i of this.matchElementsInTree(e))t.call(this,i)}elementFromNode(e){if(e.nodeType==Node.ELEMENT_NODE)return e}elementIsActive(e){return e.isConnected!=this.element.isConnected?!1:this.element.contains(e)}addElement(e){this.elements.has(e)||this.elementIsActive(e)&&(this.elements.add(e),this.delegate.elementMatched&&this.delegate.elementMatched(e))}removeElement(e){this.elements.has(e)&&(this.elements.delete(e),this.delegate.elementUnmatched&&this.delegate.elementUnmatched(e))}},Fa=class{constructor(e,t,i){this.attributeName=t,this.delegate=i,this.elementObserver=new Na(e,this)}get element(){return this.elementObserver.element}get selector(){return`[${this.attributeName}]`}start(){this.elementObserver.start()}pause(e){this.elementObserver.pause(e)}stop(){this.elementObserver.stop()}refresh(){this.elementObserver.refresh()}get started(){return this.elementObserver.started}matchElement(e){return e.hasAttribute(this.attributeName)}matchElementsInTree(e){let t=this.matchElement(e)?[e]:[],i=Array.from(e.querySelectorAll(this.selector));return t.concat(i)}elementMatched(e){this.delegate.elementMatchedAttribute&&this.delegate.elementMatchedAttribute(e,this.attributeName)}elementUnmatched(e){this.delegate.elementUnmatchedAttribute&&this.delegate.elementUnmatchedAttribute(e,this.attributeName)}elementAttributeChanged(e,t){this.delegate.elementAttributeValueChanged&&this.attributeName==t&&this.delegate.elementAttributeValueChanged(e,t)}},Va=class{constructor(e,t){this.element=e,this.delegate=t,this.started=!1,this.stringMap=new Map,this.mutationObserver=new MutationObserver(i=>this.processMutations(i))}start(){this.started||(this.started=!0,this.mutationObserver.observe(this.element,{attributes:!0,attributeOldValue:!0}),this.refresh())}stop(){this.started&&(this.mutationObserver.takeRecords(),this.mutationObserver.disconnect(),this.started=!1)}refresh(){if(this.started)for(let e of this.knownAttributeNames)this.refreshAttribute(e,null)}processMutations(e){if(this.started)for(let t of e)this.processMutation(t)}processMutation(e){let t=e.attributeName;t&&this.refreshAttribute(t,e.oldValue)}refreshAttribute(e,t){let i=this.delegate.getStringMapKeyForAttribute(e);if(i!=null){this.stringMap.has(e)||this.stringMapKeyAdded(i,e);let s=this.element.getAttribute(e);if(this.stringMap.get(e)!=s&&this.stringMapValueChanged(s,i,t),s==null){let r=this.stringMap.get(e);this.stringMap.delete(e),r&&this.stringMapKeyRemoved(i,e,r)}else this.stringMap.set(e,s)}}stringMapKeyAdded(e,t){this.delegate.stringMapKeyAdded&&this.delegate.stringMapKeyAdded(e,t)}stringMapValueChanged(e,t,i){this.delegate.stringMapValueChanged&&this.delegate.stringMapValueChanged(e,t,i)}stringMapKeyRemoved(e,t,i){this.delegate.stringMapKeyRemoved&&this.delegate.stringMapKeyRemoved(e,t,i)}get knownAttributeNames(){return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)))}get currentAttributeNames(){return Array.from(this.element.attributes).map(e=>e.name)}get recordedAttributeNames(){return Array.from(this.stringMap.keys())}};function Em(n,e,t){Ha(n,e).add(t)}function Mm(n,e,t){Ha(n,e).delete(t),Tm(n,e)}function Ha(n,e){let t=n.get(e);return t||(t=new Set,n.set(e,t)),t}function Tm(n,e){let t=n.get(e);t!=null&&t.size==0&&n.delete(e)}var Gn=class{constructor(){this.valuesByKey=new Map}get keys(){return Array.from(this.valuesByKey.keys())}get values(){return Array.from(this.valuesByKey.values()).reduce((t,i)=>t.concat(Array.from(i)),[])}get size(){return Array.from(this.valuesByKey.values()).reduce((t,i)=>t+i.size,0)}add(e,t){Em(this.valuesByKey,e,t)}delete(e,t){Mm(this.valuesByKey,e,t)}has(e,t){let i=this.valuesByKey.get(e);return i!=null&&i.has(t)}hasKey(e){return this.valuesByKey.has(e)}hasValue(e){return Array.from(this.valuesByKey.values()).some(i=>i.has(e))}getValuesForKey(e){let t=this.valuesByKey.get(e);return t?Array.from(t):[]}getKeysForValue(e){return Array.from(this.valuesByKey).filter(([t,i])=>i.has(e)).map(([t,i])=>t)}};var xr=class{constructor(e,t,i){this.attributeObserver=new Fa(e,t,this),this.delegate=i,this.tokensByElement=new Gn}get started(){return this.attributeObserver.started}start(){this.attributeObserver.start()}pause(e){this.attributeObserver.pause(e)}stop(){this.attributeObserver.stop()}refresh(){this.attributeObserver.refresh()}get element(){return this.attributeObserver.element}get attributeName(){return this.attributeObserver.attributeName}elementMatchedAttribute(e){this.tokensMatched(this.readTokensForElement(e))}elementAttributeValueChanged(e){let[t,i]=this.refreshTokensForElement(e);this.tokensUnmatched(t),this.tokensMatched(i)}elementUnmatchedAttribute(e){this.tokensUnmatched(this.tokensByElement.getValuesForKey(e))}tokensMatched(e){e.forEach(t=>this.tokenMatched(t))}tokensUnmatched(e){e.forEach(t=>this.tokenUnmatched(t))}tokenMatched(e){this.delegate.tokenMatched(e),this.tokensByElement.add(e.element,e)}tokenUnmatched(e){this.delegate.tokenUnmatched(e),this.tokensByElement.delete(e.element,e)}refreshTokensForElement(e){let t=this.tokensByElement.getValuesForKey(e),i=this.readTokensForElement(e),s=Rm(t,i).findIndex(([r,o])=>!Pm(r,o));return s==-1?[[],[]]:[t.slice(s),i.slice(s)]}readTokensForElement(e){let t=this.attributeName,i=e.getAttribute(t)||"";return Lm(i,e,t)}};function Lm(n,e,t){return n.trim().split(/\s+/).filter(i=>i.length).map((i,s)=>({element:e,attributeName:t,content:i,index:s}))}function Rm(n,e){let t=Math.max(n.length,e.length);return Array.from({length:t},(i,s)=>[n[s],e[s]])}function Pm(n,e){return n&&e&&n.index==e.index&&n.content==e.content}var kr=class{constructor(e,t,i){this.tokenListObserver=new xr(e,t,this),this.delegate=i,this.parseResultsByToken=new WeakMap,this.valuesByTokenByElement=new WeakMap}get started(){return this.tokenListObserver.started}start(){this.tokenListObserver.start()}stop(){this.tokenListObserver.stop()}refresh(){this.tokenListObserver.refresh()}get element(){return this.tokenListObserver.element}get attributeName(){return this.tokenListObserver.attributeName}tokenMatched(e){let{element:t}=e,{value:i}=this.fetchParseResultForToken(e);i&&(this.fetchValuesByTokenForElement(t).set(e,i),this.delegate.elementMatchedValue(t,i))}tokenUnmatched(e){let{element:t}=e,{value:i}=this.fetchParseResultForToken(e);i&&(this.fetchValuesByTokenForElement(t).delete(e),this.delegate.elementUnmatchedValue(t,i))}fetchParseResultForToken(e){let t=this.parseResultsByToken.get(e);return t||(t=this.parseToken(e),this.parseResultsByToken.set(e,t)),t}fetchValuesByTokenForElement(e){let t=this.valuesByTokenByElement.get(e);return t||(t=new Map,this.valuesByTokenByElement.set(e,t)),t}parseToken(e){try{return{value:this.delegate.parseValueForToken(e)}}catch(t){return{error:t}}}},qa=class{constructor(e,t){this.context=e,this.delegate=t,this.bindingsByAction=new Map}start(){this.valueListObserver||(this.valueListObserver=new kr(this.element,this.actionAttribute,this),this.valueListObserver.start())}stop(){this.valueListObserver&&(this.valueListObserver.stop(),delete this.valueListObserver,this.disconnectAllActions())}get element(){return this.context.element}get identifier(){return this.context.identifier}get actionAttribute(){return this.schema.actionAttribute}get schema(){return this.context.schema}get bindings(){return Array.from(this.bindingsByAction.values())}connectAction(e){let t=new Ia(this.context,e);this.bindingsByAction.set(e,t),this.delegate.bindingConnected(t)}disconnectAction(e){let t=this.bindingsByAction.get(e);t&&(this.bindingsByAction.delete(e),this.delegate.bindingDisconnected(t))}disconnectAllActions(){this.bindings.forEach(e=>this.delegate.bindingDisconnected(e)),this.bindingsByAction.clear()}parseValueForToken(e){let t=Ba.forToken(e);if(t.identifier==this.identifier)return t}elementMatchedValue(e,t){this.connectAction(t)}elementUnmatchedValue(e,t){this.disconnectAction(t)}},Wa=class{constructor(e,t){this.context=e,this.receiver=t,this.stringMapObserver=new Va(this.element,this),this.valueDescriptorMap=this.controller.valueDescriptorMap,this.invokeChangedCallbacksForDefaultValues()}start(){this.stringMapObserver.start()}stop(){this.stringMapObserver.stop()}get element(){return this.context.element}get controller(){return this.context.controller}getStringMapKeyForAttribute(e){if(e in this.valueDescriptorMap)return this.valueDescriptorMap[e].name}stringMapKeyAdded(e,t){let i=this.valueDescriptorMap[t];this.hasValue(e)||this.invokeChangedCallback(e,i.writer(this.receiver[e]),i.writer(i.defaultValue))}stringMapValueChanged(e,t,i){let s=this.valueDescriptorNameMap[t];e!==null&&(i===null&&(i=s.writer(s.defaultValue)),this.invokeChangedCallback(t,e,i))}stringMapKeyRemoved(e,t,i){let s=this.valueDescriptorNameMap[e];this.hasValue(e)?this.invokeChangedCallback(e,s.writer(this.receiver[e]),i):this.invokeChangedCallback(e,s.writer(s.defaultValue),i)}invokeChangedCallbacksForDefaultValues(){for(let{key:e,name:t,defaultValue:i,writer:s}of this.valueDescriptors)i!=null&&!this.controller.data.has(e)&&this.invokeChangedCallback(t,s(i),void 0)}invokeChangedCallback(e,t,i){let s=`${e}Changed`,r=this.receiver[s];if(typeof r=="function"){let o=this.valueDescriptorNameMap[e],l=o.reader(t),a=i;i&&(a=o.reader(i)),r.call(this.receiver,l,a)}}get valueDescriptors(){let{valueDescriptorMap:e}=this;return Object.keys(e).map(t=>e[t])}get valueDescriptorNameMap(){let e={};return Object.keys(this.valueDescriptorMap).forEach(t=>{let i=this.valueDescriptorMap[t];e[i.name]=i}),e}hasValue(e){let t=this.valueDescriptorNameMap[e],i=`has${_n(t.name)}`;return this.receiver[i]}},za=class{constructor(e,t){this.context=e,this.delegate=t,this.targetsByName=new Gn}start(){this.tokenListObserver||(this.tokenListObserver=new xr(this.element,this.attributeName,this),this.tokenListObserver.start())}stop(){this.tokenListObserver&&(this.disconnectAllTargets(),this.tokenListObserver.stop(),delete this.tokenListObserver)}tokenMatched({element:e,content:t}){this.scope.containsElement(e)&&this.connectTarget(e,t)}tokenUnmatched({element:e,content:t}){this.disconnectTarget(e,t)}connectTarget(e,t){var i;this.targetsByName.has(t,e)||(this.targetsByName.add(t,e),(i=this.tokenListObserver)===null||i===void 0||i.pause(()=>this.delegate.targetConnected(e,t)))}disconnectTarget(e,t){var i;this.targetsByName.has(t,e)&&(this.targetsByName.delete(t,e),(i=this.tokenListObserver)===null||i===void 0||i.pause(()=>this.delegate.targetDisconnected(e,t)))}disconnectAllTargets(){for(let e of this.targetsByName.keys)for(let t of this.targetsByName.getValuesForKey(e))this.disconnectTarget(t,e)}get attributeName(){return`data-${this.context.identifier}-target`}get element(){return this.context.element}get scope(){return this.context.scope}},$a=class{constructor(e,t){this.logDebugActivity=(i,s={})=>{let{identifier:r,controller:o,element:l}=this;s=Object.assign({identifier:r,controller:o,element:l},s),this.application.logDebugActivity(this.identifier,i,s)},this.module=e,this.scope=t,this.controller=new e.controllerConstructor(this),this.bindingObserver=new qa(this,this.dispatcher),this.valueObserver=new Wa(this,this.controller),this.targetObserver=new za(this,this);try{this.controller.initialize(),this.logDebugActivity("initialize")}catch(i){this.handleError(i,"initializing controller")}}connect(){this.bindingObserver.start(),this.valueObserver.start(),this.targetObserver.start();try{this.controller.connect(),this.logDebugActivity("connect")}catch(e){this.handleError(e,"connecting controller")}}disconnect(){try{this.controller.disconnect(),this.logDebugActivity("disconnect")}catch(e){this.handleError(e,"disconnecting controller")}this.targetObserver.stop(),this.valueObserver.stop(),this.bindingObserver.stop()}get application(){return this.module.application}get identifier(){return this.module.identifier}get schema(){return this.application.schema}get dispatcher(){return this.application.dispatcher}get element(){return this.scope.element}get parentElement(){return this.element.parentElement}handleError(e,t,i={}){let{identifier:s,controller:r,element:o}=this;i=Object.assign({identifier:s,controller:r,element:o},i),this.application.handleError(e,`Error ${t}`,i)}targetConnected(e,t){this.invokeControllerMethod(`${t}TargetConnected`,e)}targetDisconnected(e,t){this.invokeControllerMethod(`${t}TargetDisconnected`,e)}invokeControllerMethod(e,...t){let i=this.controller;typeof i[e]=="function"&&i[e](...t)}};function Cr(n,e){let t=ja(n);return Array.from(t.reduce((i,s)=>(Dm(s,e).forEach(r=>i.add(r)),i),new Set))}function Om(n,e){return ja(n).reduce((i,s)=>(i.push(...Bm(s,e)),i),[])}function ja(n){let e=[];for(;n;)e.push(n),n=Object.getPrototypeOf(n);return e.reverse()}function Dm(n,e){let t=n[e];return Array.isArray(t)?t:[]}function Bm(n,e){let t=n[e];return t?Object.keys(t).map(i=>[i,t[i]]):[]}function Im(n){return Nm(n,Fm(n))}function Nm(n,e){let t=Wm(n),i=Vm(n.prototype,e);return Object.defineProperties(t.prototype,i),t}function Fm(n){return Cr(n,"blessings").reduce((t,i)=>{let s=i(n);for(let r in s){let o=t[r]||{};t[r]=Object.assign(o,s[r])}return t},{})}function Vm(n,e){return qm(e).reduce((t,i)=>{let s=Hm(n,e,i);return s&&Object.assign(t,{[i]:s}),t},{})}function Hm(n,e,t){let i=Object.getOwnPropertyDescriptor(n,t);if(!(i&&"value"in i)){let r=Object.getOwnPropertyDescriptor(e,t).value;return i&&(r.get=i.get||r.get,r.set=i.set||r.set),r}}var qm=(()=>typeof Object.getOwnPropertySymbols=="function"?n=>[...Object.getOwnPropertyNames(n),...Object.getOwnPropertySymbols(n)]:Object.getOwnPropertyNames)(),Wm=(()=>{function n(t){function i(){return Reflect.construct(t,arguments,new.target)}return i.prototype=Object.create(t.prototype,{constructor:{value:i}}),Reflect.setPrototypeOf(i,t),i}function e(){let i=n(function(){this.a.call(this)});return i.prototype.a=function(){},new i}try{return e(),n}catch{return i=>class extends i{}}})();function zm(n){return{identifier:n.identifier,controllerConstructor:Im(n.controllerConstructor)}}var Ua=class{constructor(e,t){this.application=e,this.definition=zm(t),this.contextsByScope=new WeakMap,this.connectedContexts=new Set}get identifier(){return this.definition.identifier}get controllerConstructor(){return this.definition.controllerConstructor}get contexts(){return Array.from(this.connectedContexts)}connectContextForScope(e){let t=this.fetchContextForScope(e);this.connectedContexts.add(t),t.connect()}disconnectContextForScope(e){let t=this.contextsByScope.get(e);t&&(this.connectedContexts.delete(t),t.disconnect())}fetchContextForScope(e){let t=this.contextsByScope.get(e);return t||(t=new $a(this,e),this.contextsByScope.set(e,t)),t}},Ka=class{constructor(e){this.scope=e}has(e){return this.data.has(this.getDataKey(e))}get(e){return this.getAll(e)[0]}getAll(e){let t=this.data.get(this.getDataKey(e))||"";return km(t)}getAttributeName(e){return this.data.getAttributeNameForKey(this.getDataKey(e))}getDataKey(e){return`${e}-class`}get data(){return this.scope.data}},_a=class{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get(e){let t=this.getAttributeNameForKey(e);return this.element.getAttribute(t)}set(e,t){let i=this.getAttributeNameForKey(e);return this.element.setAttribute(i,t),this.get(e)}has(e){let t=this.getAttributeNameForKey(e);return this.element.hasAttribute(t)}delete(e){if(this.has(e)){let t=this.getAttributeNameForKey(e);return this.element.removeAttribute(t),!0}else return!1}getAttributeNameForKey(e){return`data-${this.identifier}-${Da(e)}`}},Ga=class{constructor(e){this.warnedKeysByObject=new WeakMap,this.logger=e}warn(e,t,i){let s=this.warnedKeysByObject.get(e);s||(s=new Set,this.warnedKeysByObject.set(e,s)),s.has(t)||(s.add(t),this.logger.warn(i,e))}};function Sr(n,e){return`[${n}~="${e}"]`}var Ja=class{constructor(e){this.scope=e}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get schema(){return this.scope.schema}has(e){return this.find(e)!=null}find(...e){return e.reduce((t,i)=>t||this.findTarget(i)||this.findLegacyTarget(i),void 0)}findAll(...e){return e.reduce((t,i)=>[...t,...this.findAllTargets(i),...this.findAllLegacyTargets(i)],[])}findTarget(e){let t=this.getSelectorForTargetName(e);return this.scope.findElement(t)}findAllTargets(e){let t=this.getSelectorForTargetName(e);return this.scope.findAllElements(t)}getSelectorForTargetName(e){let t=this.schema.targetAttributeForScope(this.identifier);return Sr(t,e)}findLegacyTarget(e){let t=this.getLegacySelectorForTargetName(e);return this.deprecate(this.scope.findElement(t),e)}findAllLegacyTargets(e){let t=this.getLegacySelectorForTargetName(e);return this.scope.findAllElements(t).map(i=>this.deprecate(i,e))}getLegacySelectorForTargetName(e){let t=`${this.identifier}.${e}`;return Sr(this.schema.targetAttribute,t)}deprecate(e,t){if(e){let{identifier:i}=this,s=this.schema.targetAttribute,r=this.schema.targetAttributeForScope(i);this.guide.warn(e,`target:${t}`,`Please replace ${s}="${i}.${t}" with ${r}="${t}". The ${s} attribute is deprecated and will be removed in a future version of Stimulus.`)}return e}get guide(){return this.scope.guide}},Ya=class{constructor(e,t,i,s){this.targets=new Ja(this),this.classes=new Ka(this),this.data=new _a(this),this.containsElement=r=>r.closest(this.controllerSelector)===this.element,this.schema=e,this.element=t,this.identifier=i,this.guide=new Ga(s)}findElement(e){return this.element.matches(e)?this.element:this.queryElements(e).find(this.containsElement)}findAllElements(e){return[...this.element.matches(e)?[this.element]:[],...this.queryElements(e).filter(this.containsElement)]}queryElements(e){return Array.from(this.element.querySelectorAll(e))}get controllerSelector(){return Sr(this.schema.controllerAttribute,this.identifier)}},Xa=class{constructor(e,t,i){this.element=e,this.schema=t,this.delegate=i,this.valueListObserver=new kr(this.element,this.controllerAttribute,this),this.scopesByIdentifierByElement=new WeakMap,this.scopeReferenceCounts=new WeakMap}start(){this.valueListObserver.start()}stop(){this.valueListObserver.stop()}get controllerAttribute(){return this.schema.controllerAttribute}parseValueForToken(e){let{element:t,content:i}=e,s=this.fetchScopesByIdentifierForElement(t),r=s.get(i);return r||(r=this.delegate.createScopeForElementAndIdentifier(t,i),s.set(i,r)),r}elementMatchedValue(e,t){let i=(this.scopeReferenceCounts.get(t)||0)+1;this.scopeReferenceCounts.set(t,i),i==1&&this.delegate.scopeConnected(t)}elementUnmatchedValue(e,t){let i=this.scopeReferenceCounts.get(t);i&&(this.scopeReferenceCounts.set(t,i-1),i==1&&this.delegate.scopeDisconnected(t))}fetchScopesByIdentifierForElement(e){let t=this.scopesByIdentifierByElement.get(e);return t||(t=new Map,this.scopesByIdentifierByElement.set(e,t)),t}},Qa=class{constructor(e){this.application=e,this.scopeObserver=new Xa(this.element,this.schema,this),this.scopesByIdentifier=new Gn,this.modulesByIdentifier=new Map}get element(){return this.application.element}get schema(){return this.application.schema}get logger(){return this.application.logger}get controllerAttribute(){return this.schema.controllerAttribute}get modules(){return Array.from(this.modulesByIdentifier.values())}get contexts(){return this.modules.reduce((e,t)=>e.concat(t.contexts),[])}start(){this.scopeObserver.start()}stop(){this.scopeObserver.stop()}loadDefinition(e){this.unloadIdentifier(e.identifier);let t=new Ua(this.application,e);this.connectModule(t)}unloadIdentifier(e){let t=this.modulesByIdentifier.get(e);t&&this.disconnectModule(t)}getContextForElementAndIdentifier(e,t){let i=this.modulesByIdentifier.get(t);if(i)return i.contexts.find(s=>s.element==e)}handleError(e,t,i){this.application.handleError(e,t,i)}createScopeForElementAndIdentifier(e,t){return new Ya(this.schema,e,t,this.logger)}scopeConnected(e){this.scopesByIdentifier.add(e.identifier,e);let t=this.modulesByIdentifier.get(e.identifier);t&&t.connectContextForScope(e)}scopeDisconnected(e){this.scopesByIdentifier.delete(e.identifier,e);let t=this.modulesByIdentifier.get(e.identifier);t&&t.disconnectContextForScope(e)}connectModule(e){this.modulesByIdentifier.set(e.identifier,e),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(i=>e.connectContextForScope(i))}disconnectModule(e){this.modulesByIdentifier.delete(e.identifier),this.scopesByIdentifier.getValuesForKey(e.identifier).forEach(i=>e.disconnectContextForScope(i))}},$m={controllerAttribute:"data-controller",actionAttribute:"data-action",targetAttribute:"data-target",targetAttributeForScope:n=>`data-${n}-target`},$i=class{constructor(e=document.documentElement,t=$m){this.logger=console,this.debug=!1,this.logDebugActivity=(i,s,r={})=>{this.debug&&this.logFormattedMessage(i,s,r)},this.element=e,this.schema=t,this.dispatcher=new Pa(this),this.router=new Qa(this)}static start(e,t){let i=new $i(e,t);return i.start(),i}async start(){await jm(),this.logDebugActivity("application","starting"),this.dispatcher.start(),this.router.start(),this.logDebugActivity("application","start")}stop(){this.logDebugActivity("application","stopping"),this.dispatcher.stop(),this.router.stop(),this.logDebugActivity("application","stop")}register(e,t){t.shouldLoad&&this.load({identifier:e,controllerConstructor:t})}load(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(s=>this.router.loadDefinition(s))}unload(e,...t){(Array.isArray(e)?e:[e,...t]).forEach(s=>this.router.unloadIdentifier(s))}get controllers(){return this.router.contexts.map(e=>e.controller)}getControllerForElementAndIdentifier(e,t){let i=this.router.getContextForElementAndIdentifier(e,t);return i?i.controller:null}handleError(e,t,i){var s;this.logger.error(`%s
|
27
|
+
|
28
|
+
%o
|
29
|
+
|
30
|
+
%o`,t,e,i),(s=window.onerror)===null||s===void 0||s.call(window,t,"",0,0,e)}logFormattedMessage(e,t,i={}){i=Object.assign({application:this},i),this.logger.groupCollapsed(`${e} #${t}`),this.logger.log("details:",Object.assign({},i)),this.logger.groupEnd()}};function jm(){return new Promise(n=>{document.readyState=="loading"?document.addEventListener("DOMContentLoaded",()=>n()):n()})}function Um(n){return Cr(n,"classes").reduce((t,i)=>Object.assign(t,Km(i)),{})}function Km(n){return{[`${n}Class`]:{get(){let{classes:e}=this;if(e.has(n))return e.get(n);{let t=e.getAttributeName(n);throw new Error(`Missing attribute "${t}"`)}}},[`${n}Classes`]:{get(){return this.classes.getAll(n)}},[`has${_n(n)}Class`]:{get(){return this.classes.has(n)}}}}function _m(n){return Cr(n,"targets").reduce((t,i)=>Object.assign(t,Gm(i)),{})}function Gm(n){return{[`${n}Target`]:{get(){let e=this.targets.find(n);if(e)return e;throw new Error(`Missing target element "${n}" for "${this.identifier}" controller`)}},[`${n}Targets`]:{get(){return this.targets.findAll(n)}},[`has${_n(n)}Target`]:{get(){return this.targets.has(n)}}}}function Jm(n){let e=Om(n,"values"),t={valueDescriptorMap:{get(){return e.reduce((i,s)=>{let r=Za(s),o=this.data.getAttributeNameForKey(r.key);return Object.assign(i,{[o]:r})},{})}}};return e.reduce((i,s)=>Object.assign(i,Ym(s)),t)}function Ym(n){let e=Za(n),{key:t,name:i,reader:s,writer:r}=e;return{[i]:{get(){let o=this.data.get(t);return o!==null?s(o):e.defaultValue},set(o){o===void 0?this.data.delete(t):this.data.set(t,r(o))}},[`has${_n(i)}`]:{get(){return this.data.has(t)||e.hasCustomDefaultValue}}}}function Za([n,e]){return eg(n,e)}function Ar(n){switch(n){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function Er(n){switch(typeof n){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}if(Array.isArray(n))return"array";if(Object.prototype.toString.call(n)==="[object Object]")return"object"}function Xm(n){let e=Ar(n.type);if(e){let t=Er(n.default);if(e!==t)throw new Error(`Type "${e}" must match the type of the default value. Given default value: "${n.default}" as "${t}"`);return e}}function Qm(n){let e=Xm(n),t=Er(n),i=Ar(n),s=e||t||i;if(s)return s;throw new Error(`Unknown value type "${n}"`)}function Zm(n){let e=Ar(n);if(e)return tg[e];let t=n.default;return t!==void 0?t:n}function eg(n,e){let t=`${Da(n)}-value`,i=Qm(e);return{type:i,key:t,name:Oa(t),get defaultValue(){return Zm(e)},get hasCustomDefaultValue(){return Er(e)!==void 0},reader:ig[i],writer:Ta[i]||Ta.default}}var tg={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},ig={array(n){let e=JSON.parse(n);if(!Array.isArray(e))throw new TypeError("Expected array");return e},boolean(n){return!(n=="0"||n=="false")},number(n){return Number(n)},object(n){let e=JSON.parse(n);if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError("Expected object");return e},string(n){return n}},Ta={default:ng,array:La,object:La};function La(n){return JSON.stringify(n)}function ng(n){return`${n}`}var Me=class{constructor(e){this.context=e}static get shouldLoad(){return!0}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(e,{target:t=this.element,detail:i={},prefix:s=this.identifier,bubbles:r=!0,cancelable:o=!0}={}){let l=s?`${s}:${e}`:e,a=new CustomEvent(l,{detail:i,bubbles:r,cancelable:o});return t.dispatchEvent(a),a}};Me.blessings=[Um,_m,Jm];Me.targets=[];Me.values={};var Mr=class extends Me{connect(){console.log("Hello World!",this.element)}};var Tr=class extends Me{connect(){this.console=REPLConsole.installInto("console")}runCode(n){this.console.setInput(n.detail.selection),this.console.onEnterKey()}};var ji=class extends Me{debounce(n,e){window.clearTimeout(this.debounceTimer),this.debounceTimer=window.setTimeout(n,e)}getScripts(n){let e=()=>zi(this.urlValue,{query:{name:n.target.value}});this.debounce(e,500)}};Bi(ji,"targets",["input"]),Bi(ji,"values",{url:String});var Lr=class extends Me{getScript(n){zi(n.target.value)}};var di="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(n=>n?parseInt(n,36):1);for(let n=1;n<di.length;n++)di[n]+=di[n-1];function sg(n){for(let e=1;e<di.length;e+=2)if(di[e]>n)return di[e-1]<=n;return!1}function eh(n){return n>=127462&&n<=127487}var th=8205;function de(n,e,t=!0,i=!0){return(t?nh:rg)(n,e,i)}function nh(n,e,t){if(e==n.length)return e;e&&sh(n.charCodeAt(e))&&rh(n.charCodeAt(e-1))&&e--;let i=ne(n,e);for(e+=Se(i);e<n.length;){let s=ne(n,e);if(i==th||s==th||t&&sg(s))e+=Se(s),i=s;else if(eh(s)){let r=0,o=e-2;for(;o>=0&&eh(ne(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function rg(n,e,t){for(;e>0;){let i=nh(n,e-2,t);if(i<e)return i;e--}return 0}function sh(n){return n>=56320&&n<57344}function rh(n){return n>=55296&&n<56320}function ne(n,e){let t=n.charCodeAt(e);if(!rh(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return sh(i)?(t-55296<<10)+(i-56320)+65536:t}function mi(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function Se(n){return n<65536?1:2}function pt(n,e,t=n.length){let i=0;for(let s=0;s<t;)n.charCodeAt(s)==9?(i+=e-i%e,s++):(i++,s=de(n,s));return i}function Ui(n,e,t,i){for(let s=0,r=0;;){if(r>=e)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?t-r%t:1,s=de(n,s)}return i===!0?-1:n.length}var N=class{constructor(){}lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),qe.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){let i=[];return this.decompose(e,t,i,0),qe.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new pi(this),r=new pi(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new pi(this,e)}iterRange(e,t=this.length){return new Rr(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Pr(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?N.empty:e.length<=32?new X(e):qe.from(X.split(e,[]))}},X=class extends N{constructor(e,t=og(e)){super();this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new oh(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new X(ih(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=Jn(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new X(l,o.length+r.length));else{let a=l.length>>1;i.push(new X(l.slice(0,a)),new X(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof X))return super.replace(e,t,i);let s=Jn(this.text,Jn(i.text,ih(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new X(s,r):qe.from(X.split(s,[]),r)}sliceString(e,t=this.length,i=`
|
31
|
+
`){let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new X(i,s)),i=[],s=-1);return s>-1&&t.push(new X(i,s)),t}},qe=class extends N{constructor(e,t){super();this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if(i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>5-1&&a.lines>h>>5+1){let c=this.children.slice();return c[s]=a,new qe(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
|
32
|
+
`){let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof qe))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new X(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,h=-1,c=[];function u(d){let p;if(d.lines>r&&d instanceof qe)for(let g of d.children)u(g);else d.lines>o&&(a>o||!a)?(f(),l.push(d)):d instanceof X&&a&&(p=c[c.length-1])instanceof X&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new X(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&f(),a+=d.lines,h+=d.length+1,c.push(d))}function f(){a!=0&&(l.push(c.length==1?c[0]:qe.from(c,h)),h=-1,a=c.length=0)}for(let d of e)u(d);return f(),l.length==1?l[0]:new qe(l,t)}};N.empty=new X([""],0);function og(n){let e=-1;for(let t of n)e+=t.length+1;return e}function Jn(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function ih(n,e,t){return Jn(n,[""],e,t)}var pi=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof X?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof X?s.text.length:s.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
|
33
|
+
`,this;e--}else if(s instanceof X){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof X?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Rr=class{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new pi(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},Pr=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(N.prototype[Symbol.iterator]=function(){return this.iter()},pi.prototype[Symbol.iterator]=Rr.prototype[Symbol.iterator]=Pr.prototype[Symbol.iterator]=function(){return this});var oh=class{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}};var Or=/\r\n?|\n/,Z=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(Z||(Z={})),We=class{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){Dr(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new We(e)}composeDesc(e){return this.empty?e:e.empty?this:hh(this,e)}mapDesc(e,t=!1){return e.empty?this:Br(this,e,t)}mapPos(e,t=-1,i=Z.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=s+l;if(a<0){if(h>e)return r+(e-s);r+=l}else{if(i!=Z.Simple&&h>=e&&(i==Z.TrackDel&&s<e&&h>e||i==Z.TrackBefore&&s<e||i==Z.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=h}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new We(e)}},Q=class extends We{constructor(e,t){super(e);this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Dr(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return Br(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(N.empty);i.push(o?e.slice(r,r+o):N.empty)}r+=o}return new Q(t,i)}compose(e){return this.empty?e:e.empty?this:hh(this,e,!0)}map(e,t=!1){return e.empty?this:Br(this,e,t,!0)}iterChanges(e,t=!1){Dr(this,e,t)}get desc(){return new We(this.sections)}filter(e){let t=[],i=[],s=[],r=new bi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);xe(s,c,-1);let u=r.ins==-1?-1:r.off==0?r.ins:0;xe(t,c,u),u>0&&zt(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);xe(t,c,-1),xe(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new Q(t,i),filtered:new We(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<t&&xe(s,t-o,-1);let u=new Q(s,r);l=l?l.compose(u.map(l)):u,s=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let u of c)h(u);else if(c instanceof Q){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:u,to:f=u,insert:d}=c;if(u>f||u<0||f>t)throw new RangeError(`Invalid change range ${u} to ${f} (in doc of length ${t})`);let p=d?typeof d=="string"?N.of(d.split(i||Or)):d:N.empty,g=p.length;if(u==f&&g==0)return;u<o&&a(),u>o&&xe(s,u-o,-1),xe(s,f-u,g),zt(r,s,p),o=f}}return h(e),a(!l),l}static empty(e){return new Q(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(N.empty);i[s]=N.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new Q(t,i)}};function xe(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function zt(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(N.empty);n.push(t)}}function Dr(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let h=s,c=r,u=N.empty;for(;h+=l,c+=a,a&&i&&(u=u.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function Br(n,e,t,i=!1){let s=[],r=i?[]:null,o=new bi(n),l=new bi(e);for(let a=0,h=0;;)if(o.ins==-1)a+=o.len,o.next();else if(l.ins==-1&&h<a){let c=Math.min(l.len,a-h);l.forward(c),xe(s,c,-1),h+=c}else if(l.ins>=0&&(o.done||h<a||h==a&&(l.len<o.len||l.len==o.len&&!t))){for(xe(s,l.ins,-1);a>h&&!o.done&&a+o.len<h+l.len;)a+=o.len,o.next();h+=l.len,l.next()}else if(o.ins>=0){let c=0,u=a+o.len;for(;;)if(l.ins>=0&&h>a&&h+l.len<u)c+=l.ins,h+=l.len,l.next();else if(l.ins==-1&&h<u){let f=Math.min(l.len,u-h);c+=f,l.forward(f),h+=f}else break;xe(s,c,o.ins),r&&zt(r,s,o.text),a=u,o.next()}else{if(o.done&&l.done)return r?new Q(s,r):new We(s);throw new Error("Mismatched change set lengths")}}function hh(n,e,t=!1){let i=[],s=t?[]:null,r=new bi(n),o=new bi(e);for(let l=!1;;){if(r.done&&o.done)return s?new Q(i,s):new We(i);if(r.ins==0)xe(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)xe(i,0,o.ins,l),s&&zt(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;xe(i,a,c,l),s&&c&&zt(s,i,o.text)}else o.ins==-1?(xe(i,r.off?0:r.len,a,l),s&&zt(s,i,r.textBit(a))):(xe(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&zt(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}var bi=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?N.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?N.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},$t=class{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&16?this.to:this.from}get head(){return this.flags&16?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&4?-1:this.flags&8?1:0}get bidiLevel(){let e=this.flags&3;return e==3?null:e}get goalColumn(){let e=this.flags>>5;return e==33554431?void 0:e}map(e,t=-1){let i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new $t(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return m.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return m.range(this.anchor,i)}eq(e){return this.anchor==e.anchor&&this.head==e.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return m.range(e.anchor,e.head)}},m=class{constructor(e,t=0){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:m.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let t=0;t<this.ranges.length;t++)if(!this.ranges[t].eq(e.ranges[t]))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new m([this.main])}addRange(e,t=!0){return m.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,m.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new m(e.ranges.map(t=>$t.fromJSON(t)),e.main)}static single(e,t=e){return new m([m.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return lg(e.slice(),t);i=r.to}return new m(e,t)}static cursor(e,t=0,i,s){return new $t(e,e,(t==0?0:t<0?4:8)|(i==null?3:Math.min(2,i))|(s??33554431)<<5)}static range(e,t,i){let s=(i??33554431)<<5;return t<e?new $t(t,e,16|s|8):new $t(e,t,s|(t>e?4:0))}};function lg(n,e=0){let t=n[e];n.sort((i,s)=>i.from-s.from),e=n.indexOf(t);for(let i=1;i<n.length;i++){let s=n[i],r=n[i-1];if(s.empty?s.from<=r.to:s.from<r.to){let o=r.from,l=Math.max(s.to,r.to);i<=e&&e--,n.splice(--i,2,s.anchor>s.head?m.range(l,o):m.range(o,l))}}return new m(n,e)}function ch(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var Fr=0,S=class{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.extensions=r,this.id=Fr++,this.default=e([])}static define(e={}){return new S(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Vr),!!e.static,e.enables)}of(e){return new Ki([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ki(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ki(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}};function Vr(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}var Ki=class{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Fr++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let u of this.dependencies)u=="doc"?a=!0:u=="selection"?h=!0:(((t=e[u.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[u.id]);return{create(u){return u.values[o]=i(u),1},update(u,f){if(a&&f.docChanged||h&&(f.docChanged||f.selection)||c.some(d=>(jt(u,d)&1)>0)){let d=i(u);if(l?!lh(d,u.values[o],s):!s(d,u.values[o]))return u.values[o]=d,1}return 0},reconfigure(u,f){let d=i(u),p=f.config.address[r];if(p!=null){let g=Xn(f,p);if(l?lh(d,g,s):s(d,g))return u.values[o]=g,0}return u.values[o]=d,1}}}};function lh(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function ag(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let u=Xn(a,i[c]);if(s[c]==2)for(let f of u)h.push(f);else h.push(u)}return e.combine(h)}return{create(a){for(let h of i)jt(a,h);return a.values[o]=l(a),1},update(a,h){if(!r.some(u=>jt(a,u)&1))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=i.some(p=>jt(a,p)&1),u=h.config.facets[e.id],f=h.facet(e);if(u&&!c&&Vr(t,u))return a.values[o]=f,0;let d=l(a);return e.compare(d,f)?(a.values[o]=f,0):(a.values[o]=d,1)}}}var ah=S.define({static:!0}),z=class{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new z(Fr++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(ah).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}init(e){return[this,ah.of({field:this,create:e})]}get extension(){return this}},mt={lowest:4,low:3,default:2,high:1,highest:0};function Lt(n){return e=>new Hr(e,n)}var ze={lowest:Lt(mt.lowest),low:Lt(mt.low),default:Lt(mt.default),high:Lt(mt.high),highest:Lt(mt.highest),fallback:Lt(mt.lowest),extend:Lt(mt.high),override:Lt(mt.highest)},Hr=class{constructor(e,t){this.inner=e,this.prec=t}},Gi=class{of(e){return new Yn(this,e)}reconfigure(e){return Gi.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},Yn=class{constructor(e,t){this.compartment=e,this.inner=t}},_i=class{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let f of hg(e,t,o))f instanceof z?s.push(f):(r[f.facet.id]||(r[f.facet.id]=[])).push(f);let l=Object.create(null),a=[],h=[];for(let f of s)l[f.id]=h.length<<1,h.push(d=>f.slot(d));let c=i?.config.facets;for(let f in r){let d=r[f],p=d[0].facet,g=c&&c[f]||[];if(d.every(y=>y.type==0))if(l[p.id]=a.length<<1|1,Vr(g,d))a.push(i.facet(p));else{let y=p.combine(d.map(b=>b.value));a.push(i&&p.compare(y,i.facet(p))?i.facet(p):y)}else{for(let y of d)y.type==0?(l[y.id]=a.length<<1|1,a.push(y.value)):(l[y.id]=h.length<<1,h.push(b=>y.dynamicSlot(b)));l[p.id]=h.length<<1,h.push(y=>ag(y,p,d))}}let u=h.map(f=>f(l));return new _i(e,o,u,l,a,r)}};function hg(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a>=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof Yn&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof Yn){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof Hr)r(o.inner,o.prec);else if(o instanceof z)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Ki)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,l);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(h,l)}}return r(n,mt.default),i.reduce((o,l)=>o.concat(l))}function jt(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function Xn(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}var uh=S.define(),fh=S.define({combine:n=>n.some(e=>e),static:!0}),dh=S.define({combine:n=>n.length?n[0]:void 0,static:!0}),ph=S.define(),mh=S.define(),gh=S.define(),bh=S.define({combine:n=>n.length?n[0]:!1}),$e=class{constructor(e,t){this.type=e,this.value=t}static define(){return new yh}},yh=class{of(e){return new $e(this,e)}},vh=class{constructor(e){this.map=e}of(e){return new L(this,e)}},L=class{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new L(this.type,t)}is(e){return this.type==e}static define(e={}){return new vh(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}};L.reconfigure=L.define();L.appendConfig=L.define();var ee=class{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&ch(i,t.newLength),r.some(l=>l.type==ee.time)||(this.annotations=r.concat(ee.time.of(Date.now())))}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(ee.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};ee.time=$e.define();ee.userEvent=$e.define();ee.addToHistory=$e.define();ee.remote=$e.define();function cg(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function wh(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=Q.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:L.mapEffects(n.effects,s).concat(L.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Ir(n,e,t){let i=e.selection,s=gi(e.annotations);return e.userEvent&&(s=s.concat(ee.userEvent.of(e.userEvent))),{changes:e.changes instanceof Q?e.changes:Q.of(e.changes||[],t,n.facet(dh)),selection:i&&(i instanceof m?i:m.single(i.anchor,i.head)),effects:gi(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function Sh(n,e,t){let i=Ir(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=wh(i,Ir(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=new ee(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return fg(t?ug(s):s)}function ug(n){let e=n.startState,t=!0;for(let s of e.facet(ph)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:cg(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=Q.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.invertedDesc}n=new ee(e,s,n.selection&&n.selection.map(r),L.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(mh);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof ee?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof ee?n=r[0]:n=Sh(e,gi(r),!1)}return n}function fg(n){let e=n.startState,t=e.facet(gh),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=wh(n,Ir(e,r,n.changes.newLength),!0))}return i==n?n:new ee(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}var dg=[];function gi(n){return n==null?dg:Array.isArray(n)?n:[n]}var oe=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(oe||(oe={})),pg=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Nr;try{Nr=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function mg(n){if(Nr)return Nr.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||pg.test(t)))return!0}return!1}function gg(n){return e=>{if(!/\S/.test(e))return oe.Space;if(mg(e))return oe.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return oe.Word;return oe.Other}}var B=class{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)jt(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return jt(this,i),Xn(this,i)}update(...e){return Sh(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let o of e.effects)o.is(Gi.reconfigure)?(t&&(s=new Map,t.compartments.forEach((l,a)=>s.set(a,l)),t=null),s.set(o.value.compartment,o.value.extension)):o.is(L.reconfigure)?(t=null,i=o.value):o.is(L.appendConfig)&&(t=null,i=gi(i).concat(o.value));let r;t?r=e.startState.values.slice():(t=_i.resolve(i,s,this),r=new B(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,a)=>a.reconfigure(l,this),null).values),new B(t,e.newDoc,e.newSelection,r,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:m.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=gi(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(s);for(let f=0;f<l;f++)r[f]=r[f].map(c);let u=s.mapDesc(h,!0);r.push(a.range.map(u)),s=s.compose(c),o=L.mapEffects(o,c).concat(L.mapEffects(gi(a.effects),u))}return{changes:s,selection:m.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Q?e:Q.of(e,this.doc.length,this.facet(B.lineSeparator))}toText(e){return N.of(e.split(this.facet(B.lineSeparator)||Or))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(jt(this,t),Xn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof z&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i)for(let r in i){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}return B.create({doc:e.doc,selection:m.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=_i.resolve(e.extensions||[],new Map),i=e.doc instanceof N?e.doc:N.of((e.doc||"").split(t.staticFacet(B.lineSeparator)||Or)),s=e.selection?e.selection instanceof m?e.selection:m.single(e.selection.anchor,e.selection.head):m.single(0);return ch(s,i.length),t.staticFacet(fh)||(s=s.asSingle()),new B(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(B.tabSize)}get lineBreak(){return this.facet(B.lineSeparator)||`
|
34
|
+
`}get readOnly(){return this.facet(bh)}phrase(e){for(let t of this.facet(B.phrases))if(Object.prototype.hasOwnProperty.call(t,e))return t[e];return e}languageDataAt(e,t,i=-1){let s=[];for(let r of this.facet(uh))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){return gg(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=de(t,o,!1);if(r(t.slice(a,o))!=oe.Word)break;o=a}for(;l<s;){let a=de(t,l);if(r(t.slice(l,a))!=oe.Word)break;l=a}return o==l?null:m.range(o+i,l+i)}};B.allowMultipleSelections=fh;B.tabSize=S.define({combine:n=>n.length?n[0]:4});B.lineSeparator=dh;B.readOnly=bh;B.phrases=S.define();B.languageData=uh;B.changeFilter=ph;B.transactionFilter=mh;B.transactionExtender=gh;Gi.reconfigure=L.define();function pe(n,e,t={}){let i={};for(let s of n)for(let r of Object.keys(s)){let o=s[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)i[s]===void 0&&(i[s]=e[s]);return i}var qr="\u037C",xh=typeof Symbol>"u"?"__"+qr:Symbol.for(qr),Wr=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),kh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},je=class{constructor(e,t){this.rules=[];let{finish:i}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],u=/^@(\w+)\b/.exec(o[0]),f=u&&u[1]=="keyframes";if(u&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(g=>o.map(y=>g.replace(/&/,y))).reduce((g,y)=>g.concat(y)),p,a);else if(p&&typeof p=="object"){if(!u)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(s(d),p,c,f)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||f)&&a.push((i&&!u&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(s(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
35
|
+
`)}static newName(){let e=kh[xh]||1;return kh[xh]=e+1,qr+e.toString(36)}static mount(e,t){(e[Wr]||new Ch(e)).mount(Array.isArray(t)?t:[t])}},Qn=null,Ch=class{constructor(e){if(!e.head&&e.adoptedStyleSheets&&typeof CSSStyleSheet<"u"){if(Qn)return e.adoptedStyleSheets=[Qn.sheet].concat(e.adoptedStyleSheets),e[Wr]=Qn;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),Qn=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[Wr]=this}mount(e){let t=this.sheet,i=0,s=0;for(let r=0;r<e.length;r++){let o=e[r],l=this.modules.indexOf(o);if(l<s&&l>-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,o),t)for(let a=0;a<o.rules.length;a++)t.insertRule(o.rules[a],i++)}else{for(;s<l;)i+=this.modules[s++].rules.length;i+=o.rules.length,s++}}if(!t){let r="";for(let o=0;o<this.modules.length;o++)r+=this.modules[o].getRules()+`
|
36
|
+
`;this.styleTag.textContent=r}}};var Ue=class{eq(e){return this==e}range(e,t=e){return new ts(e,t,this)}};Ue.prototype.startSide=Ue.prototype.endSide=0;Ue.prototype.point=!1;Ue.prototype.mapMode=Z.TrackDel;var ts=class{constructor(e,t,i){this.from=e,this.to=t,this.value=i}};function $r(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}var is=class{constructor(e,t,i,s){this.from=e,this.to=t,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],c=this.from[a]+e,u=this.to[a]+e,f,d;if(c==u){let p=t.mapPos(c,h.startSide,h.mapMode);if(p==null||(f=d=p,h.startSide!=h.endSide&&(d=t.mapPos(c,h.endSide),d<f)))continue}else if(f=t.mapPos(c,h.startSide),d=t.mapPos(u,h.endSide),f>d||f==d&&h.startSide>0&&h.endSide<=0)continue;(d-f||h.endSide-h.startSide)<0||(o<0&&(o=f),h.point&&(l=Math.max(l,d-f)),i.push(h),s.push(f-o),r.push(d-o))}return{mapped:i.length?new is(s,r,i,l):null,pos:o}}},F=class{constructor(e,t,i=F.empty,s){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=s}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort($r)),this.isEmpty)return t.length?F.of(t):this;let l=new Ur(this,null,-1).goto(0),a=0,h=[],c=new Re;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let u=t[a++];c.addInner(u.from,u.to,u.value)||h.push(u)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value)||h.push(new ts(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?F.empty:this.nextLayer.update({add:h,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:c,pos:u}=a.map(l,e);c&&(s=Math.max(s,c.maxPoint),t.push(c),i.push(u))}}let r=this.nextLayer.map(e);return t.length==0?r:new F(i,t,r,s)}between(e,t,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return vi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return vi.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=r),l=t.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=r),a=Ah(o,l,i),h=new yi(o,a,r),c=new yi(l,a,r);i.iterGaps((u,f,d)=>Eh(h,u,c,f,d,s)),i.empty&&i.length==0&&Eh(h,0,c,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=1e9);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Ah(r,o),a=new yi(r,l,0).goto(i),h=new yi(o,l,0).goto(i);for(;;){if(a.to!=h.to||!jr(a.active,h.active)||a.point&&(!h.point||!a.point.eq(h.point)))return!1;if(a.to>s)return!0;a.next(),h.next()}}static spans(e,t,i,s,r=-1){var o;let l=new yi(e,null,r,(o=s.filterPoint)===null||o===void 0?void 0:o.bind(s)).goto(t),a=t,h=l.openStart;for(;;){let c=Math.min(l.to,i);if(l.point?(s.point(a,c,l.point,l.activeForPoint(l.to),h),h=l.openEnd(c)+(l.to>c?1:0)):c>a&&(s.span(a,c,l.active,h),h=l.openEnd(c)),l.to>i)break;a=l.to,l.next()}return h}static of(e,t=!1){let i=new Re;for(let s of e instanceof ts?[e]:t?bg(e):e)i.add(s.from,s.to,s.value);return i.finish()}};F.empty=new F([],[],null,-1);function bg(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if($r(e,i)>0)return n.slice().sort($r);e=i}return n}F.empty.nextLayer=F.empty;var Re=class{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}finishChunk(e){this.chunks.push(new is(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new Re)).add(e,t,i)}addInner(e,t,i){let s=e-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(F.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=new F(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function Ah(n,e,t){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!t?.touchesRange(l,l+r.chunk[o].length)&&s.add(r.chunk[o])}return s}var Ur=class{constructor(e,t,i,s=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},vi=class{constructor(e){this.heap=e}static from(e,t=null,i=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new Ur(o,t,i,r));return s.length==1?s[0]:new vi(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)zr(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)zr(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),zr(this.heap,0)}}};function zr(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let s=n[i];if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),t.compare(s)<0)break;n[i]=t,n[e]=s,e=i}}var yi=class{constructor(e,t,i,s=()=>!0){this.minPoint=i,this.filterPoint=s,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=vi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Zn(this.active,e),Zn(this.activeTo,e),Zn(this.activeRank,e),this.minActive=Mh(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&this.activeRank[t]<=r;)t++;es(this.active,t,i),es(this.activeTo,t,s),es(this.activeRank,t,r),e&&es(e,t,this.cursor.from),this.minActive=Mh(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null,s=0;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&Zn(i,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let o=this.cursor.value;if(!o.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else if(!this.filterPoint(this.cursor.from,this.cursor.to,this.cursor.value,this.cursor.rank))this.cursor.next();else{this.point=o,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=o.endSide,this.cursor.from<e&&(s=1),this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){let r=0;for(;r<i.length&&i[r]<e;)r++;this.openStart=r+s}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}};function Eh(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e;for(;;){let h=n.to+a-t.to||n.endSide-t.endSide,c=h<0?n.to+a:t.to,u=Math.min(c,o);if(n.point||t.point?n.point&&t.point&&(n.point==t.point||n.point.eq(t.point))&&jr(n.activeForPoint(n.to+a),t.activeForPoint(t.to))||r.comparePoint(l,u,n.point,t.point):u>l&&!jr(n.active,t.active)&&r.compareRange(l,u,n.active,t.active),c>o)break;l=c,h<=0&&n.next(),h>=0&&t.next()}}function jr(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!n[t].eq(e[t]))return!1;return!0}function Zn(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function es(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function Mh(n,e){let t=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||n[s].endSide-n[t].endSide)<0&&(t=s,i=e[s]);return t}var gt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",229:"q"},ss={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"',229:"Q"},Th=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),yg=typeof navigator<"u"&&/Apple Computer/.test(navigator.vendor),vg=typeof navigator<"u"&&/Gecko\/\d+/.test(navigator.userAgent),Lh=typeof navigator<"u"&&/Mac/.test(navigator.platform),wg=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Sg=Th&&(Lh||+Th[1]<57)||vg&&Lh;for(se=0;se<10;se++)gt[48+se]=gt[96+se]=String(se);var se;for(se=1;se<=24;se++)gt[se+111]="F"+se;var se;for(se=65;se<=90;se++)gt[se]=String.fromCharCode(se+32),ss[se]=String.fromCharCode(se);var se;for(ns in gt)ss.hasOwnProperty(ns)||(ss[ns]=gt[ns]);var ns;function Rh(n){var e=Sg&&(n.ctrlKey||n.altKey||n.metaKey)||(yg||wg)&&n.shiftKey&&n.key&&n.key.length==1,t=!e&&n.key||(n.shiftKey?ss:gt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function fs(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function Si(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function xg(){let n=document.activeElement;for(;n&&n.shadowRoot;)n=n.shadowRoot.activeElement;return n}function Zr(n,e){if(!e.anchorNode)return!1;try{return Si(n,e.anchorNode)}catch{return!1}}function nn(n){return n.nodeType==3?sn(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function ds(n,e,t,i){return t?Ph(n,e,t,i,-1)||Ph(n,e,t,i,1):!1}function eo(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Ph(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:ps(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=eo(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=s<0?ps(n):0}else return!1}}function ps(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}var uc={left:0,right:0,top:0,bottom:0};function ms(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function kg(n){return{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Cg(n,e,t,i,s,r,o,l){let a=n.ownerDocument,h=a.defaultView;for(let c=n;c;)if(c.nodeType==1){let u,f=c==a.body;if(f)u=kg(h);else{if(c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.parentNode;continue}let g=c.getBoundingClientRect();u={left:g.left,right:g.left+c.clientWidth,top:g.top,bottom:g.top+c.clientHeight}}let d=0,p=0;if(s=="nearest")e.top<u.top?(p=-(u.top-e.top+o),t>0&&e.bottom>u.bottom+p&&(p=e.bottom-u.bottom+p+o)):e.bottom>u.bottom&&(p=e.bottom-u.bottom+o,t<0&&e.top-p<u.top&&(p=-(u.top+p-e.top+o)));else{let g=e.bottom-e.top,y=u.bottom-u.top;p=(s=="center"&&g<=y?e.top+g/2-y/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-y+o)-u.top}if(i=="nearest"?e.left<u.left?(d=-(u.left-e.left+r),t>0&&e.right>u.right+d&&(d=e.right-u.right+d+r)):e.right>u.right&&(d=e.right-u.right+r,t<0&&e.left<u.left+d&&(d=-(u.left+d-e.left+r))):d=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,d||p)if(f)h.scrollBy(d,p);else{if(p){let g=c.scrollTop;c.scrollTop+=p,p=c.scrollTop-g}if(d){let g=c.scrollLeft;c.scrollLeft+=d,d=c.scrollLeft-g}e={left:e.left-d,top:e.top-p,right:e.right-d,bottom:e.bottom-p}}if(f)break;c=c.assignedSlot||c.parentNode,i=s="nearest"}else if(c.nodeType==11)c=c.host;else break}var fc=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){this.set(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}},wi=null;function dc(n){if(n.setActive)return n.setActive();if(wi)return n.focus(wi);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(wi==null?{get preventScroll(){return wi={preventScroll:!0},!0}}:void 0),!wi){wi=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}var Oh;function sn(n,e,t=e){let i=Oh||(Oh=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function tn(n,e,t){let i={key:e,code:e,keyCode:t,which:t,cancelable:!0},s=new KeyboardEvent("keydown",i);s.synthetic=!0,n.dispatchEvent(s);let r=new KeyboardEvent("keyup",i);return r.synthetic=!0,n.dispatchEvent(r),s.defaultPrevented||r.defaultPrevented}function Ag(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function pc(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}var ce=class{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new ce(e.parentNode,eo(e),t)}static after(e,t){return new ce(e.parentNode,eo(e)+1,t)}},Eo=[],G=class{constructor(){this.parent=null,this.dom=null,this.dirty=2}get editorView(){if(!this.parent)throw new Error("Accessing view in orphan content view");return this.parent.editorView}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let i of this.children){if(i==e)return t;t+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}coordsAt(e,t){return null}sync(e){if(this.dirty&2){let t=this.dom,i=t.firstChild;for(let s of this.children){if(s.dirty){if(!s.dom&&i){let r=G.get(i);(!r||!r.parent&&r.constructor==s.constructor)&&s.reuseDOM(i)}s.sync(e),s.dirty=0}if(e&&!e.written&&e.node==t&&i!=s.dom&&(e.written=!0),s.dom.parentNode==t){for(;i&&i!=s.dom;)i=Dh(i);i=s.dom.nextSibling}else t.insertBefore(s.dom,i)}for(i&&e&&e.node==t&&(e.written=!0);i;)i=Dh(i)}else if(this.dirty&1)for(let t of this.children)t.dirty&&(t.sync(e),t.dirty=0)}reuseDOM(e){}localPosFromDOM(e,t){let i;if(e==this.dom)i=this.dom.childNodes[t];else{let s=ps(e)==0?0:t==0?-1:1;for(;;){let r=e.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(e==r.firstChild?s=-1:s=1),e=r}s<0?i=e:i=e.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!G.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,i=0){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<this.children.length;a++){let u=this.children[a],f=h+u.length;if(h<e&&f>t)return u.domBoundsAround(e,t,h);if(f>=e&&s==-1&&(s=a,r=h),h>t&&u.dom.parentNode==this.dom){o=a,l=c;break}c=f,h=f+u.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.dirty|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.dirty|=2),t.dirty&1)return;t.dirty|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.dirty&&this.markParentsDirty(!0))}setDOM(e){this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=Eo){this.markDirty();for(let s=e;s<t;s++){let r=this.children[s];r.parent==this&&r.destroy()}this.children.splice(e,t-e,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new Mo(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}merge(e,t,i,s,r,o){return!1}become(e){return!1}getSide(){return 0}destroy(){this.parent=null}};G.prototype.breakAfter=0;function Dh(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}var Mo=class{constructor(e,t,i){this.children=e,this.pos=t,this.i=i,this.off=0}findPos(e,t=1){for(;;){if(e>this.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}};function mc(n,e,t,i,s,r,o,l,a){let{children:h}=n,c=h.length?h[e]:null,u=r.length?r[r.length-1]:null,f=u?u.breakAfter:o;if(!(e==i&&c&&!o&&!f&&r.length<2&&c.merge(t,s,r.length?u:null,t==0,l,a))){if(i<h.length){let d=h[i];d&&s<d.length?(e==i&&(d=d.split(s),s=0),!f&&u&&d.merge(0,s,u,!0,0,a)?r[r.length-1]=d:(s&&d.merge(0,s,null,!1,0,a),r.push(d))):d?.breakAfter&&(u?u.breakAfter=1:o=1),i++}for(c&&(c.breakAfter=o,t>0&&(!o&&r.length&&c.merge(t,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(t<c.length||c.children.length&&c.children[c.children.length-1].length==0)&&c.merge(t,c.length,null,!1,l,0),e++));e<i&&r.length;)if(h[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(h[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&i<h.length&&!h[e-1].breakAfter&&h[i].merge(0,0,h[e-1],!1,l,a)&&e--,(e<i||r.length)&&n.replaceChildren(e,i,r)}}function gc(n,e,t,i,s,r){let o=n.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:h,off:c}=o.findPos(e,-1),u=e-t;for(let f of i)u+=f.length;n.length+=u,mc(n,h,c,l,a,i,0,s,r)}var Pe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},to=typeof document<"u"?document:{documentElement:{style:{}}},io=/Edge\/(\d+)/.exec(Pe.userAgent),bc=/MSIE \d/.test(Pe.userAgent),no=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Pe.userAgent),gs=!!(bc||no||io),Bh=!gs&&/gecko\/(\d+)/i.test(Pe.userAgent),Kr=!gs&&/Chrome\/(\d+)/.exec(Pe.userAgent),Ih="webkitFontSmoothing"in to.documentElement.style,yc=!gs&&/Apple Computer/.test(Pe.vendor),Nh=yc&&(/Mobile\/\w+/.test(Pe.userAgent)||Pe.maxTouchPoints>2),R={mac:Nh||/Mac/.test(Pe.platform),windows:/Win/.test(Pe.platform),linux:/Linux|X11/.test(Pe.platform),ie:gs,ie_version:bc?to.documentMode||6:no?+no[1]:io?+io[1]:0,gecko:Bh,gecko_version:Bh?+(/Firefox\/(\d+)/.exec(Pe.userAgent)||[0,0])[1]:0,chrome:!!Kr,chrome_version:Kr?+Kr[1]:0,ios:Nh,android:/Android\b/.test(Pe.userAgent),webkit:Ih,safari:yc,webkit_version:Ih?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:to.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"},Eg=256,yt=class extends G{constructor(e){super();this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return i&&(!(i instanceof yt)||this.length-(t-e)+i.length>Eg)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new yt(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new ce(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return so(this.dom,e,t)}},Ke=class extends G{constructor(e,t=[],i=0){super();this.mark=e,this.children=t,this.length=i;for(let s of t)s.setParent(this)}setAttrs(e){if(pc(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.dirty|=6)}sync(e){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e)}merge(e,t,i,s,r,o){return i&&(!(i instanceof Ke&&i.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(gc(this,e,t,i?i.children:[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],i=0,s=-1,r=0;for(let l of this.children){let a=i+l.length;a>e&&t.push(i<e?l.split(e-i):l),s<0&&i>=e&&(s=r),i=a,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new Ke(this.mark,t,o)}domAtPos(e){return wc(this.dom,this.children,e)}coordsAt(e,t){return xc(this,e,t)}};function so(n,e,t){let i=n.nodeValue.length;e>i&&(e=i);let s=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?R.chrome||R.gecko||(e?(s--,o=1):(r++,o=-1)):t<0?s--:r++;let l=sn(n,s,r).getClientRects();if(!l.length)return uc;let a=l[(o?o<0:t>=0)?0:l.length-1];return R.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?ms(a,o<0):a||null}var bt=class extends G{constructor(e,t,i){super();this.widget=e,this.length=t,this.side=i,this.prevWidget=null}static create(e,t,i){return new(e.customView||bt)(e,t,i)}split(e){let t=bt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(e,t,i,s,r,o){return i&&(!(i instanceof bt)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}become(e){return e.length==this.length&&e instanceof bt&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.eq(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return N.empty;let e=this;for(;e.parent;)e=e.parent;let t=e.editorView,i=t&&t.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):N.empty}domAtPos(e){return e==0?ce.before(this.dom):ce.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.dom.getClientRects(),s=null;if(!i.length)return uc;for(let r=e>0?i.length-1:0;s=i[r],!(e>0?r==0:r==i.length-1||s.top<s.bottom);r+=e>0?-1:1);return e==0&&t>0||e==this.length&&t<=0?s:ms(s,e==0)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},To=class extends bt{domAtPos(e){let{topView:t,text:i}=this.widget;return t?ro(e,0,t,i,(s,r)=>s.domAtPos(r),s=>new ce(i,Math.min(s,i.nodeValue.length))):new ce(i,Math.min(e,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(e,t){let{topView:i,text:s}=this.widget;return i?vc(e,t,i,s):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:i,text:s}=this.widget;return i?ro(e,t,i,s,(r,o,l)=>r.coordsAt(o,l),(r,o)=>so(s,r,o)):so(s,e,t)}destroy(){var e;super.destroy(),(e=this.widget.topView)===null||e===void 0||e.destroy()}get isEditable(){return!0}};function ro(n,e,t,i,s,r){if(t instanceof Ke){for(let o of t.children){let l=Si(o.dom,i),a=l?i.nodeValue.length:o.length;if(n<a||n==a&&o.getSide()<=0)return l?ro(n,e,o,i,s,r):s(o,n,e);n-=a}return s(t,t.length,-1)}else return t.dom==i?r(n,e):s(t,n,e)}function vc(n,e,t,i){if(t instanceof Ke)for(let s of t.children){let r=0,o=Si(s.dom,i);if(Si(s.dom,n))return r+(o?vc(n,e,s,i):s.localPosFromDOM(n,e));r+=o?i.nodeValue.length:s.length}else if(t.dom==i)return Math.min(e,i.nodeValue.length);return t.localPosFromDOM(n,e)}var Gt=class extends G{constructor(e){super();this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof Gt&&e.side==this.side}split(){return new Gt(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return ce.before(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){let t=this.dom.getBoundingClientRect(),i=Mg(this,this.side>0?-1:1);return i&&i.top<t.bottom&&i.bottom>t.top?{left:t.left,right:t.right,top:i.top,bottom:i.bottom}:t}get overrideDOMText(){return N.empty}};yt.prototype.children=bt.prototype.children=Gt.prototype.children=Eo;function Mg(n,e){let t=n.parent,i=t?t.children.indexOf(n):-1;for(;t&&i>=0;)if(e<0?i>0:i<t.children.length){let s=t.children[i+e];if(s instanceof yt){let r=s.coordsAt(e<0?s.length:0,e);if(r)return r}i+=e}else if(t instanceof Ke&&t.parent)i=t.parent.children.indexOf(t)+(e<0?0:1),t=t.parent;else{let s=t.dom.lastChild;if(s&&s.nodeName=="BR")return s.getClientRects()[0];break}}function wc(n,e,t){let i=0;for(let s=0;i<e.length;i++){let r=e[i],o=s+r.length;if(!(o==s&&r.getSide()<=0)){if(t>s&&t<o&&r.dom.parentNode==n)return r.domAtPos(t-s);if(t<=s)break;s=o}}for(;i>0;i--){let s=e[i-1].dom;if(s.parentNode==n)return ce.after(s)}return new ce(n,0)}function Sc(n,e,t){let i,{children:s}=n;t>0&&e instanceof Ke&&s.length&&(i=s[s.length-1])instanceof Ke&&i.mark.eq(e.mark)?Sc(i,e.children[0],t-1):(s.push(e),e.setParent(n)),n.length+=e.length}function xc(n,e,t){for(let r=0,o=0;o<n.children.length;o++){let l=n.children[o],a=r+l.length,h;if((t<=0||a==n.length||l.getSide()>0?a>=e:a>e)&&(e<a||o+1==n.children.length||(h=n.children[o+1]).length||h.getSide()>0)){let c=0;if(a==r){if(l.getSide()<=0)continue;c=t=-l.getSide()}let u=l.coordsAt(Math.max(0,e-r),t);return c&&u?ms(u,t<0):u}r=a}let i=n.dom.lastChild;if(!i)return n.dom.getBoundingClientRect();let s=nn(i);return s[s.length-1]||null}function oo(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}function Lo(n,e){if(n==e)return!0;if(!n||!e)return!1;let t=Object.keys(n),i=Object.keys(e);if(t.length!=i.length)return!1;for(let s of t)if(i.indexOf(s)==-1||n[s]!==e[s])return!1;return!0}function lo(n,e,t){if(e)for(let i in e)t&&i in t||n.removeAttribute(i);if(t)for(let i in t)e&&e[i]==t[i]||n.setAttribute(i,t[i])}var De=class{eq(e){return!1}updateDOM(e){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}ignoreEvent(e){return!0}get customView(){return null}destroy(e){}},$=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}($||($={})),E=class extends Ue{constructor(e,t,i,s){super();this.startSide=e,this.endSide=t,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(e){return new on(e)}static widget(e){let t=e.side||0,i=!!e.block;return t+=i?t>0?3e8:-4e8:t>0?1e8:-1e8,new Dt(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,s;if(e.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=kc(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new Dt(e,i,s,t,e.widget||null,!0)}static line(e){return new xi(e)}static set(e,t=!1){return F.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};E.none=F.empty;var on=class extends E{constructor(e){let{start:t,end:i}=kc(e);super(t?-1:5e8,i?1:-6e8,null,e);this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){return this==e||e instanceof on&&this.tagName==e.tagName&&this.class==e.class&&Lo(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}};on.prototype.point=!1;var xi=class extends E{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof xi&&Lo(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}};xi.prototype.mapMode=Z.TrackBefore;xi.prototype.point=!0;var Dt=class extends E{constructor(e,t,i,s,r,o){super(t,i,r,e);this.block=s,this.isReplace=o,this.mapMode=s?t<=0?Z.TrackBefore:Z.TrackAfter:Z.TrackDel}get type(){return this.startSide<this.endSide?$.WidgetRange:this.startSide<=0?$.WidgetBefore:$.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&this.widget.estimatedHeight>=5}eq(e){return e instanceof Dt&&Tg(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}};Dt.prototype.point=!0;function kc(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function Tg(n,e){return n==e||!!(n&&e&&n.compare(e))}function ao(n,e,t,i=0){let s=t.length-1;s>=0&&t[s]+i>=n?t[s]=Math.max(t[s],e):t.push(n,e)}var me=class extends G{constructor(){super(...arguments);this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,s,r,o){if(i){if(!(i instanceof me))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),gc(this,e,t,i?i.children:[],r,o),!0}split(e){let t=new me;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:s}=this.childPos(e);s&&(t.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)t.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=e,t}transferDOM(e){!this.dom||(e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Lo(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Sc(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=oo(t,this.attrs||{})),i&&(this.attrs=oo({class:i},this.attrs||{}))}domAtPos(e){return wc(this.dom,this.children,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.dirty|=6)}sync(e){var t;this.dom?this.dirty&4&&(pc(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&&(lo(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e);let i=this.dom.lastChild;for(;i&&G.get(i)instanceof Ke;)i=i.lastChild;if(!i||!this.length||i.nodeName!="BR"&&((t=G.get(i))===null||t===void 0?void 0:t.isEditable)==!1&&(!R.ios||!this.children.some(s=>s instanceof yt))){let s=document.createElement("BR");s.cmIgnore=!0,this.dom.appendChild(s)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0;for(let t of this.children){if(!(t instanceof yt))return null;let i=nn(t.dom);if(i.length!=1)return null;e+=i[0].width}return{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length}}coordsAt(e,t){return xc(this,e,t)}become(e){return!1}get type(){return $.Text}static find(e,t){for(let i=0,s=0;i<e.children.length;i++){let r=e.children[i],o=s+r.length;if(o>=t){if(r instanceof me)return r;if(o>t)break}s=o+r.breakAfter}return null}},Ot=class extends G{constructor(e,t,i){super();this.widget=e,this.length=t,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,s,r,o){return i&&(!(i instanceof Ot)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}domAtPos(e){return e==0?ce.before(this.dom):ce.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let i=new Ot(this.widget,t,this.type);return i.breakAfter=this.breakAfter,i}get children(){return Eo}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):N.empty}domBoundsAround(){return null}become(e){return e instanceof Ot&&e.type==this.type&&e.widget.constructor==this.widget.constructor?(e.widget.eq(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},bs=class{constructor(e,t,i,s){this.doc=e,this.pos=t,this.end=i,this.disallowBlockEffectsBelow=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!e.breakAfter&&!(e instanceof Ot&&e.type==$.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new me),this.atCursorPos=!0),this.curLine}flushBuffer(e){this.pendingBuffer&&(this.curLine.append(rs(new Gt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer([]),this.curLine=null,this.content.push(e)}finish(e){e?this.pendingBuffer=0:this.flushBuffer([]),this.posCovered()||this.getLine()}buildText(e,t,i){for(;e>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,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(0,i)),this.getLine().append(rs(new yt(this.text.slice(this.textOff,this.textOff+s)),t),i),this.atCursorPos=!0,this.textOff+=s,e-=s,i=0}}span(e,t,i,s){this.buildText(t-e,i,s),this.pos=t,this.openStart<0&&(this.openStart=s)}point(e,t,i,s,r){let o=t-e;if(i instanceof Dt)if(i.block){let{type:l}=i;l==$.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Ot(i.widget||new ho("div"),o,l))}else{let l=bt.create(i.widget||new ho("span"),o,i.startSide),a=this.atCursorPos&&!l.isEditable&&r<=s.length&&(e<t||i.startSide>0),h=!l.isEditable&&(e<t||i.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!a&&(this.pendingBuffer=0),this.flushBuffer(s),a&&(c.append(rs(new Gt(1),s),r),r=s.length+Math.max(0,r-s.length)),c.append(rs(l,s),r),this.atCursorPos=h,this.pendingBuffer=h?e<t?1:2:0}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);o&&(this.textOff+o<=this.text.length?this.textOff+=o:(this.skip+=o-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}filterPoint(e,t,i,s){if(s<this.disallowBlockEffectsBelow&&i instanceof Dt){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}return!0}static build(e,t,i,s,r){let o=new bs(e,t,i,r);return o.openEnd=F.spans(s,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function rs(n,e){for(let t of e)n=new Ke(t,[n],n.length);return n}var ho=class extends De{constructor(e){super();this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}},Lg=[],Cc=S.define(),Ac=S.define(),Ec=S.define(),Mc=S.define(),co=S.define(),Tc=S.define(),uo=L.define({map:(n,e)=>n.map(e)}),Lc=L.define({map:(n,e)=>n.map(e)}),Ut=class{constructor(e,t="nearest",i="nearest",s=5,r=5){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r}map(e){return e.empty?this:new Ut(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}},Fh=L.define({map:(n,e)=>n.map(e)});function ge(n,e,t){let i=n.facet(Mc);i.length?i[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}var ln=S.define({combine:n=>n.length?n[0]:!0}),Rc=class{constructor(e,t){this.field=e,this.get=t}},re=class{from(e){return new Rc(this,e)}static define(){return new re}};re.decorations=re.define();re.atomicRanges=re.define();re.scrollMargins=re.define();var Rg=0,Ji=S.define(),q=class{constructor(e,t,i){this.id=e,this.create=t,this.fields=i,this.extension=Ji.of(this)}static define(e,t){let{eventHandlers:i,provide:s,decorations:r}=t||{},o=[];if(s)for(let l of Array.isArray(s)?s:[s])o.push(l);return i&&o.push(Pc.from(l=>({plugin:l,handlers:i}))),r&&o.push(re.decorations.from(r)),new q(Rg++,e,o)}static fromClass(e,t){return q.define(i=>new e(i),t)}},Pc=re.define(),as=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}takeField(e,t){if(this.spec)for(let{field:i,get:s}of this.spec.fields)i==e&&t.push(s(this.value))}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(ge(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){ge(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){ge(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},Oc=S.define(),Dc=S.define(),Kt=S.define(),Yi=S.define(),nt=class{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new nt(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==e.length?null:e[s],h=o-l,c=a?a.fromB:1e9;for(;r<t.length&&t[r]<c;){let u=t[r],f=t[r+1],d=Math.max(l,u),p=Math.min(c,f);if(d<=p&&new nt(d+h,p+h,d,p).addToSet(i),f>c)break;r+=2}if(!a)return i;new nt(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}},fo=class{constructor(e,t,i=Lg){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=Q.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let s=[];this.changes.iterChangedRanges((o,l,a,h)=>s.push(new nt(o,l,a,h))),this.changedRanges=s;let r=e.hasFocus;r!=e.inputState.notifiedFocused&&(e.inputState.notifiedFocused=r,this.flags|=1)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},I=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(I||(I={})),po=I.LTR,Pg=I.RTL;function Bc(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}var Og=Bc("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Dg=Bc("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),mo=Object.create(null),tt=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);mo[e]=t,mo[t]=-e}function Bg(n){return n<=247?Og[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Dg[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8203||n==8204?256:1}var Ig=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,_t=class{constructor(e,t,i){this.from=e,this.to=t,this.level=i}get dir(){return this.level%2?Pg:po}side(e,t){return this.dir==t==e?this.to:this.from}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}},_=[];function Ng(n,e){let t=n.length,i=e==po?1:2,s=e==po?2:1;if(!n||i==1&&!Ig.test(n))return Ic(t);for(let o=0,l=i,a=i;o<t;o++){let h=Bg(n.charCodeAt(o));h==512?h=l:h==8&&a==4&&(h=16),_[o]=h==4?2:h,h&7&&(a=h),l=h}for(let o=0,l=i,a=i;o<t;o++){let h=_[o];if(h==128)o<t-1&&l==_[o+1]&&l&24?h=_[o]=l:_[o]=256;else if(h==64){let c=o+1;for(;c<t&&_[c]==64;)c++;let u=o&&l==8||c<t&&_[c]==8?a==1?1:8:256;for(let f=o;f<c;f++)_[f]=u;o=c-1}else h==8&&a==1&&(_[o]=1);l=h,h&7&&(a=h)}for(let o=0,l=0,a=0,h,c,u;o<t;o++)if(c=mo[h=n.charCodeAt(o)])if(c<0){for(let f=l-3;f>=0;f-=3)if(tt[f+1]==-c){let d=tt[f+2],p=d&2?i:d&4?d&1?s:i:0;p&&(_[o]=_[tt[f]]=p),l=f;break}}else{if(tt.length==189)break;tt[l++]=o,tt[l++]=h,tt[l++]=a}else if((u=_[o])==2||u==1){let f=u==i;a=f?0:1;for(let d=l-3;d>=0;d-=3){let p=tt[d+2];if(p&2)break;if(f)tt[d+2]|=2;else{if(p&4)break;tt[d+2]|=4}}}for(let o=0;o<t;o++)if(_[o]==256){let l=o+1;for(;l<t&&_[l]==256;)l++;let a=(o?_[o-1]:i)==1,h=(l<t?_[l]:i)==1,c=a==h?a?1:2:i;for(let u=o;u<l;u++)_[u]=c;o=l-1}let r=[];if(i==1)for(let o=0;o<t;){let l=o,a=_[o++]!=1;for(;o<t&&a==(_[o]!=1);)o++;if(a)for(let h=o;h>l;){let c=h,u=_[--h]!=2;for(;h>l&&u==(_[h-1]!=2);)h--;r.push(new _t(h,c,u?2:1))}else r.push(new _t(l,o,0))}else for(let o=0;o<t;){let l=o,a=_[o++]==2;for(;o<t&&a==(_[o]==2);)o++;r.push(new _t(l,o,a?1:2))}return r}function Ic(n){return[new _t(0,n,0)]}var Nc="";function Fg(n,e,t,i,s){var r;let o=i.head-n.from,l=-1;if(o==0){if(!s||!n.length)return null;e[0].level!=t&&(o=e[0].side(!1,t),l=0)}else if(o==n.length){if(s)return null;let f=e[e.length-1];f.level!=t&&(o=f.side(!0,t),l=e.length-1)}l<0&&(l=_t.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc));let a=e[l];o==a.side(s,t)&&(a=e[l+=s?1:-1],o=a.side(!s,t));let h=s==(a.dir==t),c=de(n.text,o,h);if(Nc=n.text.slice(Math.min(o,c),Math.max(o,c)),c!=a.side(s,t))return m.cursor(c+n.from,h?-1:1,a.level);let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return!u&&a.level!=t?m.cursor(s?n.to:n.from,s?-1:1,t):u&&u.level<a.level?m.cursor(u.side(!s,t)+n.from,s?1:-1,u.level):m.cursor(c+n.from,s?-1:1,a.level)}var Pt="\uFFFF",Ro=class{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(B.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Pt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s),this.readNode(s);let r=s.nextSibling;if(r==t)break;let o=G.get(s),l=G.get(r);(o&&l?o.breakAfter:(o?o.breakAfter:Vh(s))||Vh(r)&&(s.nodeName!="BR"||s.cmIgnore))&&this.lineBreak(),s=r}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=G.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+Math.min(t,i.offset))}};function Vh(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}var go=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},bo=class extends G{constructor(e){super();this.view=e,this.compositionDeco=E.none,this.decorations=[],this.pluginDecorationLength=0,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new me],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new nt(0,0,0,e.state.doc.length)],0)}get root(){return this.view.root}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:o,toA:l})=>l<this.minWidthFrom||o>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.view.inputState.composing<0?this.compositionDeco=E.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=Hg(this.view,e.changes)),(R.ie||R.chrome)&&!this.compositionDeco.size&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,s=this.updateDeco(),r=Wg(i,s,e.changes);return t=nt.extendWithRanges(t,r),this.dirty==0&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t);let{observer:i}=this.view;i.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.minWidth=this.minWidth?this.minWidth+"px":"";let r=R.chrome||R.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(r),this.dirty=0,r&&(r.written||i.selectionRange.focusNode!=r.node)&&(this.forceSelection=!0),this.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.children)r instanceof Ot&&r.widget instanceof yo&&s.push(r.dom);i.updateGaps(s)}updateChildren(e,t){let i=this.childCursor(t);for(let s=e.length-1;;s--){let r=s>=0?e[s]:null;if(!r)break;let{fromA:o,toA:l,fromB:a,toB:h}=r,{content:c,breakAtStart:u,openStart:f,openEnd:d}=bs.build(this.view.state.doc,a,h,this.decorations,this.pluginDecorationLength),{i:p,off:g}=i.findPos(l,1),{i:y,off:b}=i.findPos(o,-1);mc(this,y,b,p,g,c,u,f,d)}}updateSelection(e=!1,t=!1){if(e&&this.view.observer.readSelectionRange(),!(t||this.mayControlSelection())||R.ios&&this.view.inputState.rapidCompositionStart)return;let i=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,r=this.domAtPos(s.anchor),o=s.empty?r:this.domAtPos(s.head);if(R.gecko&&s.empty&&Vg(r)){let a=document.createTextNode("");this.view.observer.ignore(()=>r.node.insertBefore(a,r.node.childNodes[r.offset]||null)),r=o=new ce(a,0),i=!0}let l=this.view.observer.selectionRange;(i||!l.focusNode||!ds(r.node,r.offset,l.anchorNode,l.anchorOffset)||!ds(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{R.android&&R.chrome&&this.dom.contains(l.focusNode)&&zg(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let a=fs(this.root);if(s.empty){if(R.gecko){let h=qg(r.node,r.offset);if(h&&h!=3){let c=Hc(r.node,r.offset,h==1?1:-1);c&&(r=new ce(c,h==1?0:c.nodeValue.length))}}a.collapse(r.node,r.offset),s.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=s.bidiLevel)}else if(a.extend)a.collapse(r.node,r.offset),a.extend(o.node,o.offset);else{let h=document.createRange();s.anchor>s.head&&([r,o]=[o,r]),h.setEnd(o.node,o.offset),h.setStart(r.node,r.offset),a.removeAllRanges(),a.addRange(h)}}),this.view.observer.setSelectionRange(r,o)),this.impreciseAnchor=r.precise?null:new ce(l.anchorNode,l.anchorOffset),this.impreciseHead=o.precise?null:new ce(l.focusNode,l.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let e=this.view.state.selection.main,t=fs(this.root);if(!e.empty||!e.assoc||!t.modify)return;let i=me.find(this,e.head);if(!i)return;let s=i.posAtStart;if(e.head==s||e.head==s+i.length)return;let r=this.coordsAt(e.head,-1),o=this.coordsAt(e.head,1);if(!r||!o||r.bottom>o.top)return;let l=this.domAtPos(e.head+e.assoc);t.collapse(l.node,l.offset),t.modify("move",e.assoc<0?"forward":"backward","lineboundary")}mayControlSelection(){return this.view.state.facet(ln)?this.root.activeElement==this.dom:Zr(this.dom,this.view.observer.selectionRange)}nearest(e){for(let t=e;t;){let i=G.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t<this.children.length-1;){let s=this.children[t];if(i<s.length||s instanceof me)break;t++,i=0}return this.children[t].domAtPos(i)}coordsAt(e,t){for(let i=this.length,s=this.children.length-1;;s--){let r=this.children[s],o=i-r.breakAfter-r.length;if(e>o||e==o&&r.type!=$.WidgetBefore&&r.type!=$.WidgetAfter&&(!s||t==2||this.children[s-1].breakAfter||this.children[s-1].type==$.WidgetBefore&&t>-2))return r.coordsAt(e-o,t);i=o}}measureVisibleLineHeights(){let e=[],{from:t,to:i}=this.view.viewState.viewport,s=this.view.contentDOM.clientWidth,r=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1;for(let l=0,a=0;a<this.children.length;a++){let h=this.children[a],c=l+h.length;if(c>i)break;if(l>=t){let u=h.dom.getBoundingClientRect();if(e.push(u.height),r){let f=h.dom.lastChild,d=f?nn(f):[];if(d.length){let p=d[d.length-1],g=this.view.textDirection==I.LTR?p.right-u.left:u.right-p.left;g>o&&(o=g,this.minWidth=s,this.minWidthFrom=l,this.minWidthTo=c)}}}l=c+h.breakAfter}return e}measureTextSize(){for(let s of this.children)if(s instanceof me){let r=s.measureTextSize();if(r)return r}let e=document.createElement("div"),t,i;return e.className="cm-line",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let s=nn(e.firstChild)[0];t=e.getBoundingClientRect().height,i=s?s.width/27:7,e.remove()}),{lineHeight:t,charWidth:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Mo(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=t.lineBlockAt(o).bottom-t.lineBlockAt(i).top;e.push(E.replace({widget:new yo(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return E.set(e)}updateDeco(){let e=this.view.pluginField(re.decorations);return this.pluginDecorationLength=e.length,this.decorations=[...e,...this.view.state.facet(Kt),this.compositionDeco,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco]}scrollIntoView(e){let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!i)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=0,o=0,l=0,a=0;for(let c of this.view.pluginField(re.scrollMargins))if(c){let{left:u,right:f,top:d,bottom:p}=c;u!=null&&(r=Math.max(r,u)),f!=null&&(o=Math.max(o,f)),d!=null&&(l=Math.max(l,d)),p!=null&&(a=Math.max(a,p))}let h={left:i.left-r,top:i.top-l,right:i.right+o,bottom:i.bottom+a};Cg(this.view.scrollDOM,h,t.head<t.anchor?-1:1,e.x,e.y,e.xMargin,e.yMargin,this.view.textDirection==I.LTR)}};function Vg(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}var yo=class extends De{constructor(e){super();this.height=e}toDOM(){let e=document.createElement("div");return this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}};function Fc(n){let e=n.observer.selectionRange,t=e.focusNode&&Hc(e.focusNode,e.focusOffset,0);if(!t)return null;let i=n.docView.nearest(t);if(!i)return null;if(i instanceof me){let s=t;for(;s.parentNode!=i.dom;)s=s.parentNode;let r=s.previousSibling;for(;r&&!G.get(r);)r=r.previousSibling;let o=r?G.get(r).posAtEnd:i.posAtStart;return{from:o,to:o,node:s,text:t}}else{for(;;){let{parent:r}=i;if(!r)return null;if(r instanceof me)break;i=r}let s=i.posAtStart;return{from:s,to:s+i.length,node:i.dom,text:t}}}function Hg(n,e){let t=Fc(n);if(!t)return E.none;let{from:i,to:s,node:r,text:o}=t,l=e.mapPos(i,1),a=Math.max(l,e.mapPos(s,-1)),{state:h}=n,c=r.nodeType==3?r.nodeValue:new Ro([],h).readRange(r.firstChild,null).text;if(a-l<c.length)if(h.doc.sliceString(l,Math.min(h.doc.length,l+c.length),Pt)==c)a=l+c.length;else if(h.doc.sliceString(Math.max(0,a-c.length),a,Pt)==c)l=a-c.length;else return E.none;else if(h.doc.sliceString(l,a,Pt)!=c)return E.none;let u=G.get(r);return u instanceof To?u=u.widget.topView:u&&(u.parent=null),E.set(E.replace({widget:new Vc(r,o,u)}).range(l,a))}var Vc=class extends De{constructor(e,t,i){super();this.top=e,this.text=t,this.topView=i}eq(e){return this.top==e.top&&this.text==e.text}toDOM(){return this.top}ignoreEvent(){return!1}get customView(){return To}};function Hc(n,e,t){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&e>0&&t<=0)n=n.childNodes[e-1],e=ps(n);else if(n.nodeType==1&&e<n.childNodes.length&&t>=0)n=n.childNodes[e],e=0;else return null}}function qg(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}var qc=class{constructor(){this.changes=[]}compareRange(e,t){ao(e,t,this.changes)}comparePoint(e,t){ao(e,t,this.changes)}};function Wg(n,e,t){let i=new qc;return F.compare(n,e,t,i),i.changes}function zg(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function $g(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return m.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=de(s.text,r,!1):l=de(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let h=de(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=de(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return m.range(o+s.from,l+s.from)}function jg(n,e){return e.left>n?e.left-n:Math.max(0,n-e.right)}function Ug(n,e){return e.top>n?e.top-n:Math.max(0,n-e.bottom)}function _r(n,e){return n.top<e.bottom-1&&n.bottom>e.top+1}function Hh(n,e){return e<n.top?{top:e,left:n.left,right:n.right,bottom:n.bottom}:n}function qh(n,e){return e>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:e}:n}function vo(n,e,t){let i,s,r,o,l,a,h,c;for(let d=n.firstChild;d;d=d.nextSibling){let p=nn(d);for(let g=0;g<p.length;g++){let y=p[g];s&&_r(s,y)&&(y=Hh(qh(y,s.bottom),s.top));let b=jg(e,y),A=Ug(t,y);if(b==0&&A==0)return d.nodeType==3?Wh(d,e,t):vo(d,e,t);(!i||o>A||o==A&&r>b)&&(i=d,s=y,r=b,o=A),b==0?t>y.bottom&&(!h||h.bottom<y.bottom)?(l=d,h=y):t<y.top&&(!c||c.top>y.top)&&(a=d,c=y):h&&_r(h,y)?h=qh(h,y.bottom):c&&_r(c,y)&&(c=Hh(c,y.top))}}if(h&&h.bottom>=t?(i=l,s=h):c&&c.top<=t&&(i=a,s=c),!i)return{node:n,offset:0};let u=Math.max(s.left,Math.min(s.right,e));if(i.nodeType==3)return Wh(i,u,t);if(!r&&i.contentEditable=="true")return vo(i,u,t);let f=Array.prototype.indexOf.call(n.childNodes,i)+(e>=(s.left+s.right)/2?1:0);return{node:n,offset:f}}function Wh(n,e,t){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=sn(n,l,l+1).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(c.top==c.bottom)continue;o||(o=e-c.left);let u=(c.top>t?c.top-t:t-c.bottom)-1;if(c.left-1<=e&&c.right+1>=e&&u<r){let f=e>=(c.left+c.right)/2,d=f;if((R.chrome||R.gecko)&&sn(n,l).getBoundingClientRect().left==c.right&&(d=!f),u<=0)return{node:n,offset:l+(d?1:0)};s=l+(d?1:0),r=u}}}return{node:n,offset:s>-1?s:o>0?n.nodeValue.length:0}}function Wc(n,{x:e,y:t},i,s=-1){var r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,a,{docHeight:h}=n.viewState,c=t-l;if(c<0)return 0;if(c>h)return n.state.doc.length;for(let b=n.defaultLineHeight/2,A=!1;a=n.elementAtHeight(c),a.type!=$.Text;)for(;c=s>0?a.bottom+b:a.top-b,!(c>=0&&c<=h);){if(A)return i?null:0;A=!0,s=-s}t=l+c;let u=a.from;if(u<n.viewport.from)return n.viewport.from==0?0:i?null:zh(n,o,a,e,t);if(u>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:i?null:zh(n,o,a,e,t);let f=n.dom.ownerDocument,d=n.root.elementFromPoint?n.root:f,p=d.elementFromPoint(e,t);p&&!n.contentDOM.contains(p)&&(p=null),p||(e=Math.max(o.left+1,Math.min(o.right-1,e)),p=d.elementFromPoint(e,t),p&&!n.contentDOM.contains(p)&&(p=null));let g,y=-1;if(p&&((r=n.docView.nearest(p))===null||r===void 0?void 0:r.isEditable)!=!1){if(f.caretPositionFromPoint){let b=f.caretPositionFromPoint(e,t);b&&({offsetNode:g,offset:y}=b)}else if(f.caretRangeFromPoint){let b=f.caretRangeFromPoint(e,t);b&&({startContainer:g,startOffset:y}=b,R.safari&&Kg(g,y,e)&&(g=void 0))}}if(!g||!n.docView.dom.contains(g)){let b=me.find(n.docView,u);if(!b)return c>a.top+a.height/2?a.to:a.from;({node:g,offset:y}=vo(b.dom,e,t))}return n.docView.posFromDOM(g,y)}function zh(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);n.lineWrapping&&t.height>n.defaultLineHeight*1.5&&(r+=Math.floor((s-t.top)/n.defaultLineHeight)*n.viewState.heightOracle.lineLength);let o=n.state.sliceDoc(t.from,t.to);return t.from+Ui(o,r,n.state.tabSize)}function Kg(n,e,t){let i;if(n.nodeType!=3||e!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return sn(n,i-1,i).getBoundingClientRect().left>t}function _g(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=!i||!n.lineWrapping?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let a=n.dom.getBoundingClientRect(),h=n.posAtCoords({x:t==(n.textDirection==I.LTR)?a.right-1:a.left+1,y:(r.top+r.bottom)/2});if(h!=null)return m.cursor(h,t?-1:1)}let o=me.find(n.docView,e.head),l=o?t?o.posAtEnd:o.posAtStart:t?s.to:s.from;return m.cursor(l,t?-1:1)}function $h(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s);for(let o=e,l=null;;){let a=Fg(s,r,n.textDirection,o,t),h=Nc;if(!a){if(s.number==(t?n.state.doc.lines:1))return o;h=`
|
37
|
+
`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),a=m.cursor(t?s.from:s.to)}if(l){if(!l(h))return o}else{if(!i)return a;l=i(h)}o=a}}function Gg(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==oe.Space&&(s=o),s==o}}function Jg(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return m.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s),c=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let d=n.viewState.lineBlockAt(s-c);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+c}let u=a.left+o,f=i??n.defaultLineHeight>>1;for(let d=0;;d+=10){let p=l+(f+d)*r,g=Wc(n,{x:u,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<s:g>s))return m.cursor(g,e.assoc,void 0,o)}}function Gr(n,e,t){let i=n.pluginField(re.atomicRanges);for(;;){let s=!1;for(let r of i)r.between(t.from-1,t.from+1,(o,l,a)=>{t.from>o&&t.from<l&&(t=e.from>t.from?m.cursor(o,1):m.cursor(l,-1),s=!0)});if(!s)return t}}var zc=class{constructor(e){this.lastKeyCode=0,this.lastKeyTime=0,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.rapidCompositionStart=!1,this.mouseSelection=null;for(let t in le){let i=le[t];e.contentDOM.addEventListener(t,s=>{t=="keydown"&&this.keydown(e,s)||!jh(e,s)||this.ignoreDuringComposition(s)||(this.mustFlushObserver(s)&&e.observer.forceFlush(),this.runCustomHandlers(t,e,s)?s.preventDefault():i(e,s))}),this.registeredEvents.push(t)}this.notifiedFocused=e.hasFocus,this.ensureHandlers(e),R.safari&&e.contentDOM.addEventListener("input",()=>null)}setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}ensureHandlers(e){let t=this.customHandlers=e.pluginField(Pc);for(let i of t)for(let s in i.handlers)this.registeredEvents.indexOf(s)<0&&s!="scroll"&&(this.registeredEvents.push(s),e.contentDOM.addEventListener(s,r=>{!jh(e,r)||this.runCustomHandlers(s,e,r)&&r.preventDefault()}))}runCustomHandlers(e,t,i){for(let s of this.customHandlers){let r=s.handlers[e];if(r)try{if(r.call(s.plugin,i,t)||i.defaultPrevented)return!0}catch(o){ge(t.state,o)}}return!1}runScrollHandlers(e,t){for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,t,e)}catch(r){ge(e.state,r)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),this.screenKeyEvent(e,t))return!0;if(R.android&&R.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return e.observer.delayAndroidKey(t.key,t.keyCode),!0;let i;return R.ios&&(i=$c.find(s=>s.keyCode==t.keyCode))&&!(t.ctrlKey||t.altKey||t.metaKey)&&!t.synthetic?(this.pendingIOSKey=i,setTimeout(()=>this.flushIOSKey(e),250),!0):!1}flushIOSKey(e){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,tn(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:R.safari&&Date.now()-this.compositionEndedAt<500?(this.compositionEndedAt=0,!0):!1:!1}screenKeyEvent(e,t){let i=t.keyCode==9&&Date.now()<this.lastEscPress+2e3;return t.keyCode==27?this.lastEscPress=Date.now():jc.indexOf(t.keyCode)<0&&(this.lastEscPress=0),i}mustFlushObserver(e){return e.type=="keydown"&&e.keyCode!=229||e.type=="compositionend"&&!R.ios}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}},$c=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],jc=[16,17,18,20,91,92,224,225],Uc=class{constructor(e,t,i,s){this.view=e,this.style=i,this.mustSelect=s,this.lastEvent=t;let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(B.allowMultipleSelections)&&Yg(e,t),this.dragMove=Xg(e,t),this.dragging=Qg(e,t)&&Po(t)==1?null:!1,this.dragging===!1&&(t.preventDefault(),this.select(t))}move(e){if(e.buttons==0)return this.destroy();this.dragging===!1&&this.select(this.lastEvent=e)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(e){let t=this.style.get(e,this.extend,this.multiple);(this.mustSelect||!t.eq(this.view.state.selection)||t.main.assoc!=this.view.state.selection.main.assoc)&&this.view.dispatch({selection:t,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(e){e.docChanged&&this.dragging&&(this.dragging=this.dragging.map(e.changes)),this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Yg(n,e){let t=n.state.facet(Cc);return t.length?t[0](e):R.mac?e.metaKey:e.ctrlKey}function Xg(n,e){let t=n.state.facet(Ac);return t.length?t[0](e):R.mac?!e.altKey:!e.ctrlKey}function Qg(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=fs(n.root);if(i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function jh(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=G.get(t))&&i.ignoreEvent(e))return!1;return!0}var le=Object.create(null),Kc=R.ie&&R.ie_version<15||R.ios&&R.webkit_version<604;function Zg(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),_c(n,t.value)},50)}function _c(n,e){let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(wo!=null&&t.selection.ranges.every(a=>a.empty)&&wo==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let u=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:u},range:m.cursor(h.from+u.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:m.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}le.keydown=(n,e)=>{n.inputState.setSelectionOrigin("select")};var Gc=0;le.touchstart=(n,e)=>{Gc=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};le.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};le.mousedown=(n,e)=>{if(n.observer.flush(),Gc>Date.now()-2e3&&Po(e)==1)return;let t=null;for(let i of n.state.facet(Ec))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=i0(n,e)),t){let i=n.root.activeElement!=n.contentDOM;i&&n.observer.ignore(()=>dc(n.contentDOM)),n.inputState.startMouseSelection(new Uc(n,e,t,i))}};function Uh(n,e,t,i){if(i==1)return m.cursor(e,t);if(i==2)return $g(n.state,e,t);{let s=me.find(n.docView,e),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,m.range(o,l)}}var Jc=(n,e)=>n>=e.top&&n<=e.bottom,Kh=(n,e,t)=>Jc(e,t)&&n>=t.left&&n<=t.right;function e0(n,e,t,i){let s=me.find(n.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Kh(t,i,o))return-1;let l=s.coordsAt(r,1);return l&&Kh(t,i,l)?1:o&&Jc(i,o)?-1:1}function _h(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:e0(n,t,e.clientX,e.clientY)}}var t0=R.ie&&R.ie_version<=11,Gh=null,Jh=0,Yh=0;function Po(n){if(!t0)return n.detail;let e=Gh,t=Yh;return Gh=n,Yh=Date.now(),Jh=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Jh+1)%3:1}function i0(n,e){let t=_h(n,e),i=Po(e),s=n.state.selection,r=t,o=e;return{update(l){l.docChanged&&(t&&(t.pos=l.changes.mapPos(t.pos)),s=s.map(l.changes),o=null)},get(l,a,h){let c;if(o&&l.clientX==o.clientX&&l.clientY==o.clientY?c=r:(c=r=_h(n,l),o=l),!c||!t)return s;let u=Uh(n,c.pos,c.bias,i);if(t.pos!=c.pos&&!a){let f=Uh(n,t.pos,t.bias,i),d=Math.min(f.from,u.from),p=Math.max(f.to,u.to);u=d<u.from?m.range(d,p):m.range(p,d)}return a?s.replaceRange(s.main.extend(u.from,u.to)):h?s.addRange(u):m.create([u])}}}le.dragstart=(n,e)=>{let{selection:{main:t}}=n.state,{mouseSelection:i}=n.inputState;i&&(i.dragging=t),e.dataTransfer&&(e.dataTransfer.setData("Text",n.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove")};function Xh(n,e,t,i){if(!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:r}=n.inputState,o=i&&r&&r.dragging&&r.dragMove?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}le.drop=(n,e)=>{if(!e.dataTransfer)return;if(n.state.readOnly)return e.preventDefault();let t=e.dataTransfer.files;if(t&&t.length){e.preventDefault();let i=Array(t.length),s=0,r=()=>{++s==t.length&&Xh(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}}else Xh(n,e,e.dataTransfer.getData("Text"),!0)};le.paste=(n,e)=>{if(n.state.readOnly)return e.preventDefault();n.observer.flush();let t=Kc?null:e.clipboardData;t?(_c(n,t.getData("text/plain")),e.preventDefault()):Zg(n)};function n0(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function s0(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:e.join(n.lineBreak),ranges:t,linewise:i}}var wo=null;le.copy=le.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=s0(n.state);if(!t&&!s)return;wo=s?t:null;let r=Kc?null:e.clipboardData;r?(e.preventDefault(),r.clearData(),r.setData("text/plain",t)):n0(n,t),e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};le.focus=le.blur=n=>{setTimeout(()=>{n.hasFocus!=n.inputState.notifiedFocused&&n.update([])},10)};le.beforeprint=n=>{n.viewState.printing=!0,n.requestMeasure(),setTimeout(()=>{n.viewState.printing=!1,n.requestMeasure()},2e3)};function Yc(n,e){if(n.docView.compositionDeco.size){n.inputState.rapidCompositionStart=e;try{n.update([])}finally{n.inputState.rapidCompositionStart=!1}}}le.compositionstart=le.compositionupdate=n=>{n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0,n.docView.compositionDeco.size&&(n.observer.flush(),Yc(n,!0)))};le.compositionend=n=>{n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionFirstChange=null,setTimeout(()=>{n.inputState.composing<0&&Yc(n,!1)},50)};le.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};le.beforeinput=(n,e)=>{var t;let i;if(R.chrome&&R.android&&(i=$c.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}};var Qh=["pre-wrap","normal","pre-line","break-spaces"],Xc=class{constructor(){this.doc=N.empty,this.lineWrapping=!1,this.direction=I.LTR,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength)),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForStyle(e,t){return Qh.indexOf(e)>-1!=this.lineWrapping||this.direction!=t}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=Qh.indexOf(e)>-1,a=Math.round(i)!=Math.round(this.lineHeight)||this.lineWrapping!=l||this.direction!=t;if(this.lineWrapping=l,this.direction=t,this.lineHeight=i,this.charWidth=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}},Qc=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},it=class{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this.type=r}get to(){return this.from+this.length}get bottom(){return this.top+this.height}join(e){let t=(Array.isArray(this.type)?this.type:[this]).concat(Array.isArray(e.type)?e.type:[e]);return new it(this.from,this.length+e.length,this.top,this.height+e.height,t)}moveY(e){return e?new it(this.from,this.length,this.top+e,this.height,Array.isArray(this.type)?this.type.map(t=>t.moveY(e)):this.type):this}},K=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(K||(K={})),hs=.001,ke=class{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>hs&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return ke.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this;for(let o=s.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:c}=s[o],u=r.lineAt(l,K.ByPosNoHeight,t,0,0),f=u.to>=a?u:r.lineAt(a,K.ByPosNoHeight,t,0,0);for(c+=f.to-a,a=f.to;o>0&&u.from<=s[o-1].toA;)l=s[o-1].fromA,h=s[o-1].fromB,o--,l<u.from&&(u=r.lineAt(l,K.ByPosNoHeight,t,0,0));h+=u.from-l,l=u.from;let d=ys.build(i,e,h,c);r=r.replace(l,a,d)}return r.updateHeight(i,0)}static empty(){return new Te(0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,s=0,r=0;for(;;)if(t==i)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Zc(ke.of(e.slice(0,t)),o,ke.of(e.slice(i)))}};ke.prototype.size=1;var Oo=class extends ke{constructor(e,t,i){super(e,t);this.type=i}blockAt(e,t,i,s){return new it(s,this.length,i,this.height,this.type)}lineAt(e,t,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(e,t,i,s,r,o){o(this.blockAt(0,i,s,r))}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(e,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},Te=class extends Oo{constructor(e,t){super(e,t,$.Text);this.collapsed=0,this.widgetHeight=0}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof Te||s instanceof he&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof he?s=new Te(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):ke.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setHeight(e,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},he=class extends ke{constructor(e){super(e,0)}lines(e,t){let i=e.lineAt(t).number,s=e.lineAt(t+this.length).number;return{firstLine:i,lastLine:s,lineHeight:this.height/(s-i+1)}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,lineHeight:l}=this.lines(t,s),a=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:h,length:c}=t.line(r+a);return new it(h,c,i+l*a,l,$.Text)}lineAt(e,t,i,s,r){if(t==K.ByHeight)return this.blockAt(e,i,s,r);if(t==K.ByPosNoHeight){let{from:u,to:f}=i.lineAt(e);return new it(u,f-u,0,0,$.Text)}let{firstLine:o,lineHeight:l}=this.lines(i,r),{from:a,length:h,number:c}=i.lineAt(e);return new it(a,h,s+l*(c-o),l,$.Text)}forEachLine(e,t,i,s,r,o){let{firstLine:l,lineHeight:a}=this.lines(i,r);for(let h=Math.max(e,r),c=Math.min(r+this.length,t);h<=c;){let u=i.lineAt(h);h==e&&(s+=a*(u.number-l)),o(new it(u.from,u.length,s,a,$.Text)),s+=a,h=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof he?i[i.length-1]=new he(r.length+s):i.push(null,new he(s-1))}if(e>0){let r=i[0];r instanceof he?i[0]=new he(e+r.length):i.unshift(new he(e-1),null)}return ke.of(i)}decomposeLeft(e,t){t.push(new he(e-1),null)}decomposeRight(e,t){t.push(null,new he(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1,h=e.heightChanged;for(s.from>t&&o.push(new he(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let u=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++];a==-1?a=f:Math.abs(f-a)>=hs&&(a=-2);let d=new Te(u,f);d.outdated=!1,o.push(d),l+=u+1}l<=r&&o.push(null,new he(r-l).updateHeight(e,l));let c=ke.of(o);return e.heightChanged=h||a<0||Math.abs(c.height-this.height)>=hs||Math.abs(a-this.lines(e.doc,t).lineHeight)>=hs,c}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Zc=class extends ke{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0));this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==K.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==K.ByPosNoHeight?K.ByPosNoHeight:K.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,K.ByPos,i,s,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,s,r,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Zh(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Zh(r,l)}return ke.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?ke.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Zh(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof he&&(i=n[e+1])instanceof he&&n.splice(e-1,3,new he(t.length+1+i.length))}var r0=5,ys=class{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Te?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Te(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0;s<0&&(s=this.oracle.lineHeight);let r=t-e;i.block?this.addBlock(new Oo(r,s,i.type)):(r||s>=r0)&&this.addLineDeco(s,r)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Te(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new he(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Te)return e;let t=new Te(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine(),e.type==$.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=$.WidgetBefore&&(this.covering=e)}addLineDeco(e,t){let i=this.ensureLine();i.length+=t,i.collapsed+=t,i.widgetHeight=Math.max(i.widgetHeight,e),this.writtenTo=this.pos=this.pos+t}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Te)&&!this.isCovered?this.nodes.push(new Te(0,-1)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let s of this.nodes)s instanceof Te&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new ys(i,e);return F.spans(t,i,s,r,0),r.finish(i)}};function o0(n,e,t){let i=new eu;return F.compare(n,e,t,i,0),i.changes}var eu=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&ao(e,t,this.changes,5)}};function l0(n,e){let t=n.getBoundingClientRect(),i=Math.max(0,t.left),s=Math.min(innerWidth,t.right),r=Math.max(0,t.top),o=Math.min(innerHeight,t.bottom),l=n.ownerDocument.body;for(let a=n.parentNode;a&&a!=l;)if(a.nodeType==1){let h=a,c=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&c.overflow!="visible"){let u=h.getBoundingClientRect();i=Math.max(i,u.left),s=Math.min(s,u.right),r=Math.max(r,u.top),o=Math.min(o,u.bottom)}a=c.position=="absolute"||c.position=="fixed"?h.offsetParent:h.parentNode}else if(a.nodeType==11)a=a.host;else break;return{left:i-t.left,right:Math.max(i,s)-t.left,top:r-(t.top+e),bottom:Math.max(r,o)-(t.top+e)}}var cs=class{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let s=e[i],r=t[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e){return E.replace({widget:new tu(this.size,e)}).range(this.from,this.to)}},tu=class extends De{constructor(e,t){super();this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},So=class{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.heightOracle=new Xc,this.scaler=ic,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1,this.heightMap=ke.empty().applyChanges(e.facet(Kt),N.empty,this.heightOracle.setDoc(e.doc),[new nt(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=E.set(this.lineGaps.map(t=>t.draw(!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new Xi(r,o))}}this.viewports=e.sort((i,s)=>i.from-s.from),this.scaler=this.heightMap.height<=7e6?ic:new iu(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:Qi(e,this.scaler))})}update(e,t=null){let i=this.state;this.state=e.state;let s=this.state.facet(Kt),r=e.changedRanges,o=nt.extendWithRanges(r,o0(e.startState.facet(Kt),s,e?e.changes:Q.empty(this.state.doc.length))),l=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(s,i.doc,this.heightOracle.setDoc(this.state.doc),o),this.heightMap.height!=l&&(e.flags|=2);let a=o.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=!e.changes.empty||e.flags&2||a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,this.updateForViewport(),h&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace,o=i.direction=="rtl"?I.RTL:I.LTR,l=this.heightOracle.mustRefreshForStyle(r,o),a=l||this.mustMeasureContent||this.contentDOMHeight!=t.clientHeight,h=0,c=0;if(this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8),a){this.mustMeasureContent=!1,this.contentDOMHeight=t.clientHeight;let b=parseInt(i.paddingTop)||0,A=parseInt(i.paddingBottom)||0;(this.paddingTop!=b||this.paddingBottom!=A)&&(h|=8,this.paddingTop=b,this.paddingBottom=A)}let u=this.printing?{top:-1e8,bottom:1e8,left:-1e8,right:1e8}:l0(t,this.paddingTop),f=u.top-this.pixelViewport.top,d=u.bottom-this.pixelViewport.bottom;this.pixelViewport=u;let p=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(p!=this.inView&&(this.inView=p,p&&(a=!0)),!this.inView)return 0;let g=t.clientWidth;if((this.contentDOMWidth!=g||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=g,this.editorHeight=e.scrollDOM.clientHeight,h|=8),a){let b=e.docView.measureVisibleLineHeights();if(s.mustRefreshForHeights(b)&&(l=!0),l||s.lineWrapping&&Math.abs(g-this.contentDOMWidth)>s.charWidth){let{lineHeight:A,charWidth:T}=e.docView.measureTextSize();l=s.refresh(r,o,A,T,g/T,b),l&&(e.docView.minWidth=0,h|=8)}f>0&&d>0?c=Math.max(f,d):f<0&&d<0&&(c=Math.min(f,d)),s.heightChanged=!1,this.heightMap=this.heightMap.updateHeight(s,0,l,new Qc(this.viewport.from,b)),s.heightChanged&&(h|=2)}let y=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return y&&(this.viewport=this.getViewport(c,this.scrollTarget)),this.updateForViewport(),(h&2||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(l?[]:this.lineGaps)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.state.doc,{visibleTop:o,visibleBottom:l}=this,a=new Xi(s.lineAt(o-i*1e3,K.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,K.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),u=s.lineAt(h,K.ByPos,r,0,0),f;t.y=="center"?f=(u.top+u.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?f=u.top:f=u.bottom-c,a=new Xi(s.lineAt(f-1e3/2,K.ByHeight,r,0,0).from,s.lineAt(f+c+1e3/2,K.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Xi(this.heightMap.lineAt(i,K.ByPos,this.state.doc,0,0).from,this.heightMap.lineAt(s,K.ByPos,this.state.doc,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,K.ByPos,this.state.doc,0,0),{bottom:r}=this.heightMap.lineAt(t,K.ByPos,this.state.doc,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new cs(t.mapPos(s.from),t.mapPos(s.to),s.size));return i}ensureLineGaps(e){let t=[];if(this.heightOracle.direction!=I.LTR)return t;for(let i of this.viewportLines){if(i.length<4e3)continue;let s=a0(i.from,i.to,this.state);if(s.total<4e3)continue;let r,o;if(this.heightOracle.lineWrapping){let h=2e3/this.heightOracle.lineLength*this.heightOracle.lineHeight;r=os(s,(this.visibleTop-i.top-h)/i.height),o=os(s,(this.visibleBottom-i.top+h)/i.height)}else{let h=s.total*this.heightOracle.charWidth,c=2e3*this.heightOracle.charWidth;r=os(s,(this.pixelViewport.left-c)/h),o=os(s,(this.pixelViewport.right+c)/h)}let l=[];r>i.from&&l.push({from:i.from,to:r}),o<i.to&&l.push({from:o,to:i.to});let a=this.state.selection.main;a.from>=i.from&&a.from<=i.to&&tc(l,a.from-10,a.from+10),!a.empty&&a.to>=i.from&&a.to<=i.to&&tc(l,a.to-10,a.to+10);for(let{from:h,to:c}of l)c-h>1e3&&t.push(h0(e,u=>u.from>=i.from&&u.to<=i.to&&Math.abs(u.from-h)<1e3&&Math.abs(u.to-c)<1e3)||new cs(h,c,this.gapSize(i,h,c,s)))}return t}gapSize(e,t,i,s){let r=ec(s,i)-ec(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){cs.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=E.set(e.map(t=>t.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.state.facet(Kt);this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];F.spans(e,this.viewport.from,this.viewport.to,{span(s,r){t.push({from:s,to:r})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=t[r].from||s.to!=t[r].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Qi(this.heightMap.lineAt(e,K.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(e){return Qi(this.heightMap.lineAt(this.scaler.fromDOM(e),K.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(e){return Qi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Xi=class{constructor(e,t){this.from=e,this.to=t}};function a0(n,e,t){let i=[],s=n,r=0;return F.spans(t.facet(Kt),n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(i.push({from:s,to:e}),r+=e-s),{total:r,ranges:i}}function os({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function ec(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function tc(n,e,t){for(let i=0;i<n.length;i++){let s=n[i];if(s.from<t&&s.to>e){let r=[];s.from<e&&r.push({from:s.from,to:e}),s.to>t&&r.push({from:t,to:s.to}),n.splice(i,1,...r),i+=r.length-1}}}function h0(n,e){for(let t of n)if(e(t))return t}var ic={toDOM(n){return n},fromDOM(n){return n},scale:1},iu=class{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,K.ByPos,e,0,0).top,c=t.lineAt(a,K.ByPos,e,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,s=r.domBottom}}};function Qi(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new it(n.from,n.length,t,i-t,Array.isArray(n.type)?n.type.map(s=>Qi(s,e)):n.type)}var ls=S.define({combine:n=>n.join(" ")}),xo=S.define({combine:n=>n.indexOf(!0)>-1}),ko=je.newName(),nu=je.newName(),su=je.newName(),ru={"&light":"."+nu,"&dark":"."+su};function Co(n,e,t){return new je(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}var c0=Co("."+ko,{"&.cm-editor":{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,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",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"},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 4px"},".cm-selectionLayer":{zIndex:-1,contain:"size style"},".cm-selectionBackground":{position:"absolute"},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{zIndex:100,contain:"size style",pointerEvents:"none"},"&.cm-focused .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{visibility:"hidden"},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{visibility:"hidden"},"100%":{}},".cm-cursor, .cm-dropCursor":{position:"absolute",borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#f3f9ff"},"&dark .cm-activeLine":{backgroundColor:"#223039"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".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"}},ru),u0={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Jr=R.ie&&R.ie_version<=11,ou=class{constructor(e,t,i){this.view=e,this.onChange=t,this.onScrollChanged=i,this.active=!1,this.selectionRange=new fc,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.scrollTargets=[],this.intersection=null,this.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(s=>{for(let r of s)this.queue.push(r);(R.ie&&R.ie_version<=11||R.ios&&e.composing)&&s.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),Jr&&(this.onCharData=s=>{this.queue.push({target:s.target,type:"characterData",oldValue:s.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),window.addEventListener("resize",this.onResize=this.onResize.bind(this)),typeof ResizeObserver=="function"&&(this.resize=new ResizeObserver(()=>{this.view.docView.lastUpdate<Date.now()-75&&this.onResize()}),this.resize.observe(e.scrollDOM)),this.start(),window.addEventListener("scroll",this.onScroll=this.onScroll.bind(this)),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(s=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),s.length>0&&s[s.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(s=>{s.length>0&&s[s.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange(),this.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:t}=this,i=this.selectionRange;if(t.state.facet(ln)?t.root.activeElement!=this.dom:!Zr(t.dom,i))return;let s=i.anchorNode&&t.docView.nearest(i.anchorNode);s&&s.ignoreEvent(e)||((R.ie&&R.ie_version<=11||R.android&&R.chrome)&&!t.state.selection.main.empty&&i.focusNode&&ds(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)?this.flushSoon():this.flush(!1))}readSelectionRange(){let{root:e}=this.view,t=fs(e),i=R.safari&&e.nodeType==11&&xg()==this.view.contentDOM&&f0(this.view)||t;return this.selectionRange.eq(i)?!1:(this.selectionRange.setRange(i),this.selectionChanged=!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,u0),Jr&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){!this.active||(this.active=!1,this.observer.disconnect(),Jr&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){this.delayedAndroidKey||requestAnimationFrame(()=>{let i=this.delayedAndroidKey;this.delayedAndroidKey=null;let s=this.view.state;tn(this.view.contentDOM,i.key,i.keyCode)?this.processRecords():this.flush(),this.view.state==s&&this.view.update([])}),(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t})}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=window.setTimeout(()=>{this.delayedFlush=-1,this.flush()},20))}forceFlush(){this.delayedFlush>=0&&(window.clearTimeout(this.delayedFlush),this.delayedFlush=-1,this.flush())}processRecords(){let e=this.queue;for(let r of this.observer.takeRecords())e.push(r);e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);!o||(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return;e&&this.readSelectionRange();let{from:t,to:i,typeOver:s}=this.processRecords(),r=this.selectionChanged&&Zr(this.dom,this.selectionRange);if(t<0&&!r)return;this.selectionChanged=!1;let o=this.view.state;this.onChange(t,i,s),this.view.state==o&&this.view.update([])}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.dirty|=4),e.type=="childList"){let i=nc(t,e.previousSibling||e.target.previousSibling,-1),s=nc(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resize)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);window.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize),this.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout)}};function nc(n,e,t){for(;e;){let i=G.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function f0(n){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(n.contentDOM.addEventListener("beforeinput",t,!0),document.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,s=e.startOffset,r=e.endContainer,o=e.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return ds(l.node,l.offset,r,o)&&([i,s,r,o]=[r,o,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:o}}function d0(n,e,t,i){let s,r,o=n.state.selection.main;if(e>-1){let l=n.docView.domBoundsAround(e,t,0);if(!l||n.state.readOnly)return;let{from:a,to:h}=l,c=n.docView.impreciseHead||n.docView.impreciseAnchor?[]:m0(n),u=new Ro(c,n.state);u.readRange(l.startDOM,l.endDOM);let f=o.from,d=null;(n.inputState.lastKeyCode===8&&n.inputState.lastKeyTime>Date.now()-100||R.android&&u.text.length<h-a)&&(f=o.to,d="end");let p=p0(n.state.doc.sliceString(a,h,Pt),u.text,f-a,d);p&&(R.chrome&&n.inputState.lastKeyCode==13&&p.toB==p.from+2&&u.text.slice(p.from,p.toB)==Pt+Pt&&p.toB--,s={from:a+p.from,to:a+p.toA,insert:N.of(u.text.slice(p.from,p.toB).split(Pt))}),r=g0(c,a)}else if(n.hasFocus||!n.state.facet(ln)){let l=n.observer.selectionRange,{impreciseHead:a,impreciseAnchor:h}=n.docView,c=a&&a.node==l.focusNode&&a.offset==l.focusOffset||!Si(n.contentDOM,l.focusNode)?n.state.selection.main.head:n.docView.posFromDOM(l.focusNode,l.focusOffset),u=h&&h.node==l.anchorNode&&h.offset==l.anchorOffset||!Si(n.contentDOM,l.anchorNode)?n.state.selection.main.anchor:n.docView.posFromDOM(l.anchorNode,l.anchorOffset);(c!=o.head||u!=o.anchor)&&(r=m.single(u,c))}if(!(!s&&!r)){if(!s&&i&&!o.empty&&r&&r.main.empty?s={from:o.from,to:o.to,insert:n.state.doc.slice(o.from,o.to)}:s&&s.from>=o.from&&s.to<=o.to&&(s.from!=o.from||s.to!=o.to)&&o.to-o.from-(s.to-s.from)<=4&&(s={from:o.from,to:o.to,insert:n.state.doc.slice(o.from,s.from).append(s.insert).append(n.state.doc.slice(s.to,o.to))}),s){let l=n.state;if(R.ios&&n.inputState.flushIOSKey(n)||R.android&&(s.from==o.from&&s.to==o.to&&s.insert.length==1&&s.insert.lines==2&&tn(n.contentDOM,"Enter",13)||s.from==o.from-1&&s.to==o.to&&s.insert.length==0&&tn(n.contentDOM,"Backspace",8)||s.from==o.from&&s.to==o.to+1&&s.insert.length==0&&tn(n.contentDOM,"Delete",46)))return;let a=s.insert.toString();if(n.state.facet(Tc).some(u=>u(n,s.from,s.to,a)))return;n.inputState.composing>=0&&n.inputState.composing++;let h;if(s.from>=o.from&&s.to<=o.to&&s.to-s.from>=(o.to-o.from)/3&&(!r||r.main.empty&&r.main.from==s.from+s.insert.length)&&n.inputState.composing<0){let u=o.from<s.from?l.sliceDoc(o.from,s.from):"",f=o.to>s.to?l.sliceDoc(s.to,o.to):"";h=l.replaceSelection(n.state.toText(u+s.insert.sliceString(0,void 0,n.state.lineBreak)+f))}else{let u=l.changes(s),f=r&&!l.selection.main.eq(r.main)&&r.main.to<=u.newLength?r.main:void 0;if(l.selection.ranges.length>1&&n.inputState.composing>=0&&s.to<=o.to&&s.to>=o.to-10){let d=n.state.sliceDoc(s.from,s.to),p=Fc(n)||n.state.doc.lineAt(o.head),g=o.to-s.to,y=o.to-o.from;h=l.changeByRange(b=>{if(b.from==o.from&&b.to==o.to)return{changes:u,range:f||b.map(u)};let A=b.to-g,T=A-d.length;if(b.to-b.from!=y||n.state.sliceDoc(T,A)!=d||p&&b.to>=p.from&&b.from<=p.to)return{range:b};let x=l.changes({from:T,to:A,insert:s.insert}),k=b.to-o.to;return{changes:x,range:f?m.range(Math.max(0,f.anchor+k),Math.max(0,f.head+k)):b.map(x)}})}else h={changes:u,selection:f&&l.selection.replaceRange(f)}}let c="input.type";n.composing&&(c+=".compose",n.inputState.compositionFirstChange&&(c+=".start",n.inputState.compositionFirstChange=!1)),n.dispatch(h,{scrollIntoView:!0,userEvent:c})}else if(r&&!r.main.eq(o)){let l=!1,a="select";n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),a=n.inputState.lastSelectionOrigin),n.dispatch({selection:r,scrollIntoView:l,userEvent:a})}}}function p0(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}return o<r&&n.length<e.length?(r-=t<=r&&t>=o?r-t:0,l=r+(l-o),o=r):l<r&&(r-=t<=r&&t>=l?r-t:0,o=r+(o-l),l=r),{from:r,toA:o,toB:l}}function m0(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new go(t,i)),(s!=t||r!=i)&&e.push(new go(s,r))),e}function g0(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?m.single(t+e,i+e):null}var C=class{constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=e.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this.root=e.root||Ag(e.parent)||document,this.viewState=new So(e.state||B.create()),this.plugins=this.state.facet(Ji).map(t=>new as(t));for(let t of this.plugins)t.update(this);this.observer=new ou(this,(t,i,s)=>{d0(this,t,i,s)},t=>{this.inputState.runScrollHandlers(this,t),this.observer.intersecting&&this.measure()}),this.inputState=new zc(this),this.docView=new bo(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}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}dispatch(...e){this._dispatch(e.length==1&&e[0]instanceof ee?e[0]:this.state.update(...e))}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i,s=this.state;for(let o of e){if(o.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=o.state}if(this.destroyed){this.viewState.state=s;return}if(s.facet(B.phrases)!=this.state.facet(B.phrases))return this.setState(s);i=new fo(this,s,e);let r=this.viewState.scrollTarget;try{this.updateState=2;for(let o of e){if(r&&(r=r.map(o.changes)),o.scrollIntoView){let{main:l}=o.state.selection;r=new Ut(l.empty?l:m.cursor(l.head,l.head>l.anchor?-1:1))}for(let l of o.effects)l.is(uo)?r=new Ut(l.value):l.is(Lc)?r=new Ut(l.value,"center"):l.is(Fh)&&(r=l.value)}this.viewState.update(i,r),this.bidiCache=rn.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),t=this.docView.update(i),this.state.facet(Yi)!=this.styleModules&&this.mountStyles(),this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(o=>o.isUserEvent("select.pointer")))}finally{this.updateState=0}if(i.startState.facet(ls)!=i.state.facet(ls)&&(this.viewState.mustMeasureContent=!0),(t||r||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!i.empty)for(let o of this.state.facet(co))o(i)}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new So(e),this.plugins=e.facet(Ji).map(i=>new as(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new bo(this),this.inputState.ensureHandlers(this),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ji),i=e.state.facet(Ji);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new as(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this)}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this)}measure(e=!0){if(this.destroyed)return;this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.flush();let t=null;try{for(let i=0;;i++){this.updateState=1;let s=this.viewport,r=this.viewState.measure(this);if(!r&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(i>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let o=[];r&4||([this.measureRequests,o]=[o,this.measureRequests]);let l=o.map(u=>{try{return u.read(this)}catch(f){return ge(this.state,f),sc}}),a=new fo(this,this.state),h=!1,c=!1;a.flags|=r,t?t.flags|=r:t=a,this.updateState=2,a.empty||(this.updatePlugins(a),this.inputState.update(a),this.updateAttrs(),h=this.docView.update(a));for(let u=0;u<o.length;u++)if(l[u]!=sc)try{let f=o[u];f.write&&f.write(l[u],this)}catch(f){ge(this.state,f)}if(this.viewState.scrollTarget&&(this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,c=!0),h&&this.docView.updateSelection(!0),this.viewport.from==s.from&&this.viewport.to==s.to&&!c&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let i of this.state.facet(co))i(t)}get themeClasses(){return ko+" "+(this.state.facet(xo)?su:nu)+" "+this.state.facet(ls)}updateAttrs(){let e=rc(this,Oc,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(ln)?"true":"false",class:"cm-content",style:`${R.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),rc(this,Dc,t),this.observer.ignore(()=>{lo(this.contentDOM,this.contentAttrs,t),lo(this.dom,this.editorAttrs,e)}),this.editorAttrs=e,this.contentAttrs=t}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(C.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Yi),je.mount(this.root,this.styleModules.concat(c0).reverse())}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=requestAnimationFrame(()=>this.measure())),e){if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}pluginField(e){let t=[];for(let i of this.plugins)i.update(this).takeField(e,t);return t}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.spec!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}blockAtHeight(e,t){let i=Yr(t,this);return this.elementAtHeight(e-i).moveY(i)}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}visualLineAtHeight(e,t){let i=Yr(t,this);return this.lineBlockAtHeight(e-i).moveY(i)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}viewportLines(e,t){let i=Yr(t,this);for(let s of this.viewportLineBlocks)e(s.moveY(i))}get viewportLineBlocks(){return this.viewState.viewportLines}visualLineAt(e,t=0){return this.lineBlockAt(e).moveY(t+this.viewState.paddingTop)}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Gr(this,e,$h(this,e,t,i))}moveByGroup(e,t){return Gr(this,e,$h(this,e,t,i=>Gg(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return _g(this,e,t,i)}moveVertically(e,t,i){return Gr(this,e,Jg(this,e,t,i))}scrollPosIntoView(e){this.dispatch({effects:uo.of(m.cursor(e))})}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Wc(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[_t.find(r,e-s.from,-1,t)];return ms(i,o.dir==I.LTR==t>0)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.heightOracle.direction}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>b0)return Ic(e.length);let t=this.textDirection;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t)return s.order;let i=Ng(e.text,this.textDirection);return this.bidiCache.push(new rn(e.from,e.to,t,i)),i}get hasFocus(){var e;return(document.hasFocus()||R.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{dc(this.contentDOM),this.docView.updateSelection()})}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Fh.of(new Ut(typeof e=="number"?m.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return q.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=je.newName(),s=[ls.of(i),Yi.of(Co(`.${i}`,e))];return t&&t.dark&&s.push(xo.of(!0)),s}static baseTheme(e){return ze.lowest(Yi.of(Co("."+ko,e,ru)))}};C.scrollTo=uo;C.centerOn=Lc;C.styleModule=Yi;C.inputHandler=Tc;C.exceptionSink=Mc;C.updateListener=co;C.editable=ln;C.mouseSelectionStyle=Ec;C.dragMovesSelection=Ac;C.clickAddsSelectionRange=Cc;C.decorations=Kt;C.darkTheme=xo;C.contentAttributes=Dc;C.editorAttributes=Oc;C.lineWrapping=C.contentAttributes.of({class:"cm-lineWrapping"});C.announce=L.define();var b0=4096;function Yr(n,e){return(n??e.contentDOM.getBoundingClientRect().top)+e.viewState.paddingTop}var sc={},rn=class{constructor(e,t,i,s){this.from=e,this.to=t,this.dir=i,this.order=s}static update(e,t){if(t.empty)return e;let i=[],s=e.length?e[e.length-1].dir:I.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&i.push(new rn(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.order))}return i}};function rc(n,e,t){for(let i=n.state.facet(e),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&oo(o,t)}return t}var y0=R.mac?"mac":R.windows?"win":R.linux?"linux":"key";function v0(n,e){let t=n.split(/-(?!$)/),i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){let h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Xr(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}var w0=C.domEventHandlers({keydown(n,e){return hu(lu(e.state),n,e,"editor")}}),Bt=S.define({enables:w0}),oc=new WeakMap;function lu(n){let e=n.facet(Bt),t=oc.get(e);return t||oc.set(e,t=x0(e.reduce((i,s)=>i.concat(s),[]))),t}function au(n,e,t){return hu(lu(n.state),e,n,t)}var Rt=null,S0=4e3;function x0(n,e=y0){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h)=>{let c=t[o]||(t[o]=Object.create(null)),u=l.split(/ (?!$)/).map(p=>v0(p,e));for(let p=1;p<u.length;p++){let g=u.slice(0,p).join(" ");s(g,!0),c[g]||(c[g]={preventDefault:!0,commands:[y=>{let b=Rt={view:y,prefix:g,scope:o};return setTimeout(()=>{Rt==b&&(Rt=null)},S0),!0}]})}let f=u.join(" ");s(f,!1);let d=c[f]||(c[f]={preventDefault:!1,commands:[]});d.commands.push(a),h&&(d.preventDefault=!0)};for(let o of n){let l=o[e]||o.key;if(!!l)for(let a of o.scope?o.scope.split(" "):["editor"])r(a,l,o.run,o.preventDefault),o.shift&&r(a,"Shift-"+l,o.shift,o.preventDefault)}return t}function hu(n,e,t,i){let s=Rh(e),r=s.length==1&&s!=" ",o="",l=!1;Rt&&Rt.view==t&&Rt.scope==i&&(o=Rt.prefix+" ",(l=jc.indexOf(e.keyCode)<0)&&(Rt=null));let a=u=>{if(u){for(let f of u.commands)if(f(t))return!0;u.preventDefault&&(l=!0)}return!1},h=n[i],c;if(h){if(a(h[o+Xr(s,e,!r)]))return!0;if(r&&(e.shiftKey||e.altKey||e.metaKey)&&(c=gt[e.keyCode])&&c!=s){if(a(h[o+Xr(c,e,!0)]))return!0}else if(r&&e.shiftKey&&a(h[o+Xr(s,e,!0)]))return!0}return l}var cu=!R.ios,Zi=S.define({combine(n){return pe(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function uu(n={}){return[Zi.of(n),k0,C0]}var Do=class{constructor(e,t,i,s,r){this.left=e,this.top=t,this.width=i,this.height=s,this.className=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width>=0&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}},k0=q.fromClass(class{constructor(n){this.view=n,this.rangePieces=[],this.cursors=[],this.measureReq={read:this.readPos.bind(this),write:this.drawSel.bind(this)},this.selectionLayer=n.scrollDOM.appendChild(document.createElement("div")),this.selectionLayer.className="cm-selectionLayer",this.selectionLayer.setAttribute("aria-hidden","true"),this.cursorLayer=n.scrollDOM.appendChild(document.createElement("div")),this.cursorLayer.className="cm-cursorLayer",this.cursorLayer.setAttribute("aria-hidden","true"),n.requestMeasure(this.measureReq),this.setBlinkRate()}setBlinkRate(){this.cursorLayer.style.animationDuration=this.view.state.facet(Zi).cursorBlinkRate+"ms"}update(n){let e=n.startState.facet(Zi)!=n.state.facet(Zi);(e||n.selectionSet||n.geometryChanged||n.viewportChanged)&&this.view.requestMeasure(this.measureReq),n.transactions.some(t=>t.scrollIntoView)&&(this.cursorLayer.style.animationName=this.cursorLayer.style.animationName=="cm-blink"?"cm-blink2":"cm-blink"),e&&this.setBlinkRate()}readPos(){let{state:n}=this.view,e=n.facet(Zi),t=n.selection.ranges.map(s=>s.empty?[]:A0(this.view,s)).reduce((s,r)=>s.concat(r)),i=[];for(let s of n.selection.ranges){let r=s==n.selection.main;if(s.empty?!r||cu:e.drawRangeCursor){let o=E0(this.view,s,r);o&&i.push(o)}}return{rangePieces:t,cursors:i}}drawSel({rangePieces:n,cursors:e}){if(n.length!=this.rangePieces.length||n.some((t,i)=>!t.eq(this.rangePieces[i]))){this.selectionLayer.textContent="";for(let t of n)this.selectionLayer.appendChild(t.draw());this.rangePieces=n}if(e.length!=this.cursors.length||e.some((t,i)=>!t.eq(this.cursors[i]))){let t=this.cursorLayer.children;if(t.length!==e.length){this.cursorLayer.textContent="";for(let i of e)this.cursorLayer.appendChild(i.draw())}else e.forEach((i,s)=>i.adjust(t[s]));this.cursors=e}}destroy(){this.selectionLayer.remove(),this.cursorLayer.remove()}}),fu={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};cu&&(fu[".cm-line"].caretColor="transparent !important");var C0=ze.highest(C.theme(fu));function du(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==I.LTR?e.left:e.right-n.scrollDOM.clientWidth)-n.scrollDOM.scrollLeft,top:e.top-n.scrollDOM.scrollTop}}function lc(n,e,t){let i=m.cursor(e);return{from:Math.max(t.from,n.moveToLineBoundary(i,!1,!0).from),to:Math.min(t.to,n.moveToLineBoundary(i,!0,!0).from),type:$.Text}}function ac(n,e){let t=n.lineBlockAt(e);if(Array.isArray(t.type)){for(let i of t.type)if(i.to>e||i.to==e&&(i.to==t.to||i.type==$.Text))return i}return t}function A0(n,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let t=Math.max(e.from,n.viewport.from),i=Math.min(e.to,n.viewport.to),s=n.textDirection==I.LTR,r=n.contentDOM,o=r.getBoundingClientRect(),l=du(n),a=window.getComputedStyle(r.firstChild),h=o.left+parseInt(a.paddingLeft)+Math.min(0,parseInt(a.textIndent)),c=o.right-parseInt(a.paddingRight),u=ac(n,t),f=ac(n,i),d=u.type==$.Text?u:null,p=f.type==$.Text?f:null;if(n.lineWrapping&&(d&&(d=lc(n,t,d)),p&&(p=lc(n,i,p))),d&&p&&d.from==p.from)return y(b(e.from,e.to,d));{let T=d?b(e.from,null,d):A(u,!1),x=p?b(null,e.to,p):A(f,!0),k=[];return(d||u).to<(p||f).from-1?k.push(g(h,T.bottom,c,x.top)):T.bottom<x.top&&n.elementAtHeight((T.bottom+x.top)/2).type==$.Text&&(T.bottom=x.top=(T.bottom+x.top)/2),y(T).concat(k).concat(y(x))}function g(T,x,k,M){return new Do(T-l.left,x-l.top-.01,k-T,M-x+.01,"cm-selectionBackground")}function y({top:T,bottom:x,horizontal:k}){let M=[];for(let P=0;P<k.length;P+=2)M.push(g(k[P],T,k[P+1],x));return M}function b(T,x,k){let M=1e9,P=-1e9,J=[];function V(Y,ie,Le,fe,be){let Fe=n.coordsAtPos(Y,Y==k.to?-2:2),ue=n.coordsAtPos(Le,Le==k.from?2:-2);M=Math.min(Fe.top,ue.top,M),P=Math.max(Fe.bottom,ue.bottom,P),be==I.LTR?J.push(s&&ie?h:Fe.left,s&&fe?c:ue.right):J.push(!s&&fe?h:ue.left,!s&&ie?c:Fe.right)}let D=T??k.from,W=x??k.to;for(let Y of n.visibleRanges)if(Y.to>D&&Y.from<W)for(let ie=Math.max(Y.from,D),Le=Math.min(Y.to,W);;){let fe=n.state.doc.lineAt(ie);for(let be of n.bidiSpans(fe)){let Fe=be.from+fe.from,ue=be.to+fe.from;if(Fe>=Le)break;ue>ie&&V(Math.max(Fe,ie),T==null&&Fe<=D,Math.min(ue,Le),x==null&&ue>=W,be.dir)}if(ie=fe.to+1,ie>=Le)break}return J.length==0&&V(D,T==null,W,x==null,n.textDirection),{top:M,bottom:P,horizontal:J}}function A(T,x){let k=o.top+(x?T.top:T.bottom);return{top:k,bottom:k,horizontal:[]}}}function E0(n,e,t){let i=n.coordsAtPos(e.head,e.assoc||1);if(!i)return null;let s=du(n);return new Do(i.left-s.left,i.top-s.top,-1,i.bottom-i.top,t?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary")}var pu=L.define({map(n,e){return n==null?null:e.mapPos(n)}}),en=z.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(pu)?i.value:t,n)}}),M0=q.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(en);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(en)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let n=this.view.state.field(en),e=n!=null&&this.view.coordsAtPos(n);if(!e)return null;let t=this.view.scrollDOM.getBoundingClientRect();return{left:e.left-t.left+this.view.scrollDOM.scrollLeft,top:e.top-t.top+this.view.scrollDOM.scrollTop,height:e.bottom-e.top}}drawCursor(n){this.cursor&&(n?(this.cursor.style.left=n.left+"px",this.cursor.style.top=n.top+"px",this.cursor.style.height=n.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(en)!=n&&this.view.dispatch({effects:pu.of(n)})}},{eventHandlers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function mu(){return[en,M0]}function hc(n,e,t,i,s){e.lastIndex=0;for(let r=n.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,o+l.index+l[0].length,l)}function T0(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let i=[];for(let{from:s,to:r}of t)s=Math.max(n.state.doc.lineAt(s).from,s-e),r=Math.min(n.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}var gu=class{constructor(e){let{regexp:t,decoration:i,boundary:s,maxLength:r=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");this.regexp=t,this.getDeco=typeof i=="function"?i:()=>i,this.boundary=s,this.maxLength=r}createDeco(e){let t=new Re;for(let{from:i,to:s}of T0(e,this.maxLength))hc(e.state.doc,this.regexp,i,s,(r,o,l)=>t.add(r,o,this.getDeco(l,e,r)));return t.finish()}updateDeco(e,t){let i=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),e.viewportChanged||s-i>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),i,s):t}updateRange(e,t,i,s){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let a=e.state.doc.lineAt(o),h=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(r.from,a.from),u=Math.min(r.to,h.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){u=l;break}}let f=[],d;if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.index<u-a.from;){let p=d.index+a.from;f.push(this.getDeco(d,e,p).range(p,p+d[0].length))}else hc(e.state.doc,this.regexp,c,u,(p,g,y)=>f.push(this.getDeco(y,e,p).range(p,g)));t=t.update({filterFrom:c,filterTo:u,filter:(p,g)=>p<c||g>u,add:f})}}return t}},Ao=/x/.unicode!=null?"gu":"g",L0=new RegExp(`[\0-\b
|
38
|
+
-\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\uFEFF\uFFF9-\uFFFC]`,Ao),R0={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",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"},Qr=null;function P0(){var n;if(Qr==null&&typeof document<"u"&&document.body){let e=document.body.style;Qr=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return Qr||!1}var us=S.define({combine(n){let e=pe(n,{render:null,specialChars:L0,addSpecialChars:null});return(e.replaceTabs=!P0())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Ao)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Ao)),e}});function bu(n={}){return[us.of(n),O0()]}var cc=null;function O0(){return cc||(cc=q.fromClass(class{constructor(n){this.view=n,this.decorations=E.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(us)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new gu({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=ne(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,a=pt(o.text,l,i-o.from);return E.replace({widget:new vu((l-a%l)*this.view.defaultCharacterWidth)})}return this.decorationCache[r]||(this.decorationCache[r]=E.replace({widget:new yu(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(us);n.startState.facet(us)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}var D0="\u2022";function B0(n){return n>=32?D0:n==10?"\u2424":String.fromCharCode(9216+n)}var yu=class extends De{constructor(e,t){super();this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=B0(this.code),i=e.state.phrase("Control character")+" "+(R0[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}},vu=class extends De{constructor(e){super();this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}};function wu(){return N0}var I0=E.line({class:"cm-activeLine"}),N0=q.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){if(!i.empty)return E.none;let s=n.lineBlockAt(i.head);s.from>e&&(t.push(I0.range(s.from)),e=s.from)}return E.set(t)}},{decorations:n=>n.decorations});var Io=$e.define(),F0=$e.define(),V0=S.define(),Su=S.define({combine(n){return pe(n,{minDepth:100,newGroupDelay:500},{minDepth:Math.max,newGroupDelay:Math.min})}});function H0(n){let e=0;return n.iterChangedRanges((t,i)=>e=i),e}var xu=z.define({create(){return _e.empty},update(n,e){let t=e.state.facet(Su),i=e.annotation(Io);if(i){let a=e.docChanged?m.single(H0(e.changes)):void 0,h=Ce.fromTransaction(e,a),c=i.side,u=c==0?n.undone:n.done;return h?u=vs(u,u.length,t.minDepth,h):u=Mu(u,e.startState.selection),new _e(c==0?i.rest:u,c==0?u:i.rest)}let s=e.annotation(F0);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(ee.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=Ce.fromTransaction(e),o=e.annotation(ee.time),l=e.annotation(ee.userEvent);return r?n=n.addChanges(r,o,l,t.newGroupDelay,t.minDepth):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new _e(n.done.map(Ce.fromJSON),n.undone.map(Ce.fromJSON))}});function ku(n={}){return[xu,Su.of(n),C.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?Cu:e.inputType=="historyRedo"?Au:null;return i?(e.preventDefault(),i(t)):!1}})]}function ws(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(xu,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}var Cu=ws(0,!1),Au=ws(1,!1),q0=ws(0,!0),W0=ws(1,!0);var Ce=class{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new Ce(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new Ce(e.changes&&Q.fromJSON(e.changes),[],e.mapped&&We.fromJSON(e.mapped),e.startSelection&&m.fromJSON(e.startSelection),e.selectionsAfter.map(m.fromJSON))}static fromTransaction(e,t){let i=Be;for(let s of e.startState.facet(V0)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new Ce(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Be)}static selection(e){return new Ce(void 0,Be,void 0,void 0,e)}};function vs(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function z0(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(i=!0)}}),i}function $0(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function Eu(n,e){return n.length?e.length?n.concat(e):n:e}var Be=[],j0=200;function Mu(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-j0));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),vs(n,n.length-1,1e9,t.setSelAfter(i)))}else return[Ce.selection([e])]}function U0(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Bo(n,e){if(!n.length)return n;let t=n.length,i=Be;for(;t;){let s=K0(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[Ce.selection(i)]:Be}function K0(n,e,t){let i=Eu(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Be,t);if(!n.changes)return Ce.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new Ce(s,L.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}var _0=/^(input\.type|delete)($|\.)/,_e=class{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new _e(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||_0.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<s&&z0(l.changes,e.changes)||i=="input.type.compose")?o=vs(o,o.length-1,r,new Ce(e.changes.compose(l.changes),Eu(e.effects,l.effects),l.mapped,l.startSelection,Be)):o=vs(o,o.length,r,e),new _e(o,Be,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Be;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&$0(r[r.length-1],e)?this:new _e(Mu(this.done,e),this.undone,t,i)}addMapping(e){return new _e(Bo(this.done,e),Bo(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1];if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Io.of({side:e,rest:U0(s)}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let o=s.length==1?Be:s.slice(0,s.length-1);return r.mapped&&(o=Bo(o,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Io.of({side:e,rest:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};_e.empty=new _e(Be,Be);var Tu=[{key:"Mod-z",run:Cu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Au,preventDefault:!0},{key:"Mod-u",run:q0,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:W0,preventDefault:!0}];var G0=0,xs=class{constructor(e,t){this.from=e,this.to=t}},O=class{constructor(e={}){this.id=G0++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=ae.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}};O.closedBy=new O({deserialize:n=>n.split(" ")});O.openedBy=new O({deserialize:n=>n.split(" ")});O.group=new O({deserialize:n=>n.split(" ")});O.contextHash=new O({perNode:!0});O.lookAhead=new O({perNode:!0});O.mounted=new O({perNode:!0});var J0=Object.create(null),ae=class{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):J0,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new ae(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(O.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(O.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}};ae.none=new ae("",Object.create(null),0,8);var hn=class{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let s=null;for(let r of e){let o=r(i);o&&(s||(s=Object.assign({},i.props)),s[o[0].id]=o[1])}t.push(s?new ae(i.name,s,i.id,i.flags):i)}return new hn(t)}},Ss=new WeakMap,Lu=new WeakMap,U=class{constructor(e,t,i,s,r){if(this.type=e,this.children=t,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=this.prop(O.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let s=i.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e,t=0){let i=e!=null&&Ss.get(this)||this.topNode,s=new an(i);return e!=null&&(s.moveTo(e,t),Ss.set(this,s._tree)),s}fullCursor(){return new an(this.topNode,1)}get topNode(){return new st(this,0,0,null)}resolve(e,t=0){let i=ki(Ss.get(this)||this.topNode,e,t,!1);return Ss.set(this,i),i}resolveInner(e,t=0){let i=ki(Lu.get(this)||this.topNode,e,t,!0);return Lu.set(this,i),i}iterate(e){let{enter:t,leave:i,from:s=0,to:r=this.length}=e;for(let o=this.cursor(),l=()=>o.node;;){let a=!1;if(o.from<=r&&o.to>=s&&(o.type.isAnonymous||t(o.type,o.from,o.to,l)!==!1)){if(o.firstChild())continue;o.type.isAnonymous||(a=!0)}for(;a&&i&&i(o.type,o.from,o.to,l),a=o.type.isAnonymous,!o.nextSibling();){if(!o.parent())return;a=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Fo(ae.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new U(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new U(ae.none,t,i,s)))}static build(e){return Y0(e)}};U.empty=new U(ae.none,[],[],0);var As=class{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new As(this.buffer,this.index)}},It=class{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ae.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],s=this.set.types[t],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,s,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Pu(r,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i,s){let r=this.buffer,o=new Uint16Array(t-e);for(let l=e,a=0;l<t;)o[a++]=r[l++],o[a++]=r[l++]-i,o[a++]=r[l++]-i,o[a++]=r[l++]-e;return new It(o,s-i,this.set)}};function Pu(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Ou(n,e){let t=n.childBefore(e);for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(n=t,t=i.prevSibling):t=i}return n}function ki(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let r=!i&&n instanceof st&&n.index<0?null:n.parent;if(!r)return n;n=r}if(i)for(let r=n,o=r.parent;o;r=o,o=r.parent)r instanceof st&&r.index<0&&((s=o.enter(e,t,!0))===null||s===void 0?void 0:s.from)!=r.from&&(n=o);for(;;){let r=n.enter(e,t,i);if(!r)return n;n=r}}var st=class{constructor(e,t,i,s){this.node=e,this._from=t,this.index=i,this._parent=s}get type(){return this.node.type}get name(){return this.node.type.name}get from(){return this._from}get to(){return this._from+this.node.length}nextChild(e,t,i,s,r=0){for(let o=this;;){for(let{children:l,positions:a}=o.node,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],u=a[e]+o._from;if(!!Pu(s,i,u,u+c.length)){if(c instanceof It){if(r&2)continue;let f=c.findChild(0,c.buffer.length,t,i-u,s);if(f>-1)return new vt(new Du(o,c,e,u),null,f)}else if(r&1||!c.type.isAnonymous||No(c)){let f;if(!(r&1)&&c.props&&(f=c.prop(O.mounted))&&!f.overlay)return new st(f.tree,u,e,o);let d=new st(c,u,e,o);return r&1||!d.type.isAnonymous?d:d.nextChild(t<0?c.children.length-1:0,t,i,s)}}}if(r&1||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent.node.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this.node.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this.node.children.length-1,-1,e,-2)}enter(e,t,i=!0,s=!0){let r;if(i&&(r=this.node.prop(O.mounted))&&r.overlay){let o=e-this.from;for(let{from:l,to:a}of r.overlay)if((t>0?l<=o:l<o)&&(t<0?a>=o:a>o))return new st(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,s?0:2)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get cursor(){return new an(this)}get tree(){return this.node}toTree(){return this.node}resolve(e,t=0){return ki(this,e,t,!1)}resolveInner(e,t=0){return ki(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Ou(this,e)}getChild(e,t=null,i=null){let s=Cs(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return Cs(this,e,t,i)}toString(){return this.node.toString()}};function Cs(n,e,t,i){let s=n.cursor,r=[];if(!s.firstChild())return r;if(t!=null){for(;!s.type.is(t);)if(!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}var Du=class{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}},vt=class{constructor(e,t,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}child(e,t,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new vt(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,i,s=!0){if(!s)return null;let{buffer:r}=this.context,o=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return o<0?null:new vt(this.context,this,o)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new vt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new vt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get cursor(){return new an(this)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1],l=i.buffer[this.index+2];e.push(i.slice(s,r,o,l)),t.push(0)}return new U(this.type,e,t,this.to-this.from)}resolve(e,t=0){return ki(this,e,t,!1)}resolveInner(e,t=0){return ki(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Ou(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let s=Cs(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return Cs(this,e,t,i)}},an=class{constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof st)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}get name(){return this.type.name}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof st?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree.node.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=!0,s=!0){return this.buffer?s?this.enterChild(1,e,t):!1:this.yield(this._tree.enter(e,t,i&&!(this.mode&1),s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&1?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&1?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=s)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i.node.children.length;r!=o;r+=e){let l=i.node.children[r];if(this.mode&1||l instanceof It||!l.type.isAnonymous||No(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer){e:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}}for(let s=i;s<this.stack.length;s++)t=new vt(this.buffer,t,this.stack[s]);return this.bufferNode=new vt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree.node}};function No(n){return n.children.some(e=>e instanceof It||!e.type.isAnonymous||No(e))}function Y0(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=1024,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new As(t,t.length):t,a=i.types,h=0,c=0;function u(x,k,M,P,J){let{id:V,start:D,end:W,size:Y}=l,ie=c;for(;Y<0;)if(l.next(),Y==-1){let ue=r[V];M.push(ue),P.push(D-x);return}else if(Y==-3){h=V;return}else if(Y==-4){c=V;return}else throw new RangeError(`Unrecognized record size: ${Y}`);let Le=a[V],fe,be,Fe=D-x;if(W-D<=s&&(be=g(l.pos-k,J))){let ue=new Uint16Array(be.size-be.skip),Ve=l.pos-be.size,ct=ue.length;for(;l.pos>Ve;)ct=y(be.start,ue,ct);fe=new It(ue,W-be.start,i),Fe=be.start-x}else{let ue=l.pos-Y;l.next();let Ve=[],ct=[],qt=V>=o?V:-1,oi=0,Rn=W;for(;l.pos>ue;)qt>=0&&l.id==qt&&l.size>=0?(l.end<=Rn-s&&(d(Ve,ct,D,oi,l.end,Rn,qt,ie),oi=Ve.length,Rn=l.end),l.next()):u(D,ue,Ve,ct,qt);if(qt>=0&&oi>0&&oi<Ve.length&&d(Ve,ct,D,oi,D,Rn,qt,ie),Ve.reverse(),ct.reverse(),qt>-1&&oi>0){let Dl=f(Le);fe=Fo(Le,Ve,ct,0,Ve.length,0,W-D,Dl,Dl)}else fe=p(Le,Ve,ct,W-D,ie-W)}M.push(fe),P.push(Fe)}function f(x){return(k,M,P)=>{let J=0,V=k.length-1,D,W;if(V>=0&&(D=k[V])instanceof U){if(!V&&D.type==x&&D.length==P)return D;(W=D.prop(O.lookAhead))&&(J=M[V]+D.length+W)}return p(x,k,M,P,J)}}function d(x,k,M,P,J,V,D,W){let Y=[],ie=[];for(;x.length>P;)Y.push(x.pop()),ie.push(k.pop()+M-J);x.push(p(i.types[D],Y,ie,V-J,W-V)),k.push(J-M)}function p(x,k,M,P,J=0,V){if(h){let D=[O.contextHash,h];V=V?[D].concat(V):[D]}if(J>25){let D=[O.lookAhead,J];V=V?[D].concat(V):[D]}return new U(x,k,M,P,V)}function g(x,k){let M=l.fork(),P=0,J=0,V=0,D=M.end-s,W={size:0,start:0,skip:0};e:for(let Y=M.pos-x;M.pos>Y;){let ie=M.size;if(M.id==k&&ie>=0){W.size=P,W.start=J,W.skip=V,V+=4,P+=4,M.next();continue}let Le=M.pos-ie;if(ie<0||Le<Y||M.start<D)break;let fe=M.id>=o?4:0,be=M.start;for(M.next();M.pos>Le;){if(M.size<0)if(M.size==-3)fe+=4;else break e;else M.id>=o&&(fe+=4);M.next()}J=be,P+=ie,V+=fe}return(k<0||P==x)&&(W.size=P,W.start=J,W.skip=V),W.size>4?W:void 0}function y(x,k,M){let{id:P,start:J,end:V,size:D}=l;if(l.next(),D>=0&&P<o){let W=M;if(D>4){let Y=l.pos-(D-4);for(;l.pos>Y;)M=y(x,k,M)}k[--M]=W,k[--M]=V-x,k[--M]=J-x,k[--M]=P}else D==-3?h=P:D==-4&&(c=P);return M}let b=[],A=[];for(;l.pos>0;)u(n.start||0,n.bufferStart||0,b,A,-1);let T=(e=n.length)!==null&&e!==void 0?e:b.length?A[0]+b[0].length:0;return new U(a[n.topID],b.reverse(),A.reverse(),T)}var Ru=new WeakMap;function ks(n,e){if(!n.isAnonymous||e instanceof It||e.type!=n)return 1;let t=Ru.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof U)){t=1;break}t+=ks(n,i)}Ru.set(e,t)}return t}function Fo(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p<s;p++)h+=ks(n,e[p]);let c=Math.ceil(h*1.5/8),u=[],f=[];function d(p,g,y,b,A){for(let T=y;T<b;){let x=T,k=g[T],M=ks(n,p[T]);for(T++;T<b;T++){let P=ks(n,p[T]);if(M+P>=c)break;M+=P}if(T==x+1){if(M>c){let P=p[x];d(P.children,P.positions,0,P.children.length,g[x]+A);continue}u.push(p[x])}else{let P=g[T-1]+p[T-1].length-k;u.push(Fo(n,p,g,x,T,k,P,null,a))}f.push(k+A-r)}}return d(e,t,i,s,0),(l||a)(u,f,o)}var wt=class{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new wt(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,u=c?c.fromA:1e9;if(u-a>=i)for(;o&&o.from<u;){let f=o;if(a>=f.from||u<=f.to||h){let d=Math.max(f.from,a)-h,p=Math.min(f.to,u)-h;f=d>=p?null:new wt(d,p,f.tree,f.offset+h,l>0,!!c)}if(f&&s.push(f),o.to>u)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return s}},cn=class{startParse(e,t,i){return typeof e=="string"&&(e=new Bu(e)),i=i?i.length?i.map(s=>new xs(s.from,s.to)):[new xs(0,0)]:[new xs(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}},Bu=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var IS=new O({perNode:!0});var fn=new O;function Fu(n){return S.define({combine:n?e=>e.concat(n):void 0})}var Ie=class{constructor(e,t,i,s=[]){this.data=e,this.topNode=i,B.prototype.hasOwnProperty("tree")||Object.defineProperty(B.prototype,"tree",{get(){return te(this)}}),this.parser=t,this.extension=[St.of(this),B.languageData.of((r,o,l)=>r.facet(Iu(r,o,l)))].concat(s)}isActiveAt(e,t,i=-1){return Iu(e,t,i)==this.data}findRegions(e){let t=e.facet(St);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(fn)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(O.mounted);if(l){if(l.tree.prop(fn)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let h=r.children[a];h instanceof U&&s(h,r.positions[a]+o)}};return s(te(e),0),i}get allowsNesting(){return!0}};Ie.setState=L.define();function Iu(n,e,t){let i=n.facet(St);if(!i)return null;let s=i.data;if(i.allowsNesting)for(let r=te(n).topNode;r;r=r.enter(e,t,!0,!1))s=r.type.prop(fn)||s;return s}function te(n){let e=n.field(Ie.state,!1);return e?e.tree:U.empty}var Vu=class{constructor(e,t=e.length){this.doc=e,this.length=t,this.cursorPos=0,this.string="",this.cursor=e.iter()}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}},un=null,Yt=class{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}startParse(){return this.parser.startParse(new Vu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=U.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;let s=Date.now()+e;for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let r=this.parse.advance();if(r)if(this.fragments=this.withoutTempSkipped(wt.addTree(r,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=r,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(Date.now()>s)return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(wt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=un;un=this;try{return e()}finally{un=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Nu(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,u,f)=>a.push({fromA:h,toA:c,fromB:u,toB:f})),i=wt.applyChanges(i,a),s=U.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),u=e.mapPos(h.to,-1);c<u&&l.push({from:c,to:u})}}}return new Yt(this.parser,t,i,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=Nu(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends cn{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=un;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new U(ae.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return un}};function Nu(n,e,t){return wt.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}var Jt=class{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new Jt(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=new Yt(e.facet(St).parser,e,[],U.empty,0,{from:0,to:t},[],null);return i.work(20,t)||i.takeTree(),new Jt(i)}};Ie.state=z.define({create:Jt.init,update(n,e){for(let t of e.effects)if(t.is(Ie.setState))return t.value;return e.startState.facet(St)!=e.state.facet(St)?Jt.init(e.state):n.apply(e)}});var Hu=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Hu=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var X0=q.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Ie.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Ie.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Hu(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Ie.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Math.min(this.chunkBudget,100,e?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Ie.setState.of(new Jt(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>ge(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return this.working||this.workScheduled>0}},{eventHandlers:{focus(){this.scheduleWork()}}}),St=S.define({combine(n){return n.length?n[0]:null},enables:[Ie.state,X0]});var Vo=S.define(),dn=S.define({combine:n=>{if(!n.length)return" ";if(!/^(?: +|\t+)$/.test(n[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return n[0]}});function xt(n){let e=n.facet(dn);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Ci(n,e){let t="",i=n.tabSize;if(n.facet(dn).charCodeAt(0)==9)for(;e>=i;)t+=" ",e-=i;for(let s=0;s<e;s++)t+=" ";return t}function Es(n,e){n instanceof B&&(n=new Ai(n));for(let i of n.state.facet(Vo)){let s=i(n,e);if(s!=null)return s}let t=te(n.state);return t?Z0(n,t,e):null}var Ai=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=xt(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(e,t);return i.slice(e-s,Math.min(i.length,e+100-s))}column(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.countColumn(i,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return pt(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},Q0=new O;function Z0(n,e,t){return qu(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,n)}function eb(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function tb(n){let e=n.type.prop(Q0);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(O.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>rb(o,!0,1,void 0,r&&!eb(o)?s.from:void 0)}return n.parent==null?ib:null}function qu(n,e,t){for(;n;n=n.parent){let i=tb(n);if(i)return i(new Wu(t,e,n))}return null}function ib(){return 0}var Wu=class extends Ai{constructor(e,t,i){super(e.state,e.options);this.base=e,this.pos=t,this.node=i}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let e=this.state.doc.lineAt(this.node.from);for(;;){let t=this.node.resolve(e.from);for(;t.parent&&t.parent.from==t.from;)t=t.parent;if(nb(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?qu(e,this.pos,this.base):0}};function nb(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function sb(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.from<o?t:null;l=a.to}}function rb(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=e?sb(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}var ob=200;function zu(){return B.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,s=t.lineAt(i);if(i>s.from+ob)return n;let r=t.sliceString(s.from,i);if(!e.some(h=>h.test(r)))return n;let{state:o}=n,l=-1,a=[];for(let{head:h}of o.selection.ranges){let c=o.doc.lineAt(h);if(c.from==l)continue;l=c.from;let u=Es(o,c.from);if(u==null)continue;let f=/^\s*/.exec(c.text)[0],d=Ci(o,u);f!=d&&a.push({from:c.from,to:c.from+f.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}var lb=S.define(),ab=new O;function hb(n,e,t){let i=te(n);if(i.length==0)return null;let s=i.resolveInner(t),r=null;for(let o=s;o;o=o.parent){if(o.to<=t||o.from>t)continue;if(r&&o.from<e)break;let l=o.type.prop(ab);if(l){let a=l(o,n);a&&a.from<=t&&a.from>=e&&a.to>t&&(r=a)}}return r}function pn(n,e,t){for(let i of n.facet(lb)){let s=i(n,e,t);if(s)return s}return hb(n,e,t)}var Ge=class extends Ue{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Ge.prototype.elementClass="";Ge.prototype.toDOM=void 0;Ge.prototype.mapMode=Z.TrackBefore;Ge.prototype.startSide=Ge.prototype.endSide=-1;Ge.prototype.point=!0;var Ms=S.define(),cb={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>F.empty,lineMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},mn=S.define();function Uu(n){return[Ku(),mn.of(Object.assign(Object.assign({},cb),n))]}var ub=C.baseTheme({".cm-gutters":{display:"flex",height:"100%",boxSizing:"border-box",left:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#999",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"}}),qo=S.define({combine:n=>n.some(e=>e)});function Ku(n){let e=[fb,ub];return n&&n.fixed===!1&&e.push(qo.of(!0)),e}var fb=q.fromClass(class{constructor(n){this.view=n,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight+"px",this.gutters=n.state.facet(mn).map(e=>new Wo(n,e));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!n.state.facet(qo),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}n.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(qo)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&this.dom.remove();let t=F.iter(this.view.state.facet(Ms),this.view.viewport.from),i=[],s=this.gutters.map(r=>new Gu(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks){let o;if(Array.isArray(r.type)){for(let l of r.type)if(l.type==$.Text){o=l;break}}else o=r.type==$.Text?r:void 0;if(!!o){i.length&&(i=[]),_u(t,i,r.from);for(let l of s)l.line(this.view,o,i)}}for(let r of s)r.finish();n&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(n){let e=n.startState.facet(mn),t=n.state.facet(mn),i=n.docChanged||n.heightChanged||n.viewportChanged||!F.eq(n.startState.facet(Ms),n.state.facet(Ms),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new Wo(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove()}},{provide:re.scrollMargins.from(n=>n.gutters.length==0||!n.fixed?null:n.view.textDirection==I.LTR?{left:n.dom.offsetWidth}:{right:n.dom.offsetWidth})});function $u(n){return Array.isArray(n)?n:[n]}function _u(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}var Gu=class{constructor(e,t,i){this.gutter=e,this.height=i,this.localMarkers=[],this.i=0,this.cursor=F.iter(e.markers,t.from)}line(e,t,i){this.localMarkers.length&&(this.localMarkers=[]),_u(this.cursor,this.localMarkers,t.from);let s=i.length?this.localMarkers.concat(i):this.localMarkers,r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;if(s.length==0&&!o.config.renderEmptyElements)return;let l=t.top-this.height;if(this.i==o.elements.length){let a=new zo(e,t.height,l,s);o.elements.push(a),o.dom.appendChild(a.dom)}else o.elements[this.i].update(e,t.height,l,s);this.height=t.bottom,this.i++}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Wo=class{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=e.lineBlockAtHeight(s.clientY-e.documentTop);t.domEventHandlers[i](e,r,s)&&s.preventDefault()});this.markers=$u(t.markers(e)),t.initialSpacer&&(this.spacer=new zo(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=$u(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!F.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},zo=class{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.dom.style.height=(this.height=t)+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),db(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let u=o;u<this.markers.length;u++)if(this.markers[u].compare(a)){l=u,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(s);let u=s.nextSibling;s.remove(),s=u}}if(!a)break;a.toDOM&&(h?s=s.nextSibling:this.dom.insertBefore(a.toDOM(e),s)),h&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}};function db(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}var pb=S.define(),Ei=S.define({combine(n){return pe(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let s in t){let r=i[s],o=t[s];i[s]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}}),Ts=class extends Ge{constructor(e){super();this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Ho(n,e){return n.state.facet(Ei).formatNumber(e,n.state)}var mb=mn.compute([Ei],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(pb)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new Ts(Ho(e,e.state.doc.lineAt(t.from).number))},lineMarkerChange:e=>e.startState.facet(Ei)!=e.state.facet(Ei),initialSpacer(e){return new Ts(Ho(e,ju(e.state.doc.lines)))},updateSpacer(e,t){let i=Ho(t.view,ju(t.view.state.doc.lines));return i==e.number?e:new Ts(i)},domEventHandlers:n.facet(Ei).domEventHandlers}));function Ju(n={}){return[Ei.of(n),Ku(),mb]}function ju(n){let e=9;for(;e<n;)e=e*10+9;return e}var gb=new class extends Ge{constructor(){super(...arguments);this.elementClass="cm-activeLineGutter"}},bb=Ms.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges)if(i.empty){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(gb.range(s)))}return F.of(e)});function Yu(){return bb}function Xu(n,e){let t=e.mapPos(n.from,1),i=e.mapPos(n.to,-1);return t>=i?void 0:{from:t,to:i}}var Ps=L.define({map:Xu}),gn=L.define({map:Xu});function Qu(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(n.lineBlockAt(t));return e}var Xt=z.define({create(){return E.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)t.is(Ps)&&!yb(n,t.value.from,t.value.to)?n=n.update({add:[Cb.range(t.value.from,t.value.to)]}):t.is(gn)&&(n=n.update({filter:(i,s)=>t.value.from!=i||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));if(e.selection){let t=!1,{head:i}=e.selection.main;n.between(i,i,(s,r)=>{s<i&&r>i&&(t=!0)}),t&&(n=n.update({filterFrom:i,filterTo:i,filter:(s,r)=>r<=i||s>=i}))}return n},provide:n=>C.decorations.from(n)});function Rs(n,e,t){var i;let s=null;return(i=n.field(Xt,!1))===null||i===void 0||i.between(e,t,(r,o)=>{(!s||s.from>r)&&(s={from:r,to:o})}),s}function yb(n,e,t){let i=!1;return n.between(e,e,(s,r)=>{s==e&&r==t&&(i=!0)}),i}function Zu(n,e){return n.field(Xt,!1)?e:e.concat(L.appendConfig.of(sf()))}var vb=n=>{for(let e of Qu(n)){let t=pn(n.state,e.from,e.to);if(t)return n.dispatch({effects:Zu(n.state,[Ps.of(t),ef(n,t)])}),!0}return!1},wb=n=>{if(!n.state.field(Xt,!1))return!1;let e=[];for(let t of Qu(n)){let i=Rs(n.state,t.from,t.to);i&&e.push(gn.of(i),ef(n,i,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function ef(n,e,t=!0){let i=n.state.doc.lineAt(e.from).number,s=n.state.doc.lineAt(e.to).number;return C.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${n.state.phrase("to")} ${s}.`)}var Sb=n=>{let{state:e}=n,t=[];for(let i=0;i<e.doc.length;){let s=n.lineBlockAt(i),r=pn(e,s.from,s.to);r&&t.push(Ps.of(r)),i=(r?n.lineBlockAt(r.to):s).to+1}return t.length&&n.dispatch({effects:Zu(n.state,t)}),!!t.length},xb=n=>{let e=n.state.field(Xt,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(i,s)=>{t.push(gn.of({from:i,to:s}))}),n.dispatch({effects:t}),!0},tf=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:vb},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:wb},{key:"Ctrl-Alt-[",run:Sb},{key:"Ctrl-Alt-]",run:xb}],kb={placeholderDOM:null,placeholderText:"\u2026"},nf=S.define({combine(n){return pe(n,kb)}});function sf(n){let e=[Xt,Eb];return n&&e.push(nf.of(n)),e}var Cb=E.replace({widget:new class extends De{toDOM(n){let{state:e}=n,t=e.facet(nf),i=r=>{let o=n.lineBlockAt(n.posAtDOM(r.target)),l=Rs(n.state,o.from,o.to);l&&n.dispatch({effects:gn.of(l)}),r.preventDefault()};if(t.placeholderDOM)return t.placeholderDOM(n,i);let s=document.createElement("span");return s.textContent=t.placeholderText,s.setAttribute("aria-label",e.phrase("folded code")),s.title=e.phrase("unfold"),s.className="cm-foldPlaceholder",s.onclick=i,s}}}),Ab={openText:"\u2304",closedText:"\u203A",markerDOM:null,domEventHandlers:{}},Ls=class extends Ge{constructor(e,t){super();this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}};function rf(n={}){let e=Object.assign(Object.assign({},Ab),n),t=new Ls(e,!0),i=new Ls(e,!1),s=q.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(St)!=o.state.facet(St)||o.startState.field(Xt,!1)!=o.state.field(Xt,!1))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new Re;for(let a of o.viewportLineBlocks){let h=Rs(o.state,a.from,a.to)?i:pn(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:r}=e;return[s,Uu({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||F.empty},initialSpacer(){return new Ls(e,!1)},domEventHandlers:Object.assign(Object.assign({},r),{click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let h=Rs(o.state,l.from,l.to);if(h)return o.dispatch({effects:gn.of(h)}),!0;let c=pn(o.state,l.from,l.to);return c?(o.dispatch({effects:Ps.of(c)}),!0):!1}})}),sf()]}var Eb=C.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"}});var Mb=C.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),of=1e4,lf="()[]{}",af=S.define({combine(n){return pe(n,{afterCursor:!0,brackets:lf,maxScanDistance:of})}}),Tb=E.mark({class:"cm-matchingBracket"}),Lb=E.mark({class:"cm-nonmatchingBracket"}),Rb=z.define({create(){return E.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(af);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=Je(e.state,s.head,-1,i)||s.head>0&&Je(e.state,s.head-1,1,i)||i.afterCursor&&(Je(e.state,s.head,1,i)||s.head<e.state.doc.length&&Je(e.state,s.head+1,-1,i));if(!r)continue;let o=r.matched?Tb:Lb;t.push(o.range(r.start.from,r.start.to)),r.end&&t.push(o.range(r.end.from,r.end.to))}return E.set(t,!0)},provide:n=>C.decorations.from(n)}),Pb=[Rb,Mb];function hf(n={}){return[af.of(n),Pb]}function $o(n,e,t){let i=n.prop(e<0?O.openedBy:O.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function Je(n,e,t,i={}){let s=i.maxScanDistance||of,r=i.brackets||lf,o=te(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=$o(a.type,t,r);if(h&&a.from<a.to)return Ob(n,e,t,a,h,r)}return Db(n,e,t,o,l.type,s,r)}function Ob(n,e,t,i,s,r){let o=i.parent,l={from:i.from,to:i.to},a=0,h=o?.cursor;if(h&&(t<0?h.childBefore(i.from):h.childAfter(i.to)))do if(t<0?h.to<=i.from:h.from>=i.to){if(a==0&&s.indexOf(h.type.name)>-1&&h.from<h.to)return{start:l,end:{from:h.from,to:h.to},matched:!0};if($o(h.type,t,r))a++;else if($o(h.type,-t,r)&&(a--,a==0))return{start:l,end:h.from==h.to?void 0:{from:h.from,to:h.to},matched:!1}}while(t<0?h.prevSibling():h.nextSibling());return{start:l,matched:!1}}function Db(n,e,t,i,s,r,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),u=0;for(let f=0;!c.next().done&&f<=r;){let d=c.value;t<0&&(f+=d.length);let p=e+f*t;for(let g=t>0?0:d.length-1,y=t>0?d.length:-1;g!=y;g+=t){let b=o.indexOf(d[g]);if(!(b<0||i.resolve(p+g,1).type!=s))if(b%2==0==t>0)u++;else{if(u==1)return{start:h,end:{from:p+g,to:p+g+1},matched:b>>1==a>>1};u--}}t>0&&(f+=d.length)}return c.done?{start:h,matched:!1}:null}function Mi(n,e){return m.create(n.ranges.map(e),n.mainIndex)}function rt(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function kt({state:n,dispatch:e},t){let i=Mi(n.selection,t);return i.eq(n.selection)?!1:(e(rt(n,i)),!0)}function Os(n,e){return m.cursor(e?n.to:n.from)}function Sf(n,e){return kt(n,t=>t.empty?n.moveByChar(t,e):Os(t,e))}var xf=n=>Sf(n,n.textDirection!=I.LTR),kf=n=>Sf(n,n.textDirection==I.LTR);function Cf(n,e){return kt(n,t=>t.empty?n.moveByGroup(t,e):Os(t,e))}var Bb=n=>Cf(n,n.textDirection!=I.LTR),Ib=n=>Cf(n,n.textDirection==I.LTR);function Nb(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function Ds(n,e,t){let i=te(n).resolveInner(e.head),s=t?O.closedBy:O.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Nb(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?Je(n,i.from,1):Je(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,m.cursor(l,t?-1:1)}var Fb=n=>kt(n,e=>Ds(n.state,e,n.textDirection!=I.LTR)),Vb=n=>kt(n,e=>Ds(n.state,e,n.textDirection==I.LTR));function Af(n,e){return kt(n,t=>{if(!t.empty)return Os(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}var Ef=n=>Af(n,!1),Mf=n=>Af(n,!0);function Tf(n,e){let{state:t}=n,i=Mi(t.selection,o=>o.empty?n.moveVertically(o,e,n.dom.clientHeight):Os(o,e));if(i.eq(t.selection))return!1;let s=n.coordsAtPos(t.selection.main.head),r=n.scrollDOM.getBoundingClientRect();return n.dispatch(rt(t,i),{effects:s&&s.top>r.top&&s.bottom<r.bottom?C.scrollIntoView(i.main.head,{y:"start",yMargin:s.top-r.top}):void 0}),!0}var cf=n=>Tf(n,!1),jo=n=>Tf(n,!0);function Bs(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=m.cursor(i.from+r))}return s}var uf=n=>kt(n,e=>Bs(n,e,!0)),ff=n=>kt(n,e=>Bs(n,e,!1)),Hb=n=>kt(n,e=>m.cursor(n.lineBlockAt(e.head).from,1)),qb=n=>kt(n,e=>m.cursor(n.lineBlockAt(e.head).to,-1));function Wb(n,e,t){let i=!1,s=Mi(n.selection,r=>{let o=Je(n,r.head,-1)||Je(n,r.head,1)||r.head>0&&Je(n,r.head-1,1)||r.head<n.doc.length&&Je(n,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 t?m.range(r.anchor,l):m.cursor(l)});return i?(e(rt(n,s)),!0):!1}var zb=({state:n,dispatch:e})=>Wb(n,e,!1);function ot(n,e){let t=Mi(n.state.selection,i=>{let s=e(i);return m.range(i.anchor,s.head,s.goalColumn)});return t.eq(n.state.selection)?!1:(n.dispatch(rt(n.state,t)),!0)}function Lf(n,e){return ot(n,t=>n.moveByChar(t,e))}var Rf=n=>Lf(n,n.textDirection!=I.LTR),Pf=n=>Lf(n,n.textDirection==I.LTR);function Of(n,e){return ot(n,t=>n.moveByGroup(t,e))}var $b=n=>Of(n,n.textDirection!=I.LTR),jb=n=>Of(n,n.textDirection==I.LTR);var Ub=n=>ot(n,e=>Ds(n.state,e,n.textDirection!=I.LTR)),Kb=n=>ot(n,e=>Ds(n.state,e,n.textDirection==I.LTR));function Df(n,e){return ot(n,t=>n.moveVertically(t,e))}var Bf=n=>Df(n,!1),If=n=>Df(n,!0);function Nf(n,e){return ot(n,t=>n.moveVertically(t,e,n.dom.clientHeight))}var df=n=>Nf(n,!1),pf=n=>Nf(n,!0),mf=n=>ot(n,e=>Bs(n,e,!0)),gf=n=>ot(n,e=>Bs(n,e,!1)),_b=n=>ot(n,e=>m.cursor(n.lineBlockAt(e.head).from)),Gb=n=>ot(n,e=>m.cursor(n.lineBlockAt(e.head).to)),bf=({state:n,dispatch:e})=>(e(rt(n,{anchor:0})),!0),yf=({state:n,dispatch:e})=>(e(rt(n,{anchor:n.doc.length})),!0),vf=({state:n,dispatch:e})=>(e(rt(n,{anchor:n.selection.main.anchor,head:0})),!0),wf=({state:n,dispatch:e})=>(e(rt(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),Jb=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Yb=({state:n,dispatch:e})=>{let t=Fs(n).map(({from:i,to:s})=>m.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:m.create(t),userEvent:"select"})),!0},Xb=({state:n,dispatch:e})=>{let t=Mi(n.selection,i=>{var s;let r=te(n).resolveInner(i.head,1);for(;!(r.from<i.from&&r.to>=i.to||r.to>i.to&&r.from<=i.from||!(!((s=r.parent)===null||s===void 0)&&s.parent));)r=r.parent;return m.range(r.to,r.from)});return e(rt(n,t)),!0},Qb=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=m.create([t.main]):t.main.empty||(i=m.create([m.cursor(t.main.head)])),i?(e(rt(n,i)),!0):!1};function Is({state:n,dispatch:e},t){if(n.readOnly)return!1;let i="delete.selection",s=n.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=t(o);a<o?i="delete.backward":a>o&&(i="delete.forward"),o=Math.min(o,a),l=Math.max(l,a)}return o==l?{range:r}:{changes:{from:o,to:l},range:m.cursor(o)}});return s.changes.empty?!1:(e(n.update(s,{scrollIntoView:!0,userEvent:i})),!0)}function Ns(n,e,t){if(n instanceof C)for(let i of n.pluginField(re.atomicRanges))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}var Ff=(n,e)=>Is(n,t=>{let{state:i}=n,s=i.doc.lineAt(t),r,o;if(!e&&t>s.from&&t<s.from+200&&!/[^ \t]/.test(r=s.text.slice(0,t-s.from))){if(r[r.length-1]==" ")return t-1;let l=pt(r,i.tabSize),a=l%xt(i)||xt(i);for(let h=0;h<a&&r[r.length-1-h]==" ";h++)t--;o=t}else o=de(s.text,t-s.from,e,e)+s.from,o==t&&s.number!=(e?i.doc.lines:1)&&(o+=e?1:-1);return Ns(n,o,e)}),Uo=n=>Ff(n,!1),Vf=n=>Ff(n,!0),Hf=(n,e)=>Is(n,t=>{let i=t,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=de(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t)&&(l=c),i=a}return Ns(n,i,e)}),qf=n=>Hf(n,!1),Zb=n=>Hf(n,!0),Wf=n=>Is(n,e=>{let t=n.lineBlockAt(e).to;return Ns(n,e<t?t:Math.min(n.state.doc.length,e+1),!0)}),ey=n=>Is(n,e=>{let t=n.lineBlockAt(e).from;return Ns(n,e>t?t:Math.max(0,e-1),!1)});var ty=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:N.of(["",""])},range:m.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},iy=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:de(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:de(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:m.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Fs(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function zf(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of Fs(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(m.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(m.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:m.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var ny=({state:n,dispatch:e})=>zf(n,e,!1),sy=({state:n,dispatch:e})=>zf(n,e,!0);function $f(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of Fs(n))t?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});return e(n.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}var ry=({state:n,dispatch:e})=>$f(n,e,!1),oy=({state:n,dispatch:e})=>$f(n,e,!0),ly=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(Fs(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=Mi(e.selection,s=>n.moveVertically(s,!0)).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function ay(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=te(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(O.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from?{from:i.to,to:s.from}:null}var hy=jf(!1),cy=jf(!0);function jf(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&ay(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Ai(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=Es(h,r);for(c==null&&(c=/^\s*/.exec(e.doc.lineAt(r).text)[0].length);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 u=["",Ci(e,c)];return a&&u.push(Ci(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:N.of(u)},range:m.cursor(r+1+u[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Ko(n,e){let t=-1;return n.changeByRange(i=>{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:m.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}var uy=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Ai(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=Ko(n,(r,o,l)=>{let a=Es(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=Ci(n,a);(h!=c||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},Uf=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Ko(n,(t,i)=>{i.push({from:t.from,insert:n.facet(dn)})}),{userEvent:"input.indent"})),!0),Kf=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Ko(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=pt(s,n.tabSize),o=0,l=Ci(n,Math.max(0,r-xt(n)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0);var fy=[{key:"Ctrl-b",run:xf,shift:Rf,preventDefault:!0},{key:"Ctrl-f",run:kf,shift:Pf},{key:"Ctrl-p",run:Ef,shift:Bf},{key:"Ctrl-n",run:Mf,shift:If},{key:"Ctrl-a",run:Hb,shift:_b},{key:"Ctrl-e",run:qb,shift:Gb},{key:"Ctrl-d",run:Vf},{key:"Ctrl-h",run:Uo},{key:"Ctrl-k",run:Wf},{key:"Ctrl-Alt-h",run:qf},{key:"Ctrl-o",run:ty},{key:"Ctrl-t",run:iy},{key:"Ctrl-v",run:jo}],dy=[{key:"ArrowLeft",run:xf,shift:Rf,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Bb,shift:$b},{mac:"Cmd-ArrowLeft",run:ff,shift:gf},{key:"ArrowRight",run:kf,shift:Pf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Ib,shift:jb},{mac:"Cmd-ArrowRight",run:uf,shift:mf},{key:"ArrowUp",run:Ef,shift:Bf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:bf,shift:vf},{mac:"Ctrl-ArrowUp",run:cf,shift:df},{key:"ArrowDown",run:Mf,shift:If,preventDefault:!0},{mac:"Cmd-ArrowDown",run:yf,shift:wf},{mac:"Ctrl-ArrowDown",run:jo,shift:pf},{key:"PageUp",run:cf,shift:df},{key:"PageDown",run:jo,shift:pf},{key:"Home",run:ff,shift:gf},{key:"Mod-Home",run:bf,shift:vf},{key:"End",run:uf,shift:mf},{key:"Mod-End",run:yf,shift:wf},{key:"Enter",run:hy},{key:"Mod-a",run:Jb},{key:"Backspace",run:Uo,shift:Uo},{key:"Delete",run:Vf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:qf},{key:"Mod-Delete",mac:"Alt-Delete",run:Zb},{mac:"Mod-Backspace",run:ey},{mac:"Mod-Delete",run:Wf}].concat(fy.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),_f=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Fb,shift:Ub},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Vb,shift:Kb},{key:"Alt-ArrowUp",run:ny},{key:"Shift-Alt-ArrowUp",run:ry},{key:"Alt-ArrowDown",run:sy},{key:"Shift-Alt-ArrowDown",run:oy},{key:"Escape",run:Qb},{key:"Mod-Enter",run:cy},{key:"Alt-l",mac:"Ctrl-l",run:Yb},{key:"Mod-i",run:Xb,preventDefault:!0},{key:"Mod-[",run:Kf},{key:"Mod-]",run:Uf},{key:"Mod-Alt-\\",run:uy},{key:"Shift-Mod-k",run:ly},{key:"Shift-Mod-\\",run:zb}].concat(dy),Gf={key:"Tab",run:Uf,shift:Kf};var Vs={brackets:["(","[","{","'",'"'],before:`)]}'":;>`},Qt=L.define({map(n,e){let t=e.mapPos(n,-1,Z.TrackAfter);return t??void 0}}),Go=L.define({map(n,e){return e.mapPos(n)}}),Jo=new class extends Ue{};Jo.startSide=1;Jo.endSide=-1;var Yf=z.define({create(){return F.empty},update(n,e){if(e.selection){let t=e.state.doc.lineAt(e.selection.main.head).from,i=e.startState.doc.lineAt(e.startState.selection.main.head).from;t!=e.changes.mapPos(i,-1)&&(n=F.empty)}n=n.map(e.changes);for(let t of e.effects)t.is(Qt)?n=n.update({add:[Jo.range(t.value,t.value+1)]}):t.is(Go)&&(n=n.update({filter:i=>i!=t.value}));return n}});function Xf(){return[my,Yf]}var _o="()[]{}<>";function Qf(n){for(let e=0;e<_o.length;e+=2)if(_o.charCodeAt(e)==n)return _o.charAt(e+1);return mi(n<128?n:n+1)}function Zf(n,e){return n.languageDataAt("closeBrackets",e)[0]||Vs}var py=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),my=C.inputHandler.of((n,e,t,i)=>{if((py?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&Se(ne(i,0))==1||e!=s.from||t!=s.to)return!1;let r=by(n.state,i);return r?(n.dispatch(r),!0):!1}),gy=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=Zf(n,n.selection.main.head).brackets||Vs.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=yy(n.doc,o.head);for(let a of i)if(a==l&&Hs(n.doc,o.head)==Qf(ne(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:m.cursor(o.head-a.length),userEvent:"delete.backward"}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0})),!s},ed=[{key:"Backspace",run:gy}];function by(n,e){let t=Zf(n,n.selection.main.head),i=t.brackets||Vs.brackets;for(let s of i){let r=Qf(ne(s,0));if(e==s)return r==s?Sy(n,s,i.indexOf(s+s+s)>-1):vy(n,s,r,t.before||Vs.before);if(e==r&&td(n,n.selection.main.from))return wy(n,s,r)}return null}function td(n,e){let t=!1;return n.field(Yf).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function Hs(n,e){let t=n.sliceString(e,e+2);return t.slice(0,Se(ne(t,0)))}function yy(n,e){let t=n.sliceString(e-2,e);return Se(ne(t,0))==t.length?t:t.slice(1)}function vy(n,e,t,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:Qt.of(o.to+e.length),range:m.range(o.anchor+e.length,o.head+e.length)};let l=Hs(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:Qt.of(o.head+e.length),range:m.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function wy(n,e,t){let i=null,s=n.selection.ranges.map(r=>r.empty&&Hs(n.doc,r.head)==t?m.cursor(r.head+t.length):i=r);return i?null:n.update({selection:m.create(s,n.selection.mainIndex),scrollIntoView:!0,effects:n.selection.ranges.map(({from:r})=>Go.of(r))})}function Sy(n,e,t){let i=null,s=n.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:e,from:r.to}],effects:Qt.of(r.to+e.length),range:m.range(r.anchor+e.length,r.head+e.length)};let o=r.head,l=Hs(n.doc,o);if(l==e){if(Jf(n,o))return{changes:{insert:e+e,from:o},effects:Qt.of(o+e.length),range:m.cursor(o+e.length)};if(td(n,o)){let a=t&&n.sliceDoc(o,o+e.length*3)==e+e+e;return{range:m.cursor(o+e.length*(a?3:1)),effects:Go.of(o)}}}else{if(t&&n.sliceDoc(o-2*e.length,o)==e+e&&Jf(n,o-2*e.length))return{changes:{insert:e+e+e+e,from:o},effects:Qt.of(o+e.length),range:m.cursor(o+e.length)};if(n.charCategorizer(o)(l)!=oe.Word){let a=n.sliceDoc(o-1,o);if(a!=e&&n.charCategorizer(o)(a)!=oe.Word&&!xy(n,o,e))return{changes:{insert:e+e,from:o},effects:Qt.of(o+e.length),range:m.cursor(o+e.length)}}}return{range:i=r}});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Jf(n,e){let t=te(n).resolveInner(e+1);return t.parent&&t.from==e}function xy(n,e,t){let i=te(n).resolveInner(e,-1);for(let s=0;s<5;s++){if(n.sliceDoc(i.from,i.from+t.length)==t)return!0;let r=i.to==e&&i.parent;if(!r)break;i=r}return!1}var id=S.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function ei(n,e){let t=n.plugin(sd),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}var sd=q.fromClass(class{constructor(n){this.input=n.state.facet(Zt),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(id);this.top=new bn(n,!0,e.topContainer),this.bottom=new bn(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(id);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new bn(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new bn(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(Zt);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],c.update&&c.update(n)),s.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=s,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(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:re.scrollMargins.from(n=>({top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}))}),bn=class{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(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 t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=nd(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=nd(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}};function nd(n){let e=n.nextSibling;return n.remove(),e}var ky=C.baseTheme({".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"}}),Zt=S.define({enables:[sd,ky]});function j(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var s=t[i];typeof s=="string"?n.setAttribute(i,s):s!=null&&(n[i]=s)}e++}for(;e<arguments.length;e++)rd(n,arguments[e]);return n}function rd(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)rd(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}var od=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n,ii=class{constructor(e,t,i=0,s=e.length,r){this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?o=>r(od(o)):od,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 ne(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=mi(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=Se(e);let s=this.normalize(t);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o);if(a)return this.value=a,this;if(r==s.length-1)break;o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t){let i=null;for(let s=0;s<this.matches.length;s+=2){let r=this.matches[s],o=!1;this.query.charCodeAt(r)==e&&(r==this.query.length-1?i={from:this.matches[s+1],to:t+1}:(this.matches[s]++,o=!0)),o||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:t+1}:this.matches.push(1,t)),i}};typeof Symbol<"u"&&(ii.prototype[Symbol.iterator]=function(){return this});var cd={from:-1,to:-1,match:/.*/.exec("")},Zo="gm"+(/x/.unicode==null?"":"u"),el=class{constructor(e,t,i,s=0,r=e.length){if(this.to=r,this.curLine="",this.done=!1,this.value=cd,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new tl(e,t,i,s,r);this.re=new RegExp(t,Zo+(i?.ignoreCase?"i":"")),this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=s,this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=s+(i==s?1:0),i==this.curLine.length&&this.nextLine(),i<s||i>this.value.to)return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},Yo=new WeakMap,ti=class{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=Yo.get(e);if(!s||s.from>=i||s.to<=t){let l=new ti(t,e.sliceString(t,i));return Yo.set(e,l),l}if(s.from==t&&s.to==i)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to<i&&(r+=e.sliceString(s.to,i)),Yo.set(e,new ti(o,r)),new ti(t,r.slice(t-o,i-o))}},tl=class{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=cd,this.matchPos=s,this.re=new RegExp(t,Zo+(i?.ignoreCase?"i":"")),this.flat=ti.get(e,s,this.chunkEnd(s+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&&this.flat.to<this.to&&t.index+t[0].length>this.flat.text.length-10&&(t=null),t){let i=this.flat.from+t.index,s=i+t[0].length;return this.value={from:i,to:s,match:t},this.matchPos=s+(i==s?1:0),this}else{if(this.flat.to==this.to)return this.done=!0,this;this.flat=ti.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}};typeof Symbol<"u"&&(el.prototype[Symbol.iterator]=tl.prototype[Symbol.iterator]=function(){return this});function Cy(n){try{return new RegExp(n,Zo),!0}catch{return!1}}function Xo(n){let e=j("input",{class:"cm-textfield",name:"line"}),t=j("form",{class:"cm-gotoLine",onkeydown:s=>{s.keyCode==27?(s.preventDefault(),n.dispatch({effects:$s.of(!1)}),n.focus()):s.keyCode==13&&(s.preventDefault(),i())},onsubmit:s=>{s.preventDefault(),i()}},j("label",n.state.phrase("Go to line"),": ",e)," ",j("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function i(){let s=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!s)return;let{state:r}=n,o=r.doc.lineAt(r.selection.main.head),[,l,a,h,c]=s,u=h?+h.slice(1):0,f=a?+a:o.number;if(a&&c){let p=f/100;l&&(p=p*(l=="-"?-1:1)+o.number/r.doc.lines),f=Math.round(r.doc.lines*p)}else a&&l&&(f=f*(l=="-"?-1:1)+o.number);let d=r.doc.line(Math.max(1,Math.min(r.doc.lines,f)));n.dispatch({effects:$s.of(!1),selection:m.cursor(d.from+Math.max(0,Math.min(u,d.length))),scrollIntoView:!0}),n.focus()}return{dom:t,pos:-10}}var $s=L.define(),ld=z.define({create(){return!0},update(n,e){for(let t of e.effects)t.is($s)&&(n=t.value);return n},provide:n=>Zt.from(n,e=>e?Xo:null)}),Ay=n=>{let e=ei(n,Xo);if(!e){let t=[$s.of(!0)];n.state.field(ld,!1)==null&&t.push(L.appendConfig.of([ld,Ey])),n.dispatch({effects:t}),e=ei(n,Xo)}return e&&e.dom.querySelector("input").focus(),!0},Ey=C.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),My={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!0},ud=S.define({combine(n){return pe(n,My,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function fd(n){let e=[Oy,Py];return n&&e.push(ud.of(n)),e}var Ty=E.mark({class:"cm-selectionMatch"}),Ly=E.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ad(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=oe.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=oe.Word)}function Ry(n,e,t,i){return n(e.sliceDoc(t,t+1))==oe.Word&&n(e.sliceDoc(i-1,i))==oe.Word}var Py=q.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(ud),{state:t}=n,i=t.selection;if(i.ranges.length>1)return E.none;let s=i.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return E.none;let a=t.wordAt(s.head);if(!a)return E.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<e.minSelectionLength||a>200)return E.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(ad(o,t,s.from,s.to)&&Ry(o,t,s.from,s.to)))return E.none}else if(r=t.sliceDoc(s.from,s.to).trim(),!r)return E.none}let l=[];for(let a of n.visibleRanges){let h=new ii(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:c,to:u}=h.value;if((!o||ad(o,t,c,u))&&(s.empty&&c<=s.from&&u>=s.to?l.push(Ly.range(c,u)):(c>=s.to||u<=s.from)&&l.push(Ty.range(c,u)),l.length>e.maxMatches))return E.none}}return E.set(l)}},{decorations:n=>n.decorations}),Oy=C.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Dy=({state:n,dispatch:e})=>{let{selection:t}=n,i=m.create(t.ranges.map(s=>n.wordAt(s.head)||m.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function By(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new ii(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new ii(n.doc,e,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=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}var Iy=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return Dy({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=By(n,i);return s?(e(n.update({selection:n.selection.addRange(m.range(s.from,s.to),!1),effects:C.scrollIntoView(s.to)})),!0):!1},il=S.define({combine(n){var e;return{top:n.reduce((t,i)=>t??i.top,void 0)||!1,caseSensitive:n.reduce((t,i)=>t??(i.caseSensitive||i.matchCase),void 0)||!1,createPanel:((e=n.find(t=>t.createPanel))===null||e===void 0?void 0:e.createPanel)||(t=>new yd(t))}}});var nl=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Cy(this.search)),this.unquoted=this.search.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
|
39
|
+
`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp}create(){return this.regexp?new pd(this):new dd(this)}getCursor(e,t=0,i=e.length){return this.regexp?Li(this,e,t,i):Ti(this,e,t,i)}},sl=class{constructor(e){this.spec=e}};function Ti(n,e,t,i){return new ii(e,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase())}var dd=class extends sl{constructor(e){super(e)}nextMatch(e,t,i){let s=Ti(this.spec,e,i,e.length).nextOverlapping();return s.done&&(s=Ti(this.spec,e,0,t).nextOverlapping()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let r=Math.max(t,s-1e4-this.spec.unquoted.length),o=Ti(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.length)}getReplacement(e){return this.spec.replace}matchAll(e,t){let i=Ti(this.spec,e,0,e.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Ti(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.length));for(;!r.next().done;)s(r.value.from,r.value.to)}};function Li(n,e,t,i){return new el(e,n.search,n.caseSensitive?void 0:{ignoreCase:!0},t,i)}var pd=class extends sl{nextMatch(e,t,i){let s=Li(this.spec,e,i,e.length).next();return s.done&&(s=Li(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=1;;s++){let r=Math.max(t,i-s*1e4),o=Li(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.length)}getReplacement(e){return this.spec.replace.replace(/\$([$&\d+])/g,(t,i)=>i=="$"?"$":i=="&"?e.match[0]:i!="0"&&+i<e.match.length?e.match[i]:t)}matchAll(e,t){let i=Li(this.spec,e,0,e.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Li(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.length));for(;!r.next().done;)s(r.value.from,r.value.to)}},yn=L.define(),rl=L.define(),Nt=z.define({create(n){return new zs(Qo(n).create(),null)},update(n,e){for(let t of e.effects)t.is(yn)?n=new zs(t.value.create(),n.panel):t.is(rl)&&(n=new zs(n.query,t.value?ol:null));return n},provide:n=>Zt.from(n,e=>e.panel)});var zs=class{constructor(e,t){this.query=e,this.panel=t}},Ny=E.mark({class:"cm-searchMatch"}),Fy=E.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Vy=q.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(Nt))}update(n){let e=n.state.field(Nt);(e!=n.startState.field(Nt)||n.docChanged||n.selectionSet)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return E.none;let{view:t}=this,i=new Re;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-2*250;)a=r[++s].to;n.highlight(t.state.doc,l,a,(h,c)=>{let u=t.state.selection.ranges.some(f=>f.from==h&&f.to==c);i.add(h,c,u?Fy:Ny)})}return i.finish()}},{decorations:n=>n.decorations});function vn(n){return e=>{let t=e.state.field(Nt,!1);return t&&t.query.spec.valid?n(e,t):md(e)}}var js=vn((n,{query:e})=>{let{from:t,to:i}=n.state.selection.main,s=e.nextMatch(n.state.doc,t,i);return!s||s.from==t&&s.to==i?!1:(n.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0,effects:ll(n,s),userEvent:"select.search"}),!0)}),Us=vn((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main,r=e.prevMatch(t.doc,i,s);return r?(n.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:ll(n,r),userEvent:"select.search"}),!0):!1}),Hy=vn((n,{query:e})=>{let t=e.matchAll(n.state.doc,1e3);return!t||!t.length?!1:(n.dispatch({selection:m.create(t.map(i=>m.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),qy=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:s}=t.main,r=[],o=0;for(let l=new ii(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(m.range(l.value.from,l.value.to))}return e(n.update({selection:m.create(r,o),userEvent:"select.search.matches"})),!0},hd=vn((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t.doc,i,i);if(!r)return!1;let o=[],l,a;if(r.from==i&&r.to==s&&(a=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=e.nextMatch(t.doc,r.from,r.to)),r){let h=o.length==0||o[0].from>=r.to?0:r.to-r.from-a.length;l={anchor:r.from-h,head:r.to-h}}return n.dispatch({changes:o,selection:l,scrollIntoView:!!l,effects:r?ll(n,r):void 0,userEvent:"input.replace"}),!0}),Wy=vn((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state.doc,1e9).map(i=>{let{from:s,to:r}=i;return{from:s,to:r,insert:e.getReplacement(i)}});return t.length?(n.dispatch({changes:t,userEvent:"input.replace.all"}),!0):!1});function ol(n){return n.state.facet(il).createPanel(n)}function Qo(n,e){var t;let i=n.selection.main,s=i.empty||i.to>i.from+100?"":n.sliceDoc(i.from,i.to),r=(t=e?.caseSensitive)!==null&&t!==void 0?t:n.facet(il).caseSensitive;return e&&!s?e:new nl({search:s.replace(/\n/g,"\\n"),caseSensitive:r})}var md=n=>{let e=n.state.field(Nt,!1);if(e&&e.panel){let t=ei(n,ol);if(!t)return!1;let i=t.dom.querySelector("[name=search]");if(i!=n.root.activeElement){let s=Qo(n.state,e.query.spec);s.valid&&n.dispatch({effects:yn.of(s)}),i.focus(),i.select()}}else n.dispatch({effects:[rl.of(!0),e?yn.of(Qo(n.state,e.query.spec)):L.appendConfig.of($y)]});return!0},gd=n=>{let e=n.state.field(Nt,!1);if(!e||!e.panel)return!1;let t=ei(n,ol);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:rl.of(!1)}),!0},bd=[{key:"Mod-f",run:md,scope:"editor search-panel"},{key:"F3",run:js,shift:Us,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:js,shift:Us,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:gd,scope:"editor search-panel"},{key:"Mod-Shift-l",run:qy},{key:"Alt-g",run:Ay},{key:"Mod-d",run:Iy,preventDefault:!0}],yd=class{constructor(e){this.view=e;let t=this.query=e.state.field(Nt).query.spec;this.commit=this.commit.bind(this),this.searchField=j("input",{value:t.search,placeholder:Ne(e,"Find"),"aria-label":Ne(e,"Find"),class:"cm-textfield",name:"search",onchange:this.commit,onkeyup:this.commit}),this.replaceField=j("input",{value:t.replace,placeholder:Ne(e,"Replace"),"aria-label":Ne(e,"Replace"),class:"cm-textfield",name:"replace",onchange:this.commit,onkeyup:this.commit}),this.caseField=j("input",{type:"checkbox",name:"case",checked:t.caseSensitive,onchange:this.commit}),this.reField=j("input",{type:"checkbox",name:"re",checked:t.regexp,onchange:this.commit});function i(s,r,o){return j("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=j("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>js(e),[Ne(e,"next")]),i("prev",()=>Us(e),[Ne(e,"previous")]),i("select",()=>Hy(e),[Ne(e,"all")]),j("label",null,[this.caseField,Ne(e,"match case")]),j("label",null,[this.reField,Ne(e,"regexp")]),...e.state.readOnly?[]:[j("br"),this.replaceField,i("replace",()=>hd(e),[Ne(e,"replace")]),i("replaceAll",()=>Wy(e),[Ne(e,"replace all")]),j("button",{name:"close",onclick:()=>gd(e),"aria-label":Ne(e,"close"),type:"button"},["\xD7"])]])}commit(){let e=new nl({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:yn.of(e)}))}keydown(e){au(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Us:js)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),hd(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(yn)&&!i.value.eq(this.query)&&this.setQuery(i.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}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(il).top}};function Ne(n,e){return n.state.phrase(e)}var qs=30,Ws=/[\s\.,:;?!]/;function ll(n,{from:e,to:t}){let i=n.state.doc.lineAt(e).from,s=n.state.doc.lineAt(t).to,r=Math.max(i,e-qs),o=Math.min(s,t+qs),l=n.state.sliceDoc(r,o);if(r!=i){for(let a=0;a<qs;a++)if(!Ws.test(l[a+1])&&Ws.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-qs;a--)if(!Ws.test(l[a-1])&&Ws.test(l[a])){l=l.slice(0,a);break}}return C.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${n.state.doc.lineAt(e).number}`)}var zy=C.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"}}),$y=[Nt,ze.lowest(Vy),zy];var jy=typeof navigator<"u"&&!/Edge\/(\d+)/.exec(navigator.userAgent)&&/Apple Computer/.test(navigator.vendor)&&(/Mobile\/\w+/.test(navigator.userAgent)||navigator.maxTouchPoints>2),al="-10000px",cl=class{constructor(e,t,i){this.facet=t,this.createTooltipView=i,this.input=e.state.facet(t),this.tooltips=this.input.filter(s=>s),this.tooltipViews=this.tooltips.map(i)}update(e){let t=e.state.facet(this.facet),i=t.filter(r=>r);if(t===this.input){for(let r of this.tooltipViews)r.update&&r.update(e);return!1}let s=[];for(let r=0;r<i.length;r++){let o=i[r],l=-1;if(!!o){for(let a=0;a<this.tooltips.length;a++){let h=this.tooltips[a];h&&h.create==o.create&&(l=a)}if(l<0)s[r]=this.createTooltipView(o);else{let a=s[r]=this.tooltipViews[l];a.update&&a.update(e)}}}for(let r of this.tooltipViews)s.indexOf(r)<0&&r.dom.remove();return this.input=t,this.tooltips=i,this.tooltipViews=s,!0}};function Uy(){return{top:0,left:0,bottom:innerHeight,right:innerWidth}}var hl=S.define({combine:n=>{var e,t,i;return{position:jy?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Uy}}}),vd=q.fromClass(class{constructor(n){var e;this.view=n,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let t=n.state.facet(hl);this.position=t.position,this.parent=t.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new cl(n,wn,i=>this.createTooltip(i)),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(i=>{Date.now()>this.lastTransaction-50&&i.length>0&&i[i.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),(e=n.dom.ownerDocument.defaultView)===null||e===void 0||e.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 n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(hl);if(i.position!=this.position){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n){let e=n.create(this.view);if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",e.dom.appendChild(t)}return e.dom.style.position=this.position,e.dom.style.top=al,this.container.appendChild(e.dom),e.mount&&e.mount(this.view),e}destroy(){var n,e;(n=this.view.dom.ownerDocument.defaultView)===null||n===void 0||n.removeEventListener("resize",this.measureSoon);for(let{dom:t}of this.manager.tooltipViews)t.remove();(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect();return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((e,t)=>{let i=this.manager.tooltipViews[t];return i.getCoords?i.getCoords(e.pos):this.view.coordsAtPos(e.pos)}),size:this.manager.tooltipViews.map(({dom:e})=>e.getBoundingClientRect()),space:this.view.state.facet(hl).tooltipSpace(this.view)}}writeMeasure(n){let{editor:e,space:t}=n,i=[];for(let s=0;s<this.manager.tooltips.length;s++){let r=this.manager.tooltips[s],o=this.manager.tooltipViews[s],{dom:l}=o,a=n.pos[s],h=n.size[s];if(!a||a.bottom<=Math.max(e.top,t.top)||a.top>=Math.min(e.bottom,t.bottom)||a.right<Math.max(e.left,t.left)-.1||a.left>Math.min(e.right,t.right)+.1){l.style.top=al;continue}let c=r.arrow?o.dom.querySelector(".cm-tooltip-arrow"):null,u=c?7:0,f=h.right-h.left,d=h.bottom-h.top,p=o.offset||_y,g=this.view.textDirection==I.LTR,y=h.width>t.right-t.left?g?t.left:t.right-h.width:g?Math.min(a.left-(c?14:0)+p.x,t.right-f):Math.max(t.left,a.left-f+(c?14:0)-p.x),b=!!r.above;!r.strictSide&&(b?a.top-(h.bottom-h.top)-p.y<t.top:a.bottom+(h.bottom-h.top)+p.y>t.bottom)&&b==t.bottom-a.bottom>a.top-t.top&&(b=!b);let A=b?a.top-d-u-p.y:a.bottom+u+p.y,T=y+f;if(o.overlap!==!0)for(let x of i)x.left<T&&x.right>y&&x.top<A+d&&x.bottom>A&&(A=b?x.top-d-2-u:x.bottom+u+2);this.position=="absolute"?(l.style.top=A-n.parent.top+"px",l.style.left=y-n.parent.left+"px"):(l.style.top=A+"px",l.style.left=y+"px"),c&&(c.style.left=`${a.left+(g?p.x:-p.x)-(y+14-7)}px`),o.overlap!==!0&&i.push({left:y,top:A,right:T,bottom:A+d}),l.classList.toggle("cm-tooltip-above",b),l.classList.toggle("cm-tooltip-below",!b),o.positioned&&o.positioned()}}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 n of this.manager.tooltipViews)n.dom.style.top=al}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Ky=C.baseTheme({".cm-tooltip":{zIndex:100},"&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:`${7}px`,width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:`${7}px solid transparent`,borderRight:`${7}px solid transparent`},".cm-tooltip-above &":{bottom:`-${7}px`,"&:before":{borderTop:`${7}px solid #bbb`},"&:after":{borderTop:`${7}px solid #f5f5f5`,bottom:"1px"}},".cm-tooltip-below &":{top:`-${7}px`,"&:before":{borderBottom:`${7}px solid #bbb`},"&:after":{borderBottom:`${7}px solid #f5f5f5`,top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),_y={x:0,y:0},wn=S.define({enables:[vd,Ky]}),Ks=S.define(),_s=class{constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new cl(e,Ks,t=>this.createHostedView(t))}static create(e){return new _s(e)}createHostedView(e){let t=e.create(this.view);return t.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(t.dom),this.mounted&&t.mount&&t.mount(this.view),t}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned()}update(e){this.manager.update(e)}},Gy=wn.compute([Ks],n=>{let e=n.facet(Ks).filter(t=>t);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.filter(t=>t.end!=null).map(t=>t.end)),create:_s.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),wd=class{constructor(e,t,i,s,r){this.view=e,this.source=t,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){var e;clearTimeout(this.restartTimeout);let{lastMove:t}=this,i=this.view.contentDOM.contains(t.target)?this.view.posAtCoords(t):null;if(i==null)return;let s=this.view.coordsAtPos(i);if(s==null||t.y<s.top||t.y>s.bottom||t.x<s.left-this.view.defaultCharacterWidth||t.x>s.right+this.view.defaultCharacterWidth)return;let r=this.view.bidiSpans(this.view.state.doc.lineAt(i)).find(a=>a.from<=i&&a.to>=i),o=r&&r.dir==I.RTL?-1:1,l=this.source(this.view,i,t.x<s.left?-o:o);if(!((e=l)===null||e===void 0)&&e.then){let a=this.pending={pos:i};l.then(h=>{this.pending==a&&(this.pending=null,h&&this.view.dispatch({effects:this.setHover.of(h)}))},h=>ge(this.view.state,h,"hover tooltip"))}else l&&this.view.dispatch({effects:this.setHover.of(l)})}mousemove(e){var t;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let i=this.active;if(i&&!Jy(this.lastMove.target)||this.pending){let{pos:s}=i||this.pending,r=(t=i?.end)!==null&&t!==void 0?t:s;(s==r?this.view.posAtCoords(this.lastMove)!=s:!Yy(this.view,s,r,e.clientX,e.clientY,6))&&(this.view.dispatch({effects:this.setHover.of(null)}),this.pending=null)}}mouseleave(){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1,this.active&&this.view.dispatch({effects:this.setHover.of(null)})}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}};function Jy(n){for(let e=n;e;e=e.parentNode)if(e.nodeType==1&&e.classList.contains("cm-tooltip"))return!0;return!1}function Yy(n,e,t,i,s,r){let o=document.createRange(),l=n.domAtPos(e),a=n.domAtPos(t);o.setEnd(a.node,a.offset),o.setStart(l.node,l.offset);let h=o.getClientRects();o.detach();for(let c=0;c<h.length;c++){let u=h[c];if(Math.max(u.top-s,s-u.bottom,u.left-i,i-u.right)<=r)return!0}return!1}function Sd(n,e={}){let t=L.define(),i=z.define({create(){return null},update(s,r){if(s&&e.hideOnChange&&(r.docChanged||r.selection))return null;for(let o of r.effects){if(o.is(t))return o.value;if(o.is(Xy))return null}if(s&&r.docChanged){let o=r.changes.mapPos(s.pos,-1,Z.TrackDel);if(o==null)return null;let l=Object.assign(Object.create(null),s);return l.pos=o,s.end!=null&&(l.end=r.changes.mapPos(s.end)),l}return s},provide:s=>Ks.from(s)});return[i,q.define(s=>new wd(s,n,i,t,e.hoverTime||300)),Gy]}function xd(n,e){let t=n.plugin(vd);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}var Xy=L.define();var Ld=class{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=te(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(Rd(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t){e=="abort"&&this.abortListeners&&this.abortListeners.push(t)}};function kd(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Qy(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let i=kd(e)+kd(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Zy(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:Qy(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,span:t}:null}}var ul=class{constructor(e,t,i){this.completion=e,this.source=t,this.match=i}};function ni(n){return n.selection.main.head}function Rd(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}var ev=$e.define();function Pd(n,e){let t=e.completion.apply||e.completion.label,i=e.source;typeof t=="string"?n.dispatch({changes:{from:i.from,to:i.to,insert:t},selection:{anchor:i.from+t.length},userEvent:"input.complete",annotations:ev.of(e.completion)}):t(n,e.completion,i.from,i.to)}var Cd=new WeakMap;function tv(n){if(!Array.isArray(n))return n;let e=Cd.get(n);return e||Cd.set(n,e=Zy(n)),e}var Od=class{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[];for(let t=0;t<e.length;){let i=ne(e,t),s=Se(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(ne(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}match(e){if(this.pattern.length==0)return[0];if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let A=ne(e,0);return A==t[0]?[0,0,Se(A)]:A==i[0]?[-200,0,Se(A)]:null}let l=e.indexOf(this.pattern);if(l==0)return[0,0,this.pattern.length];let a=t.length,h=0;if(l<0){for(let A=0,T=Math.min(e.length,200);A<T&&h<a;){let x=ne(e,A);(x==t[h]||x==i[h])&&(s[h++]=A),A+=Se(x)}if(h<a)return null}let c=0,u=0,f=!1,d=0,p=-1,g=-1,y=/[a-z]/.test(e),b=!0;for(let A=0,T=Math.min(e.length,200),x=0;A<T&&u<a;){let k=ne(e,A);l<0&&(c<a&&k==t[c]&&(r[c++]=A),d<a&&(k==t[d]||k==i[d]?(d==0&&(p=A),g=A+1,d++):d=0));let M,P=k<255?k>=48&&k<=57||k>=97&&k<=122?2:k>=65&&k<=90?1:0:(M=mi(k))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!A||P==1&&y||x==0&&P!=0)&&(t[u]==k||i[u]==k&&(f=!0)?o[u++]=A:o.length&&(b=!1)),x=P,A+=Se(k)}return u==a&&o[0]==0&&b?this.result(-100+(f?-200:0),o,e):d==a&&p==0?[-200-e.length,0,g]:l>-1?[-700-e.length,l,l+this.pattern.length]:d==a?[-200+-700-e.length,p,g]:u==a?this.result(-100+(f?-200:0)+-700+(b?0:-1100),o,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[e-i.length],r=1;for(let o of t){let l=o+(this.astral?Se(ne(i,o)):1);r>1&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return s}},si=S.define({combine(n){return pe(n,{activateOnTyping:!0,override:null,maxRenderedOptions:100,defaultKeymap:!0,optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[]},{defaultKeymap:(e,t)=>e&&t,icons:(e,t)=>e&&t,optionClass:(e,t)=>i=>iv(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})}});function iv(n,e){return n?e?n+" "+e:n:e}function nv(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s){let r=document.createElement("span");r.className="cm-completionLabel";let{label:o}=t,l=0;for(let a=1;a<s.length;){let h=s[a++],c=s[a++];h>l&&r.appendChild(document.createTextNode(o.slice(l,h)));let u=r.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(o.slice(h,c))),u.className="cm-completionMatchedText",l=c}return l<o.length&&r.appendChild(document.createTextNode(o.slice(l))),r},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function sv(n,e){let t=document.createElement("div");t.className="cm-tooltip cm-completionInfo";let{info:i}=n.completion;if(typeof i=="string")t.textContent=i;else{let s=i(n.completion);s.then?s.then(r=>t.appendChild(r),r=>ge(e.state,r,"completion info")):t.appendChild(s)}return t}function Ad(n,e,t){if(n<=t)return{from:0,to:n};if(e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}var Dd=class{constructor(e,t){this.view=e,this.stateField=t,this.info=null,this.placeInfo={read:()=>this.measureInfo(),write:l=>this.positionInfo(l),key:this};let i=e.state.field(t),{options:s,selected:r}=i.open,o=e.state.facet(si);this.optionContent=nv(o),this.optionClass=o.optionClass,this.range=Ad(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.dom.addEventListener("mousedown",l=>{for(let a=l.target,h;a&&a!=this.dom;a=a.parentNode)if(a.nodeName=="LI"&&(h=/-(\d+)$/.exec(a.id))&&+h[1]<s.length){Pd(e,s[+h[1]]),l.preventDefault();return}}),this.list=this.dom.appendChild(this.createListBox(s,i.id,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfo)})}mount(){this.updateSel()}update(e){e.state.field(this.stateField)!=e.startState.field(this.stateField)&&this.updateSel()}positioned(){this.info&&this.view.requestMeasure(this.placeInfo)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;if((t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Ad(t.options.length,t.selected,this.view.state.facet(si).maxRenderedOptions),this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t.options,e.id,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfo)})),this.updateSelectedOption(t.selected)){this.info&&(this.info.remove(),this.info=null);let i=t.options[t.selected];i.completion.info&&(this.info=this.dom.appendChild(sv(i,this.view)),this.view.requestMeasure(this.placeInfo))}}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return t&&ov(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=e.getBoundingClientRect();if(s.top>Math.min(innerHeight,t.bottom)-10||s.bottom<Math.max(0,t.top)+10)return null;let r=Math.max(0,Math.min(s.top,innerHeight-i.height))-t.top,o=this.view.textDirection==I.RTL,l=t.left,a=innerWidth-t.right;return o&&l<Math.min(i.width,a)?o=!1:!o&&a<Math.min(i.width,l)&&(o=!0),{top:r,left:o}}positionInfo(e){this.info&&(this.info.style.top=(e?e.top:-1e6)+"px",e&&(this.info.classList.toggle("cm-completionInfo-left",e.left),this.info.classList.toggle("cm-completionInfo-right",!e.left)))}createListBox(e,t,i){let s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true");for(let r=i.from;r<i.to;r++){let{completion:o,match:l}=e[r],a=s.appendChild(document.createElement("li"));a.id=t+"-"+r,a.setAttribute("role","option");let h=this.optionClass(o);h&&(a.className=h);for(let c of this.optionContent){let u=c(o,this.view.state,l);u&&a.appendChild(u)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}};function rv(n){return e=>new Dd(e,n)}function ov(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect();i.top<t.top?n.scrollTop-=t.top-i.top:i.bottom>t.bottom&&(n.scrollTop+=i.bottom-t.bottom)}var lv=300;function Ed(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function av(n,e){let t=[],i=0;for(let o of n)if(o.hasResult())if(o.result.filter===!1)for(let l of o.result.options)t.push(new ul(l,o,[1e9-i++]));else{let l=new Od(e.sliceDoc(o.from,o.to)),a;for(let h of o.result.options)(a=l.match(h.label))&&(h.boost!=null&&(a[0]+=h.boost),t.push(new ul(h,o,a)))}let s=[],r=null;for(let o of t.sort(fv)){if(s.length==lv)break;!r||r.label!=o.completion.label||r.detail!=o.completion.detail||r.type!=o.completion.type||r.apply!=o.completion.apply?s.push(o):Ed(o.completion)>Ed(r)&&(s[s.length-1]=o),r=o.completion}return s}var Ri=class{constructor(e,t,i,s,r){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Ri(this.options,Md(t,e),this.tooltip,this.timestamp,e)}static build(e,t,i,s,r){let o=av(e,t);if(!o.length)return null;let l=0;if(s&&s.selected){let a=s.options[s.selected].completion;for(let h=0;h<o.length;h++)if(o[h].completion==a){l=h;break}}return new Ri(o,Md(i,l),{pos:e.reduce((a,h)=>h.hasResult()?Math.min(a,h.from):a,1e8),create:rv(Ye),above:r.aboveCursor},s?s.timestamp:Date.now(),l)}map(e){return new Ri(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected)}},Sn=class{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new Sn(uv,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(si),r=(i.override||t.languageDataAt("autocomplete",ni(t)).map(tv)).map(l=>(this.active.find(h=>h.source==l)||new Ae(l,this.active.some(h=>h.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!hv(r,this.active)?Ri.build(r,t,this.id,this.open,i):this.open&&e.docChanged?this.open.map(e.changes):this.open;!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new Ae(l.source,0):l));for(let l of e.effects)l.is(Id)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new Sn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:cv}};function hv(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult;)t++;for(;i<e.length&&!e[i].hasResult;)i++;let s=t==n.length,r=i==e.length;if(s||r)return s==r;if(n[t++].result!=e[i++].result)return!1}}var cv={"aria-autocomplete":"list"};function Md(n,e){return{"aria-autocomplete":"list","aria-haspopup":"listbox","aria-activedescendant":n+"-"+e,"aria-controls":n}}var uv=[];function fv(n,e){let t=e.match[0]-n.match[0];return t||n.completion.label.localeCompare(e.completion.label)}function fl(n){return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}var Ae=class{constructor(e,t,i=-1){this.source=e,this.state=t,this.explicitPos=i}hasResult(){return!1}update(e,t){let i=fl(e),s=this;i?s=s.handleUserEvent(e,i,t):e.docChanged?s=s.handleChange(e):e.selection&&s.state!=0&&(s=new Ae(s.source,0));for(let r of e.effects)if(r.is(dl))s=new Ae(s.source,1,r.value?ni(e.state):-1);else if(r.is(pl))s=new Ae(s.source,0);else if(r.is(Bd))for(let o of r.value)o.source==s.source&&(s=o);return s}handleUserEvent(e,t,i){return t=="delete"||!i.activateOnTyping?this.map(e.changes):new Ae(this.source,1)}handleChange(e){return e.changes.touchesRange(ni(e.startState))?new Ae(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new Ae(this.source,this.state,e.mapPos(this.explicitPos))}},xn=class extends Ae{constructor(e,t,i,s,r,o){super(e,2,t);this.result=i,this.from=s,this.to=r,this.span=o}hasResult(){return!0}handleUserEvent(e,t,i){let s=e.changes.mapPos(this.from),r=e.changes.mapPos(this.to,1),o=ni(e.state);if((this.explicitPos<0?o<=s:o<this.from)||o>r||t=="delete"&&ni(e.startState)==this.from)return new Ae(this.source,t=="input"&&i.activateOnTyping?1:0);let l=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos);return this.span&&(s==r||this.span.test(e.state.sliceDoc(s,r)))?new xn(this.source,l,this.result,s,r,this.span):new Ae(this.source,1,l)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new Ae(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new xn(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1),this.span)}},dl=L.define(),pl=L.define(),Bd=L.define({map(n,e){return n.map(t=>t.map(e))}}),Id=L.define(),Ye=z.define({create(){return Sn.start()},update(n,e){return n.update(e)},provide:n=>[wn.from(n,e=>e.tooltip),C.contentAttributes.from(n,e=>e.attrs)]}),Nd=75;function Gs(n,e="option"){return t=>{let i=t.state.field(Ye,!1);if(!i||!i.open||Date.now()-i.open.timestamp<Nd)return!1;let s=1,r;e=="page"&&(r=xd(t,i.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let o=i.open.selected+s*(n?1:-1),{length:l}=i.open.options;return o<0?o=e=="page"?0:l-1:o>=l&&(o=e=="page"?l-1:0),t.dispatch({effects:Id.of(o)}),!0}}var dv=n=>{let e=n.state.field(Ye,!1);return n.state.readOnly||!e||!e.open||Date.now()-e.open.timestamp<Nd?!1:(Pd(n,e.open.options[e.open.selected]),!0)},pv=n=>n.state.field(Ye,!1)?(n.dispatch({effects:dl.of(!0)}),!0):!1,mv=n=>{let e=n.state.field(Ye,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:pl.of(null)}),!0)},Fd=class{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}},Td=50,gv=50,bv=1e3,yv=q.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.composing=0;for(let e of n.state.field(Ye).active)e.state==1&&this.startQuery(e)}update(n){let e=n.state.field(Ye);if(!n.selectionSet&&!n.docChanged&&n.startState.field(Ye)==e)return;let t=n.transactions.some(i=>(i.selection||i.docChanged)&&!fl(i));for(let i=0;i<this.running.length;i++){let s=this.running[i];if(t||s.updates.length+n.transactions.length>gv&&Date.now()-s.time>bv){for(let r of s.context.abortListeners)try{r()}catch(o){ge(this.view.state,o)}s.context.abortListeners=null,this.running.splice(i--,1)}else s.updates.push(...n.transactions)}if(this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),this.debounceUpdate=e.active.some(i=>i.state==1&&!this.running.some(s=>s.active.source==i.source))?setTimeout(()=>this.startUpdate(),Td):-1,this.composing!=0)for(let i of n.transactions)fl(i)=="input"?this.composing=2:this.composing==2&&i.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1;let{state:n}=this.view,e=n.field(Ye);for(let t of e.active)t.state==1&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t)}startQuery(n){let{state:e}=this.view,t=ni(e),i=new Ld(e,t,n.explicitPos==t),s=new Fd(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:pl.of(null)}),ge(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),Td))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(si);for(let i=0;i<this.running.length;i++){let s=this.running[i];if(s.done===void 0)continue;if(this.running.splice(i--,1),s.done){let o=new xn(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:ni(s.updates.length?s.updates[0].startState:this.view.state),s.done.span&&s.done.filter!==!1?Rd(s.done.span,!0):null);for(let l of s.updates)o=o.update(l,t);if(o.hasResult()){e.push(o);continue}}let r=this.view.state.field(Ye).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new Ae(s.active.source,0);for(let l of s.updates)o=o.update(l,t);o.state!=1&&e.push(o)}else this.startQuery(r)}e.length&&this.view.dispatch({effects:Bd.of(e)})}},{eventHandlers:{compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:dl.of(!1)}),20),this.composing=0}}}),vv=C.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",listStyle:"none",margin:0,padding:0,"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer",padding:"1px 3px",lineHeight:1.2}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"\xB7\xB7\xB7"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"300px"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",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"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'\u0192'"}},".cm-completionIcon-class":{"&:after":{content:"'\u25CB'"}},".cm-completionIcon-interface":{"&:after":{content:"'\u25CC'"}},".cm-completionIcon-variable":{"&:after":{content:"'\u{1D465}'"}},".cm-completionIcon-constant":{"&:after":{content:"'\u{1D436}'"}},".cm-completionIcon-type":{"&:after":{content:"'\u{1D461}'"}},".cm-completionIcon-enum":{"&:after":{content:"'\u222A'"}},".cm-completionIcon-property":{"&:after":{content:"'\u25A1'"}},".cm-completionIcon-keyword":{"&:after":{content:"'\u{1F511}\uFE0E'"}},".cm-completionIcon-namespace":{"&:after":{content:"'\u25A2'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});function Vd(n={}){return[Ye,si.of(n),yv,wv,vv]}var ml=[{key:"Ctrl-Space",run:pv},{key:"Escape",run:mv},{key:"ArrowDown",run:Gs(!0)},{key:"ArrowUp",run:Gs(!1)},{key:"PageDown",run:Gs(!0,"page")},{key:"PageUp",run:Gs(!1,"page")},{key:"Enter",run:dv}],wv=ze.highest(Bt.computeN([si],n=>n.facet(si).defaultKeymap?[ml]:[]));var Sv=n=>{let e=bl(n.state);return e.line?xv(n):e.block?Cv(n):!1};function gl(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}var xv=gl(Mv,0);var kv=gl(qd,0);var Cv=gl((n,e)=>qd(n,e,Ev(e)),0),Hd=[{key:"Mod-/",run:Sv},{key:"Alt-A",run:kv}];function bl(n,e=n.selection.main.head){let t=n.languageDataAt("commentTokens",e);return t.length?t[0]:{}}var kn=50;function Av(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-kn,i),o=n.sliceDoc(s,s+kn),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let c,u;s-i<=2*kn?c=u=n.sliceDoc(i,s):(c=n.sliceDoc(i,i+kn),u=n.sliceDoc(s-kn,s));let f=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(u)[0].length,p=u.length-d-t.length;return c.slice(f,f+e.length)==e&&u.slice(p,p+t.length)==t?{open:{pos:i+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(u.charAt(p-1))?1:0}}:null}function Ev(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to),r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from,to:s.to})}return e}function qd(n,e,t=e.selection.ranges){let i=t.map(r=>bl(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>Av(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=i[o],{open:h,close:c}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function Mv(n,e,t=e.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of t){let l=i.length,a=1e9;for(let h=r;h<=o;){let c=e.doc.lineAt(h);if(c.from>s&&(r==o||o>c.from)){s=c.from;let u=bl(e,h).line;if(!u)continue;let f=/^\s*/.exec(c.text)[0].length,d=f==c.length,p=c.text.slice(f,f+u.length)==u?f:-1;f<c.text.length&&f<a&&(a=f),i.push({line:c,comment:p,token:u,indent:f,empty:d,single:!1})}h=c.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(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:u}of i)(u||!c)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,r.push({from:h,to:c})}return{changes:r}}return null}var yl=2e3;function Tv(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>yl||t.off>yl||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=s;a++){let h=n.doc.line(a);h.length<=l&&r.push(m.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),c=Ui(h.text,o,n.tabSize,!0);if(c>-1){let u=Ui(h.text,l,n.tabSize);r.push(m.range(h.from+c,h.from+u))}}}return r}function Lv(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function Wd(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=n.state.doc.lineAt(t),s=t-i.from,r=s>yl?-1:s==i.length?Lv(n,e.clientX):pt(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function Rv(n,e){let t=Wd(n,e),i=n.state.selection;return t?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(t.line).from),o=s.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=Wd(n,s);if(!l)return i;let a=Tv(n.state,t,l);return a.length?o?m.create(a.concat(i.ranges)):m.create(a):i}}:null}function zd(n){let e=n?.eventFilter||(t=>t.altKey&&t.button==0);return C.mouseSelectionStyle.of((t,i)=>e(i)?Rv(t,i):null)}var Pv=0,Xe=class{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=Pv++}static define(e){if(e?.base)throw new Error("Can not derive from a modified tag");let t=new Xe([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new An;return t=>t.modified.indexOf(e)>-1?t:An.get(t.base||t,t.modified.concat(e).sort((i,s)=>i.id-s.id))}},Ov=0,An=class{constructor(){this.instances=[],this.id=Ov++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Dv(t,l.modified));if(i)return i;let s=[],r=new Xe(s,e,t);for(let l of t)l.instances.push(r);let o=Kd(t);for(let l of e.set)for(let a of o)s.push(An.get(l,a));return r}};function Dv(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function Kd(n){let e=[n];for(let t=0;t<n.length;t++)for(let i of Kd(n.slice(0,t).concat(n.slice(t+1))))e.push(i);return e}function _d(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let u=0;;){if(l=="..."&&u>0&&u+3==s.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!f)throw new RangeError("Invalid path: "+s);if(r.push(f[0]=="*"?null:f[0][0]=='"'?JSON.parse(f[0]):f[0]),u+=f[0].length,u==s.length)break;let d=s[u++];if(u==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(u)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let c=new Yd(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return Gd.add(e)}var Gd=new O,xl=S.define({combine(n){return n.length?Pi.combinedMatch(n):null}}),Jd=S.define({combine(n){return n.length?n[0].match:null}});function wl(n){return n.facet(xl)||n.facet(Jd)}var Yd=class{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}},Pi=class{constructor(e,t){this.map=Object.create(null);let i;function s(o){let l=je.newName();return(i||(i=Object.create(null)))["."+l]=o,l}this.all=typeof t.all=="string"?t.all:t.all?s(t.all):null;for(let o of e){let l=(o.class||s(Object.assign({},o,{tag:null})))+(this.all?" "+this.all:""),a=o.tag;if(!Array.isArray(a))this.map[a.id]=l;else for(let h of a)this.map[h.id]=l}this.module=i?new je(i):null,this.scope=t.scope||null,this.match=this.match.bind(this);let r=[Bv];this.module&&r.push(C.styleModule.of(this.module)),this.extension=r.concat(xl.of(this)),this.fallback=r.concat(Jd.of(this))}match(e,t){if(this.scope&&t!=this.scope)return null;for(let i of e.set){let s=this.map[i.id];if(s!==void 0)return i!=e&&(this.map[e.id]=s),s}return this.map[e.id]=this.all}static combinedMatch(e){if(e.length==1)return e[0].match;let t=e.some(i=>i.scope)?void 0:Object.create(null);return(i,s)=>{let r=t&&t[i.id];if(r!==void 0)return r;let o=null;for(let l of e){let a=l.match(i,s);a&&(o=o?o+" "+a:a)}return t&&(t[i.id]=o),o}}static define(e,t){return new Pi(e,t||{})}static get(e,t,i){let s=wl(e);return s&&s(t,i||ae.none)}};var Xd=class{constructor(e){this.markCache=Object.create(null),this.tree=te(e.state),this.decorations=this.buildDeco(e,wl(e.state))}update(e){let t=te(e.state),i=wl(e.state),s=i!=e.startState.facet(xl);t.length<e.view.viewport.to&&!s&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i))}buildDeco(e,t){if(!t||!this.tree.length)return E.none;let i=new Re;for(let{from:s,to:r}of e.visibleRanges)Iv(this.tree,s,r,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=E.mark({class:a})))});return i.finish()}},Bv=ze.high(q.fromClass(Xd,{decorations:n=>n.decorations})),$d=[""],Qd=class{constructor(e,t,i){this.at=e,this.style=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,s,r,o){let{type:l,from:a,to:h}=e;if(a>=i||h<=t)return;$d[r]=l.name,l.isTop&&(o=l);let c=s,u=l.prop(Gd),f=!1;for(;u;){if(!u.context||Nv(u.context,$d,r)){for(let p of u.tags){let g=this.style(p,o);g&&(c&&(c+=" "),c+=g,u.mode==1?s+=(s?" ":"")+g:u.mode==0&&(f=!0))}break}u=u.next}if(this.startSpan(e.from,c),f)return;let d=e.tree&&e.tree.prop(O.mounted);if(d&&d.overlay){let p=e.node.enter(d.overlay[0].from+a,1),g=e.firstChild();for(let y=0,b=a;;y++){let A=y<d.overlay.length?d.overlay[y]:null,T=A?A.from+a:h,x=Math.max(t,b),k=Math.min(i,T);if(x<k&&g)for(;e.from<k&&(this.highlightRange(e,x,k,s,r+1,o),this.startSpan(Math.min(i,e.to),c),!(e.to>=T||!e.nextSibling())););if(!A||T>i)break;b=A.to+a,b>t&&(this.highlightRange(p.cursor,Math.max(t,A.from+a),Math.min(i,b),s,r,d.tree.type),this.startSpan(b,c))}g&&e.parent()}else if(e.firstChild()){do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r+1,o),this.startSpan(Math.min(i,e.to),c)}while(e.nextSibling());e.parent()}}};function Iv(n,e,t,i,s){let r=new Qd(e,i,s);r.highlightRange(n.cursor(),e,t,"",0,n.type),r.flush(t)}function Nv(n,e,t){if(n.length>t-1)return!1;for(let i=t-1,s=n.length-1;s>=0;s--,i--){let r=n[s];if(r&&r!=e[i])return!1}return!0}var v=Xe.define,Js=v(),Ft=v(),jd=v(Ft),Ud=v(Ft),Vt=v(),Ys=v(Vt),vl=v(Vt),ht=v(),ri=v(ht),lt=v(),at=v(),Sl=v(),Cn=v(Sl),Xs=v(),w={comment:Js,lineComment:v(Js),blockComment:v(Js),docComment:v(Js),name:Ft,variableName:v(Ft),typeName:jd,tagName:v(jd),propertyName:Ud,attributeName:v(Ud),className:v(Ft),labelName:v(Ft),namespace:v(Ft),macroName:v(Ft),literal:Vt,string:Ys,docString:v(Ys),character:v(Ys),attributeValue:v(Ys),number:vl,integer:v(vl),float:v(vl),bool:v(Vt),regexp:v(Vt),escape:v(Vt),color:v(Vt),url:v(Vt),keyword:lt,self:v(lt),null:v(lt),atom:v(lt),unit:v(lt),modifier:v(lt),operatorKeyword:v(lt),controlKeyword:v(lt),definitionKeyword:v(lt),moduleKeyword:v(lt),operator:at,derefOperator:v(at),arithmeticOperator:v(at),logicOperator:v(at),bitwiseOperator:v(at),compareOperator:v(at),updateOperator:v(at),definitionOperator:v(at),typeOperator:v(at),controlOperator:v(at),punctuation:Sl,separator:v(Sl),bracket:Cn,angleBracket:v(Cn),squareBracket:v(Cn),paren:v(Cn),brace:v(Cn),content:ht,heading:ri,heading1:v(ri),heading2:v(ri),heading3:v(ri),heading4:v(ri),heading5:v(ri),heading6:v(ri),contentSeparator:v(ht),list:v(ht),quote:v(ht),emphasis:v(ht),strong:v(ht),link:v(ht),monospace:v(ht),strikethrough:v(ht),inserted:v(),deleted:v(),changed:v(),invalid:v(),meta:Xs,documentMeta:v(Xs),annotation:v(Xs),processingInstruction:v(Xs),definition:Xe.defineModifier(),constant:Xe.defineModifier(),function:Xe.defineModifier(),standard:Xe.defineModifier(),local:Xe.defineModifier(),special:Xe.defineModifier()},Zd=Pi.define([{tag:w.link,textDecoration:"underline"},{tag:w.heading,textDecoration:"underline",fontWeight:"bold"},{tag:w.emphasis,fontStyle:"italic"},{tag:w.strong,fontWeight:"bold"},{tag:w.strikethrough,textDecoration:"line-through"},{tag:w.keyword,color:"#708"},{tag:[w.atom,w.bool,w.url,w.contentSeparator,w.labelName],color:"#219"},{tag:[w.literal,w.inserted],color:"#164"},{tag:[w.string,w.deleted],color:"#a11"},{tag:[w.regexp,w.escape,w.special(w.string)],color:"#e40"},{tag:w.definition(w.variableName),color:"#00f"},{tag:w.local(w.variableName),color:"#30a"},{tag:[w.typeName,w.namespace],color:"#085"},{tag:w.className,color:"#167"},{tag:[w.special(w.variableName),w.macroName],color:"#256"},{tag:w.definition(w.propertyName),color:"#00c"},{tag:w.comment,color:"#940"},{tag:w.meta,color:"#7a757a"},{tag:w.invalid,color:"#f00"}]),Gx=Pi.define([{tag:w.link,class:"cmt-link"},{tag:w.heading,class:"cmt-heading"},{tag:w.emphasis,class:"cmt-emphasis"},{tag:w.strong,class:"cmt-strong"},{tag:w.keyword,class:"cmt-keyword"},{tag:w.atom,class:"cmt-atom"},{tag:w.bool,class:"cmt-bool"},{tag:w.url,class:"cmt-url"},{tag:w.labelName,class:"cmt-labelName"},{tag:w.inserted,class:"cmt-inserted"},{tag:w.deleted,class:"cmt-deleted"},{tag:w.literal,class:"cmt-literal"},{tag:w.string,class:"cmt-string"},{tag:w.number,class:"cmt-number"},{tag:[w.regexp,w.escape,w.special(w.string)],class:"cmt-string2"},{tag:w.variableName,class:"cmt-variableName"},{tag:w.local(w.variableName),class:"cmt-variableName cmt-local"},{tag:w.definition(w.variableName),class:"cmt-variableName cmt-definition"},{tag:w.special(w.variableName),class:"cmt-variableName2"},{tag:w.definition(w.propertyName),class:"cmt-propertyName cmt-definition"},{tag:w.typeName,class:"cmt-typeName"},{tag:w.namespace,class:"cmt-namespace"},{tag:w.className,class:"cmt-className"},{tag:w.macroName,class:"cmt-macroName"},{tag:w.propertyName,class:"cmt-propertyName"},{tag:w.operator,class:"cmt-operator"},{tag:w.comment,class:"cmt-comment"},{tag:w.meta,class:"cmt-meta"},{tag:w.invalid,class:"cmt-invalid"},{tag:w.punctuation,class:"cmt-punctuation"}]);var tp=class{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}},Ht=class{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let s=E.set(e.map(r=>r.from==r.to||r.from==r.to-1&&i.doc.lineAt(r.from).to==r.from?E.widget({widget:new op(r),diagnostic:r}).range(r.from):E.mark({attributes:{class:"cm-lintRange cm-lintRange-"+r.severity},diagnostic:r}).range(r.from,r.to)),!0);return new Ht(s,t,Oi(s))}};function Oi(n,e=null,t=0){let i=null;return n.between(t,1e9,(s,r,{spec:o})=>{if(!(e&&o.diagnostic!=e))return i=new tp(s,r,o.diagnostic),!1}),i}function Fv(n,e){return n.field(Oe,!1)?e:e.concat(L.appendConfig.of([Oe,C.decorations.compute([Oe],t=>{let{selected:i,panel:s}=t.field(Oe);return!i||!s||i.from==i.to?E.none:E.set([Hv.range(i.from,i.to)])}),Sd(qv),Uv]))}var Vv=L.define(),Al=L.define(),ip=L.define(),Oe=z.define({create(){return new Ht(E.none,null,null)},update(n,e){if(e.docChanged){let t=n.diagnostics.map(e.changes),i=null;if(n.selected){let s=e.changes.mapPos(n.selected.from,1);i=Oi(t,n.selected.diagnostic,s)||Oi(t,null,s)}n=new Ht(t,n.panel,i)}for(let t of e.effects)t.is(Vv)?n=Ht.init(t.value,n.panel,e.state):t.is(Al)?n=new Ht(n.diagnostics,t.value?En.open:null,n.selected):t.is(ip)&&(n=new Ht(n.diagnostics,n.panel,t.value));return n},provide:n=>[Zt.from(n,e=>e.panel),C.decorations.from(n,e=>e.diagnostics)]});var Hv=E.mark({class:"cm-lintRange cm-lintRange-active"});function qv(n,e,t){let{diagnostics:i}=n.state.field(Oe),s=[],r=2e8,o=0;return i.between(e-(t<0?1:0),e+(t>0?1:0),(l,a,{spec:h})=>{e>=l&&e<=a&&(l==a||(e>l||t>0)&&(e<a||t<0))&&(s.push(h.diagnostic),r=Math.min(l,r),o=Math.max(a,o))}),s.length?{pos:r,end:o,above:n.state.doc.lineAt(r).to<o,create(){return{dom:Wv(n,s)}}}:null}function Wv(n,e){return j("ul",{class:"cm-tooltip-lint"},e.map(t=>rp(n,t,!1)))}var zv=n=>{let e=n.state.field(Oe,!1);(!e||!e.panel)&&n.dispatch({effects:Fv(n.state,[Al.of(!0)])});let t=ei(n,En.open);return t&&t.dom.querySelector(".cm-panel-lint ul").focus(),!0},ep=n=>{let e=n.state.field(Oe,!1);return!e||!e.panel?!1:(n.dispatch({effects:Al.of(!1)}),!0)},$v=n=>{let e=n.state.field(Oe,!1);if(!e)return!1;let t=n.state.selection.main,i=e.diagnostics.iter(t.to+1);return!i.value&&(i=e.diagnostics.iter(0),!i.value||i.from==t.from&&i.to==t.to)?!1:(n.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},np=[{key:"Mod-Shift-m",run:zv},{key:"F8",run:$v}];function sp(n){let e=[];if(n)e:for(let{name:t}of n){for(let i=0;i<t.length;i++){let s=t[i];if(/[a-zA-Z]/.test(s)&&!e.some(r=>r.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function rp(n,e,t){var i;let s=t?sp(e.actions):[];return j("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},j("span",{class:"cm-diagnosticText"},e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=u=>{u.preventDefault();let f=Oi(n.state.field(Oe).diagnostics,e);f&&r.apply(n,f.from,f.to)},{name:a}=r,h=s[o]?a.indexOf(s[o]):-1,c=h<0?a:[a.slice(0,h),j("u",a.slice(h,h+1)),a.slice(h+1)];return j("button",{type:"button",class:"cm-diagnosticAction",onclick:l,onmousedown:l,"aria-label":` Action: ${a}${h<0?"":` (access key "${s[o]})"`}.`},c)}),e.source&&j("div",{class:"cm-diagnosticSource"},e.source))}var op=class extends De{constructor(e){super();this.diagnostic=e}eq(e){return e.diagnostic==this.diagnostic}toDOM(){return j("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}},Cl=class{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=rp(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}},En=class{constructor(e){this.view=e,this.items=[];let t=s=>{if(s.keyCode==27)ep(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=sp(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==s.keyCode){let a=Oi(this.view.state.field(Oe).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;s.preventDefault()},i=s=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(s.target)&&this.moveSelection(r)};this.list=j("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=j("div",{class:"cm-panel-lint"},this.list,j("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>ep(this.view)},"\xD7")),this.update()}get selectedIndex(){let e=this.view.state.field(Oe).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Oe),i=0,s=!1,r=null;for(e.between(0,this.view.state.doc.length,(o,l,{spec:a})=>{let h=-1,c;for(let u=i;u<this.items.length;u++)if(this.items[u].diagnostic==a.diagnostic){h=u;break}h<0?(c=new Cl(this.view,a.diagnostic),this.items.splice(i,0,c),s=!0):(c=this.items[h],h>i&&(this.items.splice(i,h-i),s=!0)),t&&c.diagnostic==t.diagnostic?c.dom.hasAttribute("aria-selected")||(c.dom.setAttribute("aria-selected","true"),r=c):c.dom.hasAttribute("aria-selected")&&c.dom.removeAttribute("aria-selected"),i++});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new Cl(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!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})=>{o.top<l.top?this.list.scrollTop-=l.top-o.top:o.bottom>l.bottom&&(this.list.scrollTop+=o.bottom-l.bottom)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(Oe),i=Oi(t.diagnostics,this.items[e].diagnostic);!i||this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:ip.of(i)})}static open(e){return new En(e)}};function jv(n,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(n)}</svg>')`}function kl(n){return jv(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}var Uv=C.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-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:kl("#d11")},".cm-lintRange-warning":{backgroundImage:kl("orange")},".cm-lintRange-info":{backgroundImage:kl("#999")},".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-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}}});var lp=[Ju(),Yu(),bu(),ku(),rf(),uu(),mu(),B.allowMultipleSelections.of(!0),zu(),Zd.fallback,hf(),Xf(),Vd(),zd(),wu(),fd(),Bt.of([...ed,..._f,...bd,...Tu,...tf,...Hd,...ml,...np])];function ap(n,e,t,i=0,s=0){e==null&&(e=n.search(/[^\s\u00a0]/),e==-1&&(e=n.length));let r=s;for(let o=i;o<e;o++)n.charCodeAt(o)==9?r+=t-r%t:r++;return r}var Ml=class{constructor(e,t,i){this.string=e,this.tabSize=t,this.indentUnit=i,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),i;if(typeof e=="string"?i=t==e:i=t&&(e instanceof RegExp?e.test(t):e(t)),i)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=ap(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){return ap(this.string,null,this.tabSize)}match(e,t,i){if(typeof e=="string"){let s=o=>i?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return s(r)==s(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let s=this.string.slice(this.pos).match(e);return s&&s.index>0?null:(s&&t!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}};function Kv(n){return{token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||_v,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||Ll}}function _v(n){if(typeof n!="object")return n;let e={};for(let t in n){let i=n[t];e[t]=i instanceof Array?i.slice():i}return e}var Tn=class extends Ie{constructor(e){let t=Fu(e.languageData),i=Kv(e),s,r=new class extends cn{createParse(o,l,a){return new up(s,o,l,a)}};super(t,r,Xv(t),[Vo.of((o,l)=>this.getIndent(o,l))]);s=this,this.streamParser=i,this.stateAfter=new O({perNode:!0}),this.tokenTable=e.tokenTable?new Rl(i.tokenTable):Yv}static define(e){return new Tn(e)}getIndent(e,t){let i=te(e.state),s=i.resolve(t);for(;s&&s.type!=this.topNode;)s=s.parent;if(!s)return null;let r=Tl(this,i,0,s.from,t),o,l;if(r?(l=r.state,o=r.pos+1):(l=this.streamParser.startState(e.unit),o=0),t-o>1e4)return null;for(;o<t;){let h=e.state.doc.lineAt(o),c=Math.min(t,h.to);if(h.length){let u=new Ml(h.text,e.state.tabSize,e.unit);for(;u.pos<c-h.from;)fp(this.streamParser.token,u,l)}else this.streamParser.blankLine(l,e.unit);if(c==t)break;o=h.to+1}let{text:a}=e.lineAt(t);return this.streamParser.indent(l,/^\s*(.*)/.exec(a)[1],e)}get allowsNesting(){return!1}};function Tl(n,e,t,i,s){let r=t>=i&&t+e.length<=s&&e.prop(n.stateAfter);if(r)return{state:n.streamParser.copyState(r),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof U&&a<s&&Tl(n,l,a,i,s);if(h)return h}return null}function cp(n,e,t,i,s){if(s&&t<=0&&i>=e.length)return e;!s&&e.type==n.topNode&&(s=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],a;if(o<i&&l instanceof U){if(!(a=cp(n,l,t-o,i-o,s)))break;return s?new U(e.type,e.children.slice(0,r).concat(a),e.positions.slice(0,r+1),o+a.length):a}}return null}function Gv(n,e,t,i){for(let s of e){let r=s.from+(s.openStart?25:0),o=s.to-(s.openEnd?25:0),l=r<=t&&o>t&&Tl(n,s.tree,0-s.offset,t,o),a;if(l&&(a=cp(n,s.tree,t+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:a}}return{state:n.streamParser.startState(i?xt(i):4),tree:U.empty}}var up=class{constructor(e,t,i,s){this.lang=e,this.input=t,this.fragments=i,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let r=Yt.get(),o=s[0].from,{state:l,tree:a}=Gv(e,i,o,r?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);r&&this.parsedPos<r.viewport.from-1e5&&(this.state=this.lang.streamParser.startState(xt(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from)}advance(){let e=Yt.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(t,this.chunkStart+2048);for(e&&(i=Math.min(i,e.viewport.to));this.parsedPos<i;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
|
40
|
+
`&&(t="");else{let i=t.indexOf(`
|
41
|
+
`);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let s=this.rangeIndex;;){let r=this.ranges[s].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let s=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?s>r:s>=r)break;t+=this.ranges[++this.rangeIndex].from-s}return t}emitToken(e,t,i,s,r){if(this.ranges.length>1){r=this.skipGapsTo(t,r,1),t+=r;let o=this.chunk.length;r=this.skipGapsTo(i,r,-1),i+=r,s+=this.chunk.length-o}return this.chunk.push(e,t,i,s),r}parseLine(e){let{line:t,end:i}=this.nextLine(),s=0,{streamParser:r}=this.lang,o=new Ml(t,e?e.state.tabSize:4,e?xt(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=fp(r.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,4,s)),o.start>1e4)break}this.parsedPos=i,this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=U.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Jv,topID:0,maxBufferLength:2048,reused:this.chunkReused});e=new U(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new U(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}};function fp(n,e,t){e.start=e.pos;for(let i=0;i<10;i++){let s=n(e,t);if(e.pos>e.start)return s}throw new Error("Stream parser failed to advance stream.")}var Ll=Object.create(null),Mn=[ae.none],Jv=new hn(Mn),hp=[],dp=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","typeName"],["attribute","propertyName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])dp[n]=pp(Ll,e);var Rl=class{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),dp)}resolve(e){return e?this.table[e]||(this.table[e]=pp(this.extra,e)):0}},Yv=new Rl(Ll);function El(n,e){hp.indexOf(n)>-1||(hp.push(n),console.warn(e))}function pp(n,e){let t=null;for(let r of e.split(".")){let o=n[r]||w[r];o?typeof o=="function"?t?t=o(t):El(r,`Modifier ${r} used at start of tag`):t?El(r,`Tag ${r} used as modifier`):t=o:El(r,`Unknown highlighting tag ${r}`)}if(!t)return 0;let i=e.replace(/ /g,"_"),s=ae.define({id:Mn.length,name:i,props:[_d({[i]:t})]});return Mn.push(s),s.id}function Xv(n){let e=ae.define({id:Mn.length,name:"Document",props:[fn.add(()=>n)]});return Mn.push(e),e}function Ol(n){for(var e={},t=0,i=n.length;t<i;++t)e[n[t]]=!0;return e}var gp=["alias","and","BEGIN","begin","break","case","class","def","defined?","do","else","elsif","END","end","ensure","false","for","if","in","module","next","not","or","redo","rescue","retry","return","self","super","then","true","undef","unless","until","when","while","yield","nil","raise","throw","catch","fail","loop","callcc","caller","lambda","proc","public","protected","private","require","load","require_relative","extend","autoload","__END__","__FILE__","__LINE__","__dir__"],Qv=Ol(gp),Zv=Ol(["def","class","case","for","while","until","module","then","catch","loop","proc","begin"]),ew=Ol(["end","until"]),mp={"[":"]","{":"}","(":")"},tw={"]":"[","}":"{",")":"("},Qe;function Di(n,e,t){return t.tokenize.push(n),n(e,t)}function Qs(n,e){if(n.sol()&&n.match("=begin")&&n.eol())return e.tokenize.push(rw),"comment";if(n.eatSpace())return null;var t=n.next(),i;if(t=="`"||t=="'"||t=='"')return Di(Ln(t,"string",t=='"'||t=="`"),n,e);if(t=="/")return iw(n)?Di(Ln(t,"string.special",!0),n,e):"operator";if(t=="%"){var s="string",r=!0;n.eat("s")?s="atom":n.eat(/[WQ]/)?s="string":n.eat(/[r]/)?s="string.special":n.eat(/[wxq]/)&&(s="string",r=!1);var o=n.eat(/[^\w\s=]/);return o?(mp.propertyIsEnumerable(o)&&(o=mp[o]),Di(Ln(o,s,r,!0),n,e)):"operator"}else{if(t=="#")return n.skipToEnd(),"comment";if(t=="<"&&(i=n.match(/^<([-~])[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/)))return Di(sw(i[2],i[1]),n,e);if(t=="0")return n.eat("x")?n.eatWhile(/[\da-fA-F]/):n.eat("b")?n.eatWhile(/[01]/):n.eatWhile(/[0-7]/),"number";if(/\d/.test(t))return n.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/),"number";if(t=="?"){for(;n.match(/^\\[CM]-/););return n.eat("\\")?n.eatWhile(/\w/):n.next(),"string"}else{if(t==":")return n.eat("'")?Di(Ln("'","atom",!1),n,e):n.eat('"')?Di(Ln('"',"atom",!0),n,e):n.eat(/[\<\>]/)?(n.eat(/[\<\>]/),"atom"):n.eat(/[\+\-\*\/\&\|\:\!]/)?"atom":n.eat(/[a-zA-Z$@_\xa1-\uffff]/)?(n.eatWhile(/[\w$\xa1-\uffff]/),n.eat(/[\?\!\=]/),"atom"):"operator";if(t=="@"&&n.match(/^@?[a-zA-Z_\xa1-\uffff]/))return n.eat("@"),n.eatWhile(/[\w\xa1-\uffff]/),"propertyName";if(t=="$")return n.eat(/[a-zA-Z_]/)?n.eatWhile(/[\w]/):n.eat(/\d/)?n.eat(/\d/):n.next(),"variableName.special";if(/[a-zA-Z_\xa1-\uffff]/.test(t))return n.eatWhile(/[\w\xa1-\uffff]/),n.eat(/[\?\!]/),n.eat(":")?"atom":"variable";if(t=="|"&&(e.varList||e.lastTok=="{"||e.lastTok=="do"))return Qe="|",null;if(/[\(\)\[\]{}\\;]/.test(t))return Qe=t,null;if(t=="-"&&n.eat(">"))return"operator";if(/[=+\-\/*:\.^%<>~|]/.test(t)){var l=n.eatWhile(/[=+\-\/*:\.^%<>~|]/);return t=="."&&!l&&(Qe="."),"operator"}else return null}}}function iw(n){for(var e=n.pos,t=0,i,s=!1,r=!1;(i=n.next())!=null;)if(r)r=!1;else{if("[{(".indexOf(i)>-1)t++;else if("]})".indexOf(i)>-1){if(t--,t<0)break}else if(i=="/"&&t==0){s=!0;break}r=i=="\\"}return n.backUp(n.pos-e),s}function Pl(n){return n||(n=1),function(e,t){if(e.peek()=="}"){if(n==1)return t.tokenize.pop(),t.tokenize[t.tokenize.length-1](e,t);t.tokenize[t.tokenize.length-1]=Pl(n-1)}else e.peek()=="{"&&(t.tokenize[t.tokenize.length-1]=Pl(n+1));return Qs(e,t)}}function nw(){var n=!1;return function(e,t){return n?(t.tokenize.pop(),t.tokenize[t.tokenize.length-1](e,t)):(n=!0,Qs(e,t))}}function Ln(n,e,t,i){return function(s,r){var o=!1,l;for(r.context.type==="read-quoted-paused"&&(r.context=r.context.prev,s.eat("}"));(l=s.next())!=null;){if(l==n&&(i||!o)){r.tokenize.pop();break}if(t&&l=="#"&&!o){if(s.eat("{")){n=="}"&&(r.context={prev:r.context,type:"read-quoted-paused"}),r.tokenize.push(Pl());break}else if(/[@\$]/.test(s.peek())){r.tokenize.push(nw());break}}o=!o&&l=="\\"}return e}}function sw(n,e){return function(t,i){return e&&t.eatSpace(),t.match(n)?i.tokenize.pop():t.skipToEnd(),"string"}}function rw(n,e){return n.sol()&&n.match("=end")&&n.eol()&&e.tokenize.pop(),n.skipToEnd(),"comment"}var bp={startState:function(n){return{tokenize:[Qs],indented:0,context:{type:"top",indented:-n},continuedLine:!1,lastTok:null,varList:!1}},token:function(n,e){Qe=null,n.sol()&&(e.indented=n.indentation());var t=e.tokenize[e.tokenize.length-1](n,e),i,s=Qe;if(t=="variable"){var r=n.current();t=e.lastTok=="."?"property":Qv.propertyIsEnumerable(n.current())?"keyword":/^[A-Z]/.test(r)?"tag":e.lastTok=="def"||e.lastTok=="class"||e.varList?"def":"variable",t=="keyword"&&(s=r,Zv.propertyIsEnumerable(r)?i="indent":ew.propertyIsEnumerable(r)?i="dedent":((r=="if"||r=="unless")&&n.column()==n.indentation()||r=="do"&&e.context.indented<e.indented)&&(i="indent"))}return(Qe||t&&t!="comment")&&(e.lastTok=s),Qe=="|"&&(e.varList=!e.varList),i=="indent"||/[\(\[\{]/.test(Qe)?e.context={prev:e.context,type:Qe||t,indented:e.indented}:(i=="dedent"||/[\)\]\}]/.test(Qe))&&e.context.prev&&(e.context=e.context.prev),n.eol()&&(e.continuedLine=Qe=="\\"||t=="operator"),t},indent:function(n,e,t){if(n.tokenize[n.tokenize.length-1]!=Qs)return null;var i=e&&e.charAt(0),s=n.context,r=s.type==tw[i]||s.type=="keyword"&&/^(?:end|until|else|elsif|when|rescue)\b/.test(e);return s.indented+(r?0:t.unit)+(n.continuedLine?t.unit:0)},languageData:{indentOnInput:/^\s*(?:end|rescue|elsif|else|\})$/,commentTokens:{line:"#"},autocomplete:gp}};var Zs=class extends Me{connect(){this.editor=new C({parent:this.element,state:B.create({doc:this.scriptValue,extensions:[lp,Tn.define(bp),ze.high(Bt.of([{key:"Mod-Enter",run:()=>this.submitCodeSelected}])),Bt.of([Gf])]})})}get submitCodeSelected(){let n=new CustomEvent("codeSubmission",{detail:{selection:this.selectedBlock}});return this.element.dispatchEvent(n),!0}get selection(){return this.editor.state.selection.main}get doc(){return this.editor.state.doc}get selectedBlock(){let{from:n,to:e}=this.selection;return n!=e?this.doc.toString().slice(n,e):this.doc.lineAt(n).text}};Bi(Zs,"values",{script:String});window.Stimulus=$i.start();Stimulus.register("hello",Mr);Stimulus.register("playground",Tr);Stimulus.register("search-scripts",ji);Stimulus.register("select-script",Lr);Stimulus.register("codemirror",Zs);})();
|