@wordpress/media-editor 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/components/media-editor/index.cjs +533 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +43 -57
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  6. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +122 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +65 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +183 -257
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  19. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  20. package/build/components/media-editor-modal/index.cjs +112 -155
  21. package/build/components/media-editor-modal/index.cjs.map +1 -7
  22. package/build/components/media-editor-provider/index.cjs +32 -55
  23. package/build/components/media-editor-provider/index.cjs.map +1 -7
  24. package/build/components/media-form/index.cjs +76 -77
  25. package/build/components/media-form/index.cjs.map +1 -7
  26. package/build/components/media-preview/index.cjs +114 -114
  27. package/build/components/media-preview/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/index.cjs +181 -188
  29. package/build/components/rotation-ruler/index.cjs.map +1 -7
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  32. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  33. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  34. package/build/image-editor/core/camera.cjs +257 -205
  35. package/build/image-editor/core/camera.cjs.map +1 -7
  36. package/build/image-editor/core/constants.cjs +127 -102
  37. package/build/image-editor/core/constants.cjs.map +1 -7
  38. package/build/image-editor/core/containment.cjs +275 -262
  39. package/build/image-editor/core/containment.cjs.map +1 -7
  40. package/build/image-editor/core/crop-rect.cjs +33 -44
  41. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  42. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  43. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  44. package/build/image-editor/core/index.cjs +88 -61
  45. package/build/image-editor/core/interaction-controller.cjs +583 -646
  46. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  47. package/build/image-editor/core/math/rotation.cjs +26 -35
  48. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  49. package/build/image-editor/core/math/sanitize.cjs +124 -80
  50. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  51. package/build/image-editor/core/setter-helpers.cjs +57 -60
  52. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  53. package/build/image-editor/core/source-region.cjs +220 -190
  54. package/build/image-editor/core/source-region.cjs.map +1 -7
  55. package/build/image-editor/core/state.cjs +278 -265
  56. package/build/image-editor/core/state.cjs.map +1 -7
  57. package/build/image-editor/core/stencil-math.cjs +193 -206
  58. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  59. package/build/image-editor/core/transform-style.cjs +39 -48
  60. package/build/image-editor/core/transform-style.cjs.map +1 -7
  61. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  62. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  63. package/build/image-editor/core/types.cjs +4 -18
  64. package/build/image-editor/core/viewport-state.cjs +31 -45
  65. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  66. package/build/image-editor/index.cjs +65 -64
  67. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  68. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  69. package/build/image-editor/react/components/cropper.cjs +583 -710
  70. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  71. package/build/image-editor/react/components/index.cjs +22 -33
  72. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  74. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  76. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  78. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  80. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  81. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  82. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  84. package/build/image-editor/react/hooks/index.cjs +16 -31
  85. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  87. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  89. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  90. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  91. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  92. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  93. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  95. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  96. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  97. package/build/index.cjs +45 -39
  98. package/build/lock-unlock.cjs +9 -35
  99. package/build/lock-unlock.cjs.map +1 -7
  100. package/build/private-apis.cjs +16 -37
  101. package/build/private-apis.cjs.map +1 -7
  102. package/build/state/aspect-ratio-presets.cjs +53 -0
  103. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  104. package/build/state/composite-reducer.cjs +134 -112
  105. package/build/state/composite-reducer.cjs.map +1 -7
  106. package/build/state/index.cjs +63 -47
  107. package/build/state/media-editor-state-provider.cjs +35 -48
  108. package/build/state/media-editor-state-provider.cjs.map +1 -7
  109. package/build/state/types.cjs +12 -31
  110. package/build/state/types.cjs.map +1 -7
  111. package/build/state/use-media-editor-state.cjs +261 -294
  112. package/build/state/use-media-editor-state.cjs.map +1 -7
  113. package/build/store/actions.cjs +17 -44
  114. package/build/store/actions.cjs.map +1 -7
  115. package/build/store/constants.cjs +8 -29
  116. package/build/store/constants.cjs.map +1 -7
  117. package/build/store/index.cjs +33 -40
  118. package/build/store/index.cjs.map +1 -7
  119. package/build/store/reducer.cjs +28 -50
  120. package/build/store/reducer.cjs.map +1 -7
  121. package/build/store/selectors.cjs +16 -41
  122. package/build/store/selectors.cjs.map +1 -7
  123. package/build/utils/get-media-type.cjs +18 -41
  124. package/build/utils/get-media-type.cjs.map +1 -7
  125. package/build/utils/index.cjs +9 -28
  126. package/build-module/components/media-editor/index.mjs +490 -673
  127. package/build-module/components/media-editor/index.mjs.map +1 -7
  128. package/build-module/components/media-editor/use-crop-options.mjs +38 -32
  129. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  130. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  131. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  132. package/build-module/components/media-editor-canvas/index.mjs +98 -96
  133. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  134. package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
  135. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  136. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  137. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  138. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  139. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  140. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  142. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  144. package/build-module/components/media-editor-modal/index.mjs +88 -124
  145. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  146. package/build-module/components/media-editor-provider/index.mjs +26 -29
  147. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  148. package/build-module/components/media-form/index.mjs +68 -56
  149. package/build-module/components/media-form/index.mjs.map +1 -7
  150. package/build-module/components/media-preview/index.mjs +106 -90
  151. package/build-module/components/media-preview/index.mjs.map +1 -7
  152. package/build-module/components/rotation-ruler/index.mjs +161 -164
  153. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  154. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  156. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  158. package/build-module/image-editor/core/camera.mjs +245 -178
  159. package/build-module/image-editor/core/camera.mjs.map +1 -7
  160. package/build-module/image-editor/core/constants.mjs +110 -64
  161. package/build-module/image-editor/core/constants.mjs.map +1 -7
  162. package/build-module/image-editor/core/containment.mjs +265 -237
  163. package/build-module/image-editor/core/containment.mjs.map +1 -7
  164. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  165. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  166. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  168. package/build-module/image-editor/core/index.mjs +5 -34
  169. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  170. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  171. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  172. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  173. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  174. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  175. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  176. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  177. package/build-module/image-editor/core/source-region.mjs +210 -160
  178. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  179. package/build-module/image-editor/core/state.mjs +271 -243
  180. package/build-module/image-editor/core/state.mjs.map +1 -7
  181. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  182. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  183. package/build-module/image-editor/core/transform-style.mjs +34 -23
  184. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  185. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  186. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  187. package/build-module/image-editor/core/types.mjs +0 -1
  188. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  189. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  190. package/build-module/image-editor/index.mjs +3 -38
  191. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  192. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  193. package/build-module/image-editor/react/components/cropper.mjs +550 -686
  194. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  195. package/build-module/image-editor/react/components/index.mjs +1 -7
  196. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  198. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  200. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  202. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  204. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  205. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  206. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  208. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  209. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  211. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  213. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  215. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  217. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  219. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  220. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  221. package/build-module/index.mjs +3 -10
  222. package/build-module/lock-unlock.mjs +5 -10
  223. package/build-module/lock-unlock.mjs.map +1 -7
  224. package/build-module/private-apis.mjs +8 -9
  225. package/build-module/private-apis.mjs.map +1 -7
  226. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  227. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  228. package/build-module/state/composite-reducer.mjs +114 -90
  229. package/build-module/state/composite-reducer.mjs.map +1 -7
  230. package/build-module/state/index.mjs +5 -25
  231. package/build-module/state/media-editor-state-provider.mjs +29 -24
  232. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  233. package/build-module/state/types.mjs +8 -7
  234. package/build-module/state/types.mjs.map +1 -7
  235. package/build-module/state/use-media-editor-state.mjs +256 -286
  236. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  237. package/build-module/store/actions.mjs +12 -19
  238. package/build-module/store/actions.mjs.map +1 -7
  239. package/build-module/store/constants.mjs +4 -5
  240. package/build-module/store/constants.mjs.map +1 -7
  241. package/build-module/store/index.mjs +8 -9
  242. package/build-module/store/index.mjs.map +1 -7
  243. package/build-module/store/reducer.mjs +23 -26
  244. package/build-module/store/reducer.mjs.map +1 -7
  245. package/build-module/store/selectors.mjs +8 -13
  246. package/build-module/store/selectors.mjs.map +1 -7
  247. package/build-module/utils/get-media-type.mjs +14 -17
  248. package/build-module/utils/get-media-type.mjs.map +1 -7
  249. package/build-module/utils/index.mjs +1 -6
  250. package/build-style/style-rtl.css +41 -4
  251. package/build-style/style.css +41 -4
  252. package/build-types/components/media-editor/index.d.ts +4 -0
  253. package/build-types/components/media-editor/index.d.ts.map +1 -1
  254. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  256. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  257. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  258. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  259. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  260. package/build-types/components/media-preview/index.d.ts.map +1 -1
  261. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  262. package/build-types/image-editor/core/constants.d.ts +0 -1
  263. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  264. package/build-types/image-editor/core/index.d.ts +1 -1
  265. package/build-types/image-editor/core/index.d.ts.map +1 -1
  266. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  267. package/build-types/image-editor/core/types.d.ts +1 -1
  268. package/build-types/image-editor/index.d.ts +7 -6
  269. package/build-types/image-editor/index.d.ts.map +1 -1
  270. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  271. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  272. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  273. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  274. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  275. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  276. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  277. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  278. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  279. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  280. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  281. package/build-types/state/composite-reducer.d.ts +1 -1
  282. package/build-types/state/composite-reducer.d.ts.map +1 -1
  283. package/build-types/state/index.d.ts +1 -0
  284. package/build-types/state/index.d.ts.map +1 -1
  285. package/build-types/state/types.d.ts +2 -1
  286. package/build-types/state/types.d.ts.map +1 -1
  287. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  288. package/package.json +21 -21
  289. package/src/components/media-editor/index.tsx +215 -162
  290. package/src/components/media-editor/style.scss +19 -0
  291. package/src/components/media-editor/use-crop-options.ts +5 -2
  292. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  293. package/src/components/media-editor-canvas/index.tsx +16 -26
  294. package/src/components/media-editor-image-controls/index.tsx +4 -2
  295. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  296. package/src/components/media-editor-modal/style.scss +1 -1
  297. package/src/components/media-preview/index.tsx +66 -23
  298. package/src/components/media-preview/style.scss +16 -2
  299. package/src/components/rotation-ruler/style.scss +6 -2
  300. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  301. package/src/image-editor/README.md +8 -8
  302. package/src/image-editor/core/constants.ts +0 -13
  303. package/src/image-editor/core/index.ts +1 -5
  304. package/src/image-editor/core/setter-helpers.ts +1 -1
  305. package/src/image-editor/core/types.ts +1 -1
  306. package/src/image-editor/docs/architecture.md +1 -1
  307. package/src/image-editor/docs/recipes.md +3 -3
  308. package/src/image-editor/index.ts +7 -16
  309. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  310. package/src/image-editor/react/components/cropper.tsx +19 -27
  311. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  312. package/src/image-editor/react/hooks/index.ts +2 -2
  313. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  314. package/src/state/aspect-ratio-presets.ts +18 -0
  315. package/src/state/composite-reducer.ts +2 -2
  316. package/src/state/index.ts +1 -0
  317. package/src/state/types.ts +2 -6
  318. package/src/state/use-media-editor-state.ts +7 -5
  319. package/build/image-editor/core/index.cjs.map +0 -7
  320. package/build/image-editor/core/types.cjs.map +0 -7
  321. package/build/image-editor/index.cjs.map +0 -7
  322. package/build/image-editor/react/components/index.cjs.map +0 -7
  323. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  324. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  325. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  326. package/build/index.cjs.map +0 -7
  327. package/build/state/index.cjs.map +0 -7
  328. package/build/utils/index.cjs.map +0 -7
  329. package/build-module/image-editor/core/index.mjs.map +0 -7
  330. package/build-module/image-editor/core/types.mjs.map +0 -7
  331. package/build-module/image-editor/index.mjs.map +0 -7
  332. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  333. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  334. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  335. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  336. package/build-module/index.mjs.map +0 -7
  337. package/build-module/state/index.mjs.map +0 -7
  338. package/build-module/utils/index.mjs.map +0 -7
  339. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/image-editor/core/state.ts"],
