import e from"@babel/runtime/helpers/defineProperty";import t from"prop-types";import{useRef as r,useEffect as n}from"react";import{Transforms as i}from"slate";import{useSlateStatic as o,ReactEditor as d}from"slate-react";import s from"./ImageElement.css.js";import{jsxs as c,jsx as a}from"react/jsx-runtime";function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?m(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var l=function(e){var t,m=e.attributes,l=e.element,p=e.imageWidth,f=e.mode,v=e.children,h="write"===f,b=r(),y=r(),g=o(),w=new AbortController,O=function(e){b.current&&b.current.style.setProperty("width","".concat(e,"px"))},P=function(){var e=document.getElementById("resizable".concat(l.url)),t=e&&window.getComputedStyle(e).getPropertyValue("width");return t?parseInt(t,10):document.body.clientWidth},j=function e(){i.removeNodes(g,{at:d.findPath(g,l)}),i.insertNodes(g,u(u({},l),{},{dimensions:{width:P()-24}}),{at:d.findPath(g,l)}),document.body.removeEventListener("pointerup",e)},E=document.getElementsByClassName("c-docs-custom-page-content"),L=E&&E[0]&&E[0].offsetWidth-36||.5*document.body.clientWidth,N=function(e){var t=P(),r=e.pageX;document.body.addEventListener("pointermove",(function(e){return function(e,t,r){e.preventDefault(),P()<150||P()>L?O(Math.min(Math.max(P(),150),L)):O(-1*(t-e.pageX)+r)}(e,r,t)}),{signal:w.signal}),document.body.addEventListener("pointerup",j)};n((function(){return b.current&&h&&b.current.addEventListener("mousedown",N),function(){w.abort(),document.body.removeEventListener("pointerup",j),document.body.removeEventListener("pointermove",j),b.current&&b.current.removeEventListener("mousedown",N)}}),[f]);var W=(null===(t=l.dimensions)||void 0===t?void 0:t.width)+24;return c("div",u(u({},m),{},{children:[a("div",{contentEditable:!1,children:l&&a("div",{style:{width:W||p},ref:b,id:"resizable".concat(l.url),className:s.resizable,children:c("div",{className:s.container,children:[h&&a("div",{className:s.handleLeft}),a("img",{src:l.url,className:s.image,ref:y,alt:""}),h&&a("div",{className:s.handleRight})]})})}),v]}))};l.propTypes={attributes:t.shape({}).isRequired,children:t.node.isRequired,element:t.shape({url:t.string.isRequired,dimensions:t.shape({width:t.string})}).isRequired,imageWidth:t.string,mode:t.string},l.defaultProps={imageWidth:void 0,mode:void 0};export{l as default};
//# sourceMappingURL=ImageElement.js.map
