@wordpress/media-editor 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperties(exports, {
3
- __esModule: { value: true },
4
- [Symbol.toStringTag]: { value: "Module" }
5
- });
6
- let ______image_editor_core_camera_ts = require("../../image-editor/core/camera.cjs");
7
- // packages/media-editor/src/components/media-editor-modal/build-modifiers.ts
8
- /**
9
- * Tolerance (percent) used to decide whether a crop rect is effectively
10
- * full-frame. Sub-pixel / float-ulp deltas below this value are treated
11
- * as no crop. Matches the historical threshold used by the legacy
12
- * `use-save-image.js` (which compared against `99.9`).
13
- */
14
- const CROP_TOLERANCE = .1;
15
- /**
16
- * Build a Core-compatible modifiers array from the cropper state.
17
- *
18
- * Emits `[flip, rotate, crop]` in that order. Identity operations are
19
- * pruned — an absent flip, a rotation that normalizes to 0°, and a crop
20
- * rect that covers (within tolerance) the full post-rotate AABB each
21
- * produce no modifier. An identity state (fresh image, no edits) returns
22
- * an empty array; callers can use that to skip the `/edit` call.
23
- *
24
- * Frames and math:
25
- *
26
- * The cropper's `cropRect` is stored as fractions of the **snap-rotation**
27
- * bounding box (the stencil-reference frame — see `createCamera` /
28
- * `createExportCamera`). Pan is in that frame; zoom scales the image
29
- * beneath a fixed stencil. Two conversions are needed to reach the frame
30
- * Core's crop modifier applies against:
31
- *
32
- * 1. Express the stencil rect in snap-AABB **pixels**:
33
- * Image screen-normalized top-left with zoom/pan is
34
- * `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the
35
- * inverse of that transform applied to `cropRect`.
36
- *
37
- * 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs
38
- * share the source-image center, so the conversion is a pure
39
- * translation by `(fullCenter - snapCenter)`. Finally, express the
40
- * translated rect as percentages of the full AABB.
41
- *
42
- * Rotation sign: the cropper composes `flip · R(θ)` on the source (see
43
- * `createExportCamera` — rotate then flip). Core's `[flip, rotate]`
44
- * applies the opposite order: `R(θ') · flip`. For both to land on the
45
- * same pixels we invert the rotation sign when exactly one flip axis
46
- * is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips
47
- * leave the sign alone because `flip_h · flip_v = -I` commutes with
48
- * rotation.
49
- *
50
- * @param cropper The cropper controller. The current edit and the loaded
51
- * image's natural size are both read from its state.
52
- * @return Ordered modifier array; empty when nothing is server-relevant or
53
- * no image has loaded.
54
- */
55
- function buildModifiers(cropper) {
56
- const modifiers = [];
57
- const { state } = cropper;
58
- const { image } = state;
59
- if (!image || image.naturalWidth === 0 || image.naturalHeight === 0) return modifiers;
60
- const imageSize = {
61
- width: image.naturalWidth,
62
- height: image.naturalHeight
63
- };
64
- const { cropRect, pan, zoom, flip } = state;
65
- const hasFlipH = flip.horizontal;
66
- const hasFlipV = flip.vertical;
67
- if (hasFlipH || hasFlipV) modifiers.push({
68
- type: "flip",
69
- args: { flip: {
70
- horizontal: hasFlipH,
71
- vertical: hasFlipV
72
- } }
73
- });
74
- const rawAngle = (state.rotation % 360 + 360) % 360;
75
- const signedAngle = hasFlipH !== hasFlipV ? (360 - rawAngle) % 360 : rawAngle;
76
- if (signedAngle !== 0) modifiers.push({
77
- type: "rotate",
78
- args: { angle: signedAngle }
79
- });
80
- const snapRotation = Math.round(state.rotation / 90) * 90;
81
- const { width: snapW, height: snapH } = (0, ______image_editor_core_camera_ts.getRotatedBBox)(imageSize.width, imageSize.height, snapRotation);
82
- const { width: fullW, height: fullH } = (0, ______image_editor_core_camera_ts.getRotatedBBox)(imageSize.width, imageSize.height, state.rotation);
83
- const imgLeft = .5 + pan.x - zoom / 2;
84
- const imgTop = .5 + pan.y - zoom / 2;
85
- const snapX = (cropRect.x - imgLeft) / zoom * snapW;
86
- const snapY = (cropRect.y - imgTop) / zoom * snapH;
87
- const widthPx = cropRect.width / zoom * snapW;
88
- const heightPx = cropRect.height / zoom * snapH;
89
- const offsetX = (fullW - snapW) / 2;
90
- const offsetY = (fullH - snapH) / 2;
91
- const fullX = snapX + offsetX;
92
- const fullY = snapY + offsetY;
93
- const leftPct = fullX / fullW * 100;
94
- const topPct = fullY / fullH * 100;
95
- const widthPct = widthPx / fullW * 100;
96
- const heightPct = heightPx / fullH * 100;
97
- if (!(leftPct <= CROP_TOLERANCE && topPct <= CROP_TOLERANCE && widthPct >= 99.9 && heightPct >= 99.9)) modifiers.push({
98
- type: "crop",
99
- args: {
100
- left: leftPct,
101
- top: topPct,
102
- width: widthPct,
103
- height: heightPct
104
- }
105
- });
106
- return modifiers;
107
- }
108
- exports.buildModifiers = buildModifiers;
109
-
110
- //# sourceMappingURL=build-modifiers.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-modifiers.cjs","names":["getRotatedBBox"],"sources":["../../../src/components/media-editor-modal/build-modifiers.ts"],"sourcesContent":["import type { CropperController } from '../../image-editor';\nimport { getRotatedBBox } from '../../image-editor/core/camera';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis. Applied first in this module's output.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * cropper's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\nexport type Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n/**\n * Tolerance (percent) used to decide whether a crop rect is effectively\n * full-frame. Sub-pixel / float-ulp deltas below this value are treated\n * as no crop. Matches the historical threshold used by the legacy\n * `use-save-image.js` (which compared against `99.9`).\n */\nconst CROP_TOLERANCE = 0.1;\n\n/**\n * Build a Core-compatible modifiers array from the cropper state.\n *\n * Emits `[flip, rotate, crop]` in that order. Identity operations are\n * pruned — an absent flip, a rotation that normalizes to 0°, and a crop\n * rect that covers (within tolerance) the full post-rotate AABB each\n * produce no modifier. An identity state (fresh image, no edits) returns\n * an empty array; callers can use that to skip the `/edit` call.\n *\n * Frames and math:\n *\n * The cropper's `cropRect` is stored as fractions of the **snap-rotation**\n * bounding box (the stencil-reference frame — see `createCamera` /\n * `createExportCamera`). Pan is in that frame; zoom scales the image\n * beneath a fixed stencil. Two conversions are needed to reach the frame\n * Core's crop modifier applies against:\n *\n * 1. Express the stencil rect in snap-AABB **pixels**:\n * Image screen-normalized top-left with zoom/pan is\n * `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the\n * inverse of that transform applied to `cropRect`.\n *\n * 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs\n * share the source-image center, so the conversion is a pure\n * translation by `(fullCenter - snapCenter)`. Finally, express the\n * translated rect as percentages of the full AABB.\n *\n * Rotation sign: the cropper composes `flip · R(θ)` on the source (see\n * `createExportCamera` — rotate then flip). Core's `[flip, rotate]`\n * applies the opposite order: `R(θ') · flip`. For both to land on the\n * same pixels we invert the rotation sign when exactly one flip axis\n * is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips\n * leave the sign alone because `flip_h · flip_v = -I` commutes with\n * rotation.\n *\n * @param cropper The cropper controller. The current edit and the loaded\n * image's natural size are both read from its state.\n * @return Ordered modifier array; empty when nothing is server-relevant or\n * no image has loaded.\n */\nexport function buildModifiers(\n\tcropper: Pick< CropperController, 'state' >\n): Modifier[] {\n\tconst modifiers: Modifier[] = [];\n\tconst { state } = cropper;\n\tconst { image } = state;\n\n\tif ( ! image || image.naturalWidth === 0 || image.naturalHeight === 0 ) {\n\t\treturn modifiers;\n\t}\n\n\tconst imageSize = {\n\t\twidth: image.naturalWidth,\n\t\theight: image.naturalHeight,\n\t};\n\tconst { cropRect, pan, zoom, flip } = state;\n\tconst hasFlipH = flip.horizontal;\n\tconst hasFlipV = flip.vertical;\n\n\tif ( hasFlipH || hasFlipV ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'flip',\n\t\t\targs: { flip: { horizontal: hasFlipH, vertical: hasFlipV } },\n\t\t} );\n\t}\n\n\tconst rawAngle = ( ( state.rotation % 360 ) + 360 ) % 360;\n\t// Invert the sign for single-axis flips so Core's `flip → rotate`\n\t// pipeline matches the cropper's `rotate → flip` composition.\n\tconst singleAxisFlip = hasFlipH !== hasFlipV;\n\tconst signedAngle = singleAxisFlip ? ( 360 - rawAngle ) % 360 : rawAngle;\n\tif ( signedAngle !== 0 ) {\n\t\tmodifiers.push( { type: 'rotate', args: { angle: signedAngle } } );\n\t}\n\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst { width: snapW, height: snapH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tconst { width: fullW, height: fullH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tstate.rotation\n\t);\n\n\t// Stencil rect in snap-AABB pixels. Inverts `createExportCamera`'s\n\t// pan/zoom composition to recover the pixel rectangle the stencil\n\t// framed in that frame.\n\tconst imgLeft = 0.5 + pan.x - zoom / 2;\n\tconst imgTop = 0.5 + pan.y - zoom / 2;\n\tconst snapX = ( ( cropRect.x - imgLeft ) / zoom ) * snapW;\n\tconst snapY = ( ( cropRect.y - imgTop ) / zoom ) * snapH;\n\tconst widthPx = ( cropRect.width / zoom ) * snapW;\n\tconst heightPx = ( cropRect.height / zoom ) * snapH;\n\n\t// Translate to the full AABB (both centered on source).\n\tconst offsetX = ( fullW - snapW ) / 2;\n\tconst offsetY = ( fullH - snapH ) / 2;\n\tconst fullX = snapX + offsetX;\n\tconst fullY = snapY + offsetY;\n\n\t// Percentages of the full AABB — Core's crop frame after rotate.\n\tconst leftPct = ( fullX / fullW ) * 100;\n\tconst topPct = ( fullY / fullH ) * 100;\n\tconst widthPct = ( widthPx / fullW ) * 100;\n\tconst heightPct = ( heightPx / fullH ) * 100;\n\n\tconst coversFullFrame =\n\t\tleftPct <= CROP_TOLERANCE &&\n\t\ttopPct <= CROP_TOLERANCE &&\n\t\twidthPct >= 100 - CROP_TOLERANCE &&\n\t\theightPct >= 100 - CROP_TOLERANCE;\n\n\tif ( ! coversFullFrame ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: leftPct,\n\t\t\t\ttop: topPct,\n\t\t\t\twidth: widthPct,\n\t\t\t\theight: heightPct,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn modifiers;\n}\n"],"mappings":";;;;;;;;;;;;;AAoCA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CvB,SAAgB,eACf,SACa;CACb,MAAM,YAAwB,CAAC;CAC/B,MAAM,EAAE,UAAU;CAClB,MAAM,EAAE,UAAU;CAElB,IAAK,CAAE,SAAS,MAAM,iBAAiB,KAAK,MAAM,kBAAkB,GACnE,OAAO;CAGR,MAAM,YAAY;EACjB,OAAO,MAAM;EACb,QAAQ,MAAM;CACf;CACA,MAAM,EAAE,UAAU,KAAK,MAAM,SAAS;CACtC,MAAM,WAAW,KAAK;CACtB,MAAM,WAAW,KAAK;CAEtB,IAAK,YAAY,UAChB,UAAU,KAAM;EACf,MAAM;EACN,MAAM,EAAE,MAAM;GAAE,YAAY;GAAU,UAAU;EAAS,EAAE;CAC5D,CAAE;CAGH,MAAM,YAAe,MAAM,WAAW,MAAQ,OAAQ;CAItD,MAAM,cADiB,aAAa,YACG,MAAM,YAAa,MAAM;CAChE,IAAK,gBAAgB,GACpB,UAAU,KAAM;EAAE,MAAM;EAAU,MAAM,EAAE,OAAO,YAAY;CAAE,CAAE;CAGlE,MAAM,eAAe,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CACzD,MAAM,EAAE,OAAO,OAAO,QAAQ,WAAA,GAAUA,kCAAAA,eAAAA,CACvC,UAAU,OACV,UAAU,QACV,YACD;CACA,MAAM,EAAE,OAAO,OAAO,QAAQ,WAAA,GAAUA,kCAAAA,eAAAA,CACvC,UAAU,OACV,UAAU,QACV,MAAM,QACP;CAKA,MAAM,UAAU,KAAM,IAAI,IAAI,OAAO;CACrC,MAAM,SAAS,KAAM,IAAI,IAAI,OAAO;CACpC,MAAM,SAAY,SAAS,IAAI,WAAY,OAAS;CACpD,MAAM,SAAY,SAAS,IAAI,UAAW,OAAS;CACnD,MAAM,UAAY,SAAS,QAAQ,OAAS;CAC5C,MAAM,WAAa,SAAS,SAAS,OAAS;CAG9C,MAAM,WAAY,QAAQ,SAAU;CACpC,MAAM,WAAY,QAAQ,SAAU;CACpC,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,QAAQ;CAGtB,MAAM,UAAY,QAAQ,QAAU;CACpC,MAAM,SAAW,QAAQ,QAAU;CACnC,MAAM,WAAa,UAAU,QAAU;CACvC,MAAM,YAAc,WAAW,QAAU;CAQzC,IAAK,EALJ,WAAW,kBACX,UAAU,kBACV,YAAY,QACZ,aAAa,OAGb,UAAU,KAAM;EACf,MAAM;EACN,MAAM;GACL,MAAM;GACN,KAAK;GACL,OAAO;GACP,QAAQ;EACT;CACD,CAAE;CAGH,OAAO;AACR"}
@@ -1,277 +0,0 @@
1
- "use strict";
2
- Object.defineProperties(exports, {
3
- __esModule: { value: true },
4
- [Symbol.toStringTag]: { value: "Module" }
5
- });
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
- */
20
- function getRotatedBBox(width, height, rotation) {
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
- };
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
- */
46
- function getImageFit(containerSize, imageSize, rotation) {
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
- }
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
- */
105
- function getViewScale(cropRect, canvasSize, visualSize, targetFill, maxScale) {
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)));
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
- */
131
- function createCamera(state, containerSize, imageSize) {
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;
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
- */
158
- function worldToScreen(camera, point) {
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
- };
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
- */
175
- function screenToWorld(camera, point) {
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
- };
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
- */
192
- function aabb(camera, corners) {
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
- };
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
- */
223
- function getVisibleBounds(camera) {
224
- return aabb(camera, [
225
- [0, 0],
226
- [1, 0],
227
- [1, 1],
228
- [0, 1]
229
- ]);
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
- */
246
- function createExportCamera(state, imageSize, outputSize) {
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;
267
- }
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 +0,0 @@
1
- {"version":3,"file":"camera.cjs","names":["mat2d","vec2","isSafeNumber","degreesToRadians","isValidSize","safeBoundedNumber","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":"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"}
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperties(exports, {
3
- __esModule: { value: true },
4
- [Symbol.toStringTag]: { value: "Module" }
5
- });
6
- // packages/media-editor/src/image-editor/core/constants.ts
7
- /**
8
- * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the
9
- * crop area, but smaller/fine-rotated crops can be valid below 1x — the true
10
- * floor for those comes from `getMinZoom`.
11
- */
12
- const MIN_ZOOM = 1;
13
- /**
14
- * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric
15
- * coverage minimum of 0, but camera and inverse-matrix math need a stable,
16
- * positive scale.
17
- */
18
- const ABSOLUTE_MIN_ZOOM = .1;
19
- const MAX_ZOOM = 10;
20
- /**
21
- * Minimum crop rect dimension in source-image pixels, enforced per axis
22
- * during resize. Prevents accidental sub-pixel crops while staying small
23
- * enough to allow tight crops (favicons, icons). Adjust here to tune the
24
- * floor globally.
25
- */
26
- const MIN_CROP_PIXELS = 16;
27
- /**
28
- * Minimum on-screen crop rect dimension in CSS pixels. The source-pixel
29
- * floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large
30
- * image fit into a small canvas it can render only a few CSS pixels wide —
31
- * too small to grab the resize handles. This floor keeps the crop operable
32
- * regardless of display scale; it binds when zoomed out and yields to the
33
- * source-pixel floor once the image is shown large enough. Sized to one
34
- * handle touch target (`$handle-touch-target-size` in `cropper.scss`).
35
- */
36
- const MIN_CROP_SCREEN_PX = 44;
37
- /**
38
- * Fraction of the constraining canvas axis the settled crop should occupy on
39
- * screen. When a crop is shown smaller than this (e.g. a square crop in a tall
40
- * image, capped by the contain-fit footprint's narrow axis), the view magnifies
41
- * to fill the canvas. `1` = always fill the canvas; lower = rescue only the
42
- * under-filled cases. See `getViewScale`.
43
- */
44
- const SETTLE_TARGET_CANVAS_FILL = .8;
45
- /**
46
- * Upper bound on the presentational view magnification (`getViewScale`).
47
- * Prevents a near-degenerate crop from magnifying the scene without limit.
48
- */
49
- const MAX_VIEW_SCALE = 8;
50
- /**
51
- * CSS pixels per source pixel required before resize handles snap the selected
52
- * source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on
53
- * screen, so snapping would feel notchy without a visible pixel boundary.
54
- */
55
- const PIXEL_SNAP_DISPLAY_SCALE = 1;
56
- /**
57
- * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.
58
- * This could be made configurable as a prop to the Cropper component.
59
- */
60
- const DEFAULT_WHEEL_ZOOM_SPEED = .0025;
61
- /** Fine step for keyboard-driven cropper movement, in normalized coordinates. */
62
- const DEFAULT_KEYBOARD_STEP = .01;
63
- /** Coarse keyboard movement multiplier when Shift is held. */
64
- const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
65
- /**
66
- * Maximum free-rotation offset in degrees from the nearest 90° step.
67
- * The rotation slider allows ±45° around the current cardinal angle.
68
- */
69
- const MAX_ROTATION_OFFSET = 45;
70
- const DEFAULT_CROP_RECT = {
71
- x: 0,
72
- y: 0,
73
- width: 1,
74
- height: 1
75
- };
76
- const DEFAULT_FLIP = {
77
- horizontal: false,
78
- vertical: false
79
- };
80
- const DEFAULT_PAN = {
81
- x: 0,
82
- y: 0
83
- };
84
- const DEFAULT_STATE = {
85
- image: null,
86
- pan: { ...DEFAULT_PAN },
87
- zoom: 1,
88
- rotation: 0,
89
- basePan: { ...DEFAULT_PAN },
90
- baseZoom: 1,
91
- baseRotation: 0,
92
- flip: { ...DEFAULT_FLIP },
93
- cropRect: { ...DEFAULT_CROP_RECT }
94
- };
95
- /**
96
- * Default aspect ratio presets. Consumers can use these as-is, override
97
- * with their own list, or extend with additional presets.
98
- *
99
- * @example
100
- * // Use defaults:
101
- * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />
102
- *
103
- * // Custom presets:
104
- * const socialPresets = [
105
- * { label: 'Instagram Post', value: 1 },
106
- * { label: 'Instagram Story', value: 9 / 16 },
107
- * { label: 'YouTube Thumbnail', value: 16 / 9 },
108
- * ];
109
- *
110
- * // Extend defaults:
111
- * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];
112
- */
113
- /**
114
- * Sentinel value for "Original" aspect ratio — resolved at runtime
115
- * to the image's natural width / height.
116
- */
117
- const ORIGINAL_ASPECT_RATIO = -1;
118
- exports.ABSOLUTE_MIN_ZOOM = ABSOLUTE_MIN_ZOOM;
119
- exports.DEFAULT_KEYBOARD_STEP = DEFAULT_KEYBOARD_STEP;
120
- exports.DEFAULT_STATE = DEFAULT_STATE;
121
- exports.DEFAULT_WHEEL_ZOOM_SPEED = DEFAULT_WHEEL_ZOOM_SPEED;
122
- exports.KEYBOARD_SHIFT_STEP_MULTIPLIER = KEYBOARD_SHIFT_STEP_MULTIPLIER;
123
- exports.MAX_ROTATION_OFFSET = MAX_ROTATION_OFFSET;
124
- exports.MAX_VIEW_SCALE = MAX_VIEW_SCALE;
125
- exports.MAX_ZOOM = MAX_ZOOM;
126
- exports.MIN_CROP_PIXELS = MIN_CROP_PIXELS;
127
- exports.MIN_CROP_SCREEN_PX = MIN_CROP_SCREEN_PX;
128
- exports.MIN_ZOOM = MIN_ZOOM;
129
- exports.ORIGINAL_ASPECT_RATIO = ORIGINAL_ASPECT_RATIO;
130
- exports.PIXEL_SNAP_DISPLAY_SCALE = PIXEL_SNAP_DISPLAY_SCALE;
131
- exports.SETTLE_TARGET_CANVAS_FILL = SETTLE_TARGET_CANVAS_FILL;
132
-
133
- //# sourceMappingURL=constants.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","names":[],"sources":["../../../src/image-editor/core/constants.ts"],"sourcesContent":["import type { NormalizedRect, Flip, CropperState } from './types';\n\n/**\n * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the\n * crop area, but smaller/fine-rotated crops can be valid below 1x — the true\n * floor for those comes from `getMinZoom`.\n */\nexport const MIN_ZOOM = 1;\n/**\n * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric\n * coverage minimum of 0, but camera and inverse-matrix math need a stable,\n * positive scale.\n */\nexport const ABSOLUTE_MIN_ZOOM = 0.1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Minimum crop rect dimension in source-image pixels, enforced per axis\n * during resize. Prevents accidental sub-pixel crops while staying small\n * enough to allow tight crops (favicons, icons). Adjust here to tune the\n * floor globally.\n */\nexport const MIN_CROP_PIXELS = 16;\n\n/**\n * Minimum on-screen crop rect dimension in CSS pixels. The source-pixel\n * floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large\n * image fit into a small canvas it can render only a few CSS pixels wide —\n * too small to grab the resize handles. This floor keeps the crop operable\n * regardless of display scale; it binds when zoomed out and yields to the\n * source-pixel floor once the image is shown large enough. Sized to one\n * handle touch target (`$handle-touch-target-size` in `cropper.scss`).\n */\nexport const MIN_CROP_SCREEN_PX = 44;\n\n/**\n * Fraction of the constraining canvas axis the settled crop should occupy on\n * screen. When a crop is shown smaller than this (e.g. a square crop in a tall\n * image, capped by the contain-fit footprint's narrow axis), the view magnifies\n * to fill the canvas. `1` = always fill the canvas; lower = rescue only the\n * under-filled cases. See `getViewScale`.\n */\nexport const SETTLE_TARGET_CANVAS_FILL = 0.8;\n\n/**\n * Upper bound on the presentational view magnification (`getViewScale`).\n * Prevents a near-degenerate crop from magnifying the scene without limit.\n */\nexport const MAX_VIEW_SCALE = 8;\n\n/**\n * CSS pixels per source pixel required before resize handles snap the selected\n * source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on\n * screen, so snapping would feel notchy without a visible pixel boundary.\n */\nexport const PIXEL_SNAP_DISPLAY_SCALE = 1;\n\n/**\n * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.\n * This could be made configurable as a prop to the Cropper component.\n */\nexport const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;\n\n/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */\nexport const DEFAULT_KEYBOARD_STEP = 0.01;\n\n/** Coarse keyboard movement multiplier when Shift is held. */\nexport const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90° step.\n * The rotation slider allows ±45° around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n"],"mappings":";;;;;;;;;;;AAOA,MAAa,WAAW;;;;;;AAMxB,MAAa,oBAAoB;AACjC,MAAa,WAAW;;;;;;;AAQxB,MAAa,kBAAkB;;;;;;;;;;AAW/B,MAAa,qBAAqB;;;;;;;;AASlC,MAAa,4BAA4B;;;;;AAMzC,MAAa,iBAAiB;;;;;;AAO9B,MAAa,2BAA2B;;;;;AAMxC,MAAa,2BAA2B;;AAGxC,MAAa,wBAAwB;;AAGrC,MAAa,iCAAiC;;;;;AAM9C,MAAa,sBAAsB;AAEnC,MAAM,oBAAoC;CACzC,GAAG;CACH,GAAG;CACH,OAAO;CACP,QAAQ;AACT;AAEA,MAAM,eAAqB;CAC1B,YAAY;CACZ,UAAU;AACX;AAEA,MAAM,cAAwC;CAC7C,GAAG;CACH,GAAG;AACJ;AAEA,MAAa,gBAA8B;CAC1C,OAAO;CACP,KAAK,EAAE,GAAG,YAAY;CACtB,MAAA;CACA,UAAU;CACV,SAAS,EAAE,GAAG,YAAY;CAC1B,UAAA;CACA,cAAc;CACd,MAAM,EAAE,GAAG,aAAa;CACxB,UAAU,EAAE,GAAG,kBAAkB;AAClC;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,wBAAwB"}