@wordpress/media-editor 0.11.1 → 0.11.2-next.v.202606191442.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 (138) hide show
  1. package/build/components/media-editor/index.cjs.map +1 -1
  2. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  3. package/build/components/media-editor-canvas/index.cjs +63 -15
  4. package/build/components/media-editor-canvas/index.cjs.map +3 -3
  5. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  6. package/build/components/media-editor-image-controls/index.cjs +2 -2
  7. package/build/components/media-editor-image-controls/index.cjs.map +2 -2
  8. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
  9. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
  10. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
  11. package/build/components/rotation-ruler/index.cjs +1 -1
  12. package/build/components/rotation-ruler/index.cjs.map +1 -1
  13. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  14. package/build/image-editor/core/camera.cjs +13 -0
  15. package/build/image-editor/core/camera.cjs.map +2 -2
  16. package/build/image-editor/core/constants.cjs +12 -3
  17. package/build/image-editor/core/constants.cjs.map +2 -2
  18. package/build/image-editor/core/containment.cjs.map +1 -1
  19. package/build/image-editor/core/crop-rect.cjs.map +1 -1
  20. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
  21. package/build/image-editor/core/interaction-controller.cjs +9 -7
  22. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  23. package/build/image-editor/core/math/sanitize.cjs.map +1 -1
  24. package/build/image-editor/core/setter-helpers.cjs.map +1 -1
  25. package/build/image-editor/core/source-region.cjs +111 -2
  26. package/build/image-editor/core/source-region.cjs.map +2 -2
  27. package/build/image-editor/core/state.cjs.map +1 -1
  28. package/build/image-editor/core/stencil-math.cjs +3 -4
  29. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  30. package/build/image-editor/core/transform-style.cjs.map +1 -1
  31. package/build/image-editor/core/types.cjs.map +1 -1
  32. package/build/image-editor/react/components/cropper.cjs +232 -55
  33. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  34. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
  35. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
  36. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  37. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
  38. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  39. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
  40. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
  41. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
  42. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
  43. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
  44. package/build/index.cjs.map +1 -1
  45. package/build/state/types.cjs.map +1 -1
  46. package/build/state/use-media-editor-state.cjs +1 -1
  47. package/build/state/use-media-editor-state.cjs.map +2 -2
  48. package/build-module/components/media-editor/index.mjs.map +1 -1
  49. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  50. package/build-module/components/media-editor-canvas/index.mjs +55 -17
  51. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  52. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  53. package/build-module/components/media-editor-image-controls/index.mjs +2 -2
  54. package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
  55. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
  56. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
  57. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
  58. package/build-module/components/rotation-ruler/index.mjs +1 -1
  59. package/build-module/components/rotation-ruler/index.mjs.map +1 -1
  60. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
  61. package/build-module/image-editor/core/camera.mjs +12 -0
  62. package/build-module/image-editor/core/camera.mjs.map +2 -2
  63. package/build-module/image-editor/core/constants.mjs +8 -2
  64. package/build-module/image-editor/core/constants.mjs.map +2 -2
  65. package/build-module/image-editor/core/containment.mjs.map +1 -1
  66. package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
  67. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
  68. package/build-module/image-editor/core/interaction-controller.mjs +9 -7
  69. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  70. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
  71. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
  72. package/build-module/image-editor/core/source-region.mjs +108 -1
  73. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  74. package/build-module/image-editor/core/state.mjs.map +1 -1
  75. package/build-module/image-editor/core/stencil-math.mjs +3 -4
  76. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  77. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  78. package/build-module/image-editor/react/components/cropper.mjs +242 -57
  79. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  80. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
  81. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
  82. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  83. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +65 -19
  84. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  85. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
  86. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
  87. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
  88. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
  89. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
  90. package/build-module/index.mjs.map +1 -1
  91. package/build-module/state/types.mjs.map +1 -1
  92. package/build-module/state/use-media-editor-state.mjs +1 -1
  93. package/build-module/state/use-media-editor-state.mjs.map +2 -2
  94. package/build-style/style-rtl.css +49 -6
  95. package/build-style/style.css +49 -6
  96. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  97. package/build-types/image-editor/core/camera.d.ts +25 -1
  98. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  99. package/build-types/image-editor/core/constants.d.ts +20 -1
  100. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  101. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  102. package/build-types/image-editor/core/source-region.d.ts +23 -1
  103. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  104. package/build-types/image-editor/core/stencil-math.d.ts +10 -5
  105. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  106. package/build-types/image-editor/core/types.d.ts +14 -0
  107. package/build-types/image-editor/core/types.d.ts.map +1 -1
  108. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  109. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  110. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
  111. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  112. package/package.json +25 -20
  113. package/src/components/media-editor/style.scss +21 -9
  114. package/src/components/media-editor-canvas/index.tsx +82 -13
  115. package/src/components/media-editor-canvas/style.scss +41 -0
  116. package/src/image-editor/core/camera.ts +60 -1
  117. package/src/image-editor/core/constants.ts +23 -1
  118. package/src/image-editor/core/interaction-controller.ts +25 -11
  119. package/src/image-editor/core/source-region.ts +202 -1
  120. package/src/image-editor/core/stencil-math.ts +23 -14
  121. package/src/image-editor/core/test/camera.ts +272 -1
  122. package/src/image-editor/core/test/interaction-controller.ts +100 -0
  123. package/src/image-editor/core/test/stencil-math.ts +120 -6
  124. package/src/image-editor/core/types.ts +17 -0
  125. package/src/image-editor/react/components/cropper.tsx +362 -72
  126. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
  127. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
  128. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
  129. package/src/image-editor/react/components/test/cropper.tsx +689 -6
  130. package/tsconfig.tsbuildinfo +1 -1
  131. package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
  132. package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
  133. package/build-types/components/media-editor-transform-controls/index.d.ts +0 -21
  134. package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
  135. package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
  136. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
  137. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
  138. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
@@ -75,7 +75,7 @@ function computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCro
75
75
  height: edgeBottom - edgeTop
76
76
  };
77
77
  }
