@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131006.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 (217) hide show
  1. package/build/components/media-editor/index.cjs +560 -0
  2. package/build/components/media-editor/index.cjs.map +7 -0
  3. package/build/components/media-editor-canvas/index.cjs +14 -2
  4. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  5. package/build/components/media-editor-crop-panel/index.cjs +34 -27
  6. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  7. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
  8. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
  9. package/build/components/media-editor-modal/index.cjs +42 -430
  10. package/build/components/media-editor-modal/index.cjs.map +3 -3
  11. package/build/components/media-editor-toolbar/index.cjs +143 -75
  12. package/build/components/media-editor-toolbar/index.cjs.map +3 -3
  13. package/build/components/media-form/index.cjs +3 -0
  14. package/build/components/media-form/index.cjs.map +2 -2
  15. package/build/components/rotation-ruler/index.cjs +197 -0
  16. package/build/components/rotation-ruler/index.cjs.map +7 -0
  17. package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
  18. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
  19. package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
  20. package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
  21. package/build/image-editor/core/constants.cjs +9 -0
  22. package/build/image-editor/core/constants.cjs.map +2 -2
  23. package/build/image-editor/core/containment.cjs +7 -13
  24. package/build/image-editor/core/containment.cjs.map +2 -2
  25. package/build/image-editor/core/interaction-controller.cjs +43 -7
  26. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  27. package/build/image-editor/core/state.cjs +5 -1
  28. package/build/image-editor/core/state.cjs.map +2 -2
  29. package/build/image-editor/core/transform-style.cjs.map +1 -1
  30. package/build/image-editor/core/types.cjs.map +1 -1
  31. package/build/image-editor/core/viewport-state.cjs +50 -0
  32. package/build/image-editor/core/viewport-state.cjs.map +7 -0
  33. package/build/image-editor/react/components/cropper.cjs +192 -72
  34. package/build/image-editor/react/components/cropper.cjs.map +3 -3
  35. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
  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 +16 -4
  38. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  39. package/build/image-editor/react/components/viewport-provider.cjs +51 -0
  40. package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
  41. package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
  42. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  43. package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
  44. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
  45. package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
  46. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  47. package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
  48. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
  49. package/build/image-editor/react/visually-hidden-style.cjs +41 -0
  50. package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
  51. package/build/private-apis.cjs +2 -0
  52. package/build/private-apis.cjs.map +2 -2
  53. package/build-module/components/media-editor/index.mjs +545 -0
  54. package/build-module/components/media-editor/index.mjs.map +7 -0
  55. package/build-module/components/media-editor-canvas/index.mjs +14 -2
  56. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  57. package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
  58. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  59. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
  60. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
  61. package/build-module/components/media-editor-modal/index.mjs +46 -455
  62. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  63. package/build-module/components/media-editor-toolbar/index.mjs +137 -77
  64. package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
  65. package/build-module/components/media-form/index.mjs +3 -0
  66. package/build-module/components/media-form/index.mjs.map +2 -2
  67. package/build-module/components/rotation-ruler/index.mjs +166 -0
  68. package/build-module/components/rotation-ruler/index.mjs.map +7 -0
  69. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
  70. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
  71. package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
  72. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
  73. package/build-module/image-editor/core/constants.mjs +6 -0
  74. package/build-module/image-editor/core/constants.mjs.map +2 -2
  75. package/build-module/image-editor/core/containment.mjs +6 -12
  76. package/build-module/image-editor/core/containment.mjs.map +2 -2
  77. package/build-module/image-editor/core/interaction-controller.mjs +50 -8
  78. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  79. package/build-module/image-editor/core/state.mjs +5 -1
  80. package/build-module/image-editor/core/state.mjs.map +2 -2
  81. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  82. package/build-module/image-editor/core/viewport-state.mjs +24 -0
  83. package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
  84. package/build-module/image-editor/react/components/cropper.mjs +195 -73
  85. package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
  86. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
  87. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  88. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
  89. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  90. package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
  91. package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
  92. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
  93. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  94. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
  95. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
  96. package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
  97. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  98. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
  99. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
  100. package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
  101. package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
  102. package/build-module/private-apis.mjs +2 -0
  103. package/build-module/private-apis.mjs.map +2 -2
  104. package/build-style/style-rtl.css +254 -29
  105. package/build-style/style.css +254 -29
  106. package/build-types/components/media-editor/index.d.ts +34 -0
  107. package/build-types/components/media-editor/index.d.ts.map +1 -0
  108. package/build-types/components/media-editor-canvas/index.d.ts +10 -1
  109. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  110. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  111. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  112. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
  113. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
  114. package/build-types/components/media-editor-modal/index.d.ts +2 -2
  115. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  116. package/build-types/components/media-editor-provider/index.d.ts +1 -1
  117. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  118. package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
  119. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
  120. package/build-types/components/media-form/index.d.ts +1 -1
  121. package/build-types/components/media-form/index.d.ts.map +1 -1
  122. package/build-types/components/rotation-ruler/index.d.ts +46 -0
  123. package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
  124. package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
  125. package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
  126. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
  127. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
  128. package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
  129. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
  130. package/build-types/image-editor/core/constants.d.ts +9 -0
  131. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  132. package/build-types/image-editor/core/containment.d.ts +11 -7
  133. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  134. package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
  135. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  136. package/build-types/image-editor/core/state.d.ts.map +1 -1
  137. package/build-types/image-editor/core/transform-style.d.ts +1 -1
  138. package/build-types/image-editor/core/types.d.ts +25 -0
  139. package/build-types/image-editor/core/types.d.ts.map +1 -1
  140. package/build-types/image-editor/core/viewport-state.d.ts +7 -0
  141. package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
  142. package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
  143. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  144. package/build-types/image-editor/react/components/cropper.d.ts +2 -1
  145. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  146. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
  147. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  148. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
  149. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
  150. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
  151. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  152. package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
  153. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
  154. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  155. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
  156. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
  157. package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
  158. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  159. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
  160. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
  161. package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
  162. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
  163. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  164. package/build-types/private-apis.d.ts.map +1 -1
  165. package/build-types/store/actions.d.ts +3 -3
  166. package/build-types/store/actions.d.ts.map +1 -1
  167. package/package.json +16 -15
  168. package/src/components/media-editor/index.tsx +709 -0
  169. package/src/components/media-editor/style.scss +89 -0
  170. package/src/components/media-editor-canvas/index.tsx +24 -0
  171. package/src/components/media-editor-crop-panel/index.tsx +39 -27
  172. package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
  173. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
  174. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
  175. package/src/components/media-editor-modal/index.tsx +49 -589
  176. package/src/components/media-editor-modal/style.scss +13 -112
  177. package/src/components/media-editor-toolbar/index.tsx +122 -63
  178. package/src/components/media-editor-toolbar/style.scss +39 -11
  179. package/src/components/media-form/index.tsx +5 -0
  180. package/src/components/rotation-ruler/README.md +37 -0
  181. package/src/components/rotation-ruler/index.tsx +266 -0
  182. package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
  183. package/src/components/rotation-ruler/style.scss +147 -0
  184. package/src/components/rotation-ruler/test/index.tsx +109 -0
  185. package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
  186. package/src/hooks/use-crop-gesture-handlers.ts +54 -0
  187. package/src/image-editor/core/constants.ts +12 -0
  188. package/src/image-editor/core/containment.ts +16 -28
  189. package/src/image-editor/core/interaction-controller.ts +66 -10
  190. package/src/image-editor/core/state.ts +15 -8
  191. package/src/image-editor/core/test/camera.ts +15 -26
  192. package/src/image-editor/core/test/interaction-controller.ts +158 -7
  193. package/src/image-editor/core/test/state.ts +21 -1
  194. package/src/image-editor/core/transform-style.ts +1 -1
  195. package/src/image-editor/core/types.ts +16 -0
  196. package/src/image-editor/core/viewport-state.ts +33 -0
  197. package/src/image-editor/docs/architecture.md +1 -1
  198. package/src/image-editor/docs/recipes.md +2 -2
  199. package/src/image-editor/react/components/cropper.scss +28 -0
  200. package/src/image-editor/react/components/cropper.tsx +268 -72
  201. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
  202. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
  203. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
  204. package/src/image-editor/react/components/test/cropper.tsx +294 -5
  205. package/src/image-editor/react/components/viewport-provider.tsx +39 -0
  206. package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
  207. package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
  208. package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
  209. package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
  210. package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
  211. package/src/image-editor/react/hooks/use-interaction.ts +36 -6
  212. package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
  213. package/src/image-editor/react/visually-hidden-style.ts +15 -0
  214. package/src/private-apis.ts +2 -0
  215. package/src/style.scss +3 -0
  216. package/tsconfig.json +1 -0
  217. package/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/image-editor/react/hooks/use-cropper-state.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useReducer, useCallback, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tFlip,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\n\n/**\n * The return type of the useCropperState hook.\n *\n * The hook exposes its state through named setter methods rather\n * than a raw dispatch function. Each setter has a specific\n * behavioral contract (see individual JSDoc) that maps 1:1 to a\n * reducer action internally. Keeping the reducer actions private\n * lets the implementation evolve without breaking consumers.\n */\nexport interface UseCropperStateReturn {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/**\n\t * Set the image pan offset in normalized coordinates. Use\n\t * `setCropRect` for the crop rectangle.\n\t */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/** Set the zoom level. Clamped to [1, 10]. */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together so focal-point zoom remains atomic. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Set the rotation in degrees. Normalized to [0, 360). */\n\tsetRotation: ( rotation: number ) => void;\n\t/** Set the flip state. */\n\tsetFlip: ( flip: Flip ) => void;\n\t/** Snap rotate 90\u00B0 preserving the image selection (Google Photos style). */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Set the crop rectangle in normalized coordinates. */\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\t/**\n\t * Settle the crop rect after a resize drag: expand to fill the\n\t * available visual area while preserving the framed image region.\n\t * Typically called from a stencil's `onResizeEnd` callback.\n\t */\n\tsettleCrop: () => void;\n\t/** Apply a transform operation through the pipeline. */\n\tapplyOperation: ( op: TransformOperation ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure \u2014 see\n\t * `exportCroppedImage` in core for the error semantics (image\n\t * load errors, CORS taint, missing canvas context). Wrap in\n\t * try/catch if you need to recover.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n}\n\n/**\n * Reducer-based state management hook for the image editor.\n *\n * Provides the full cropper state and named setter methods for\n * every supported transition. The reducer and containment logic\n * live in core/state.ts (framework-agnostic); this hook is a thin\n * React wrapper around that pure reducer, with memoized callbacks.\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper state, setters, and utilities.\n */\nexport function useCropperState(\n\tinitialState?: Partial< CropperState >\n): UseCropperStateReturn {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\tconst initialRef = useRef< CropperState >(\n\t\tenforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Keep a ref to the latest state so callbacks with stable identity\n\t// (reset, setImage) can read fresh state without re-creating themselves.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tdispatch( { type: 'SET_IMAGE', payload: image } );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tinitialRef.current = enforceContainment( {\n\t\t\t\t...initialRef.current,\n\t\t\t\timage,\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setPan = useCallback(\n\t\t( pan: NormalizedPoint ) => {\n\t\t\tdispatch( { type: 'SET_PAN', payload: pan } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoom = useCallback(\n\t\t( zoom: number ) => {\n\t\t\tdispatch( { type: 'SET_ZOOM', payload: zoom } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoomAtPoint = useCallback(\n\t\t( zoom: number, pan: NormalizedPoint ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setRotation = useCallback(\n\t\t( rotation: number ) => {\n\t\t\tdispatch( { type: 'SET_ROTATION', payload: rotation } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setFlip = useCallback(\n\t\t( flip: Flip ) => {\n\t\t\tdispatch( { type: 'SET_FLIP', payload: flip } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst snapRotate90 = useCallback(\n\t\t( direction: 1 | -1 ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setCropRect = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatch( { type: 'SET_CROP_RECT', payload: rect } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst settleCrop = useCallback( () => {\n\t\tdispatch( { type: 'SETTLE_CROP' } );\n\t}, [ dispatch ] );\n\n\tconst applyOperation = useCallback(\n\t\t( op: TransformOperation ) => {\n\t\t\tdispatch( { type: 'APPLY_OPERATION', payload: op } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatch( { type: 'RESET', payload: resetState } );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. RESET preserves the currently-loaded image; the\n\t\t\t// containment step can tweak pan/zoom/cropRect by float ulp,\n\t\t\t// which we must fold into the \"initial\" snapshot or isDirty\n\t\t\t// would report true after a reset.\n\t\t\tinitialRef.current = enforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\timage: stateRef.current.image,\n\t\t\t\t...resetState,\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialRef.current );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded \u2014 call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\tconst controller: UseCropperStateReturn = {\n\t\tstate,\n\t\tsetImage,\n\t\tsetPan,\n\t\tsetZoom,\n\t\tsetZoomAtPoint,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tapplyOperation,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t};\n\treturn controller;\n}\n"],
5
- "mappings": ";AAGA,SAAS,YAAY,aAAa,cAAc;AAYhD,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAiEA,SAAS,gBACf,cACwB;AACxB,QAAM,CAAE,OAAO,QAAS,IAAI;AAAA,IAC3B;AAAA,IACA;AAAA,IACA,CAAE,SAAU,mBAAoB,EAAE,GAAG,eAAe,GAAG,KAAK,CAAE;AAAA,EAC/D;AAEA,QAAM,aAAa;AAAA,IAClB,mBAAoB,EAAE,GAAG,eAAe,GAAG,aAAa,CAAE;AA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eAAU,EAAE,MAAM,iBAAiB,SAAS,KAAK,CAAE;AAAA,IACpD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,QAAM,aAAa,YAAa,MAAM;AACrC,aAAU,EAAE,MAAM,cAAc,CAAE;AAAA,EACnC,GAAG,CAAE,QAAS,CAAE;AAEhB,QAAM,iBAAiB;AAAA,IACtB,CAAE,OAA4B;AAC7B,eAAU,EAAE,MAAM,mBAAmB,SAAS,GAAG,CAAE;AAAA,IACpD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,QAAM,QAAQ;AAAA,IACb,CAAE,eAA0C;AAC3C,eAAU,EAAE,MAAM,SAAS,SAAS,WAAW,CAAE;AAMjD,iBAAW,UAAU,mBAAoB;AAAA,QACxC,GAAG;AAAA,QACH,OAAO,SAAS,QAAQ;AAAA,QACxB,GAAG;AAAA,MACJ,CAAE;AAAA,IACH;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,QAAM,UAAU,aAAc,OAAO,WAAW,OAAQ;AAExD,QAAM,kBAAkB;AAAA,IACvB,CAAE,UAAmB,YAAuC;AAC3D,UAAK,CAAE,MAAM,OAAQ;AACpB,eAAO,QAAQ;AAAA,UACd,IAAI,MAAO,6CAAyC;AAAA,QACrD;AAAA,MACD;AACA,aAAO;AAAA,QACN,MAAM,MAAM;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,KAAM;AAAA,EACT;AAEA,QAAM,aAAoC;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseReducer,\n\tuseCallback,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tFlip,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\n\n/**\n * The return type of the useCropperState hook.\n *\n * The hook exposes its state through named setter methods rather\n * than a raw dispatch function. Each setter has a specific\n * behavioral contract (see individual JSDoc) that maps 1:1 to a\n * reducer action internally. Keeping the reducer actions private\n * lets the implementation evolve without breaking consumers.\n */\nexport interface UseCropperStateReturn {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/**\n\t * Set the image pan offset in normalized coordinates. Use\n\t * `setCropRect` for the crop rectangle.\n\t */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/** Set the zoom level. Clamped to [1, 10]. */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together so focal-point zoom remains atomic. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Set the rotation in degrees. Normalized to [0, 360). */\n\tsetRotation: ( rotation: number ) => void;\n\t/** Set the flip state. */\n\tsetFlip: ( flip: Flip ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip: ( direction: 'horizontal' | 'vertical' ) => void;\n\t/** Snap rotate 90\u00B0 preserving the image selection (Google Photos style). */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Set the crop rectangle in normalized coordinates. */\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\t/**\n\t * Settle the crop rect after a resize drag: expand to fill the\n\t * available visual area while preserving the framed image region.\n\t * Typically called from a stencil's `onResizeEnd` callback.\n\t *\n\t * Flushes the pending resize history before dispatching, then suppresses\n\t * the settle dispatch itself so resizing and settling undo as one step.\n\t */\n\tsettleCrop: () => void;\n\t/** Apply a transform operation through the pipeline. */\n\tapplyOperation: ( op: TransformOperation ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/** Whether there is a cropper state to undo. */\n\thasUndo: boolean;\n\t/** Whether there is a cropper state to redo. */\n\thasRedo: boolean;\n\t/** Undo the last committed cropper operation. */\n\tundo: () => void;\n\t/** Redo the last undone cropper operation. */\n\tredo: () => void;\n\t/**\n\t * Flush the pending history entry immediately, bypassing the debounce\n\t * timer. Useful in two situations:\n\t *\n\t * - **Pointer-up / key-up**: commit as soon as the user releases so the\n\t * undo button lights up without waiting for the debounce window.\n\t * - **Gesture start**: pass to `onGestureStart` on the `Cropper` so any\n\t * pending sidebar interaction is committed before a new canvas gesture\n\t * begins, keeping the two interactions as separate undo steps.\n\t */\n\tcommitHistory: () => void;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure \u2014 see\n\t * `exportCroppedImage` in core for the error semantics (image\n\t * load errors, CORS taint, missing canvas context). Wrap in\n\t * try/catch if you need to recover.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n}\n\n/** Milliseconds of inactivity after which a continuous interaction is committed to history. */\nconst HISTORY_DEBOUNCE_MS = 300;\n\n/** Small tolerance for cropper floating-point comparisons. */\nconst HISTORY_EPSILON = 1e-6;\n\nfunction nearlyEqual( a: number, b: number ): boolean {\n\treturn Math.abs( a - b ) < HISTORY_EPSILON;\n}\n\nfunction areHistoryStatesEqual( a: CropperState, b: CropperState ): 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\n/**\n * Reducer-based state management hook for the image editor.\n *\n * Provides the full cropper state and named setter methods for\n * every supported transition. The reducer and containment logic\n * live in core/state.ts (framework-agnostic); this hook is a thin\n * React wrapper around that pure reducer, with memoized callbacks.\n *\n * History is recorded via a state-change debounce: any state change\n * starts a 300 ms timer; when it fires the pre-change state is pushed\n * onto the undo stack. `commitHistory` flushes the timer immediately\n * (useful on pointer-up / key-up for a crisp commit feel).\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper state, setters, and utilities.\n */\nexport function useCropperState(\n\tinitialState?: Partial< CropperState >\n): UseCropperStateReturn {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\tconst initialRef = useRef< CropperState >(\n\t\tenforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Keep a ref to the latest state so callbacks with stable identity\n\t// (reset, setImage) can read fresh state without re-creating themselves.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\n\t// History stack for undo/redo. Using refs for the arrays avoids\n\t// unnecessary re-renders on every push; a pair of boolean state values\n\t// drives the enabled/disabled state of the undo/redo buttons.\n\tconst historyRef = useRef< CropperState[] >( [] );\n\tconst redoStackRef = useRef< CropperState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Debounce-based history: tracks the last committed state and a pending\n\t// timer. Any state change resets the timer; when it expires the\n\t// pre-change state is pushed to history.\n\tconst lastCommittedStateRef = useRef< CropperState | null >( state );\n\tconst debounceTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\t// Set to true before dispatching actions that must not produce a debounce\n\t// history entry (undo, redo, reset, setImage, discrete actions).\n\tconst suppressDebounceRef = useRef( false );\n\n\t// Pushes `entry` (defaults to current state) onto the undo stack and\n\t// clears the redo stack. Skips if `entry` is already the last item,\n\t// so rapid discrete actions on unchanged state don't create duplicates.\n\tconst pushToHistory = useCallback( ( entry?: CropperState ) => {\n\t\tconst target = entry ?? stateRef.current;\n\t\tconst previousEntry =\n\t\t\thistoryRef.current[ historyRef.current.length - 1 ];\n\t\tif ( previousEntry && areHistoryStatesEqual( previousEntry, target ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, target ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Watch state and debounce history commits. Any dispatch resets the\n\t// timer; once the state has settled for HISTORY_DEBOUNCE_MS the\n\t// pre-change snapshot is pushed to the undo stack.\n\tuseEffect( () => {\n\t\t// Suppress flag: undo/redo/reset/setImage/discrete actions set this\n\t\t// to opt out of the debounce for their own state changes.\n\t\tif ( suppressDebounceRef.current ) {\n\t\t\tsuppressDebounceRef.current = false;\n\t\t\tlastCommittedStateRef.current = stateRef.current;\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tlastCommittedStateRef.current !== null &&\n\t\t\tareHistoryStatesEqual(\n\t\t\t\tlastCommittedStateRef.current,\n\t\t\t\tstateRef.current\n\t\t\t)\n\t\t) {\n\t\t\tlastCommittedStateRef.current = stateRef.current;\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout( debounceTimerRef.current );\n\t\tdebounceTimerRef.current = setTimeout( () => {\n\t\t\tconst snapshot = lastCommittedStateRef.current;\n\t\t\tif (\n\t\t\t\tsnapshot !== null &&\n\t\t\t\t! areHistoryStatesEqual( snapshot, stateRef.current )\n\t\t\t) {\n\t\t\t\tpushToHistory( snapshot );\n\t\t\t}\n\t\t\tlastCommittedStateRef.current = stateRef.current;\n\t\t}, HISTORY_DEBOUNCE_MS );\n\t\treturn () => clearTimeout( debounceTimerRef.current );\n\t}, [ state, pushToHistory ] );\n\n\t// Flush the pending debounce immediately: cancel the timer and push the\n\t// pre-change snapshot if the state has actually changed. Used by\n\t// pointer-up / key-up handlers for an instant commit feel, and by\n\t// undo/redo/discrete actions before recording their own history entry.\n\tconst commitHistory = useCallback( () => {\n\t\tclearTimeout( debounceTimerRef.current );\n\t\tconst snapshot = lastCommittedStateRef.current;\n\t\tif (\n\t\t\tsnapshot !== null &&\n\t\t\t! areHistoryStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushToHistory( snapshot );\n\t\t}\n\t\tlastCommittedStateRef.current = stateRef.current;\n\t}, [ pushToHistory ] );\n\n\tconst undo = useCallback( () => {\n\t\t// Flush any pending gesture so it becomes a distinct undo step\n\t\t// before we pop history. This ensures mid-gesture undo undoes the\n\t\t// pending change rather than silently discarding it.\n\t\tcommitHistory();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsuppressDebounceRef.current = true;\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tdispatch( { type: 'RESET', payload: prev } );\n\t}, [ dispatch, commitHistory ] );\n\n\tconst redo = useCallback( () => {\n\t\t// Flush any pending gesture before redoing so the in-flight change\n\t\t// is saved and the redo target lands on top of it.\n\t\tcommitHistory();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsuppressDebounceRef.current = true;\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tdispatch( { type: 'RESET', payload: next } );\n\t}, [ dispatch, commitHistory ] );\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tclearTimeout( debounceTimerRef.current );\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'SET_IMAGE', payload: image } );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tinitialRef.current = enforceContainment( {\n\t\t\t\t...initialRef.current,\n\t\t\t\timage,\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setPan = useCallback(\n\t\t( pan: NormalizedPoint ) => {\n\t\t\tdispatch( { type: 'SET_PAN', payload: pan } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoom = useCallback(\n\t\t( zoom: number ) => {\n\t\t\tdispatch( { type: 'SET_ZOOM', payload: zoom } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoomAtPoint = useCallback(\n\t\t( zoom: number, pan: NormalizedPoint ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setRotation = useCallback(\n\t\t( rotation: number ) => {\n\t\t\tdispatch( { type: 'SET_ROTATION', payload: rotation } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setFlip = useCallback(\n\t\t( flip: Flip ) => {\n\t\t\tcommitHistory(); // flush any pending continuous gesture first\n\t\t\tpushToHistory(); // record current state as the undo point\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'SET_FLIP', payload: flip } );\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst toggleFlip = useCallback(\n\t\t( direction: 'horizontal' | 'vertical' ) => {\n\t\t\tsetFlip( {\n\t\t\t\t...stateRef.current.flip,\n\t\t\t\t[ direction ]: ! stateRef.current.flip[ direction ],\n\t\t\t} );\n\t\t},\n\t\t[ setFlip ]\n\t);\n\n\tconst snapRotate90 = useCallback(\n\t\t( direction: 1 | -1 ) => {\n\t\t\tcommitHistory();\n\t\t\tpushToHistory();\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst setCropRect = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatch( { type: 'SET_CROP_RECT', payload: rect } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst settleCrop = useCallback( () => {\n\t\tcommitHistory();\n\t\tsuppressDebounceRef.current = true;\n\t\tdispatch( { type: 'SETTLE_CROP' } );\n\t}, [ dispatch, commitHistory ] );\n\n\tconst applyOperation = useCallback(\n\t\t( op: TransformOperation ) => {\n\t\t\tcommitHistory();\n\t\t\tpushToHistory();\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'APPLY_OPERATION', payload: op } );\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tcommitHistory();\n\t\t\tconst nextInitialState = enforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\timage: stateRef.current.image,\n\t\t\t\t...resetState,\n\t\t\t} );\n\t\t\tif (\n\t\t\t\t! areHistoryStatesEqual( stateRef.current, nextInitialState )\n\t\t\t) {\n\t\t\t\tpushToHistory();\n\t\t\t}\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'RESET', payload: resetState } );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. RESET preserves the currently-loaded image; the\n\t\t\t// containment step can tweak pan/zoom/cropRect by float ulp,\n\t\t\t// which we must fold into the \"initial\" snapshot or isDirty\n\t\t\t// would report true after a reset.\n\t\t\tinitialRef.current = nextInitialState;\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialRef.current );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded \u2014 call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\tconst controller: UseCropperStateReturn = {\n\t\tstate,\n\t\tsetImage,\n\t\tsetPan,\n\t\tsetZoom,\n\t\tsetZoomAtPoint,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\ttoggleFlip,\n\t\tsnapRotate90,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tapplyOperation,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo,\n\t\tredo,\n\t\tcommitHistory,\n\t};\n\treturn controller;\n}\n"],
5
+ "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAYP,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA+EP,IAAM,sBAAsB;AAG5B,IAAM,kBAAkB;AAExB,SAAS,YA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R;",
6
6
  "names": []
7
7
  }
@@ -15,12 +15,24 @@ function isHandledKeyboardPan(event) {
15
15
  return false;
16
16
  }
17
17
  }
