@wordpress/media-editor 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/media-editor/index.cjs.map +1 -1
  3. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  4. package/build/components/media-editor-canvas/index.cjs +63 -15
  5. package/build/components/media-editor-canvas/index.cjs.map +3 -3
  6. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  7. package/build/components/media-editor-image-controls/index.cjs +2 -2
  8. package/build/components/media-editor-image-controls/index.cjs.map +2 -2
  9. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
  10. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
  11. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
  12. package/build/components/rotation-ruler/index.cjs +1 -1
  13. package/build/components/rotation-ruler/index.cjs.map +1 -1
  14. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  15. package/build/image-editor/core/camera.cjs +13 -0
  16. package/build/image-editor/core/camera.cjs.map +2 -2
  17. package/build/image-editor/core/constants.cjs +12 -3
  18. package/build/image-editor/core/constants.cjs.map +2 -2
  19. package/build/image-editor/core/containment.cjs.map +1 -1
  20. package/build/image-editor/core/crop-rect.cjs.map +1 -1
  21. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
  22. package/build/image-editor/core/interaction-controller.cjs +9 -7
  23. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  24. package/build/image-editor/core/math/sanitize.cjs.map +1 -1
  25. package/build/image-editor/core/setter-helpers.cjs.map +1 -1
  26. package/build/image-editor/core/source-region.cjs +111 -2
  27. package/build/image-editor/core/source-region.cjs.map +2 -2
  28. package/build/image-editor/core/state.cjs.map +1 -1
  29. package/build/image-editor/core/stencil-math.cjs +3 -4
  30. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  31. package/build/image-editor/core/transform-style.cjs.map +1 -1
  32. package/build/image-editor/core/types.cjs.map +1 -1
  33. package/build/image-editor/react/components/cropper.cjs +232 -55
  34. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  35. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
  36. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
  37. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  38. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
  39. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  40. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
  41. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
  42. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
  43. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
  44. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
  45. package/build/index.cjs.map +1 -1
  46. package/build/state/types.cjs.map +1 -1
  47. package/build/state/use-media-editor-state.cjs +1 -1
  48. package/build/state/use-media-editor-state.cjs.map +2 -2
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  51. package/build-module/components/media-editor-canvas/index.mjs +55 -17
  52. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  53. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  54. package/build-module/components/media-editor-image-controls/index.mjs +2 -2
  55. package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
  56. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
  57. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
  58. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
  59. package/build-module/components/rotation-ruler/index.mjs +1 -1
  60. package/build-module/components/rotation-ruler/index.mjs.map +1 -1
  61. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
  62. package/build-module/image-editor/core/camera.mjs +12 -0
  63. package/build-module/image-editor/core/camera.mjs.map +2 -2
  64. package/build-module/image-editor/core/constants.mjs +8 -2
  65. package/build-module/image-editor/core/constants.mjs.map +2 -2
  66. package/build-module/image-editor/core/containment.mjs.map +1 -1
  67. package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
  68. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
  69. package/build-module/image-editor/core/interaction-controller.mjs +9 -7
  70. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  71. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
  72. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
  73. package/build-module/image-editor/core/source-region.mjs +108 -1
  74. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  75. package/build-module/image-editor/core/state.mjs.map +1 -1
  76. package/build-module/image-editor/core/stencil-math.mjs +3 -4
  77. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  78. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  79. package/build-module/image-editor/react/components/cropper.mjs +242 -57
  80. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  81. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
  82. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
  83. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  84. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +65 -19
  85. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  86. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
  87. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
  88. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
  89. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
  90. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
  91. package/build-module/index.mjs.map +1 -1
  92. package/build-module/state/types.mjs.map +1 -1
  93. package/build-module/state/use-media-editor-state.mjs +1 -1
  94. package/build-module/state/use-media-editor-state.mjs.map +2 -2
  95. package/build-style/style-rtl.css +49 -6
  96. package/build-style/style.css +49 -6
  97. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  98. package/build-types/image-editor/core/camera.d.ts +25 -1
  99. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  100. package/build-types/image-editor/core/constants.d.ts +20 -1
  101. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  102. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  103. package/build-types/image-editor/core/source-region.d.ts +23 -1
  104. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  105. package/build-types/image-editor/core/stencil-math.d.ts +10 -5
  106. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  107. package/build-types/image-editor/core/types.d.ts +14 -0
  108. package/build-types/image-editor/core/types.d.ts.map +1 -1
  109. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  110. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  111. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
  112. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  113. package/package.json +25 -20
  114. package/src/components/media-editor/style.scss +21 -9
  115. package/src/components/media-editor-canvas/index.tsx +82 -13
  116. package/src/components/media-editor-canvas/style.scss +41 -0
  117. package/src/image-editor/core/camera.ts +60 -1
  118. package/src/image-editor/core/constants.ts +23 -1
  119. package/src/image-editor/core/interaction-controller.ts +25 -11
  120. package/src/image-editor/core/source-region.ts +202 -1
  121. package/src/image-editor/core/stencil-math.ts +23 -14
  122. package/src/image-editor/core/test/camera.ts +272 -1
  123. package/src/image-editor/core/test/interaction-controller.ts +100 -0
  124. package/src/image-editor/core/test/stencil-math.ts +120 -6
  125. package/src/image-editor/core/types.ts +17 -0
  126. package/src/image-editor/react/components/cropper.tsx +362 -72
  127. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
  128. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
  129. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
  130. package/src/image-editor/react/components/test/cropper.tsx +689 -6
  131. package/tsconfig.tsbuildinfo +1 -1
  132. package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
  133. package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
  134. package/build-types/components/media-editor-transform-controls/index.d.ts +0 -21
  135. package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
  136. package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
  137. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
  138. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
  139. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/interaction-controller.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, Size } from './types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tDEFAULT_WHEEL_ZOOM_SPEED,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n\tMIN_ZOOM,\n\tMAX_ZOOM,\n} from './constants';\nimport { restrictPanZoom } from './containment';\n\n/** Time window for detecting a double-tap gesture (ms). */\nconst DOUBLE_TAP_TIME = 300;\n/** Max distance between taps to count as a double-tap (px). */\nconst DOUBLE_TAP_DISTANCE = 30;\n/** Duration of the zoom animation state (ms). */\nconst ZOOM_ANIMATION_DURATION = 200;\n\n/**\n * Get the natural image dimensions from cropper state, falling back to 1x1.\n *\n * @param state The current cropper state.\n * @return The image dimensions.\n */\nfunction getImageSizeFromState( state: CropperState ): {\n\twidth: number;\n\theight: number;\n} {\n\treturn state.image\n\t\t? { width: state.image.naturalWidth, height: state.image.naturalHeight }\n\t\t: { width: 1, height: 1 };\n}\n\n/**\n * Get the distance between two touch points.\n *\n * @param t1 The first touch.\n * @param t2 The second touch.\n * @return The pixel distance between the two touches.\n */\nfunction getTouchDistance( t1: Touch, t2: Touch ): number {\n\tconst dx = t1.clientX - t2.clientX;\n\tconst dy = t1.clientY - t2.clientY;\n\treturn Math.sqrt( dx * dx + dy * dy );\n}\n\n/**\n * Status reported by the interaction controller when drag/zoom state changes.\n */\nexport interface InteractionStatus {\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n}\n\n/**\n * State updates the interaction controller can request from its host UI.\n */\nexport interface CropperInteractionActions {\n\t/** Set the image pan offset in normalized coordinates. */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/**\n\t * Set the zoom level. Cursorless surfaces (slider, keyboard `+`/`-`)\n\t * rely on this anchoring at the crop center; pointer-driven zoom\n\t * paths use `setZoomAtPoint` with an explicit focal point instead.\n\t */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together for focal-point zoom. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Snap rotate by 90 degrees. */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;\n}\n\n/**\n * Options for creating an InteractionController.\n *\n * Scalar options (minZoom, maxZoom, etc.) are read lazily on each\n * interaction, so changes to the options object take effect immediately\n * without recreating the controller.\n */\nexport interface InteractionControllerOptions {\n\t/** Returns the current cropper state. Called on every interaction. */\n\tgetState: () => CropperState;\n\t/** State updates the interaction controller can request from its host UI. */\n\tactions: CropperInteractionActions;\n\t/** Returns the container dimensions in pixels. */\n\tgetContainerSize: () => Size;\n\t/** Returns the rendered image dimensions in pixels, if available. */\n\tgetImageSize: () => Size | undefined;\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Read lazily. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/** Called when isDragging or isZooming changes. */\n\tonStatusChange?: ( status: InteractionStatus ) => void;\n}\n\n/**\n * Framework-agnostic imperative controller for image cropper interactions.\n *\n * Handles mouse, touch, and keyboard event processing for pan, zoom,\n * and crop manipulation. Uses requestAnimationFrame for drag/pinch\n * updates to avoid layout thrashing.\n *\n * The controller does not register DOM event listeners itself \u2014 that is the\n * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).\n * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,\n * and `handleKeyDown` methods that the UI layer calls with native DOM events.\n *\n * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)\n * are read lazily from `this.options` on each interaction, so the UI layer\n * can update them without recreating the controller.\n *\n * Call `destroy()` to clean up timers and pending animation frames.\n */\nexport class InteractionController {\n\tprivate readonly options: InteractionControllerOptions;\n\n\t/** Current drag/zoom status. */\n\tprivate isDragging = false;\n\tprivate isZooming = false;\n\n\t/** Active drag state during pointer interactions. */\n\tprivate drag: {\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t} | null = null;\n\n\t/** Active touch state during touch interactions. */\n\tprivate touch: {\n\t\t/** Finger distance at pinch start (0 until pinch detected). */\n\t\tstartDistance: number;\n\t\t/** Zoom level when pinch was detected. */\n\t\tstartZoom: number;\n\t\t/** First touch X/Y (for single-finger pan delta). */\n\t\tlastTouchX: number;\n\t\tlastTouchY: number;\n\t\t/** Pan when gesture started. */\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t\t/** Container rect snapshot for focal-point math. */\n\t\tcontainerRect?: DOMRect;\n\t\t/** Midpoint of two fingers when pinch was detected. */\n\t\tstartMidX: number;\n\t\tstartMidY: number;\n\t\t/** Whether pinch was ever detected during this gesture. */\n\t\tdidPinch: boolean;\n\t\t/** Whether any dispatch has occurred (prevents dispatching before first move). */\n\t\tmoved: boolean;\n\t} | null = null;\n\n\t/** Cleanup function for active touch listeners on document. */\n\tprivate touchCleanup: ( () => void ) | null = null;\n\n\t/**\n\t * Cleanup function for active pointer-drag listeners on the\n\t * captured element. Set while a pointer drag is in progress so\n\t * `destroy()` can tear the drag down cleanly if the consumer\n\t * unmounts mid-drag. Cleared on pointerup/lostpointercapture.\n\t */\n\tprivate pointerCleanup: ( () => void ) | null = null;\n\n\t/** Last tap info for double-tap detection. */\n\tprivate lastTap: {\n\t\ttime: number;\n\t\tx: number;\n\t\ty: number;\n\t} | null = null;\n\n\t/** Timer for the zoom animation state (double-tap). */\n\tprivate zoomTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Timer for wheel gesture debounce. */\n\tprivate wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Whether a wheel gesture is currently active. */\n\tprivate wheelGestureActive = false;\n\n\t/** Current requestAnimationFrame ID. */\n\tprivate rafId = 0;\n\n\tconstructor( options: InteractionControllerOptions ) {\n\t\tthis.options = options;\n\t}\n\n\t/** Read minZoom lazily so option changes take effect immediately. */\n\tprivate get minZoom(): number {\n\t\treturn this.options.minZoom ?? MIN_ZOOM;\n\t}\n\n\t/** Read maxZoom lazily so option changes take effect immediately. */\n\tprivate get maxZoom(): number {\n\t\treturn this.options.maxZoom ?? MAX_ZOOM;\n\t}\n\n\t/** Read zoomSpeed lazily so option changes take effect immediately. */\n\tprivate get zoomSpeed(): number {\n\t\treturn this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;\n\t}\n\n\t/** Read keyboardStep lazily so option changes take effect immediately. */\n\tprivate get keyboardStep(): number {\n\t\treturn this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;\n\t}\n\n\t/**\n\t * Get the keyboard pan step, including modifier-based coarse movement.\n\t *\n\t * @param event The native KeyboardEvent.\n\t * @return The normalized pan step.\n\t */\n\tprivate getKeyboardStep( event: KeyboardEvent ): number {\n\t\treturn event.shiftKey\n\t\t\t? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t: this.keyboardStep;\n\t}\n\n\t/** Read doubleTapZoom lazily so option changes take effect immediately. */\n\tprivate get doubleTapZoom(): number {\n\t\treturn this.options.doubleTapZoom ?? 2;\n\t}\n\n\t/**\n\t * Update the drag/zoom status and notify via callback if changed.\n\t *\n\t * @param update Partial status with isDragging and/or isZooming.\n\t */\n\tprivate setStatus(\n\t\tupdate: Partial< { isDragging: boolean; isZooming: boolean } >\n\t): void {\n\t\tlet changed = false;\n\t\tif (\n\t\t\tupdate.isDragging !== undefined &&\n\t\t\tupdate.isDragging !== this.isDragging\n\t\t) {\n\t\t\tthis.isDragging = update.isDragging;\n\t\t\tchanged = true;\n\t\t}\n\t\tif (\n\t\t\tupdate.isZooming !== undefined &&\n\t\t\tupdate.isZooming !== this.isZooming\n\t\t) {\n\t\t\tthis.isZooming = update.isZooming;\n\t\t\tchanged = true;\n\t\t}\n\t\tif ( changed ) {\n\t\t\tthis.options.onStatusChange?.( {\n\t\t\t\tisDragging: this.isDragging,\n\t\t\t\tisZooming: this.isZooming,\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a pointer-down event on the container element.\n\t *\n\t * Initiates a drag (pan) interaction. Captures the pointer on the\n\t * provided element and registers pointermove/pointerup/lostpointercapture\n\t * listeners for the duration of the drag.\n\t *\n\t * @param e The native PointerEvent.\n\t * @param el The DOM element to capture the pointer on.\n\t */\n\thandlePointerDown( e: PointerEvent, el: HTMLElement ): void {\n\t\t// Only handle primary button (left click / first touch).\n\t\tif ( e.button !== 0 ) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\n\t\t// Blur any focused handle so its focus ring doesn't linger,\n\t\t// but leave the canvas itself alone so keyboard control works after drag.\n\t\tconst ownerDoc = el.ownerDocument;\n\t\tif (\n\t\t\townerDoc?.activeElement instanceof HTMLElement &&\n\t\t\townerDoc.activeElement !== el\n\t\t) {\n\t\t\townerDoc.activeElement.blur();\n\t\t}\n\n\t\tel.focus();\n\n\t\t// Capture pointer so drag works across iframe boundaries.\n\t\tel.setPointerCapture( e.pointerId );\n\n\t\tthis.setStatus( { isDragging: true } );\n\t\tthis.options.onGestureStart?.();\n\n\t\tconst currentState = this.options.getState();\n\t\tthis.drag = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tstartPanX: currentState.pan.x,\n\t\t\tstartPanY: currentState.pan.y,\n\t\t};\n\n\t\tconst onPointerMove = ( moveEvent: Event ) => {\n\t\t\tconst drag = this.drag;\n\t\t\tif ( ! drag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pe = moveEvent as PointerEvent;\n\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\t\tconst s = this.options.getState();\n\t\t\t\tconst imgSize = this.options.getImageSize();\n\t\t\t\tconst containerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = imgSize ?? containerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( pe.clientX - drag.startX ) / panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( pe.clientY - drag.startY ) / panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: drag.startPanX + deltaX,\n\t\t\t\t\t\t\ty: drag.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t} );\n\t\t};\n\n\t\tconst removeListeners = () => {\n\t\t\tel.removeEventListener( 'pointermove', onPointerMove );\n\t\t\tel.removeEventListener( 'pointerup', onPointerUp );\n\t\t\tel.removeEventListener( 'lostpointercapture', onPointerUp );\n\t\t};\n\n\t\tconst onPointerUp = () => {\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t\tthis.drag = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tremoveListeners();\n\t\t\tthis.pointerCleanup = null;\n\t\t};\n\n\t\tel.addEventListener( 'pointermove', onPointerMove );\n\t\tel.addEventListener( 'pointerup', onPointerUp );\n\t\tel.addEventListener( 'lostpointercapture', onPointerUp );\n\t\t// Expose cleanup to destroy() in case the consumer unmounts\n\t\t// mid-drag. The pending rAF is cancelled in destroy().\n\t\tthis.pointerCleanup = removeListeners;\n\t}\n\n\t/**\n\t * Handle a wheel event on the container element.\n\t *\n\t * Implements focal-point zoom: the point under the cursor stays\n\t * stationary on screen while the zoom level changes.\n\t *\n\t * Must be registered with `{ passive: false }` to allow preventDefault.\n\t *\n\t * @param e The native WheelEvent.\n\t */\n\thandleWheel( e: WheelEvent ): void {\n\t\te.preventDefault();\n\n\t\tif ( this.drag ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Debounced gesture boundaries for wheel zoom.\n\t\t// Start on first wheel event, end after 300ms of no events.\n\t\tif ( ! this.wheelGestureActive ) {\n\t\t\tthis.wheelGestureActive = true;\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.wheelGestureTimer = setTimeout( () => {\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}, DOUBLE_TAP_TIME );\n\n\t\tconst s = this.options.getState();\n\t\tconst delta = -e.deltaY * this.zoomSpeed;\n\t\tconst newZoom = Math.min(\n\t\t\tthis.maxZoom,\n\t\t\tMath.max( this.minZoom, s.zoom + delta )\n\t\t);\n\n\t\tif ( newZoom === s.zoom ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Focal-point zoom: keep the point under the cursor stationary.\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\t\tconst visSize = imgSize ?? containerSize;\n\t\tconst target = e.currentTarget;\n\t\tconst rect =\n\t\t\ttarget instanceof Element\n\t\t\t\t? target.getBoundingClientRect()\n\t\t\t\t: undefined;\n\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\tconst fx = e.clientX - rect.left - containerSize.width / 2;\n\t\t\tconst fy = e.clientY - rect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - newZoom / s.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\tconst newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },\n\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\ts.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a touch-start event on the container element.\n\t *\n\t * Supports single-finger pan, two-finger pinch zoom, and\n\t * double-tap to toggle between fit and 2x zoom. Registers\n\t * touchmove/touchend/touchcancel on the provided document for the\n\t * duration of the gesture.\n\t *\n\t * @param e The native TouchEvent.\n\t * @param containerRect The bounding rect of the container element.\n\t * @param doc The document to register move/end listeners on.\n\t * Defaults to globalThis.document. Pass the iframe's\n\t * contentDocument when running inside an iframe.\n\t */\n\thandleTouchStart(\n\t\te: TouchEvent,\n\t\tcontainerRect: DOMRect,\n\t\tdoc: Document = document\n\t): void {\n\t\t// Second finger arriving during an existing gesture \u2014 snapshot\n\t\t// pinch start values. handleTouchMove will detect 2 touches and\n\t\t// handle pinch automatically.\n\t\tif ( this.touch && e.touches.length === 2 ) {\n\t\t\tconst s = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch.didPinch = true;\n\t\t\tthis.touch.startDistance = distance;\n\t\t\tthis.touch.startZoom = s.zoom;\n\t\t\tthis.touch.startPanX = s.pan.x;\n\t\t\tthis.touch.startPanY = s.pan.y;\n\t\t\tthis.touch.startMidX = midX;\n\t\t\tthis.touch.startMidY = midY;\n\t\t\tthis.touch.containerRect = containerRect;\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( e.touches.length === 1 ) {\n\t\t\tconst tapX = e.touches[ 0 ].clientX;\n\t\t\tconst tapY = e.touches[ 0 ].clientY;\n\t\t\tif ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentState = this.options.getState();\n\n\t\t\t// Record touch state. Don't decide pan vs pinch yet \u2014\n\t\t\t// that happens in handleTouchMove based on touches.length.\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: 0,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: e.touches[ 0 ].clientX,\n\t\t\t\tlastTouchY: e.touches[ 0 ].clientY,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: 0,\n\t\t\t\tstartMidY: 0,\n\t\t\t\tdidPinch: false,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t} else if ( e.touches.length === 2 ) {\n\t\t\t// Both fingers landed simultaneously (rare but possible).\n\t\t\tconst currentState = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: distance,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: 0,\n\t\t\t\tlastTouchY: 0,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: midX,\n\t\t\t\tstartMidY: midY,\n\t\t\t\tdidPinch: true,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\n\t\tconst onTouchEnd = () => {\n\t\t\tthis.touch = null;\n\t\t\tthis.touchCleanup = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tdoc.removeEventListener( 'touchmove', this.handleTouchMove );\n\t\t\tdoc.removeEventListener( 'touchend', onTouchEnd );\n\t\t\tdoc.removeEventListener( 'touchcancel', onTouchEnd );\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t};\n\n\t\t// Clean up any previous touch listeners before registering new ones.\n\t\tthis.touchCleanup?.();\n\n\t\tdoc.addEventListener( 'touchmove', this.handleTouchMove, {\n\t\t\tpassive: false,\n\t\t} );\n\t\tdoc.addEventListener( 'touchend', onTouchEnd );\n\t\tdoc.addEventListener( 'touchcancel', onTouchEnd );\n\n\t\tthis.touchCleanup = onTouchEnd;\n\t}\n\n\t// Handle a touchmove event during an active touch gesture. Decides pinch\n\t// vs. pan based on current `moveEvent.touches.length`, so the gesture\n\t// can transition between modes without timing sensitivity (e.g. fingers\n\t// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays\n\t// attached when used as an event listener.\n\tprivate handleTouchMove = ( moveEvent: TouchEvent ): void => {\n\t\tconst touch = this.touch;\n\t\tif ( ! touch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcancelAnimationFrame( this.rafId );\n\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\tconst s = this.options.getState();\n\n\t\t\tif ( moveEvent.touches.length === 2 ) {\n\t\t\t\t// Two fingers \u2192 always pinch, regardless of how gesture\n\t\t\t\t// started. Initialize pinch state on first 2-finger move.\n\t\t\t\tif ( ! touch.didPinch ) {\n\t\t\t\t\ttouch.didPinch = true;\n\t\t\t\t\ttouch.startDistance = getTouchDistance(\n\t\t\t\t\t\tmoveEvent.touches[ 0 ],\n\t\t\t\t\t\tmoveEvent.touches[ 1 ]\n\t\t\t\t\t);\n\t\t\t\t\ttouch.startZoom = s.zoom;\n\t\t\t\t\ttouch.startPanX = s.pan.x;\n\t\t\t\t\ttouch.startPanY = s.pan.y;\n\t\t\t\t\ttouch.startMidX =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientX +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientX ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\ttouch.startMidY =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientY +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientY ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst latestContainerSize = this.options.getContainerSize();\n\t\t\t\tconst latestImageSize = this.options.getImageSize();\n\n\t\t\t\t// Pinch zoom with focal point at finger midpoint,\n\t\t\t\t// plus simultaneous pan from midpoint drift.\n\t\t\t\tconst t0 = moveEvent.touches[ 0 ];\n\t\t\t\tconst t1 = moveEvent.touches[ 1 ];\n\t\t\t\tconst currentDistance = getTouchDistance( t0, t1 );\n\t\t\t\tconst ratio = currentDistance / touch.startDistance;\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, touch.startZoom * ratio )\n\t\t\t\t);\n\n\t\t\t\tconst visSize = latestImageSize ?? latestContainerSize;\n\t\t\t\tconst rect = touch.containerRect;\n\t\t\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\t\t\t// Current midpoint.\n\t\t\t\t\tconst mx =\n\t\t\t\t\t\t( t0.clientX + t1.clientX ) / 2 -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst my =\n\t\t\t\t\t\t( t0.clientY + t1.clientY ) / 2 -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\n\t\t\t\t\t// Pan from midpoint drift (fingers moving together).\n\t\t\t\t\tconst startMx =\n\t\t\t\t\t\ttouch.startMidX -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst startMy =\n\t\t\t\t\t\ttouch.startMidY -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\t\t\t\t\tconst panDx =\n\t\t\t\t\t\tvisSize.width > 0\n\t\t\t\t\t\t\t? ( mx - startMx ) / visSize.width\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst panDy =\n\t\t\t\t\t\tvisSize.height > 0\n\t\t\t\t\t\t\t? ( my - startMy ) / visSize.height\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\t// Focal-point zoom correction.\n\t\t\t\t\tconst zoomRatio = s.zoom !== 0 ? 1 - newZoom / s.zoom : 0;\n\t\t\t\t\tconst focalNormX = mx / visSize.width;\n\t\t\t\t\tconst focalNormY = my / visSize.height;\n\t\t\t\t\tconst zoomCropX =\n\t\t\t\t\t\ts.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\t\t\tconst zoomCropY =\n\t\t\t\t\t\ts.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\t\t\t// Combined: pan drift + zoom correction.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX + panDx + ( zoomCropX - s.pan.x );\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY + panDy + ( zoomCropY - s.pan.y );\n\n\t\t\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...s,\n\t\t\t\t\t\t\tzoom: newZoom,\n\t\t\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\t\ts.cropRect\n\t\t\t\t\t);\n\t\t\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t\t\t} else if ( newZoom !== s.zoom ) {\n\t\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\t}\n\t\t\t} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {\n\t\t\t\t// One finger and no pinch ever detected \u2192 pan.\n\t\t\t\t// If fingers went 2\u21921 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan \u2014 avoids accidental pan after releasing\n\t\t\t\t// one finger from a pinch.\n\t\t\t\tif ( ! touch.moved ) {\n\t\t\t\t\ttouch.moved = true;\n\t\t\t\t\tthis.setStatus( { isDragging: true } );\n\t\t\t\t}\n\t\t\t\tconst panImageSize = this.options.getImageSize();\n\t\t\t\tconst panContainerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = panImageSize ?? panContainerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientX -\n\t\t\t\t\t\t\t\ttouch.lastTouchX ) /\n\t\t\t\t\t\t panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientY -\n\t\t\t\t\t\t\t\ttouch.lastTouchY ) /\n\t\t\t\t\t\t panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: touch.startPanX + deltaX,\n\t\t\t\t\t\t\ty: touch.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Handle double-tap-to-toggle-zoom. On a second tap within the configured\n\t// time/distance threshold, toggles zoom between `minZoom` and\n\t// `doubleTapZoom` around the tap point and dispatches. Returns `true` if\n\t// the tap was handled as a double-tap (caller should early-return),\n\t// `false` otherwise (caller proceeds with normal single-tap handling).\n\t// Either way, records the tap for next time.\n\tprivate tryDoubleTap(\n\t\te: TouchEvent,\n\t\ttapX: number,\n\t\ttapY: number,\n\t\tcontainerRect: DOMRect\n\t): boolean {\n\t\tconst now = Date.now();\n\t\tconst lastTap = this.lastTap;\n\t\tif ( ! lastTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\t\tconst timeDelta = now - lastTap.time;\n\t\tconst distDelta = Math.sqrt(\n\t\t\t( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2\n\t\t);\n\t\tconst isDoubleTap =\n\t\t\ttimeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;\n\t\tif ( ! isDoubleTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\n\t\t// It's a double-tap \u2014 suppress browser zoom.\n\t\te.preventDefault();\n\t\tthis.lastTap = null;\n\n\t\tconst currentState = this.options.getState();\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\n\t\t// Toggle: if past halfway to doubleTapZoom, go back to 1x.\n\t\tconst targetZoom =\n\t\t\tcurrentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2\n\t\t\t\t? this.minZoom\n\t\t\t\t: this.doubleTapZoom;\n\t\tconst visSize = imgSize ?? containerSize;\n\n\t\t// Enable zoom animation before dispatching.\n\t\tthis.setStatus( { isZooming: true } );\n\t\tclearTimeout( this.zoomTimer );\n\t\tthis.zoomTimer = setTimeout( () => {\n\t\t\tthis.setStatus( { isZooming: false } );\n\t\t}, ZOOM_ANIMATION_DURATION );\n\n\t\t// Double-tap bypasses the normal handleTouchStart gesture path so\n\t\t// onGestureStart/End are never called \u2014 fire them here so undo\n\t\t// receives a proper boundary around this discrete zoom action.\n\t\tthis.options.onGestureStart?.();\n\n\t\tif ( visSize.width > 0 && visSize.height > 0 ) {\n\t\t\tconst fx = tapX - containerRect.left - containerSize.width / 2;\n\t\t\tconst fy = tapY - containerRect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - targetZoom / currentState.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX =\n\t\t\t\tcurrentState.pan.x +\n\t\t\t\t( focalNormX - currentState.pan.x ) * zoomRatio;\n\t\t\tconst newCropY =\n\t\t\t\tcurrentState.pan.y +\n\t\t\t\t( focalNormY - currentState.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{\n\t\t\t\t\t...currentState,\n\t\t\t\t\tzoom: targetZoom,\n\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t},\n\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\tcurrentState.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( targetZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( targetZoom );\n\t\t}\n\n\t\tthis.options.onGestureEnd?.();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a keydown event on the container element.\n\t *\n\t * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.\n\t *\n\t * @param e The native KeyboardEvent.\n\t */\n\thandleKeyDown( e: KeyboardEvent ): void {\n\t\tconst currentState = this.options.getState();\n\n\t\tswitch ( e.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y + keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y - keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x + keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x - keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '+':\n\t\t\tcase '=': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom + 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '-':\n\t\t\tcase '_': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom - 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'r':\n\t\t\tcase 'R': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'h':\n\t\t\tcase 'H': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'horizontal' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'v':\n\t\t\tcase 'V': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'vertical' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clean up all timers, animation frames, and active touch listeners.\n\t *\n\t * Must be called when the controller is no longer needed (e.g., on\n\t * component unmount or element removal).\n\t */\n\tdestroy(): void {\n\t\tcancelAnimationFrame( this.rafId );\n\t\tclearTimeout( this.zoomTimer );\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.touchCleanup?.();\n\t\tthis.touchCle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AA,MACD;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAgB;AACf,yBAAsB,KAAK,KAAM;AACjC,iBAAc,KAAK,SAAU;AAC7B,iBAAc,KAAK,iBAAkB;AACrC,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,iBAAiB;AACtB,SAAK,iBAAiB;AACtB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, Size } from './types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tDEFAULT_WHEEL_ZOOM_SPEED,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n\tMIN_ZOOM,\n\tMAX_ZOOM,\n} from './constants';\nimport { restrictPanZoom } from './containment';\n\n/** Time window for detecting a double-tap gesture (ms). */\nconst DOUBLE_TAP_TIME = 300;\n/** Max distance between taps to count as a double-tap (px). */\nconst DOUBLE_TAP_DISTANCE = 30;\n/** Duration of the zoom animation state (ms). */\nconst ZOOM_ANIMATION_DURATION = 200;\n\n/**\n * Get the natural image dimensions from cropper state, falling back to 1x1.\n *\n * @param state The current cropper state.\n * @return The image dimensions.\n */\nfunction getImageSizeFromState( state: CropperState ): {\n\twidth: number;\n\theight: number;\n} {\n\treturn state.image\n\t\t? { width: state.image.naturalWidth, height: state.image.naturalHeight }\n\t\t: { width: 1, height: 1 };\n}\n\n/**\n * Get the distance between two touch points.\n *\n * @param t1 The first touch.\n * @param t2 The second touch.\n * @return The pixel distance between the two touches.\n */\nfunction getTouchDistance( t1: Touch, t2: Touch ): number {\n\tconst dx = t1.clientX - t2.clientX;\n\tconst dy = t1.clientY - t2.clientY;\n\treturn Math.sqrt( dx * dx + dy * dy );\n}\n\n/**\n * Status reported by the interaction controller when drag/zoom state changes.\n */\nexport interface InteractionStatus {\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n}\n\n/**\n * State updates the interaction controller can request from its host UI.\n */\nexport interface CropperInteractionActions {\n\t/** Set the image pan offset in normalized coordinates. */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/**\n\t * Set the zoom level. Cursorless surfaces (slider, keyboard `+`/`-`)\n\t * rely on this anchoring at the crop center; pointer-driven zoom\n\t * paths use `setZoomAtPoint` with an explicit focal point instead.\n\t */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together for focal-point zoom. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Snap rotate by 90 degrees. */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;\n}\n\n/**\n * Options for creating an InteractionController.\n *\n * Scalar options (minZoom, maxZoom, etc.) are read lazily on each\n * interaction, so changes to the options object take effect immediately\n * without recreating the controller.\n */\nexport interface InteractionControllerOptions {\n\t/** Returns the current cropper state. Called on every interaction. */\n\tgetState: () => CropperState;\n\t/** State updates the interaction controller can request from its host UI. */\n\tactions: CropperInteractionActions;\n\t/** Returns the container dimensions in pixels. */\n\tgetContainerSize: () => Size;\n\t/** Returns the rendered image dimensions in pixels, if available. */\n\tgetImageSize: () => Size | undefined;\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Read lazily. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/** Called when isDragging or isZooming changes. */\n\tonStatusChange?: ( status: InteractionStatus ) => void;\n}\n\n/**\n * Framework-agnostic imperative controller for image cropper interactions.\n *\n * Handles mouse, touch, and keyboard event processing for pan, zoom,\n * and crop manipulation. Uses requestAnimationFrame for drag/pinch\n * updates to avoid layout thrashing.\n *\n * The controller does not register DOM event listeners itself — that is the\n * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).\n * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,\n * and `handleKeyDown` methods that the UI layer calls with native DOM events.\n *\n * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)\n * are read lazily from `this.options` on each interaction, so the UI layer\n * can update them without recreating the controller.\n *\n * Call `destroy()` to clean up timers and pending animation frames.\n */\nexport class InteractionController {\n\tprivate readonly options: InteractionControllerOptions;\n\n\t/** Current drag/zoom status. */\n\tprivate isDragging = false;\n\tprivate isZooming = false;\n\n\t/** Active drag state during pointer interactions. */\n\tprivate drag: {\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t} | null = null;\n\n\t/** Active touch state during touch interactions. */\n\tprivate touch: {\n\t\t/** Finger distance at pinch start (0 until pinch detected). */\n\t\tstartDistance: number;\n\t\t/** Zoom level when pinch was detected. */\n\t\tstartZoom: number;\n\t\t/** First touch X/Y (for single-finger pan delta). */\n\t\tlastTouchX: number;\n\t\tlastTouchY: number;\n\t\t/** Pan when gesture started. */\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t\t/** Container rect snapshot for focal-point math. */\n\t\tcontainerRect?: DOMRect;\n\t\t/** Midpoint of two fingers when pinch was detected. */\n\t\tstartMidX: number;\n\t\tstartMidY: number;\n\t\t/** Whether pinch was ever detected during this gesture. */\n\t\tdidPinch: boolean;\n\t\t/** Whether any dispatch has occurred (prevents dispatching before first move). */\n\t\tmoved: boolean;\n\t} | null = null;\n\n\t/** Cleanup function for active touch listeners on document. */\n\tprivate touchCleanup: ( () => void ) | null = null;\n\n\t/**\n\t * Cleanup function for active pointer-drag listeners on the\n\t * captured element. Set while a pointer drag is in progress so\n\t * `destroy()` can tear the drag down cleanly if the consumer\n\t * unmounts mid-drag. Cleared on pointerup/lostpointercapture.\n\t */\n\tprivate pointerCleanup: ( () => void ) | null = null;\n\n\t/** Last tap info for double-tap detection. */\n\tprivate lastTap: {\n\t\ttime: number;\n\t\tx: number;\n\t\ty: number;\n\t} | null = null;\n\n\t/** Timer for the zoom animation state (double-tap). */\n\tprivate zoomTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Timer for wheel gesture debounce. */\n\tprivate wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Whether a wheel gesture is currently active. */\n\tprivate wheelGestureActive = false;\n\n\t/** Current requestAnimationFrame ID. */\n\tprivate rafId = 0;\n\n\tconstructor( options: InteractionControllerOptions ) {\n\t\tthis.options = options;\n\t}\n\n\t/** Read minZoom lazily so option changes take effect immediately. */\n\tprivate get minZoom(): number {\n\t\treturn this.options.minZoom ?? MIN_ZOOM;\n\t}\n\n\t/** Read maxZoom lazily so option changes take effect immediately. */\n\tprivate get maxZoom(): number {\n\t\treturn this.options.maxZoom ?? MAX_ZOOM;\n\t}\n\n\t/** Read zoomSpeed lazily so option changes take effect immediately. */\n\tprivate get zoomSpeed(): number {\n\t\treturn this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;\n\t}\n\n\t/** Read keyboardStep lazily so option changes take effect immediately. */\n\tprivate get keyboardStep(): number {\n\t\treturn this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;\n\t}\n\n\t/**\n\t * Get the keyboard pan step, including modifier-based coarse movement.\n\t *\n\t * @param event The native KeyboardEvent.\n\t * @return The normalized pan step.\n\t */\n\tprivate getKeyboardStep( event: KeyboardEvent ): number {\n\t\treturn event.shiftKey\n\t\t\t? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t: this.keyboardStep;\n\t}\n\n\t/** Read doubleTapZoom lazily so option changes take effect immediately. */\n\tprivate get doubleTapZoom(): number {\n\t\treturn this.options.doubleTapZoom ?? 2;\n\t}\n\n\t/**\n\t * Update the drag/zoom status and notify via callback if changed.\n\t *\n\t * @param update Partial status with isDragging and/or isZooming.\n\t */\n\tprivate setStatus(\n\t\tupdate: Partial< { isDragging: boolean; isZooming: boolean } >\n\t): void {\n\t\tlet changed = false;\n\t\tif (\n\t\t\tupdate.isDragging !== undefined &&\n\t\t\tupdate.isDragging !== this.isDragging\n\t\t) {\n\t\t\tthis.isDragging = update.isDragging;\n\t\t\tchanged = true;\n\t\t}\n\t\tif (\n\t\t\tupdate.isZooming !== undefined &&\n\t\t\tupdate.isZooming !== this.isZooming\n\t\t) {\n\t\t\tthis.isZooming = update.isZooming;\n\t\t\tchanged = true;\n\t\t}\n\t\tif ( changed ) {\n\t\t\tthis.options.onStatusChange?.( {\n\t\t\t\tisDragging: this.isDragging,\n\t\t\t\tisZooming: this.isZooming,\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a pointer-down event on the container element.\n\t *\n\t * Initiates a drag (pan) interaction. Captures the pointer on the\n\t * provided element and registers pointermove/pointerup/lostpointercapture\n\t * listeners for the duration of the drag.\n\t *\n\t * @param e The native PointerEvent.\n\t * @param el The DOM element to capture the pointer on.\n\t */\n\thandlePointerDown( e: PointerEvent, el: HTMLElement ): void {\n\t\t// Only handle primary button (left click / first touch).\n\t\tif ( e.button !== 0 ) {\n\t\t\treturn;\n\t\t}\n\t\t// Touch gestures are handled by touchstart/touchmove. Starting the\n\t\t// pointer drag path too can briefly toggle drag UI before pinch begins.\n\t\tif ( e.pointerType === 'touch' ) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\n\t\t// Blur any focused handle so its focus ring doesn't linger,\n\t\t// but leave the canvas itself alone so keyboard control works after drag.\n\t\tconst ownerDoc = el.ownerDocument;\n\t\tif (\n\t\t\townerDoc?.activeElement instanceof HTMLElement &&\n\t\t\townerDoc.activeElement !== el\n\t\t) {\n\t\t\townerDoc.activeElement.blur();\n\t\t}\n\n\t\tel.focus();\n\n\t\t// Capture pointer so drag works across iframe boundaries.\n\t\tel.setPointerCapture( e.pointerId );\n\n\t\tthis.setStatus( { isDragging: true } );\n\t\tthis.options.onGestureStart?.();\n\n\t\tconst currentState = this.options.getState();\n\t\tthis.drag = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tstartPanX: currentState.pan.x,\n\t\t\tstartPanY: currentState.pan.y,\n\t\t};\n\n\t\tconst onPointerMove = ( moveEvent: Event ) => {\n\t\t\tconst drag = this.drag;\n\t\t\tif ( ! drag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pe = moveEvent as PointerEvent;\n\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\t\tconst s = this.options.getState();\n\t\t\t\tconst imgSize = this.options.getImageSize();\n\t\t\t\tconst containerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = imgSize ?? containerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( pe.clientX - drag.startX ) / panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( pe.clientY - drag.startY ) / panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: drag.startPanX + deltaX,\n\t\t\t\t\t\t\ty: drag.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t} );\n\t\t};\n\n\t\tconst removeListeners = () => {\n\t\t\tel.removeEventListener( 'pointermove', onPointerMove );\n\t\t\tel.removeEventListener( 'pointerup', onPointerUp );\n\t\t\tel.removeEventListener( 'lostpointercapture', onPointerUp );\n\t\t};\n\n\t\tconst onPointerUp = () => {\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t\tthis.drag = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tremoveListeners();\n\t\t\tthis.pointerCleanup = null;\n\t\t};\n\n\t\tel.addEventListener( 'pointermove', onPointerMove );\n\t\tel.addEventListener( 'pointerup', onPointerUp );\n\t\tel.addEventListener( 'lostpointercapture', onPointerUp );\n\t\t// Expose cleanup to destroy() in case the consumer unmounts\n\t\t// mid-drag. The pending rAF is cancelled in destroy().\n\t\tthis.pointerCleanup = removeListeners;\n\t}\n\n\t/**\n\t * Handle a wheel event on the container element.\n\t *\n\t * Implements focal-point zoom: the point under the cursor stays\n\t * stationary on screen while the zoom level changes.\n\t *\n\t * Must be registered with `{ passive: false }` to allow preventDefault.\n\t *\n\t * @param e The native WheelEvent.\n\t */\n\thandleWheel( e: WheelEvent ): void {\n\t\te.preventDefault();\n\n\t\tif ( this.drag ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Debounced gesture boundaries for wheel zoom.\n\t\t// Start on first wheel event, end after 300ms of no events.\n\t\tif ( ! this.wheelGestureActive ) {\n\t\t\tthis.wheelGestureActive = true;\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.wheelGestureTimer = setTimeout( () => {\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}, DOUBLE_TAP_TIME );\n\n\t\tconst s = this.options.getState();\n\t\tconst delta = -e.deltaY * this.zoomSpeed;\n\t\tconst newZoom = Math.min(\n\t\t\tthis.maxZoom,\n\t\t\tMath.max( this.minZoom, s.zoom + delta )\n\t\t);\n\n\t\tif ( newZoom === s.zoom ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Focal-point zoom: keep the point under the cursor stationary.\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\t\tconst visSize = imgSize ?? containerSize;\n\t\tconst target = e.currentTarget;\n\t\tconst rect =\n\t\t\ttarget instanceof Element\n\t\t\t\t? target.getBoundingClientRect()\n\t\t\t\t: undefined;\n\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\tconst fx = e.clientX - rect.left - containerSize.width / 2;\n\t\t\tconst fy = e.clientY - rect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - newZoom / s.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\tconst newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },\n\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\ts.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a touch-start event on the container element.\n\t *\n\t * Supports single-finger pan, two-finger pinch zoom, and\n\t * double-tap to toggle between fit and 2x zoom. Registers\n\t * touchmove/touchend/touchcancel on the provided document for the\n\t * duration of the gesture.\n\t *\n\t * @param e The native TouchEvent.\n\t * @param containerRect The bounding rect of the container element.\n\t * @param doc The document to register move/end listeners on.\n\t * Defaults to globalThis.document. Pass the iframe's\n\t * contentDocument when running inside an iframe.\n\t */\n\thandleTouchStart(\n\t\te: TouchEvent,\n\t\tcontainerRect: DOMRect,\n\t\tdoc: Document = document\n\t): void {\n\t\t// Second finger arriving during an existing gesture — snapshot\n\t\t// pinch start values. handleTouchMove will detect 2 touches and\n\t\t// handle pinch automatically.\n\t\tif ( this.touch && e.touches.length === 2 ) {\n\t\t\tconst s = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch.didPinch = true;\n\t\t\tthis.touch.startDistance = distance;\n\t\t\tthis.touch.startZoom = s.zoom;\n\t\t\tthis.touch.startPanX = s.pan.x;\n\t\t\tthis.touch.startPanY = s.pan.y;\n\t\t\tthis.touch.startMidX = midX;\n\t\t\tthis.touch.startMidY = midY;\n\t\t\tthis.touch.containerRect = containerRect;\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( e.touches.length === 1 ) {\n\t\t\tconst tapX = e.touches[ 0 ].clientX;\n\t\t\tconst tapY = e.touches[ 0 ].clientY;\n\t\t\tif ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentState = this.options.getState();\n\n\t\t\t// Record touch state. Don't decide pan vs pinch yet —\n\t\t\t// that happens in handleTouchMove based on touches.length.\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: 0,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: e.touches[ 0 ].clientX,\n\t\t\t\tlastTouchY: e.touches[ 0 ].clientY,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: 0,\n\t\t\t\tstartMidY: 0,\n\t\t\t\tdidPinch: false,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t} else if ( e.touches.length === 2 ) {\n\t\t\t// Both fingers landed simultaneously (rare but possible).\n\t\t\tconst currentState = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: distance,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: 0,\n\t\t\t\tlastTouchY: 0,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: midX,\n\t\t\t\tstartMidY: midY,\n\t\t\t\tdidPinch: true,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\n\t\tconst onTouchEnd = () => {\n\t\t\tthis.touch = null;\n\t\t\tthis.touchCleanup = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tdoc.removeEventListener( 'touchmove', this.handleTouchMove );\n\t\t\tdoc.removeEventListener( 'touchend', onTouchEnd );\n\t\t\tdoc.removeEventListener( 'touchcancel', onTouchEnd );\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t};\n\n\t\t// Clean up any previous touch listeners before registering new ones.\n\t\tthis.touchCleanup?.();\n\n\t\tdoc.addEventListener( 'touchmove', this.handleTouchMove, {\n\t\t\tpassive: false,\n\t\t} );\n\t\tdoc.addEventListener( 'touchend', onTouchEnd );\n\t\tdoc.addEventListener( 'touchcancel', onTouchEnd );\n\n\t\tthis.touchCleanup = onTouchEnd;\n\t}\n\n\t// Handle a touchmove event during an active touch gesture. Decides pinch\n\t// vs. pan based on current `moveEvent.touches.length`, so the gesture\n\t// can transition between modes without timing sensitivity (e.g. fingers\n\t// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays\n\t// attached when used as an event listener.\n\tprivate handleTouchMove = ( moveEvent: TouchEvent ): void => {\n\t\tconst touch = this.touch;\n\t\tif ( ! touch ) {\n\t\t\treturn;\n\t\t}\n\t\tmoveEvent.preventDefault();\n\n\t\tcancelAnimationFrame( this.rafId );\n\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\tconst s = this.options.getState();\n\n\t\t\tif ( moveEvent.touches.length === 2 ) {\n\t\t\t\t// Two fingers → always pinch, regardless of how gesture\n\t\t\t\t// started. Initialize pinch state on first 2-finger move.\n\t\t\t\tif ( ! touch.didPinch ) {\n\t\t\t\t\ttouch.didPinch = true;\n\t\t\t\t\ttouch.startDistance = getTouchDistance(\n\t\t\t\t\t\tmoveEvent.touches[ 0 ],\n\t\t\t\t\t\tmoveEvent.touches[ 1 ]\n\t\t\t\t\t);\n\t\t\t\t\ttouch.startZoom = s.zoom;\n\t\t\t\t\ttouch.startPanX = s.pan.x;\n\t\t\t\t\ttouch.startPanY = s.pan.y;\n\t\t\t\t\ttouch.startMidX =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientX +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientX ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\ttouch.startMidY =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientY +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientY ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst latestContainerSize = this.options.getContainerSize();\n\t\t\t\tconst latestImageSize = this.options.getImageSize();\n\n\t\t\t\t// Pinch zoom with focal point at finger midpoint,\n\t\t\t\t// plus simultaneous pan from midpoint drift.\n\t\t\t\tconst t0 = moveEvent.touches[ 0 ];\n\t\t\t\tconst t1 = moveEvent.touches[ 1 ];\n\t\t\t\tconst currentDistance = getTouchDistance( t0, t1 );\n\t\t\t\tconst ratio = currentDistance / touch.startDistance;\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, touch.startZoom * ratio )\n\t\t\t\t);\n\n\t\t\t\tconst visSize = latestImageSize ?? latestContainerSize;\n\t\t\t\tconst rect = touch.containerRect;\n\t\t\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\t\t\t// Current midpoint.\n\t\t\t\t\tconst mx =\n\t\t\t\t\t\t( t0.clientX + t1.clientX ) / 2 -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst my =\n\t\t\t\t\t\t( t0.clientY + t1.clientY ) / 2 -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\n\t\t\t\t\t// Pan from midpoint drift (fingers moving together).\n\t\t\t\t\tconst startMx =\n\t\t\t\t\t\ttouch.startMidX -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst startMy =\n\t\t\t\t\t\ttouch.startMidY -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\t\t\t\t\tconst panDx =\n\t\t\t\t\t\tvisSize.width > 0\n\t\t\t\t\t\t\t? ( mx - startMx ) / visSize.width\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst panDy =\n\t\t\t\t\t\tvisSize.height > 0\n\t\t\t\t\t\t\t? ( my - startMy ) / visSize.height\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\t// Focal-point zoom correction. Keep this based on the\n\t\t\t\t\t// pinch-start state; using the current reducer state here\n\t\t\t\t\t// compounds prior touchmove frames and makes a fixed pinch\n\t\t\t\t\t// center drift after the image is already zoomed or panned.\n\t\t\t\t\tconst zoomRatio =\n\t\t\t\t\t\ttouch.startZoom !== 0\n\t\t\t\t\t\t\t? 1 - newZoom / touch.startZoom\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst startFocalNormX = startMx / visSize.width;\n\t\t\t\t\tconst startFocalNormY = startMy / visSize.height;\n\n\t\t\t\t\t// Combined: midpoint drift + zoom around the pinch-start\n\t\t\t\t\t// midpoint, so moving both fingers together pans while\n\t\t\t\t\t// symmetric pinches keep the start center stationary.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX +\n\t\t\t\t\t\tpanDx +\n\t\t\t\t\t\t( startFocalNormX - touch.startPanX ) * zoomRatio;\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY +\n\t\t\t\t\t\tpanDy +\n\t\t\t\t\t\t( startFocalNormY - touch.startPanY ) * zoomRatio;\n\n\t\t\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...s,\n\t\t\t\t\t\t\tzoom: newZoom,\n\t\t\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\t\ts.cropRect\n\t\t\t\t\t);\n\t\t\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t\t\t} else if ( newZoom !== s.zoom ) {\n\t\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\t}\n\t\t\t} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {\n\t\t\t\t// One finger and no pinch ever detected → pan.\n\t\t\t\t// If fingers went 2→1 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan — avoids accidental pan after releasing\n\t\t\t\t// one finger from a pinch.\n\t\t\t\tif ( ! touch.moved ) {\n\t\t\t\t\ttouch.moved = true;\n\t\t\t\t\tthis.setStatus( { isDragging: true } );\n\t\t\t\t}\n\t\t\t\tconst panImageSize = this.options.getImageSize();\n\t\t\t\tconst panContainerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = panImageSize ?? panContainerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientX -\n\t\t\t\t\t\t\t\ttouch.lastTouchX ) /\n\t\t\t\t\t\t panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientY -\n\t\t\t\t\t\t\t\ttouch.lastTouchY ) /\n\t\t\t\t\t\t panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: touch.startPanX + deltaX,\n\t\t\t\t\t\t\ty: touch.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Handle double-tap-to-toggle-zoom. On a second tap within the configured\n\t// time/distance threshold, toggles zoom between `minZoom` and\n\t// `doubleTapZoom` around the tap point and dispatches. Returns `true` if\n\t// the tap was handled as a double-tap (caller should early-return),\n\t// `false` otherwise (caller proceeds with normal single-tap handling).\n\t// Either way, records the tap for next time.\n\tprivate tryDoubleTap(\n\t\te: TouchEvent,\n\t\ttapX: number,\n\t\ttapY: number,\n\t\tcontainerRect: DOMRect\n\t): boolean {\n\t\tconst now = Date.now();\n\t\tconst lastTap = this.lastTap;\n\t\tif ( ! lastTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\t\tconst timeDelta = now - lastTap.time;\n\t\tconst distDelta = Math.sqrt(\n\t\t\t( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2\n\t\t);\n\t\tconst isDoubleTap =\n\t\t\ttimeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;\n\t\tif ( ! isDoubleTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\n\t\t// It's a double-tap — suppress browser zoom.\n\t\te.preventDefault();\n\t\tthis.lastTap = null;\n\n\t\tconst currentState = this.options.getState();\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\n\t\t// Toggle: if past halfway to doubleTapZoom, go back to 1x.\n\t\tconst targetZoom =\n\t\t\tcurrentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2\n\t\t\t\t? this.minZoom\n\t\t\t\t: this.doubleTapZoom;\n\t\tconst visSize = imgSize ?? containerSize;\n\n\t\t// Enable zoom animation before dispatching.\n\t\tthis.setStatus( { isZooming: true } );\n\t\tclearTimeout( this.zoomTimer );\n\t\tthis.zoomTimer = setTimeout( () => {\n\t\t\tthis.setStatus( { isZooming: false } );\n\t\t}, ZOOM_ANIMATION_DURATION );\n\n\t\t// Double-tap bypasses the normal handleTouchStart gesture path so\n\t\t// onGestureStart/End are never called — fire them here so undo\n\t\t// receives a proper boundary around this discrete zoom action.\n\t\tthis.options.onGestureStart?.();\n\n\t\tif ( visSize.width > 0 && visSize.height > 0 ) {\n\t\t\tconst fx = tapX - containerRect.left - containerSize.width / 2;\n\t\t\tconst fy = tapY - containerRect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - targetZoom / currentState.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX =\n\t\t\t\tcurrentState.pan.x +\n\t\t\t\t( focalNormX - currentState.pan.x ) * zoomRatio;\n\t\t\tconst newCropY =\n\t\t\t\tcurrentState.pan.y +\n\t\t\t\t( focalNormY - currentState.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{\n\t\t\t\t\t...currentState,\n\t\t\t\t\tzoom: targetZoom,\n\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t},\n\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\tcurrentState.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( targetZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( targetZoom );\n\t\t}\n\n\t\tthis.options.onGestureEnd?.();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a keydown event on the container element.\n\t *\n\t * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.\n\t *\n\t * @param e The native KeyboardEvent.\n\t */\n\thandleKeyDown( e: KeyboardEvent ): void {\n\t\tconst currentState = this.options.getState();\n\n\t\tswitch ( e.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y + keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y - keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x + keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x - keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '+':\n\t\t\tcase '=': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom + 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '-':\n\t\t\tcase '_': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom - 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'r':\n\t\t\tcase 'R': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'h':\n\t\t\tcase 'H': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'horizontal' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'v':\n\t\t\tcase 'V': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'vertical' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clean up all timers, animation frames, and active touch listeners.\n\t *\n\t * Must be called when the controller is no longer needed (e.g., on\n\t * component unmount or element removal).\n\t */\n\tdestroy(): void {\n\t\tcancelAnimationFrame( this.rafId );\n\t\tclearTimeout( this.zoomTimer );\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.touchCleanup?.();\n\t\tthis.touchCleanup = null;\n\t\tthis.pointerCleanup?.();\n\t\tthis.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f,yBAAsB,KAAK,KAAM;AACjC,iBAAc,KAAK,SAAU;AAC7B,iBAAc,KAAK,iBAAkB;AACrC,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,iBAAiB;AACtB,SAAK,iBAAiB;AACtB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/image-editor/core/math/sanitize.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from '../types';\n\n/**\n * Magnitude beyond which any cropper-math input is treated as corrupt.\n * Picks a value well above any realistic image/rotation/zoom/pan but far\n * below `Number.MAX_VALUE`, so multiplications inside trig and matrix code\n * can't overflow to `Infinity`.\n */\nconst MAX_SAFE_MAGNITUDE = 1e6;\n\n/**\n * Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`\n * because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow\n * downstream trig/matrix math even though the spec reports them as finite.\n *\n * Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this\n * function \u2014 they don't overflow on their own. Protection against divisions\n * by sub-normal values lives in `sanitizeCropperState`'s zoom guard.\n *\n * @param value The candidate value.\n * @param fallback The replacement to return when `value` is unsafe.\n * @return Either `value` or `fallback`.\n */\nexport function safeBoundedNumber( value: number, fallback: number ): number {\n\tif ( ! Number.isFinite( value ) ) {\n\t\treturn fallback;\n\t}\n\tif ( Math.abs( value ) > MAX_SAFE_MAGNITUDE ) {\n\t\treturn fallback;\n\t}\n\treturn value;\n}\n\n/**\n * Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}\n * for callers that need to short-circuit rather than substitute a fallback.\n *\n * @param value The candidate value.\n * @return Whether `value` is safe to use in math.\n */\nexport function isSafeNumber( value: number ): boolean {\n\treturn Number.isFinite( value ) && Math.abs( value ) <= MAX_SAFE_MAGNITUDE;\n}\n\n/**\n * Returns `true` when both dimensions are finite and within the safe\n * range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters\n * because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but\n * make `container / dim` overflow to `Infinity` downstream in\n * `getImageFit` / `createCamera`. Use this to short-circuit math that\n * would otherwise produce non-finite output.\n *\n * @param size The size to check.\n * @return Whether `size` is safe to use in math.\n */\nexport function isValidSize( size: Size ): boolean {\n\treturn (\n\t\tNumber.isFinite( size.width ) &&\n\t\tNumber.isFinite( size.height ) &&\n\t\tsize.width >= Number.EPSILON &&\n\t\tsize.height >= Number.EPSILON &&\n\t\tsize.width <= MAX_SAFE_MAGNITUDE &&\n\t\tsize.height <= MAX_SAFE_MAGNITUDE\n\t);\n}\n\n/**\n * Returns a copy of `rect` with every numeric field replaced by a safe\n * value via {@link safeBoundedNumber}. Returns the same reference when no\n * field needed substitution so callers can keep their reference-equality\n * short-circuits intact for clean inputs.\n *\n * @param rect The rect to sanitize.\n * @return A rect with all numeric fields finite.\n */\nexport function sanitizeRect( rect: NormalizedRect ): NormalizedRect {\n\tconst x = safeBoundedNumber( rect.x, 0 );\n\tconst y = safeBoundedNumber( rect.y, 0 );\n\tconst width = safeBoundedNumber( rect.width, 0 );\n\tconst height = safeBoundedNumber( rect.height, 0 );\n\tif (\n\t\tx === rect.x &&\n\t\ty === rect.y &&\n\t\twidth === rect.width &&\n\t\theight === rect.height\n\t) {\n\t\treturn rect;\n\t}\n\treturn { x, y, width, height };\n}\n\n/**\n * Returns a copy of `state` with the cropper-math numeric fields replaced\n * by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base\n * pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /\n * naturalHeight) are intentionally NOT sanitized \u2014 image dimensions reach\n * the math layer as a separate `imageSize` argument, and cloning the\n * image object here would break the reducer's reference-equality\n * short-circuit.\n *\n * Returns the same `state` reference when no field needed substitution\n * so callers in hot paths (every pointermove via `restrictPanZoom`) can\n * keep their reference-equality optimizations. Sub-object references\n * (`pan`, `basePan`, `cropRect`) are also preserved when their fields\n * are individually clean.\n *\n * @param state The cropper state to sanitize.\n * @return A cropper state with the math-relevant numeric fields finite.\n */\nexport function sanitizeCropperState( state: CropperState ): CropperState {\n\tconst panX = safeBoundedNumber( state.pan.x, 0 );\n\tconst panY = safeBoundedNumber( state.pan.y, 0 );\n\tconst basePanX = safeBoundedNumber( state.basePan.x, 0 );\n\tconst basePanY = safeBoundedNumber( state.basePan.y, 0 );\n\tconst rotation = safeBoundedNumber( state.rotation, 0 );\n\tconst baseRotation = safeBoundedNumber( state.baseRotation, 0 );\n\tconst rawZoom = safeBoundedNumber( state.zoom, 1 );\n\t// Zoom must be strictly positive AND large enough that 1/zoom doesn't\n\t// overflow. Sub-normals (e.g. Number.MIN_VALUE) pass `> 0` but make\n\t// division explode, so guard against them with Number.EPSILON.\n\tconst zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;\n\tconst rawBaseZoom = safeBoundedNumber( state.baseZoom, 1 );\n\tconst baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;\n\tconst cropRect = sanitizeRect( state.cropRect );\n\n\tconst panUnchanged = panX === state.pan.x && panY === state.pan.y;\n\tconst basePanUnchanged =\n\t\tbasePanX === state.basePan.x && basePanY === state.basePan.y;\n\n\tif (\n\t\tpanUnchanged &&\n\t\tbasePanUnchanged &&\n\t\tzoom === state.zoom &&\n\t\tbaseZoom === state.baseZoom &&\n\t\trotation === state.rotation &&\n\t\tbaseRotation === state.baseRotation &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn {\n\t\t...state,\n\t\tpan: panUnchanged ? state.pan : { x: panX, y: panY },\n\t\tzoom,\n\t\trotation,\n\t\tbasePan: basePanUnchanged\n\t\t\t? state.basePan\n\t\t\t: { x: basePanX, y: basePanY },\n\t\tbaseZoom,\n\t\tbaseRotation,\n\t\tcropRect,\n\t};\n}\n"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from '../types';\n\n/**\n * Magnitude beyond which any cropper-math input is treated as corrupt.\n * Picks a value well above any realistic image/rotation/zoom/pan but far\n * below `Number.MAX_VALUE`, so multiplications inside trig and matrix code\n * can't overflow to `Infinity`.\n */\nconst MAX_SAFE_MAGNITUDE = 1e6;\n\n/**\n * Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`\n * because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow\n * downstream trig/matrix math even though the spec reports them as finite.\n *\n * Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this\n * function — they don't overflow on their own. Protection against divisions\n * by sub-normal values lives in `sanitizeCropperState`'s zoom guard.\n *\n * @param value The candidate value.\n * @param fallback The replacement to return when `value` is unsafe.\n * @return Either `value` or `fallback`.\n */\nexport function safeBoundedNumber( value: number, fallback: number ): number {\n\tif ( ! Number.isFinite( value ) ) {\n\t\treturn fallback;\n\t}\n\tif ( Math.abs( value ) > MAX_SAFE_MAGNITUDE ) {\n\t\treturn fallback;\n\t}\n\treturn value;\n}\n\n/**\n * Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}\n * for callers that need to short-circuit rather than substitute a fallback.\n *\n * @param value The candidate value.\n * @return Whether `value` is safe to use in math.\n */\nexport function isSafeNumber( value: number ): boolean {\n\treturn Number.isFinite( value ) && Math.abs( value ) <= MAX_SAFE_MAGNITUDE;\n}\n\n/**\n * Returns `true` when both dimensions are finite and within the safe\n * range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters\n * because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but\n * make `container / dim` overflow to `Infinity` downstream in\n * `getImageFit` / `createCamera`. Use this to short-circuit math that\n * would otherwise produce non-finite output.\n *\n * @param size The size to check.\n * @return Whether `size` is safe to use in math.\n */\nexport function isValidSize( size: Size ): boolean {\n\treturn (\n\t\tNumber.isFinite( size.width ) &&\n\t\tNumber.isFinite( size.height ) &&\n\t\tsize.width >= Number.EPSILON &&\n\t\tsize.height >= Number.EPSILON &&\n\t\tsize.width <= MAX_SAFE_MAGNITUDE &&\n\t\tsize.height <= MAX_SAFE_MAGNITUDE\n\t);\n}\n\n/**\n * Returns a copy of `rect` with every numeric field replaced by a safe\n * value via {@link safeBoundedNumber}. Returns the same reference when no\n * field needed substitution so callers can keep their reference-equality\n * short-circuits intact for clean inputs.\n *\n * @param rect The rect to sanitize.\n * @return A rect with all numeric fields finite.\n */\nexport function sanitizeRect( rect: NormalizedRect ): NormalizedRect {\n\tconst x = safeBoundedNumber( rect.x, 0 );\n\tconst y = safeBoundedNumber( rect.y, 0 );\n\tconst width = safeBoundedNumber( rect.width, 0 );\n\tconst height = safeBoundedNumber( rect.height, 0 );\n\tif (\n\t\tx === rect.x &&\n\t\ty === rect.y &&\n\t\twidth === rect.width &&\n\t\theight === rect.height\n\t) {\n\t\treturn rect;\n\t}\n\treturn { x, y, width, height };\n}\n\n/**\n * Returns a copy of `state` with the cropper-math numeric fields replaced\n * by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base\n * pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /\n * naturalHeight) are intentionally NOT sanitized — image dimensions reach\n * the math layer as a separate `imageSize` argument, and cloning the\n * image object here would break the reducer's reference-equality\n * short-circuit.\n *\n * Returns the same `state` reference when no field needed substitution\n * so callers in hot paths (every pointermove via `restrictPanZoom`) can\n * keep their reference-equality optimizations. Sub-object references\n * (`pan`, `basePan`, `cropRect`) are also preserved when their fields\n * are individually clean.\n *\n * @param state The cropper state to sanitize.\n * @return A cropper state with the math-relevant numeric fields finite.\n */\nexport function sanitizeCropperState( state: CropperState ): CropperState {\n\tconst panX = safeBoundedNumber( state.pan.x, 0 );\n\tconst panY = safeBoundedNumber( state.pan.y, 0 );\n\tconst basePanX = safeBoundedNumber( state.basePan.x, 0 );\n\tconst basePanY = safeBoundedNumber( state.basePan.y, 0 );\n\tconst rotation = safeBoundedNumber( state.rotation, 0 );\n\tconst baseRotation = safeBoundedNumber( state.baseRotation, 0 );\n\tconst rawZoom = safeBoundedNumber( state.zoom, 1 );\n\t// Zoom must be strictly positive AND large enough that 1/zoom doesn't\n\t// overflow. Sub-normals (e.g. Number.MIN_VALUE) pass `> 0` but make\n\t// division explode, so guard against them with Number.EPSILON.\n\tconst zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;\n\tconst rawBaseZoom = safeBoundedNumber( state.baseZoom, 1 );\n\tconst baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;\n\tconst cropRect = sanitizeRect( state.cropRect );\n\n\tconst panUnchanged = panX === state.pan.x && panY === state.pan.y;\n\tconst basePanUnchanged =\n\t\tbasePanX === state.basePan.x && basePanY === state.basePan.y;\n\n\tif (\n\t\tpanUnchanged &&\n\t\tbasePanUnchanged &&\n\t\tzoom === state.zoom &&\n\t\tbaseZoom === state.baseZoom &&\n\t\trotation === state.rotation &&\n\t\tbaseRotation === state.baseRotation &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn {\n\t\t...state,\n\t\tpan: panUnchanged ? state.pan : { x: panX, y: panY },\n\t\tzoom,\n\t\trotation,\n\t\tbasePan: basePanUnchanged\n\t\t\t? state.basePan\n\t\t\t: { x: basePanX, y: basePanY },\n\t\tbaseZoom,\n\t\tbaseRotation,\n\t\tcropRect,\n\t};\n}\n"],
