@wordpress/media-editor 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (432) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/components/media-editor/index.cjs +586 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +42 -57
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  6. package/build/components/media-editor/use-save-media-editor.cjs +131 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +117 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +81 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +61 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +181 -257
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/index.cjs +112 -155
  19. package/build/components/media-editor-modal/index.cjs.map +1 -7
  20. package/build/components/media-editor-provider/index.cjs +32 -55
  21. package/build/components/media-editor-provider/index.cjs.map +1 -7
  22. package/build/components/media-form/index.cjs +82 -77
  23. package/build/components/media-form/index.cjs.map +1 -7
  24. package/build/components/media-preview/index.cjs +113 -114
  25. package/build/components/media-preview/index.cjs.map +1 -7
  26. package/build/components/rotation-ruler/index.cjs +181 -188
  27. package/build/components/rotation-ruler/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  29. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  30. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  32. package/build/index.cjs +45 -39
  33. package/build/lock-unlock.cjs +9 -35
  34. package/build/lock-unlock.cjs.map +1 -7
  35. package/build/private-apis.cjs +16 -37
  36. package/build/private-apis.cjs.map +1 -7
  37. package/build/state/aspect-ratio-presets.cjs +59 -0
  38. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  39. package/build/state/composite-reducer.cjs +100 -113
  40. package/build/state/composite-reducer.cjs.map +1 -7
  41. package/build/state/index.cjs +22 -45
  42. package/build/state/media-editor-state-provider.cjs +35 -48
  43. package/build/state/media-editor-state-provider.cjs.map +1 -7
  44. package/build/state/types.cjs +11 -31
  45. package/build/state/types.cjs.map +1 -7
  46. package/build/state/use-media-editor-state.cjs +227 -296
  47. package/build/state/use-media-editor-state.cjs.map +1 -7
  48. package/build/store/actions.cjs +17 -44
  49. package/build/store/actions.cjs.map +1 -7
  50. package/build/store/constants.cjs +8 -29
  51. package/build/store/constants.cjs.map +1 -7
  52. package/build/store/index.cjs +33 -40
  53. package/build/store/index.cjs.map +1 -7
  54. package/build/store/reducer.cjs +28 -50
  55. package/build/store/reducer.cjs.map +1 -7
  56. package/build/store/selectors.cjs +16 -41
  57. package/build/store/selectors.cjs.map +1 -7
  58. package/build/utils/get-media-type.cjs +18 -41
  59. package/build/utils/get-media-type.cjs.map +1 -7
  60. package/build/utils/index.cjs +9 -28
  61. package/build-module/components/media-editor/index.mjs +545 -675
  62. package/build-module/components/media-editor/index.mjs.map +1 -7
  63. package/build-module/components/media-editor/use-crop-options.mjs +37 -32
  64. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  65. package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
  66. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  67. package/build-module/components/media-editor-canvas/index.mjs +95 -98
  68. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  69. package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
  70. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  71. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
  72. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  73. package/build-module/components/media-editor-image-controls/index.mjs +171 -238
  74. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  75. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
  76. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  77. package/build-module/components/media-editor-modal/index.mjs +88 -124
  78. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  79. package/build-module/components/media-editor-provider/index.mjs +26 -29
  80. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  81. package/build-module/components/media-form/index.mjs +74 -56
  82. package/build-module/components/media-form/index.mjs.map +1 -7
  83. package/build-module/components/media-preview/index.mjs +105 -90
  84. package/build-module/components/media-preview/index.mjs.map +1 -7
  85. package/build-module/components/rotation-ruler/index.mjs +161 -164
  86. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  87. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  88. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  89. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  90. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  91. package/build-module/index.mjs +3 -10
  92. package/build-module/lock-unlock.mjs +5 -10
  93. package/build-module/lock-unlock.mjs.map +1 -7
  94. package/build-module/private-apis.mjs +8 -9
  95. package/build-module/private-apis.mjs.map +1 -7
  96. package/build-module/state/aspect-ratio-presets.mjs +53 -0
  97. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  98. package/build-module/state/composite-reducer.mjs +80 -91
  99. package/build-module/state/composite-reducer.mjs.map +1 -7
  100. package/build-module/state/index.mjs +3 -26
  101. package/build-module/state/media-editor-state-provider.mjs +29 -24
  102. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  103. package/build-module/state/types.mjs +7 -7
  104. package/build-module/state/types.mjs.map +1 -7
  105. package/build-module/state/use-media-editor-state.mjs +223 -288
  106. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  107. package/build-module/store/actions.mjs +12 -19
  108. package/build-module/store/actions.mjs.map +1 -7
  109. package/build-module/store/constants.mjs +4 -5
  110. package/build-module/store/constants.mjs.map +1 -7
  111. package/build-module/store/index.mjs +8 -9
  112. package/build-module/store/index.mjs.map +1 -7
  113. package/build-module/store/reducer.mjs +23 -26
  114. package/build-module/store/reducer.mjs.map +1 -7
  115. package/build-module/store/selectors.mjs +8 -13
  116. package/build-module/store/selectors.mjs.map +1 -7
  117. package/build-module/utils/get-media-type.mjs +14 -17
  118. package/build-module/utils/get-media-type.mjs.map +1 -7
  119. package/build-module/utils/index.mjs +1 -6
  120. package/build-style/style-rtl.css +145 -61
  121. package/build-style/style.css +144 -61
  122. package/build-types/components/media-editor/index.d.ts +20 -2
  123. package/build-types/components/media-editor/index.d.ts.map +1 -1
  124. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  125. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  126. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  127. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  128. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  129. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  130. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  131. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  132. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  133. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  134. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  135. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  136. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  137. package/build-types/components/media-form/index.d.ts.map +1 -1
  138. package/build-types/components/media-preview/index.d.ts.map +1 -1
  139. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  140. package/build-types/state/aspect-ratio-presets.d.ts +24 -0
  141. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  142. package/build-types/state/composite-reducer.d.ts +17 -19
  143. package/build-types/state/composite-reducer.d.ts.map +1 -1
  144. package/build-types/state/index.d.ts +2 -4
  145. package/build-types/state/index.d.ts.map +1 -1
  146. package/build-types/state/types.d.ts +20 -63
  147. package/build-types/state/types.d.ts.map +1 -1
  148. package/build-types/state/use-media-editor-state.d.ts +33 -52
  149. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  150. package/package.json +22 -23
  151. package/src/components/media-editor/index.tsx +355 -167
  152. package/src/components/media-editor/style.scss +19 -0
  153. package/src/components/media-editor/use-crop-options.ts +9 -10
  154. package/src/components/media-editor/use-save-media-editor.ts +48 -10
  155. package/src/components/media-editor-canvas/index.tsx +30 -51
  156. package/src/components/media-editor-canvas/style.scss +6 -6
  157. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  158. package/src/components/media-editor-crop-panel/style.scss +21 -0
  159. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  160. package/src/components/media-editor-image-controls/index.tsx +15 -11
  161. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  162. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  163. package/src/components/media-editor-modal/index.tsx +1 -1
  164. package/src/components/media-editor-modal/style.scss +1 -1
  165. package/src/components/media-form/index.tsx +7 -1
  166. package/src/components/media-preview/index.tsx +65 -23
  167. package/src/components/media-preview/style.scss +16 -2
  168. package/src/components/rotation-ruler/style.scss +9 -5
  169. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  170. package/src/state/README.md +32 -0
  171. package/src/state/aspect-ratio-presets.ts +37 -0
  172. package/src/state/composite-reducer.ts +42 -80
  173. package/src/state/index.ts +2 -17
  174. package/src/state/types.ts +18 -72
  175. package/src/state/use-media-editor-state.ts +155 -238
  176. package/src/style.scss +2 -1
  177. package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
  178. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
  179. package/build/image-editor/core/camera.cjs +0 -225
  180. package/build/image-editor/core/camera.cjs.map +0 -7
  181. package/build/image-editor/core/constants.cjs +0 -108
  182. package/build/image-editor/core/constants.cjs.map +0 -7
  183. package/build/image-editor/core/containment.cjs +0 -276
  184. package/build/image-editor/core/containment.cjs.map +0 -7
  185. package/build/image-editor/core/crop-rect.cjs +0 -48
  186. package/build/image-editor/core/crop-rect.cjs.map +0 -7
  187. package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
  188. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
  189. package/build/image-editor/core/index.cjs +0 -62
  190. package/build/image-editor/core/index.cjs.map +0 -7
  191. package/build/image-editor/core/interaction-controller.cjs +0 -654
  192. package/build/image-editor/core/interaction-controller.cjs.map +0 -7
  193. package/build/image-editor/core/math/rotation.cjs +0 -41
  194. package/build/image-editor/core/math/rotation.cjs.map +0 -7
  195. package/build/image-editor/core/math/sanitize.cjs +0 -92
  196. package/build/image-editor/core/math/sanitize.cjs.map +0 -7
  197. package/build/image-editor/core/setter-helpers.cjs +0 -64
  198. package/build/image-editor/core/setter-helpers.cjs.map +0 -7
  199. package/build/image-editor/core/source-region.cjs +0 -206
  200. package/build/image-editor/core/source-region.cjs.map +0 -7
  201. package/build/image-editor/core/state.cjs +0 -283
  202. package/build/image-editor/core/state.cjs.map +0 -7
  203. package/build/image-editor/core/stencil-math.cjs +0 -216
  204. package/build/image-editor/core/stencil-math.cjs.map +0 -7
  205. package/build/image-editor/core/transform-style.cjs +0 -52
  206. package/build/image-editor/core/transform-style.cjs.map +0 -7
  207. package/build/image-editor/core/transforms/pipeline.cjs +0 -43
  208. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
  209. package/build/image-editor/core/types.cjs +0 -19
  210. package/build/image-editor/core/types.cjs.map +0 -7
  211. package/build/image-editor/core/viewport-state.cjs +0 -50
  212. package/build/image-editor/core/viewport-state.cjs.map +0 -7
  213. package/build/image-editor/index.cjs +0 -67
  214. package/build/image-editor/index.cjs.map +0 -7
  215. package/build/image-editor/react/components/cropper-provider.cjs +0 -50
  216. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
  217. package/build/image-editor/react/components/cropper.cjs +0 -722
  218. package/build/image-editor/react/components/cropper.cjs.map +0 -7
  219. package/build/image-editor/react/components/index.cjs +0 -36
  220. package/build/image-editor/react/components/index.cjs.map +0 -7
  221. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
  222. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
  223. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
  224. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
  225. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
  226. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
  227. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
  228. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
  229. package/build/image-editor/react/components/viewport-provider.cjs +0 -51
  230. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
  231. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
  232. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
  233. package/build/image-editor/react/hooks/index.cjs +0 -34
  234. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  235. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
  236. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
  237. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  238. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  239. package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
  240. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
  241. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
  242. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
  243. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
  244. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
  245. package/build/image-editor/react/visually-hidden-style.cjs +0 -41
  246. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
  247. package/build/index.cjs.map +0 -7
  248. package/build/state/index.cjs.map +0 -7
  249. package/build/utils/index.cjs.map +0 -7
  250. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
  251. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
  252. package/build-module/image-editor/core/camera.mjs +0 -198
  253. package/build-module/image-editor/core/camera.mjs.map +0 -7
  254. package/build-module/image-editor/core/constants.mjs +0 -69
  255. package/build-module/image-editor/core/constants.mjs.map +0 -7
  256. package/build-module/image-editor/core/containment.mjs +0 -253
  257. package/build-module/image-editor/core/containment.mjs.map +0 -7
  258. package/build-module/image-editor/core/crop-rect.mjs +0 -23
  259. package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
  260. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
  261. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
  262. package/build-module/image-editor/core/index.mjs +0 -36
  263. package/build-module/image-editor/core/index.mjs.map +0 -7
  264. package/build-module/image-editor/core/interaction-controller.mjs +0 -635
  265. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
  266. package/build-module/image-editor/core/math/rotation.mjs +0 -15
  267. package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
  268. package/build-module/image-editor/core/math/sanitize.mjs +0 -63
  269. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
  270. package/build-module/image-editor/core/setter-helpers.mjs +0 -39
  271. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
  272. package/build-module/image-editor/core/source-region.mjs +0 -178
  273. package/build-module/image-editor/core/source-region.mjs.map +0 -7
  274. package/build-module/image-editor/core/state.mjs +0 -260
  275. package/build-module/image-editor/core/state.mjs.map +0 -7
  276. package/build-module/image-editor/core/stencil-math.mjs +0 -187
  277. package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
  278. package/build-module/image-editor/core/transform-style.mjs +0 -27
  279. package/build-module/image-editor/core/transform-style.mjs.map +0 -7
  280. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
  281. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
  282. package/build-module/image-editor/core/types.mjs +0 -1
  283. package/build-module/image-editor/core/types.mjs.map +0 -7
  284. package/build-module/image-editor/core/viewport-state.mjs +0 -24
  285. package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
  286. package/build-module/image-editor/index.mjs +0 -39
  287. package/build-module/image-editor/index.mjs.map +0 -7
  288. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
  289. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
  290. package/build-module/image-editor/react/components/cropper.mjs +0 -704
  291. package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
  292. package/build-module/image-editor/react/components/index.mjs +0 -9
  293. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  294. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
  295. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
  296. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
  297. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
  298. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
  299. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
  300. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
  301. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
  302. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
  303. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
  304. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
  305. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
  306. package/build-module/image-editor/react/hooks/index.mjs +0 -8
  307. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  308. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
  309. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
  310. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  311. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  312. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
  313. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
  314. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
  315. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
  316. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
  317. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
  318. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
  319. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
  320. package/build-module/index.mjs.map +0 -7
  321. package/build-module/state/index.mjs.map +0 -7
  322. package/build-module/utils/index.mjs.map +0 -7
  323. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
  324. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  325. package/build-types/image-editor/core/camera.d.ts +0 -128
  326. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  327. package/build-types/image-editor/core/constants.d.ts +0 -99
  328. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  329. package/build-types/image-editor/core/containment.d.ts +0 -72
  330. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  331. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  332. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  333. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  334. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  335. package/build-types/image-editor/core/index.d.ts +0 -10
  336. package/build-types/image-editor/core/index.d.ts.map +0 -1
  337. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  338. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  339. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  340. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  341. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  342. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  343. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  344. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  345. package/build-types/image-editor/core/source-region.d.ts +0 -94
  346. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  347. package/build-types/image-editor/core/state.d.ts +0 -51
  348. package/build-types/image-editor/core/state.d.ts.map +0 -1
  349. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  350. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  351. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  352. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  353. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  354. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  355. package/build-types/image-editor/core/types.d.ts +0 -269
  356. package/build-types/image-editor/core/types.d.ts.map +0 -1
  357. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  358. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  359. package/build-types/image-editor/index.d.ts +0 -16
  360. package/build-types/image-editor/index.d.ts.map +0 -1
  361. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  362. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  363. package/build-types/image-editor/react/components/cropper.d.ts +0 -63
  364. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  365. package/build-types/image-editor/react/components/index.d.ts +0 -4
  366. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  367. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  368. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  369. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  370. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  371. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  372. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  373. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  374. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  375. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  376. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  377. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  378. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  379. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  380. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  381. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  382. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  383. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
  384. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  385. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  386. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  387. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  388. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  389. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  390. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  391. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  392. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  393. package/src/components/media-editor-modal/build-modifiers.ts +0 -161
  394. package/src/image-editor/README.md +0 -61
  395. package/src/image-editor/core/camera.ts +0 -429
  396. package/src/image-editor/core/constants.ts +0 -150
  397. package/src/image-editor/core/containment.ts +0 -469
  398. package/src/image-editor/core/crop-rect.ts +0 -42
  399. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  400. package/src/image-editor/core/index.ts +0 -47
  401. package/src/image-editor/core/interaction-controller.ts +0 -976
  402. package/src/image-editor/core/math/rotation.ts +0 -26
  403. package/src/image-editor/core/math/sanitize.ts +0 -155
  404. package/src/image-editor/core/setter-helpers.ts +0 -63
  405. package/src/image-editor/core/source-region.ts +0 -367
  406. package/src/image-editor/core/state.ts +0 -484
  407. package/src/image-editor/core/stencil-math.ts +0 -379
  408. package/src/image-editor/core/transform-style.ts +0 -56
  409. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  410. package/src/image-editor/core/types.ts +0 -230
  411. package/src/image-editor/core/viewport-state.ts +0 -30
  412. package/src/image-editor/docs/architecture.md +0 -63
  413. package/src/image-editor/docs/recipes.md +0 -184
  414. package/src/image-editor/index.ts +0 -52
  415. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  416. package/src/image-editor/react/components/cropper.scss +0 -259
  417. package/src/image-editor/react/components/cropper.tsx +0 -1116
  418. package/src/image-editor/react/components/index.ts +0 -3
  419. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  420. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  421. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  422. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  423. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  424. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  425. package/src/image-editor/react/hooks/index.ts +0 -4
  426. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  427. package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
  428. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  429. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  430. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  431. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  432. package/src/image-editor/style.scss +0 -1
