@wordpress/media-editor 0.20.0 → 0.22.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 (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -1,414 +1,362 @@
1
- // packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
2
- import {
3
- useCallback,
4
- useEffect,
5
- useId,
6
- useMemo,
7
- useRef
8
- } from "@wordpress/element";
1
+ import { useCallback, useEffect, useId, useMemo, useRef } from "@wordpress/element";
9
2
  import { __ } from "@wordpress/i18n";
10
- import {
11
- DEFAULT_KEYBOARD_STEP,
12
- KEYBOARD_SHIFT_STEP_MULTIPLIER
13
- } from "../../../core/constants.mjs";
14
- import {
15
- computeFreeResizeRect,
16
- computeLockedResizeRect,
17
- computeShiftLockedResizeRect
18
- } from "../../../core/stencil-math.mjs";
3
+ import { DEFAULT_KEYBOARD_STEP, KEYBOARD_SHIFT_STEP_MULTIPLIER } from "../../../core/constants.mjs";
4
+ import { computeFreeResizeRect, computeLockedResizeRect, computeShiftLockedResizeRect } from "../../../core/stencil-math.mjs";
19
5
  import { VISUALLY_HIDDEN_STYLE } from "../../visually-hidden-style.mjs";
20
6
  import { jsx, jsxs } from "react/jsx-runtime";
21
- var CORNER_POSITIONS = ["nw", "ne", "se", "sw"];
22
- var ALL_POSITIONS = [
23
- "nw",
24
- "n",
25
- "ne",
26
- "e",
27
- "se",
28
- "s",
29
- "sw",
30
- "w"
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
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
+ */
32
38
  function getHandleLabel(pos) {
33
- switch (pos) {
34
- case "n":
35
- return __("Resize from top edge");
36
- case "s":
37
- return __("Resize from bottom edge");
38
- case "e":
39
- return __("Resize from right edge");
40
- case "w":
41
- return __("Resize from left edge");
42
- case "nw":
43
- return __("Resize from top-left corner");
44
- case "ne":
45
- return __("Resize from top-right corner");
46
- case "sw":
47
- return __("Resize from bottom-left corner");
48
- case "se":
49
- return __("Resize from bottom-right corner");
50
- }
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
+ }
51
49
  }
52
- var KEYBOARD_SETTLE_DELAY = 500;
53
- function RectangleStencil({
54
- cropRect,
55
- containerSize,
56
- imageSize,
57
- onCropChange,
58
- onResizeStart,
59
- onResizeEnd,
60
- aspectRatio,
61
- freeformCrop = false,
62
- isResizeDisabled = false,
63
- stencilTransition,
64
- cropBounds,
65
- onEscape,
66
- minCropSize,
67
- snapCropRect,
68
- keyboardResizeStep
69
- }) {
70
- const boundsMinX = cropBounds?.minX ?? 0;
71
- const boundsMinY = cropBounds?.minY ?? 0;
72
- const boundsMaxX = cropBounds?.maxX ?? 1;
73
- const boundsMaxY = cropBounds?.maxY ?? 1;
74
- const bounds = useMemo(
75
- () => ({
76
- minX: boundsMinX,
77
- minY: boundsMinY,
78
- maxX: boundsMaxX,
79
- maxY: boundsMaxY
80
- }),
81
- [boundsMinX, boundsMinY, boundsMaxX, boundsMaxY]
82
- );
83
- const keyboardSettleTimerRef = useRef(void 0);
84
- const keyboardResizeActiveRef = useRef(false);
85
- const resizeHandleDescriptionId = useId();
86
- const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
87
- const activePointerResizeRef = useRef(null);
88
- useEffect(() => {
89
- return () => {
90
- clearTimeout(keyboardSettleTimerRef.current);
91
- keyboardResizeActiveRef.current = false;
92
- activePointerResizeRef.current?.cancel(false);
93
- };
94
- }, []);
95
- const latestHandlersRef = useRef(null);
96
- const normalizedRatio = useMemo(() => {
97
- if (!hasLockedRatio || imageSize.width === 0) {
98
- return 0;
99
- }
100
- return aspectRatio * imageSize.height / imageSize.width;
101
- }, [aspectRatio, hasLockedRatio, imageSize.width, imageSize.height]);
102
- const offsetX = (containerSize.width - imageSize.width) / 2;
103
- const offsetY = (containerSize.height - imageSize.height) / 2;
104
- const left = offsetX + cropRect.x * imageSize.width;
105
- const top = offsetY + cropRect.y * imageSize.height;
106
- const width = cropRect.width * imageSize.width;
107
- const height = cropRect.height * imageSize.height;
108
- const handlePointerDown = useCallback(
109
- (handle, event) => {
110
- if (isResizeDisabled || event.pointerType === "touch" && event.isPrimary === false) {
111
- event.preventDefault();
112
- event.stopPropagation();
113
- return;
114
- }
115
- if (event.button !== 0) {
116
- return;
117
- }
118
- event.preventDefault();
119
- event.stopPropagation();
120
- const ownerDoc = event.currentTarget.ownerDocument;
121
- if (ownerDoc.activeElement instanceof HTMLElement) {
122
- ownerDoc.activeElement.blur();
123
- }
124
- const el = event.currentTarget;
125
- el.setPointerCapture(event.pointerId);
126
- const drag = {
127
- handle,
128
- startX: event.clientX,
129
- startY: event.clientY,
130
- startRect: { ...cropRect }
131
- };
132
- let rafId = 0;
133
- let latestX = event.clientX;
134
- let latestY = event.clientY;
135
- let latestShift = event.shiftKey;
136
- const onMove = (e) => {
137
- const pe = e;
138
- latestX = pe.clientX;
139
- latestY = pe.clientY;
140
- latestShift = pe.shiftKey;
141
- if (rafId) {
142
- return;
143
- }
144
- rafId = requestAnimationFrame(() => {
145
- rafId = 0;
146
- const h = latestHandlersRef.current;
147
- if (!h) {
148
- return;
149
- }
150
- let newRect;
151
- if (h.hasLockedRatio) {
152
- newRect = h.computeLockedRect(drag, latestX, latestY);
153
- } else if (latestShift) {
154
- newRect = h.computeShiftLockedRect(
155
- drag,
156
- latestX,
157
- latestY
158
- );
159
- } else {
160
- newRect = h.computeFreeRect(drag, latestX, latestY);
161
- newRect = h.snapCropRect?.(newRect, drag.handle) ?? newRect;
162
- }
163
- h.onCropChange(newRect);
164
- });
165
- };
166
- let ended = false;
167
- const endResize = (notifyResizeEnd = true, restoreFocus = true) => {
168
- if (ended) {
169
- return;
170
- }
171
- ended = true;
172
- if (rafId) {
173
- cancelAnimationFrame(rafId);
174
- rafId = 0;
175
- }
176
- el.removeEventListener("pointermove", onMove);
177
- el.removeEventListener("pointerup", onEnd);
178
- el.removeEventListener("lostpointercapture", onEnd);
179
- activePointerResizeRef.current = null;
180
- if (notifyResizeEnd) {
181
- latestHandlersRef.current?.onResizeEnd?.();
182
- }
183
- if (restoreFocus) {
184
- el.focus({ preventScroll: true });
185
- }
186
- };
187
- const cancelResize = (notifyResizeEnd = true) => endResize(notifyResizeEnd, false);
188
- const onEnd = () => endResize();
189
- el.addEventListener("pointermove", onMove);
190
- el.addEventListener("pointerup", onEnd);
191
- el.addEventListener("lostpointercapture", onEnd);
192
- activePointerResizeRef.current = { cancel: cancelResize };
193
- onResizeStart?.(handle);
194
- clearTimeout(keyboardSettleTimerRef.current);
195
- keyboardResizeActiveRef.current = false;
196
- },
197
- [cropRect, isResizeDisabled, onResizeStart]
198
- );
199
- const computeFreeRect = useCallback(
200
- (drag, clientX, clientY) => computeFreeResizeRect(
201
- drag,
202
- clientX,
203
- clientY,
204
- imageSize,
205
- bounds,
206
- minCropSize
207
- ),
208
- [imageSize, bounds, minCropSize]
209
- );
210
- const computeLockedRect = useCallback(
211
- (drag, clientX, clientY, driverAxis) => computeLockedResizeRect(
212
- drag,
213
- clientX,
214
- clientY,
215
- imageSize,
216
- bounds,
217
- normalizedRatio,
218
- minCropSize,
219
- driverAxis
220
- ),
221
- [imageSize, bounds, normalizedRatio, minCropSize]
222
- );
223
- const computeShiftLockedRect = useCallback(
224
- (drag, clientX, clientY) => computeShiftLockedResizeRect(
225
- drag,
226
- clientX,
227
- clientY,
228
- imageSize,
229
- bounds,
230
- minCropSize
231
- ),
232
- [imageSize, bounds, minCropSize]
233
- );
234
- latestHandlersRef.current = {
235
- hasLockedRatio,
236
- computeLockedRect,
237
- computeFreeRect,
238
- computeShiftLockedRect,
239
- onCropChange,
240
- onResizeEnd,
241
- snapCropRect
242
- };
243
- useEffect(() => {
244
- if (!isResizeDisabled) {
245
- return;
246
- }
247
- activePointerResizeRef.current?.cancel();
248
- if (keyboardResizeActiveRef.current) {
249
- clearTimeout(keyboardSettleTimerRef.current);
250
- keyboardResizeActiveRef.current = false;
251
- latestHandlersRef.current?.onResizeEnd?.();
252
- }
253
- }, [isResizeDisabled]);
254
- const handleKeyDown = useCallback(
255
- (handle, event) => {
256
- const key = event.key;
257
- if (isResizeDisabled) {
258
- return;
259
- }
260
- if (key === "Escape") {
261
- event.preventDefault();
262
- event.stopPropagation();
263
- onEscape?.();
264
- return;
265
- }
266
- if (key !== "ArrowUp" && key !== "ArrowDown" && key !== "ArrowLeft" && key !== "ArrowRight") {
267
- return;
268
- }
269
- event.preventDefault();
270
- event.stopPropagation();
271
- if (!keyboardResizeActiveRef.current) {
272
- keyboardResizeActiveRef.current = true;
273
- onResizeStart?.(handle);
274
- }
275
- const scheduleKeyboardResizeEnd = () => {
276
- clearTimeout(keyboardSettleTimerRef.current);
277
- keyboardSettleTimerRef.current = setTimeout(() => {
278
- keyboardResizeActiveRef.current = false;
279
- onResizeEnd?.();
280
- }, KEYBOARD_SETTLE_DELAY);
281
- };
282
- const stepMultiplier = event.shiftKey ? KEYBOARD_SHIFT_STEP_MULTIPLIER : 1;
283
- const stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;
284
- const stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;
285
- const adjustedStepX = stepX * stepMultiplier;
286
- const adjustedStepY = stepY * stepMultiplier;
287
- let dx = 0;
288
- let dy = 0;
289
- if (key === "ArrowLeft") {
290
- dx = -adjustedStepX;
291
- }
292
- if (key === "ArrowRight") {
293
- dx = adjustedStepX;
294
- }
295
- if (key === "ArrowUp") {
296
- dy = -adjustedStepY;
297
- }
298
- if (key === "ArrowDown") {
299
- dy = adjustedStepY;
300
- }
301
- const keyboardDriverAxis = dx !== 0 ? "width" : "height";
302
- if (hasLockedRatio) {
303
- const syntheticDrag = {
304
- handle,
305
- startX: 0,
306
- startY: 0,
307
- startRect: { ...cropRect }
308
- };
309
- const clientX = dx * imageSize.width;
310
- const clientY = dy * imageSize.height;
311
- onCropChange(
312
- computeLockedRect(
313
- syntheticDrag,
314
- clientX,
315
- clientY,
316
- keyboardDriverAxis
317
- )
318
- );
319
- scheduleKeyboardResizeEnd();
320
- } else {
321
- const syntheticDrag = {
322
- handle,
323
- startX: 0,
324
- startY: 0,
325
- startRect: { ...cropRect }
326
- };
327
- const clientX = dx * imageSize.width;
328
- const clientY = dy * imageSize.height;
329
- const rect = computeFreeRect(syntheticDrag, clientX, clientY);
330
- onCropChange(snapCropRect?.(rect, handle) ?? rect);
331
- scheduleKeyboardResizeEnd();
332
- }
333
- },
334
- [
335
- cropRect,
336
- hasLockedRatio,
337
- imageSize.width,
338
- imageSize.height,
339
- computeLockedRect,
340
- computeFreeRect,
341
- onCropChange,
342
- onResizeStart,
343
- onResizeEnd,
344
- onEscape,
345
- keyboardResizeStep,
346
- snapCropRect,
347
- isResizeDisabled
348
- ]
349
- );
350
- if (containerSize.width === 0 || containerSize.height === 0) {
351
- return null;
352
- }
353
- const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
354
- return /* @__PURE__ */ jsxs(
355
- "div",
356
- {
357
- className: "wp-media-editor-image-editor__stencil",
358
- "data-testid": "cropper-stencil",
359
- style: {
360
- left,
361
- top,
362
- width,
363
- height,
364
- transition: stencilTransition
365
- },
366
- children: [
367
- freeformCrop && /* @__PURE__ */ jsx(
368
- "div",
369
- {
370
- id: resizeHandleDescriptionId,
371
- style: VISUALLY_HIDDEN_STYLE,
372
- children: __(
373
- "Use arrow keys to resize the crop area. Hold Shift for larger steps."
374
- )
375
- }
376
- ),
377
- /* @__PURE__ */ jsx(
378
- "div",
379
- {
380
- className: "wp-media-editor-image-editor__stencil-rect",
381
- style: {
382
- width: "100%",
383
- height: "100%",
384
- top: 0,
385
- left: 0
386
- }
387
- }
388
- ),
389
- freeformCrop && handles.map((pos) => /* @__PURE__ */ jsx(
390
- "button",
391
- {
392
- type: "button",
393
- className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
394
- onPointerDown: (event) => handlePointerDown(pos, event),
395
- onTouchStart: (event) => {
396
- if (event.touches.length < 2) {
397
- event.stopPropagation();
398
- }
399
- },
400
- onKeyDown: (event) => handleKeyDown(pos, event),
401
- disabled: isResizeDisabled,
402
- "aria-label": getHandleLabel(pos),
403
- "aria-describedby": resizeHandleDescriptionId
404
- },
405
- pos
406
- ))
407
- ]
408
- }
409
- );
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
+ });
410
359
  }
411
- export {
412
- RectangleStencil
413
- };
414
- //# sourceMappingURL=rectangle-stencil.mjs.map
360
+ export { RectangleStencil };
361
+
362
+ //# sourceMappingURL=rectangle-stencil.mjs.map