@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,225 +1,277 @@
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/camera.ts
21
- var camera_exports = {};
22
- __export(camera_exports, {
23
- createCamera: () => createCamera,
24
- createExportCamera: () => createExportCamera,
25
- getImageFit: () => getImageFit,
26
- getRotatedBBox: () => getRotatedBBox,
27
- getViewScale: () => getViewScale,
28
- getVisibleBounds: () => getVisibleBounds,
29
- screenToWorld: () => screenToWorld,
30
- worldToScreen: () => worldToScreen
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
31
5
  });
32
- module.exports = __toCommonJS(camera_exports);
33
- var import_gl_matrix = require("gl-matrix");
34
- var import_rotation = require("./math/rotation.cjs");
35
- var import_sanitize = require("./math/sanitize.cjs");
36
- var _scratchMat = import_gl_matrix.mat2d.create();
37
- var _scratchVec = import_gl_matrix.vec2.create();
6
+ let gl_matrix = require("gl-matrix");
7
+ let __math_rotation_ts = require("./math/rotation.cjs");
8
+ let __math_sanitize_ts = require("./math/sanitize.cjs");
9
+ // packages/media-editor/src/image-editor/core/camera.ts
10
+ const _scratchMat = gl_matrix.mat2d.create();
11
+ const _scratchVec = gl_matrix.vec2.create();
12
+ /**
13
+ * Compute the axis-aligned bounding box of a rectangle after rotation.
14
+ *
15
+ * @param width The width of the rectangle.
16
+ * @param height The height of the rectangle.
17
+ * @param rotation The rotation angle in degrees.
18
+ * @return The bounding box size after rotation.
19
+ */
38
20
  function getRotatedBBox(width, height, rotation) {
39
- if (!(0, import_sanitize.isSafeNumber)(width) || !(0, import_sanitize.isSafeNumber)(height) || !(0, import_sanitize.isSafeNumber)(rotation) || width <= 0 || height <= 0) {
40
- return { width: 0, height: 0 };
41
- }
42
- const rad = (0, import_rotation.degreesToRadians)(rotation);
43
- const cosR = Math.abs(Math.cos(rad));
44
- const sinR = Math.abs(Math.sin(rad));
45
- return {
46
- width: cosR * width + sinR * height,
47
- height: sinR * width + cosR * height
48
- };
21
+ if (!(0, __math_sanitize_ts.isSafeNumber)(width) || !(0, __math_sanitize_ts.isSafeNumber)(height) || !(0, __math_sanitize_ts.isSafeNumber)(rotation) || width <= 0 || height <= 0) return {
22
+ width: 0,
23
+ height: 0
24
+ };
25
+ const rad = (0, __math_rotation_ts.degreesToRadians)(rotation);
26
+ const cosR = Math.abs(Math.cos(rad));
27
+ const sinR = Math.abs(Math.sin(rad));
28
+ return {
29
+ width: cosR * width + sinR * height,
30
+ height: sinR * width + cosR * height
31
+ };
49
32
  }
33
+ /**
34
+ * Compute the fitted (unrotated) image element dimensions and the visual
35
+ * (rotated) bounding box dimensions for a given container, image, and rotation.
36
+ *
37
+ * This is the same "contain" fit logic used by createCamera, extracted so
38
+ * cropper.tsx can size the <img> element and position overlays without
39
+ * duplicating the math.
40
+ *
41
+ * @param containerSize The container dimensions in pixels.
42
+ * @param imageSize The natural image dimensions in pixels.
43
+ * @param rotation The rotation angle in degrees.
44
+ * @return The fitted element size and visual bounding box size.
45
+ */
50
46
  function getImageFit(containerSize, imageSize, rotation) {
51
- if (!(0, import_sanitize.isValidSize)(containerSize) || !(0, import_sanitize.isValidSize)(imageSize)) {
52
- return {
53
- elementSize: { width: 0, height: 0 },
54
- visualSize: { width: 0, height: 0 }
55
- };
56
- }
57
- const safeRotation = (0, import_sanitize.safeBoundedNumber)(rotation, 0);
58
- const snapRotation = Math.round(safeRotation / 90) * 90;
59
- const naturalBBox = getRotatedBBox(
60
- imageSize.width,
61
- imageSize.height,
62
- snapRotation
63
- );
64
- if (naturalBBox.width === 0 || naturalBBox.height === 0) {
65
- return {
66
- elementSize: { width: 0, height: 0 },
67
- visualSize: { width: 0, height: 0 }
68
- };
69
- }
70
- const fitScale = Math.min(
71
- containerSize.width / naturalBBox.width,
72
- containerSize.height / naturalBBox.height
73
- );
74
- const renderedW = imageSize.width * fitScale;
75
- const renderedH = imageSize.height * fitScale;
76
- const visualSize = getRotatedBBox(renderedW, renderedH, snapRotation);
77
- return {
78
- elementSize: { width: renderedW, height: renderedH },
79
- visualSize
80
- };
47
+ if (!(0, __math_sanitize_ts.isValidSize)(containerSize) || !(0, __math_sanitize_ts.isValidSize)(imageSize)) return {
48
+ elementSize: {
49
+ width: 0,
50
+ height: 0
51
+ },
52
+ visualSize: {
53
+ width: 0,
54
+ height: 0
55
+ }
56
+ };
57
+ const safeRotation = (0, __math_sanitize_ts.safeBoundedNumber)(rotation, 0);
58
+ const snapRotation = Math.round(safeRotation / 90) * 90;
59
+ const naturalBBox = getRotatedBBox(imageSize.width, imageSize.height, snapRotation);
60
+ if (naturalBBox.width === 0 || naturalBBox.height === 0) return {
61
+ elementSize: {
62
+ width: 0,
63
+ height: 0
64
+ },
65
+ visualSize: {
66
+ width: 0,
67
+ height: 0
68
+ }
69
+ };
70
+ const fitScale = Math.min(containerSize.width / naturalBBox.width, containerSize.height / naturalBBox.height);
71
+ const renderedW = imageSize.width * fitScale;
72
+ const renderedH = imageSize.height * fitScale;
73
+ const visualSize = getRotatedBBox(renderedW, renderedH, snapRotation);
74
+ return {
75
+ elementSize: {
76
+ width: renderedW,
77
+ height: renderedH
78
+ },
79
+ visualSize
80
+ };
81
81
  }
