@wordpress/media-editor 0.21.0 → 0.22.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 (339) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/components/media-editor/index.cjs +533 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +43 -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 +111 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +122 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +65 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +183 -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 +119 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  19. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  20. package/build/components/media-editor-modal/index.cjs +112 -155
  21. package/build/components/media-editor-modal/index.cjs.map +1 -7
  22. package/build/components/media-editor-provider/index.cjs +32 -55
  23. package/build/components/media-editor-provider/index.cjs.map +1 -7
  24. package/build/components/media-form/index.cjs +76 -77
  25. package/build/components/media-form/index.cjs.map +1 -7
  26. package/build/components/media-preview/index.cjs +114 -114
  27. package/build/components/media-preview/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/index.cjs +181 -188
  29. package/build/components/rotation-ruler/index.cjs.map +1 -7
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  32. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  33. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  34. package/build/image-editor/core/camera.cjs +257 -205
  35. package/build/image-editor/core/camera.cjs.map +1 -7
  36. package/build/image-editor/core/constants.cjs +127 -102
  37. package/build/image-editor/core/constants.cjs.map +1 -7
  38. package/build/image-editor/core/containment.cjs +275 -262
  39. package/build/image-editor/core/containment.cjs.map +1 -7
  40. package/build/image-editor/core/crop-rect.cjs +33 -44
  41. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  42. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  43. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  44. package/build/image-editor/core/index.cjs +88 -61
  45. package/build/image-editor/core/interaction-controller.cjs +583 -646
  46. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  47. package/build/image-editor/core/math/rotation.cjs +26 -35
  48. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  49. package/build/image-editor/core/math/sanitize.cjs +124 -80
  50. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  51. package/build/image-editor/core/setter-helpers.cjs +57 -60
  52. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  53. package/build/image-editor/core/source-region.cjs +220 -190
  54. package/build/image-editor/core/source-region.cjs.map +1 -7
  55. package/build/image-editor/core/state.cjs +278 -265
  56. package/build/image-editor/core/state.cjs.map +1 -7
  57. package/build/image-editor/core/stencil-math.cjs +193 -206
  58. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  59. package/build/image-editor/core/transform-style.cjs +39 -48
  60. package/build/image-editor/core/transform-style.cjs.map +1 -7
  61. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  62. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  63. package/build/image-editor/core/types.cjs +4 -18
  64. package/build/image-editor/core/viewport-state.cjs +31 -45
  65. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  66. package/build/image-editor/index.cjs +65 -64
  67. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  68. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  69. package/build/image-editor/react/components/cropper.cjs +583 -710
  70. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  71. package/build/image-editor/react/components/index.cjs +22 -33
  72. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  74. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  76. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  78. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  80. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  81. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  82. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  84. package/build/image-editor/react/hooks/index.cjs +16 -31
  85. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  87. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  89. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  90. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  91. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  92. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  93. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  95. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  96. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  97. package/build/index.cjs +45 -39
  98. package/build/lock-unlock.cjs +9 -35
  99. package/build/lock-unlock.cjs.map +1 -7
  100. package/build/private-apis.cjs +16 -37
  101. package/build/private-apis.cjs.map +1 -7
  102. package/build/state/aspect-ratio-presets.cjs +53 -0
  103. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  104. package/build/state/composite-reducer.cjs +134 -112
  105. package/build/state/composite-reducer.cjs.map +1 -7
  106. package/build/state/index.cjs +63 -47
  107. package/build/state/media-editor-state-provider.cjs +35 -48
  108. package/build/state/media-editor-state-provider.cjs.map +1 -7
  109. package/build/state/types.cjs +12 -31
  110. package/build/state/types.cjs.map +1 -7
  111. package/build/state/use-media-editor-state.cjs +261 -294
  112. package/build/state/use-media-editor-state.cjs.map +1 -7
  113. package/build/store/actions.cjs +17 -44
  114. package/build/store/actions.cjs.map +1 -7
  115. package/build/store/constants.cjs +8 -29
  116. package/build/store/constants.cjs.map +1 -7
  117. package/build/store/index.cjs +33 -40
  118. package/build/store/index.cjs.map +1 -7
  119. package/build/store/reducer.cjs +28 -50
  120. package/build/store/reducer.cjs.map +1 -7
  121. package/build/store/selectors.cjs +16 -41
  122. package/build/store/selectors.cjs.map +1 -7
  123. package/build/utils/get-media-type.cjs +18 -41
  124. package/build/utils/get-media-type.cjs.map +1 -7
  125. package/build/utils/index.cjs +9 -28
  126. package/build-module/components/media-editor/index.mjs +490 -673
  127. package/build-module/components/media-editor/index.mjs.map +1 -7
  128. package/build-module/components/media-editor/use-crop-options.mjs +38 -32
  129. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  130. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  131. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  132. package/build-module/components/media-editor-canvas/index.mjs +98 -96
  133. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  134. package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
  135. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  136. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  137. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  138. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  139. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  140. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  142. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  144. package/build-module/components/media-editor-modal/index.mjs +88 -124
  145. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  146. package/build-module/components/media-editor-provider/index.mjs +26 -29
  147. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  148. package/build-module/components/media-form/index.mjs +68 -56
  149. package/build-module/components/media-form/index.mjs.map +1 -7
  150. package/build-module/components/media-preview/index.mjs +106 -90
  151. package/build-module/components/media-preview/index.mjs.map +1 -7
  152. package/build-module/components/rotation-ruler/index.mjs +161 -164
  153. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  154. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  156. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  158. package/build-module/image-editor/core/camera.mjs +245 -178
  159. package/build-module/image-editor/core/camera.mjs.map +1 -7
  160. package/build-module/image-editor/core/constants.mjs +110 -64
  161. package/build-module/image-editor/core/constants.mjs.map +1 -7
  162. package/build-module/image-editor/core/containment.mjs +265 -237
  163. package/build-module/image-editor/core/containment.mjs.map +1 -7
  164. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  165. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  166. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  168. package/build-module/image-editor/core/index.mjs +5 -34
  169. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  170. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  171. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  172. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  173. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  174. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  175. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  176. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  177. package/build-module/image-editor/core/source-region.mjs +210 -160
  178. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  179. package/build-module/image-editor/core/state.mjs +271 -243
  180. package/build-module/image-editor/core/state.mjs.map +1 -7
  181. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  182. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  183. package/build-module/image-editor/core/transform-style.mjs +34 -23
  184. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  185. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  186. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  187. package/build-module/image-editor/core/types.mjs +0 -1
  188. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  189. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  190. package/build-module/image-editor/index.mjs +3 -38
  191. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  192. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  193. package/build-module/image-editor/react/components/cropper.mjs +550 -686
  194. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  195. package/build-module/image-editor/react/components/index.mjs +1 -7
  196. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  198. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  200. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  202. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  204. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  205. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  206. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  208. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  209. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  211. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  213. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  215. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  217. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  219. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  220. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  221. package/build-module/index.mjs +3 -10
  222. package/build-module/lock-unlock.mjs +5 -10
  223. package/build-module/lock-unlock.mjs.map +1 -7
  224. package/build-module/private-apis.mjs +8 -9
  225. package/build-module/private-apis.mjs.map +1 -7
  226. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  227. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  228. package/build-module/state/composite-reducer.mjs +114 -90
  229. package/build-module/state/composite-reducer.mjs.map +1 -7
  230. package/build-module/state/index.mjs +5 -25
  231. package/build-module/state/media-editor-state-provider.mjs +29 -24
  232. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  233. package/build-module/state/types.mjs +8 -7
  234. package/build-module/state/types.mjs.map +1 -7
  235. package/build-module/state/use-media-editor-state.mjs +256 -286
  236. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  237. package/build-module/store/actions.mjs +12 -19
  238. package/build-module/store/actions.mjs.map +1 -7
  239. package/build-module/store/constants.mjs +4 -5
  240. package/build-module/store/constants.mjs.map +1 -7
  241. package/build-module/store/index.mjs +8 -9
  242. package/build-module/store/index.mjs.map +1 -7
  243. package/build-module/store/reducer.mjs +23 -26
  244. package/build-module/store/reducer.mjs.map +1 -7
  245. package/build-module/store/selectors.mjs +8 -13
  246. package/build-module/store/selectors.mjs.map +1 -7
  247. package/build-module/utils/get-media-type.mjs +14 -17
  248. package/build-module/utils/get-media-type.mjs.map +1 -7
  249. package/build-module/utils/index.mjs +1 -6
  250. package/build-style/style-rtl.css +41 -4
  251. package/build-style/style.css +41 -4
  252. package/build-types/components/media-editor/index.d.ts +4 -0
  253. package/build-types/components/media-editor/index.d.ts.map +1 -1
  254. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  256. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  257. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  258. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  259. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  260. package/build-types/components/media-preview/index.d.ts.map +1 -1
  261. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  262. package/build-types/image-editor/core/constants.d.ts +0 -1
  263. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  264. package/build-types/image-editor/core/index.d.ts +1 -1
  265. package/build-types/image-editor/core/index.d.ts.map +1 -1
  266. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  267. package/build-types/image-editor/core/types.d.ts +1 -1
  268. package/build-types/image-editor/index.d.ts +7 -6
  269. package/build-types/image-editor/index.d.ts.map +1 -1
  270. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  271. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  272. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  273. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  274. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  275. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  276. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  277. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  278. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  279. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  280. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  281. package/build-types/state/composite-reducer.d.ts +1 -1
  282. package/build-types/state/composite-reducer.d.ts.map +1 -1
  283. package/build-types/state/index.d.ts +1 -0
  284. package/build-types/state/index.d.ts.map +1 -1
  285. package/build-types/state/types.d.ts +2 -1
  286. package/build-types/state/types.d.ts.map +1 -1
  287. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  288. package/package.json +21 -21
  289. package/src/components/media-editor/index.tsx +215 -162
  290. package/src/components/media-editor/style.scss +19 -0
  291. package/src/components/media-editor/use-crop-options.ts +5 -2
  292. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  293. package/src/components/media-editor-canvas/index.tsx +16 -26
  294. package/src/components/media-editor-image-controls/index.tsx +4 -2
  295. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  296. package/src/components/media-editor-modal/style.scss +1 -1
  297. package/src/components/media-preview/index.tsx +66 -23
  298. package/src/components/media-preview/style.scss +16 -2
  299. package/src/components/rotation-ruler/style.scss +6 -2
  300. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  301. package/src/image-editor/README.md +8 -8
  302. package/src/image-editor/core/constants.ts +0 -13
  303. package/src/image-editor/core/index.ts +1 -5
  304. package/src/image-editor/core/setter-helpers.ts +1 -1
  305. package/src/image-editor/core/types.ts +1 -1
  306. package/src/image-editor/docs/architecture.md +1 -1
  307. package/src/image-editor/docs/recipes.md +3 -3
  308. package/src/image-editor/index.ts +7 -16
  309. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  310. package/src/image-editor/react/components/cropper.tsx +19 -27
  311. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  312. package/src/image-editor/react/hooks/index.ts +2 -2
  313. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  314. package/src/state/aspect-ratio-presets.ts +18 -0
  315. package/src/state/composite-reducer.ts +2 -2
  316. package/src/state/index.ts +1 -0
  317. package/src/state/types.ts +2 -6
  318. package/src/state/use-media-editor-state.ts +7 -5
  319. package/build/image-editor/core/index.cjs.map +0 -7
  320. package/build/image-editor/core/types.cjs.map +0 -7
  321. package/build/image-editor/index.cjs.map +0 -7
  322. package/build/image-editor/react/components/index.cjs.map +0 -7
  323. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  324. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  325. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  326. package/build/index.cjs.map +0 -7
  327. package/build/state/index.cjs.map +0 -7
  328. package/build/utils/index.cjs.map +0 -7
  329. package/build-module/image-editor/core/index.mjs.map +0 -7
  330. package/build-module/image-editor/core/types.mjs.map +0 -7
  331. package/build-module/image-editor/index.mjs.map +0 -7
  332. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  333. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  334. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  335. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  336. package/build-module/index.mjs.map +0 -7
  337. package/build-module/state/index.mjs.map +0 -7
  338. package/build-module/utils/index.mjs.map +0 -7
  339. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