18
+ function isHandledKeyboardZoom(event) {
19
+ switch (event.key) {
20
+ case "+":
21
+ case "=":
22
+ case "-":
23
+ case "_":
24
+ return true;
25
+ default:
26
+ return false;
27
+ }
28
+ }
18
29
  function useInteraction(state, actions, containerSize, imageSize, options) {
19
30
  const [isDragging, setIsDragging] = useState(false);
20
31
  const [isZooming, setIsZooming] = useState(false);
21
32
  const [isGestureActive, setIsGestureActive] = useState(false);
22
33
  const [isKeyboardPanning, setIsKeyboardPanning] = useState(false);
23
34
  const keyboardInteractionTimerRef = useRef();
35
+ const isKeyboardGestureActiveRef = useRef(false);
24
36
  const stateRef = useRef(state);
25
37
  stateRef.current = state;
26
38
  const containerSizeRef = useRef(containerSize);
@@ -38,11 +50,16 @@ function useInteraction(state, actions, containerSize, imageSize, options) {
38
50
  const stopPlacementGesture = useCallback(() => {
39
51
  setIsGestureActive(false);
40
52
  }, []);
41
- const signalKeyboardPlacement = useCallback(() => {
42
- setIsKeyboardPanning(true);
53
+ const signalKeyboardGesture = useCallback(() => {
54
+ if (!isKeyboardGestureActiveRef.current) {
55
+ isKeyboardGestureActiveRef.current = true;
56
+ optionsRef.current?.onGestureStart?.();
57
+ }
43
58
  clearTimeout(keyboardInteractionTimerRef.current);
44
59
  keyboardInteractionTimerRef.current = setTimeout(() => {
60
+ isKeyboardGestureActiveRef.current = false;
45
61
  setIsKeyboardPanning(false);
62
+ optionsRef.current?.onGestureEnd?.();
46
63
  }, KEYBOARD_INTERACTION_IDLE_MS);
47
64
  }, []);
48
65
  useEffect(() => {
@@ -57,7 +74,8 @@ function useInteraction(state, actions, containerSize, imageSize, options) {
57
74
  setPan: (pan) => actionsRef.current.setPan(pan),
58
75
  setZoom: (zoom) => actionsRef.current.setZoom(zoom),
59
76
  setZoomAtPoint: (zoom, pan) => actionsRef.current.setZoomAtPoint(zoom, pan),
60
- snapRotate90: (direction) => actionsRef.current.snapRotate90(direction)
77
+ snapRotate90: (direction) => actionsRef.current.snapRotate90(direction),
78
+ toggleFlip: (direction) => actionsRef.current.toggleFlip?.(direction)
61
79
  },
62
80
  getContainerSize: () => containerSizeRef.current,
63
81
  getImageSize: () => imageSizeRef.current,
@@ -111,11 +129,14 @@ function useInteraction(state, actions, containerSize, imageSize, options) {
111
129
  const onKeyDown = useCallback(
112
130
  (e) => {
113
131
  if (isHandledKeyboardPan(e.nativeEvent)) {
114
- signalKeyboardPlacement();
132
+ setIsKeyboardPanning(true);
133
+ signalKeyboardGesture();
134
+ } else if (isHandledKeyboardZoom(e.nativeEvent)) {
135
+ signalKeyboardGesture();
115
136
  }
116
137
  controllerRef.current?.handleKeyDown(e.nativeEvent);
117
138
  },
118
- [signalKeyboardPlacement]
139
+ [signalKeyboardGesture]
119
140
  );
120
141
  const onWheelNative = useCallback((e) => {
121
142
  controllerRef.current?.handleWheel(e);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/image-editor/react/hooks/use-interaction.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler \u2014 must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\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\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.01. */\n\tzoomSpeed?: number;\n\t/** Pan step size in normalized coords for keyboard events. Defaults to 0.05. */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\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}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\tconst signalKeyboardPlacement = useCallback( () => {\n\t\tsetIsKeyboardPanning( true );\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tsetIsKeyboardPanning( false );\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardPlacement();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardPlacement ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],
5
- "mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAMzD;AAAA,EACC;AAAA,OAEM;AA2CP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAiBO,SAAS,eACf,OACA,SACA,eACA,WACA,SACuB;AACvB,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AACtD,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AACpD,QAAM,CAAE,iBAAiB,kBAAmB,IAAI,SAAU,KAAM;AAChE,QAAM,CAAE,mBAAmB,oBAAqB,IAAI,SAAU,KAAM;AACpE,QAAM,8BACL,OAA0C;AAI3C,QAAM,WAAW,OAAQ,KAAM;AAC/B,WAAS,UAAU;AACnB,QAAM,mBAAmB,OAAQ,aAAc;AAC/C,mBAAiB,UAAU;AAC3B,QAAM,eAAe,OAAQ,SAAU;AACvC,eAAa,UAAU;AACvB,QAAM,aAAa,OAAQ,OAAQ;AACnC,aAAW,UAAU;AACrB,QAAM,aAAa,OAAQ,OAAQ;AACnC,aAAW,UAAU;AAErB,QAAM,gBAAgB,OAAwC,IAAK;AACnE,QAAM,wBAAwB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AAA,MACtC;AAAA,MACA,cAAc,MAAM;AACnB,6BAAqB;AACrB,mBAAW,SAAS,eAAe;AAAA,MACpC;AAAA,MACA,gBAAgB,CAAE,WAAY;AAC7B,sBAAe,OAAO,UAAW;AACjC,qBAAc,OAAO,SAAU;AAAA,MAChC;AAAA,IACD,CAAE;AACF,kBAAc,UAAU;AACxB,WAAO,MAAM;AACZ,iBAAW,QAAQ;AACnB,oBAAc,UAAU;AAAA,IACzB;AAAA,EACD,GAAG,CAAE,uBAAuB,oBAAqB,CAAE;AAEnD,QAAM,gBAAgB,YAAa,CAAE,MAA2B;AAC/D,UAAM,KAAK,EAAE;AACb,kBAAc,SAAS,kBAAmB,EAAE,aAAa,EAAG;AAAA,EAC7D,GAAG,CAAC,CAAE;AAEN,QAAM,eAAe,YAAa,CAAE,MAAyB;AAC5D,UAAM,KAAK,EAAE;AACb,UAAM,OAAO,GAAG,sBAAsB;AACtC,kBAAc,SAAS;AAAA,MACtB,EAAE;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,YAAY;AAAA,IACjB,CAAE,MAA4B;AAC7B,UAAK,qBAAsB,EAAE,WAAY,GAAI;AAC5C,gCAAwB;AAAA,MACzB;AACA,oBAAc,SAAS,cAAe,EAAE,WAAY;AAAA,IACrD;AAAA,IACA,CAAE,uBAAwB;AAAA,EAC3B;AAEA,QAAM,gBAAgB,YAAa,CAAE,MAAmB;AACvD,kBAAc,SAAS,YAAa,CAAE;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,UAAU;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,mBAAmB,qBAAqB;AAAA,EAC5D;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler \u2014 must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\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\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\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}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isHandledKeyboardZoom( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase '+':\n\t\tcase '=':\n\t\tcase '-':\n\t\tcase '_':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\n\t// Tracks whether a keyboard gesture (pan or zoom) is currently active so\n\t// onGestureStart is only fired once per gesture, not on every key repeat.\n\tconst isKeyboardGestureActiveRef = useRef( false );\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\t// Shared timer logic for any keyboard gesture (pan or zoom): fires\n\t// onGestureStart once per burst and onGestureEnd after the idle window.\n\tconst signalKeyboardGesture = useCallback( () => {\n\t\tif ( ! isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = true;\n\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tsetIsKeyboardPanning( false );\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t\ttoggleFlip: ( direction ) =>\n\t\t\t\t\tactionsRef.current.toggleFlip?.( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsetIsKeyboardPanning( true );\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t} else if ( isHandledKeyboardZoom( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardGesture ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],
5
+ "mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAMzD;AAAA,EACC;AAAA,OAEM;AA8CP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,sBAAuB,OAAgC;AAC/D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAiBO,SAAS,eACf,OACA,SACA,eACA,WACA,SACuB;AACvB,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AACtD,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AACpD,QAAM,CAAE,iBAAiB,kBAAmB,IAAI,SAAU,KAAM;AAChE,QAAM,CAAE,mBAAmB,oBAAqB,IAAI,SAAU,KAAM;AACpE,QAAM,8BACL,OAA0C;AAG3C,QAAM,6BAA6B,OAAQ,KAAM;AAIjD,QAAM,WAAW,OAAQ,KAAM;AAC/B,WAAS,UAAU;AACnB,QAAM,mBAAmB,OAAQ,aAAc;AAC/C,mBAAiB,UAAU;AAC3B,QAAM,eAAe,OAAQ,SAAU;AACvC,eAAa,UAAU;AACvB,QAAM,aAAa,OAAQ,OAAQ;AACn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A,EACzB;AAEA,QAAM,gBAAgB,YAAa,CAAE,MAAmB;AACvD,kBAAc,SAAS,YAAa,CAAE;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,UAAU;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,mBAAmB,qBAAqB;AAAA,EAC5D;AACD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,29 @@
1
+ // packages/media-editor/src/image-editor/react/hooks/use-viewport-state.ts
2
+ import { useReducer, useCallback, useMemo } from "@wordpress/element";
3
+ import {
4
+ viewportReducer,
5
+ DEFAULT_VIEWPORT_STATE
6
+ } from "../../core/viewport-state.mjs";
7
+ function useViewportState() {
8
+ const [viewport, dispatch] = useReducer(
9
+ viewportReducer,
10
+ DEFAULT_VIEWPORT_STATE
11
+ );
12
+ const setViewportZoom = useCallback((zoom) => {
13
+ dispatch({ type: "SET_VIEWPORT_ZOOM", payload: zoom });
14
+ }, []);
15
+ const setViewportPan = useCallback((pan) => {
16
+ dispatch({ type: "SET_VIEWPORT_PAN", payload: pan });
17
+ }, []);
18
+ const resetViewport = useCallback(() => {
19
+ dispatch({ type: "RESET_VIEWPORT" });
20
+ }, []);
21
+ return useMemo(
22
+ () => ({ viewport, setViewportZoom, setViewportPan, resetViewport }),
23
+ [viewport, setViewportZoom, setViewportPan, resetViewport]
24
+ );
25
+ }
26
+ export {
27
+ useViewportState
28
+ };
29
+ //# sourceMappingURL=use-viewport-state.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useReducer, useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation \u2014 scaffolded for the\n\t * upcoming navigator panel (viewport zoom slider).\n\t */\n\tsetViewportZoom: ( zoom: number ) => void;\n\tsetViewportPan: ( pan: { x: number; y: number } ) => void;\n\tresetViewport: () => void;\n}\n\nexport function useViewportState(): UseViewportStateReturn {\n\tconst [ viewport, dispatch ] = useReducer(\n\t\tviewportReducer,\n\t\tDEFAULT_VIEWPORT_STATE\n\t);\n\n\tconst setViewportZoom = useCallback( ( zoom: number ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_ZOOM', payload: zoom } );\n\t}, [] );\n\n\tconst setViewportPan = useCallback( ( pan: { x: number; y: number } ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_PAN', payload: pan } );\n\t}, [] );\n\n\tconst resetViewport = useCallback( () => {\n\t\tdispatch( { type: 'RESET_VIEWPORT' } );\n\t}, [] );\n\n\treturn useMemo(\n\t\t() => ( { viewport, setViewportZoom, setViewportPan, resetViewport } ),\n\t\t[ viewport, setViewportZoom, setViewportPan, resetViewport ]\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,YAAY,aAAa,eAAe;AAMjD;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAaA,SAAS,mBAA2C;AAC1D,QAAM,CAAE,UAAU,QAAS,IAAI;AAAA,IAC9B;AAAA,IACA;AAAA,EACD;AAEA,QAAM,kBAAkB,YAAa,CAAE,SAAkB;AACxD,aAAU,EAAE,MAAM,qBAAqB,SAAS,KAAK,CAAE;AAAA,EACxD,GAAG,CAAC,CAAE;AAEN,QAAM,iBAAiB,YAAa,CAAE,QAAmC;AACxE,aAAU,EAAE,MAAM,oBAAoB,SAAS,IAAI,CAAE;AAAA,EACtD,GAAG,CAAC,CAAE;AAEN,QAAM,gBAAgB,YAAa,MAAM;AACxC,aAAU,EAAE,MAAM,iBAAiB,CAAE;AAAA,EACtC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,OAAQ,EAAE,UAAU,iBAAiB,gBAAgB,cAAc;AAAA,IACnE,CAAE,UAAU,iBAAiB,gBAAgB,aAAc;AAAA,EAC5D;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,16 @@
1
+ // packages/media-editor/src/image-editor/react/visually-hidden-style.ts
2
+ var VISUALLY_HIDDEN_STYLE = {
3
+ position: "absolute",
4
+ width: 1,
5
+ height: 1,
6
+ padding: 0,
7
+ margin: -1,
8
+ overflow: "hidden",
9
+ clip: "rect(0, 0, 0, 0)",
10
+ whiteSpace: "nowrap",
11
+ border: 0
12
+ };
13
+ export {
14
+ VISUALLY_HIDDEN_STYLE
15
+ };
16
+ //# sourceMappingURL=visually-hidden-style.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/image-editor/react/visually-hidden-style.ts"],
4
+ "sourcesContent": ["/**\n * CSS style object that visually hides an element while keeping it accessible\n * to screen readers.\n */\nexport const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {\n\tposition: 'absolute',\n\twidth: 1,\n\theight: 1,\n\tpadding: 0,\n\tmargin: -1,\n\toverflow: 'hidden',\n\tclip: 'rect(0, 0, 0, 0)',\n\twhiteSpace: 'nowrap',\n\tborder: 0,\n};\n"],
5
+ "mappings": ";AAIO,IAAM,wBAA6C;AAAA,EACzD,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,QAAQ;AACT;",
6
+ "names": []
7
+ }
@@ -2,9 +2,11 @@
2
2
  import { lock } from "./lock-unlock.mjs";
3
3
  import { store } from "./store/index.mjs";
4
4
  import { MediaEditorModal } from "./components/media-editor-modal/index.mjs";
5
+ import { MediaEditor } from "./components/media-editor/index.mjs";
5
6
  var privateApis = {};
6
7
  lock(privateApis, {
7
8
  store,
9
+ MediaEditor,
8
10
  MediaEditorModal
9
11
  });
10
12
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/private-apis.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditorModal,\n} );\n"],
5
- "mappings": ";AAGA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,wBAAwB;AAE1B,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AAAA,EACA;AACD,CAAE;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\nimport { MediaEditor } from './components/media-editor';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditor,\n\tMediaEditorModal,\n} );\n"],
5
+ "mappings": ";AAGA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAErB,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
6
6
  "names": []
7
7
  }