@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/interaction-controller.ts"],
4
- "sourcesContent": ["import type { CropperState, NormalizedPoint, Size } from './types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tDEFAULT_WHEEL_ZOOM_SPEED,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n\tMIN_ZOOM,\n\tMAX_ZOOM,\n} from './constants';\nimport { restrictPanZoom } from './containment';\n\n/** Time window for detecting a double-tap gesture (ms). */\nconst DOUBLE_TAP_TIME = 300;\n/** Max distance between taps to count as a double-tap (px). */\nconst DOUBLE_TAP_DISTANCE = 30;\n/** Duration of the zoom animation state (ms). */\nconst ZOOM_ANIMATION_DURATION = 200;\n\n/**\n * Get the natural image dimensions from cropper state, falling back to 1x1.\n *\n * @param state The current cropper state.\n * @return The image dimensions.\n */\nfunction getImageSizeFromState( state: CropperState ): {\n\twidth: number;\n\theight: number;\n} {\n\treturn state.image\n\t\t? { width: state.image.naturalWidth, height: state.image.naturalHeight }\n\t\t: { width: 1, height: 1 };\n}\n\n/**\n * Get the distance between two touch points.\n *\n * @param t1 The first touch.\n * @param t2 The second touch.\n * @return The pixel distance between the two touches.\n */\nfunction getTouchDistance( t1: Touch, t2: Touch ): number {\n\tconst dx = t1.clientX - t2.clientX;\n\tconst dy = t1.clientY - t2.clientY;\n\treturn Math.sqrt( dx * dx + dy * dy );\n}\n\n/**\n * Status reported by the interaction controller when drag/zoom state changes.\n */\nexport interface InteractionStatus {\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n}\n\n/**\n * State updates the interaction controller can request from its host UI.\n */\nexport interface CropperInteractionActions {\n\t/** Set the image pan offset in normalized coordinates. */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/**\n\t * Set the zoom level. Cursorless surfaces (slider, keyboard `+`/`-`)\n\t * rely on this anchoring at the crop center; pointer-driven zoom\n\t * paths use `setZoomAtPoint` with an explicit focal point instead.\n\t */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together for focal-point zoom. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Snap rotate by 90 degrees. */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;\n}\n\n/**\n * Options for creating an InteractionController.\n *\n * Scalar options (minZoom, maxZoom, etc.) are read lazily on each\n * interaction, so changes to the options object take effect immediately\n * without recreating the controller.\n */\nexport interface InteractionControllerOptions {\n\t/** Returns the current cropper state. Called on every interaction. */\n\tgetState: () => CropperState;\n\t/** State updates the interaction controller can request from its host UI. */\n\tactions: CropperInteractionActions;\n\t/** Returns the container dimensions in pixels. */\n\tgetContainerSize: () => Size;\n\t/** Returns the rendered image dimensions in pixels, if available. */\n\tgetImageSize: () => Size | undefined;\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Read lazily. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/** Called when isDragging or isZooming changes. */\n\tonStatusChange?: ( status: InteractionStatus ) => void;\n}\n\n/**\n * Framework-agnostic imperative controller for image cropper interactions.\n *\n * Handles mouse, touch, and keyboard event processing for pan, zoom,\n * and crop manipulation. Uses requestAnimationFrame for drag/pinch\n * updates to avoid layout thrashing.\n *\n * The controller does not register DOM event listeners itself — that is the\n * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).\n * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,\n * and `handleKeyDown` methods that the UI layer calls with native DOM events.\n *\n * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)\n * are read lazily from `this.options` on each interaction, so the UI layer\n * can update them without recreating the controller.\n *\n * Call `destroy()` to clean up timers and pending animation frames.\n */\nexport class InteractionController {\n\tprivate readonly options: InteractionControllerOptions;\n\n\t/** Current drag/zoom status. */\n\tprivate isDragging = false;\n\tprivate isZooming = false;\n\n\t/** Active drag state during pointer interactions. */\n\tprivate drag: {\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t} | null = null;\n\n\t/** Active touch state during touch interactions. */\n\tprivate touch: {\n\t\t/** Finger distance at pinch start (0 until pinch detected). */\n\t\tstartDistance: number;\n\t\t/** Zoom level when pinch was detected. */\n\t\tstartZoom: number;\n\t\t/** First touch X/Y (for single-finger pan delta). */\n\t\tlastTouchX: number;\n\t\tlastTouchY: number;\n\t\t/** Pan when gesture started. */\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t\t/** Container rect snapshot for focal-point math. */\n\t\tcontainerRect?: DOMRect;\n\t\t/** Midpoint of two fingers when pinch was detected. */\n\t\tstartMidX: number;\n\t\tstartMidY: number;\n\t\t/** Whether pinch was ever detected during this gesture. */\n\t\tdidPinch: boolean;\n\t\t/** Whether any dispatch has occurred (prevents dispatching before first move). */\n\t\tmoved: boolean;\n\t} | null = null;\n\n\t/** Cleanup function for active touch listeners on document. */\n\tprivate touchCleanup: ( () => void ) | null = null;\n\n\t/**\n\t * Cleanup function for active pointer-drag listeners on the\n\t * captured element. Set while a pointer drag is in progress so\n\t * `destroy()` can tear the drag down cleanly if the consumer\n\t * unmounts mid-drag. Cleared on pointerup/lostpointercapture.\n\t */\n\tprivate pointerCleanup: ( () => void ) | null = null;\n\n\t/** Last tap info for double-tap detection. */\n\tprivate lastTap: {\n\t\ttime: number;\n\t\tx: number;\n\t\ty: number;\n\t} | null = null;\n\n\t/** Timer for the zoom animation state (double-tap). */\n\tprivate zoomTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Timer for wheel gesture debounce. */\n\tprivate wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Whether a wheel gesture is currently active. */\n\tprivate wheelGestureActive = false;\n\n\t/** Current requestAnimationFrame ID. */\n\tprivate rafId = 0;\n\n\tconstructor( options: InteractionControllerOptions ) {\n\t\tthis.options = options;\n\t}\n\n\t/** Read minZoom lazily so option changes take effect immediately. */\n\tprivate get minZoom(): number {\n\t\treturn this.options.minZoom ?? MIN_ZOOM;\n\t}\n\n\t/** Read maxZoom lazily so option changes take effect immediately. */\n\tprivate get maxZoom(): number {\n\t\treturn this.options.maxZoom ?? MAX_ZOOM;\n\t}\n\n\t/** Read zoomSpeed lazily so option changes take effect immediately. */\n\tprivate get zoomSpeed(): number {\n\t\treturn this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;\n\t}\n\n\t/** Read keyboardStep lazily so option changes take effect immediately. */\n\tprivate get keyboardStep(): number {\n\t\treturn this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;\n\t}\n\n\t/**\n\t * Get the keyboard pan step, including modifier-based coarse movement.\n\t *\n\t * @param event The native KeyboardEvent.\n\t * @return The normalized pan step.\n\t */\n\tprivate getKeyboardStep( event: KeyboardEvent ): number {\n\t\treturn event.shiftKey\n\t\t\t? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t: this.keyboardStep;\n\t}\n\n\t/** Read doubleTapZoom lazily so option changes take effect immediately. */\n\tprivate get doubleTapZoom(): number {\n\t\treturn this.options.doubleTapZoom ?? 2;\n\t}\n\n\t/**\n\t * Update the drag/zoom status and notify via callback if changed.\n\t *\n\t * @param update Partial status with isDragging and/or isZooming.\n\t */\n\tprivate setStatus(\n\t\tupdate: Partial< { isDragging: boolean; isZooming: boolean } >\n\t): void {\n\t\tlet changed = false;\n\t\tif (\n\t\t\tupdate.isDragging !== undefined &&\n\t\t\tupdate.isDragging !== this.isDragging\n\t\t) {\n\t\t\tthis.isDragging = update.isDragging;\n\t\t\tchanged = true;\n\t\t}\n\t\tif (\n\t\t\tupdate.isZooming !== undefined &&\n\t\t\tupdate.isZooming !== this.isZooming\n\t\t) {\n\t\t\tthis.isZooming = update.isZooming;\n\t\t\tchanged = true;\n\t\t}\n\t\tif ( changed ) {\n\t\t\tthis.options.onStatusChange?.( {\n\t\t\t\tisDragging: this.isDragging,\n\t\t\t\tisZooming: this.isZooming,\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a pointer-down event on the container element.\n\t *\n\t * Initiates a drag (pan) interaction. Captures the pointer on the\n\t * provided element and registers pointermove/pointerup/lostpointercapture\n\t * listeners for the duration of the drag.\n\t *\n\t * @param e The native PointerEvent.\n\t * @param el The DOM element to capture the pointer on.\n\t */\n\thandlePointerDown( e: PointerEvent, el: HTMLElement ): void {\n\t\t// Only handle primary button (left click / first touch).\n\t\tif ( e.button !== 0 ) {\n\t\t\treturn;\n\t\t}\n\t\t// Touch gestures are handled by touchstart/touchmove. Starting the\n\t\t// pointer drag path too can briefly toggle drag UI before pinch begins.\n\t\tif ( e.pointerType === 'touch' ) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\n\t\t// Blur any focused handle so its focus ring doesn't linger,\n\t\t// but leave the canvas itself alone so keyboard control works after drag.\n\t\tconst ownerDoc = el.ownerDocument;\n\t\tif (\n\t\t\townerDoc?.activeElement instanceof HTMLElement &&\n\t\t\townerDoc.activeElement !== el\n\t\t) {\n\t\t\townerDoc.activeElement.blur();\n\t\t}\n\n\t\tel.focus();\n\n\t\t// Capture pointer so drag works across iframe boundaries.\n\t\tel.setPointerCapture( e.pointerId );\n\n\t\t// End a pending wheel gesture now, so its debounce timer cannot\n\t\t// fire mid-drag and end the drag's gesture along with it.\n\t\tif ( this.wheelGestureActive ) {\n\t\t\tclearTimeout( this.wheelGestureTimer );\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}\n\n\t\tthis.setStatus( { isDragging: true } );\n\t\tthis.options.onGestureStart?.();\n\n\t\tconst currentState = this.options.getState();\n\t\tthis.drag = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tstartPanX: currentState.pan.x,\n\t\t\tstartPanY: currentState.pan.y,\n\t\t};\n\n\t\tconst onPointerMove = ( moveEvent: Event ) => {\n\t\t\tconst drag = this.drag;\n\t\t\tif ( ! drag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pe = moveEvent as PointerEvent;\n\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\t\tconst s = this.options.getState();\n\t\t\t\tconst imgSize = this.options.getImageSize();\n\t\t\t\tconst containerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = imgSize ?? containerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( pe.clientX - drag.startX ) / panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( pe.clientY - drag.startY ) / panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: drag.startPanX + deltaX,\n\t\t\t\t\t\t\ty: drag.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t} );\n\t\t};\n\n\t\tconst removeListeners = () => {\n\t\t\tel.removeEventListener( 'pointermove', onPointerMove );\n\t\t\tel.removeEventListener( 'pointerup', onPointerUp );\n\t\t\tel.removeEventListener( 'lostpointercapture', onPointerUp );\n\t\t};\n\n\t\tconst onPointerUp = () => {\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t\tthis.drag = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tremoveListeners();\n\t\t\tthis.pointerCleanup = null;\n\t\t};\n\n\t\tel.addEventListener( 'pointermove', onPointerMove );\n\t\tel.addEventListener( 'pointerup', onPointerUp );\n\t\tel.addEventListener( 'lostpointercapture', onPointerUp );\n\t\t// Expose cleanup to destroy() in case the consumer unmounts\n\t\t// mid-drag. The pending rAF is cancelled in destroy().\n\t\tthis.pointerCleanup = removeListeners;\n\t}\n\n\t/**\n\t * Handle a wheel event on the container element.\n\t *\n\t * Implements focal-point zoom: the point under the cursor stays\n\t * stationary on screen while the zoom level changes.\n\t *\n\t * Must be registered with `{ passive: false }` to allow preventDefault.\n\t *\n\t * @param e The native WheelEvent.\n\t */\n\thandleWheel( e: WheelEvent ): void {\n\t\te.preventDefault();\n\n\t\tif ( this.drag ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Debounced gesture boundaries for wheel zoom.\n\t\t// Start on first wheel event, end after 300ms of no events.\n\t\tif ( ! this.wheelGestureActive ) {\n\t\t\tthis.wheelGestureActive = true;\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.wheelGestureTimer = setTimeout( () => {\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}, DOUBLE_TAP_TIME );\n\n\t\tconst s = this.options.getState();\n\t\tconst delta = -e.deltaY * this.zoomSpeed;\n\t\tconst newZoom = Math.min(\n\t\t\tthis.maxZoom,\n\t\t\tMath.max( this.minZoom, s.zoom + delta )\n\t\t);\n\n\t\tif ( newZoom === s.zoom ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Focal-point zoom: keep the point under the cursor stationary.\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\t\tconst visSize = imgSize ?? containerSize;\n\t\tconst target = e.currentTarget;\n\t\tconst rect =\n\t\t\ttarget instanceof Element\n\t\t\t\t? target.getBoundingClientRect()\n\t\t\t\t: undefined;\n\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\tconst fx = e.clientX - rect.left - containerSize.width / 2;\n\t\t\tconst fy = e.clientY - rect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - newZoom / s.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\tconst newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },\n\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\ts.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a touch-start event on the container element.\n\t *\n\t * Supports single-finger pan, two-finger pinch zoom, and\n\t * double-tap to toggle between fit and 2x zoom. Registers\n\t * touchmove/touchend/touchcancel on the provided document for the\n\t * duration of the gesture.\n\t *\n\t * @param e The native TouchEvent.\n\t * @param containerRect The bounding rect of the container element.\n\t * @param doc The document to register move/end listeners on.\n\t * Defaults to globalThis.document. Pass the iframe's\n\t * contentDocument when running inside an iframe.\n\t */\n\thandleTouchStart(\n\t\te: TouchEvent,\n\t\tcontainerRect: DOMRect,\n\t\tdoc: Document = document\n\t): void {\n\t\t// Second finger arriving during an existing gesture — snapshot\n\t\t// pinch start values. handleTouchMove will detect 2 touches and\n\t\t// handle pinch automatically.\n\t\tif ( this.touch && e.touches.length === 2 ) {\n\t\t\tconst s = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch.didPinch = true;\n\t\t\tthis.touch.startDistance = distance;\n\t\t\tthis.touch.startZoom = s.zoom;\n\t\t\tthis.touch.startPanX = s.pan.x;\n\t\t\tthis.touch.startPanY = s.pan.y;\n\t\t\tthis.touch.startMidX = midX;\n\t\t\tthis.touch.startMidY = midY;\n\t\t\tthis.touch.containerRect = containerRect;\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( e.touches.length === 1 ) {\n\t\t\tconst tapX = e.touches[ 0 ].clientX;\n\t\t\tconst tapY = e.touches[ 0 ].clientY;\n\t\t\tif ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentState = this.options.getState();\n\n\t\t\t// Record touch state. Don't decide pan vs pinch yet —\n\t\t\t// that happens in handleTouchMove based on touches.length.\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: 0,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: e.touches[ 0 ].clientX,\n\t\t\t\tlastTouchY: e.touches[ 0 ].clientY,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: 0,\n\t\t\t\tstartMidY: 0,\n\t\t\t\tdidPinch: false,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t} else if ( e.touches.length === 2 ) {\n\t\t\t// Both fingers landed simultaneously (rare but possible).\n\t\t\tconst currentState = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: distance,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: 0,\n\t\t\t\tlastTouchY: 0,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: midX,\n\t\t\t\tstartMidY: midY,\n\t\t\t\tdidPinch: true,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\n\t\tconst onTouchEnd = () => {\n\t\t\tthis.touch = null;\n\t\t\tthis.touchCleanup = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tdoc.removeEventListener( 'touchmove', this.handleTouchMove );\n\t\t\tdoc.removeEventListener( 'touchend', onTouchEnd );\n\t\t\tdoc.removeEventListener( 'touchcancel', onTouchEnd );\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t};\n\n\t\t// Clean up any previous touch listeners before registering new ones.\n\t\tthis.touchCleanup?.();\n\n\t\tdoc.addEventListener( 'touchmove', this.handleTouchMove, {\n\t\t\tpassive: false,\n\t\t} );\n\t\tdoc.addEventListener( 'touchend', onTouchEnd );\n\t\tdoc.addEventListener( 'touchcancel', onTouchEnd );\n\n\t\tthis.touchCleanup = onTouchEnd;\n\t}\n\n\t// Handle a touchmove event during an active touch gesture. Decides pinch\n\t// vs. pan based on current `moveEvent.touches.length`, so the gesture\n\t// can transition between modes without timing sensitivity (e.g. fingers\n\t// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays\n\t// attached when used as an event listener.\n\tprivate handleTouchMove = ( moveEvent: TouchEvent ): void => {\n\t\tconst touch = this.touch;\n\t\tif ( ! touch ) {\n\t\t\treturn;\n\t\t}\n\t\tmoveEvent.preventDefault();\n\n\t\tcancelAnimationFrame( this.rafId );\n\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\tconst s = this.options.getState();\n\n\t\t\tif ( moveEvent.touches.length === 2 ) {\n\t\t\t\t// Two fingers → always pinch, regardless of how gesture\n\t\t\t\t// started. Initialize pinch state on first 2-finger move.\n\t\t\t\tif ( ! touch.didPinch ) {\n\t\t\t\t\ttouch.didPinch = true;\n\t\t\t\t\ttouch.startDistance = getTouchDistance(\n\t\t\t\t\t\tmoveEvent.touches[ 0 ],\n\t\t\t\t\t\tmoveEvent.touches[ 1 ]\n\t\t\t\t\t);\n\t\t\t\t\ttouch.startZoom = s.zoom;\n\t\t\t\t\ttouch.startPanX = s.pan.x;\n\t\t\t\t\ttouch.startPanY = s.pan.y;\n\t\t\t\t\ttouch.startMidX =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientX +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientX ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\ttouch.startMidY =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientY +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientY ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst latestContainerSize = this.options.getContainerSize();\n\t\t\t\tconst latestImageSize = this.options.getImageSize();\n\n\t\t\t\t// Pinch zoom with focal point at finger midpoint,\n\t\t\t\t// plus simultaneous pan from midpoint drift.\n\t\t\t\tconst t0 = moveEvent.touches[ 0 ];\n\t\t\t\tconst t1 = moveEvent.touches[ 1 ];\n\t\t\t\tconst currentDistance = getTouchDistance( t0, t1 );\n\t\t\t\tconst ratio = currentDistance / touch.startDistance;\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, touch.startZoom * ratio )\n\t\t\t\t);\n\n\t\t\t\tconst visSize = latestImageSize ?? latestContainerSize;\n\t\t\t\tconst rect = touch.containerRect;\n\t\t\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\t\t\t// Current midpoint.\n\t\t\t\t\tconst mx =\n\t\t\t\t\t\t( t0.clientX + t1.clientX ) / 2 -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst my =\n\t\t\t\t\t\t( t0.clientY + t1.clientY ) / 2 -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\n\t\t\t\t\t// Pan from midpoint drift (fingers moving together).\n\t\t\t\t\tconst startMx =\n\t\t\t\t\t\ttouch.startMidX -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst startMy =\n\t\t\t\t\t\ttouch.startMidY -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\t\t\t\t\tconst panDx =\n\t\t\t\t\t\tvisSize.width > 0\n\t\t\t\t\t\t\t? ( mx - startMx ) / visSize.width\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst panDy =\n\t\t\t\t\t\tvisSize.height > 0\n\t\t\t\t\t\t\t? ( my - startMy ) / visSize.height\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\t// Focal-point zoom correction. Keep this based on the\n\t\t\t\t\t// pinch-start state; using the current reducer state here\n\t\t\t\t\t// compounds prior touchmove frames and makes a fixed pinch\n\t\t\t\t\t// center drift after the image is already zoomed or panned.\n\t\t\t\t\tconst zoomRatio =\n\t\t\t\t\t\ttouch.startZoom !== 0\n\t\t\t\t\t\t\t? 1 - newZoom / touch.startZoom\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst startFocalNormX = startMx / visSize.width;\n\t\t\t\t\tconst startFocalNormY = startMy / visSize.height;\n\n\t\t\t\t\t// Combined: midpoint drift + zoom around the pinch-start\n\t\t\t\t\t// midpoint, so moving both fingers together pans while\n\t\t\t\t\t// symmetric pinches keep the start center stationary.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX +\n\t\t\t\t\t\tpanDx +\n\t\t\t\t\t\t( startFocalNormX - touch.startPanX ) * zoomRatio;\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY +\n\t\t\t\t\t\tpanDy +\n\t\t\t\t\t\t( startFocalNormY - touch.startPanY ) * zoomRatio;\n\n\t\t\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...s,\n\t\t\t\t\t\t\tzoom: newZoom,\n\t\t\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\t\ts.cropRect\n\t\t\t\t\t);\n\t\t\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t\t\t} else if ( newZoom !== s.zoom ) {\n\t\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\t}\n\t\t\t} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {\n\t\t\t\t// One finger and no pinch ever detected → pan.\n\t\t\t\t// If fingers went 2→1 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan — avoids accidental pan after releasing\n\t\t\t\t// one finger from a pinch.\n\t\t\t\tif ( ! touch.moved ) {\n\t\t\t\t\ttouch.moved = true;\n\t\t\t\t\tthis.setStatus( { isDragging: true } );\n\t\t\t\t}\n\t\t\t\tconst panImageSize = this.options.getImageSize();\n\t\t\t\tconst panContainerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = panImageSize ?? panContainerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientX -\n\t\t\t\t\t\t\t\ttouch.lastTouchX ) /\n\t\t\t\t\t\t\tpanSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientY -\n\t\t\t\t\t\t\t\ttouch.lastTouchY ) /\n\t\t\t\t\t\t\tpanSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: touch.startPanX + deltaX,\n\t\t\t\t\t\t\ty: touch.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Handle double-tap-to-toggle-zoom. On a second tap within the configured\n\t// time/distance threshold, toggles zoom between `minZoom` and\n\t// `doubleTapZoom` around the tap point and dispatches. Returns `true` if\n\t// the tap was handled as a double-tap (caller should early-return),\n\t// `false` otherwise (caller proceeds with normal single-tap handling).\n\t// Either way, records the tap for next time.\n\tprivate tryDoubleTap(\n\t\te: TouchEvent,\n\t\ttapX: number,\n\t\ttapY: number,\n\t\tcontainerRect: DOMRect\n\t): boolean {\n\t\tconst now = Date.now();\n\t\tconst lastTap = this.lastTap;\n\t\tif ( ! lastTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\t\tconst timeDelta = now - lastTap.time;\n\t\tconst distDelta = Math.sqrt(\n\t\t\t( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2\n\t\t);\n\t\tconst isDoubleTap =\n\t\t\ttimeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;\n\t\tif ( ! isDoubleTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\n\t\t// It's a double-tap — suppress browser zoom.\n\t\te.preventDefault();\n\t\tthis.lastTap = null;\n\n\t\tconst currentState = this.options.getState();\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\n\t\t// Toggle: if past halfway to doubleTapZoom, go back to 1x.\n\t\tconst targetZoom =\n\t\t\tcurrentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2\n\t\t\t\t? this.minZoom\n\t\t\t\t: this.doubleTapZoom;\n\t\tconst visSize = imgSize ?? containerSize;\n\n\t\t// Enable zoom animation before dispatching.\n\t\tthis.setStatus( { isZooming: true } );\n\t\tclearTimeout( this.zoomTimer );\n\t\tthis.zoomTimer = setTimeout( () => {\n\t\t\tthis.setStatus( { isZooming: false } );\n\t\t}, ZOOM_ANIMATION_DURATION );\n\n\t\t// Double-tap bypasses the normal handleTouchStart gesture path so\n\t\t// onGestureStart/End are never called — fire them here so undo\n\t\t// receives a proper boundary around this discrete zoom action.\n\t\tthis.options.onGestureStart?.();\n\n\t\tif ( visSize.width > 0 && visSize.height > 0 ) {\n\t\t\tconst fx = tapX - containerRect.left - containerSize.width / 2;\n\t\t\tconst fy = tapY - containerRect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - targetZoom / currentState.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX =\n\t\t\t\tcurrentState.pan.x +\n\t\t\t\t( focalNormX - currentState.pan.x ) * zoomRatio;\n\t\t\tconst newCropY =\n\t\t\t\tcurrentState.pan.y +\n\t\t\t\t( focalNormY - currentState.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{\n\t\t\t\t\t...currentState,\n\t\t\t\t\tzoom: targetZoom,\n\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t},\n\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\tcurrentState.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( targetZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( targetZoom );\n\t\t}\n\n\t\tthis.options.onGestureEnd?.();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a keydown event on the container element.\n\t *\n\t * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.\n\t *\n\t * @param e The native KeyboardEvent.\n\t */\n\thandleKeyDown( e: KeyboardEvent ): void {\n\t\tconst currentState = this.options.getState();\n\n\t\tswitch ( e.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y + keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y - keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x + keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x - keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '+':\n\t\t\tcase '=': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom + 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '-':\n\t\t\tcase '_': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom - 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'r':\n\t\t\tcase 'R': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'h':\n\t\t\tcase 'H': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'horizontal' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'v':\n\t\t\tcase 'V': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'vertical' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clean up all timers, animation frames, and active touch listeners.\n\t *\n\t * Must be called when the controller is no longer needed (e.g., on\n\t * component unmount or element removal).\n\t */\n\tdestroy(): void {\n\t\tcancelAnimationFrame( this.rafId );\n\t\tclearTimeout( this.zoomTimer );\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.touchCleanup?.();\n\t\tthis.touchCleanup = null;\n\t\tthis.pointerCleanup?.();\n\t\tthis.pointerCleanup = null;\n\t\tthis.drag = null;\n\t\tthis.touch = null;\n\t\tthis.lastTap = null;\n\t\t// Reset the gesture bookkeeping too. The timers above are cancelled\n\t\t// rather than run, so these flags would otherwise stay set: a stale\n\t\t// `wheelGestureActive` suppresses the next wheel gesture's start,\n\t\t// and `setStatus` dedupes against `isDragging` / `isZooming`, so a\n\t\t// stale value swallows the next real change.\n\t\tthis.wheelGestureActive = false;\n\t\tthis.isDragging = false;\n\t\tthis.isZooming = false;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAMO;AACP,yBAAgC;AAGhC,IAAM,kBAAkB;AAExB,IAAM,sBAAsB;AAE5B,IAAM,0BAA0B;AAQhC,SAAS,sBAAuB,OAG9B;AACD,SAAO,MAAM,QACV,EAAE,OAAO,MAAM,MAAM,cAAc,QAAQ,MAAM,MAAM,cAAc,IACrE,EAAE,OAAO,GAAG,QAAQ,EAAE;AAC1B;AASA,SAAS,iBAAkB,IAAW,IAAoB;AACzD,QAAM,KAAK,GAAG,UAAU,GAAG;AAC3B,QAAM,KAAK,GAAG,UAAU,GAAG;AAC3B,SAAO,KAAK,KAAM,KAAK,KAAK,KAAK,EAAG;AACrC;AAuFO,IAAM,wBAAN,MAA4B;AAAA,EACjB;AAAA;AAAA,EAGT,aAAa;AAAA,EACb,YAAY;AAAA;AAAA,EAGZ,OAKG;AAAA;AAAA,EAGH,QAoBG;AAAA;AAAA,EAGH,eAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtC,iBAAwC;AAAA;AAAA,EAGxC,UAIG;AAAA;AAAA,EAGH;AAAA;AAAA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AK,QAAQ,QAAQ,aAAc,EAAE,WAAW,KAAK,CAAE;AACvD;AAAA,MACD;AAAA,MACA,KAAK;AAAA,MACL,KAAK,KAAK;AACT,YAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAW;AACvD;AAAA,QACD;AACA,UAAE,eAAe;AACjB,aAAK,QAAQ,QAAQ,aAAc,YAAa;AAChD;AAAA,MACD;AAAA,MACA,KAAK;AAAA,MACL,KAAK,KAAK;AACT,YAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAW;AACvD;AAAA,QACD;AACA,UAAE,eAAe;AACjB,aAAK,QAAQ,QAAQ,aAAc,UAAW;AAC9C;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAgB;AACf,yBAAsB,KAAK,KAAM;AACjC,iBAAc,KAAK,SAAU;AAC7B,iBAAc,KAAK,iBAAkB;AACrC,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,iBAAiB;AACtB,SAAK,iBAAiB;AACtB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAMf,SAAK,qBAAqB;AAC1B,SAAK,aAAa;AAClB,SAAK,YAAY;AAAA,EAClB;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"interaction-controller.cjs","names":["MIN_ZOOM","MAX_ZOOM","DEFAULT_WHEEL_ZOOM_SPEED","DEFAULT_KEYBOARD_STEP","KEYBOARD_SHIFT_STEP_MULTIPLIER","restrictPanZoom"],"sources":["../../../src/image-editor/core/interaction-controller.ts"],"sourcesContent":["import type { CropperState, NormalizedPoint, Size } from './types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tDEFAULT_WHEEL_ZOOM_SPEED,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n\tMIN_ZOOM,\n\tMAX_ZOOM,\n} from './constants';\nimport { restrictPanZoom } from './containment';\n\n/** Time window for detecting a double-tap gesture (ms). */\nconst DOUBLE_TAP_TIME = 300;\n/** Max distance between taps to count as a double-tap (px). */\nconst DOUBLE_TAP_DISTANCE = 30;\n/** Duration of the zoom animation state (ms). */\nconst ZOOM_ANIMATION_DURATION = 200;\n\n/**\n * Get the natural image dimensions from cropper state, falling back to 1x1.\n *\n * @param state The current cropper state.\n * @return The image dimensions.\n */\nfunction getImageSizeFromState( state: CropperState ): {\n\twidth: number;\n\theight: number;\n} {\n\treturn state.image\n\t\t? { width: state.image.naturalWidth, height: state.image.naturalHeight }\n\t\t: { width: 1, height: 1 };\n}\n\n/**\n * Get the distance between two touch points.\n *\n * @param t1 The first touch.\n * @param t2 The second touch.\n * @return The pixel distance between the two touches.\n */\nfunction getTouchDistance( t1: Touch, t2: Touch ): number {\n\tconst dx = t1.clientX - t2.clientX;\n\tconst dy = t1.clientY - t2.clientY;\n\treturn Math.sqrt( dx * dx + dy * dy );\n}\n\n/**\n * Status reported by the interaction controller when drag/zoom state changes.\n */\nexport interface InteractionStatus {\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n}\n\n/**\n * State updates the interaction controller can request from its host UI.\n */\nexport interface CropperInteractionActions {\n\t/** Set the image pan offset in normalized coordinates. */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/**\n\t * Set the zoom level. Cursorless surfaces (slider, keyboard `+`/`-`)\n\t * rely on this anchoring at the crop center; pointer-driven zoom\n\t * paths use `setZoomAtPoint` with an explicit focal point instead.\n\t */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together for focal-point zoom. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Snap rotate by 90 degrees. */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;\n}\n\n/**\n * Options for creating an InteractionController.\n *\n * Scalar options (minZoom, maxZoom, etc.) are read lazily on each\n * interaction, so changes to the options object take effect immediately\n * without recreating the controller.\n */\nexport interface InteractionControllerOptions {\n\t/** Returns the current cropper state. Called on every interaction. */\n\tgetState: () => CropperState;\n\t/** State updates the interaction controller can request from its host UI. */\n\tactions: CropperInteractionActions;\n\t/** Returns the container dimensions in pixels. */\n\tgetContainerSize: () => Size;\n\t/** Returns the rendered image dimensions in pixels, if available. */\n\tgetImageSize: () => Size | undefined;\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Read lazily. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/** Called when isDragging or isZooming changes. */\n\tonStatusChange?: ( status: InteractionStatus ) => void;\n}\n\n/**\n * Framework-agnostic imperative controller for image cropper interactions.\n *\n * Handles mouse, touch, and keyboard event processing for pan, zoom,\n * and crop manipulation. Uses requestAnimationFrame for drag/pinch\n * updates to avoid layout thrashing.\n *\n * The controller does not register DOM event listeners itself — that is the\n * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).\n * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,\n * and `handleKeyDown` methods that the UI layer calls with native DOM events.\n *\n * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)\n * are read lazily from `this.options` on each interaction, so the UI layer\n * can update them without recreating the controller.\n *\n * Call `destroy()` to clean up timers and pending animation frames.\n */\nexport class InteractionController {\n\tprivate readonly options: InteractionControllerOptions;\n\n\t/** Current drag/zoom status. */\n\tprivate isDragging = false;\n\tprivate isZooming = false;\n\n\t/** Active drag state during pointer interactions. */\n\tprivate drag: {\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t} | null = null;\n\n\t/** Active touch state during touch interactions. */\n\tprivate touch: {\n\t\t/** Finger distance at pinch start (0 until pinch detected). */\n\t\tstartDistance: number;\n\t\t/** Zoom level when pinch was detected. */\n\t\tstartZoom: number;\n\t\t/** First touch X/Y (for single-finger pan delta). */\n\t\tlastTouchX: number;\n\t\tlastTouchY: number;\n\t\t/** Pan when gesture started. */\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t\t/** Container rect snapshot for focal-point math. */\n\t\tcontainerRect?: DOMRect;\n\t\t/** Midpoint of two fingers when pinch was detected. */\n\t\tstartMidX: number;\n\t\tstartMidY: number;\n\t\t/** Whether pinch was ever detected during this gesture. */\n\t\tdidPinch: boolean;\n\t\t/** Whether any dispatch has occurred (prevents dispatching before first move). */\n\t\tmoved: boolean;\n\t} | null = null;\n\n\t/** Cleanup function for active touch listeners on document. */\n\tprivate touchCleanup: ( () => void ) | null = null;\n\n\t/**\n\t * Cleanup function for active pointer-drag listeners on the\n\t * captured element. Set while a pointer drag is in progress so\n\t * `destroy()` can tear the drag down cleanly if the consumer\n\t * unmounts mid-drag. Cleared on pointerup/lostpointercapture.\n\t */\n\tprivate pointerCleanup: ( () => void ) | null = null;\n\n\t/** Last tap info for double-tap detection. */\n\tprivate lastTap: {\n\t\ttime: number;\n\t\tx: number;\n\t\ty: number;\n\t} | null = null;\n\n\t/** Timer for the zoom animation state (double-tap). */\n\tprivate zoomTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Timer for wheel gesture debounce. */\n\tprivate wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Whether a wheel gesture is currently active. */\n\tprivate wheelGestureActive = false;\n\n\t/** Current requestAnimationFrame ID. */\n\tprivate rafId = 0;\n\n\tconstructor( options: InteractionControllerOptions ) {\n\t\tthis.options = options;\n\t}\n\n\t/** Read minZoom lazily so option changes take effect immediately. */\n\tprivate get minZoom(): number {\n\t\treturn this.options.minZoom ?? MIN_ZOOM;\n\t}\n\n\t/** Read maxZoom lazily so option changes take effect immediately. */\n\tprivate get maxZoom(): number {\n\t\treturn this.options.maxZoom ?? MAX_ZOOM;\n\t}\n\n\t/** Read zoomSpeed lazily so option changes take effect immediately. */\n\tprivate get zoomSpeed(): number {\n\t\treturn this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;\n\t}\n\n\t/** Read keyboardStep lazily so option changes take effect immediately. */\n\tprivate get keyboardStep(): number {\n\t\treturn this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;\n\t}\n\n\t/**\n\t * Get the keyboard pan step, including modifier-based coarse movement.\n\t *\n\t * @param event The native KeyboardEvent.\n\t * @return The normalized pan step.\n\t */\n\tprivate getKeyboardStep( event: KeyboardEvent ): number {\n\t\treturn event.shiftKey\n\t\t\t? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t: this.keyboardStep;\n\t}\n\n\t/** Read doubleTapZoom lazily so option changes take effect immediately. */\n\tprivate get doubleTapZoom(): number {\n\t\treturn this.options.doubleTapZoom ?? 2;\n\t}\n\n\t/**\n\t * Update the drag/zoom status and notify via callback if changed.\n\t *\n\t * @param update Partial status with isDragging and/or isZooming.\n\t */\n\tprivate setStatus(\n\t\tupdate: Partial< { isDragging: boolean; isZooming: boolean } >\n\t): void {\n\t\tlet changed = false;\n\t\tif (\n\t\t\tupdate.isDragging !== undefined &&\n\t\t\tupdate.isDragging !== this.isDragging\n\t\t) {\n\t\t\tthis.isDragging = update.isDragging;\n\t\t\tchanged = true;\n\t\t}\n\t\tif (\n\t\t\tupdate.isZooming !== undefined &&\n\t\t\tupdate.isZooming !== this.isZooming\n\t\t) {\n\t\t\tthis.isZooming = update.isZooming;\n\t\t\tchanged = true;\n\t\t}\n\t\tif ( changed ) {\n\t\t\tthis.options.onStatusChange?.( {\n\t\t\t\tisDragging: this.isDragging,\n\t\t\t\tisZooming: this.isZooming,\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a pointer-down event on the container element.\n\t *\n\t * Initiates a drag (pan) interaction. Captures the pointer on the\n\t * provided element and registers pointermove/pointerup/lostpointercapture\n\t * listeners for the duration of the drag.\n\t *\n\t * @param e The native PointerEvent.\n\t * @param el The DOM element to capture the pointer on.\n\t */\n\thandlePointerDown( e: PointerEvent, el: HTMLElement ): void {\n\t\t// Only handle primary button (left click / first touch).\n\t\tif ( e.button !== 0 ) {\n\t\t\treturn;\n\t\t}\n\t\t// Touch gestures are handled by touchstart/touchmove. Starting the\n\t\t// pointer drag path too can briefly toggle drag UI before pinch begins.\n\t\tif ( e.pointerType === 'touch' ) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\n\t\t// Blur any focused handle so its focus ring doesn't linger,\n\t\t// but leave the canvas itself alone so keyboard control works after drag.\n\t\tconst ownerDoc = el.ownerDocument;\n\t\tif (\n\t\t\townerDoc?.activeElement instanceof HTMLElement &&\n\t\t\townerDoc.activeElement !== el\n\t\t) {\n\t\t\townerDoc.activeElement.blur();\n\t\t}\n\n\t\tel.focus();\n\n\t\t// Capture pointer so drag works across iframe boundaries.\n\t\tel.setPointerCapture( e.pointerId );\n\n\t\t// End a pending wheel gesture now, so its debounce timer cannot\n\t\t// fire mid-drag and end the drag's gesture along with it.\n\t\tif ( this.wheelGestureActive ) {\n\t\t\tclearTimeout( this.wheelGestureTimer );\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}\n\n\t\tthis.setStatus( { isDragging: true } );\n\t\tthis.options.onGestureStart?.();\n\n\t\tconst currentState = this.options.getState();\n\t\tthis.drag = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tstartPanX: currentState.pan.x,\n\t\t\tstartPanY: currentState.pan.y,\n\t\t};\n\n\t\tconst onPointerMove = ( moveEvent: Event ) => {\n\t\t\tconst drag = this.drag;\n\t\t\tif ( ! drag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pe = moveEvent as PointerEvent;\n\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\t\tconst s = this.options.getState();\n\t\t\t\tconst imgSize = this.options.getImageSize();\n\t\t\t\tconst containerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = imgSize ?? containerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( pe.clientX - drag.startX ) / panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( pe.clientY - drag.startY ) / panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: drag.startPanX + deltaX,\n\t\t\t\t\t\t\ty: drag.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t} );\n\t\t};\n\n\t\tconst removeListeners = () => {\n\t\t\tel.removeEventListener( 'pointermove', onPointerMove );\n\t\t\tel.removeEventListener( 'pointerup', onPointerUp );\n\t\t\tel.removeEventListener( 'lostpointercapture', onPointerUp );\n\t\t};\n\n\t\tconst onPointerUp = () => {\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t\tthis.drag = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tremoveListeners();\n\t\t\tthis.pointerCleanup = null;\n\t\t};\n\n\t\tel.addEventListener( 'pointermove', onPointerMove );\n\t\tel.addEventListener( 'pointerup', onPointerUp );\n\t\tel.addEventListener( 'lostpointercapture', onPointerUp );\n\t\t// Expose cleanup to destroy() in case the consumer unmounts\n\t\t// mid-drag. The pending rAF is cancelled in destroy().\n\t\tthis.pointerCleanup = removeListeners;\n\t}\n\n\t/**\n\t * Handle a wheel event on the container element.\n\t *\n\t * Implements focal-point zoom: the point under the cursor stays\n\t * stationary on screen while the zoom level changes.\n\t *\n\t * Must be registered with `{ passive: false }` to allow preventDefault.\n\t *\n\t * @param e The native WheelEvent.\n\t */\n\thandleWheel( e: WheelEvent ): void {\n\t\te.preventDefault();\n\n\t\tif ( this.drag ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Debounced gesture boundaries for wheel zoom.\n\t\t// Start on first wheel event, end after 300ms of no events.\n\t\tif ( ! this.wheelGestureActive ) {\n\t\t\tthis.wheelGestureActive = true;\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.wheelGestureTimer = setTimeout( () => {\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}, DOUBLE_TAP_TIME );\n\n\t\tconst s = this.options.getState();\n\t\tconst delta = -e.deltaY * this.zoomSpeed;\n\t\tconst newZoom = Math.min(\n\t\t\tthis.maxZoom,\n\t\t\tMath.max( this.minZoom, s.zoom + delta )\n\t\t);\n\n\t\tif ( newZoom === s.zoom ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Focal-point zoom: keep the point under the cursor stationary.\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\t\tconst visSize = imgSize ?? containerSize;\n\t\tconst target = e.currentTarget;\n\t\tconst rect =\n\t\t\ttarget instanceof Element\n\t\t\t\t? target.getBoundingClientRect()\n\t\t\t\t: undefined;\n\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\tconst fx = e.clientX - rect.left - containerSize.width / 2;\n\t\t\tconst fy = e.clientY - rect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - newZoom / s.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\tconst newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },\n\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\ts.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a touch-start event on the container element.\n\t *\n\t * Supports single-finger pan, two-finger pinch zoom, and\n\t * double-tap to toggle between fit and 2x zoom. Registers\n\t * touchmove/touchend/touchcancel on the provided document for the\n\t * duration of the gesture.\n\t *\n\t * @param e The native TouchEvent.\n\t * @param containerRect The bounding rect of the container element.\n\t * @param doc The document to register move/end listeners on.\n\t * Defaults to globalThis.document. Pass the iframe's\n\t * contentDocument when running inside an iframe.\n\t */\n\thandleTouchStart(\n\t\te: TouchEvent,\n\t\tcontainerRect: DOMRect,\n\t\tdoc: Document = document\n\t): void {\n\t\t// Second finger arriving during an existing gesture — snapshot\n\t\t// pinch start values. handleTouchMove will detect 2 touches and\n\t\t// handle pinch automatically.\n\t\tif ( this.touch && e.touches.length === 2 ) {\n\t\t\tconst s = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch.didPinch = true;\n\t\t\tthis.touch.startDistance = distance;\n\t\t\tthis.touch.startZoom = s.zoom;\n\t\t\tthis.touch.startPanX = s.pan.x;\n\t\t\tthis.touch.startPanY = s.pan.y;\n\t\t\tthis.touch.startMidX = midX;\n\t\t\tthis.touch.startMidY = midY;\n\t\t\tthis.touch.containerRect = containerRect;\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( e.touches.length === 1 ) {\n\t\t\tconst tapX = e.touches[ 0 ].clientX;\n\t\t\tconst tapY = e.touches[ 0 ].clientY;\n\t\t\tif ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentState = this.options.getState();\n\n\t\t\t// Record touch state. Don't decide pan vs pinch yet —\n\t\t\t// that happens in handleTouchMove based on touches.length.\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: 0,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: e.touches[ 0 ].clientX,\n\t\t\t\tlastTouchY: e.touches[ 0 ].clientY,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: 0,\n\t\t\t\tstartMidY: 0,\n\t\t\t\tdidPinch: false,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t} else if ( e.touches.length === 2 ) {\n\t\t\t// Both fingers landed simultaneously (rare but possible).\n\t\t\tconst currentState = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: distance,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: 0,\n\t\t\t\tlastTouchY: 0,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: midX,\n\t\t\t\tstartMidY: midY,\n\t\t\t\tdidPinch: true,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\n\t\tconst onTouchEnd = () => {\n\t\t\tthis.touch = null;\n\t\t\tthis.touchCleanup = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tdoc.removeEventListener( 'touchmove', this.handleTouchMove );\n\t\t\tdoc.removeEventListener( 'touchend', onTouchEnd );\n\t\t\tdoc.removeEventListener( 'touchcancel', onTouchEnd );\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t};\n\n\t\t// Clean up any previous touch listeners before registering new ones.\n\t\tthis.touchCleanup?.();\n\n\t\tdoc.addEventListener( 'touchmove', this.handleTouchMove, {\n\t\t\tpassive: false,\n\t\t} );\n\t\tdoc.addEventListener( 'touchend', onTouchEnd );\n\t\tdoc.addEventListener( 'touchcancel', onTouchEnd );\n\n\t\tthis.touchCleanup = onTouchEnd;\n\t}\n\n\t// Handle a touchmove event during an active touch gesture. Decides pinch\n\t// vs. pan based on current `moveEvent.touches.length`, so the gesture\n\t// can transition between modes without timing sensitivity (e.g. fingers\n\t// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays\n\t// attached when used as an event listener.\n\tprivate handleTouchMove = ( moveEvent: TouchEvent ): void => {\n\t\tconst touch = this.touch;\n\t\tif ( ! touch ) {\n\t\t\treturn;\n\t\t}\n\t\tmoveEvent.preventDefault();\n\n\t\tcancelAnimationFrame( this.rafId );\n\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\tconst s = this.options.getState();\n\n\t\t\tif ( moveEvent.touches.length === 2 ) {\n\t\t\t\t// Two fingers → always pinch, regardless of how gesture\n\t\t\t\t// started. Initialize pinch state on first 2-finger move.\n\t\t\t\tif ( ! touch.didPinch ) {\n\t\t\t\t\ttouch.didPinch = true;\n\t\t\t\t\ttouch.startDistance = getTouchDistance(\n\t\t\t\t\t\tmoveEvent.touches[ 0 ],\n\t\t\t\t\t\tmoveEvent.touches[ 1 ]\n\t\t\t\t\t);\n\t\t\t\t\ttouch.startZoom = s.zoom;\n\t\t\t\t\ttouch.startPanX = s.pan.x;\n\t\t\t\t\ttouch.startPanY = s.pan.y;\n\t\t\t\t\ttouch.startMidX =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientX +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientX ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\ttouch.startMidY =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientY +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientY ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst latestContainerSize = this.options.getContainerSize();\n\t\t\t\tconst latestImageSize = this.options.getImageSize();\n\n\t\t\t\t// Pinch zoom with focal point at finger midpoint,\n\t\t\t\t// plus simultaneous pan from midpoint drift.\n\t\t\t\tconst t0 = moveEvent.touches[ 0 ];\n\t\t\t\tconst t1 = moveEvent.touches[ 1 ];\n\t\t\t\tconst currentDistance = getTouchDistance( t0, t1 );\n\t\t\t\tconst ratio = currentDistance / touch.startDistance;\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, touch.startZoom * ratio )\n\t\t\t\t);\n\n\t\t\t\tconst visSize = latestImageSize ?? latestContainerSize;\n\t\t\t\tconst rect = touch.containerRect;\n\t\t\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\t\t\t// Current midpoint.\n\t\t\t\t\tconst mx =\n\t\t\t\t\t\t( t0.clientX + t1.clientX ) / 2 -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst my =\n\t\t\t\t\t\t( t0.clientY + t1.clientY ) / 2 -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\n\t\t\t\t\t// Pan from midpoint drift (fingers moving together).\n\t\t\t\t\tconst startMx =\n\t\t\t\t\t\ttouch.startMidX -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst startMy =\n\t\t\t\t\t\ttouch.startMidY -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\t\t\t\t\tconst panDx =\n\t\t\t\t\t\tvisSize.width > 0\n\t\t\t\t\t\t\t? ( mx - startMx ) / visSize.width\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst panDy =\n\t\t\t\t\t\tvisSize.height > 0\n\t\t\t\t\t\t\t? ( my - startMy ) / visSize.height\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\t// Focal-point zoom correction. Keep this based on the\n\t\t\t\t\t// pinch-start state; using the current reducer state here\n\t\t\t\t\t// compounds prior touchmove frames and makes a fixed pinch\n\t\t\t\t\t// center drift after the image is already zoomed or panned.\n\t\t\t\t\tconst zoomRatio =\n\t\t\t\t\t\ttouch.startZoom !== 0\n\t\t\t\t\t\t\t? 1 - newZoom / touch.startZoom\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst startFocalNormX = startMx / visSize.width;\n\t\t\t\t\tconst startFocalNormY = startMy / visSize.height;\n\n\t\t\t\t\t// Combined: midpoint drift + zoom around the pinch-start\n\t\t\t\t\t// midpoint, so moving both fingers together pans while\n\t\t\t\t\t// symmetric pinches keep the start center stationary.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX +\n\t\t\t\t\t\tpanDx +\n\t\t\t\t\t\t( startFocalNormX - touch.startPanX ) * zoomRatio;\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY +\n\t\t\t\t\t\tpanDy +\n\t\t\t\t\t\t( startFocalNormY - touch.startPanY ) * zoomRatio;\n\n\t\t\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...s,\n\t\t\t\t\t\t\tzoom: newZoom,\n\t\t\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\t\ts.cropRect\n\t\t\t\t\t);\n\t\t\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t\t\t} else if ( newZoom !== s.zoom ) {\n\t\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\t}\n\t\t\t} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {\n\t\t\t\t// One finger and no pinch ever detected → pan.\n\t\t\t\t// If fingers went 2→1 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan — avoids accidental pan after releasing\n\t\t\t\t// one finger from a pinch.\n\t\t\t\tif ( ! touch.moved ) {\n\t\t\t\t\ttouch.moved = true;\n\t\t\t\t\tthis.setStatus( { isDragging: true } );\n\t\t\t\t}\n\t\t\t\tconst panImageSize = this.options.getImageSize();\n\t\t\t\tconst panContainerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = panImageSize ?? panContainerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientX -\n\t\t\t\t\t\t\t\ttouch.lastTouchX ) /\n\t\t\t\t\t\t\tpanSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientY -\n\t\t\t\t\t\t\t\ttouch.lastTouchY ) /\n\t\t\t\t\t\t\tpanSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: touch.startPanX + deltaX,\n\t\t\t\t\t\t\ty: touch.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Handle double-tap-to-toggle-zoom. On a second tap within the configured\n\t// time/distance threshold, toggles zoom between `minZoom` and\n\t// `doubleTapZoom` around the tap point and dispatches. Returns `true` if\n\t// the tap was handled as a double-tap (caller should early-return),\n\t// `false` otherwise (caller proceeds with normal single-tap handling).\n\t// Either way, records the tap for next time.\n\tprivate tryDoubleTap(\n\t\te: TouchEvent,\n\t\ttapX: number,\n\t\ttapY: number,\n\t\tcontainerRect: DOMRect\n\t): boolean {\n\t\tconst now = Date.now();\n\t\tconst lastTap = this.lastTap;\n\t\tif ( ! lastTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\t\tconst timeDelta = now - lastTap.time;\n\t\tconst distDelta = Math.sqrt(\n\t\t\t( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2\n\t\t);\n\t\tconst isDoubleTap =\n\t\t\ttimeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;\n\t\tif ( ! isDoubleTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\n\t\t// It's a double-tap — suppress browser zoom.\n\t\te.preventDefault();\n\t\tthis.lastTap = null;\n\n\t\tconst currentState = this.options.getState();\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\n\t\t// Toggle: if past halfway to doubleTapZoom, go back to 1x.\n\t\tconst targetZoom =\n\t\t\tcurrentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2\n\t\t\t\t? this.minZoom\n\t\t\t\t: this.doubleTapZoom;\n\t\tconst visSize = imgSize ?? containerSize;\n\n\t\t// Enable zoom animation before dispatching.\n\t\tthis.setStatus( { isZooming: true } );\n\t\tclearTimeout( this.zoomTimer );\n\t\tthis.zoomTimer = setTimeout( () => {\n\t\t\tthis.setStatus( { isZooming: false } );\n\t\t}, ZOOM_ANIMATION_DURATION );\n\n\t\t// Double-tap bypasses the normal handleTouchStart gesture path so\n\t\t// onGestureStart/End are never called — fire them here so undo\n\t\t// receives a proper boundary around this discrete zoom action.\n\t\tthis.options.onGestureStart?.();\n\n\t\tif ( visSize.width > 0 && visSize.height > 0 ) {\n\t\t\tconst fx = tapX - containerRect.left - containerSize.width / 2;\n\t\t\tconst fy = tapY - containerRect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - targetZoom / currentState.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX =\n\t\t\t\tcurrentState.pan.x +\n\t\t\t\t( focalNormX - currentState.pan.x ) * zoomRatio;\n\t\t\tconst newCropY =\n\t\t\t\tcurrentState.pan.y +\n\t\t\t\t( focalNormY - currentState.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{\n\t\t\t\t\t...currentState,\n\t\t\t\t\tzoom: targetZoom,\n\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t},\n\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\tcurrentState.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( targetZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( targetZoom );\n\t\t}\n\n\t\tthis.options.onGestureEnd?.();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a keydown event on the container element.\n\t *\n\t * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.\n\t *\n\t * @param e The native KeyboardEvent.\n\t */\n\thandleKeyDown( e: KeyboardEvent ): void {\n\t\tconst currentState = this.options.getState();\n\n\t\tswitch ( e.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y + keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y - keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x + keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x - keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '+':\n\t\t\tcase '=': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom + 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '-':\n\t\t\tcase '_': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom - 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'r':\n\t\t\tcase 'R': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'h':\n\t\t\tcase 'H': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'horizontal' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'v':\n\t\t\tcase 'V': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'vertical' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clean up all timers, animation frames, and active touch listeners.\n\t *\n\t * Must be called when the controller is no longer needed (e.g., on\n\t * component unmount or element removal).\n\t */\n\tdestroy(): void {\n\t\tcancelAnimationFrame( this.rafId );\n\t\tclearTimeout( this.zoomTimer );\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.touchCleanup?.();\n\t\tthis.touchCleanup = null;\n\t\tthis.pointerCleanup?.();\n\t\tthis.pointerCleanup = null;\n\t\tthis.drag = null;\n\t\tthis.touch = null;\n\t\tthis.lastTap = null;\n\t\t// Reset the gesture bookkeeping too. The timers above are cancelled\n\t\t// rather than run, so these flags would otherwise stay set: a stale\n\t\t// `wheelGestureActive` suppresses the next wheel gesture's start,\n\t\t// and `setStatus` dedupes against `isDragging` / `isZooming`, so a\n\t\t// stale value swallows the next real change.\n\t\tthis.wheelGestureActive = false;\n\t\tthis.isDragging = false;\n\t\tthis.isZooming = false;\n\t}\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,kBAAkB;;AAExB,MAAM,s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EAAE,QAChC;IAED,EAAE,eAAe;IACjB,KAAK,QAAQ,QAAQ,aAAc,EAAE,WAAW,KAAK,CAAE;IACvD;GAED,KAAK;GACL,KAAK;IACJ,IAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAC5C;IAED,EAAE,eAAe;IACjB,KAAK,QAAQ,QAAQ,aAAc,YAAa;IAChD;GAED,KAAK;GACL,KAAK;IACJ,IAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAC5C;IAED,EAAE,eAAe;IACjB,KAAK,QAAQ,QAAQ,aAAc,UAAW;EAGhD;CACD;;;;;;;CAQA,UAAgB;EACf,qBAAsB,KAAK,KAAM;EACjC,aAAc,KAAK,SAAU;EAC7B,aAAc,KAAK,iBAAkB;EACrC,KAAK,eAAe;EACpB,KAAK,eAAe;EACpB,KAAK,iBAAiB;EACtB,KAAK,iBAAiB;EACtB,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,KAAK,UAAU;EAMf,KAAK,qBAAqB;EAC1B,KAAK,aAAa;EAClB,KAAK,YAAY;CAClB;AACD"}
@@ -1,41 +1,32 @@
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/math/rotation.ts
21
- var rotation_exports = {};
22
- __export(rotation_exports, {
23
- degreesToRadians: () => degreesToRadians,
24
- normalizeRotation: () => normalizeRotation
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
25
5
  });
26
- module.exports = __toCommonJS(rotation_exports);
6
+ // packages/media-editor/src/image-editor/core/math/rotation.ts
7
+ /**
8
+ * Normalizes a rotation value to the range [0, 360).
9
+ *
10
+ * Negative rotations are converted to their positive clockwise equivalent.
11
+ * For example, -90 becomes 270, -45 becomes 315, and 450 becomes 90.
12
+ *
13
+ * @param degrees The rotation value in degrees.
14
+ * @return The normalized rotation in the range [0, 360).
15
+ */
27
16
  function normalizeRotation(degrees) {
28
- if (degrees >= 0) {
29
- return degrees % 360;
30
- }
31
- return (360 + degrees % 360) % 360;
17
+ if (degrees >= 0) return degrees % 360;
18
+ return (360 + degrees % 360) % 360;
32
19
  }
20
+ /**
21
+ * Converts an angle from degrees to radians.
22
+ *
23
+ * @param degrees The angle in degrees.
24
+ * @return The angle in radians.
25
+ */
33
26
  function degreesToRadians(degrees) {
34
- return degrees * Math.PI / 180;
27
+ return degrees * Math.PI / 180;
35
28
  }
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- degreesToRadians,
39
- normalizeRotation
40
- });
41
- //# sourceMappingURL=rotation.cjs.map
29
+ exports.degreesToRadians = degreesToRadians;
30
+ exports.normalizeRotation = normalizeRotation;
31
+
32
+ //# sourceMappingURL=rotation.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/image-editor/core/math/rotation.ts"],
4
- "sourcesContent": ["/**\n * Normalizes a rotation value to the range [0, 360).\n *\n * Negative rotations are converted to their positive clockwise equivalent.\n * For example, -90 becomes 270, -45 becomes 315, and 450 becomes 90.\n *\n * @param degrees The rotation value in degrees.\n * @return The normalized rotation in the range [0, 360).\n */\nexport function normalizeRotation( degrees: number ): number {\n\tif ( degrees >= 0 ) {\n\t\treturn degrees % 360;\n\t}\n\t// For negative rotations, convert to positive clockwise equivalent.\n\treturn ( 360 + ( degrees % 360 ) ) % 360;\n}\n\n/**\n * Converts an angle from degrees to radians.\n *\n * @param degrees The angle in degrees.\n * @return The angle in radians.\n */\nexport function degreesToRadians( degrees: number ): number {\n\treturn ( degrees * Math.PI ) / 180;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,kBAAmB,SAA0B;AAC5D,MAAK,WAAW,GAAI;AACnB,WAAO,UAAU;AAAA,EAClB;AAEA,UAAS,MAAQ,UAAU,OAAU;AACtC;AAQO,SAAS,iBAAkB,SAA0B;AAC3D,SAAS,UAAU,KAAK,KAAO;AAChC;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"rotation.cjs","names":[],"sources":["../../../../src/image-editor/core/math/rotation.ts"],"sourcesContent":["/**\n * Normalizes a rotation value to the range [0, 360).\n *\n * Negative rotations are converted to their positive clockwise equivalent.\n * For example, -90 becomes 270, -45 becomes 315, and 450 becomes 90.\n *\n * @param degrees The rotation value in degrees.\n * @return The normalized rotation in the range [0, 360).\n */\nexport function normalizeRotation( degrees: number ): number {\n\tif ( degrees >= 0 ) {\n\t\treturn degrees % 360;\n\t}\n\t// For negative rotations, convert to positive clockwise equivalent.\n\treturn ( 360 + ( degrees % 360 ) ) % 360;\n}\n\n/**\n * Converts an angle from degrees to radians.\n *\n * @param degrees The angle in degrees.\n * @return The angle in radians.\n */\nexport function degreesToRadians( degrees: number ): number {\n\treturn ( degrees * Math.PI ) / 180;\n}\n"],"mappings":";;;;;;;;;;;;;;;AASA,SAAgB,kBAAmB,SAA0B;CAC5D,IAAK,WAAW,GACf,OAAO,UAAU;CAGlB,QAAS,MAAQ,UAAU,OAAU;AACtC;;;;;;;AAQA,SAAgB,iBAAkB,SAA0B;CAC3D,OAAS,UAAU,KAAK,KAAO;AAChC"}
@@ -1,92 +1,136 @@
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/math/sanitize.ts
21
- var sanitize_exports = {};
22
- __export(sanitize_exports, {
23
- isSafeNumber: () => isSafeNumber,
24
- isValidSize: () => isValidSize,
25
- safeBoundedNumber: () => safeBoundedNumber,
26
- sanitizeCropperState: () => sanitizeCropperState,
27
- sanitizeRect: () => sanitizeRect
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
28
5
  });
29
- module.exports = __toCommonJS(sanitize_exports);
30
- var MAX_SAFE_MAGNITUDE = 1e6;
6
+ // packages/media-editor/src/image-editor/core/math/sanitize.ts
7
+ /**
8
+ * Magnitude beyond which any cropper-math input is treated as corrupt.
9
+ * Picks a value well above any realistic image/rotation/zoom/pan but far
10
+ * below `Number.MAX_VALUE`, so multiplications inside trig and matrix code
11
+ * can't overflow to `Infinity`.
12
+ */
13
+ const MAX_SAFE_MAGNITUDE = 1e6;
14
+ /**
15
+ * Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,
16
+ * MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`
17
+ * because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow
18
+ * downstream trig/matrix math even though the spec reports them as finite.
19
+ *
20
+ * Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this
21
+ * function — they don't overflow on their own. Protection against divisions
22
+ * by sub-normal values lives in `sanitizeCropperState`'s zoom guard.
23
+ *
24
+ * @param value The candidate value.
25
+ * @param fallback The replacement to return when `value` is unsafe.
26
+ * @return Either `value` or `fallback`.
27
+ */
31
28
  function safeBoundedNumber(value, fallback) {
32
- if (!Number.isFinite(value)) {
33
- return fallback;
34
- }
35
- if (Math.abs(value) > MAX_SAFE_MAGNITUDE) {
36
- return fallback;
37
- }
38
- return value;
29
+ if (!Number.isFinite(value)) return fallback;
30
+ if (Math.abs(value) > MAX_SAFE_MAGNITUDE) return fallback;
31
+ return value;
39
32
  }
33
+ /**
34
+ * Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,
35
+ * MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}
36
+ * for callers that need to short-circuit rather than substitute a fallback.
37
+ *
38
+ * @param value The candidate value.
39
+ * @return Whether `value` is safe to use in math.
40
+ */
40
41
  function isSafeNumber(value) {
41
- return Number.isFinite(value) && Math.abs(value) <= MAX_SAFE_MAGNITUDE;
42
+ return Number.isFinite(value) && Math.abs(value) <= MAX_SAFE_MAGNITUDE;
42
43
  }
44
+ /**
45
+ * Returns `true` when both dimensions are finite and within the safe
46
+ * range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters
47
+ * because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but
48
+ * make `container / dim` overflow to `Infinity` downstream in
49
+ * `getImageFit` / `createCamera`. Use this to short-circuit math that
50
+ * would otherwise produce non-finite output.
51
+ *
52
+ * @param size The size to check.
53
+ * @return Whether `size` is safe to use in math.
54
+ */
43
55
  function isValidSize(size) {
44
- return Number.isFinite(size.width) && Number.isFinite(size.height) && size.width >= Number.EPSILON && size.height >= Number.EPSILON && size.width <= MAX_SAFE_MAGNITUDE && size.height <= MAX_SAFE_MAGNITUDE;
56
+ return Number.isFinite(size.width) && Number.isFinite(size.height) && size.width >= Number.EPSILON && size.height >= Number.EPSILON && size.width <= MAX_SAFE_MAGNITUDE && size.height <= MAX_SAFE_MAGNITUDE;
45
57
  }
58
+ /**
59
+ * Returns a copy of `rect` with every numeric field replaced by a safe
60
+ * value via {@link safeBoundedNumber}. Returns the same reference when no
61
+ * field needed substitution so callers can keep their reference-equality
62
+ * short-circuits intact for clean inputs.
63
+ *
64
+ * @param rect The rect to sanitize.
65
+ * @return A rect with all numeric fields finite.
66
+ */
46
67
  function sanitizeRect(rect) {
47
- const x = safeBoundedNumber(rect.x, 0);
48
- const y = safeBoundedNumber(rect.y, 0);
49
- const width = safeBoundedNumber(rect.width, 0);
50
- const height = safeBoundedNumber(rect.height, 0);
51
- if (x === rect.x && y === rect.y && width === rect.width && height === rect.height) {
52
- return rect;
53
- }
54
- return { x, y, width, height };
68
+ const x = safeBoundedNumber(rect.x, 0);
69
+ const y = safeBoundedNumber(rect.y, 0);
70
+ const width = safeBoundedNumber(rect.width, 0);
71
+ const height = safeBoundedNumber(rect.height, 0);
72
+ if (x === rect.x && y === rect.y && width === rect.width && height === rect.height) return rect;
73
+ return {
74
+ x,
75
+ y,
76
+ width,
77
+ height
78
+ };
55
79
  }
80
+ /**
81
+ * Returns a copy of `state` with the cropper-math numeric fields replaced
82
+ * by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base
83
+ * pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /
84
+ * naturalHeight) are intentionally NOT sanitized — image dimensions reach
85
+ * the math layer as a separate `imageSize` argument, and cloning the
86
+ * image object here would break the reducer's reference-equality
87
+ * short-circuit.
88
+ *
89
+ * Returns the same `state` reference when no field needed substitution
90
+ * so callers in hot paths (every pointermove via `restrictPanZoom`) can
91
+ * keep their reference-equality optimizations. Sub-object references
92
+ * (`pan`, `basePan`, `cropRect`) are also preserved when their fields
93
+ * are individually clean.
94
+ *
95
+ * @param state The cropper state to sanitize.
96
+ * @return A cropper state with the math-relevant numeric fields finite.
97
+ */
56
98
  function sanitizeCropperState(state) {
57
- const panX = safeBoundedNumber(state.pan.x, 0);
58
- const panY = safeBoundedNumber(state.pan.y, 0);
59
- const basePanX = safeBoundedNumber(state.basePan.x, 0);
60
- const basePanY = safeBoundedNumber(state.basePan.y, 0);
61
- const rotation = safeBoundedNumber(state.rotation, 0);
62
- const baseRotation = safeBoundedNumber(state.baseRotation, 0);
63
- const rawZoom = safeBoundedNumber(state.zoom, 1);
64
- const zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;
65
- const rawBaseZoom = safeBoundedNumber(state.baseZoom, 1);
66
- const baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;
67
- const cropRect = sanitizeRect(state.cropRect);
68
- const panUnchanged = panX === state.pan.x && panY === state.pan.y;
69
- const basePanUnchanged = basePanX === state.basePan.x && basePanY === state.basePan.y;
70
- if (panUnchanged && basePanUnchanged && zoom === state.zoom && baseZoom === state.baseZoom && rotation === state.rotation && baseRotation === state.baseRotation && cropRect === state.cropRect) {
71
- return state;
72
- }
73
- return {
74
- ...state,
75
- pan: panUnchanged ? state.pan : { x: panX, y: panY },
76
- zoom,
77
- rotation,
78
- basePan: basePanUnchanged ? state.basePan : { x: basePanX, y: basePanY },
79
- baseZoom,
80
- baseRotation,
81
- cropRect
82
- };
99
+ const panX = safeBoundedNumber(state.pan.x, 0);
100
+ const panY = safeBoundedNumber(state.pan.y, 0);
101
+ const basePanX = safeBoundedNumber(state.basePan.x, 0);
102
+ const basePanY = safeBoundedNumber(state.basePan.y, 0);
103
+ const rotation = safeBoundedNumber(state.rotation, 0);
104
+ const baseRotation = safeBoundedNumber(state.baseRotation, 0);
105
+ const rawZoom = safeBoundedNumber(state.zoom, 1);
106
+ const zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;
107
+ const rawBaseZoom = safeBoundedNumber(state.baseZoom, 1);
108
+ const baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;
109
+ const cropRect = sanitizeRect(state.cropRect);
110
+ const panUnchanged = panX === state.pan.x && panY === state.pan.y;
111
+ const basePanUnchanged = basePanX === state.basePan.x && basePanY === state.basePan.y;
112
+ if (panUnchanged && basePanUnchanged && zoom === state.zoom && baseZoom === state.baseZoom && rotation === state.rotation && baseRotation === state.baseRotation && cropRect === state.cropRect) return state;
113
+ return {
114
+ ...state,
115
+ pan: panUnchanged ? state.pan : {
116
+ x: panX,
117
+ y: panY
118
+ },
119
+ zoom,
120
+ rotation,
121
+ basePan: basePanUnchanged ? state.basePan : {
122
+ x: basePanX,
123
+ y: basePanY
124
+ },
125
+ baseZoom,
126
+ baseRotation,
127
+ cropRect
128
+ };
83
129
  }
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- isSafeNumber,
87
- isValidSize,
88
- safeBoundedNumber,
89
- sanitizeCropperState,
90
- sanitizeRect
91
- });
92
- //# sourceMappingURL=sanitize.cjs.map
130
+ exports.isSafeNumber = isSafeNumber;
131
+ exports.isValidSize = isValidSize;
132
+ exports.safeBoundedNumber = safeBoundedNumber;
133
+ exports.sanitizeCropperState = sanitizeCropperState;
134
+ exports.sanitizeRect = sanitizeRect;
135
+
136
+ //# sourceMappingURL=sanitize.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/image-editor/core/math/sanitize.ts"],
4
- "sourcesContent": ["import type { CropperState, NormalizedRect, Size } from '../types';\n\n/**\n * Magnitude beyond which any cropper-math input is treated as corrupt.\n * Picks a value well above any realistic image/rotation/zoom/pan but far\n * below `Number.MAX_VALUE`, so multiplications inside trig and matrix code\n * can't overflow to `Infinity`.\n */\nconst MAX_SAFE_MAGNITUDE = 1e6;\n\n/**\n * Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`\n * because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow\n * downstream trig/matrix math even though the spec reports them as finite.\n *\n * Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this\n * function — they don't overflow on their own. Protection against divisions\n * by sub-normal values lives in `sanitizeCropperState`'s zoom guard.\n *\n * @param value The candidate value.\n * @param fallback The replacement to return when `value` is unsafe.\n * @return Either `value` or `fallback`.\n */\nexport function safeBoundedNumber( value: number, fallback: number ): number {\n\tif ( ! Number.isFinite( value ) ) {\n\t\treturn fallback;\n\t}\n\tif ( Math.abs( value ) > MAX_SAFE_MAGNITUDE ) {\n\t\treturn fallback;\n\t}\n\treturn value;\n}\n\n/**\n * Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}\n * for callers that need to short-circuit rather than substitute a fallback.\n *\n * @param value The candidate value.\n * @return Whether `value` is safe to use in math.\n */\nexport function isSafeNumber( value: number ): boolean {\n\treturn Number.isFinite( value ) && Math.abs( value ) <= MAX_SAFE_MAGNITUDE;\n}\n\n/**\n * Returns `true` when both dimensions are finite and within the safe\n * range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters\n * because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but\n * make `container / dim` overflow to `Infinity` downstream in\n * `getImageFit` / `createCamera`. Use this to short-circuit math that\n * would otherwise produce non-finite output.\n *\n * @param size The size to check.\n * @return Whether `size` is safe to use in math.\n */\nexport function isValidSize( size: Size ): boolean {\n\treturn (\n\t\tNumber.isFinite( size.width ) &&\n\t\tNumber.isFinite( size.height ) &&\n\t\tsize.width >= Number.EPSILON &&\n\t\tsize.height >= Number.EPSILON &&\n\t\tsize.width <= MAX_SAFE_MAGNITUDE &&\n\t\tsize.height <= MAX_SAFE_MAGNITUDE\n\t);\n}\n\n/**\n * Returns a copy of `rect` with every numeric field replaced by a safe\n * value via {@link safeBoundedNumber}. Returns the same reference when no\n * field needed substitution so callers can keep their reference-equality\n * short-circuits intact for clean inputs.\n *\n * @param rect The rect to sanitize.\n * @return A rect with all numeric fields finite.\n */\nexport function sanitizeRect( rect: NormalizedRect ): NormalizedRect {\n\tconst x = safeBoundedNumber( rect.x, 0 );\n\tconst y = safeBoundedNumber( rect.y, 0 );\n\tconst width = safeBoundedNumber( rect.width, 0 );\n\tconst height = safeBoundedNumber( rect.height, 0 );\n\tif (\n\t\tx === rect.x &&\n\t\ty === rect.y &&\n\t\twidth === rect.width &&\n\t\theight === rect.height\n\t) {\n\t\treturn rect;\n\t}\n\treturn { x, y, width, height };\n}\n\n/**\n * Returns a copy of `state` with the cropper-math numeric fields replaced\n * by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base\n * pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /\n * naturalHeight) are intentionally NOT sanitized — image dimensions reach\n * the math layer as a separate `imageSize` argument, and cloning the\n * image object here would break the reducer's reference-equality\n * short-circuit.\n *\n * Returns the same `state` reference when no field needed substitution\n * so callers in hot paths (every pointermove via `restrictPanZoom`) can\n * keep their reference-equality optimizations. Sub-object references\n * (`pan`, `basePan`, `cropRect`) are also preserved when their fields\n * are individually clean.\n *\n * @param state The cropper state to sanitize.\n * @return A cropper state with the math-relevant numeric fields finite.\n */\nexport function sanitizeCropperState( state: CropperState ): CropperState {\n\tconst panX = safeBoundedNumber( state.pan.x, 0 );\n\tconst panY = safeBoundedNumber( state.pan.y, 0 );\n\tconst basePanX = safeBoundedNumber( state.basePan.x, 0 );\n\tconst basePanY = safeBoundedNumber( state.basePan.y, 0 );\n\tconst rotation = safeBoundedNumber( state.rotation, 0 );\n\tconst baseRotation = safeBoundedNumber( state.baseRotation, 0 );\n\tconst rawZoom = safeBoundedNumber( state.zoom, 1 );\n\t// Zoom must be strictly positive AND large enough that 1/zoom doesn't\n\t// overflow. Sub-normals (e.g. Number.MIN_VALUE) pass `> 0` but make\n\t// division explode, so guard against them with Number.EPSILON.\n\tconst zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;\n\tconst rawBaseZoom = safeBoundedNumber( state.baseZoom, 1 );\n\tconst baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;\n\tconst cropRect = sanitizeRect( state.cropRect );\n\n\tconst panUnchanged = panX === state.pan.x && panY === state.pan.y;\n\tconst basePanUnchanged =\n\t\tbasePanX === state.basePan.x && basePanY === state.basePan.y;\n\n\tif (\n\t\tpanUnchanged &&\n\t\tbasePanUnchanged &&\n\t\tzoom === state.zoom &&\n\t\tbaseZoom === state.baseZoom &&\n\t\trotation === state.rotation &&\n\t\tbaseRotation === state.baseRotation &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn {\n\t\t...state,\n\t\tpan: panUnchanged ? state.pan : { x: panX, y: panY },\n\t\tzoom,\n\t\trotation,\n\t\tbasePan: basePanUnchanged\n\t\t\t? state.basePan\n\t\t\t: { x: basePanX, y: basePanY },\n\t\tbaseZoom,\n\t\tbaseRotation,\n\t\tcropRect,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,IAAM,qBAAqB;AAgBpB,SAAS,kBAAmB,OAAe,UAA2B;AAC5E,MAAK,CAAE,OAAO,SAAU,KAAM,GAAI;AACjC,WAAO;AAAA,EACR;AACA,MAAK,KAAK,IAAK,KAAM,IAAI,oBAAqB;AAC7C,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAUO,SAAS,aAAc,OAAyB;AACtD,SAAO,OAAO,SAAU,KAAM,KAAK,KAAK,IAAK,KAAM,KAAK;AACzD;AAaO,SAAS,YAAa,MAAsB;AAClD,SACC,OAAO,SAAU,KAAK,KAAM,KAC5B,OAAO,SAAU,KAAK,MAAO,KAC7B,KAAK,SAAS,OAAO,WACrB,KAAK,UAAU,OAAO,WACtB,KAAK,SAAS,sBACd,KAAK,UAAU;AAEjB;AAWO,SAAS,aAAc,MAAuC;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D;AAAA,IACA;AAAA,IACA,SAAS,mBACN,MAAM,UACN,EAAE,GAAG,UAAU,GAAG,SAAS;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"sanitize.cjs","names":[],"sources":["../../../../src/image-editor/core/math/sanitize.ts"],"sourcesContent":["import type { CropperState, NormalizedRect, Size } from '../types';\n\n/**\n * Magnitude beyond which any cropper-math input is treated as corrupt.\n * Picks a value well above any realistic image/rotation/zoom/pan but far\n * below `Number.MAX_VALUE`, so multiplications inside trig and matrix code\n * can't overflow to `Infinity`.\n */\nconst MAX_SAFE_MAGNITUDE = 1e6;\n\n/**\n * Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`\n * because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow\n * downstream trig/matrix math even though the spec reports them as finite.\n *\n * Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this\n * function — they don't overflow on their own. Protection against divisions\n * by sub-normal values lives in `sanitizeCropperState`'s zoom guard.\n *\n * @param value The candidate value.\n * @param fallback The replacement to return when `value` is unsafe.\n * @return Either `value` or `fallback`.\n */\nexport function safeBoundedNumber( value: number, fallback: number ): number {\n\tif ( ! Number.isFinite( value ) ) {\n\t\treturn fallback;\n\t}\n\tif ( Math.abs( value ) > MAX_SAFE_MAGNITUDE ) {\n\t\treturn fallback;\n\t}\n\treturn value;\n}\n\n/**\n * Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}\n * for callers that need to short-circuit rather than substitute a fallback.\n *\n * @param value The candidate value.\n * @return Whether `value` is safe to use in math.\n */\nexport function isSafeNumber( value: number ): boolean {\n\treturn Number.isFinite( value ) && Math.abs( value ) <= MAX_SAFE_MAGNITUDE;\n}\n\n/**\n * Returns `true` when both dimensions are finite and within the safe\n * range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters\n * because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but\n * make `container / dim` overflow to `Infinity` downstream in\n * `getImageFit` / `createCamera`. Use this to short-circuit math that\n * would otherwise produce non-finite output.\n *\n * @param size The size to check.\n * @return Whether `size` is safe to use in math.\n */\nexport function isValidSize( size: Size ): boolean {\n\treturn (\n\t\tNumber.isFinite( size.width ) &&\n\t\tNumber.isFinite( size.height ) &&\n\t\tsize.width >= Number.EPSILON &&\n\t\tsize.height >= Number.EPSILON &&\n\t\tsize.width <= MAX_SAFE_MAGNITUDE &&\n\t\tsize.height <= MAX_SAFE_MAGNITUDE\n\t);\n}\n\n/**\n * Returns a copy of `rect` with every numeric field replaced by a safe\n * value via {@link safeBoundedNumber}. Returns the same reference when no\n * field needed substitution so callers can keep their reference-equality\n * short-circuits intact for clean inputs.\n *\n * @param rect The rect to sanitize.\n * @return A rect with all numeric fields finite.\n */\nexport function sanitizeRect( rect: NormalizedRect ): NormalizedRect {\n\tconst x = safeBoundedNumber( rect.x, 0 );\n\tconst y = safeBoundedNumber( rect.y, 0 );\n\tconst width = safeBoundedNumber( rect.width, 0 );\n\tconst height = safeBoundedNumber( rect.height, 0 );\n\tif (\n\t\tx === rect.x &&\n\t\ty === rect.y &&\n\t\twidth === rect.width &&\n\t\theight === rect.height\n\t) {\n\t\treturn rect;\n\t}\n\treturn { x, y, width, height };\n}\n\n/**\n * Returns a copy of `state` with the cropper-math numeric fields replaced\n * by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base\n * pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /\n * naturalHeight) are intentionally NOT sanitized — image dimensions reach\n * the math layer as a separate `imageSize` argument, and cloning the\n * image object here would break the reducer's reference-equality\n * short-circuit.\n *\n * Returns the same `state` reference when no field needed substitution\n * so callers in hot paths (every pointermove via `restrictPanZoom`) can\n * keep their reference-equality optimizations. Sub-object references\n * (`pan`, `basePan`, `cropRect`) are also preserved when their fields\n * are individually clean.\n *\n * @param state The cropper state to sanitize.\n * @return A cropper state with the math-relevant numeric fields finite.\n */\nexport function sanitizeCropperState( state: CropperState ): CropperState {\n\tconst panX = safeBoundedNumber( state.pan.x, 0 );\n\tconst panY = safeBoundedNumber( state.pan.y, 0 );\n\tconst basePanX = safeBoundedNumber( state.basePan.x, 0 );\n\tconst basePanY = safeBoundedNumber( state.basePan.y, 0 );\n\tconst rotation = safeBoundedNumber( state.rotation, 0 );\n\tconst baseRotation = safeBoundedNumber( state.baseRotation, 0 );\n\tconst rawZoom = safeBoundedNumber( state.zoom, 1 );\n\t// Zoom must be strictly positive AND large enough that 1/zoom doesn't\n\t// overflow. Sub-normals (e.g. Number.MIN_VALUE) pass `> 0` but make\n\t// division explode, so guard against them with Number.EPSILON.\n\tconst zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;\n\tconst rawBaseZoom = safeBoundedNumber( state.baseZoom, 1 );\n\tconst baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;\n\tconst cropRect = sanitizeRect( state.cropRect );\n\n\tconst panUnchanged = panX === state.pan.x && panY === state.pan.y;\n\tconst basePanUnchanged =\n\t\tbasePanX === state.basePan.x && basePanY === state.basePan.y;\n\n\tif (\n\t\tpanUnchanged &&\n\t\tbasePanUnchanged &&\n\t\tzoom === state.zoom &&\n\t\tbaseZoom === state.baseZoom &&\n\t\trotation === state.rotation &&\n\t\tbaseRotation === state.baseRotation &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn {\n\t\t...state,\n\t\tpan: panUnchanged ? state.pan : { x: panX, y: panY },\n\t\tzoom,\n\t\trotation,\n\t\tbasePan: basePanUnchanged\n\t\t\t? state.basePan\n\t\t\t: { x: basePanX, y: basePanY },\n\t\tbaseZoom,\n\t\tbaseRotation,\n\t\tcropRect,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAQA,MAAM,qBAA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