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