@wordpress/media-editor 0.21.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 (339) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/components/media-editor/index.cjs +533 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +43 -57
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  6. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +122 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +65 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +183 -257
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  19. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  20. package/build/components/media-editor-modal/index.cjs +112 -155
  21. package/build/components/media-editor-modal/index.cjs.map +1 -7
  22. package/build/components/media-editor-provider/index.cjs +32 -55
  23. package/build/components/media-editor-provider/index.cjs.map +1 -7
  24. package/build/components/media-form/index.cjs +76 -77
  25. package/build/components/media-form/index.cjs.map +1 -7
  26. package/build/components/media-preview/index.cjs +114 -114
  27. package/build/components/media-preview/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/index.cjs +181 -188
  29. package/build/components/rotation-ruler/index.cjs.map +1 -7
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  32. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  33. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  34. package/build/image-editor/core/camera.cjs +257 -205
  35. package/build/image-editor/core/camera.cjs.map +1 -7
  36. package/build/image-editor/core/constants.cjs +127 -102
  37. package/build/image-editor/core/constants.cjs.map +1 -7
  38. package/build/image-editor/core/containment.cjs +275 -262
  39. package/build/image-editor/core/containment.cjs.map +1 -7
  40. package/build/image-editor/core/crop-rect.cjs +33 -44
  41. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  42. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  43. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  44. package/build/image-editor/core/index.cjs +88 -61
  45. package/build/image-editor/core/interaction-controller.cjs +583 -646
  46. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  47. package/build/image-editor/core/math/rotation.cjs +26 -35
  48. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  49. package/build/image-editor/core/math/sanitize.cjs +124 -80
  50. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  51. package/build/image-editor/core/setter-helpers.cjs +57 -60
  52. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  53. package/build/image-editor/core/source-region.cjs +220 -190
  54. package/build/image-editor/core/source-region.cjs.map +1 -7
  55. package/build/image-editor/core/state.cjs +278 -265
  56. package/build/image-editor/core/state.cjs.map +1 -7
  57. package/build/image-editor/core/stencil-math.cjs +193 -206
  58. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  59. package/build/image-editor/core/transform-style.cjs +39 -48
  60. package/build/image-editor/core/transform-style.cjs.map +1 -7
  61. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  62. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  63. package/build/image-editor/core/types.cjs +4 -18
  64. package/build/image-editor/core/viewport-state.cjs +31 -45
  65. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  66. package/build/image-editor/index.cjs +65 -64
  67. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  68. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  69. package/build/image-editor/react/components/cropper.cjs +583 -710
  70. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  71. package/build/image-editor/react/components/index.cjs +22 -33
  72. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  74. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  76. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  78. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  80. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  81. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  82. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  84. package/build/image-editor/react/hooks/index.cjs +16 -31
  85. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  87. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  89. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  90. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  91. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  92. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  93. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  95. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  96. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  97. package/build/index.cjs +45 -39
  98. package/build/lock-unlock.cjs +9 -35
  99. package/build/lock-unlock.cjs.map +1 -7
  100. package/build/private-apis.cjs +16 -37
  101. package/build/private-apis.cjs.map +1 -7
  102. package/build/state/aspect-ratio-presets.cjs +53 -0
  103. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  104. package/build/state/composite-reducer.cjs +134 -112
  105. package/build/state/composite-reducer.cjs.map +1 -7
  106. package/build/state/index.cjs +63 -47
  107. package/build/state/media-editor-state-provider.cjs +35 -48
  108. package/build/state/media-editor-state-provider.cjs.map +1 -7
  109. package/build/state/types.cjs +12 -31
  110. package/build/state/types.cjs.map +1 -7
  111. package/build/state/use-media-editor-state.cjs +261 -294
  112. package/build/state/use-media-editor-state.cjs.map +1 -7
  113. package/build/store/actions.cjs +17 -44
  114. package/build/store/actions.cjs.map +1 -7
  115. package/build/store/constants.cjs +8 -29
  116. package/build/store/constants.cjs.map +1 -7
  117. package/build/store/index.cjs +33 -40
  118. package/build/store/index.cjs.map +1 -7
  119. package/build/store/reducer.cjs +28 -50
  120. package/build/store/reducer.cjs.map +1 -7
  121. package/build/store/selectors.cjs +16 -41
  122. package/build/store/selectors.cjs.map +1 -7
  123. package/build/utils/get-media-type.cjs +18 -41
  124. package/build/utils/get-media-type.cjs.map +1 -7
  125. package/build/utils/index.cjs +9 -28
  126. package/build-module/components/media-editor/index.mjs +490 -673
  127. package/build-module/components/media-editor/index.mjs.map +1 -7
  128. package/build-module/components/media-editor/use-crop-options.mjs +38 -32
  129. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  130. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  131. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  132. package/build-module/components/media-editor-canvas/index.mjs +98 -96
  133. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  134. package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
  135. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  136. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  137. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  138. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  139. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  140. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  142. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  144. package/build-module/components/media-editor-modal/index.mjs +88 -124
  145. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  146. package/build-module/components/media-editor-provider/index.mjs +26 -29
  147. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  148. package/build-module/components/media-form/index.mjs +68 -56
  149. package/build-module/components/media-form/index.mjs.map +1 -7
  150. package/build-module/components/media-preview/index.mjs +106 -90
  151. package/build-module/components/media-preview/index.mjs.map +1 -7
  152. package/build-module/components/rotation-ruler/index.mjs +161 -164
  153. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  154. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  156. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  158. package/build-module/image-editor/core/camera.mjs +245 -178
  159. package/build-module/image-editor/core/camera.mjs.map +1 -7
  160. package/build-module/image-editor/core/constants.mjs +110 -64
  161. package/build-module/image-editor/core/constants.mjs.map +1 -7
  162. package/build-module/image-editor/core/containment.mjs +265 -237
  163. package/build-module/image-editor/core/containment.mjs.map +1 -7
  164. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  165. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  166. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  168. package/build-module/image-editor/core/index.mjs +5 -34
  169. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  170. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  171. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  172. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  173. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  174. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  175. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  176. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  177. package/build-module/image-editor/core/source-region.mjs +210 -160
  178. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  179. package/build-module/image-editor/core/state.mjs +271 -243
  180. package/build-module/image-editor/core/state.mjs.map +1 -7
  181. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  182. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  183. package/build-module/image-editor/core/transform-style.mjs +34 -23
  184. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  185. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  186. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  187. package/build-module/image-editor/core/types.mjs +0 -1
  188. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  189. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  190. package/build-module/image-editor/index.mjs +3 -38
  191. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  192. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  193. package/build-module/image-editor/react/components/cropper.mjs +550 -686
  194. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  195. package/build-module/image-editor/react/components/index.mjs +1 -7
  196. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  198. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  200. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  202. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  204. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  205. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  206. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  208. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  209. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  211. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  213. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  215. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  217. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  219. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  220. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  221. package/build-module/index.mjs +3 -10
  222. package/build-module/lock-unlock.mjs +5 -10
  223. package/build-module/lock-unlock.mjs.map +1 -7
  224. package/build-module/private-apis.mjs +8 -9
  225. package/build-module/private-apis.mjs.map +1 -7
  226. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  227. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  228. package/build-module/state/composite-reducer.mjs +114 -90
  229. package/build-module/state/composite-reducer.mjs.map +1 -7
  230. package/build-module/state/index.mjs +5 -25
  231. package/build-module/state/media-editor-state-provider.mjs +29 -24
  232. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  233. package/build-module/state/types.mjs +8 -7
  234. package/build-module/state/types.mjs.map +1 -7
  235. package/build-module/state/use-media-editor-state.mjs +256 -286
  236. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  237. package/build-module/store/actions.mjs +12 -19
  238. package/build-module/store/actions.mjs.map +1 -7
  239. package/build-module/store/constants.mjs +4 -5
  240. package/build-module/store/constants.mjs.map +1 -7
  241. package/build-module/store/index.mjs +8 -9
  242. package/build-module/store/index.mjs.map +1 -7
  243. package/build-module/store/reducer.mjs +23 -26
  244. package/build-module/store/reducer.mjs.map +1 -7
  245. package/build-module/store/selectors.mjs +8 -13
  246. package/build-module/store/selectors.mjs.map +1 -7
  247. package/build-module/utils/get-media-type.mjs +14 -17
  248. package/build-module/utils/get-media-type.mjs.map +1 -7
  249. package/build-module/utils/index.mjs +1 -6
  250. package/build-style/style-rtl.css +41 -4
  251. package/build-style/style.css +41 -4
  252. package/build-types/components/media-editor/index.d.ts +4 -0
  253. package/build-types/components/media-editor/index.d.ts.map +1 -1
  254. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  256. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  257. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  258. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  259. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  260. package/build-types/components/media-preview/index.d.ts.map +1 -1
  261. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  262. package/build-types/image-editor/core/constants.d.ts +0 -1
  263. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  264. package/build-types/image-editor/core/index.d.ts +1 -1
  265. package/build-types/image-editor/core/index.d.ts.map +1 -1
  266. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  267. package/build-types/image-editor/core/types.d.ts +1 -1
  268. package/build-types/image-editor/index.d.ts +7 -6
  269. package/build-types/image-editor/index.d.ts.map +1 -1
  270. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  271. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  272. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  273. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  274. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  275. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  276. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  277. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  278. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  279. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  280. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  281. package/build-types/state/composite-reducer.d.ts +1 -1
  282. package/build-types/state/composite-reducer.d.ts.map +1 -1
  283. package/build-types/state/index.d.ts +1 -0
  284. package/build-types/state/index.d.ts.map +1 -1
  285. package/build-types/state/types.d.ts +2 -1
  286. package/build-types/state/types.d.ts.map +1 -1
  287. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  288. package/package.json +21 -21
  289. package/src/components/media-editor/index.tsx +215 -162
  290. package/src/components/media-editor/style.scss +19 -0
  291. package/src/components/media-editor/use-crop-options.ts +5 -2
  292. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  293. package/src/components/media-editor-canvas/index.tsx +16 -26
  294. package/src/components/media-editor-image-controls/index.tsx +4 -2
  295. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  296. package/src/components/media-editor-modal/style.scss +1 -1
  297. package/src/components/media-preview/index.tsx +66 -23
  298. package/src/components/media-preview/style.scss +16 -2
  299. package/src/components/rotation-ruler/style.scss +6 -2
  300. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  301. package/src/image-editor/README.md +8 -8
  302. package/src/image-editor/core/constants.ts +0 -13
  303. package/src/image-editor/core/index.ts +1 -5
  304. package/src/image-editor/core/setter-helpers.ts +1 -1
  305. package/src/image-editor/core/types.ts +1 -1
  306. package/src/image-editor/docs/architecture.md +1 -1
  307. package/src/image-editor/docs/recipes.md +3 -3
  308. package/src/image-editor/index.ts +7 -16
  309. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  310. package/src/image-editor/react/components/cropper.tsx +19 -27
  311. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  312. package/src/image-editor/react/hooks/index.ts +2 -2
  313. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  314. package/src/state/aspect-ratio-presets.ts +18 -0
  315. package/src/state/composite-reducer.ts +2 -2
  316. package/src/state/index.ts +1 -0
  317. package/src/state/types.ts +2 -6
  318. package/src/state/use-media-editor-state.ts +7 -5
  319. package/build/image-editor/core/index.cjs.map +0 -7
  320. package/build/image-editor/core/types.cjs.map +0 -7
  321. package/build/image-editor/index.cjs.map +0 -7
  322. package/build/image-editor/react/components/index.cjs.map +0 -7
  323. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  324. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  325. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  326. package/build/index.cjs.map +0 -7
  327. package/build/state/index.cjs.map +0 -7
  328. package/build/utils/index.cjs.map +0 -7
  329. package/build-module/image-editor/core/index.mjs.map +0 -7
  330. package/build-module/image-editor/core/types.mjs.map +0 -7
  331. package/build-module/image-editor/index.mjs.map +0 -7
  332. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  333. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  334. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  335. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  336. package/build-module/index.mjs.map +0 -7
  337. package/build-module/state/index.mjs.map +0 -7
  338. package/build-module/utils/index.mjs.map +0 -7
  339. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