4
- "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 ) ||\n\t\t! nearlyEqual( current.cropRect.width, initial.cropRect.width ) ||\n\t\t! n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OM","MIN_ZOOM","normalizeRotation","restrictPanZoom","restrictCropRect","degreesToRadians","DEFAULT_STATE"],"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 ) ||\n\t\t! nearlyEqual( current.cropRect.width, initial.cropRect.width ) ||\n\t\t! nearlyEqual( current.cropRect.height, initial.cropRect.height )\n\t);\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,gBAAgB;AAEtB,SAAS,YAAa,GAAW,GAAqB;CACrD,OAAO,KAAK,IAAK,IAAI,CAAE,IAAI;AAC5B;;;;;;;;;;;;AAaA,SAAgB,sBACf,GACA,GACU;CACV,MAAM,SAA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Q,SAAS,OAAO,QAAQ,SAAS,KAAM,KAC9D,CAAE,YAAa,QAAQ,SAAS,QAAQ,QAAQ,SAAS,MAAO;AAElE"}
@@ -1,216 +1,203 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/image-editor/core/stencil-math.ts
21
- var stencil_math_exports = {};
22
- __export(stencil_math_exports, {
23
- DEFAULT_MIN_CROP_SIZE: () => DEFAULT_MIN_CROP_SIZE,
24
- computeFreeResizeRect: () => computeFreeResizeRect,
25
- computeLockedResizeRect: () => computeLockedResizeRect,
26
- computeShiftLockedResizeRect: () => computeShiftLockedResizeRect,
27
- getMinCropPixels: () => getMinCropPixels
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
28
5
  });