@@ -1,260 +1,288 @@
1
+ import { ABSOLUTE_MIN_ZOOM, DEFAULT_STATE, MAX_ZOOM, MIN_ZOOM } from "./constants.mjs";
2
+ import { degreesToRadians, normalizeRotation } from "./math/rotation.mjs";
3
+ import { restrictCropRect, restrictPanZoom } from "./containment.mjs";
1
4
  // packages/media-editor/src/image-editor/core/state.ts
2
- import {
3
- ABSOLUTE_MIN_ZOOM,
4
- DEFAULT_STATE,
5
- MAX_ZOOM,
6
- MIN_ZOOM
7
- } from "./constants.mjs";
8
- import { normalizeRotation, degreesToRadians } from "./math/rotation.mjs";
9
- import { restrictPanZoom, restrictCropRect } from "./containment.mjs";
10
- var STATE_EPSILON = 1e-6;
5
+ /** Small tolerance for cropper floating-point comparisons. */
6
+ const STATE_EPSILON = 1e-6;
11
7
  function nearlyEqual(a, b) {
12
- return Math.abs(a - b) < STATE_EPSILON;
8
+ return Math.abs(a - b) < STATE_EPSILON;
13
9
  }
10
+ /**
11
+ * Value-equality check for two cropper states.
12
+ *
13
+ * Used by history machinery to dedup snapshots and detect no-op
14
+ * transitions. Compares every field that participates in the rendered
15
+ * output; ignores reference identity.
16
+ *
17
+ * @param a First cropper state.
18
+ * @param b Second cropper state.
19
+ * @return Whether the two states are value-equal across all tracked fields.
20
+ */
14
21
  function areCropperStatesEqual(a, b) {
15
- const aImage = a.image;
16
- const bImage = b.image;
17
- return aImage?.src === bImage?.src && aImage?.naturalWidth === bImage?.naturalWidth && aImage?.naturalHeight === bImage?.naturalHeight && nearlyEqual(a.pan.x, b.pan.x) && nearlyEqual(a.pan.y, b.pan.y) && nearlyEqual(a.zoom, b.zoom) && nearlyEqual(a.rotation, b.rotation) && a.flip.horizontal === b.flip.horizontal && a.flip.vertical === b.flip.vertical && nearlyEqual(a.cropRect.x, b.cropRect.x) && nearlyEqual(a.cropRect.y, b.cropRect.y) && nearlyEqual(a.cropRect.width, b.cropRect.width) && nearlyEqual(a.cropRect.height, b.cropRect.height);
22
+ const aImage = a.image;
23
+ const bImage = b.image;
24
+ return aImage?.src === bImage?.src && aImage?.naturalWidth === bImage?.naturalWidth && aImage?.naturalHeight === bImage?.naturalHeight && nearlyEqual(a.pan.x, b.pan.x) && nearlyEqual(a.pan.y, b.pan.y) && nearlyEqual(a.zoom, b.zoom) && nearlyEqual(a.rotation, b.rotation) && a.flip.horizontal === b.flip.horizontal && a.flip.vertical === b.flip.vertical && nearlyEqual(a.cropRect.x, b.cropRect.x) && nearlyEqual(a.cropRect.y, b.cropRect.y) && nearlyEqual(a.cropRect.width, b.cropRect.width) && nearlyEqual(a.cropRect.height, b.cropRect.height);
18
25
  }
