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