@embedpdf/utils 2.0.0 → 2.0.2
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 +143 -123
- 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 +143 -123
- package/dist/react/index.js.map +1 -1
- package/dist/shared/plugin-interaction-primitives/drag-resize-controller.d.ts +18 -0
- package/dist/shared-preact/plugin-interaction-primitives/drag-resize-controller.d.ts +18 -0
- package/dist/shared-react/plugin-interaction-primitives/drag-resize-controller.d.ts +18 -0
- package/dist/shared-svelte/plugin-interaction-primitives/drag-resize-controller.d.ts +18 -0
- package/dist/shared-vue/plugin-interaction-primitives/drag-resize-controller.d.ts +18 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +143 -123
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/counter-rotate-container.vue.d.ts +17 -3
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +143 -123
- package/dist/vue/index.js.map +1 -1
- package/package.json +2 -2
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"),s="onDblClick";class r{constructor(t,e){this.config=t,this.onUpdate=e,this.state="idle",this.startPoint=null,this.startElement=null,this.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[],this.currentVertices=[],this.currentVertices=t.vertices||[]}updateConfig(t){this.config={...this.config,...t},this.currentVertices=t.vertices||[]}startDrag(t,e){this.state="dragging",this.startPoint={x:t,y:e},this.startElement={...this.config.element},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.onUpdate({state:"start",transformData:{type:"vertex-edit",changes:{vertices:this.startVertices},metadata:{vertexIndex:t}}}))}move(t,e){if("idle"!==this.state&&this.startPoint)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=this.calculateDelta(t,e),n=this.calculateResizePosition(i,this.activeHandle);this.currentPosition=n,this.onUpdate({state:"move",transformData:{type:"resize",changes:{rect:n},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}}})}}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{const i=this.getCurrentPosition();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}}}):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.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[]}getCurrentPosition(){return this.currentPosition||this.config.element}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,s=Math.cos(n),r=Math.sin(n),a=t.x/i,o=t.y/i;return{x:s*a+r*o,y:-r*a+s*o}}clampPoint(t){var e;const i=null==(e=this.config.constraints)?void 0:e.boundingBox;return i?{x:Math.max(0,Math.min(t.x,i.width)),y:Math.max(0,Math.min(t.y,i.height))}:t}calculateVertexPosition(t,e){if(null===this.activeVertexIndex)return this.startVertices;const i=this.calculateDelta(t,e),n=[...this.startVertices],s=n[this.activeVertexIndex],r={x:s.x+i.x,y:s.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}};return this.applyConstraints(e)}calculateResizePosition(t,e){var i;if(!this.startElement)return this.config.element;let{origin:{x:n,y:s},size:{width:r,height:a}}=this.startElement;switch(e){case"se":r+=t.x,a+=t.y;break;case"sw":n+=t.x,r-=t.x,a+=t.y;break;case"ne":r+=t.x,s+=t.y,a-=t.y;break;case"nw":n+=t.x,r-=t.x,s+=t.y,a-=t.y;break;case"n":s+=t.y,a-=t.y;break;case"s":a+=t.y;break;case"e":r+=t.x;break;case"w":n+=t.x,r-=t.x}if(this.config.maintainAspectRatio&&this.startElement){const t=this.startElement.size.width/this.startElement.size.height;if(["n","s","e","w"].includes(e))if("n"===e||"s"===e){const e=a*t,i=e-r;r=e,n-=i/2}else{const i=r/t,o=i-a;a=i,"w"===e&&(n=this.startElement.origin.x+this.startElement.size.width-r),s-=o/2}else{Math.abs(r-this.startElement.size.width)>Math.abs(a-this.startElement.size.height)?a=r/t:r=a*t,e.includes("w")&&(n=this.startElement.origin.x+this.startElement.size.width-r),e.includes("n")&&(s=this.startElement.origin.y+this.startElement.size.height-a)}}const o=null==(i=this.config.constraints)?void 0:i.boundingBox;if(o)switch(e){case"e":r=Math.min(r,o.width-n);break;case"s":a=Math.min(a,o.height-s);break;case"se":r=Math.min(r,o.width-n),a=Math.min(a,o.height-s);break;case"w":n<0&&(r+=n,n=0);break;case"n":s<0&&(a+=s,s=0);break;case"sw":n<0&&(r+=n,n=0),a=Math.min(a,o.height-s);break;case"nw":n<0&&(r+=n,n=0),s<0&&(a+=s,s=0);break;case"ne":r=Math.min(r,o.width-n),s<0&&(a+=s,s=0)}return this.applyConstraints({origin:{x:n,y:s},size:{width:r,height:a}})}applyConstraints(t){const{constraints:e}=this.config;if(!e)return t;let{origin:{x:i,y:n},size:{width:s,height:r}}=t;return s=Math.max(e.minWidth||1,s),r=Math.max(e.minHeight||1,r),e.maxWidth&&(s=Math.min(e.maxWidth,s)),e.maxHeight&&(r=Math.min(e.maxHeight,r)),e.boundingBox&&(i=Math.max(0,Math.min(i,e.boundingBox.width-s)),n=Math.max(0,Math.min(n,e.boundingBox.height-r))),{origin:{x:i,y:n},size:{width:s,height:r}}}}function a(t,e){return"n"===t||"s"===t?"ns-resize":"e"===t||"w"===t?"ew-resize":e%2==0?{nw:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",se:"nwse-resize"}[t]:{nw:"nesw-resize",ne:"nwse-resize",sw:"nwse-resize",se:"nesw-resize"}[t]}function o(t,e,i){const n=-t/2;return"center"===i?n:"outside"===i?n-e:n+e}function c(t){const{onUpdate:e,enabled:i=!0,...s}=t,a=n.useRef(null),o=n.useRef(e);n.useEffect(()=>{o.current=e},[e]),n.useEffect(()=>{a.current?a.current.updateConfig(s):a.current=new r(s,t=>{var e;return null==(e=o.current)?void 0:e.call(o,t)})},[s.element,s.constraints,s.maintainAspectRatio,s.pageRotation,s.scale,s.vertices]);const c=n.useCallback(t=>{var e;i&&(t.preventDefault(),t.stopPropagation(),null==(e=a.current)||e.startDrag(t.clientX,t.clientY),t.currentTarget.setPointerCapture(t.pointerId))},[i]),l=n.useCallback(t=>{var e;t.preventDefault(),t.stopPropagation(),null==(e=a.current)||e.move(t.clientX,t.clientY)},[]),h=n.useCallback(t=>{var e,i,n;t.preventDefault(),t.stopPropagation(),null==(e=a.current)||e.end(),null==(n=(i=t.currentTarget).releasePointerCapture)||n.call(i,t.pointerId)},[]),u=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=a.current)||n.startResize(t,e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:l,onPointerUp:h,onPointerCancel:h}),[i,l,h]),d=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=a.current)||n.startVertexEdit(t,e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:l,onPointerUp:h,onPointerCancel:h}),[i,l,h]);return{dragProps:i?{onPointerDown:c,onPointerMove:l,onPointerUp:h,onPointerCancel:h}:{},createResizeProps:u,createVertexProps:d}}exports.CounterRotate=function({children:s,...r}){const{rect:a,rotation:o}=r,{matrix:c,width:l,height:h}=e.getCounterRotation(a,o),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:c,transformOrigin:"0 0",width:l,height:h,pointerEvents:"none",zIndex:3},ref:t=>{u.current=t}};return t.jsx(i.Fragment,{children:s({menuWrapperProps:d,matrix:c,rect:{origin:{x:a.origin.x,y:a.origin.y},size:{width:l,height:h}}})})},exports.useDoublePressProps=function(t,{delay:e=300,tolerancePx:i=18}={}){const r=n.useRef({t:0,x:0,y:0}),a=n.useCallback(n=>{if(!t)return;if("mouse"===n.pointerType||!1===n.isPrimary)return;const s=performance.now(),a=n.clientX,o=n.clientY,c=s-r.current.t<=e,l=a-r.current.x,h=o-r.current.y;c&&l*l+h*h<=i*i&&(null==t||t(n)),r.current={t:s,x:a,y:o}},[t,e,i]),o=n.useCallback(e=>{null==t||t(e)},[t]);return t?{[s]:o,onPointerUpCapture:a}:{}},exports.useDragResize=c,exports.useInteractionHandles=function(t){const{controller:e,resizeUI:i,vertexUI:s,includeVertices:r=!1,handleAttrs:l,vertexAttrs:h}=t,{dragProps:u,createResizeProps:d,createVertexProps:g}=c(e);return{dragProps:u,resize:n.useMemo(()=>function(t,e={}){const{handleSize:i=8,spacing:n=1,offsetMode:s="outside",includeSides:r=!1,zIndex:c=3,rotationAwareCursor:l=!0}=e,h=(t.pageRotation??0)%4,u=t=>({[t]:o(i,n,s)+"px"});return[["nw",{...u("top"),...u("left")}],["ne",{...u("top"),...u("right")}],["sw",{...u("bottom"),...u("left")}],["se",{...u("bottom"),...u("right")}],...r?[["n",{...u("top"),left:`calc(50% - ${i/2}px)`}],["s",{...u("bottom"),left:`calc(50% - ${i/2}px)`}],["w",{...u("left"),top:`calc(50% - ${i/2}px)`}],["e",{...u("right"),top:`calc(50% - ${i/2}px)`}]]:[]].map(([t,e])=>({handle:t,style:{position:"absolute",width:i+"px",height:i+"px",borderRadius:"50%",zIndex:c,cursor:l?a(t,h):"default",touchAction:"none",...e},attrs:{"data-epdf-handle":t}}))}(e,i).map(t=>{var e;return{key:null==(e=t.attrs)?void 0:e["data-epdf-handle"],style:t.style,...d(t.handle),...t.attrs??{},...(null==l?void 0:l(t.handle))??{}}}),[e.element.origin.x,e.element.origin.y,e.element.size.width,e.element.size.height,e.scale,e.pageRotation,e.maintainAspectRatio,null==i?void 0:i.handleSize,null==i?void 0:i.spacing,null==i?void 0:i.offsetMode,null==i?void 0:i.includeSides,null==i?void 0:i.zIndex,null==i?void 0:i.rotationAwareCursor,d,l]),vertices:n.useMemo(()=>{if(!r)return[];return function(t,e={},i){const{vertexSize:n=12,zIndex:s=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:s,touchAction:"none"},attrs:{"data-epdf-vertex":e}}))}(e,s,e.vertices).map((t,e)=>({key:e,style:t.style,...g(e),...t.attrs??{},...(null==h?void 0:h(e))??{}}))},[r,e.element.origin.x,e.element.origin.y,e.element.size.width,e.element.size.height,e.scale,e.vertices,null==s?void 0:s.vertexSize,null==s?void 0:s.zIndex,g,h])}};
|
|
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"),s="onDblClick";class r{constructor(t,e){this.config=t,this.onUpdate=e,this.state="idle",this.startPoint=null,this.startElement=null,this.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[],this.currentVertices=[],this.currentVertices=t.vertices||[]}updateConfig(t){this.config={...this.config,...t},this.currentVertices=t.vertices||[]}startDrag(t,e){this.state="dragging",this.startPoint={x:t,y:e},this.startElement={...this.config.element},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.onUpdate({state:"start",transformData:{type:"vertex-edit",changes:{vertices:this.startVertices},metadata:{vertexIndex:t}}}))}move(t,e){if("idle"!==this.state&&this.startPoint)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=this.calculateDelta(t,e),n=this.calculateResizePosition(i,this.activeHandle);this.currentPosition=n,this.onUpdate({state:"move",transformData:{type:"resize",changes:{rect:n},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}}})}}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{const i=this.getCurrentPosition();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}}}):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.activeHandle=null,this.currentPosition=null,this.activeVertexIndex=null,this.startVertices=[]}getCurrentPosition(){return this.currentPosition||this.config.element}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,s=Math.cos(n),r=Math.sin(n),a=t.x/i,o=t.y/i;return{x:s*a+r*o,y:-r*a+s*o}}clampPoint(t){var e;const i=null==(e=this.config.constraints)?void 0:e.boundingBox;return i?{x:Math.max(0,Math.min(t.x,i.width)),y:Math.max(0,Math.min(t.y,i.height))}:t}calculateVertexPosition(t,e){if(null===this.activeVertexIndex)return this.startVertices;const i=this.calculateDelta(t,e),n=[...this.startVertices],s=n[this.activeVertexIndex],r={x:s.x+i.x,y:s.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}};return this.applyConstraints(e)}calculateResizePosition(t,e){if(!this.startElement)return this.config.element;const i=function(t){return{x:t.includes("e")?"left":t.includes("w")?"right":"center",y:t.includes("s")?"top":t.includes("n")?"bottom":"center"}}(e),n=this.startElement.size.width/this.startElement.size.height||1;let s=this.applyResizeDelta(t,i);return this.config.maintainAspectRatio&&(s=this.enforceAspectRatio(s,i,n)),s=this.clampToBounds(s,i,n),this.applyConstraints(s)}applyResizeDelta(t,e){const i=this.startElement;let n=i.origin.x,s=i.origin.y,r=i.size.width,a=i.size.height;return"left"===e.x?r+=t.x:"right"===e.x&&(n+=t.x,r-=t.x),"top"===e.y?a+=t.y:"bottom"===e.y&&(s+=t.y,a-=t.y),{origin:{x:n,y:s},size:{width:r,height:a}}}enforceAspectRatio(t,e,i){const n=this.startElement;let{x:s,y:r}=t.origin,{width:a,height:o}=t.size;if("center"===e.x||"center"===e.y)"center"===e.y?(o=a/i,r=n.origin.y+(n.size.height-o)/2):(a=o*i,s=n.origin.x+(n.size.width-a)/2);else{Math.abs(a-n.size.width)>=Math.abs(o-n.size.height)?o=a/i:a=o*i}return"right"===e.x&&(s=n.origin.x+n.size.width-a),"bottom"===e.y&&(r=n.origin.y+n.size.height-o),{origin:{x:s,y:r},size:{width:a,height:o}}}clampToBounds(t,e,i){var n;const s=null==(n=this.config.constraints)?void 0:n.boundingBox;if(!s)return t;const r=this.startElement;let{x:a,y:o}=t.origin,{width:c,height:h}=t.size;c=Math.max(1,c),h=Math.max(1,h);const l="left"===e.x?r.origin.x:r.origin.x+r.size.width,u="top"===e.y?r.origin.y:r.origin.y+r.size.height,d="left"===e.x?s.width-l:"right"===e.x?l:2*Math.min(r.origin.x,s.width-r.origin.x-r.size.width)+r.size.width,g="top"===e.y?s.height-u:"bottom"===e.y?u:2*Math.min(r.origin.y,s.height-r.origin.y-r.size.height)+r.size.height;if(this.config.maintainAspectRatio){const t=c>d?d/c:1,e=h>g?g/h:1,i=Math.min(t,e);i<1&&(c*=i,h*=i)}else c=Math.min(c,d),h=Math.min(h,g);return a="left"===e.x?l:"right"===e.x?l-c:r.origin.x+(r.size.width-c)/2,o="top"===e.y?u:"bottom"===e.y?u-h:r.origin.y+(r.size.height-h)/2,a=Math.max(0,Math.min(a,s.width-c)),o=Math.max(0,Math.min(o,s.height-h)),{origin:{x:a,y:o},size:{width:c,height:h}}}applyConstraints(t){const{constraints:e}=this.config;if(!e)return t;let{origin:{x:i,y:n},size:{width:s,height:r}}=t;const a=e.minWidth??1,o=e.minHeight??1,c=e.maxWidth,h=e.maxHeight;if(this.config.maintainAspectRatio&&s>0&&r>0){const t=s/r;s<a&&(s=a,r=s/t),r<o&&(r=o,s=r*t),void 0!==c&&s>c&&(s=c,r=s/t),void 0!==h&&r>h&&(r=h,s=r*t)}else s=Math.max(a,s),r=Math.max(o,r),void 0!==c&&(s=Math.min(c,s)),void 0!==h&&(r=Math.min(h,r));return e.boundingBox&&(i=Math.max(0,Math.min(i,e.boundingBox.width-s)),n=Math.max(0,Math.min(n,e.boundingBox.height-r))),{origin:{x:i,y:n},size:{width:s,height:r}}}}function a(t,e){return"n"===t||"s"===t?"ns-resize":"e"===t||"w"===t?"ew-resize":e%2==0?{nw:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",se:"nwse-resize"}[t]:{nw:"nesw-resize",ne:"nwse-resize",sw:"nwse-resize",se:"nesw-resize"}[t]}function o(t,e,i){const n=-t/2;return"center"===i?n:"outside"===i?n-e:n+e}function c(t){const{onUpdate:e,enabled:i=!0,...s}=t,a=n.useRef(null),o=n.useRef(e);n.useEffect(()=>{o.current=e},[e]),n.useEffect(()=>{a.current?a.current.updateConfig(s):a.current=new r(s,t=>{var e;return null==(e=o.current)?void 0:e.call(o,t)})},[s.element,s.constraints,s.maintainAspectRatio,s.pageRotation,s.scale,s.vertices]);const c=n.useCallback(t=>{var e;i&&(t.preventDefault(),t.stopPropagation(),null==(e=a.current)||e.startDrag(t.clientX,t.clientY),t.currentTarget.setPointerCapture(t.pointerId))},[i]),h=n.useCallback(t=>{var e;t.preventDefault(),t.stopPropagation(),null==(e=a.current)||e.move(t.clientX,t.clientY)},[]),l=n.useCallback(t=>{var e,i,n;t.preventDefault(),t.stopPropagation(),null==(e=a.current)||e.end(),null==(n=(i=t.currentTarget).releasePointerCapture)||n.call(i,t.pointerId)},[]),u=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=a.current)||n.startResize(t,e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:h,onPointerUp:l,onPointerCancel:l}),[i,h,l]),d=n.useCallback(t=>({onPointerDown:e=>{var n;i&&(e.preventDefault(),e.stopPropagation(),null==(n=a.current)||n.startVertexEdit(t,e.clientX,e.clientY),e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:h,onPointerUp:l,onPointerCancel:l}),[i,h,l]);return{dragProps:i?{onPointerDown:c,onPointerMove:h,onPointerUp:l,onPointerCancel:l}:{},createResizeProps:u,createVertexProps:d}}exports.CounterRotate=function({children:s,...r}){const{rect:a,rotation:o}=r,{matrix:c,width:h,height:l}=e.getCounterRotation(a,o),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:c,transformOrigin:"0 0",width:h,height:l,pointerEvents:"none",zIndex:3},ref:t=>{u.current=t}};return t.jsx(i.Fragment,{children:s({menuWrapperProps:d,matrix:c,rect:{origin:{x:a.origin.x,y:a.origin.y},size:{width:h,height:l}}})})},exports.useDoublePressProps=function(t,{delay:e=300,tolerancePx:i=18}={}){const r=n.useRef({t:0,x:0,y:0}),a=n.useCallback(n=>{if(!t)return;if("mouse"===n.pointerType||!1===n.isPrimary)return;const s=performance.now(),a=n.clientX,o=n.clientY,c=s-r.current.t<=e,h=a-r.current.x,l=o-r.current.y;c&&h*h+l*l<=i*i&&(null==t||t(n)),r.current={t:s,x:a,y:o}},[t,e,i]),o=n.useCallback(e=>{null==t||t(e)},[t]);return t?{[s]:o,onPointerUpCapture:a}:{}},exports.useDragResize=c,exports.useInteractionHandles=function(t){const{controller:e,resizeUI:i,vertexUI:s,includeVertices:r=!1,handleAttrs:h,vertexAttrs:l}=t,{dragProps:u,createResizeProps:d,createVertexProps:g}=c(e);return{dragProps:u,resize:n.useMemo(()=>function(t,e={}){const{handleSize:i=8,spacing:n=1,offsetMode:s="outside",includeSides:r=!1,zIndex:c=3,rotationAwareCursor:h=!0}=e,l=(t.pageRotation??0)%4,u=t=>({[t]:o(i,n,s)+"px"});return[["nw",{...u("top"),...u("left")}],["ne",{...u("top"),...u("right")}],["sw",{...u("bottom"),...u("left")}],["se",{...u("bottom"),...u("right")}],...r?[["n",{...u("top"),left:`calc(50% - ${i/2}px)`}],["s",{...u("bottom"),left:`calc(50% - ${i/2}px)`}],["w",{...u("left"),top:`calc(50% - ${i/2}px)`}],["e",{...u("right"),top:`calc(50% - ${i/2}px)`}]]:[]].map(([t,e])=>({handle:t,style:{position:"absolute",width:i+"px",height:i+"px",borderRadius:"50%",zIndex:c,cursor:h?a(t,l):"default",touchAction:"none",...e},attrs:{"data-epdf-handle":t}}))}(e,i).map(t=>{var e;return{key:null==(e=t.attrs)?void 0:e["data-epdf-handle"],style:t.style,...d(t.handle),...t.attrs??{},...(null==h?void 0:h(t.handle))??{}}}),[e.element.origin.x,e.element.origin.y,e.element.size.width,e.element.size.height,e.scale,e.pageRotation,e.maintainAspectRatio,null==i?void 0:i.handleSize,null==i?void 0:i.spacing,null==i?void 0:i.offsetMode,null==i?void 0:i.includeSides,null==i?void 0:i.zIndex,null==i?void 0:i.rotationAwareCursor,d,h]),vertices:n.useMemo(()=>{if(!r)return[];return function(t,e={},i){const{vertexSize:n=12,zIndex:s=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:s,touchAction:"none"},attrs:{"data-epdf-vertex":e}}))}(e,s,e.vertices).map((t,e)=>({key:e,style:t.style,...g(e),...t.attrs??{},...(null==l?void 0:l(e))??{}}))},[r,e.element.origin.x,e.element.origin.y,e.element.size.width,e.element.size.height,e.scale,e.vertices,null==s?void 0:s.vertexSize,null==s?void 0:s.zIndex,g,l])}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/preact/adapter.ts","../../src/shared/plugin-interaction-primitives/drag-resize-controller.ts","../../src/shared/plugin-interaction-primitives/utils.ts","../../src/shared/hooks/use-drag-resize.ts","../../src/shared/components/counter-rotate-container.tsx","../../src/shared/hooks/use-double-press-props.ts","../../src/shared/hooks/use-interaction-handles.ts"],"sourcesContent":["import { createContext, JSX, Fragment, FunctionComponent } from 'preact';\nexport { useEffect, useRef, useState, useCallback, useMemo, useContext } from 'preact/hooks';\nexport type { ComponentChildren as ReactNode, JSX } from 'preact';\n\nexport { createContext, Fragment };\n\nexport type CSSProperties = import('preact').JSX.CSSProperties;\nexport type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<\n T extends EventTarget ? T : never\n>;\n\nexport type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarget ? T : never>;\nexport type PointerEvent<T = Element> = JSX.TargetedPointerEvent<T extends EventTarget ? T : never>;\nexport type ChangeEvent<T = Element> = JSX.TargetedInputEvent<T extends EventTarget ? T : never>;\nexport type TouchEvent<T = Element> = JSX.TargetedTouchEvent<T extends EventTarget ? T : never>;\nexport type ComponentType = FunctionComponent;\n\nexport const dblClickProp = 'onDblClick' as const;\n","import { Position, Rect } from '@embedpdf/models';\n\nexport interface DragResizeConfig {\n element: Rect;\n vertices?: Position[];\n constraints?: {\n minWidth?: number;\n minHeight?: number;\n maxWidth?: number;\n maxHeight?: number;\n boundingBox?: { width: number; height: number }; // page bounds\n };\n maintainAspectRatio?: boolean;\n pageRotation?: number;\n scale?: number;\n}\n\nexport type InteractionState = 'idle' | 'dragging' | 'resizing' | 'vertex-editing';\nexport type ResizeHandle = 'nw' | 'ne' | 'sw' | 'se' | 'n' | 'e' | 's' | 'w';\n\nexport interface TransformData {\n type: 'move' | 'resize' | 'vertex-edit';\n changes: {\n rect?: Rect;\n vertices?: Position[];\n };\n metadata?: {\n handle?: ResizeHandle;\n vertexIndex?: number;\n maintainAspectRatio?: boolean;\n };\n}\n\nexport interface InteractionEvent {\n state: 'start' | 'move' | 'end';\n transformData?: TransformData;\n}\n\n/**\n * Pure geometric controller that manages drag/resize/vertex-edit logic.\n */\nexport class DragResizeController {\n private state: InteractionState = 'idle';\n private startPoint: Position | null = null;\n private startElement: Rect | null = null;\n private activeHandle: ResizeHandle | null = null;\n private currentPosition: Rect | null = null;\n\n // Vertex editing state - pure geometric\n private activeVertexIndex: number | null = null;\n private startVertices: Position[] = [];\n private currentVertices: Position[] = [];\n\n constructor(\n private config: DragResizeConfig,\n private onUpdate: (event: InteractionEvent) => void,\n ) {\n this.currentVertices = config.vertices || [];\n }\n\n updateConfig(config: Partial<DragResizeConfig>) {\n this.config = { ...this.config, ...config };\n this.currentVertices = config.vertices || [];\n }\n\n startDrag(clientX: number, clientY: number) {\n this.state = 'dragging';\n this.startPoint = { x: clientX, y: clientY };\n this.startElement = { ...this.config.element };\n this.currentPosition = { ...this.config.element };\n\n this.onUpdate({\n state: 'start',\n transformData: {\n type: 'move',\n changes: {\n rect: this.startElement,\n },\n },\n });\n }\n\n startResize(handle: ResizeHandle, clientX: number, clientY: number) {\n this.state = 'resizing';\n this.activeHandle = handle;\n this.startPoint = { x: clientX, y: clientY };\n this.startElement = { ...this.config.element };\n this.currentPosition = { ...this.config.element };\n\n this.onUpdate({\n state: 'start',\n transformData: {\n type: 'resize',\n changes: {\n rect: this.startElement,\n },\n metadata: {\n handle: this.activeHandle,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n }\n\n startVertexEdit(vertexIndex: number, clientX: number, clientY: number) {\n // Refresh vertices from latest config before validating index\n this.currentVertices = [...(this.config.vertices ?? this.currentVertices)];\n if (vertexIndex < 0 || vertexIndex >= this.currentVertices.length) return;\n\n this.state = 'vertex-editing';\n this.activeVertexIndex = vertexIndex;\n this.startPoint = { x: clientX, y: clientY };\n this.startVertices = [...this.currentVertices];\n\n this.onUpdate({\n state: 'start',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices: this.startVertices,\n },\n metadata: {\n vertexIndex,\n },\n },\n });\n }\n\n move(clientX: number, clientY: number) {\n if (this.state === 'idle' || !this.startPoint) return;\n\n if (this.state === 'dragging' && this.startElement) {\n const delta = this.calculateDelta(clientX, clientY);\n const position = this.calculateDragPosition(delta);\n this.currentPosition = position;\n\n this.onUpdate({\n state: 'move',\n transformData: {\n type: 'move',\n changes: {\n rect: position,\n },\n },\n });\n } else if (this.state === 'resizing' && this.activeHandle && this.startElement) {\n const delta = this.calculateDelta(clientX, clientY);\n const position = this.calculateResizePosition(delta, this.activeHandle);\n this.currentPosition = position;\n\n this.onUpdate({\n state: 'move',\n transformData: {\n type: 'resize',\n changes: {\n rect: position,\n },\n metadata: {\n handle: this.activeHandle,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n } else if (this.state === 'vertex-editing' && this.activeVertexIndex !== null) {\n const vertices = this.calculateVertexPosition(clientX, clientY);\n this.currentVertices = vertices;\n\n this.onUpdate({\n state: 'move',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices,\n },\n metadata: {\n vertexIndex: this.activeVertexIndex,\n },\n },\n });\n }\n }\n\n end() {\n if (this.state === 'idle') return;\n\n const wasState = this.state;\n const handle = this.activeHandle;\n const vertexIndex = this.activeVertexIndex;\n\n if (wasState === 'vertex-editing') {\n this.onUpdate({\n state: 'end',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices: this.currentVertices,\n },\n metadata: {\n vertexIndex: vertexIndex || undefined,\n },\n },\n });\n } else {\n const finalPosition = this.getCurrentPosition();\n this.onUpdate({\n state: 'end',\n transformData: {\n type: wasState === 'dragging' ? 'move' : 'resize',\n changes: {\n rect: finalPosition,\n },\n metadata:\n wasState === 'dragging'\n ? undefined\n : {\n handle: handle || undefined,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n }\n\n this.reset();\n }\n\n cancel() {\n if (this.state === 'idle') return;\n\n if (this.state === 'vertex-editing') {\n this.onUpdate({\n state: 'end',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices: this.startVertices,\n },\n metadata: {\n vertexIndex: this.activeVertexIndex || undefined,\n },\n },\n });\n } else if (this.startElement) {\n this.onUpdate({\n state: 'end',\n transformData: {\n type: this.state === 'dragging' ? 'move' : 'resize',\n changes: {\n rect: this.startElement,\n },\n metadata:\n this.state === 'dragging'\n ? undefined\n : {\n handle: this.activeHandle || undefined,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n }\n\n this.reset();\n }\n\n private reset() {\n this.state = 'idle';\n this.startPoint = null;\n this.startElement = null;\n this.activeHandle = null;\n this.currentPosition = null;\n this.activeVertexIndex = null;\n this.startVertices = [];\n }\n\n private getCurrentPosition() {\n return this.currentPosition || this.config.element;\n }\n\n private calculateDelta(clientX: number, clientY: number): Position {\n if (!this.startPoint) return { x: 0, y: 0 };\n\n const rawDelta: Position = {\n x: clientX - this.startPoint.x,\n y: clientY - this.startPoint.y,\n };\n\n return this.transformDelta(rawDelta);\n }\n\n private transformDelta(delta: Position): Position {\n const { pageRotation = 0, scale = 1 } = this.config;\n\n const rad = (pageRotation * Math.PI) / 2;\n const cos = Math.cos(rad);\n const sin = Math.sin(rad);\n\n const scaledX = delta.x / scale;\n const scaledY = delta.y / scale;\n\n return {\n x: cos * scaledX + sin * scaledY,\n y: -sin * scaledX + cos * scaledY,\n };\n }\n\n private clampPoint(p: Position): Position {\n const bbox = this.config.constraints?.boundingBox;\n if (!bbox) return p;\n return {\n x: Math.max(0, Math.min(p.x, bbox.width)),\n y: Math.max(0, Math.min(p.y, bbox.height)),\n };\n }\n\n private calculateVertexPosition(clientX: number, clientY: number): Position[] {\n if (this.activeVertexIndex === null) return this.startVertices;\n\n const delta = this.calculateDelta(clientX, clientY);\n const newVertices = [...this.startVertices];\n const currentVertex = newVertices[this.activeVertexIndex];\n\n const moved = {\n x: currentVertex.x + delta.x,\n y: currentVertex.y + delta.y,\n };\n newVertices[this.activeVertexIndex] = this.clampPoint(moved);\n\n return newVertices;\n }\n\n private calculateDragPosition(delta: Position): Rect {\n if (!this.startElement) return this.config.element;\n\n const position: Rect = {\n origin: {\n x: this.startElement.origin.x + delta.x,\n y: this.startElement.origin.y + delta.y,\n },\n size: {\n width: this.startElement.size.width,\n height: this.startElement.size.height,\n },\n };\n\n return this.applyConstraints(position);\n }\n\n private calculateResizePosition(delta: Position, handle: ResizeHandle): Rect {\n if (!this.startElement) return this.config.element;\n\n let {\n origin: { x, y },\n size: { width, height },\n } = this.startElement;\n\n switch (handle) {\n case 'se':\n width += delta.x;\n height += delta.y;\n break;\n case 'sw':\n x += delta.x;\n width -= delta.x;\n height += delta.y;\n break;\n case 'ne':\n width += delta.x;\n y += delta.y;\n height -= delta.y;\n break;\n case 'nw':\n x += delta.x;\n width -= delta.x;\n y += delta.y;\n height -= delta.y;\n break;\n case 'n':\n y += delta.y;\n height -= delta.y;\n break;\n case 's':\n height += delta.y;\n break;\n case 'e':\n width += delta.x;\n break;\n case 'w':\n x += delta.x;\n width -= delta.x;\n break;\n }\n\n // Maintain aspect ratio if needed\n if (this.config.maintainAspectRatio && this.startElement) {\n const aspectRatio = this.startElement.size.width / this.startElement.size.height;\n\n if (['n', 's', 'e', 'w'].includes(handle)) {\n if (handle === 'n' || handle === 's') {\n const newWidth = height * aspectRatio;\n const widthDiff = newWidth - width;\n width = newWidth;\n x -= widthDiff / 2;\n } else {\n const newHeight = width / aspectRatio;\n const heightDiff = newHeight - height;\n height = newHeight;\n if (handle === 'w') {\n x = this.startElement.origin.x + this.startElement.size.width - width;\n }\n y -= heightDiff / 2;\n }\n } else {\n const widthChange = Math.abs(width - this.startElement.size.width);\n const heightChange = Math.abs(height - this.startElement.size.height);\n if (widthChange > heightChange) {\n height = width / aspectRatio;\n } else {\n width = height * aspectRatio;\n }\n if (handle.includes('w')) {\n x = this.startElement.origin.x + this.startElement.size.width - width;\n }\n if (handle.includes('n')) {\n y = this.startElement.origin.y + this.startElement.size.height - height;\n }\n }\n }\n\n // Handle-aware bounding box clamping to avoid shifting opposite edge\n const bbox = this.config.constraints?.boundingBox;\n if (bbox) {\n switch (handle) {\n case 'e':\n width = Math.min(width, bbox.width - x);\n break;\n case 's':\n height = Math.min(height, bbox.height - y);\n break;\n case 'se':\n width = Math.min(width, bbox.width - x);\n height = Math.min(height, bbox.height - y);\n break;\n case 'w':\n if (x < 0) {\n width += x;\n x = 0;\n }\n break;\n case 'n':\n if (y < 0) {\n height += y;\n y = 0;\n }\n break;\n case 'sw':\n if (x < 0) {\n width += x;\n x = 0;\n }\n height = Math.min(height, bbox.height - y);\n break;\n case 'nw':\n if (x < 0) {\n width += x;\n x = 0;\n }\n if (y < 0) {\n height += y;\n y = 0;\n }\n break;\n case 'ne':\n width = Math.min(width, bbox.width - x);\n if (y < 0) {\n height += y;\n y = 0;\n }\n break;\n }\n }\n\n return this.applyConstraints({ origin: { x, y }, size: { width, height } });\n }\n\n private applyConstraints(position: Rect): Rect {\n const { constraints } = this.config;\n if (!constraints) return position;\n\n let {\n origin: { x, y },\n size: { width, height },\n } = position;\n\n // Apply size constraints\n width = Math.max(constraints.minWidth || 1, width);\n height = Math.max(constraints.minHeight || 1, height);\n\n if (constraints.maxWidth) width = Math.min(constraints.maxWidth, width);\n if (constraints.maxHeight) height = Math.min(constraints.maxHeight, height);\n\n // Apply bounding box constraints\n if (constraints.boundingBox) {\n x = Math.max(0, Math.min(x, constraints.boundingBox.width - width));\n y = Math.max(0, Math.min(y, constraints.boundingBox.height - height));\n }\n\n return { origin: { x, y }, size: { width, height } };\n }\n}\n","import type { Position, Rect } from '@embedpdf/models';\nimport type { ResizeHandle, DragResizeConfig } from './drag-resize-controller';\n\nexport type QuarterTurns = 0 | 1 | 2 | 3;\n\nexport interface ResizeUI {\n handleSize?: number; // px (default 8)\n spacing?: number; // px distance from the box edge (default 1)\n offsetMode?: 'outside' | 'inside' | 'center'; // default 'outside'\n includeSides?: boolean; // default false\n zIndex?: number; // default 3\n rotationAwareCursor?: boolean; // default true\n}\n\nexport interface VertexUI {\n vertexSize?: number; // px (default 12)\n zIndex?: number; // default 4\n}\n\nexport interface HandleDescriptor {\n handle: ResizeHandle;\n style: Record<string, number | string>;\n attrs?: Record<string, any>;\n}\n\nfunction diagonalCursor(handle: ResizeHandle, rot: QuarterTurns): string {\n // Standard cursors; diagonals flip on odd quarter-turns\n const diag0: Record<'nw' | 'ne' | 'sw' | 'se', string> = {\n nw: 'nwse-resize',\n ne: 'nesw-resize',\n sw: 'nesw-resize',\n se: 'nwse-resize',\n };\n if (handle === 'n' || handle === 's') return 'ns-resize';\n if (handle === 'e' || handle === 'w') return 'ew-resize';\n if (rot % 2 === 0) return diag0[handle as 'nw' | 'ne' | 'sw' | 'se'];\n return { nw: 'nesw-resize', ne: 'nwse-resize', sw: 'nwse-resize', se: 'nesw-resize' }[\n handle as 'nw' | 'ne' | 'sw' | 'se'\n ]!;\n}\n\nfunction edgeOffset(k: number, spacing: number, mode: 'outside' | 'inside' | 'center') {\n // Base puts the handle centered on the edge\n const base = -k / 2;\n if (mode === 'center') return base;\n // outside moves further out (more negative), inside moves in (less negative)\n return mode === 'outside' ? base - spacing : base + spacing;\n}\n\nexport function describeResizeFromConfig(\n cfg: DragResizeConfig,\n ui: ResizeUI = {},\n): HandleDescriptor[] {\n const {\n handleSize = 8,\n spacing = 1,\n offsetMode = 'outside',\n includeSides = false,\n zIndex = 3,\n rotationAwareCursor = true,\n } = ui;\n\n const rotation = ((cfg.pageRotation ?? 0) % 4) as QuarterTurns;\n\n const off = (edge: 'top' | 'right' | 'bottom' | 'left') => ({\n [edge]: edgeOffset(handleSize, spacing, offsetMode) + 'px',\n });\n\n const corners: Array<[ResizeHandle, Record<string, number | string>]> = [\n ['nw', { ...off('top'), ...off('left') }],\n ['ne', { ...off('top'), ...off('right') }],\n ['sw', { ...off('bottom'), ...off('left') }],\n ['se', { ...off('bottom'), ...off('right') }],\n ];\n const sides: Array<[ResizeHandle, Record<string, number | string>]> = includeSides\n ? [\n ['n', { ...off('top'), left: `calc(50% - ${handleSize / 2}px)` }],\n ['s', { ...off('bottom'), left: `calc(50% - ${handleSize / 2}px)` }],\n ['w', { ...off('left'), top: `calc(50% - ${handleSize / 2}px)` }],\n ['e', { ...off('right'), top: `calc(50% - ${handleSize / 2}px)` }],\n ]\n : [];\n\n const all = [...corners, ...sides];\n\n return all.map(([handle, pos]) => ({\n handle,\n style: {\n position: 'absolute',\n width: handleSize + 'px',\n height: handleSize + 'px',\n borderRadius: '50%',\n zIndex,\n cursor: rotationAwareCursor ? diagonalCursor(handle, rotation) : 'default',\n touchAction: 'none',\n ...(pos as any),\n },\n attrs: { 'data-epdf-handle': handle },\n }));\n}\n\nexport function describeVerticesFromConfig(\n cfg: DragResizeConfig,\n ui: VertexUI = {},\n liveVertices?: Position[],\n): HandleDescriptor[] {\n const { vertexSize = 12, zIndex = 4 } = ui;\n const rect: Rect = cfg.element;\n const scale = cfg.scale ?? 1;\n const verts = liveVertices ?? cfg.vertices ?? [];\n\n return verts.map((v, i) => {\n const left = (v.x - rect.origin.x) * scale - vertexSize / 2;\n const top = (v.y - rect.origin.y) * scale - vertexSize / 2;\n return {\n handle: 'nw', // not used; kept for type\n style: {\n position: 'absolute',\n left: left + 'px',\n top: top + 'px',\n width: vertexSize + 'px',\n height: vertexSize + 'px',\n borderRadius: '50%',\n cursor: 'pointer',\n zIndex,\n touchAction: 'none',\n },\n attrs: { 'data-epdf-vertex': i },\n };\n });\n}\n","import { useRef, useCallback, useEffect, PointerEvent } from '@framework';\nimport {\n DragResizeController,\n DragResizeConfig,\n InteractionEvent,\n ResizeHandle,\n} from '../plugin-interaction-primitives';\n\nexport interface UseDragResizeOptions extends DragResizeConfig {\n onUpdate?: (event: InteractionEvent) => void;\n enabled?: boolean;\n}\n\nexport interface ResizeHandleEventProps {\n onPointerDown: (e: PointerEvent) => void;\n onPointerMove: (e: PointerEvent) => void;\n onPointerUp: (e: PointerEvent) => void;\n onPointerCancel: (e: PointerEvent) => void;\n}\n\nexport function useDragResize(options: UseDragResizeOptions) {\n const { onUpdate, enabled = true, ...config } = options;\n const controllerRef = useRef<DragResizeController | null>(null);\n const onUpdateRef = useRef<typeof onUpdate>(onUpdate);\n\n useEffect(() => {\n onUpdateRef.current = onUpdate;\n }, [onUpdate]);\n\n // Initialize or update controller\n useEffect(() => {\n if (!controllerRef.current) {\n controllerRef.current = new DragResizeController(config, (event) =>\n onUpdateRef.current?.(event),\n );\n } else {\n controllerRef.current.updateConfig(config);\n }\n }, [\n config.element,\n config.constraints,\n config.maintainAspectRatio,\n config.pageRotation,\n config.scale,\n config.vertices,\n ]);\n\n const handleDragStart = useCallback(\n (e: PointerEvent) => {\n if (!enabled) return;\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.startDrag(e.clientX, e.clientY);\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n },\n [enabled],\n );\n\n const handleMove = useCallback((e: PointerEvent) => {\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.move(e.clientX, e.clientY);\n }, []);\n\n const handleEnd = useCallback((e: PointerEvent) => {\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.end();\n (e.currentTarget as HTMLElement).releasePointerCapture?.(e.pointerId);\n }, []);\n\n const createResizeHandler = useCallback(\n (handle: ResizeHandle): ResizeHandleEventProps => ({\n onPointerDown: (e: PointerEvent) => {\n if (!enabled) return;\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.startResize(handle, e.clientX, e.clientY);\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n },\n onPointerMove: handleMove,\n onPointerUp: handleEnd,\n onPointerCancel: handleEnd,\n }),\n [enabled, handleMove, handleEnd],\n );\n\n const createVertexHandler = useCallback(\n (vertexIndex: number): ResizeHandleEventProps => ({\n onPointerDown: (e: PointerEvent) => {\n if (!enabled) return;\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.startVertexEdit(vertexIndex, e.clientX, e.clientY);\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n },\n onPointerMove: handleMove,\n onPointerUp: handleEnd,\n onPointerCancel: handleEnd,\n }),\n [enabled, handleMove, handleEnd],\n );\n\n return {\n dragProps: enabled\n ? {\n onPointerDown: handleDragStart,\n onPointerMove: handleMove,\n onPointerUp: handleEnd,\n onPointerCancel: handleEnd,\n }\n : {},\n createResizeProps: createResizeHandler,\n createVertexProps: createVertexHandler,\n };\n}\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { getCounterRotation } from '@embedpdf/utils';\nimport { ReactNode, CSSProperties, Fragment, useRef, useEffect } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n ref: (el: HTMLDivElement | null) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n const elementRef = useRef<HTMLDivElement | null>(null);\n\n // Use native event listeners with capture phase to prevent event propagation\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n const handlePointerDown = (e: Event) => {\n // Stop propagation to prevent underlying layers from receiving the event\n e.stopPropagation();\n // DO NOT use e.preventDefault() here - it breaks click events on mobile/tablet!\n // preventDefault() stops the browser from generating click events from touch,\n // which makes buttons inside this container non-functional on touch devices.\n };\n\n const handleTouchStart = (e: Event) => {\n // Stop propagation to prevent underlying layers from receiving the event\n e.stopPropagation();\n // DO NOT use e.preventDefault() here - it breaks click events on mobile/tablet!\n // preventDefault() stops the browser from generating click events from touch,\n // which makes buttons inside this container non-functional on touch devices.\n };\n\n // Use capture phase to intercept before synthetic events\n element.addEventListener('pointerdown', handlePointerDown, { capture: true });\n element.addEventListener('touchstart', handleTouchStart, { capture: true });\n\n return () => {\n element.removeEventListener('pointerdown', handlePointerDown, { capture: true });\n element.removeEventListener('touchstart', handleTouchStart, { capture: true });\n };\n }, []);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps: MenuWrapperProps = {\n style: menuWrapperStyle,\n ref: (el: HTMLDivElement | null) => {\n elementRef.current = el;\n },\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\n })}\n </Fragment>\n );\n}\n","import { useRef, useCallback, dblClickProp } from '@framework';\nimport type { PointerEvent } from '@framework';\n\ntype DoublePressOptions = {\n delay?: number; // ms between taps\n tolerancePx?: number; // spatial tolerance\n};\n\ntype DoubleHandler<T extends Element> = ((e: PointerEvent<T> | MouseEvent) => void) | undefined;\n\ntype DoubleProps<K extends string> = Partial<Record<K, (e: any) => void>> & {\n onPointerUp?: (e: any) => void;\n};\n\nexport function useDoublePressProps<\n T extends Element = Element,\n K extends string = typeof dblClickProp,\n>(\n onDouble?: DoubleHandler<T>,\n { delay = 300, tolerancePx = 18 }: DoublePressOptions = {},\n): DoubleProps<K> {\n const last = useRef({ t: 0, x: 0, y: 0 });\n\n const handlePointerUp = useCallback(\n (e: any) => {\n if (!onDouble) return;\n\n // Ignore mouse (it will use native dblclick),\n // and ignore non-primary pointers (multi-touch, etc.)\n if (e.pointerType === 'mouse' || e.isPrimary === false) return;\n\n const now = performance.now();\n const x = e.clientX as number;\n const y = e.clientY as number;\n\n const withinTime = now - last.current.t <= delay;\n const dx = x - last.current.x;\n const dy = y - last.current.y;\n const withinDist = dx * dx + dy * dy <= tolerancePx * tolerancePx;\n\n if (withinTime && withinDist) onDouble?.(e as PointerEvent<T>);\n\n last.current = { t: now, x, y };\n },\n [onDouble, delay, tolerancePx],\n );\n\n const handleDouble = useCallback(\n (e: any) => {\n onDouble?.(e);\n },\n [onDouble],\n );\n\n return onDouble\n ? ({\n // Computed property uses the framework’s name ('onDoubleClick' or 'onDblClick')\n [dblClickProp]: handleDouble,\n onPointerUpCapture: handlePointerUp,\n } as DoubleProps<K>)\n : {};\n}\n","import { useMemo, PointerEvent } from '@framework';\nimport type { CSSProperties } from '@framework';\nimport { useDragResize, UseDragResizeOptions } from './use-drag-resize';\nimport {\n describeResizeFromConfig,\n describeVerticesFromConfig,\n type ResizeUI,\n type VertexUI,\n} from '../plugin-interaction-primitives/utils';\n\nexport type HandleElementProps = {\n key: string | number;\n style: CSSProperties;\n onPointerDown: (e: PointerEvent) => void;\n onPointerMove: (e: PointerEvent) => void;\n onPointerUp: (e: PointerEvent) => void;\n onPointerCancel: (e: PointerEvent) => void;\n} & Record<string, any>;\n\nexport function useInteractionHandles(opts: {\n controller: UseDragResizeOptions; // SINGLE config (rect/scale/rotation/vertices/…)\n resizeUI?: ResizeUI; // purely visual knobs\n vertexUI?: VertexUI; // purely visual knobs\n includeVertices?: boolean; // default false\n handleAttrs?: (\n h: 'nw' | 'ne' | 'sw' | 'se' | 'n' | 'e' | 's' | 'w',\n ) => Record<string, any> | void;\n vertexAttrs?: (i: number) => Record<string, any> | void;\n}) {\n const {\n controller,\n resizeUI,\n vertexUI,\n includeVertices = false,\n handleAttrs,\n vertexAttrs,\n } = opts;\n\n const { dragProps, createResizeProps, createVertexProps } = useDragResize(controller);\n\n // Resize handles: only uses data from the SAME controller config.\n const resize: HandleElementProps[] = useMemo(() => {\n const desc = describeResizeFromConfig(controller, resizeUI);\n return desc.map((d) => ({\n key: d.attrs?.['data-epdf-handle'] as string,\n style: d.style as CSSProperties,\n ...createResizeProps(d.handle),\n ...(d.attrs ?? {}),\n ...(handleAttrs?.(d.handle) ?? {}),\n }));\n // deps: controller geometry knobs + UI knobs + handler factory\n }, [\n controller.element.origin.x,\n controller.element.origin.y,\n controller.element.size.width,\n controller.element.size.height,\n controller.scale,\n controller.pageRotation,\n controller.maintainAspectRatio,\n resizeUI?.handleSize,\n resizeUI?.spacing,\n resizeUI?.offsetMode,\n resizeUI?.includeSides,\n resizeUI?.zIndex,\n resizeUI?.rotationAwareCursor,\n createResizeProps,\n handleAttrs,\n ]);\n\n // Vertex handles: same source; prefer live vertices if parent rerenders with updated cfg.vertices\n const vertices: HandleElementProps[] = useMemo(() => {\n if (!includeVertices) return [];\n const desc = describeVerticesFromConfig(controller, vertexUI, controller.vertices);\n return desc.map((d, i) => ({\n key: i,\n style: d.style as CSSProperties,\n ...createVertexProps(i),\n ...(d.attrs ?? {}),\n ...(vertexAttrs?.(i) ?? {}),\n }));\n }, [\n includeVertices,\n controller.element.origin.x,\n controller.element.origin.y,\n controller.element.size.width,\n controller.element.size.height,\n controller.scale,\n controller.vertices, // identity/content drives recalculation\n vertexUI?.vertexSize,\n vertexUI?.zIndex,\n createVertexProps,\n vertexAttrs,\n ]);\n\n return { dragProps, resize, vertices };\n}\n"],"names":["dblClickProp","DragResizeController","constructor","config","onUpdate","this","state","startPoint","startElement","activeHandle","currentPosition","activeVertexIndex","startVertices","currentVertices","vertices","updateConfig","startDrag","clientX","clientY","x","y","element","transformData","type","changes","rect","startResize","handle","metadata","maintainAspectRatio","startVertexEdit","vertexIndex","length","move","delta","calculateDelta","position","calculateDragPosition","calculateResizePosition","calculateVertexPosition","end","wasState","finalPosition","getCurrentPosition","reset","cancel","rawDelta","transformDelta","pageRotation","scale","rad","Math","PI","cos","sin","scaledX","scaledY","clampPoint","p","bbox","_a","constraints","boundingBox","max","min","width","height","newVertices","currentVertex","moved","origin","size","applyConstraints","aspectRatio","includes","newWidth","widthDiff","newHeight","heightDiff","abs","minWidth","minHeight","maxWidth","maxHeight","diagonalCursor","rot","nw","ne","sw","se","edgeOffset","k","spacing","mode","base","useDragResize","options","enabled","controllerRef","useRef","onUpdateRef","useEffect","current","event","call","handleDragStart","useCallback","e","preventDefault","stopPropagation","currentTarget","setPointerCapture","pointerId","handleMove","handleEnd","_c","_b","releasePointerCapture","createResizeHandler","onPointerDown","onPointerMove","onPointerUp","onPointerCancel","createVertexHandler","dragProps","createResizeProps","createVertexProps","children","props","rotation","matrix","getCounterRotation","elementRef","handlePointerDown","handleTouchStart","addEventListener","capture","removeEventListener","menuWrapperProps","style","left","top","transform","transformOrigin","pointerEvents","zIndex","ref","el","Fragment","onDouble","delay","tolerancePx","last","t","handlePointerUp","pointerType","isPrimary","now","performance","withinTime","dx","dy","handleDouble","onPointerUpCapture","opts","controller","resizeUI","vertexUI","includeVertices","handleAttrs","vertexAttrs","resize","useMemo","cfg","ui","handleSize","offsetMode","includeSides","rotationAwareCursor","off","edge","map","pos","borderRadius","cursor","touchAction","attrs","describeResizeFromConfig","d","key","liveVertices","vertexSize","v","i","describeVerticesFromConfig"],"mappings":"iMAiBaA,EAAe,aCwBrB,MAAMC,EAYX,WAAAC,CACUC,EACAC,GADAC,KAAAF,OAAAA,EACAE,KAAAD,SAAAA,EAbVC,KAAQC,MAA0B,OAClCD,KAAQE,WAA8B,KACtCF,KAAQG,aAA4B,KACpCH,KAAQI,aAAoC,KAC5CJ,KAAQK,gBAA+B,KAGvCL,KAAQM,kBAAmC,KAC3CN,KAAQO,cAA4B,GACpCP,KAAQQ,gBAA8B,GAMpCR,KAAKQ,gBAAkBV,EAAOW,UAAY,EAC5C,CAEA,YAAAC,CAAaZ,GACXE,KAAKF,OAAS,IAAKE,KAAKF,UAAWA,GACnCE,KAAKQ,gBAAkBV,EAAOW,UAAY,EAC5C,CAEA,SAAAE,CAAUC,EAAiBC,GACzBb,KAAKC,MAAQ,WACbD,KAAKE,WAAa,CAAEY,EAAGF,EAASG,EAAGF,GACnCb,KAAKG,aAAe,IAAKH,KAAKF,OAAOkB,SACrChB,KAAKK,gBAAkB,IAAKL,KAAKF,OAAOkB,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xBW8J,EAAAA,QAAQ,KAC7C,IAAKJ,EAAiB,MAAO,GAE7B,OJ4BG,SACLK,EACAC,EAAe,CAAA,EACfgB,GAEA,MAAMC,WAAEA,EAAa,GAAA9C,OAAIA,EAAS,GAAM6B,EAClCrJ,EAAaoJ,EAAIxJ,QACjB4B,EAAQ4H,EAAI5H,OAAS,EAG3B,OAFc6I,GAAgBjB,EAAI/J,UAAY,IAEjCuK,IAAI,CAACW,EAAGC,KAGZ,CACLtK,OAAQ,KACRgH,MAAO,CACLvG,SAAU,WACVwG,MANUoD,EAAE7K,EAAIM,EAAK6C,OAAOnD,GAAK8B,EAAQ8I,EAAa,EAMzC,KACblD,KANSmD,EAAE5K,EAAIK,EAAK6C,OAAOlD,GAAK6B,EAAQ8I,EAAa,EAM1C,KACX9H,MAAO8H,EAAa,KACpB7H,OAAQ6H,EAAa,KACrBR,aAAc,MACdC,OAAQ,UACRvC,SACAwC,YAAa,QAEfC,MAAO,CAAE,mBAAoBO,KAGnC,CI1DiBC,CAA2B7B,EAAYE,EAAUF,EAAWvJ,UAC7DuK,IAAI,CAACO,EAAGK,KAAA,CAClBJ,IAAKI,EACLtD,MAAOiD,EAAEjD,SACNb,EAAkBmE,MACjBL,EAAEF,OAAS,CAAA,MACX,MAAAhB,OAAA,EAAAA,EAAcuB,KAAM,CAAA,MAEzB,CACDzB,EACAH,EAAWhJ,QAAQiD,OAAOnD,EAC1BkJ,EAAWhJ,QAAQiD,OAAOlD,EAC1BiJ,EAAWhJ,QAAQkD,KAAKN,MACxBoG,EAAWhJ,QAAQkD,KAAKL,OACxBmG,EAAWpH,MACXoH,EAAWvJ,SACX,MAAAyJ,OAAA,EAAAA,EAAUwB,WACV,MAAAxB,OAAA,EAAAA,EAAUtB,OACVnB,EACA4C,IAIJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/preact/adapter.ts","../../src/shared/plugin-interaction-primitives/drag-resize-controller.ts","../../src/shared/plugin-interaction-primitives/utils.ts","../../src/shared/hooks/use-drag-resize.ts","../../src/shared/components/counter-rotate-container.tsx","../../src/shared/hooks/use-double-press-props.ts","../../src/shared/hooks/use-interaction-handles.ts"],"sourcesContent":["import { createContext, JSX, Fragment, FunctionComponent } from 'preact';\nexport { useEffect, useRef, useState, useCallback, useMemo, useContext } from 'preact/hooks';\nexport type { ComponentChildren as ReactNode, JSX } from 'preact';\n\nexport { createContext, Fragment };\n\nexport type CSSProperties = import('preact').JSX.CSSProperties;\nexport type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<\n T extends EventTarget ? T : never\n>;\n\nexport type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarget ? T : never>;\nexport type PointerEvent<T = Element> = JSX.TargetedPointerEvent<T extends EventTarget ? T : never>;\nexport type ChangeEvent<T = Element> = JSX.TargetedInputEvent<T extends EventTarget ? T : never>;\nexport type TouchEvent<T = Element> = JSX.TargetedTouchEvent<T extends EventTarget ? T : never>;\nexport type ComponentType = FunctionComponent;\n\nexport const dblClickProp = 'onDblClick' as const;\n","import { Position, Rect } from '@embedpdf/models';\n\nexport interface DragResizeConfig {\n element: Rect;\n vertices?: Position[];\n constraints?: {\n minWidth?: number;\n minHeight?: number;\n maxWidth?: number;\n maxHeight?: number;\n boundingBox?: { width: number; height: number }; // page bounds\n };\n maintainAspectRatio?: boolean;\n pageRotation?: number;\n scale?: number;\n}\n\nexport type InteractionState = 'idle' | 'dragging' | 'resizing' | 'vertex-editing';\nexport type ResizeHandle = 'nw' | 'ne' | 'sw' | 'se' | 'n' | 'e' | 's' | 'w';\n\nexport interface TransformData {\n type: 'move' | 'resize' | 'vertex-edit';\n changes: {\n rect?: Rect;\n vertices?: Position[];\n };\n metadata?: {\n handle?: ResizeHandle;\n vertexIndex?: number;\n maintainAspectRatio?: boolean;\n };\n}\n\nexport interface InteractionEvent {\n state: 'start' | 'move' | 'end';\n transformData?: TransformData;\n}\n\n/** Anchor describes which edges stay fixed when resizing. */\ntype Anchor = {\n x: 'left' | 'right' | 'center';\n y: 'top' | 'bottom' | 'center';\n};\n\n/**\n * Derive anchor from handle.\n * - 'e' means we're dragging east → left edge is anchored\n * - 'nw' means we're dragging north-west → bottom-right corner is anchored\n */\nfunction getAnchor(handle: ResizeHandle): Anchor {\n return {\n x: handle.includes('e') ? 'left' : handle.includes('w') ? 'right' : 'center',\n y: handle.includes('s') ? 'top' : handle.includes('n') ? 'bottom' : 'center',\n };\n}\n\n/**\n * Pure geometric controller that manages drag/resize/vertex-edit logic.\n */\nexport class DragResizeController {\n private state: InteractionState = 'idle';\n private startPoint: Position | null = null;\n private startElement: Rect | null = null;\n private activeHandle: ResizeHandle | null = null;\n private currentPosition: Rect | null = null;\n\n // Vertex editing state - pure geometric\n private activeVertexIndex: number | null = null;\n private startVertices: Position[] = [];\n private currentVertices: Position[] = [];\n\n constructor(\n private config: DragResizeConfig,\n private onUpdate: (event: InteractionEvent) => void,\n ) {\n this.currentVertices = config.vertices || [];\n }\n\n updateConfig(config: Partial<DragResizeConfig>) {\n this.config = { ...this.config, ...config };\n this.currentVertices = config.vertices || [];\n }\n\n startDrag(clientX: number, clientY: number) {\n this.state = 'dragging';\n this.startPoint = { x: clientX, y: clientY };\n this.startElement = { ...this.config.element };\n this.currentPosition = { ...this.config.element };\n\n this.onUpdate({\n state: 'start',\n transformData: {\n type: 'move',\n changes: {\n rect: this.startElement,\n },\n },\n });\n }\n\n startResize(handle: ResizeHandle, clientX: number, clientY: number) {\n this.state = 'resizing';\n this.activeHandle = handle;\n this.startPoint = { x: clientX, y: clientY };\n this.startElement = { ...this.config.element };\n this.currentPosition = { ...this.config.element };\n\n this.onUpdate({\n state: 'start',\n transformData: {\n type: 'resize',\n changes: {\n rect: this.startElement,\n },\n metadata: {\n handle: this.activeHandle,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n }\n\n startVertexEdit(vertexIndex: number, clientX: number, clientY: number) {\n // Refresh vertices from latest config before validating index\n this.currentVertices = [...(this.config.vertices ?? this.currentVertices)];\n if (vertexIndex < 0 || vertexIndex >= this.currentVertices.length) return;\n\n this.state = 'vertex-editing';\n this.activeVertexIndex = vertexIndex;\n this.startPoint = { x: clientX, y: clientY };\n this.startVertices = [...this.currentVertices];\n\n this.onUpdate({\n state: 'start',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices: this.startVertices,\n },\n metadata: {\n vertexIndex,\n },\n },\n });\n }\n\n move(clientX: number, clientY: number) {\n if (this.state === 'idle' || !this.startPoint) return;\n\n if (this.state === 'dragging' && this.startElement) {\n const delta = this.calculateDelta(clientX, clientY);\n const position = this.calculateDragPosition(delta);\n this.currentPosition = position;\n\n this.onUpdate({\n state: 'move',\n transformData: {\n type: 'move',\n changes: {\n rect: position,\n },\n },\n });\n } else if (this.state === 'resizing' && this.activeHandle && this.startElement) {\n const delta = this.calculateDelta(clientX, clientY);\n const position = this.calculateResizePosition(delta, this.activeHandle);\n this.currentPosition = position;\n\n this.onUpdate({\n state: 'move',\n transformData: {\n type: 'resize',\n changes: {\n rect: position,\n },\n metadata: {\n handle: this.activeHandle,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n } else if (this.state === 'vertex-editing' && this.activeVertexIndex !== null) {\n const vertices = this.calculateVertexPosition(clientX, clientY);\n this.currentVertices = vertices;\n\n this.onUpdate({\n state: 'move',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices,\n },\n metadata: {\n vertexIndex: this.activeVertexIndex,\n },\n },\n });\n }\n }\n\n end() {\n if (this.state === 'idle') return;\n\n const wasState = this.state;\n const handle = this.activeHandle;\n const vertexIndex = this.activeVertexIndex;\n\n if (wasState === 'vertex-editing') {\n this.onUpdate({\n state: 'end',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices: this.currentVertices,\n },\n metadata: {\n vertexIndex: vertexIndex || undefined,\n },\n },\n });\n } else {\n const finalPosition = this.getCurrentPosition();\n this.onUpdate({\n state: 'end',\n transformData: {\n type: wasState === 'dragging' ? 'move' : 'resize',\n changes: {\n rect: finalPosition,\n },\n metadata:\n wasState === 'dragging'\n ? undefined\n : {\n handle: handle || undefined,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n }\n\n this.reset();\n }\n\n cancel() {\n if (this.state === 'idle') return;\n\n if (this.state === 'vertex-editing') {\n this.onUpdate({\n state: 'end',\n transformData: {\n type: 'vertex-edit',\n changes: {\n vertices: this.startVertices,\n },\n metadata: {\n vertexIndex: this.activeVertexIndex || undefined,\n },\n },\n });\n } else if (this.startElement) {\n this.onUpdate({\n state: 'end',\n transformData: {\n type: this.state === 'dragging' ? 'move' : 'resize',\n changes: {\n rect: this.startElement,\n },\n metadata:\n this.state === 'dragging'\n ? undefined\n : {\n handle: this.activeHandle || undefined,\n maintainAspectRatio: this.config.maintainAspectRatio,\n },\n },\n });\n }\n\n this.reset();\n }\n\n private reset() {\n this.state = 'idle';\n this.startPoint = null;\n this.startElement = null;\n this.activeHandle = null;\n this.currentPosition = null;\n this.activeVertexIndex = null;\n this.startVertices = [];\n }\n\n private getCurrentPosition() {\n return this.currentPosition || this.config.element;\n }\n\n private calculateDelta(clientX: number, clientY: number): Position {\n if (!this.startPoint) return { x: 0, y: 0 };\n\n const rawDelta: Position = {\n x: clientX - this.startPoint.x,\n y: clientY - this.startPoint.y,\n };\n\n return this.transformDelta(rawDelta);\n }\n\n private transformDelta(delta: Position): Position {\n const { pageRotation = 0, scale = 1 } = this.config;\n\n const rad = (pageRotation * Math.PI) / 2;\n const cos = Math.cos(rad);\n const sin = Math.sin(rad);\n\n const scaledX = delta.x / scale;\n const scaledY = delta.y / scale;\n\n return {\n x: cos * scaledX + sin * scaledY,\n y: -sin * scaledX + cos * scaledY,\n };\n }\n\n private clampPoint(p: Position): Position {\n const bbox = this.config.constraints?.boundingBox;\n if (!bbox) return p;\n return {\n x: Math.max(0, Math.min(p.x, bbox.width)),\n y: Math.max(0, Math.min(p.y, bbox.height)),\n };\n }\n\n private calculateVertexPosition(clientX: number, clientY: number): Position[] {\n if (this.activeVertexIndex === null) return this.startVertices;\n\n const delta = this.calculateDelta(clientX, clientY);\n const newVertices = [...this.startVertices];\n const currentVertex = newVertices[this.activeVertexIndex];\n\n const moved = {\n x: currentVertex.x + delta.x,\n y: currentVertex.y + delta.y,\n };\n newVertices[this.activeVertexIndex] = this.clampPoint(moved);\n\n return newVertices;\n }\n\n private calculateDragPosition(delta: Position): Rect {\n if (!this.startElement) return this.config.element;\n\n const position: Rect = {\n origin: {\n x: this.startElement.origin.x + delta.x,\n y: this.startElement.origin.y + delta.y,\n },\n size: {\n width: this.startElement.size.width,\n height: this.startElement.size.height,\n },\n };\n\n return this.applyConstraints(position);\n }\n\n /**\n * Calculate the new rect after a resize operation.\n * Pipeline: applyDelta → enforceAspectRatio → clampToBounds → applyConstraints\n */\n private calculateResizePosition(delta: Position, handle: ResizeHandle): Rect {\n if (!this.startElement) return this.config.element;\n\n const anchor = getAnchor(handle);\n const aspectRatio = this.startElement.size.width / this.startElement.size.height || 1;\n\n // Step 1: Apply delta to get raw resize\n let rect = this.applyResizeDelta(delta, anchor);\n\n // Step 2: Enforce aspect ratio if enabled\n if (this.config.maintainAspectRatio) {\n rect = this.enforceAspectRatio(rect, anchor, aspectRatio);\n }\n\n // Step 3: Clamp to bounding box\n rect = this.clampToBounds(rect, anchor, aspectRatio);\n\n // Step 4: Apply min/max constraints\n return this.applyConstraints(rect);\n }\n\n /**\n * Apply the mouse delta to produce a raw (unconstrained) resized rect.\n */\n private applyResizeDelta(delta: Position, anchor: Anchor): Rect {\n const start = this.startElement!;\n let x = start.origin.x;\n let y = start.origin.y;\n let width = start.size.width;\n let height = start.size.height;\n\n // Horizontal: if anchor is left, right edge moves; if anchor is right, left edge moves\n if (anchor.x === 'left') {\n width += delta.x;\n } else if (anchor.x === 'right') {\n x += delta.x;\n width -= delta.x;\n }\n // anchor.x === 'center' means no horizontal resize from this handle\n\n // Vertical: if anchor is top, bottom edge moves; if anchor is bottom, top edge moves\n if (anchor.y === 'top') {\n height += delta.y;\n } else if (anchor.y === 'bottom') {\n y += delta.y;\n height -= delta.y;\n }\n\n return { origin: { x, y }, size: { width, height } };\n }\n\n /**\n * Enforce aspect ratio while respecting the anchor.\n * For edge handles (center anchor on one axis), the rect expands symmetrically on that axis.\n * For corner handles, the anchor corner stays fixed.\n */\n private enforceAspectRatio(rect: Rect, anchor: Anchor, aspectRatio: number): Rect {\n const start = this.startElement!;\n let { x, y } = rect.origin;\n let { width, height } = rect.size;\n\n const isEdgeHandle = anchor.x === 'center' || anchor.y === 'center';\n\n if (isEdgeHandle) {\n // Edge handle: one dimension drives, the other follows, centered on the non-moving axis\n if (anchor.y === 'center') {\n // Horizontal edge (e/w): width is primary\n height = width / aspectRatio;\n // Center vertically relative to original\n y = start.origin.y + (start.size.height - height) / 2;\n } else {\n // Vertical edge (n/s): height is primary\n width = height * aspectRatio;\n // Center horizontally relative to original\n x = start.origin.x + (start.size.width - width) / 2;\n }\n } else {\n // Corner handle: pick the dominant axis based on which changed more\n const dw = Math.abs(width - start.size.width);\n const dh = Math.abs(height - start.size.height);\n\n if (dw >= dh) {\n height = width / aspectRatio;\n } else {\n width = height * aspectRatio;\n }\n }\n\n // Reposition based on anchor\n if (anchor.x === 'right') {\n x = start.origin.x + start.size.width - width;\n }\n if (anchor.y === 'bottom') {\n y = start.origin.y + start.size.height - height;\n }\n\n return { origin: { x, y }, size: { width, height } };\n }\n\n /**\n * Clamp rect to bounding box while respecting anchor and aspect ratio.\n */\n private clampToBounds(rect: Rect, anchor: Anchor, aspectRatio: number): Rect {\n const bbox = this.config.constraints?.boundingBox;\n if (!bbox) return rect;\n\n const start = this.startElement!;\n let { x, y } = rect.origin;\n let { width, height } = rect.size;\n\n // Ensure positive dimensions\n width = Math.max(1, width);\n height = Math.max(1, height);\n\n // Calculate anchor points (the edges/corners that must stay fixed)\n const anchorX = anchor.x === 'left' ? start.origin.x : start.origin.x + start.size.width;\n const anchorY = anchor.y === 'top' ? start.origin.y : start.origin.y + start.size.height;\n\n // Calculate max available space from anchor\n const maxW =\n anchor.x === 'left'\n ? bbox.width - anchorX\n : anchor.x === 'right'\n ? anchorX\n : Math.min(start.origin.x, bbox.width - start.origin.x - start.size.width) * 2 +\n start.size.width;\n\n const maxH =\n anchor.y === 'top'\n ? bbox.height - anchorY\n : anchor.y === 'bottom'\n ? anchorY\n : Math.min(start.origin.y, bbox.height - start.origin.y - start.size.height) * 2 +\n start.size.height;\n\n if (this.config.maintainAspectRatio) {\n // Find the scaling factor that fits both constraints\n const scaleW = width > maxW ? maxW / width : 1;\n const scaleH = height > maxH ? maxH / height : 1;\n const scale = Math.min(scaleW, scaleH);\n\n if (scale < 1) {\n width *= scale;\n height *= scale;\n }\n } else {\n // Clamp independently\n width = Math.min(width, maxW);\n height = Math.min(height, maxH);\n }\n\n // Recompute position based on anchor\n if (anchor.x === 'left') {\n x = anchorX;\n } else if (anchor.x === 'right') {\n x = anchorX - width;\n } else {\n x = start.origin.x + (start.size.width - width) / 2;\n }\n\n if (anchor.y === 'top') {\n y = anchorY;\n } else if (anchor.y === 'bottom') {\n y = anchorY - height;\n } else {\n y = start.origin.y + (start.size.height - height) / 2;\n }\n\n // Final clamp to ensure we're within bounds (handles center anchor edge cases)\n x = Math.max(0, Math.min(x, bbox.width - width));\n y = Math.max(0, Math.min(y, bbox.height - height));\n\n return { origin: { x, y }, size: { width, height } };\n }\n\n private applyConstraints(position: Rect): Rect {\n const { constraints } = this.config;\n if (!constraints) return position;\n\n let {\n origin: { x, y },\n size: { width, height },\n } = position;\n\n const minW = constraints.minWidth ?? 1;\n const minH = constraints.minHeight ?? 1;\n const maxW = constraints.maxWidth;\n const maxH = constraints.maxHeight;\n\n if (this.config.maintainAspectRatio && width > 0 && height > 0) {\n const ratio = width / height;\n\n // Enforce mins (scale up)\n if (width < minW) {\n width = minW;\n height = width / ratio;\n }\n if (height < minH) {\n height = minH;\n width = height * ratio;\n }\n\n // Enforce maxes (scale down)\n if (maxW !== undefined && width > maxW) {\n width = maxW;\n height = width / ratio;\n }\n if (maxH !== undefined && height > maxH) {\n height = maxH;\n width = height * ratio;\n }\n } else {\n width = Math.max(minW, width);\n height = Math.max(minH, height);\n if (maxW !== undefined) width = Math.min(maxW, width);\n if (maxH !== undefined) height = Math.min(maxH, height);\n }\n\n // Clamp position to bounding box\n if (constraints.boundingBox) {\n x = Math.max(0, Math.min(x, constraints.boundingBox.width - width));\n y = Math.max(0, Math.min(y, constraints.boundingBox.height - height));\n }\n\n return { origin: { x, y }, size: { width, height } };\n }\n}\n","import type { Position, Rect } from '@embedpdf/models';\nimport type { ResizeHandle, DragResizeConfig } from './drag-resize-controller';\n\nexport type QuarterTurns = 0 | 1 | 2 | 3;\n\nexport interface ResizeUI {\n handleSize?: number; // px (default 8)\n spacing?: number; // px distance from the box edge (default 1)\n offsetMode?: 'outside' | 'inside' | 'center'; // default 'outside'\n includeSides?: boolean; // default false\n zIndex?: number; // default 3\n rotationAwareCursor?: boolean; // default true\n}\n\nexport interface VertexUI {\n vertexSize?: number; // px (default 12)\n zIndex?: number; // default 4\n}\n\nexport interface HandleDescriptor {\n handle: ResizeHandle;\n style: Record<string, number | string>;\n attrs?: Record<string, any>;\n}\n\nfunction diagonalCursor(handle: ResizeHandle, rot: QuarterTurns): string {\n // Standard cursors; diagonals flip on odd quarter-turns\n const diag0: Record<'nw' | 'ne' | 'sw' | 'se', string> = {\n nw: 'nwse-resize',\n ne: 'nesw-resize',\n sw: 'nesw-resize',\n se: 'nwse-resize',\n };\n if (handle === 'n' || handle === 's') return 'ns-resize';\n if (handle === 'e' || handle === 'w') return 'ew-resize';\n if (rot % 2 === 0) return diag0[handle as 'nw' | 'ne' | 'sw' | 'se'];\n return { nw: 'nesw-resize', ne: 'nwse-resize', sw: 'nwse-resize', se: 'nesw-resize' }[\n handle as 'nw' | 'ne' | 'sw' | 'se'\n ]!;\n}\n\nfunction edgeOffset(k: number, spacing: number, mode: 'outside' | 'inside' | 'center') {\n // Base puts the handle centered on the edge\n const base = -k / 2;\n if (mode === 'center') return base;\n // outside moves further out (more negative), inside moves in (less negative)\n return mode === 'outside' ? base - spacing : base + spacing;\n}\n\nexport function describeResizeFromConfig(\n cfg: DragResizeConfig,\n ui: ResizeUI = {},\n): HandleDescriptor[] {\n const {\n handleSize = 8,\n spacing = 1,\n offsetMode = 'outside',\n includeSides = false,\n zIndex = 3,\n rotationAwareCursor = true,\n } = ui;\n\n const rotation = ((cfg.pageRotation ?? 0) % 4) as QuarterTurns;\n\n const off = (edge: 'top' | 'right' | 'bottom' | 'left') => ({\n [edge]: edgeOffset(handleSize, spacing, offsetMode) + 'px',\n });\n\n const corners: Array<[ResizeHandle, Record<string, number | string>]> = [\n ['nw', { ...off('top'), ...off('left') }],\n ['ne', { ...off('top'), ...off('right') }],\n ['sw', { ...off('bottom'), ...off('left') }],\n ['se', { ...off('bottom'), ...off('right') }],\n ];\n const sides: Array<[ResizeHandle, Record<string, number | string>]> = includeSides\n ? [\n ['n', { ...off('top'), left: `calc(50% - ${handleSize / 2}px)` }],\n ['s', { ...off('bottom'), left: `calc(50% - ${handleSize / 2}px)` }],\n ['w', { ...off('left'), top: `calc(50% - ${handleSize / 2}px)` }],\n ['e', { ...off('right'), top: `calc(50% - ${handleSize / 2}px)` }],\n ]\n : [];\n\n const all = [...corners, ...sides];\n\n return all.map(([handle, pos]) => ({\n handle,\n style: {\n position: 'absolute',\n width: handleSize + 'px',\n height: handleSize + 'px',\n borderRadius: '50%',\n zIndex,\n cursor: rotationAwareCursor ? diagonalCursor(handle, rotation) : 'default',\n touchAction: 'none',\n ...(pos as any),\n },\n attrs: { 'data-epdf-handle': handle },\n }));\n}\n\nexport function describeVerticesFromConfig(\n cfg: DragResizeConfig,\n ui: VertexUI = {},\n liveVertices?: Position[],\n): HandleDescriptor[] {\n const { vertexSize = 12, zIndex = 4 } = ui;\n const rect: Rect = cfg.element;\n const scale = cfg.scale ?? 1;\n const verts = liveVertices ?? cfg.vertices ?? [];\n\n return verts.map((v, i) => {\n const left = (v.x - rect.origin.x) * scale - vertexSize / 2;\n const top = (v.y - rect.origin.y) * scale - vertexSize / 2;\n return {\n handle: 'nw', // not used; kept for type\n style: {\n position: 'absolute',\n left: left + 'px',\n top: top + 'px',\n width: vertexSize + 'px',\n height: vertexSize + 'px',\n borderRadius: '50%',\n cursor: 'pointer',\n zIndex,\n touchAction: 'none',\n },\n attrs: { 'data-epdf-vertex': i },\n };\n });\n}\n","import { useRef, useCallback, useEffect, PointerEvent } from '@framework';\nimport {\n DragResizeController,\n DragResizeConfig,\n InteractionEvent,\n ResizeHandle,\n} from '../plugin-interaction-primitives';\n\nexport interface UseDragResizeOptions extends DragResizeConfig {\n onUpdate?: (event: InteractionEvent) => void;\n enabled?: boolean;\n}\n\nexport interface ResizeHandleEventProps {\n onPointerDown: (e: PointerEvent) => void;\n onPointerMove: (e: PointerEvent) => void;\n onPointerUp: (e: PointerEvent) => void;\n onPointerCancel: (e: PointerEvent) => void;\n}\n\nexport function useDragResize(options: UseDragResizeOptions) {\n const { onUpdate, enabled = true, ...config } = options;\n const controllerRef = useRef<DragResizeController | null>(null);\n const onUpdateRef = useRef<typeof onUpdate>(onUpdate);\n\n useEffect(() => {\n onUpdateRef.current = onUpdate;\n }, [onUpdate]);\n\n // Initialize or update controller\n useEffect(() => {\n if (!controllerRef.current) {\n controllerRef.current = new DragResizeController(config, (event) =>\n onUpdateRef.current?.(event),\n );\n } else {\n controllerRef.current.updateConfig(config);\n }\n }, [\n config.element,\n config.constraints,\n config.maintainAspectRatio,\n config.pageRotation,\n config.scale,\n config.vertices,\n ]);\n\n const handleDragStart = useCallback(\n (e: PointerEvent) => {\n if (!enabled) return;\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.startDrag(e.clientX, e.clientY);\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n },\n [enabled],\n );\n\n const handleMove = useCallback((e: PointerEvent) => {\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.move(e.clientX, e.clientY);\n }, []);\n\n const handleEnd = useCallback((e: PointerEvent) => {\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.end();\n (e.currentTarget as HTMLElement).releasePointerCapture?.(e.pointerId);\n }, []);\n\n const createResizeHandler = useCallback(\n (handle: ResizeHandle): ResizeHandleEventProps => ({\n onPointerDown: (e: PointerEvent) => {\n if (!enabled) return;\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.startResize(handle, e.clientX, e.clientY);\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n },\n onPointerMove: handleMove,\n onPointerUp: handleEnd,\n onPointerCancel: handleEnd,\n }),\n [enabled, handleMove, handleEnd],\n );\n\n const createVertexHandler = useCallback(\n (vertexIndex: number): ResizeHandleEventProps => ({\n onPointerDown: (e: PointerEvent) => {\n if (!enabled) return;\n e.preventDefault();\n e.stopPropagation();\n controllerRef.current?.startVertexEdit(vertexIndex, e.clientX, e.clientY);\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n },\n onPointerMove: handleMove,\n onPointerUp: handleEnd,\n onPointerCancel: handleEnd,\n }),\n [enabled, handleMove, handleEnd],\n );\n\n return {\n dragProps: enabled\n ? {\n onPointerDown: handleDragStart,\n onPointerMove: handleMove,\n onPointerUp: handleEnd,\n onPointerCancel: handleEnd,\n }\n : {},\n createResizeProps: createResizeHandler,\n createVertexProps: createVertexHandler,\n };\n}\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { getCounterRotation } from '@embedpdf/utils';\nimport { ReactNode, CSSProperties, Fragment, useRef, useEffect } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n ref: (el: HTMLDivElement | null) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n const elementRef = useRef<HTMLDivElement | null>(null);\n\n // Use native event listeners with capture phase to prevent event propagation\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n const handlePointerDown = (e: Event) => {\n // Stop propagation to prevent underlying layers from receiving the event\n e.stopPropagation();\n // DO NOT use e.preventDefault() here - it breaks click events on mobile/tablet!\n // preventDefault() stops the browser from generating click events from touch,\n // which makes buttons inside this container non-functional on touch devices.\n };\n\n const handleTouchStart = (e: Event) => {\n // Stop propagation to prevent underlying layers from receiving the event\n e.stopPropagation();\n // DO NOT use e.preventDefault() here - it breaks click events on mobile/tablet!\n // preventDefault() stops the browser from generating click events from touch,\n // which makes buttons inside this container non-functional on touch devices.\n };\n\n // Use capture phase to intercept before synthetic events\n element.addEventListener('pointerdown', handlePointerDown, { capture: true });\n element.addEventListener('touchstart', handleTouchStart, { capture: true });\n\n return () => {\n element.removeEventListener('pointerdown', handlePointerDown, { capture: true });\n element.removeEventListener('touchstart', handleTouchStart, { capture: true });\n };\n }, []);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps: MenuWrapperProps = {\n style: menuWrapperStyle,\n ref: (el: HTMLDivElement | null) => {\n elementRef.current = el;\n },\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\n })}\n </Fragment>\n );\n}\n","import { useRef, useCallback, dblClickProp } from '@framework';\nimport type { PointerEvent } from '@framework';\n\ntype DoublePressOptions = {\n delay?: number; // ms between taps\n tolerancePx?: number; // spatial tolerance\n};\n\ntype DoubleHandler<T extends Element> = ((e: PointerEvent<T> | MouseEvent) => void) | undefined;\n\ntype DoubleProps<K extends string> = Partial<Record<K, (e: any) => void>> & {\n onPointerUp?: (e: any) => void;\n};\n\nexport function useDoublePressProps<\n T extends Element = Element,\n K extends string = typeof dblClickProp,\n>(\n onDouble?: DoubleHandler<T>,\n { delay = 300, tolerancePx = 18 }: DoublePressOptions = {},\n): DoubleProps<K> {\n const last = useRef({ t: 0, x: 0, y: 0 });\n\n const handlePointerUp = useCallback(\n (e: any) => {\n if (!onDouble) return;\n\n // Ignore mouse (it will use native dblclick),\n // and ignore non-primary pointers (multi-touch, etc.)\n if (e.pointerType === 'mouse' || e.isPrimary === false) return;\n\n const now = performance.now();\n const x = e.clientX as number;\n const y = e.clientY as number;\n\n const withinTime = now - last.current.t <= delay;\n const dx = x - last.current.x;\n const dy = y - last.current.y;\n const withinDist = dx * dx + dy * dy <= tolerancePx * tolerancePx;\n\n if (withinTime && withinDist) onDouble?.(e as PointerEvent<T>);\n\n last.current = { t: now, x, y };\n },\n [onDouble, delay, tolerancePx],\n );\n\n const handleDouble = useCallback(\n (e: any) => {\n onDouble?.(e);\n },\n [onDouble],\n );\n\n return onDouble\n ? ({\n // Computed property uses the framework’s name ('onDoubleClick' or 'onDblClick')\n [dblClickProp]: handleDouble,\n onPointerUpCapture: handlePointerUp,\n } as DoubleProps<K>)\n : {};\n}\n","import { useMemo, PointerEvent } from '@framework';\nimport type { CSSProperties } from '@framework';\nimport { useDragResize, UseDragResizeOptions } from './use-drag-resize';\nimport {\n describeResizeFromConfig,\n describeVerticesFromConfig,\n type ResizeUI,\n type VertexUI,\n} from '../plugin-interaction-primitives/utils';\n\nexport type HandleElementProps = {\n key: string | number;\n style: CSSProperties;\n onPointerDown: (e: PointerEvent) => void;\n onPointerMove: (e: PointerEvent) => void;\n onPointerUp: (e: PointerEvent) => void;\n onPointerCancel: (e: PointerEvent) => void;\n} & Record<string, any>;\n\nexport function useInteractionHandles(opts: {\n controller: UseDragResizeOptions; // SINGLE config (rect/scale/rotation/vertices/…)\n resizeUI?: ResizeUI; // purely visual knobs\n vertexUI?: VertexUI; // purely visual knobs\n includeVertices?: boolean; // default false\n handleAttrs?: (\n h: 'nw' | 'ne' | 'sw' | 'se' | 'n' | 'e' | 's' | 'w',\n ) => Record<string, any> | void;\n vertexAttrs?: (i: number) => Record<string, any> | void;\n}) {\n const {\n controller,\n resizeUI,\n vertexUI,\n includeVertices = false,\n handleAttrs,\n vertexAttrs,\n } = opts;\n\n const { dragProps, createResizeProps, createVertexProps } = useDragResize(controller);\n\n // Resize handles: only uses data from the SAME controller config.\n const resize: HandleElementProps[] = useMemo(() => {\n const desc = describeResizeFromConfig(controller, resizeUI);\n return desc.map((d) => ({\n key: d.attrs?.['data-epdf-handle'] as string,\n style: d.style as CSSProperties,\n ...createResizeProps(d.handle),\n ...(d.attrs ?? {}),\n ...(handleAttrs?.(d.handle) ?? {}),\n }));\n // deps: controller geometry knobs + UI knobs + handler factory\n }, [\n controller.element.origin.x,\n controller.element.origin.y,\n controller.element.size.width,\n controller.element.size.height,\n controller.scale,\n controller.pageRotation,\n controller.maintainAspectRatio,\n resizeUI?.handleSize,\n resizeUI?.spacing,\n resizeUI?.offsetMode,\n resizeUI?.includeSides,\n resizeUI?.zIndex,\n resizeUI?.rotationAwareCursor,\n createResizeProps,\n handleAttrs,\n ]);\n\n // Vertex handles: same source; prefer live vertices if parent rerenders with updated cfg.vertices\n const vertices: HandleElementProps[] = useMemo(() => {\n if (!includeVertices) return [];\n const desc = describeVerticesFromConfig(controller, vertexUI, controller.vertices);\n return desc.map((d, i) => ({\n key: i,\n style: d.style as CSSProperties,\n ...createVertexProps(i),\n ...(d.attrs ?? {}),\n ...(vertexAttrs?.(i) ?? {}),\n }));\n }, [\n includeVertices,\n controller.element.origin.x,\n controller.element.origin.y,\n controller.element.size.width,\n controller.element.size.height,\n controller.scale,\n controller.vertices, // identity/content drives recalculation\n vertexUI?.vertexSize,\n vertexUI?.zIndex,\n createVertexProps,\n vertexAttrs,\n ]);\n\n return { dragProps, resize, vertices };\n}\n"],"names":["dblClickProp","DragResizeController","constructor","config","onUpdate","this","state","startPoint","startElement","activeHandle","currentPosition","activeVertexIndex","startVertices","currentVertices","vertices","updateConfig","startDrag","clientX","clientY","x","y","element","transformData","type","changes","rect","startResize","handle","metadata","maintainAspectRatio","startVertexEdit","vertexIndex","length","move","delta","calculateDelta","position","calculateDragPosition","calculateResizePosition","calculateVertexPosition","end","wasState","finalPosition","getCurrentPosition","reset","cancel","rawDelta","transformDelta","pageRotation","scale","rad","Math","PI","cos","sin","scaledX","scaledY","clampPoint","p","bbox","_a","constraints","boundingBox","max","min","width","height","newVertices","currentVertex","moved","origin","size","applyConstraints","anchor","includes","getAnchor","aspectRatio","applyResizeDelta","enforceAspectRatio","clampToBounds","start","abs","anchorX","anchorY","maxW","maxH","scaleW","scaleH","minW","minWidth","minH","minHeight","maxWidth","maxHeight","ratio","diagonalCursor","rot","nw","ne","sw","se","edgeOffset","k","spacing","mode","base","useDragResize","options","enabled","controllerRef","useRef","onUpdateRef","useEffect","current","event","call","handleDragStart","useCallback","e","preventDefault","stopPropagation","currentTarget","setPointerCapture","pointerId","handleMove","handleEnd","_c","_b","releasePointerCapture","createResizeHandler","onPointerDown","onPointerMove","onPointerUp","onPointerCancel","createVertexHandler","dragProps","createResizeProps","createVertexProps","children","props","rotation","matrix","getCounterRotation","elementRef","handlePointerDown","handleTouchStart","addEventListener","capture","removeEventListener","menuWrapperProps","style","left","top","transform","transformOrigin","pointerEvents","zIndex","ref","el","Fragment","onDouble","delay","tolerancePx","last","t","handlePointerUp","pointerType","isPrimary","now","performance","withinTime","dx","dy","handleDouble","onPointerUpCapture","opts","controller","resizeUI","vertexUI","includeVertices","handleAttrs","vertexAttrs","resize","useMemo","cfg","ui","handleSize","offsetMode","includeSides","rotationAwareCursor","off","edge","map","pos","borderRadius","cursor","touchAction","attrs","describeResizeFromConfig","d","key","liveVertices","vertexSize","v","i","describeVerticesFromConfig"],"mappings":"iMAiBaA,EAAe,aC0CrB,MAAMC,EAYX,WAAAC,CACUC,EACAC,GADAC,KAAAF,OAAAA,E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AAGC,KAGZ,CACLjL,OAAQ,KACR2H,MAAO,CACLlH,SAAU,WACVmH,MANUoD,EAAExL,EAAIM,EAAK6C,OAAOnD,GAAK8B,EAAQyJ,EAAa,EAMzC,KACblD,KANSmD,EAAEvL,EAAIK,EAAK6C,OAAOlD,GAAK6B,EAAQyJ,EAAa,EAM1C,KACXzI,MAAOyI,EAAa,KACpBxI,OAAQwI,EAAa,KACrBR,aAAc,MACdC,OAAQ,UACRvC,SACAwC,YAAa,QAEfC,MAAO,CAAE,mBAAoBO,KAGnC,CI1DiBC,CAA2B7B,EAAYE,EAAUF,EAAWlK,UAC7DkL,IAAI,CAACO,EAAGK,KAAA,CAClBJ,IAAKI,EACLtD,MAAOiD,EAAEjD,SACNb,EAAkBmE,MACjBL,EAAEF,OAAS,CAAA,MACX,MAAAhB,OAAA,EAAAA,EAAcuB,KAAM,CAAA,MAEzB,CACDzB,EACAH,EAAW3J,QAAQiD,OAAOnD,EAC1B6J,EAAW3J,QAAQiD,OAAOlD,EAC1B4J,EAAW3J,QAAQkD,KAAKN,MACxB+G,EAAW3J,QAAQkD,KAAKL,OACxB8G,EAAW/H,MACX+H,EAAWlK,SACX,MAAAoK,OAAA,EAAAA,EAAUwB,WACV,MAAAxB,OAAA,EAAAA,EAAUtB,OACVnB,EACA4C,IAIJ"}
|
package/dist/preact/index.js
CHANGED
|
@@ -49,6 +49,12 @@ function CounterRotate({ children, ...props }) {
|
|
|
49
49
|
}
|
|
50
50
|
}) });
|
|
51
51
|
}
|
|
52
|
+
function getAnchor(handle) {
|
|
53
|
+
return {
|
|
54
|
+
x: handle.includes("e") ? "left" : handle.includes("w") ? "right" : "center",
|
|
55
|
+
y: handle.includes("s") ? "top" : handle.includes("n") ? "bottom" : "center"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
52
58
|
class DragResizeController {
|
|
53
59
|
constructor(config, onUpdate) {
|
|
54
60
|
this.config = config;
|
|
@@ -306,134 +312,124 @@ class DragResizeController {
|
|
|
306
312
|
};
|
|
307
313
|
return this.applyConstraints(position);
|
|
308
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Calculate the new rect after a resize operation.
|
|
317
|
+
* Pipeline: applyDelta → enforceAspectRatio → clampToBounds → applyConstraints
|
|
318
|
+
*/
|
|
309
319
|
calculateResizePosition(delta, handle) {
|
|
310
|
-
var _a;
|
|
311
320
|
if (!this.startElement) return this.config.element;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
case "se":
|
|
318
|
-
width += delta.x;
|
|
319
|
-
height += delta.y;
|
|
320
|
-
break;
|
|
321
|
-
case "sw":
|
|
322
|
-
x += delta.x;
|
|
323
|
-
width -= delta.x;
|
|
324
|
-
height += delta.y;
|
|
325
|
-
break;
|
|
326
|
-
case "ne":
|
|
327
|
-
width += delta.x;
|
|
328
|
-
y += delta.y;
|
|
329
|
-
height -= delta.y;
|
|
330
|
-
break;
|
|
331
|
-
case "nw":
|
|
332
|
-
x += delta.x;
|
|
333
|
-
width -= delta.x;
|
|
334
|
-
y += delta.y;
|
|
335
|
-
height -= delta.y;
|
|
336
|
-
break;
|
|
337
|
-
case "n":
|
|
338
|
-
y += delta.y;
|
|
339
|
-
height -= delta.y;
|
|
340
|
-
break;
|
|
341
|
-
case "s":
|
|
342
|
-
height += delta.y;
|
|
343
|
-
break;
|
|
344
|
-
case "e":
|
|
345
|
-
width += delta.x;
|
|
346
|
-
break;
|
|
347
|
-
case "w":
|
|
348
|
-
x += delta.x;
|
|
349
|
-
width -= delta.x;
|
|
350
|
-
break;
|
|
321
|
+
const anchor = getAnchor(handle);
|
|
322
|
+
const aspectRatio = this.startElement.size.width / this.startElement.size.height || 1;
|
|
323
|
+
let rect = this.applyResizeDelta(delta, anchor);
|
|
324
|
+
if (this.config.maintainAspectRatio) {
|
|
325
|
+
rect = this.enforceAspectRatio(rect, anchor, aspectRatio);
|
|
351
326
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
327
|
+
rect = this.clampToBounds(rect, anchor, aspectRatio);
|
|
328
|
+
return this.applyConstraints(rect);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Apply the mouse delta to produce a raw (unconstrained) resized rect.
|
|
332
|
+
*/
|
|
333
|
+
applyResizeDelta(delta, anchor) {
|
|
334
|
+
const start = this.startElement;
|
|
335
|
+
let x = start.origin.x;
|
|
336
|
+
let y = start.origin.y;
|
|
337
|
+
let width = start.size.width;
|
|
338
|
+
let height = start.size.height;
|
|
339
|
+
if (anchor.x === "left") {
|
|
340
|
+
width += delta.x;
|
|
341
|
+
} else if (anchor.x === "right") {
|
|
342
|
+
x += delta.x;
|
|
343
|
+
width -= delta.x;
|
|
344
|
+
}
|
|
345
|
+
if (anchor.y === "top") {
|
|
346
|
+
height += delta.y;
|
|
347
|
+
} else if (anchor.y === "bottom") {
|
|
348
|
+
y += delta.y;
|
|
349
|
+
height -= delta.y;
|
|
350
|
+
}
|
|
351
|
+
return { origin: { x, y }, size: { width, height } };
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Enforce aspect ratio while respecting the anchor.
|
|
355
|
+
* For edge handles (center anchor on one axis), the rect expands symmetrically on that axis.
|
|
356
|
+
* For corner handles, the anchor corner stays fixed.
|
|
357
|
+
*/
|
|
358
|
+
enforceAspectRatio(rect, anchor, aspectRatio) {
|
|
359
|
+
const start = this.startElement;
|
|
360
|
+
let { x, y } = rect.origin;
|
|
361
|
+
let { width, height } = rect.size;
|
|
362
|
+
const isEdgeHandle = anchor.x === "center" || anchor.y === "center";
|
|
363
|
+
if (isEdgeHandle) {
|
|
364
|
+
if (anchor.y === "center") {
|
|
365
|
+
height = width / aspectRatio;
|
|
366
|
+
y = start.origin.y + (start.size.height - height) / 2;
|
|
369
367
|
} else {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (widthChange > heightChange) {
|
|
373
|
-
height = width / aspectRatio;
|
|
374
|
-
} else {
|
|
375
|
-
width = height * aspectRatio;
|
|
376
|
-
}
|
|
377
|
-
if (handle.includes("w")) {
|
|
378
|
-
x = this.startElement.origin.x + this.startElement.size.width - width;
|
|
379
|
-
}
|
|
380
|
-
if (handle.includes("n")) {
|
|
381
|
-
y = this.startElement.origin.y + this.startElement.size.height - height;
|
|
382
|
-
}
|
|
368
|
+
width = height * aspectRatio;
|
|
369
|
+
x = start.origin.x + (start.size.width - width) / 2;
|
|
383
370
|
}
|
|
371
|
+
} else {
|
|
372
|
+
const dw = Math.abs(width - start.size.width);
|
|
373
|
+
const dh = Math.abs(height - start.size.height);
|
|
374
|
+
if (dw >= dh) {
|
|
375
|
+
height = width / aspectRatio;
|
|
376
|
+
} else {
|
|
377
|
+
width = height * aspectRatio;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (anchor.x === "right") {
|
|
381
|
+
x = start.origin.x + start.size.width - width;
|
|
382
|
+
}
|
|
383
|
+
if (anchor.y === "bottom") {
|
|
384
|
+
y = start.origin.y + start.size.height - height;
|
|
384
385
|
}
|
|
386
|
+
return { origin: { x, y }, size: { width, height } };
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Clamp rect to bounding box while respecting anchor and aspect ratio.
|
|
390
|
+
*/
|
|
391
|
+
clampToBounds(rect, anchor, aspectRatio) {
|
|
392
|
+
var _a;
|
|
385
393
|
const bbox = (_a = this.config.constraints) == null ? void 0 : _a.boundingBox;
|
|
386
|
-
if (bbox)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
break;
|
|
404
|
-
case "n":
|
|
405
|
-
if (y < 0) {
|
|
406
|
-
height += y;
|
|
407
|
-
y = 0;
|
|
408
|
-
}
|
|
409
|
-
break;
|
|
410
|
-
case "sw":
|
|
411
|
-
if (x < 0) {
|
|
412
|
-
width += x;
|
|
413
|
-
x = 0;
|
|
414
|
-
}
|
|
415
|
-
height = Math.min(height, bbox.height - y);
|
|
416
|
-
break;
|
|
417
|
-
case "nw":
|
|
418
|
-
if (x < 0) {
|
|
419
|
-
width += x;
|
|
420
|
-
x = 0;
|
|
421
|
-
}
|
|
422
|
-
if (y < 0) {
|
|
423
|
-
height += y;
|
|
424
|
-
y = 0;
|
|
425
|
-
}
|
|
426
|
-
break;
|
|
427
|
-
case "ne":
|
|
428
|
-
width = Math.min(width, bbox.width - x);
|
|
429
|
-
if (y < 0) {
|
|
430
|
-
height += y;
|
|
431
|
-
y = 0;
|
|
432
|
-
}
|
|
433
|
-
break;
|
|
394
|
+
if (!bbox) return rect;
|
|
395
|
+
const start = this.startElement;
|
|
396
|
+
let { x, y } = rect.origin;
|
|
397
|
+
let { width, height } = rect.size;
|
|
398
|
+
width = Math.max(1, width);
|
|
399
|
+
height = Math.max(1, height);
|
|
400
|
+
const anchorX = anchor.x === "left" ? start.origin.x : start.origin.x + start.size.width;
|
|
401
|
+
const anchorY = anchor.y === "top" ? start.origin.y : start.origin.y + start.size.height;
|
|
402
|
+
const maxW = anchor.x === "left" ? bbox.width - anchorX : anchor.x === "right" ? anchorX : Math.min(start.origin.x, bbox.width - start.origin.x - start.size.width) * 2 + start.size.width;
|
|
403
|
+
const maxH = anchor.y === "top" ? bbox.height - anchorY : anchor.y === "bottom" ? anchorY : Math.min(start.origin.y, bbox.height - start.origin.y - start.size.height) * 2 + start.size.height;
|
|
404
|
+
if (this.config.maintainAspectRatio) {
|
|
405
|
+
const scaleW = width > maxW ? maxW / width : 1;
|
|
406
|
+
const scaleH = height > maxH ? maxH / height : 1;
|
|
407
|
+
const scale = Math.min(scaleW, scaleH);
|
|
408
|
+
if (scale < 1) {
|
|
409
|
+
width *= scale;
|
|
410
|
+
height *= scale;
|
|
434
411
|
}
|
|
412
|
+
} else {
|
|
413
|
+
width = Math.min(width, maxW);
|
|
414
|
+
height = Math.min(height, maxH);
|
|
435
415
|
}
|
|
436
|
-
|
|
416
|
+
if (anchor.x === "left") {
|
|
417
|
+
x = anchorX;
|
|
418
|
+
} else if (anchor.x === "right") {
|
|
419
|
+
x = anchorX - width;
|
|
420
|
+
} else {
|
|
421
|
+
x = start.origin.x + (start.size.width - width) / 2;
|
|
422
|
+
}
|
|
423
|
+
if (anchor.y === "top") {
|
|
424
|
+
y = anchorY;
|
|
425
|
+
} else if (anchor.y === "bottom") {
|
|
426
|
+
y = anchorY - height;
|
|
427
|
+
} else {
|
|
428
|
+
y = start.origin.y + (start.size.height - height) / 2;
|
|
429
|
+
}
|
|
430
|
+
x = Math.max(0, Math.min(x, bbox.width - width));
|
|
431
|
+
y = Math.max(0, Math.min(y, bbox.height - height));
|
|
432
|
+
return { origin: { x, y }, size: { width, height } };
|
|
437
433
|
}
|
|
438
434
|
applyConstraints(position) {
|
|
439
435
|
const { constraints } = this.config;
|
|
@@ -442,10 +438,34 @@ class DragResizeController {
|
|
|
442
438
|
origin: { x, y },
|
|
443
439
|
size: { width, height }
|
|
444
440
|
} = position;
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
441
|
+
const minW = constraints.minWidth ?? 1;
|
|
442
|
+
const minH = constraints.minHeight ?? 1;
|
|
443
|
+
const maxW = constraints.maxWidth;
|
|
444
|
+
const maxH = constraints.maxHeight;
|
|
445
|
+
if (this.config.maintainAspectRatio && width > 0 && height > 0) {
|
|
446
|
+
const ratio = width / height;
|
|
447
|
+
if (width < minW) {
|
|
448
|
+
width = minW;
|
|
449
|
+
height = width / ratio;
|
|
450
|
+
}
|
|
451
|
+
if (height < minH) {
|
|
452
|
+
height = minH;
|
|
453
|
+
width = height * ratio;
|
|
454
|
+
}
|
|
455
|
+
if (maxW !== void 0 && width > maxW) {
|
|
456
|
+
width = maxW;
|
|
457
|
+
height = width / ratio;
|
|
458
|
+
}
|
|
459
|
+
if (maxH !== void 0 && height > maxH) {
|
|
460
|
+
height = maxH;
|
|
461
|
+
width = height * ratio;
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
width = Math.max(minW, width);
|
|
465
|
+
height = Math.max(minH, height);
|
|
466
|
+
if (maxW !== void 0) width = Math.min(maxW, width);
|
|
467
|
+
if (maxH !== void 0) height = Math.min(maxH, height);
|
|
468
|
+
}
|
|
449
469
|
if (constraints.boundingBox) {
|
|
450
470
|
x = Math.max(0, Math.min(x, constraints.boundingBox.width - width));
|
|
451
471
|
y = Math.max(0, Math.min(y, constraints.boundingBox.height - height));
|