19
26
  function clampRequestedZoom(state, zoom) {
20
- if (state.image) {
21
- return Math.min(MAX_ZOOM, Math.max(ABSOLUTE_MIN_ZOOM, zoom));
22
- }
23
- return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
27
+ if (state.image) return Math.min(MAX_ZOOM, Math.max(ABSOLUTE_MIN_ZOOM, zoom));
28
+ return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
24
29
  }
30
+ /**
31
+ * Translate a pipeline transform operation into the equivalent
32
+ * reducer action. Pipeline ops aren't 1:1 with reducer actions —
33
+ * `rotate` is a delta here, whereas SET_ROTATION takes an absolute
34
+ * angle — so deltas are resolved against the current state.
35
+ *
36
+ * Used by APPLY_OPERATION (and by the pipeline module's
37
+ * `applyOperationToState`, which is now a thin wrapper around the
38
+ * reducer) so that pipeline replay produces identical bounded
39
+ * state to UI interaction or direct setters.
40
+ *
41
+ * @param state The current cropper state.
42
+ * @param op The pipeline operation.
43
+ * @return The equivalent reducer action.
44
+ */
25
45
  function operationToAction(state, op) {
26
- switch (op.type) {
27
- case "crop":
28
- return { type: "SET_CROP_RECT", payload: { ...op.rect } };
29
- case "rotate": {
30
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
31
- const fieldDelta = singleFlip ? -op.degrees : op.degrees;
32
- return {
33
- type: "SET_ROTATION",
34
- payload: normalizeRotation(state.rotation + fieldDelta)
35
- };
36
- }
37
- case "flip":
38
- return {
39
- type: "SET_FLIP",
40
- payload: {
41
- ...state.flip,
42
- [op.direction]: !state.flip[op.direction]
43
- }
44
- };
45
- case "zoom":
46
- return { type: "SET_ZOOM", payload: op.factor };
47
- }
46
+ switch (op.type) {
47
+ case "crop": return {
48
+ type: "SET_CROP_RECT",
49
+ payload: { ...op.rect }
50
+ };
51
+ case "rotate": {
52
+ const fieldDelta = state.flip.horizontal !== state.flip.vertical ? -op.degrees : op.degrees;
53
+ return {
54
+ type: "SET_ROTATION",
55
+ payload: normalizeRotation(state.rotation + fieldDelta)
56
+ };
57
+ }
58
+ case "flip": return {
59
+ type: "SET_FLIP",
60
+ payload: {
61
+ ...state.flip,
62
+ [op.direction]: !state.flip[op.direction]
63
+ }
64
+ };
65
+ case "zoom": return {
66
+ type: "SET_ZOOM",
67
+ payload: op.factor
68
+ };
69
+ }
48
70
  }
71
+ /**
72
+ * Enforces containment: restricts the crop rect to fit within the
73
+ * rotated image, computes minimum zoom, clamps zoom, and restricts
74
+ * the pan position so the image always covers the crop area.
75
+ * Called after every relevant state transition.
76
+ *
77
+ * @param state The state to enforce containment on.
78
+ * @return The state with cropRect, zoom, and position restricted.
79
+ */
49
80
  function enforceContainment(state) {
50
- if (!state.image) {
51
- return state;
52
- }
53
- const imageSize = {
54
- width: state.image.naturalWidth,
55
- height: state.image.naturalHeight
56
- };
57
- const imageAspectRatio = imageSize.width / imageSize.height;
58
- const { pan: panAfterZoom, zoom } = restrictPanZoom(
59
- state,
60
- imageSize,
61
- state.cropRect
62
- );
63
- const cropRect = restrictCropRect(
64
- state.cropRect,
65
- zoom,
66
- state.rotation,
67
- imageAspectRatio
68
- );
69
- let pan = panAfterZoom;
70
- if (cropRect !== state.cropRect) {
71
- ({ pan } = restrictPanZoom(
72
- { ...state, zoom, cropRect },
73
- imageSize,
74
- cropRect
75
- ));
76
- }
77
- if (pan.x === state.pan.x && pan.y === state.pan.y && zoom === state.zoom && cropRect === state.cropRect) {
78
- return state;
79
- }
80
- return { ...state, pan, zoom, cropRect };
81
+ if (!state.image) return state;
82
+ const imageSize = {
83
+ width: state.image.naturalWidth,
84
+ height: state.image.naturalHeight
85
+ };
86
+ const imageAspectRatio = imageSize.width / imageSize.height;
87
+ const { pan: panAfterZoom, zoom } = restrictPanZoom(state, imageSize, state.cropRect);
88
+ const cropRect = restrictCropRect(state.cropRect, zoom, state.rotation, imageAspectRatio);
89
+ let pan = panAfterZoom;
90
+ if (cropRect !== state.cropRect) ({pan} = restrictPanZoom({
91
+ ...state,
92
+ zoom,
93
+ cropRect
94
+ }, imageSize, cropRect));
95
+ if (pan.x === state.pan.x && pan.y === state.pan.y && zoom === state.zoom && cropRect === state.cropRect) return state;
96
+ return {
97
+ ...state,
98
+ pan,
99
+ zoom,
100
+ cropRect
101
+ };
81
102
  }