29
- module.exports = __toCommonJS(stencil_math_exports);
30
- var import_constants = require("./constants.cjs");
6
+ let __constants_ts = require("./constants.cjs");
7
+ // packages/media-editor/src/image-editor/core/stencil-math.ts
8
+ /**
9
+ * Resolve the minimum crop dimension, in source-image pixels, for the current
10
+ * display scale.
11
+ *
12
+ * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that
13
+ * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that
14
+ * keeps the crop large enough to grab. The on-screen floor converted to source
15
+ * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the
16
+ * larger of the two. When the image is shown small (small `displayScale`) the
17
+ * on-screen floor dominates; once it is shown large enough the source-pixel
18
+ * floor takes over.
19
+ *
20
+ * @param displayScale CSS pixels rendered per source pixel
21
+ * (fit scale × zoom × view scale).
22
+ * @return Minimum crop dimension in source-image pixels.
23
+ */
31
24
  function getMinCropPixels(displayScale) {
32
- if (displayScale <= 0) {
33
- return import_constants.MIN_CROP_PIXELS;
34
- }
35
- return Math.max(import_constants.MIN_CROP_PIXELS, import_constants.MIN_CROP_SCREEN_PX / displayScale);
25
+ if (displayScale <= 0) return __constants_ts.MIN_CROP_PIXELS;
26
+ return Math.max(__constants_ts.MIN_CROP_PIXELS, __constants_ts.MIN_CROP_SCREEN_PX / displayScale);
36
27
  }
