@wordpress/media-editor 0.22.0 → 0.24.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 (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -1,362 +0,0 @@
1
- import { useCallback, useEffect, useId, useMemo, useRef } from "@wordpress/element";
2
- import { __ } from "@wordpress/i18n";
3
- import { DEFAULT_KEYBOARD_STEP, KEYBOARD_SHIFT_STEP_MULTIPLIER } from "../../../core/constants.mjs";
4
- import { computeFreeResizeRect, computeLockedResizeRect, computeShiftLockedResizeRect } from "../../../core/stencil-math.mjs";
5
- import { VISUALLY_HIDDEN_STYLE } from "../../visually-hidden-style.mjs";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- // packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
8
- /**
9
- * Corner handle positions only — used when aspect ratio is locked.
10
- * Ordered clockwise from top-left for logical tab order.
11
- */
12
- const CORNER_POSITIONS = [
13
- "nw",
14
- "ne",
15
- "se",
16
- "sw"
17
- ];
18
- /**
19
- * All handle positions rendered by the stencil.
20
- * Ordered clockwise from top-left for logical tab order.
21
- */
22
- const ALL_POSITIONS = [
23
- "nw",
24
- "n",
25
- "ne",
26
- "e",
27
- "se",
28
- "s",
29
- "sw",
30
- "w"
31
- ];
32
- /**
33
- * Get the translated aria-label for a resize handle position.
34
- *
35
- * @param pos The handle position identifier.
36
- * @return The translated label string.
37
- */
38
- function getHandleLabel(pos) {
39
- switch (pos) {
40
- case "n": return __("Resize from top edge");
41
- case "s": return __("Resize from bottom edge");
42
- case "e": return __("Resize from right edge");
43
- case "w": return __("Resize from left edge");
44
- case "nw": return __("Resize from top-left corner");
45
- case "ne": return __("Resize from top-right corner");
46
- case "sw": return __("Resize from bottom-left corner");
47
- case "se": return __("Resize from bottom-right corner");
48
- }
49
- }
50
- /** Delay before keyboard resize triggers settle (ms). */
51
- const KEYBOARD_SETTLE_DELAY = 500;
52
- /**
53
- * A rectangular crop stencil with resize handles.
54
- *
55
- * In freeform mode, handles resize the crop area. Clicks inside the
56
- * crop pass through to the container for image panning. The crop
57
- * auto-centers after resize via SETTLE_CROP.
58
- *
59
- * @param props Component props implementing StencilProps.
60
- * @param props.cropRect The crop rectangle in normalized coordinates.
61
- * @param props.containerSize The container element dimensions in pixels.
62
- * @param props.imageSize The rendered image dimensions in pixels.
63
- * @param props.onCropChange Callback fired when the crop rect changes.
64
- * @param props.onResizeStart Callback fired when a resize drag starts.
65
- * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).
66
- * @param props.aspectRatio Optional fixed aspect ratio (width / height).
67
- * @param props.freeformCrop Whether resize handles are shown.
68
- * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.
69
- * @param props.stencilTransition CSS transition string for settle animation.
70
- * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).
71
- * @param props.onEscape Called when Escape is pressed on a resize handle.
72
- * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.
73
- * @param props.snapCropRect Optional post-processor for freeform resize output.
74
- * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.
75
- * @return The rectangle stencil element.
76
- */
77
- function RectangleStencil({ cropRect, containerSize, imageSize, onCropChange, onResizeStart, onResizeEnd, aspectRatio, freeformCrop = false, isResizeDisabled = false, stencilTransition, cropBounds, onEscape, minCropSize, snapCropRect, keyboardResizeStep }) {
78
- const boundsMinX = cropBounds?.minX ?? 0;
79
- const boundsMinY = cropBounds?.minY ?? 0;
80
- const boundsMaxX = cropBounds?.maxX ?? 1;
81
- const boundsMaxY = cropBounds?.maxY ?? 1;
82
- const bounds = useMemo(() => ({
83
- minX: boundsMinX,
84
- minY: boundsMinY,
85
- maxX: boundsMaxX,
86
- maxY: boundsMaxY
87
- }), [
88
- boundsMinX,
89
- boundsMinY,
90
- boundsMaxX,
91
- boundsMaxY
92
- ]);
93
- const keyboardSettleTimerRef = useRef(void 0);
94
- const keyboardResizeActiveRef = useRef(false);
95
- const resizeHandleDescriptionId = useId();
96
- const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
97
- const activePointerResizeRef = useRef(null);
98
- useEffect(() => {
99
- return () => {
100
- clearTimeout(keyboardSettleTimerRef.current);
101
- keyboardResizeActiveRef.current = false;
102
- activePointerResizeRef.current?.cancel(false);
103
- };
104
- }, []);
105
- const latestHandlersRef = useRef(null);
106
- const normalizedRatio = useMemo(() => {
107
- if (!hasLockedRatio || imageSize.width === 0) return 0;
108
- return aspectRatio * imageSize.height / imageSize.width;
109
- }, [
110
- aspectRatio,
111
- hasLockedRatio,
112
- imageSize.width,
113
- imageSize.height
114
- ]);
115
- const offsetX = (containerSize.width - imageSize.width) / 2;
116
- const offsetY = (containerSize.height - imageSize.height) / 2;
117
- const left = offsetX + cropRect.x * imageSize.width;
118
- const top = offsetY + cropRect.y * imageSize.height;
119
- const width = cropRect.width * imageSize.width;
120
- const height = cropRect.height * imageSize.height;
121
- /**
122
- * Start a resize drag on a handle. Registers pointer listeners
123
- * synchronously so no events are missed between capture and the
124
- * next React commit.
125
- */
126
- const handlePointerDown = useCallback((handle, event) => {
127
- if (isResizeDisabled || event.pointerType === "touch" && event.isPrimary === false) {
128
- event.preventDefault();
129
- event.stopPropagation();
130
- return;
131
- }
132
- if (event.button !== 0) return;
133
- event.preventDefault();
134
- event.stopPropagation();
135
- const ownerDoc = event.currentTarget.ownerDocument;
136
- if (ownerDoc.activeElement instanceof HTMLElement) ownerDoc.activeElement.blur();
137
- const el = event.currentTarget;
138
- el.setPointerCapture(event.pointerId);
139
- const drag = {
140
- handle,
141
- startX: event.clientX,
142
- startY: event.clientY,
143
- startRect: { ...cropRect }
144
- };
145
- let rafId = 0;
146
- let latestX = event.clientX;
147
- let latestY = event.clientY;
148
- let latestShift = event.shiftKey;
149
- const onMove = (e) => {
150
- const pe = e;
151
- latestX = pe.clientX;
152
- latestY = pe.clientY;
153
- latestShift = pe.shiftKey;
154
- if (rafId) return;
155
- rafId = requestAnimationFrame(() => {
156
- rafId = 0;
157
- const h = latestHandlersRef.current;
158
- if (!h) return;
159
- let newRect;
160
- if (h.hasLockedRatio) newRect = h.computeLockedRect(drag, latestX, latestY);
161
- else if (latestShift) newRect = h.computeShiftLockedRect(drag, latestX, latestY);
162
- else {
163
- newRect = h.computeFreeRect(drag, latestX, latestY);
164
- newRect = h.snapCropRect?.(newRect, drag.handle) ?? newRect;
165
- }
166
- h.onCropChange(newRect);
167
- });
168
- };
169
- let ended = false;
170
- const endResize = (notifyResizeEnd = true, restoreFocus = true) => {
171
- if (ended) return;
172
- ended = true;
173
- if (rafId) {
174
- cancelAnimationFrame(rafId);
175
- rafId = 0;
176
- }
177
- el.removeEventListener("pointermove", onMove);
178
- el.removeEventListener("pointerup", onEnd);
179
- el.removeEventListener("lostpointercapture", onEnd);
180
- activePointerResizeRef.current = null;
181
- if (notifyResizeEnd) latestHandlersRef.current?.onResizeEnd?.();
182
- if (restoreFocus) el.focus({ preventScroll: true });
183
- };
184
- const cancelResize = (notifyResizeEnd = true) => endResize(notifyResizeEnd, false);
185
- const onEnd = () => endResize();
186
- el.addEventListener("pointermove", onMove);
187
- el.addEventListener("pointerup", onEnd);
188
- el.addEventListener("lostpointercapture", onEnd);
189
- activePointerResizeRef.current = { cancel: cancelResize };
190
- onResizeStart?.(handle);
191
- clearTimeout(keyboardSettleTimerRef.current);
192
- keyboardResizeActiveRef.current = false;
193
- }, [
194
- cropRect,
195
- isResizeDisabled,
196
- onResizeStart
197
- ]);
198
- /**
199
- * Compute the new crop rect for a free (no aspect ratio) resize.
200
- * Delegates to the pure function in core/stencil-math.ts.
201
- */
202
- const computeFreeRect = useCallback((drag, clientX, clientY) => computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize), [
203
- imageSize,
204
- bounds,
205
- minCropSize
206
- ]);
207
- /**
208
- * Compute the new crop rect for a locked-aspect-ratio corner resize.
209
- * Delegates to the pure function in core/stencil-math.ts.
210
- */
211
- const computeLockedRect = useCallback((drag, clientX, clientY, driverAxis) => computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize, driverAxis), [
212
- imageSize,
213
- bounds,
214
- normalizedRatio,
215
- minCropSize
216
- ]);
217
- latestHandlersRef.current = {
218
- hasLockedRatio,
219
- computeLockedRect,
220
- computeFreeRect,
221
- computeShiftLockedRect: useCallback((drag, clientX, clientY) => computeShiftLockedResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize), [
222
- imageSize,
223
- bounds,
224
- minCropSize
225
- ]),
226
- onCropChange,
227
- onResizeEnd,
228
- snapCropRect
229
- };
230
- useEffect(() => {
231
- if (!isResizeDisabled) return;
232
- activePointerResizeRef.current?.cancel();
233
- if (keyboardResizeActiveRef.current) {
234
- clearTimeout(keyboardSettleTimerRef.current);
235
- keyboardResizeActiveRef.current = false;
236
- latestHandlersRef.current?.onResizeEnd?.();
237
- }
238
- }, [isResizeDisabled]);
239
- /**
240
- * Handle keyboard events on a resize handle.
241
- * Arrow keys resize; Escape returns focus to the canvas.
242
- * Shift multiplies the step size by 10 for coarser movement.
243
- */
244
- const handleKeyDown = useCallback((handle, event) => {
245
- const key = event.key;
246
- if (isResizeDisabled) return;
247
- if (key === "Escape") {
248
- event.preventDefault();
249
- event.stopPropagation();
250
- onEscape?.();
251
- return;
252
- }
253
- if (key !== "ArrowUp" && key !== "ArrowDown" && key !== "ArrowLeft" && key !== "ArrowRight") return;
254
- event.preventDefault();
255
- event.stopPropagation();
256
- if (!keyboardResizeActiveRef.current) {
257
- keyboardResizeActiveRef.current = true;
258
- onResizeStart?.(handle);
259
- }
260
- const scheduleKeyboardResizeEnd = () => {
261
- clearTimeout(keyboardSettleTimerRef.current);
262
- keyboardSettleTimerRef.current = setTimeout(() => {
263
- keyboardResizeActiveRef.current = false;
264
- onResizeEnd?.();
265
- }, KEYBOARD_SETTLE_DELAY);
266
- };
267
- const stepMultiplier = event.shiftKey ? KEYBOARD_SHIFT_STEP_MULTIPLIER : 1;
268
- const stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;
269
- const stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;
270
- const adjustedStepX = stepX * stepMultiplier;
271
- const adjustedStepY = stepY * stepMultiplier;
272
- let dx = 0;
273
- let dy = 0;
274
- if (key === "ArrowLeft") dx = -adjustedStepX;
275
- if (key === "ArrowRight") dx = adjustedStepX;
276
- if (key === "ArrowUp") dy = -adjustedStepY;
277
- if (key === "ArrowDown") dy = adjustedStepY;
278
- const keyboardDriverAxis = dx !== 0 ? "width" : "height";
279
- if (hasLockedRatio) {
280
- const syntheticDrag = {
281
- handle,
282
- startX: 0,
283
- startY: 0,
284
- startRect: { ...cropRect }
285
- };
286
- const clientX = dx * imageSize.width;
287
- const clientY = dy * imageSize.height;
288
- onCropChange(computeLockedRect(syntheticDrag, clientX, clientY, keyboardDriverAxis));
289
- scheduleKeyboardResizeEnd();
290
- } else {
291
- const syntheticDrag = {
292
- handle,
293
- startX: 0,
294
- startY: 0,
295
- startRect: { ...cropRect }
296
- };
297
- const clientX = dx * imageSize.width;
298
- const clientY = dy * imageSize.height;
299
- const rect = computeFreeRect(syntheticDrag, clientX, clientY);
300
- onCropChange(snapCropRect?.(rect, handle) ?? rect);
301
- scheduleKeyboardResizeEnd();
302
- }
303
- }, [
304
- cropRect,
305
- hasLockedRatio,
306
- imageSize.width,
307
- imageSize.height,
308
- computeLockedRect,
309
- computeFreeRect,
310
- onCropChange,
311
- onResizeStart,
312
- onResizeEnd,
313
- onEscape,
314
- keyboardResizeStep,
315
- snapCropRect,
316
- isResizeDisabled
317
- ]);
318
- if (containerSize.width === 0 || containerSize.height === 0) return null;
319
- const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
320
- return /* @__PURE__ */ jsxs("div", {
321
- className: "wp-media-editor-image-editor__stencil",
322
- "data-testid": "cropper-stencil",
323
- style: {
324
- left,
325
- top,
326
- width,
327
- height,
328
- transition: stencilTransition
329
- },
330
- children: [
331
- freeformCrop && /* @__PURE__ */ jsx("div", {
332
- id: resizeHandleDescriptionId,
333
- style: VISUALLY_HIDDEN_STYLE,
334
- children: __("Use arrow keys to resize the crop area. Hold Shift for larger steps.")
335
- }),
336
- /* @__PURE__ */ jsx("div", {
337
- className: "wp-media-editor-image-editor__stencil-rect",
338
- style: {
339
- width: "100%",
340
- height: "100%",
341
- top: 0,
342
- left: 0
343
- }
344
- }),
345
- freeformCrop && handles.map((pos) => /* @__PURE__ */ jsx("button", {
346
- type: "button",
347
- className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
348
- onPointerDown: (event) => handlePointerDown(pos, event),
349
- onTouchStart: (event) => {
350
- if (event.touches.length < 2) event.stopPropagation();
351
- },
352
- onKeyDown: (event) => handleKeyDown(pos, event),
353
- disabled: isResizeDisabled,
354
- "aria-label": getHandleLabel(pos),
355
- "aria-describedby": resizeHandleDescriptionId
356
- }, pos))
357
- ]
358
- });
359
- }
360
- export { RectangleStencil };
361
-
362
- //# sourceMappingURL=rectangle-stencil.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rectangle-stencil.mjs","names":[],"sources":["../../../../../src/image-editor/react/components/stencils/rectangle-stencil.tsx"],"sourcesContent":["import {\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport type { StencilProps, NormalizedRect } from '../../../core/types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n} from '../../../core/constants';\nimport {\n\tcomputeFreeResizeRect,\n\tcomputeLockedResizeRect,\n\tcomputeShiftLockedResizeRect,\n\ttype HandlePosition,\n\ttype CropBounds,\n\ttype ResizeDragState,\n\ttype ResizeDriverAxis,\n} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only — used when aspect ratio is locked.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst CORNER_POSITIONS: HandlePosition[] = [ 'nw', 'ne', 'se', 'sw' ];\n\n/**\n * All handle positions rendered by the stencil.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst ALL_POSITIONS: HandlePosition[] = [\n\t'nw',\n\t'n',\n\t'ne',\n\t'e',\n\t'se',\n\t's',\n\t'sw',\n\t'w',\n];\n\n/**\n * Get the translated aria-label for a resize handle position.\n *\n * @param pos The handle position identifier.\n * @return The translated label string.\n */\nfunction getHandleLabel( pos: HandlePosition ): string {\n\tswitch ( pos ) {\n\t\tcase 'n':\n\t\t\treturn __( 'Resize from top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize from bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize from right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize from left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize from top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize from top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize from bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize from bottom-right corner' );\n\t}\n}\n\n/** Delay before keyboard resize triggers settle (ms). */\nconst KEYBOARD_SETTLE_DELAY = 500;\n\n/**\n * Props for the RectangleStencil component.\n */\ntype RectangleStencilProps = StencilProps;\n\n/**\n * A rectangular crop stencil with resize handles.\n *\n * In freeform mode, handles resize the crop area. Clicks inside the\n * crop pass through to the container for image panning. The crop\n * auto-centers after resize via SETTLE_CROP.\n *\n * @param props Component props implementing StencilProps.\n * @param props.cropRect The crop rectangle in normalized coordinates.\n * @param props.containerSize The container element dimensions in pixels.\n * @param props.imageSize The rendered image dimensions in pixels.\n * @param props.onCropChange Callback fired when the crop rect changes.\n * @param props.onResizeStart Callback fired when a resize drag starts.\n * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).\n * @param props.aspectRatio Optional fixed aspect ratio (width / height).\n * @param props.freeformCrop Whether resize handles are shown.\n * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.\n * @param props.stencilTransition CSS transition string for settle animation.\n * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).\n * @param props.onEscape Called when Escape is pressed on a resize handle.\n * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param props.snapCropRect Optional post-processor for freeform resize output.\n * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.\n * @return The rectangle stencil element.\n */\nexport function RectangleStencil( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tonCropChange,\n\tonResizeStart,\n\tonResizeEnd,\n\taspectRatio,\n\tfreeformCrop = false,\n\tisResizeDisabled = false,\n\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\n\tsnapCropRect,\n\tkeyboardResizeStep,\n}: RectangleStencilProps ) {\n\t// Use cropBounds from the camera if available, otherwise default to [0,1].\n\tconst boundsMinX = cropBounds?.minX ?? 0;\n\tconst boundsMinY = cropBounds?.minY ?? 0;\n\tconst boundsMaxX = cropBounds?.maxX ?? 1;\n\tconst boundsMaxY = cropBounds?.maxY ?? 1;\n\tconst bounds: CropBounds = useMemo(\n\t\t() => ( {\n\t\t\tminX: boundsMinX,\n\t\t\tminY: boundsMinY,\n\t\t\tmaxX: boundsMaxX,\n\t\t\tmaxY: boundsMaxY,\n\t\t} ),\n\t\t[ boundsMinX, boundsMinY, boundsMaxX, boundsMaxY ]\n\t);\n\tconst keyboardSettleTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\tconst keyboardResizeActiveRef = useRef( false );\n\tconst resizeHandleDescriptionId = useId();\n\tconst hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );\n\tconst activePointerResizeRef = useRef< {\n\t\tcancel: ( notifyResizeEnd?: boolean ) => void;\n\t} | null >( null );\n\n\t// Clear the pending keyboard settle timer on unmount so it can't\n\t// fire onResizeEnd / dispatch onto an unmounted parent.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\tactivePointerResizeRef.current?.cancel( false );\n\t\t};\n\t}, [] );\n\n\t// Latest callbacks for the drag listeners. The drag closure in\n\t// handlePointerDown reads from this ref so it always sees current\n\t// props without having to re-attach listeners mid-drag. Previously,\n\t// drag listeners lived in a useEffect that re-ran whenever `bounds`\n\t// changed (every SET_CROP_RECT dispatch), creating a window where\n\t// pointerup could be missed and the crop would never settle.\n\tconst latestHandlersRef = useRef< {\n\t\thasLockedRatio: boolean;\n\t\tcomputeLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t) => NormalizedRect;\n\t\tcomputeFreeRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tcomputeShiftLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tonCropChange: ( rect: NormalizedRect ) => void;\n\t\tonResizeEnd?: () => void;\n\t\tsnapCropRect?: (\n\t\t\trect: NormalizedRect,\n\t\t\thandle: HandlePosition\n\t\t) => NormalizedRect;\n\t} | null >( null );\n\n\t// The normalized aspect ratio: the w/h ratio in normalized space that\n\t// produces the desired pixel aspect ratio.\n\t// pixelW = w * imageSize.width, pixelH = h * imageSize.height\n\t// pixelW / pixelH = aspectRatio => w / h = aspectRatio * imageSize.height / imageSize.width\n\tconst normalizedRatio = useMemo( () => {\n\t\tif ( ! hasLockedRatio || imageSize.width === 0 ) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn ( aspectRatio * imageSize.height ) / imageSize.width;\n\t}, [ aspectRatio, hasLockedRatio, imageSize.width, imageSize.height ] );\n\n\t// Convert normalized crop rect to pixel bounds, accounting for the\n\t// image offset within the container.\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\t/**\n\t * Start a resize drag on a handle. Registers pointer listeners\n\t * synchronously so no events are missed between capture and the\n\t * next React commit.\n\t */\n\tconst handlePointerDown = useCallback(\n\t\t( handle: HandlePosition, event: React.PointerEvent ) => {\n\t\t\tif (\n\t\t\t\tisResizeDisabled ||\n\t\t\t\t( event.pointerType === 'touch' && event.isPrimary === false )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t\t// Blur any previously focused handle.\n\t\t\tconst ownerDoc = event.currentTarget.ownerDocument;\n\t\t\tif ( ownerDoc.activeElement instanceof HTMLElement ) {\n\t\t\t\townerDoc.activeElement.blur();\n\t\t\t}\n\t\t\t// Capture pointer so drag works across iframe boundaries.\n\t\t\tconst el = event.currentTarget as HTMLButtonElement;\n\t\t\tel.setPointerCapture( event.pointerId );\n\n\t\t\tconst drag: ResizeDragState = {\n\t\t\t\thandle,\n\t\t\t\tstartX: event.clientX,\n\t\t\t\tstartY: event.clientY,\n\t\t\t\tstartRect: { ...cropRect },\n\t\t\t};\n\n\t\t\t// RAF-throttle: stash the latest pointer position and\n\t\t\t// process it once per animation frame. Avoids dispatching\n\t\t\t// on every pointermove (which fires at much higher than\n\t\t\t// screen refresh rate) and matches the pan-drag path in\n\t\t\t// InteractionController.\n\t\t\tlet rafId = 0;\n\t\t\tlet latestX = event.clientX;\n\t\t\tlet latestY = event.clientY;\n\t\t\tlet latestShift = event.shiftKey;\n\n\t\t\tconst onMove = ( e: Event ) => {\n\t\t\t\tconst pe = e as PointerEvent;\n\t\t\t\tlatestX = pe.clientX;\n\t\t\t\tlatestY = pe.clientY;\n\t\t\t\tlatestShift = pe.shiftKey;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\t\trafId = 0;\n\t\t\t\t\tconst h = latestHandlersRef.current;\n\t\t\t\t\tif ( ! h ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet newRect: NormalizedRect;\n\t\t\t\t\tif ( h.hasLockedRatio ) {\n\t\t\t\t\t\tnewRect = h.computeLockedRect( drag, latestX, latestY );\n\t\t\t\t\t} else if ( latestShift ) {\n\t\t\t\t\t\tnewRect = h.computeShiftLockedRect(\n\t\t\t\t\t\t\tdrag,\n\t\t\t\t\t\t\tlatestX,\n\t\t\t\t\t\t\tlatestY\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewRect = h.computeFreeRect( drag, latestX, latestY );\n\t\t\t\t\t\tnewRect =\n\t\t\t\t\t\t\th.snapCropRect?.( newRect, drag.handle ) ?? newRect;\n\t\t\t\t\t}\n\t\t\t\t\th.onCropChange( newRect );\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Guard against duplicate firing: pointerup and\n\t\t\t// lostpointercapture both fire on normal release.\n\t\t\tlet ended = false;\n\t\t\tconst endResize = (\n\t\t\t\tnotifyResizeEnd = true,\n\t\t\t\trestoreFocus = true\n\t\t\t) => {\n\t\t\t\tif ( ended ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tended = true;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t\t\trafId = 0;\n\t\t\t\t}\n\t\t\t\tel.removeEventListener( 'pointermove', onMove );\n\t\t\t\tel.removeEventListener( 'pointerup', onEnd );\n\t\t\t\tel.removeEventListener( 'lostpointercapture', onEnd );\n\t\t\t\tactivePointerResizeRef.current = null;\n\t\t\t\tif ( notifyResizeEnd ) {\n\t\t\t\t\tlatestHandlersRef.current?.onResizeEnd?.();\n\t\t\t\t}\n\t\t\t\t// Restore focus to the handle so arrow keys work\n\t\t\t\t// immediately after a mouse drag. Browsers suppress\n\t\t\t\t// :focus-visible after pointer interactions, so the\n\t\t\t\t// focus ring stays hidden until the user presses a key.\n\t\t\t\tif ( restoreFocus ) {\n\t\t\t\t\tel.focus( { preventScroll: true } );\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst cancelResize = ( notifyResizeEnd = true ) =>\n\t\t\t\tendResize( notifyResizeEnd, false );\n\t\t\tconst onEnd = () => endResize();\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\n\t\t\tactivePointerResizeRef.current = { cancel: cancelResize };\n\n\t\t\tonResizeStart?.( handle );\n\t\t\t// Cancel any pending keyboard settle so it can't fire onResizeEnd\n\t\t\t// mid-drag if the user switches from keyboard to pointer within\n\t\t\t// the settle window.\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t},\n\t\t[ cropRect, isResizeDisabled, onResizeStart ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a free (no aspect ratio) resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeFreeRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeFreeResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a locked-aspect-ratio corner resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t): NormalizedRect =>\n\t\t\tcomputeLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tnormalizedRatio,\n\t\t\t\tminCropSize,\n\t\t\t\tdriverAxis\n\t\t\t),\n\t\t[ imageSize, bounds, normalizedRatio, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect when Shift is held during a freeform\n\t * resize — preserves the start rect's aspect ratio.\n\t */\n\tconst computeShiftLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeShiftLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\tlatestHandlersRef.current = {\n\t\thasLockedRatio,\n\t\tcomputeLockedRect,\n\t\tcomputeFreeRect,\n\t\tcomputeShiftLockedRect,\n\t\tonCropChange,\n\t\tonResizeEnd,\n\t\tsnapCropRect,\n\t};\n\n\t// Cancel an in-flight resize when the handles are disabled. Reads\n\t// `onResizeEnd` from the ref above so a new callback identity does\n\t// not re-run this and close the gesture twice.\n\tuseEffect( () => {\n\t\tif ( ! isResizeDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tactivePointerResizeRef.current?.cancel();\n\t\t// A keyboard resize settles on a timer rather than a pointer\n\t\t// release, so close it here too: otherwise the pending timer\n\t\t// fires `onResizeEnd` after the resize was already cancelled.\n\t\tif ( keyboardResizeActiveRef.current ) {\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\tlatestHandlersRef.current?.onResizeEnd?.();\n\t\t}\n\t}, [ isResizeDisabled ] );\n\n\t/**\n\t * Handle keyboard events on a resize handle.\n\t * Arrow keys resize; Escape returns focus to the canvas.\n\t * Shift multiplies the step size by 10 for coarser movement.\n\t */\n\tconst handleKeyDown = useCallback(\n\t\t( handle: HandlePosition, event: React.KeyboardEvent ) => {\n\t\t\tconst key = event.key;\n\n\t\t\tif ( isResizeDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( key === 'Escape' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonEscape?.();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tkey !== 'ArrowUp' &&\n\t\t\t\tkey !== 'ArrowDown' &&\n\t\t\t\tkey !== 'ArrowLeft' &&\n\t\t\t\tkey !== 'ArrowRight'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\n\t\t\tif ( ! keyboardResizeActiveRef.current ) {\n\t\t\t\tkeyboardResizeActiveRef.current = true;\n\t\t\t\tonResizeStart?.( handle );\n\t\t\t}\n\n\t\t\tconst scheduleKeyboardResizeEnd = () => {\n\t\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\t\tkeyboardSettleTimerRef.current = setTimeout( () => {\n\t\t\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\t\t\tonResizeEnd?.();\n\t\t\t\t}, KEYBOARD_SETTLE_DELAY );\n\t\t\t};\n\n\t\t\tconst stepMultiplier = event.shiftKey\n\t\t\t\t? KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: 1;\n\t\t\tconst stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst adjustedStepX = stepX * stepMultiplier;\n\t\t\tconst adjustedStepY = stepY * stepMultiplier;\n\n\t\t\t// Determine the normalized delta from the arrow key.\n\t\t\tlet dx = 0;\n\t\t\tlet dy = 0;\n\t\t\tif ( key === 'ArrowLeft' ) {\n\t\t\t\tdx = -adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -adjustedStepY;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = adjustedStepY;\n\t\t\t}\n\t\t\tconst keyboardDriverAxis: ResizeDriverAxis =\n\t\t\t\tdx !== 0 ? 'width' : 'height';\n\n\t\t\tif ( hasLockedRatio ) {\n\t\t\t\t// For locked aspect ratio, synthesize a drag from the\n\t\t\t\t// current rect and apply the delta via computeLockedRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tonCropChange(\n\t\t\t\t\tcomputeLockedRect(\n\t\t\t\t\t\tsyntheticDrag,\n\t\t\t\t\t\tclientX,\n\t\t\t\t\t\tclientY,\n\t\t\t\t\t\tkeyboardDriverAxis\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t} else {\n\t\t\t\t// For freeform resize, synthesize a drag via computeFreeRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tconst rect = computeFreeRect( syntheticDrag, clientX, clientY );\n\t\t\t\tonCropChange( snapCropRect?.( rect, handle ) ?? rect );\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tcropRect,\n\t\t\thasLockedRatio,\n\t\t\timageSize.width,\n\t\t\timageSize.height,\n\t\t\tcomputeLockedRect,\n\t\t\tcomputeFreeRect,\n\t\t\tonCropChange,\n\t\t\tonResizeStart,\n\t\t\tonResizeEnd,\n\t\t\tonEscape,\n\t\t\tkeyboardResizeStep,\n\t\t\tsnapCropRect,\n\t\t\tisResizeDisabled,\n\t\t]\n\t);\n\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__stencil\"\n\t\t\tdata-testid=\"cropper-stencil\"\n\t\t\tstyle={ {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\ttransition: stencilTransition,\n\t\t\t} }\n\t\t>\n\t\t\t{ freeformCrop && (\n\t\t\t\t<div\n\t\t\t\t\tid={ resizeHandleDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Use arrow keys to resize the crop area. Hold Shift for larger steps.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /* The crop rectangle border. pointer-events: none is set in\n\t\t\t\t CSS so clicks pass through to the container for panning. */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__stencil-rect\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\theight: '100%',\n\t\t\t\t\ttop: 0,\n\t\t\t\t\tleft: 0,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ /* Resize handles — only in freeform mode.\n\t\t\t\t Semantics: role=\"button\" with aria-label describing\n\t\t\t\t which edge/corner. Arrow keys resize (onKeyDown).\n\t\t\t\t role=\"slider\" would be more precise but requires\n\t\t\t\t per-handle aria-valuemin/max/now which don't map\n\t\t\t\t cleanly to a 2D crop rect. */ }\n\t\t\t{ freeformCrop &&\n\t\t\t\thandles.map( ( pos ) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={ pos }\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${ pos }` }\n\t\t\t\t\t\tonPointerDown={ ( event ) =>\n\t\t\t\t\t\t\thandlePointerDown( pos, event )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonTouchStart={ ( event ) => {\n\t\t\t\t\t\t\tif ( event.touches.length < 2 ) {\n\t\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonKeyDown={ ( event ) => handleKeyDown( pos, event ) }\n\t\t\t\t\t\t// The handlers already refuse input, but the\n\t\t\t\t\t\t// button must say so too, or assistive technology\n\t\t\t\t\t\t// announces a control that does nothing.\n\t\t\t\t\t\tdisabled={ isResizeDisabled }\n\t\t\t\t\t\taria-label={ getHandleLabel( pos ) }\n\t\t\t\t\t\taria-describedby={ resizeHandleDescriptionId }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,mBAAqC;CAAE;CAAM;CAAM;CAAM;AAAK;;;;;AAMpE,MAAM,gBAAkC;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;AAQA,SAAS,eAAgB,KAA8B;CACtD,QAAS,KAAT;EACC,KAAK,KACJ,OAAO,GAAI,sBAA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3B,OAAO;GAEN,MAAM,gBAAiC;IACtC;IACA,QAAQ;IACR,QAAQ;IACR,WAAW,EAAE,GAAG,SAAS;GAC1B;GACA,MAAM,UAAU,KAAK,UAAU;GAC/B,MAAM,UAAU,KAAK,UAAU;GAC/B,MAAM,OAAO,gBAAiB,eAAe,SAAS,OAAQ;GAC9D,aAAc,eAAgB,MAAM,MAAO,KAAK,IAAK;GACrD,0BAA0B;EAC3B;CACD,GACA;EACC;EACA;EACA,UAAU;EACV,UAAU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CACD;CAEA,IAAK,cAAc,UAAU,KAAK,cAAc,WAAW,GAC1D,OAAO;CAGR,MAAM,UAAU,iBAAiB,mBAAmB;CAEpD,OACC,qBAAC,OAAD;EACC,WAAU;EACV,eAAY;EACZ,OAAQ;GACP;GACA;GACA;GACA;GACA,YAAY;EACb;EATD,UAAA;GAWG,gBACD,oBAAC,OAAD;IACC,IAAK;IACL,OAAQ;IAEN,UAAA,GACD,sEACD;GACI,CAAA;GAIN,oBAAC,OAAD;IACC,WAAU;IACV,OAAQ;KACP,OAAO;KACP,QAAQ;KACR,KAAK;KACL,MAAM;IACP;GACA,CAAA;GAOC,gBACD,QAAQ,KAAO,QACd,oBAAC,UAAD;IAEC,MAAK;IACL,WAAY,8EAA+E;IAC3F,gBAAkB,UACjB,kBAAmB,KAAK,KAAM;IAE/B,eAAiB,UAAW;KAC3B,IAAK,MAAM,QAAQ,SAAS,GAC3B,MAAM,gBAAgB;IAExB;IACA,YAAc,UAAW,cAAe,KAAK,KAAM;IAInD,UAAW;IACX,cAAa,eAAgB,GAAI;IACjC,oBAAmB;GACnB,GAlBM,GAkBN,CACA;EACC;;AAEP"}
@@ -1,20 +0,0 @@
1
- import { createContext, useContext } from "@wordpress/element";
2
- import { useViewportState } from "../hooks/use-viewport-state.mjs";
3
- import { jsx } from "react/jsx-runtime";
4
- // packages/media-editor/src/image-editor/react/components/viewport-provider.tsx
5
- const ViewportContext = createContext(null);
6
- function ViewportProvider({ children }) {
7
- const viewportState = useViewportState();
8
- return /* @__PURE__ */ jsx(ViewportContext.Provider, {
9
- value: viewportState,
10
- children
11
- });
12
- }
13
- function useViewport() {
14
- const context = useContext(ViewportContext);
15
- if (!context) throw new Error("useViewport must be used within a ViewportProvider.");
16
- return context;
17
- }
18
- export { ViewportProvider, useViewport };
19
-
20
- //# sourceMappingURL=viewport-provider.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"viewport-provider.mjs","names":[],"sources":["../../../../src/image-editor/react/components/viewport-provider.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseViewportState,\n\ttype UseViewportStateReturn,\n} from '../hooks/use-viewport-state';\n\ntype ViewportContextValue = UseViewportStateReturn;\n\nconst ViewportContext = createContext< ViewportContextValue | null >( null );\n\nexport function ViewportProvider( {\n\tchildren,\n}: {\n\tchildren: React.ReactNode;\n} ) {\n\tconst viewportState = useViewportState();\n\treturn (\n\t\t<ViewportContext.Provider value={ viewportState }>\n\t\t\t{ children }\n\t\t</ViewportContext.Provider>\n\t);\n}\n\nexport function useViewport(): UseViewportStateReturn {\n\tconst context = useContext( ViewportContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useViewport must be used within a ViewportProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":";;;;AAQA,MAAM,kBAAkB,cAA8C,IAAK;AAE3E,SAAgB,iBAAkB,EACjC,YAGG;CACH,MAAM,gBAAgB,iBAAiB;CACvC,OACC,oBAAC,gBAAgB,UAAjB;EAA0B,OAAQ;EAC/B;CACuB,CAAA;AAE5B;AAEA,SAAgB,cAAsC;CACrD,MAAM,UAAU,WAAY,eAAgB;CAC5C,IAAK,CAAE,SACN,MAAM,IAAI,MACT,qDACD;CAED,OAAO;AACR"}
@@ -1,75 +0,0 @@
1
- import { buildFocalPointZoomAction } from "../../core/setter-helpers.mjs";
2
- // packages/media-editor/src/image-editor/react/hooks/build-cropper-setters.ts
3
- /**
4
- * Build the named cropper setters from a dispatch function and a
5
- * state getter. The two consuming hooks differ in how they dispatch:
6
- *
7
- * - `useCropperController` dispatches directly into its `useReducer`.
8
- * - `useMediaEditorState` wraps cropper actions in a composite
9
- * `CROPPER` envelope so the history machinery can record them.
10
- *
11
- * Both pass their own dispatch function and a getter that returns
12
- * the current `CropperState`. The factory shape keeps the two hooks
13
- * in lockstep — add a setter here once, both hooks get it.
14
- *
15
- * @param dispatchCropperAction Apply a `CropperAction` to the
16
- * underlying reducer.
17
- * @param getCropperState Return the current `CropperState`.
18
- * Used by setters that need to read
19
- * the latest state to compute their
20
- * payload (focal-point zoom, flip toggle).
21
- * @return The named cropper setters.
22
- */
23
- function buildCropperSetters(dispatchCropperAction, getCropperState) {
24
- return {
25
- setPan: (pan) => dispatchCropperAction({
26
- type: "SET_PAN",
27
- payload: pan
28
- }),
29
- setZoom: (zoom) => {
30
- const action = buildFocalPointZoomAction(getCropperState(), zoom);
31
- if (action) dispatchCropperAction(action);
32
- },
33
- setZoomAtPoint: (zoom, pan) => dispatchCropperAction({
34
- type: "SET_ZOOM_AT_POINT",
35
- payload: {
36
- zoom,
37
- pan
38
- }
39
- }),
40
- setRotation: (rotation) => dispatchCropperAction({
41
- type: "SET_ROTATION",
42
- payload: rotation
43
- }),
44
- setFlip: (flip) => dispatchCropperAction({
45
- type: "SET_FLIP",
46
- payload: flip
47
- }),
48
- toggleFlip: (direction) => {
49
- const { flip } = getCropperState();
50
- dispatchCropperAction({
51
- type: "SET_FLIP",
52
- payload: {
53
- ...flip,
54
- [direction]: !flip[direction]
55
- }
56
- });
57
- },
58
- snapRotate90: (direction) => dispatchCropperAction({
59
- type: "SNAP_ROTATE_90",
60
- payload: { direction }
61
- }),
62
- setCropRect: (rect) => dispatchCropperAction({
63
- type: "SET_CROP_RECT",
64
- payload: rect
65
- }),
66
- settleCrop: () => dispatchCropperAction({ type: "SETTLE_CROP" }),
67
- applyOperation: (op) => dispatchCropperAction({
68
- type: "APPLY_OPERATION",
69
- payload: op
70
- })
71
- };
72
- }
73
- export { buildCropperSetters };
74
-
75
- //# sourceMappingURL=build-cropper-setters.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-cropper-setters.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/build-cropper-setters.ts"],"sourcesContent":["import type {\n\tCropperAction,\n\tCropperState,\n\tFlip,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tTransformOperation,\n} from '../../core/types';\nimport { buildFocalPointZoomAction } from '../../core/setter-helpers';\n\n/**\n * The named cropper setters shared by every hook that drives the\n * cropper reducer — the pure `useCropperController` and any composite\n * store that delegates cropper actions (e.g. `useMediaEditorState`).\n *\n * `setImage` and `reset` are intentionally NOT included: each hook\n * has additional bookkeeping for them (dirty-baseline, history clear)\n * that doesn't fit a shared factory.\n */\nexport interface CropperSetters {\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\tsetZoom: ( zoom: number ) => void;\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\tsetRotation: ( rotation: number ) => void;\n\tsetFlip: ( flip: Flip ) => void;\n\ttoggleFlip: ( direction: 'horizontal' | 'vertical' ) => void;\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\tsettleCrop: () => void;\n\tapplyOperation: ( op: TransformOperation ) => void;\n}\n\n/**\n * Build the named cropper setters from a dispatch function and a\n * state getter. The two consuming hooks differ in how they dispatch:\n *\n * - `useCropperController` dispatches directly into its `useReducer`.\n * - `useMediaEditorState` wraps cropper actions in a composite\n * `CROPPER` envelope so the history machinery can record them.\n *\n * Both pass their own dispatch function and a getter that returns\n * the current `CropperState`. The factory shape keeps the two hooks\n * in lockstep — add a setter here once, both hooks get it.\n *\n * @param dispatchCropperAction Apply a `CropperAction` to the\n * underlying reducer.\n * @param getCropperState Return the current `CropperState`.\n * Used by setters that need to read\n * the latest state to compute their\n * payload (focal-point zoom, flip toggle).\n * @return The named cropper setters.\n */\nexport function buildCropperSetters(\n\tdispatchCropperAction: ( action: CropperAction ) => void,\n\tgetCropperState: () => CropperState\n): CropperSetters {\n\treturn {\n\t\tsetPan: ( pan ) =>\n\t\t\tdispatchCropperAction( { type: 'SET_PAN', payload: pan } ),\n\t\tsetZoom: ( zoom ) => {\n\t\t\tconst action = buildFocalPointZoomAction( getCropperState(), zoom );\n\t\t\tif ( action ) {\n\t\t\t\tdispatchCropperAction( action );\n\t\t\t}\n\t\t},\n\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} ),\n\t\tsetRotation: ( rotation ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_ROTATION',\n\t\t\t\tpayload: rotation,\n\t\t\t} ),\n\t\tsetFlip: ( flip ) =>\n\t\t\tdispatchCropperAction( { type: 'SET_FLIP', payload: flip } ),\n\t\ttoggleFlip: ( direction ) => {\n\t\t\tconst { flip } = getCropperState();\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_FLIP',\n\t\t\t\tpayload: { ...flip, [ direction ]: ! flip[ direction ] },\n\t\t\t} );\n\t\t},\n\t\tsnapRotate90: ( direction ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} ),\n\t\tsetCropRect: ( rect ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: rect,\n\t\t\t} ),\n\t\tsettleCrop: () => dispatchCropperAction( { type: 'SETTLE_CROP' } ),\n\t\tapplyOperation: ( op ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'APPLY_OPERATION',\n\t\t\t\tpayload: op,\n\t\t\t} ),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,oBACf,uBACA,iBACiB;CACjB,OAAO;EACN,SAAU,QACT,sBAAuB;GAAE,MAAM;GAAW,SAAS;EAAI,CAAE;EAC1D,UAAW,SAAU;GACpB,MAAM,SAAS,0BAA2B,gBAAgB,GAAG,IAAK;GAClE,IAAK,QACJ,sBAAuB,MAAO;EAEhC;EACA,iBAAkB,MAAM,QACvB,sBAAuB;GACtB,MAAM;GACN,SAAS;IAAE;IAAM;GAAI;EACtB,CAAE;EACH,cAAe,aACd,sBAAuB;GACtB,MAAM;GACN,SAAS;EACV,CAAE;EACH,UAAW,SACV,sBAAuB;GAAE,MAAM;GAAY,SAAS;EAAK,CAAE;EAC5D,aAAc,cAAe;GAC5B,MAAM,EAAE,SAAS,gBAAgB;GACjC,sBAAuB;IACtB,MAAM;IACN,SAAS;KAAE,GAAG;MAAQ,YAAa,CAAE,KAAM;IAAY;GACxD,CAAE;EACH;EACA,eAAgB,cACf,sBAAuB;GACtB,MAAM;GACN,SAAS,EAAE,UAAU;EACtB,CAAE;EACH,cAAe,SACd,sBAAuB;GACtB,MAAM;GACN,SAAS;EACV,CAAE;EACH,kBAAkB,sBAAuB,EAAE,MAAM,cAAc,CAAE;EACjE,iBAAkB,OACjB,sBAAuB;GACtB,MAAM;GACN,SAAS;EACV,CAAE;CACJ;AACD"}
@@ -1,3 +0,0 @@
1
- import { useCropperController } from "./use-cropper-controller.mjs";
2
- import { buildCropperSetters } from "./build-cropper-setters.mjs";
3
- export { buildCropperSetters, useCropperController };
@@ -1,99 +0,0 @@
1
- import { speak } from "@wordpress/a11y";
2
- import { useEffect, useLayoutEffect, useRef } from "@wordpress/element";
3
- import { __, sprintf } from "@wordpress/i18n";
4
- import { getSourceRegion } from "../../core/source-region.mjs";
5
- // packages/media-editor/src/image-editor/react/hooks/use-aria-announcer.ts
6
- /** Debounce delay for ARIA live announcements (ms). */
7
- const ARIA_DEBOUNCE_MS = 300;
8
- function getFlipAnnouncement(state, previousState) {
9
- if (!previousState || previousState.flip.horizontal === state.flip.horizontal && previousState.flip.vertical === state.flip.vertical) return;
10
- const { horizontal, vertical } = state.flip;
11
- if (horizontal && vertical) return __("Flipped horizontally and vertically");
12
- if (horizontal) return __("Flipped horizontally");
13
- if (vertical) return __("Flipped vertically");
14
- return __("Flip removed");
15
- }
16
- function getRotationAnnouncement(state, previousState) {
17
- if (previousState && Math.round(previousState.rotation) === Math.round(state.rotation)) return;
18
- const visualDir = state.flip.horizontal !== state.flip.vertical ? -1 : 1;
19
- let visualRotation = Math.round(state.rotation) * visualDir % 360;
20
- if (visualRotation > 180) visualRotation -= 360;
21
- if (visualRotation <= -180) visualRotation += 360;
22
- if (visualRotation === 0) return previousState ? __("Rotation 0 degrees") : void 0;
23
- if (visualRotation > 0) return sprintf(__("Rotated %d degrees clockwise"), visualRotation);
24
- return sprintf(__("Rotated %d degrees counterclockwise"), Math.abs(visualRotation));
25
- }
26
- function getCropAnnouncement(state, previousState) {
27
- if (!state.image) return;
28
- const imageSize = {
29
- width: state.image.naturalWidth,
30
- height: state.image.naturalHeight
31
- };
32
- const region = getSourceRegion(state, imageSize);
33
- if (previousState?.image) {
34
- const previousRegion = getSourceRegion({
35
- ...state,
36
- cropRect: previousState.cropRect
37
- }, imageSize);
38
- if (Math.round(previousRegion.width) === Math.round(region.width) && Math.round(previousRegion.height) === Math.round(region.height)) return;
39
- }
40
- return sprintf(__("Crop %1$d by %2$d pixels"), Math.round(region.width), Math.round(region.height));
41
- }
42
- function getZoomAnnouncement(state, previousState) {
43
- if (previousState && Math.round(previousState.zoom * 100) === Math.round(state.zoom * 100)) return;
44
- return sprintf(__("Zoom %d%%"), Math.round(state.zoom * 100));
45
- }
46
- function buildAnnouncement(state, previousState) {
47
- const flip = getFlipAnnouncement(state, previousState);
48
- if (flip) return flip;
49
- return [
50
- getRotationAnnouncement(state, previousState),
51
- getZoomAnnouncement(state, previousState),
52
- getCropAnnouncement(state, previousState)
53
- ].filter((part) => part !== void 0).join(", ");
54
- }
55
- /**
56
- * Debounce and dedupe ARIA-live announcements for screen readers as the
57
- * cropper state changes. Calls `speak()` from `@wordpress/a11y` to use the
58
- * centralized, persistent live region instead of a local one that may be
59
- * dynamically mounted.
60
- *
61
- * Debouncing avoids flooding announcements during drag/pointermove bursts;
62
- * deduping avoids re-announcing the same state.
63
- *
64
- * @param state The current cropper state to announce.
65
- */
66
- function useAriaAnnouncer(state) {
67
- const timerRef = useRef(void 0);
68
- const prevMessageRef = useRef("");
69
- const prevStateRef = useRef(null);
70
- const latestStateRef = useRef(state);
71
- useLayoutEffect(() => {
72
- latestStateRef.current = state;
73
- }, [state]);
74
- useEffect(() => {
75
- clearTimeout(timerRef.current);
76
- timerRef.current = setTimeout(() => {
77
- const current = latestStateRef.current;
78
- const msg = buildAnnouncement(current, prevStateRef.current);
79
- prevStateRef.current = current;
80
- if (msg !== prevMessageRef.current) {
81
- prevMessageRef.current = msg;
82
- speak(msg);
83
- }
84
- }, ARIA_DEBOUNCE_MS);
85
- return () => {
86
- clearTimeout(timerRef.current);
87
- };
88
- }, [
89
- state.zoom,
90
- state.rotation,
91
- state.cropRect.width,
92
- state.cropRect.height,
93
- state.flip.horizontal,
94
- state.flip.vertical
95
- ]);
96
- }
97
- export { useAriaAnnouncer };
98
-
99
- //# sourceMappingURL=use-aria-announcer.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-aria-announcer.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/use-aria-announcer.ts"],"sourcesContent":["import { speak } from '@wordpress/a11y';\nimport { useEffect, useLayoutEffect, useRef } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { CropperState } from '../../core/types';\nimport { getSourceRegion } from '../../core/source-region';\n\n/** Debounce delay for ARIA live announcements (ms). */\nconst ARIA_DEBOUNCE_MS = 300;\n\nfunction getFlipAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif (\n\t\t! previousState ||\n\t\t( previousState.flip.horizontal === state.flip.horizontal &&\n\t\t\tpreviousState.flip.vertical === state.flip.vertical )\n\t) {\n\t\treturn undefined;\n\t}\n\tconst { horizontal, vertical } = state.flip;\n\tif ( horizontal && vertical ) {\n\t\treturn __( 'Flipped horizontally and vertically' );\n\t}\n\tif ( horizontal ) {\n\t\treturn __( 'Flipped horizontally' );\n\t}\n\tif ( vertical ) {\n\t\treturn __( 'Flipped vertically' );\n\t}\n\treturn __( 'Flip removed' );\n}\n\nfunction getRotationAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif (\n\t\tpreviousState &&\n\t\tMath.round( previousState.rotation ) === Math.round( state.rotation )\n\t) {\n\t\treturn undefined;\n\t}\n\t// Announce the visual rotation — what the user perceives on screen. A\n\t// single-axis flip mirrors the image, reversing the entire on-screen\n\t// rotation relative to the stored field (the same S·R·S inversion the\n\t// reducer applies), so negate the whole angle in that case.\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\t// Normalize to (-180, 180] so the sign indicates direction.\n\tlet visualRotation = ( Math.round( state.rotation ) * visualDir ) % 360;\n\tif ( visualRotation > 180 ) {\n\t\tvisualRotation -= 360;\n\t}\n\tif ( visualRotation <= -180 ) {\n\t\tvisualRotation += 360;\n\t}\n\tif ( visualRotation === 0 ) {\n\t\treturn previousState ? __( 'Rotation 0 degrees' ) : undefined;\n\t}\n\tif ( visualRotation > 0 ) {\n\t\treturn sprintf(\n\t\t\t/* translators: %d: rotation angle in degrees. */\n\t\t\t__( 'Rotated %d degrees clockwise' ),\n\t\t\tvisualRotation\n\t\t);\n\t}\n\treturn sprintf(\n\t\t/* translators: %d: rotation angle in degrees. */\n\t\t__( 'Rotated %d degrees counterclockwise' ),\n\t\tMath.abs( visualRotation )\n\t);\n}\n\nfunction getCropAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif ( ! state.image ) {\n\t\treturn undefined;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tconst region = getSourceRegion( state, imageSize );\n\t// Announce only when the crop's pixel dimensions change. Measuring both the\n\t// previous and current crop rects under the current rotation and zoom keeps\n\t// the comparison in the same pixel units we announce, and leaves a zoom-only\n\t// change — which doesn't move the crop rect — silent.\n\tif ( previousState?.image ) {\n\t\tconst previousRegion = getSourceRegion(\n\t\t\t{ ...state, cropRect: previousState.cropRect },\n\t\t\timageSize\n\t\t);\n\t\tif (\n\t\t\tMath.round( previousRegion.width ) === Math.round( region.width ) &&\n\t\t\tMath.round( previousRegion.height ) === Math.round( region.height )\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn sprintf(\n\t\t/* translators: 1: crop width in pixels, 2: crop height in pixels. */\n\t\t__( 'Crop %1$d by %2$d pixels' ),\n\t\tMath.round( region.width ),\n\t\tMath.round( region.height )\n\t);\n}\n\nfunction getZoomAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif (\n\t\tpreviousState &&\n\t\tMath.round( previousState.zoom * 100 ) ===\n\t\t\tMath.round( state.zoom * 100 )\n\t) {\n\t\treturn undefined;\n\t}\n\treturn sprintf(\n\t\t/* translators: %d: zoom level as a percentage. */\n\t\t__( 'Zoom %d%%' ),\n\t\tMath.round( state.zoom * 100 )\n\t);\n}\n\nfunction buildAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string {\n\t// Flip changes are announced alone.\n\tconst flip = getFlipAnnouncement( state, previousState );\n\tif ( flip ) {\n\t\treturn flip;\n\t}\n\n\tconst parts = [\n\t\tgetRotationAnnouncement( state, previousState ),\n\t\tgetZoomAnnouncement( state, previousState ),\n\t\tgetCropAnnouncement( state, previousState ),\n\t].filter( ( part ): part is string => part !== undefined );\n\n\treturn parts.join( ', ' );\n}\n\n/**\n * Debounce and dedupe ARIA-live announcements for screen readers as the\n * cropper state changes. Calls `speak()` from `@wordpress/a11y` to use the\n * centralized, persistent live region instead of a local one that may be\n * dynamically mounted.\n *\n * Debouncing avoids flooding announcements during drag/pointermove bursts;\n * deduping avoids re-announcing the same state.\n *\n * @param state The current cropper state to announce.\n */\nexport function useAriaAnnouncer( state: CropperState ): void {\n\tconst timerRef = useRef< ReturnType< typeof setTimeout > | undefined >(\n\t\tundefined\n\t);\n\tconst prevMessageRef = useRef( '' );\n\tconst prevStateRef = useRef< CropperState | null >( null );\n\tconst latestStateRef = useRef( state );\n\tuseLayoutEffect( () => {\n\t\tlatestStateRef.current = state;\n\t}, [ state ] );\n\n\tuseEffect( () => {\n\t\tclearTimeout( timerRef.current );\n\t\ttimerRef.current = setTimeout( () => {\n\t\t\tconst current = latestStateRef.current;\n\t\t\tconst msg = buildAnnouncement( current, prevStateRef.current );\n\t\t\tprevStateRef.current = current;\n\t\t\tif ( msg !== prevMessageRef.current ) {\n\t\t\t\tprevMessageRef.current = msg;\n\t\t\t\tspeak( msg );\n\t\t\t}\n\t\t}, ARIA_DEBOUNCE_MS );\n\n\t\treturn () => {\n\t\t\tclearTimeout( timerRef.current );\n\t\t};\n\t}, [\n\t\tstate.zoom,\n\t\tstate.rotation,\n\t\tstate.cropRect.width,\n\t\tstate.cropRect.height,\n\t\tstate.flip.horizontal,\n\t\tstate.flip.vertical,\n\t] );\n}\n"],"mappings":";;;;;;AAOA,MAAM,mBAAmB;AAEzB,SAAS,oBACR,OACA,eACqB;CACrB,IACC,CAAE,iBACA,cAAc,KAAK,eAAe,MAAM,KAAK,cAC9C,cAAc,KAAK,aAAa,MAAM,KAAK,UAE5C;CAED,MAAM,EAAE,YAAY,aAAa,MAAM;CACvC,IAAK,cAAc,UAClB,OAAO,GAAI,qCAAsC;CAElD,IAAK,YACJ,OAAO,GAAI,sBAAuB;CAEnC,IAAK,UACJ,OAAO,GAAI,oBAAqB;CAEjC,OAAO,GAAI,cAAe;AAC3B;AAEA,SAAS,wBACR,OACA,eACqB;CACrB,IACC,iBACA,K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