82
+ /**
83
+ * Resolve the presentational view magnification that makes the crop fill the
84
+ * canvas.
85
+ *
86
+ * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit
87
+ * footprint, with no zoom), so its on-screen size is capped by that footprint.
88
+ * When a crop's aspect differs from the image's, it can be much smaller than
89
+ * the canvas could show (e.g. a square crop in a tall image is bound by the
90
+ * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by
91
+ * the returned factor uniformly magnifies the whole scene — image, crop
92
+ * overlay, and overlays — so the crop reaches `targetFill` of its constraining
93
+ * canvas axis, with the image bleeding past the canvas (clipped by the host).
94
+ *
95
+ * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,
96
+ * so the framed source region — and therefore the export — is unchanged.
97
+ *
98
+ * @param cropRect The crop rectangle, normalized to the footprint.
99
+ * @param canvasSize The canvas size in pixels.
100
+ * @param visualSize The contain-fit (rotated) image footprint in pixels.
101
+ * @param targetFill Fraction of the constraining canvas axis to fill (0–1].
102
+ * @param maxScale Upper bound on the magnification.
103
+ * @return A magnification factor in [1, maxScale]; 1 when none is needed.
104
+ */
82
105
  function getViewScale(cropRect, canvasSize, visualSize, targetFill, maxScale) {
83
- const cropScreenW = cropRect.width * visualSize.width;
84
- const cropScreenH = cropRect.height * visualSize.height;
85
- if (!(0, import_sanitize.isValidSize)(canvasSize) || !(0, import_sanitize.isValidSize)(visualSize) || !(cropScreenW > 0) || !(cropScreenH > 0) || !Number.isFinite(targetFill) || !Number.isFinite(maxScale) || !(targetFill > 0) || !(maxScale >= 1)) {
86
- return 1;
87
- }
88
- const kW = targetFill * canvasSize.width / cropScreenW;
89
- const kH = targetFill * canvasSize.height / cropScreenH;
90
- const k = Math.min(kW, kH);
91
- return Math.min(maxScale, Math.max(1, k));
106
+ const cropScreenW = cropRect.width * visualSize.width;
107
+ const cropScreenH = cropRect.height * visualSize.height;
108
+ if (!(0, __math_sanitize_ts.isValidSize)(canvasSize) || !(0, __math_sanitize_ts.isValidSize)(visualSize) || !(cropScreenW > 0) || !(cropScreenH > 0) || !Number.isFinite(targetFill) || !Number.isFinite(maxScale) || !(targetFill > 0) || !(maxScale >= 1)) return 1;
109
+ const kW = targetFill * canvasSize.width / cropScreenW;
110
+ const kH = targetFill * canvasSize.height / cropScreenH;
111
+ return Math.min(maxScale, Math.max(1, Math.min(kW, kH)));
92
112
  }
113
+ /**
114
+ * Compose a camera matrix from cropper state, container, and image dimensions.
115
+ *
116
+ * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.
117
+ * Input (0,0) = image top-left, (1,1) = image bottom-right.
118
+ *
119
+ * Composition order (left-to-right = outermost first, applied last to point):
120
+ * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels
121
+ *
122
+ * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`
123
+ * are viewport-relative: the image mirrors across the viewport's vertical /
124
+ * horizontal axis regardless of current rotation.
125
+ *
126
+ * @param state The current cropper state (zoom, rotation, flip, crop).
127
+ * @param containerSize The size of the container in pixels.
128
+ * @param imageSize The natural size of the image in pixels.
129
+ * @return The composed camera matrix.
130
+ */
93
131
  function createCamera(state, containerSize, imageSize) {
94
- const m = import_gl_matrix.mat2d.create();
95
- if (!(0, import_sanitize.isValidSize)(containerSize) || !(0, import_sanitize.isValidSize)(imageSize)) {
96
- return m;
97
- }
98
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
99
- const snapRotation = Math.round(safeState.rotation / 90) * 90;
100
- const naturalBBox = getRotatedBBox(
101
- imageSize.width,
102
- imageSize.height,
103
- snapRotation
104
- );
105
- if (naturalBBox.width === 0 || naturalBBox.height === 0) {
106
- return m;
107
- }
108
- const fitScale = Math.min(
109
- containerSize.width / naturalBBox.width,
110
- containerSize.height / naturalBBox.height
111
- );
112
- const renderedW = imageSize.width * fitScale;
113
- const renderedH = imageSize.height * fitScale;
114
- const { width: visualW, height: visualH } = getRotatedBBox(
115
- renderedW,
116
- renderedH,
117
- snapRotation
118
- );
119
- import_gl_matrix.mat2d.translate(m, m, [
120
- containerSize.width / 2,
121
- containerSize.height / 2
122
- ]);
123
- import_gl_matrix.mat2d.translate(m, m, [
124
- safeState.pan.x * visualW,
125
- safeState.pan.y * visualH
126
- ]);
127
- import_gl_matrix.mat2d.scale(m, m, [
128
- safeState.flip.horizontal ? -1 : 1,
129
- safeState.flip.vertical ? -1 : 1
130
- ]);
131
- import_gl_matrix.mat2d.rotate(m, m, (0, import_rotation.degreesToRadians)(safeState.rotation));
132
- import_gl_matrix.mat2d.scale(m, m, [safeState.zoom, safeState.zoom]);
133
- import_gl_matrix.mat2d.translate(m, m, [-renderedW / 2, -renderedH / 2]);
134
- import_gl_matrix.mat2d.scale(m, m, [renderedW, renderedH]);
135
- return m;
132
+ const m = gl_matrix.mat2d.create();
133
+ if (!(0, __math_sanitize_ts.isValidSize)(containerSize) || !(0, __math_sanitize_ts.isValidSize)(imageSize)) return m;
134
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
135
+ const snapRotation = Math.round(safeState.rotation / 90) * 90;
136
+ const naturalBBox = getRotatedBBox(imageSize.width, imageSize.height, snapRotation);
137
+ if (naturalBBox.width === 0 || naturalBBox.height === 0) return m;
138
+ const fitScale = Math.min(containerSize.width / naturalBBox.width, containerSize.height / naturalBBox.height);
139
+ const renderedW = imageSize.width * fitScale;
140
+ const renderedH = imageSize.height * fitScale;
141
+ const { width: visualW, height: visualH } = getRotatedBBox(renderedW, renderedH, snapRotation);
142
+ gl_matrix.mat2d.translate(m, m, [containerSize.width / 2, containerSize.height / 2]);
143
+ gl_matrix.mat2d.translate(m, m, [safeState.pan.x * visualW, safeState.pan.y * visualH]);
144
+ gl_matrix.mat2d.scale(m, m, [safeState.flip.horizontal ? -1 : 1, safeState.flip.vertical ? -1 : 1]);
145
+ gl_matrix.mat2d.rotate(m, m, (0, __math_rotation_ts.degreesToRadians)(safeState.rotation));
146
+ gl_matrix.mat2d.scale(m, m, [safeState.zoom, safeState.zoom]);
147
+ gl_matrix.mat2d.translate(m, m, [-renderedW / 2, -renderedH / 2]);
148
+ gl_matrix.mat2d.scale(m, m, [renderedW, renderedH]);
149
+ return m;
136
150
  }