@@ -1,23 +1,9 @@
1
- // packages/media-editor/src/image-editor/react/components/cropper.tsx
2
1
  import clsx from "clsx";
3
- import {
4
- useState,
5
- useCallback,
6
- useMemo,
7
- useRef,
8
- useEffect,
9
- useLayoutEffect,
10
- useId,
11
- forwardRef
12
- } from "@wordpress/element";
2
+ import { flushSync, forwardRef, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "@wordpress/element";
13
3
  import { __ } from "@wordpress/i18n";
14
4
  import { getImageFit, getRotatedBBox, getViewScale } from "../../core/camera.mjs";
15
5
  import { getImageCropBounds, getMinZoom } from "../../core/containment.mjs";
16
- import {
17
- MAX_VIEW_SCALE,
18
- PIXEL_SNAP_DISPLAY_SCALE,
19
- SETTLE_TARGET_CANVAS_FILL
20
- } from "../../core/constants.mjs";
6
+ import { MAX_VIEW_SCALE, PIXEL_SNAP_DISPLAY_SCALE, SETTLE_TARGET_CANVAS_FILL } from "../../core/constants.mjs";
21
7
  import { computeInscribedRect } from "../../core/crop-rect.mjs";
22
8
  import { getMinCropPixels } from "../../core/stencil-math.mjs";
23
9
  import { useInteraction } from "../hooks/use-interaction.mjs";
@@ -27,678 +13,556 @@ import { RectangleStencil } from "./stencils/rectangle-stencil.mjs";
27
13
  import { DimmingOverlay } from "./overlays/dimming-overlay.mjs";
28
14
  import { GridOverlay } from "./overlays/grid-overlay.mjs";
29
15
  import { DimensionsOverlay } from "./overlays/dimensions-overlay.mjs";
30
- import {
31
- getSourceRegion,
32
- snapCropRectToSourcePixelGrid,
33
- snapCropRectToSourcePixels
34
- } from "../../core/source-region.mjs";
16
+ import { getSourceRegion, snapCropRectToSourcePixelGrid, snapCropRectToSourcePixels } from "../../core/source-region.mjs";
35
17
  import { ViewportProvider, useViewport } from "./viewport-provider.mjs";
36
18
  import { VISUALLY_HIDDEN_STYLE } from "../visually-hidden-style.mjs";
37
19
  import { jsx, jsxs } from "react/jsx-runtime";
38
- var CROP_RECT_EPSILON = 1e-6;
39
- var CARDINAL_ROTATION_EPSILON = 1e-6;
40
- var SETTLE_TRANSITION_DURATION_MS = 200;
41
- var SETTLE_TRANSITION_FALLBACK_MS = SETTLE_TRANSITION_DURATION_MS + 100;
42
- var SETTLE_TRANSFORM_TRANSITION = `transform ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`;
43
- var SETTLE_STENCIL_TRANSITION = [
44
- `left ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
45
- `top ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
46
- `width ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
47
- `height ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`
20
+ // packages/media-editor/src/image-editor/react/components/cropper.tsx
21
+ /** Threshold for comparing normalized crop rect values. */
22
+ const CROP_RECT_EPSILON = 1e-6;
23
+ /** Threshold for deciding whether rotation is at a 90-degree stop. */
24
+ const CARDINAL_ROTATION_EPSILON = 1e-6;
25
+ /** Duration of the settle transform transition after resize end. */
26
+ const SETTLE_TRANSITION_DURATION_MS = 200;
27
+ const SETTLE_TRANSITION_FALLBACK_MS = 300;
28
+ const SETTLE_TRANSFORM_TRANSITION = `transform ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`;
29
+ const SETTLE_STENCIL_TRANSITION = [
30
+ `left ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
31
+ `top ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
32
+ `width ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
33
+ `height ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`
48
34
  ].join(", ");
49
- function CropperInner({
50
- src,
51
- controller,
52
- stencil: StencilComponent = RectangleStencil,
53
- showGrid = false,
54
- isPlacementActive = false,
55
- showDimming = true,
56
- showDimensions = true,
57
- minZoom,
58
- maxZoom,
59
- aspectRatio,
60
- freeformCrop = false,
61
- focusOnMount = false,
62
- disabled = false,
63
- onImageLoaded,
64
- onStateChange,
65
- onGestureStart,
66
- onGestureEnd,
67
- className
68
- }, ref) {
69
- const {
70
- state,
71
- setImage,
72
- setCropRect,
73
- settleCrop,
74
- setVisualSize,
75
- adjustCropRectForViewport
76
- } = controller;
77
- const {
78
- viewport: viewportState,
79
- setViewportPan,
80
- resetViewport
81
- } = useViewport();
82
- const canvasRef = useRef(null);
83
- const cropAreaDescriptionId = useId();
84
- const [isCropAreaFocused, setIsCropAreaFocused] = useState(focusOnMount);
85
- const [isFocusVisible, setIsFocusVisible] = useState(false);
86
- const [canvasSize, setCanvasSize] = useState({
87
- width: 0,
88
- height: 0
89
- });
90
- useLayoutEffect(() => {
91
- if (focusOnMount) {
92
- canvasRef.current?.focus({ preventScroll: true });
93
- }
94
- }, [focusOnMount]);
95
- const handleCropAreaFocus = useCallback(
96
- (event) => {
97
- const target = event.target;
98
- if (target === event.currentTarget) {
99
- setIsCropAreaFocused(true);
100
- }
101
- if (event.relatedTarget !== null && target.matches(":focus-visible")) {
102
- setIsFocusVisible(true);
103
- }
104
- },
105
- []
106
- );
107
- const handleCropAreaBlur = useCallback(
108
- (event) => {
109
- if (event.target === event.currentTarget) {
110
- setIsCropAreaFocused(false);
111
- }
112
- if (!event.currentTarget.contains(
113
- event.relatedTarget
114
- )) {
115
- setIsFocusVisible(false);
116
- }
117
- },
118
- []
119
- );
120
- useEffect(() => {
121
- const element = canvasRef.current;
122
- if (!element) {
123
- return;
124
- }
125
- const observer = new ResizeObserver((entries) => {
126
- for (const entry of entries) {
127
- const { width, height } = entry.contentRect;
128
- setCanvasSize((prev) => {
129
- if (prev.width === width && prev.height === height) {
130
- return prev;
131
- }
132
- return { width, height };
133
- });
134
- }
135
- });
136
- observer.observe(element);
137
- return () => {
138
- observer.disconnect();
139
- };
140
- }, []);
141
- useEffect(() => {
142
- onStateChange?.(state);
143
- }, [state, onStateChange]);
144
- useAriaAnnouncer(state);
145
- const naturalWidth = state.image?.naturalWidth ?? 0;
146
- const naturalHeight = state.image?.naturalHeight ?? 0;
147
- const { elementSize, visualSize } = useMemo(
148
- () => getImageFit(
149
- canvasSize,
150
- { width: naturalWidth, height: naturalHeight },
151
- state.rotation
152
- ),
153
- [canvasSize, naturalWidth, naturalHeight, state.rotation]
154
- );
155
- useEffect(() => {
156
- setVisualSize(visualSize);
157
- }, [visualSize, setVisualSize]);
158
- useEffect(() => {
159
- if (freeformCrop || visualSize.width === 0 || visualSize.height === 0 || !aspectRatio || aspectRatio <= 0) {
160
- return;
161
- }
162
- const rect = computeInscribedRect(aspectRatio, visualSize);
163
- const current = state.cropRect;
164
- if (Math.abs(current.x - rect.x) < CROP_RECT_EPSILON && Math.abs(current.y - rect.y) < CROP_RECT_EPSILON && Math.abs(current.width - rect.width) < CROP_RECT_EPSILON && Math.abs(current.height - rect.height) < CROP_RECT_EPSILON) {
165
- return;
166
- }
167
- adjustCropRectForViewport(rect);
168
- }, [
169
- freeformCrop,
170
- aspectRatio,
171
- visualSize,
172
- adjustCropRectForViewport,
173
- state.cropRect
174
- ]);
175
- const prevAspectRatioRef = useRef(aspectRatio);
176
- useEffect(() => {
177
- if (prevAspectRatioRef.current === aspectRatio) {
178
- return;
179
- }
180
- prevAspectRatioRef.current = aspectRatio;
181
- if (!freeformCrop || visualSize.width === 0 || visualSize.height === 0 || !aspectRatio || aspectRatio <= 0) {
182
- return;
183
- }
184
- const rect = computeInscribedRect(aspectRatio, visualSize);
185
- const current = state.cropRect;
186
- if (Math.abs(current.x - rect.x) < CROP_RECT_EPSILON && Math.abs(current.y - rect.y) < CROP_RECT_EPSILON && Math.abs(current.width - rect.width) < CROP_RECT_EPSILON && Math.abs(current.height - rect.height) < CROP_RECT_EPSILON) {
187
- return;
188
- }
189
- adjustCropRectForViewport(rect);
190
- }, [
191
- aspectRatio,
192
- freeformCrop,
193
- visualSize,
194
- adjustCropRectForViewport,
195
- state.cropRect
196
- ]);
197
- const cropBounds = useMemo(() => {
198
- if (!state.image || elementSize.width === 0) {
199
- return void 0;
200
- }
201
- return getImageCropBounds(state, elementSize, visualSize);
202
- }, [state, elementSize, visualSize]);
203
- const effectiveMinZoom = minZoom !== void 0 ? minZoom : getMinZoom(state);
204
- const [isResizing, setIsResizing] = useState(false);
205
- const isResizingRef = useRef(false);
206
- const isSettlingRef = useRef(false);
207
- const [isTouchPinching, setIsTouchPinchingState] = useState(false);
208
- const isTouchPinchingRef = useRef(false);
209
- const setTouchPinching = useCallback((isPinching) => {
210
- isTouchPinchingRef.current = isPinching;
211
- setIsTouchPinchingState(isPinching);
212
- }, []);
213
- const [activeHandle, setActiveHandle] = useState(
214
- null
215
- );
216
- const viewScaleRest = useMemo(
217
- () => getViewScale(
218
- state.cropRect,
219
- canvasSize,
220
- visualSize,
221
- SETTLE_TARGET_CANVAS_FILL,
222
- MAX_VIEW_SCALE
223
- ),
224
- [state.cropRect, canvasSize, visualSize]
225
- );
226
- const [frozenViewScale, setFrozenViewScale] = useState(1);
227
- const viewScale = isResizing ? frozenViewScale : viewScaleRest;
228
- const scaledVisualSize = useMemo(
229
- () => ({
230
- width: visualSize.width * viewScale,
231
- height: visualSize.height * viewScale
232
- }),
233
- [visualSize.width, visualSize.height, viewScale]
234
- );
235
- const displayScale = naturalWidth > 0 ? elementSize.width / naturalWidth * state.zoom * viewScale : 0;
236
- const keyboardResizeStep = useMemo(() => {
237
- if (displayScale < PIXEL_SNAP_DISPLAY_SCALE || aspectRatio && aspectRatio > 0 || naturalWidth <= 0 || naturalHeight <= 0) {
238
- return void 0;
239
- }
240
- const snapRotation = Math.round(state.rotation / 90) * 90;
241
- if (Math.abs(state.rotation - snapRotation) >= CARDINAL_ROTATION_EPSILON) {
242
- return void 0;
243
- }
244
- const bbox = getRotatedBBox(
245
- naturalWidth,
246
- naturalHeight,
247
- snapRotation
248
- );
249
- if (bbox.width <= 0 || bbox.height <= 0) {
250
- return void 0;
251
- }
252
- return {
253
- width: state.zoom / bbox.width,
254
- height: state.zoom / bbox.height
255
- };
256
- }, [
257
- displayScale,
258
- aspectRatio,
259
- naturalWidth,
260
- naturalHeight,
261
- state.rotation,
262
- state.zoom
263
- ]);
264
- const minCropSize = useMemo(() => {
265
- if (naturalWidth <= 0 || naturalHeight <= 0) {
266
- return void 0;
267
- }
268
- const snapRotation = Math.round(state.rotation / 90) * 90;
269
- const bbox = getRotatedBBox(
270
- naturalWidth,
271
- naturalHeight,
272
- snapRotation
273
- );
274
- const minPixels = getMinCropPixels(displayScale);
275
- return {
276
- width: Math.min(1, minPixels * state.zoom / bbox.width),
277
- height: Math.min(1, minPixels * state.zoom / bbox.height)
278
- };
279
- }, [
280
- naturalWidth,
281
- naturalHeight,
282
- state.rotation,
283
- state.zoom,
284
- displayScale
285
- ]);
286
- const snapCropRect = useCallback(
287
- (rect, handle) => {
288
- if (displayScale < PIXEL_SNAP_DISPLAY_SCALE || naturalWidth <= 0 || naturalHeight <= 0) {
289
- return rect;
290
- }
291
- return snapCropRectToSourcePixels(
292
- state,
293
- { width: naturalWidth, height: naturalHeight },
294
- rect,
295
- handle
296
- );
297
- },
298
- [displayScale, naturalWidth, naturalHeight, state]
299
- );
300
- const wasPixelSnapEnabledRef = useRef(false);
301
- useEffect(() => {
302
- const isPixelSnapEnabled = freeformCrop && (!aspectRatio || aspectRatio <= 0) && displayScale >= PIXEL_SNAP_DISPLAY_SCALE && naturalWidth > 0 && naturalHeight > 0;
303
- const wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;
304
- wasPixelSnapEnabledRef.current = isPixelSnapEnabled;
305
- if (!isPixelSnapEnabled || wasPixelSnapEnabled) {
306
- return;
307
- }
308
- const snappedCropRect = snapCropRectToSourcePixelGrid(
309
- state,
310
- { width: naturalWidth, height: naturalHeight },
311
- state.cropRect
312
- );
313
- const currentCropRect = state.cropRect;
314
- if (Math.abs(currentCropRect.x - snappedCropRect.x) < CROP_RECT_EPSILON && Math.abs(currentCropRect.y - snappedCropRect.y) < CROP_RECT_EPSILON && Math.abs(currentCropRect.width - snappedCropRect.width) < CROP_RECT_EPSILON && Math.abs(currentCropRect.height - snappedCropRect.height) < CROP_RECT_EPSILON) {
315
- return;
316
- }
317
- adjustCropRectForViewport(snappedCropRect);
318
- }, [
319
- adjustCropRectForViewport,
320
- aspectRatio,
321
- displayScale,
322
- freeformCrop,
323
- naturalWidth,
324
- naturalHeight,
325
- state
326
- ]);
327
- const {
328
- handlers,
329
- onWheelNative,
330
- isDragging,
331
- isZooming,
332
- isPlacementActive: isInteractionPlacementActive
333
- } = useInteraction(state, controller, canvasSize, scaledVisualSize, {
334
- minZoom: effectiveMinZoom,
335
- maxZoom,
336
- onGestureStart,
337
- onGestureEnd,
338
- disabled
339
- });
340
- const canvasHandlers = {
341
- ...handlers,
342
- onPointerDownCapture: () => {
343
- setIsFocusVisible(false);
344
- },
345
- onTouchStartCapture: (event) => {
346
- if (event.touches.length > 1) {
347
- setTouchPinching(true);
348
- }
349
- },
350
- onTouchMoveCapture: (event) => {
351
- if (event.touches.length > 1) {
352
- setTouchPinching(true);
353
- }
354
- },
355
- onTouchEndCapture: (event) => {
356
- if (event.touches.length === 0) {
357
- setTouchPinching(false);
358
- }
359
- },
360
- onTouchCancelCapture: (event) => {
361
- if (event.touches.length === 0) {
362
- setTouchPinching(false);
363
- }
364
- },
365
- onKeyDownCapture: (event) => {
366
- if (!["Shift", "Control", "Alt", "Meta"].includes(event.key)) {
367
- setIsFocusVisible(true);
368
- }
369
- },
370
- onPointerDown: (event) => {
371
- if (disabled || isResizingRef.current || isTouchPinchingRef.current || event.pointerType === "touch" && event.isPrimary === false) {
372
- event.preventDefault();
373
- return;
374
- }
375
- handlers.onPointerDown?.(event);
376
- setIsFocusVisible(false);
377
- }
378
- };
379
- useEffect(() => {
380
- const el = canvasRef.current;
381
- if (!el) {
382
- return;
383
- }
384
- const handleWheel = (event) => {
385
- if (isResizingRef.current || isSettlingRef.current) {
386
- event.preventDefault();
387
- return;
388
- }
389
- onWheelNative(event);
390
- };
391
- el.addEventListener("wheel", handleWheel, {
392
- passive: false
393
- });
394
- return () => {
395
- el.removeEventListener("wheel", handleWheel);
396
- };
397
- }, [onWheelNative]);
398
- const transformString = useTransformStyle(state, visualSize);
399
- const handleImageLoad = useCallback(
400
- (event) => {
401
- const img = event.currentTarget;
402
- const size = {
403
- width: img.naturalWidth,
404
- height: img.naturalHeight
405
- };
406
- setImage({
407
- src,
408
- naturalWidth: size.width,
409
- naturalHeight: size.height
410
- });
411
- onImageLoaded?.(size);
412
- },
413
- [src, setImage, onImageLoaded]
414
- );
415
- const handleCropChange = useCallback(
416
- (rect) => {
417
- if (isTouchPinchingRef.current) {
418
- return;
419
- }
420
- setCropRect(rect);
421
- if (isResizingRef.current && scaledVisualSize.width > 0 && scaledVisualSize.height > 0) {
422
- const offsetX = (canvasSize.width - scaledVisualSize.width) / 2;
423
- const offsetY = (canvasSize.height - scaledVisualSize.height) / 2;
424
- const rightOverflow = Math.max(
425
- 0,
426
- offsetX + (rect.x + rect.width) * scaledVisualSize.width - canvasSize.width
427
- );
428
- const leftOverflow = Math.max(
429
- 0,
430
- -(offsetX + rect.x * scaledVisualSize.width)
431
- );
432
- const bottomOverflow = Math.max(
433
- 0,
434
- offsetY + (rect.y + rect.height) * scaledVisualSize.height - canvasSize.height
435
- );
436
- const topOverflow = Math.max(
437
- 0,
438
- -(offsetY + rect.y * scaledVisualSize.height)
439
- );
440
- setViewportPan({
441
- x: -rightOverflow + leftOverflow,
442
- y: -bottomOverflow + topOverflow
443
- });
444
- }
445
- },
446
- [setCropRect, setViewportPan, canvasSize, scaledVisualSize]
447
- );
448
- const [settling, setSettling] = useState(false);
449
- const settleTimerRef = useRef(void 0);
450
- const finishSettling = useCallback(() => {
451
- clearTimeout(settleTimerRef.current);
452
- isSettlingRef.current = false;
453
- setSettling(false);
454
- }, []);
455
- useEffect(() => {
456
- return () => {
457
- clearTimeout(settleTimerRef.current);
458
- };
459
- }, []);
460
- const isInteractiveGrid = showGrid === "interactive";
461
- const showInteractiveGrid = isInteractiveGrid && (isInteractionPlacementActive || isResizing || isPlacementActive);
462
- const outputSize = useMemo(() => {
463
- if (!showDimensions || !activeHandle || !state.image) {
464
- return null;
465
- }
466
- const region = getSourceRegion(state, {
467
- width: state.image.naturalWidth,
468
- height: state.image.naturalHeight
469
- });
470
- return { width: region.width, height: region.height };
471
- }, [showDimensions, activeHandle, state]);
472
- const handleEscape = useCallback(() => {
473
- setIsFocusVisible(true);
474
- canvasRef.current?.focus({ preventScroll: true });
475
- }, []);
476
- const handleResizeStart = useCallback(
477
- (handle) => {
478
- if (isTouchPinchingRef.current) {
479
- return;
480
- }
481
- setFrozenViewScale(viewScaleRest);
482
- isResizingRef.current = true;
483
- setIsResizing(true);
484
- setActiveHandle(handle ?? null);
485
- finishSettling();
486
- resetViewport();
487
- onGestureStart?.();
488
- },
489
- [finishSettling, onGestureStart, resetViewport, viewScaleRest]
490
- );
491
- const handleResizeEnd = useCallback(() => {
492
- const isCancellingForPinch = isTouchPinchingRef.current;
493
- isResizingRef.current = false;
494
- setIsResizing(false);
495
- setActiveHandle(null);
496
- clearTimeout(settleTimerRef.current);
497
- if (isCancellingForPinch) {
498
- finishSettling();
499
- resetViewport();
500
- return;
501
- }
502
- isSettlingRef.current = true;
503
- setSettling(true);
504
- resetViewport();
505
- settleCrop();
506
- onGestureEnd?.();
507
- settleTimerRef.current = setTimeout(
508
- finishSettling,
509
- SETTLE_TRANSITION_FALLBACK_MS
510
- );
511
- }, [finishSettling, settleCrop, onGestureEnd, resetViewport]);
512
- const handleSettleTransitionEnd = useCallback(
513
- (event) => {
514
- if (!isSettlingRef.current || event.propertyName !== "transform") {
515
- return;
516
- }
517
- finishSettling();
518
- },
519
- [finishSettling]
520
- );
521
- let imageTransition;
522
- if (settling) {
523
- imageTransition = SETTLE_TRANSFORM_TRANSITION;
524
- } else if (isZooming) {
525
- imageTransition = "transform 150ms linear";
526
- }
527
- const settleStencilTransition = settling ? SETTLE_STENCIL_TRANSITION : void 0;
528
- const imageStyle = useMemo(() => {
529
- if (elementSize.width === 0 || elementSize.height === 0) {
530
- return {};
531
- }
532
- const centerX = (canvasSize.width - elementSize.width) / 2;
533
- const centerY = (canvasSize.height - elementSize.height) / 2;
534
- return {
535
- width: elementSize.width,
536
- height: elementSize.height,
537
- maxWidth: elementSize.width,
538
- maxHeight: elementSize.height,
539
- left: centerX,
540
- top: centerY,
541
- // Always lead with `scale()` (identity at rest) so the transform's
542
- // function list stays structurally constant across rest, resize, and
543
- // settle. A conditional that dropped `scale()` at viewScale === 1
544
- // would change the list shape exactly when the settle transition
545
- // crosses 1:1, forcing the browser to fall back to matrix-decomposition
546
- // interpolation instead of interpolating each function in turn.
547
- transform: `scale(${viewScale}) ${transformString}`,
548
- transition: imageTransition,
549
- imageRendering: displayScale > 1 ? "pixelated" : void 0
550
- };
551
- }, [
552
- canvasSize,
553
- elementSize,
554
- transformString,
555
- imageTransition,
556
- displayScale,
557
- viewScale
558
- ]);
559
- const settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : void 0;
560
- const willChange = isResizing || settling ? "transform" : void 0;
561
- let stageStyle;
562
- if (viewportState.pan.x !== 0 || viewportState.pan.y !== 0) {
563
- stageStyle = {
564
- transform: `translate(${viewportState.pan.x}px, ${viewportState.pan.y}px)`,
565
- transition: settleTransition,
566
- willChange
567
- };
568
- } else if (settling) {
569
- stageStyle = {
570
- transform: "translate(0px, 0px)",
571
- transition: settleTransition,
572
- willChange
573
- };
574
- }
575
- return /* @__PURE__ */ jsx(
576
- "div",
577
- {
578
- ref,
579
- className: clsx(
580
- "wp-media-editor-image-editor",
581
- isDragging && "wp-media-editor-image-editor--dragging",
582
- className
583
- ),
584
- children: /* @__PURE__ */ jsxs(
585
- "div",
586
- {
587
- ref: canvasRef,
588
- className: clsx(
589
- "wp-media-editor-image-editor__canvas",
590
- isInteractiveGrid && "wp-media-editor-image-editor__canvas--grid-interactive",
591
- showInteractiveGrid && "wp-media-editor-image-editor__canvas--show-grid",
592
- settling && "wp-media-editor-image-editor__canvas--settling",
593
- // Marks the cropper as in keyboard-interaction mode.
594
- // CSS uses :focus on the canvas to show the stencil
595
- // outline and :focus on a handle to show its ring,
596
- // so the class applies whenever any cropper element
597
- // has keyboard focus.
598
- isFocusVisible && "wp-media-editor-image-editor__canvas--focus-visible"
599
- ),
600
- tabIndex: 0,
601
- role: "group",
602
- "aria-label": __("Crop area"),
603
- "aria-describedby": isCropAreaFocused ? cropAreaDescriptionId : void 0,
604
- onFocus: handleCropAreaFocus,
605
- onBlur: handleCropAreaBlur,
606
- ...canvasHandlers,
607
- children: [
608
- /* @__PURE__ */ jsx(
609
- "div",
610
- {
611
- id: cropAreaDescriptionId,
612
- style: VISUALLY_HIDDEN_STYLE,
613
- children: __(
614
- "When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls."
615
- )
616
- }
617
- ),
618
- /* @__PURE__ */ jsxs(
619
- "div",
620
- {
621
- className: "wp-media-editor-image-editor__stage",
622
- "data-testid": "cropper-stage",
623
- style: stageStyle,
624
- onTransitionEnd: handleSettleTransitionEnd,
625
- children: [
626
- /* @__PURE__ */ jsx(
627
- "img",
628
- {
629
- className: "wp-media-editor-image-editor__image",
630
- "data-testid": "cropper-image",
631
- src,
632
- alt: "",
633
- onLoad: handleImageLoad,
634
- style: imageStyle,
635
- draggable: false
636
- }
637
- ),
638
- showDimming && /* @__PURE__ */ jsx(
639
- DimmingOverlay,
640
- {
641
- cropRect: state.cropRect,
642
- containerSize: canvasSize,
643
- imageSize: scaledVisualSize,
644
- transition: settleStencilTransition
645
- }
646
- ),
647
- /* @__PURE__ */ jsx(
648
- StencilComponent,
649
- {
650
- cropRect: state.cropRect,
651
- containerSize: canvasSize,
652
- imageSize: scaledVisualSize,
653
- onCropChange: handleCropChange,
654
- onResizeStart: handleResizeStart,
655
- onResizeEnd: handleResizeEnd,
656
- onEscape: handleEscape,
657
- aspectRatio,
658
- freeformCrop,
659
- isResizeDisabled: isTouchPinching || disabled,
660
- stencilTransition: settleStencilTransition,
661
- cropBounds,
662
- minCropSize,
663
- snapCropRect,
664
- keyboardResizeStep
665
- }
666
- ),
667
- (showGrid === true || isInteractiveGrid) && /* @__PURE__ */ jsx(
668
- GridOverlay,
669
- {
670
- cropRect: state.cropRect,
671
- containerSize: canvasSize,
672
- imageSize: scaledVisualSize
673
- }
674
- ),
675
- activeHandle && outputSize && /* @__PURE__ */ jsx(
676
- DimensionsOverlay,
677
- {
678
- cropRect: state.cropRect,
679
- containerSize: canvasSize,
680
- imageSize: scaledVisualSize,
681
- activeHandle,
682
- outputWidth: outputSize.width,
683
- outputHeight: outputSize.height
684
- }
685
- )
686
- ]
687
- }
688
- )
689
- ]
690
- }
691
- )
692
- }
693
- );
35
+ /**
36
+ * The main image cropper component.
37
+ *
38
+ * Renders an image within a container with interactive crop overlays.
39
+ * Creates the camera once per render via getImageFit, then passes
40
+ * derived values to stencil, overlays, and interaction hooks.
41
+ *
42
+ * The component fills its parent container (100% width and height).
43
+ * Wrap it in a sized container to control its dimensions.
44
+ *
45
+ * @param root0 Component props implementing CropperProps.
46
+ * @param root0.src Image source URL.
47
+ * @param root0.controller The cropper controller from `useCropperController` or a composite store.
48
+ * @param root0.stencil Custom stencil component.
49
+ * @param root0.showGrid Grid overlay mode: false | true | 'interactive'.
50
+ * @param root0.isPlacementActive Keep grid visible during external placement activity.
51
+ * @param root0.showDimming Show dimming overlay outside crop.
52
+ * @param root0.showDimensions Show live dimensions tooltip during resize.
53
+ * @param root0.minZoom Minimum zoom level override.
54
+ * @param root0.maxZoom Maximum zoom level.
55
+ * @param root0.aspectRatio Fixed aspect ratio (width/height).
56
+ * @param root0.freeformCrop Enable resize handles.
57
+ * @param root0.focusOnMount Focus the crop area on mount.
58
+ * @param root0.disabled Ignore all crop interaction.
59
+ * @param root0.onImageLoaded Image load callback.
60
+ * @param root0.onImageError Image error callback.
61
+ * @param root0.onGestureStart Gesture boundary start.
62
+ * @param root0.onGestureEnd Gesture boundary end.
63
+ * @param root0.className Additional CSS class.
64
+ * @param ref Forwarded ref for the container div.
65
+ */
66
+ function CropperInner({ src, controller, stencil: StencilComponent = RectangleStencil, showGrid = false, isPlacementActive = false, showDimming = true, showDimensions = true, minZoom, maxZoom, aspectRatio, freeformCrop = false, focusOnMount = false, disabled = false, onImageLoaded, onImageError, onGestureStart, onGestureEnd, className }, ref) {
67
+ const { state, setImage, setCropRect, settleCrop, setVisualSize, adjustCropRectForViewport } = controller;
68
+ const { viewport: viewportState, setViewportPan, resetViewport } = useViewport();
69
+ const canvasRef = useRef(null);
70
+ const cropAreaDescriptionId = useId();
71
+ const [isCropAreaFocused, setIsCropAreaFocused] = useState(focusOnMount);
72
+ const [isFocusVisible, setIsFocusVisible] = useState(false);
73
+ const [canvasSize, setCanvasSize] = useState({
74
+ width: 0,
75
+ height: 0
76
+ });
77
+ useLayoutEffect(() => {
78
+ if (focusOnMount) canvasRef.current?.focus({ preventScroll: true });
79
+ }, [focusOnMount]);
80
+ const handleCropAreaFocus = useCallback((event) => {
81
+ const target = event.target;
82
+ if (target === event.currentTarget) setIsCropAreaFocused(true);
83
+ if (event.relatedTarget !== null && target.matches(":focus-visible")) setIsFocusVisible(true);
84
+ }, []);
85
+ const handleCropAreaBlur = useCallback((event) => {
86
+ if (event.target === event.currentTarget) setIsCropAreaFocused(false);
87
+ if (!event.currentTarget.contains(event.relatedTarget)) setIsFocusVisible(false);
88
+ }, []);
89
+ useEffect(() => {
90
+ const element = canvasRef.current;
91
+ if (!element) return;
92
+ const observer = new ResizeObserver((entries) => {
93
+ for (const entry of entries) {
94
+ const { width, height } = entry.contentRect;
95
+ flushSync(() => {
96
+ setCanvasSize((prev) => {
97
+ if (prev.width === width && prev.height === height) return prev;
98
+ return {
99
+ width,
100
+ height
101
+ };
102
+ });
103
+ });
104
+ }
105
+ });
106
+ observer.observe(element);
107
+ return () => {
108
+ observer.disconnect();
109
+ };
110
+ }, []);
111
+ useAriaAnnouncer(state);
112
+ const naturalWidth = state.image?.naturalWidth ?? 0;
113
+ const naturalHeight = state.image?.naturalHeight ?? 0;
114
+ const { elementSize, visualSize } = useMemo(() => getImageFit(canvasSize, {
115
+ width: naturalWidth,
116
+ height: naturalHeight
117
+ }, state.rotation), [
118
+ canvasSize,
119
+ naturalWidth,
120
+ naturalHeight,
121
+ state.rotation
122
+ ]);
123
+ useEffect(() => {
124
+ setVisualSize(visualSize);
125
+ }, [visualSize, setVisualSize]);
126
+ useEffect(() => {
127
+ if (freeformCrop || visualSize.width === 0 || visualSize.height === 0 || !aspectRatio || aspectRatio <= 0) return;
128
+ const rect = computeInscribedRect(aspectRatio, visualSize);
129
+ const current = state.cropRect;
130
+ if (Math.abs(current.x - rect.x) < CROP_RECT_EPSILON && Math.abs(current.y - rect.y) < CROP_RECT_EPSILON && Math.abs(current.width - rect.width) < CROP_RECT_EPSILON && Math.abs(current.height - rect.height) < CROP_RECT_EPSILON) return;
131
+ adjustCropRectForViewport(rect);
132
+ }, [
133
+ freeformCrop,
134
+ aspectRatio,
135
+ visualSize,
136
+ adjustCropRectForViewport,
137
+ state.cropRect
138
+ ]);
139
+ const prevAspectRatioRef = useRef(aspectRatio);
140
+ useEffect(() => {
141
+ if (prevAspectRatioRef.current === aspectRatio) return;
142
+ prevAspectRatioRef.current = aspectRatio;
143
+ if (!freeformCrop || visualSize.width === 0 || visualSize.height === 0 || !aspectRatio || aspectRatio <= 0) return;
144
+ const rect = computeInscribedRect(aspectRatio, visualSize);
145
+ const current = state.cropRect;
146
+ if (Math.abs(current.x - rect.x) < CROP_RECT_EPSILON && Math.abs(current.y - rect.y) < CROP_RECT_EPSILON && Math.abs(current.width - rect.width) < CROP_RECT_EPSILON && Math.abs(current.height - rect.height) < CROP_RECT_EPSILON) return;
147
+ adjustCropRectForViewport(rect);
148
+ }, [
149
+ aspectRatio,
150
+ freeformCrop,
151
+ visualSize,
152
+ adjustCropRectForViewport,
153
+ state.cropRect
154
+ ]);
155
+ const cropBounds = useMemo(() => {
156
+ if (!state.image || elementSize.width === 0) return;
157
+ return getImageCropBounds(state, elementSize, visualSize);
158
+ }, [
159
+ state,
160
+ elementSize,
161
+ visualSize
162
+ ]);
163
+ const effectiveMinZoom = minZoom !== void 0 ? minZoom : getMinZoom(state);
164
+ const [isResizing, setIsResizing] = useState(false);
165
+ const isResizingRef = useRef(false);
166
+ const isSettlingRef = useRef(false);
167
+ const [isTouchPinching, setIsTouchPinchingState] = useState(false);
168
+ const isTouchPinchingRef = useRef(false);
169
+ const setTouchPinching = useCallback((isPinching) => {
170
+ isTouchPinchingRef.current = isPinching;
171
+ setIsTouchPinchingState(isPinching);
172
+ }, []);
173
+ const [activeHandle, setActiveHandle] = useState(null);
174
+ const viewScaleRest = useMemo(() => getViewScale(state.cropRect, canvasSize, visualSize, SETTLE_TARGET_CANVAS_FILL, MAX_VIEW_SCALE), [
175
+ state.cropRect,
176
+ canvasSize,
177
+ visualSize
178
+ ]);
179
+ const [frozenViewScale, setFrozenViewScale] = useState(1);
180
+ const viewScale = isResizing ? frozenViewScale : viewScaleRest;
181
+ const scaledVisualSize = useMemo(() => ({
182
+ width: visualSize.width * viewScale,
183
+ height: visualSize.height * viewScale
184
+ }), [
185
+ visualSize.width,
186
+ visualSize.height,
187
+ viewScale
188
+ ]);
189
+ const displayScale = naturalWidth > 0 ? elementSize.width / naturalWidth * state.zoom * viewScale : 0;
190
+ const keyboardResizeStep = useMemo(() => {
191
+ if (displayScale < PIXEL_SNAP_DISPLAY_SCALE || aspectRatio && aspectRatio > 0 || naturalWidth <= 0 || naturalHeight <= 0) return;
192
+ const snapRotation = Math.round(state.rotation / 90) * 90;
193
+ if (Math.abs(state.rotation - snapRotation) >= CARDINAL_ROTATION_EPSILON) return;
194
+ const bbox = getRotatedBBox(naturalWidth, naturalHeight, snapRotation);
195
+ if (bbox.width <= 0 || bbox.height <= 0) return;
196
+ return {
197
+ width: state.zoom / bbox.width,
198
+ height: state.zoom / bbox.height
199
+ };
200
+ }, [
201
+ displayScale,
202
+ aspectRatio,
203
+ naturalWidth,
204
+ naturalHeight,
205
+ state.rotation,
206
+ state.zoom
207
+ ]);
208
+ const minCropSize = useMemo(() => {
209
+ if (naturalWidth <= 0 || naturalHeight <= 0) return;
210
+ const snapRotation = Math.round(state.rotation / 90) * 90;
211
+ const bbox = getRotatedBBox(naturalWidth, naturalHeight, snapRotation);
212
+ const minPixels = getMinCropPixels(displayScale);
213
+ return {
214
+ width: Math.min(1, minPixels * state.zoom / bbox.width),
215
+ height: Math.min(1, minPixels * state.zoom / bbox.height)
216
+ };
217
+ }, [
218
+ naturalWidth,
219
+ naturalHeight,
220
+ state.rotation,
221
+ state.zoom,
222
+ displayScale
223
+ ]);
224
+ const snapCropRect = useCallback((rect, handle) => {
225
+ if (displayScale < PIXEL_SNAP_DISPLAY_SCALE || naturalWidth <= 0 || naturalHeight <= 0) return rect;
226
+ return snapCropRectToSourcePixels(state, {
227
+ width: naturalWidth,
228
+ height: naturalHeight
229
+ }, rect, handle);
230
+ }, [
231
+ displayScale,
232
+ naturalWidth,
233
+ naturalHeight,
234
+ state
235
+ ]);
236
+ const wasPixelSnapEnabledRef = useRef(false);
237
+ useEffect(() => {
238
+ const isPixelSnapEnabled = freeformCrop && (!aspectRatio || aspectRatio <= 0) && displayScale >= PIXEL_SNAP_DISPLAY_SCALE && naturalWidth > 0 && naturalHeight > 0;
239
+ const wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;
240
+ wasPixelSnapEnabledRef.current = isPixelSnapEnabled;
241
+ if (!isPixelSnapEnabled || wasPixelSnapEnabled) return;
242
+ const snappedCropRect = snapCropRectToSourcePixelGrid(state, {
243
+ width: naturalWidth,
244
+ height: naturalHeight
245
+ }, state.cropRect);
246
+ const currentCropRect = state.cropRect;
247
+ if (Math.abs(currentCropRect.x - snappedCropRect.x) < CROP_RECT_EPSILON && Math.abs(currentCropRect.y - snappedCropRect.y) < CROP_RECT_EPSILON && Math.abs(currentCropRect.width - snappedCropRect.width) < CROP_RECT_EPSILON && Math.abs(currentCropRect.height - snappedCropRect.height) < CROP_RECT_EPSILON) return;
248
+ adjustCropRectForViewport(snappedCropRect);
249
+ }, [
250
+ adjustCropRectForViewport,
251
+ aspectRatio,
252
+ displayScale,
253
+ freeformCrop,
254
+ naturalWidth,
255
+ naturalHeight,
256
+ state
257
+ ]);
258
+ const { handlers, onWheelNative, isDragging, isZooming, isPlacementActive: isInteractionPlacementActive } = useInteraction(state, controller, canvasSize, scaledVisualSize, {
259
+ minZoom: effectiveMinZoom,
260
+ maxZoom,
261
+ onGestureStart,
262
+ onGestureEnd,
263
+ disabled
264
+ });
265
+ const canvasHandlers = {
266
+ ...handlers,
267
+ onPointerDownCapture: () => {
268
+ setIsFocusVisible(false);
269
+ },
270
+ onTouchStartCapture: (event) => {
271
+ if (event.touches.length > 1) setTouchPinching(true);
272
+ },
273
+ onTouchMoveCapture: (event) => {
274
+ if (event.touches.length > 1) setTouchPinching(true);
275
+ },
276
+ onTouchEndCapture: (event) => {
277
+ if (event.touches.length === 0) setTouchPinching(false);
278
+ },
279
+ onTouchCancelCapture: (event) => {
280
+ if (event.touches.length === 0) setTouchPinching(false);
281
+ },
282
+ onKeyDownCapture: (event) => {
283
+ if (![
284
+ "Shift",
285
+ "Control",
286
+ "Alt",
287
+ "Meta"
288
+ ].includes(event.key)) setIsFocusVisible(true);
289
+ },
290
+ onPointerDown: (event) => {
291
+ if (disabled || isResizingRef.current || isTouchPinchingRef.current || event.pointerType === "touch" && event.isPrimary === false) {
292
+ event.preventDefault();
293
+ return;
294
+ }
295
+ handlers.onPointerDown?.(event);
296
+ setIsFocusVisible(false);
297
+ }
298
+ };
299
+ useEffect(() => {
300
+ const el = canvasRef.current;
301
+ if (!el) return;
302
+ const handleWheel = (event) => {
303
+ if (isResizingRef.current || isSettlingRef.current) {
304
+ event.preventDefault();
305
+ return;
306
+ }
307
+ onWheelNative(event);
308
+ };
309
+ el.addEventListener("wheel", handleWheel, { passive: false });
310
+ return () => {
311
+ el.removeEventListener("wheel", handleWheel);
312
+ };
313
+ }, [onWheelNative]);
314
+ const transformString = useTransformStyle(state, visualSize);
315
+ /**
316
+ * Handle the image load event.
317
+ */
318
+ const handleImageLoad = useCallback((event) => {
319
+ const img = event.currentTarget;
320
+ const size = {
321
+ width: img.naturalWidth,
322
+ height: img.naturalHeight
323
+ };
324
+ setImage({
325
+ src,
326
+ naturalWidth: size.width,
327
+ naturalHeight: size.height
328
+ });
329
+ onImageLoaded?.(size);
330
+ }, [
331
+ src,
332
+ setImage,
333
+ onImageLoaded
334
+ ]);
335
+ const handleCropChange = useCallback((rect) => {
336
+ if (isTouchPinchingRef.current) return;
337
+ setCropRect(rect);
338
+ if (isResizingRef.current && scaledVisualSize.width > 0 && scaledVisualSize.height > 0) {
339
+ const offsetX = (canvasSize.width - scaledVisualSize.width) / 2;
340
+ const offsetY = (canvasSize.height - scaledVisualSize.height) / 2;
341
+ const rightOverflow = Math.max(0, offsetX + (rect.x + rect.width) * scaledVisualSize.width - canvasSize.width);
342
+ const leftOverflow = Math.max(0, -(offsetX + rect.x * scaledVisualSize.width));
343
+ const bottomOverflow = Math.max(0, offsetY + (rect.y + rect.height) * scaledVisualSize.height - canvasSize.height);
344
+ const topOverflow = Math.max(0, -(offsetY + rect.y * scaledVisualSize.height));
345
+ setViewportPan({
346
+ x: -rightOverflow + leftOverflow,
347
+ y: -bottomOverflow + topOverflow
348
+ });
349
+ }
350
+ }, [
351
+ setCropRect,
352
+ setViewportPan,
353
+ canvasSize,
354
+ scaledVisualSize
355
+ ]);
356
+ const [settling, setSettling] = useState(false);
357
+ const settleTimerRef = useRef(void 0);
358
+ const finishSettling = useCallback(() => {
359
+ clearTimeout(settleTimerRef.current);
360
+ isSettlingRef.current = false;
361
+ setSettling(false);
362
+ }, []);
363
+ useEffect(() => {
364
+ return () => {
365
+ clearTimeout(settleTimerRef.current);
366
+ };
367
+ }, []);
368
+ const isInteractiveGrid = showGrid === "interactive";
369
+ const showInteractiveGrid = isInteractiveGrid && (isInteractionPlacementActive || isResizing || isPlacementActive);
370
+ const outputSize = useMemo(() => {
371
+ if (!showDimensions || !activeHandle || !state.image) return null;
372
+ const region = getSourceRegion(state, {
373
+ width: state.image.naturalWidth,
374
+ height: state.image.naturalHeight
375
+ });
376
+ return {
377
+ width: region.width,
378
+ height: region.height
379
+ };
380
+ }, [
381
+ showDimensions,
382
+ activeHandle,
383
+ state
384
+ ]);
385
+ /**
386
+ * Handle Escape on a resize handle — return focus to the canvas so
387
+ * arrow keys pan the image rather than resize.
388
+ */
389
+ const handleEscape = useCallback(() => {
390
+ setIsFocusVisible(true);
391
+ canvasRef.current?.focus({ preventScroll: true });
392
+ }, []);
393
+ const handleResizeStart = useCallback((handle) => {
394
+ if (isTouchPinchingRef.current) return;
395
+ setFrozenViewScale(viewScaleRest);
396
+ isResizingRef.current = true;
397
+ setIsResizing(true);
398
+ setActiveHandle(handle ?? null);
399
+ finishSettling();
400
+ resetViewport();
401
+ onGestureStart?.();
402
+ }, [
403
+ finishSettling,
404
+ onGestureStart,
405
+ resetViewport,
406
+ viewScaleRest
407
+ ]);
408
+ /**
409
+ * Handle resize end — settle the crop rect (re-center, fill height)
410
+ * and reset the viewport pan back to neutral.
411
+ */
412
+ const handleResizeEnd = useCallback(() => {
413
+ const isCancellingForPinch = isTouchPinchingRef.current;
414
+ isResizingRef.current = false;
415
+ setIsResizing(false);
416
+ setActiveHandle(null);
417
+ clearTimeout(settleTimerRef.current);
418
+ if (isCancellingForPinch) {
419
+ finishSettling();
420
+ resetViewport();
421
+ return;
422
+ }
423
+ isSettlingRef.current = true;
424
+ setSettling(true);
425
+ resetViewport();
426
+ settleCrop();
427
+ onGestureEnd?.();
428
+ settleTimerRef.current = setTimeout(finishSettling, SETTLE_TRANSITION_FALLBACK_MS);
429
+ }, [
430
+ finishSettling,
431
+ settleCrop,
432
+ onGestureEnd,
433
+ resetViewport
434
+ ]);
435
+ /**
436
+ * Finish settling when the settle transform transition actually completes.
437
+ * The handler lives on the stage, but in the common (un-panned) case the
438
+ * transform transition runs on the image layer and its `transitionend`
439
+ * bubbles up to here. Other transitionend events (stencil left/top/width/
440
+ * height) also bubble up, so only the transform transition should clear the
441
+ * settle state.
442
+ */
443
+ const handleSettleTransitionEnd = useCallback((event) => {
444
+ if (!isSettlingRef.current || event.propertyName !== "transform") return;
445
+ finishSettling();
446
+ }, [finishSettling]);
447
+ let imageTransition;
448
+ if (settling) imageTransition = SETTLE_TRANSFORM_TRANSITION;
449
+ else if (isZooming) imageTransition = "transform 150ms linear";
450
+ const settleStencilTransition = settling ? SETTLE_STENCIL_TRANSITION : void 0;
451
+ const imageStyle = useMemo(() => {
452
+ if (elementSize.width === 0 || elementSize.height === 0) return {};
453
+ const centerX = (canvasSize.width - elementSize.width) / 2;
454
+ const centerY = (canvasSize.height - elementSize.height) / 2;
455
+ return {
456
+ width: elementSize.width,
457
+ height: elementSize.height,
458
+ maxWidth: elementSize.width,
459
+ maxHeight: elementSize.height,
460
+ left: centerX,
461
+ top: centerY,
462
+ transform: `scale(${viewScale}) ${transformString}`,
463
+ transition: imageTransition,
464
+ imageRendering: displayScale > 1 ? "pixelated" : void 0
465
+ };
466
+ }, [
467
+ canvasSize,
468
+ elementSize,
469
+ transformString,
470
+ imageTransition,
471
+ displayScale,
472
+ viewScale
473
+ ]);
474
+ const settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : void 0;
475
+ const willChange = isResizing || settling ? "transform" : void 0;
476
+ let stageStyle;
477
+ if (viewportState.pan.x !== 0 || viewportState.pan.y !== 0) stageStyle = {
478
+ transform: `translate(${viewportState.pan.x}px, ${viewportState.pan.y}px)`,
479
+ transition: settleTransition,
480
+ willChange
481
+ };
482
+ else if (settling) stageStyle = {
483
+ transform: "translate(0px, 0px)",
484
+ transition: settleTransition,
485
+ willChange
486
+ };
487
+ return /* @__PURE__ */ jsx("div", {
488
+ ref,
489
+ className: clsx("wp-media-editor-image-editor", isDragging && "wp-media-editor-image-editor--dragging", className),
490
+ children: /* @__PURE__ */ jsxs("div", {
491
+ ref: canvasRef,
492
+ className: clsx("wp-media-editor-image-editor__canvas", isInteractiveGrid && "wp-media-editor-image-editor__canvas--grid-interactive", showInteractiveGrid && "wp-media-editor-image-editor__canvas--show-grid", settling && "wp-media-editor-image-editor__canvas--settling", isFocusVisible && "wp-media-editor-image-editor__canvas--focus-visible"),
493
+ tabIndex: 0,
494
+ role: "group",
495
+ "aria-label": __("Crop area"),
496
+ "aria-describedby": isCropAreaFocused ? cropAreaDescriptionId : void 0,
497
+ onFocus: handleCropAreaFocus,
498
+ onBlur: handleCropAreaBlur,
499
+ ...canvasHandlers,
500
+ children: [/* @__PURE__ */ jsx("div", {
501
+ id: cropAreaDescriptionId,
502
+ style: VISUALLY_HIDDEN_STYLE,
503
+ children: __("When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.")
504
+ }), /* @__PURE__ */ jsxs("div", {
505
+ className: "wp-media-editor-image-editor__stage",
506
+ "data-testid": "cropper-stage",
507
+ style: stageStyle,
508
+ onTransitionEnd: handleSettleTransitionEnd,
509
+ children: [
510
+ /* @__PURE__ */ jsx("img", {
511
+ className: "wp-media-editor-image-editor__image",
512
+ "data-testid": "cropper-image",
513
+ src,
514
+ alt: "",
515
+ onLoad: handleImageLoad,
516
+ onError: onImageError,
517
+ style: imageStyle,
518
+ draggable: false
519
+ }),
520
+ showDimming && /* @__PURE__ */ jsx(DimmingOverlay, {
521
+ cropRect: state.cropRect,
522
+ containerSize: canvasSize,
523
+ imageSize: scaledVisualSize,
524
+ transition: settleStencilTransition
525
+ }),
526
+ /* @__PURE__ */ jsx(StencilComponent, {
527
+ cropRect: state.cropRect,
528
+ containerSize: canvasSize,
529
+ imageSize: scaledVisualSize,
530
+ onCropChange: handleCropChange,
531
+ onResizeStart: handleResizeStart,
532
+ onResizeEnd: handleResizeEnd,
533
+ onEscape: handleEscape,
534
+ aspectRatio,
535
+ freeformCrop,
536
+ isResizeDisabled: isTouchPinching || disabled,
537
+ stencilTransition: settleStencilTransition,
538
+ cropBounds,
539
+ minCropSize,
540
+ snapCropRect,
541
+ keyboardResizeStep
542
+ }),
543
+ (showGrid === true || isInteractiveGrid) && /* @__PURE__ */ jsx(GridOverlay, {
544
+ cropRect: state.cropRect,
545
+ containerSize: canvasSize,
546
+ imageSize: scaledVisualSize
547
+ }),
548
+ activeHandle && outputSize && /* @__PURE__ */ jsx(DimensionsOverlay, {
549
+ cropRect: state.cropRect,
550
+ containerSize: canvasSize,
551
+ imageSize: scaledVisualSize,
552
+ activeHandle,
553
+ outputWidth: outputSize.width,
554
+ outputHeight: outputSize.height
555
+ })
556
+ ]
557
+ })]
558
+ })
559
+ });
694
560
  }
695
- var CropperInnerWithRef = forwardRef(
696
- CropperInner
697
- );
698
- var Cropper = forwardRef(
699
- (props, ref) => /* @__PURE__ */ jsx(ViewportProvider, { children: /* @__PURE__ */ jsx(CropperInnerWithRef, { ...props, ref }) })
700
- );
701
- export {
702
- Cropper
703
- };
704
- //# sourceMappingURL=cropper.mjs.map
561
+ const CropperInnerWithRef = forwardRef(CropperInner);
562
+ const Cropper = forwardRef((props, ref) => /* @__PURE__ */ jsx(ViewportProvider, { children: /* @__PURE__ */ jsx(CropperInnerWithRef, {
563
+ ...props,
564
+ ref
565
+ }) }));
566
+ export { Cropper };
567
+
568
+ //# sourceMappingURL=cropper.mjs.map