@wordpress/media-editor 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -1,586 +0,0 @@
1
- import { DEFAULT_KEYBOARD_STEP, DEFAULT_WHEEL_ZOOM_SPEED, KEYBOARD_SHIFT_STEP_MULTIPLIER, MAX_ZOOM, MIN_ZOOM } from "./constants.mjs";
2
- import { restrictPanZoom } from "./containment.mjs";
3
- // packages/media-editor/src/image-editor/core/interaction-controller.ts
4
- /** Time window for detecting a double-tap gesture (ms). */
5
- const DOUBLE_TAP_TIME = 300;
6
- /** Max distance between taps to count as a double-tap (px). */
7
- const DOUBLE_TAP_DISTANCE = 30;
8
- /** Duration of the zoom animation state (ms). */
9
- const ZOOM_ANIMATION_DURATION = 200;
10
- /**
11
- * Get the natural image dimensions from cropper state, falling back to 1x1.
12
- *
13
- * @param state The current cropper state.
14
- * @return The image dimensions.
15
- */
16
- function getImageSizeFromState(state) {
17
- return state.image ? {
18
- width: state.image.naturalWidth,
19
- height: state.image.naturalHeight
20
- } : {
21
- width: 1,
22
- height: 1
23
- };
24
- }
25
- /**
26
- * Get the distance between two touch points.
27
- *
28
- * @param t1 The first touch.
29
- * @param t2 The second touch.
30
- * @return The pixel distance between the two touches.
31
- */
32
- function getTouchDistance(t1, t2) {
33
- const dx = t1.clientX - t2.clientX;
34
- const dy = t1.clientY - t2.clientY;
35
- return Math.sqrt(dx * dx + dy * dy);
36
- }
37
- /**
38
- * Framework-agnostic imperative controller for image cropper interactions.
39
- *
40
- * Handles mouse, touch, and keyboard event processing for pan, zoom,
41
- * and crop manipulation. Uses requestAnimationFrame for drag/pinch
42
- * updates to avoid layout thrashing.
43
- *
44
- * The controller does not register DOM event listeners itself — that is the
45
- * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).
46
- * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,
47
- * and `handleKeyDown` methods that the UI layer calls with native DOM events.
48
- *
49
- * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)
50
- * are read lazily from `this.options` on each interaction, so the UI layer
51
- * can update them without recreating the controller.
52
- *
53
- * Call `destroy()` to clean up timers and pending animation frames.
54
- */
55
- var InteractionController = class {
56
- options;
57
- /** Current drag/zoom status. */
58
- isDragging = false;
59
- isZooming = false;
60
- /** Active drag state during pointer interactions. */
61
- drag = null;
62
- /** Active touch state during touch interactions. */
63
- touch = null;
64
- /** Cleanup function for active touch listeners on document. */
65
- touchCleanup = null;
66
- /**
67
- * Cleanup function for active pointer-drag listeners on the
68
- * captured element. Set while a pointer drag is in progress so
69
- * `destroy()` can tear the drag down cleanly if the consumer
70
- * unmounts mid-drag. Cleared on pointerup/lostpointercapture.
71
- */
72
- pointerCleanup = null;
73
- /** Last tap info for double-tap detection. */
74
- lastTap = null;
75
- /** Timer for the zoom animation state (double-tap). */
76
- zoomTimer;
77
- /** Timer for wheel gesture debounce. */
78
- wheelGestureTimer;
79
- /** Whether a wheel gesture is currently active. */
80
- wheelGestureActive = false;
81
- /** Current requestAnimationFrame ID. */
82
- rafId = 0;
83
- constructor(options) {
84
- this.options = options;
85
- }
86
- /** Read minZoom lazily so option changes take effect immediately. */
87
- get minZoom() {
88
- return this.options.minZoom ?? MIN_ZOOM;
89
- }
90
- /** Read maxZoom lazily so option changes take effect immediately. */
91
- get maxZoom() {
92
- return this.options.maxZoom ?? MAX_ZOOM;
93
- }
94
- /** Read zoomSpeed lazily so option changes take effect immediately. */
95
- get zoomSpeed() {
96
- return this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;
97
- }
98
- /** Read keyboardStep lazily so option changes take effect immediately. */
99
- get keyboardStep() {
100
- return this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;
101
- }
102
- /**
103
- * Get the keyboard pan step, including modifier-based coarse movement.
104
- *
105
- * @param event The native KeyboardEvent.
106
- * @return The normalized pan step.
107
- */
108
- getKeyboardStep(event) {
109
- return event.shiftKey ? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER : this.keyboardStep;
110
- }
111
- /** Read doubleTapZoom lazily so option changes take effect immediately. */
112
- get doubleTapZoom() {
113
- return this.options.doubleTapZoom ?? 2;
114
- }
115
- /**
116
- * Update the drag/zoom status and notify via callback if changed.
117
- *
118
- * @param update Partial status with isDragging and/or isZooming.
119
- */
120
- setStatus(update) {
121
- let changed = false;
122
- if (update.isDragging !== void 0 && update.isDragging !== this.isDragging) {
123
- this.isDragging = update.isDragging;
124
- changed = true;
125
- }
126
- if (update.isZooming !== void 0 && update.isZooming !== this.isZooming) {
127
- this.isZooming = update.isZooming;
128
- changed = true;
129
- }
130
- if (changed) this.options.onStatusChange?.({
131
- isDragging: this.isDragging,
132
- isZooming: this.isZooming
133
- });
134
- }
135
- /**
136
- * Handle a pointer-down event on the container element.
137
- *
138
- * Initiates a drag (pan) interaction. Captures the pointer on the
139
- * provided element and registers pointermove/pointerup/lostpointercapture
140
- * listeners for the duration of the drag.
141
- *
142
- * @param e The native PointerEvent.
143
- * @param el The DOM element to capture the pointer on.
144
- */
145
- handlePointerDown(e, el) {
146
- if (e.button !== 0) return;
147
- if (e.pointerType === "touch") return;
148
- e.preventDefault();
149
- const ownerDoc = el.ownerDocument;
150
- if (ownerDoc?.activeElement instanceof HTMLElement && ownerDoc.activeElement !== el) ownerDoc.activeElement.blur();
151
- el.focus();
152
- el.setPointerCapture(e.pointerId);
153
- if (this.wheelGestureActive) {
154
- clearTimeout(this.wheelGestureTimer);
155
- this.wheelGestureActive = false;
156
- this.options.onGestureEnd?.();
157
- }
158
- this.setStatus({ isDragging: true });
159
- this.options.onGestureStart?.();
160
- const currentState = this.options.getState();
161
- this.drag = {
162
- startX: e.clientX,
163
- startY: e.clientY,
164
- startPanX: currentState.pan.x,
165
- startPanY: currentState.pan.y
166
- };
167
- const onPointerMove = (moveEvent) => {
168
- const drag = this.drag;
169
- if (!drag) return;
170
- const pe = moveEvent;
171
- cancelAnimationFrame(this.rafId);
172
- this.rafId = requestAnimationFrame(() => {
173
- const s = this.options.getState();
174
- const imgSize = this.options.getImageSize();
175
- const containerSize = this.options.getContainerSize();
176
- const panSize = imgSize ?? containerSize;
177
- const deltaX = panSize.width > 0 ? (pe.clientX - drag.startX) / panSize.width : 0;
178
- const deltaY = panSize.height > 0 ? (pe.clientY - drag.startY) / panSize.height : 0;
179
- const { pan: newCrop } = restrictPanZoom({
180
- ...s,
181
- pan: {
182
- x: drag.startPanX + deltaX,
183
- y: drag.startPanY + deltaY
184
- }
185
- }, getImageSizeFromState(s), s.cropRect);
186
- this.options.actions.setPan(newCrop);
187
- });
188
- };
189
- const removeListeners = () => {
190
- el.removeEventListener("pointermove", onPointerMove);
191
- el.removeEventListener("pointerup", onPointerUp);
192
- el.removeEventListener("lostpointercapture", onPointerUp);
193
- };
194
- const onPointerUp = () => {
195
- this.setStatus({ isDragging: false });
196
- this.options.onGestureEnd?.();
197
- this.drag = null;
198
- cancelAnimationFrame(this.rafId);
199
- removeListeners();
200
- this.pointerCleanup = null;
201
- };
202
- el.addEventListener("pointermove", onPointerMove);
203
- el.addEventListener("pointerup", onPointerUp);
204
- el.addEventListener("lostpointercapture", onPointerUp);
205
- this.pointerCleanup = removeListeners;
206
- }
207
- /**
208
- * Handle a wheel event on the container element.
209
- *
210
- * Implements focal-point zoom: the point under the cursor stays
211
- * stationary on screen while the zoom level changes.
212
- *
213
- * Must be registered with `{ passive: false }` to allow preventDefault.
214
- *
215
- * @param e The native WheelEvent.
216
- */
217
- handleWheel(e) {
218
- e.preventDefault();
219
- if (this.drag) return;
220
- if (!this.wheelGestureActive) {
221
- this.wheelGestureActive = true;
222
- this.options.onGestureStart?.();
223
- }
224
- clearTimeout(this.wheelGestureTimer);
225
- this.wheelGestureTimer = setTimeout(() => {
226
- this.wheelGestureActive = false;
227
- this.options.onGestureEnd?.();
228
- }, DOUBLE_TAP_TIME);
229
- const s = this.options.getState();
230
- const delta = -e.deltaY * this.zoomSpeed;
231
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, s.zoom + delta));
232
- if (newZoom === s.zoom) return;
233
- const containerSize = this.options.getContainerSize();
234
- const visSize = this.options.getImageSize() ?? containerSize;
235
- const target = e.currentTarget;
236
- const rect = target instanceof Element ? target.getBoundingClientRect() : void 0;
237
- if (visSize.width > 0 && visSize.height > 0 && rect) {
238
- const fx = e.clientX - rect.left - containerSize.width / 2;
239
- const fy = e.clientY - rect.top - containerSize.height / 2;
240
- const zoomRatio = 1 - newZoom / s.zoom;
241
- const focalNormX = fx / visSize.width;
242
- const focalNormY = fy / visSize.height;
243
- const newCropX = s.pan.x + (focalNormX - s.pan.x) * zoomRatio;
244
- const newCropY = s.pan.y + (focalNormY - s.pan.y) * zoomRatio;
245
- const { pan: clampedCrop } = restrictPanZoom({
246
- ...s,
247
- zoom: newZoom,
248
- pan: {
249
- x: newCropX,
250
- y: newCropY
251
- }
252
- }, getImageSizeFromState(s), s.cropRect);
253
- this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
254
- } else this.options.actions.setZoom(newZoom);
255
- }
256
- /**
257
- * Handle a touch-start event on the container element.
258
- *
259
- * Supports single-finger pan, two-finger pinch zoom, and
260
- * double-tap to toggle between fit and 2x zoom. Registers
261
- * touchmove/touchend/touchcancel on the provided document for the
262
- * duration of the gesture.
263
- *
264
- * @param e The native TouchEvent.
265
- * @param containerRect The bounding rect of the container element.
266
- * @param doc The document to register move/end listeners on.
267
- * Defaults to globalThis.document. Pass the iframe's
268
- * contentDocument when running inside an iframe.
269
- */
270
- handleTouchStart(e, containerRect, doc = document) {
271
- if (this.touch && e.touches.length === 2) {
272
- const s = this.options.getState();
273
- const distance = getTouchDistance(e.touches[0], e.touches[1]);
274
- const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
275
- const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
276
- this.touch.didPinch = true;
277
- this.touch.startDistance = distance;
278
- this.touch.startZoom = s.zoom;
279
- this.touch.startPanX = s.pan.x;
280
- this.touch.startPanY = s.pan.y;
281
- this.touch.startMidX = midX;
282
- this.touch.startMidY = midY;
283
- this.touch.containerRect = containerRect;
284
- this.setStatus({ isDragging: false });
285
- return;
286
- }
287
- if (e.touches.length === 1) {
288
- const tapX = e.touches[0].clientX;
289
- const tapY = e.touches[0].clientY;
290
- if (this.tryDoubleTap(e, tapX, tapY, containerRect)) return;
291
- const currentState = this.options.getState();
292
- this.touch = {
293
- startDistance: 0,
294
- startZoom: currentState.zoom,
295
- lastTouchX: e.touches[0].clientX,
296
- lastTouchY: e.touches[0].clientY,
297
- startPanX: currentState.pan.x,
298
- startPanY: currentState.pan.y,
299
- containerRect,
300
- startMidX: 0,
301
- startMidY: 0,
302
- didPinch: false,
303
- moved: false
304
- };
305
- this.options.onGestureStart?.();
306
- } else if (e.touches.length === 2) {
307
- const currentState = this.options.getState();
308
- const distance = getTouchDistance(e.touches[0], e.touches[1]);
309
- const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
310
- const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
311
- this.touch = {
312
- startDistance: distance,
313
- startZoom: currentState.zoom,
314
- lastTouchX: 0,
315
- lastTouchY: 0,
316
- startPanX: currentState.pan.x,
317
- startPanY: currentState.pan.y,
318
- containerRect,
319
- startMidX: midX,
320
- startMidY: midY,
321
- didPinch: true,
322
- moved: false
323
- };
324
- this.options.onGestureStart?.();
325
- }
326
- const onTouchEnd = () => {
327
- this.touch = null;
328
- this.touchCleanup = null;
329
- cancelAnimationFrame(this.rafId);
330
- doc.removeEventListener("touchmove", this.handleTouchMove);
331
- doc.removeEventListener("touchend", onTouchEnd);
332
- doc.removeEventListener("touchcancel", onTouchEnd);
333
- this.setStatus({ isDragging: false });
334
- this.options.onGestureEnd?.();
335
- };
336
- this.touchCleanup?.();
337
- doc.addEventListener("touchmove", this.handleTouchMove, { passive: false });
338
- doc.addEventListener("touchend", onTouchEnd);
339
- doc.addEventListener("touchcancel", onTouchEnd);
340
- this.touchCleanup = onTouchEnd;
341
- }
342
- handleTouchMove = (moveEvent) => {
343
- const touch = this.touch;
344
- if (!touch) return;
345
- moveEvent.preventDefault();
346
- cancelAnimationFrame(this.rafId);
347
- this.rafId = requestAnimationFrame(() => {
348
- const s = this.options.getState();
349
- if (moveEvent.touches.length === 2) {
350
- if (!touch.didPinch) {
351
- touch.didPinch = true;
352
- touch.startDistance = getTouchDistance(moveEvent.touches[0], moveEvent.touches[1]);
353
- touch.startZoom = s.zoom;
354
- touch.startPanX = s.pan.x;
355
- touch.startPanY = s.pan.y;
356
- touch.startMidX = (moveEvent.touches[0].clientX + moveEvent.touches[1].clientX) / 2;
357
- touch.startMidY = (moveEvent.touches[0].clientY + moveEvent.touches[1].clientY) / 2;
358
- this.setStatus({ isDragging: false });
359
- return;
360
- }
361
- const latestContainerSize = this.options.getContainerSize();
362
- const latestImageSize = this.options.getImageSize();
363
- const t0 = moveEvent.touches[0];
364
- const t1 = moveEvent.touches[1];
365
- const ratio = getTouchDistance(t0, t1) / touch.startDistance;
366
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, touch.startZoom * ratio));
367
- const visSize = latestImageSize ?? latestContainerSize;
368
- const rect = touch.containerRect;
369
- if (visSize.width > 0 && visSize.height > 0 && rect) {
370
- const mx = (t0.clientX + t1.clientX) / 2 - rect.left - latestContainerSize.width / 2;
371
- const my = (t0.clientY + t1.clientY) / 2 - rect.top - latestContainerSize.height / 2;
372
- const startMx = touch.startMidX - rect.left - latestContainerSize.width / 2;
373
- const startMy = touch.startMidY - rect.top - latestContainerSize.height / 2;
374
- const panDx = visSize.width > 0 ? (mx - startMx) / visSize.width : 0;
375
- const panDy = visSize.height > 0 ? (my - startMy) / visSize.height : 0;
376
- const zoomRatio = touch.startZoom !== 0 ? 1 - newZoom / touch.startZoom : 0;
377
- const startFocalNormX = startMx / visSize.width;
378
- const startFocalNormY = startMy / visSize.height;
379
- const newCropX = touch.startPanX + panDx + (startFocalNormX - touch.startPanX) * zoomRatio;
380
- const newCropY = touch.startPanY + panDy + (startFocalNormY - touch.startPanY) * zoomRatio;
381
- const { pan: clampedCrop } = restrictPanZoom({
382
- ...s,
383
- zoom: newZoom,
384
- pan: {
385
- x: newCropX,
386
- y: newCropY
387
- }
388
- }, getImageSizeFromState(s), s.cropRect);
389
- this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
390
- } else if (newZoom !== s.zoom) this.options.actions.setZoom(newZoom);
391
- } else if (moveEvent.touches.length === 1 && !touch.didPinch) {
392
- if (!touch.moved) {
393
- touch.moved = true;
394
- this.setStatus({ isDragging: true });
395
- }
396
- const panImageSize = this.options.getImageSize();
397
- const panContainerSize = this.options.getContainerSize();
398
- const panSize = panImageSize ?? panContainerSize;
399
- const deltaX = panSize.width > 0 ? (moveEvent.touches[0].clientX - touch.lastTouchX) / panSize.width : 0;
400
- const deltaY = panSize.height > 0 ? (moveEvent.touches[0].clientY - touch.lastTouchY) / panSize.height : 0;
401
- const { pan: newCrop } = restrictPanZoom({
402
- ...s,
403
- pan: {
404
- x: touch.startPanX + deltaX,
405
- y: touch.startPanY + deltaY
406
- }
407
- }, getImageSizeFromState(s), s.cropRect);
408
- this.options.actions.setPan(newCrop);
409
- }
410
- });
411
- };
412
- tryDoubleTap(e, tapX, tapY, containerRect) {
413
- const now = Date.now();
414
- const lastTap = this.lastTap;
415
- if (!lastTap) {
416
- this.lastTap = {
417
- time: now,
418
- x: tapX,
419
- y: tapY
420
- };
421
- return false;
422
- }
423
- const timeDelta = now - lastTap.time;
424
- const distDelta = Math.sqrt((tapX - lastTap.x) ** 2 + (tapY - lastTap.y) ** 2);
425
- if (!(timeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE)) {
426
- this.lastTap = {
427
- time: now,
428
- x: tapX,
429
- y: tapY
430
- };
431
- return false;
432
- }
433
- e.preventDefault();
434
- this.lastTap = null;
435
- const currentState = this.options.getState();
436
- const containerSize = this.options.getContainerSize();
437
- const imgSize = this.options.getImageSize();
438
- const targetZoom = currentState.zoom > (this.minZoom + this.doubleTapZoom) / 2 ? this.minZoom : this.doubleTapZoom;
439
- const visSize = imgSize ?? containerSize;
440
- this.setStatus({ isZooming: true });
441
- clearTimeout(this.zoomTimer);
442
- this.zoomTimer = setTimeout(() => {
443
- this.setStatus({ isZooming: false });
444
- }, ZOOM_ANIMATION_DURATION);
445
- this.options.onGestureStart?.();
446
- if (visSize.width > 0 && visSize.height > 0) {
447
- const fx = tapX - containerRect.left - containerSize.width / 2;
448
- const fy = tapY - containerRect.top - containerSize.height / 2;
449
- const zoomRatio = 1 - targetZoom / currentState.zoom;
450
- const focalNormX = fx / visSize.width;
451
- const focalNormY = fy / visSize.height;
452
- const newCropX = currentState.pan.x + (focalNormX - currentState.pan.x) * zoomRatio;
453
- const newCropY = currentState.pan.y + (focalNormY - currentState.pan.y) * zoomRatio;
454
- const { pan: clampedCrop } = restrictPanZoom({
455
- ...currentState,
456
- zoom: targetZoom,
457
- pan: {
458
- x: newCropX,
459
- y: newCropY
460
- }
461
- }, getImageSizeFromState(currentState), currentState.cropRect);
462
- this.options.actions.setZoomAtPoint(targetZoom, clampedCrop);
463
- } else this.options.actions.setZoom(targetZoom);
464
- this.options.onGestureEnd?.();
465
- return true;
466
- }
467
- /**
468
- * Handle a keydown event on the container element.
469
- *
470
- * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.
471
- *
472
- * @param e The native KeyboardEvent.
473
- */
474
- handleKeyDown(e) {
475
- const currentState = this.options.getState();
476
- switch (e.key) {
477
- case "ArrowUp": {
478
- e.preventDefault();
479
- const keyboardStep = this.getKeyboardStep(e);
480
- const { pan: newCrop } = restrictPanZoom({
481
- ...currentState,
482
- pan: {
483
- x: currentState.pan.x,
484
- y: currentState.pan.y + keyboardStep
485
- }
486
- }, getImageSizeFromState(currentState), currentState.cropRect);
487
- this.options.actions.setPan(newCrop);
488
- break;
489
- }
490
- case "ArrowDown": {
491
- e.preventDefault();
492
- const keyboardStep = this.getKeyboardStep(e);
493
- const { pan: newCrop } = restrictPanZoom({
494
- ...currentState,
495
- pan: {
496
- x: currentState.pan.x,
497
- y: currentState.pan.y - keyboardStep
498
- }
499
- }, getImageSizeFromState(currentState), currentState.cropRect);
500
- this.options.actions.setPan(newCrop);
501
- break;
502
- }
503
- case "ArrowLeft": {
504
- e.preventDefault();
505
- const keyboardStep = this.getKeyboardStep(e);
506
- const { pan: newCrop } = restrictPanZoom({
507
- ...currentState,
508
- pan: {
509
- x: currentState.pan.x + keyboardStep,
510
- y: currentState.pan.y
511
- }
512
- }, getImageSizeFromState(currentState), currentState.cropRect);
513
- this.options.actions.setPan(newCrop);
514
- break;
515
- }
516
- case "ArrowRight": {
517
- e.preventDefault();
518
- const keyboardStep = this.getKeyboardStep(e);
519
- const { pan: newCrop } = restrictPanZoom({
520
- ...currentState,
521
- pan: {
522
- x: currentState.pan.x - keyboardStep,
523
- y: currentState.pan.y
524
- }
525
- }, getImageSizeFromState(currentState), currentState.cropRect);
526
- this.options.actions.setPan(newCrop);
527
- break;
528
- }
529
- case "+":
530
- case "=": {
531
- e.preventDefault();
532
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, currentState.zoom + .5));
533
- this.options.actions.setZoom(newZoom);
534
- break;
535
- }
536
- case "-":
537
- case "_": {
538
- e.preventDefault();
539
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, currentState.zoom - .5));
540
- this.options.actions.setZoom(newZoom);
541
- break;
542
- }
543
- case "r":
544
- case "R":
545
- if (e.metaKey || e.ctrlKey || e.altKey) break;
546
- e.preventDefault();
547
- this.options.actions.snapRotate90(e.shiftKey ? -1 : 1);
548
- break;
549
- case "h":
550
- case "H":
551
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) break;
552
- e.preventDefault();
553
- this.options.actions.toggleFlip?.("horizontal");
554
- break;
555
- case "v":
556
- case "V":
557
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) break;
558
- e.preventDefault();
559
- this.options.actions.toggleFlip?.("vertical");
560
- }
561
- }
562
- /**
563
- * Clean up all timers, animation frames, and active touch listeners.
564
- *
565
- * Must be called when the controller is no longer needed (e.g., on
566
- * component unmount or element removal).
567
- */
568
- destroy() {
569
- cancelAnimationFrame(this.rafId);
570
- clearTimeout(this.zoomTimer);
571
- clearTimeout(this.wheelGestureTimer);
572
- this.touchCleanup?.();
573
- this.touchCleanup = null;
574
- this.pointerCleanup?.();
575
- this.pointerCleanup = null;
576
- this.drag = null;
577
- this.touch = null;
578
- this.lastTap = null;
579
- this.wheelGestureActive = false;
580
- this.isDragging = false;
581
- this.isZooming = false;
582
- }
583
- };
584
- export { InteractionController };
585
-
586
- //# sourceMappingURL=interaction-controller.mjs.map