37
- var DEFAULT_MIN_CROP_SIZE = { width: 0.05, height: 0.05 };
28
+ /**
29
+ * Default minimum crop rect dimension in normalized space, used when no
30
+ * explicit per-axis minimum is supplied (e.g. before the source image
31
+ * has loaded). Real usage derives a pixel-based min from the source
32
+ * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.
33
+ */
34
+ const DEFAULT_MIN_CROP_SIZE = {
35
+ width: .05,
36
+ height: .05
37
+ };
38
+ /**
39
+ * Compute the new crop rect for a free (no aspect ratio) resize.
40
+ *
41
+ * Each edge moves independently based on the handle being dragged.
42
+ * Edges are clamped to the provided bounds and maintain a minimum size.
43
+ *
44
+ * @param drag The current drag state.
45
+ * @param clientX Current mouse/touch X position in pixels.
46
+ * @param clientY Current mouse/touch Y position in pixels.
47
+ * @param imageSize The rendered image dimensions in pixels.
48
+ * @param bounds The allowed crop area bounds.
49
+ * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
50
+ * @return The new crop rect in normalized coordinates.
51
+ */
38
52
  function computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize = DEFAULT_MIN_CROP_SIZE) {
39
- const dx = imageSize.width > 0 ? (clientX - drag.startX) / imageSize.width : 0;
40
- const dy = imageSize.height > 0 ? (clientY - drag.startY) / imageSize.height : 0;
41
- const s = drag.startRect;
42
- const handle = drag.handle;
43
- let edgeTop = s.y;
44
- let edgeBottom = s.y + s.height;
45
- let edgeLeft = s.x;
46
- let edgeRight = s.x + s.width;
47
- if (handle === "n" || handle === "nw" || handle === "ne") {
48
- edgeTop = Math.max(
49
- bounds.minY,
50
- Math.min(s.y + dy, edgeBottom - minCropSize.height)
51
- );
52
- }
53
- if (handle === "s" || handle === "sw" || handle === "se") {
54
- edgeBottom = Math.max(
55
- edgeTop + minCropSize.height,
56
- Math.min(s.y + s.height + dy, bounds.maxY)
57
- );
58
- }
59
- if (handle === "w" || handle === "nw" || handle === "sw") {
60
- edgeLeft = Math.max(
61
- bounds.minX,
62
- Math.min(s.x + dx, edgeRight - minCropSize.width)
63
- );
64
- }
65
- if (handle === "e" || handle === "ne" || handle === "se") {
66
- edgeRight = Math.max(
67
- edgeLeft + minCropSize.width,
68
- Math.min(s.x + s.width + dx, bounds.maxX)
69
- );
70
- }
71
- return {
72
- x: edgeLeft,
73
- y: edgeTop,
74
- width: edgeRight - edgeLeft,
75
- height: edgeBottom - edgeTop
76
- };
53
+ const dx = imageSize.width > 0 ? (clientX - drag.startX) / imageSize.width : 0;
54
+ const dy = imageSize.height > 0 ? (clientY - drag.startY) / imageSize.height : 0;
55
+ const s = drag.startRect;
56
+ const handle = drag.handle;
57
+ let edgeTop = s.y;
58
+ let edgeBottom = s.y + s.height;
59
+ let edgeLeft = s.x;
60
+ let edgeRight = s.x + s.width;
61
+ if (handle === "n" || handle === "nw" || handle === "ne") edgeTop = Math.max(bounds.minY, Math.min(s.y + dy, edgeBottom - minCropSize.height));
62
+ if (handle === "s" || handle === "sw" || handle === "se") edgeBottom = Math.max(edgeTop + minCropSize.height, Math.min(s.y + s.height + dy, bounds.maxY));
63
+ if (handle === "w" || handle === "nw" || handle === "sw") edgeLeft = Math.max(bounds.minX, Math.min(s.x + dx, edgeRight - minCropSize.width));
64
+ if (handle === "e" || handle === "ne" || handle === "se") edgeRight = Math.max(edgeLeft + minCropSize.width, Math.min(s.x + s.width + dx, bounds.maxX));
65
+ return {
66
+ x: edgeLeft,
67
+ y: edgeTop,
68
+ width: edgeRight - edgeLeft,
69
+ height: edgeBottom - edgeTop
70
+ };
77
71
  }