5
5
  "mappings": ";AAWA,IAAM,qBAAqB;AAgBpB,SAAS,kBAAmB,OAAe,UAA2B;AAC5E,MAAK,CAAE,OAAO,SAAU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OAAO,UAAU,cAAc;AAC/D,QAAM,WAAW,aAAc,MAAM,QAAS;AAE9C,QAAM,eAAe,SAAS,MAAM,IAAI,KAAK,SAAS,MAAM,IAAI;AAChE,QAAM,mBACL,aAAa,MAAM,QAAQ,KAAK,aAAa,MAAM,QAAQ;AAE5D,MACC,gBACA,oBACA,SAAS,MAAM,QACf,aAAa,MAAM,YACnB,aAAa,MAAM,YACnB,iBAAiB,MAAM,gBACvB,aAAa,MAAM,UAClB;AACD,WAAO;AAAA,EACR;AACA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,KAAK,eAAe,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,KAAK;AAAA,IACnD;AAAA,IACA;AAAA,IACA,SAAS,mBACN,MAAM,UACN,EAAE,GAAG,UAAU,GAAG,SAAS;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/setter-helpers.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom \u2014 zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0\u20131), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t }\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t }\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
5
5
  "mappings": ";AAIA,SAAS,gBAAgB;AACzB,SAAS,YAAY,uBAAuB;AAoBrC,SAAS,0BACf,OACA,eACuB;AACvB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,IAAK,WAAY,KAAM,GAAG,aAAc;AAAA,EAC9C;AACA,MAAK,gBAAgB,MAAM,MAAO;AACjC,WAAO;AAAA,EACR;AAKA,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;AACrD,QAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;AACtD,QAAM,YAAY,IAAI,cAAc,MAAM;AAC1C,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,YAA+C,MAAM,QACxD;AAAA,IACA,OAAO,MAAM,MAAM;AAAA,IACnB,QAAQ,MAAM,MAAM;AAAA,EACpB,IACA,EAAE,OAAO,GAAG,QAAQ,EAAE;AACzB,QAAM,EAAE,KAAK,WAAW,IAA8B;AAAA,IACrD;AAAA,MACC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AACA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,EAAE,MAAM,aAAa,KAAK,WAAW;AAAA,EAC/C;AACD;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,7 @@