151
+ /**
152
+ * Transform a normalized world point [0,1] to screen pixels.
153
+ *
154
+ * @param camera The camera matrix from createCamera.
155
+ * @param point The normalized world coordinate to transform.
156
+ * @return The screen pixel coordinate.
157
+ */
137
158
  function worldToScreen(camera, point) {
138
- const out = import_gl_matrix.vec2.create();
139
- import_gl_matrix.vec2.transformMat2d(out, [point.x, point.y], camera);
140
- return { x: out[0], y: out[1] };
159
+ const out = gl_matrix.vec2.create();
160
+ gl_matrix.vec2.transformMat2d(out, [point.x, point.y], camera);
161
+ return {
162
+ x: out[0],
163
+ y: out[1]
164
+ };
141
165
  }
166
+ /**
167
+ * Transform a screen pixel point to normalized world coordinates [0,1].
168
+ *
169
+ * @param camera The camera matrix from createCamera.
170
+ * @param point The screen pixel coordinate to transform.
171
+ * @param point.x The x component of the screen pixel coordinate.
172
+ * @param point.y The y component of the screen pixel coordinate.
173
+ * @return The normalized world coordinate.
174
+ */
142
175
  function screenToWorld(camera, point) {
143
- import_gl_matrix.mat2d.invert(_scratchMat, camera);
144
- const out = _scratchVec;
145
- import_gl_matrix.vec2.transformMat2d(out, [point.x, point.y], _scratchMat);
146
- return { x: out[0], y: out[1] };
176
+ gl_matrix.mat2d.invert(_scratchMat, camera);
177
+ const out = _scratchVec;
178
+ gl_matrix.vec2.transformMat2d(out, [point.x, point.y], _scratchMat);
179
+ return {
180
+ x: out[0],
181
+ y: out[1]
182
+ };
147
183
  }
184
+ /**
185
+ * Compute the axis-aligned bounding box of a set of corners after
186
+ * transforming them through a camera matrix.
187
+ *
188
+ * @param camera The camera matrix from createCamera.
189
+ * @param corners The corners to transform (each as [x, y]).
190
+ * @return The screen-space bounding box.
191
+ */
148
192
  function aabb(camera, corners) {
149
- const screenCorners = corners.map((c) => {
150
- const out = import_gl_matrix.vec2.create();
151
- import_gl_matrix.vec2.transformMat2d(out, c, camera);
152
- return out;
153
- });
154
- let minX = screenCorners[0][0];
155
- let maxX = screenCorners[0][0];
156
- let minY = screenCorners[0][1];
157
- let maxY = screenCorners[0][1];
158
- for (let i = 1; i < screenCorners.length; i++) {
159
- const s = screenCorners[i];
160
- if (s[0] < minX) {
161
- minX = s[0];
162
- }
163
- if (s[0] > maxX) {
164
- maxX = s[0];
165
- }
166
- if (s[1] < minY) {
167
- minY = s[1];
168
- }
169
- if (s[1] > maxY) {
170
- maxY = s[1];
171
- }
172
- }
173
- return { left: minX, top: minY, width: maxX - minX, height: maxY - minY };
193
+ const screenCorners = corners.map((c) => {
194
+ const out = gl_matrix.vec2.create();
195
+ gl_matrix.vec2.transformMat2d(out, c, camera);
196
+ return out;
197
+ });
198
+ let minX = screenCorners[0][0];
199
+ let maxX = screenCorners[0][0];
200
+ let minY = screenCorners[0][1];
201
+ let maxY = screenCorners[0][1];
202
+ for (let i = 1; i < screenCorners.length; i++) {
203
+ const s = screenCorners[i];
204
+ if (s[0] < minX) minX = s[0];
205
+ if (s[0] > maxX) maxX = s[0];
206
+ if (s[1] < minY) minY = s[1];
207
+ if (s[1] > maxY) maxY = s[1];
208
+ }
209
+ return {
210
+ left: minX,
211
+ top: minY,
212
+ width: maxX - minX,
213
+ height: maxY - minY
214
+ };
174
215
  }
216
+ /**
217
+ * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])
218
+ * after applying the camera transform.
219
+ *
220
+ * @param camera The camera matrix from createCamera.
221
+ * @return The screen-space bounding box of the full image.
222
+ */
175
223
  function getVisibleBounds(camera) {
176
- return aabb(camera, [
177
- [0, 0],
178
- [1, 0],
179
- [1, 1],
180
- [0, 1]
181
- ]);
224
+ return aabb(camera, [
225
+ [0, 0],
226
+ [1, 0],
227
+ [1, 1],
228
+ [0, 1]
229
+ ]);
182
230
  }