72
+ /**
73
+ * Compute the new crop rect for a locked-aspect-ratio corner resize.
74
+ *
75
+ * The opposite corner is the anchor. The dragged corner moves freely
76
+ * but the result is clamped to maintain the aspect ratio and stay
77
+ * within bounds.
78
+ *
79
+ * @param drag The current drag state.
80
+ * @param clientX Current mouse/touch X position in pixels.
81
+ * @param clientY Current mouse/touch Y position in pixels.
82
+ * @param imageSize The rendered image dimensions in pixels.
83
+ * @param bounds The allowed crop area bounds.
84
+ * @param normalizedRatio The locked aspect ratio (width / height in normalized space).
85
+ * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
86
+ * @param driverAxis Optional explicit driver axis. Used for keyboard
87
+ * resize, where one arrow axis should determine the step.
88
+ * @return The new crop rect in normalized coordinates.
89
+ */
78
90
  function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize = DEFAULT_MIN_CROP_SIZE, driverAxis) {
79
- if (normalizedRatio <= 0 || imageSize.width <= 0 || imageSize.height <= 0) {
80
- return { ...drag.startRect };
81
- }
82
- const dx = (clientX - drag.startX) / imageSize.width;
83
- const dy = (clientY - drag.startY) / imageSize.height;
84
- const s = drag.startRect;
85
- const handle = drag.handle;
86
- const anchorX = handle === "nw" || handle === "sw" ? s.x + s.width : s.x;
87
- const anchorY = handle === "nw" || handle === "ne" ? s.y + s.height : s.y;
88
- const dirX = handle === "nw" || handle === "sw" ? -1 : 1;
89
- const dirY = handle === "nw" || handle === "ne" ? -1 : 1;
90
- const draggedX = (handle === "nw" || handle === "sw" ? s.x : s.x + s.width) + dx;
91
- const draggedY = (handle === "nw" || handle === "ne" ? s.y : s.y + s.height) + dy;
92
- let distW = (draggedX - anchorX) * dirX;
93
- let distH = (draggedY - anchorY) * dirY;
94
- const minDistW = Math.max(
95
- minCropSize.width,
96
- minCropSize.height * normalizedRatio
97
- );
98
- const minDistH = minDistW / normalizedRatio;
99
- distW = Math.max(distW, minDistW);
100
- distH = Math.max(distH, minDistH);
101
- const pixelRatio = normalizedRatio * imageSize.width / imageSize.height;
102
- const isWidthDriver = driverAxis === "width" || !driverAxis && distW * imageSize.width / (distH * imageSize.height) > pixelRatio;
103
- if (isWidthDriver) {
104
- distH = distW / normalizedRatio;
105
- } else {
106
- distW = distH * normalizedRatio;
107
- }
108
- const maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;
109
- const maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;
110
- if (distW > maxW) {
111
- distW = maxW;
112
- distH = distW / normalizedRatio;
113
- }
114
- if (distH > maxH) {
115
- distH = maxH;
116
- distW = distH * normalizedRatio;
117
- }
118
- distW = Math.max(distW, minDistW);
119
- distH = Math.max(distH, minDistH);
120
- const newX = dirX > 0 ? anchorX : anchorX - distW;
121
- const newY = dirY > 0 ? anchorY : anchorY - distH;
122
- return { x: newX, y: newY, width: distW, height: distH };
91
+ if (normalizedRatio <= 0 || imageSize.width <= 0 || imageSize.height <= 0) return { ...drag.startRect };
92
+ const dx = (clientX - drag.startX) / imageSize.width;
93
+ const dy = (clientY - drag.startY) / imageSize.height;
94
+ const s = drag.startRect;
95
+ const handle = drag.handle;
96
+ const anchorX = handle === "nw" || handle === "sw" ? s.x + s.width : s.x;
97
+ const anchorY = handle === "nw" || handle === "ne" ? s.y + s.height : s.y;
98
+ const dirX = handle === "nw" || handle === "sw" ? -1 : 1;
99
+ const dirY = handle === "nw" || handle === "ne" ? -1 : 1;
100
+ const draggedX = (handle === "nw" || handle === "sw" ? s.x : s.x + s.width) + dx;
101
+ const draggedY = (handle === "nw" || handle === "ne" ? s.y : s.y + s.height) + dy;
102
+ let distW = (draggedX - anchorX) * dirX;
103
+ let distH = (draggedY - anchorY) * dirY;
104
+ const minDistW = Math.max(minCropSize.width, minCropSize.height * normalizedRatio);
105
+ const minDistH = minDistW / normalizedRatio;
106
+ distW = Math.max(distW, minDistW);
107
+ distH = Math.max(distH, minDistH);
108
+ const pixelRatio = normalizedRatio * imageSize.width / imageSize.height;
109
+ if (driverAxis === "width" || !driverAxis && distW * imageSize.width / (distH * imageSize.height) > pixelRatio) distH = distW / normalizedRatio;
110
+ else distW = distH * normalizedRatio;
111
+ const maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;
112
+ const maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;
113
+ if (distW > maxW) {
114
+ distW = maxW;
115
+ distH = distW / normalizedRatio;
116
+ }
117
+ if (distH > maxH) {
118
+ distH = maxH;
119
+ distW = distH * normalizedRatio;
120
+ }
121
+ distW = Math.max(distW, minDistW);
122
+ distH = Math.max(distH, minDistH);
123
+ return {
124
+ x: dirX > 0 ? anchorX : anchorX - distW,
125
+ y: dirY > 0 ? anchorY : anchorY - distH,
126
+ width: distW,
127
+ height: distH
128
+ };
123
129
  }