103
+ /**
104
+ * Snapshot the current `crop`, `zoom`, and `rotation` into the
105
+ * corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called
106
+ * by every committing action so that the next SET_ROTATION derives
107
+ * its transient pan from a fresh base (not from a drifted one).
108
+ *
109
+ * SET_ROTATION is the only action that does NOT commit base — it
110
+ * reads the base, computes a transient pan, and leaves the base
111
+ * alone. This is what eliminates rotation drift near edges.
112
+ *
113
+ * @param next The post-containment state to commit.
114
+ * @return The state with base fields synced to current.
115
+ */
82
116
  function commitBase(next) {
83
- if (next.basePan.x === next.pan.x && next.basePan.y === next.pan.y && next.baseZoom === next.zoom && next.baseRotation === next.rotation) {
84
- return next;
85
- }
86
- return {
87
- ...next,
88
- basePan: { x: next.pan.x, y: next.pan.y },
89
- baseZoom: next.zoom,
90
- baseRotation: next.rotation
91
- };
117
+ if (next.basePan.x === next.pan.x && next.basePan.y === next.pan.y && next.baseZoom === next.zoom && next.baseRotation === next.rotation) return next;
118
+ return {
119
+ ...next,
120
+ basePan: {
121
+ x: next.pan.x,
122
+ y: next.pan.y
123
+ },
124
+ baseZoom: next.zoom,
125
+ baseRotation: next.rotation
126
+ };
92
127
  }
