UNPKG

@binarycastle/vue-html-editor

Version:

A powerful and extensible HTML editor component for Vue 3 with plugin support

2 lines (1 loc) 30.3 kB
(function(T,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],d):(T=typeof globalThis<"u"?globalThis:T||self,d(T.VueHtmlEditor={},T.Vue))})(this,function(T,d){"use strict";var M="top",$="bottom",H="right",S="left",Oe="auto",ne=[M,$,H,S],Q="start",oe="end",bt="clippingParents",$e="viewport",ie="popper",Ot="reference",He=ne.reduce(function(t,e){return t.concat([e+"-"+Q,e+"-"+oe])},[]),Ve=[].concat(ne,[Oe]).reduce(function(t,e){return t.concat([e,e+"-"+Q,e+"-"+oe])},[]),kt="beforeRead",Ct="read",Et="afterRead",Pt="beforeMain",At="main",Bt="afterMain",Rt="beforeWrite",Tt="write",Lt="afterWrite",Mt=[kt,Ct,Et,Pt,At,Bt,Rt,Tt,Lt];function I(t){return t?(t.nodeName||"").toLowerCase():null}function j(t){if(t==null)return window;if(t.toString()!=="[object Window]"){var e=t.ownerDocument;return e&&e.defaultView||window}return t}function Y(t){var e=j(t).Element;return t instanceof e||t instanceof Element}function V(t){var e=j(t).HTMLElement;return t instanceof e||t instanceof HTMLElement}function ke(t){if(typeof ShadowRoot>"u")return!1;var e=j(t).ShadowRoot;return t instanceof e||t instanceof ShadowRoot}function St(t){var e=t.state;Object.keys(e.elements).forEach(function(r){var o=e.styles[r]||{},n=e.attributes[r]||{},i=e.elements[r];!V(i)||!I(i)||(Object.assign(i.style,o),Object.keys(n).forEach(function(c){var a=n[c];a===!1?i.removeAttribute(c):i.setAttribute(c,a===!0?"":a)}))})}function jt(t){var e=t.state,r={popper:{position:e.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(e.elements.popper.style,r.popper),e.styles=r,e.elements.arrow&&Object.assign(e.elements.arrow.style,r.arrow),function(){Object.keys(e.elements).forEach(function(o){var n=e.elements[o],i=e.attributes[o]||{},c=Object.keys(e.styles.hasOwnProperty(o)?e.styles[o]:r[o]),a=c.reduce(function(s,f){return s[f]="",s},{});!V(n)||!I(n)||(Object.assign(n.style,a),Object.keys(i).forEach(function(s){n.removeAttribute(s)}))})}}const Dt={name:"applyStyles",enabled:!0,phase:"write",fn:St,effect:jt,requires:["computeStyles"]};function N(t){return t.split("-")[0]}var _=Math.max,pe=Math.min,Z=Math.round;function Ce(){var t=navigator.userAgentData;return t!=null&&t.brands&&Array.isArray(t.brands)?t.brands.map(function(e){return e.brand+"/"+e.version}).join(" "):navigator.userAgent}function We(){return!/^((?!chrome|android).)*safari/i.test(Ce())}function ee(t,e,r){e===void 0&&(e=!1),r===void 0&&(r=!1);var o=t.getBoundingClientRect(),n=1,i=1;e&&V(t)&&(n=t.offsetWidth>0&&Z(o.width)/t.offsetWidth||1,i=t.offsetHeight>0&&Z(o.height)/t.offsetHeight||1);var c=Y(t)?j(t):window,a=c.visualViewport,s=!We()&&r,f=(o.left+(s&&a?a.offsetLeft:0))/n,l=(o.top+(s&&a?a.offsetTop:0))/i,g=o.width/n,O=o.height/i;return{width:g,height:O,top:l,right:f+g,bottom:l+O,left:f,x:f,y:l}}function Ee(t){var e=ee(t),r=t.offsetWidth,o=t.offsetHeight;return Math.abs(e.width-r)<=1&&(r=e.width),Math.abs(e.height-o)<=1&&(o=e.height),{x:t.offsetLeft,y:t.offsetTop,width:r,height:o}}function Fe(t,e){var r=e.getRootNode&&e.getRootNode();if(t.contains(e))return!0;if(r&&ke(r)){var o=e;do{if(o&&t.isSameNode(o))return!0;o=o.parentNode||o.host}while(o)}return!1}function q(t){return j(t).getComputedStyle(t)}function $t(t){return["table","td","th"].indexOf(I(t))>=0}function U(t){return((Y(t)?t.ownerDocument:t.document)||window.document).documentElement}function ve(t){return I(t)==="html"?t:t.assignedSlot||t.parentNode||(ke(t)?t.host:null)||U(t)}function Ie(t){return!V(t)||q(t).position==="fixed"?null:t.offsetParent}function Ht(t){var e=/firefox/i.test(Ce()),r=/Trident/i.test(Ce());if(r&&V(t)){var o=q(t);if(o.position==="fixed")return null}var n=ve(t);for(ke(n)&&(n=n.host);V(n)&&["html","body"].indexOf(I(n))<0;){var i=q(n);if(i.transform!=="none"||i.perspective!=="none"||i.contain==="paint"||["transform","perspective"].indexOf(i.willChange)!==-1||e&&i.willChange==="filter"||e&&i.filter&&i.filter!=="none")return n;n=n.parentNode}return null}function ae(t){for(var e=j(t),r=Ie(t);r&&$t(r)&&q(r).position==="static";)r=Ie(r);return r&&(I(r)==="html"||I(r)==="body"&&q(r).position==="static")?e:r||Ht(t)||e}function Pe(t){return["top","bottom"].indexOf(t)>=0?"x":"y"}function se(t,e,r){return _(t,pe(e,r))}function Vt(t,e,r){var o=se(t,e,r);return o>r?r:o}function Ne(){return{top:0,right:0,bottom:0,left:0}}function qe(t){return Object.assign({},Ne(),t)}function Ue(t,e){return e.reduce(function(r,o){return r[o]=t,r},{})}var Wt=function(e,r){return e=typeof e=="function"?e(Object.assign({},r.rects,{placement:r.placement})):e,qe(typeof e!="number"?e:Ue(e,ne))};function Ft(t){var e,r=t.state,o=t.name,n=t.options,i=r.elements.arrow,c=r.modifiersData.popperOffsets,a=N(r.placement),s=Pe(a),f=[S,H].indexOf(a)>=0,l=f?"height":"width";if(!(!i||!c)){var g=Wt(n.padding,r),O=Ee(i),v=s==="y"?M:S,C=s==="y"?$:H,h=r.rects.reference[l]+r.rects.reference[s]-c[s]-r.rects.popper[l],y=c[s]-r.rects.reference[s],E=ae(i),A=E?s==="y"?E.clientHeight||0:E.clientWidth||0:0,P=h/2-y/2,m=g[v],w=A-O[l]-g[C],x=A/2-O[l]/2+P,k=se(m,x,w),L=s;r.modifiersData[o]=(e={},e[L]=k,e.centerOffset=k-x,e)}}function It(t){var e=t.state,r=t.options,o=r.element,n=o===void 0?"[data-popper-arrow]":o;n!=null&&(typeof n=="string"&&(n=e.elements.popper.querySelector(n),!n)||Fe(e.elements.popper,n)&&(e.elements.arrow=n))}const Nt={name:"arrow",enabled:!0,phase:"main",fn:Ft,effect:It,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function te(t){return t.split("-")[1]}var qt={top:"auto",right:"auto",bottom:"auto",left:"auto"};function Ut(t,e){var r=t.x,o=t.y,n=e.devicePixelRatio||1;return{x:Z(r*n)/n||0,y:Z(o*n)/n||0}}function ze(t){var e,r=t.popper,o=t.popperRect,n=t.placement,i=t.variation,c=t.offsets,a=t.position,s=t.gpuAcceleration,f=t.adaptive,l=t.roundOffsets,g=t.isFixed,O=c.x,v=O===void 0?0:O,C=c.y,h=C===void 0?0:C,y=typeof l=="function"?l({x:v,y:h}):{x:v,y:h};v=y.x,h=y.y;var E=c.hasOwnProperty("x"),A=c.hasOwnProperty("y"),P=S,m=M,w=window;if(f){var x=ae(r),k="clientHeight",L="clientWidth";if(x===j(r)&&(x=U(r),q(x).position!=="static"&&a==="absolute"&&(k="scrollHeight",L="scrollWidth")),x=x,n===M||(n===S||n===H)&&i===oe){m=$;var R=g&&x===w&&w.visualViewport?w.visualViewport.height:x[k];h-=R-o.height,h*=s?1:-1}if(n===S||(n===M||n===$)&&i===oe){P=H;var u=g&&x===w&&w.visualViewport?w.visualViewport.width:x[L];v-=u-o.width,v*=s?1:-1}}var p=Object.assign({position:a},f&&qt),b=l===!0?Ut({x:v,y:h},j(r)):{x:v,y:h};if(v=b.x,h=b.y,s){var B;return Object.assign({},p,(B={},B[m]=A?"0":"",B[P]=E?"0":"",B.transform=(w.devicePixelRatio||1)<=1?"translate("+v+"px, "+h+"px)":"translate3d("+v+"px, "+h+"px, 0)",B))}return Object.assign({},p,(e={},e[m]=A?h+"px":"",e[P]=E?v+"px":"",e.transform="",e))}function zt(t){var e=t.state,r=t.options,o=r.gpuAcceleration,n=o===void 0?!0:o,i=r.adaptive,c=i===void 0?!0:i,a=r.roundOffsets,s=a===void 0?!0:a,f={placement:N(e.placement),variation:te(e.placement),popper:e.elements.popper,popperRect:e.rects.popper,gpuAcceleration:n,isFixed:e.options.strategy==="fixed"};e.modifiersData.popperOffsets!=null&&(e.styles.popper=Object.assign({},e.styles.popper,ze(Object.assign({},f,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:c,roundOffsets:s})))),e.modifiersData.arrow!=null&&(e.styles.arrow=Object.assign({},e.styles.arrow,ze(Object.assign({},f,{offsets:e.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:s})))),e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-placement":e.placement})}const Xt={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:zt,data:{}};var me={passive:!0};function Yt(t){var e=t.state,r=t.instance,o=t.options,n=o.scroll,i=n===void 0?!0:n,c=o.resize,a=c===void 0?!0:c,s=j(e.elements.popper),f=[].concat(e.scrollParents.reference,e.scrollParents.popper);return i&&f.forEach(function(l){l.addEventListener("scroll",r.update,me)}),a&&s.addEventListener("resize",r.update,me),function(){i&&f.forEach(function(l){l.removeEventListener("scroll",r.update,me)}),a&&s.removeEventListener("resize",r.update,me)}}const _t={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:Yt,data:{}};var Gt={left:"right",right:"left",bottom:"top",top:"bottom"};function ge(t){return t.replace(/left|right|bottom|top/g,function(e){return Gt[e]})}var Kt={start:"end",end:"start"};function Xe(t){return t.replace(/start|end/g,function(e){return Kt[e]})}function Ae(t){var e=j(t),r=e.pageXOffset,o=e.pageYOffset;return{scrollLeft:r,scrollTop:o}}function Be(t){return ee(U(t)).left+Ae(t).scrollLeft}function Jt(t,e){var r=j(t),o=U(t),n=r.visualViewport,i=o.clientWidth,c=o.clientHeight,a=0,s=0;if(n){i=n.width,c=n.height;var f=We();(f||!f&&e==="fixed")&&(a=n.offsetLeft,s=n.offsetTop)}return{width:i,height:c,x:a+Be(t),y:s}}function Qt(t){var e,r=U(t),o=Ae(t),n=(e=t.ownerDocument)==null?void 0:e.body,i=_(r.scrollWidth,r.clientWidth,n?n.scrollWidth:0,n?n.clientWidth:0),c=_(r.scrollHeight,r.clientHeight,n?n.scrollHeight:0,n?n.clientHeight:0),a=-o.scrollLeft+Be(t),s=-o.scrollTop;return q(n||r).direction==="rtl"&&(a+=_(r.clientWidth,n?n.clientWidth:0)-i),{width:i,height:c,x:a,y:s}}function Re(t){var e=q(t),r=e.overflow,o=e.overflowX,n=e.overflowY;return/auto|scroll|overlay|hidden/.test(r+n+o)}function Ye(t){return["html","body","#document"].indexOf(I(t))>=0?t.ownerDocument.body:V(t)&&Re(t)?t:Ye(ve(t))}function le(t,e){var r;e===void 0&&(e=[]);var o=Ye(t),n=o===((r=t.ownerDocument)==null?void 0:r.body),i=j(o),c=n?[i].concat(i.visualViewport||[],Re(o)?o:[]):o,a=e.concat(c);return n?a:a.concat(le(ve(c)))}function Te(t){return Object.assign({},t,{left:t.x,top:t.y,right:t.x+t.width,bottom:t.y+t.height})}function Zt(t,e){var r=ee(t,!1,e==="fixed");return r.top=r.top+t.clientTop,r.left=r.left+t.clientLeft,r.bottom=r.top+t.clientHeight,r.right=r.left+t.clientWidth,r.width=t.clientWidth,r.height=t.clientHeight,r.x=r.left,r.y=r.top,r}function _e(t,e,r){return e===$e?Te(Jt(t,r)):Y(e)?Zt(e,r):Te(Qt(U(t)))}function er(t){var e=le(ve(t)),r=["absolute","fixed"].indexOf(q(t).position)>=0,o=r&&V(t)?ae(t):t;return Y(o)?e.filter(function(n){return Y(n)&&Fe(n,o)&&I(n)!=="body"}):[]}function tr(t,e,r,o){var n=e==="clippingParents"?er(t):[].concat(e),i=[].concat(n,[r]),c=i[0],a=i.reduce(function(s,f){var l=_e(t,f,o);return s.top=_(l.top,s.top),s.right=pe(l.right,s.right),s.bottom=pe(l.bottom,s.bottom),s.left=_(l.left,s.left),s},_e(t,c,o));return a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}function Ge(t){var e=t.reference,r=t.element,o=t.placement,n=o?N(o):null,i=o?te(o):null,c=e.x+e.width/2-r.width/2,a=e.y+e.height/2-r.height/2,s;switch(n){case M:s={x:c,y:e.y-r.height};break;case $:s={x:c,y:e.y+e.height};break;case H:s={x:e.x+e.width,y:a};break;case S:s={x:e.x-r.width,y:a};break;default:s={x:e.x,y:e.y}}var f=n?Pe(n):null;if(f!=null){var l=f==="y"?"height":"width";switch(i){case Q:s[f]=s[f]-(e[l]/2-r[l]/2);break;case oe:s[f]=s[f]+(e[l]/2-r[l]/2);break}}return s}function ce(t,e){e===void 0&&(e={});var r=e,o=r.placement,n=o===void 0?t.placement:o,i=r.strategy,c=i===void 0?t.strategy:i,a=r.boundary,s=a===void 0?bt:a,f=r.rootBoundary,l=f===void 0?$e:f,g=r.elementContext,O=g===void 0?ie:g,v=r.altBoundary,C=v===void 0?!1:v,h=r.padding,y=h===void 0?0:h,E=qe(typeof y!="number"?y:Ue(y,ne)),A=O===ie?Ot:ie,P=t.rects.popper,m=t.elements[C?A:O],w=tr(Y(m)?m:m.contextElement||U(t.elements.popper),s,l,c),x=ee(t.elements.reference),k=Ge({reference:x,element:P,placement:n}),L=Te(Object.assign({},P,k)),R=O===ie?L:x,u={top:w.top-R.top+E.top,bottom:R.bottom-w.bottom+E.bottom,left:w.left-R.left+E.left,right:R.right-w.right+E.right},p=t.modifiersData.offset;if(O===ie&&p){var b=p[n];Object.keys(u).forEach(function(B){var W=[H,$].indexOf(B)>=0?1:-1,z=[M,$].indexOf(B)>=0?"y":"x";u[B]+=b[z]*W})}return u}function rr(t,e){e===void 0&&(e={});var r=e,o=r.placement,n=r.boundary,i=r.rootBoundary,c=r.padding,a=r.flipVariations,s=r.allowedAutoPlacements,f=s===void 0?Ve:s,l=te(o),g=l?a?He:He.filter(function(C){return te(C)===l}):ne,O=g.filter(function(C){return f.indexOf(C)>=0});O.length===0&&(O=g);var v=O.reduce(function(C,h){return C[h]=ce(t,{placement:h,boundary:n,rootBoundary:i,padding:c})[N(h)],C},{});return Object.keys(v).sort(function(C,h){return v[C]-v[h]})}function nr(t){if(N(t)===Oe)return[];var e=ge(t);return[Xe(t),e,Xe(e)]}function or(t){var e=t.state,r=t.options,o=t.name;if(!e.modifiersData[o]._skip){for(var n=r.mainAxis,i=n===void 0?!0:n,c=r.altAxis,a=c===void 0?!0:c,s=r.fallbackPlacements,f=r.padding,l=r.boundary,g=r.rootBoundary,O=r.altBoundary,v=r.flipVariations,C=v===void 0?!0:v,h=r.allowedAutoPlacements,y=e.options.placement,E=N(y),A=E===y,P=s||(A||!C?[ge(y)]:nr(y)),m=[y].concat(P).reduce(function(re,X){return re.concat(N(X)===Oe?rr(e,{placement:X,boundary:l,rootBoundary:g,padding:f,flipVariations:C,allowedAutoPlacements:h}):X)},[]),w=e.rects.reference,x=e.rects.popper,k=new Map,L=!0,R=m[0],u=0;u<m.length;u++){var p=m[u],b=N(p),B=te(p)===Q,W=[M,$].indexOf(b)>=0,z=W?"width":"height",D=ce(e,{placement:p,boundary:l,rootBoundary:g,altBoundary:O,padding:f}),F=W?B?H:S:B?$:M;w[z]>x[z]&&(F=ge(F));var he=ge(F),G=[];if(i&&G.push(D[b]<=0),a&&G.push(D[F]<=0,D[he]<=0),G.every(function(re){return re})){R=p,L=!1;break}k.set(p,G)}if(L)for(var ye=C?3:1,Me=function(X){var de=m.find(function(xe){var K=k.get(xe);if(K)return K.slice(0,X).every(function(Se){return Se})});if(de)return R=de,"break"},fe=ye;fe>0;fe--){var we=Me(fe);if(we==="break")break}e.placement!==R&&(e.modifiersData[o]._skip=!0,e.placement=R,e.reset=!0)}}const ir={name:"flip",enabled:!0,phase:"main",fn:or,requiresIfExists:["offset"],data:{_skip:!1}};function Ke(t,e,r){return r===void 0&&(r={x:0,y:0}),{top:t.top-e.height-r.y,right:t.right-e.width+r.x,bottom:t.bottom-e.height+r.y,left:t.left-e.width-r.x}}function Je(t){return[M,H,$,S].some(function(e){return t[e]>=0})}function ar(t){var e=t.state,r=t.name,o=e.rects.reference,n=e.rects.popper,i=e.modifiersData.preventOverflow,c=ce(e,{elementContext:"reference"}),a=ce(e,{altBoundary:!0}),s=Ke(c,o),f=Ke(a,n,i),l=Je(s),g=Je(f);e.modifiersData[r]={referenceClippingOffsets:s,popperEscapeOffsets:f,isReferenceHidden:l,hasPopperEscaped:g},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":l,"data-popper-escaped":g})}const sr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:ar};function lr(t,e,r){var o=N(t),n=[S,M].indexOf(o)>=0?-1:1,i=typeof r=="function"?r(Object.assign({},e,{placement:t})):r,c=i[0],a=i[1];return c=c||0,a=(a||0)*n,[S,H].indexOf(o)>=0?{x:a,y:c}:{x:c,y:a}}function cr(t){var e=t.state,r=t.options,o=t.name,n=r.offset,i=n===void 0?[0,0]:n,c=Ve.reduce(function(l,g){return l[g]=lr(g,e.rects,i),l},{}),a=c[e.placement],s=a.x,f=a.y;e.modifiersData.popperOffsets!=null&&(e.modifiersData.popperOffsets.x+=s,e.modifiersData.popperOffsets.y+=f),e.modifiersData[o]=c}const ur={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:cr};function fr(t){var e=t.state,r=t.name;e.modifiersData[r]=Ge({reference:e.rects.reference,element:e.rects.popper,placement:e.placement})}const dr={name:"popperOffsets",enabled:!0,phase:"read",fn:fr,data:{}};function pr(t){return t==="x"?"y":"x"}function vr(t){var e=t.state,r=t.options,o=t.name,n=r.mainAxis,i=n===void 0?!0:n,c=r.altAxis,a=c===void 0?!1:c,s=r.boundary,f=r.rootBoundary,l=r.altBoundary,g=r.padding,O=r.tether,v=O===void 0?!0:O,C=r.tetherOffset,h=C===void 0?0:C,y=ce(e,{boundary:s,rootBoundary:f,padding:g,altBoundary:l}),E=N(e.placement),A=te(e.placement),P=!A,m=Pe(E),w=pr(m),x=e.modifiersData.popperOffsets,k=e.rects.reference,L=e.rects.popper,R=typeof h=="function"?h(Object.assign({},e.rects,{placement:e.placement})):h,u=typeof R=="number"?{mainAxis:R,altAxis:R}:Object.assign({mainAxis:0,altAxis:0},R),p=e.modifiersData.offset?e.modifiersData.offset[e.placement]:null,b={x:0,y:0};if(x){if(i){var B,W=m==="y"?M:S,z=m==="y"?$:H,D=m==="y"?"height":"width",F=x[m],he=F+y[W],G=F-y[z],ye=v?-L[D]/2:0,Me=A===Q?k[D]:L[D],fe=A===Q?-L[D]:-k[D],we=e.elements.arrow,re=v&&we?Ee(we):{width:0,height:0},X=e.modifiersData["arrow#persistent"]?e.modifiersData["arrow#persistent"].padding:Ne(),de=X[W],xe=X[z],K=se(0,k[D],re[D]),Se=P?k[D]/2-ye-K-de-u.mainAxis:Me-K-de-u.mainAxis,Mr=P?-k[D]/2+ye+K+xe+u.mainAxis:fe+K+xe+u.mainAxis,je=e.elements.arrow&&ae(e.elements.arrow),Sr=je?m==="y"?je.clientTop||0:je.clientLeft||0:0,dt=(B=p?.[m])!=null?B:0,jr=F+Se-dt-Sr,Dr=F+Mr-dt,pt=se(v?pe(he,jr):he,F,v?_(G,Dr):G);x[m]=pt,b[m]=pt-F}if(a){var vt,$r=m==="x"?M:S,Hr=m==="x"?$:H,J=x[w],be=w==="y"?"height":"width",mt=J+y[$r],gt=J-y[Hr],De=[M,S].indexOf(E)!==-1,ht=(vt=p?.[w])!=null?vt:0,yt=De?mt:J-k[be]-L[be]-ht+u.altAxis,wt=De?J+k[be]+L[be]-ht-u.altAxis:gt,xt=v&&De?Vt(yt,J,wt):se(v?yt:mt,J,v?wt:gt);x[w]=xt,b[w]=xt-J}e.modifiersData[o]=b}}const mr={name:"preventOverflow",enabled:!0,phase:"main",fn:vr,requiresIfExists:["offset"]};function gr(t){return{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}}function hr(t){return t===j(t)||!V(t)?Ae(t):gr(t)}function yr(t){var e=t.getBoundingClientRect(),r=Z(e.width)/t.offsetWidth||1,o=Z(e.height)/t.offsetHeight||1;return r!==1||o!==1}function wr(t,e,r){r===void 0&&(r=!1);var o=V(e),n=V(e)&&yr(e),i=U(e),c=ee(t,n,r),a={scrollLeft:0,scrollTop:0},s={x:0,y:0};return(o||!o&&!r)&&((I(e)!=="body"||Re(i))&&(a=hr(e)),V(e)?(s=ee(e,!0),s.x+=e.clientLeft,s.y+=e.clientTop):i&&(s.x=Be(i))),{x:c.left+a.scrollLeft-s.x,y:c.top+a.scrollTop-s.y,width:c.width,height:c.height}}function xr(t){var e=new Map,r=new Set,o=[];t.forEach(function(i){e.set(i.name,i)});function n(i){r.add(i.name);var c=[].concat(i.requires||[],i.requiresIfExists||[]);c.forEach(function(a){if(!r.has(a)){var s=e.get(a);s&&n(s)}}),o.push(i)}return t.forEach(function(i){r.has(i.name)||n(i)}),o}function br(t){var e=xr(t);return Mt.reduce(function(r,o){return r.concat(e.filter(function(n){return n.phase===o}))},[])}function Or(t){var e;return function(){return e||(e=new Promise(function(r){Promise.resolve().then(function(){e=void 0,r(t())})})),e}}function kr(t){var e=t.reduce(function(r,o){var n=r[o.name];return r[o.name]=n?Object.assign({},n,o,{options:Object.assign({},n.options,o.options),data:Object.assign({},n.data,o.data)}):o,r},{});return Object.keys(e).map(function(r){return e[r]})}var Qe={placement:"bottom",modifiers:[],strategy:"absolute"};function Ze(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return!e.some(function(o){return!(o&&typeof o.getBoundingClientRect=="function")})}function Cr(t){t===void 0&&(t={});var e=t,r=e.defaultModifiers,o=r===void 0?[]:r,n=e.defaultOptions,i=n===void 0?Qe:n;return function(a,s,f){f===void 0&&(f=i);var l={placement:"bottom",orderedModifiers:[],options:Object.assign({},Qe,i),modifiersData:{},elements:{reference:a,popper:s},attributes:{},styles:{}},g=[],O=!1,v={state:l,setOptions:function(E){var A=typeof E=="function"?E(l.options):E;h(),l.options=Object.assign({},i,l.options,A),l.scrollParents={reference:Y(a)?le(a):a.contextElement?le(a.contextElement):[],popper:le(s)};var P=br(kr([].concat(o,l.options.modifiers)));return l.orderedModifiers=P.filter(function(m){return m.enabled}),C(),v.update()},forceUpdate:function(){if(!O){var E=l.elements,A=E.reference,P=E.popper;if(Ze(A,P)){l.rects={reference:wr(A,ae(P),l.options.strategy==="fixed"),popper:Ee(P)},l.reset=!1,l.placement=l.options.placement,l.orderedModifiers.forEach(function(u){return l.modifiersData[u.name]=Object.assign({},u.data)});for(var m=0;m<l.orderedModifiers.length;m++){if(l.reset===!0){l.reset=!1,m=-1;continue}var w=l.orderedModifiers[m],x=w.fn,k=w.options,L=k===void 0?{}:k,R=w.name;typeof x=="function"&&(l=x({state:l,options:L,name:R,instance:v})||l)}}}},update:Or(function(){return new Promise(function(y){v.forceUpdate(),y(l)})}),destroy:function(){h(),O=!0}};if(!Ze(a,s))return v;v.setOptions(f).then(function(y){!O&&f.onFirstUpdate&&f.onFirstUpdate(y)});function C(){l.orderedModifiers.forEach(function(y){var E=y.name,A=y.options,P=A===void 0?{}:A,m=y.effect;if(typeof m=="function"){var w=m({state:l,name:E,instance:v,options:P}),x=function(){};g.push(w||x)}})}function h(){g.forEach(function(y){return y()}),g=[]}return v}}var Er=[_t,dr,Xt,Dt,ur,ir,mr,Nt,sr],Pr=Cr({defaultModifiers:Er});class Le{plugins=new Map;register(e){this.plugins.set(e.command,e)}unregister(e){this.plugins.delete(e)}getPlugins(){return Array.from(this.plugins.values())}getPlugin(e){return this.plugins.get(e)}executeCommand(e,r){const o=this.plugins.get(e);return o?(o.execute(r),!0):!1}clear(){this.plugins.clear()}}const Ar=new Le,ue={bold:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>',italic:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>',underline:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" y1="21" x2="20" y2="21"/></svg>',strikeThrough:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4H9a3 3 0 0 0-2.83 4"/><path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" y1="12" x2="20" y2="12"/></svg>',removeFormat:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3,6 5,6 21,6"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>'},et={command:"bold",icon:ue.bold,title:"Bold",execute:()=>{document.execCommand("bold",!1)},isActive:()=>document.queryCommandState("bold")},tt={command:"italic",icon:ue.italic,title:"Italic",execute:()=>{document.execCommand("italic",!1)},isActive:()=>document.queryCommandState("italic")},rt={command:"underline",icon:ue.underline,title:"Underline",execute:()=>{document.execCommand("underline",!1)},isActive:()=>document.queryCommandState("underline")},nt={command:"strikeThrough",icon:ue.strikeThrough,title:"Strikethrough",execute:()=>{document.execCommand("strikeThrough",!1)},isActive:()=>document.queryCommandState("strikeThrough")},ot={command:"removeFormat",icon:ue.removeFormat,title:"Remove Format",execute:()=>{document.execCommand("removeFormatting",!1)},isActive:()=>!1},it={insertUnorderedList:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>',insertOrderedList:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1.5"/></svg>'},at={command:"insertUnorderedList",icon:it.insertUnorderedList,title:"Bullet List",execute:()=>{document.execCommand("insertUnorderedList",!1)},isActive:()=>document.queryCommandState("insertUnorderedList")},st={command:"insertOrderedList",icon:it.insertOrderedList,title:"Numbered List",execute:()=>{document.execCommand("insertOrderedList",!1)},isActive:()=>document.queryCommandState("insertOrderedList")},lt={createLink:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',insertImage:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="M21 15l-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>'},ct={command:"createLink",icon:lt.createLink,title:"Link",execute:()=>{const t=prompt("Enter URL:");t&&document.execCommand("createLink",!1,t)},isActive:()=>!1},ut={command:"insertImage",icon:lt.insertImage,title:"Image",execute:()=>{const t=prompt("Enter image URL (http/https only):");t&&(t.startsWith("http://")||t.startsWith("https://")?document.execCommand("insertImage",!1,t):alert("Only HTTP/HTTPS image URLs are allowed."))},isActive:()=>!1},ft=[et,tt,rt,nt,ot,at,st,ct,ut],Br={class:"v-html-editor relative"},Rr=["onClick","title"],Tr=["innerHTML"],Lr=((t,e)=>{const r=t.__vccOpts||t;for(const[o,n]of e)r[o]=n;return r})(d.defineComponent({__name:"VHtmlEditor",props:d.mergeModels({toolbarAlwaysShow:{type:Boolean,default:!1},plugins:{default:()=>ft},css:{default:""},noEditorClasses:{type:Boolean,default:!1}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const e=t,r=d.useModel(t,"modelValue"),o=d.computed(()=>e.css?e.css.replace(/([^{}]+){/g,(u,p)=>{const b=p.trim();return b.startsWith("@")?u:`${b.split(",").map(W=>`.v-html-editor ${W.trim()}`).join(", ")} {`}):""),n=d.ref(),i=d.ref();let c=null;const a=d.ref(!1),s=d.ref(!1),f=d.ref(!1);let l=null;const g=new Le;d.onMounted(()=>{e.plugins.forEach(u=>{g.register(u)})}),d.watch(()=>e.plugins,u=>{g.clear(),u.forEach(p=>{g.register(p)})},{deep:!0});const O=u=>{const p=u.target;r.value=p.innerHTML},v=()=>{c&&(c.destroy(),c=null)},C=u=>{if(!u.rangeCount||!n.value)return!1;const b=u.getRangeAt(0).commonAncestorContainer;return n.value.contains(b)||n.value===b},h=()=>{l&&clearTimeout(l),l=window.setTimeout(()=>{const u=window.getSelection();if(!u||u.rangeCount===0){k();return}if(!C(u)){k();return}const p=u.getRangeAt(0);!p.collapsed&&u.toString().trim()||e.toolbarAlwaysShow?w(p):k()},50)},y=()=>{e.toolbarAlwaysShow&&(l&&clearTimeout(l),l=window.setTimeout(()=>{const u=window.getSelection();if(u&&u.rangeCount>0&&C(u)){const p=u.getRangeAt(0);w(p)}},50))},E=()=>{f.value=!0},A=()=>{f.value=!1,setTimeout(()=>{s.value||(a.value=!1,v())},100)},P=()=>{a.value&&c&&c.update()},m=(u,p)=>{if(!p)return!1;const b=p.getBoundingClientRect();return u.top>0&&u.left>0&&u.top>=b.top-100&&u.top<=b.bottom+100&&u.left>=b.left-100&&u.left<=b.right+100},w=u=>{if(!i.value||!n.value)return;const p=u.getBoundingClientRect();if(!m(p,n.value)){const B=n.value.getBoundingClientRect();if(B.top===0&&B.left===0){k();return}const W=new DOMRect(B.left+20,B.top+20,0,0);x({getBoundingClientRect:()=>W});return}x({getBoundingClientRect:()=>new DOMRect(u.collapsed?p.left:p.left+p.width/2,p.top-10,0,0)})},x=u=>{i.value&&(v(),c=Pr(u,i.value,{placement:"top",modifiers:[{name:"offset",options:{offset:[0,10]}},{name:"preventOverflow",options:{boundary:"viewport",padding:8}},{name:"flip",options:{fallbackPlacements:["bottom","top"]}}]}),a.value=!0)},k=()=>{e.toolbarAlwaysShow||setTimeout(()=>{s.value||(a.value=!1,v())},100)},L=u=>{n.value&&(g.executeCommand(u,n.value),d.nextTick(()=>{n.value&&(r.value=n.value.innerHTML)}))},R=u=>{const p=g.getPlugin(u);return p?.isActive?p.isActive():!1};return d.watch(r,u=>{n.value&&n.value.innerHTML!==u&&(n.value.innerHTML=u||"")},{immediate:!0}),d.onMounted(()=>{document.addEventListener("selectionchange",h),window.addEventListener("scroll",P,!0),n.value&&r.value&&(n.value.innerHTML=r.value)}),d.onUnmounted(()=>{document.removeEventListener("selectionchange",h),window.removeEventListener("scroll",P,!0),l&&clearTimeout(l),v()}),(u,p)=>(d.openBlock(),d.createElementBlock("div",Br,[d.createElementVNode("div",{ref_key:"editorRef",ref:n,contenteditable:"true",onInput:O,onMouseup:h,onKeyup:h,onClick:y,onFocus:E,onBlur:A,class:d.normalizeClass(e.noEditorClasses?{"editor-styled":e.css}:["min-h-32 p-4 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent prose prose-sm max-w-none",{"editor-styled":e.css}]),style:d.normalizeStyle(e.noEditorClasses?void 0:"white-space: pre-wrap;")},null,38),(d.openBlock(),d.createBlock(d.Teleport,{to:"body"},[d.withDirectives(d.createElementVNode("div",{ref_key:"toolbarRef",ref:i,onMouseenter:p[0]||(p[0]=b=>s.value=!0),onMouseleave:p[1]||(p[1]=b=>{s.value=!1,k()}),class:"fixed z-[10000] bg-gray-800 text-white rounded-lg shadow-lg p-2 flex items-center space-x-1"},[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(d.unref(g).getPlugins(),b=>(d.openBlock(),d.createElementBlock("button",{key:b.command,onClick:B=>L(b.command),class:d.normalizeClass(["px-2 py-1 rounded text-sm font-medium transition-colors duration-150 flex items-center justify-center",R(b.command)?"bg-blue-500 text-white":"hover:bg-gray-700 text-gray-200"]),title:b.title},[d.createElementVNode("span",{innerHTML:b.icon,class:"w-4 h-4"},null,8,Tr)],10,Rr))),128))],544),[[d.vShow,a.value]])])),o.value?(d.openBlock(),d.createBlock(d.resolveDynamicComponent("style"),{key:0},{default:d.withCtx(()=>[d.createTextVNode(d.toDisplayString(o.value),1)]),_:1})):d.createCommentVNode("",!0)]))}}),[["__scopeId","data-v-e039b53a"]]);T.EditorPluginRegistry=Le,T.VHtmlEditor=Lr,T.boldPlugin=et,T.defaultPlugins=ft,T.imagePlugin=ut,T.italicPlugin=tt,T.linkPlugin=ct,T.orderedListPlugin=st,T.pluginRegistry=Ar,T.removeFormatPlugin=ot,T.strikeThroughPlugin=nt,T.underlinePlugin=rt,T.unorderedListPlugin=at,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});