@wordpress/media-editor 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -1,288 +0,0 @@
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";
4
- // packages/media-editor/src/image-editor/core/state.ts
5
- /** Small tolerance for cropper floating-point comparisons. */
6
- const STATE_EPSILON = 1e-6;
7
- function nearlyEqual(a, b) {
8
- return Math.abs(a - b) < STATE_EPSILON;
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
- */
21
- function areCropperStatesEqual(a, b) {
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);
25
- }
26
- function clampRequestedZoom(state, 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));
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
- */
45
- function operationToAction(state, op) {
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
- }
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
- */
80
- function enforceContainment(state) {
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
- };
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
- */
116
- function commitBase(next) {
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
- };
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
- */
145
- function cropperReducer(state, action) {
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
- }
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
- */
283
- function isStateDirty(current, initial) {
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);
285
- }
286
- export { areCropperStatesEqual, cropperReducer, enforceContainment, isStateDirty };
287
-
288
- //# sourceMappingURL=state.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.mjs","names":[],"sources":["../../../src/image-editor/core/state.ts"],"sourcesContent":["import type { CropperAction, CropperState, TransformOperation } from './types';\nimport {\n\tABSOLUTE_MIN_ZOOM,\n\tDEFAULT_STATE,\n\tMAX_ZOOM,\n\tMIN_ZOOM,\n} from './constants';\nimport { normalizeRotation, degreesToRadians } from './math/rotation';\nimport { restrictPanZoom, restrictCropRect } from './containment';\n\n/** Small tolerance for cropper floating-point comparisons. */\nconst STATE_EPSILON = 1e-6;\n\nfunction nearlyEqual( a: number, b: number ): boolean {\n\treturn Math.abs( a - b ) < STATE_EPSILON;\n}\n\n/**\n * Value-equality check for two cropper states.\n *\n * Used by history machinery to dedup snapshots and detect no-op\n * transitions. Compares every field that participates in the rendered\n * output; ignores reference identity.\n *\n * @param a First cropper state.\n * @param b Second cropper state.\n * @return Whether the two states are value-equal across all tracked fields.\n */\nexport function areCropperStatesEqual(\n\ta: CropperState,\n\tb: CropperState\n): boolean {\n\tconst aImage = a.image;\n\tconst bImage = b.image;\n\treturn (\n\t\taImage?.src === bImage?.src &&\n\t\taImage?.naturalWidth === bImage?.naturalWidth &&\n\t\taImage?.naturalHeight === bImage?.naturalHeight &&\n\t\tnearlyEqual( a.pan.x, b.pan.x ) &&\n\t\tnearlyEqual( a.pan.y, b.pan.y ) &&\n\t\tnearlyEqual( a.zoom, b.zoom ) &&\n\t\tnearlyEqual( a.rotation, b.rotation ) &&\n\t\ta.flip.horizontal === b.flip.horizontal &&\n\t\ta.flip.vertical === b.flip.vertical &&\n\t\tnearlyEqual( a.cropRect.x, b.cropRect.x ) &&\n\t\tnearlyEqual( a.cropRect.y, b.cropRect.y ) &&\n\t\tnearlyEqual( a.cropRect.width, b.cropRect.width ) &&\n\t\tnearlyEqual( a.cropRect.height, b.cropRect.height )\n\t);\n}\n\nfunction clampRequestedZoom( state: CropperState, zoom: number ): number {\n\t// With an image, enforceContainment raises zoom to the coverage-aware\n\t// floor below. Without an image, no enforcement runs, so MIN_ZOOM stays\n\t// the conservative resting default.\n\tif ( state.image ) {\n\t\treturn Math.min( MAX_ZOOM, Math.max( ABSOLUTE_MIN_ZOOM, zoom ) );\n\t}\n\treturn Math.min( MAX_ZOOM, Math.max( MIN_ZOOM, zoom ) );\n}\n\n/**\n * Translate a pipeline transform operation into the equivalent\n * reducer action. Pipeline ops aren't 1:1 with reducer actions —\n * `rotate` is a delta here, whereas SET_ROTATION takes an absolute\n * angle — so deltas are resolved against the current state.\n *\n * Used by APPLY_OPERATION (and by the pipeline module's\n * `applyOperationToState`, which is now a thin wrapper around the\n * reducer) so that pipeline replay produces identical bounded\n * state to UI interaction or direct setters.\n *\n * @param state The current cropper state.\n * @param op The pipeline operation.\n * @return The equivalent reducer action.\n */\nfunction operationToAction(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperAction {\n\tswitch ( op.type ) {\n\t\tcase 'crop':\n\t\t\treturn { type: 'SET_CROP_RECT', payload: { ...op.rect } };\n\t\tcase 'rotate': {\n\t\t\t// `op.degrees` is the visual rotation the caller wants (positive\n\t\t\t// = CW on screen). A single-axis flip inverts on-screen rotation\n\t\t\t// relative to the rotation field, so negate the field delta in\n\t\t\t// that case — this keeps `{ type: 'rotate', degrees: 90 }` a\n\t\t\t// reliable \"90° clockwise visually\" instruction across flip\n\t\t\t// states, matching the SNAP_ROTATE_90 convention.\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst fieldDelta = singleFlip ? -op.degrees : op.degrees;\n\t\t\treturn {\n\t\t\t\ttype: 'SET_ROTATION',\n\t\t\t\tpayload: normalizeRotation( state.rotation + fieldDelta ),\n\t\t\t};\n\t\t}\n\t\tcase 'flip':\n\t\t\treturn {\n\t\t\t\ttype: 'SET_FLIP',\n\t\t\t\tpayload: {\n\t\t\t\t\t...state.flip,\n\t\t\t\t\t[ op.direction ]: ! state.flip[ op.direction ],\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'zoom':\n\t\t\treturn { type: 'SET_ZOOM', payload: op.factor };\n\t}\n}\n\n/**\n * Enforces containment: restricts the crop rect to fit within the\n * rotated image, computes minimum zoom, clamps zoom, and restricts\n * the pan position so the image always covers the crop area.\n * Called after every relevant state transition.\n *\n * @param state The state to enforce containment on.\n * @return The state with cropRect, zoom, and position restricted.\n */\nexport function enforceContainment( state: CropperState ): CropperState {\n\tif ( ! state.image ) {\n\t\treturn state;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tconst imageAspectRatio = imageSize.width / imageSize.height;\n\n\t// 1. First bump zoom so the image can cover the crop rect as-is.\n\t// This ensures that explicit crop rect changes (e.g., fixed-crop\n\t// mode during rotation) get zoom accommodation, not crop shrinkage.\n\tconst { pan: panAfterZoom, zoom } = restrictPanZoom(\n\t\tstate,\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\n\t// 2. Now restrict the crop rect at the (possibly bumped) zoom.\n\t// This handles cases where the crop rect is still too large\n\t// (e.g., if zoom hit MAX_ZOOM).\n\tconst cropRect = restrictCropRect(\n\t\tstate.cropRect,\n\t\tzoom,\n\t\tstate.rotation,\n\t\timageAspectRatio\n\t);\n\n\t// 3. If the crop rect was shrunk, re-restrict pan for the new rect.\n\tlet pan = panAfterZoom;\n\tif ( cropRect !== state.cropRect ) {\n\t\t( { pan } = restrictPanZoom(\n\t\t\t{ ...state, zoom, cropRect },\n\t\t\timageSize,\n\t\t\tcropRect\n\t\t) );\n\t}\n\n\tif (\n\t\tpan.x === state.pan.x &&\n\t\tpan.y === state.pan.y &&\n\t\tzoom === state.zoom &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn { ...state, pan, zoom, cropRect };\n}\n\n/**\n * Snapshot the current `crop`, `zoom`, and `rotation` into the\n * corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called\n * by every committing action so that the next SET_ROTATION derives\n * its transient pan from a fresh base (not from a drifted one).\n *\n * SET_ROTATION is the only action that does NOT commit base — it\n * reads the base, computes a transient pan, and leaves the base\n * alone. This is what eliminates rotation drift near edges.\n *\n * @param next The post-containment state to commit.\n * @return The state with base fields synced to current.\n */\nfunction commitBase( next: CropperState ): CropperState {\n\tif (\n\t\tnext.basePan.x === next.pan.x &&\n\t\tnext.basePan.y === next.pan.y &&\n\t\tnext.baseZoom === next.zoom &&\n\t\tnext.baseRotation === next.rotation\n\t) {\n\t\treturn next;\n\t}\n\treturn {\n\t\t...next,\n\t\tbasePan: { x: next.pan.x, y: next.pan.y },\n\t\tbaseZoom: next.zoom,\n\t\tbaseRotation: next.rotation,\n\t};\n}\n\n/**\n * Reducer function for cropper state management.\n *\n * Every state transition that could invalidate the containment invariant\n * (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment\n * to ensure the image always covers the crop area.\n *\n * Committing actions (everything except SET_ROTATION) also call\n * `commitBase` to snapshot the post-containment state as the new\n * base pose. SET_ROTATION derives from that base without mutating\n * it, which prevents accumulated-clamp drift during continuous fine\n * rotation.\n *\n * @param state The current cropper state.\n * @param action The action to process.\n * @return The new cropper state.\n */\nexport function cropperReducer(\n\tstate: CropperState,\n\taction: CropperAction\n): CropperState {\n\t// Every action runs through enforceContainment to maintain the invariant:\n\t// the image always fully covers the crop area.\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\timage: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SET_PAN':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tpan: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SET_ZOOM': {\n\t\t\tconst z = clampRequestedZoom( state, action.payload );\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: z,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_ZOOM_AT_POINT': {\n\t\t\tconst z = clampRequestedZoom( state, action.payload.zoom );\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: z,\n\t\t\t\t\tpan: action.payload.pan,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_ROTATION': {\n\t\t\t// Rotate the base pan around the crop-rect center by the\n\t\t\t// delta from the base rotation. Deriving each tick from\n\t\t\t// the fixed base — rather than compounding on the previous\n\t\t\t// tick — prevents accumulated-clamp drift. Rotating\n\t\t\t// 0°→30°→0° now returns to the exact base pan.\n\t\t\t//\n\t\t\t// Zoom starts from baseZoom; enforceContainment may bump it\n\t\t\t// up to cover the rotated crop, but never raises the base.\n\t\t\t//\n\t\t\t// SET_ROTATION is the only action that does NOT call\n\t\t\t// commitBase — the base pose stays pinned at the user's\n\t\t\t// last committed pan/zoom/rotation.\n\t\t\tconst newRotation = normalizeRotation( action.payload );\n\t\t\t// With viewport-relative flip, pan rotation is conjugated by\n\t\t\t// the flip (S * R * S) — which reverses direction when exactly\n\t\t\t// one axis is flipped. Negate sin in that case so the crop\n\t\t\t// stays framed on the same image content through rotation.\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst deltaRad = degreesToRadians(\n\t\t\t\tnewRotation - state.baseRotation\n\t\t\t);\n\t\t\tconst cos = Math.cos( deltaRad );\n\t\t\tconst sin = Math.sin( deltaRad ) * ( singleFlip ? -1 : 1 );\n\t\t\tconst cropCx = state.cropRect.x + state.cropRect.width / 2;\n\t\t\tconst cropCy = state.cropRect.y + state.cropRect.height / 2;\n\t\t\tconst ox = cropCx - 0.5;\n\t\t\tconst oy = cropCy - 0.5;\n\t\t\tconst dx = state.basePan.x - ox;\n\t\t\tconst dy = state.basePan.y - oy;\n\t\t\treturn enforceContainment( {\n\t\t\t\t...state,\n\t\t\t\trotation: newRotation,\n\t\t\t\tzoom: state.baseZoom,\n\t\t\t\tpan: {\n\t\t\t\t\tx: ox + cos * dx - sin * dy,\n\t\t\t\t\ty: oy + sin * dx + cos * dy,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tcase 'SNAP_ROTATE_90': {\n\t\t\t// 90° snap: the crop rect rotates 90° around its own center\n\t\t\t// (width/height swap), and the pan rotates 90° around the\n\t\t\t// pan-space origin. The combination keeps the same image\n\t\t\t// slice framed — just viewed through a rotated window.\n\t\t\t//\n\t\t\t// `direction` is the visual rotation the caller wants: +1\n\t\t\t// means \"rotate the image CW on screen\", −1 means \"CCW\".\n\t\t\t// With a single-axis flip active, rotation on screen appears\n\t\t\t// reversed relative to the rotation field (S·R·S conjugation),\n\t\t\t// so internally we negate the direction applied to the\n\t\t\t// `rotation` field. Pan rotates in the caller's direction —\n\t\t\t// that way the same image content stays framed after the\n\t\t\t// snap regardless of flip state.\n\t\t\tconst rawDir = action.payload.direction;\n\t\t\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\t\t\tconst fieldDir = singleFlip ? -rawDir : rawDir;\n\t\t\tconst rot90 = normalizeRotation( state.rotation + fieldDir * 90 );\n\t\t\tconst rect = state.cropRect;\n\t\t\tconst cx = rect.x + rect.width / 2;\n\t\t\tconst cy = rect.y + rect.height / 2;\n\n\t\t\t// Rotate pan vector 90° around origin.\n\t\t\t// CW (rawDir=+1): (px, py) → (-py, px)\n\t\t\t// CCW (rawDir=-1): (px, py) → (py, -px)\n\t\t\tconst newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;\n\t\t\tconst newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;\n\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\trotation: rot90,\n\t\t\t\t\tzoom: state.baseZoom,\n\t\t\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: cx - rect.height / 2,\n\t\t\t\t\t\ty: cy - rect.width / 2,\n\t\t\t\t\t\twidth: rect.height,\n\t\t\t\t\t\theight: rect.width,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_FLIP': {\n\t\t\t// Mirror the crop rect and pan so the same image content stays\n\t\t\t// framed after a flip. Flip in the camera matrix is composed\n\t\t\t// outside rotation (viewport-relative), so both `pan` and\n\t\t\t// `cropRect` live in viewport-aligned space: negating the flipped\n\t\t\t// axis on each is enough — no rotation math needed.\n\t\t\tconst oldFlip = state.flip;\n\t\t\tconst newFlip = action.payload;\n\t\t\tconst flippedH = oldFlip.horizontal !== newFlip.horizontal;\n\t\t\tconst flippedV = oldFlip.vertical !== newFlip.vertical;\n\t\t\tconst rect = state.cropRect;\n\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tflip: newFlip,\n\t\t\t\t\tpan: {\n\t\t\t\t\t\tx: flippedH ? -state.pan.x : state.pan.x,\n\t\t\t\t\t\ty: flippedV ? -state.pan.y : state.pan.y,\n\t\t\t\t\t},\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: flippedH ? 1 - rect.x - rect.width : rect.x,\n\t\t\t\t\t\ty: flippedV ? 1 - rect.y - rect.height : rect.y,\n\t\t\t\t\t\twidth: rect.width,\n\t\t\t\t\t\theight: rect.height,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'SET_CROP_RECT':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tcropRect: action.payload,\n\t\t\t\t} )\n\t\t\t);\n\n\t\tcase 'SETTLE_CROP': {\n\t\t\t// After a resize drag ends: expand the crop to fill the\n\t\t\t// available height (maintaining its aspect ratio), center it,\n\t\t\t// and adjust zoom/pan so the exact same image content that\n\t\t\t// was visible inside the old crop is visible in the new one.\n\t\t\tconst rect = state.cropRect;\n\t\t\tif ( rect.width === 0 || rect.height === 0 || ! state.image ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\t// Scale factor: how much the crop grows. fitScale fills the\n\t\t\t// larger axis to 1 (viewport-filling settle). Cap so the\n\t\t\t// resulting zoom stays at or below MAX_ZOOM — tight crops\n\t\t\t// would otherwise push state.zoom past the user-facing cap\n\t\t\t// and break wheel/slider interactions, which clamp to\n\t\t\t// MAX_ZOOM and snap state.zoom down on the first input.\n\t\t\tconst fitScale = 1 / Math.max( rect.width, rect.height );\n\t\t\tconst zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;\n\t\t\tconst s = Math.min( fitScale, zoomCap );\n\n\t\t\tconst newW = rect.width * s;\n\t\t\tconst newH = rect.height * s;\n\n\t\t\t// The old crop center in normalized visual space.\n\t\t\tconst oldCx = rect.x + rect.width / 2;\n\t\t\tconst oldCy = rect.y + rect.height / 2;\n\n\t\t\t// Zoom scales by s so the same image region fills the new\n\t\t\t// crop at the same relative size. When s is capped, the new\n\t\t\t// crop is smaller than the viewport but the visible content\n\t\t\t// inside it remains the source region the user framed.\n\t\t\t// Pan: the visible content center was at\n\t\t\t// (cropCx - crop.x, cropCy - crop.y)\n\t\t\t// in visual-normalized space. After centering the crop to\n\t\t\t// (0.5, 0.5), the pan must place that same content at\n\t\t\t// the new center. Both pan and zoom scale by s because\n\t\t\t// the CSS translate is independent of zoom.\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...state,\n\t\t\t\t\tzoom: state.zoom * s,\n\t\t\t\t\tpan: {\n\t\t\t\t\t\tx: ( state.pan.x - oldCx + 0.5 ) * s,\n\t\t\t\t\t\ty: ( state.pan.y - oldCy + 0.5 ) * s,\n\t\t\t\t\t},\n\t\t\t\t\tcropRect: {\n\t\t\t\t\t\tx: ( 1 - newW ) / 2,\n\t\t\t\t\t\ty: ( 1 - newH ) / 2,\n\t\t\t\t\t\twidth: newW,\n\t\t\t\t\t\theight: newH,\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tcase 'APPLY_OPERATION':\n\t\t\t// Route through the action equivalent so a pipeline replay\n\t\t\t// yields the same bounded state as the matching UI/setter\n\t\t\t// path (containment, baseZoom relaxation, pan rotation\n\t\t\t// around crop center, etc.).\n\t\t\treturn cropperReducer(\n\t\t\t\tstate,\n\t\t\t\toperationToAction( state, action.payload )\n\t\t\t);\n\n\t\tcase 'RESET':\n\t\t\treturn commitBase(\n\t\t\t\tenforceContainment( {\n\t\t\t\t\t...DEFAULT_STATE,\n\t\t\t\t\timage: state.image,\n\t\t\t\t\t...action.payload,\n\t\t\t\t} )\n\t\t\t);\n\t}\n}\n\n/**\n * Shallow comparison of key cropper state fields to determine if\n * the state has been modified from an initial snapshot.\n *\n * @param current The current cropper state.\n * @param initial The initial cropper state snapshot.\n * @return True if any tracked field differs.\n */\nexport function isStateDirty(\n\tcurrent: CropperState,\n\tinitial: CropperState\n): boolean {\n\treturn (\n\t\t! nearlyEqual( current.pan.x, initial.pan.x ) ||\n\t\t! nearlyEqual( current.pan.y, initial.pan.y ) ||\n\t\t! nearlyEqual( current.zoom, initial.zoom ) ||\n\t\t! nearlyEqual( current.rotation, initial.rotation ) ||\n\t\tcurrent.flip.horizontal !== initial.flip.horizontal ||\n\t\tcurrent.flip.vertical !== initial.flip.vertical ||\n\t\t! nearlyEqual( current.cropRect.x, initial.cropRect.x ) ||\n\t\t! nearlyEqual( current.cropRect.y, initial.cropRect.y ) ||\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Aa,QAAQ,SAAS,GAAG,QAAQ,SAAS,CAAE,KACtD,CAAE,YAAa,QAAQ,SAAS,OAAO,QAAQ,SAAS,KAAM,KAC9D,CAAE,YAAa,QAAQ,SAAS,QAAQ,QAAQ,SAAS,MAAO;AAElE"}
@@ -1,194 +0,0 @@
1
- import { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from "./constants.mjs";
2
- // packages/media-editor/src/image-editor/core/stencil-math.ts
3
- /**
4
- * Resolve the minimum crop dimension, in source-image pixels, for the current
5
- * display scale.
6
- *
7
- * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that
8
- * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that
9
- * keeps the crop large enough to grab. The on-screen floor converted to source
10
- * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the
11
- * larger of the two. When the image is shown small (small `displayScale`) the
12
- * on-screen floor dominates; once it is shown large enough the source-pixel
13
- * floor takes over.
14
- *
15
- * @param displayScale CSS pixels rendered per source pixel
16
- * (fit scale × zoom × view scale).
17
- * @return Minimum crop dimension in source-image pixels.
18
- */
19
- function getMinCropPixels(displayScale) {
20
- if (displayScale <= 0) return MIN_CROP_PIXELS;
21
- return Math.max(MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale);
22
- }
23
- /**
24
- * Default minimum crop rect dimension in normalized space, used when no
25
- * explicit per-axis minimum is supplied (e.g. before the source image
26
- * has loaded). Real usage derives a pixel-based min from the source
27
- * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.
28
- */
29
- const DEFAULT_MIN_CROP_SIZE = {
30
- width: .05,
31
- height: .05
32
- };
33
- /**
34
- * Compute the new crop rect for a free (no aspect ratio) resize.
35
- *
36
- * Each edge moves independently based on the handle being dragged.
37
- * Edges are clamped to the provided bounds and maintain a minimum size.
38
- *
39
- * @param drag The current drag state.
40
- * @param clientX Current mouse/touch X position in pixels.
41
- * @param clientY Current mouse/touch Y position in pixels.
42
- * @param imageSize The rendered image dimensions in pixels.
43
- * @param bounds The allowed crop area bounds.
44
- * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
45
- * @return The new crop rect in normalized coordinates.
46
- */
47
- function computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize = DEFAULT_MIN_CROP_SIZE) {
48
- const dx = imageSize.width > 0 ? (clientX - drag.startX) / imageSize.width : 0;
49
- const dy = imageSize.height > 0 ? (clientY - drag.startY) / imageSize.height : 0;
50
- const s = drag.startRect;
51
- const handle = drag.handle;
52
- let edgeTop = s.y;
53
- let edgeBottom = s.y + s.height;
54
- let edgeLeft = s.x;
55
- let edgeRight = s.x + s.width;
56
- if (handle === "n" || handle === "nw" || handle === "ne") edgeTop = Math.max(bounds.minY, Math.min(s.y + dy, edgeBottom - minCropSize.height));
57
- if (handle === "s" || handle === "sw" || handle === "se") edgeBottom = Math.max(edgeTop + minCropSize.height, Math.min(s.y + s.height + dy, bounds.maxY));
58
- if (handle === "w" || handle === "nw" || handle === "sw") edgeLeft = Math.max(bounds.minX, Math.min(s.x + dx, edgeRight - minCropSize.width));
59
- if (handle === "e" || handle === "ne" || handle === "se") edgeRight = Math.max(edgeLeft + minCropSize.width, Math.min(s.x + s.width + dx, bounds.maxX));
60
- return {
61
- x: edgeLeft,
62
- y: edgeTop,
63
- width: edgeRight - edgeLeft,
64
- height: edgeBottom - edgeTop
65
- };
66
- }
67
- /**
68
- * Compute the new crop rect for a locked-aspect-ratio corner resize.
69
- *
70
- * The opposite corner is the anchor. The dragged corner moves freely
71
- * but the result is clamped to maintain the aspect ratio and stay
72
- * within bounds.
73
- *
74
- * @param drag The current drag state.
75
- * @param clientX Current mouse/touch X position in pixels.
76
- * @param clientY Current mouse/touch Y position in pixels.
77
- * @param imageSize The rendered image dimensions in pixels.
78
- * @param bounds The allowed crop area bounds.
79
- * @param normalizedRatio The locked aspect ratio (width / height in normalized space).
80
- * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
81
- * @param driverAxis Optional explicit driver axis. Used for keyboard
82
- * resize, where one arrow axis should determine the step.
83
- * @return The new crop rect in normalized coordinates.
84
- */
85
- function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize = DEFAULT_MIN_CROP_SIZE, driverAxis) {
86
- if (normalizedRatio <= 0 || imageSize.width <= 0 || imageSize.height <= 0) return { ...drag.startRect };
87
- const dx = (clientX - drag.startX) / imageSize.width;
88
- const dy = (clientY - drag.startY) / imageSize.height;
89
- const s = drag.startRect;
90
- const handle = drag.handle;
91
- const anchorX = handle === "nw" || handle === "sw" ? s.x + s.width : s.x;
92
- const anchorY = handle === "nw" || handle === "ne" ? s.y + s.height : s.y;
93
- const dirX = handle === "nw" || handle === "sw" ? -1 : 1;
94
- const dirY = handle === "nw" || handle === "ne" ? -1 : 1;
95
- const draggedX = (handle === "nw" || handle === "sw" ? s.x : s.x + s.width) + dx;
96
- const draggedY = (handle === "nw" || handle === "ne" ? s.y : s.y + s.height) + dy;
97
- let distW = (draggedX - anchorX) * dirX;
98
- let distH = (draggedY - anchorY) * dirY;
99
- const minDistW = Math.max(minCropSize.width, minCropSize.height * normalizedRatio);
100
- const minDistH = minDistW / normalizedRatio;
101
- distW = Math.max(distW, minDistW);
102
- distH = Math.max(distH, minDistH);
103
- const pixelRatio = normalizedRatio * imageSize.width / imageSize.height;
104
- if (driverAxis === "width" || !driverAxis && distW * imageSize.width / (distH * imageSize.height) > pixelRatio) distH = distW / normalizedRatio;
105
- else distW = distH * normalizedRatio;
106
- const maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;
107
- const maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;
108
- if (distW > maxW) {
109
- distW = maxW;
110
- distH = distW / normalizedRatio;
111
- }
112
- if (distH > maxH) {
113
- distH = maxH;
114
- distW = distH * normalizedRatio;
115
- }
116
- distW = Math.max(distW, minDistW);
117
- distH = Math.max(distH, minDistH);
118
- return {
119
- x: dirX > 0 ? anchorX : anchorX - distW,
120
- y: dirY > 0 ? anchorY : anchorY - distH,
121
- width: distW,
122
- height: distH
123
- };
124
- }
125
- /**
126
- * Compute the new crop rect for a resize that temporarily locks the
127
- * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).
128
- *
129
- * Corner handles delegate to {@link computeLockedResizeRect}. Edge
130
- * handles size the dragged axis freely, then expand the perpendicular
131
- * axis symmetrically around the rect's center to preserve the ratio,
132
- * clamping symmetrically so the rect stays within bounds.
133
- *
134
- * @param drag The current drag state.
135
- * @param clientX Current mouse/touch X position in pixels.
136
- * @param clientY Current mouse/touch Y position in pixels.
137
- * @param imageSize The rendered image dimensions in pixels.
138
- * @param bounds The allowed crop area bounds.
139
- * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
140
- * @return The new crop rect in normalized coordinates.
141
- */
142
- function computeShiftLockedResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize = DEFAULT_MIN_CROP_SIZE) {
143
- const s = drag.startRect;
144
- const pixelW = s.width * imageSize.width;
145
- if (s.height * imageSize.height <= 0 || pixelW <= 0) return computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize);
146
- const normalizedRatio = s.width / s.height;
147
- const handle = drag.handle;
148
- if (handle === "nw" || handle === "ne" || handle === "sw" || handle === "se") return computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize);
149
- const free = computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize);
150
- if (handle === "n" || handle === "s") {
151
- let newHeight = free.height;
152
- let newWidth = newHeight * normalizedRatio;
153
- const centerX = s.x + s.width / 2;
154
- const maxWidth = Math.min(centerX - bounds.minX, bounds.maxX - centerX) * 2;
155
- if (newWidth > maxWidth) {
156
- newWidth = maxWidth;
157
- newHeight = newWidth / normalizedRatio;
158
- }
159
- const minHeight = Math.max(minCropSize.height, minCropSize.width / normalizedRatio);
160
- if (newHeight < minHeight) {
161
- newHeight = minHeight;
162
- newWidth = newHeight * normalizedRatio;
163
- }
164
- const newY = handle === "n" ? s.y + s.height - newHeight : s.y;
165
- return {
166
- x: centerX - newWidth / 2,
167
- y: newY,
168
- width: newWidth,
169
- height: newHeight
170
- };
171
- }
172
- let newWidth = free.width;
173
- let newHeight = newWidth / normalizedRatio;
174
- const centerY = s.y + s.height / 2;
175
- const maxHeight = Math.min(centerY - bounds.minY, bounds.maxY - centerY) * 2;
176
- if (newHeight > maxHeight) {
177
- newHeight = maxHeight;
178
- newWidth = newHeight * normalizedRatio;
179
- }
180
- const minWidth = Math.max(minCropSize.width, minCropSize.height * normalizedRatio);
181
- if (newWidth < minWidth) {
182
- newWidth = minWidth;
183
- newHeight = newWidth / normalizedRatio;
184
- }
185
- return {
186
- x: handle === "w" ? s.x + s.width - newWidth : s.x,
187
- y: centerY - newHeight / 2,
188
- width: newWidth,
189
- height: newHeight
190
- };
191
- }
192
- export { DEFAULT_MIN_CROP_SIZE, computeFreeResizeRect, computeLockedResizeRect, computeShiftLockedResizeRect, getMinCropPixels };
193
-
194
- //# sourceMappingURL=stencil-math.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stencil-math.mjs","names":[],"sources":["../../../src/image-editor/core/stencil-math.ts"],"sourcesContent":["import { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/** Axis whose resize distance controls the locked-ratio size projection. */\nexport type ResizeDriverAxis = 'width' | 'height';\n\n/**\n * Resolve the minimum crop dimension, in source-image pixels, for the current\n * display scale.\n *\n * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that\n * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that\n * keeps the crop large enough to grab. The on-screen floor converted to source\n * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the\n * larger of the two. When the image is shown small (small `displayScale`) the\n * on-screen floor dominates; once it is shown large enough the source-pixel\n * floor takes over.\n *\n * @param displayScale CSS pixels rendered per source pixel\n * (fit scale × zoom × view scale).\n * @return Minimum crop dimension in source-image pixels.\n */\nexport function getMinCropPixels( displayScale: number ): number {\n\tif ( displayScale <= 0 ) {\n\t\treturn MIN_CROP_PIXELS;\n\t}\n\treturn Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );\n}\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param driverAxis Optional explicit driver axis. Used for keyboard\n * resize, where one arrow axis should determine the step.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE,\n\tdriverAxis?: ResizeDriverAxis\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\". Pointer drags use the dragged-corner\n\t// geometry so the projected crop changes continuously as the pointer moves.\n\t// Keyboard resize passes an explicit axis because a single-axis arrow step\n\t// should drive that axis instead of being cancelled by the unchanged axis.\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tconst isWidthDriver =\n\t\tdriverAxis === 'width' ||\n\t\t( ! driverAxis &&\n\t\t\t( distW * imageSize.width ) / ( distH * imageSize.height ) >\n\t\t\t\tpixelRatio );\n\n\tif ( isWidthDriver ) {\n\t\t// Width is the driver — compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver — compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAkB,cAA+B;CAChE,IAAK,gBAAgB,GACpB,OAAO;CAER,OAAO,KAAK,IAAK,iB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,MAAM,UAAU,EAAE,IAAI,EAAE,SAAS;CACjC,MAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;CAC5D,IAAK,YAAY,WAAY;EAC5B,YAAY;EACZ,WAAW,YAAY;CACxB;CACA,MAAM,WAAW,KAAK,IACrB,YAAY,OACZ,YAAY,SAAS,eACtB;CACA,IAAK,WAAW,UAAW;EAC1B,WAAW;EACX,YAAY,WAAW;CACxB;CAEA,OAAO;EACN,GAFY,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;EAG1D,GAAG,UAAU,YAAY;EACzB,OAAO;EACP,QAAQ;CACT;AACD"}
@@ -1,38 +0,0 @@
1
- import { degreesToRadians } from "./math/rotation.mjs";
2
- import { isValidSize, sanitizeCropperState } from "./math/sanitize.mjs";
3
- // packages/media-editor/src/image-editor/core/transform-style.ts
4
- /** Identity CSS transform — applied when inputs aren't safe to compose. */
5
- const IDENTITY_MATRIX_STYLE = "matrix(1, 0, 0, 1, 0, 0)";
6
- /**
7
- * Computes a CSS matrix() transform string from the cropper state.
8
- *
9
- * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)
10
- * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).
11
- *
12
- * Flip is composed outside rotation so it is viewport-relative — horizontal
13
- * flip mirrors across the viewport's vertical axis regardless of rotation.
14
- * Must match the matrix order in `createCamera` / `getImageCropBounds`.
15
- *
16
- * This is a pure function with no framework dependencies. The React hook
17
- * `useTransformStyle` wraps this in `useMemo` for memoization.
18
- *
19
- * @param state The current cropper state.
20
- * @param imageSize The rendered image dimensions in pixels.
21
- * @return A CSS transform string.
22
- */
23
- function computeTransformStyle(state, imageSize) {
24
- if (!isValidSize(imageSize)) return IDENTITY_MATRIX_STYLE;
25
- const safeState = sanitizeCropperState(state);
26
- const translateX = safeState.pan.x * imageSize.width;
27
- const translateY = safeState.pan.y * imageSize.height;
28
- const rad = degreesToRadians(safeState.rotation);
29
- const cos = Math.cos(rad);
30
- const sin = Math.sin(rad);
31
- const sx = safeState.flip.horizontal ? -1 : 1;
32
- const sy = safeState.flip.vertical ? -1 : 1;
33
- const z = safeState.zoom;
34
- return `matrix(${sx * cos * z}, ${sy * sin * z}, ${-sx * sin * z}, ${sy * cos * z}, ${translateX}, ${translateY})`;
35
- }
36
- export { computeTransformStyle };
37
-
38
- //# sourceMappingURL=transform-style.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform-style.mjs","names":[],"sources":["../../../src/image-editor/core/transform-style.ts"],"sourcesContent":["import type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/** Identity CSS transform — applied when inputs aren't safe to compose. */\nconst IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative — horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getImageCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\t// Match the identity short-circuit used by `createCamera` and\n\t// `getSourceRegion` so the preview path stays consistent with the math\n\t// path when `imageSize` itself is hostile (state sanitization below\n\t// only guards the state fields, not these size arguments).\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn IDENTITY_MATRIX_STYLE;\n\t}\n\t// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here\n\t// while the parallel `createCamera` path returns a finite matrix. Both\n\t// paths must agree under defense-in-depth conditions.\n\tconst safeState = sanitizeCropperState( state );\n\tconst translateX = safeState.pan.x * imageSize.width;\n\tconst translateY = safeState.pan.y * imageSize.height;\n\tconst rad = degreesToRadians( safeState.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = safeState.flip.horizontal ? -1 : 1;\n\tconst sy = safeState.flip.vertical ? -1 : 1;\n\tconst z = safeState.zoom;\n\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],"mappings":";;;;AAKA,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;AAmB9B,SAAgB,sBACf,OACA,WACS;CAKT,IAAK,CAAE,YAAa,SAAU,GAC7B,OAAO;CAKR,MAAM,YAAY,qBAAsB,KAAM;CAC9C,MAAM,aAAa,UAAU,IAAI,IAAI,UAAU;CAC/C,MAAM,aAAa,UAAU,IAAI,IAAI,UAAU;CAC/C,MAAM,MAAM,iBAAkB,UAAU,QAAS;CACjD,MAAM,MAAM,KAAK,IAAK,GAAI;CAC1B,MAAM,MAAM,KAAK,IAAK,GAAI;CAC1B,MAAM,KAAK,UAAU,KAAK,aAAa,KAAK;CAC5C,MAAM,KAAK,UAAU,KAAK,WAAW,KAAK;CAC1C,MAAM,IAAI,UAAU;CAQpB,OAAO,UALG,KAAK,MAAM,EAKA,IAJX,KAAK,MAAM,EAIQ,IAHnB,CAAC,KAAK,MAAM,EAGe,IAF3B,KAAK,MAAM,EAEwB,IAAK,WAAY,IAAK,WAAY;AAChF"}
@@ -1,35 +0,0 @@
1
- import { DEFAULT_STATE } from "../constants.mjs";
2
- import { cropperReducer } from "../state.mjs";
3
- // packages/media-editor/src/image-editor/core/transforms/pipeline.ts
4
- /**
5
- * Apply a single transform operation to a cropper state, returning
6
- * a new state with the containment invariant enforced.
7
- *
8
- * Delegates to the reducer via APPLY_OPERATION so pipeline replay
9
- * produces identical bounded state to UI interaction or setter
10
- * calls. The same logical operation yields the same result
11
- * regardless of entrypoint.
12
- *
13
- * @param state The current cropper state.
14
- * @param op The operation to apply.
15
- * @return A new cropper state with the operation applied.
16
- */
17
- function applyOperationToState(state, op) {
18
- return cropperReducer(state, {
19
- type: "APPLY_OPERATION",
20
- payload: op
21
- });
22
- }
23
- /**
24
- * Replay all operations from an initial state to produce the final state.
25
- *
26
- * @param pipeline The array of transform operations to replay.
27
- * @param initialState The starting state. Defaults to DEFAULT_STATE.
28
- * @return The resulting cropper state after all operations are applied.
29
- */
30
- function stateFromPipeline(pipeline, initialState = { ...DEFAULT_STATE }) {
31
- return pipeline.reduce((state, op) => applyOperationToState(state, op), initialState);
32
- }
33
- export { applyOperationToState, stateFromPipeline };
34
-
35
- //# sourceMappingURL=pipeline.mjs.map