@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
@@ -15,7 +15,7 @@ export interface MediaPreviewProps {
15
15
  * Props for MediaPreviewContent component.
16
16
  */
17
17
  interface MediaPreviewContentProps {
18
- mediaType: { type: string };
18
+ previewType: string;
19
19
  mediaUrl: string;
20
20
  altText?: string;
21
21
  displayTitle?: string;
@@ -25,8 +25,35 @@ interface MediaPreviewContentProps {
25
25
  loadingState: 'loading' | 'loaded' | 'error';
26
26
  }
27
27
 
28
+ interface MediaPreviewFileInfoProps {
29
+ mediaUrl: string;
30
+ displayTitle?: string;
31
+ mimeType?: string;
32
+ }
33
+
34
+ function MediaPreviewFileInfo( {
35
+ mediaUrl,
36
+ displayTitle,
37
+ mimeType,
38
+ }: MediaPreviewFileInfoProps ) {
39
+ return (
40
+ <div className="media-editor-preview__file-info">
41
+ <p className="media-editor-preview__file-name">{ displayTitle }</p>
42
+ <p className="media-editor-preview__mime-type">{ mimeType }</p>
43
+ { /* eslint-disable-next-line react/jsx-no-target-blank */ }
44
+ <a
45
+ href={ mediaUrl }
46
+ target="_blank"
47
+ className="media-editor-preview__download-link"
48
+ >
49
+ { __( 'View file' ) }
50
+ </a>
51
+ </div>
52
+ );
53
+ }
54
+
28
55
  function MediaPreviewContent( {
29
- mediaType,
56
+ previewType,
30
57
  mediaUrl,
31
58
  altText,
32
59
  displayTitle,
@@ -35,7 +62,7 @@ function MediaPreviewContent( {
35
62
  onError,
36
63
  loadingState,
37
64
  }: MediaPreviewContentProps ) {
38
- switch ( mediaType.type ) {
65
+ switch ( previewType ) {
39
66
  case 'image':
40
67
  return (
41
68
  <img
@@ -58,25 +85,33 @@ function MediaPreviewContent( {
58
85
  { displayTitle }
59
86
  </audio>
60
87
  );
88
+ case 'pdf':
89
+ // The browser renders the children instead of the PDF when it
90
+ // can't display it, e.g. when the request fails.
91
+ return (
92
+ <object
93
+ className="media-editor-preview__pdf"
94
+ // Ask the viewer to fit the whole page rather than the
95
+ // width. Chrome reads `view`, Firefox reads `zoom`, and
96
+ // Safari ignores both.
97
+ data={ `${ mediaUrl }#view=Fit&zoom=page-fit` }
98
+ type="application/pdf"
99
+ aria-label={ __( 'Embed of the selected PDF file.' ) }
100
+ >
101
+ <MediaPreviewFileInfo
102
+ mediaUrl={ mediaUrl }
103
+ displayTitle={ displayTitle }
104
+ mimeType={ mimeType }
105
+ />
106
+ </object>
107
+ );
61
108
  default:
62
109
  return (
63
- <div className="media-editor-preview__file-info">
64
- <p className="media-editor-preview__file-name">
65
- { displayTitle }
66
- </p>
67
- <p className="media-editor-preview__mime-type">
68
- { mimeType }
69
- </p>
70
- { /* eslint-disable-next-line react/jsx-no-target-blank */ }
71
- <a
72
- href={ mediaUrl }
73
- target="_blank"
74
- rel="noopener"
75
- className="media-editor-preview__download-link"
76
- >
77
- { __( 'View file' ) }
78
- </a>
79
- </div>
110
+ <MediaPreviewFileInfo
111
+ mediaUrl={ mediaUrl }
112
+ displayTitle={ displayTitle }
113
+ mimeType={ mimeType }
114
+ />
80
115
  );
81
116
  }
82
117
  }
@@ -103,6 +138,13 @@ export default function MediaPreview( props: MediaPreviewProps ) {
103
138
 
104
139
  const mediaType = getMediaTypeFromMimeType( mimeType );
105
140
 
141
+ // Without a built-in PDF viewer (e.g. on most mobile browsers), show
142
+ // the file info instead of an embed that can't render.
143
+ const previewType =
144
+ mimeType === 'application/pdf' && window.navigator.pdfViewerEnabled
145
+ ? 'pdf'
146
+ : mediaType.type;
147
+
106
148
  if ( ! mediaUrl ) {
107
149
  return (
108
150
  <div className="media-editor-preview media-editor-preview--empty">
@@ -126,15 +168,15 @@ export default function MediaPreview( props: MediaPreviewProps ) {
126
168
  return (
127
169
  <div
128
170
  { ...props }
129
- className={ `media-editor-preview media-editor-preview--${ mediaType.type }` }
171
+ className={ `media-editor-preview media-editor-preview--${ previewType }` }
130
172
  >
131
- { mediaType.type === 'image' && loadingState === 'loading' && (
173
+ { previewType === 'image' && loadingState === 'loading' && (
132
174
  <div className="media-editor-preview__spinner">
133
175
  <WCSpinner />
134
176
  </div>
135
177
  ) }
136
178
  <MediaPreviewContent
137
- mediaType={ mediaType }
179
+ previewType={ previewType }
138
180
  mediaUrl={ mediaUrl }
139
181
  altText={ altText }
140
182
  displayTitle={ displayTitle }
@@ -48,11 +48,25 @@
48
48
  max-width: 100%;
49
49
  }
50
50
 
51
- &--file {
52
- text-align: center;
51
+ &--pdf {
52
+ align-items: stretch;
53
+ width: 100%;
54
+ max-width: $wide-content-width;
55
+ margin-inline: auto;
56
+ }
57
+
58
+ &__pdf {
59
+ display: flex;
60
+ flex: 1;
61
+ align-items: center;
62
+ justify-content: center;
63
+ min-width: 0;
64
+ border: 0;
65
+ border-radius: $radius-small;
53
66
  }
54
67
 
55
68
  &__file-info {
69
+ text-align: center;
56
70
  background: $gray-100;
57
71
  padding: $grid-unit-30;
58
72
  border-radius: 2px;
@@ -1,4 +1,5 @@
1
1
  @use "@wordpress/base-styles/colors" as *;
2
+ @use "@wordpress/base-styles/mixins" as *;
2
3
  @use "@wordpress/base-styles/variables" as *;
3
4
 
4
5
  // Default to WordPress core's admin theme blue when the host hasn't
@@ -17,8 +18,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
17
18
  height: 32px;
18
19
  padding: 0 $grid-unit-10;
19
20
  box-sizing: border-box;
20
- color: $gray-900;
21
- font-family: $font-family-body;
21
+ font-family: var(--wpds-typography-font-family-body);
22
22
  user-select: none;
23
23
  touch-action: none;
24
24
  cursor: ew-resize;
@@ -38,8 +38,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
38
38
  }
39
39
 
40
40
  &:has(.rotation-ruler__input:focus-visible) {
41
- outline: 2px solid $rotation-ruler-accent;
42
- outline-offset: 2px;
41
+ @include outset-ring__focus();
43
42
  border-radius: 4px;
44
43
  }
45
44
  }
@@ -70,6 +69,10 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
70
69
  border-radius: 1px;
71
70
  transform: translateX(-50%);
72
71
  pointer-events: none;
72
+
73
+ @media (forced-colors: active) {
74
+ background: CanvasText;
75
+ }
73
76
  }
74
77
 
75
78
  .rotation-ruler__strip {
@@ -85,6 +88,8 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
85
88
 
86
89
  .rotation-ruler__ticks {
87
90
  position: absolute;
91
+ // Keep SVG ticks visible when the browser forces dark colors.
92
+ color: CanvasText;
88
93
  // The tick offset is applied as a JS-set inline `transform: translateX()`
89
94
  // (see rotation-ruler/index.tsx), which rtlcss can't mirror. If rtlcss
90
95
  // flipped this `left` to `right`, the anchor and the transform would
@@ -141,7 +146,6 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
141
146
  font-size: 12px;
142
147
  font-weight: var(--wpds-typography-font-weight-emphasis);
143
148
  line-height: 14px;
144
- color: $gray-900;
145
149
  pointer-events: none;
146
150
 
147
151
  &::before {
@@ -94,12 +94,9 @@ export function useRulerDrag(
94
94
  onPointerDownStart,
95
95
  } = options;
96
96
 
97
- // Mutable mirror of the latest committed value plus per-drag state.
98
- // Pointermove handlers fire far faster than React commits, so we
99
- // cannot read `value` from closure. The `value` write happens in an
100
- // effect (not at render time) to satisfy `react-hooks/refs`; the
101
- // effect flushes after commit, so by the time any pointer handler
102
- // runs, the ref reflects the latest committed `value`.
97
+ // Per-drag state, including the last emitted value. Pointermove
98
+ // handlers fire far faster than React commits, so they cannot read
99
+ // `value` from closure. Pointerdown seeds it from the committed `value`.
103
100
  const latestRef = useRef< {
104
101
  value: number;
105
102
  startX: number;
@@ -119,9 +116,6 @@ export function useRulerDrag(
119
116
  capturePointerId: 0,
120
117
  windowPointerUp: null,
121
118
  } );
122
- useEffect( () => {
123
- latestRef.current.value = value;
124
- }, [ value ] );
125
119
 
126
120
  const endDrag = useCallback( () => {
127
121
  const state = latestRef.current;
@@ -170,7 +164,8 @@ export function useRulerDrag(
170
164
  state.captureElement = event.currentTarget;
171
165
  state.capturePointerId = event.pointerId;
172
166
  state.startX = event.clientX;
173
- state.startValue = state.value;
167
+ state.value = value;
168
+ state.startValue = value;
174
169
  state.activeStep = event.shiftKey ? step / 2 : step;
175
170
  state.dragging = true;
176
171
  onPointerDownStart?.();
@@ -186,7 +181,7 @@ export function useRulerDrag(
186
181
  window.addEventListener( 'pointerup', onWindowUp );
187
182
  window.addEventListener( 'pointercancel', onWindowUp );
188
183
  },
189
- [ disabled, onPointerDownStart, endDrag, step ]
184
+ [ disabled, onPointerDownStart, endDrag, step, value ]
190
185
  );
191
186
 
192
187
  const onPointerMove = useCallback(
@@ -0,0 +1,32 @@
1
+ # Media Editor Session
2
+
3
+ The media editor's session owns its undo and redo history. The image editor's state from `@wordpress/image-editor` is one slice of the session's state, next to the sidebar crop options and named edits, kept through `useImageEditor( { state, onChange } )`, so one history covers them all.
4
+
5
+ `useMediaEditorState()` creates a media editor session; `<MediaEditorStateProvider>` calls it, and `useMediaEditor()` reads the one it made. Calling `useMediaEditorState()` again inside the provider makes a second session that shares nothing with the first, so components use `useMediaEditor()`. The session owns the source image, every editing slice, the shared undo/redo history, gesture boundaries, and whether the edits change the saved image (`hasOutputEdits`). The image editor is one participant: `session.imageEditor` is a geometry-only `ImageEditorController` that an `<ImageEditorCanvas>` takes via its `controller` prop, and its `isDirty` covers geometry alone. Replacing the source image (`setSourceImage`, which the image editor's `setImage` also calls) starts a fresh session with default geometry and crop options, a clean baseline, and no history. Save code asks the session, not the image editor, whether image output needs saving.
6
+
7
+ The session also holds named edits other than crop: `session.edits`, set with `session.setEdit( name, value )` and removed by passing `undefined`. They share the crop history, so undo, redo and gestures treat them like any crop change, and a different source image clears them. Values are plain data (`EditValue`: strings, numbers, booleans, `null`, and arrays and objects of those), because the session compares them by content to tell a real change from a no-op. Edits do not yet count towards `hasOutputEdits`; nothing saves them.
8
+
9
+ `session.reset()` puts every slice back to its starting state in one undo entry: default geometry and crop options, no edits, same image. The Reset button calls it; it does not compose per-slice resets itself.
10
+
11
+ ## Use the Session With the Canvas
12
+
13
+ Use the media editor session when image editor state must share history with controls such as aspect ratio. The session owns history and gesture boundaries; pass its `imageEditor` controller to `<ImageEditorCanvas>`.
14
+
15
+ ```tsx
16
+ import { ImageEditorCanvas } from '@wordpress/image-editor';
17
+ import { useMediaEditor } from '../state';
18
+
19
+ function MediaEditorCanvas( { src }: { src: string } ) {
20
+ const session = useMediaEditor();
21
+
22
+ return (
23
+ <ImageEditorCanvas
24
+ src={ src }
25
+ controller={ session.imageEditor }
26
+ freeformCrop
27
+ onGestureStart={ session.beginGesture }
28
+ onGestureEnd={ session.endGesture }
29
+ />
30
+ );
31
+ }
32
+ ```
@@ -0,0 +1,37 @@
1
+ import { __ } from '@wordpress/i18n';
2
+
3
+ /**
4
+ * An aspect ratio preset with a human-readable label.
5
+ */
6
+ export interface AspectRatioPreset {
7
+ /** Display label (e.g., "Square (1:1)"). */
8
+ label: string;
9
+ /**
10
+ * The aspect ratio value (width / height). 0 = free,
11
+ * `ORIGINAL_ASPECT_RATIO` = the image's own ratio.
12
+ */
13
+ value: number;
14
+ }
15
+
16
+ /**
17
+ * Sentinel value for "Original" aspect ratio — resolved at runtime
18
+ * to the image's natural width / height.
19
+ */
20
+ export const ORIGINAL_ASPECT_RATIO = -1;
21
+
22
+ /**
23
+ * The presets the editor offers by default. They live here rather than
24
+ * in the image editor package, because which ratios to offer, and what
25
+ * to call them, is a product choice. The package takes a plain number.
26
+ */
27
+ export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
28
+ { label: __( 'Free' ), value: 0 },
29
+ { label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
30
+ { label: __( 'Square (1:1)' ), value: 1 },
31
+ { label: __( 'Landscape (16:9)' ), value: 16 / 9 },
32
+ { label: __( 'Portrait (9:16)' ), value: 9 / 16 },
33
+ { label: __( 'Classic (4:3)' ), value: 4 / 3 },
34
+ { label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
35
+ { label: __( 'Photo (3:2)' ), value: 3 / 2 },
36
+ { label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
37
+ ];
@@ -1,81 +1,47 @@
1
1
  import fastDeepEqual from 'fast-deep-equal/es6/index.js';
2
2
  import {
3
- cropperReducer,
4
- areCropperStatesEqual,
5
- computeInscribedRect,
6
- type CropperState,
7
- } from '../image-editor';
3
+ areImageEditorStatesEqual,
4
+ createImageEditorState,
5
+ type ImageEditorState,
6
+ } from '@wordpress/image-editor';
8
7
  import {
9
8
  DEFAULT_CROP_OPTIONS,
10
- type CropOptionsSlice,
11
9
  type MediaEditorAction,
12
10
  type MediaEditorState,
13
11
  } from './types';
14
12
 
15
13
  /**
16
- * Pure composite reducer for the media editor.
14
+ * Pure reducer for the media editor.
17
15
  *
18
- * Delegates `CROPPER`-tagged actions to the framework-agnostic
19
- * `cropperReducer` and owns first-class transitions for the sidebar
20
- * `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite
21
- * in one transaction (used by undo/redo).
16
+ * The image editor works out its own next state (through the controller from
17
+ * `@wordpress/image-editor`) and this reducer stores it. The reducer
18
+ * also owns the sidebar crop options and the named edits.
22
19
  *
23
- * Note: this reducer carries NO history of its own. Snapshots and
24
- * stacks live in the `useMediaEditorState` hook that wraps it.
20
+ * This reducer keeps no history; `useMediaEditorState` does.
25
21
  *
26
- * @param state Current composite state.
22
+ * @param state Current state.
27
23
  * @param action Action to apply.
28
- * @return Next composite state.
24
+ * @return Next state.
29
25
  */
30
26
  export function mediaEditorReducer(
31
27
  state: MediaEditorState,
32
28
  action: MediaEditorAction
33
29
  ): MediaEditorState {
34
30
  switch ( action.type ) {
35
- case 'CROPPER': {
36
- const nextCropper = cropperReducer( state.cropper, action.action );
37
- if ( nextCropper === state.cropper ) {
38
- return state;
39
- }
40
- return { ...state, cropper: nextCropper };
41
- }
42
- case 'SET_ASPECT_RATIO_VALUE': {
43
- const { presetKey, resolved, visualSize } = action.payload;
44
- // Atomically: update the preset key AND reshape the
45
- // cropRect (when the ratio is non-Free and we have a
46
- // visualSize). One transaction = one undo entry.
47
- const shouldReshape =
48
- resolved !== undefined &&
49
- resolved > 0 &&
50
- visualSize.width > 0 &&
51
- visualSize.height > 0;
52
- const nextCropOptions: CropOptionsSlice = {
53
- ...state.cropOptions,
54
- aspectRatioValue: presetKey,
55
- };
56
- if ( ! shouldReshape ) {
57
- if ( state.cropOptions.aspectRatioValue === presetKey ) {
58
- return state;
59
- }
60
- return { ...state, cropOptions: nextCropOptions };
61
- }
62
- const newCropRect = computeInscribedRect( resolved, visualSize );
63
- const nextCropper = cropperReducer( state.cropper, {
64
- type: 'SET_CROP_RECT',
65
- payload: newCropRect,
66
- } );
67
- return {
68
- ...state,
69
- cropper: nextCropper,
70
- cropOptions: nextCropOptions,
71
- };
72
- }
73
- case 'RESET': {
74
- const next = buildInitialMediaEditorState(
75
- cropperReducer( state.cropper, { type: 'RESET' } )
76
- );
77
- return areMediaEditorStatesEqual( state, next ) ? state : next;
78
- }
31
+ case 'SET_IMAGE_EDITOR':
32
+ return action.payload === state.imageEditor
33
+ ? state
34
+ : { ...state, imageEditor: action.payload };
35
+ case 'SET_ASPECT_RATIO_VALUE':
36
+ return state.cropOptions.aspectRatioValue === action.payload
37
+ ? state
38
+ : {
39
+ ...state,
40
+ cropOptions: {
41
+ ...state.cropOptions,
42
+ aspectRatioValue: action.payload,
43
+ },
44
+ };
79
45
  case 'SET_EDIT': {
80
46
  const { name, value } = action.payload;
81
47
  if ( value === undefined ) {
@@ -91,27 +57,23 @@ export function mediaEditorReducer(
91
57
  }
92
58
  return { ...state, edits: { ...state.edits, [ name ]: value } };
93
59
  }
60
+ case 'RESET': {
61
+ const next = buildInitialMediaEditorState(
62
+ createImageEditorState( { image: state.imageEditor.image } )
63
+ );
64
+ return areMediaEditorStatesEqual( state, next ) ? state : next;
65
+ }
94
66
  case 'RESTORE_SNAPSHOT':
95
67
  return action.payload;
96
- case 'VIEWPORT_ADJUST_CROP_RECT': {
97
- const nextCropper = cropperReducer( state.cropper, {
98
- type: 'SET_CROP_RECT',
99
- payload: action.payload,
100
- } );
101
- if ( nextCropper === state.cropper ) {
102
- return state;
103
- }
104
- return { ...state, cropper: nextCropper };
105
- }
106
68
  }
107
69
  }
108
70
 
109
71
  /**
110
- * Value-equality check for two composite states. Used by the history
111
- * machinery to dedup snapshots when an action turned out to be a no-op.
72
+ * Value-equality check for two media editor states. The history uses it
73
+ * to skip snapshots when an action turned out to be a no-op.
112
74
  *
113
- * @param a First composite state.
114
- * @param b Second composite state.
75
+ * @param a First state.
76
+ * @param b Second state.
115
77
  * @return Whether `a` and `b` are value-equal across all slices.
116
78
  */
117
79
  export function areMediaEditorStatesEqual(
@@ -122,24 +84,24 @@ export function areMediaEditorStatesEqual(
122
84
  return true;
123
85
  }
124
86
  return (
125
- areCropperStatesEqual( a.cropper, b.cropper ) &&
87
+ areImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&
126
88
  a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&
127
89
  fastDeepEqual( a.edits, b.edits )
128
90
  );
129
91
  }
130
92
 
131
93
  /**
132
- * Build the composite state a session starts from: the given cropper
133
- * slice, default crop options, and no edits.
94
+ * Build the state a session starts from: the given image editor state,
95
+ * default crop options, and no edits.
134
96
  *
135
- * @param cropper The cropper slice.
136
- * @return Composite initial state.
97
+ * @param imageEditor The image editor state.
98
+ * @return Initial state.
137
99
  */
138
100
  export function buildInitialMediaEditorState(
139
- cropper: CropperState
101
+ imageEditor: ImageEditorState
140
102
  ): MediaEditorState {
141
103
  return {
142
- cropper,
104
+ imageEditor,
143
105
  cropOptions: { ...DEFAULT_CROP_OPTIONS },
144
106
  edits: {},
145
107
  };
@@ -1,22 +1,7 @@
1
- export {
2
- useMediaEditorState,
3
- resolveAspectRatio,
4
- } from './use-media-editor-state';
1
+ export { useMediaEditorState } from './use-media-editor-state';
5
2
  export type { MediaEditorSession } from './use-media-editor-state';
6
3
  export {
7
4
  MediaEditorStateProvider,
8
5
  useMediaEditor,
9
6
  } from './media-editor-state-provider';
10
- export {
11
- mediaEditorReducer,
12
- areMediaEditorStatesEqual,
13
- buildInitialMediaEditorState,
14
- } from './composite-reducer';
15
- export { DEFAULT_CROP_OPTIONS } from './types';
16
- export type {
17
- CropOptionsSlice,
18
- EditsSlice,
19
- EditValue,
20
- MediaEditorState,
21
- MediaEditorAction,
22
- } from './types';
7
+ export type { EditsSlice, EditValue, MediaEditorState } from './types';
@@ -1,26 +1,20 @@
1
- import type {
2
- CropperAction,
3
- CropperState,
4
- NormalizedRect,
5
- Size,
6
- } from '../image-editor';
1
+ import type { ImageEditorState } from '@wordpress/image-editor';
7
2
 
8
3
  /**
9
- * Sidebar control state for the cropper. Lives in the composite store
10
- * so it participates in the same undo history as cropper geometry.
4
+ * Sidebar control state for the image editor, kept in the same undo history
5
+ * as the crop.
11
6
  */
12
7
  export interface CropOptionsSlice {
13
8
  /**
14
9
  * Selected aspect-ratio preset as a string (round-trippable through
15
10
  * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive
16
- * decimal = fixed ratio.
11
+ * decimal = fixed ratio. The image editor holds the resolved ratio itself.
17
12
  */
18
13
  aspectRatioValue: string;
19
14
  }
20
15
 
21
16
  /**
22
- * Default values for the crop-options slice. Mirrors the initial state
23
- * used by the sidebar before the user has touched anything.
17
+ * The crop options a session starts from.
24
18
  */
25
19
  export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
26
20
  aspectRatioValue: '0',
@@ -50,81 +44,33 @@ export type EditValue =
50
44
  export type EditsSlice = Record< string, EditValue >;
51
45
 
52
46
  /**
53
- * The full composite state for the media editor — cropper geometry,
54
- * the sidebar control slice, and named edits.
47
+ * The full state of the media editor: the image editor's state, the sidebar
48
+ * crop options and named edits.
55
49
  *
56
50
  * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay
57
51
  * referentially equal across actions that don't touch them.
58
52
  */
59
53
  export interface MediaEditorState {
60
- cropper: CropperState;
54
+ imageEditor: ImageEditorState;
61
55
  cropOptions: CropOptionsSlice;
62
56
  edits: EditsSlice;
63
57
  }
64
58
 
65
- /**
66
- * Composite reducer action union.
67
- *
68
- * Cropper geometry actions are wrapped in a `CROPPER` envelope and
69
- * delegated to the pure `cropperReducer`. Sidebar and history
70
- * concerns are first-class actions on this reducer.
71
- */
59
+ /** Actions the media editor reducer handles. */
72
60
  export type MediaEditorAction =
73
- /**
74
- * Delegate to the underlying cropper reducer. Used for every
75
- * geometry transition (pan / zoom / rotation / flip / cropRect /
76
- * settle / etc.).
77
- */
78
- | {
79
- type: 'CROPPER';
80
- action: CropperAction;
81
- }
82
- /**
83
- * Set the aspect-ratio preset. Atomically updates the preset key
84
- * and the cropRect (computed from the resolved ratio and the
85
- * current visualSize). One transaction = one undo entry.
86
- */
87
- | {
88
- type: 'SET_ASPECT_RATIO_VALUE';
89
- payload: {
90
- /** Preset key as it appears in the dropdown. */
91
- presetKey: string;
92
- /**
93
- * Resolved width/height ratio. `undefined` = Free
94
- * (no lock; cropRect stays where it is).
95
- */
96
- resolved: number | undefined;
97
- /**
98
- * Rendered image size used to compute the inscribed
99
- * rect. Caller supplies it because the reducer is
100
- * framework-agnostic and has no DOM access.
101
- */
102
- visualSize: Size;
103
- };
104
- }
105
- /**
106
- * Put every slice back to its starting state, keeping the image:
107
- * default geometry, default crop options, no edits. One action,
108
- * so one undo entry.
109
- */
110
- | { type: 'RESET' }
61
+ /** Replace the image editor's state with the next one it reports. */
62
+ | { type: 'SET_IMAGE_EDITOR'; payload: ImageEditorState }
63
+ /** Set the aspect-ratio preset the dropdown shows. */
64
+ | { type: 'SET_ASPECT_RATIO_VALUE'; payload: string }
111
65
  /** Set a named edit, or remove it when `value` is `undefined`. */
112
66
  | {
113
67
  type: 'SET_EDIT';
114
68
  payload: { name: string; value: EditValue | undefined };
115
69
  }
116
70
  /**
117
- * Replace the entire composite state with `payload`. Used by
118
- * undo/redo to restore a full snapshot atomically.
71
+ * Put every slice back to its starting state, keeping the image. One
72
+ * action, so one undo entry.
119
73
  */
120
- | { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }
121
- /**
122
- * Adjust the cropper's cropRect in response to a viewport change
123
- * (e.g., window resize). Behaviorally identical to a `CROPPER
124
- * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip
125
- * history recording — viewport reshapes aren't editor actions.
126
- */
127
- | {
128
- type: 'VIEWPORT_ADJUST_CROP_RECT';
129
- payload: NormalizedRect;
130
- };
74
+ | { type: 'RESET' }
75
+ /** Replace the whole state with a snapshot (undo/redo). */
76
+ | { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState };