import{g as G}from"./index-Cq7z4i0o.js";import{r as H}from"./codemirror-DpyRu-EA.js";function J(O,A){for(var a=0;a<A.length;a++){const d=A[a];if(typeof d!="string"&&!Array.isArray(d)){for(const i in d)if(i!=="default"&&!(i in O)){const g=Object.getOwnPropertyDescriptor(d,i);g&&Object.defineProperty(O,i,g.get?g:{enumerable:!0,get:()=>d[i]})}}}return Object.freeze(Object.defineProperty(O,Symbol.toStringTag,{value:"Module"}))}var q={exports:{}},F;function Q(){return F||(F=1,(function(O,A){(function(a){a(H())})(function(a){var d={pairs:`()[]{}''""`,closeBefore:`)]}'":;>`,triples:"",explode:"[]{}"},i=a.Pos;a.defineOption("autoCloseBrackets",!1,function(e,t,n){n&&n!=a.Init&&(e.removeKeyMap(x),e.state.closeBrackets=null),t&&(E(g(t,"pairs")),e.state.closeBrackets=t,e.addKeyMap(x))});function g(e,t){return t=="pairs"&&typeof e=="string"?e:typeof e=="object"&&e[t]!=null?e[t]:d[t]}var x={Backspace:K,Enter:L};function E(e){for(var t=0;t<e.length;t++){var n=e.charAt(t),s="'"+n+"'";x[s]||(x[s]=D(n))}}E(d.pairs+"`");function D(e){return function(t){return z(t,e)}}function y(e){var t=e.state.closeBrackets;if(!t||t.override)return t;var n=e.getModeAt(e.getCursor());return n.closeBrackets||t}function K(e){var t=y(e);if(!t||e.getOption("disableInput"))return a.Pass;for(var n=g(t,"pairs"),s=e.listSelections(),r=0;r<s.length;r++){if(!s[r].empty())return a.Pass;var f=_(e,s[r].head);if(!f||n.indexOf(f)%2!=0)return a.Pass}for(var r=s.length-1;r>=0;r--){var o=s[r].head;e.replaceRange("",i(o.line,o.ch-1),i(o.line,o.ch+1),"+delete")}}function L(e){var t=y(e),n=t&&g(t,"explode");if(!n||e.getOption("disableInput"))return a.Pass;for(var s=e.listSelections(),r=0;r<s.length;r++){if(!s[r].empty())return a.Pass;var f=_(e,s[r].head);if(!f||n.indexOf(f)%2!=0)return a.Pass}e.operation(function(){var o=e.lineSeparator()||`
`;e.replaceSelection(o+o,null),k(e,-1),s=e.listSelections();for(var h=0;h<s.length;h++){var S=s[h].head.line;e.indentLine(S,null,!0),e.indentLine(S+1,null,!0)}})}function k(e,t){for(var n=[],s=e.listSelections(),r=0,f=0;f<s.length;f++){var o=s[f];o.head==e.getCursor()&&(r=f);var h=o.head.ch||t>0?{line:o.head.line,ch:o.head.ch+t}:{line:o.head.line-1};n.push({anchor:h,head:h})}e.setSelections(n,r)}function W(e){var t=a.cmpPos(e.anchor,e.head)>0;return{anchor:new i(e.anchor.line,e.anchor.ch+(t?-1:1)),head:new i(e.head.line,e.head.ch+(t?1:-1))}}function z(e,t){var n=y(e);if(!n||e.getOption("disableInput"))return a.Pass;var s=g(n,"pairs"),r=s.indexOf(t);if(r==-1)return a.Pass;for(var f=g(n,"closeBefore"),o=g(n,"triples"),h=s.charAt(r+1)==t,S=e.listSelections(),B=r%2==0,c,R=0;R<S.length;R++){var w=S[R],l=w.head,u,P=e.getRange(l,i(l.line,l.ch+1));if(B&&!w.empty())u="surround";else if((h||!B)&&P==t)h&&N(e,l)?u="both":o.indexOf(t)>=0&&e.getRange(l,i(l.line,l.ch+3))==t+t+t?u="skipThree":u="skip";else if(h&&l.ch>1&&o.indexOf(t)>=0&&e.getRange(i(l.line,l.ch-2),l)==t+t){if(l.ch>2&&/\bstring/.test(e.getTokenTypeAt(i(l.line,l.ch-2))))return a.Pass;u="addFour"}else if(h){var I=l.ch==0?" ":e.getRange(i(l.line,l.ch-1),l);if(!a.isWordChar(P)&&I!=t&&!a.isWordChar(I))u="both";else return a.Pass}else if(B&&(P.length===0||/\s/.test(P)||f.indexOf(P)>-1))u="both";else return a.Pass;if(!c)c=u;else if(c!=u)return a.Pass}var b=r%2?s.charAt(r-1):t,j=r%2?t:s.charAt(r+1);e.operation(function(){if(c=="skip")k(e,1);else if(c=="skipThree")k(e,3);else if(c=="surround"){for(var p=e.getSelections(),v=0;v<p.length;v++)p[v]=b+p[v]+j;e.replaceSelections(p,"around"),p=e.listSelections().slice();for(var v=0;v<p.length;v++)p[v]=W(p[v]);e.setSelections(p)}else c=="both"?(e.replaceSelection(b+j,null),e.triggerElectric(b+j),k(e,-1)):c=="addFour"&&(e.replaceSelection(b+b+b+b,"before"),k(e,1))})}function _(e,t){var n=e.getRange(i(t.line,t.ch-1),i(t.line,t.ch+1));return n.length==2?n:null}function N(e,t){var n=e.getTokenAt(i(t.line,t.ch+1));return/\bstring/.test(n.type)&&n.start==t.ch&&(t.ch==0||!/\bstring/.test(e.getTokenTypeAt(t)))}})})()),q.exports}var $=Q();const T=G($),X=J({__proto__:null,default:T},[$]);export{X as c};
//# sourceMappingURL=closebrackets-ChVPTJBD.js.map
