@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,276 +1,289 @@
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/containment.ts
21
- var containment_exports = {};
22
- __export(containment_exports, {
23
- getImageCropBounds: () => getImageCropBounds,
24
- getMinZoom: () => getMinZoom,
25
- restrictCropRect: () => restrictCropRect,
26
- restrictPanZoom: () => restrictPanZoom
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
27
5
  });
28
- module.exports = __toCommonJS(containment_exports);
29
- var import_gl_matrix = require("gl-matrix");
30
- var import_constants = require("./constants.cjs");
31
- var import_rotation = require("./math/rotation.cjs");
32
- var import_sanitize = require("./math/sanitize.cjs");
33
- var import_camera = require("./camera.cjs");
34
- var EPSILON = 1e-9;
6
+ let gl_matrix = require("gl-matrix");
7
+ let __constants_ts = require("./constants.cjs");
8
+ let __math_rotation_ts = require("./math/rotation.cjs");
9
+ let __math_sanitize_ts = require("./math/sanitize.cjs");
10
+ let __camera_ts = require("./camera.cjs");
11
+ // packages/media-editor/src/image-editor/core/containment.ts
12
+ /**
13
+ * Compute the visual (rotated) bounding-box dimensions in pixel-proportional
14
+ * units where the unrotated image is `a × 1` (renderedW = a, renderedH = 1).
15
+ *
16
+ * @param rotation Rotation angle in degrees.
17
+ * @param imageAspectRatio Image width / height ratio.
18
+ * @return Visual dimensions and trig helpers.
19
+ */
35
20
  function getVisualDimensions(rotation, imageAspectRatio) {
36
- const rad = (0, import_rotation.degreesToRadians)(rotation);
37
- const absC = Math.abs(Math.cos(rad));
38
- const absS = Math.abs(Math.sin(rad));
39
- const bbox = (0, import_camera.getRotatedBBox)(imageAspectRatio, 1, rotation);
40
- return {
41
- visualW: bbox.width,
42
- visualH: bbox.height,
43
- absC,
44
- absS
45
- };
21
+ const rad = (0, __math_rotation_ts.degreesToRadians)(rotation);
22
+ const absC = Math.abs(Math.cos(rad));
23
+ const absS = Math.abs(Math.sin(rad));
24
+ const bbox = (0, __camera_ts.getRotatedBBox)(imageAspectRatio, 1, rotation);
25
+ return {
26
+ visualW: bbox.width,
27
+ visualH: bbox.height,
28
+ absC,
29
+ absS
30
+ };
46
31
  }