2
2
  import { mat2d, vec2 } from "gl-matrix";
3
3
  import { createCamera, getRotatedBBox, getVisibleBounds } from "./camera.mjs";
4
4
  import { isValidSize, sanitizeCropperState } from "./math/sanitize.mjs";
5
+ import { normalizeRotation } from "./math/rotation.mjs";
5
6
  function getSourceRegion(state, imageSize) {
6
7
  const safeState = sanitizeCropperState(state);
7
8
  if (!isValidSize(imageSize)) {
@@ -52,6 +53,110 @@ function getSourceRegion(state, imageSize) {
52
53
  zoom: safeState.zoom
53
54
  };
54
55
  }
56
+ function getCropRectFromSourceRegion(state, imageSize, region) {
57
+ if (!isValidSize(imageSize) || region.width <= 0 || region.height <= 0) {
58
+ return null;
59
+ }
60
+ const safeState = sanitizeCropperState(state);
61
+ const syntheticContainer = { width: 1e3, height: 1e3 };
62
+ const baseCamera = createCamera(
63
+ { ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },
64
+ syntheticContainer,
65
+ imageSize
66
+ );
67
+ const visibleBounds = getVisibleBounds(baseCamera);
68
+ if (visibleBounds.width <= 0 || visibleBounds.height <= 0) {
69
+ return null;
70
+ }
71
+ const sourceCenter = vec2.fromValues(
72
+ (region.x + region.width / 2) / imageSize.width,
73
+ (region.y + region.height / 2) / imageSize.height
74
+ );
75
+ const screenCenter = vec2.create();
76
+ const camera = createCamera(safeState, syntheticContainer, imageSize);
77
+ vec2.transformMat2d(screenCenter, sourceCenter, camera);
78
+ const snapRotation = Math.round(safeState.rotation / 90) * 90;
79
+ const { width: rotW, height: rotH } = getRotatedBBox(
80
+ imageSize.width,
81
+ imageSize.height,
82
+ snapRotation
83
+ );
84
+ if (rotW <= 0 || rotH <= 0) {
85
+ return null;
86
+ }
87
+ const width = region.width * safeState.zoom / rotW;
88
+ const height = region.height * safeState.zoom / rotH;
89
+ const centerX = (screenCenter[0] - visibleBounds.left) / visibleBounds.width;
90
+ const centerY = (screenCenter[1] - visibleBounds.top) / visibleBounds.height;
91
+ return {
92
+ x: centerX - width / 2,
93
+ y: centerY - height / 2,
94
+ width,
95
+ height
96
+ };
97
+ }
98
+ var CARDINAL_ROTATION_EPSILON = 1e-6;
99
+ function isCardinalRotation(rotation) {
100
+ const normalizedRotation = normalizeRotation(rotation);
101
+ const nearestCardinal = Math.round(normalizedRotation / 90) * 90;
102
+ return Math.abs(normalizedRotation - nearestCardinal) < CARDINAL_ROTATION_EPSILON;
103
+ }
104
+ function snapCropRectToSourcePixels(state, imageSize, cropRect, handle) {
105
+ const safeState = sanitizeCropperState(state);
106
+ if (!isCardinalRotation(safeState.rotation)) {
107
+ return cropRect;
108
+ }
109
+ return snapCropRectEdgesToSourcePixels(safeState, imageSize, cropRect, {
110
+ left: handle.includes("w"),
111
+ top: handle.includes("n"),
112
+ right: handle.includes("e"),
113
+ bottom: handle.includes("s")
114
+ });
115
+ }
116
+ function snapCropRectToSourcePixelGrid(state, imageSize, cropRect) {
117
+ return snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, {
118
+ left: true,
119
+ top: true,
120
+ right: true,
121
+ bottom: true
122
+ });
123
+ }
124
+ function snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, edges) {
125
+ if (!isValidSize(imageSize)) {
126
+ return cropRect;
127
+ }
128
+ const stateWithCrop = sanitizeCropperState({ ...state, cropRect });
129
+ const region = getSourceRegion(stateWithCrop, imageSize);
130
+ const shouldSnapX = edges.left || edges.right;
131
+ const shouldSnapY = edges.top || edges.bottom;
132
+ const left = edges.left ? Math.round(region.x) : region.x;
133
+ const top = edges.top ? Math.round(region.y) : region.y;
134
+ const right = edges.right ? Math.round(region.x + region.width) : region.x + region.width;
135
+ const bottom = edges.bottom ? Math.round(region.y + region.height) : region.y + region.height;
136
+ if (right <= left || bottom <= top) {
137
+ return cropRect;
138
+ }
139
+ const snappedCropRect = getCropRectFromSourceRegion(
140
+ stateWithCrop,
141
+ imageSize,
142
+ {
143
+ ...region,
144
+ x: left,
145
+ y: top,
146
+ width: right - left,
147
+ height: bottom - top
148
+ }
149
+ );
150
+ if (!snappedCropRect) {
151
+ return cropRect;
152
+ }
153
+ return {
154
+ x: shouldSnapX ? snappedCropRect.x : cropRect.x,
155
+ y: shouldSnapY ? snappedCropRect.y : cropRect.y,
156
+ width: shouldSnapX ? snappedCropRect.width : cropRect.width,
157
+ height: shouldSnapY ? snappedCropRect.height : cropRect.height
158
+ };
159
+ }
55
160
  function getSourceRegionPercent(state, imageSize) {
56
161
  if (!isValidSize(imageSize)) {
57
162
  return { x: 0, y: 0, width: 0, height: 0 };
@@ -66,6 +171,8 @@ function getSourceRegionPercent(state, imageSize) {
66
171
  }
67
172
  export {
68
173
  getSourceRegion,
69
- getSourceRegionPercent
174
+ getSourceRegionPercent,
175
+ snapCropRectToSourcePixelGrid,
176
+ snapCropRectToSourcePixels
70
177
  };
71
178
  //# sourceMappingURL=source-region.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/source-region.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from './types';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/**\n * The selected image region in source-pixel coordinates.\n */\nexport interface SourceRegion {\n\t/** X offset in source pixels. */\n\tx: number;\n\t/** Y offset in source pixels. */\n\ty: number;\n\t/** Width in source pixels. */\n\twidth: number;\n\t/** Height in source pixels. */\n\theight: number;\n\t/** Rotation in degrees (0-360). */\n\trotation: number;\n\t/** Flip state. */\n\tflip: { horizontal: boolean; vertical: boolean };\n\t/** Zoom factor applied. */\n\tzoom: number;\n}\n\n/**\n * Get the selected image region in source-pixel coordinates.\n *\n * Converts the current crop state (normalized visual space) to the actual\n * region of the original image that's selected. This is the bridge between\n * the cropper's internal coordinate system and external tools (image\n * processing libraries, AI APIs, server-side processing) that work in\n * source-pixel coordinates.\n *\n * The returned rectangle accounts for pan, zoom, and the crop rect position,\n * but expresses the crop in the unrotated image's coordinate space. Rotation\n * and flip are included as separate fields since they represent transforms,\n * not a region.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @return The selected region in source pixels plus rotation/flip metadata.\n */\nexport function getSourceRegion(\n\tstate: CropperState,\n\timageSize: Size\n): SourceRegion {\n\t// Sanitize before the zero-size short-circuit so the early return\n\t// doesn't leak raw non-finite state.rotation or state.zoom out\n\t// through the metadata fields. (state.flip is boolean and isn't\n\t// at risk of NaN propagation.)\n\tconst safeState = sanitizeCropperState( state );\n\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\tx: 0,\n\t\t\ty: 0,\n\t\t\twidth: 0,\n\t\t\theight: 0,\n\t\t\trotation: safeState.rotation,\n\t\t\tflip: { ...safeState.flip },\n\t\t\tzoom: safeState.zoom,\n\t\t};\n\t}\n\n\t// Use a synthetic 1:1 container so the camera maps normalized coords\n\t// to a known pixel space. The container size cancels out.\n\tconst syntheticContainer: Size = { width: 1000, height: 1000 };\n\tconst camera = createCamera( safeState, syntheticContainer, imageSize );\n\n\t// Inverse camera maps screen pixels back to normalized [0,1] world coords.\n\tconst inv = mat2d.create();\n\tmat2d.invert( inv, camera );\n\n\t// The crop rect center in screen space. We need the base camera\n\t// (zoom=1, no pan) to locate the visual bounds, then place the\n\t// crop rect within them.\n\tconst baseCamera = createCamera(\n\t\t{ ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },\n\t\tsyntheticContainer,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\tconst cropRect = safeState.cropRect;\n\tconst cropCenterScreenX =\n\t\tvisibleBounds.left +\n\t\t( cropRect.x + cropRect.width / 2 ) * visibleBounds.width;\n\tconst cropCenterScreenY =\n\t\tvisibleBounds.top +\n\t\t( cropRect.y + cropRect.height / 2 ) * visibleBounds.height;\n\n\t// Transform crop center through inverse camera to get source position.\n\tconst srcCenter = vec2.create();\n\tvec2.transformMat2d(\n\t\tsrcCenter,\n\t\t[ cropCenterScreenX, cropCenterScreenY ],\n\t\tinv\n\t);\n\n\t// Crop rect size in the snap-rotation visual space, divided by zoom\n\t// for source-pixel dimensions. Matches the stencil's reference frame.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tconst sourceW = ( cropRect.width * rotW ) / safeState.zoom;\n\tconst sourceH = ( cropRect.height * rotH ) / safeState.zoom;\n\n\treturn {\n\t\tx: srcCenter[ 0 ] * imageSize.width - sourceW / 2,\n\t\ty: srcCenter[ 1 ] * imageSize.height - sourceH / 2,\n\t\twidth: sourceW,\n\t\theight: sourceH,\n\t\trotation: safeState.rotation,\n\t\tflip: { ...safeState.flip },\n\t\tzoom: safeState.zoom,\n\t};\n}\n\n/**\n * The selected crop region expressed as percentages of the source image.\n */\nexport interface SourceRegionPercent {\n\t/** X offset as a percentage (0\u2013100) of the source image width. */\n\tx: number;\n\t/** Y offset as a percentage (0\u2013100) of the source image height. */\n\ty: number;\n\t/** Width as a percentage (0\u2013100) of the source image width. */\n\twidth: number;\n\t/** Height as a percentage (0\u2013100) of the source image height. */\n\theight: number;\n}\n\n/**\n * Get the selected image region as percentages of the source image dimensions.\n *\n * Returns `{ x, y, width, height }` where each value is a percentage (0\u2013100)\n * of the source image's natural width or height. This format is compatible\n * with the WordPress REST API attachments `/edit` endpoint and CSS-based\n * crop workflows.\n *\n * Internally delegates to `getSourceRegion` and divides by the image\n * dimensions, so accuracy is identical.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @return The crop region as percentages (0\u2013100).\n */\nexport function getSourceRegionPercent(\n\tstate: CropperState,\n\timageSize: Size\n): SourceRegionPercent {\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn { x: 0, y: 0, width: 0, height: 0 };\n\t}\n\tconst region = getSourceRegion( state, imageSize );\n\treturn {\n\t\tx: ( region.x / imageSize.width ) * 100,\n\t\ty: ( region.y / imageSize.height ) * 100,\n\t\twidth: ( region.width / imageSize.width ) * 100,\n\t\theight: ( region.height / imageSize.height ) * 100,\n\t};\n}\n"],
5
- "mappings": ";AAGA,SAAS,OAAO,YAAY;AAM5B,SAAS,cAAc,gBAAgB,wBAAwB;AAC/D,SAAS,aAAa,4BAA4B;AAwC3C,SAAS,gBACf,OACA,WACe;AAKf,QAAM,YAAY,qBAAsB,KAAM;AAE9C,MAAK,CAAE,YAAa,SAAU,GAAI;AACjC,WAAO;AAAA,MACN,GAAG;AAAA,MACH,GAAG;AAAA,MACH,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,UAAU,UAAU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ACsB;AACtB,MAAK,CAAE,YAAa,SAAU,GAAI;AACjC,WAAO,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE;AAAA,EAC1C;AACA,QAAM,SAAS,gBAAiB,OAAO,SAAU;AACjD,SAAO;AAAA,IACN,GAAK,OAAO,IAAI,UAAU,QAAU;AAAA,IACpC,GAAK,OAAO,IAAI,UAAU,SAAW;AAAA,IACrC,OAAS,OAAO,QAAQ,UAAU,QAAU;AAAA,IAC5C,QAAU,OAAO,SAAS,UAAU,SAAW;AAAA,EAChD;AACD;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tHandlePosition,\n\tNormalizedRect,\n\tSize,\n} from './types';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\nimport { normalizeRotation } from './math/rotation';\n\n/**\n * The selected image region in source-pixel coordinates.\n */\nexport interface SourceRegion {\n\t/** X offset in source pixels. */\n\tx: number;\n\t/** Y offset in source pixels. */\n\ty: number;\n\t/** Width in source pixels. */\n\twidth: number;\n\t/** Height in source pixels. */\n\theight: number;\n\t/** Rotation in degrees (0-360). */\n\trotation: number;\n\t/** Flip state. */\n\tflip: { horizontal: boolean; vertical: boolean };\n\t/** Zoom factor applied. */\n\tzoom: number;\n}\n\n/**\n * Get the selected image region in source-pixel coordinates.\n *\n * Converts the current crop state (normalized visual space) to the actual\n * region of the original image that's selected. This is the bridge between\n * the cropper's internal coordinate system and external tools (image\n * processing libraries, AI APIs, server-side processing) that work in\n * source-pixel coordinates.\n *\n * The returned rectangle accounts for pan, zoom, and the crop rect position,\n * but expresses the crop in the unrotated image's coordinate space. Rotation\n * and flip are included as separate fields since they represent transforms,\n * not a region.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @return The selected region in source pixels plus rotation/flip metadata.\n */\nexport function getSourceRegion(\n\tstate: CropperState,\n\timageSize: Size\n): SourceRegion {\n\t// Sanitize before the zero-size short-circuit so the early return\n\t// doesn't leak raw non-finite state.rotation or state.zoom out\n\t// through the metadata fields. (state.flip is boolean and isn't\n\t// at risk of NaN propagation.)\n\tconst safeState = sanitizeCropperState( state );\n\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\tx: 0,\n\t\t\ty: 0,\n\t\t\twidth: 0,\n\t\t\theight: 0,\n\t\t\trotation: safeState.rotation,\n\t\t\tflip: { ...safeState.flip },\n\t\t\tzoom: safeState.zoom,\n\t\t};\n\t}\n\n\t// Use a synthetic 1:1 container so the camera maps normalized coords\n\t// to a known pixel space. The container size cancels out.\n\tconst syntheticContainer: Size = { width: 1000, height: 1000 };\n\tconst camera = createCamera( safeState, syntheticContainer, imageSize );\n\n\t// Inverse camera maps screen pixels back to normalized [0,1] world coords.\n\tconst inv = mat2d.create();\n\tmat2d.invert( inv, camera );\n\n\t// The crop rect center in screen space. We need the base camera\n\t// (zoom=1, no pan) to locate the visual bounds, then place the\n\t// crop rect within them.\n\tconst baseCamera = createCamera(\n\t\t{ ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },\n\t\tsyntheticContainer,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\tconst cropRect = safeState.cropRect;\n\tconst cropCenterScreenX =\n\t\tvisibleBounds.left +\n\t\t( cropRect.x + cropRect.width / 2 ) * visibleBounds.width;\n\tconst cropCenterScreenY =\n\t\tvisibleBounds.top +\n\t\t( cropRect.y + cropRect.height / 2 ) * visibleBounds.height;\n\n\t// Transform crop center through inverse camera to get source position.\n\tconst srcCenter = vec2.create();\n\tvec2.transformMat2d(\n\t\tsrcCenter,\n\t\t[ cropCenterScreenX, cropCenterScreenY ],\n\t\tinv\n\t);\n\n\t// Crop rect size in the snap-rotation visual space, divided by zoom\n\t// for source-pixel dimensions. Matches the stencil's reference frame.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tconst sourceW = ( cropRect.width * rotW ) / safeState.zoom;\n\tconst sourceH = ( cropRect.height * rotH ) / safeState.zoom;\n\n\treturn {\n\t\tx: srcCenter[ 0 ] * imageSize.width - sourceW / 2,\n\t\ty: srcCenter[ 1 ] * imageSize.height - sourceH / 2,\n\t\twidth: sourceW,\n\t\theight: sourceH,\n\t\trotation: safeState.rotation,\n\t\tflip: { ...safeState.flip },\n\t\tzoom: safeState.zoom,\n\t};\n}\n\n/**\n * Convert a source-pixel region back to the cropper's normalized crop rect.\n *\n * The math intentionally mirrors `getSourceRegion`: map the requested source\n * center through the current camera, then express that screen point inside the\n * same base visible bounds used to position crop overlays.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @param region The source-pixel region to represent as a crop rect.\n * @return The normalized crop rect, or null when inputs cannot be mapped.\n */\nfunction getCropRectFromSourceRegion(\n\tstate: CropperState,\n\timageSize: Size,\n\tregion: SourceRegion\n): NormalizedRect | null {\n\tif (\n\t\t! isValidSize( imageSize ) ||\n\t\tregion.width <= 0 ||\n\t\tregion.height <= 0\n\t) {\n\t\treturn null;\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\tconst syntheticContainer: Size = { width: 1000, height: 1000 };\n\tconst baseCamera = createCamera(\n\t\t{ ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },\n\t\tsyntheticContainer,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\tif ( visibleBounds.width <= 0 || visibleBounds.height <= 0 ) {\n\t\treturn null;\n\t}\n\n\tconst sourceCenter = vec2.fromValues(\n\t\t( region.x + region.width / 2 ) / imageSize.width,\n\t\t( region.y + region.height / 2 ) / imageSize.height\n\t);\n\tconst screenCenter = vec2.create();\n\tconst camera = createCamera( safeState, syntheticContainer, imageSize );\n\tvec2.transformMat2d( screenCenter, sourceCenter, camera );\n\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tif ( rotW <= 0 || rotH <= 0 ) {\n\t\treturn null;\n\t}\n\n\tconst width = ( region.width * safeState.zoom ) / rotW;\n\tconst height = ( region.height * safeState.zoom ) / rotH;\n\tconst centerX =\n\t\t( screenCenter[ 0 ] - visibleBounds.left ) / visibleBounds.width;\n\tconst centerY =\n\t\t( screenCenter[ 1 ] - visibleBounds.top ) / visibleBounds.height;\n\n\treturn {\n\t\tx: centerX - width / 2,\n\t\ty: centerY - height / 2,\n\t\twidth,\n\t\theight,\n\t};\n}\n\ninterface SourcePixelSnapEdges {\n\tleft: boolean;\n\ttop: boolean;\n\tright: boolean;\n\tbottom: boolean;\n}\n\nconst CARDINAL_ROTATION_EPSILON = 1e-6;\n\n/**\n * Check whether a rotation is effectively at a 90-degree stop.\n *\n * @param rotation The rotation angle in degrees.\n * @return Whether the rotation is close enough to a cardinal angle.\n */\nfunction isCardinalRotation( rotation: number ): boolean {\n\tconst normalizedRotation = normalizeRotation( rotation );\n\tconst nearestCardinal = Math.round( normalizedRotation / 90 ) * 90;\n\treturn (\n\t\tMath.abs( normalizedRotation - nearestCardinal ) <\n\t\tCARDINAL_ROTATION_EPSILON\n\t);\n}\n\n/**\n * Snap a crop rect so the selected source-region edges land on whole pixels.\n *\n * This is a display-time affordance for visible pixel grids; it does not alter\n * pan/zoom/rotation. Callers decide when snapping is appropriate.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @param cropRect The candidate crop rect from resize math.\n * @param handle The active resize handle. Only edges moved by the handle snap.\n * @return A crop rect whose selected source-region edges are whole pixels.\n */\nexport function snapCropRectToSourcePixels(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect,\n\thandle: HandlePosition\n): NormalizedRect {\n\tconst safeState = sanitizeCropperState( state );\n\tif ( ! isCardinalRotation( safeState.rotation ) ) {\n\t\treturn cropRect;\n\t}\n\n\treturn snapCropRectEdgesToSourcePixels( safeState, imageSize, cropRect, {\n\t\tleft: handle.includes( 'w' ),\n\t\ttop: handle.includes( 'n' ),\n\t\tright: handle.includes( 'e' ),\n\t\tbottom: handle.includes( 's' ),\n\t} );\n}\n\n/**\n * Snap all source-region edges for a crop rect to the nearest whole pixels.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @param cropRect The crop rect to align to the source-pixel grid.\n * @return A crop rect whose source-region edges are whole pixels.\n */\nexport function snapCropRectToSourcePixelGrid(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): NormalizedRect {\n\treturn snapCropRectEdgesToSourcePixels( state, imageSize, cropRect, {\n\t\tleft: true,\n\t\ttop: true,\n\t\tright: true,\n\t\tbottom: true,\n\t} );\n}\n\nfunction snapCropRectEdgesToSourcePixels(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect,\n\tedges: SourcePixelSnapEdges\n): NormalizedRect {\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn cropRect;\n\t}\n\n\tconst stateWithCrop = sanitizeCropperState( { ...state, cropRect } );\n\tconst region = getSourceRegion( stateWithCrop, imageSize );\n\tconst shouldSnapX = edges.left || edges.right;\n\tconst shouldSnapY = edges.top || edges.bottom;\n\tconst left = edges.left ? Math.round( region.x ) : region.x;\n\tconst top = edges.top ? Math.round( region.y ) : region.y;\n\tconst right = edges.right\n\t\t? Math.round( region.x + region.width )\n\t\t: region.x + region.width;\n\tconst bottom = edges.bottom\n\t\t? Math.round( region.y + region.height )\n\t\t: region.y + region.height;\n\tif ( right <= left || bottom <= top ) {\n\t\treturn cropRect;\n\t}\n\n\tconst snappedCropRect = getCropRectFromSourceRegion(\n\t\tstateWithCrop,\n\t\timageSize,\n\t\t{\n\t\t\t...region,\n\t\t\tx: left,\n\t\t\ty: top,\n\t\t\twidth: right - left,\n\t\t\theight: bottom - top,\n\t\t}\n\t);\n\tif ( ! snappedCropRect ) {\n\t\treturn cropRect;\n\t}\n\n\treturn {\n\t\tx: shouldSnapX ? snappedCropRect.x : cropRect.x,\n\t\ty: shouldSnapY ? snappedCropRect.y : cropRect.y,\n\t\twidth: shouldSnapX ? snappedCropRect.width : cropRect.width,\n\t\theight: shouldSnapY ? snappedCropRect.height : cropRect.height,\n\t};\n}\n\n/**\n * The selected crop region expressed as percentages of the source image.\n */\nexport interface SourceRegionPercent {\n\t/** X offset as a percentage (0–100) of the source image width. */\n\tx: number;\n\t/** Y offset as a percentage (0–100) of the source image height. */\n\ty: number;\n\t/** Width as a percentage (0–100) of the source image width. */\n\twidth: number;\n\t/** Height as a percentage (0–100) of the source image height. */\n\theight: number;\n}\n\n/**\n * Get the selected image region as percentages of the source image dimensions.\n *\n * Returns `{ x, y, width, height }` where each value is a percentage (0–100)\n * of the source image's natural width or height. This format is compatible\n * with the WordPress REST API attachments `/edit` endpoint and CSS-based\n * crop workflows.\n *\n * Internally delegates to `getSourceRegion` and divides by the image\n * dimensions, so accuracy is identical.\n *\n * @param state The current cropper state.\n * @param imageSize The natural dimensions of the source image.\n * @return The crop region as percentages (0–100).\n */\nexport function getSourceRegionPercent(\n\tstate: CropperState,\n\timageSize: Size\n): SourceRegionPercent {\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn { x: 0, y: 0, width: 0, height: 0 };\n\t}\n\tconst region = getSourceRegion( state, imageSize );\n\treturn {\n\t\tx: ( region.x / imageSize.width ) * 100,\n\t\ty: ( region.y / imageSize.height ) * 100,\n\t\twidth: ( region.width / imageSize.width ) * 100,\n\t\theight: ( region.height / imageSize.height ) * 100,\n\t};\n}\n"],
5
+ "mappings": ";AAGA,SAAS,OAAO,YAAY;AAW5B,SAAS,cAAc,gBAAgB,wBAAwB;AAC/D,SAAS,aAAa,4BAA4B;AAClD,SAAS,yBAAyB;AAwC3B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AAM,KAAK,MAAO,OAAO,CAAE,IAAI,OAAO;AACxD,QAAM,QAAQ,MAAM,QACjB,KAAK,MAAO,OAAO,IAAI,OAAO,KAAM,IACpC,OAAO,IAAI,OAAO;AACrB,QAAM,SAAS,MAAM,SAClB,KAAK,MAAO,OAAO,IAAI,OAAO,MAAO,IACrC,OAAO,IAAI,OAAO;AACrB,MAAK,SAAS,QAAQ,UAAU,KAAM;AACrC,WAAO;AAAA,EACR;AAEA,QAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,MACC,GAAG;AAAA,MACH,GAAG;AAAA,MACH,GAAG;AAAA,MACH,OAAO,QAAQ;AAAA,MACf,QAAQ,SAAS;AAAA,IAClB;AAAA,EACD;AACA,MAAK,CAAE,iBAAkB;AACxB,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG,cAAc,gBAAgB,IAAI,SAAS;AAAA,IAC9C,GAAG,cAAc,gBAAgB,IAAI,SAAS;AAAA,IAC9C,OAAO,cAAc,gBAAgB,QAAQ,SAAS;AAAA,IACtD,QAAQ,cAAc,gBAAgB,SAAS,SAAS;AAAA,EACzD;AACD;AA+BO,SAAS,uBACf,OACA,WACsB;AACtB,MAAK,CAAE,YAAa,SAAU,GAAI;AACjC,WAAO,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE;AAAA,EAC1C;AACA,QAAM,SAAS,gBAAiB,OAAO,SAAU;AACjD,SAAO;AAAA,IACN,GAAK,OAAO,IAAI,UAAU,QAAU;AAAA,IACpC,GAAK,OAAO,IAAI,UAAU,SAAW;AAAA,IACrC,OAAS,OAAO,QAAQ,UAAU,QAAU;AAAA,IAC5C,QAAU,OAAO,SAAS,UAAU,SAAW;AAAA,EAChD;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/state.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperAction, CropperState, TransformOperation } from './types';\nimport {\n\tABSOLUTE_MIN_ZOOM,\n\tDEFAULT_STATE,\n\tMAX_ZOOM,\n\tMIN_ZOOM,\n} from './constants';\nimport { normalizeRotation, degreesToRadians } from './math/rotation';\nimport { restrictPanZoom, restrictCropRect } from './containment';\n\n/** Small tolerance for cropper floating-point comparisons. */\nconst STATE_EPSILON = 1e-6;\n\nfunction nearlyEqual( a: number, b: number ): boolean {\n\treturn Math.abs( a - b ) < STATE_EPSILON;\n}\n\n/**\n * Value-equality check for two cropper states.\n *\n * Used by history machinery to dedup snapshots and detect no-op\n * transitions. Compares every field that participates in the rendered\n * output; ignores reference identity.\n *\n * @param a First cropper state.\n * @param b Second cropper state.\n * @return Whether the two states are value-equal across all tracked fields.\n */\nexport function areCropperStatesEqual(\n\ta: CropperState,\n\tb: CropperState\n): boolean {\n\tconst aImage = a.image;\n\tconst bImage = b.image;\n\treturn (\n\t\taImage?.src === bImage?.src &&\n\t\taImage?.naturalWidth === bImage?.naturalWidth &&\n\t\taImage?.naturalHeight === bImage?.naturalHeight &&\n\t\tnearlyEqual( a.pan.x, b.pan.x ) &&\n\t\tnearlyEqual( a.pan.y, b.pan.y ) &&\n\t\tnearlyEqual( a.zoom, b.zoom ) &&\n\t\tnearlyEqual( a.rotation, b.rotation ) &&\n\t\ta.flip.horizontal === b.flip.horizontal &&\n\t\ta.flip.vertical === b.flip.vertical &&\n\t\tnearlyEqual( a.cropRect.x, b.cropRect.x ) &&\n\t\tnearlyEqual( a.cropRect.y, b.cropRect.y ) &&\n\t\tnearlyEqual( a.cropRect.width, b.cropRect.width ) &&\n\t\tnearlyEqual( a.cropRect.height, b.cropRect.height )\n\t);\n}\n\nfunction clampRequestedZoom( state: CropperState, zoom: number ): number {\n\t// With an image, enforceContainment raises zoom to the coverage-aware\n\t// floor below. Without an image, no enforcement runs, so MIN_ZOOM stays\n\t// the conservative resting default.\n\tif ( state.image ) {\n\t\treturn Math.min( MAX_ZOOM, Math.max( ABSOLUTE_MIN_ZOOM, zoom ) );\n\t}\n\treturn Math.min( MAX_ZOOM, Math.max( MIN_ZOOM, zoom ) );\n}\n\n/**\n * Translate a pipeline transform operation into the equivalent\n * reducer action. Pipeline ops aren't 1:1 with reducer actions \u2014\n * `rotate` is a delta here, whereas SET_ROTATION takes an absolute\n * angle \u2014 so deltas are resolved against the current state.\n *\n * Used by APPLY_OPERATION (and by the pipeline module's\n * `applyOperationToState`, which is now a thin wrapper around the\n * reducer) so that pipeline replay produces identical bounded\n * state to UI interaction or direct setters.\n *\n * @param state The current cropper state.\n * @param op The pipeline operation.\n * @return The equivalent reducer action.\n */\nfunction operationToAction(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperAction {\n\tswitch ( op.type ) {\n\t\tcase 'crop':\n\t\t\treturn { type: 'SET_CROP_RECT', payload: { ...op.rect } };\n\t\tcase 'rotate': {\n\t\t\t// `op.degrees` is the visual rotation the caller wants (positive\n\t\t\t// = CW on screen). A single-axis flip inverts on-screen rotation\n\t\t\t// relative to the rotation field, so negate the field delta in\n\t\t\t// that case \u2014 this keeps `{ type: 'rotate', degrees: 90 }` a\n\t\t\t// reliable \"90\u00B0 clockwise visually\" instruction across flip\n\t\t\t// states, matching the SNAP_ROTATE_90 convention.\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst fieldDelta = singleFlip ? -op.degrees : op.degrees;\n\t\t\treturn {\n\t\t\t\ttype: 'SET_ROTATION',\n\t\t\t\tpayload: normalizeRotation( state.rotation + fieldDelta ),\n\t\t\t};\n\t\t}\n\t\tcase 'flip':\n\t\t\treturn {\n\t\t\t\ttype: 'SET_FLIP',\n\t\t\t\tpayload: {\n\t\t\t\t\t...state.flip,\n\t\t\t\t\t[ op.direction ]: ! state.flip[ op.direction ],\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'zoom':\n\t\t\treturn { type: 'SET_ZOOM', payload: op.factor };\n\t}\n}\n\n/**\n * Enforces containment: restricts the crop rect to fit within the\n * rotated image, computes minimum zoom, clamps zoom, and restricts\n * the pan position so the image always covers the crop area.\n * Called after every relevant state transition.\n *\n * @param state The state to enforce containment on.\n * @return The state with cropRect, zoom, and position restricted.\n */\nexport function enforceContainment( state: CropperState ): CropperState {\n\tif ( ! state.image ) {\n\t\treturn state;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tconst imageAspectRatio = imageSize.width / imageSize.height;\n\n\t// 1. First bump zoom so the image can cover the crop rect as-is.\n\t// This ensures that explicit crop rect changes (e.g., fixed-crop\n\t// mode during rotation) get zoom accommodation, not crop shrinkage.\n\tconst { pan: panAfterZoom, zoom } = restrictPanZoom(\n\t\tstate,\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\n\t// 2. Now restrict the crop rect at the (possibly bumped) zoom.\n\t// This handles cases where the crop rect is still too large\n\t// (e.g., if zoom hit MAX_ZOOM).\n\tconst cropRect = restrictCropRect(\n\t\tstate.cropRect,\n\t\tzoom,\n\t\tstate.rotation,\n\t\timageAspectRatio\n\t);\n\n\t// 3. If the crop rect was shrunk, re-restrict pan for the new rect.\n\tlet pan = panAfterZoom;\n\tif ( cropRect !== state.cropRect ) {\n\t\t( { pan } = restrictPanZoom(\n\t\t\t{ ...state, zoom, cropRect },\n\t\t\timageSize,\n\t\t\tcropRect\n\t\t) );\n\t}\n\n\tif (\n\t\tpan.x === state.pan.x &&\n\t\tpan.y === state.pan.y &&\n\t\tzoom === state.zoom &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn { ...state, pan, zoom, cropRect };\n}\n\n/**\n * Snapshot the current `crop`, `zoom`, and `rotation` into the\n * corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called\n * by every committing action so that the next SET_ROTATION derives\n * its transient pan from a fresh base (not from a drifted one).\n *\n * SET_ROTATION is the only action that does NOT commit base \u2014 it\n * reads the base, computes a transient pan, and leaves the base\n * alone. This is what eliminates rotation drift near edges.\n *\n * @param next The post-containment state to commit.\n * @return The state with base fields synced to current.\n */\nfunction commitBase( next: CropperState ): CropperState {\n\tif (\n\t\tnext.basePan.x === next.pan.x &&\n\t\tnext.basePan.y === next.pan.y &&\n\t\tnext.baseZoom === next.zoom &&\n\t\tnext.baseRotation === next.rotation\n\t) {\n\t\treturn next;\n\t}\n\treturn {\n\t\t...next,\n\t\tbasePan: { x: next.pan.x, y: next.pan.y },\n\t\tbaseZoom: next.zoom,\n\t\tbaseRotation: next.rotation,\n\t};\n}\n\n/**\n * Reducer function for cropper state management.\n *\n * Every state transition that could invalidate the containment invariant\n * (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment\n * to ensure the image always covers the crop area.\n *\n * Committing actions (everything except SET_ROTATION) also call\n * `commitBase` to snapshot the post-containment state as the new\n * base pose. SET_ROTATION derives from that base without mutating\n * it, which prevents accumulated-clamp drift during continuous fine\n * rotation.\n *\n * @param state The current cropper state.\n * @param action The action to process.\n * @return The new cropper state.\n */\nexport function cropperReducer(\n\tstate: CropperState,\n\taction: CropperAction\n): CropperState {\n\t// Every action runs through enforceContainment to maintain the invariant:\n\t// the image always fully covers the crop area.\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\timage: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SET_PAN':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tpan: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SET_ZOOM': {\n\t\t\tconst z = clampRequestedZoom( state, action.payload );\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: z,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_ZOOM_AT_POINT': {\n\t\t\tconst z = clampRequestedZoom( state, action.payload.zoom );\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: z,\n\t\t\t\t\tpan: action.payload.pan,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_ROTATION': {\n\t\t\t// Rotate the base pan around the crop-rect center by the\n\t\t\t// delta from the base rotation. Deriving each tick from\n\t\t\t// the fixed base \u2014 rather than compounding on the previous\n\t\t\t// tick \u2014 prevents accumulated-clamp drift. Rotating\n\t\t\t// 0\u00B0\u219230\u00B0\u21920\u00B0 now returns to the exact base pan.\n\t\t\t//\n\t\t\t// Zoom starts from baseZoom; enforceContainment may bump it\n\t\t\t// up to cover the rotated crop, but never raises the base.\n\t\t\t//\n\t\t\t// SET_ROTATION is the only action that does NOT call\n\t\t\t// commitBase \u2014 the base pose stays pinned at the user's\n\t\t\t// last committed pan/zoom/rotation.\n\t\t\tconst newRotation = normalizeRotation( action.payload );\n\t\t\t// With viewport-relative flip, pan rotation is conjugated by\n\t\t\t// the flip (S * R * S) \u2014 which reverses direction when exactly\n\t\t\t// one axis is flipped. Negate sin in that case so the crop\n\t\t\t// stays framed on the same image content through rotation.\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst deltaRad = degreesToRadians(\n\t\t\t\tnewRotation - state.baseRotation\n\t\t\t);\n\t\t\tconst cos = Math.cos( deltaRad );\n\t\t\tconst sin = Math.sin( deltaRad ) * ( singleFlip ? -1 : 1 );\n\t\t\tconst cropCx = state.cropRect.x + state.cropRect.width / 2;\n\t\t\tconst cropCy = state.cropRect.y + state.cropRect.height / 2;\n\t\t\tconst ox = cropCx - 0.5;\n\t\t\tconst oy = cropCy - 0.5;\n\t\t\tconst dx = state.basePan.x - ox;\n\t\t\tconst dy = state.basePan.y - oy;\n\t\t\treturn enforceContainment( {\n\t\t\t\t...state,\n\t\t\t\trotation: newRotation,\n\t\t\t\tzoom: state.baseZoom,\n\t\t\t\tpan: {\n\t\t\t\t\tx: ox + cos * dx - sin * dy,\n\t\t\t\t\ty: oy + sin * dx + cos * dy,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tcase 'SNAP_ROTATE_90': {\n\t\t\t// 90\u00B0 snap: the crop rect rotates 90\u00B0 around its own center\n\t\t\t// (width/height swap), and the pan rotates 90\u00B0 around the\n\t\t\t// pan-space origin. The combination keeps the same image\n\t\t\t// slice framed \u2014 just viewed through a rotated window.\n\t\t\t//\n\t\t\t// `direction` is the visual rotation the caller wants: +1\n\t\t\t// means \"rotate the image CW on screen\", \u22121 means \"CCW\".\n\t\t\t// With a single-axis flip active, rotation on screen appears\n\t\t\t// reversed relative to the rotation field (S\u00B7R\u00B7S conjugation),\n\t\t\t// so internally we negate the direction applied to the\n\t\t\t// `rotation` field. Pan rotates in the caller's direction \u2014\n\t\t\t// that way the same image content stays framed after the\n\t\t\t// snap regardless of flip state.\n\t\t\tconst rawDir = action.payload.direction;\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst fieldDir = singleFlip ? -rawDir : rawDir;\n\t\t\tconst rot90 = normalizeRotation( state.rotation + fieldDir * 90 );\n\t\t\tconst rect = state.cropRect;\n\t\t\tconst cx = rect.x + rect.width / 2;\n\t\t\tconst cy = rect.y + rect.height / 2;\n\n\t\t\t// Rotate pan vector 90\u00B0 around origin.\n\t\t\t// CW (rawDir=+1): (px, py) \u2192 (-py, px)\n\t\t\t// CCW (rawDir=-1): (px, py) \u2192 (py, -px)\n\t\t\tconst newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;\n\t\t\tconst newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;\n\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\trotation: rot90,\n\t\t\t\t\tzoom: state.baseZoom,\n\t\t\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: cx - rect.height / 2,\n\t\t\t\t\t\ty: cy - rect.width / 2,\n\t\t\t\t\t\twidth: rect.height,\n\t\t\t\t\t\theight: rect.width,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_FLIP': {\n\t\t\t// Mirror the crop rect and pan so the same image content stays\n\t\t\t// framed after a flip. Flip in the camera matrix is composed\n\t\t\t// outside rotation (viewport-relative), so both `pan` and\n\t\t\t// `cropRect` live in viewport-aligned space: negating the flipped\n\t\t\t// axis on each is enough \u2014 no rotation math needed.\n\t\t\tconst oldFlip = state.flip;\n\t\t\tconst newFlip = action.payload;\n\t\t\tconst flippedH = oldFlip.horizontal !== newFlip.horizontal;\n\t\t\tconst flippedV = oldFlip.vertical !== newFlip.vertical;\n\t\t\tconst rect = state.cropRect;\n\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tflip: newFlip,\n\t\t\t\t\tpan: {\n\t\t\t\t\t\tx: flippedH ? -state.pan.x : state.pan.x,\n\t\t\t\t\t\ty: flippedV ? -state.pan.y : state.pan.y,\n\t\t\t\t\t},\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: flippedH ? 1 - rect.x - rect.width : rect.x,\n\t\t\t\t\t\ty: flippedV ? 1 - rect.y - rect.height : rect.y,\n\t\t\t\t\t\twidth: rect.width,\n\t\t\t\t\t\theight: rect.height,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_CROP_RECT':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tcropRect: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SETTLE_CROP': {\n\t\t\t// After a resize drag ends: expand the crop to fill the\n\t\t\t// available height (maintaining its aspect ratio), center it,\n\t\t\t// and adjust zoom/pan so the exact same image content that\n\t\t\t// was visible inside the old crop is visible in the new one.\n\t\t\tconst rect = state.cropRect;\n\t\t\tif ( rect.width === 0 || rect.height === 0 || ! state.image ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\t// Scale factor: how much the crop grows. fitScale fills the\n\t\t\t// larger axis to 1 (viewport-filling settle). Cap so the\n\t\t\t// resulting zoom stays at or below MAX_ZOOM \u2014 tight crops\n\t\t\t// would otherwise push state.zoom past the user-facing cap\n\t\t\t// and break wheel/slider interactions, which clamp to\n\t\t\t// MAX_ZOOM and snap state.zoom down on the first input.\n\t\t\tconst fitScale = 1 / Math.max( rect.width, rect.height );\n\t\t\tconst zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;\n\t\t\tconst s = Math.min( fitScale, zoomCap );\n\n\t\t\tconst newW = rect.width * s;\n\t\t\tconst newH = rect.height * s;\n\n\t\t\t// The old crop center in normalized visual space.\n\t\t\tconst oldCx = rect.x + rect.width / 2;\n\t\t\tconst oldCy = rect.y + rect.height / 2;\n\n\t\t\t// Zoom scales by s so the same image region fills the new\n\t\t\t// crop at the same relative size. When s is capped, the new\n\t\t\t// crop is smaller than the viewport but the visible content\n\t\t\t// inside it remains the source region the user framed.\n\t\t\t// Pan: the visible content center was at\n\t\t\t// (cropCx - crop.x, cropCy - crop.y)\n\t\t\t// in visual-normalized space. After centering the crop to\n\t\t\t// (0.5, 0.5), the pan must place that same content at\n\t\t\t// the new center. Both pan and zoom scale by s because\n\t\t\t// the CSS translate is independent of zoom.\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: state.zoom * s,\n\t\t\t\t\tpan: {\n\t\t\t\t\t\tx: ( state.pan.x - oldCx + 0.5 ) * s,\n\t\t\t\t\t\ty: ( state.pan.y - oldCy + 0.5 ) * s,\n\t\t\t\t\t},\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: ( 1 - newW ) / 2,\n\t\t\t\t\t\ty: ( 1 - newH ) / 2,\n\t\t\t\t\t\twidth: newW,\n\t\t\t\t\t\theight: newH,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'APPLY_OPERATION':\n\t\t\t// Route through the action equivalent so a pipeline replay\n\t\t\t// yields the same bounded state as the matching UI/setter\n\t\t\t// path (containment, baseZoom relaxation, pan rotation\n\t\t\t// around crop center, etc.).\n\t\t\treturn cropperReducer(\n\t\t\t\tstate,\n\t\t\t\toperationToAction( state, action.payload )\n\t\t\t);\n\n\t\tcase 'RESET':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...DEFAULT_STATE,\n\t\t\t\t\timage: state.image,\n\t\t\t\t\t...action.payload,\n\t\t\t\t} )\n\t\t\t);\n\t}\n}\n\n/**\n * Shallow comparison of key cropper state fields to determine if\n * the state has been modified from an initial snapshot.\n *\n * @param current The current cropper state.\n * @param initial The initial cropper state snapshot.\n * @return True if any tracked field differs.\n */\nexport function isStateDirty(\n\tcurrent: CropperState,\n\tinitial: CropperState\n): boolean {\n\treturn (\n\t\t! nearlyEqual( current.pan.x, initial.pan.x ) ||\n\t\t! nearlyEqual( current.pan.y, initial.pan.y ) ||\n\t\t! nearlyEqual( current.zoom, initial.zoom ) ||\n\t\t! nearlyEqual( current.rotation, initial.rotation ) ||\n\t\tcurrent.flip.horizontal !== initial.flip.horizontal ||\n\t\tcurrent.flip.vertical !== initial.flip.vertical ||\n\t\t! nearlyEqual( current.cropRect.x, initial.cropRect.x ) ||\n\t\t! nearlyEqual( current.cropRect.y, initial.cropRect.y ) ||\n\t\t! nearlyEqual( current.cropRect.width, initial.cropRect.width ) ||\n\t\t! nearlyEqual( current.cropRect.height, initial.cropRect.height )\n\t);\n}\n"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperAction, CropperState, TransformOperation } from './types';\nimport {\n\tABSOLUTE_MIN_ZOOM,\n\tDEFAULT_STATE,\n\tMAX_ZOOM,\n\tMIN_ZOOM,\n} from './constants';\nimport { normalizeRotation, degreesToRadians } from './math/rotation';\nimport { restrictPanZoom, restrictCropRect } from './containment';\n\n/** Small tolerance for cropper floating-point comparisons. */\nconst STATE_EPSILON = 1e-6;\n\nfunction nearlyEqual( a: number, b: number ): boolean {\n\treturn Math.abs( a - b ) < STATE_EPSILON;\n}\n\n/**\n * Value-equality check for two cropper states.\n *\n * Used by history machinery to dedup snapshots and detect no-op\n * transitions. Compares every field that participates in the rendered\n * output; ignores reference identity.\n *\n * @param a First cropper state.\n * @param b Second cropper state.\n * @return Whether the two states are value-equal across all tracked fields.\n */\nexport function areCropperStatesEqual(\n\ta: CropperState,\n\tb: CropperState\n): boolean {\n\tconst aImage = a.image;\n\tconst bImage = b.image;\n\treturn (\n\t\taImage?.src === bImage?.src &&\n\t\taImage?.naturalWidth === bImage?.naturalWidth &&\n\t\taImage?.naturalHeight === bImage?.naturalHeight &&\n\t\tnearlyEqual( a.pan.x, b.pan.x ) &&\n\t\tnearlyEqual( a.pan.y, b.pan.y ) &&\n\t\tnearlyEqual( a.zoom, b.zoom ) &&\n\t\tnearlyEqual( a.rotation, b.rotation ) &&\n\t\ta.flip.horizontal === b.flip.horizontal &&\n\t\ta.flip.vertical === b.flip.vertical &&\n\t\tnearlyEqual( a.cropRect.x, b.cropRect.x ) &&\n\t\tnearlyEqual( a.cropRect.y, b.cropRect.y ) &&\n\t\tnearlyEqual( a.cropRect.width, b.cropRect.width ) &&\n\t\tnearlyEqual( a.cropRect.height, b.cropRect.height )\n\t);\n}\n\nfunction clampRequestedZoom( state: CropperState, zoom: number ): number {\n\t// With an image, enforceContainment raises zoom to the coverage-aware\n\t// floor below. Without an image, no enforcement runs, so MIN_ZOOM stays\n\t// the conservative resting default.\n\tif ( state.image ) {\n\t\treturn Math.min( MAX_ZOOM, Math.max( ABSOLUTE_MIN_ZOOM, zoom ) );\n\t}\n\treturn Math.min( MAX_ZOOM, Math.max( MIN_ZOOM, zoom ) );\n}\n\n/**\n * Translate a pipeline transform operation into the equivalent\n * reducer action. Pipeline ops aren't 1:1 with reducer actions —\n * `rotate` is a delta here, whereas SET_ROTATION takes an absolute\n * angle — so deltas are resolved against the current state.\n *\n * Used by APPLY_OPERATION (and by the pipeline module's\n * `applyOperationToState`, which is now a thin wrapper around the\n * reducer) so that pipeline replay produces identical bounded\n * state to UI interaction or direct setters.\n *\n * @param state The current cropper state.\n * @param op The pipeline operation.\n * @return The equivalent reducer action.\n */\nfunction operationToAction(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperAction {\n\tswitch ( op.type ) {\n\t\tcase 'crop':\n\t\t\treturn { type: 'SET_CROP_RECT', payload: { ...op.rect } };\n\t\tcase 'rotate': {\n\t\t\t// `op.degrees` is the visual rotation the caller wants (positive\n\t\t\t// = CW on screen). A single-axis flip inverts on-screen rotation\n\t\t\t// relative to the rotation field, so negate the field delta in\n\t\t\t// that case — this keeps `{ type: 'rotate', degrees: 90 }` a\n\t\t\t// reliable \"90° clockwise visually\" instruction across flip\n\t\t\t// states, matching the SNAP_ROTATE_90 convention.\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst fieldDelta = singleFlip ? -op.degrees : op.degrees;\n\t\t\treturn {\n\t\t\t\ttype: 'SET_ROTATION',\n\t\t\t\tpayload: normalizeRotation( state.rotation + fieldDelta ),\n\t\t\t};\n\t\t}\n\t\tcase 'flip':\n\t\t\treturn {\n\t\t\t\ttype: 'SET_FLIP',\n\t\t\t\tpayload: {\n\t\t\t\t\t...state.flip,\n\t\t\t\t\t[ op.direction ]: ! state.flip[ op.direction ],\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'zoom':\n\t\t\treturn { type: 'SET_ZOOM', payload: op.factor };\n\t}\n}\n\n/**\n * Enforces containment: restricts the crop rect to fit within the\n * rotated image, computes minimum zoom, clamps zoom, and restricts\n * the pan position so the image always covers the crop area.\n * Called after every relevant state transition.\n *\n * @param state The state to enforce containment on.\n * @return The state with cropRect, zoom, and position restricted.\n */\nexport function enforceContainment( state: CropperState ): CropperState {\n\tif ( ! state.image ) {\n\t\treturn state;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tconst imageAspectRatio = imageSize.width / imageSize.height;\n\n\t// 1. First bump zoom so the image can cover the crop rect as-is.\n\t// This ensures that explicit crop rect changes (e.g., fixed-crop\n\t// mode during rotation) get zoom accommodation, not crop shrinkage.\n\tconst { pan: panAfterZoom, zoom } = restrictPanZoom(\n\t\tstate,\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\n\t// 2. Now restrict the crop rect at the (possibly bumped) zoom.\n\t// This handles cases where the crop rect is still too large\n\t// (e.g., if zoom hit MAX_ZOOM).\n\tconst cropRect = restrictCropRect(\n\t\tstate.cropRect,\n\t\tzoom,\n\t\tstate.rotation,\n\t\timageAspectRatio\n\t);\n\n\t// 3. If the crop rect was shrunk, re-restrict pan for the new rect.\n\tlet pan = panAfterZoom;\n\tif ( cropRect !== state.cropRect ) {\n\t\t( { pan } = restrictPanZoom(\n\t\t\t{ ...state, zoom, cropRect },\n\t\t\timageSize,\n\t\t\tcropRect\n\t\t) );\n\t}\n\n\tif (\n\t\tpan.x === state.pan.x &&\n\t\tpan.y === state.pan.y &&\n\t\tzoom === state.zoom &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn { ...state, pan, zoom, cropRect };\n}\n\n/**\n * Snapshot the current `crop`, `zoom`, and `rotation` into the\n * corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called\n * by every committing action so that the next SET_ROTATION derives\n * its transient pan from a fresh base (not from a drifted one).\n *\n * SET_ROTATION is the only action that does NOT commit base — it\n * reads the base, computes a transient pan, and leaves the base\n * alone. This is what eliminates rotation drift near edges.\n *\n * @param next The post-containment state to commit.\n * @return The state with base fields synced to current.\n */\nfunction commitBase( next: CropperState ): CropperState {\n\tif (\n\t\tnext.basePan.x === next.pan.x &&\n\t\tnext.basePan.y === next.pan.y &&\n\t\tnext.baseZoom === next.zoom &&\n\t\tnext.baseRotation === next.rotation\n\t) {\n\t\treturn next;\n\t}\n\treturn {\n\t\t...next,\n\t\tbasePan: { x: next.pan.x, y: next.pan.y },\n\t\tbaseZoom: next.zoom,\n\t\tbaseRotation: next.rotation,\n\t};\n}\n\n/**\n * Reducer function for cropper state management.\n *\n * Every state transition that could invalidate the containment invariant\n * (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment\n * to ensure the image always covers the crop area.\n *\n * Committing actions (everything except SET_ROTATION) also call\n * `commitBase` to snapshot the post-containment state as the new\n * base pose. SET_ROTATION derives from that base without mutating\n * it, which prevents accumulated-clamp drift during continuous fine\n * rotation.\n *\n * @param state The current cropper state.\n * @param action The action to process.\n * @return The new cropper state.\n */\nexport function cropperReducer(\n\tstate: CropperState,\n\taction: CropperAction\n): CropperState {\n\t// Every action runs through enforceContainment to maintain the invariant:\n\t// the image always fully covers the crop area.\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\timage: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SET_PAN':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tpan: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SET_ZOOM': {\n\t\t\tconst z = clampRequestedZoom( state, action.payload );\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: z,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_ZOOM_AT_POINT': {\n\t\t\tconst z = clampRequestedZoom( state, action.payload.zoom );\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: z,\n\t\t\t\t\tpan: action.payload.pan,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_ROTATION': {\n\t\t\t// Rotate the base pan around the crop-rect center by the\n\t\t\t// delta from the base rotation. Deriving each tick from\n\t\t\t// the fixed base — rather than compounding on the previous\n\t\t\t// tick — prevents accumulated-clamp drift. Rotating\n\t\t\t// 0°→30°→0° now returns to the exact base pan.\n\t\t\t//\n\t\t\t// Zoom starts from baseZoom; enforceContainment may bump it\n\t\t\t// up to cover the rotated crop, but never raises the base.\n\t\t\t//\n\t\t\t// SET_ROTATION is the only action that does NOT call\n\t\t\t// commitBase — the base pose stays pinned at the user's\n\t\t\t// last committed pan/zoom/rotation.\n\t\t\tconst newRotation = normalizeRotation( action.payload );\n\t\t\t// With viewport-relative flip, pan rotation is conjugated by\n\t\t\t// the flip (S * R * S) — which reverses direction when exactly\n\t\t\t// one axis is flipped. Negate sin in that case so the crop\n\t\t\t// stays framed on the same image content through rotation.\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst deltaRad = degreesToRadians(\n\t\t\t\tnewRotation - state.baseRotation\n\t\t\t);\n\t\t\tconst cos = Math.cos( deltaRad );\n\t\t\tconst sin = Math.sin( deltaRad ) * ( singleFlip ? -1 : 1 );\n\t\t\tconst cropCx = state.cropRect.x + state.cropRect.width / 2;\n\t\t\tconst cropCy = state.cropRect.y + state.cropRect.height / 2;\n\t\t\tconst ox = cropCx - 0.5;\n\t\t\tconst oy = cropCy - 0.5;\n\t\t\tconst dx = state.basePan.x - ox;\n\t\t\tconst dy = state.basePan.y - oy;\n\t\t\treturn enforceContainment( {\n\t\t\t\t...state,\n\t\t\t\trotation: newRotation,\n\t\t\t\tzoom: state.baseZoom,\n\t\t\t\tpan: {\n\t\t\t\t\tx: ox + cos * dx - sin * dy,\n\t\t\t\t\ty: oy + sin * dx + cos * dy,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tcase 'SNAP_ROTATE_90': {\n\t\t\t// 90° snap: the crop rect rotates 90° around its own center\n\t\t\t// (width/height swap), and the pan rotates 90° around the\n\t\t\t// pan-space origin. The combination keeps the same image\n\t\t\t// slice framed — just viewed through a rotated window.\n\t\t\t//\n\t\t\t// `direction` is the visual rotation the caller wants: +1\n\t\t\t// means \"rotate the image CW on screen\", −1 means \"CCW\".\n\t\t\t// With a single-axis flip active, rotation on screen appears\n\t\t\t// reversed relative to the rotation field (S·R·S conjugation),\n\t\t\t// so internally we negate the direction applied to the\n\t\t\t// `rotation` field. Pan rotates in the caller's direction —\n\t\t\t// that way the same image content stays framed after the\n\t\t\t// snap regardless of flip state.\n\t\t\tconst rawDir = action.payload.direction;\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst fieldDir = singleFlip ? -rawDir : rawDir;\n\t\t\tconst rot90 = normalizeRotation( state.rotation + fieldDir * 90 );\n\t\t\tconst rect = state.cropRect;\n\t\t\tconst cx = rect.x + rect.width / 2;\n\t\t\tconst cy = rect.y + rect.height / 2;\n\n\t\t\t// Rotate pan vector 90° around origin.\n\t\t\t// CW (rawDir=+1): (px, py) → (-py, px)\n\t\t\t// CCW (rawDir=-1): (px, py) → (py, -px)\n\t\t\tconst newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;\n\t\t\tconst newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;\n\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\trotation: rot90,\n\t\t\t\t\tzoom: state.baseZoom,\n\t\t\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: cx - rect.height / 2,\n\t\t\t\t\t\ty: cy - rect.width / 2,\n\t\t\t\t\t\twidth: rect.height,\n\t\t\t\t\t\theight: rect.width,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_FLIP': {\n\t\t\t// Mirror the crop rect and pan so the same image content stays\n\t\t\t// framed after a flip. Flip in the camera matrix is composed\n\t\t\t// outside rotation (viewport-relative), so both `pan` and\n\t\t\t// `cropRect` live in viewport-aligned space: negating the flipped\n\t\t\t// axis on each is enough — no rotation math needed.\n\t\t\tconst oldFlip = state.flip;\n\t\t\tconst newFlip = action.payload;\n\t\t\tconst flippedH = oldFlip.horizontal !== newFlip.horizontal;\n\t\t\tconst flippedV = oldFlip.vertical !== newFlip.vertical;\n\t\t\tconst rect = state.cropRect;\n\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tflip: newFlip,\n\t\t\t\t\tpan: {\n\t\t\t\t\t\tx: flippedH ? -state.pan.x : state.pan.x,\n\t\t\t\t\t\ty: flippedV ? -state.pan.y : state.pan.y,\n\t\t\t\t\t},\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: flippedH ? 1 - rect.x - rect.width : rect.x,\n\t\t\t\t\t\ty: flippedV ? 1 - rect.y - rect.height : rect.y,\n\t\t\t\t\t\twidth: rect.width,\n\t\t\t\t\t\theight: rect.height,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_CROP_RECT':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tcropRect: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SETTLE_CROP': {\n\t\t\t// After a resize drag ends: expand the crop to fill the\n\t\t\t// available height (maintaining its aspect ratio), center it,\n\t\t\t// and adjust zoom/pan so the exact same image content that\n\t\t\t// was visible inside the old crop is visible in the new one.\n\t\t\tconst rect = state.cropRect;\n\t\t\tif ( rect.width === 0 || rect.height === 0 || ! state.image ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\t// Scale factor: how much the crop grows. fitScale fills the\n\t\t\t// larger axis to 1 (viewport-filling settle). Cap so the\n\t\t\t// resulting zoom stays at or below MAX_ZOOM — tight crops\n\t\t\t// would otherwise push state.zoom past the user-facing cap\n\t\t\t// and break wheel/slider interactions, which clamp to\n\t\t\t// MAX_ZOOM and snap state.zoom down on the first input.\n\t\t\tconst fitScale = 1 / Math.max( rect.width, rect.height );\n\t\t\tconst zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;\n\t\t\tconst s = Math.min( fitScale, zoomCap );\n\n\t\t\tconst newW = rect.width * s;\n\t\t\tconst newH = rect.height * s;\n\n\t\t\t// The old crop center in normalized visual space.\n\t\t\tconst oldCx = rect.x + rect.width / 2;\n\t\t\tconst oldCy = rect.y + rect.height / 2;\n\n\t\t\t// Zoom scales by s so the same image region fills the new\n\t\t\t// crop at the same relative size. When s is capped, the new\n\t\t\t// crop is smaller than the viewport but the visible content\n\t\t\t// inside it remains the source region the user framed.\n\t\t\t// Pan: the visible content center was at\n\t\t\t// (cropCx - crop.x, cropCy - crop.y)\n\t\t\t// in visual-normalized space. After centering the crop to\n\t\t\t// (0.5, 0.5), the pan must place that same content at\n\t\t\t// the new center. Both pan and zoom scale by s because\n\t\t\t// the CSS translate is independent of zoom.\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: state.zoom * s,\n\t\t\t\t\tpan: {\n\t\t\t\t\t\tx: ( state.pan.x - oldCx + 0.5 ) * s,\n\t\t\t\t\t\ty: ( state.pan.y - oldCy + 0.5 ) * s,\n\t\t\t\t\t},\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: ( 1 - newW ) / 2,\n\t\t\t\t\t\ty: ( 1 - newH ) / 2,\n\t\t\t\t\t\twidth: newW,\n\t\t\t\t\t\theight: newH,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'APPLY_OPERATION':\n\t\t\t// Route through the action equivalent so a pipeline replay\n\t\t\t// yields the same bounded state as the matching UI/setter\n\t\t\t// path (containment, baseZoom relaxation, pan rotation\n\t\t\t// around crop center, etc.).\n\t\t\treturn cropperReducer(\n\t\t\t\tstate,\n\t\t\t\toperationToAction( state, action.payload )\n\t\t\t);\n\n\t\tcase 'RESET':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...DEFAULT_STATE,\n\t\t\t\t\timage: state.image,\n\t\t\t\t\t...action.payload,\n\t\t\t\t} )\n\t\t\t);\n\t}\n}\n\n/**\n * Shallow comparison of key cropper state fields to determine if\n * the state has been modified from an initial snapshot.\n *\n * @param current The current cropper state.\n * @param initial The initial cropper state snapshot.\n * @return True if any tracked field differs.\n */\nexport function isStateDirty(\n\tcurrent: CropperState,\n\tinitial: CropperState\n): boolean {\n\treturn (\n\t\t! nearlyEqual( current.pan.x, initial.pan.x ) ||\n\t\t! nearlyEqual( current.pan.y, initial.pan.y ) ||\n\t\t! nearlyEqual( current.zoom, initial.zoom ) ||\n\t\t! nearlyEqual( current.rotation, initial.rotation ) ||\n\t\tcurrent.flip.horizontal !== initial.flip.horizontal ||\n\t\tcurrent.flip.vertical !== initial.flip.vertical ||\n\t\t! nearlyEqual( current.cropRect.x, initial.cropRect.x ) ||\n\t\t! nearlyEqual( current.cropRect.y, initial.cropRect.y ) ||\n\t\t! nearlyEqual( current.cropRect.width, initial.cropRect.width ) ||\n\t\t! nearlyEqual( current.cropRect.height, initial.cropRect.height )\n\t);\n}\n"],
5
5
  "mappings": ";AAIA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,iBAAiB,wBAAwB;AAGlD,IAAM,gBAAgB;AAEtB,SAAS,YAAa,GAAW,GAAqB;AACrD,SAAO,KAAK,IAAK,IAAI,CAAE,IAAI;AAC5B;AAaO,SAAS,sBACf,GACA,GACU;AACV,QAAM,SAAS,EAAE;AACjB,QAAM,SAAS,EAAE;AACjB,SACC,QAAQ,QAAQ,QAAQ,OACxB,QAAQ,iBAAiB,QAAQ,gBACjC,QAAQ,kBAAkB,QA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AAA,MAC1C;AAAA,IAED,KAAK;AACJ,aAAO;AAAA,QACN,mBAAoB;AAAA,UACnB,GAAG;AAAA,UACH,OAAO,MAAM;AAAA,UACb,GAAG,OAAO;AAAA,QACX,CAAE;AAAA,MACH;AAAA,EACF;AACD;AAUO,SAAS,aACf,SACA,SACU;AACV,SACC,CAAE,YAAa,QAAQ,IAAI,GAAG,QAAQ,IAAI,CAAE,KAC5C,CAAE,YAAa,QAAQ,IAAI,GAAG,QAAQ,IAAI,CAAE,KAC5C,CAAE,YAAa,QAAQ,MAAM,QAAQ,IAAK,KAC1C,CAAE,YAAa,QAAQ,UAAU,QAAQ,QAAS,KAClD,QAAQ,KAAK,eAAe,QAAQ,KAAK,cACzC,QAAQ,KAAK,aAAa,QAAQ,KAAK,YACvC,CAAE,YAAa,QAAQ,SAAS,GAAG,QAAQ,SAAS,CAAE,KACtD,CAAE,YAAa,QAAQ,SAAS,GAAG,QAAQ,SAAS,CAAE,KACtD,CAAE,YAAa,QAAQ,SAAS,OAAO,QAAQ,SAAS,KAAM,KAC9D,CAAE,YAAa,QAAQ,SAAS,QAAQ,QAAQ,SAAS,MAAO;AAElE;",
6
6
  "names": []
7
7
  }