130
+ /**
131
+ * Compute the new crop rect for a resize that temporarily locks the
132
+ * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).
133
+ *
134
+ * Corner handles delegate to {@link computeLockedResizeRect}. Edge
135
+ * handles size the dragged axis freely, then expand the perpendicular
136
+ * axis symmetrically around the rect's center to preserve the ratio,
137
+ * clamping symmetrically so the rect stays within bounds.
138
+ *
139
+ * @param drag The current drag state.
140
+ * @param clientX Current mouse/touch X position in pixels.
141
+ * @param clientY Current mouse/touch Y position in pixels.
142
+ * @param imageSize The rendered image dimensions in pixels.
143
+ * @param bounds The allowed crop area bounds.
144
+ * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
145
+ * @return The new crop rect in normalized coordinates.
146
+ */
124
147
  function computeShiftLockedResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize = DEFAULT_MIN_CROP_SIZE) {
125
- const s = drag.startRect;
126
- const pixelW = s.width * imageSize.width;
127
- const pixelH = s.height * imageSize.height;
128
- if (pixelH <= 0 || pixelW <= 0) {
129
- return computeFreeResizeRect(
130
- drag,
131
- clientX,
132
- clientY,
133
- imageSize,
134
- bounds,
135
- minCropSize
136
- );
137
- }
138
- const normalizedRatio = s.width / s.height;
139
- const handle = drag.handle;
140
- if (handle === "nw" || handle === "ne" || handle === "sw" || handle === "se") {
141
- return computeLockedResizeRect(
142
- drag,
143
- clientX,
144
- clientY,
145
- imageSize,
146
- bounds,
147
- normalizedRatio,
148
- minCropSize
149
- );
150
- }
151
- const free = computeFreeResizeRect(
152
- drag,
153
- clientX,
154
- clientY,
155
- imageSize,
156
- bounds,
157
- minCropSize
158
- );
159
- if (handle === "n" || handle === "s") {
160
- let newHeight2 = free.height;
161
- let newWidth2 = newHeight2 * normalizedRatio;
162
- const centerX = s.x + s.width / 2;
163
- const maxWidth = Math.min(centerX - bounds.minX, bounds.maxX - centerX) * 2;
164
- if (newWidth2 > maxWidth) {
165
- newWidth2 = maxWidth;
166
- newHeight2 = newWidth2 / normalizedRatio;
167
- }
168
- const minHeight = Math.max(
169
- minCropSize.height,
170
- minCropSize.width / normalizedRatio
171
- );
172
- if (newHeight2 < minHeight) {
173
- newHeight2 = minHeight;
174
- newWidth2 = newHeight2 * normalizedRatio;
175
- }
176
- const newY = handle === "n" ? s.y + s.height - newHeight2 : s.y;
177
- return {
178
- x: centerX - newWidth2 / 2,
179
- y: newY,
180
- width: newWidth2,
181
- height: newHeight2
182
- };
183
- }
184
- let newWidth = free.width;
185
- let newHeight = newWidth / normalizedRatio;
186
- const centerY = s.y + s.height / 2;
187
- const maxHeight = Math.min(centerY - bounds.minY, bounds.maxY - centerY) * 2;
188
- if (newHeight > maxHeight) {
189
- newHeight = maxHeight;
190
- newWidth = newHeight * normalizedRatio;
191
- }
192
- const minWidth = Math.max(
193
- minCropSize.width,
194
- minCropSize.height * normalizedRatio
195
- );
196
- if (newWidth < minWidth) {
197
- newWidth = minWidth;
198
- newHeight = newWidth / normalizedRatio;
199
- }
200
- const newX = handle === "w" ? s.x + s.width - newWidth : s.x;
201
- return {
202
- x: newX,
203
- y: centerY - newHeight / 2,
204
- width: newWidth,
205
- height: newHeight
206
- };
148
+ const s = drag.startRect;
149
+ const pixelW = s.width * imageSize.width;
150
+ if (s.height * imageSize.height <= 0 || pixelW <= 0) return computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize);
151
+ const normalizedRatio = s.width / s.height;
152
+ const handle = drag.handle;
153
+ if (handle === "nw" || handle === "ne" || handle === "sw" || handle === "se") return computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize);
154
+ const free = computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize);
155
+ if (handle === "n" || handle === "s") {
156
+ let newHeight = free.height;
157
+ let newWidth = newHeight * normalizedRatio;
158
+ const centerX = s.x + s.width / 2;
159
+ const maxWidth = Math.min(centerX - bounds.minX, bounds.maxX - centerX) * 2;
160
+ if (newWidth > maxWidth) {
161
+ newWidth = maxWidth;
162
+ newHeight = newWidth / normalizedRatio;
163
+ }
164
+ const minHeight = Math.max(minCropSize.height, minCropSize.width / normalizedRatio);
165
+ if (newHeight < minHeight) {
166
+ newHeight = minHeight;
167
+ newWidth = newHeight * normalizedRatio;
168
+ }
169
+ const newY = handle === "n" ? s.y + s.height - newHeight : s.y;
170
+ return {
171
+ x: centerX - newWidth / 2,
172
+ y: newY,
173
+ width: newWidth,
174
+ height: newHeight
175
+ };
176
+ }
177
+ let newWidth = free.width;
178
+ let newHeight = newWidth / normalizedRatio;
179
+ const centerY = s.y + s.height / 2;
180
+ const maxHeight = Math.min(centerY - bounds.minY, bounds.maxY - centerY) * 2;
181
+ if (newHeight > maxHeight) {
182
+ newHeight = maxHeight;
183
+ newWidth = newHeight * normalizedRatio;
184
+ }
185
+ const minWidth = Math.max(minCropSize.width, minCropSize.height * normalizedRatio);
186
+ if (newWidth < minWidth) {
187
+ newWidth = minWidth;
188
+ newHeight = newWidth / normalizedRatio;
189
+ }
190
+ return {
191
+ x: handle === "w" ? s.x + s.width - newWidth : s.x,
192
+ y: centerY - newHeight / 2,
193
+ width: newWidth,
194
+ height: newHeight
195
+ };
207
196
  }