231
+ /**
232
+ * Compose a camera matrix for exporting to a canvas.
233
+ *
234
+ * The resulting matrix maps image-pixel coordinates directly to output-canvas
235
+ * coordinates. Apply it with `ctx.setTransform( ...camera )` then
236
+ * `ctx.drawImage( image, 0, 0 )`.
237
+ *
238
+ * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:
239
+ * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)
240
+ *
241
+ * @param state The current cropper state.
242
+ * @param imageSize The natural size of the source image in pixels.
243
+ * @param outputSize The desired output canvas size in pixels.
244
+ * @return The composed export camera matrix.
245
+ */
183
246
  function createExportCamera(state, imageSize, outputSize) {
184
- const m = import_gl_matrix.mat2d.create();
185
- if (!(0, import_sanitize.isValidSize)(imageSize) || !(0, import_sanitize.isValidSize)(outputSize)) {
186
- return m;
187
- }
188
- const { rotation, flip, cropRect, zoom, pan } = (0, import_sanitize.sanitizeCropperState)(state);
189
- const snapRotation = Math.round(rotation / 90) * 90;
190
- const { width: rotW, height: rotH } = getRotatedBBox(
191
- imageSize.width,
192
- imageSize.height,
193
- snapRotation
194
- );
195
- const naturalCropW = cropRect.width * rotW;
196
- const naturalCropH = cropRect.height * rotH;
197
- const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
198
- const outputScaleY = naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
199
- const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
200
- const cropOffsetY = cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
201
- const visualCenterX = rotW / 2 + pan.x * rotW;
202
- const visualCenterY = rotH / 2 + pan.y * rotH;
203
- import_gl_matrix.mat2d.scale(m, m, [outputScaleX, outputScaleY]);
204
- import_gl_matrix.mat2d.translate(m, m, [
205
- visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,
206
- visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY
207
- ]);
208
- import_gl_matrix.mat2d.scale(m, m, [flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1]);
209
- import_gl_matrix.mat2d.rotate(m, m, (0, import_rotation.degreesToRadians)(rotation));
210
- import_gl_matrix.mat2d.scale(m, m, [zoom, zoom]);
211
- import_gl_matrix.mat2d.translate(m, m, [-imageSize.width / 2, -imageSize.height / 2]);
212
- return m;
247
+ const m = gl_matrix.mat2d.create();
248
+ if (!(0, __math_sanitize_ts.isValidSize)(imageSize) || !(0, __math_sanitize_ts.isValidSize)(outputSize)) return m;
249
+ const { rotation, flip, cropRect, zoom, pan } = (0, __math_sanitize_ts.sanitizeCropperState)(state);
250
+ const snapRotation = Math.round(rotation / 90) * 90;
251
+ const { width: rotW, height: rotH } = getRotatedBBox(imageSize.width, imageSize.height, snapRotation);
252
+ const naturalCropW = cropRect.width * rotW;
253
+ const naturalCropH = cropRect.height * rotH;
254
+ const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
255
+ const outputScaleY = naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
256
+ const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
257
+ const cropOffsetY = cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
258
+ const visualCenterX = rotW / 2 + pan.x * rotW;
259
+ const visualCenterY = rotH / 2 + pan.y * rotH;
260
+ gl_matrix.mat2d.scale(m, m, [outputScaleX, outputScaleY]);
261
+ gl_matrix.mat2d.translate(m, m, [visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX, visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY]);
262
+ gl_matrix.mat2d.scale(m, m, [flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1]);
263
+ gl_matrix.mat2d.rotate(m, m, (0, __math_rotation_ts.degreesToRadians)(rotation));
264
+ gl_matrix.mat2d.scale(m, m, [zoom, zoom]);
265
+ gl_matrix.mat2d.translate(m, m, [-imageSize.width / 2, -imageSize.height / 2]);
266
+ return m;
213
267
  }
