@wordpress/media-editor 0.21.0 → 0.23.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 (432) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/components/media-editor/index.cjs +586 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +42 -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 +131 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +117 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +81 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +61 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +181 -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 +120 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/index.cjs +112 -155
  19. package/build/components/media-editor-modal/index.cjs.map +1 -7
  20. package/build/components/media-editor-provider/index.cjs +32 -55
  21. package/build/components/media-editor-provider/index.cjs.map +1 -7
  22. package/build/components/media-form/index.cjs +82 -77
  23. package/build/components/media-form/index.cjs.map +1 -7
  24. package/build/components/media-preview/index.cjs +113 -114
  25. package/build/components/media-preview/index.cjs.map +1 -7
  26. package/build/components/rotation-ruler/index.cjs +181 -188
  27. package/build/components/rotation-ruler/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  29. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  30. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  32. package/build/index.cjs +45 -39
  33. package/build/lock-unlock.cjs +9 -35
  34. package/build/lock-unlock.cjs.map +1 -7
  35. package/build/private-apis.cjs +16 -37
  36. package/build/private-apis.cjs.map +1 -7
  37. package/build/state/aspect-ratio-presets.cjs +59 -0
  38. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  39. package/build/state/composite-reducer.cjs +100 -113
  40. package/build/state/composite-reducer.cjs.map +1 -7
  41. package/build/state/index.cjs +22 -45
  42. package/build/state/media-editor-state-provider.cjs +35 -48
  43. package/build/state/media-editor-state-provider.cjs.map +1 -7
  44. package/build/state/types.cjs +11 -31
  45. package/build/state/types.cjs.map +1 -7
  46. package/build/state/use-media-editor-state.cjs +227 -296
  47. package/build/state/use-media-editor-state.cjs.map +1 -7
  48. package/build/store/actions.cjs +17 -44
  49. package/build/store/actions.cjs.map +1 -7
  50. package/build/store/constants.cjs +8 -29
  51. package/build/store/constants.cjs.map +1 -7
  52. package/build/store/index.cjs +33 -40
  53. package/build/store/index.cjs.map +1 -7
  54. package/build/store/reducer.cjs +28 -50
  55. package/build/store/reducer.cjs.map +1 -7
  56. package/build/store/selectors.cjs +16 -41
  57. package/build/store/selectors.cjs.map +1 -7
  58. package/build/utils/get-media-type.cjs +18 -41
  59. package/build/utils/get-media-type.cjs.map +1 -7
  60. package/build/utils/index.cjs +9 -28
  61. package/build-module/components/media-editor/index.mjs +545 -675
  62. package/build-module/components/media-editor/index.mjs.map +1 -7
  63. package/build-module/components/media-editor/use-crop-options.mjs +37 -32
  64. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  65. package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
  66. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  67. package/build-module/components/media-editor-canvas/index.mjs +95 -98
  68. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  69. package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
  70. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  71. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
  72. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  73. package/build-module/components/media-editor-image-controls/index.mjs +171 -238
  74. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  75. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
  76. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  77. package/build-module/components/media-editor-modal/index.mjs +88 -124
  78. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  79. package/build-module/components/media-editor-provider/index.mjs +26 -29
  80. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  81. package/build-module/components/media-form/index.mjs +74 -56
  82. package/build-module/components/media-form/index.mjs.map +1 -7
  83. package/build-module/components/media-preview/index.mjs +105 -90
  84. package/build-module/components/media-preview/index.mjs.map +1 -7
  85. package/build-module/components/rotation-ruler/index.mjs +161 -164
  86. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  87. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  88. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  89. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  90. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  91. package/build-module/index.mjs +3 -10
  92. package/build-module/lock-unlock.mjs +5 -10
  93. package/build-module/lock-unlock.mjs.map +1 -7
  94. package/build-module/private-apis.mjs +8 -9
  95. package/build-module/private-apis.mjs.map +1 -7
  96. package/build-module/state/aspect-ratio-presets.mjs +53 -0
  97. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  98. package/build-module/state/composite-reducer.mjs +80 -91
  99. package/build-module/state/composite-reducer.mjs.map +1 -7
  100. package/build-module/state/index.mjs +3 -26
  101. package/build-module/state/media-editor-state-provider.mjs +29 -24
  102. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  103. package/build-module/state/types.mjs +7 -7
  104. package/build-module/state/types.mjs.map +1 -7
  105. package/build-module/state/use-media-editor-state.mjs +223 -288
  106. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  107. package/build-module/store/actions.mjs +12 -19
  108. package/build-module/store/actions.mjs.map +1 -7
  109. package/build-module/store/constants.mjs +4 -5
  110. package/build-module/store/constants.mjs.map +1 -7
  111. package/build-module/store/index.mjs +8 -9
  112. package/build-module/store/index.mjs.map +1 -7
  113. package/build-module/store/reducer.mjs +23 -26
  114. package/build-module/store/reducer.mjs.map +1 -7
  115. package/build-module/store/selectors.mjs +8 -13
  116. package/build-module/store/selectors.mjs.map +1 -7
  117. package/build-module/utils/get-media-type.mjs +14 -17
  118. package/build-module/utils/get-media-type.mjs.map +1 -7
  119. package/build-module/utils/index.mjs +1 -6
  120. package/build-style/style-rtl.css +145 -61
  121. package/build-style/style.css +144 -61
  122. package/build-types/components/media-editor/index.d.ts +20 -2
  123. package/build-types/components/media-editor/index.d.ts.map +1 -1
  124. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  125. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  126. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  127. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  128. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  129. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  130. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  131. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  132. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  133. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  134. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  135. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  136. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  137. package/build-types/components/media-form/index.d.ts.map +1 -1
  138. package/build-types/components/media-preview/index.d.ts.map +1 -1
  139. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  140. package/build-types/state/aspect-ratio-presets.d.ts +24 -0
  141. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  142. package/build-types/state/composite-reducer.d.ts +17 -19
  143. package/build-types/state/composite-reducer.d.ts.map +1 -1
  144. package/build-types/state/index.d.ts +2 -4
  145. package/build-types/state/index.d.ts.map +1 -1
  146. package/build-types/state/types.d.ts +20 -63
  147. package/build-types/state/types.d.ts.map +1 -1
  148. package/build-types/state/use-media-editor-state.d.ts +33 -52
  149. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  150. package/package.json +22 -23
  151. package/src/components/media-editor/index.tsx +355 -167
  152. package/src/components/media-editor/style.scss +19 -0
  153. package/src/components/media-editor/use-crop-options.ts +9 -10
  154. package/src/components/media-editor/use-save-media-editor.ts +48 -10
  155. package/src/components/media-editor-canvas/index.tsx +30 -51
  156. package/src/components/media-editor-canvas/style.scss +6 -6
  157. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  158. package/src/components/media-editor-crop-panel/style.scss +21 -0
  159. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  160. package/src/components/media-editor-image-controls/index.tsx +15 -11
  161. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  162. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  163. package/src/components/media-editor-modal/index.tsx +1 -1
  164. package/src/components/media-editor-modal/style.scss +1 -1
  165. package/src/components/media-form/index.tsx +7 -1
  166. package/src/components/media-preview/index.tsx +65 -23
  167. package/src/components/media-preview/style.scss +16 -2
  168. package/src/components/rotation-ruler/style.scss +9 -5
  169. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  170. package/src/state/README.md +32 -0
  171. package/src/state/aspect-ratio-presets.ts +37 -0
  172. package/src/state/composite-reducer.ts +42 -80
  173. package/src/state/index.ts +2 -17
  174. package/src/state/types.ts +18 -72
  175. package/src/state/use-media-editor-state.ts +155 -238
  176. package/src/style.scss +2 -1
  177. package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
  178. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
  179. package/build/image-editor/core/camera.cjs +0 -225
  180. package/build/image-editor/core/camera.cjs.map +0 -7
  181. package/build/image-editor/core/constants.cjs +0 -108
  182. package/build/image-editor/core/constants.cjs.map +0 -7
  183. package/build/image-editor/core/containment.cjs +0 -276
  184. package/build/image-editor/core/containment.cjs.map +0 -7
  185. package/build/image-editor/core/crop-rect.cjs +0 -48
  186. package/build/image-editor/core/crop-rect.cjs.map +0 -7
  187. package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
  188. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
  189. package/build/image-editor/core/index.cjs +0 -62
  190. package/build/image-editor/core/index.cjs.map +0 -7
  191. package/build/image-editor/core/interaction-controller.cjs +0 -654
  192. package/build/image-editor/core/interaction-controller.cjs.map +0 -7
  193. package/build/image-editor/core/math/rotation.cjs +0 -41
  194. package/build/image-editor/core/math/rotation.cjs.map +0 -7
  195. package/build/image-editor/core/math/sanitize.cjs +0 -92
  196. package/build/image-editor/core/math/sanitize.cjs.map +0 -7
  197. package/build/image-editor/core/setter-helpers.cjs +0 -64
  198. package/build/image-editor/core/setter-helpers.cjs.map +0 -7
  199. package/build/image-editor/core/source-region.cjs +0 -206
  200. package/build/image-editor/core/source-region.cjs.map +0 -7
  201. package/build/image-editor/core/state.cjs +0 -283
  202. package/build/image-editor/core/state.cjs.map +0 -7
  203. package/build/image-editor/core/stencil-math.cjs +0 -216
  204. package/build/image-editor/core/stencil-math.cjs.map +0 -7
  205. package/build/image-editor/core/transform-style.cjs +0 -52
  206. package/build/image-editor/core/transform-style.cjs.map +0 -7
  207. package/build/image-editor/core/transforms/pipeline.cjs +0 -43
  208. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
  209. package/build/image-editor/core/types.cjs +0 -19
  210. package/build/image-editor/core/types.cjs.map +0 -7
  211. package/build/image-editor/core/viewport-state.cjs +0 -50
  212. package/build/image-editor/core/viewport-state.cjs.map +0 -7
  213. package/build/image-editor/index.cjs +0 -67
  214. package/build/image-editor/index.cjs.map +0 -7
  215. package/build/image-editor/react/components/cropper-provider.cjs +0 -50
  216. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
  217. package/build/image-editor/react/components/cropper.cjs +0 -722
  218. package/build/image-editor/react/components/cropper.cjs.map +0 -7
  219. package/build/image-editor/react/components/index.cjs +0 -36
  220. package/build/image-editor/react/components/index.cjs.map +0 -7
  221. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
  222. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
  223. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
  224. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
  225. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
  226. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
  227. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
  228. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
  229. package/build/image-editor/react/components/viewport-provider.cjs +0 -51
  230. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
  231. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
  232. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
  233. package/build/image-editor/react/hooks/index.cjs +0 -34
  234. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  235. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
  236. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
  237. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  238. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  239. package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
  240. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
  241. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
  242. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
  243. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
  244. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
  245. package/build/image-editor/react/visually-hidden-style.cjs +0 -41
  246. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
  247. package/build/index.cjs.map +0 -7
  248. package/build/state/index.cjs.map +0 -7
  249. package/build/utils/index.cjs.map +0 -7
  250. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
  251. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
  252. package/build-module/image-editor/core/camera.mjs +0 -198
  253. package/build-module/image-editor/core/camera.mjs.map +0 -7
  254. package/build-module/image-editor/core/constants.mjs +0 -69
  255. package/build-module/image-editor/core/constants.mjs.map +0 -7
  256. package/build-module/image-editor/core/containment.mjs +0 -253
  257. package/build-module/image-editor/core/containment.mjs.map +0 -7
  258. package/build-module/image-editor/core/crop-rect.mjs +0 -23
  259. package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
  260. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
  261. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
  262. package/build-module/image-editor/core/index.mjs +0 -36
  263. package/build-module/image-editor/core/index.mjs.map +0 -7
  264. package/build-module/image-editor/core/interaction-controller.mjs +0 -635
  265. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
  266. package/build-module/image-editor/core/math/rotation.mjs +0 -15
  267. package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
  268. package/build-module/image-editor/core/math/sanitize.mjs +0 -63
  269. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
  270. package/build-module/image-editor/core/setter-helpers.mjs +0 -39
  271. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
  272. package/build-module/image-editor/core/source-region.mjs +0 -178
  273. package/build-module/image-editor/core/source-region.mjs.map +0 -7
  274. package/build-module/image-editor/core/state.mjs +0 -260
  275. package/build-module/image-editor/core/state.mjs.map +0 -7
  276. package/build-module/image-editor/core/stencil-math.mjs +0 -187
  277. package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
  278. package/build-module/image-editor/core/transform-style.mjs +0 -27
  279. package/build-module/image-editor/core/transform-style.mjs.map +0 -7
  280. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
  281. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
  282. package/build-module/image-editor/core/types.mjs +0 -1
  283. package/build-module/image-editor/core/types.mjs.map +0 -7
  284. package/build-module/image-editor/core/viewport-state.mjs +0 -24
  285. package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
  286. package/build-module/image-editor/index.mjs +0 -39
  287. package/build-module/image-editor/index.mjs.map +0 -7
  288. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
  289. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
  290. package/build-module/image-editor/react/components/cropper.mjs +0 -704
  291. package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
  292. package/build-module/image-editor/react/components/index.mjs +0 -9
  293. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  294. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
  295. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
  296. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
  297. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
  298. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
  299. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
  300. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
  301. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
  302. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
  303. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
  304. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
  305. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
  306. package/build-module/image-editor/react/hooks/index.mjs +0 -8
  307. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  308. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
  309. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
  310. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  311. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  312. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
  313. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
  314. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
  315. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
  316. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
  317. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
  318. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
  319. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
  320. package/build-module/index.mjs.map +0 -7
  321. package/build-module/state/index.mjs.map +0 -7
  322. package/build-module/utils/index.mjs.map +0 -7
  323. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
  324. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  325. package/build-types/image-editor/core/camera.d.ts +0 -128
  326. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  327. package/build-types/image-editor/core/constants.d.ts +0 -99
  328. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  329. package/build-types/image-editor/core/containment.d.ts +0 -72
  330. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  331. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  332. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  333. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  334. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  335. package/build-types/image-editor/core/index.d.ts +0 -10
  336. package/build-types/image-editor/core/index.d.ts.map +0 -1
  337. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  338. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  339. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  340. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  341. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  342. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  343. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  344. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  345. package/build-types/image-editor/core/source-region.d.ts +0 -94
  346. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  347. package/build-types/image-editor/core/state.d.ts +0 -51
  348. package/build-types/image-editor/core/state.d.ts.map +0 -1
  349. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  350. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  351. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  352. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  353. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  354. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  355. package/build-types/image-editor/core/types.d.ts +0 -269
  356. package/build-types/image-editor/core/types.d.ts.map +0 -1
  357. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  358. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  359. package/build-types/image-editor/index.d.ts +0 -16
  360. package/build-types/image-editor/index.d.ts.map +0 -1
  361. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  362. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  363. package/build-types/image-editor/react/components/cropper.d.ts +0 -63
  364. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  365. package/build-types/image-editor/react/components/index.d.ts +0 -4
  366. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  367. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  368. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  369. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  370. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  371. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  372. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  373. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  374. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  375. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  376. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  377. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  378. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  379. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  380. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  381. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  382. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  383. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
  384. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  385. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  386. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  387. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  388. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  389. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  390. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  391. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  392. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  393. package/src/components/media-editor-modal/build-modifiers.ts +0 -161
  394. package/src/image-editor/README.md +0 -61
  395. package/src/image-editor/core/camera.ts +0 -429
  396. package/src/image-editor/core/constants.ts +0 -150
  397. package/src/image-editor/core/containment.ts +0 -469
  398. package/src/image-editor/core/crop-rect.ts +0 -42
  399. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  400. package/src/image-editor/core/index.ts +0 -47
  401. package/src/image-editor/core/interaction-controller.ts +0 -976
  402. package/src/image-editor/core/math/rotation.ts +0 -26
  403. package/src/image-editor/core/math/sanitize.ts +0 -155
  404. package/src/image-editor/core/setter-helpers.ts +0 -63
  405. package/src/image-editor/core/source-region.ts +0 -367
  406. package/src/image-editor/core/state.ts +0 -484
  407. package/src/image-editor/core/stencil-math.ts +0 -379
  408. package/src/image-editor/core/transform-style.ts +0 -56
  409. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  410. package/src/image-editor/core/types.ts +0 -230
  411. package/src/image-editor/core/viewport-state.ts +0 -30
  412. package/src/image-editor/docs/architecture.md +0 -63
  413. package/src/image-editor/docs/recipes.md +0 -184
  414. package/src/image-editor/index.ts +0 -52
  415. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  416. package/src/image-editor/react/components/cropper.scss +0 -259
  417. package/src/image-editor/react/components/cropper.tsx +0 -1116
  418. package/src/image-editor/react/components/index.ts +0 -3
  419. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  420. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  421. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  422. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  423. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  424. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  425. package/src/image-editor/react/hooks/index.ts +0 -4
  426. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  427. package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
  428. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  429. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  430. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  431. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  432. package/src/image-editor/style.scss +0 -1