@@ -47,7 +47,7 @@ function computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCro
47
47
  height: edgeBottom - edgeTop
48
48
  };
49
49
  }
50
- function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize = DEFAULT_MIN_CROP_SIZE) {
50
+ function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize = DEFAULT_MIN_CROP_SIZE, driverAxis) {
51
51
  if (normalizedRatio <= 0 || imageSize.width <= 0 || imageSize.height <= 0) {
52
52
  return { ...drag.startRect };
53
53
  }
@@ -70,10 +70,9 @@ function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, norm
70
70
  const minDistH = minDistW / normalizedRatio;
71
71
  distW = Math.max(distW, minDistW);
72
72
  distH = Math.max(distH, minDistH);
73
- const pixelDistW = distW * imageSize.width;
74
- const pixelDistH = distH * imageSize.height;
75
73
  const pixelRatio = normalizedRatio * imageSize.width / imageSize.height;
76
- if (pixelDistW / pixelDistH > pixelRatio) {
74
+ const isWidthDriver = driverAxis === "width" || !driverAxis && distW * imageSize.width / (distH * imageSize.height) > pixelRatio;
75
+ if (isWidthDriver) {
77
76
  distH = distW / normalizedRatio;
78
77
  } else {
79
78
  distW = distH * normalizedRatio;