import{E as j,T as x,X as D}from"./cmCore-1.0.74-RFmA52TM.js";/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var h=function(){return h=Object.assign||function(o){for(var r,e=1,f=arguments.length;e<f;e++)for(var t in r=arguments[e])Object.prototype.hasOwnProperty.call(r,t)&&(o[t]=r[t]);return o},h.apply(this,arguments)};function p(o,r,e){if(e||arguments.length===2)for(var f,t=0,m=r.length;t<m;t++)!f&&t in r||(f||(f=Array.prototype.slice.call(r,0,t)),f[t]=r[t]);return o.concat(f||Array.prototype.slice.call(r))}var u=function(o){return/^-?\d+$/.test(o)},w=function(o,r,e){e===void 0&&(e={from:void 0,to:void 0});var f=o.map(function(n){if(n.from=u(n.from)?n.from:void 0,n.to=u(n.to)?n.to:void 0,u(n.from)&&u(n.to)){var d=h({},n);n.from=Math.min(d.from,d.to),n.to=Math.max(d.from,d.to)}return n}),t={from:u(r==null?void 0:r.from)?r==null?void 0:r.from:void 0,to:u(r==null?void 0:r.to)?r==null?void 0:r.to:void 0};if(u(t.from)&&u(t.to)){var m=h({},t);t.from=Math.min(m.from,m.to),t.to=Math.max(m.from,m.to)}var a={from:u(e==null?void 0:e.from)?e==null?void 0:e.from:void 0,to:u(e==null?void 0:e.to)?e==null?void 0:e.to:void 0};if(u(a.from)&&u(a.to)){var l=h({},a);a.from=Math.min(l.from,l.to),a.to=Math.max(l.from,l.to)}var i=p(p([],f.map(function(n){return n.from}),!0),[t==null?void 0:t.from,a==null?void 0:a.from],!1).filter(function(n){return n!==void 0}),c=p(p([],f.map(function(n){return n.to}),!0),[t==null?void 0:t.to,a==null?void 0:a.to],!1).filter(function(n){return n!==void 0}),s=p(p([],i,!0),c,!0),g=0,M=0;s.length>0&&(g=Math.max.apply(Math,s),M=Math.min.apply(Math,s));var b=Math.abs(g),T=Math.abs(M),v=Math.max(b,T)+1,y=-v;return f=f.map(function(n){return n.from=u(n.from)?n.from:y,n.to=u(n.to)?n.to:v,n}),t={from:u(t.from)?t.from:y,to:u(t.to)?t.to:v},a={from:u(a.from)?a.from:y,to:u(a.to)?a.to:v},f=f.slice().sort(function(n,d){var S=n.to-n.from,E=d.to-d.from;if(n.from>d.from)return 1;if(n.from===d.from){if(n.from+S>d.from+E)return-1;if(n.from+S===d.from+E)return 0;if(n.from+S<d.from+E)return 1}return-1}),O(f,t,[],a).map(function(n){return{from:n.from===y?void 0:n.from,to:n.to===v?void 0:n.to}})},O=function(o,r,e,f){var t=e;if(r===null||o.length===0)return r===null||e.some(function(i){return i.from===(r==null?void 0:r.from)&&i.to===(r==null?void 0:r.to)})||t.push(r),(t=t.filter(function(i){return i.from<=f.to&&i.to>=f.from})).map(function(i){return function(c,s){return{from:c.from<s.from?s.from:c.from,to:c.to>s.to?s.to:c.to}}(i,f)});var m=r.to-r.from;if(r.from>=o[0].from&&r.from<=o[0].to)r.from+m<=o[0].to?r=null:r.from=o[0].to+1;else if(r.from<o[0].from&&r.from+m>=o[0].from){var a=r.to,l={from:r.from,to:o[0].from-1};e.push(l),a>o[0].to?r.from=o[0].to+1:r=null}return o.shift(),O(o,r,e,f)},A=function(o){return D.transactionFilter.of(function(r){if(r.isUserEvent("delete.selection")&&!r.isUserEvent("delete.selection.smart")){var e=r.startState.selection.ranges.map(function(t){return{from:t.from,to:t.to}});if(e.length>0){var f=o(r.startState);return w(f,e[0],{from:0,to:r.startState.doc.line(r.startState.doc.lines).to}).map(function(t){return r.startState.update({changes:{from:t.from,to:t.to},annotations:x.userEvent.of("".concat(r.annotation(x.userEvent),".smart"))})})}}return r})},F=function(o){return D.changeFilter.of(function(r){var e,f,t,m;try{for(var a=o(r.startState),l=o(r.state),i=0;i<a.length;i++){var c=(e=a[i].from)!==null&&e!==void 0?e:0,s=(f=a[i].to)!==null&&f!==void 0?f:r.startState.doc.line(r.startState.doc.lines).to,g=(t=l[i].from)!==null&&t!==void 0?t:0,M=(m=l[i].to)!==null&&m!==void 0?m:r.state.doc.line(r.state.doc.lines).to;if(r.startState.sliceDoc(c,s)!==r.state.sliceDoc(g,M))return!1}}catch{return!1}return!0})},U=function(o){return j.domEventHandlers({paste:function(r,e){var f=(r.clipboardData||window.clipboardData).getData("Text"),t=e.state.selection.ranges.map(function(l){return{from:l.from,to:l.to}});if(t.length>0){var m=o(e.state),a=w(m,t[0],{from:0,to:e.state.doc.line(e.state.doc.lines).to});a.length>0&&e.dispatch({changes:{from:a[0].from,to:a[0].to,insert:f},annotations:x.userEvent.of("input.paste.smart")})}return!0}})},P=function(o){return[U(o),A(o),F(o)]};export{P as c};