@@ -1,97 +1,86 @@
1
- // packages/media-editor/src/state/composite-reducer.ts
2
1
  import fastDeepEqual from "fast-deep-equal/es6/index.js";
3
- import {
4
- cropperReducer,
5
- areCropperStatesEqual,
6
- computeInscribedRect
7
- } from "../image-editor/index.mjs";
8
- import {
9
- DEFAULT_CROP_OPTIONS
10
- } from "./types.mjs";
2
+ import { areImageEditorStatesEqual, createImageEditorState } from "@wordpress/image-editor";
3
+ import { DEFAULT_CROP_OPTIONS } from "./types.mjs";
4
+ // packages/media-editor/src/state/composite-reducer.ts
5
+ /**
6
+ * Pure reducer for the media editor.
7
+ *
8
+ * The image editor works out its own next state (through the controller from
9
+ * `@wordpress/image-editor`) and this reducer stores it. The reducer
10
+ * also owns the sidebar crop options and the named edits.
11
+ *
12
+ * This reducer keeps no history; `useMediaEditorState` does.
13
+ *
14
+ * @param state Current state.
15
+ * @param action Action to apply.
16
+ * @return Next state.
17
+ */
11
18
  function mediaEditorReducer(state, action) {
12
- switch (action.type) {
13
- case "CROPPER": {
14
- const nextCropper = cropperReducer(state.cropper, action.action);
15
- if (nextCropper === state.cropper) {
16
- return state;
17
- }
18
- return { ...state, cropper: nextCropper };
19
- }
20
- case "SET_ASPECT_RATIO_VALUE": {
21
- const { presetKey, resolved, visualSize } = action.payload;
22
- const shouldReshape = resolved !== void 0 && resolved > 0 && visualSize.width > 0 && visualSize.height > 0;
23
- const nextCropOptions = {
24
- ...state.cropOptions,
25
- aspectRatioValue: presetKey
26
- };
27
- if (!shouldReshape) {
28
- if (state.cropOptions.aspectRatioValue === presetKey) {
29
- return state;
30
- }
31
- return { ...state, cropOptions: nextCropOptions };
32
- }
33
- const newCropRect = computeInscribedRect(resolved, visualSize);
34
- const nextCropper = cropperReducer(state.cropper, {
35
- type: "SET_CROP_RECT",
36
- payload: newCropRect
37
- });
38
- return {
39
- ...state,
40
- cropper: nextCropper,
41
- cropOptions: nextCropOptions
42
- };
43
- }
44
- case "RESET": {
45
- const next = buildInitialMediaEditorState(
46
- cropperReducer(state.cropper, { type: "RESET" })
47
- );
48
- return areMediaEditorStatesEqual(state, next) ? state : next;
49
- }
50
- case "SET_EDIT": {
51
- const { name, value } = action.payload;
52
- if (value === void 0) {
53
- if (!Object.hasOwn(state.edits, name)) {
54
- return state;
55
- }
56
- const edits = { ...state.edits };
57
- delete edits[name];
58
- return { ...state, edits };
59
- }
60
- if (fastDeepEqual(state.edits[name], value)) {
61
- return state;
62
- }
63
- return { ...state, edits: { ...state.edits, [name]: value } };
64
- }
65
- case "RESTORE_SNAPSHOT":
66
- return action.payload;
67
- case "VIEWPORT_ADJUST_CROP_RECT": {
68
- const nextCropper = cropperReducer(state.cropper, {
69
- type: "SET_CROP_RECT",
70
- payload: action.payload
71
- });
72
- if (nextCropper === state.cropper) {
73
- return state;
74
- }
75
- return { ...state, cropper: nextCropper };
76
- }
77
- }
19
+ switch (action.type) {
20
+ case "SET_IMAGE_EDITOR": return action.payload === state.imageEditor ? state : {
21
+ ...state,
22
+ imageEditor: action.payload
23
+ };
24
+ case "SET_ASPECT_RATIO_VALUE": return state.cropOptions.aspectRatioValue === action.payload ? state : {
25
+ ...state,
26
+ cropOptions: {
27
+ ...state.cropOptions,
28
+ aspectRatioValue: action.payload
29
+ }
30
+ };
31
+ case "SET_EDIT": {
32
+ const { name, value } = action.payload;
33
+ if (value === void 0) {
34
+ if (!Object.hasOwn(state.edits, name)) return state;
35
+ const edits = { ...state.edits };
36
+ delete edits[name];
37
+ return {
38
+ ...state,
39
+ edits
40
+ };
41
+ }
42
+ if (fastDeepEqual(state.edits[name], value)) return state;
43
+ return {
44
+ ...state,
45
+ edits: {
46
+ ...state.edits,
47
+ [name]: value
48
+ }
49
+ };
50
+ }
51
+ case "RESET": {
52
+ const next = buildInitialMediaEditorState(createImageEditorState({ image: state.imageEditor.image }));
53
+ return areMediaEditorStatesEqual(state, next) ? state : next;
54
+ }
55
+ case "RESTORE_SNAPSHOT": return action.payload;
56
+ }
78
57
  }