78
- function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize = DEFAULT_MIN_CROP_SIZE) {
78
+ function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize = DEFAULT_MIN_CROP_SIZE, driverAxis) {
79
79
  if (normalizedRatio <= 0 || imageSize.width <= 0 || imageSize.height <= 0) {
80
80
  return { ...drag.startRect };
81
81
  }
@@ -98,10 +98,9 @@ function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, norm
98
98
  const minDistH = minDistW / normalizedRatio;
99
99
  distW = Math.max(distW, minDistW);
100
100
  distH = Math.max(distH, minDistH);
101
- const pixelDistW = distW * imageSize.width;
102
- const pixelDistH = distH * imageSize.height;
103
101
  const pixelRatio = normalizedRatio * imageSize.width / imageSize.height;
104
- if (pixelDistW / pixelDistH > pixelRatio) {
102
+ const isWidthDriver = driverAxis === "width" || !driverAxis && distW * imageSize.width / (distH * imageSize.height) > pixelRatio;
103
+ if (isWidthDriver) {
105
104
  distH = distW / normalizedRatio;
106
105
  } else {
107
106
  distW = distH * normalizedRatio;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/stencil-math.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/**\n * Resolve the minimum crop dimension, in source-image pixels, for the current\n * display scale.\n *\n * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that\n * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that\n * keeps the crop large enough to grab. The on-screen floor converted to source\n * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the\n * larger of the two. When zoomed out (small `displayScale`) the on-screen floor\n * dominates; once the image is shown large enough the source-pixel floor takes\n * over.\n *\n * @param displayScale CSS pixels rendered per source pixel (fit scale \u00D7 zoom).\n * @return Minimum crop dimension in source-image pixels.\n */\nexport function getMinCropPixels( displayScale: number ): number {\n\tif ( displayScale <= 0 ) {\n\t\treturn MIN_CROP_PIXELS;\n\t}\n\treturn Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );\n}\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\" \u2014 whichever the user moved more\n\t// (in pixel space) determines the size, the other follows. The\n\t// `normalizedRatio` is w/h in normalized space; the equivalent\n\t// pixel-space ratio is `normalizedRatio * imageW / imageH`. We\n\t// compare the pixel motion ratio against that pixel-space ratio\n\t// so the units line up (was a unit mismatch on non-square images).\n\tconst pixelDistW = distW * imageSize.width;\n\tconst pixelDistH = distH * imageSize.height;\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tif ( pixelDistW / pixelDistH > pixelRatio ) {\n\t\t// Width is the driver \u2014 compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver \u2014 compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAoD;AAoB7C,SAAS,iBAAkB,cAA+B;AAChE,MAAK,gBAAgB,GAAI;AACxB,WAAO;AAAA,EACR;AACA,SAAO,KAAK,IAAK,kCAAiB,sCAAqB,YAAa;AACrE;AAQO,IAAM,wBAA8B,EAAE,OAAO,MAAM,QAAQ,KAAK;AAuChE,SAAS,sBACf,MACA,SACA,SACA,WACA,QACA,cAAoB,uBACH;AACjB,QAAM,KACL,UAAU,QAAQ,KAAM,UAAU,KAAK,UAAW,UAAU,QAAQ;AACrE,QAAM,KACL,UAAU,SAAS,KAAM,UAAU,KAAK,UAAW,UAAU,SAAS;AAEvE,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,KAAK;AAEpB,MAAI,UAAU,EAAE;AAChB,MAAI,aAAa,EAAE,IAAI,EAAE;AACzB,MAAI,WAAW,EAAE;AACjB,MAAI,YAAY,EAAE,IAAI,EAAE;AAExB,MAAK,WAAW,OAAO,WAAW,QAAQ,WAAW,MAAO;AAC3D,cAAU,KAAK;AAAA,MACd,OAAO;AAAA,MACP,KAAK,IAAK,EAAE,IA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,QAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,MAAK,YAAY,WAAY;AAC5B,gBAAY;AACZ,eAAW,YAAY;AAAA,EACxB;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,YAAY;AAAA,IACZ,YAAY,SAAS;AAAA,EACtB;AACA,MAAK,WAAW,UAAW;AAC1B,eAAW;AACX,gBAAY,WAAW;AAAA,EACxB;AACA,QAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;AAC3D,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,UAAU,YAAY;AAAA,IACzB,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/** Axis whose resize distance controls the locked-ratio size projection. */\nexport type ResizeDriverAxis = 'width' | 'height';\n\n/**\n * Resolve the minimum crop dimension, in source-image pixels, for the current\n * display scale.\n *\n * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that\n * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that\n * keeps the crop large enough to grab. The on-screen floor converted to source\n * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the\n * larger of the two. When the image is shown small (small `displayScale`) the\n * on-screen floor dominates; once it is shown large enough the source-pixel\n * floor takes over.\n *\n * @param displayScale CSS pixels rendered per source pixel\n * (fit scale × zoom × view scale).\n * @return Minimum crop dimension in source-image pixels.\n */\nexport function getMinCropPixels( displayScale: number ): number {\n\tif ( displayScale <= 0 ) {\n\t\treturn MIN_CROP_PIXELS;\n\t}\n\treturn Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );\n}\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param driverAxis Optional explicit driver axis. Used for keyboard\n * resize, where one arrow axis should determine the step.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE,\n\tdriverAxis?: ResizeDriverAxis\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\". Pointer drags use the dragged-corner\n\t// geometry so the projected crop changes continuously as the pointer moves.\n\t// Keyboard resize passes an explicit axis because a single-axis arrow step\n\t// should drive that axis instead of being cancelled by the unchanged axis.\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tconst isWidthDriver =\n\t\tdriverAxis === 'width' ||\n\t\t( ! driverAxis &&\n\t\t\t( distW * imageSize.width ) / ( distH * imageSize.height ) >\n\t\t\t\tpixelRatio );\n\n\tif ( isWidthDriver ) {\n\t\t// Width is the driver — compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver — compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAoD;AAwB7C,SAAS,iBAAkB,cAA+B;AAChE,MAAK,gBAAgB,GAAI;AACxB,WAAO;AAAA,EACR;AACA,SAAO,KAAK,IAAK,kCAAiB,sCAAqB,YAAa;AACrE;AAQO,IAAM,wBAA8B,EAAE,OAAO,MAAM,QAAQ,KAAK;AAuChE,SAAS,sBACf,MACA,SACA,SACA,WACA,QACA,cAAoB,uBACH;AACjB,QAAM,KACL,UAAU,QAAQ,K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AA,MACZ,YAAY,QAAQ;AAAA,IACrB;AACA,QAAKD,aAAY,WAAY;AAC5B,MAAAA,aAAY;AACZ,MAAAC,YAAWD,aAAY;AAAA,IACxB;AAGA,UAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,SAASA,aAAY,EAAE;AAC7D,WAAO;AAAA,MACN,GAAG,UAAUC,YAAW;AAAA,MACxB,GAAG;AAAA,MACH,OAAOA;AAAA,MACP,QAAQD;AAAA,IACT;AAAA,EACD;AAGA,MAAI,WAAW,KAAK;AACpB,MAAI,YAAY,WAAW;AAC3B,QAAM,UAAU,EAAE,IAAI,EAAE,SAAS;AACjC,QAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,MAAK,YAAY,WAAY;AAC5B,gBAAY;AACZ,eAAW,YAAY;AAAA,EACxB;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,YAAY;AAAA,IACZ,YAAY,SAAS;AAAA,EACtB;AACA,MAAK,WAAW,UAAW;AAC1B,eAAW;AACX,gBAAY,WAAW;AAAA,EACxB;AACA,QAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;AAC3D,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,UAAU,YAAY;AAAA,IACzB,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
6
6
  "names": ["newHeight", "newWidth"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/transform-style.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/** Identity CSS transform \u2014 applied when inputs aren't safe to compose. */\nconst IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative \u2014 horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getImageCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\t// Match the identity short-circuit used by `createCamera` and\n\t// `getSourceRegion` so the preview path stays consistent with the math\n\t// path when `imageSize` itself is hostile (state sanitization below\n\t// only guards the state fields, not these size arguments).\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn IDENTITY_MATRIX_STYLE;\n\t}\n\t// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here\n\t// while the parallel `createCamera` path returns a finite matrix. Both\n\t// paths must agree under defense-in-depth conditions.\n\tconst safeState = sanitizeCropperState( state );\n\tconst translateX = safeState.pan.x * imageSize.width;\n\tconst translateY = safeState.pan.y * imageSize.height;\n\tconst rad = degreesToRadians( safeState.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = safeState.flip.horizontal ? -1 : 1;\n\tconst sy = safeState.flip.vertical ? -1 : 1;\n\tconst z = safeState.zoom;\n\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/** Identity CSS transform — applied when inputs aren't safe to compose. */\nconst IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative — horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getImageCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\t// Match the identity short-circuit used by `createCamera` and\n\t// `getSourceRegion` so the preview path stays consistent with the math\n\t// path when `imageSize` itself is hostile (state sanitization below\n\t// only guards the state fields, not these size arguments).\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn IDENTITY_MATRIX_STYLE;\n\t}\n\t// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here\n\t// while the parallel `createCamera` path returns a finite matrix. Both\n\t// paths must agree under defense-in-depth conditions.\n\tconst safeState = sanitizeCropperState( state );\n\tconst translateX = safeState.pan.x * imageSize.width;\n\tconst translateY = safeState.pan.y * imageSize.height;\n\tconst rad = degreesToRadians( safeState.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = safeState.flip.horizontal ? -1 : 1;\n\tconst sy = safeState.flip.vertical ? -1 : 1;\n\tconst z = safeState.zoom;\n\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAiC;AACjC,sBAAkD;AAGlD,IAAM,wBAAwB;AAmBvB,SAAS,sBACf,OACA,WACS;AAKT,MAAK,KAAE,6BAAa,SAAU,GAAI;AACjC,WAAO;AAAA,EACR;AAIA,QAAM,gBAAY,sCAAsB,KAAM;AAC9C,QAAM,aAAa,UAAU,IAAI,IAAI,UAAU;AAC/C,QAAM,aAAa,UAAU,IAAI,IAAI,UAAU;AAC/C,QAAM,UAAM,kCAAkB,UAAU,QAAS;AACjD,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,KAAK,UAAU,KAAK,aAAa,KAAK;AAC5C,QAAM,KAAK,UAAU,KAAK,WAAW,KAAK;AAC1C,QAAM,IAAI,UAAU;AAGpB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,CAAC,KAAK,MAAM;AACtB,QAAM,IAAI,KAAK,MAAM;AAErB,SAAO,UAAW,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,UAAW,KAAM,UAAW;AAC/E;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/types.ts"],
4
- "sourcesContent": ["import type { mat2d } from 'gl-matrix';\n\n/**\n * A 2D camera represented as a 2\u00D73 affine transformation matrix (`mat2d`).\n *\n * This is not a camera object with properties \u2014 it's a raw 6-element matrix\n * `[a, b, c, d, tx, ty]` that maps normalized world coordinates [0,1] to\n * screen pixels. It composes pan, rotation, flip, zoom, and contain-fit\n * into a single transform.\n *\n * Use `createCamera()` to build one from `CropperState`, then pass it to\n * `worldToScreen()` / `screenToWorld()` for coordinate conversion.\n *\n * A 3D camera would use `mat4`; this is strictly 2D (no perspective).\n */\nexport type Camera = mat2d;\n\n/**\n * A point with normalized coordinates (0-1 range relative to image dimensions).\n */\nexport interface NormalizedPoint {\n\tx: number;\n\ty: number;\n}\n\n/**\n * A rectangle with normalized coordinates (0-1 range).\n * Origin is the top-left corner of the image.\n */\nexport interface NormalizedRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Width and height dimensions.\n */\nexport interface Size {\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Flip state for horizontal and vertical axes.\n */\nexport interface Flip {\n\thorizontal: boolean;\n\tvertical: boolean;\n}\n\n/**\n * A JSON-serializable transform operation for the non-destructive pipeline.\n */\nexport type TransformOperation =\n\t| { type: 'crop'; rect: NormalizedRect }\n\t| { type: 'rotate'; degrees: number }\n\t| { type: 'flip'; direction: 'horizontal' | 'vertical' }\n\t| { type: 'zoom'; factor: number };\n\n/**\n * Full cropper state.\n */\nexport interface CropperState {\n\t/** The source image information. Null until an image is loaded. */\n\timage: {\n\t\tsrc: string;\n\t\tnaturalWidth: number;\n\t\tnaturalHeight: number;\n\t} | null;\n\t/**\n\t * Image pan offset in normalized coordinates. Not the crop\n\t * rectangle \u2014 that's `cropRect` below.\n\t */\n\tpan: NormalizedPoint;\n\t/** Zoom level. 1 = no zoom. */\n\tzoom: number;\n\t/** Rotation in degrees, normalized to 0-360. */\n\trotation: number;\n\t/**\n\t * Base pan/zoom/rotation \u2014 the pose the user last explicitly set.\n\t *\n\t * During continuous fine rotation (SET_ROTATION), every tick\n\t * re-derives the transient `pan`/`zoom` from these base values\n\t * rather than compounding on the previous tick. This prevents\n\t * drift from accumulated containment clamping near image edges:\n\t * rotating 0\u00B0\u219230\u00B0\u21920\u00B0 returns to the exact starting pan, not a\n\t * slightly-nudged version of it.\n\t *\n\t * These are updated by every action except SET_ROTATION itself \u2014\n\t * explicit zoom, pan, crop-rect, flip, and 90\u00B0 snap all commit\n\t * the post-containment state into base. SET_ROTATION reads from\n\t * `basePan` and `baseRotation` to compute the new pan, and reads\n\t * `baseZoom` as the zoom floor (enforceContainment may bump it up\n\t * to cover the rotated crop, but never leaves it above baseZoom).\n\t */\n\tbasePan: NormalizedPoint;\n\tbaseZoom: number;\n\tbaseRotation: number;\n\t/** Flip state. */\n\tflip: Flip;\n\t/** The crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n}\n\n/**\n * Internal reducer action union.\n *\n * This type is intentionally not exported from the image-editor public barrel.\n * Consumers should drive state through the controller returned by\n * `useCropperReducer()` (or a composite store) or through serializable\n * `TransformOperation` values.\n */\nexport type CropperAction =\n\t/** Sets the loaded image metadata (natural size, src). */\n\t| { type: 'SET_IMAGE'; payload: CropperState[ 'image' ] }\n\t/** Sets the image pan offset. (Crop rectangle is SET_CROP_RECT.) */\n\t| { type: 'SET_PAN'; payload: NormalizedPoint }\n\t/** Sets the zoom level, clamped to [coverage-aware min, MAX_ZOOM]. */\n\t| { type: 'SET_ZOOM'; payload: number }\n\t/**\n\t * Sets zoom and pan together atomically. Used by focal-point\n\t * zoom (wheel, pinch) to keep a target point stationary while\n\t * zoom changes.\n\t */\n\t| {\n\t\t\ttype: 'SET_ZOOM_AT_POINT';\n\t\t\tpayload: { zoom: number; pan: NormalizedPoint };\n\t }\n\t/** Sets the absolute rotation angle in degrees. */\n\t| { type: 'SET_ROTATION'; payload: number }\n\t/** Rotates by +/-90 degrees (snap). */\n\t| { type: 'SNAP_ROTATE_90'; payload: { direction: 1 | -1 } }\n\t/** Sets the flip state. */\n\t| { type: 'SET_FLIP'; payload: Flip }\n\t/** Sets the crop rectangle. */\n\t| { type: 'SET_CROP_RECT'; payload: NormalizedRect }\n\t/** Settle animation after resize drag, recentering the crop rect. */\n\t| { type: 'SETTLE_CROP' }\n\t/** Applies a single pipeline transform via the reducer. */\n\t| { type: 'APPLY_OPERATION'; payload: TransformOperation }\n\t/** Resets to DEFAULT_STATE, optionally merging a partial override. */\n\t| { type: 'RESET'; payload?: Partial< CropperState > };\n\n/**\n * Viewport camera state \u2014 display-only, does not affect export or undo.\n *\n * Applied as a CSS transform on the inner stage div so the user can scroll\n * the view independently of the crop. zoom > 1 magnifies; pan shifts in CSS px.\n */\nexport interface ViewportState {\n\tzoom: number;\n\tpan: { x: number; y: number };\n}\n\nexport type ViewportAction =\n\t| { type: 'SET_VIEWPORT_ZOOM'; payload: number }\n\t| { type: 'SET_VIEWPORT_PAN'; payload: { x: number; y: number } }\n\t| { type: 'RESET_VIEWPORT' };\n\n/**\n * Direction of a crop resize handle. Eight compass positions: four\n * corners and four edge midpoints. Used by stencil callbacks and any\n * overlay that needs to know which handle the user is dragging.\n */\nexport type HandlePosition = 'n' | 's' | 'e' | 'w' | 'nw' | 'ne' | 'sw' | 'se';\n\n/**\n * The contract for a pluggable stencil component.\n * Stencils render the crop area overlay and handle resize interactions.\n */\nexport interface StencilProps {\n\t/** The current crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** The container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** The rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** Callback when the crop rectangle changes (during drag). */\n\tonCropChange: ( rect: NormalizedRect ) => void;\n\t/**\n\t * Callback when a resize interaction starts \u2014 pointerdown on a handle\n\t * or the first arrow-key press on a focused handle. The handle direction\n\t * is passed so downstream overlays can anchor to it. The argument is\n\t * optional to keep custom stencils that don't track a direction\n\t * backward-compatible.\n\t */\n\tonResizeStart?: ( handle?: HandlePosition ) => void;\n\t/** Callback when a resize drag ends (mouseup after handle drag). */\n\tonResizeEnd?: () => void;\n\t/** Optional fixed aspect ratio (width / height) in pixel space. */\n\taspectRatio?: number;\n\t/** Whether the crop handles are shown for freeform resizing. */\n\tfreeformCrop?: boolean;\n\t/** CSS transition string for settle animation. */\n\tstencilTransition?: string;\n\t/** Maximum crop rect bounds based on current zoom/rotation. */\n\tcropBounds?: {\n\t\tminX: number;\n\t\tminY: number;\n\t\tmaxX: number;\n\t\tmaxY: number;\n\t};\n\t/** Called when Escape is pressed on a resize handle. */\n\tonEscape?: () => void;\n\t/**\n\t * Minimum crop rect dimension in normalized space, per axis. Derived\n\t * by the host from a pixel-based floor (see `MIN_CROP_PIXELS`) and\n\t * the source image dimensions. Omit to use the stencil's default.\n\t */\n\tminCropSize?: Size;\n}\n"],
4
+ "sourcesContent": ["import type { mat2d } from 'gl-matrix';\n\n/**\n * A 2D camera represented as a 2×3 affine transformation matrix (`mat2d`).\n *\n * This is not a camera object with properties — it's a raw 6-element matrix\n * `[a, b, c, d, tx, ty]` that maps normalized world coordinates [0,1] to\n * screen pixels. It composes pan, rotation, flip, zoom, and contain-fit\n * into a single transform.\n *\n * Use `createCamera()` to build one from `CropperState`, then pass it to\n * `worldToScreen()` / `screenToWorld()` for coordinate conversion.\n *\n * A 3D camera would use `mat4`; this is strictly 2D (no perspective).\n */\nexport type Camera = mat2d;\n\n/**\n * A point with normalized coordinates (0-1 range relative to image dimensions).\n */\nexport interface NormalizedPoint {\n\tx: number;\n\ty: number;\n}\n\n/**\n * A rectangle with normalized coordinates (0-1 range).\n * Origin is the top-left corner of the image.\n */\nexport interface NormalizedRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Width and height dimensions.\n */\nexport interface Size {\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Flip state for horizontal and vertical axes.\n */\nexport interface Flip {\n\thorizontal: boolean;\n\tvertical: boolean;\n}\n\n/**\n * A JSON-serializable transform operation for the non-destructive pipeline.\n */\nexport type TransformOperation =\n\t| { type: 'crop'; rect: NormalizedRect }\n\t| { type: 'rotate'; degrees: number }\n\t| { type: 'flip'; direction: 'horizontal' | 'vertical' }\n\t| { type: 'zoom'; factor: number };\n\n/**\n * Full cropper state.\n */\nexport interface CropperState {\n\t/** The source image information. Null until an image is loaded. */\n\timage: {\n\t\tsrc: string;\n\t\tnaturalWidth: number;\n\t\tnaturalHeight: number;\n\t} | null;\n\t/**\n\t * Image pan offset in normalized coordinates. Not the crop\n\t * rectangle — that's `cropRect` below.\n\t */\n\tpan: NormalizedPoint;\n\t/** Zoom level. 1 = no zoom. */\n\tzoom: number;\n\t/** Rotation in degrees, normalized to 0-360. */\n\trotation: number;\n\t/**\n\t * Base pan/zoom/rotation — the pose the user last explicitly set.\n\t *\n\t * During continuous fine rotation (SET_ROTATION), every tick\n\t * re-derives the transient `pan`/`zoom` from these base values\n\t * rather than compounding on the previous tick. This prevents\n\t * drift from accumulated containment clamping near image edges:\n\t * rotating 0°→30°→0° returns to the exact starting pan, not a\n\t * slightly-nudged version of it.\n\t *\n\t * These are updated by every action except SET_ROTATION itself —\n\t * explicit zoom, pan, crop-rect, flip, and 90° snap all commit\n\t * the post-containment state into base. SET_ROTATION reads from\n\t * `basePan` and `baseRotation` to compute the new pan, and reads\n\t * `baseZoom` as the zoom floor (enforceContainment may bump it up\n\t * to cover the rotated crop, but never leaves it above baseZoom).\n\t */\n\tbasePan: NormalizedPoint;\n\tbaseZoom: number;\n\tbaseRotation: number;\n\t/** Flip state. */\n\tflip: Flip;\n\t/** The crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n}\n\n/**\n * Internal reducer action union.\n *\n * This type is intentionally not exported from the image-editor public barrel.\n * Consumers should drive state through the controller returned by\n * `useCropperReducer()` (or a composite store) or through serializable\n * `TransformOperation` values.\n */\nexport type CropperAction =\n\t/** Sets the loaded image metadata (natural size, src). */\n\t| { type: 'SET_IMAGE'; payload: CropperState[ 'image' ] }\n\t/** Sets the image pan offset. (Crop rectangle is SET_CROP_RECT.) */\n\t| { type: 'SET_PAN'; payload: NormalizedPoint }\n\t/** Sets the zoom level, clamped to [coverage-aware min, MAX_ZOOM]. */\n\t| { type: 'SET_ZOOM'; payload: number }\n\t/**\n\t * Sets zoom and pan together atomically. Used by focal-point\n\t * zoom (wheel, pinch) to keep a target point stationary while\n\t * zoom changes.\n\t */\n\t| {\n\t\t\ttype: 'SET_ZOOM_AT_POINT';\n\t\t\tpayload: { zoom: number; pan: NormalizedPoint };\n\t }\n\t/** Sets the absolute rotation angle in degrees. */\n\t| { type: 'SET_ROTATION'; payload: number }\n\t/** Rotates by +/-90 degrees (snap). */\n\t| { type: 'SNAP_ROTATE_90'; payload: { direction: 1 | -1 } }\n\t/** Sets the flip state. */\n\t| { type: 'SET_FLIP'; payload: Flip }\n\t/** Sets the crop rectangle. */\n\t| { type: 'SET_CROP_RECT'; payload: NormalizedRect }\n\t/** Settle animation after resize drag, recentering the crop rect. */\n\t| { type: 'SETTLE_CROP' }\n\t/** Applies a single pipeline transform via the reducer. */\n\t| { type: 'APPLY_OPERATION'; payload: TransformOperation }\n\t/** Resets to DEFAULT_STATE, optionally merging a partial override. */\n\t| { type: 'RESET'; payload?: Partial< CropperState > };\n\n/**\n * Viewport camera state — display-only, does not affect export or undo.\n *\n * Applied as a CSS transform on the inner stage div so the user can scroll\n * the view independently of the crop. zoom > 1 magnifies; pan shifts in CSS px.\n */\nexport interface ViewportState {\n\tzoom: number;\n\tpan: { x: number; y: number };\n}\n\nexport type ViewportAction =\n\t| { type: 'SET_VIEWPORT_ZOOM'; payload: number }\n\t| { type: 'SET_VIEWPORT_PAN'; payload: { x: number; y: number } }\n\t| { type: 'RESET_VIEWPORT' };\n\n/**\n * Direction of a crop resize handle. Eight compass positions: four\n * corners and four edge midpoints. Used by stencil callbacks and any\n * overlay that needs to know which handle the user is dragging.\n */\nexport type HandlePosition = 'n' | 's' | 'e' | 'w' | 'nw' | 'ne' | 'sw' | 'se';\n\n/**\n * The contract for a pluggable stencil component.\n * Stencils render the crop area overlay and handle resize interactions.\n */\nexport interface StencilProps {\n\t/** The current crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** The container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** The rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** Callback when the crop rectangle changes (during drag). */\n\tonCropChange: ( rect: NormalizedRect ) => void;\n\t/**\n\t * Callback when a resize interaction starts — pointerdown on a handle\n\t * or the first arrow-key press on a focused handle. The handle direction\n\t * is passed so downstream overlays can anchor to it. The argument is\n\t * optional to keep custom stencils that don't track a direction\n\t * backward-compatible.\n\t */\n\tonResizeStart?: ( handle?: HandlePosition ) => void;\n\t/** Callback when a resize drag ends (mouseup after handle drag). */\n\tonResizeEnd?: () => void;\n\t/** Optional fixed aspect ratio (width / height) in pixel space. */\n\taspectRatio?: number;\n\t/** Whether the crop handles are shown for freeform resizing. */\n\tfreeformCrop?: boolean;\n\t/** Whether resize handles should ignore pointer and keyboard input. */\n\tisResizeDisabled?: boolean;\n\t/** CSS transition string for settle animation. */\n\tstencilTransition?: string;\n\t/** Maximum crop rect bounds based on current zoom/rotation. */\n\tcropBounds?: {\n\t\tminX: number;\n\t\tminY: number;\n\t\tmaxX: number;\n\t\tmaxY: number;\n\t};\n\t/** Called when Escape is pressed on a resize handle. */\n\tonEscape?: () => void;\n\t/**\n\t * Minimum crop rect dimension in normalized space, per axis. Derived\n\t * by the host from a pixel-based floor (see `MIN_CROP_PIXELS`) and\n\t * the source image dimensions. Omit to use the stencil's default.\n\t */\n\tminCropSize?: Size;\n\t/**\n\t * Optional post-processor for freeform resize output. Hosts use this for\n\t * display-gated behavior such as snapping visible pixel grids to source\n\t * pixel boundaries.\n\t */\n\tsnapCropRect?: (\n\t\trect: NormalizedRect,\n\t\thandle: HandlePosition\n\t) => NormalizedRect;\n\t/**\n\t * Optional keyboard resize step in normalized space, per axis. Hosts use\n\t * this when keyboard resize should follow the rendered image scale instead\n\t * of the default percentage-based step.\n\t */\n\tkeyboardResizeStep?: Size;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -38,8 +38,9 @@ var import_element = require("@wordpress/element");
38
38
  var import_i18n = require("@wordpress/i18n");
39
39
  var import_camera = require("../../core/camera.cjs");
40
40
  var import_containment = require("../../core/containment.cjs");
41
- var import_stencil_math = require("../../core/stencil-math.cjs");
41
+ var import_constants = require("../../core/constants.cjs");
42
42
  var import_crop_rect = require("../../core/crop-rect.cjs");
43
+ var import_stencil_math = require("../../core/stencil-math.cjs");
43
44
  var import_use_interaction = require("../hooks/use-interaction.cjs");
44
45
  var import_use_transform_style = require("../hooks/use-transform-style.cjs");
45
46
  var import_use_aria_announcer = require("../hooks/use-aria-announcer.cjs");
@@ -52,6 +53,16 @@ var import_viewport_provider = require("./viewport-provider.cjs");
52
53
  var import_visually_hidden_style = require("../visually-hidden-style.cjs");
53
54
  var import_jsx_runtime = require("react/jsx-runtime");
54
55
  var CROP_RECT_EPSILON = 1e-6;
56
+ var CARDINAL_ROTATION_EPSILON = 1e-6;
57
+ var SETTLE_TRANSITION_DURATION_MS = 200;
58
+ var SETTLE_TRANSITION_FALLBACK_MS = SETTLE_TRANSITION_DURATION_MS + 100;
59
+ var SETTLE_TRANSFORM_TRANSITION = `transform ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`;
60
+ var SETTLE_STENCIL_TRANSITION = [
61
+ `left ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
62
+ `top ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
63
+ `width ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
64
+ `height ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`
65
+ ].join(", ");
55
66
  function CropperInner({
56
67
  src,
57
68
  controller,
@@ -157,29 +168,6 @@ function CropperInner({
157
168
  ),
158
169
  [canvasSize, naturalWidth, naturalHeight, state.rotation]
159
170
  );
160
- const minCropSize = (0, import_element.useMemo)(() => {
161
- if (naturalWidth <= 0 || naturalHeight <= 0) {
162
- return void 0;
163
- }
164
- const snapRotation = Math.round(state.rotation / 90) * 90;
165
- const bbox = (0, import_camera.getRotatedBBox)(
166
- naturalWidth,
167
- naturalHeight,
168
- snapRotation
169
- );
170
- const displayScale = elementSize.width / naturalWidth * state.zoom;
171
- const minPixels = (0, import_stencil_math.getMinCropPixels)(displayScale);
172
- return {
173
- width: Math.min(1, minPixels * state.zoom / bbox.width),
174
- height: Math.min(1, minPixels * state.zoom / bbox.height)
175
- };
176
- }, [
177
- naturalWidth,
178
- naturalHeight,
179
- state.rotation,
180
- state.zoom,
181
- elementSize.width
182
- ]);
183
171
  (0, import_element.useEffect)(() => {
184
172
  setVisualSize(visualSize);
185
173
  }, [visualSize, setVisualSize]);
@@ -232,16 +220,133 @@ function CropperInner({
232
220
  const [isResizing, setIsResizing] = (0, import_element.useState)(false);
233
221
  const isResizingRef = (0, import_element.useRef)(false);
234
222
  const isSettlingRef = (0, import_element.useRef)(false);
223
+ const [isTouchPinching, setIsTouchPinchingState] = (0, import_element.useState)(false);
224
+ const isTouchPinchingRef = (0, import_element.useRef)(false);
225
+ const setTouchPinching = (0, import_element.useCallback)((isPinching) => {
226
+ isTouchPinchingRef.current = isPinching;
227
+ setIsTouchPinchingState(isPinching);
228
+ }, []);
235
229
  const [activeHandle, setActiveHandle] = (0, import_element.useState)(
236
230
  null
237
231
  );
232
+ const viewScaleRest = (0, import_element.useMemo)(
233
+ () => (0, import_camera.getViewScale)(
234
+ state.cropRect,
235
+ canvasSize,
236
+ visualSize,
237
+ import_constants.SETTLE_TARGET_CANVAS_FILL,
238
+ import_constants.MAX_VIEW_SCALE
239
+ ),
240
+ [state.cropRect, canvasSize, visualSize]
241
+ );
242
+ const [frozenViewScale, setFrozenViewScale] = (0, import_element.useState)(1);
243
+ const viewScale = isResizing ? frozenViewScale : viewScaleRest;
244
+ const scaledVisualSize = (0, import_element.useMemo)(
245
+ () => ({
246
+ width: visualSize.width * viewScale,
247
+ height: visualSize.height * viewScale
248
+ }),
249
+ [visualSize.width, visualSize.height, viewScale]
250
+ );
251
+ const displayScale = naturalWidth > 0 ? elementSize.width / naturalWidth * state.zoom * viewScale : 0;
252
+ const keyboardResizeStep = (0, import_element.useMemo)(() => {
253
+ if (displayScale < import_constants.PIXEL_SNAP_DISPLAY_SCALE || aspectRatio && aspectRatio > 0 || naturalWidth <= 0 || naturalHeight <= 0) {
254
+ return void 0;
255
+ }
256
+ const snapRotation = Math.round(state.rotation / 90) * 90;
257
+ if (Math.abs(state.rotation - snapRotation) >= CARDINAL_ROTATION_EPSILON) {
258
+ return void 0;
259
+ }
260
+ const bbox = (0, import_camera.getRotatedBBox)(
261
+ naturalWidth,
262
+ naturalHeight,
263
+ snapRotation
264
+ );
265
+ if (bbox.width <= 0 || bbox.height <= 0) {
266
+ return void 0;
267
+ }
268
+ return {
269
+ width: state.zoom / bbox.width,
270
+ height: state.zoom / bbox.height
271
+ };
272
+ }, [
273
+ displayScale,
274
+ aspectRatio,
275
+ naturalWidth,
276
+ naturalHeight,
277
+ state.rotation,
278
+ state.zoom
279
+ ]);
280
+ const minCropSize = (0, import_element.useMemo)(() => {
281
+ if (naturalWidth <= 0 || naturalHeight <= 0) {
282
+ return void 0;
283
+ }
284
+ const snapRotation = Math.round(state.rotation / 90) * 90;
285
+ const bbox = (0, import_camera.getRotatedBBox)(
286
+ naturalWidth,
287
+ naturalHeight,
288
+ snapRotation
289
+ );
290
+ const minPixels = (0, import_stencil_math.getMinCropPixels)(displayScale);
291
+ return {
292
+ width: Math.min(1, minPixels * state.zoom / bbox.width),
293
+ height: Math.min(1, minPixels * state.zoom / bbox.height)
294
+ };
295
+ }, [
296
+ naturalWidth,
297
+ naturalHeight,
298
+ state.rotation,
299
+ state.zoom,
300
+ displayScale
301
+ ]);
302
+ const snapCropRect = (0, import_element.useCallback)(
303
+ (rect, handle) => {
304
+ if (displayScale < import_constants.PIXEL_SNAP_DISPLAY_SCALE || naturalWidth <= 0 || naturalHeight <= 0) {
305
+ return rect;
306
+ }
307
+ return (0, import_source_region.snapCropRectToSourcePixels)(
308
+ state,
309
+ { width: naturalWidth, height: naturalHeight },
310
+ rect,
311
+ handle
312
+ );
313
+ },
314
+ [displayScale, naturalWidth, naturalHeight, state]
315
+ );
316
+ const wasPixelSnapEnabledRef = (0, import_element.useRef)(false);
317
+ (0, import_element.useEffect)(() => {
318
+ const isPixelSnapEnabled = freeformCrop && (!aspectRatio || aspectRatio <= 0) && displayScale >= import_constants.PIXEL_SNAP_DISPLAY_SCALE && naturalWidth > 0 && naturalHeight > 0;
319
+ const wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;
320
+ wasPixelSnapEnabledRef.current = isPixelSnapEnabled;
321
+ if (!isPixelSnapEnabled || wasPixelSnapEnabled) {
322
+ return;
323
+ }
324
+ const snappedCropRect = (0, import_source_region.snapCropRectToSourcePixelGrid)(
325
+ state,
326
+ { width: naturalWidth, height: naturalHeight },
327
+ state.cropRect
328
+ );
329
+ const currentCropRect = state.cropRect;
330
+ if (Math.abs(currentCropRect.x - snappedCropRect.x) < CROP_RECT_EPSILON && Math.abs(currentCropRect.y - snappedCropRect.y) < CROP_RECT_EPSILON && Math.abs(currentCropRect.width - snappedCropRect.width) < CROP_RECT_EPSILON && Math.abs(currentCropRect.height - snappedCropRect.height) < CROP_RECT_EPSILON) {
331
+ return;
332
+ }
333
+ setCropRect(snappedCropRect);
334
+ }, [
335
+ aspectRatio,
336
+ displayScale,
337
+ freeformCrop,
338
+ naturalWidth,
339
+ naturalHeight,
340
+ setCropRect,
341
+ state
342
+ ]);
238
343
  const {
239
344
  handlers,
240
345
  onWheelNative,
241
346
  isDragging,
242
347
  isZooming,
243
348
  isPlacementActive: isInteractionPlacementActive
244
- } = (0, import_use_interaction.useInteraction)(state, controller, canvasSize, visualSize, {
349
+ } = (0, import_use_interaction.useInteraction)(state, controller, canvasSize, scaledVisualSize, {
245
350
  minZoom: effectiveMinZoom,
246
351
  maxZoom,
247
352
  onGestureStart,
@@ -252,12 +357,36 @@ function CropperInner({
252
357
  onPointerDownCapture: () => {
253
358
  setIsFocusVisible(false);
254
359
  },
360
+ onTouchStartCapture: (event) => {
361
+ if (event.touches.length > 1) {
362
+ setTouchPinching(true);
363
+ }
364
+ },
365
+ onTouchMoveCapture: (event) => {
366
+ if (event.touches.length > 1) {
367
+ setTouchPinching(true);
368
+ }
369
+ },
370
+ onTouchEndCapture: (event) => {
371
+ if (event.touches.length === 0) {
372
+ setTouchPinching(false);
373
+ }
374
+ },
375
+ onTouchCancelCapture: (event) => {
376
+ if (event.touches.length === 0) {
377
+ setTouchPinching(false);
378
+ }
379
+ },
255
380
  onKeyDownCapture: (event) => {
256
381
  if (!["Shift", "Control", "Alt", "Meta"].includes(event.key)) {
257
382
  setIsFocusVisible(true);
258
383
  }
259
384
  },
260
385
  onPointerDown: (event) => {
386
+ if (isResizingRef.current || isTouchPinchingRef.current || event.pointerType === "touch" && event.isPrimary === false) {
387
+ event.preventDefault();
388
+ return;
389
+ }
261
390
  handlers.onPointerDown?.(event);
262
391
  setIsFocusVisible(false);
263
392
  }
@@ -300,25 +429,28 @@ function CropperInner({
300
429
  );
301
430
  const handleCropChange = (0, import_element.useCallback)(
302
431
  (rect) => {
432
+ if (isTouchPinchingRef.current) {
433
+ return;
434
+ }
303
435
  setCropRect(rect);
304
- if (isResizingRef.current && visualSize.width > 0 && visualSize.height > 0) {
305
- const offsetX = (canvasSize.width - visualSize.width) / 2;
306
- const offsetY = (canvasSize.height - visualSize.height) / 2;
436
+ if (isResizingRef.current && scaledVisualSize.width > 0 && scaledVisualSize.height > 0) {
437
+ const offsetX = (canvasSize.width - scaledVisualSize.width) / 2;
438
+ const offsetY = (canvasSize.height - scaledVisualSize.height) / 2;
307
439
  const rightOverflow = Math.max(
308
440
  0,
309
- offsetX + (rect.x + rect.width) * visualSize.width - canvasSize.width
441
+ offsetX + (rect.x + rect.width) * scaledVisualSize.width - canvasSize.width
310
442
  );
311
443
  const leftOverflow = Math.max(
312
444
  0,
313
- -(offsetX + rect.x * visualSize.width)
445
+ -(offsetX + rect.x * scaledVisualSize.width)
314
446
  );
315
447
  const bottomOverflow = Math.max(
316
448
  0,
317
- offsetY + (rect.y + rect.height) * visualSize.height - canvasSize.height
449
+ offsetY + (rect.y + rect.height) * scaledVisualSize.height - canvasSize.height
318
450
  );
319
451
  const topOverflow = Math.max(
320
452
  0,
321
- -(offsetY + rect.y * visualSize.height)
453
+ -(offsetY + rect.y * scaledVisualSize.height)
322
454
  );
323
455
  setViewportPan({
324
456
  x: -rightOverflow + leftOverflow,
@@ -326,10 +458,15 @@ function CropperInner({
326
458
  });
327
459
  }
328
460
  },
329
- [setCropRect, setViewportPan, canvasSize, visualSize]
461
+ [setCropRect, setViewportPan, canvasSize, scaledVisualSize]
330
462
  );
331
463
  const [settling, setSettling] = (0, import_element.useState)(false);
332
464
  const settleTimerRef = (0, import_element.useRef)();
465
+ const finishSettling = (0, import_element.useCallback)(() => {
466
+ clearTimeout(settleTimerRef.current);
467
+ isSettlingRef.current = false;
468
+ setSettling(false);
469
+ }, []);
333
470
  (0, import_element.useEffect)(() => {
334
471
  return () => {
335
472
  clearTimeout(settleTimerRef.current);
@@ -353,39 +490,56 @@ function CropperInner({
353
490
  }, []);
354
491
  const handleResizeStart = (0, import_element.useCallback)(
355
492
  (handle) => {
493
+ if (isTouchPinchingRef.current) {
494
+ return;
495
+ }
496
+ setFrozenViewScale(viewScaleRest);
356
497
  isResizingRef.current = true;
357
498
  setIsResizing(true);
358
499
  setActiveHandle(handle ?? null);
359
- clearTimeout(settleTimerRef.current);
360
- isSettlingRef.current = false;
361
- setSettling(false);
500
+ finishSettling();
362
501
  resetViewport();
363
502
  onGestureStart?.();
364
503
  },
365
- [onGestureStart, resetViewport]
504
+ [finishSettling, onGestureStart, resetViewport, viewScaleRest]
366
505
  );
367
506
  const handleResizeEnd = (0, import_element.useCallback)(() => {
507
+ const isCancellingForPinch = isTouchPinchingRef.current;
368
508
  isResizingRef.current = false;
369
509
  setIsResizing(false);
370
510
  setActiveHandle(null);
511
+ clearTimeout(settleTimerRef.current);
512
+ if (isCancellingForPinch) {
513
+ finishSettling();
514
+ resetViewport();
515
+ return;
516
+ }
371
517
  isSettlingRef.current = true;
372
518
  setSettling(true);
373
519
  resetViewport();
374
520
  settleCrop();
375
521
  onGestureEnd?.();
376
- clearTimeout(settleTimerRef.current);
377
- settleTimerRef.current = setTimeout(() => {
378
- isSettlingRef.current = false;
379
- setSettling(false);
380
- }, 200);
381
- }, [settleCrop, onGestureEnd, resetViewport]);
522
+ settleTimerRef.current = setTimeout(
523
+ finishSettling,
524
+ SETTLE_TRANSITION_FALLBACK_MS
525
+ );
526
+ }, [finishSettling, settleCrop, onGestureEnd, resetViewport]);
527
+ const handleSettleTransitionEnd = (0, import_element.useCallback)(
528
+ (event) => {
529
+ if (!isSettlingRef.current || event.propertyName !== "transform") {
530
+ return;
531
+ }
532
+ finishSettling();
533
+ },
534
+ [finishSettling]
535
+ );
382
536
  let imageTransition;
383
537
  if (settling) {
384
- imageTransition = "transform 200ms ease-out";
538
+ imageTransition = SETTLE_TRANSFORM_TRANSITION;
385
539
  } else if (isZooming) {
386
540
  imageTransition = "transform 150ms linear";
387
541
  }
388
- const settleStencilTransition = settling ? "left 200ms ease-out, top 200ms ease-out, width 200ms ease-out, height 200ms ease-out" : void 0;
542
+ const settleStencilTransition = settling ? SETTLE_STENCIL_TRANSITION : void 0;
389
543
  const imageStyle = (0, import_element.useMemo)(() => {
390
544
  if (elementSize.width === 0 || elementSize.height === 0) {
391
545
  return {};
@@ -399,11 +553,25 @@ function CropperInner({
399
553
  maxHeight: elementSize.height,
400
554
  left: centerX,
401
555
  top: centerY,
402
- transform: transformString,
403
- transition: imageTransition
556
+ // Always lead with `scale()` (identity at rest) so the transform's
557
+ // function list stays structurally constant across rest, resize, and
558
+ // settle. A conditional that dropped `scale()` at viewScale === 1
559
+ // would change the list shape exactly when the settle transition
560
+ // crosses 1:1, forcing the browser to fall back to matrix-decomposition
561
+ // interpolation instead of interpolating each function in turn.
562
+ transform: `scale(${viewScale}) ${transformString}`,
563
+ transition: imageTransition,
564
+ imageRendering: displayScale > 1 ? "pixelated" : void 0
404
565
  };
405
- }, [canvasSize, elementSize, transformString, imageTransition]);
406
- const settleTransition = settling ? "transform 200ms ease-out" : void 0;
566
+ }, [
567
+ canvasSize,
568
+ elementSize,
569
+ transformString,
570
+ imageTransition,
571
+ displayScale,
572
+ viewScale
573
+ ]);
574
+ const settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : void 0;
407
575
  const willChange = isResizing || settling ? "transform" : void 0;
408
576
  let stageStyle;
409
577
  if (viewportState.pan.x !== 0 || viewportState.pan.y !== 0) {
@@ -413,7 +581,11 @@ function CropperInner({
413
581
  willChange
414
582
  };
415
583
  } else if (settling) {
416
- stageStyle = { transition: settleTransition, willChange };
584
+ stageStyle = {
585
+ transform: "translate(0px, 0px)",
586
+ transition: settleTransition,
587
+ willChange
588
+ };
417
589
  }
418
590
  const setContainerRef = (0, import_element.useCallback)(
419
591
  (element) => {
@@ -474,11 +646,13 @@ function CropperInner({
474
646
  className: "wp-media-editor-image-editor__stage",
475
647
  "data-testid": "cropper-stage",
476
648
  style: stageStyle,
649
+ onTransitionEnd: handleSettleTransitionEnd,
477
650
  children: [
478
651
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
479
652
  "img",
480
653
  {
481
654
  className: "wp-media-editor-image-editor__image",
655
+ "data-testid": "cropper-image",
482
656
  src,
483
657
  alt: "",
484
658
  onLoad: handleImageLoad,
@@ -491,7 +665,7 @@ function CropperInner({
491
665
  {
492
666
  cropRect: state.cropRect,
493
667
  containerSize: canvasSize,
494
- imageSize: visualSize,
668
+ imageSize: scaledVisualSize,
495
669
  transition: settleStencilTransition
496
670
  }
497
671
  ),
@@ -500,16 +674,19 @@ function CropperInner({
500
674
  {
501
675
  cropRect: state.cropRect,
502
676
  containerSize: canvasSize,
503
- imageSize: visualSize,
677
+ imageSize: scaledVisualSize,
504
678
  onCropChange: handleCropChange,
505
679
  onResizeStart: handleResizeStart,
506
680
  onResizeEnd: handleResizeEnd,
507
681
  onEscape: handleEscape,
508
682
  aspectRatio,
509
683
  freeformCrop,
684
+ isResizeDisabled: isTouchPinching,
510
685
  stencilTransition: settleStencilTransition,
511
686
  cropBounds,
512
- minCropSize
687
+ minCropSize,
688
+ snapCropRect,
689
+ keyboardResizeStep
513
690
  }
514
691
  ),
515
692
  (showGrid === true || isInteractiveGrid) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -517,7 +694,7 @@ function CropperInner({
517
694
  {
518
695
  cropRect: state.cropRect,
519
696
  containerSize: canvasSize,
520
- imageSize: visualSize
697
+ imageSize: scaledVisualSize
521
698
  }
522
699
  ),
523
700
  activeHandle && outputSize && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -525,7 +702,7 @@ function CropperInner({
525
702
  {
526
703
  cropRect: state.cropRect,
527
704
  containerSize: canvasSize,
528
- imageSize: visualSize,
705
+ imageSize: scaledVisualSize,
529
706
  activeHandle,
530
707
  outputWidth: outputSize.width,
531
708
  outputHeight: outputSize.height