@wordpress/media-editor 0.20.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 (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -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