58
+ /**
59
+ * Value-equality check for two media editor states. The history uses it
60
+ * to skip snapshots when an action turned out to be a no-op.
61
+ *
62
+ * @param a First state.
63
+ * @param b Second state.
64
+ * @return Whether `a` and `b` are value-equal across all slices.
65
+ */
79
66
  function areMediaEditorStatesEqual(a, b) {
80
- if (a === b) {
81
- return true;
82
- }
83
- return areCropperStatesEqual(a.cropper, b.cropper) && a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue && fastDeepEqual(a.edits, b.edits);
67
+ if (a === b) return true;
68
+ return areImageEditorStatesEqual(a.imageEditor, b.imageEditor) && a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue && fastDeepEqual(a.edits, b.edits);
84
69
  }
85
- function buildInitialMediaEditorState(cropper) {
86
- return {
87
- cropper,
88
- cropOptions: { ...DEFAULT_CROP_OPTIONS },
89
- edits: {}
90
- };
70
+ /**
71
+ * Build the state a session starts from: the given image editor state,
72
+ * default crop options, and no edits.
73
+ *
74
+ * @param imageEditor The image editor state.
75
+ * @return Initial state.
76
+ */
77
+ function buildInitialMediaEditorState(imageEditor) {
78
+ return {
79
+ imageEditor,
80
+ cropOptions: { ...DEFAULT_CROP_OPTIONS },
81
+ edits: {}
82
+ };
91
83
  }
92
- export {
93
- areMediaEditorStatesEqual,
94
- buildInitialMediaEditorState,
95
- mediaEditorReducer
96
- };
97
- //# sourceMappingURL=composite-reducer.mjs.map
84
+ export { areMediaEditorStatesEqual, buildInitialMediaEditorState, mediaEditorReducer };
85
+
86
+ //# sourceMappingURL=composite-reducer.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/state/composite-reducer.ts"],
4
- "sourcesContent": ["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tcropperReducer,\n\tareCropperStatesEqual,\n\tcomputeInscribedRect,\n\ttype CropperState,\n} from '../image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype CropOptionsSlice,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure composite reducer for the media editor.\n *\n * Delegates `CROPPER`-tagged actions to the framework-agnostic\n * `cropperReducer` and owns first-class transitions for the sidebar\n * `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite\n * in one transaction (used by undo/redo).\n *\n * Note: this reducer carries NO history of its own. Snapshots and\n * stacks live in the `useMediaEditorState` hook that wraps it.\n *\n * @param state Current composite state.\n * @param action Action to apply.\n * @return Next composite state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'CROPPER': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, action.action );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t\tcase 'SET_ASPECT_RATIO_VALUE': {\n\t\t\tconst { presetKey, resolved, visualSize } = action.payload;\n\t\t\t// Atomically: update the preset key AND reshape the\n\t\t\t// cropRect (when the ratio is non-Free and we have a\n\t\t\t// visualSize). One transaction = one undo entry.\n\t\t\tconst shouldReshape =\n\t\t\t\tresolved !== undefined &&\n\t\t\t\tresolved > 0 &&\n\t\t\t\tvisualSize.width > 0 &&\n\t\t\t\tvisualSize.height > 0;\n\t\t\tconst nextCropOptions: CropOptionsSlice = {\n\t\t\t\t...state.cropOptions,\n\t\t\t\taspectRatioValue: presetKey,\n\t\t\t};\n\t\t\tif ( ! shouldReshape ) {\n\t\t\t\tif ( state.cropOptions.aspectRatioValue === presetKey ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\treturn { ...state, cropOptions: nextCropOptions };\n\t\t\t}\n\t\t\tconst newCropRect = computeInscribedRect( resolved, visualSize );\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: newCropRect,\n\t\t\t} );\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tcropper: nextCropper,\n\t\t\t\tcropOptions: nextCropOptions,\n\t\t\t};\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcropperReducer( state.cropper, { type: 'RESET' } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t\tcase 'VIEWPORT_ADJUST_CROP_RECT': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: action.payload,\n\t\t\t} );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t}\n}\n\n/**\n * Value-equality check for two composite states. Used by the history\n * machinery to dedup snapshots when an action turned out to be a no-op.\n *\n * @param a First composite state.\n * @param b Second composite state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareCropperStatesEqual( a.cropper, b.cropper ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the composite state a session starts from: the given cropper\n * slice, default crop options, and no edits.\n *\n * @param cropper The cropper slice.\n * @return Composite initial state.\n */\nexport function buildInitialMediaEditorState(\n\tcropper: CropperState\n): MediaEditorState {\n\treturn {\n\t\tcropper,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],
5
- "mappings": ";AAAA,OAAO,mBAAmB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,OAIM;AAiBA,SAAS,mBACf,OACA,QACmB;AACnB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,WAAW;AACf,YAAM,cAAc,eAAgB,MAAM,SAAS,OAAO,MAAO;AACjE,UAAK,gBAAgB,MAAM,SAAU;AACpC,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,SAAS,YAAY;AAAA,IACzC;AAAA,IACA,KAAK,0BAA0B;AAC9B,YAAM,EAAE,WAAW,UAAU,WAAW,IAAI,OAAO;AAInD,YAAM,gBACL,aAAa,UACb,WAAW,KACX,WAAW,QAAQ,KACnB,WAAW,SAAS;AACrB,YAAM,kBAAoC;AAAA,QACzC,GAAG,MAAM;AAAA,QACT,kBAAkB;AAAA,MACnB;AACA,UAAK,CAAE,eAAgB;AACtB,YAAK,MAAM,YAAY,qBAAqB,WAAY;AACvD,iBAAO;AAAA,QACR;AACA,eAAO,EAAE,GAAG,OAAO,aAAa,gBAAgB;AAAA,MACjD;AACA,YAAM,cAAc,qBAAsB,UAAU,UAAW;AAC/D,YAAM,cAAc,eAAgB,MAAM,SAAS;AAAA,QAClD,MAAM;AAAA,QACN,SAAS;AAAA,MACV,CAAE;AACF,aAAO;AAAA,QACN,GAAG;AAAA,QACH,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,IACD;AAAA,IACA,KAAK,SAAS;AACb,YAAM,OAAO;AAAA,QACZ,eAAgB,MAAM,SAAS,EAAE,MAAM,QAAQ,CAAE;AAAA,MAClD;AACA,aAAO,0BAA2B,OAAO,IAAK,IAAI,QAAQ;AAAA,IAC3D;AAAA,IACA,KAAK,YAAY;AAChB,YAAM,EAAE,MAAM,MAAM,IAAI,OAAO;AAC/B,UAAK,UAAU,QAAY;AAC1B,YAAK,CAAE,OAAO,OAAQ,MAAM,OAAO,IAAK,GAAI;AAC3C,iBAAO;AAAA,QACR;AACA,cAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;AAC/B,eAAO,MAAO,IAAK;AACnB,eAAO,EAAE,GAAG,OAAO,MAAM;AAAA,MAC1B;AACA,UAAK,cAAe,MAAM,MAAO,IAAK,GAAG,KAAM,GAAI;AAClD,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,OAAO,EAAE,GAAG,MAAM,OAAO,CAAE,IAAK,GAAG,MAAM,EAAE;AAAA,IAC/D;AAAA,IACA,KAAK;AACJ,aAAO,OAAO;AAAA,IACf,KAAK,6BAA6B;AACjC,YAAM,cAAc,eAAgB,MAAM,SAAS;AAAA,QAClD,MAAM;AAAA,QACN,SAAS,OAAO;AAAA,MACjB,CAAE;AACF,UAAK,gBAAgB,MAAM,SAAU;AACpC,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,SAAS,YAAY;AAAA,IACzC;AAAA,EACD;AACD;AAUO,SAAS,0BACf,GACA,GACU;AACV,MAAK,MAAM,GAAI;AACd,WAAO;AAAA,EACR;AACA,SACC,sBAAuB,EAAE,SAAS,EAAE,OAAQ,KAC5C,EAAE,YAAY,qBAAqB,EAAE,YAAY,oBACjD,cAAe,EAAE,OAAO,EAAE,KAAM;AAElC;AASO,SAAS,6BACf,SACmB;AACnB,SAAO;AAAA,IACN;AAAA,IACA,aAAa,EAAE,GAAG,qBAAqB;AAAA,IACvC,OAAO,CAAC;AAAA,EACT;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"composite-reducer.mjs","names":[],"sources":["../../src/state/composite-reducer.ts"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tareImageEditorStatesEqual,\n\tcreateImageEditorState,\n\ttype ImageEditorState,\n} from '@wordpress/image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure reducer for the media editor.\n *\n * The image editor works out its own next state (through the controller from\n * `@wordpress/image-editor`) and this reducer stores it. The reducer\n * also owns the sidebar crop options and the named edits.\n *\n * This reducer keeps no history; `useMediaEditorState` does.\n *\n * @param state Current state.\n * @param action Action to apply.\n * @return Next state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE_EDITOR':\n\t\t\treturn action.payload === state.imageEditor\n\t\t\t\t? state\n\t\t\t\t: { ...state, imageEditor: action.payload };\n\t\tcase 'SET_ASPECT_RATIO_VALUE':\n\t\t\treturn state.cropOptions.aspectRatioValue === action.payload\n\t\t\t\t? state\n\t\t\t\t: {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tcropOptions: {\n\t\t\t\t\t\t\t...state.cropOptions,\n\t\t\t\t\t\t\taspectRatioValue: action.payload,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcreateImageEditorState( { image: state.imageEditor.image } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t}\n}\n\n/**\n * Value-equality check for two media editor states. The history uses it\n * to skip snapshots when an action turned out to be a no-op.\n *\n * @param a First state.\n * @param b Second state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the state a session starts from: the given image editor state,\n * default crop options, and no edits.\n *\n * @param imageEditor The image editor state.\n * @return Initial state.\n */\nexport function buildInitialMediaEditorState(\n\timageEditor: ImageEditorState\n): MediaEditorState {\n\treturn {\n\t\timageEditor,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,mBACf,OACA,QACmB;CACnB,QAAS,OAAO,MAAhB;EACC,KAAK,oBACJ,OAAO,OAAO,YAAY,MAAM,cAC7B,QACA;GAAE,GAAG;GAAO,aAAa,OAAO;EAAQ;EAC5C,KAAK,0BACJ,OAAO,MAAM,YAAY,qBAAqB,OAAO,UAClD,QACA;GACA,GAAG;GACH,aAAa;IACZ,GAAG,MAAM;IACT,kBAAkB,OAAO;GAC1B;EACD;EACH,KAAK,YAAY;GAChB,MAAM,EAAE,MAAM,UAAU,OAAO;GAC/B,IAAK,UAAU,KAAA,GAAY;IAC1B,IAAK,CAAE,OAAO,OAAQ,MAAM,OAAO,IAAK,GACvC,OAAO;IAER,MAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;IAC/B,OAAO,MAAO;IACd,OAAO;KAAE,GAAG;KAAO;IAAM;GAC1B;GACA,IAAK,cAAe,MAAM,MAAO,OAAQ,KAAM,GAC9C,OAAO;GAER,OAAO;IAAE,GAAG;IAAO,OAAO;KAAE,GAAG,MAAM;MAAS,OAAQ;IAAM;GAAE;EAC/D;EACA,KAAK,SAAS;GACb,MAAM,OAAO,6BACZ,uBAAwB,EAAE,OAAO,MAAM,YAAY,MAAM,CAAE,CAC5D;GACA,OAAO,0BAA2B,OAAO,IAAK,IAAI,QAAQ;EAC3D;EACA,KAAK,oBACJ,OAAO,OAAO;CAChB;AACD;;;;;;;;;AAUA,SAAgB,0BACf,GACA,GACU;CACV,IAAK,MAAM,GACV,OAAO;CAER,OACC,0BAA2B,EAAE,aAAa,EAAE,WAAY,KACxD,EAAE,YAAY,qBAAqB,EAAE,YAAY,oBACjD,cAAe,EAAE,OAAO,EAAE,KAAM;AAElC;;;;;;;;AASA,SAAgB,6BACf,aACmB;CACnB,OAAO;EACN;EACA,aAAa,EAAE,GAAG,qBAAqB;EACvC,OAAO,CAAC;CACT;AACD"}
@@ -1,26 +1,3 @@
1
- // packages/media-editor/src/state/index.ts
2
- import {
3
- useMediaEditorState,
4
- resolveAspectRatio
5
- } from "./use-media-editor-state.mjs";
6
- import {
7
- MediaEditorStateProvider,
8
- useMediaEditor
9
- } from "./media-editor-state-provider.mjs";
10
- import {
11
- mediaEditorReducer,
12
- areMediaEditorStatesEqual,
13
- buildInitialMediaEditorState
14
- } from "./composite-reducer.mjs";
15
- import { DEFAULT_CROP_OPTIONS } from "./types.mjs";
16
- export {
17
- DEFAULT_CROP_OPTIONS,
18
- MediaEditorStateProvider,
19
- areMediaEditorStatesEqual,
20
- buildInitialMediaEditorState,
21
- mediaEditorReducer,
22
- resolveAspectRatio,
23
- useMediaEditor,
24
- useMediaEditorState
25
- };
26
- //# sourceMappingURL=index.mjs.map
1
+ import { useMediaEditorState } from "./use-media-editor-state.mjs";
2
+ import { MediaEditorStateProvider, useMediaEditor } from "./media-editor-state-provider.mjs";
3
+ export { MediaEditorStateProvider, useMediaEditor, useMediaEditorState };
@@ -1,29 +1,34 @@
1
- // packages/media-editor/src/state/media-editor-state-provider.tsx
2
1
  import { createContext, useContext } from "@wordpress/element";
3
- import {
4
- useMediaEditorState
5
- } from "./use-media-editor-state.mjs";
2
+ import { useMediaEditorState } from "./use-media-editor-state.mjs";
6
3
  import { jsx } from "react/jsx-runtime";
7
- var MediaEditorStateContext = createContext(
8
- null
9
- );
10
- function MediaEditorStateProvider({
11
- children
12
- }) {
13
- const controller = useMediaEditorState();
14
- return /* @__PURE__ */ jsx(MediaEditorStateContext.Provider, { value: controller, children });
4
+ // packages/media-editor/src/state/media-editor-state-provider.tsx
5
+ const MediaEditorStateContext = createContext(null);
6
+ /**
7
+ * Provider that vends the media editor session via context. Wrap
8
+ * the media editor in this so every consumer (canvas, toolbar,
9
+ * sidebar) reads from the same store.
10
+ *
11
+ * @param props
12
+ * @param props.children
13
+ */
14
+ function MediaEditorStateProvider({ children }) {
15
+ const controller = useMediaEditorState();
16
+ return /* @__PURE__ */ jsx(MediaEditorStateContext.Provider, {
17
+ value: controller,
18
+ children
19
+ });
15
20
  }
21
+ /**
22
+ * Consume the media editor session. Throws if used
23
+ * outside a `<MediaEditorStateProvider>`.
24
+ *
25
+ * @return The media editor session.
26
+ */
16
27
  function useMediaEditor() {
17
- const context = useContext(MediaEditorStateContext);
18
- if (!context) {
19
- throw new Error(
20
- "useMediaEditor must be used within a MediaEditorStateProvider."
21
- );
22
- }
23
- return context;
28
+ const context = useContext(MediaEditorStateContext);
29
+ if (!context) throw new Error("useMediaEditor must be used within a MediaEditorStateProvider.");
30
+ return context;
24
31
  }
25
- export {
26
- MediaEditorStateProvider,
27
- useMediaEditor
28
- };
29
- //# sourceMappingURL=media-editor-state-provider.mjs.map
32
+ export { MediaEditorStateProvider, useMediaEditor };
33
+
34
+ //# sourceMappingURL=media-editor-state-provider.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/state/media-editor-state-provider.tsx"],
4
- "sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseMediaEditorState,\n\ttype MediaEditorSession,\n} from './use-media-editor-state';\n\nconst MediaEditorStateContext = createContext< MediaEditorSession | null >(\n\tnull\n);\n\ninterface MediaEditorStateProviderProps {\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Provider that vends the media editor session via context. Wrap\n * the media editor in this so every consumer (canvas, toolbar,\n * sidebar) reads from the same store.\n *\n * @param props\n * @param props.children\n */\nexport function MediaEditorStateProvider( {\n\tchildren,\n}: MediaEditorStateProviderProps ) {\n\tconst controller = useMediaEditorState();\n\n\treturn (\n\t\t<MediaEditorStateContext.Provider value={ controller }>\n\t\t\t{ children }\n\t\t</MediaEditorStateContext.Provider>\n\t);\n}\n\n/**\n * Consume the media editor session. Throws if used\n * outside a `<MediaEditorStateProvider>`.\n *\n * @return The media editor session.\n */\nexport function useMediaEditor(): MediaEditorSession {\n\tconst context = useContext( MediaEditorStateContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditor must be used within a MediaEditorStateProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],
5
- "mappings": ";AAAA,SAAS,eAAe,kBAAkB;AAC1C;AAAA,EACC;AAAA,OAEM;AAyBL;AAvBF,IAAM,0BAA0B;AAAA,EAC/B;AACD;AAeO,SAAS,yBAA0B;AAAA,EACzC;AACD,GAAmC;AAClC,QAAM,aAAa,oBAAoB;AAEvC,SACC,oBAAC,wBAAwB,UAAxB,EAAiC,OAAQ,YACvC,UACH;AAEF;AAQO,SAAS,iBAAqC;AACpD,QAAM,UAAU,WAAY,uBAAwB;AACpD,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"media-editor-state-provider.mjs","names":[],"sources":["../../src/state/media-editor-state-provider.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseMediaEditorState,\n\ttype MediaEditorSession,\n} from './use-media-editor-state';\n\nconst MediaEditorStateContext = createContext< MediaEditorSession | null >(\n\tnull\n);\n\ninterface MediaEditorStateProviderProps {\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Provider that vends the media editor session via context. Wrap\n * the media editor in this so every consumer (canvas, toolbar,\n * sidebar) reads from the same store.\n *\n * @param props\n * @param props.children\n */\nexport function MediaEditorStateProvider( {\n\tchildren,\n}: MediaEditorStateProviderProps ) {\n\tconst controller = useMediaEditorState();\n\n\treturn (\n\t\t<MediaEditorStateContext.Provider value={ controller }>\n\t\t\t{ children }\n\t\t</MediaEditorStateContext.Provider>\n\t);\n}\n\n/**\n * Consume the media editor session. Throws if used\n * outside a `<MediaEditorStateProvider>`.\n *\n * @return The media editor session.\n */\nexport function useMediaEditor(): MediaEditorSession {\n\tconst context = useContext( MediaEditorStateContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditor must be used within a MediaEditorStateProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":";;;;AAMA,MAAM,0BAA0B,cAC/B,IACD;;;;;;;;;AAeA,SAAgB,yBAA0B,EACzC,YACkC;CAClC,MAAM,aAAa,oBAAoB;CAEvC,OACC,oBAAC,wBAAwB,UAAzB;EAAkC,OAAQ;EACvC;CAC+B,CAAA;AAEpC;;;;;;;AAQA,SAAgB,iBAAqC;CACpD,MAAM,UAAU,WAAY,uBAAwB;CACpD,IAAK,CAAE,SACN,MAAM,IAAI,MACT,gEACD;CAED,OAAO;AACR"}
@@ -1,8 +1,8 @@
1
1
  // packages/media-editor/src/state/types.ts
2
- var DEFAULT_CROP_OPTIONS = {
3
- aspectRatioValue: "0"
4
- };
5
- export {
6
- DEFAULT_CROP_OPTIONS
7
- };
8
- //# sourceMappingURL=types.mjs.map
2
+ /**
3
+ * The crop options a session starts from.
4
+ */
5
+ const DEFAULT_CROP_OPTIONS = { aspectRatioValue: "0" };
6
+ export { DEFAULT_CROP_OPTIONS };
7
+
8
+ //# sourceMappingURL=types.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/state/types.ts"],
4
- "sourcesContent": ["import type {\n\tCropperAction,\n\tCropperState,\n\tNormalizedRect,\n\tSize,\n} from '../image-editor';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * A value an edit can hold: plain data only, because the session\n * compares values by content to tell a real change from a no-op.\n * Anything else, such as a `Blob`, would compare equal to any other\n * and the change would be dropped — keep bytes behind a URL instead.\n *\n * Objects must satisfy the index signature, so type a value with a\n * `type` alias rather than an `interface`.\n */\nexport type EditValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| EditValue[]\n\t| { [ key: string ]: EditValue };\n\n/**\n * Named edits other than crop, keyed by edit name (for example\n * `my-plugin/vignette`). An edit that is not present means \"no edit\".\n */\nexport type EditsSlice = Record< string, EditValue >;\n\n/**\n * The full composite state for the media editor — cropper geometry,\n * the sidebar control slice, and named edits.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\tcropper: CropperState;\n\tcropOptions: CropOptionsSlice;\n\tedits: EditsSlice;\n}\n\n/**\n * Composite reducer action union.\n *\n * Cropper geometry actions are wrapped in a `CROPPER` envelope and\n * delegated to the pure `cropperReducer`. Sidebar and history\n * concerns are first-class actions on this reducer.\n */\nexport type MediaEditorAction =\n\t/**\n\t * Delegate to the underlying cropper reducer. Used for every\n\t * geometry transition (pan / zoom / rotation / flip / cropRect /\n\t * settle / etc.).\n\t */\n\t| {\n\t\t\ttype: 'CROPPER';\n\t\t\taction: CropperAction;\n\t }\n\t/**\n\t * Set the aspect-ratio preset. Atomically updates the preset key\n\t * and the cropRect (computed from the resolved ratio and the\n\t * current visualSize). One transaction = one undo entry.\n\t */\n\t| {\n\t\t\ttype: 'SET_ASPECT_RATIO_VALUE';\n\t\t\tpayload: {\n\t\t\t\t/** Preset key as it appears in the dropdown. */\n\t\t\t\tpresetKey: string;\n\t\t\t\t/**\n\t\t\t\t * Resolved width/height ratio. `undefined` = Free\n\t\t\t\t * (no lock; cropRect stays where it is).\n\t\t\t\t */\n\t\t\t\tresolved: number | undefined;\n\t\t\t\t/**\n\t\t\t\t * Rendered image size used to compute the inscribed\n\t\t\t\t * rect. Caller supplies it because the reducer is\n\t\t\t\t * framework-agnostic and has no DOM access.\n\t\t\t\t */\n\t\t\t\tvisualSize: Size;\n\t\t\t};\n\t }\n\t/**\n\t * Put every slice back to its starting state, keeping the image:\n\t * default geometry, default crop options, no edits. One action,\n\t * so one undo entry.\n\t */\n\t| { type: 'RESET' }\n\t/** Set a named edit, or remove it when `value` is `undefined`. */\n\t| {\n\t\t\ttype: 'SET_EDIT';\n\t\t\tpayload: { name: string; value: EditValue | undefined };\n\t }\n\t/**\n\t * Replace the entire composite state with `payload`. Used by\n\t * undo/redo to restore a full snapshot atomically.\n\t */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }\n\t/**\n\t * Adjust the cropper's cropRect in response to a viewport change\n\t * (e.g., window resize). Behaviorally identical to a `CROPPER\n\t * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip\n\t * history recording — viewport reshapes aren't editor actions.\n\t */\n\t| {\n\t\t\ttype: 'VIEWPORT_ADJUST_CROP_RECT';\n\t\t\tpayload: NormalizedRect;\n\t };\n"],
5
- "mappings": ";AAwBO,IAAM,uBAAyC;AAAA,EACrD,kBAAkB;AACnB;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../../src/state/types.ts"],"sourcesContent":["import type { ImageEditorState } from '@wordpress/image-editor';\n\n/**\n * Sidebar control state for the image editor, kept in the same undo history\n * as the crop.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio. The image editor holds the resolved ratio itself.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * The crop options a session starts from.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * A value an edit can hold: plain data only, because the session\n * compares values by content to tell a real change from a no-op.\n * Anything else, such as a `Blob`, would compare equal to any other\n * and the change would be dropped — keep bytes behind a URL instead.\n *\n * Objects must satisfy the index signature, so type a value with a\n * `type` alias rather than an `interface`.\n */\nexport type EditValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| EditValue[]\n\t| { [ key: string ]: EditValue };\n\n/**\n * Named edits other than crop, keyed by edit name (for example\n * `my-plugin/vignette`). An edit that is not present means \"no edit\".\n */\nexport type EditsSlice = Record< string, EditValue >;\n\n/**\n * The full state of the media editor: the image editor's state, the sidebar\n * crop options and named edits.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\timageEditor: ImageEditorState;\n\tcropOptions: CropOptionsSlice;\n\tedits: EditsSlice;\n}\n\n/** Actions the media editor reducer handles. */\nexport type MediaEditorAction =\n\t/** Replace the image editor's state with the next one it reports. */\n\t| { type: 'SET_IMAGE_EDITOR'; payload: ImageEditorState }\n\t/** Set the aspect-ratio preset the dropdown shows. */\n\t| { type: 'SET_ASPECT_RATIO_VALUE'; payload: string }\n\t/** Set a named edit, or remove it when `value` is `undefined`. */\n\t| {\n\t\t\ttype: 'SET_EDIT';\n\t\t\tpayload: { name: string; value: EditValue | undefined };\n\t }\n\t/**\n\t * Put every slice back to its starting state, keeping the image. One\n\t * action, so one undo entry.\n\t */\n\t| { type: 'RESET' }\n\t/** Replace the whole state with a snapshot (undo/redo). */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState };\n"],"mappings":";;;;AAkBA,MAAa,uBAAyC,EACrD,kBAAkB,IACnB"}