@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,426 +1,367 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
21
- var rectangle_stencil_exports = {};
22
- __export(rectangle_stencil_exports, {
23
- RectangleStencil: () => RectangleStencil
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(rectangle_stencil_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_i18n = require("@wordpress/i18n");
28
- var import_constants = require("../../../core/constants.cjs");
29
- var import_stencil_math = require("../../../core/stencil-math.cjs");
30
- var import_visually_hidden_style = require("../../visually-hidden-style.cjs");
31
- var import_jsx_runtime = require("react/jsx-runtime");
32
- var CORNER_POSITIONS = ["nw", "ne", "se", "sw"];
33
- var ALL_POSITIONS = [
34
- "nw",
35
- "n",
36
- "ne",
37
- "e",
38
- "se",
39
- "s",
40
- "sw",
41
- "w"
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let _wordpress_i18n = require("@wordpress/i18n");
8
+ let _________core_constants_ts = require("../../../core/constants.cjs");
9
+ let _________core_stencil_math_ts = require("../../../core/stencil-math.cjs");
10
+ let ______visually_hidden_style_ts = require("../../visually-hidden-style.cjs");
11
+ let react_jsx_runtime = require("react/jsx-runtime");
12
+ // packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
13
+ /**
14
+ * Corner handle positions only — used when aspect ratio is locked.
15
+ * Ordered clockwise from top-left for logical tab order.
16
+ */
17
+ const CORNER_POSITIONS = [
18
+ "nw",
19
+ "ne",
20
+ "se",
21
+ "sw"
42
22
  ];
23
+ /**
24
+ * All handle positions rendered by the stencil.
25
+ * Ordered clockwise from top-left for logical tab order.
26
+ */
27
+ const ALL_POSITIONS = [
28
+ "nw",
29
+ "n",
30
+ "ne",
31
+ "e",
32
+ "se",
33
+ "s",
34
+ "sw",
35
+ "w"
36
+ ];
37
+ /**
38
+ * Get the translated aria-label for a resize handle position.
39
+ *
40
+ * @param pos The handle position identifier.
41
+ * @return The translated label string.
42
+ */
43
43
  function getHandleLabel(pos) {
44
- switch (pos) {
45
- case "n":
46
- return (0, import_i18n.__)("Resize from top edge");
47
- case "s":
48
- return (0, import_i18n.__)("Resize from bottom edge");
49
- case "e":
50
- return (0, import_i18n.__)("Resize from right edge");
51
- case "w":
52
- return (0, import_i18n.__)("Resize from left edge");
53
- case "nw":
54
- return (0, import_i18n.__)("Resize from top-left corner");
55
- case "ne":
56
- return (0, import_i18n.__)("Resize from top-right corner");
57
- case "sw":
58
- return (0, import_i18n.__)("Resize from bottom-left corner");
59
- case "se":
60
- return (0, import_i18n.__)("Resize from bottom-right corner");
61
- }
44
+ switch (pos) {
45
+ case "n": return (0, _wordpress_i18n.__)("Resize from top edge");
46
+ case "s": return (0, _wordpress_i18n.__)("Resize from bottom edge");
47
+ case "e": return (0, _wordpress_i18n.__)("Resize from right edge");
48
+ case "w": return (0, _wordpress_i18n.__)("Resize from left edge");
49
+ case "nw": return (0, _wordpress_i18n.__)("Resize from top-left corner");
50
+ case "ne": return (0, _wordpress_i18n.__)("Resize from top-right corner");
51
+ case "sw": return (0, _wordpress_i18n.__)("Resize from bottom-left corner");
52
+ case "se": return (0, _wordpress_i18n.__)("Resize from bottom-right corner");
53
+ }
62
54
  }
63
- var KEYBOARD_SETTLE_DELAY = 500;
64
- function RectangleStencil({
65
- cropRect,
66
- containerSize,
67
- imageSize,
68
- onCropChange,
69
- onResizeStart,
70
- onResizeEnd,
71
- aspectRatio,
72
- freeformCrop = false,
73
- isResizeDisabled = false,
74
- stencilTransition,
75
- cropBounds,
76
- onEscape,
77
- minCropSize,
78
- snapCropRect,
79
- keyboardResizeStep
80
- }) {
81
- const boundsMinX = cropBounds?.minX ?? 0;
82
- const boundsMinY = cropBounds?.minY ?? 0;
83
- const boundsMaxX = cropBounds?.maxX ?? 1;
84
- const boundsMaxY = cropBounds?.maxY ?? 1;
85
- const bounds = (0, import_element.useMemo)(
86
- () => ({
87
- minX: boundsMinX,
88
- minY: boundsMinY,
89
- maxX: boundsMaxX,
90
- maxY: boundsMaxY
91
- }),
92
- [boundsMinX, boundsMinY, boundsMaxX, boundsMaxY]
93
- );
94
- const keyboardSettleTimerRef = (0, import_element.useRef)(void 0);
95
- const keyboardResizeActiveRef = (0, import_element.useRef)(false);
96
- const resizeHandleDescriptionId = (0, import_element.useId)();
97
- const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
98
- const activePointerResizeRef = (0, import_element.useRef)(null);
99
- (0, import_element.useEffect)(() => {
100
- return () => {
101
- clearTimeout(keyboardSettleTimerRef.current);
102
- keyboardResizeActiveRef.current = false;
103
- activePointerResizeRef.current?.cancel(false);
104
- };
105
- }, []);
106
- const latestHandlersRef = (0, import_element.useRef)(null);
107
- const normalizedRatio = (0, import_element.useMemo)(() => {
108
- if (!hasLockedRatio || imageSize.width === 0) {
109
- return 0;
110
- }
111
- return aspectRatio * imageSize.height / imageSize.width;
112
- }, [aspectRatio, hasLockedRatio, imageSize.width, imageSize.height]);
113
- const offsetX = (containerSize.width - imageSize.width) / 2;
114
- const offsetY = (containerSize.height - imageSize.height) / 2;
115
- const left = offsetX + cropRect.x * imageSize.width;
116
- const top = offsetY + cropRect.y * imageSize.height;
117
- const width = cropRect.width * imageSize.width;
118
- const height = cropRect.height * imageSize.height;
119
- const handlePointerDown = (0, import_element.useCallback)(
120
- (handle, event) => {
121
- if (isResizeDisabled || event.pointerType === "touch" && event.isPrimary === false) {
122
- event.preventDefault();
123
- event.stopPropagation();
124
- return;
125
- }
126
- if (event.button !== 0) {
127
- return;
128
- }
129
- event.preventDefault();
130
- event.stopPropagation();
131
- const ownerDoc = event.currentTarget.ownerDocument;
132
- if (ownerDoc.activeElement instanceof HTMLElement) {
133
- ownerDoc.activeElement.blur();
134
- }
135
- const el = event.currentTarget;
136
- el.setPointerCapture(event.pointerId);
137
- const drag = {
138
- handle,
139
- startX: event.clientX,
140
- startY: event.clientY,
141
- startRect: { ...cropRect }
142
- };
143
- let rafId = 0;
144
- let latestX = event.clientX;
145
- let latestY = event.clientY;
146
- let latestShift = event.shiftKey;
147
- const onMove = (e) => {
148
- const pe = e;
149
- latestX = pe.clientX;
150
- latestY = pe.clientY;
151
- latestShift = pe.shiftKey;
152
- if (rafId) {
153
- return;
154
- }
155
- rafId = requestAnimationFrame(() => {
156
- rafId = 0;
157
- const h = latestHandlersRef.current;
158
- if (!h) {
159
- return;
160
- }
161
- let newRect;
162
- if (h.hasLockedRatio) {
163
- newRect = h.computeLockedRect(drag, latestX, latestY);
164
- } else if (latestShift) {
165
- newRect = h.computeShiftLockedRect(
166
- drag,
167
- latestX,
168
- latestY
169
- );
170
- } else {
171
- newRect = h.computeFreeRect(drag, latestX, latestY);
172
- newRect = h.snapCropRect?.(newRect, drag.handle) ?? newRect;
173
- }
174
- h.onCropChange(newRect);
175
- });
176
- };
177
- let ended = false;
178
- const endResize = (notifyResizeEnd = true, restoreFocus = true) => {
179
- if (ended) {
180
- return;
181
- }
182
- ended = true;
183
- if (rafId) {
184
- cancelAnimationFrame(rafId);
185
- rafId = 0;
186
- }
187
- el.removeEventListener("pointermove", onMove);
188
- el.removeEventListener("pointerup", onEnd);
189
- el.removeEventListener("lostpointercapture", onEnd);
190
- activePointerResizeRef.current = null;
191
- if (notifyResizeEnd) {
192
- latestHandlersRef.current?.onResizeEnd?.();
193
- }
194
- if (restoreFocus) {
195
- el.focus({ preventScroll: true });
196
- }
197
- };
198
- const cancelResize = (notifyResizeEnd = true) => endResize(notifyResizeEnd, false);
199
- const onEnd = () => endResize();
200
- el.addEventListener("pointermove", onMove);
201
- el.addEventListener("pointerup", onEnd);
202
- el.addEventListener("lostpointercapture", onEnd);
203
- activePointerResizeRef.current = { cancel: cancelResize };
204
- onResizeStart?.(handle);
205
- clearTimeout(keyboardSettleTimerRef.current);
206
- keyboardResizeActiveRef.current = false;
207
- },
208
- [cropRect, isResizeDisabled, onResizeStart]
209
- );
210
- const computeFreeRect = (0, import_element.useCallback)(
211
- (drag, clientX, clientY) => (0, import_stencil_math.computeFreeResizeRect)(
212
- drag,
213
- clientX,
214
- clientY,
215
- imageSize,
216
- bounds,
217
- minCropSize
218
- ),
219
- [imageSize, bounds, minCropSize]
220
- );
221
- const computeLockedRect = (0, import_element.useCallback)(
222
- (drag, clientX, clientY, driverAxis) => (0, import_stencil_math.computeLockedResizeRect)(
223
- drag,
224
- clientX,
225
- clientY,
226
- imageSize,
227
- bounds,
228
- normalizedRatio,
229
- minCropSize,
230
- driverAxis
231
- ),
232
- [imageSize, bounds, normalizedRatio, minCropSize]
233
- );
234
- const computeShiftLockedRect = (0, import_element.useCallback)(
235
- (drag, clientX, clientY) => (0, import_stencil_math.computeShiftLockedResizeRect)(
236
- drag,
237
- clientX,
238
- clientY,
239
- imageSize,
240
- bounds,
241
- minCropSize
242
- ),
243
- [imageSize, bounds, minCropSize]
244
- );
245
- latestHandlersRef.current = {
246
- hasLockedRatio,
247
- computeLockedRect,
248
- computeFreeRect,
249
- computeShiftLockedRect,
250
- onCropChange,
251
- onResizeEnd,
252
- snapCropRect
253
- };
254
- (0, import_element.useEffect)(() => {
255
- if (!isResizeDisabled) {
256
- return;
257
- }
258
- activePointerResizeRef.current?.cancel();
259
- if (keyboardResizeActiveRef.current) {
260
- clearTimeout(keyboardSettleTimerRef.current);
261
- keyboardResizeActiveRef.current = false;
262
- latestHandlersRef.current?.onResizeEnd?.();
263
- }
264
- }, [isResizeDisabled]);
265
- const handleKeyDown = (0, import_element.useCallback)(
266
- (handle, event) => {
267
- const key = event.key;
268
- if (isResizeDisabled) {
269
- return;
270
- }
271
- if (key === "Escape") {
272
- event.preventDefault();
273
- event.stopPropagation();
274
- onEscape?.();
275
- return;
276
- }
277
- if (key !== "ArrowUp" && key !== "ArrowDown" && key !== "ArrowLeft" && key !== "ArrowRight") {
278
- return;
279
- }
280
- event.preventDefault();
281
- event.stopPropagation();
282
- if (!keyboardResizeActiveRef.current) {
283
- keyboardResizeActiveRef.current = true;
284
- onResizeStart?.(handle);
285
- }
286
- const scheduleKeyboardResizeEnd = () => {
287
- clearTimeout(keyboardSettleTimerRef.current);
288
- keyboardSettleTimerRef.current = setTimeout(() => {
289
- keyboardResizeActiveRef.current = false;
290
- onResizeEnd?.();
291
- }, KEYBOARD_SETTLE_DELAY);
292
- };
293
- const stepMultiplier = event.shiftKey ? import_constants.KEYBOARD_SHIFT_STEP_MULTIPLIER : 1;
294
- const stepX = keyboardResizeStep?.width ?? import_constants.DEFAULT_KEYBOARD_STEP;
295
- const stepY = keyboardResizeStep?.height ?? import_constants.DEFAULT_KEYBOARD_STEP;
296
- const adjustedStepX = stepX * stepMultiplier;
297
- const adjustedStepY = stepY * stepMultiplier;
298
- let dx = 0;
299
- let dy = 0;
300
- if (key === "ArrowLeft") {
301
- dx = -adjustedStepX;
302
- }
303
- if (key === "ArrowRight") {
304
- dx = adjustedStepX;
305
- }
306
- if (key === "ArrowUp") {
307
- dy = -adjustedStepY;
308
- }
309
- if (key === "ArrowDown") {
310
- dy = adjustedStepY;
311
- }
312
- const keyboardDriverAxis = dx !== 0 ? "width" : "height";
313
- if (hasLockedRatio) {
314
- const syntheticDrag = {
315
- handle,
316
- startX: 0,
317
- startY: 0,
318
- startRect: { ...cropRect }
319
- };
320
- const clientX = dx * imageSize.width;
321
- const clientY = dy * imageSize.height;
322
- onCropChange(
323
- computeLockedRect(
324
- syntheticDrag,
325
- clientX,
326
- clientY,
327
- keyboardDriverAxis
328
- )
329
- );
330
- scheduleKeyboardResizeEnd();
331
- } else {
332
- const syntheticDrag = {
333
- handle,
334
- startX: 0,
335
- startY: 0,
336
- startRect: { ...cropRect }
337
- };
338
- const clientX = dx * imageSize.width;
339
- const clientY = dy * imageSize.height;
340
- const rect = computeFreeRect(syntheticDrag, clientX, clientY);
341
- onCropChange(snapCropRect?.(rect, handle) ?? rect);
342
- scheduleKeyboardResizeEnd();
343
- }
344
- },
345
- [
346
- cropRect,
347
- hasLockedRatio,
348
- imageSize.width,
349
- imageSize.height,
350
- computeLockedRect,
351
- computeFreeRect,
352
- onCropChange,
353
- onResizeStart,
354
- onResizeEnd,
355
- onEscape,
356
- keyboardResizeStep,
357
- snapCropRect,
358
- isResizeDisabled
359
- ]
360
- );
361
- if (containerSize.width === 0 || containerSize.height === 0) {
362
- return null;
363
- }
364
- const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
365
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
366
- "div",
367
- {
368
- className: "wp-media-editor-image-editor__stencil",
369
- "data-testid": "cropper-stencil",
370
- style: {
371
- left,
372
- top,
373
- width,
374
- height,
375
- transition: stencilTransition
376
- },
377
- children: [
378
- freeformCrop && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
379
- "div",
380
- {
381
- id: resizeHandleDescriptionId,
382
- style: import_visually_hidden_style.VISUALLY_HIDDEN_STYLE,
383
- children: (0, import_i18n.__)(
384
- "Use arrow keys to resize the crop area. Hold Shift for larger steps."
385
- )
386
- }
387
- ),
388
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
389
- "div",
390
- {
391
- className: "wp-media-editor-image-editor__stencil-rect",
392
- style: {
393
- width: "100%",
394
- height: "100%",
395
- top: 0,
396
- left: 0
397
- }
398
- }
399
- ),
400
- freeformCrop && handles.map((pos) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
401
- "button",
402
- {
403
- type: "button",
404
- className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
405
- onPointerDown: (event) => handlePointerDown(pos, event),
406
- onTouchStart: (event) => {
407
- if (event.touches.length < 2) {
408
- event.stopPropagation();
409
- }
410
- },
411
- onKeyDown: (event) => handleKeyDown(pos, event),
412
- disabled: isResizeDisabled,
413
- "aria-label": getHandleLabel(pos),
414
- "aria-describedby": resizeHandleDescriptionId
415
- },
416
- pos
417
- ))
418
- ]
419
- }
420
- );
55
+ /** Delay before keyboard resize triggers settle (ms). */
56
+ const KEYBOARD_SETTLE_DELAY = 500;
57
+ /**
58
+ * A rectangular crop stencil with resize handles.
59
+ *
60
+ * In freeform mode, handles resize the crop area. Clicks inside the
61
+ * crop pass through to the container for image panning. The crop
62
+ * auto-centers after resize via SETTLE_CROP.
63
+ *
64
+ * @param props Component props implementing StencilProps.
65
+ * @param props.cropRect The crop rectangle in normalized coordinates.
66
+ * @param props.containerSize The container element dimensions in pixels.
67
+ * @param props.imageSize The rendered image dimensions in pixels.
68
+ * @param props.onCropChange Callback fired when the crop rect changes.
69
+ * @param props.onResizeStart Callback fired when a resize drag starts.
70
+ * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).
71
+ * @param props.aspectRatio Optional fixed aspect ratio (width / height).
72
+ * @param props.freeformCrop Whether resize handles are shown.
73
+ * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.
74
+ * @param props.stencilTransition CSS transition string for settle animation.
75
+ * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).
76
+ * @param props.onEscape Called when Escape is pressed on a resize handle.
77
+ * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.
78
+ * @param props.snapCropRect Optional post-processor for freeform resize output.
79
+ * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.
80
+ * @return The rectangle stencil element.
81
+ */
82
+ function RectangleStencil({ cropRect, containerSize, imageSize, onCropChange, onResizeStart, onResizeEnd, aspectRatio, freeformCrop = false, isResizeDisabled = false, stencilTransition, cropBounds, onEscape, minCropSize, snapCropRect, keyboardResizeStep }) {
83
+ const boundsMinX = cropBounds?.minX ?? 0;
84
+ const boundsMinY = cropBounds?.minY ?? 0;
85
+ const boundsMaxX = cropBounds?.maxX ?? 1;
86
+ const boundsMaxY = cropBounds?.maxY ?? 1;
87
+ const bounds = (0, _wordpress_element.useMemo)(() => ({
88
+ minX: boundsMinX,
89
+ minY: boundsMinY,
90
+ maxX: boundsMaxX,
91
+ maxY: boundsMaxY
92
+ }), [
93
+ boundsMinX,
94
+ boundsMinY,
95
+ boundsMaxX,
96
+ boundsMaxY
97
+ ]);
98
+ const keyboardSettleTimerRef = (0, _wordpress_element.useRef)(void 0);
99
+ const keyboardResizeActiveRef = (0, _wordpress_element.useRef)(false);
100
+ const resizeHandleDescriptionId = (0, _wordpress_element.useId)();
101
+ const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
102
+ const activePointerResizeRef = (0, _wordpress_element.useRef)(null);
103
+ (0, _wordpress_element.useEffect)(() => {
104
+ return () => {
105
+ clearTimeout(keyboardSettleTimerRef.current);
106
+ keyboardResizeActiveRef.current = false;
107
+ activePointerResizeRef.current?.cancel(false);
108
+ };
109
+ }, []);
110
+ const latestHandlersRef = (0, _wordpress_element.useRef)(null);
111
+ const normalizedRatio = (0, _wordpress_element.useMemo)(() => {
112
+ if (!hasLockedRatio || imageSize.width === 0) return 0;
113
+ return aspectRatio * imageSize.height / imageSize.width;
114
+ }, [
115
+ aspectRatio,
116
+ hasLockedRatio,
117
+ imageSize.width,
118
+ imageSize.height
119
+ ]);
120
+ const offsetX = (containerSize.width - imageSize.width) / 2;
121
+ const offsetY = (containerSize.height - imageSize.height) / 2;
122
+ const left = offsetX + cropRect.x * imageSize.width;
123
+ const top = offsetY + cropRect.y * imageSize.height;
124
+ const width = cropRect.width * imageSize.width;
125
+ const height = cropRect.height * imageSize.height;
126
+ /**
127
+ * Start a resize drag on a handle. Registers pointer listeners
128
+ * synchronously so no events are missed between capture and the
129
+ * next React commit.
130
+ */
131
+ const handlePointerDown = (0, _wordpress_element.useCallback)((handle, event) => {
132
+ if (isResizeDisabled || event.pointerType === "touch" && event.isPrimary === false) {
133
+ event.preventDefault();
134
+ event.stopPropagation();
135
+ return;
136
+ }
137
+ if (event.button !== 0) return;
138
+ event.preventDefault();
139
+ event.stopPropagation();
140
+ const ownerDoc = event.currentTarget.ownerDocument;
141
+ if (ownerDoc.activeElement instanceof HTMLElement) ownerDoc.activeElement.blur();
142
+ const el = event.currentTarget;
143
+ el.setPointerCapture(event.pointerId);
144
+ const drag = {
145
+ handle,
146
+ startX: event.clientX,
147
+ startY: event.clientY,
148
+ startRect: { ...cropRect }
149
+ };
150
+ let rafId = 0;
151
+ let latestX = event.clientX;
152
+ let latestY = event.clientY;
153
+ let latestShift = event.shiftKey;
154
+ const onMove = (e) => {
155
+ const pe = e;
156
+ latestX = pe.clientX;
157
+ latestY = pe.clientY;
158
+ latestShift = pe.shiftKey;
159
+ if (rafId) return;
160
+ rafId = requestAnimationFrame(() => {
161
+ rafId = 0;
162
+ const h = latestHandlersRef.current;
163
+ if (!h) return;
164
+ let newRect;
165
+ if (h.hasLockedRatio) newRect = h.computeLockedRect(drag, latestX, latestY);
166
+ else if (latestShift) newRect = h.computeShiftLockedRect(drag, latestX, latestY);
167
+ else {
168
+ newRect = h.computeFreeRect(drag, latestX, latestY);
169
+ newRect = h.snapCropRect?.(newRect, drag.handle) ?? newRect;
170
+ }
171
+ h.onCropChange(newRect);
172
+ });
173
+ };
174
+ let ended = false;
175
+ const endResize = (notifyResizeEnd = true, restoreFocus = true) => {
176
+ if (ended) return;
177
+ ended = true;
178
+ if (rafId) {
179
+ cancelAnimationFrame(rafId);
180
+ rafId = 0;
181
+ }
182
+ el.removeEventListener("pointermove", onMove);
183
+ el.removeEventListener("pointerup", onEnd);
184
+ el.removeEventListener("lostpointercapture", onEnd);
185
+ activePointerResizeRef.current = null;
186
+ if (notifyResizeEnd) latestHandlersRef.current?.onResizeEnd?.();
187
+ if (restoreFocus) el.focus({ preventScroll: true });
188
+ };
189
+ const cancelResize = (notifyResizeEnd = true) => endResize(notifyResizeEnd, false);
190
+ const onEnd = () => endResize();
191
+ el.addEventListener("pointermove", onMove);
192
+ el.addEventListener("pointerup", onEnd);
193
+ el.addEventListener("lostpointercapture", onEnd);
194
+ activePointerResizeRef.current = { cancel: cancelResize };
195
+ onResizeStart?.(handle);
196
+ clearTimeout(keyboardSettleTimerRef.current);
197
+ keyboardResizeActiveRef.current = false;
198
+ }, [
199
+ cropRect,
200
+ isResizeDisabled,
201
+ onResizeStart
202
+ ]);
203
+ /**
204
+ * Compute the new crop rect for a free (no aspect ratio) resize.
205
+ * Delegates to the pure function in core/stencil-math.ts.
206
+ */
207
+ const computeFreeRect = (0, _wordpress_element.useCallback)((drag, clientX, clientY) => (0, _________core_stencil_math_ts.computeFreeResizeRect)(drag, clientX, clientY, imageSize, bounds, minCropSize), [
208
+ imageSize,
209
+ bounds,
210
+ minCropSize
211
+ ]);
212
+ /**
213
+ * Compute the new crop rect for a locked-aspect-ratio corner resize.
214
+ * Delegates to the pure function in core/stencil-math.ts.
215
+ */
216
+ const computeLockedRect = (0, _wordpress_element.useCallback)((drag, clientX, clientY, driverAxis) => (0, _________core_stencil_math_ts.computeLockedResizeRect)(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize, driverAxis), [
217
+ imageSize,
218
+ bounds,
219
+ normalizedRatio,
220
+ minCropSize
221
+ ]);
222
+ latestHandlersRef.current = {
223
+ hasLockedRatio,
224
+ computeLockedRect,
225
+ computeFreeRect,
226
+ computeShiftLockedRect: (0, _wordpress_element.useCallback)((drag, clientX, clientY) => (0, _________core_stencil_math_ts.computeShiftLockedResizeRect)(drag, clientX, clientY, imageSize, bounds, minCropSize), [
227
+ imageSize,
228
+ bounds,
229
+ minCropSize
230
+ ]),
231
+ onCropChange,
232
+ onResizeEnd,
233
+ snapCropRect
234
+ };
235
+ (0, _wordpress_element.useEffect)(() => {
236
+ if (!isResizeDisabled) return;
237
+ activePointerResizeRef.current?.cancel();
238
+ if (keyboardResizeActiveRef.current) {
239
+ clearTimeout(keyboardSettleTimerRef.current);
240
+ keyboardResizeActiveRef.current = false;
241
+ latestHandlersRef.current?.onResizeEnd?.();
242
+ }
243
+ }, [isResizeDisabled]);
244
+ /**
245
+ * Handle keyboard events on a resize handle.
246
+ * Arrow keys resize; Escape returns focus to the canvas.
247
+ * Shift multiplies the step size by 10 for coarser movement.
248
+ */
249
+ const handleKeyDown = (0, _wordpress_element.useCallback)((handle, event) => {
250
+ const key = event.key;
251
+ if (isResizeDisabled) return;
252
+ if (key === "Escape") {
253
+ event.preventDefault();
254
+ event.stopPropagation();
255
+ onEscape?.();
256
+ return;
257
+ }
258
+ if (key !== "ArrowUp" && key !== "ArrowDown" && key !== "ArrowLeft" && key !== "ArrowRight") return;
259
+ event.preventDefault();
260
+ event.stopPropagation();
261
+ if (!keyboardResizeActiveRef.current) {
262
+ keyboardResizeActiveRef.current = true;
263
+ onResizeStart?.(handle);
264
+ }
265
+ const scheduleKeyboardResizeEnd = () => {
266
+ clearTimeout(keyboardSettleTimerRef.current);
267
+ keyboardSettleTimerRef.current = setTimeout(() => {
268
+ keyboardResizeActiveRef.current = false;
269
+ onResizeEnd?.();
270
+ }, KEYBOARD_SETTLE_DELAY);
271
+ };
272
+ const stepMultiplier = event.shiftKey ? _________core_constants_ts.KEYBOARD_SHIFT_STEP_MULTIPLIER : 1;
273
+ const stepX = keyboardResizeStep?.width ?? _________core_constants_ts.DEFAULT_KEYBOARD_STEP;
274
+ const stepY = keyboardResizeStep?.height ?? _________core_constants_ts.DEFAULT_KEYBOARD_STEP;
275
+ const adjustedStepX = stepX * stepMultiplier;
276
+ const adjustedStepY = stepY * stepMultiplier;
277
+ let dx = 0;
278
+ let dy = 0;
279
+ if (key === "ArrowLeft") dx = -adjustedStepX;
280
+ if (key === "ArrowRight") dx = adjustedStepX;
281
+ if (key === "ArrowUp") dy = -adjustedStepY;
282
+ if (key === "ArrowDown") dy = adjustedStepY;
283
+ const keyboardDriverAxis = dx !== 0 ? "width" : "height";
284
+ if (hasLockedRatio) {
285
+ const syntheticDrag = {
286
+ handle,
287
+ startX: 0,
288
+ startY: 0,
289
+ startRect: { ...cropRect }
290
+ };
291
+ const clientX = dx * imageSize.width;
292
+ const clientY = dy * imageSize.height;
293
+ onCropChange(computeLockedRect(syntheticDrag, clientX, clientY, keyboardDriverAxis));
294
+ scheduleKeyboardResizeEnd();
295
+ } else {
296
+ const syntheticDrag = {
297
+ handle,
298
+ startX: 0,
299
+ startY: 0,
300
+ startRect: { ...cropRect }
301
+ };
302
+ const clientX = dx * imageSize.width;
303
+ const clientY = dy * imageSize.height;
304
+ const rect = computeFreeRect(syntheticDrag, clientX, clientY);
305
+ onCropChange(snapCropRect?.(rect, handle) ?? rect);
306
+ scheduleKeyboardResizeEnd();
307
+ }
308
+ }, [
309
+ cropRect,
310
+ hasLockedRatio,
311
+ imageSize.width,
312
+ imageSize.height,
313
+ computeLockedRect,
314
+ computeFreeRect,
315
+ onCropChange,
316
+ onResizeStart,
317
+ onResizeEnd,
318
+ onEscape,
319
+ keyboardResizeStep,
320
+ snapCropRect,
321
+ isResizeDisabled
322
+ ]);
323
+ if (containerSize.width === 0 || containerSize.height === 0) return null;
324
+ const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
325
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
326
+ className: "wp-media-editor-image-editor__stencil",
327
+ "data-testid": "cropper-stencil",
328
+ style: {
329
+ left,
330
+ top,
331
+ width,
332
+ height,
333
+ transition: stencilTransition
334
+ },
335
+ children: [
336
+ freeformCrop && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
337
+ id: resizeHandleDescriptionId,
338
+ style: ______visually_hidden_style_ts.VISUALLY_HIDDEN_STYLE,
339
+ children: (0, _wordpress_i18n.__)("Use arrow keys to resize the crop area. Hold Shift for larger steps.")
340
+ }),
341
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
342
+ className: "wp-media-editor-image-editor__stencil-rect",
343
+ style: {
344
+ width: "100%",
345
+ height: "100%",
346
+ top: 0,
347
+ left: 0
348
+ }
349
+ }),
350
+ freeformCrop && handles.map((pos) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
351
+ type: "button",
352
+ className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
353
+ onPointerDown: (event) => handlePointerDown(pos, event),
354
+ onTouchStart: (event) => {
355
+ if (event.touches.length < 2) event.stopPropagation();
356
+ },
357
+ onKeyDown: (event) => handleKeyDown(pos, event),
358
+ disabled: isResizeDisabled,
359
+ "aria-label": getHandleLabel(pos),
360
+ "aria-describedby": resizeHandleDescriptionId
361
+ }, pos))
362
+ ]
363
+ });
421
364
  }
422
- // Annotate the CommonJS export names for ESM import in node:
423
- 0 && (module.exports = {
424
- RectangleStencil
425
- });
426
- //# sourceMappingURL=rectangle-stencil.cjs.map
365
+ exports.RectangleStencil = RectangleStencil;
366
+
367
+ //# sourceMappingURL=rectangle-stencil.cjs.map