128
+ /**
129
+ * Reducer function for cropper state management.
130
+ *
131
+ * Every state transition that could invalidate the containment invariant
132
+ * (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment
133
+ * to ensure the image always covers the crop area.
134
+ *
135
+ * Committing actions (everything except SET_ROTATION) also call
136
+ * `commitBase` to snapshot the post-containment state as the new
137
+ * base pose. SET_ROTATION derives from that base without mutating
138
+ * it, which prevents accumulated-clamp drift during continuous fine
139
+ * rotation.
140
+ *
141
+ * @param state The current cropper state.
142
+ * @param action The action to process.
143
+ * @return The new cropper state.
144
+ */
93
145
  function cropperReducer(state, action) {
94
- switch (action.type) {
95
- case "SET_IMAGE":
96
- return commitBase(
97
- enforceContainment({
98
- ...state,
99
- image: action.payload
100
- })
101
- );
102
- case "SET_PAN":
103
- return commitBase(
104
- enforceContainment({
105
- ...state,
106
- pan: action.payload
107
- })
108
- );
109
- case "SET_ZOOM": {
110
- const z = clampRequestedZoom(state, action.payload);
111
- return commitBase(
112
- enforceContainment({
113
- ...state,
114
- zoom: z
115
- })
116
- );
117
- }
118
- case "SET_ZOOM_AT_POINT": {
119
- const z = clampRequestedZoom(state, action.payload.zoom);
120
- return commitBase(
121
- enforceContainment({
122
- ...state,
123
- zoom: z,
124
- pan: action.payload.pan
125
- })
126
- );
127
- }
128
- case "SET_ROTATION": {
129
- const newRotation = normalizeRotation(action.payload);
130
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
131
- const deltaRad = degreesToRadians(
132
- newRotation - state.baseRotation
133
- );
134
- const cos = Math.cos(deltaRad);
135
- const sin = Math.sin(deltaRad) * (singleFlip ? -1 : 1);
136
- const cropCx = state.cropRect.x + state.cropRect.width / 2;
137
- const cropCy = state.cropRect.y + state.cropRect.height / 2;
138
- const ox = cropCx - 0.5;
139
- const oy = cropCy - 0.5;
140
- const dx = state.basePan.x - ox;
141
- const dy = state.basePan.y - oy;
142
- return enforceContainment({
143
- ...state,
144
- rotation: newRotation,
145
- zoom: state.baseZoom,
146
- pan: {
147
- x: ox + cos * dx - sin * dy,
148
- y: oy + sin * dx + cos * dy
149
- }
150
- });
151
- }
152
- case "SNAP_ROTATE_90": {
153
- const rawDir = action.payload.direction;
154
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
155
- const fieldDir = singleFlip ? -rawDir : rawDir;
156
- const rot90 = normalizeRotation(state.rotation + fieldDir * 90);
157
- const rect = state.cropRect;
158
- const cx = rect.x + rect.width / 2;
159
- const cy = rect.y + rect.height / 2;
160
- const newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;
161
- const newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;
162
- return commitBase(
163
- enforceContainment({
164
- ...state,
165
- rotation: rot90,
166
- zoom: state.baseZoom,
167
- pan: { x: newPanX, y: newPanY },
168
- cropRect: {
169
- x: cx - rect.height / 2,
170
- y: cy - rect.width / 2,
171
- width: rect.height,
172
- height: rect.width
173
- }
174
- })
175
- );
176
- }
177
- case "SET_FLIP": {
178
- const oldFlip = state.flip;
179
- const newFlip = action.payload;
180
- const flippedH = oldFlip.horizontal !== newFlip.horizontal;
181
- const flippedV = oldFlip.vertical !== newFlip.vertical;
182
- const rect = state.cropRect;
183
- return commitBase(
184
- enforceContainment({
185
- ...state,
186
- flip: newFlip,
187
- pan: {
188
- x: flippedH ? -state.pan.x : state.pan.x,
189
- y: flippedV ? -state.pan.y : state.pan.y
190
- },
191
- cropRect: {
192
- x: flippedH ? 1 - rect.x - rect.width : rect.x,
193
- y: flippedV ? 1 - rect.y - rect.height : rect.y,
194
- width: rect.width,
195
- height: rect.height
196
- }
197
- })
198
- );
199
- }
200
- case "SET_CROP_RECT":
201
- return commitBase(
202
- enforceContainment({
203
- ...state,
204
- cropRect: action.payload
205
- })
206
- );
207
- case "SETTLE_CROP": {
208
- const rect = state.cropRect;
209
- if (rect.width === 0 || rect.height === 0 || !state.image) {
210
- return state;
211
- }
212
- const fitScale = 1 / Math.max(rect.width, rect.height);
213
- const zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;
214
- const s = Math.min(fitScale, zoomCap);
215
- const newW = rect.width * s;
216
- const newH = rect.height * s;
217
- const oldCx = rect.x + rect.width / 2;
218
- const oldCy = rect.y + rect.height / 2;
219
- return commitBase(
220
- enforceContainment({
221
- ...state,
222
- zoom: state.zoom * s,
223
- pan: {
224
- x: (state.pan.x - oldCx + 0.5) * s,
225
- y: (state.pan.y - oldCy + 0.5) * s
226
- },
227
- cropRect: {
228
- x: (1 - newW) / 2,
229
- y: (1 - newH) / 2,
230
- width: newW,
231
- height: newH
232
- }
233
- })
234
- );
235
- }
236
- case "APPLY_OPERATION":
237
- return cropperReducer(
238
- state,
239
- operationToAction(state, action.payload)
240
- );
241
- case "RESET":
242
- return commitBase(
243
- enforceContainment({
244
- ...DEFAULT_STATE,
245
- image: state.image,
246
- ...action.payload
247
- })
248
- );
249
- }
146
+ switch (action.type) {
147
+ case "SET_IMAGE": return commitBase(enforceContainment({
148
+ ...state,
149
+ image: action.payload
150
+ }));
151
+ case "SET_PAN": return commitBase(enforceContainment({
152
+ ...state,
153
+ pan: action.payload
154
+ }));
155
+ case "SET_ZOOM": {
156
+ const z = clampRequestedZoom(state, action.payload);
157
+ return commitBase(enforceContainment({
158
+ ...state,
159
+ zoom: z
160
+ }));
161
+ }
162
+ case "SET_ZOOM_AT_POINT": {
163
+ const z = clampRequestedZoom(state, action.payload.zoom);
164
+ return commitBase(enforceContainment({
165
+ ...state,
166
+ zoom: z,
167
+ pan: action.payload.pan
168
+ }));
169
+ }
170
+ case "SET_ROTATION": {
171
+ const newRotation = normalizeRotation(action.payload);
172
+ const singleFlip = state.flip.horizontal !== state.flip.vertical;
173
+ const deltaRad = degreesToRadians(newRotation - state.baseRotation);
174
+ const cos = Math.cos(deltaRad);
175
+ const sin = Math.sin(deltaRad) * (singleFlip ? -1 : 1);
176
+ const cropCx = state.cropRect.x + state.cropRect.width / 2;
177
+ const cropCy = state.cropRect.y + state.cropRect.height / 2;
178
+ const ox = cropCx - .5;
179
+ const oy = cropCy - .5;
180
+ const dx = state.basePan.x - ox;
181
+ const dy = state.basePan.y - oy;
182
+ return enforceContainment({
183
+ ...state,
184
+ rotation: newRotation,
185
+ zoom: state.baseZoom,
186
+ pan: {
187
+ x: ox + cos * dx - sin * dy,
188
+ y: oy + sin * dx + cos * dy
189
+ }
190
+ });
191
+ }
192
+ case "SNAP_ROTATE_90": {
193
+ const rawDir = action.payload.direction;
194
+ const fieldDir = state.flip.horizontal !== state.flip.vertical ? -rawDir : rawDir;
195
+ const rot90 = normalizeRotation(state.rotation + fieldDir * 90);
196
+ const rect = state.cropRect;
197
+ const cx = rect.x + rect.width / 2;
198
+ const cy = rect.y + rect.height / 2;
199
+ const newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;
200
+ const newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;
201
+ return commitBase(enforceContainment({
202
+ ...state,
203
+ rotation: rot90,
204
+ zoom: state.baseZoom,
205
+ pan: {
206
+ x: newPanX,
207
+ y: newPanY
208
+ },
209
+ cropRect: {
210
+ x: cx - rect.height / 2,
211
+ y: cy - rect.width / 2,
212
+ width: rect.height,
213
+ height: rect.width
214
+ }
215
+ }));
216
+ }
217
+ case "SET_FLIP": {
218
+ const oldFlip = state.flip;
219
+ const newFlip = action.payload;
220
+ const flippedH = oldFlip.horizontal !== newFlip.horizontal;
221
+ const flippedV = oldFlip.vertical !== newFlip.vertical;
222
+ const rect = state.cropRect;
223
+ return commitBase(enforceContainment({
224
+ ...state,
225
+ flip: newFlip,
226
+ pan: {
227
+ x: flippedH ? -state.pan.x : state.pan.x,
228
+ y: flippedV ? -state.pan.y : state.pan.y
229
+ },
230
+ cropRect: {
231
+ x: flippedH ? 1 - rect.x - rect.width : rect.x,
232
+ y: flippedV ? 1 - rect.y - rect.height : rect.y,
233
+ width: rect.width,
234
+ height: rect.height
235
+ }
236
+ }));
237
+ }
238
+ case "SET_CROP_RECT": return commitBase(enforceContainment({
239
+ ...state,
240
+ cropRect: action.payload
241
+ }));
242
+ case "SETTLE_CROP": {
243
+ const rect = state.cropRect;
244
+ if (rect.width === 0 || rect.height === 0 || !state.image) return state;
245
+ const fitScale = 1 / Math.max(rect.width, rect.height);
246
+ const zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;
247
+ const s = Math.min(fitScale, zoomCap);
248
+ const newW = rect.width * s;
249
+ const newH = rect.height * s;
250
+ const oldCx = rect.x + rect.width / 2;
251
+ const oldCy = rect.y + rect.height / 2;
252
+ return commitBase(enforceContainment({
253
+ ...state,
254
+ zoom: state.zoom * s,
255
+ pan: {
256
+ x: (state.pan.x - oldCx + .5) * s,
257
+ y: (state.pan.y - oldCy + .5) * s
258
+ },
259
+ cropRect: {
260
+ x: (1 - newW) / 2,
261
+ y: (1 - newH) / 2,
262
+ width: newW,
263
+ height: newH
264
+ }
265
+ }));
266
+ }
267
+ case "APPLY_OPERATION": return cropperReducer(state, operationToAction(state, action.payload));
268
+ case "RESET": return commitBase(enforceContainment({
269
+ ...DEFAULT_STATE,
270
+ image: state.image,
271
+ ...action.payload
272
+ }));
273
+ }
250
274
  }
