@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,484 +0,0 @@
1
- import type { CropperAction, CropperState, TransformOperation } from './types';
2
- import {
3
- ABSOLUTE_MIN_ZOOM,
4
- DEFAULT_STATE,
5
- MAX_ZOOM,
6
- MIN_ZOOM,
7
- } from './constants';
8
- import { normalizeRotation, degreesToRadians } from './math/rotation';
9
- import { restrictPanZoom, restrictCropRect } from './containment';
10
-
11
- /** Small tolerance for cropper floating-point comparisons. */
12
- const STATE_EPSILON = 1e-6;
13
-
14
- function nearlyEqual( a: number, b: number ): boolean {
15
- return Math.abs( a - b ) < STATE_EPSILON;
16
- }
17
-
18
- /**
19
- * Value-equality check for two cropper states.
20
- *
21
- * Used by history machinery to dedup snapshots and detect no-op
22
- * transitions. Compares every field that participates in the rendered
23
- * output; ignores reference identity.
24
- *
25
- * @param a First cropper state.
26
- * @param b Second cropper state.
27
- * @return Whether the two states are value-equal across all tracked fields.
28
- */
29
- export function areCropperStatesEqual(
30
- a: CropperState,
31
- b: CropperState
32
- ): boolean {
33
- const aImage = a.image;
34
- const bImage = b.image;
35
- return (
36
- aImage?.src === bImage?.src &&
37
- aImage?.naturalWidth === bImage?.naturalWidth &&
38
- aImage?.naturalHeight === bImage?.naturalHeight &&
39
- nearlyEqual( a.pan.x, b.pan.x ) &&
40
- nearlyEqual( a.pan.y, b.pan.y ) &&
41
- nearlyEqual( a.zoom, b.zoom ) &&
42
- nearlyEqual( a.rotation, b.rotation ) &&
43
- a.flip.horizontal === b.flip.horizontal &&
44
- a.flip.vertical === b.flip.vertical &&
45
- nearlyEqual( a.cropRect.x, b.cropRect.x ) &&
46
- nearlyEqual( a.cropRect.y, b.cropRect.y ) &&
47
- nearlyEqual( a.cropRect.width, b.cropRect.width ) &&
48
- nearlyEqual( a.cropRect.height, b.cropRect.height )
49
- );
50
- }
51
-
52
- function clampRequestedZoom( state: CropperState, zoom: number ): number {
53
- // With an image, enforceContainment raises zoom to the coverage-aware
54
- // floor below. Without an image, no enforcement runs, so MIN_ZOOM stays
55
- // the conservative resting default.
56
- if ( state.image ) {
57
- return Math.min( MAX_ZOOM, Math.max( ABSOLUTE_MIN_ZOOM, zoom ) );
58
- }
59
- return Math.min( MAX_ZOOM, Math.max( MIN_ZOOM, zoom ) );
60
- }
61
-
62
- /**
63
- * Translate a pipeline transform operation into the equivalent
64
- * reducer action. Pipeline ops aren't 1:1 with reducer actions —
65
- * `rotate` is a delta here, whereas SET_ROTATION takes an absolute
66
- * angle — so deltas are resolved against the current state.
67
- *
68
- * Used by APPLY_OPERATION (and by the pipeline module's
69
- * `applyOperationToState`, which is now a thin wrapper around the
70
- * reducer) so that pipeline replay produces identical bounded
71
- * state to UI interaction or direct setters.
72
- *
73
- * @param state The current cropper state.
74
- * @param op The pipeline operation.
75
- * @return The equivalent reducer action.
76
- */
77
- function operationToAction(
78
- state: CropperState,
79
- op: TransformOperation
80
- ): CropperAction {
81
- switch ( op.type ) {
82
- case 'crop':
83
- return { type: 'SET_CROP_RECT', payload: { ...op.rect } };
84
- case 'rotate': {
85
- // `op.degrees` is the visual rotation the caller wants (positive
86
- // = CW on screen). A single-axis flip inverts on-screen rotation
87
- // relative to the rotation field, so negate the field delta in
88
- // that case — this keeps `{ type: 'rotate', degrees: 90 }` a
89
- // reliable "90° clockwise visually" instruction across flip
90
- // states, matching the SNAP_ROTATE_90 convention.
91
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
92
- const fieldDelta = singleFlip ? -op.degrees : op.degrees;
93
- return {
94
- type: 'SET_ROTATION',
95
- payload: normalizeRotation( state.rotation + fieldDelta ),
96
- };
97
- }
98
- case 'flip':
99
- return {
100
- type: 'SET_FLIP',
101
- payload: {
102
- ...state.flip,
103
- [ op.direction ]: ! state.flip[ op.direction ],
104
- },
105
- };
106
- case 'zoom':
107
- return { type: 'SET_ZOOM', payload: op.factor };
108
- }
109
- }
110
-
111
- /**
112
- * Enforces containment: restricts the crop rect to fit within the
113
- * rotated image, computes minimum zoom, clamps zoom, and restricts
114
- * the pan position so the image always covers the crop area.
115
- * Called after every relevant state transition.
116
- *
117
- * @param state The state to enforce containment on.
118
- * @return The state with cropRect, zoom, and position restricted.
119
- */
120
- export function enforceContainment( state: CropperState ): CropperState {
121
- if ( ! state.image ) {
122
- return state;
123
- }
124
- const imageSize = {
125
- width: state.image.naturalWidth,
126
- height: state.image.naturalHeight,
127
- };
128
- const imageAspectRatio = imageSize.width / imageSize.height;
129
-
130
- // 1. First bump zoom so the image can cover the crop rect as-is.
131
- // This ensures that explicit crop rect changes (e.g., fixed-crop
132
- // mode during rotation) get zoom accommodation, not crop shrinkage.
133
- const { pan: panAfterZoom, zoom } = restrictPanZoom(
134
- state,
135
- imageSize,
136
- state.cropRect
137
- );
138
-
139
- // 2. Now restrict the crop rect at the (possibly bumped) zoom.
140
- // This handles cases where the crop rect is still too large
141
- // (e.g., if zoom hit MAX_ZOOM).
142
- const cropRect = restrictCropRect(
143
- state.cropRect,
144
- zoom,
145
- state.rotation,
146
- imageAspectRatio
147
- );
148
-
149
- // 3. If the crop rect was shrunk, re-restrict pan for the new rect.
150
- let pan = panAfterZoom;
151
- if ( cropRect !== state.cropRect ) {
152
- ( { pan } = restrictPanZoom(
153
- { ...state, zoom, cropRect },
154
- imageSize,
155
- cropRect
156
- ) );
157
- }
158
-
159
- if (
160
- pan.x === state.pan.x &&
161
- pan.y === state.pan.y &&
162
- zoom === state.zoom &&
163
- cropRect === state.cropRect
164
- ) {
165
- return state;
166
- }
167
- return { ...state, pan, zoom, cropRect };
168
- }
169
-
170
- /**
171
- * Snapshot the current `crop`, `zoom`, and `rotation` into the
172
- * corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called
173
- * by every committing action so that the next SET_ROTATION derives
174
- * its transient pan from a fresh base (not from a drifted one).
175
- *
176
- * SET_ROTATION is the only action that does NOT commit base — it
177
- * reads the base, computes a transient pan, and leaves the base
178
- * alone. This is what eliminates rotation drift near edges.
179
- *
180
- * @param next The post-containment state to commit.
181
- * @return The state with base fields synced to current.
182
- */
183
- function commitBase( next: CropperState ): CropperState {
184
- if (
185
- next.basePan.x === next.pan.x &&
186
- next.basePan.y === next.pan.y &&
187
- next.baseZoom === next.zoom &&
188
- next.baseRotation === next.rotation
189
- ) {
190
- return next;
191
- }
192
- return {
193
- ...next,
194
- basePan: { x: next.pan.x, y: next.pan.y },
195
- baseZoom: next.zoom,
196
- baseRotation: next.rotation,
197
- };
198
- }
199
-
200
- /**
201
- * Reducer function for cropper state management.
202
- *
203
- * Every state transition that could invalidate the containment invariant
204
- * (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment
205
- * to ensure the image always covers the crop area.
206
- *
207
- * Committing actions (everything except SET_ROTATION) also call
208
- * `commitBase` to snapshot the post-containment state as the new
209
- * base pose. SET_ROTATION derives from that base without mutating
210
- * it, which prevents accumulated-clamp drift during continuous fine
211
- * rotation.
212
- *
213
- * @param state The current cropper state.
214
- * @param action The action to process.
215
- * @return The new cropper state.
216
- */
217
- export function cropperReducer(
218
- state: CropperState,
219
- action: CropperAction
220
- ): CropperState {
221
- // Every action runs through enforceContainment to maintain the invariant:
222
- // the image always fully covers the crop area.
223
- switch ( action.type ) {
224
- case 'SET_IMAGE':
225
- return commitBase(
226
- enforceContainment( {
227
- ...state,
228
- image: action.payload,
229
- } )
230
- );
231
-
232
- case 'SET_PAN':
233
- return commitBase(
234
- enforceContainment( {
235
- ...state,
236
- pan: action.payload,
237
- } )
238
- );
239
-
240
- case 'SET_ZOOM': {
241
- const z = clampRequestedZoom( state, action.payload );
242
- return commitBase(
243
- enforceContainment( {
244
- ...state,
245
- zoom: z,
246
- } )
247
- );
248
- }
249
-
250
- case 'SET_ZOOM_AT_POINT': {
251
- const z = clampRequestedZoom( state, action.payload.zoom );
252
- return commitBase(
253
- enforceContainment( {
254
- ...state,
255
- zoom: z,
256
- pan: action.payload.pan,
257
- } )
258
- );
259
- }
260
-
261
- case 'SET_ROTATION': {
262
- // Rotate the base pan around the crop-rect center by the
263
- // delta from the base rotation. Deriving each tick from
264
- // the fixed base — rather than compounding on the previous
265
- // tick — prevents accumulated-clamp drift. Rotating
266
- // 0°→30°→0° now returns to the exact base pan.
267
- //
268
- // Zoom starts from baseZoom; enforceContainment may bump it
269
- // up to cover the rotated crop, but never raises the base.
270
- //
271
- // SET_ROTATION is the only action that does NOT call
272
- // commitBase — the base pose stays pinned at the user's
273
- // last committed pan/zoom/rotation.
274
- const newRotation = normalizeRotation( action.payload );
275
- // With viewport-relative flip, pan rotation is conjugated by
276
- // the flip (S * R * S) — which reverses direction when exactly
277
- // one axis is flipped. Negate sin in that case so the crop
278
- // stays framed on the same image content through rotation.
279
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
280
- const deltaRad = degreesToRadians(
281
- newRotation - state.baseRotation
282
- );
283
- const cos = Math.cos( deltaRad );
284
- const sin = Math.sin( deltaRad ) * ( singleFlip ? -1 : 1 );
285
- const cropCx = state.cropRect.x + state.cropRect.width / 2;
286
- const cropCy = state.cropRect.y + state.cropRect.height / 2;
287
- const ox = cropCx - 0.5;
288
- const oy = cropCy - 0.5;
289
- const dx = state.basePan.x - ox;
290
- const dy = state.basePan.y - oy;
291
- return enforceContainment( {
292
- ...state,
293
- rotation: newRotation,
294
- zoom: state.baseZoom,
295
- pan: {
296
- x: ox + cos * dx - sin * dy,
297
- y: oy + sin * dx + cos * dy,
298
- },
299
- } );
300
- }
301
-
302
- case 'SNAP_ROTATE_90': {
303
- // 90° snap: the crop rect rotates 90° around its own center
304
- // (width/height swap), and the pan rotates 90° around the
305
- // pan-space origin. The combination keeps the same image
306
- // slice framed — just viewed through a rotated window.
307
- //
308
- // `direction` is the visual rotation the caller wants: +1
309
- // means "rotate the image CW on screen", −1 means "CCW".
310
- // With a single-axis flip active, rotation on screen appears
311
- // reversed relative to the rotation field (S·R·S conjugation),
312
- // so internally we negate the direction applied to the
313
- // `rotation` field. Pan rotates in the caller's direction —
314
- // that way the same image content stays framed after the
315
- // snap regardless of flip state.
316
- const rawDir = action.payload.direction;
317
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
318
- const fieldDir = singleFlip ? -rawDir : rawDir;
319
- const rot90 = normalizeRotation( state.rotation + fieldDir * 90 );
320
- const rect = state.cropRect;
321
- const cx = rect.x + rect.width / 2;
322
- const cy = rect.y + rect.height / 2;
323
-
324
- // Rotate pan vector 90° around origin.
325
- // CW (rawDir=+1): (px, py) → (-py, px)
326
- // CCW (rawDir=-1): (px, py) → (py, -px)
327
- const newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;
328
- const newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;
329
-
330
- return commitBase(
331
- enforceContainment( {
332
- ...state,
333
- rotation: rot90,
334
- zoom: state.baseZoom,
335
- pan: { x: newPanX, y: newPanY },
336
- cropRect: {
337
- x: cx - rect.height / 2,
338
- y: cy - rect.width / 2,
339
- width: rect.height,
340
- height: rect.width,
341
- },
342
- } )
343
- );
344
- }
345
-
346
- case 'SET_FLIP': {
347
- // Mirror the crop rect and pan so the same image content stays
348
- // framed after a flip. Flip in the camera matrix is composed
349
- // outside rotation (viewport-relative), so both `pan` and
350
- // `cropRect` live in viewport-aligned space: negating the flipped
351
- // axis on each is enough — no rotation math needed.
352
- const oldFlip = state.flip;
353
- const newFlip = action.payload;
354
- const flippedH = oldFlip.horizontal !== newFlip.horizontal;
355
- const flippedV = oldFlip.vertical !== newFlip.vertical;
356
- const rect = state.cropRect;
357
-
358
- return commitBase(
359
- enforceContainment( {
360
- ...state,
361
- flip: newFlip,
362
- pan: {
363
- x: flippedH ? -state.pan.x : state.pan.x,
364
- y: flippedV ? -state.pan.y : state.pan.y,
365
- },
366
- cropRect: {
367
- x: flippedH ? 1 - rect.x - rect.width : rect.x,
368
- y: flippedV ? 1 - rect.y - rect.height : rect.y,
369
- width: rect.width,
370
- height: rect.height,
371
- },
372
- } )
373
- );
374
- }
375
-
376
- case 'SET_CROP_RECT':
377
- return commitBase(
378
- enforceContainment( {
379
- ...state,
380
- cropRect: action.payload,
381
- } )
382
- );
383
-
384
- case 'SETTLE_CROP': {
385
- // After a resize drag ends: expand the crop to fill the
386
- // available height (maintaining its aspect ratio), center it,
387
- // and adjust zoom/pan so the exact same image content that
388
- // was visible inside the old crop is visible in the new one.
389
- const rect = state.cropRect;
390
- if ( rect.width === 0 || rect.height === 0 || ! state.image ) {
391
- return state;
392
- }
393
-
394
- // Scale factor: how much the crop grows. fitScale fills the
395
- // larger axis to 1 (viewport-filling settle). Cap so the
396
- // resulting zoom stays at or below MAX_ZOOM — tight crops
397
- // would otherwise push state.zoom past the user-facing cap
398
- // and break wheel/slider interactions, which clamp to
399
- // MAX_ZOOM and snap state.zoom down on the first input.
400
- const fitScale = 1 / Math.max( rect.width, rect.height );
401
- const zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;
402
- const s = Math.min( fitScale, zoomCap );
403
-
404
- const newW = rect.width * s;
405
- const newH = rect.height * s;
406
-
407
- // The old crop center in normalized visual space.
408
- const oldCx = rect.x + rect.width / 2;
409
- const oldCy = rect.y + rect.height / 2;
410
-
411
- // Zoom scales by s so the same image region fills the new
412
- // crop at the same relative size. When s is capped, the new
413
- // crop is smaller than the viewport but the visible content
414
- // inside it remains the source region the user framed.
415
- // Pan: the visible content center was at
416
- // (cropCx - crop.x, cropCy - crop.y)
417
- // in visual-normalized space. After centering the crop to
418
- // (0.5, 0.5), the pan must place that same content at
419
- // the new center. Both pan and zoom scale by s because
420
- // the CSS translate is independent of zoom.
421
- return commitBase(
422
- enforceContainment( {
423
- ...state,
424
- zoom: state.zoom * s,
425
- pan: {
426
- x: ( state.pan.x - oldCx + 0.5 ) * s,
427
- y: ( state.pan.y - oldCy + 0.5 ) * s,
428
- },
429
- cropRect: {
430
- x: ( 1 - newW ) / 2,
431
- y: ( 1 - newH ) / 2,
432
- width: newW,
433
- height: newH,
434
- },
435
- } )
436
- );
437
- }
438
-
439
- case 'APPLY_OPERATION':
440
- // Route through the action equivalent so a pipeline replay
441
- // yields the same bounded state as the matching UI/setter
442
- // path (containment, baseZoom relaxation, pan rotation
443
- // around crop center, etc.).
444
- return cropperReducer(
445
- state,
446
- operationToAction( state, action.payload )
447
- );
448
-
449
- case 'RESET':
450
- return commitBase(
451
- enforceContainment( {
452
- ...DEFAULT_STATE,
453
- image: state.image,
454
- ...action.payload,
455
- } )
456
- );
457
- }
458
- }
459
-
460
- /**
461
- * Shallow comparison of key cropper state fields to determine if
462
- * the state has been modified from an initial snapshot.
463
- *
464
- * @param current The current cropper state.
465
- * @param initial The initial cropper state snapshot.
466
- * @return True if any tracked field differs.
467
- */
468
- export function isStateDirty(
469
- current: CropperState,
470
- initial: CropperState
471
- ): boolean {
472
- return (
473
- ! nearlyEqual( current.pan.x, initial.pan.x ) ||
474
- ! nearlyEqual( current.pan.y, initial.pan.y ) ||
475
- ! nearlyEqual( current.zoom, initial.zoom ) ||
476
- ! nearlyEqual( current.rotation, initial.rotation ) ||
477
- current.flip.horizontal !== initial.flip.horizontal ||
478
- current.flip.vertical !== initial.flip.vertical ||
479
- ! nearlyEqual( current.cropRect.x, initial.cropRect.x ) ||
480
- ! nearlyEqual( current.cropRect.y, initial.cropRect.y ) ||
481
- ! nearlyEqual( current.cropRect.width, initial.cropRect.width ) ||
482
- ! nearlyEqual( current.cropRect.height, initial.cropRect.height )
483
- );
484
- }