@wordpress/media-editor 0.20.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 (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -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