275
+ /**
276
+ * Shallow comparison of key cropper state fields to determine if
277
+ * the state has been modified from an initial snapshot.
278
+ *
279
+ * @param current The current cropper state.
280
+ * @param initial The initial cropper state snapshot.
281
+ * @return True if any tracked field differs.
282
+ */
251
283
  function isStateDirty(current, initial) {
252
- return !nearlyEqual(current.pan.x, initial.pan.x) || !nearlyEqual(current.pan.y, initial.pan.y) || !nearlyEqual(current.zoom, initial.zoom) || !nearlyEqual(current.rotation, initial.rotation) || current.flip.horizontal !== initial.flip.horizontal || current.flip.vertical !== initial.flip.vertical || !nearlyEqual(current.cropRect.x, initial.cropRect.x) || !nearlyEqual(current.cropRect.y, initial.cropRect.y) || !nearlyEqual(current.cropRect.width, initial.cropRect.width) || !nearlyEqual(current.cropRect.height, initial.cropRect.height);
284
+ return !nearlyEqual(current.pan.x, initial.pan.x) || !nearlyEqual(current.pan.y, initial.pan.y) || !nearlyEqual(current.zoom, initial.zoom) || !nearlyEqual(current.rotation, initial.rotation) || current.flip.horizontal !== initial.flip.horizontal || current.flip.vertical !== initial.flip.vertical || !nearlyEqual(current.cropRect.x, initial.cropRect.x) || !nearlyEqual(current.cropRect.y, initial.cropRect.y) || !nearlyEqual(current.cropRect.width, initial.cropRect.width) || !nearlyEqual(current.cropRect.height, initial.cropRect.height);
253
285
  }
254
- export {
255
- areCropperStatesEqual,
256
- cropperReducer,
257
- enforceContainment,
258
- isStateDirty
259
- };
260
- //# sourceMappingURL=state.mjs.map
286
+ export { areCropperStatesEqual, cropperReducer, enforceContainment, isStateDirty };
287
+
288
+ //# sourceMappingURL=state.mjs.map