@@ -1,1116 +0,0 @@
1
- import clsx from 'clsx';
2
- import {
3
- useState,
4
- useCallback,
5
- useMemo,
6
- useRef,
7
- useEffect,
8
- useLayoutEffect,
9
- useId,
10
- forwardRef,
11
- } from '@wordpress/element';
12
- import { __ } from '@wordpress/i18n';
13
- import type {
14
- CropperState,
15
- HandlePosition,
16
- StencilProps,
17
- Size,
18
- NormalizedRect,
19
- } from '../../core/types';
20
- import type { CropperController } from '../hooks/use-cropper-reducer';
21
- import { getImageFit, getRotatedBBox, getViewScale } from '../../core/camera';
22
- import { getImageCropBounds, getMinZoom } from '../../core/containment';
23
- import {
24
- MAX_VIEW_SCALE,
25
- PIXEL_SNAP_DISPLAY_SCALE,
26
- SETTLE_TARGET_CANVAS_FILL,
27
- } from '../../core/constants';
28
- import { computeInscribedRect } from '../../core/crop-rect';
29
- import { getMinCropPixels } from '../../core/stencil-math';
30
- import { useInteraction } from '../hooks/use-interaction';
31
- import { useTransformStyle } from '../hooks/use-transform-style';
32
- import { useAriaAnnouncer } from '../hooks/use-aria-announcer';
33
- import { RectangleStencil } from './stencils/rectangle-stencil';
34
- import { DimmingOverlay } from './overlays/dimming-overlay';
35
- import { GridOverlay } from './overlays/grid-overlay';
36
- import { DimensionsOverlay } from './overlays/dimensions-overlay';
37
- import {
38
- getSourceRegion,
39
- snapCropRectToSourcePixelGrid,
40
- snapCropRectToSourcePixels,
41
- } from '../../core/source-region';
42
- import { ViewportProvider, useViewport } from './viewport-provider';
43
- import { VISUALLY_HIDDEN_STYLE } from '../visually-hidden-style';
44
-
45
- /** Threshold for comparing normalized crop rect values. */
46
- const CROP_RECT_EPSILON = 1e-6;
47
- /** Threshold for deciding whether rotation is at a 90-degree stop. */
48
- const CARDINAL_ROTATION_EPSILON = 1e-6;
49
- /** Duration of the settle transform transition after resize end. */
50
- const SETTLE_TRANSITION_DURATION_MS = 200;
51
- // Fallback timer for when the computed transform is unchanged and no
52
- // `transitionend` fires. Sits past the CSS duration so it only wins the race
53
- // when the transition genuinely never runs.
54
- const SETTLE_TRANSITION_FALLBACK_MS = SETTLE_TRANSITION_DURATION_MS + 100;
55
- const SETTLE_TRANSFORM_TRANSITION = `transform ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`;
56
- const SETTLE_STENCIL_TRANSITION = [
57
- `left ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,
58
- `top ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,
59
- `width ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,
60
- `height ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,
61
- ].join( ', ' );
62
-
63
- /**
64
- * Props for the Cropper component.
65
- */
66
- export interface CropperProps {
67
- /** Image source URL. */
68
- src: string;
69
- /** The cropper controller from `useCropperReducer` or a composite store. */
70
- controller: CropperController;
71
- /** Stencil component for the crop area. Defaults to RectangleStencil. */
72
- stencil?: React.ComponentType< StencilProps >;
73
- /** Show the rule-of-thirds grid overlay, or only during interactions. */
74
- showGrid?: boolean | 'interactive';
75
- /** Whether external placement activity should keep the grid visible. */
76
- isPlacementActive?: boolean;
77
- /** Show the dimming overlay outside the crop area. */
78
- showDimming?: boolean;
79
- /** Show the live output dimensions tooltip during a resize. */
80
- showDimensions?: boolean;
81
- /** Minimum zoom level override. Defaults to the coverage-aware minimum. */
82
- minZoom?: number;
83
- /** Maximum zoom level. */
84
- maxZoom?: number;
85
- /** Fixed aspect ratio (width / height) in pixel space for the crop area. */
86
- aspectRatio?: number;
87
- /**
88
- * Enable freeform crop mode with resizable handles.
89
- * When false (default), the crop area is fixed and centered.
90
- * When true, the crop area has resize handles and can be freely repositioned.
91
- */
92
- freeformCrop?: boolean;
93
- /** Focus the crop area when the cropper mounts. */
94
- focusOnMount?: boolean;
95
- /**
96
- * Ignore all crop interaction: pointer drags, wheel zoom, keyboard
97
- * pan/zoom and the stencil's resize handles. Any gesture already in
98
- * flight is cancelled. Used while the edit is being saved, so the
99
- * modifiers sent to the server cannot change after the request starts.
100
- */
101
- disabled?: boolean;
102
- /** Callback fired when the image is loaded. */
103
- onImageLoaded?: ( size: Size ) => void;
104
- /**
105
- * Callback fired on every state change. Fires at pointermove rate
106
- * during drags, so keep the handler light — no heavy work, no
107
- * expensive parent re-renders. For commit-style events (drag end,
108
- * settled crop), use `onGestureEnd` instead.
109
- *
110
- * Useful for lightweight syncing with external tools, analytics,
111
- * or AI agents. Receives the full state so consumers can derive
112
- * whatever they need.
113
- */
114
- onStateChange?: ( state: CropperState ) => void;
115
- /** Fires when a continuous gesture begins (pan drag, handle resize, pinch zoom). */
116
- onGestureStart?: () => void;
117
- /** Fires when a continuous gesture ends (pointerup, resize settle). */
118
- onGestureEnd?: () => void;
119
- /** Additional className for the container. */
120
- className?: string;
121
- }
122
-
123
- /**
124
- * The main image cropper component.
125
- *
126
- * Renders an image within a container with interactive crop overlays.
127
- * Creates the camera once per render via getImageFit, then passes
128
- * derived values to stencil, overlays, and interaction hooks.
129
- *
130
- * The component fills its parent container (100% width and height).
131
- * Wrap it in a sized container to control its dimensions.
132
- *
133
- * @param root0 Component props implementing CropperProps.
134
- * @param root0.src Image source URL.
135
- * @param root0.controller The cropper controller from `useCropperReducer` or a composite store.
136
- * @param root0.stencil Custom stencil component.
137
- * @param root0.showGrid Grid overlay mode: false | true | 'interactive'.
138
- * @param root0.isPlacementActive Keep grid visible during external placement activity.
139
- * @param root0.showDimming Show dimming overlay outside crop.
140
- * @param root0.showDimensions Show live dimensions tooltip during resize.
141
- * @param root0.minZoom Minimum zoom level override.
142
- * @param root0.maxZoom Maximum zoom level.
143
- * @param root0.aspectRatio Fixed aspect ratio (width/height).
144
- * @param root0.freeformCrop Enable resize handles.
145
- * @param root0.focusOnMount Focus the crop area on mount.
146
- * @param root0.disabled Ignore all crop interaction.
147
- * @param root0.onImageLoaded Image load callback.
148
- * @param root0.onStateChange Every-frame state callback.
149
- * @param root0.onGestureStart Gesture boundary start.
150
- * @param root0.onGestureEnd Gesture boundary end.
151
- * @param root0.className Additional CSS class.
152
- * @param ref Forwarded ref for the container div.
153
- */
154
- function CropperInner(
155
- {
156
- src,
157
- controller,
158
- stencil: StencilComponent = RectangleStencil,
159
- showGrid = false,
160
- isPlacementActive = false,
161
- showDimming = true,
162
- showDimensions = true,
163
- minZoom,
164
- maxZoom,
165
- aspectRatio,
166
- freeformCrop = false,
167
- focusOnMount = false,
168
- disabled = false,
169
- onImageLoaded,
170
- onStateChange,
171
- onGestureStart,
172
- onGestureEnd,
173
- className,
174
- }: CropperProps,
175
- ref: React.ForwardedRef< HTMLDivElement >
176
- ) {
177
- const {
178
- state,
179
- setImage,
180
- setCropRect,
181
- settleCrop,
182
- setVisualSize,
183
- adjustCropRectForViewport,
184
- } = controller;
185
- const {
186
- viewport: viewportState,
187
- setViewportPan,
188
- resetViewport,
189
- } = useViewport();
190
- // Canvas measurement via ResizeObserver. The canvas is the inner
191
- // positioning context for image/stencil/handles — inset from the root
192
- // by the handle gutter, so crop math operates on the reduced box.
193
- const canvasRef = useRef< HTMLDivElement >( null );
194
- const cropAreaDescriptionId = useId();
195
- const [ isCropAreaFocused, setIsCropAreaFocused ] =
196
- useState( focusOnMount );
197
- const [ isFocusVisible, setIsFocusVisible ] = useState( false );
198
- const [ canvasSize, setCanvasSize ] = useState< Size >( {
199
- width: 0,
200
- height: 0,
201
- } );
202
-
203
- useLayoutEffect( () => {
204
- if ( focusOnMount ) {
205
- canvasRef.current?.focus( { preventScroll: true } );
206
- }
207
- }, [ focusOnMount ] );
208
-
209
- const handleCropAreaFocus = useCallback(
210
- ( event: React.FocusEvent< HTMLDivElement > ) => {
211
- const target = event.target as HTMLElement;
212
- if ( target === event.currentTarget ) {
213
- setIsCropAreaFocused( true );
214
- }
215
- // Show the outline only when focus arrived via keyboard
216
- // navigation. relatedTarget is null for pointer-initiated and
217
- // cross-window focus, so it reliably excludes those cases
218
- // without needing a separate ref or flag. Applies to focus
219
- // arriving on the canvas itself or on a descendant handle.
220
- if (
221
- event.relatedTarget !== null &&
222
- target.matches( ':focus-visible' )
223
- ) {
224
- setIsFocusVisible( true );
225
- }
226
- },
227
- []
228
- );
229
-
230
- const handleCropAreaBlur = useCallback(
231
- ( event: React.FocusEvent< HTMLDivElement > ) => {
232
- if ( event.target === event.currentTarget ) {
233
- setIsCropAreaFocused( false );
234
- }
235
- // Reset keyboard-active styling only when focus leaves the
236
- // cropper entirely. Moves between the canvas and a handle (or
237
- // between handles) keep the keyboard-active state intact.
238
- if (
239
- ! event.currentTarget.contains(
240
- event.relatedTarget as Node | null
241
- )
242
- ) {
243
- setIsFocusVisible( false );
244
- }
245
- },
246
- []
247
- );
248
-
249
- useEffect( () => {
250
- const element = canvasRef.current;
251
- if ( ! element ) {
252
- return;
253
- }
254
- const observer = new ResizeObserver( ( entries ) => {
255
- for ( const entry of entries ) {
256
- const { width, height } = entry.contentRect;
257
- setCanvasSize( ( prev ) => {
258
- if ( prev.width === width && prev.height === height ) {
259
- return prev;
260
- }
261
- return { width, height };
262
- } );
263
- }
264
- } );
265
- observer.observe( element );
266
- return () => {
267
- observer.disconnect();
268
- };
269
- }, [] );
270
-
271
- // Notify consumer of state changes.
272
- useEffect( () => {
273
- onStateChange?.( state );
274
- }, [ state, onStateChange ] );
275
-
276
- // ARIA announcements: announce significant state changes for screen readers
277
- // via the centralized @wordpress/a11y speak() API called inside the hook.
278
- useAriaAnnouncer( state );
279
-
280
- // Compute fitted image dimensions and visual bounds from camera math.
281
- const naturalWidth = state.image?.naturalWidth ?? 0;
282
- const naturalHeight = state.image?.naturalHeight ?? 0;
283
- const { elementSize, visualSize } = useMemo(
284
- () =>
285
- getImageFit(
286
- canvasSize,
287
- { width: naturalWidth, height: naturalHeight },
288
- state.rotation
289
- ),
290
- [ canvasSize, naturalWidth, naturalHeight, state.rotation ]
291
- );
292
-
293
- // Report the rendered image size to the controller. Composite
294
- // controllers need it to compute aspect-ratio reshapes from the
295
- // reducer (the dropdown dispatches without DOM access); pure
296
- // controllers ignore it.
297
- useEffect( () => {
298
- setVisualSize( visualSize );
299
- }, [ visualSize, setVisualSize ] );
300
-
301
- // In fixed-crop mode, auto-size the crop rect only when a fixed
302
- // aspect ratio is selected. With "Free" selected, turning freeform
303
- // handles off should preserve the user's current unconstrained
304
- // crop. Uses `adjustCropRectForViewport` so window-resize-driven
305
- // reshapes don't create undo entries (composite controller); the
306
- // dedup at lines below avoids redundant dispatches when the
307
- // reducer has already updated the cropRect for an aspect change.
308
- useEffect( () => {
309
- if (
310
- freeformCrop ||
311
- visualSize.width === 0 ||
312
- visualSize.height === 0 ||
313
- ! aspectRatio ||
314
- aspectRatio <= 0
315
- ) {
316
- return;
317
- }
318
- const rect = computeInscribedRect( aspectRatio, visualSize );
319
- const current = state.cropRect;
320
- if (
321
- Math.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&
322
- Math.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&
323
- Math.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&
324
- Math.abs( current.height - rect.height ) < CROP_RECT_EPSILON
325
- ) {
326
- return;
327
- }
328
- adjustCropRectForViewport( rect );
329
- }, [
330
- freeformCrop,
331
- aspectRatio,
332
- visualSize,
333
- adjustCropRectForViewport,
334
- state.cropRect,
335
- ] );
336
-
337
- // In freeform mode, when aspectRatio changes, reshape the crop to
338
- // the largest inscribed rect of the new ratio. Bails out when the
339
- // cropRect already matches the inscribed rect — composite stores
340
- // reshape atomically inside the reducer, so this effect is a
341
- // no-op there.
342
- const prevAspectRatioRef = useRef( aspectRatio );
343
- useEffect( () => {
344
- if ( prevAspectRatioRef.current === aspectRatio ) {
345
- return;
346
- }
347
- prevAspectRatioRef.current = aspectRatio;
348
-
349
- if (
350
- ! freeformCrop ||
351
- visualSize.width === 0 ||
352
- visualSize.height === 0 ||
353
- ! aspectRatio ||
354
- aspectRatio <= 0
355
- ) {
356
- return;
357
- }
358
- const rect = computeInscribedRect( aspectRatio, visualSize );
359
- const current = state.cropRect;
360
- if (
361
- Math.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&
362
- Math.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&
363
- Math.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&
364
- Math.abs( current.height - rect.height ) < CROP_RECT_EPSILON
365
- ) {
366
- return;
367
- }
368
- adjustCropRectForViewport( rect );
369
- }, [
370
- aspectRatio,
371
- freeformCrop,
372
- visualSize,
373
- adjustCropRectForViewport,
374
- state.cropRect,
375
- ] );
376
-
377
- // Compute the crop handle bounds from the actual image footprint.
378
- // Depends on the full state object because getImageCropBounds reads
379
- // crop, zoom, rotation, flip, and image. React Compiler requires
380
- // the complete dependency; the computation is lightweight (a few
381
- // trig ops + 4 corner transforms).
382
- const cropBounds = useMemo( () => {
383
- if ( ! state.image || elementSize.width === 0 ) {
384
- return undefined;
385
- }
386
- return getImageCropBounds( state, elementSize, visualSize );
387
- }, [ state, elementSize, visualSize ] );
388
- const effectiveMinZoom =
389
- minZoom !== undefined ? minZoom : getMinZoom( state );
390
- const [ isResizing, setIsResizing ] = useState( false );
391
- const isResizingRef = useRef( false );
392
- const isSettlingRef = useRef( false );
393
- const [ isTouchPinching, setIsTouchPinchingState ] = useState( false );
394
- const isTouchPinchingRef = useRef( false );
395
- const setTouchPinching = useCallback( ( isPinching: boolean ) => {
396
- isTouchPinchingRef.current = isPinching;
397
- setIsTouchPinchingState( isPinching );
398
- }, [] );
399
- // Direction of the handle the user is currently resizing — pointer or
400
- // keyboard. `null` outside of an active resize. Drives the live
401
- // dimensions tooltip overlay.
402
- const [ activeHandle, setActiveHandle ] = useState< HandlePosition | null >(
403
- null
404
- );
405
-
406
- // Presentational magnification so the at-rest crop fills the canvas. The
407
- // crop overlay is laid out as `cropRect * visualSize` (the contain-fit
408
- // footprint, no zoom), so a crop whose aspect differs from the image's can
409
- // render far smaller than the canvas allows. Scaling `elementSize` and
410
- // `visualSize` together magnifies the whole scene uniformly — image,
411
- // overlays, and the pixel->normalized interaction math — and the root's
412
- // `overflow: hidden` clips the image bleed. Magnifying around the footprint
413
- // centre keeps the crop centred only because the at-rest crop is always
414
- // centred (SETTLE_CROP, computeInscribedRect, and the initial full-frame
415
- // crop all centre it).
416
- const viewScaleRest = useMemo(
417
- () =>
418
- getViewScale(
419
- state.cropRect,
420
- canvasSize,
421
- visualSize,
422
- SETTLE_TARGET_CANVAS_FILL,
423
- MAX_VIEW_SCALE
424
- ),
425
- [ state.cropRect, canvasSize, visualSize ]
426
- );
427
- // During a resize the magnification is frozen at its pre-drag value rather
428
- // than recomputed per pointer move: recomputing live would zoom the scene
429
- // under the cursor, and snapping to 1 would reset the zoom the moment a
430
- // handle is grabbed. `handleResizeStart` snapshots the current rest value
431
- // into `frozenViewScale`; on release the settle recomputes from the new crop.
432
- const [ frozenViewScale, setFrozenViewScale ] = useState( 1 );
433
- const viewScale = isResizing ? frozenViewScale : viewScaleRest;
434
- const scaledVisualSize = useMemo(
435
- () => ( {
436
- width: visualSize.width * viewScale,
437
- height: visualSize.height * viewScale,
438
- } ),
439
- [ visualSize.width, visualSize.height, viewScale ]
440
- );
441
- // CSS pixels rendered per source pixel: the contain fit
442
- // (elementSize / natural), times zoom and the view-scale magnification.
443
- const displayScale =
444
- naturalWidth > 0
445
- ? ( elementSize.width / naturalWidth ) * state.zoom * viewScale
446
- : 0;
447
- const keyboardResizeStep = useMemo( () => {
448
- if (
449
- displayScale < PIXEL_SNAP_DISPLAY_SCALE ||
450
- ( aspectRatio && aspectRatio > 0 ) ||
451
- naturalWidth <= 0 ||
452
- naturalHeight <= 0
453
- ) {
454
- return undefined;
455
- }
456
- const snapRotation = Math.round( state.rotation / 90 ) * 90;
457
- if (
458
- Math.abs( state.rotation - snapRotation ) >=
459
- CARDINAL_ROTATION_EPSILON
460
- ) {
461
- return undefined;
462
- }
463
- const bbox = getRotatedBBox(
464
- naturalWidth,
465
- naturalHeight,
466
- snapRotation
467
- );
468
- if ( bbox.width <= 0 || bbox.height <= 0 ) {
469
- return undefined;
470
- }
471
- // Keyboard steps are normalized crop-space deltas, but snapping wants
472
- // one source pixel per key press. The normalized delta for one source
473
- // pixel is different on each axis when the snap-rotation bbox is not
474
- // square, so this must be an object with separate width/height steps
475
- // instead of a single scalar.
476
- return {
477
- width: state.zoom / bbox.width,
478
- height: state.zoom / bbox.height,
479
- };
480
- }, [
481
- displayScale,
482
- aspectRatio,
483
- naturalWidth,
484
- naturalHeight,
485
- state.rotation,
486
- state.zoom,
487
- ] );
488
-
489
- // Per-axis minimum crop size in normalized space, expressing a pixel floor
490
- // on the captured source region. cropRect is normalized in the viewport's
491
- // snap-rotation bbox; the captured source-pixel width is
492
- // `cropRect.width * bbox.width / zoom`, so the normalized floor scales with
493
- // `zoom` to keep the source-pixel floor constant. The floor itself adapts to
494
- // the on-screen display scale (fit × zoom × view scale) via
495
- // `getMinCropPixels`, so on a large image shown small the crop can't shrink
496
- // until the handles collapse — it yields to the 24px source floor only once
497
- // the image is shown large enough.
498
- const minCropSize: Size | undefined = useMemo( () => {
499
- if ( naturalWidth <= 0 || naturalHeight <= 0 ) {
500
- return undefined;
501
- }
502
- const snapRotation = Math.round( state.rotation / 90 ) * 90;
503
- const bbox = getRotatedBBox(
504
- naturalWidth,
505
- naturalHeight,
506
- snapRotation
507
- );
508
- const minPixels = getMinCropPixels( displayScale );
509
- return {
510
- width: Math.min( 1, ( minPixels * state.zoom ) / bbox.width ),
511
- height: Math.min( 1, ( minPixels * state.zoom ) / bbox.height ),
512
- };
513
- }, [
514
- naturalWidth,
515
- naturalHeight,
516
- state.rotation,
517
- state.zoom,
518
- displayScale,
519
- ] );
520
-
521
- const snapCropRect = useCallback(
522
- ( rect: NormalizedRect, handle: HandlePosition ): NormalizedRect => {
523
- if (
524
- displayScale < PIXEL_SNAP_DISPLAY_SCALE ||
525
- naturalWidth <= 0 ||
526
- naturalHeight <= 0
527
- ) {
528
- return rect;
529
- }
530
- return snapCropRectToSourcePixels(
531
- state,
532
- { width: naturalWidth, height: naturalHeight },
533
- rect,
534
- handle
535
- );
536
- },
537
- [ displayScale, naturalWidth, naturalHeight, state ]
538
- );
539
-
540
- const wasPixelSnapEnabledRef = useRef( false );
541
- useEffect( () => {
542
- const isPixelSnapEnabled =
543
- freeformCrop &&
544
- ( ! aspectRatio || aspectRatio <= 0 ) &&
545
- displayScale >= PIXEL_SNAP_DISPLAY_SCALE &&
546
- naturalWidth > 0 &&
547
- naturalHeight > 0;
548
- const wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;
549
- wasPixelSnapEnabledRef.current = isPixelSnapEnabled;
550
-
551
- if ( ! isPixelSnapEnabled || wasPixelSnapEnabled ) {
552
- return;
553
- }
554
-
555
- const snappedCropRect = snapCropRectToSourcePixelGrid(
556
- state,
557
- { width: naturalWidth, height: naturalHeight },
558
- state.cropRect
559
- );
560
- const currentCropRect = state.cropRect;
561
- if (
562
- Math.abs( currentCropRect.x - snappedCropRect.x ) <
563
- CROP_RECT_EPSILON &&
564
- Math.abs( currentCropRect.y - snappedCropRect.y ) <
565
- CROP_RECT_EPSILON &&
566
- Math.abs( currentCropRect.width - snappedCropRect.width ) <
567
- CROP_RECT_EPSILON &&
568
- Math.abs( currentCropRect.height - snappedCropRect.height ) <
569
- CROP_RECT_EPSILON
570
- ) {
571
- return;
572
- }
573
-
574
- // The display scale crossing the threshold is not an edit, so the
575
- // snap must not record an undo entry. Recording it here would also
576
- // clear the redo stack whenever an undo or redo crosses it.
577
- adjustCropRectForViewport( snappedCropRect );
578
- }, [
579
- adjustCropRectForViewport,
580
- aspectRatio,
581
- displayScale,
582
- freeformCrop,
583
- naturalWidth,
584
- naturalHeight,
585
- state,
586
- ] );
587
-
588
- // Use the interaction hook for mouse, touch, and keyboard events.
589
- const {
590
- handlers,
591
- onWheelNative,
592
- isDragging,
593
- isZooming,
594
- isPlacementActive: isInteractionPlacementActive,
595
- } = useInteraction( state, controller, canvasSize, scaledVisualSize, {
596
- minZoom: effectiveMinZoom,
597
- maxZoom,
598
- onGestureStart,
599
- onGestureEnd,
600
- disabled,
601
- } );
602
-
603
- // Compose focus-visibility tracking into the canvas event handlers.
604
- // Kept as a spread rather than explicit props to avoid triggering
605
- // jsx-a11y/no-noninteractive-element-interactions on role="group".
606
- //
607
- // The pointer/key tracking lives in the capture phase so it runs
608
- // before any child handler — handles call stopPropagation in their
609
- // own onPointerDown / onKeyDown, which would otherwise prevent the
610
- // keyboard-active state from updating when the user interacts with
611
- // a handle directly.
612
- const canvasHandlers = {
613
- ...handlers,
614
- onPointerDownCapture: () => {
615
- setIsFocusVisible( false );
616
- },
617
- onTouchStartCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {
618
- if ( event.touches.length > 1 ) {
619
- setTouchPinching( true );
620
- }
621
- },
622
- onTouchMoveCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {
623
- if ( event.touches.length > 1 ) {
624
- setTouchPinching( true );
625
- }
626
- },
627
- onTouchEndCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {
628
- if ( event.touches.length === 0 ) {
629
- setTouchPinching( false );
630
- }
631
- },
632
- onTouchCancelCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {
633
- if ( event.touches.length === 0 ) {
634
- setTouchPinching( false );
635
- }
636
- },
637
- onKeyDownCapture: ( event: React.KeyboardEvent< HTMLDivElement > ) => {
638
- // Modifier-only keypresses precede another key rather than
639
- // indicating deliberate keyboard interaction on their own.
640
- if (
641
- ! [ 'Shift', 'Control', 'Alt', 'Meta' ].includes( event.key )
642
- ) {
643
- setIsFocusVisible( true );
644
- }
645
- },
646
- onPointerDown: ( event: React.PointerEvent< HTMLDivElement > ) => {
647
- if (
648
- disabled ||
649
- isResizingRef.current ||
650
- isTouchPinchingRef.current ||
651
- ( event.pointerType === 'touch' && event.isPrimary === false )
652
- ) {
653
- event.preventDefault();
654
- return;
655
- }
656
- handlers.onPointerDown?.( event );
657
- // Re-assert false after handlers run — el.focus() inside the
658
- // handler fires onFocus, which may otherwise set it back to true.
659
- setIsFocusVisible( false );
660
- },
661
- };
662
-
663
- // Register wheel handler natively with { passive: false } so
664
- // preventDefault works. React's onWheel registers as passive. Bound
665
- // to the canvas (not the root) so pointer geometry inside the handler
666
- // resolves against the canvas box.
667
- useEffect( () => {
668
- const el = canvasRef.current;
669
- if ( ! el ) {
670
- return;
671
- }
672
- const handleWheel = ( event: WheelEvent ) => {
673
- // Block wheel zoom while resizing or settling — the stage CSS
674
- // transform changes getBoundingClientRect() during this window,
675
- // so focal-point math would resolve against the wrong center.
676
- if ( isResizingRef.current || isSettlingRef.current ) {
677
- event.preventDefault();
678
- return;
679
- }
680
- onWheelNative( event );
681
- };
682
- el.addEventListener( 'wheel', handleWheel, {
683
- passive: false,
684
- } );
685
- return () => {
686
- el.removeEventListener( 'wheel', handleWheel );
687
- };
688
- }, [ onWheelNative ] );
689
-
690
- // Use the unscaled contain-fit footprint here. `imageStyle` prepends
691
- // `scale(viewScale)` to this matrix, so pan translations are magnified with
692
- // the rest of the scene; using `scaledVisualSize` here would apply viewScale
693
- // to pan twice.
694
- const transformString = useTransformStyle( state, visualSize );
695
-
696
- /**
697
- * Handle the image load event.
698
- */
699
- const handleImageLoad = useCallback(
700
- ( event: React.SyntheticEvent< HTMLImageElement > ) => {
701
- const img = event.currentTarget;
702
- const size: Size = {
703
- width: img.naturalWidth,
704
- height: img.naturalHeight,
705
- };
706
-
707
- setImage( {
708
- src,
709
- naturalWidth: size.width,
710
- naturalHeight: size.height,
711
- } );
712
-
713
- onImageLoaded?.( size );
714
- },
715
- [ src, setImage, onImageLoaded ]
716
- );
717
-
718
- const handleCropChange = useCallback(
719
- ( rect: NormalizedRect ) => {
720
- if ( isTouchPinchingRef.current ) {
721
- return;
722
- }
723
- setCropRect( rect );
724
- // During a resize drag, pan the viewport so the handle stays
725
- // visible even when the crop extends beyond the canvas edge.
726
- if (
727
- isResizingRef.current &&
728
- scaledVisualSize.width > 0 &&
729
- scaledVisualSize.height > 0
730
- ) {
731
- const offsetX =
732
- ( canvasSize.width - scaledVisualSize.width ) / 2;
733
- const offsetY =
734
- ( canvasSize.height - scaledVisualSize.height ) / 2;
735
- const rightOverflow = Math.max(
736
- 0,
737
- offsetX +
738
- ( rect.x + rect.width ) * scaledVisualSize.width -
739
- canvasSize.width
740
- );
741
- const leftOverflow = Math.max(
742
- 0,
743
- -( offsetX + rect.x * scaledVisualSize.width )
744
- );
745
- const bottomOverflow = Math.max(
746
- 0,
747
- offsetY +
748
- ( rect.y + rect.height ) * scaledVisualSize.height -
749
- canvasSize.height
750
- );
751
- const topOverflow = Math.max(
752
- 0,
753
- -( offsetY + rect.y * scaledVisualSize.height )
754
- );
755
- setViewportPan( {
756
- x: -rightOverflow + leftOverflow,
757
- y: -bottomOverflow + topOverflow,
758
- } );
759
- }
760
- },
761
- [ setCropRect, setViewportPan, canvasSize, scaledVisualSize ]
762
- );
763
-
764
- // Settling animation: brief transition after resize end.
765
- const [ settling, setSettling ] = useState( false );
766
- const settleTimerRef = useRef<
767
- ReturnType< typeof setTimeout > | undefined
768
- >( undefined );
769
- const finishSettling = useCallback( () => {
770
- clearTimeout( settleTimerRef.current );
771
- isSettlingRef.current = false;
772
- setSettling( false );
773
- }, [] );
774
-
775
- // Clear the pending settle timer on unmount so it can't fire a
776
- // state update on an unmounted component.
777
- useEffect( () => {
778
- return () => {
779
- clearTimeout( settleTimerRef.current );
780
- };
781
- }, [] );
782
-
783
- const isInteractiveGrid = showGrid === 'interactive';
784
- const showInteractiveGrid =
785
- isInteractiveGrid &&
786
- ( isInteractionPlacementActive || isResizing || isPlacementActive );
787
-
788
- // Output crop size in source pixels — drives the live tooltip
789
- // overlay. Only computed during pointer drags, so the per-frame
790
- // state churn during pan/zoom doesn't pay for it.
791
- const outputSize = useMemo( () => {
792
- if ( ! showDimensions || ! activeHandle || ! state.image ) {
793
- return null;
794
- }
795
- const region = getSourceRegion( state, {
796
- width: state.image.naturalWidth,
797
- height: state.image.naturalHeight,
798
- } );
799
- return { width: region.width, height: region.height };
800
- }, [ showDimensions, activeHandle, state ] );
801
-
802
- /**
803
- * Handle Escape on a resize handle — return focus to the canvas so
804
- * arrow keys pan the image rather than resize.
805
- */
806
- const handleEscape = useCallback( () => {
807
- // Escape is always a keyboard action, so show the outline immediately
808
- // rather than relying on the focus handler's :focus-visible check.
809
- setIsFocusVisible( true );
810
- canvasRef.current?.focus( { preventScroll: true } );
811
- }, [] );
812
-
813
- const handleResizeStart = useCallback(
814
- ( handle?: HandlePosition ) => {
815
- if ( isTouchPinchingRef.current ) {
816
- return;
817
- }
818
- // Freeze the magnification at its current value so grabbing a
819
- // handle doesn't reset the zoom; it holds for the whole drag.
820
- setFrozenViewScale( viewScaleRest );
821
- isResizingRef.current = true;
822
- setIsResizing( true );
823
- setActiveHandle( handle ?? null );
824
- // Clear any in-flight settle so transitions don't apply during the
825
- // new drag (rapid successive resizes would otherwise inherit the
826
- // previous settle animation).
827
- finishSettling();
828
- resetViewport();
829
- onGestureStart?.();
830
- },
831
- [ finishSettling, onGestureStart, resetViewport, viewScaleRest ]
832
- );
833
-
834
- /**
835
- * Handle resize end — settle the crop rect (re-center, fill height)
836
- * and reset the viewport pan back to neutral.
837
- */
838
- const handleResizeEnd = useCallback( () => {
839
- const isCancellingForPinch = isTouchPinchingRef.current;
840
- isResizingRef.current = false;
841
- setIsResizing( false );
842
- setActiveHandle( null );
843
- clearTimeout( settleTimerRef.current );
844
-
845
- if ( isCancellingForPinch ) {
846
- // A pinch took over mid-resize. Tear down resize UI without
847
- // settling or firing onGestureEnd: the pinch owns the gesture
848
- // boundary and fires the end on its own touchend. The resize and
849
- // the pinch therefore collapse into a single undo step, since
850
- // `beginGesture` is idempotent and the snapshot captured at resize
851
- // start is flushed by the pinch's `endGesture`.
852
- finishSettling();
853
- resetViewport();
854
- return;
855
- }
856
-
857
- isSettlingRef.current = true;
858
- setSettling( true );
859
- // Reset viewport pan first so it transitions back to zero in sync
860
- // with the settle animation on the image.
861
- resetViewport();
862
- settleCrop();
863
- onGestureEnd?.();
864
- // Normal completion is driven by transitionend so settling cannot clear
865
- // before the browser has actually finished animating. Keep a fallback for
866
- // cases where the computed transform is unchanged and no event fires.
867
- settleTimerRef.current = setTimeout(
868
- finishSettling,
869
- SETTLE_TRANSITION_FALLBACK_MS
870
- );
871
- }, [ finishSettling, settleCrop, onGestureEnd, resetViewport ] );
872
-
873
- /**
874
- * Finish settling when the settle transform transition actually completes.
875
- * The handler lives on the stage, but in the common (un-panned) case the
876
- * transform transition runs on the image layer and its `transitionend`
877
- * bubbles up to here. Other transitionend events (stencil left/top/width/
878
- * height) also bubble up, so only the transform transition should clear the
879
- * settle state.
880
- */
881
- const handleSettleTransitionEnd = useCallback(
882
- ( event: React.TransitionEvent< HTMLDivElement > ) => {
883
- if (
884
- ! isSettlingRef.current ||
885
- event.propertyName !== 'transform'
886
- ) {
887
- return;
888
- }
889
- finishSettling();
890
- },
891
- [ finishSettling ]
892
- );
893
-
894
- let imageTransition: string | undefined;
895
- if ( settling ) {
896
- imageTransition = SETTLE_TRANSFORM_TRANSITION;
897
- } else if ( isZooming ) {
898
- imageTransition = 'transform 150ms linear';
899
- }
900
- const settleStencilTransition = settling
901
- ? SETTLE_STENCIL_TRANSITION
902
- : undefined;
903
-
904
- // Compute the image's CSS style. The element keeps its contain-fit box; the
905
- // view-scale magnification is folded into the transform as an outer
906
- // `scale()` so the whole settle motion (zoom, pan, and magnification) is one
907
- // coherent transform that interpolates as a unit — the image slides/scales
908
- // to its position rather than animating its box separately. Magnifying
909
- // around the centred box keeps the (centred) crop centred.
910
- const imageStyle = useMemo( (): React.CSSProperties => {
911
- if ( elementSize.width === 0 || elementSize.height === 0 ) {
912
- return {};
913
- }
914
- const centerX = ( canvasSize.width - elementSize.width ) / 2;
915
- const centerY = ( canvasSize.height - elementSize.height ) / 2;
916
- // Above 1:1 the image is upscaled, so render nearest-neighbour to keep
917
- // pixel boundaries crisp (e.g. small images the cropper magnifies);
918
- // below 1:1 leave smoothing on for downscaled large images.
919
- return {
920
- width: elementSize.width,
921
- height: elementSize.height,
922
- maxWidth: elementSize.width,
923
- maxHeight: elementSize.height,
924
- left: centerX,
925
- top: centerY,
926
- // Always lead with `scale()` (identity at rest) so the transform's
927
- // function list stays structurally constant across rest, resize, and
928
- // settle. A conditional that dropped `scale()` at viewScale === 1
929
- // would change the list shape exactly when the settle transition
930
- // crosses 1:1, forcing the browser to fall back to matrix-decomposition
931
- // interpolation instead of interpolating each function in turn.
932
- transform: `scale(${ viewScale }) ${ transformString }`,
933
- transition: imageTransition,
934
- imageRendering: displayScale > 1 ? 'pixelated' : undefined,
935
- };
936
- }, [
937
- canvasSize,
938
- elementSize,
939
- transformString,
940
- imageTransition,
941
- displayScale,
942
- viewScale,
943
- ] );
944
-
945
- // Viewport pan CSS transform for the stage div. Applied during resize
946
- // drags to keep handles visible when the crop extends past the canvas edge.
947
- // Transitions back to zero during the settle animation.
948
- // will-change promotes the stage to its own compositor layer while the
949
- // transform is active, keeping per-frame pan updates off the main thread.
950
- const settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : undefined;
951
- const willChange = isResizing || settling ? 'transform' : undefined;
952
- let stageStyle: React.CSSProperties | undefined;
953
- if ( viewportState.pan.x !== 0 || viewportState.pan.y !== 0 ) {
954
- stageStyle = {
955
- transform: `translate(${ viewportState.pan.x }px, ${ viewportState.pan.y }px)`,
956
- transition: settleTransition,
957
- willChange,
958
- };
959
- } else if ( settling ) {
960
- // Animate the viewport pan back to an explicit identity translate rather
961
- // than dropping the transform property, so the reset eases instead of
962
- // snapping (transitions to a removed transform are unreliable).
963
- stageStyle = {
964
- transform: 'translate(0px, 0px)',
965
- transition: settleTransition,
966
- willChange,
967
- };
968
- }
969
-
970
- return (
971
- <div
972
- ref={ ref }
973
- className={ clsx(
974
- 'wp-media-editor-image-editor',
975
- isDragging && 'wp-media-editor-image-editor--dragging',
976
- className
977
- ) }
978
- >
979
- { /*
980
- * The canvas is the interactive, inset surface. Handles and
981
- * the ARIA role/tabIndex live here so pointer geometry
982
- * (getBoundingClientRect on e.currentTarget) resolves against
983
- * the same box that crop math uses. The root stays as the
984
- * clipping shell for the dimming overlay's box-shadow.
985
- *
986
- * Not role="application" — that disables the screen reader's
987
- * normal keyboard interception, too heavy-handed for a single
988
- * widget. Screen reader users get the ARIA live region below
989
- * as the announcement channel.
990
- */ }
991
- <div
992
- ref={ canvasRef }
993
- className={ clsx(
994
- 'wp-media-editor-image-editor__canvas',
995
- isInteractiveGrid &&
996
- 'wp-media-editor-image-editor__canvas--grid-interactive',
997
- showInteractiveGrid &&
998
- 'wp-media-editor-image-editor__canvas--show-grid',
999
- settling &&
1000
- 'wp-media-editor-image-editor__canvas--settling',
1001
- // Marks the cropper as in keyboard-interaction mode.
1002
- // CSS uses :focus on the canvas to show the stencil
1003
- // outline and :focus on a handle to show its ring,
1004
- // so the class applies whenever any cropper element
1005
- // has keyboard focus.
1006
- isFocusVisible &&
1007
- 'wp-media-editor-image-editor__canvas--focus-visible'
1008
- ) }
1009
- tabIndex={ 0 }
1010
- role="group"
1011
- aria-label={ __( 'Crop area' ) }
1012
- aria-describedby={
1013
- isCropAreaFocused ? cropAreaDescriptionId : undefined
1014
- }
1015
- onFocus={ handleCropAreaFocus }
1016
- onBlur={ handleCropAreaBlur }
1017
- { ...canvasHandlers }
1018
- >
1019
- <div
1020
- id={ cropAreaDescriptionId }
1021
- style={ VISUALLY_HIDDEN_STYLE }
1022
- >
1023
- { __(
1024
- 'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'
1025
- ) }
1026
- </div>
1027
- { /*
1028
- * The stage is an inner full-size div that receives the
1029
- * viewport pan CSS transform. Keeping the transform here
1030
- * (rather than on the canvas) means the canvas always stays
1031
- * at its natural position, so the root div's background is
1032
- * never exposed when the stage is panned during a resize drag.
1033
- */ }
1034
- <div
1035
- className="wp-media-editor-image-editor__stage"
1036
- data-testid="cropper-stage"
1037
- style={ stageStyle }
1038
- onTransitionEnd={ handleSettleTransitionEnd }
1039
- >
1040
- { /* The image layer */ }
1041
- <img
1042
- className="wp-media-editor-image-editor__image"
1043
- data-testid="cropper-image"
1044
- src={ src }
1045
- alt=""
1046
- onLoad={ handleImageLoad }
1047
- style={ imageStyle }
1048
- draggable={ false }
1049
- />
1050
-
1051
- { /* Dimming overlay outside the crop area */ }
1052
- { showDimming && (
1053
- <DimmingOverlay
1054
- cropRect={ state.cropRect }
1055
- containerSize={ canvasSize }
1056
- imageSize={ scaledVisualSize }
1057
- transition={ settleStencilTransition }
1058
- />
1059
- ) }
1060
-
1061
- { /* The stencil (crop area with handles) */ }
1062
- <StencilComponent
1063
- cropRect={ state.cropRect }
1064
- containerSize={ canvasSize }
1065
- imageSize={ scaledVisualSize }
1066
- onCropChange={ handleCropChange }
1067
- onResizeStart={ handleResizeStart }
1068
- onResizeEnd={ handleResizeEnd }
1069
- onEscape={ handleEscape }
1070
- aspectRatio={ aspectRatio }
1071
- freeformCrop={ freeformCrop }
1072
- isResizeDisabled={ isTouchPinching || disabled }
1073
- stencilTransition={ settleStencilTransition }
1074
- cropBounds={ cropBounds }
1075
- minCropSize={ minCropSize }
1076
- snapCropRect={ snapCropRect }
1077
- keyboardResizeStep={ keyboardResizeStep }
1078
- />
1079
-
1080
- { /* Rule-of-thirds grid */ }
1081
- { ( showGrid === true || isInteractiveGrid ) && (
1082
- <GridOverlay
1083
- cropRect={ state.cropRect }
1084
- containerSize={ canvasSize }
1085
- imageSize={ scaledVisualSize }
1086
- />
1087
- ) }
1088
-
1089
- { /* Live dimensions tooltip pinned to the dragged handle. */ }
1090
- { activeHandle && outputSize && (
1091
- <DimensionsOverlay
1092
- cropRect={ state.cropRect }
1093
- containerSize={ canvasSize }
1094
- imageSize={ scaledVisualSize }
1095
- activeHandle={ activeHandle }
1096
- outputWidth={ outputSize.width }
1097
- outputHeight={ outputSize.height }
1098
- />
1099
- ) }
1100
- </div>
1101
- </div>
1102
- </div>
1103
- );
1104
- }
1105
-
1106
- const CropperInnerWithRef = forwardRef< HTMLDivElement, CropperProps >(
1107
- CropperInner
1108
- );
1109
-
1110
- export const Cropper = forwardRef< HTMLDivElement, CropperProps >(
1111
- ( props, ref ) => (
1112
- <ViewportProvider>
1113
- <CropperInnerWithRef { ...props } ref={ ref } />
1114
- </ViewportProvider>
1115
- )
1116
- );