214
- // Annotate the CommonJS export names for ESM import in node:
215
- 0 && (module.exports = {
216
- createCamera,
217
- createExportCamera,
218
- getImageFit,
219
- getRotatedBBox,
220
- getViewScale,
221
- getVisibleBounds,
222
- screenToWorld,
223
- worldToScreen
224
- });
225
- //# sourceMappingURL=camera.cjs.map
268
+ exports.createCamera = createCamera;
269
+ exports.createExportCamera = createExportCamera;
270
+ exports.getImageFit = getImageFit;
271
+ exports.getRotatedBBox = getRotatedBBox;
272
+ exports.getViewScale = getViewScale;
273
+ exports.getVisibleBounds = getVisibleBounds;
274
+ exports.screenToWorld = screenToWorld;
275
+ exports.worldToScreen = worldToScreen;
276
+
277
+ //# sourceMappingURL=camera.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/image-editor/core/camera.ts"],
4
- "sourcesContent": ["import { mat2d, vec2 } from 'gl-matrix';\nimport type {\n\tCropperState,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tCamera,\n} from './types';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisSafeNumber,\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n} from './math/sanitize';\n\n// Pre-allocated scratch buffers for `screenToWorld`, which is called per\n// pointermove. Module-level singletons — safe because usage is synchronous.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Compute the axis-aligned bounding box of a rectangle after rotation.\n *\n * @param width The width of the rectangle.\n * @param height The height of the rectangle.\n * @param rotation The rotation angle in degrees.\n * @return The bounding box size after rotation.\n */\nexport function getRotatedBBox(\n\twidth: number,\n\theight: number,\n\trotation: number\n): Size {\n\t// Short-circuit on any unsafe input. `isSafeNumber` is stricter than\n\t// `Number.isFinite`: very large but technically-finite rotations (e.g.\n\t// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then\n\t// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.\n\tif (\n\t\t! isSafeNumber( width ) ||\n\t\t! isSafeNumber( height ) ||\n\t\t! isSafeNumber( rotation ) ||\n\t\twidth <= 0 ||\n\t\theight <= 0\n\t) {\n\t\treturn { width: 0, height: 0 };\n\t}\n\tconst rad = degreesToRadians( rotation );\n\tconst cosR = Math.abs( Math.cos( rad ) );\n\tconst sinR = Math.abs( Math.sin( rad ) );\n\treturn {\n\t\twidth: cosR * width + sinR * height,\n\t\theight: sinR * width + cosR * height,\n\t};\n}\n\n/**\n * Compute the fitted (unrotated) image element dimensions and the visual\n * (rotated) bounding box dimensions for a given container, image, and rotation.\n *\n * This is the same \"contain\" fit logic used by createCamera, extracted so\n * cropper.tsx can size the <img> element and position overlays without\n * duplicating the math.\n *\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The natural image dimensions in pixels.\n * @param rotation The rotation angle in degrees.\n * @return The fitted element size and visual bounding box size.\n */\nexport function getImageFit(\n\tcontainerSize: Size,\n\timageSize: Size,\n\trotation: number\n): { elementSize: Size; visualSize: Size } {\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\t// Snap rotation to the nearest 90° multiple for layout sizing.\n\t// This keeps the stencil a stable size through fine ±45° rotation\n\t// (no inflation at 15°/30° etc.) while still swapping aspect at\n\t// 90°/180°/270° so the snap rotate preserves the framed content.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\t// Defensive: getRotatedBBox returns zero dims for hostile inputs, which\n\t// would make fitScale infinite. Mirror the zero-container short-circuit.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\tconst visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );\n\treturn {\n\t\telementSize: { width: renderedW, height: renderedH },\n\t\tvisualSize,\n\t};\n}\n\n/**\n * Resolve the presentational view magnification that makes the crop fill the\n * canvas.\n *\n * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n * footprint, with no zoom), so its on-screen size is capped by that footprint.\n * When a crop's aspect differs from the image's, it can be much smaller than\n * the canvas could show (e.g. a square crop in a tall image is bound by the\n * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by\n * the returned factor uniformly magnifies the whole scene — image, crop\n * overlay, and overlays — so the crop reaches `targetFill` of its constraining\n * canvas axis, with the image bleeding past the canvas (clipped by the host).\n *\n * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,\n * so the framed source region — and therefore the export — is unchanged.\n *\n * @param cropRect The crop rectangle, normalized to the footprint.\n * @param canvasSize The canvas size in pixels.\n * @param visualSize The contain-fit (rotated) image footprint in pixels.\n * @param targetFill Fraction of the constraining canvas axis to fill (0–1].\n * @param maxScale Upper bound on the magnification.\n * @return A magnification factor in [1, maxScale]; 1 when none is needed.\n */\nexport function getViewScale(\n\tcropRect: NormalizedRect,\n\tcanvasSize: Size,\n\tvisualSize: Size,\n\ttargetFill: number,\n\tmaxScale: number\n): number {\n\tconst cropScreenW = cropRect.width * visualSize.width;\n\tconst cropScreenH = cropRect.height * visualSize.height;\n\t// `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and\n\t// negatives, so a non-finite rect/dimension/scale can't propagate to a\n\t// `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.\n\tif (\n\t\t! isValidSize( canvasSize ) ||\n\t\t! isValidSize( visualSize ) ||\n\t\t! ( cropScreenW > 0 ) ||\n\t\t! ( cropScreenH > 0 ) ||\n\t\t! Number.isFinite( targetFill ) ||\n\t\t! Number.isFinite( maxScale ) ||\n\t\t! ( targetFill > 0 ) ||\n\t\t! ( maxScale >= 1 )\n\t) {\n\t\treturn 1;\n\t}\n\tconst kW = ( targetFill * canvasSize.width ) / cropScreenW;\n\tconst kH = ( targetFill * canvasSize.height ) / cropScreenH;\n\tconst k = Math.min( kW, kH );\n\treturn Math.min( maxScale, Math.max( 1, k ) );\n}\n\n/**\n * Compose a camera matrix from cropper state, container, and image dimensions.\n *\n * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.\n * Input (0,0) = image top-left, (1,1) = image bottom-right.\n *\n * Composition order (left-to-right = outermost first, applied last to point):\n * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels\n *\n * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`\n * are viewport-relative: the image mirrors across the viewport's vertical /\n * horizontal axis regardless of current rotation.\n *\n * @param state The current cropper state (zoom, rotation, flip, crop).\n * @param containerSize The size of the container in pixels.\n * @param imageSize The natural size of the image in pixels.\n * @return The composed camera matrix.\n */\nexport function createCamera(\n\tstate: CropperState,\n\tcontainerSize: Size,\n\timageSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn m;\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Use the nearest 90° multiple for layout sizing so the stencil\n\t// and visual bounds are stable through fine rotation. The actual\n\t// `state.rotation` is still used for the rotation component of\n\t// the matrix below.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\n\t// Rotated bounding box of the natural image (at snap angle).\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror\n\t// the zero-size short-circuit so `fitScale` doesn't become Infinity.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn m;\n\t}\n\n\t// \"Contain\" fit: scale rotated bounding box to fit within container.\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\n\t// The rendered (unrotated) image dimensions at this fit scale.\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\n\t// Visual (rotated) image footprint in pixels (at snap angle).\n\tconst { width: visualW, height: visualH } = getRotatedBBox(\n\t\trenderedW,\n\t\trenderedH,\n\t\tsnapRotation\n\t);\n\n\t// Build matrix left-to-right (outermost first).\n\t// Innermost operations (last in code) are applied first to input point.\n\n\t// Outermost: translate to container center.\n\tmat2d.translate( m, m, [\n\t\tcontainerSize.width / 2,\n\t\tcontainerSize.height / 2,\n\t] );\n\n\t// Pan offset in visual-space pixels.\n\tmat2d.translate( m, m, [\n\t\tsafeState.pan.x * visualW,\n\t\tsafeState.pan.y * visualH,\n\t] );\n\n\t// Flip (viewport-relative — composed outside rotation so horizontal\n\t// flip always mirrors across the viewport's vertical axis).\n\tmat2d.scale( m, m, [\n\t\tsafeState.flip.horizontal ? -1 : 1,\n\t\tsafeState.flip.vertical ? -1 : 1,\n\t] );\n\n\t// Rotate.\n\tmat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );\n\n\t// Zoom.\n\tmat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );\n\n\t// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).\n\tmat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );\n\n\t// Innermost: scale from normalized [0,1] to rendered pixels.\n\tmat2d.scale( m, m, [ renderedW, renderedH ] );\n\n\treturn m;\n}\n\n/**\n * Transform a normalized world point [0,1] to screen pixels.\n *\n * @param camera The camera matrix from createCamera.\n * @param point The normalized world coordinate to transform.\n * @return The screen pixel coordinate.\n */\nexport function worldToScreen(\n\tcamera: Camera,\n\tpoint: NormalizedPoint\n): { x: number; y: number } {\n\tconst out = vec2.create();\n\tvec2.transformMat2d( out, [ point.x, point.y ], camera );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * Transform a screen pixel point to normalized world coordinates [0,1].\n *\n * @param camera The camera matrix from createCamera.\n * @param point The screen pixel coordinate to transform.\n * @param point.x The x component of the screen pixel coordinate.\n * @param point.y The y component of the screen pixel coordinate.\n * @return The normalized world coordinate.\n */\nexport function screenToWorld(\n\tcamera: Camera,\n\tpoint: { x: number; y: number }\n): NormalizedPoint {\n\tmat2d.invert( _scratchMat, camera );\n\tconst out = _scratchVec;\n\tvec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * The bounding box of a transformed region in screen (pixel) space.\n */\nexport interface VisualBounds {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Compute the axis-aligned bounding box of a set of corners after\n * transforming them through a camera matrix.\n *\n * @param camera The camera matrix from createCamera.\n * @param corners The corners to transform (each as [x, y]).\n * @return The screen-space bounding box.\n */\nfunction aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {\n\tconst screenCorners = corners.map( ( c ) => {\n\t\tconst out = vec2.create();\n\t\tvec2.transformMat2d( out, c, camera );\n\t\treturn out;\n\t} );\n\tlet minX = screenCorners[ 0 ][ 0 ];\n\tlet maxX = screenCorners[ 0 ][ 0 ];\n\tlet minY = screenCorners[ 0 ][ 1 ];\n\tlet maxY = screenCorners[ 0 ][ 1 ];\n\tfor ( let i = 1; i < screenCorners.length; i++ ) {\n\t\tconst s = screenCorners[ i ];\n\t\tif ( s[ 0 ] < minX ) {\n\t\t\tminX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 0 ] > maxX ) {\n\t\t\tmaxX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 1 ] < minY ) {\n\t\t\tminY = s[ 1 ];\n\t\t}\n\t\tif ( s[ 1 ] > maxY ) {\n\t\t\tmaxY = s[ 1 ];\n\t\t}\n\t}\n\treturn { left: minX, top: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/**\n * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])\n * after applying the camera transform.\n *\n * @param camera The camera matrix from createCamera.\n * @return The screen-space bounding box of the full image.\n */\nexport function getVisibleBounds( camera: Camera ): VisualBounds {\n\treturn aabb( camera, [\n\t\t[ 0, 0 ],\n\t\t[ 1, 0 ],\n\t\t[ 1, 1 ],\n\t\t[ 0, 1 ],\n\t] );\n}\n\n/**\n * Compose a camera matrix for exporting to a canvas.\n *\n * The resulting matrix maps image-pixel coordinates directly to output-canvas\n * coordinates. Apply it with `ctx.setTransform( ...camera )` then\n * `ctx.drawImage( image, 0, 0 )`.\n *\n * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:\n * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the source image in pixels.\n * @param outputSize The desired output canvas size in pixels.\n * @return The composed export camera matrix.\n */\nexport function createExportCamera(\n\tstate: CropperState,\n\timageSize: Size,\n\toutputSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\tif ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {\n\t\treturn m;\n\t}\n\tconst { rotation, flip, cropRect, zoom, pan } =\n\t\tsanitizeCropperState( state );\n\t// Reference frame for cropRect/pan is the snap-rotation bbox — that's\n\t// what the stencil and CSS matrix use in the preview (see createCamera\n\t// and getImageFit). Using the true rotation here would position the\n\t// crop window at a different offset than the stencil framed, and show\n\t// a shifted region after any fine rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Scale factor to map the natural crop region to the output canvas size.\n\tconst naturalCropW = cropRect.width * rotW;\n\tconst naturalCropH = cropRect.height * rotH;\n\tconst outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;\n\tconst outputScaleY =\n\t\tnaturalCropH > 0 ? outputSize.height / naturalCropH : 1;\n\n\tconst cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;\n\tconst cropOffsetY =\n\t\tcropRect.y * rotH + outputSize.height / 2 / outputScaleY;\n\tconst visualCenterX = rotW / 2 + pan.x * rotW;\n\tconst visualCenterY = rotH / 2 + pan.y * rotH;\n\tmat2d.scale( m, m, [ outputScaleX, outputScaleY ] );\n\tmat2d.translate( m, m, [\n\t\tvisualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,\n\t\tvisualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,\n\t] );\n\t// Flip is composed outside rotation so it acts in viewport/output space —\n\t// must match createCamera's order for preview and export to agree.\n\tmat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );\n\tmat2d.rotate( m, m, degreesToRadians( rotation ) );\n\tmat2d.scale( m, m, [ zoom, zoom ] );\n\tmat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );\n\treturn m;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA4B;AAQ5B,sBAAiC;AACjC,sBAKO;AAIP,IAAM,cAAc,uBAAM,OAAO;AACjC,IAAM,cAAc,sBAAK,OAAO;AAUzB,SAAS,eACf,OACA,QACA,UACO;AAKP,MACC,KAAE,8BAAc,KAAM,KACtB,KAAE,8BAAc,MAAO,KACvB,KAAE,8BAAc,QAAS,KACzB,SAAS,KACT,UAAU,GACT;AACD,WAAO,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,EAC9B;AACA,QAAM,UAAM,kCAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,SAAO;AAAA,IACN,OAAO,OAAO,QAAQ,OAAO;AAAA,IAC7B,QAAQ,OAAO,QAAQ,OAAO;AAAA,EAC/B;AACD;AAeO,SAAS,YACf,eACA,WACA,UAC0C;AAC1C,MAAK,KAAE,6BAAa,aAAc,KAAK,KAAE,6BAAa,SAAU,GAAI;AACnE,WAAO;AAAA,MACN,aAAa,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,MACnC,YAAY,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,IACnC;AAAA,EACD;AACA,QAAM,mBAAe,mCAAmB,UAAU,CAAE;AAKpD,QAAM,eAAe,KAAK,MAAO,eAAe,EAAG,IAAI;AACvD,QAAM,cAAc;AAAA,IACnB,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,EACD;AAGA,MAAK,YAAY,UAAU,KAAK,YAAY,WAAW,GAAI;AAC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BoundedNumber","sanitizeCropperState"],"sources":["../../../src/image-editor/core/camera.ts"],"sourcesContent":["import { mat2d, vec2 } from 'gl-matrix';\nimport type {\n\tCropperState,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tCamera,\n} from './types';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisSafeNumber,\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n} from './math/sanitize';\n\n// Pre-allocated scratch buffers for `screenToWorld`, which is called per\n// pointermove. Module-level singletons — safe because usage is synchronous.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Compute the axis-aligned bounding box of a rectangle after rotation.\n *\n * @param width The width of the rectangle.\n * @param height The height of the rectangle.\n * @param rotation The rotation angle in degrees.\n * @return The bounding box size after rotation.\n */\nexport function getRotatedBBox(\n\twidth: number,\n\theight: number,\n\trotation: number\n): Size {\n\t// Short-circuit on any unsafe input. `isSafeNumber` is stricter than\n\t// `Number.isFinite`: very large but technically-finite rotations (e.g.\n\t// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then\n\t// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.\n\tif (\n\t\t! isSafeNumber( width ) ||\n\t\t! isSafeNumber( height ) ||\n\t\t! isSafeNumber( rotation ) ||\n\t\twidth <= 0 ||\n\t\theight <= 0\n\t) {\n\t\treturn { width: 0, height: 0 };\n\t}\n\tconst rad = degreesToRadians( rotation );\n\tconst cosR = Math.abs( Math.cos( rad ) );\n\tconst sinR = Math.abs( Math.sin( rad ) );\n\treturn {\n\t\twidth: cosR * width + sinR * height,\n\t\theight: sinR * width + cosR * height,\n\t};\n}\n\n/**\n * Compute the fitted (unrotated) image element dimensions and the visual\n * (rotated) bounding box dimensions for a given container, image, and rotation.\n *\n * This is the same \"contain\" fit logic used by createCamera, extracted so\n * cropper.tsx can size the <img> element and position overlays without\n * duplicating the math.\n *\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The natural image dimensions in pixels.\n * @param rotation The rotation angle in degrees.\n * @return The fitted element size and visual bounding box size.\n */\nexport function getImageFit(\n\tcontainerSize: Size,\n\timageSize: Size,\n\trotation: number\n): { elementSize: Size; visualSize: Size } {\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\t// Snap rotation to the nearest 90° multiple for layout sizing.\n\t// This keeps the stencil a stable size through fine ±45° rotation\n\t// (no inflation at 15°/30° etc.) while still swapping aspect at\n\t// 90°/180°/270° so the snap rotate preserves the framed content.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\t// Defensive: getRotatedBBox returns zero dims for hostile inputs, which\n\t// would make fitScale infinite. Mirror the zero-container short-circuit.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\tconst visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );\n\treturn {\n\t\telementSize: { width: renderedW, height: renderedH },\n\t\tvisualSize,\n\t};\n}\n\n/**\n * Resolve the presentational view magnification that makes the crop fill the\n * canvas.\n *\n * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n * footprint, with no zoom), so its on-screen size is capped by that footprint.\n * When a crop's aspect differs from the image's, it can be much smaller than\n * the canvas could show (e.g. a square crop in a tall image is bound by the\n * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by\n * the returned factor uniformly magnifies the whole scene — image, crop\n * overlay, and overlays — so the crop reaches `targetFill` of its constraining\n * canvas axis, with the image bleeding past the canvas (clipped by the host).\n *\n * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,\n * so the framed source region — and therefore the export — is unchanged.\n *\n * @param cropRect The crop rectangle, normalized to the footprint.\n * @param canvasSize The canvas size in pixels.\n * @param visualSize The contain-fit (rotated) image footprint in pixels.\n * @param targetFill Fraction of the constraining canvas axis to fill (0–1].\n * @param maxScale Upper bound on the magnification.\n * @return A magnification factor in [1, maxScale]; 1 when none is needed.\n */\nexport function getViewScale(\n\tcropRect: NormalizedRect,\n\tcanvasSize: Size,\n\tvisualSize: Size,\n\ttargetFill: number,\n\tmaxScale: number\n): number {\n\tconst cropScreenW = cropRect.width * visualSize.width;\n\tconst cropScreenH = cropRect.height * visualSize.height;\n\t// `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and\n\t// negatives, so a non-finite rect/dimension/scale can't propagate to a\n\t// `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.\n\tif (\n\t\t! isValidSize( canvasSize ) ||\n\t\t! isValidSize( visualSize ) ||\n\t\t! ( cropScreenW > 0 ) ||\n\t\t! ( cropScreenH > 0 ) ||\n\t\t! Number.isFinite( targetFill ) ||\n\t\t! Number.isFinite( maxScale ) ||\n\t\t! ( targetFill > 0 ) ||\n\t\t! ( maxScale >= 1 )\n\t) {\n\t\treturn 1;\n\t}\n\tconst kW = ( targetFill * canvasSize.width ) / cropScreenW;\n\tconst kH = ( targetFill * canvasSize.height ) / cropScreenH;\n\tconst k = Math.min( kW, kH );\n\treturn Math.min( maxScale, Math.max( 1, k ) );\n}\n\n/**\n * Compose a camera matrix from cropper state, container, and image dimensions.\n *\n * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.\n * Input (0,0) = image top-left, (1,1) = image bottom-right.\n *\n * Composition order (left-to-right = outermost first, applied last to point):\n * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels\n *\n * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`\n * are viewport-relative: the image mirrors across the viewport's vertical /\n * horizontal axis regardless of current rotation.\n *\n * @param state The current cropper state (zoom, rotation, flip, crop).\n * @param containerSize The size of the container in pixels.\n * @param imageSize The natural size of the image in pixels.\n * @return The composed camera matrix.\n */\nexport function createCamera(\n\tstate: CropperState,\n\tcontainerSize: Size,\n\timageSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn m;\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Use the nearest 90° multiple for layout sizing so the stencil\n\t// and visual bounds are stable through fine rotation. The actual\n\t// `state.rotation` is still used for the rotation component of\n\t// the matrix below.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\n\t// Rotated bounding box of the natural image (at snap angle).\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror\n\t// the zero-size short-circuit so `fitScale` doesn't become Infinity.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn m;\n\t}\n\n\t// \"Contain\" fit: scale rotated bounding box to fit within container.\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\n\t// The rendered (unrotated) image dimensions at this fit scale.\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\n\t// Visual (rotated) image footprint in pixels (at snap angle).\n\tconst { width: visualW, height: visualH } = getRotatedBBox(\n\t\trenderedW,\n\t\trenderedH,\n\t\tsnapRotation\n\t);\n\n\t// Build matrix left-to-right (outermost first).\n\t// Innermost operations (last in code) are applied first to input point.\n\n\t// Outermost: translate to container center.\n\tmat2d.translate( m, m, [\n\t\tcontainerSize.width / 2,\n\t\tcontainerSize.height / 2,\n\t] );\n\n\t// Pan offset in visual-space pixels.\n\tmat2d.translate( m, m, [\n\t\tsafeState.pan.x * visualW,\n\t\tsafeState.pan.y * visualH,\n\t] );\n\n\t// Flip (viewport-relative — composed outside rotation so horizontal\n\t// flip always mirrors across the viewport's vertical axis).\n\tmat2d.scale( m, m, [\n\t\tsafeState.flip.horizontal ? -1 : 1,\n\t\tsafeState.flip.vertical ? -1 : 1,\n\t] );\n\n\t// Rotate.\n\tmat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );\n\n\t// Zoom.\n\tmat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );\n\n\t// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).\n\tmat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );\n\n\t// Innermost: scale from normalized [0,1] to rendered pixels.\n\tmat2d.scale( m, m, [ renderedW, renderedH ] );\n\n\treturn m;\n}\n\n/**\n * Transform a normalized world point [0,1] to screen pixels.\n *\n * @param camera The camera matrix from createCamera.\n * @param point The normalized world coordinate to transform.\n * @return The screen pixel coordinate.\n */\nexport function worldToScreen(\n\tcamera: Camera,\n\tpoint: NormalizedPoint\n): { x: number; y: number } {\n\tconst out = vec2.create();\n\tvec2.transformMat2d( out, [ point.x, point.y ], camera );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * Transform a screen pixel point to normalized world coordinates [0,1].\n *\n * @param camera The camera matrix from createCamera.\n * @param point The screen pixel coordinate to transform.\n * @param point.x The x component of the screen pixel coordinate.\n * @param point.y The y component of the screen pixel coordinate.\n * @return The normalized world coordinate.\n */\nexport function screenToWorld(\n\tcamera: Camera,\n\tpoint: { x: number; y: number }\n): NormalizedPoint {\n\tmat2d.invert( _scratchMat, camera );\n\tconst out = _scratchVec;\n\tvec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * The bounding box of a transformed region in screen (pixel) space.\n */\nexport interface VisualBounds {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Compute the axis-aligned bounding box of a set of corners after\n * transforming them through a camera matrix.\n *\n * @param camera The camera matrix from createCamera.\n * @param corners The corners to transform (each as [x, y]).\n * @return The screen-space bounding box.\n */\nfunction aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {\n\tconst screenCorners = corners.map( ( c ) => {\n\t\tconst out = vec2.create();\n\t\tvec2.transformMat2d( out, c, camera );\n\t\treturn out;\n\t} );\n\tlet minX = screenCorners[ 0 ][ 0 ];\n\tlet maxX = screenCorners[ 0 ][ 0 ];\n\tlet minY = screenCorners[ 0 ][ 1 ];\n\tlet maxY = screenCorners[ 0 ][ 1 ];\n\tfor ( let i = 1; i < screenCorners.length; i++ ) {\n\t\tconst s = screenCorners[ i ];\n\t\tif ( s[ 0 ] < minX ) {\n\t\t\tminX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 0 ] > maxX ) {\n\t\t\tmaxX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 1 ] < minY ) {\n\t\t\tminY = s[ 1 ];\n\t\t}\n\t\tif ( s[ 1 ] > maxY ) {\n\t\t\tmaxY = s[ 1 ];\n\t\t}\n\t}\n\treturn { left: minX, top: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/**\n * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])\n * after applying the camera transform.\n *\n * @param camera The camera matrix from createCamera.\n * @return The screen-space bounding box of the full image.\n */\nexport function getVisibleBounds( camera: Camera ): VisualBounds {\n\treturn aabb( camera, [\n\t\t[ 0, 0 ],\n\t\t[ 1, 0 ],\n\t\t[ 1, 1 ],\n\t\t[ 0, 1 ],\n\t] );\n}\n\n/**\n * Compose a camera matrix for exporting to a canvas.\n *\n * The resulting matrix maps image-pixel coordinates directly to output-canvas\n * coordinates. Apply it with `ctx.setTransform( ...camera )` then\n * `ctx.drawImage( image, 0, 0 )`.\n *\n * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:\n * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the source image in pixels.\n * @param outputSize The desired output canvas size in pixels.\n * @return The composed export camera matrix.\n */\nexport function createExportCamera(\n\tstate: CropperState,\n\timageSize: Size,\n\toutputSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\tif ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {\n\t\treturn m;\n\t}\n\tconst { rotation, flip, cropRect, zoom, pan } =\n\t\tsanitizeCropperState( state );\n\t// Reference frame for cropRect/pan is the snap-rotation bbox — that's\n\t// what the stencil and CSS matrix use in the preview (see createCamera\n\t// and getImageFit). Using the true rotation here would position the\n\t// crop window at a different offset than the stencil framed, and show\n\t// a shifted region after any fine rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Scale factor to map the natural crop region to the output canvas size.\n\tconst naturalCropW = cropRect.width * rotW;\n\tconst naturalCropH = cropRect.height * rotH;\n\tconst outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;\n\tconst outputScaleY =\n\t\tnaturalCropH > 0 ? outputSize.height / naturalCropH : 1;\n\n\tconst cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;\n\tconst cropOffsetY =\n\t\tcropRect.y * rotH + outputSize.height / 2 / outputScaleY;\n\tconst visualCenterX = rotW / 2 + pan.x * rotW;\n\tconst visualCenterY = rotH / 2 + pan.y * rotH;\n\tmat2d.scale( m, m, [ outputScaleX, outputScaleY ] );\n\tmat2d.translate( m, m, [\n\t\tvisualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,\n\t\tvisualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,\n\t] );\n\t// Flip is composed outside rotation so it acts in viewport/output space —\n\t// must match createCamera's order for preview and export to agree.\n\tmat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );\n\tmat2d.rotate( m, m, degreesToRadians( rotation ) );\n\tmat2d.scale( m, m, [ zoom, zoom ] );\n\tmat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );\n\treturn m;\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,cAAcA,UAAAA,MAAM,OAAO;AACjC,MAAM,cAAcC,UAAAA,KAAK,OAAO;;;;;;;;;AAUhC,SAAgB,eACf,OACA,QACA,UACO;CAKP,IACC,EAAA,GAAEC,mBAAAA,aAAAA,CAAc,KAAM,KACtB,EAAA,GAAEA,mBAAAA,aAAAA,CAAc,MAAO,KACvB,EAAA,GAAEA,mBAAAA,aAAAA,CAAc,QAAS,KACzB,SAAS,KACT,UAAU,GAEV,OAAO;EAAE,OAAO;EAAG,QAAQ;CAAE;CAE9B,MAAM,OAAA,GAAMC,mBAAAA,iBAAAA,CAAkB,QAAS;CACvC,MAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;CACvC,MAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;CACvC,OAAO;EACN,OAAO,OAAO,QAAQ,OAAO;EAC7B,QAAQ,OAAO,QAAQ,OAAO;CAC/B;AACD;;;;;;;;;;;;;;AAeA,SAAgB,YACf,eACA,WACA,UAC0C;CAC1C,IAAK,EAAA,GAAEC,mBAAAA,YAAAA,CAAa,aAAc,KAAK,EAAA,GAAEA,mBAAAA,YAAAA,CAAa,SAAU,GAC/D,OAAO;EACN,aAAa;GAAE,OAAO;GAAG,QAAQ;EAAE;EACnC,YAAY;GAAE,OAAO;GAAG,QAAQ;EAAE;CACnC;CAED,MAAM,gBAAA,GAAeC,mBAAAA,kBAAAA,CAAmB,UAAU,CAAE;CAKpD,MAAM,eAAe,KAAK,MAAO,eAAe,EAAG,IAAI;CACvD,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