208
- // Annotate the CommonJS export names for ESM import in node:
209
- 0 && (module.exports = {
210
- DEFAULT_MIN_CROP_SIZE,
211
- computeFreeResizeRect,
212
- computeLockedResizeRect,
213
- computeShiftLockedResizeRect,
214
- getMinCropPixels
215
- });
216
- //# sourceMappingURL=stencil-math.cjs.map
197
+ exports.DEFAULT_MIN_CROP_SIZE = DEFAULT_MIN_CROP_SIZE;
198
+ exports.computeFreeResizeRect = computeFreeResizeRect;
199
+ exports.computeLockedResizeRect = computeLockedResizeRect;
200
+ exports.computeShiftLockedResizeRect = computeShiftLockedResizeRect;
201
+ exports.getMinCropPixels = getMinCropPixels;
202
+
203
+ //# sourceMappingURL=stencil-math.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/image-editor/core/stencil-math.ts"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAoD;AAwB7C,SAAS,iBAAkB,c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AAC3B,UAAM,UAAU,EAAE,IAAI,EAAE,QAAQ;AAGhC,UAAM,WACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,QAAKC,YAAW,UAAW;AAC1B,MAAAA,YAAW;AACX,MAAAD,aAAYC,YAAW;AAAA,IACxB;AAKA,UAAM,YAAY,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ,YAAY,QAAQ;AAAA,IACrB;AACA,QAAKD,aAAY,WAAY;AAC5B,MAAAA,aAAY;AACZ,MAAAC,YAAWD,aAAY;AAAA,IACxB;AAGA,UAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,SAASA,aAAY,EAAE;AAC7D,WAAO;AAAA,MACN,GAAG,UAAUC,YAAW;AAAA,MACxB,GAAG;AAAA,MACH,OAAOA;AAAA,MACP,QAAQD;AAAA,IACT;AAAA,EACD;AAGA,MAAI,WAAW,KAAK;AACpB,MAAI,YAAY,WAAW;AAC3B,QAAM,UAAU,EAAE,IAAI,EAAE,SAAS;AACjC,QAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,MAAK,YAAY,WAAY;AAC5B,gBAAY;AACZ,eAAW,YAAY;AAAA,EACxB;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,YAAY;AAAA,IACZ,YAAY,SAAS;AAAA,EACtB;AACA,MAAK,WAAW,UAAW;AAC1B,eAAW;AACX,gBAAY,WAAW;AAAA,EACxB;AACA,QAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;AAC3D,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,UAAU,YAAY;AAAA,IACzB,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
6
- "names": ["newHeight", "newWidth"]
7
- }
1
+ {"version":3,"file":"stencil-math.cjs","names":["MIN_CROP_PIXELS","MIN_CROP_SCREEN_PX"],"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,OAAOA,eAAAA;CAER,OAAO,KAAK,IAAKA,eAAAA,iBAAiBC,eAAAA,qBAAqB,YAAa;AACrE;;;;;;;AAQA,MAAa,wBAA8B;CAAE,OAAO;CAAM,QAAQ;AAAK;;;;;;;;;;;;;;;AAuCvE,SAAgB,sBACf,MACA,SACA,SACA,WACA,QACA,cAAoB,uBACH;CACjB,MAAM,KACL,UAAU,QAAQ,KAAM,UAAU,KAAK,UAAW,UAAU,QAAQ;CACrE,MAAM,KACL,UAAU,SAAS,KAAM,UAAU,KAAK,UAAW,UAAU,SAAS;CAEvE,MAAM,IAAI,KAAK;CACf,MAAM,SAAS,KAAK;CAEpB,IAAI,UAAU,EAAE;CAChB,IAAI,aAAa,EAAE,IAAI,EAAE;CACzB,IAAI,WAAW,EAAE;CACjB,IAAI,YAAY,EAAE,IAAI,EAAE;CAExB,IAAK,WAAW,OAAO,WAAW,QAAQ,WAAW,MACpD,UAAU,KAAK,IACd,OAAO,MACP,KAAK,IAAK,EAAE,IAAI,IAAI,aAAa,YAAY,MAAO,CACrD;CAED,IAAK,WAAW,OAAO,WAAW,QAAQ,WAAW,MACpD,aAAa,KAAK,IACjB,UAAU,YAAY,QACtB,KAAK,IAAK,EAAE,IAAI,EAAE,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