@wordpress/media-editor 0.22.0 → 0.24.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 (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  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 +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  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 +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -4,73 +4,64 @@ Object.defineProperties(exports, {
4
4
  [Symbol.toStringTag]: { value: "Module" }
5
5
  });
6
6
  let _wordpress_element = require("@wordpress/element");
7
- let ___image_editor_index_ts = require("../image-editor/index.cjs");
8
- let ___image_editor_core_index_ts = require("../image-editor/core/index.cjs");
9
- let ___image_editor_react_hooks_index_ts = require("../image-editor/react/hooks/index.cjs");
7
+ let _wordpress_image_editor = require("@wordpress/image-editor");
8
+ let __aspect_ratio_presets_ts = require("./aspect-ratio-presets.cjs");
10
9
  let __composite_reducer_ts = require("./composite-reducer.cjs");
11
10
  // packages/media-editor/src/state/use-media-editor-state.ts
12
11
  /**
13
12
  * Resolve an aspect-ratio preset value (the string the dropdown
14
- * round-trips) into a numeric width/height ratio for the cropper.
13
+ * round-trips) into a numeric width/height ratio for the image editor.
15
14
  *
16
15
  * - `'0'` → `undefined` (Free; no lock)
17
16
  * - `'-1'` (Original) → image's natural width / height, or `undefined`
18
17
  * if no image is loaded.
19
18
  * - Any positive decimal → the parsed number.
20
19
  *
21
- * Centralizing here means the dropdown, the action dispatcher, and
22
- * the test harness all resolve the same way.
23
- *
24
- * @param presetKey Preset value from the dropdown.
25
- * @param cropperImage The cropper's loaded image, or `null`.
20
+ * @param presetKey Preset value from the dropdown.
21
+ * @param image The image editor's loaded image, or `null`.
26
22
  * @return The resolved ratio, or `undefined` for Free / unresolvable.
27
23
  */
28
- function resolveAspectRatio(presetKey, cropperImage) {
24
+ function resolveAspectRatio(presetKey, image) {
29
25
  const num = parseFloat(presetKey);
30
26
  if (num === 0 || Number.isNaN(num)) return;
31
- if (num === ___image_editor_index_ts.ORIGINAL_ASPECT_RATIO) {
32
- if (cropperImage && cropperImage.naturalWidth > 0 && cropperImage.naturalHeight > 0) return cropperImage.naturalWidth / cropperImage.naturalHeight;
27
+ if (num === __aspect_ratio_presets_ts.ORIGINAL_ASPECT_RATIO) {
28
+ if (image && image.naturalWidth > 0 && image.naturalHeight > 0) return image.naturalWidth / image.naturalHeight;
33
29
  return;
34
30
  }
35
31
  if (num > 0) return num;
36
32
  }
37
- function areCropperImagesEqual(a, b) {
33
+ function areImagesEqual(a, b) {
38
34
  return a?.src === b?.src && a?.naturalWidth === b?.naturalWidth && a?.naturalHeight === b?.naturalHeight;
39
35
  }
40
36
  /**
41
37
  * The media editor session.
42
38
  *
43
- * Owns the only undo/redo history for the editor. Cropper geometry
44
- * actions, sidebar cropOptions actions and named edits flow through
45
- * the same reducer and the same history stack.
39
+ * Owns the only undo/redo history for the editor. The image editor's state,
40
+ * the sidebar crop options and named edits are slices of one state, so
41
+ * one history stack covers them all. The image editor works out its own
42
+ * changes and reports each next state through `onChange`.
46
43
  *
47
44
  * History semantics:
48
- * - Each action's pre-state is pushed to the undo stack before the
49
- * action commits, unless a gesture is open or the action is a
50
- * no-op (post-state value-equal to pre-state).
51
- * - During a gesture (`beginGesture` → `endGesture`) all mutations
52
- * coalesce: only the pre-gesture snapshot is pushed, at gesture
53
- * end. Any pending gesture is flushed on undo/redo.
54
- * - Viewport-driven cropRect reshapes (window resize) use a
55
- * dedicated non-recording dispatch path so they never produce
56
- * undo entries.
45
+ * - Each change pushes its pre-state to the undo stack, unless a
46
+ * gesture is open or the change is a no-op (post-state value-equal
47
+ * to pre-state).
48
+ * - During a gesture (`beginGesture` → `endGesture`) changes coalesce:
49
+ * only the pre-gesture snapshot is pushed, at gesture end. Undo and
50
+ * redo close an open gesture first.
51
+ * - Changes the image editor marks as not edits (an image loading, a refit
52
+ * after a window resize) are never recorded.
57
53
  *
58
- * `isDirty` tracks the full editor session, including undoable UI
59
- * state. Use `hasOutputEdits` when deciding whether the image output
60
- * needs saving.
54
+ * `isDirty` tracks the full session, including undoable UI state. Use
55
+ * `hasOutputEdits` when deciding whether the image output needs saving.
61
56
  *
62
57
  * The session starts empty. Call `setSourceImage` to load an image.
63
58
  *
64
59
  * @return The media editor session.
65
60
  */
66
61
  function useMediaEditorState() {
67
- const [state, dispatch] = (0, _wordpress_element.useReducer)(__composite_reducer_ts.mediaEditorReducer, null, () => (0, __composite_reducer_ts.buildInitialMediaEditorState)({ ...___image_editor_core_index_ts.DEFAULT_STATE }));
62
+ const [state, dispatch] = (0, _wordpress_element.useReducer)(__composite_reducer_ts.mediaEditorReducer, null, () => (0, __composite_reducer_ts.buildInitialMediaEditorState)((0, _wordpress_image_editor.createImageEditorState)()));
68
63
  const [initialBaseline, setInitialBaseline] = (0, _wordpress_element.useState)(() => state);
69
64
  const stateRef = (0, _wordpress_element.useRef)(state);
70
- const visualSizeRef = (0, _wordpress_element.useRef)({
71
- width: 0,
72
- height: 0
73
- });
74
65
  const historyRef = (0, _wordpress_element.useRef)([]);
75
66
  const redoStackRef = (0, _wordpress_element.useRef)([]);
76
67
  const [hasUndo, setHasUndo] = (0, _wordpress_element.useState)(false);
@@ -88,12 +79,10 @@ function useMediaEditorState() {
88
79
  const dispatchWithHistory = (0, _wordpress_element.useCallback)((action, recordHistory = true) => {
89
80
  const preState = stateRef.current;
90
81
  const postState = (0, __composite_reducer_ts.mediaEditorReducer)(preState, action);
91
- if (recordHistory) {
92
- if (!(0, __composite_reducer_ts.areMediaEditorStatesEqual)(preState, postState)) {
93
- if (isGestureOpenRef.current) {
94
- if (gestureSnapshotRef.current === null) gestureSnapshotRef.current = preState;
95
- } else pushSnapshot(preState);
96
- }
82
+ if (recordHistory && !(0, __composite_reducer_ts.areMediaEditorStatesEqual)(preState, postState)) {
83
+ if (isGestureOpenRef.current) {
84
+ if (gestureSnapshotRef.current === null) gestureSnapshotRef.current = preState;
85
+ } else pushSnapshot(preState);
97
86
  }
98
87
  stateRef.current = postState;
99
88
  dispatch(action);
@@ -109,19 +98,18 @@ function useMediaEditorState() {
109
98
  gestureSnapshotRef.current = null;
110
99
  isGestureOpenRef.current = false;
111
100
  }, [pushSnapshot]);
112
- const dispatchCropperAction = (0, _wordpress_element.useCallback)((action) => {
113
- dispatchWithHistory({
114
- type: "CROPPER",
115
- action
116
- });
117
- }, [dispatchWithHistory]);
118
- const cropperSetters = (0, _wordpress_element.useMemo)(() => (0, ___image_editor_react_hooks_index_ts.buildCropperSetters)(dispatchCropperAction, () => stateRef.current.cropper), [dispatchCropperAction]);
101
+ const asOneUndoEntry = (0, _wordpress_element.useCallback)((run) => {
102
+ if (isGestureOpenRef.current) {
103
+ run();
104
+ return;
105
+ }
106
+ beginGesture();
107
+ run();
108
+ endGesture();
109
+ }, [beginGesture, endGesture]);
119
110
  const setSourceImage = (0, _wordpress_element.useCallback)((image) => {
120
- if (areCropperImagesEqual(stateRef.current.cropper.image, image)) return;
121
- const next = (0, __composite_reducer_ts.buildInitialMediaEditorState)((0, ___image_editor_core_index_ts.enforceContainment)({
122
- ...___image_editor_core_index_ts.DEFAULT_STATE,
123
- image
124
- }));
111
+ if (areImagesEqual(stateRef.current.imageEditor.image, image)) return;
112
+ const next = (0, __composite_reducer_ts.buildInitialMediaEditorState)((0, _wordpress_image_editor.createImageEditorState)({ image }));
125
113
  stateRef.current = next;
126
114
  dispatch({
127
115
  type: "RESTORE_SNAPSHOT",
@@ -135,26 +123,33 @@ function useMediaEditorState() {
135
123
  setHasUndo(false);
136
124
  setHasRedo(false);
137
125
  }, []);
138
- const resetCropper = (0, _wordpress_element.useCallback)((resetState) => {
126
+ const handleImageEditorChange = (0, _wordpress_element.useCallback)((nextState, { isEdit }) => {
127
+ if (!areImagesEqual(stateRef.current.imageEditor.image, nextState.image)) {
128
+ setSourceImage(nextState.image);
129
+ return;
130
+ }
139
131
  dispatchWithHistory({
140
- type: "CROPPER",
141
- action: {
142
- type: "RESET",
143
- payload: resetState
144
- }
145
- });
146
- }, [dispatchWithHistory]);
132
+ type: "SET_IMAGE_EDITOR",
133
+ payload: nextState
134
+ }, isEdit);
135
+ }, [dispatchWithHistory, setSourceImage]);
136
+ const imageEditorController = (0, _wordpress_image_editor.useImageEditor)({
137
+ state: state.imageEditor,
138
+ onChange: handleImageEditorChange
139
+ });
147
140
  const setAspectRatioValue = (0, _wordpress_element.useCallback)((presetKey) => {
148
- const resolved = resolveAspectRatio(presetKey, stateRef.current.cropper.image);
149
- dispatchWithHistory({
150
- type: "SET_ASPECT_RATIO_VALUE",
151
- payload: {
152
- presetKey,
153
- resolved,
154
- visualSize: visualSizeRef.current
155
- }
141
+ asOneUndoEntry(() => {
142
+ dispatchWithHistory({
143
+ type: "SET_ASPECT_RATIO_VALUE",
144
+ payload: presetKey
145
+ });
146
+ imageEditorController.setAspectRatio(resolveAspectRatio(presetKey, stateRef.current.imageEditor.image));
156
147
  });
157
- }, [dispatchWithHistory]);
148
+ }, [
149
+ asOneUndoEntry,
150
+ dispatchWithHistory,
151
+ imageEditorController
152
+ ]);
158
153
  const reset = (0, _wordpress_element.useCallback)(() => {
159
154
  dispatchWithHistory({ type: "RESET" });
160
155
  }, [dispatchWithHistory]);
@@ -195,42 +190,13 @@ function useMediaEditorState() {
195
190
  payload: next
196
191
  });
197
192
  }, [endGesture]);
198
- const setVisualSize = (0, _wordpress_element.useCallback)((size) => {
199
- visualSizeRef.current = size;
200
- }, []);
201
- const adjustCropRectForViewport = (0, _wordpress_element.useCallback)((rect) => {
202
- dispatchWithHistory({
203
- type: "VIEWPORT_ADJUST_CROP_RECT",
204
- payload: rect
205
- }, false);
206
- }, [dispatchWithHistory]);
193
+ const imageEditor = (0, _wordpress_element.useMemo)(() => ({
194
+ ...imageEditorController,
195
+ setImage: setSourceImage
196
+ }), [imageEditorController, setSourceImage]);
207
197
  const isDirty = !(0, __composite_reducer_ts.areMediaEditorStatesEqual)(state, initialBaseline);
208
- const isCropperDirty = !(0, ___image_editor_core_index_ts.areCropperStatesEqual)(state.cropper, initialBaseline.cropper);
209
- const getCroppedImage = (0, _wordpress_element.useCallback)((mimeType, quality) => {
210
- if (!state.cropper.image) return Promise.reject(/* @__PURE__ */ new Error("No image loaded — call setSourceImage first."));
211
- return (0, ___image_editor_index_ts.exportCroppedImage)(state.cropper.image.src, state.cropper, mimeType, quality);
212
- }, [state.cropper]);
213
- const cropper = (0, _wordpress_element.useMemo)(() => ({
214
- ...cropperSetters,
215
- state: state.cropper,
216
- setImage: setSourceImage,
217
- reset: resetCropper,
218
- isDirty: isCropperDirty,
219
- getCroppedImage,
220
- setVisualSize,
221
- adjustCropRectForViewport
222
- }), [
223
- cropperSetters,
224
- state.cropper,
225
- setSourceImage,
226
- resetCropper,
227
- isCropperDirty,
228
- getCroppedImage,
229
- setVisualSize,
230
- adjustCropRectForViewport
231
- ]);
232
198
  return (0, _wordpress_element.useMemo)(() => ({
233
- cropper,
199
+ imageEditor,
234
200
  cropOptions: state.cropOptions,
235
201
  setAspectRatioValue,
236
202
  edits: state.edits,
@@ -238,7 +204,7 @@ function useMediaEditorState() {
238
204
  setSourceImage,
239
205
  reset,
240
206
  isDirty,
241
- hasOutputEdits: isCropperDirty,
207
+ hasOutputEdits: imageEditor.isDirty,
242
208
  hasUndo,
243
209
  hasRedo,
244
210
  undo,
@@ -246,7 +212,7 @@ function useMediaEditorState() {
246
212
  beginGesture,
247
213
  endGesture
248
214
  }), [
249
- cropper,
215
+ imageEditor,
250
216
  state.cropOptions,
251
217
  setAspectRatioValue,
252
218
  state.edits,
@@ -254,7 +220,6 @@ function useMediaEditorState() {
254
220
  setSourceImage,
255
221
  reset,
256
222
  isDirty,
257
- isCropperDirty,
258
223
  hasUndo,
259
224
  hasRedo,
260
225
  undo,
@@ -263,7 +228,6 @@ function useMediaEditorState() {
263
228
  endGesture
264
229
  ]);
265
230
  }
266
- exports.resolveAspectRatio = resolveAspectRatio;
267
231
  exports.useMediaEditorState = useMediaEditorState;
268
232
 
269
233
  //# sourceMappingURL=use-media-editor-state.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-media-editor-state.cjs","names":["ORIGINAL_ASPECT_RATIO","useReducer","mediaEditorReducer","buildInitialMediaEditorState","DEFAULT_STATE","useState","useRef","useCallback","areMediaEditorStatesEqual","useMemo","buildCropperSetters","enforceContainment","areCropperStatesEqual","exportCroppedImage"],"sources":["../../src/state/use-media-editor-state.ts"],"sourcesContent":["import {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport {\n\tORIGINAL_ASPECT_RATIO,\n\texportCroppedImage,\n\ttype CropperController,\n\ttype CropperState,\n\ttype NormalizedRect,\n\ttype Size,\n} from '../image-editor';\nimport {\n\tDEFAULT_STATE,\n\tareCropperStatesEqual,\n\tenforceContainment,\n\ttype CropperAction,\n} from '../image-editor/core';\nimport { buildCropperSetters } from '../image-editor/react/hooks';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tEditsSlice,\n\tEditValue,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the cropper.\n *\n * - `'0'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → the parsed number.\n *\n * Centralizing here means the dropdown, the action dispatcher, and\n * the test harness all resolve the same way.\n *\n * @param presetKey Preset value from the dropdown.\n * @param cropperImage The cropper's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nexport function resolveAspectRatio(\n\tpresetKey: string,\n\tcropperImage: CropperState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif (\n\t\t\tcropperImage &&\n\t\t\tcropperImage.naturalWidth > 0 &&\n\t\t\tcropperImage.naturalHeight > 0\n\t\t) {\n\t\t\treturn cropperImage.naturalWidth / cropperImage.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The media editor session exposed by `useMediaEditorState`.\n *\n * The session owns what is being edited and how: the source image,\n * every editing slice, the shared undo/redo history, gesture\n * boundaries, and whether the edits change the saved image. The\n * cropper is one participant in the session — `cropper` is a\n * geometry-only controller that a `<Cropper>` takes via its\n * `controller` prop — rather than the session itself.\n */\nexport interface MediaEditorSession {\n\t/**\n\t * Geometry controller for the cropper slice. Its setters record\n\t * history in the session; its `isDirty` covers geometry only.\n\t * Its `setImage` is `setSourceImage`, so the `<Cropper>` reporting\n\t * a newly loaded image starts a fresh session.\n\t */\n\tcropper: CropperController;\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/**\n\t * Put every slice back to its starting state in one undo entry:\n\t * default geometry and crop options, no edits. Keeps the image.\n\t */\n\treset: () => void;\n\t/** The named edits other than crop, keyed by edit name. */\n\tedits: EditsSlice;\n\t/**\n\t * Set a named edit, or remove it by passing `undefined`. Recorded\n\t * in the session history like any crop change. Setting a value\n\t * equal in content to the current one is a no-op.\n\t */\n\tsetEdit: ( name: string, value: EditValue | undefined ) => void;\n\t/**\n\t * Replace the image being edited. A different image starts a\n\t * fresh session: default geometry and crop options, a clean\n\t * baseline, and no history. Reporting the same image again is a\n\t * no-op.\n\t */\n\tsetSourceImage: ( image: CropperState[ 'image' ] ) => void;\n\t/**\n\t * Whether anything in the session differs from its baseline,\n\t * including editor-only state such as the aspect-ratio preset.\n\t */\n\tisDirty: boolean;\n\t/**\n\t * Whether the edits change the saved image, so saving has to\n\t * produce new image output rather than only metadata.\n\t */\n\thasOutputEdits: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed action across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone action across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all state-changing\n\t * actions coalesce into one undo entry — the snapshot taken at\n\t * `beginGesture`. Pair with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n}\n\n/**\n * The media editor session.\n *\n * Owns the only undo/redo history for the editor. Cropper geometry\n * actions, sidebar cropOptions actions and named edits flow through\n * the same reducer and the same history stack.\n *\n * History semantics:\n * - Each action's pre-state is pushed to the undo stack before the\n * action commits, unless a gesture is open or the action is a\n * no-op (post-state value-equal to pre-state).\n * - During a gesture (`beginGesture` → `endGesture`) all mutations\n * coalesce: only the pre-gesture snapshot is pushed, at gesture\n * end. Any pending gesture is flushed on undo/redo.\n * - Viewport-driven cropRect reshapes (window resize) use a\n * dedicated non-recording dispatch path so they never produce\n * undo entries.\n *\n * `isDirty` tracks the full editor session, including undoable UI\n * state. Use `hasOutputEdits` when deciding whether the image output\n * needs saving.\n *\n * The session starts empty. Call `setSourceImage` to load an image.\n *\n * @return The media editor session.\n */\nexport function useMediaEditorState(): MediaEditorSession {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState( { ...DEFAULT_STATE } )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setSourceImage` refreshes this when\n\t// a new image establishes a fresh baseline.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, dispatch wrapper). Every mutation path\n\t// (`dispatchWithHistory`, `setSourceImage`, `undo`, `redo`) writes this\n\t// synchronously, so multiple actions in one event see the latest\n\t// reducer output before React commits.\n\tconst stateRef = useRef( state );\n\tconst visualSizeRef = useRef< Size >( { width: 0, height: 0 } );\n\n\t// History stacks: full composite snapshots. Refs avoid re-renders\n\t// on every push; a boolean state pair drives the enabled/disabled\n\t// indicators for undo/redo buttons.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first non-no-op action captures\n\t// the pre-gesture snapshot; subsequent actions don't push.\n\t// `endGesture` pushes the captured snapshot (or nothing, if the\n\t// gesture produced no changes).\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Core dispatch wrapper. Synchronously computes the post-state via\n\t// the pure reducer so we can skip history pushes for no-op actions\n\t// and keep `stateRef` in lockstep with React's pending state.\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif ( recordHistory ) {\n\t\t\t\tif ( ! areMediaEditorStatesEqual( preState, postState ) ) {\n\t\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo).\n\t// Pushes the pre-gesture snapshot only if it differs from current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// =====================================================================\n\t// Cropper-slice setters (built from the shared factory so the pure\n\t// hook and this composite stay in lockstep — add a setter in\n\t// `buildCropperSetters` once and both hooks get it).\n\t// =====================================================================\n\n\tconst dispatchCropperAction = useCallback(\n\t\t( action: CropperAction ) => {\n\t\t\tdispatchWithHistory( { type: 'CROPPER', action } );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst cropperSetters = useMemo(\n\t\t() =>\n\t\t\tbuildCropperSetters(\n\t\t\t\tdispatchCropperAction,\n\t\t\t\t() => stateRef.current.cropper\n\t\t\t),\n\t\t[ dispatchCropperAction ]\n\t);\n\n\tconst setSourceImage = useCallback( ( image: CropperState[ 'image' ] ) => {\n\t\tif ( areCropperImagesEqual( stateRef.current.cropper.image, image ) ) {\n\t\t\treturn;\n\t\t}\n\t\t// New image = fresh session: default geometry and crop options, a\n\t\t// clean baseline, and no history. Built from defaults rather than\n\t\t// dispatching SET_IMAGE, which keeps the current pan / zoom /\n\t\t// rotation / flip / cropRect — edits made against one image must\n\t\t// not survive onto another.\n\t\tconst next = buildInitialMediaEditorState(\n\t\t\tenforceContainment( { ...DEFAULT_STATE, image } )\n\t\t);\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t\tsetInitialBaseline( next );\n\t\tisGestureOpenRef.current = false;\n\t\tgestureSnapshotRef.current = null;\n\t\thistoryRef.current = [];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( false );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst resetCropper = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'CROPPER',\n\t\t\t\taction: { type: 'RESET', payload: resetState },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// CropOptions-slice setters\n\t// =====================================================================\n\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tconst resolved = resolveAspectRatio(\n\t\t\t\tpresetKey,\n\t\t\t\tstateRef.current.cropper.image\n\t\t\t);\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\tpayload: {\n\t\t\t\t\tpresetKey,\n\t\t\t\t\tresolved,\n\t\t\t\t\tvisualSize: visualSizeRef.current,\n\t\t\t\t},\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Session\n\t// =====================================================================\n\n\tconst reset = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET' } );\n\t}, [ dispatchWithHistory ] );\n\n\t// =====================================================================\n\t// Edits-slice setters\n\t// =====================================================================\n\n\tconst setEdit = useCallback(\n\t\t( name: string, value: EditValue | undefined ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_EDIT',\n\t\t\t\tpayload: { name, value },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// History\n\t// =====================================================================\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\t// =====================================================================\n\t// Viewport\n\t// =====================================================================\n\n\tconst setVisualSize = useCallback( ( size: Size ) => {\n\t\tvisualSizeRef.current = size;\n\t}, [] );\n\n\tconst adjustCropRectForViewport = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },\n\t\t\t\tfalse\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Derived\n\t// =====================================================================\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\tconst isCropperDirty = ! areCropperStatesEqual(\n\t\tstate.cropper,\n\t\tinitialBaseline.cropper\n\t);\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.cropper.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded — call setSourceImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.cropper.image.src,\n\t\t\t\tstate.cropper,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state.cropper ]\n\t);\n\n\tconst cropper = useMemo< CropperController >(\n\t\t() => ( {\n\t\t\t...cropperSetters,\n\t\t\tstate: state.cropper,\n\t\t\tsetImage: setSourceImage,\n\t\t\treset: resetCropper,\n\t\t\tisDirty: isCropperDirty,\n\t\t\tgetCroppedImage,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t} ),\n\t\t[\n\t\t\tcropperSetters,\n\t\t\tstate.cropper,\n\t\t\tsetSourceImage,\n\t\t\tresetCropper,\n\t\t\tisCropperDirty,\n\t\t\tgetCroppedImage,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t]\n\t);\n\n\tconst session = useMemo< MediaEditorSession >(\n\t\t() => ( {\n\t\t\tcropper,\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tedits: state.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\t// Only geometry changes the saved image so far.\n\t\t\thasOutputEdits: isCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t} ),\n\t\t[\n\t\t\tcropper,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tstate.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t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BAAAA,CAA2B,OAAO,eAAgB;CACpE,MAAM,iBAAiB,EAAA,GAAEI,8BAAAA,sBAAAA,CACxB,MAAM,SACN,gBAAgB,OACjB;CAEA,MAAM,mBAAA,GAAkBL,mBAAAA,YAAAA,EACrB,UAAmB,YAAuC;EAC3D,IAAK,CAAE,MAAM,QAAQ,OACpB,OAAO,QAAQ,uBACd,IAAI,MAAO,8CAA+C,CAC3D;EAED,QAAA,GAAOM,yBAAAA,mBAAAA,CACN,MAAM,QAAQ,MAAM,KACpB,MAAM,SACN,UACA,OACD;CACD,GACA,CAAE,MAAM,OAAQ,CACjB;CAEA,MAAM,WAAA,GAAUJ,mBAAAA,QAAAA,QACP;EACP,GAAG;EACH,OAAO,MAAM;EACb,UAAU;EACV,OAAO;EACP,SAAS;EACT;EACA;EACA;CACD,IACA;EACC;EACA,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;CACD,CACD;CAuCA,QAAA,GArCgBA,mBAAAA,QAAAA,QACP;EACP;EACA,aAAa,MAAM;EACnB;EACA,OAAO,MAAM;EACb;EACA;EACA;EACA;EAEA,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA;CACD,IACA;EACC;EACA,MAAM;EACN;EACA,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAEY;AACd"}
1
+ {"version":3,"file":"use-media-editor-state.cjs","names":["ORIGINAL_ASPECT_RATIO","useReducer","mediaEditorReducer","buildInitialMediaEditorState","createImageEditorState","useState","useRef","useCallback","areMediaEditorStatesEqual","useImageEditor","useMemo"],"sources":["../../src/state/use-media-editor-state.ts"],"sourcesContent":["import {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport {\n\tcreateImageEditorState,\n\tuseImageEditor,\n\ttype ImageEditorController,\n\ttype ImageEditorState,\n} from '@wordpress/image-editor';\nimport { ORIGINAL_ASPECT_RATIO } from './aspect-ratio-presets';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tEditsSlice,\n\tEditValue,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the image editor.\n *\n * - `'0'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → the parsed number.\n *\n * @param presetKey Preset value from the dropdown.\n * @param image The image editor's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nfunction resolveAspectRatio(\n\tpresetKey: string,\n\timage: ImageEditorState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif ( image && image.naturalWidth > 0 && image.naturalHeight > 0 ) {\n\t\t\treturn image.naturalWidth / image.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areImagesEqual(\n\ta: ImageEditorState[ 'image' ],\n\tb: ImageEditorState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The media editor session exposed by `useMediaEditorState`.\n *\n * The session owns what is being edited and how: the source image,\n * every editing slice, the shared undo/redo history, gesture\n * boundaries, and whether the edits change the saved image. The\n * image editor is one participant in the session — `imageEditor` is the\n * controller an `<ImageEditorCanvas>` takes via its `controller` prop — rather\n * than the session itself.\n */\nexport interface MediaEditorSession {\n\t/**\n\t * Controller for the image editor. Its setters record history in the\n\t * session; its `isDirty` covers the crop only. Its `setImage` is\n\t * `setSourceImage`, so the `<ImageEditorCanvas>` reporting a newly loaded\n\t * image starts a fresh session.\n\t */\n\timageEditor: ImageEditorController;\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset and reshape the crop in one undo entry. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/**\n\t * Put every slice back to its starting state in one undo entry:\n\t * default crop and crop options, no edits. Keeps the image.\n\t */\n\treset: () => void;\n\t/**\n\t * The named edits other than crop, keyed by edit name. Not an\n\t * extension API: undoable and cleared by `reset`, but not counted by\n\t * `hasOutputEdits` and not saved.\n\t */\n\tedits: EditsSlice;\n\t/**\n\t * Set a named edit, or remove it by passing `undefined`. Recorded\n\t * in the session history like any crop change. Setting a value\n\t * equal in content to the current one is a no-op.\n\t */\n\tsetEdit: ( name: string, value: EditValue | undefined ) => void;\n\t/**\n\t * Replace the image being edited. A different image starts a\n\t * fresh session: default crop and crop options, a clean baseline,\n\t * and no history. Reporting the same image again is a no-op.\n\t */\n\tsetSourceImage: ( image: ImageEditorState[ 'image' ] ) => void;\n\t/**\n\t * Whether anything in the session differs from its baseline,\n\t * including editor-only state such as the aspect-ratio preset.\n\t */\n\tisDirty: boolean;\n\t/**\n\t * Whether the edits change the saved image, so saving has to\n\t * produce new image output rather than only metadata. Geometry\n\t * counts; named edits do not.\n\t */\n\thasOutputEdits: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed change across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone change across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all changes coalesce\n\t * into one undo entry — the snapshot taken at `beginGesture`. Pair\n\t * with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n}\n\n/**\n * The media editor session.\n *\n * Owns the only undo/redo history for the editor. The image editor's state,\n * the sidebar crop options and named edits are slices of one state, so\n * one history stack covers them all. The image editor works out its own\n * changes and reports each next state through `onChange`.\n *\n * History semantics:\n * - Each change pushes its pre-state to the undo stack, unless a\n * gesture is open or the change is a no-op (post-state value-equal\n * to pre-state).\n * - During a gesture (`beginGesture` → `endGesture`) changes coalesce:\n * only the pre-gesture snapshot is pushed, at gesture end. Undo and\n * redo close an open gesture first.\n * - Changes the image editor marks as not edits (an image loading, a refit\n * after a window resize) are never recorded.\n *\n * `isDirty` tracks the full session, including undoable UI state. Use\n * `hasOutputEdits` when deciding whether the image output needs saving.\n *\n * The session starts empty. Call `setSourceImage` to load an image.\n *\n * @return The media editor session.\n */\nexport function useMediaEditorState(): MediaEditorSession {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState( createImageEditorState() )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. `setSourceImage` refreshes it when a new image starts a\n\t// fresh session.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest state, so several actions in one event see each other's\n\t// output before React commits. Every mutation path writes it\n\t// synchronously.\n\tconst stateRef = useRef( state );\n\n\t// History stacks: full snapshots. Refs avoid re-renders on every\n\t// push; a boolean state pair drives the undo/redo indicators.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first change captures the\n\t// pre-gesture snapshot; later changes don't push.\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif (\n\t\t\t\trecordHistory &&\n\t\t\t\t! areMediaEditorStatesEqual( preState, postState )\n\t\t\t) {\n\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo). Pushes\n\t// the pre-gesture snapshot only if it differs from the current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// Run several changes as one undo entry, unless a gesture is already\n\t// open, which groups them anyway.\n\tconst asOneUndoEntry = useCallback(\n\t\t( run: () => void ) => {\n\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\trun();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbeginGesture();\n\t\t\trun();\n\t\t\tendGesture();\n\t\t},\n\t\t[ beginGesture, endGesture ]\n\t);\n\n\tconst setSourceImage = useCallback(\n\t\t( image: ImageEditorState[ 'image' ] ) => {\n\t\t\tif ( areImagesEqual( stateRef.current.imageEditor.image, image ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// New image = fresh session: default crop and crop options, a\n\t\t\t// clean baseline, and no history. Edits made against one\n\t\t\t// image must not survive onto another.\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcreateImageEditorState( { image } )\n\t\t\t);\n\t\t\tstateRef.current = next;\n\t\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t\t\tsetInitialBaseline( next );\n\t\t\tisGestureOpenRef.current = false;\n\t\t\tgestureSnapshotRef.current = null;\n\t\t\thistoryRef.current = [];\n\t\t\tredoStackRef.current = [];\n\t\t\tsetHasUndo( false );\n\t\t\tsetHasRedo( false );\n\t\t},\n\t\t[]\n\t);\n\n\tconst handleImageEditorChange = useCallback(\n\t\t( nextState: ImageEditorState, { isEdit }: { isEdit: boolean } ) => {\n\t\t\tif (\n\t\t\t\t! areImagesEqual(\n\t\t\t\t\tstateRef.current.imageEditor.image,\n\t\t\t\t\tnextState.image\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsetSourceImage( nextState.image );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'SET_IMAGE_EDITOR', payload: nextState },\n\t\t\t\tisEdit\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory, setSourceImage ]\n\t);\n\n\tconst imageEditorController = useImageEditor( {\n\t\tstate: state.imageEditor,\n\t\tonChange: handleImageEditorChange,\n\t} );\n\n\t// The locked ratio has two owners: the preset the sidebar shows, and\n\t// the number the image editor holds. This is the only path that sets\n\t// both, so call it rather than `imageEditor.setAspectRatio`, which\n\t// would leave the sidebar showing a ratio the crop no longer has.\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tasOneUndoEntry( () => {\n\t\t\t\tdispatchWithHistory( {\n\t\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\t\tpayload: presetKey,\n\t\t\t\t} );\n\t\t\t\timageEditorController.setAspectRatio(\n\t\t\t\t\tresolveAspectRatio(\n\t\t\t\t\t\tpresetKey,\n\t\t\t\t\t\tstateRef.current.imageEditor.image\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t} );\n\t\t},\n\t\t[ asOneUndoEntry, dispatchWithHistory, imageEditorController ]\n\t);\n\n\tconst reset = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET' } );\n\t}, [ dispatchWithHistory ] );\n\n\tconst setEdit = useCallback(\n\t\t( name: string, value: EditValue | undefined ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_EDIT',\n\t\t\t\tpayload: { name, value },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\tconst imageEditor = useMemo< ImageEditorController >(\n\t\t() => ( { ...imageEditorController, setImage: setSourceImage } ),\n\t\t[ imageEditorController, setSourceImage ]\n\t);\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\timageEditor,\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tedits: state.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\t// Only the crop changes the saved image so far.\n\t\t\t//\n\t\t\t// This reads the image editor's own clean state, not the\n\t\t\t// session's. The two agree because the session only ever\n\t\t\t// replaces the editor's slice with a state the editor handed\n\t\t\t// out, and because a fresh state for an image matches the\n\t\t\t// default one on every field `isDirty` compares. Change\n\t\t\t// either and this has to compare against the session's\n\t\t\t// baseline instead.\n\t\t\thasOutputEdits: imageEditor.isDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t} ),\n\t\t[\n\t\t\timageEditor,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tstate.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t]\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,mBACR,WACA,OACqB;CACrB,MAAM,MAAM,WAAY,SAAU;CAClC,IAAK,QAAQ,KAAK,OAAO,MAAO,GAAI,GACnC;CAED,IAAK,QAAQA,0BAAAA,uBAAwB;EACpC,IAAK,SAAS,MAAM,eAAe,KAAK,MAAM,gBAAgB,GAC7D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G,EAAG;EACrD,WAAY,WAAW,QAAQ,SAAS,CAAE;EAC1C,WAAY,IAAK;EACjB,SAAS,UAAU;EACnB,SAAU;GAAE,MAAM;GAAoB,SAAS;EAAK,CAAE;CACvD,GAAG,CAAE,UAAW,CAAE;CAElB,MAAM,QAAA,GAAOA,mBAAAA,YAAAA,OAAmB;EAC/B,WAAW;EACX,MAAM,OAAO,aAAa,QAAS;EACnC,IAAK,CAAE,MACN;EAED,WAAW,UAAU,CAAE,GAAG,WAAW,SAAS,SAAS,OAAQ;EAC/D,aAAa,UAAU,aAAa,QAAQ,MAAO,CAAE;EACrD,WAAY,IAAK;EACjB,WAAY,aAAa,QAAQ,SAAS,CAAE;EAC5C,SAAS,UAAU;EACnB,SAAU;GAAE,MAAM;GAAoB,SAAS;EAAK,CAAE;CACvD,GAAG,CAAE,UAAW,CAAE;CAElB,MAAM,eAAA,GAAcG,mBAAAA,QAAAA,QACX;EAAE,GAAG;EAAuB,UAAU;CAAe,IAC7D,CAAE,uBAAuB,cAAe,CACzC;CAEA,MAAM,UAAU,EAAA,GAAEF,uBAAAA,0BAAAA,CAA2B,OAAO,eAAgB;CAEpE,QAAA,GAAOE,mBAAAA,QAAAA,QACE;EACP;EACA,aAAa,MAAM;EACnB;EACA,OAAO,MAAM;EACb;EACA;EACA;EACA;EAUA,gBAAgB,YAAY;EAC5B;EACA;EACA;EACA;EACA;EACA;CACD,IACA;EACC;EACA,MAAM;EACN;EACA,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CACD;AACD"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -26,12 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
28
  }) : target, mod));
27
29
  let _wordpress_data = require("@wordpress/data");
28
30
  let __reducer_ts = require("./reducer.cjs");
29
- __reducer_ts = __toESM(__reducer_ts);
30
31
  let __actions_ts = require("./actions.cjs");
31
- __actions_ts = __toESM(__actions_ts);
32
32
  let __selectors_ts = require("./selectors.cjs");
33
- __selectors_ts = __toESM(__selectors_ts);
34
33
  let __constants_ts = require("./constants.cjs");
34
+ __reducer_ts = __toESM(__reducer_ts);
35
+ __actions_ts = __toESM(__actions_ts);
36
+ __selectors_ts = __toESM(__selectors_ts);
35
37
  // packages/media-editor/src/store/index.ts
36
38
  const store = (0, _wordpress_data.createReduxStore)(__constants_ts.STORE_NAME, {
37
39
  reducer: __reducer_ts.default,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["createReduxStore","STORE_NAME","register"],"sources":["../../src/store/index.ts"],"sourcesContent":["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,SAAA,GAAQA,gBAAAA,iBAAAA,CAAkBC,eAAAA,YAAY;CAClD,SAAA,aAAA;CACA,SAAA;CACA,WAAA;AACD,CAAE;CAEFC,GAAAA,gBAAAA,SAAAA,CAAU,KAAM"}
1
+ {"version":3,"file":"index.cjs","names":["createReduxStore","STORE_NAME","reducer","actions","selectors","register"],"sources":["../../src/store/index.ts"],"sourcesContent":["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,SAAA,GAAQA,gBAAAA,iBAAAA,CAAkBC,eAAAA,YAAY;CAClDC,SAAAA,aAAAA;CACAC,SAAAA;CACAC,WAAAA;AACD,CAAE;CAEFC,GAAAA,gBAAAA,SAAAA,CAAU,KAAM"}
@@ -4,6 +4,13 @@ Object.defineProperties(exports, {
4
4
  [Symbol.toStringTag]: { value: "Module" }
5
5
  });
6
6
  // packages/media-editor/src/utils/get-media-type.ts
7
+ /** The media types the editor tells apart, by MIME type prefix. */
8
+ const MEDIA_TYPES = [
9
+ "image",
10
+ "video",
11
+ "audio",
12
+ "application"
13
+ ];
7
14
  /**
8
15
  * Determines the media type from a MIME type string.
9
16
  *
@@ -17,6 +24,7 @@ function getMediaTypeFromMimeType(mimeType) {
17
24
  if (mimeType.startsWith("audio/")) return { type: "audio" };
18
25
  return { type: "application" };
19
26
  }
27
+ exports.MEDIA_TYPES = MEDIA_TYPES;
20
28
  exports.getMediaTypeFromMimeType = getMediaTypeFromMimeType;
21
29
 
22
30
  //# sourceMappingURL=get-media-type.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-media-type.cjs","names":[],"sources":["../../src/utils/get-media-type.ts"],"sourcesContent":["/**\n * Media type result.\n */\nexport interface MediaType {\n\ttype: 'image' | 'video' | 'audio' | 'application';\n}\n\n/**\n * Determines the media type from a MIME type string.\n *\n * @param mimeType - The MIME type to check.\n * @return Object with type property ('image', 'video', 'audio', or 'application').\n */\nexport function getMediaTypeFromMimeType( mimeType?: string ): MediaType {\n\tif ( ! mimeType ) {\n\t\treturn { type: 'application' };\n\t}\n\n\tif ( mimeType.startsWith( 'image/' ) ) {\n\t\treturn { type: 'image' };\n\t}\n\tif ( mimeType.startsWith( 'video/' ) ) {\n\t\treturn { type: 'video' };\n\t}\n\tif ( mimeType.startsWith( 'audio/' ) ) {\n\t\treturn { type: 'audio' };\n\t}\n\treturn { type: 'application' };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,yBAA0B,UAA+B;CACxE,IAAK,CAAE,UACN,OAAO,EAAE,MAAM,cAAc;CAG9B,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO,EAAE,MAAM,QAAQ;CAExB,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO,EAAE,MAAM,QAAQ;CAExB,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO,EAAE,MAAM,QAAQ;CAExB,OAAO,EAAE,MAAM,cAAc;AAC9B"}
1
+ {"version":3,"file":"get-media-type.cjs","names":[],"sources":["../../src/utils/get-media-type.ts"],"sourcesContent":["/** The media types the editor tells apart, by MIME type prefix. */\nexport const MEDIA_TYPES = [\n\t'image',\n\t'video',\n\t'audio',\n\t'application',\n] as const;\n\n/**\n * Media type result.\n */\nexport interface MediaType {\n\ttype: ( typeof MEDIA_TYPES )[ number ];\n}\n\n/**\n * Determines the media type from a MIME type string.\n *\n * @param mimeType - The MIME type to check.\n * @return Object with type property ('image', 'video', 'audio', or 'application').\n */\nexport function getMediaTypeFromMimeType( mimeType?: string ): MediaType {\n\tif ( ! mimeType ) {\n\t\treturn { type: 'application' };\n\t}\n\n\tif ( mimeType.startsWith( 'image/' ) ) {\n\t\treturn { type: 'image' };\n\t}\n\tif ( mimeType.startsWith( 'video/' ) ) {\n\t\treturn { type: 'video' };\n\t}\n\tif ( mimeType.startsWith( 'audio/' ) ) {\n\t\treturn { type: 'audio' };\n\t}\n\treturn { type: 'application' };\n}\n"],"mappings":";;;;;;;AACA,MAAa,cAAc;CAC1B;CACA;CACA;CACA;AACD;;;;;;;AAeA,SAAgB,yBAA0B,UAA+B;CACxE,IAAK,CAAE,UACN,OAAO,EAAE,MAAM,cAAc;CAG9B,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO,EAAE,MAAM,QAAQ;CAExB,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO,EAAE,MAAM,QAAQ;CAExB,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO,EAAE,MAAM,QAAQ;CAExB,OAAO,EAAE,MAAM,cAAc;AAC9B"}
@@ -4,6 +4,12 @@ Object.defineProperties(exports, {
4
4
  [Symbol.toStringTag]: { value: "Module" }
5
5
  });
6
6
  let __get_media_type_ts = require("./get-media-type.cjs");
7
+ Object.defineProperty(exports, "MEDIA_TYPES", {
8
+ enumerable: true,
9
+ get: function() {
10
+ return __get_media_type_ts.MEDIA_TYPES;
11
+ }
12
+ });
7
13
  Object.defineProperty(exports, "getMediaTypeFromMimeType", {
8
14
  enumerable: true,
9
15
  get: function() {