@embedpdf/utils 2.6.2 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +164 -164
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +164 -164
- package/dist/react/index.js.map +1 -1
- package/dist/shared/plugin-interaction-primitives/drag-resize-controller.d.ts +1 -1
- package/dist/shared-preact/plugin-interaction-primitives/drag-resize-controller.d.ts +1 -1
- package/dist/shared-react/plugin-interaction-primitives/drag-resize-controller.d.ts +1 -1
- package/dist/shared-svelte/plugin-interaction-primitives/drag-resize-controller.d.ts +1 -1
- package/dist/shared-vue/plugin-interaction-primitives/drag-resize-controller.d.ts +1 -1
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +164 -164
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +163 -163
- package/dist/vue/index.js.map +1 -1
- package/package.json +3 -3
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("preact/jsx-runtime"),e=require("@embedpdf/utils"),i=require("preact"),n=require("preact/hooks"),o=require("@embedpdf/models"),r="onDblClick";const a={n:0,ne:45,e:90,se:135,s:180,sw:225,w:270,nw:315},s=["ns-resize","nesw-resize","ew-resize","nwse-resize","ns-resize","nesw-resize","ew-resize","nwse-resize"];function l(t,e,i=0){const n=((a[t]+90*e+i)%360+360)%360,o=Math.round(n/45)%8;return s[o]}function h(t,e,i){const n=-t/2;return"center"===i?n:"outside"===i?n-e:n+e}function c(t,e,i,n=!1){if(!e)return t;let{origin:{x:o,y:r},size:{width:a,height:s}}=t;const l=e.minWidth??1,h=e.minHeight??1,c=e.maxWidth,u=e.maxHeight;if(i&&a>0&&s>0){const t=a/s;a<l&&(a=l,s=a/t),s<h&&(s=h,a=s*t),void 0!==c&&a>c&&(a=c,s=a/t),void 0!==u&&s>u&&(s=u,a=s*t)}else a=Math.max(l,a),s=Math.max(h,s),void 0!==c&&(a=Math.min(c,a)),void 0!==u&&(s=Math.min(u,s));return e.boundingBox&&!n&&(o=Math.max(0,Math.min(o,e.boundingBox.width-a)),r=Math.max(0,Math.min(r,e.boundingBox.height-s))),{origin:{x:o,y:r},size:{width:a,height:s}}}function u(t,e,i){const n=1e-6,r=o.calculateRotatedRectAABB(t,e);return r.origin.x>=-n&&r.origin.y>=-n&&r.origin.x+r.size.width<=i.width+n&&r.origin.y+r.size.height<=i.height+n}function d(t,e,i,n,r){const{startRect:a,maintainAspectRatio:s=!1,annotationRotation:l=0,constraints:h}=i,u=function(t){return{x:t.includes("e")?"left":t.includes("w")?"right":"center",y:t.includes("s")?"top":t.includes("n")?"bottom":"center"}}(e),d=a.size.width/a.size.height||1;let g=function(t,e,i){let n=t.origin.x,o=t.origin.y,r=t.size.width,a=t.size.height;return"left"===i.x?r+=e.x:"right"===i.x&&(n+=e.x,r-=e.x),"top"===i.y?a+=e.y:"bottom"===i.y&&(o+=e.y,a-=e.y),{origin:{x:n,y:o},size:{width:r,height:a}}}(a,t,u);if(s&&(g=function(t,e,i,n){let{x:o,y:r}=t.origin,{width:a,height:s}=t.size;if("center"===i.x||"center"===i.y)"center"===i.y?(s=a/n,r=e.origin.y+(e.size.height-s)/2):(a=s*n,o=e.origin.x+(e.size.width-a)/2);else{const t=Math.abs(a-e.size.width),i=Math.abs(s-e.size.height),o=t+i;if(0===o)a=e.size.width,s=e.size.height;else{const e=t/o,r=i/o,l=a/n;a=e*a+r*(s*n),s=e*l+r*s}}return"right"===i.x&&(o=e.origin.x+e.size.width-a),"bottom"===i.y&&(r=e.origin.y+e.size.height-s),{origin:{x:o,y:r},size:{width:a,height:s}}}(g,a,u,d)),n&&(g=function(t,e,i,n,o){if(!n)return t;let{x:r,y:a}=t.origin,{width:s,height:l}=t.size;s=Math.max(1,s),l=Math.max(1,l);const h="left"===i.x?e.origin.x:e.origin.x+e.size.width,c="top"===i.y?e.origin.y:e.origin.y+e.size.height,u="left"===i.x?n.width-h:"right"===i.x?h:2*Math.min(e.origin.x,n.width-e.origin.x-e.size.width)+e.size.width,d="top"===i.y?n.height-c:"bottom"===i.y?c:2*Math.min(e.origin.y,n.height-e.origin.y-e.size.height)+e.size.height;if(o){const t=s>u?u/s:1,e=l>d?d/l:1,i=Math.min(t,e);i<1&&(s*=i,l*=i)}else s=Math.min(s,u),l=Math.min(l,d);return r="left"===i.x?h:"right"===i.x?h-s:e.origin.x+(e.size.width-s)/2,a="top"===i.y?c:"bottom"===i.y?c-l:e.origin.y+(e.size.height-l)/2,r=Math.max(0,Math.min(r,n.width-s)),a=Math.max(0,Math.min(a,n.height-l)),{origin:{x:r,y:a},size:{width:s,height:l}}}(g,a,u,null==h?void 0:h.boundingBox,s)),g=c(g,h,s,r),r&&(g=function(t,e,i){let n,o;return n="left"===i.x?e.origin.x:"right"===i.x?e.origin.x+e.size.width-t.size.width:e.origin.x+(e.size.width-t.size.width)/2,o="top"===i.y?e.origin.y:"bottom"===i.y?e.origin.y+e.size.height-t.size.height:e.origin.y+(e.size.height-t.size.height)/2,{origin:{x:n,y:o},size:t.size}}(g,a,u)),0!==l){const t=function(t,e){return{x:"left"===e.x?t.origin.x:"right"===e.x?t.origin.x+t.size.width:t.origin.x+t.size.width/2,y:"top"===e.y?t.origin.y:"bottom"===e.y?t.origin.y+t.size.height:t.origin.y+t.size.height/2}}(a,u),e={x:a.origin.x+a.size.width/2,y:a.origin.y+a.size.height/2},i={x:g.origin.x+g.size.width/2,y:g.origin.y+g.size.height/2},n=o.rotatePointAround(t,e,l),r=o.rotatePointAround(t,i,l);g={origin:{x:g.origin.x+(n.x-r.x),y:g.origin.y+(n.y-r.y)},size:g.size}}return g}class g{constructor(t,e){this.config=t,this.onUpdate=e,this.state="idle",this.startPoint=null,this.startElement=null,this.startRotationElement=null,this.gestureRotationCenter=null,this.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[],this.currentVertices=[],this.rotationCenter=null,this.centerScreen=null,this.initialRotation=0,this.lastComputedRotation=0,this.rotationDelta=0,this.rotationSnappedAngle=null,this.currentVertices=t.vertices||[]}updateConfig(t){this.config={...this.config,...t},"vertex-editing"!==this.state&&(this.currentVertices=t.vertices||[])}startDrag(t,e){this.state="dragging",this.startPoint={x:t,y:e},this.startElement={...this.config.element},this.startRotationElement=this.config.rotationElement?{...this.config.rotationElement}:null,this.currentPosition={...this.config.element},this.onUpdate({state:"start",transformData:{type:"move",changes:{rect:this.startElement}}})}startResize(t,e,i){this.state="resizing",this.activeHandle=t,this.startPoint={x:e,y:i},this.startElement={...this.config.element},this.currentPosition={...this.config.element},this.onUpdate({state:"start",transformData:{type:"resize",changes:{rect:this.startElement},metadata:{handle:this.activeHandle,maintainAspectRatio:this.config.maintainAspectRatio}}})}startVertexEdit(t,e,i){this.currentVertices=[...this.config.vertices??this.currentVertices],t<0||t>=this.currentVertices.length||(this.state="vertex-editing",this.activeVertexIndex=t,this.startPoint={x:e,y:i},this.startVertices=[...this.currentVertices],this.gestureRotationCenter=this.config.rotationCenter??{x:this.config.element.origin.x+this.config.element.size.width/2,y:this.config.element.origin.y+this.config.element.size.height/2},this.onUpdate({state:"start",transformData:{type:"vertex-edit",changes:{vertices:this.startVertices},metadata:{vertexIndex:t}}}))}startRotation(t,e,i=0,n){this.state="rotating",this.startPoint={x:t,y:e},this.startElement={...this.config.element},this.rotationCenter=this.config.rotationCenter??{x:this.config.element.origin.x+this.config.element.size.width/2,y:this.config.element.origin.y+this.config.element.size.height/2};const{scale:o=1}=this.config,r=this.config.rotationElement??this.config.element,a=r.size.width*o,s=r.size.height*o,l=n??Math.max(a,s)/2+35,h=(i+90*(this.config.pageRotation??0))*Math.PI/180;this.centerScreen={x:t-l*Math.sin(h),y:e+l*Math.cos(h)},this.initialRotation=i,this.lastComputedRotation=i,this.rotationDelta=0,this.rotationSnappedAngle=null,this.onUpdate({state:"start",transformData:{type:"rotate",changes:{rotation:i},metadata:{rotationAngle:i,rotationDelta:0,rotationCenter:this.rotationCenter,isSnapped:!1}}})}move(t,e,i){if("idle"!==this.state&&this.startPoint)if(void 0===i||0!==i){if("dragging"===this.state&&this.startElement){const i=this.calculateDelta(t,e),n=this.calculateDragPosition(i);this.currentPosition=n,this.onUpdate({state:"move",transformData:{type:"move",changes:{rect:n}}})}else if("resizing"===this.state&&this.activeHandle&&this.startElement){const i=function(t,e,i){const{annotationRotation:n=0,constraints:o}=i,r=null==o?void 0:o.boundingBox;if(0!==n&&r){const o=d(t,e,i,!1,!0);if(u(o,n,r))return o;let a=d({x:0,y:0},e,i,!1,!0),s=0,l=1;for(let h=0;h<20;h+=1){const o=(s+l)/2,h=d({x:t.x*o,y:t.y*o},e,i,!1,!0);u(h,n,r)?(a=h,s=o):l=o}return a}return d(t,e,i,!0,!1)}(this.calculateLocalDelta(t,e),this.activeHandle,{startRect:this.startElement,maintainAspectRatio:this.config.maintainAspectRatio,annotationRotation:this.config.annotationRotation,constraints:this.config.constraints});this.currentPosition=i,this.onUpdate({state:"move",transformData:{type:"resize",changes:{rect:i},metadata:{handle:this.activeHandle,maintainAspectRatio:this.config.maintainAspectRatio}}})}else if("vertex-editing"===this.state&&null!==this.activeVertexIndex){const i=this.calculateVertexPosition(t,e);this.currentVertices=i,this.onUpdate({state:"move",transformData:{type:"vertex-edit",changes:{vertices:i},metadata:{vertexIndex:this.activeVertexIndex}}})}else if("rotating"===this.state&&this.rotationCenter){const i=this.calculateAngleFromMouse(t,e),n=this.applyRotationSnapping(i),r=o.normalizeAngle(n.angle),a=r-this.lastComputedRotation,s=a>180?a-360:a<-180?a+360:a;this.rotationDelta+=s,this.lastComputedRotation=r,this.rotationSnappedAngle=n.isSnapped?r:null,this.onUpdate({state:"move",transformData:{type:"rotate",changes:{rotation:r},metadata:{rotationAngle:r,rotationDelta:this.rotationDelta,rotationCenter:this.rotationCenter,isSnapped:n.isSnapped,snappedAngle:this.rotationSnappedAngle??void 0,cursorPosition:{clientX:t,clientY:e}}}})}}else this.end()}end(){if("idle"===this.state)return;const t=this.state,e=this.activeHandle,i=this.activeVertexIndex;if("vertex-editing"===t)this.onUpdate({state:"end",transformData:{type:"vertex-edit",changes:{vertices:this.currentVertices},metadata:{vertexIndex:i||void 0}}});else if("rotating"===t)this.onUpdate({state:"end",transformData:{type:"rotate",changes:{rotation:this.lastComputedRotation},metadata:{rotationAngle:this.lastComputedRotation,rotationDelta:this.rotationDelta,rotationCenter:this.rotationCenter||void 0,isSnapped:null!==this.rotationSnappedAngle,snappedAngle:this.rotationSnappedAngle??void 0}}});else{const i=this.currentPosition||this.config.element;this.onUpdate({state:"end",transformData:{type:"dragging"===t?"move":"resize",changes:{rect:i},metadata:"dragging"===t?void 0:{handle:e||void 0,maintainAspectRatio:this.config.maintainAspectRatio}}})}this.reset()}cancel(){"idle"!==this.state&&("vertex-editing"===this.state?this.onUpdate({state:"end",transformData:{type:"vertex-edit",changes:{vertices:this.startVertices},metadata:{vertexIndex:this.activeVertexIndex||void 0}}}):"rotating"===this.state?this.onUpdate({state:"end",transformData:{type:"rotate",changes:{rotation:this.initialRotation},metadata:{rotationAngle:this.initialRotation,rotationDelta:0,rotationCenter:this.rotationCenter||void 0,isSnapped:!1}}}):this.startElement&&this.onUpdate({state:"end",transformData:{type:"dragging"===this.state?"move":"resize",changes:{rect:this.startElement},metadata:"dragging"===this.state?void 0:{handle:this.activeHandle||void 0,maintainAspectRatio:this.config.maintainAspectRatio}}}),this.reset())}reset(){this.state="idle",this.startPoint=null,this.startElement=null,this.startRotationElement=null,this.gestureRotationCenter=null,this.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[],this.rotationCenter=null,this.centerScreen=null,this.initialRotation=0,this.lastComputedRotation=0,this.rotationDelta=0,this.rotationSnappedAngle=null}calculateDelta(t,e){if(!this.startPoint)return{x:0,y:0};const i={x:t-this.startPoint.x,y:e-this.startPoint.y};return this.transformDelta(i)}transformDelta(t){const{pageRotation:e=0,scale:i=1}=this.config,n=e*Math.PI/2,o=Math.cos(n),r=Math.sin(n),a=t.x/i,s=t.y/i;return{x:o*a+r*s,y:-r*a+o*s}}calculateLocalDelta(t,e){const i=this.calculateDelta(t,e),{annotationRotation:n=0}=this.config;if(0===n)return i;const o=n*Math.PI/180,r=Math.cos(o),a=Math.sin(o);return{x:r*i.x+a*i.y,y:-a*i.x+r*i.y}}clampPoint(t){var e;const i=null==(e=this.config.constraints)?void 0:e.boundingBox;if(!i)return t;const{annotationRotation:n=0}=this.config;if(0===n)return{x:Math.max(0,Math.min(t.x,i.width)),y:Math.max(0,Math.min(t.y,i.height))};const r=this.gestureRotationCenter??this.config.rotationCenter??{x:this.config.element.origin.x+this.config.element.size.width/2,y:this.config.element.origin.y+this.config.element.size.height/2},a=o.rotatePointAround(t,r,n),s=Math.max(0,Math.min(a.x,i.width)),l=Math.max(0,Math.min(a.y,i.height));return s===a.x&&l===a.y?t:o.rotatePointAround({x:s,y:l},r,-n)}calculateVertexPosition(t,e){if(null===this.activeVertexIndex)return this.startVertices;const i=this.calculateLocalDelta(t,e),n=[...this.startVertices],o=n[this.activeVertexIndex],r={x:o.x+i.x,y:o.y+i.y};return n[this.activeVertexIndex]=this.clampPoint(r),n}calculateDragPosition(t){if(!this.startElement)return this.config.element;const e={origin:{x:this.startElement.origin.x+t.x,y:this.startElement.origin.y+t.y},size:{width:this.startElement.size.width,height:this.startElement.size.height}},{annotationRotation:i=0,constraints:n}=this.config,o=null==n?void 0:n.boundingBox;if(0!==i&&o){let t,n,r,a;if(this.startRotationElement)t=this.startRotationElement.size.width,n=this.startRotationElement.size.height,r=this.startRotationElement.origin.x-this.startElement.origin.x,a=this.startRotationElement.origin.y-this.startElement.origin.y;else{const o=Math.abs(i*Math.PI/180),s=Math.abs(Math.cos(o)),l=Math.abs(Math.sin(o)),h=e.size.width,c=e.size.height;t=h*s+c*l,n=h*l+c*s,r=(h-t)/2,a=(c-n)/2}let{x:s,y:l}=e.origin;return s=Math.max(-r,Math.min(s,o.width-t-r)),l=Math.max(-a,Math.min(l,o.height-n-a)),{origin:{x:s,y:l},size:e.size}}return c(e,n,this.config.maintainAspectRatio??!1)}calculateAngleFromMouse(t,e){if(!this.centerScreen)return this.initialRotation;const i=t-this.centerScreen.x,n=e-this.centerScreen.y;if(Math.sqrt(i*i+n*n)<10)return this.lastComputedRotation;const r=90*(this.config.pageRotation??0),a=Math.atan2(n,i)*(180/Math.PI)+90-r;return o.normalizeAngle(Math.round(a))}applyRotationSnapping(t){const e=this.config.rotationSnapAngles??[0,90,180,270],i=this.config.rotationSnapThreshold??4,n=o.normalizeAngle(t);for(const r of e){const t=o.normalizeAngle(r),e=Math.abs(n-t);if(Math.min(e,360-e)<=i)return{angle:t,isSnapped:!0,snapTarget:t}}return{angle:n,isSnapped:!1}}}function p(t){const{onUpdate:e,enabled:i=!0,...o}=t,r=n.useRef(null),a=n.useRef(e),s=n.useRef(null),l=n.useRef(null);n.useEffect(()=>{a.current=e},[e]),n.useEffect(()=>{r.current?r.current.updateConfig(o):r.current=new g(o,t=>{var e;return null==(e=a.current)?void 0:e.call(a,t)})},[o.element,o.rotationCenter,o.rotationElement,o.constraints,o.maintainAspectRatio,o.pageRotation,o.annotationRotation,o.scale,o.vertices]);const h=n.useCallback(t=>{var e,i;const n=s.current,o=l.current,r=t??n;if(o&&null!==r)try{(null==(e=o.hasPointerCapture)?void 0:e.call(o,r))&&(null==(i=o.releasePointerCapture)||i.call(o,r))}catch{}s.current=null,l.current=null},[]),c=n.useCallback(t=>{var e;null!==s.current&&s.current!==t.pointerId&&(null==(e=r.current)||e.end(),h(s.current));const i=t.currentTarget;s.current=t.pointerId,l.current=i;try{i.setPointerCapture(t.pointerId)}catch{}},[h]);n.useEffect(()=>{const t=globalThis,e=t=>{var e;const i=s.current;null!==i&&t.pointerId===i&&(null==(e=r.current)||e.end(),h(t.pointerId))},i=()=>{var t;null!==s.current&&(null==(t=r.current)||t.end(),h())};return t.addEventListener("pointerup",e,!0),t.addEventListener("pointercancel",e,!0),t.addEventListener("blur",i,!0),()=>{t.removeEventListener("pointerup",e,!0),t.removeEventListener("pointercancel",e,!0),t.removeEventListener("blur",i,!0)}},[h]),n.useEffect(()=>()=>{var t;null!==s.current&&(null==(t=r.current)||t.end(),h())},[h]);const u=n.useCallback(t=>{var e;i&&(t.preventDefault(),t.stopPropagation(),null==(e=r.current)||e.startDrag(t.clientX,t.clientY),c(t))},[i,c]),d=n.useCallback(t=>{var e;t.preventDefault(),t.stopPropagation();const i=s.current;null!==i&&t.pointerId!==i||(null==(e=r.current)||e.move(t.clientX,t.clientY,t.buttons),s.current===t.pointerId&&0===t.buttons&&h(t.pointerId))},[h]),p=n.useCallback(t=>{var e;t.preventDefault(),t.stopPropagation();const i=s.current;null!==i&&t.pointerId!==i||(null==(e=r.current)||e.end(),h(t.pointerId))},[h]),m=n.useCallback(t=>{var e;const i=s.current;null!==i&&t.pointerId===i&&(null==(e=r.current)||e.end(),h(t.pointerId))},[h]),x=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=r.current)||n.startResize(t,e.clientX,e.clientY),c(e))},onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}),[i,d,p,m,c]),f=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=r.current)||n.startVertexEdit(t,e.clientX,e.clientY),c(e))},onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}),[i,d,p,m,c]),v=n.useCallback((t=0,e)=>({onPointerDown:n=>{var o;if(!i)return;n.preventDefault(),n.stopPropagation();const a=n.currentTarget.getBoundingClientRect(),s=a.left+a.width/2,l=a.top+a.height/2;null==(o=r.current)||o.startRotation(s,l,t,e),c(n)},onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}),[i,d,p,m,c]);return{dragProps:i?{onPointerDown:u,onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}:{},createResizeProps:x,createVertexProps:f,createRotationProps:v}}exports.CounterRotate=function({children:o,...r}){const{rect:a,rotation:s}=r,{matrix:l,width:h,height:c}=e.getCounterRotation(a,s),u=n.useRef(null);n.useEffect(()=>{const t=u.current;if(!t)return;const e=t=>{t.stopPropagation()},i=t=>{t.stopPropagation()};return t.addEventListener("pointerdown",e,{capture:!0}),t.addEventListener("touchstart",i,{capture:!0}),()=>{t.removeEventListener("pointerdown",e,{capture:!0}),t.removeEventListener("touchstart",i,{capture:!0})}},[]);const d={style:{position:"absolute",left:a.origin.x,top:a.origin.y,transform:l,transformOrigin:"0 0",width:h,height:c,pointerEvents:"none",zIndex:3},ref:t=>{u.current=t}};return t.jsx(i.Fragment,{children:o({menuWrapperProps:d,matrix:l,rect:{origin:{x:a.origin.x,y:a.origin.y},size:{width:h,height:c}}})})},exports.useDoublePressProps=function(t,{delay:e=300,tolerancePx:i=18}={}){const o=n.useRef({t:0,x:0,y:0}),a=n.useCallback(n=>{if(!t)return;if("mouse"===n.pointerType||!1===n.isPrimary)return;const r=performance.now(),a=n.clientX,s=n.clientY,l=r-o.current.t<=e,h=a-o.current.x,c=s-o.current.y;l&&h*h+c*c<=i*i&&(null==t||t(n)),o.current={t:r,x:a,y:s}},[t,e,i]),s=n.useCallback(e=>{null==t||t(e)},[t]);return t?{[r]:s,onPointerUpCapture:a}:{}},exports.useDragResize=p,exports.useInteractionHandles=function(t){var e,i,o,r,a,s;const{controller:c,resizeUI:u,vertexUI:d,rotationUI:g,includeVertices:m=!1,includeRotation:x=!1,currentRotation:f=0,handleAttrs:v,vertexAttrs:y,rotationAttrs:z}=t,{dragProps:R,createResizeProps:w,createVertexProps:P,createRotationProps:M}=p(c);return{dragProps:R,resize:n.useMemo(()=>function(t,e={}){const{handleSize:i=8,spacing:n=1,offsetMode:o="outside",includeSides:r=!1,zIndex:a=3,rotationAwareCursor:s=!0}=e,c=(t.pageRotation??0)%4,u=t.annotationRotation??0,d=t=>({[t]:h(i,n,o)+"px"});return[["nw",{...d("top"),...d("left")}],["ne",{...d("top"),...d("right")}],["sw",{...d("bottom"),...d("left")}],["se",{...d("bottom"),...d("right")}],...r?[["n",{...d("top"),left:`calc(50% - ${i/2}px)`}],["s",{...d("bottom"),left:`calc(50% - ${i/2}px)`}],["w",{...d("left"),top:`calc(50% - ${i/2}px)`}],["e",{...d("right"),top:`calc(50% - ${i/2}px)`}]]:[]].map(([t,e])=>({handle:t,style:{position:"absolute",width:i+"px",height:i+"px",borderRadius:"50%",zIndex:a,cursor:s?l(t,c,u):"default",pointerEvents:"auto",touchAction:"none",...e},attrs:{"data-epdf-handle":t}}))}(c,u).map(t=>{var e;return{key:null==(e=t.attrs)?void 0:e["data-epdf-handle"],style:t.style,...w(t.handle),...t.attrs??{},...(null==v?void 0:v(t.handle))??{}}}),[c.element.origin.x,c.element.origin.y,c.element.size.width,c.element.size.height,c.scale,c.pageRotation,c.annotationRotation,c.maintainAspectRatio,null==u?void 0:u.handleSize,null==u?void 0:u.spacing,null==u?void 0:u.offsetMode,null==u?void 0:u.includeSides,null==u?void 0:u.zIndex,null==u?void 0:u.rotationAwareCursor,w,v]),vertices:n.useMemo(()=>{if(!m)return[];return function(t,e={},i){const{vertexSize:n=12,zIndex:o=4}=e,r=t.element,a=t.scale??1;return(i??t.vertices??[]).map((t,e)=>({handle:"nw",style:{position:"absolute",left:(t.x-r.origin.x)*a-n/2+"px",top:(t.y-r.origin.y)*a-n/2+"px",width:n+"px",height:n+"px",borderRadius:"50%",cursor:"pointer",zIndex:o,pointerEvents:"auto",touchAction:"none"},attrs:{"data-epdf-vertex":e}}))}(c,d,c.vertices).map((t,e)=>({key:e,style:t.style,...P(e),...t.attrs??{},...(null==y?void 0:y(e))??{}}))},[m,c.element.origin.x,c.element.origin.y,c.element.size.width,c.element.size.height,c.scale,c.vertices,null==d?void 0:d.vertexSize,null==d?void 0:d.zIndex,P,y]),rotation:n.useMemo(()=>{if(!x)return null;const t=function(t,e={},i=0){const{handleSize:n=16,zIndex:o=5,showConnector:r=!0,connectorWidth:a=1}=e,s=t.scale??1,l=t.element,h=t.rotationElement??l,c=t.rotationCenter??{x:l.origin.x+l.size.width/2,y:l.origin.y+l.size.height/2};h.size.width,h.size.height;const u=(c.x-h.origin.x)*s,d=(c.y-h.origin.y)*s,g=i*Math.PI/180,p=e.margin??35,m=l.size.height*s/2+p;return{handleStyle:{position:"absolute",left:u+m*Math.sin(g)-n/2+"px",top:d-m*Math.cos(g)-n/2+"px",width:n+"px",height:n+"px",borderRadius:"50%",cursor:"grab",zIndex:o,pointerEvents:"auto",touchAction:"none"},connectorStyle:r?{position:"absolute",left:u-a/2+"px",top:d-m+"px",width:a+"px",height:m+"px",transformOrigin:"center bottom",transform:`rotate(${i}deg)`,zIndex:o-1,pointerEvents:"none"}:{},radius:m,attrs:{"data-epdf-rotation-handle":!0}}}(c,g,f);return{handle:{style:t.handleStyle,...M(f,t.radius),...t.attrs??{},...(null==z?void 0:z())??{}},connector:{style:t.connectorStyle,"data-epdf-rotation-connector":!0}}},[x,c.element.origin.x,c.element.origin.y,c.element.size.width,c.element.size.height,null==(e=c.rotationCenter)?void 0:e.x,null==(i=c.rotationCenter)?void 0:i.y,null==(o=c.rotationElement)?void 0:o.origin.x,null==(r=c.rotationElement)?void 0:r.origin.y,null==(a=c.rotationElement)?void 0:a.size.width,null==(s=c.rotationElement)?void 0:s.size.height,c.scale,f,null==g?void 0:g.handleSize,null==g?void 0:g.margin,null==g?void 0:g.zIndex,null==g?void 0:g.showConnector,null==g?void 0:g.connectorWidth,M,z])}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("preact/jsx-runtime"),e=require("@embedpdf/utils"),i=require("preact"),n=require("preact/hooks"),o=require("@embedpdf/models"),r="onDblClick";function a(t,e,i,n=!1){if(!e)return t;let{origin:{x:o,y:r},size:{width:a,height:s}}=t;const l=e.minWidth??1,h=e.minHeight??1,c=e.maxWidth,u=e.maxHeight;if(i&&a>0&&s>0){const t=a/s;a<l&&(a=l,s=a/t),s<h&&(s=h,a=s*t),void 0!==c&&a>c&&(a=c,s=a/t),void 0!==u&&s>u&&(s=u,a=s*t)}else a=Math.max(l,a),s=Math.max(h,s),void 0!==c&&(a=Math.min(c,a)),void 0!==u&&(s=Math.min(u,s));return e.boundingBox&&!n&&(o=Math.max(0,Math.min(o,e.boundingBox.width-a)),r=Math.max(0,Math.min(r,e.boundingBox.height-s))),{origin:{x:o,y:r},size:{width:a,height:s}}}function s(t,e,i){const n=1e-6,r=o.calculateRotatedRectAABB(t,e);return r.origin.x>=-n&&r.origin.y>=-n&&r.origin.x+r.size.width<=i.width+n&&r.origin.y+r.size.height<=i.height+n}function l(t,e,i,n,r){const{startRect:s,maintainAspectRatio:l=!1,annotationRotation:h=0,constraints:c}=i,u=function(t){return{x:t.includes("e")?"left":t.includes("w")?"right":"center",y:t.includes("s")?"top":t.includes("n")?"bottom":"center"}}(e),d=s.size.width/s.size.height||1;let g=function(t,e,i){let n=t.origin.x,o=t.origin.y,r=t.size.width,a=t.size.height;return"left"===i.x?r+=e.x:"right"===i.x&&(n+=e.x,r-=e.x),"top"===i.y?a+=e.y:"bottom"===i.y&&(o+=e.y,a-=e.y),{origin:{x:n,y:o},size:{width:r,height:a}}}(s,t,u);if(l&&(g=function(t,e,i,n){let{x:o,y:r}=t.origin,{width:a,height:s}=t.size;if("center"===i.x||"center"===i.y)"center"===i.y?(s=a/n,r=e.origin.y+(e.size.height-s)/2):(a=s*n,o=e.origin.x+(e.size.width-a)/2);else{const t=Math.abs(a-e.size.width),i=Math.abs(s-e.size.height),o=t+i;if(0===o)a=e.size.width,s=e.size.height;else{const e=t/o,r=i/o,l=a/n;a=e*a+r*(s*n),s=e*l+r*s}}return"right"===i.x&&(o=e.origin.x+e.size.width-a),"bottom"===i.y&&(r=e.origin.y+e.size.height-s),{origin:{x:o,y:r},size:{width:a,height:s}}}(g,s,u,d)),n&&(g=function(t,e,i,n,o){if(!n)return t;let{x:r,y:a}=t.origin,{width:s,height:l}=t.size;s=Math.max(1,s),l=Math.max(1,l);const h="left"===i.x?e.origin.x:e.origin.x+e.size.width,c="top"===i.y?e.origin.y:e.origin.y+e.size.height,u="left"===i.x?n.width-h:"right"===i.x?h:2*Math.min(e.origin.x,n.width-e.origin.x-e.size.width)+e.size.width,d="top"===i.y?n.height-c:"bottom"===i.y?c:2*Math.min(e.origin.y,n.height-e.origin.y-e.size.height)+e.size.height;if(o){const t=s>u?u/s:1,e=l>d?d/l:1,i=Math.min(t,e);i<1&&(s*=i,l*=i)}else s=Math.min(s,u),l=Math.min(l,d);return r="left"===i.x?h:"right"===i.x?h-s:e.origin.x+(e.size.width-s)/2,a="top"===i.y?c:"bottom"===i.y?c-l:e.origin.y+(e.size.height-l)/2,r=Math.max(0,Math.min(r,n.width-s)),a=Math.max(0,Math.min(a,n.height-l)),{origin:{x:r,y:a},size:{width:s,height:l}}}(g,s,u,null==c?void 0:c.boundingBox,l)),g=a(g,c,l,r),r&&(g=function(t,e,i){let n,o;return n="left"===i.x?e.origin.x:"right"===i.x?e.origin.x+e.size.width-t.size.width:e.origin.x+(e.size.width-t.size.width)/2,o="top"===i.y?e.origin.y:"bottom"===i.y?e.origin.y+e.size.height-t.size.height:e.origin.y+(e.size.height-t.size.height)/2,{origin:{x:n,y:o},size:t.size}}(g,s,u)),0!==h){const t=function(t,e){return{x:"left"===e.x?t.origin.x:"right"===e.x?t.origin.x+t.size.width:t.origin.x+t.size.width/2,y:"top"===e.y?t.origin.y:"bottom"===e.y?t.origin.y+t.size.height:t.origin.y+t.size.height/2}}(s,u),e={x:s.origin.x+s.size.width/2,y:s.origin.y+s.size.height/2},i={x:g.origin.x+g.size.width/2,y:g.origin.y+g.size.height/2},n=o.rotatePointAround(t,e,h),r=o.rotatePointAround(t,i,h);g={origin:{x:g.origin.x+(n.x-r.x),y:g.origin.y+(n.y-r.y)},size:g.size}}return g}const h={n:0,ne:45,e:90,se:135,s:180,sw:225,w:270,nw:315},c=["ns-resize","nesw-resize","ew-resize","nwse-resize","ns-resize","nesw-resize","ew-resize","nwse-resize"];function u(t,e,i=0){const n=((h[t]+90*e+i)%360+360)%360,o=Math.round(n/45)%8;return c[o]}function d(t,e,i){const n=-t/2;return"center"===i?n:"outside"===i?n-e:n+e}class g{constructor(t,e){this.config=t,this.onUpdate=e,this.state="idle",this.startPoint=null,this.startElement=null,this.startRotationElement=null,this.gestureRotationCenter=null,this.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[],this.currentVertices=[],this.rotationCenter=null,this.centerScreen=null,this.initialRotation=0,this.lastComputedRotation=0,this.rotationDelta=0,this.rotationSnappedAngle=null,this.currentVertices=t.vertices||[]}updateConfig(t){this.config={...this.config,...t},"vertex-editing"!==this.state&&(this.currentVertices=t.vertices||[])}startDrag(t,e){this.state="dragging",this.startPoint={x:t,y:e},this.startElement={...this.config.element},this.startRotationElement=this.config.rotationElement?{...this.config.rotationElement}:null,this.currentPosition={...this.config.element},this.onUpdate({state:"start",transformData:{type:"move",changes:{rect:this.startElement}}})}startResize(t,e,i){this.state="resizing",this.activeHandle=t,this.startPoint={x:e,y:i},this.startElement={...this.config.element},this.currentPosition={...this.config.element},this.onUpdate({state:"start",transformData:{type:"resize",changes:{rect:this.startElement},metadata:{handle:this.activeHandle,maintainAspectRatio:this.config.maintainAspectRatio}}})}startVertexEdit(t,e,i){this.currentVertices=[...this.config.vertices??this.currentVertices],t<0||t>=this.currentVertices.length||(this.state="vertex-editing",this.activeVertexIndex=t,this.startPoint={x:e,y:i},this.startVertices=[...this.currentVertices],this.gestureRotationCenter=this.config.rotationCenter??{x:this.config.element.origin.x+this.config.element.size.width/2,y:this.config.element.origin.y+this.config.element.size.height/2},this.onUpdate({state:"start",transformData:{type:"vertex-edit",changes:{vertices:this.startVertices},metadata:{vertexIndex:t}}}))}startRotation(t,e,i=0,n){this.state="rotating",this.startPoint={x:t,y:e},this.startElement={...this.config.element},this.rotationCenter=this.config.rotationCenter??{x:this.config.element.origin.x+this.config.element.size.width/2,y:this.config.element.origin.y+this.config.element.size.height/2};const{scale:o=1}=this.config,r=this.config.rotationElement??this.config.element,a=r.size.width*o,s=r.size.height*o,l=n??Math.max(a,s)/2+35,h=(i+90*(this.config.pageRotation??0))*Math.PI/180;this.centerScreen={x:t-l*Math.sin(h),y:e+l*Math.cos(h)},this.initialRotation=i,this.lastComputedRotation=i,this.rotationDelta=0,this.rotationSnappedAngle=null,this.onUpdate({state:"start",transformData:{type:"rotate",changes:{rotation:i},metadata:{rotationAngle:i,rotationDelta:0,rotationCenter:this.rotationCenter,isSnapped:!1}}})}move(t,e,i,n){if("idle"!==this.state&&this.startPoint)if(void 0===i||0!==i){if("dragging"===this.state&&this.startElement){const i=this.calculateDelta(t,e),n=this.calculateDragPosition(i);this.currentPosition=n,this.onUpdate({state:"move",transformData:{type:"move",changes:{rect:n}}})}else if("resizing"===this.state&&this.activeHandle&&this.startElement){const i=function(t,e,i){const{annotationRotation:n=0,constraints:o}=i,r=null==o?void 0:o.boundingBox;if(0!==n&&r){const o=l(t,e,i,!1,!0);if(s(o,n,r))return o;let a=l({x:0,y:0},e,i,!1,!0),h=0,c=1;for(let u=0;u<20;u+=1){const o=(h+c)/2,u=l({x:t.x*o,y:t.y*o},e,i,!1,!0);s(u,n,r)?(a=u,h=o):c=o}return a}return l(t,e,i,!0,!1)}(this.calculateLocalDelta(t,e),this.activeHandle,{startRect:this.startElement,maintainAspectRatio:this.config.maintainAspectRatio||!!n,annotationRotation:this.config.annotationRotation,constraints:this.config.constraints});this.currentPosition=i,this.onUpdate({state:"move",transformData:{type:"resize",changes:{rect:i},metadata:{handle:this.activeHandle,maintainAspectRatio:this.config.maintainAspectRatio||!!n}}})}else if("vertex-editing"===this.state&&null!==this.activeVertexIndex){const i=this.calculateVertexPosition(t,e);this.currentVertices=i,this.onUpdate({state:"move",transformData:{type:"vertex-edit",changes:{vertices:i},metadata:{vertexIndex:this.activeVertexIndex}}})}else if("rotating"===this.state&&this.rotationCenter){const i=this.calculateAngleFromMouse(t,e),n=this.applyRotationSnapping(i),r=o.normalizeAngle(n.angle),a=r-this.lastComputedRotation,s=a>180?a-360:a<-180?a+360:a;this.rotationDelta+=s,this.lastComputedRotation=r,this.rotationSnappedAngle=n.isSnapped?r:null,this.onUpdate({state:"move",transformData:{type:"rotate",changes:{rotation:r},metadata:{rotationAngle:r,rotationDelta:this.rotationDelta,rotationCenter:this.rotationCenter,isSnapped:n.isSnapped,snappedAngle:this.rotationSnappedAngle??void 0,cursorPosition:{clientX:t,clientY:e}}}})}}else this.end()}end(){if("idle"===this.state)return;const t=this.state,e=this.activeHandle,i=this.activeVertexIndex;if("vertex-editing"===t)this.onUpdate({state:"end",transformData:{type:"vertex-edit",changes:{vertices:this.currentVertices},metadata:{vertexIndex:i||void 0}}});else if("rotating"===t)this.onUpdate({state:"end",transformData:{type:"rotate",changes:{rotation:this.lastComputedRotation},metadata:{rotationAngle:this.lastComputedRotation,rotationDelta:this.rotationDelta,rotationCenter:this.rotationCenter||void 0,isSnapped:null!==this.rotationSnappedAngle,snappedAngle:this.rotationSnappedAngle??void 0}}});else{const i=this.currentPosition||this.config.element;this.onUpdate({state:"end",transformData:{type:"dragging"===t?"move":"resize",changes:{rect:i},metadata:"dragging"===t?void 0:{handle:e||void 0,maintainAspectRatio:this.config.maintainAspectRatio}}})}this.reset()}cancel(){"idle"!==this.state&&("vertex-editing"===this.state?this.onUpdate({state:"end",transformData:{type:"vertex-edit",changes:{vertices:this.startVertices},metadata:{vertexIndex:this.activeVertexIndex||void 0}}}):"rotating"===this.state?this.onUpdate({state:"end",transformData:{type:"rotate",changes:{rotation:this.initialRotation},metadata:{rotationAngle:this.initialRotation,rotationDelta:0,rotationCenter:this.rotationCenter||void 0,isSnapped:!1}}}):this.startElement&&this.onUpdate({state:"end",transformData:{type:"dragging"===this.state?"move":"resize",changes:{rect:this.startElement},metadata:"dragging"===this.state?void 0:{handle:this.activeHandle||void 0,maintainAspectRatio:this.config.maintainAspectRatio}}}),this.reset())}reset(){this.state="idle",this.startPoint=null,this.startElement=null,this.startRotationElement=null,this.gestureRotationCenter=null,this.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[],this.rotationCenter=null,this.centerScreen=null,this.initialRotation=0,this.lastComputedRotation=0,this.rotationDelta=0,this.rotationSnappedAngle=null}calculateDelta(t,e){if(!this.startPoint)return{x:0,y:0};const i={x:t-this.startPoint.x,y:e-this.startPoint.y};return this.transformDelta(i)}transformDelta(t){const{pageRotation:e=0,scale:i=1}=this.config,n=e*Math.PI/2,o=Math.cos(n),r=Math.sin(n),a=t.x/i,s=t.y/i;return{x:o*a+r*s,y:-r*a+o*s}}calculateLocalDelta(t,e){const i=this.calculateDelta(t,e),{annotationRotation:n=0}=this.config;if(0===n)return i;const o=n*Math.PI/180,r=Math.cos(o),a=Math.sin(o);return{x:r*i.x+a*i.y,y:-a*i.x+r*i.y}}clampPoint(t){var e;const i=null==(e=this.config.constraints)?void 0:e.boundingBox;if(!i)return t;const{annotationRotation:n=0}=this.config;if(0===n)return{x:Math.max(0,Math.min(t.x,i.width)),y:Math.max(0,Math.min(t.y,i.height))};const r=this.gestureRotationCenter??this.config.rotationCenter??{x:this.config.element.origin.x+this.config.element.size.width/2,y:this.config.element.origin.y+this.config.element.size.height/2},a=o.rotatePointAround(t,r,n),s=Math.max(0,Math.min(a.x,i.width)),l=Math.max(0,Math.min(a.y,i.height));return s===a.x&&l===a.y?t:o.rotatePointAround({x:s,y:l},r,-n)}calculateVertexPosition(t,e){if(null===this.activeVertexIndex)return this.startVertices;const i=this.calculateLocalDelta(t,e),n=[...this.startVertices],o=n[this.activeVertexIndex],r={x:o.x+i.x,y:o.y+i.y};return n[this.activeVertexIndex]=this.clampPoint(r),n}calculateDragPosition(t){if(!this.startElement)return this.config.element;const e={origin:{x:this.startElement.origin.x+t.x,y:this.startElement.origin.y+t.y},size:{width:this.startElement.size.width,height:this.startElement.size.height}},{annotationRotation:i=0,constraints:n}=this.config,o=null==n?void 0:n.boundingBox;if(0!==i&&o){let t,n,r,a;if(this.startRotationElement)t=this.startRotationElement.size.width,n=this.startRotationElement.size.height,r=this.startRotationElement.origin.x-this.startElement.origin.x,a=this.startRotationElement.origin.y-this.startElement.origin.y;else{const o=Math.abs(i*Math.PI/180),s=Math.abs(Math.cos(o)),l=Math.abs(Math.sin(o)),h=e.size.width,c=e.size.height;t=h*s+c*l,n=h*l+c*s,r=(h-t)/2,a=(c-n)/2}let{x:s,y:l}=e.origin;return s=Math.max(-r,Math.min(s,o.width-t-r)),l=Math.max(-a,Math.min(l,o.height-n-a)),{origin:{x:s,y:l},size:e.size}}return a(e,n,this.config.maintainAspectRatio??!1)}calculateAngleFromMouse(t,e){if(!this.centerScreen)return this.initialRotation;const i=t-this.centerScreen.x,n=e-this.centerScreen.y;if(Math.sqrt(i*i+n*n)<10)return this.lastComputedRotation;const r=90*(this.config.pageRotation??0),a=Math.atan2(n,i)*(180/Math.PI)+90-r;return o.normalizeAngle(Math.round(a))}applyRotationSnapping(t){const e=this.config.rotationSnapAngles??[0,90,180,270],i=this.config.rotationSnapThreshold??4,n=o.normalizeAngle(t);for(const r of e){const t=o.normalizeAngle(r),e=Math.abs(n-t);if(Math.min(e,360-e)<=i)return{angle:t,isSnapped:!0,snapTarget:t}}return{angle:n,isSnapped:!1}}}function p(t){const{onUpdate:e,enabled:i=!0,...o}=t,r=n.useRef(null),a=n.useRef(e),s=n.useRef(null),l=n.useRef(null);n.useEffect(()=>{a.current=e},[e]),n.useEffect(()=>{r.current?r.current.updateConfig(o):r.current=new g(o,t=>{var e;return null==(e=a.current)?void 0:e.call(a,t)})},[o.element,o.rotationCenter,o.rotationElement,o.constraints,o.maintainAspectRatio,o.pageRotation,o.annotationRotation,o.scale,o.vertices]);const h=n.useCallback(t=>{var e,i;const n=s.current,o=l.current,r=t??n;if(o&&null!==r)try{(null==(e=o.hasPointerCapture)?void 0:e.call(o,r))&&(null==(i=o.releasePointerCapture)||i.call(o,r))}catch{}s.current=null,l.current=null},[]),c=n.useCallback(t=>{var e;null!==s.current&&s.current!==t.pointerId&&(null==(e=r.current)||e.end(),h(s.current));const i=t.currentTarget;s.current=t.pointerId,l.current=i;try{i.setPointerCapture(t.pointerId)}catch{}},[h]);n.useEffect(()=>{const t=globalThis,e=t=>{var e;const i=s.current;null!==i&&t.pointerId===i&&(null==(e=r.current)||e.end(),h(t.pointerId))},i=()=>{var t;null!==s.current&&(null==(t=r.current)||t.end(),h())};return t.addEventListener("pointerup",e,!0),t.addEventListener("pointercancel",e,!0),t.addEventListener("blur",i,!0),()=>{t.removeEventListener("pointerup",e,!0),t.removeEventListener("pointercancel",e,!0),t.removeEventListener("blur",i,!0)}},[h]),n.useEffect(()=>()=>{var t;null!==s.current&&(null==(t=r.current)||t.end(),h())},[h]);const u=n.useCallback(t=>{var e;i&&(t.preventDefault(),t.stopPropagation(),null==(e=r.current)||e.startDrag(t.clientX,t.clientY),c(t))},[i,c]),d=n.useCallback(t=>{var e;t.preventDefault(),t.stopPropagation();const i=s.current;null!==i&&t.pointerId!==i||(null==(e=r.current)||e.move(t.clientX,t.clientY,t.buttons,t.shiftKey),s.current===t.pointerId&&0===t.buttons&&h(t.pointerId))},[h]),p=n.useCallback(t=>{var e;t.preventDefault(),t.stopPropagation();const i=s.current;null!==i&&t.pointerId!==i||(null==(e=r.current)||e.end(),h(t.pointerId))},[h]),m=n.useCallback(t=>{var e;const i=s.current;null!==i&&t.pointerId===i&&(null==(e=r.current)||e.end(),h(t.pointerId))},[h]),x=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=r.current)||n.startResize(t,e.clientX,e.clientY),c(e))},onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}),[i,d,p,m,c]),f=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=r.current)||n.startVertexEdit(t,e.clientX,e.clientY),c(e))},onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}),[i,d,p,m,c]),v=n.useCallback((t=0,e)=>({onPointerDown:n=>{var o;if(!i)return;n.preventDefault(),n.stopPropagation();const a=n.currentTarget.getBoundingClientRect(),s=a.left+a.width/2,l=a.top+a.height/2;null==(o=r.current)||o.startRotation(s,l,t,e),c(n)},onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}),[i,d,p,m,c]);return{dragProps:i?{onPointerDown:u,onPointerMove:d,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:m}:{},createResizeProps:x,createVertexProps:f,createRotationProps:v}}exports.CounterRotate=function({children:o,...r}){const{rect:a,rotation:s}=r,{matrix:l,width:h,height:c}=e.getCounterRotation(a,s),u=n.useRef(null);n.useEffect(()=>{const t=u.current;if(!t)return;const e=t=>{t.stopPropagation()},i=t=>{t.stopPropagation()};return t.addEventListener("pointerdown",e,{capture:!0}),t.addEventListener("touchstart",i,{capture:!0,passive:!0}),()=>{t.removeEventListener("pointerdown",e,{capture:!0}),t.removeEventListener("touchstart",i,{capture:!0})}},[]);const d={style:{position:"absolute",left:a.origin.x,top:a.origin.y,transform:l,transformOrigin:"0 0",width:h,height:c,pointerEvents:"none",zIndex:3},ref:t=>{u.current=t}};return t.jsx(i.Fragment,{children:o({menuWrapperProps:d,matrix:l,rect:{origin:{x:a.origin.x,y:a.origin.y},size:{width:h,height:c}}})})},exports.useDoublePressProps=function(t,{delay:e=300,tolerancePx:i=18}={}){const o=n.useRef({t:0,x:0,y:0}),a=n.useCallback(n=>{if(!t)return;if("mouse"===n.pointerType||!1===n.isPrimary)return;const r=performance.now(),a=n.clientX,s=n.clientY,l=r-o.current.t<=e,h=a-o.current.x,c=s-o.current.y;l&&h*h+c*c<=i*i&&(null==t||t(n)),o.current={t:r,x:a,y:s}},[t,e,i]),s=n.useCallback(e=>{null==t||t(e)},[t]);return t?{[r]:s,onPointerUpCapture:a}:{}},exports.useDragResize=p,exports.useInteractionHandles=function(t){var e,i,o,r,a,s;const{controller:l,resizeUI:h,vertexUI:c,rotationUI:g,includeVertices:m=!1,includeRotation:x=!1,currentRotation:f=0,handleAttrs:v,vertexAttrs:y,rotationAttrs:z}=t,{dragProps:R,createResizeProps:w,createVertexProps:P,createRotationProps:M}=p(l);return{dragProps:R,resize:n.useMemo(()=>function(t,e={}){const{handleSize:i=8,spacing:n=1,offsetMode:o="outside",includeSides:r=!1,zIndex:a=3,rotationAwareCursor:s=!0}=e,l=(t.pageRotation??0)%4,h=t.annotationRotation??0,c=t=>({[t]:d(i,n,o)+"px"});return[["nw",{...c("top"),...c("left")}],["ne",{...c("top"),...c("right")}],["sw",{...c("bottom"),...c("left")}],["se",{...c("bottom"),...c("right")}],...r?[["n",{...c("top"),left:`calc(50% - ${i/2}px)`}],["s",{...c("bottom"),left:`calc(50% - ${i/2}px)`}],["w",{...c("left"),top:`calc(50% - ${i/2}px)`}],["e",{...c("right"),top:`calc(50% - ${i/2}px)`}]]:[]].map(([t,e])=>({handle:t,style:{position:"absolute",width:i+"px",height:i+"px",borderRadius:"50%",zIndex:a,cursor:s?u(t,l,h):"default",pointerEvents:"auto",touchAction:"none",...e},attrs:{"data-epdf-handle":t}}))}(l,h).map(t=>{var e;return{key:null==(e=t.attrs)?void 0:e["data-epdf-handle"],style:t.style,...w(t.handle),...t.attrs??{},...(null==v?void 0:v(t.handle))??{}}}),[l.element.origin.x,l.element.origin.y,l.element.size.width,l.element.size.height,l.scale,l.pageRotation,l.annotationRotation,l.maintainAspectRatio,null==h?void 0:h.handleSize,null==h?void 0:h.spacing,null==h?void 0:h.offsetMode,null==h?void 0:h.includeSides,null==h?void 0:h.zIndex,null==h?void 0:h.rotationAwareCursor,w,v]),vertices:n.useMemo(()=>{if(!m)return[];return function(t,e={},i){const{vertexSize:n=12,zIndex:o=4}=e,r=t.element,a=t.scale??1;return(i??t.vertices??[]).map((t,e)=>({handle:"nw",style:{position:"absolute",left:(t.x-r.origin.x)*a-n/2+"px",top:(t.y-r.origin.y)*a-n/2+"px",width:n+"px",height:n+"px",borderRadius:"50%",cursor:"pointer",zIndex:o,pointerEvents:"auto",touchAction:"none"},attrs:{"data-epdf-vertex":e}}))}(l,c,l.vertices).map((t,e)=>({key:e,style:t.style,...P(e),...t.attrs??{},...(null==y?void 0:y(e))??{}}))},[m,l.element.origin.x,l.element.origin.y,l.element.size.width,l.element.size.height,l.scale,l.vertices,null==c?void 0:c.vertexSize,null==c?void 0:c.zIndex,P,y]),rotation:n.useMemo(()=>{if(!x)return null;const t=function(t,e={},i=0){const{handleSize:n=16,zIndex:o=5,showConnector:r=!0,connectorWidth:a=1}=e,s=t.scale??1,l=t.element,h=t.rotationElement??l,c=t.rotationCenter??{x:l.origin.x+l.size.width/2,y:l.origin.y+l.size.height/2};h.size.width,h.size.height;const u=(c.x-h.origin.x)*s,d=(c.y-h.origin.y)*s,g=i*Math.PI/180,p=e.margin??35,m=l.size.height*s/2+p;return{handleStyle:{position:"absolute",left:u+m*Math.sin(g)-n/2+"px",top:d-m*Math.cos(g)-n/2+"px",width:n+"px",height:n+"px",borderRadius:"50%",cursor:"grab",zIndex:o,pointerEvents:"auto",touchAction:"none"},connectorStyle:r?{position:"absolute",left:u-a/2+"px",top:d-m+"px",width:a+"px",height:m+"px",transformOrigin:"center bottom",transform:`rotate(${i}deg)`,zIndex:o-1,pointerEvents:"none"}:{},radius:m,attrs:{"data-epdf-rotation-handle":!0}}}(l,g,f);return{handle:{style:t.handleStyle,...M(f,t.radius),...t.attrs??{},...(null==z?void 0:z())??{}},connector:{style:t.connectorStyle,"data-epdf-rotation-connector":!0}}},[x,l.element.origin.x,l.element.origin.y,l.element.size.width,l.element.size.height,null==(e=l.rotationCenter)?void 0:e.x,null==(i=l.rotationCenter)?void 0:i.y,null==(o=l.rotationElement)?void 0:o.origin.x,null==(r=l.rotationElement)?void 0:r.origin.y,null==(a=l.rotationElement)?void 0:a.size.width,null==(s=l.rotationElement)?void 0:s.size.height,l.scale,f,null==g?void 0:g.handleSize,null==g?void 0:g.margin,null==g?void 0:g.zIndex,null==g?void 0:g.showConnector,null==g?void 0:g.connectorWidth,M,z])}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|