32
+ /**
33
+ * The geometric minimum zoom required for the rotated image to fully cover the
34
+ * crop rectangle. Works in pixel-proportional space where the unrotated image
35
+ * is a×1; the crop rect lives in visual-normalized space and is scaled by the
36
+ * rotation-dependent visual dimensions before projecting into the image-local
37
+ * frame.
38
+ *
39
+ * Returns 0 for a degenerate (zero-area) crop — callers compose the result
40
+ * with their own floor (typically the current zoom or `MIN_ZOOM`).
41
+ *
42
+ * @param rotation Rotation angle in degrees.
43
+ * @param imageAspectRatio Image width / height ratio.
44
+ * @param cropRect The crop rectangle in normalized coordinates.
45
+ * @return The minimum zoom factor needed for coverage.
46
+ */
47
47
  function getMinZoomForCover(rotation, imageAspectRatio, cropRect) {
48
- const aspectRatio = Math.max(imageAspectRatio, Number.EPSILON);
49
- const snapRotation = Math.round(rotation / 90) * 90;
50
- const { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(
51
- snapRotation,
52
- aspectRatio
53
- );
54
- const { absC, absS } = getVisualDimensions(rotation, aspectRatio);
55
- const cropHalfW = cropRect.width * snapVisualW / 2;
56
- const cropHalfH = cropRect.height * snapVisualH / 2;
57
- const spanAlpha = cropHalfW * absC + cropHalfH * absS;
58
- const spanBeta = cropHalfW * absS + cropHalfH * absC;
59
- const zoomFromAlpha = 2 * spanAlpha / aspectRatio;
60
- const zoomFromBeta = 2 * spanBeta;
61
- return Math.max(zoomFromAlpha, zoomFromBeta);
48
+ const aspectRatio = Math.max(imageAspectRatio, Number.EPSILON);
49
+ const { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(Math.round(rotation / 90) * 90, aspectRatio);
50
+ const { absC, absS } = getVisualDimensions(rotation, aspectRatio);
51
+ const cropHalfW = cropRect.width * snapVisualW / 2;
52
+ const cropHalfH = cropRect.height * snapVisualH / 2;
53
+ const spanAlpha = cropHalfW * absC + cropHalfH * absS;
54
+ const spanBeta = cropHalfW * absS + cropHalfH * absC;
55
+ const zoomFromAlpha = 2 * spanAlpha / aspectRatio;
56
+ const zoomFromBeta = 2 * spanBeta;
57
+ return Math.max(zoomFromAlpha, zoomFromBeta);
62
58
  }
59
+ /**
60
+ * Resolves the effective minimum zoom for the current state — the coverage-
61
+ * aware floor when an image is loaded, falling back to `MIN_ZOOM` otherwise.
62
+ * Used by both the cropper's interaction layer and the zoom slider so the
63
+ * floor stays consistent across surfaces.
64
+ *
65
+ * @param state The current cropper state.
66
+ * @return The minimum zoom factor.
67
+ */
63
68
  function getMinZoom(state) {
64
- if (!state.image) {
65
- return import_constants.MIN_ZOOM;
66
- }
67
- const imageSize = {
68
- width: state.image.naturalWidth,
69
- height: state.image.naturalHeight
70
- };
71
- if (!(0, import_sanitize.isValidSize)(imageSize)) {
72
- return import_constants.MIN_ZOOM;
73
- }
74
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
75
- const aspectRatio = imageSize.width / imageSize.height;
76
- return Math.max(
77
- import_constants.ABSOLUTE_MIN_ZOOM,
78
- getMinZoomForCover(
79
- safeState.rotation,
80
- aspectRatio,
81
- safeState.cropRect
82
- )
83
- );
69
+ if (!state.image) return __constants_ts.MIN_ZOOM;
70
+ const imageSize = {
71
+ width: state.image.naturalWidth,
72
+ height: state.image.naturalHeight
73
+ };
74
+ if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return __constants_ts.MIN_ZOOM;
75
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
76
+ const aspectRatio = imageSize.width / imageSize.height;
77
+ return Math.max(__constants_ts.ABSOLUTE_MIN_ZOOM, getMinZoomForCover(safeState.rotation, aspectRatio, safeState.cropRect));
84
78
  }
79
+ /**
80
+ * Compute the crop handle bounds in normalized visual space — the
81
+ * axis-aligned bounding box (AABB) of the actual image footprint at the
82
+ * current pan/zoom/rotation.
83
+ *
84
+ * Returns the full image AABB without intersecting with the container
85
+ * viewport. The viewport pan mechanism in the Cropper component allows
86
+ * the canvas to scroll so handles can reach the image edge even when it
87
+ * lies outside the visible canvas area.
88
+ *
89
+ * Unlike a static centerline-based calculation, this accounts for the
90
+ * current pan position — if the user pans right, the left bound tightens
91
+ * because the image's left edge has moved right.
92
+ *
93
+ * @param state The current cropper state (crop, zoom, rotation, flip).
94
+ * @param elementSize The fitted (unrotated) image element dimensions in pixels.
95
+ * @param visualSize The visual (rotated) image bounding box in pixels.
96
+ * @return The min/max x and y that a crop rect edge can reach in normalized space.
97
+ */
85
98
  function getImageCropBounds(state, elementSize, visualSize) {
86
- if (!(0, import_sanitize.isValidSize)(elementSize) || !(0, import_sanitize.isValidSize)(visualSize)) {
87
- return { minX: 0, minY: 0, maxX: 1, maxY: 1 };
88
- }
89
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
90
- const tx = safeState.pan.x * visualSize.width;
91
- const ty = safeState.pan.y * visualSize.height;
92
- const rad = (0, import_rotation.degreesToRadians)(safeState.rotation);
93
- const cos = Math.cos(rad);
94
- const sin = Math.sin(rad);
95
- const sx = safeState.flip.horizontal ? -1 : 1;
96
- const sy = safeState.flip.vertical ? -1 : 1;
97
- const z = safeState.zoom;
98
- const ma = sx * cos * z;
99
- const mb = sy * sin * z;
100
- const mc = -sx * sin * z;
101
- const md = sy * cos * z;
102
- const hw = elementSize.width / 2;
103
- const hh = elementSize.height / 2;
104
- const corners = [
105
- [-hw, -hh],
106
- [hw, -hh],
107
- [hw, hh],
108
- [-hw, hh]
109
- ];
110
- let imgMinX = Infinity;
111
- let imgMaxX = -Infinity;
112
- let imgMinY = Infinity;
113
- let imgMaxY = -Infinity;
114
- for (const [cx, cy] of corners) {
115
- const screenX = ma * cx + mc * cy + tx;
116
- const screenY = mb * cx + md * cy + ty;
117
- const nx = screenX / visualSize.width + 0.5;
118
- const ny = screenY / visualSize.height + 0.5;
119
- imgMinX = Math.min(imgMinX, nx);
120
- imgMaxX = Math.max(imgMaxX, nx);
121
- imgMinY = Math.min(imgMinY, ny);
122
- imgMaxY = Math.max(imgMaxY, ny);
123
- }
124
- return {
125
- minX: imgMinX,
126
- minY: imgMinY,
127
- maxX: imgMaxX,
128
- maxY: imgMaxY
129
- };
99
+ if (!(0, __math_sanitize_ts.isValidSize)(elementSize) || !(0, __math_sanitize_ts.isValidSize)(visualSize)) return {
100
+ minX: 0,
101
+ minY: 0,
102
+ maxX: 1,
103
+ maxY: 1
104
+ };
105
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
106
+ const tx = safeState.pan.x * visualSize.width;
107
+ const ty = safeState.pan.y * visualSize.height;
108
+ const rad = (0, __math_rotation_ts.degreesToRadians)(safeState.rotation);
109
+ const cos = Math.cos(rad);
110
+ const sin = Math.sin(rad);
111
+ const sx = safeState.flip.horizontal ? -1 : 1;
112
+ const sy = safeState.flip.vertical ? -1 : 1;
113
+ const z = safeState.zoom;
114
+ const ma = sx * cos * z;
115
+ const mb = sy * sin * z;
116
+ const mc = -sx * sin * z;
117
+ const md = sy * cos * z;
118
+ const hw = elementSize.width / 2;
119
+ const hh = elementSize.height / 2;
120
+ const corners = [
121
+ [-hw, -hh],
122
+ [hw, -hh],
123
+ [hw, hh],
124
+ [-hw, hh]
125
+ ];
126
+ let imgMinX = Infinity;
127
+ let imgMaxX = -Infinity;
128
+ let imgMinY = Infinity;
129
+ let imgMaxY = -Infinity;
130
+ for (const [cx, cy] of corners) {
131
+ const screenX = ma * cx + mc * cy + tx;
132
+ const screenY = mb * cx + md * cy + ty;
133
+ const nx = screenX / visualSize.width + .5;
134
+ const ny = screenY / visualSize.height + .5;
135
+ imgMinX = Math.min(imgMinX, nx);
136
+ imgMaxX = Math.max(imgMaxX, nx);
137
+ imgMinY = Math.min(imgMinY, ny);
138
+ imgMaxY = Math.max(imgMaxY, ny);
139
+ }
140
+ return {
141
+ minX: imgMinX,
142
+ minY: imgMinY,
143
+ maxX: imgMaxX,
144
+ maxY: imgMaxY
145
+ };
130
146
  }
147
+ /**
148
+ * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.
149
+ * If the crop rect is too large for the current zoom and rotation, it is scaled
150
+ * down proportionally and re-centered.
151
+ *
152
+ * Works in pixel-proportional space where the unrotated image is a×1.
153
+ *
154
+ * @param cropRect The crop rectangle in normalized coordinates.
155
+ * @param zoom The current zoom factor.
156
+ * @param rotation The rotation angle in degrees.
157
+ * @param imageAspectRatio The image width / height ratio.
158
+ * @return The restricted crop rectangle.
159
+ */
131
160
  function restrictCropRect(cropRect, zoom, rotation, imageAspectRatio) {
132
- const safeRect = (0, import_sanitize.sanitizeRect)(cropRect);
133
- const zoomCandidate = (0, import_sanitize.safeBoundedNumber)(zoom, 1);
134
- const safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;
135
- const safeRotation = (0, import_sanitize.safeBoundedNumber)(rotation, 0);
136
- const safeAspect = (0, import_sanitize.safeBoundedNumber)(imageAspectRatio, 1);
137
- const aspectRatio = Math.max(safeAspect, Number.EPSILON);
138
- const snapRotation = Math.round(safeRotation / 90) * 90;
139
- const { visualW, visualH } = getVisualDimensions(
140
- snapRotation,
141
- aspectRatio
142
- );
143
- const { absC, absS } = getVisualDimensions(safeRotation, aspectRatio);
144
- const W = safeRect.width;
145
- const H = safeRect.height;
146
- const cropWPx = W * visualW;
147
- const cropHPx = H * visualH;
148
- const spanAlpha = cropWPx * absC + cropHPx * absS;
149
- const spanBeta = cropWPx * absS + cropHPx * absC;
150
- const limitAlpha = aspectRatio * safeZoom;
151
- const limitBeta = safeZoom;
152
- let t = 1;
153
- if (spanAlpha > 0) {
154
- t = Math.min(t, limitAlpha / spanAlpha);
155
- }
156
- if (spanBeta > 0) {
157
- t = Math.min(t, limitBeta / spanBeta);
158
- }
159
- if (t >= 1 - EPSILON) {
160
- return safeRect;
161
- }
162
- const newW = W * t;
163
- const newH = H * t;
164
- const centerX = safeRect.x + W / 2;
165
- const centerY = safeRect.y + H / 2;
166
- let newX = centerX - newW / 2;
167
- let newY = centerY - newH / 2;
168
- newX = Math.max(0, Math.min(newX, 1 - newW));
169
- newY = Math.max(0, Math.min(newY, 1 - newH));
170
- return { x: newX, y: newY, width: newW, height: newH };
161
+ const safeRect = (0, __math_sanitize_ts.sanitizeRect)(cropRect);
162
+ const zoomCandidate = (0, __math_sanitize_ts.safeBoundedNumber)(zoom, 1);
163
+ const safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;
164
+ const safeRotation = (0, __math_sanitize_ts.safeBoundedNumber)(rotation, 0);
165
+ const safeAspect = (0, __math_sanitize_ts.safeBoundedNumber)(imageAspectRatio, 1);
166
+ const aspectRatio = Math.max(safeAspect, Number.EPSILON);
167
+ const { visualW, visualH } = getVisualDimensions(Math.round(safeRotation / 90) * 90, aspectRatio);
168
+ const { absC, absS } = getVisualDimensions(safeRotation, aspectRatio);
169
+ const W = safeRect.width;
170
+ const H = safeRect.height;
171
+ const cropWPx = W * visualW;
172
+ const cropHPx = H * visualH;
173
+ const spanAlpha = cropWPx * absC + cropHPx * absS;
174
+ const spanBeta = cropWPx * absS + cropHPx * absC;
175
+ const limitAlpha = aspectRatio * safeZoom;
176
+ const limitBeta = safeZoom;
177
+ let t = 1;
178
+ if (spanAlpha > 0) t = Math.min(t, limitAlpha / spanAlpha);
179
+ if (spanBeta > 0) t = Math.min(t, limitBeta / spanBeta);
180
+ if (t >= .999999999) return safeRect;
181
+ const newW = W * t;
182
+ const newH = H * t;
183
+ const centerX = safeRect.x + W / 2;
184
+ const centerY = safeRect.y + H / 2;
185
+ let newX = centerX - newW / 2;
186
+ let newY = centerY - newH / 2;
187
+ newX = Math.max(0, Math.min(newX, 1 - newW));
188
+ newY = Math.max(0, Math.min(newY, 1 - newH));
189
+ return {
190
+ x: newX,
191
+ y: newY,
192
+ width: newW,
193
+ height: newH
194
+ };
171
195
  }
172
- var CANONICAL_CONTAINER = { width: 1e3, height: 1e3 };
173
- var _scratchMat = import_gl_matrix.mat2d.create();
174
- var _scratchVec = import_gl_matrix.vec2.create();
196
+ /**
197
+ * Canonical container used internally by restrictPanZoom.
198
+ * Containment is scale-invariant, so the actual size doesn't matter —
199
+ * only the relative geometry between stencil and image matters.
200
+ */
201
+ const CANONICAL_CONTAINER = {
202
+ width: 1e3,
203
+ height: 1e3
204
+ };
205
+ const _scratchMat = gl_matrix.mat2d.create();
206
+ const _scratchVec = gl_matrix.vec2.create();
207
+ /**
208
+ * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers
209
+ * the crop rectangle.
210
+ *
211
+ * Uses the camera matrix to project: builds a camera from the candidate state,
212
+ * maps the stencil corners (axis-aligned in the visual bounding box) to world
213
+ * space via the inverse camera, and checks that all world points lie within
214
+ * [0,1]×[0,1]. If any point is outside, computes the minimal pan correction.
215
+ *
216
+ * @param state The current cropper state.
217
+ * @param imageSize The natural size of the image in pixels.
218
+ * @param cropRect The crop rectangle in normalized coordinates.
219
+ * @return The restricted crop pan and zoom values.
220
+ */
175
221
  function restrictPanZoom(state, imageSize, cropRect) {
176
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
177
- const safeCropRect = (0, import_sanitize.sanitizeRect)(cropRect);
178
- const aspectRatio = (0, import_sanitize.isValidSize)(imageSize) ? imageSize.width / imageSize.height : 1;
179
- const minZoom = Math.max(
180
- import_constants.ABSOLUTE_MIN_ZOOM,
181
- getMinZoomForCover(safeState.rotation, aspectRatio, safeCropRect)
182
- );
183
- const zoom = Math.min(import_constants.MAX_ZOOM, Math.max(safeState.zoom, minZoom));
184
- const candidateState = { ...safeState, zoom };
185
- const camera = (0, import_camera.createCamera)(
186
- candidateState,
187
- CANONICAL_CONTAINER,
188
- imageSize
189
- );
190
- const snapRotation = Math.round(safeState.rotation / 90) * 90;
191
- const baseCamera = (0, import_camera.createCamera)(
192
- {
193
- ...candidateState,
194
- pan: { x: 0, y: 0 },
195
- zoom: 1,
196
- rotation: snapRotation
197
- },
198
- CANONICAL_CONTAINER,
199
- imageSize
200
- );
201
- const visibleBounds = (0, import_camera.getVisibleBounds)(baseCamera);
202
- const stencilCorners = [
203
- [
204
- visibleBounds.left + safeCropRect.x * visibleBounds.width,
205
- visibleBounds.top + safeCropRect.y * visibleBounds.height
206
- ],
207
- [
208
- visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width,
209
- visibleBounds.top + safeCropRect.y * visibleBounds.height
210
- ],
211
- [
212
- visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width,
213
- visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height
214
- ],
215
- [
216
- visibleBounds.left + safeCropRect.x * visibleBounds.width,
217
- visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height
218
- ]
219
- ];
220
- import_gl_matrix.mat2d.invert(_scratchMat, camera);
221
- let minWx = Infinity;
222
- let maxWx = -Infinity;
223
- let minWy = Infinity;
224
- let maxWy = -Infinity;
225
- for (const corner of stencilCorners) {
226
- import_gl_matrix.vec2.transformMat2d(_scratchVec, corner, _scratchMat);
227
- const w = _scratchVec;
228
- if (w[0] < minWx) {
229
- minWx = w[0];
230
- }
231
- if (w[0] > maxWx) {
232
- maxWx = w[0];
233
- }
234
- if (w[1] < minWy) {
235
- minWy = w[1];
236
- }
237
- if (w[1] > maxWy) {
238
- maxWy = w[1];
239
- }
240
- }
241
- if (minWx >= -EPSILON && maxWx <= 1 + EPSILON && minWy >= -EPSILON && maxWy <= 1 + EPSILON) {
242
- return { pan: safeState.pan, zoom };
243
- }
244
- let dwx = 0;
245
- let dwy = 0;
246
- if (minWx < 0 && maxWx <= 1 + EPSILON) {
247
- dwx = -minWx;
248
- } else if (maxWx > 1 && minWx >= -EPSILON) {
249
- dwx = 1 - maxWx;
250
- } else if (minWx < 0 && maxWx > 1) {
251
- dwx = (1 - maxWx - minWx) / 2;
252
- }
253
- if (minWy < 0 && maxWy <= 1 + EPSILON) {
254
- dwy = -minWy;
255
- } else if (maxWy > 1 && minWy >= -EPSILON) {
256
- dwy = 1 - maxWy;
257
- } else if (minWy < 0 && maxWy > 1) {
258
- dwy = (1 - maxWy - minWy) / 2;
259
- }
260
- const dsx = camera[0] * dwx + camera[2] * dwy;
261
- const dsy = camera[1] * dwx + camera[3] * dwy;
262
- const newPanX = safeState.pan.x - (visibleBounds.width > 0 ? dsx / visibleBounds.width : 0);
263
- const newPanY = safeState.pan.y - (visibleBounds.height > 0 ? dsy / visibleBounds.height : 0);
264
- return {
265
- pan: { x: newPanX, y: newPanY },
266
- zoom
267
- };
222
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
223
+ const safeCropRect = (0, __math_sanitize_ts.sanitizeRect)(cropRect);
224
+ const aspectRatio = (0, __math_sanitize_ts.isValidSize)(imageSize) ? imageSize.width / imageSize.height : 1;
225
+ const minZoom = Math.max(__constants_ts.ABSOLUTE_MIN_ZOOM, getMinZoomForCover(safeState.rotation, aspectRatio, safeCropRect));
226
+ const zoom = Math.min(__constants_ts.MAX_ZOOM, Math.max(safeState.zoom, minZoom));
227
+ const candidateState = {
228
+ ...safeState,
229
+ zoom
230
+ };
231
+ const camera = (0, __camera_ts.createCamera)(candidateState, CANONICAL_CONTAINER, imageSize);
232
+ const snapRotation = Math.round(safeState.rotation / 90) * 90;
233
+ const baseCamera = (0, __camera_ts.createCamera)({
234
+ ...candidateState,
235
+ pan: {
236
+ x: 0,
237
+ y: 0
238
+ },
239
+ zoom: 1,
240
+ rotation: snapRotation
241
+ }, CANONICAL_CONTAINER, imageSize);
242
+ const visibleBounds = (0, __camera_ts.getVisibleBounds)(baseCamera);
243
+ const stencilCorners = [
244
+ [visibleBounds.left + safeCropRect.x * visibleBounds.width, visibleBounds.top + safeCropRect.y * visibleBounds.height],
245
+ [visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width, visibleBounds.top + safeCropRect.y * visibleBounds.height],
246
+ [visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width, visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height],
247
+ [visibleBounds.left + safeCropRect.x * visibleBounds.width, visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height]
248
+ ];
249
+ gl_matrix.mat2d.invert(_scratchMat, camera);
250
+ let minWx = Infinity;
251
+ let maxWx = -Infinity;
252
+ let minWy = Infinity;
253
+ let maxWy = -Infinity;
254
+ for (const corner of stencilCorners) {
255
+ gl_matrix.vec2.transformMat2d(_scratchVec, corner, _scratchMat);
256
+ const w = _scratchVec;
257
+ if (w[0] < minWx) minWx = w[0];
258
+ if (w[0] > maxWx) maxWx = w[0];
259
+ if (w[1] < minWy) minWy = w[1];
260
+ if (w[1] > maxWy) maxWy = w[1];
261
+ }
262
+ if (minWx >= -1e-9 && maxWx <= 1.000000001 && minWy >= -1e-9 && maxWy <= 1.000000001) return {
263
+ pan: safeState.pan,
264
+ zoom
265
+ };
266
+ let dwx = 0;
267
+ let dwy = 0;
268
+ if (minWx < 0 && maxWx <= 1.000000001) dwx = -minWx;
269
+ else if (maxWx > 1 && minWx >= -1e-9) dwx = 1 - maxWx;
270
+ else if (minWx < 0 && maxWx > 1) dwx = (1 - maxWx - minWx) / 2;
271
+ if (minWy < 0 && maxWy <= 1.000000001) dwy = -minWy;
272
+ else if (maxWy > 1 && minWy >= -1e-9) dwy = 1 - maxWy;
273
+ else if (minWy < 0 && maxWy > 1) dwy = (1 - maxWy - minWy) / 2;
274
+ const dsx = camera[0] * dwx + camera[2] * dwy;
275
+ const dsy = camera[1] * dwx + camera[3] * dwy;
276
+ return {
277
+ pan: {
278
+ x: safeState.pan.x - (visibleBounds.width > 0 ? dsx / visibleBounds.width : 0),
279
+ y: safeState.pan.y - (visibleBounds.height > 0 ? dsy / visibleBounds.height : 0)
280
+ },
281
+ zoom
282
+ };
268
283
  }
269
- // Annotate the CommonJS export names for ESM import in node:
270
- 0 && (module.exports = {
271
- getImageCropBounds,
272
- getMinZoom,
273
- restrictCropRect,
274
- restrictPanZoom
275
- });
276
- //# sourceMappingURL=containment.cjs.map
284
+ exports.getImageCropBounds = getImageCropBounds;
285
+ exports.getMinZoom = getMinZoom;
286
+ exports.restrictCropRect = restrictCropRect;
287
+ exports.restrictPanZoom = restrictPanZoom;
288
+
289
+ //# sourceMappingURL=containment.cjs.map