@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
@@ -6,18 +6,12 @@ import {
6
6
  useState,
7
7
  } from '@wordpress/element';
8
8
  import {
9
- DEFAULT_STATE,
10
- ORIGINAL_ASPECT_RATIO,
11
- areCropperStatesEqual,
12
- buildCropperSetters,
13
- enforceContainment,
14
- exportCroppedImage,
15
- type CropperAction,
16
- type CropperController,
17
- type CropperState,
18
- type NormalizedRect,
19
- type Size,
20
- } from '../image-editor';
9
+ createImageEditorState,
10
+ useImageEditor,
11
+ type ImageEditorController,
12
+ type ImageEditorState,
13
+ } from '@wordpress/image-editor';
14
+ import { ORIGINAL_ASPECT_RATIO } from './aspect-ratio-presets';
21
15
  import {
22
16
  mediaEditorReducer,
23
17
  areMediaEditorStatesEqual,
@@ -33,35 +27,28 @@ import type {
33
27
 
34
28
  /**
35
29
  * Resolve an aspect-ratio preset value (the string the dropdown
36
- * round-trips) into a numeric width/height ratio for the cropper.
30
+ * round-trips) into a numeric width/height ratio for the image editor.
37
31
  *
38
32
  * - `'0'` → `undefined` (Free; no lock)
39
33
  * - `'-1'` (Original) → image's natural width / height, or `undefined`
40
34
  * if no image is loaded.
41
35
  * - Any positive decimal → the parsed number.
42
36
  *
43
- * Centralizing here means the dropdown, the action dispatcher, and
44
- * the test harness all resolve the same way.
45
- *
46
- * @param presetKey Preset value from the dropdown.
47
- * @param cropperImage The cropper's loaded image, or `null`.
37
+ * @param presetKey Preset value from the dropdown.
38
+ * @param image The image editor's loaded image, or `null`.
48
39
  * @return The resolved ratio, or `undefined` for Free / unresolvable.
49
40
  */
50
- export function resolveAspectRatio(
41
+ function resolveAspectRatio(
51
42
  presetKey: string,
52
- cropperImage: CropperState[ 'image' ] | null
43
+ image: ImageEditorState[ 'image' ] | null
53
44
  ): number | undefined {
54
45
  const num = parseFloat( presetKey );
55
46
  if ( num === 0 || Number.isNaN( num ) ) {
56
47
  return undefined;
57
48
  }
58
49
  if ( num === ORIGINAL_ASPECT_RATIO ) {
59
- if (
60
- cropperImage &&
61
- cropperImage.naturalWidth > 0 &&
62
- cropperImage.naturalHeight > 0
63
- ) {
64
- return cropperImage.naturalWidth / cropperImage.naturalHeight;
50
+ if ( image && image.naturalWidth > 0 && image.naturalHeight > 0 ) {
51
+ return image.naturalWidth / image.naturalHeight;
65
52
  }
66
53
  return undefined;
67
54
  }
@@ -71,9 +58,9 @@ export function resolveAspectRatio(
71
58
  return undefined;
72
59
  }
73
60
 
74
- function areCropperImagesEqual(
75
- a: CropperState[ 'image' ],
76
- b: CropperState[ 'image' ]
61
+ function areImagesEqual(
62
+ a: ImageEditorState[ 'image' ],
63
+ b: ImageEditorState[ 'image' ]
77
64
  ): boolean {
78
65
  return (
79
66
  a?.src === b?.src &&
@@ -88,25 +75,25 @@ function areCropperImagesEqual(
88
75
  * The session owns what is being edited and how: the source image,
89
76
  * every editing slice, the shared undo/redo history, gesture
90
77
  * boundaries, and whether the edits change the saved image. The
91
- * cropper is one participant in the session — `cropper` is a
92
- * geometry-only controller that a `<Cropper>` takes via its
93
- * `controller` prop — rather than the session itself.
78
+ * image editor is one participant in the session — `imageEditor` is the
79
+ * controller an `<ImageEditorCanvas>` takes via its `controller` prop — rather
80
+ * than the session itself.
94
81
  */
95
82
  export interface MediaEditorSession {
96
83
  /**
97
- * Geometry controller for the cropper slice. Its setters record
98
- * history in the session; its `isDirty` covers geometry only.
99
- * Its `setImage` is `setSourceImage`, so the `<Cropper>` reporting
100
- * a newly loaded image starts a fresh session.
84
+ * Controller for the image editor. Its setters record history in the
85
+ * session; its `isDirty` covers the crop only. Its `setImage` is
86
+ * `setSourceImage`, so the `<ImageEditorCanvas>` reporting a newly loaded
87
+ * image starts a fresh session.
101
88
  */
102
- cropper: CropperController;
89
+ imageEditor: ImageEditorController;
103
90
  /** The cropOptions slice. */
104
91
  cropOptions: CropOptionsSlice;
105
- /** Set the aspect-ratio preset. Atomic with the cropRect reshape. */
92
+ /** Set the aspect-ratio preset and reshape the crop in one undo entry. */
106
93
  setAspectRatioValue: ( presetKey: string ) => void;
107
94
  /**
108
95
  * Put every slice back to its starting state in one undo entry:
109
- * default geometry and crop options, no edits. Keeps the image.
96
+ * default crop and crop options, no edits. Keeps the image.
110
97
  */
111
98
  reset: () => void;
112
99
  /** The named edits other than crop, keyed by edit name. */
@@ -119,11 +106,10 @@ export interface MediaEditorSession {
119
106
  setEdit: ( name: string, value: EditValue | undefined ) => void;
120
107
  /**
121
108
  * Replace the image being edited. A different image starts a
122
- * fresh session: default geometry and crop options, a clean
123
- * baseline, and no history. Reporting the same image again is a
124
- * no-op.
109
+ * fresh session: default crop and crop options, a clean baseline,
110
+ * and no history. Reporting the same image again is a no-op.
125
111
  */
126
- setSourceImage: ( image: CropperState[ 'image' ] ) => void;
112
+ setSourceImage: ( image: ImageEditorState[ 'image' ] ) => void;
127
113
  /**
128
114
  * Whether anything in the session differs from its baseline,
129
115
  * including editor-only state such as the aspect-ratio preset.
@@ -138,14 +124,14 @@ export interface MediaEditorSession {
138
124
  hasUndo: boolean;
139
125
  /** Whether there's a redoable change in history. */
140
126
  hasRedo: boolean;
141
- /** Undo the last committed action across all slices. */
127
+ /** Undo the last committed change across all slices. */
142
128
  undo: () => void;
143
- /** Redo the last undone action across all slices. */
129
+ /** Redo the last undone change across all slices. */
144
130
  redo: () => void;
145
131
  /**
146
- * Open a gesture boundary. During a gesture all state-changing
147
- * actions coalesce into one undo entry — the snapshot taken at
148
- * `beginGesture`. Pair with `endGesture` on pointer-up / key-up.
132
+ * Open a gesture boundary. During a gesture all changes coalesce
133
+ * into one undo entry — the snapshot taken at `beginGesture`. Pair
134
+ * with `endGesture` on pointer-up / key-up.
149
135
  */
150
136
  beginGesture: () => void;
151
137
  /** Close a gesture boundary and commit the pre-gesture snapshot. */
@@ -155,24 +141,23 @@ export interface MediaEditorSession {
155
141
  /**
156
142
  * The media editor session.
157
143
  *
158
- * Owns the only undo/redo history for the editor. Cropper geometry
159
- * actions, sidebar cropOptions actions and named edits flow through
160
- * the same reducer and the same history stack.
144
+ * Owns the only undo/redo history for the editor. The image editor's state,
145
+ * the sidebar crop options and named edits are slices of one state, so
146
+ * one history stack covers them all. The image editor works out its own
147
+ * changes and reports each next state through `onChange`.
161
148
  *
162
149
  * History semantics:
163
- * - Each action's pre-state is pushed to the undo stack before the
164
- * action commits, unless a gesture is open or the action is a
165
- * no-op (post-state value-equal to pre-state).
166
- * - During a gesture (`beginGesture` → `endGesture`) all mutations
167
- * coalesce: only the pre-gesture snapshot is pushed, at gesture
168
- * end. Any pending gesture is flushed on undo/redo.
169
- * - Viewport-driven cropRect reshapes (window resize) use a
170
- * dedicated non-recording dispatch path so they never produce
171
- * undo entries.
150
+ * - Each change pushes its pre-state to the undo stack, unless a
151
+ * gesture is open or the change is a no-op (post-state value-equal
152
+ * to pre-state).
153
+ * - During a gesture (`beginGesture` → `endGesture`) changes coalesce:
154
+ * only the pre-gesture snapshot is pushed, at gesture end. Undo and
155
+ * redo close an open gesture first.
156
+ * - Changes the image editor marks as not edits (an image loading, a refit
157
+ * after a window resize) are never recorded.
172
158
  *
173
- * `isDirty` tracks the full editor session, including undoable UI
174
- * state. Use `hasOutputEdits` when deciding whether the image output
175
- * needs saving.
159
+ * `isDirty` tracks the full session, including undoable UI state. Use
160
+ * `hasOutputEdits` when deciding whether the image output needs saving.
176
161
  *
177
162
  * The session starts empty. Call `setSourceImage` to load an image.
178
163
  *
@@ -180,36 +165,29 @@ export interface MediaEditorSession {
180
165
  */
181
166
  export function useMediaEditorState(): MediaEditorSession {
182
167
  const [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>
183
- buildInitialMediaEditorState( { ...DEFAULT_STATE } )
168
+ buildInitialMediaEditorState( createImageEditorState() )
184
169
  );
185
170
 
186
171
  // The "clean" snapshot the current state is compared against for
187
- // `isDirty`. Stored in state (not a ref) so the comparison reads
188
- // a value, not a ref's `current`. `setSourceImage` refreshes this when
189
- // a new image establishes a fresh baseline.
172
+ // `isDirty`. `setSourceImage` refreshes it when a new image starts a
173
+ // fresh session.
190
174
  const [ initialBaseline, setInitialBaseline ] =
191
175
  useState< MediaEditorState >( () => state );
192
176
 
193
- // Latest-state ref used by setters that need to read fresh state
194
- // (focal-point zoom, dispatch wrapper). Every mutation path
195
- // (`dispatchWithHistory`, `setSourceImage`, `undo`, `redo`) writes this
196
- // synchronously, so multiple actions in one event see the latest
197
- // reducer output before React commits.
177
+ // Latest state, so several actions in one event see each other's
178
+ // output before React commits. Every mutation path writes it
179
+ // synchronously.
198
180
  const stateRef = useRef( state );
199
- const visualSizeRef = useRef< Size >( { width: 0, height: 0 } );
200
181
 
201
- // History stacks: full composite snapshots. Refs avoid re-renders
202
- // on every push; a boolean state pair drives the enabled/disabled
203
- // indicators for undo/redo buttons.
182
+ // History stacks: full snapshots. Refs avoid re-renders on every
183
+ // push; a boolean state pair drives the undo/redo indicators.
204
184
  const historyRef = useRef< MediaEditorState[] >( [] );
205
185
  const redoStackRef = useRef< MediaEditorState[] >( [] );
206
186
  const [ hasUndo, setHasUndo ] = useState( false );
207
187
  const [ hasRedo, setHasRedo ] = useState( false );
208
188
 
209
- // Gesture state. While open, the first non-no-op action captures
210
- // the pre-gesture snapshot; subsequent actions don't push.
211
- // `endGesture` pushes the captured snapshot (or nothing, if the
212
- // gesture produced no changes).
189
+ // Gesture state. While open, the first change captures the
190
+ // pre-gesture snapshot; later changes don't push.
213
191
  const isGestureOpenRef = useRef( false );
214
192
  const gestureSnapshotRef = useRef< MediaEditorState | null >( null );
215
193
 
@@ -224,22 +202,20 @@ export function useMediaEditorState(): MediaEditorSession {
224
202
  setHasRedo( false );
225
203
  }, [] );
226
204
 
227
- // Core dispatch wrapper. Synchronously computes the post-state via
228
- // the pure reducer so we can skip history pushes for no-op actions
229
- // and keep `stateRef` in lockstep with React's pending state.
230
205
  const dispatchWithHistory = useCallback(
231
206
  ( action: MediaEditorAction, recordHistory = true ) => {
232
207
  const preState = stateRef.current;
233
208
  const postState = mediaEditorReducer( preState, action );
234
- if ( recordHistory ) {
235
- if ( ! areMediaEditorStatesEqual( preState, postState ) ) {
236
- if ( isGestureOpenRef.current ) {
237
- if ( gestureSnapshotRef.current === null ) {
238
- gestureSnapshotRef.current = preState;
239
- }
240
- } else {
241
- pushSnapshot( preState );
209
+ if (
210
+ recordHistory &&
211
+ ! areMediaEditorStatesEqual( preState, postState )
212
+ ) {
213
+ if ( isGestureOpenRef.current ) {
214
+ if ( gestureSnapshotRef.current === null ) {
215
+ gestureSnapshotRef.current = preState;
242
216
  }
217
+ } else {
218
+ pushSnapshot( preState );
243
219
  }
244
220
  }
245
221
  stateRef.current = postState;
@@ -256,8 +232,8 @@ export function useMediaEditorState(): MediaEditorSession {
256
232
  gestureSnapshotRef.current = null;
257
233
  }, [] );
258
234
 
259
- // Close a gesture (or flush a pending one before undo/redo).
260
- // Pushes the pre-gesture snapshot only if it differs from current
235
+ // Close a gesture (or flush a pending one before undo/redo). Pushes
236
+ // the pre-gesture snapshot only if it differs from the current
261
237
  // state. Safe to call when no gesture is open.
262
238
  const endGesture = useCallback( () => {
263
239
  const snapshot = gestureSnapshotRef.current;
@@ -271,95 +247,95 @@ export function useMediaEditorState(): MediaEditorSession {
271
247
  isGestureOpenRef.current = false;
272
248
  }, [ pushSnapshot ] );
273
249
 
274
- // =====================================================================
275
- // Cropper-slice setters (built from the shared factory so the pure
276
- // hook and this composite stay in lockstep — add a setter in
277
- // `buildCropperSetters` once and both hooks get it).
278
- // =====================================================================
279
-
280
- const dispatchCropperAction = useCallback(
281
- ( action: CropperAction ) => {
282
- dispatchWithHistory( { type: 'CROPPER', action } );
250
+ // Run several changes as one undo entry, unless a gesture is already
251
+ // open, which groups them anyway.
252
+ const asOneUndoEntry = useCallback(
253
+ ( run: () => void ) => {
254
+ if ( isGestureOpenRef.current ) {
255
+ run();
256
+ return;
257
+ }
258
+ beginGesture();
259
+ run();
260
+ endGesture();
283
261
  },
284
- [ dispatchWithHistory ]
262
+ [ beginGesture, endGesture ]
285
263
  );
286
264
 
287
- const cropperSetters = useMemo(
288
- () =>
289
- buildCropperSetters(
290
- dispatchCropperAction,
291
- () => stateRef.current.cropper
292
- ),
293
- [ dispatchCropperAction ]
265
+ const setSourceImage = useCallback(
266
+ ( image: ImageEditorState[ 'image' ] ) => {
267
+ if ( areImagesEqual( stateRef.current.imageEditor.image, image ) ) {
268
+ return;
269
+ }
270
+ // New image = fresh session: default crop and crop options, a
271
+ // clean baseline, and no history. Edits made against one
272
+ // image must not survive onto another.
273
+ const next = buildInitialMediaEditorState(
274
+ createImageEditorState( { image } )
275
+ );
276
+ stateRef.current = next;
277
+ dispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );
278
+ setInitialBaseline( next );
279
+ isGestureOpenRef.current = false;
280
+ gestureSnapshotRef.current = null;
281
+ historyRef.current = [];
282
+ redoStackRef.current = [];
283
+ setHasUndo( false );
284
+ setHasRedo( false );
285
+ },
286
+ []
294
287
  );
295
288
 
296
- const setSourceImage = useCallback( ( image: CropperState[ 'image' ] ) => {
297
- if ( areCropperImagesEqual( stateRef.current.cropper.image, image ) ) {
298
- return;
299
- }
300
- // New image = fresh session: default geometry and crop options, a
301
- // clean baseline, and no history. Built from defaults rather than
302
- // dispatching SET_IMAGE, which keeps the current pan / zoom /
303
- // rotation / flip / cropRect — edits made against one image must
304
- // not survive onto another.
305
- const next = buildInitialMediaEditorState(
306
- enforceContainment( { ...DEFAULT_STATE, image } )
307
- );
308
- stateRef.current = next;
309
- dispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );
310
- setInitialBaseline( next );
311
- isGestureOpenRef.current = false;
312
- gestureSnapshotRef.current = null;
313
- historyRef.current = [];
314
- redoStackRef.current = [];
315
- setHasUndo( false );
316
- setHasRedo( false );
317
- }, [] );
318
-
319
- const resetCropper = useCallback(
320
- ( resetState?: Partial< CropperState > ) => {
321
- dispatchWithHistory( {
322
- type: 'CROPPER',
323
- action: { type: 'RESET', payload: resetState },
324
- } );
289
+ const handleImageEditorChange = useCallback(
290
+ ( nextState: ImageEditorState, { isEdit }: { isEdit: boolean } ) => {
291
+ if (
292
+ ! areImagesEqual(
293
+ stateRef.current.imageEditor.image,
294
+ nextState.image
295
+ )
296
+ ) {
297
+ setSourceImage( nextState.image );
298
+ return;
299
+ }
300
+ dispatchWithHistory(
301
+ { type: 'SET_IMAGE_EDITOR', payload: nextState },
302
+ isEdit
303
+ );
325
304
  },
326
- [ dispatchWithHistory ]
305
+ [ dispatchWithHistory, setSourceImage ]
327
306
  );
328
307
 
329
- // =====================================================================
330
- // CropOptions-slice setters
331
- // =====================================================================
308
+ const imageEditorController = useImageEditor( {
309
+ state: state.imageEditor,
310
+ onChange: handleImageEditorChange,
311
+ } );
332
312
 
313
+ // The locked ratio has two owners: the preset the sidebar shows, and
314
+ // the number the image editor holds. This is the only path that sets
315
+ // both, so call it rather than `imageEditor.setAspectRatio`, which
316
+ // would leave the sidebar showing a ratio the crop no longer has.
333
317
  const setAspectRatioValue = useCallback(
334
318
  ( presetKey: string ) => {
335
- const resolved = resolveAspectRatio(
336
- presetKey,
337
- stateRef.current.cropper.image
338
- );
339
- dispatchWithHistory( {
340
- type: 'SET_ASPECT_RATIO_VALUE',
341
- payload: {
342
- presetKey,
343
- resolved,
344
- visualSize: visualSizeRef.current,
345
- },
319
+ asOneUndoEntry( () => {
320
+ dispatchWithHistory( {
321
+ type: 'SET_ASPECT_RATIO_VALUE',
322
+ payload: presetKey,
323
+ } );
324
+ imageEditorController.setAspectRatio(
325
+ resolveAspectRatio(
326
+ presetKey,
327
+ stateRef.current.imageEditor.image
328
+ )
329
+ );
346
330
  } );
347
331
  },
348
- [ dispatchWithHistory ]
332
+ [ asOneUndoEntry, dispatchWithHistory, imageEditorController ]
349
333
  );
350
334
 
351
- // =====================================================================
352
- // Session
353
- // =====================================================================
354
-
355
335
  const reset = useCallback( () => {
356
336
  dispatchWithHistory( { type: 'RESET' } );
357
337
  }, [ dispatchWithHistory ] );
358
338
 
359
- // =====================================================================
360
- // Edits-slice setters
361
- // =====================================================================
362
-
363
339
  const setEdit = useCallback(
364
340
  ( name: string, value: EditValue | undefined ) => {
365
341
  dispatchWithHistory( {
@@ -370,10 +346,6 @@ export function useMediaEditorState(): MediaEditorSession {
370
346
  [ dispatchWithHistory ]
371
347
  );
372
348
 
373
- // =====================================================================
374
- // History
375
- // =====================================================================
376
-
377
349
  const undo = useCallback( () => {
378
350
  endGesture();
379
351
  const prev = historyRef.current[ historyRef.current.length - 1 ];
@@ -402,77 +374,16 @@ export function useMediaEditorState(): MediaEditorSession {
402
374
  dispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );
403
375
  }, [ endGesture ] );
404
376
 
405
- // =====================================================================
406
- // Viewport
407
- // =====================================================================
408
-
409
- const setVisualSize = useCallback( ( size: Size ) => {
410
- visualSizeRef.current = size;
411
- }, [] );
412
-
413
- const adjustCropRectForViewport = useCallback(
414
- ( rect: NormalizedRect ) => {
415
- dispatchWithHistory(
416
- { type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },
417
- false
418
- );
419
- },
420
- [ dispatchWithHistory ]
377
+ const imageEditor = useMemo< ImageEditorController >(
378
+ () => ( { ...imageEditorController, setImage: setSourceImage } ),
379
+ [ imageEditorController, setSourceImage ]
421
380
  );
422
381
 
423
- // =====================================================================
424
- // Derived
425
- // =====================================================================
426
-
427
382
  const isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );
428
- const isCropperDirty = ! areCropperStatesEqual(
429
- state.cropper,
430
- initialBaseline.cropper
431
- );
432
-
433
- const getCroppedImage = useCallback(
434
- ( mimeType?: string, quality?: number ): Promise< Blob > => {
435
- if ( ! state.cropper.image ) {
436
- return Promise.reject(
437
- new Error( 'No image loaded — call setSourceImage first.' )
438
- );
439
- }
440
- return exportCroppedImage(
441
- state.cropper.image.src,
442
- state.cropper,
443
- mimeType,
444
- quality
445
- );
446
- },
447
- [ state.cropper ]
448
- );
449
-
450
- const cropper = useMemo< CropperController >(
451
- () => ( {
452
- ...cropperSetters,
453
- state: state.cropper,
454
- setImage: setSourceImage,
455
- reset: resetCropper,
456
- isDirty: isCropperDirty,
457
- getCroppedImage,
458
- setVisualSize,
459
- adjustCropRectForViewport,
460
- } ),
461
- [
462
- cropperSetters,
463
- state.cropper,
464
- setSourceImage,
465
- resetCropper,
466
- isCropperDirty,
467
- getCroppedImage,
468
- setVisualSize,
469
- adjustCropRectForViewport,
470
- ]
471
- );
472
383
 
473
- const session = useMemo< MediaEditorSession >(
384
+ return useMemo(
474
385
  () => ( {
475
- cropper,
386
+ imageEditor,
476
387
  cropOptions: state.cropOptions,
477
388
  setAspectRatioValue,
478
389
  edits: state.edits,
@@ -480,8 +391,16 @@ export function useMediaEditorState(): MediaEditorSession {
480
391
  setSourceImage,
481
392
  reset,
482
393
  isDirty,
483
- // Only geometry changes the saved image so far.
484
- hasOutputEdits: isCropperDirty,
394
+ // Only the crop changes the saved image so far.
395
+ //
396
+ // This reads the image editor's own clean state, not the
397
+ // session's. The two agree because the session only ever
398
+ // replaces the editor's slice with a state the editor handed
399
+ // out, and because a fresh state for an image matches the
400
+ // default one on every field `isDirty` compares. Change
401
+ // either and this has to compare against the session's
402
+ // baseline instead.
403
+ hasOutputEdits: imageEditor.isDirty,
485
404
  hasUndo,
486
405
  hasRedo,
487
406
  undo,
@@ -490,7 +409,7 @@ export function useMediaEditorState(): MediaEditorSession {
490
409
  endGesture,
491
410
  } ),
492
411
  [
493
- cropper,
412
+ imageEditor,
494
413
  state.cropOptions,
495
414
  setAspectRatioValue,
496
415
  state.edits,
@@ -498,7 +417,6 @@ export function useMediaEditorState(): MediaEditorSession {
498
417
  setSourceImage,
499
418
  reset,
500
419
  isDirty,
501
- isCropperDirty,
502
420
  hasUndo,
503
421
  hasRedo,
504
422
  undo,
@@ -507,5 +425,4 @@ export function useMediaEditorState(): MediaEditorSession {
507
425
  endGesture,
508
426
  ]
509
427
  );
510
- return session;
511
428
  }
package/src/style.scss CHANGED
@@ -1,10 +1,11 @@
1
1
  // Import component styles
2
2
  @use "./components/media-preview/style.scss" as *;
3
- @use "./image-editor/style.scss" as *;
3
+ @use "@wordpress/image-editor/build-style/style.css" as *;
4
4
  @use "./components/media-editor/style.scss" as *;
5
5
  @use "./components/media-form/style.scss" as *;
6
6
  @use "./components/media-editor-modal/style.scss" as *;
7
7
  @use "./components/media-editor-canvas/style.scss" as *;
8
8
  @use "./components/media-editor-image-controls/style.scss" as *;
9
+ @use "./components/media-editor-crop-panel/style.scss" as *;
9
10
  @use "./components/media-editor-keyboard-shortcuts-modal/style.scss" as *;
10
11
  @use "./components/rotation-ruler/style.scss" as *;