@wordpress/media-editor 0.7.1-next.v.202604201441.0 → 0.8.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 (300) hide show
  1. package/build/components/media-editor-canvas/index.cjs +54 -0
  2. package/build/components/media-editor-canvas/index.cjs.map +7 -0
  3. package/build/components/media-editor-crop-panel/index.cjs +116 -0
  4. package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
  5. package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
  6. package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
  7. package/build/components/media-editor-modal/index.cjs +497 -0
  8. package/build/components/media-editor-modal/index.cjs.map +7 -0
  9. package/build/components/media-editor-toolbar/index.cjs +146 -0
  10. package/build/components/media-editor-toolbar/index.cjs.map +7 -0
  11. package/build/image-editor/core/camera.cjs +194 -0
  12. package/build/image-editor/core/camera.cjs.map +7 -0
  13. package/build/image-editor/core/constants.cjs +81 -0
  14. package/build/image-editor/core/constants.cjs.map +7 -0
  15. package/build/image-editor/core/containment.cjs +245 -0
  16. package/build/image-editor/core/containment.cjs.map +7 -0
  17. package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
  18. package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
  19. package/build/image-editor/core/index.cjs +50 -0
  20. package/build/image-editor/core/index.cjs.map +7 -0
  21. package/build/image-editor/core/interaction-controller.cjs +608 -0
  22. package/build/image-editor/core/interaction-controller.cjs.map +7 -0
  23. package/build/image-editor/core/math/rotation.cjs +41 -0
  24. package/build/image-editor/core/math/rotation.cjs.map +7 -0
  25. package/build/image-editor/core/source-region.cjs +95 -0
  26. package/build/image-editor/core/source-region.cjs.map +7 -0
  27. package/build/image-editor/core/state.cjs +269 -0
  28. package/build/image-editor/core/state.cjs.map +7 -0
  29. package/build/image-editor/core/stencil-math.cjs +197 -0
  30. package/build/image-editor/core/stencil-math.cjs.map +7 -0
  31. package/build/image-editor/core/transform-style.cjs +46 -0
  32. package/build/image-editor/core/transform-style.cjs.map +7 -0
  33. package/build/image-editor/core/transforms/pipeline.cjs +43 -0
  34. package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
  35. package/build/image-editor/core/types.cjs +19 -0
  36. package/build/image-editor/core/types.cjs.map +7 -0
  37. package/build/image-editor/index.cjs +57 -0
  38. package/build/image-editor/index.cjs.map +7 -0
  39. package/build/image-editor/react/components/cropper-provider.cjs +50 -0
  40. package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
  41. package/build/image-editor/react/components/cropper.cjs +365 -0
  42. package/build/image-editor/react/components/cropper.cjs.map +7 -0
  43. package/build/image-editor/react/components/index.cjs +36 -0
  44. package/build/image-editor/react/components/index.cjs.map +7 -0
  45. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
  46. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
  47. package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
  48. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
  49. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
  50. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
  51. package/build/image-editor/react/hooks/index.cjs +31 -0
  52. package/build/image-editor/react/hooks/index.cjs.map +7 -0
  53. package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
  54. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
  55. package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
  56. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
  57. package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
  58. package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
  59. package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
  60. package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
  61. package/build/index.cjs +5 -2
  62. package/build/index.cjs.map +2 -2
  63. package/build/lock-unlock.cjs +37 -0
  64. package/build/lock-unlock.cjs.map +7 -0
  65. package/build/private-apis.cjs +38 -0
  66. package/build/private-apis.cjs.map +7 -0
  67. package/build/store/actions.cjs +45 -0
  68. package/build/store/actions.cjs.map +7 -0
  69. package/build/store/constants.cjs +31 -0
  70. package/build/store/constants.cjs.map +7 -0
  71. package/build/store/index.cjs +51 -0
  72. package/build/store/index.cjs.map +7 -0
  73. package/build/store/reducer.cjs +51 -0
  74. package/build/store/reducer.cjs.map +7 -0
  75. package/build/store/selectors.cjs +43 -0
  76. package/build/store/selectors.cjs.map +7 -0
  77. package/build-module/components/media-editor-canvas/index.mjs +33 -0
  78. package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
  79. package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
  80. package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
  81. package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
  82. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
  83. package/build-module/components/media-editor-modal/index.mjs +483 -0
  84. package/build-module/components/media-editor-modal/index.mjs.map +7 -0
  85. package/build-module/components/media-editor-toolbar/index.mjs +130 -0
  86. package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
  87. package/build-module/image-editor/core/camera.mjs +163 -0
  88. package/build-module/image-editor/core/camera.mjs.map +7 -0
  89. package/build-module/image-editor/core/constants.mjs +51 -0
  90. package/build-module/image-editor/core/constants.mjs.map +7 -0
  91. package/build-module/image-editor/core/containment.mjs +218 -0
  92. package/build-module/image-editor/core/containment.mjs.map +7 -0
  93. package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
  94. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
  95. package/build-module/image-editor/core/index.mjs +24 -0
  96. package/build-module/image-editor/core/index.mjs.map +7 -0
  97. package/build-module/image-editor/core/interaction-controller.mjs +583 -0
  98. package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
  99. package/build-module/image-editor/core/math/rotation.mjs +15 -0
  100. package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
  101. package/build-module/image-editor/core/source-region.mjs +69 -0
  102. package/build-module/image-editor/core/source-region.mjs.map +7 -0
  103. package/build-module/image-editor/core/state.mjs +242 -0
  104. package/build-module/image-editor/core/state.mjs.map +7 -0
  105. package/build-module/image-editor/core/stencil-math.mjs +169 -0
  106. package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
  107. package/build-module/image-editor/core/transform-style.mjs +21 -0
  108. package/build-module/image-editor/core/transform-style.mjs.map +7 -0
  109. package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
  110. package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
  111. package/build-module/image-editor/core/types.mjs +1 -0
  112. package/build-module/image-editor/core/types.mjs.map +7 -0
  113. package/build-module/image-editor/index.mjs +30 -0
  114. package/build-module/image-editor/index.mjs.map +7 -0
  115. package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
  116. package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
  117. package/build-module/image-editor/react/components/cropper.mjs +337 -0
  118. package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
  119. package/build-module/image-editor/react/components/index.mjs +9 -0
  120. package/build-module/image-editor/react/components/index.mjs.map +7 -0
  121. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
  122. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
  123. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
  124. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
  125. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
  126. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
  127. package/build-module/image-editor/react/hooks/index.mjs +6 -0
  128. package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
  129. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
  130. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
  131. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
  132. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
  133. package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
  134. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
  135. package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
  136. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
  137. package/build-module/index.mjs +3 -1
  138. package/build-module/index.mjs.map +2 -2
  139. package/build-module/lock-unlock.mjs +11 -0
  140. package/build-module/lock-unlock.mjs.map +7 -0
  141. package/build-module/private-apis.mjs +13 -0
  142. package/build-module/private-apis.mjs.map +7 -0
  143. package/build-module/store/actions.mjs +19 -0
  144. package/build-module/store/actions.mjs.map +7 -0
  145. package/build-module/store/constants.mjs +6 -0
  146. package/build-module/store/constants.mjs.map +7 -0
  147. package/build-module/store/index.mjs +16 -0
  148. package/build-module/store/index.mjs.map +7 -0
  149. package/build-module/store/reducer.mjs +26 -0
  150. package/build-module/store/reducer.mjs.map +7 -0
  151. package/build-module/store/selectors.mjs +16 -0
  152. package/build-module/store/selectors.mjs.map +7 -0
  153. package/build-style/style-rtl.css +315 -0
  154. package/build-style/style.css +315 -0
  155. package/build-types/components/media-editor-canvas/index.d.ts +22 -0
  156. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
  157. package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
  158. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
  159. package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
  160. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
  161. package/build-types/components/media-editor-modal/index.d.ts +20 -0
  162. package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
  163. package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
  164. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
  165. package/build-types/image-editor/core/camera.d.ts +107 -0
  166. package/build-types/image-editor/core/camera.d.ts.map +1 -0
  167. package/build-types/image-editor/core/constants.d.ts +46 -0
  168. package/build-types/image-editor/core/constants.d.ts.map +1 -0
  169. package/build-types/image-editor/core/containment.d.ts +61 -0
  170. package/build-types/image-editor/core/containment.d.ts.map +1 -0
  171. package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
  172. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
  173. package/build-types/image-editor/core/index.d.ts +8 -0
  174. package/build-types/image-editor/core/index.d.ts.map +1 -0
  175. package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
  176. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
  177. package/build-types/image-editor/core/math/rotation.d.ts +18 -0
  178. package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
  179. package/build-types/image-editor/core/source-region.d.ts +75 -0
  180. package/build-types/image-editor/core/source-region.d.ts.map +1 -0
  181. package/build-types/image-editor/core/state.d.ts +42 -0
  182. package/build-types/image-editor/core/state.d.ts.map +1 -0
  183. package/build-types/image-editor/core/stencil-math.d.ts +79 -0
  184. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
  185. package/build-types/image-editor/core/transform-style.d.ts +23 -0
  186. package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
  187. package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
  188. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
  189. package/build-types/image-editor/core/types.d.ts +211 -0
  190. package/build-types/image-editor/core/types.d.ts.map +1 -0
  191. package/build-types/image-editor/index.d.ts +16 -0
  192. package/build-types/image-editor/index.d.ts.map +1 -0
  193. package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
  194. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
  195. package/build-types/image-editor/react/components/cropper.d.ts +59 -0
  196. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
  197. package/build-types/image-editor/react/components/index.d.ts +4 -0
  198. package/build-types/image-editor/react/components/index.d.ts.map +1 -0
  199. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
  200. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
  201. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
  202. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
  203. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
  204. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
  205. package/build-types/image-editor/react/hooks/index.d.ts +3 -0
  206. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
  207. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
  208. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
  209. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
  210. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
  211. package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
  212. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
  213. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
  214. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
  215. package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
  216. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
  217. package/build-types/index.d.ts +1 -0
  218. package/build-types/index.d.ts.map +1 -1
  219. package/build-types/lock-unlock.d.ts +2 -0
  220. package/build-types/lock-unlock.d.ts.map +1 -0
  221. package/build-types/private-apis.d.ts +2 -0
  222. package/build-types/private-apis.d.ts.map +1 -0
  223. package/build-types/store/actions.d.ts +27 -0
  224. package/build-types/store/actions.d.ts.map +1 -0
  225. package/build-types/store/constants.d.ts +2 -0
  226. package/build-types/store/constants.d.ts.map +1 -0
  227. package/build-types/store/index.d.ts +4 -0
  228. package/build-types/store/index.d.ts.map +1 -0
  229. package/build-types/store/reducer.d.ts +23 -0
  230. package/build-types/store/reducer.d.ts.map +1 -0
  231. package/build-types/store/selectors.d.ts +8 -0
  232. package/build-types/store/selectors.d.ts.map +1 -0
  233. package/package.json +21 -7
  234. package/src/components/media-editor-canvas/index.tsx +56 -0
  235. package/src/components/media-editor-canvas/style.scss +9 -0
  236. package/src/components/media-editor-crop-panel/index.tsx +143 -0
  237. package/src/components/media-editor-modal/build-modifiers.ts +164 -0
  238. package/src/components/media-editor-modal/index.tsx +639 -0
  239. package/src/components/media-editor-modal/style.scss +139 -0
  240. package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
  241. package/src/components/media-editor-toolbar/index.tsx +150 -0
  242. package/src/components/media-editor-toolbar/style.scss +21 -0
  243. package/src/image-editor/README.md +162 -0
  244. package/src/image-editor/core/camera.ts +352 -0
  245. package/src/image-editor/core/constants.ts +93 -0
  246. package/src/image-editor/core/containment.ts +435 -0
  247. package/src/image-editor/core/export/canvas-renderer.ts +253 -0
  248. package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
  249. package/src/image-editor/core/index.ts +35 -0
  250. package/src/image-editor/core/interaction-controller.ts +889 -0
  251. package/src/image-editor/core/math/rotation.ts +26 -0
  252. package/src/image-editor/core/source-region.ts +166 -0
  253. package/src/image-editor/core/state.ts +428 -0
  254. package/src/image-editor/core/stencil-math.ts +330 -0
  255. package/src/image-editor/core/test/camera.ts +593 -0
  256. package/src/image-editor/core/test/interaction-controller.ts +996 -0
  257. package/src/image-editor/core/test/preview-export-parity.ts +242 -0
  258. package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
  259. package/src/image-editor/core/test/state.ts +762 -0
  260. package/src/image-editor/core/test/stencil-math.ts +321 -0
  261. package/src/image-editor/core/transform-style.ts +44 -0
  262. package/src/image-editor/core/transforms/pipeline.ts +43 -0
  263. package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
  264. package/src/image-editor/core/types.ts +177 -0
  265. package/src/image-editor/docs/architecture.md +96 -0
  266. package/src/image-editor/docs/recipes.md +720 -0
  267. package/src/image-editor/docs/roadmap.md +66 -0
  268. package/src/image-editor/index.ts +43 -0
  269. package/src/image-editor/react/components/cropper-provider.tsx +73 -0
  270. package/src/image-editor/react/components/cropper.scss +195 -0
  271. package/src/image-editor/react/components/cropper.tsx +534 -0
  272. package/src/image-editor/react/components/index.ts +3 -0
  273. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
  274. package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
  275. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
  276. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
  277. package/src/image-editor/react/components/test/cropper.tsx +140 -0
  278. package/src/image-editor/react/hooks/index.ts +2 -0
  279. package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
  280. package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
  281. package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
  282. package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
  283. package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
  284. package/src/image-editor/react/hooks/use-interaction.ts +223 -0
  285. package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
  286. package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
  287. package/src/image-editor/stories/style.css +94 -0
  288. package/src/image-editor/style.scss +1 -0
  289. package/src/index.ts +3 -0
  290. package/src/lock-unlock.ts +10 -0
  291. package/src/private-apis.ts +12 -0
  292. package/src/store/actions.ts +33 -0
  293. package/src/store/constants.ts +1 -0
  294. package/src/store/index.ts +20 -0
  295. package/src/store/reducer.ts +48 -0
  296. package/src/store/selectors.ts +16 -0
  297. package/src/store/test/reducer.ts +57 -0
  298. package/src/style.scss +4 -0
  299. package/tsconfig.json +10 -2
  300. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/media-editor-toolbar/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button, RangeControl } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useCropper } from '../../image-editor';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\n\nexport interface MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n}: MediaEditorToolbarProps ) {\n\tconst { state, setRotation, setFlip, snapRotate90, reset, isDirty } =\n\t\tuseCropper();\n\n\tconst handleReset = () => {\n\t\treset();\n\t\tonReset?.();\n\t};\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number | undefined ) => {\n\t\tif ( value === undefined ) {\n\t\t\treturn;\n\t\t}\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly \u00B1MAX lands state on a\n\t\t// 90\u00B0 midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className=\"media-editor-toolbar__rotation-slider\">\n\t\t\t\t<RangeControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tstep={ 0.5 }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleReset }\n\t\t\t>\n\t\t\t\t{ __( 'Reset' ) }\n\t\t\t</Button>\n\t\t</Stack>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,QAAQ,oBAAoB;AACrC,SAAS,aAAa;AACtB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AA2DlC,SAQC,KARD;AArCa,SAAR,mBAAqC;AAAA,EAC3C;AAAA,EACA;AACD,GAA6B;AAC5B,QAAM,EAAE,OAAO,aAAa,SAAS,cAAc,OAAO,QAAQ,IACjE,WAAW;AAEZ,QAAM,cAAc,MAAM;AACzB,UAAM;AACN,cAAU;AAAA,EACX;AAKA,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD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ACT,QAAS;AAAA,cACR,YAAY,MAAM,KAAK;AAAA,cACvB,UAAU,CAAE,MAAM,KAAK;AAAA,YACxB,CAAE;AAAA;AAAA,QAEJ;AAAA,QACA,oBAAC,SAAI,WAAU,yCACd;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACrB,yBAAuB;AAAA,YACvB,OAAQ,GAAI,eAAgB;AAAA,YAC5B,qBAAmB;AAAA,YACnB,KAAM,CAAC;AAAA,YACP,KAAM;AAAA,YACN,MAAO;AAAA,YACP,OAAQ;AAAA,YACR,UAAW;AAAA,YACX,aAAc;AAAA;AAAA,QACf,GACD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,MAAK;AAAA,YACL,SAAQ;AAAA,YACR,UAAW,CAAE;AAAA,YACb,wBAAsB;AAAA,YACtB,SAAU;AAAA,YAER,aAAI,OAAQ;AAAA;AAAA,QACf;AAAA;AAAA;AAAA,EACD;AAEF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,163 @@
1
+ // packages/media-editor/src/image-editor/core/camera.ts
2
+ import { mat2d, vec2 } from "gl-matrix";
3
+ import { degreesToRadians } from "./math/rotation.mjs";
4
+ var _scratchMat = mat2d.create();
5
+ var _scratchVec = vec2.create();
6
+ function getRotatedBBox(width, height, rotation) {
7
+ const rad = degreesToRadians(rotation);
8
+ const cosR = Math.abs(Math.cos(rad));
9
+ const sinR = Math.abs(Math.sin(rad));
10
+ return {
11
+ width: cosR * width + sinR * height,
12
+ height: sinR * width + cosR * height
13
+ };
14
+ }
15
+ function getImageFit(containerSize, imageSize, rotation) {
16
+ if (containerSize.width === 0 || containerSize.height === 0 || imageSize.width === 0 || imageSize.height === 0) {
17
+ return {
18
+ elementSize: { width: 0, height: 0 },
19
+ visualSize: { width: 0, height: 0 }
20
+ };
21
+ }
22
+ const snapRotation = Math.round(rotation / 90) * 90;
23
+ const naturalBBox = getRotatedBBox(
24
+ imageSize.width,
25
+ imageSize.height,
26
+ snapRotation
27
+ );
28
+ const fitScale = Math.min(
29
+ containerSize.width / naturalBBox.width,
30
+ containerSize.height / naturalBBox.height
31
+ );
32
+ const renderedW = imageSize.width * fitScale;
33
+ const renderedH = imageSize.height * fitScale;
34
+ const visualSize = getRotatedBBox(renderedW, renderedH, snapRotation);
35
+ return {
36
+ elementSize: { width: renderedW, height: renderedH },
37
+ visualSize
38
+ };
39
+ }
40
+ function createCamera(state, containerSize, imageSize) {
41
+ const m = mat2d.create();
42
+ if (containerSize.width === 0 || containerSize.height === 0 || imageSize.width === 0 || imageSize.height === 0) {
43
+ return m;
44
+ }
45
+ const snapRotation = Math.round(state.rotation / 90) * 90;
46
+ const naturalBBox = getRotatedBBox(
47
+ imageSize.width,
48
+ imageSize.height,
49
+ snapRotation
50
+ );
51
+ const fitScale = Math.min(
52
+ containerSize.width / naturalBBox.width,
53
+ containerSize.height / naturalBBox.height
54
+ );
55
+ const renderedW = imageSize.width * fitScale;
56
+ const renderedH = imageSize.height * fitScale;
57
+ const { width: visualW, height: visualH } = getRotatedBBox(
58
+ renderedW,
59
+ renderedH,
60
+ snapRotation
61
+ );
62
+ mat2d.translate(m, m, [
63
+ containerSize.width / 2,
64
+ containerSize.height / 2
65
+ ]);
66
+ mat2d.translate(m, m, [state.pan.x * visualW, state.pan.y * visualH]);
67
+ mat2d.scale(m, m, [
68
+ state.flip.horizontal ? -1 : 1,
69
+ state.flip.vertical ? -1 : 1
70
+ ]);
71
+ mat2d.rotate(m, m, degreesToRadians(state.rotation));
72
+ mat2d.scale(m, m, [state.zoom, state.zoom]);
73
+ mat2d.translate(m, m, [-renderedW / 2, -renderedH / 2]);
74
+ mat2d.scale(m, m, [renderedW, renderedH]);
75
+ return m;
76
+ }
77
+ function worldToScreen(camera, point) {
78
+ const out = vec2.create();
79
+ vec2.transformMat2d(out, [point.x, point.y], camera);
80
+ return { x: out[0], y: out[1] };
81
+ }
82
+ function screenToWorld(camera, point) {
83
+ mat2d.invert(_scratchMat, camera);
84
+ const out = _scratchVec;
85
+ vec2.transformMat2d(out, [point.x, point.y], _scratchMat);
86
+ return { x: out[0], y: out[1] };
87
+ }
88
+ function aabb(camera, corners) {
89
+ const screenCorners = corners.map((c) => {
90
+ const out = vec2.create();
91
+ vec2.transformMat2d(out, c, camera);
92
+ return out;
93
+ });
94
+ let minX = screenCorners[0][0];
95
+ let maxX = screenCorners[0][0];
96
+ let minY = screenCorners[0][1];
97
+ let maxY = screenCorners[0][1];
98
+ for (let i = 1; i < screenCorners.length; i++) {
99
+ const s = screenCorners[i];
100
+ if (s[0] < minX) {
101
+ minX = s[0];
102
+ }
103
+ if (s[0] > maxX) {
104
+ maxX = s[0];
105
+ }
106
+ if (s[1] < minY) {
107
+ minY = s[1];
108
+ }
109
+ if (s[1] > maxY) {
110
+ maxY = s[1];
111
+ }
112
+ }
113
+ return { left: minX, top: minY, width: maxX - minX, height: maxY - minY };
114
+ }
115
+ function getVisibleBounds(camera) {
116
+ return aabb(camera, [
117
+ [0, 0],
118
+ [1, 0],
119
+ [1, 1],
120
+ [0, 1]
121
+ ]);
122
+ }
123
+ function createExportCamera(state, imageSize, outputSize) {
124
+ const m = mat2d.create();
125
+ const { rotation, flip, cropRect, zoom, pan } = state;
126
+ if (imageSize.width === 0 || imageSize.height === 0 || outputSize.width === 0 || outputSize.height === 0) {
127
+ return m;
128
+ }
129
+ const snapRotation = Math.round(rotation / 90) * 90;
130
+ const { width: rotW, height: rotH } = getRotatedBBox(
131
+ imageSize.width,
132
+ imageSize.height,
133
+ snapRotation
134
+ );
135
+ const naturalCropW = cropRect.width * rotW;
136
+ const naturalCropH = cropRect.height * rotH;
137
+ const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
138
+ const outputScaleY = naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
139
+ const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
140
+ const cropOffsetY = cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
141
+ const visualCenterX = rotW / 2 + pan.x * rotW;
142
+ const visualCenterY = rotH / 2 + pan.y * rotH;
143
+ mat2d.scale(m, m, [outputScaleX, outputScaleY]);
144
+ mat2d.translate(m, m, [
145
+ visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,
146
+ visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY
147
+ ]);
148
+ mat2d.scale(m, m, [flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1]);
149
+ mat2d.rotate(m, m, degreesToRadians(rotation));
150
+ mat2d.scale(m, m, [zoom, zoom]);
151
+ mat2d.translate(m, m, [-imageSize.width / 2, -imageSize.height / 2]);
152
+ return m;
153
+ }
154
+ export {
155
+ createCamera,
156
+ createExportCamera,
157
+ getImageFit,
158
+ getRotatedBBox,
159
+ getVisibleBounds,
160
+ screenToWorld,
161
+ worldToScreen
162
+ };
163
+ //# sourceMappingURL=camera.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/image-editor/core/camera.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, Size, Camera } from './types';\nimport { degreesToRadians } from './math/rotation';\n\n// Pre-allocated scratch buffers for `screenToWorld`, which is called per\n// pointermove. Module-level singletons \u2014 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\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 (\n\t\tcontainerSize.width === 0 ||\n\t\tcontainerSize.height === 0 ||\n\t\timageSize.width === 0 ||\n\t\timageSize.height === 0\n\t) {\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\t// Snap rotation to the nearest 90\u00B0 multiple for layout sizing.\n\t// This keeps the stencil a stable size through fine \u00B145\u00B0 rotation\n\t// (no inflation at 15\u00B0/30\u00B0 etc.) while still swapping aspect at\n\t// 90\u00B0/180\u00B0/270\u00B0 so the snap rotate preserves the framed content.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\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 * 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 (\n\t\tcontainerSize.width === 0 ||\n\t\tcontainerSize.height === 0 ||\n\t\timageSize.width === 0 ||\n\t\timageSize.height === 0\n\t) {\n\t\treturn m;\n\t}\n\n\t// Use the nearest 90\u00B0 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( state.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// \"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, [ state.pan.x * visualW, state.pan.y * visualH ] );\n\n\t// Flip (viewport-relative \u2014 composed outside rotation so horizontal\n\t// flip always mirrors across the viewport's vertical axis).\n\tmat2d.scale( m, m, [\n\t\tstate.flip.horizontal ? -1 : 1,\n\t\tstate.flip.vertical ? -1 : 1,\n\t] );\n\n\t// Rotate.\n\tmat2d.rotate( m, m, degreesToRadians( state.rotation ) );\n\n\t// Zoom.\n\tmat2d.scale( m, m, [ state.zoom, state.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) \u2192 flip \u2192 rotate \u2192 zoom \u2192 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\tconst { rotation, flip, cropRect, zoom, pan } = state;\n\tif (\n\t\timageSize.width === 0 ||\n\t\timageSize.height === 0 ||\n\t\toutputSize.width === 0 ||\n\t\toutputSize.height === 0\n\t) {\n\t\treturn m;\n\t}\n\t// Reference frame for cropRect/pan is the snap-rotation bbox \u2014 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 \u2014\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": ";AAGA,SAAS,OAAO,YAAY;AAM5B,SAAS,wBAAwB;AAIjC,IAAM,cAAc,MAAM,OAAO;AACjC,IAAM,cAAc,KAAK,OAAO;AAUzB,SAAS,eACf,OACA,QACA,UACO;AACP,QAAM,MAAM,iBAAkB,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,MACC,cAAc,UAAU,KACxB,cAAc,WAAW,KACzB,UAAU,UAAU,KACpB,UAAU,WAAW,GACpB;AACD,WAAO;AAAA,MACN,aAAa,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,MACnC,YAAY,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,IACnC;AAAA,EACD;AAKA,QAAM,eAAe,KAAK,MAAO,WAAW,EAAG,IAAI;AACnD,QAAM,cAAc;AAAA,IACnB,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,EACD;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,cAAc,QAAQ,YAAY;AAAA,IAClC,cAAc,SAAS,YAAY;AAAA,EACpC;AACA,QAAM,YAAY,UAAU,QAAQ;AACpC,QAAM,YAAY,UAAU,SAAS;AACrC,QAAM,aAAa,eAAgB,WAAW,WAAW,YAAa;AACtE,SAAO;AAAA,IACN,aAAa,EAAE,OAAO,WAAW,QAAQ,UAAU;AAAA,IACnD;AAAA,EACD;AACD;AAoBO,SAAS,aACf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AAC,UAAU,QAAQ,GAAG,CAAC,UAAU,SAAS,CAAE,CAAE;AACvE,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,51 @@
1
+ // packages/media-editor/src/image-editor/core/constants.ts
2
+ import { __ } from "@wordpress/i18n";
3
+ var MIN_ZOOM = 1;
4
+ var MAX_ZOOM = 10;
5
+ var MAX_ROTATION_OFFSET = 45;
6
+ var DEFAULT_CROP_RECT = {
7
+ x: 0,
8
+ y: 0,
9
+ width: 1,
10
+ height: 1
11
+ };
12
+ var DEFAULT_FLIP = {
13
+ horizontal: false,
14
+ vertical: false
15
+ };
16
+ var DEFAULT_PAN = {
17
+ x: 0,
18
+ y: 0
19
+ };
20
+ var DEFAULT_STATE = {
21
+ image: null,
22
+ pan: { ...DEFAULT_PAN },
23
+ zoom: MIN_ZOOM,
24
+ rotation: 0,
25
+ basePan: { ...DEFAULT_PAN },
26
+ baseZoom: MIN_ZOOM,
27
+ baseRotation: 0,
28
+ flip: { ...DEFAULT_FLIP },
29
+ cropRect: { ...DEFAULT_CROP_RECT }
30
+ };
31
+ var ORIGINAL_ASPECT_RATIO = -1;
32
+ var DEFAULT_ASPECT_RATIOS = [
33
+ { label: __("Free"), value: 0 },
34
+ { label: __("Original"), value: ORIGINAL_ASPECT_RATIO },
35
+ { label: __("Square (1:1)"), value: 1 },
36
+ { label: __("Landscape (16:9)"), value: 16 / 9 },
37
+ { label: __("Portrait (9:16)"), value: 9 / 16 },
38
+ { label: __("Classic (4:3)"), value: 4 / 3 },
39
+ { label: __("Classic portrait (3:4)"), value: 3 / 4 },
40
+ { label: __("Photo (3:2)"), value: 3 / 2 },
41
+ { label: __("Photo portrait (2:3)"), value: 2 / 3 }
42
+ ];
43
+ export {
44
+ DEFAULT_ASPECT_RATIOS,
45
+ DEFAULT_STATE,
46
+ MAX_ROTATION_OFFSET,
47
+ MAX_ZOOM,
48
+ MIN_ZOOM,
49
+ ORIGINAL_ASPECT_RATIO
50
+ };
51
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/image-editor/core/constants.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\nexport const MIN_ZOOM = 1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90\u00B0 step.\n * The rotation slider allows \u00B145\u00B0 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 \u2014 resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],
5
+ "mappings": ";AAGA,SAAS,UAAU;AAOZ,IAAM,WAAW;AACjB,IAAM,WAAW;AAMjB,IAAM,sBAAsB;AAEnC,IAAM,oBAAoC;AAAA,EACzC,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,EACP,QAAQ;AACT;AAEA,IAAM,eAAqB;AAAA,EAC1B,YAAY;AAAA,EACZ,UAAU;AACX;AAEA,IAAM,cAAwC;AAAA,EAC7C,GAAG;AAAA,EACH,GAAG;AACJ;AAEO,IAAM,gBAA8B;AAAA,EAC1C,OAAO;AAAA,EACP,KAAK,EAAE,GAAG,YAAY;AAAA,EACtB,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS,EAAE,GAAG,YAAY;AAAA,EAC1B,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM,EAAE,GAAG,aAAa;AAAA,EACxB,UAAU,EAAE,GAAG,kBAAkB;AAClC;AAkCO,IAAM,wBAAwB;AAE9B,IAAM,wBAA6C;AAAA,EACzD,EAAE,OAAO,GAAI,MAAO,GAAG,OAAO,EAAE;AAAA,EAChC,EAAE,OAAO,GAAI,UAAW,GAAG,OAAO,sBAAsB;AAAA,EACxD,EAAE,OAAO,GAAI,cAAe,GAAG,OAAO,EAAE;AAAA,EACxC,EAAE,OAAO,GAAI,kBAAmB,GAAG,OAAO,KAAK,EAAE;AAAA,EACjD,EAAE,OAAO,GAAI,iBAAkB,GAAG,OAAO,IAAI,GAAG;AAAA,EAChD,EAAE,OAAO,GAAI,eAAgB,GAAG,OAAO,IAAI,EAAE;AAAA,EAC7C,EAAE,OAAO,GAAI,wBAAyB,GAAG,OAAO,IAAI,EAAE;AAAA,EACtD,EAAE,OAAO,GAAI,aAAc,GAAG,OAAO,IAAI,EAAE;AAAA,EAC3C,EAAE,OAAO,GAAI,sBAAuB,GAAG,OAAO,IAAI,EAAE;AACrD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,218 @@
1
+ // packages/media-editor/src/image-editor/core/containment.ts
2
+ import { mat2d, vec2 } from "gl-matrix";
3
+ import { degreesToRadians } from "./math/rotation.mjs";
4
+ import { createCamera, getRotatedBBox, getVisibleBounds } from "./camera.mjs";
5
+ var EPSILON = 1e-9;
6
+ function getVisualDimensions(rotation, imageAspectRatio) {
7
+ const rad = degreesToRadians(rotation);
8
+ const absC = Math.abs(Math.cos(rad));
9
+ const absS = Math.abs(Math.sin(rad));
10
+ const bbox = getRotatedBBox(imageAspectRatio, 1, rotation);
11
+ return {
12
+ visualW: bbox.width,
13
+ visualH: bbox.height,
14
+ absC,
15
+ absS
16
+ };
17
+ }
18
+ function getMinZoomForCover(rotation, imageAspectRatio, cropRect) {
19
+ const aspectRatio = Math.max(imageAspectRatio, Number.EPSILON);
20
+ const snapRotation = Math.round(rotation / 90) * 90;
21
+ const { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(
22
+ snapRotation,
23
+ aspectRatio
24
+ );
25
+ const { absC, absS } = getVisualDimensions(rotation, aspectRatio);
26
+ const cropHalfW = cropRect.width * snapVisualW / 2;
27
+ const cropHalfH = cropRect.height * snapVisualH / 2;
28
+ const spanAlpha = cropHalfW * absC + cropHalfH * absS;
29
+ const spanBeta = cropHalfW * absS + cropHalfH * absC;
30
+ const zoomFromAlpha = 2 * spanAlpha / aspectRatio;
31
+ const zoomFromBeta = 2 * spanBeta;
32
+ return Math.max(1, zoomFromAlpha, zoomFromBeta);
33
+ }
34
+ function getCropBounds(state, elementSize, visualSize, containerSize) {
35
+ if (elementSize.width === 0 || elementSize.height === 0 || visualSize.width === 0 || visualSize.height === 0) {
36
+ return { minX: 0, minY: 0, maxX: 1, maxY: 1 };
37
+ }
38
+ const tx = state.pan.x * visualSize.width;
39
+ const ty = state.pan.y * visualSize.height;
40
+ const rad = degreesToRadians(state.rotation);
41
+ const cos = Math.cos(rad);
42
+ const sin = Math.sin(rad);
43
+ const sx = state.flip.horizontal ? -1 : 1;
44
+ const sy = state.flip.vertical ? -1 : 1;
45
+ const z = state.zoom;
46
+ const ma = sx * cos * z;
47
+ const mb = sy * sin * z;
48
+ const mc = -sx * sin * z;
49
+ const md = sy * cos * z;
50
+ const hw = elementSize.width / 2;
51
+ const hh = elementSize.height / 2;
52
+ const corners = [
53
+ [-hw, -hh],
54
+ [hw, -hh],
55
+ [hw, hh],
56
+ [-hw, hh]
57
+ ];
58
+ const offsetX = (containerSize.width - visualSize.width) / 2;
59
+ const offsetY = (containerSize.height - visualSize.height) / 2;
60
+ let imgMinX = Infinity;
61
+ let imgMaxX = -Infinity;
62
+ let imgMinY = Infinity;
63
+ let imgMaxY = -Infinity;
64
+ for (const [cx, cy] of corners) {
65
+ const screenX = ma * cx + mc * cy + tx;
66
+ const screenY = mb * cx + md * cy + ty;
67
+ const nx = screenX / visualSize.width + 0.5;
68
+ const ny = screenY / visualSize.height + 0.5;
69
+ imgMinX = Math.min(imgMinX, nx);
70
+ imgMaxX = Math.max(imgMaxX, nx);
71
+ imgMinY = Math.min(imgMinY, ny);
72
+ imgMaxY = Math.max(imgMaxY, ny);
73
+ }
74
+ const containerMinX = -offsetX / visualSize.width;
75
+ const containerMaxX = (containerSize.width - offsetX) / visualSize.width;
76
+ const containerMinY = -offsetY / visualSize.height;
77
+ const containerMaxY = (containerSize.height - offsetY) / visualSize.height;
78
+ return {
79
+ minX: Math.max(imgMinX, containerMinX),
80
+ minY: Math.max(imgMinY, containerMinY),
81
+ maxX: Math.min(imgMaxX, containerMaxX),
82
+ maxY: Math.min(imgMaxY, containerMaxY)
83
+ };
84
+ }
85
+ function restrictCropRect(cropRect, zoom, rotation, imageAspectRatio) {
86
+ const aspectRatio = Math.max(imageAspectRatio, Number.EPSILON);
87
+ const snapRotation = Math.round(rotation / 90) * 90;
88
+ const { visualW, visualH } = getVisualDimensions(
89
+ snapRotation,
90
+ aspectRatio
91
+ );
92
+ const { absC, absS } = getVisualDimensions(rotation, aspectRatio);
93
+ const W = cropRect.width;
94
+ const H = cropRect.height;
95
+ const cropWPx = W * visualW;
96
+ const cropHPx = H * visualH;
97
+ const spanAlpha = cropWPx * absC + cropHPx * absS;
98
+ const spanBeta = cropWPx * absS + cropHPx * absC;
99
+ const limitAlpha = aspectRatio * zoom;
100
+ const limitBeta = zoom;
101
+ let t = 1;
102
+ if (spanAlpha > 0) {
103
+ t = Math.min(t, limitAlpha / spanAlpha);
104
+ }
105
+ if (spanBeta > 0) {
106
+ t = Math.min(t, limitBeta / spanBeta);
107
+ }
108
+ if (t >= 1 - EPSILON) {
109
+ return cropRect;
110
+ }
111
+ const newW = W * t;
112
+ const newH = H * t;
113
+ const centerX = cropRect.x + W / 2;
114
+ const centerY = cropRect.y + H / 2;
115
+ let newX = centerX - newW / 2;
116
+ let newY = centerY - newH / 2;
117
+ newX = Math.max(0, Math.min(newX, 1 - newW));
118
+ newY = Math.max(0, Math.min(newY, 1 - newH));
119
+ return { x: newX, y: newY, width: newW, height: newH };
120
+ }
121
+ var CANONICAL_CONTAINER = { width: 1e3, height: 1e3 };
122
+ var _scratchMat = mat2d.create();
123
+ var _scratchVec = vec2.create();
124
+ function restrictPanZoom(state, imageSize, cropRect) {
125
+ const aspectRatio = imageSize.width > 0 && imageSize.height > 0 ? imageSize.width / imageSize.height : 1;
126
+ const minZoom = getMinZoomForCover(state.rotation, aspectRatio, cropRect);
127
+ const zoom = Math.max(state.zoom, minZoom);
128
+ const candidateState = { ...state, zoom };
129
+ const camera = createCamera(
130
+ candidateState,
131
+ CANONICAL_CONTAINER,
132
+ imageSize
133
+ );
134
+ const snapRotation = Math.round(state.rotation / 90) * 90;
135
+ const baseCamera = createCamera(
136
+ {
137
+ ...candidateState,
138
+ pan: { x: 0, y: 0 },
139
+ zoom: 1,
140
+ rotation: snapRotation
141
+ },
142
+ CANONICAL_CONTAINER,
143
+ imageSize
144
+ );
145
+ const visibleBounds = getVisibleBounds(baseCamera);
146
+ const stencilCorners = [
147
+ [
148
+ visibleBounds.left + cropRect.x * visibleBounds.width,
149
+ visibleBounds.top + cropRect.y * visibleBounds.height
150
+ ],
151
+ [
152
+ visibleBounds.left + (cropRect.x + cropRect.width) * visibleBounds.width,
153
+ visibleBounds.top + cropRect.y * visibleBounds.height
154
+ ],
155
+ [
156
+ visibleBounds.left + (cropRect.x + cropRect.width) * visibleBounds.width,
157
+ visibleBounds.top + (cropRect.y + cropRect.height) * visibleBounds.height
158
+ ],
159
+ [
160
+ visibleBounds.left + cropRect.x * visibleBounds.width,
161
+ visibleBounds.top + (cropRect.y + cropRect.height) * visibleBounds.height
162
+ ]
163
+ ];
164
+ mat2d.invert(_scratchMat, camera);
165
+ let minWx = Infinity;
166
+ let maxWx = -Infinity;
167
+ let minWy = Infinity;
168
+ let maxWy = -Infinity;
169
+ for (const corner of stencilCorners) {
170
+ vec2.transformMat2d(_scratchVec, corner, _scratchMat);
171
+ const w = _scratchVec;
172
+ if (w[0] < minWx) {
173
+ minWx = w[0];
174
+ }
175
+ if (w[0] > maxWx) {
176
+ maxWx = w[0];
177
+ }
178
+ if (w[1] < minWy) {
179
+ minWy = w[1];
180
+ }
181
+ if (w[1] > maxWy) {
182
+ maxWy = w[1];
183
+ }
184
+ }
185
+ if (minWx >= -EPSILON && maxWx <= 1 + EPSILON && minWy >= -EPSILON && maxWy <= 1 + EPSILON) {
186
+ return { pan: state.pan, zoom };
187
+ }
188
+ let dwx = 0;
189
+ let dwy = 0;
190
+ if (minWx < 0 && maxWx <= 1 + EPSILON) {
191
+ dwx = -minWx;
192
+ } else if (maxWx > 1 && minWx >= -EPSILON) {
193
+ dwx = 1 - maxWx;
194
+ } else if (minWx < 0 && maxWx > 1) {
195
+ dwx = (1 - maxWx - minWx) / 2;
196
+ }
197
+ if (minWy < 0 && maxWy <= 1 + EPSILON) {
198
+ dwy = -minWy;
199
+ } else if (maxWy > 1 && minWy >= -EPSILON) {
200
+ dwy = 1 - maxWy;
201
+ } else if (minWy < 0 && maxWy > 1) {
202
+ dwy = (1 - maxWy - minWy) / 2;
203
+ }
204
+ const dsx = camera[0] * dwx + camera[2] * dwy;
205
+ const dsy = camera[1] * dwx + camera[3] * dwy;
206
+ const newPanX = state.pan.x - (visibleBounds.width > 0 ? dsx / visibleBounds.width : 0);
207
+ const newPanY = state.pan.y - (visibleBounds.height > 0 ? dsy / visibleBounds.height : 0);
208
+ return {
209
+ pan: { x: newPanX, y: newPanY },
210
+ zoom
211
+ };
212
+ }
213
+ export {
214
+ getCropBounds,
215
+ restrictCropRect,
216
+ restrictPanZoom
217
+ };
218
+ //# sourceMappingURL=containment.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/image-editor/core/containment.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * Calculates the minimum zoom factor needed for the rotated image to fully cover\n * the crop rectangle, using normalized coordinates and imageAspectRatio.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n * The crop rect is in visual-normalized space and must be scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor (always >= 1).\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( 1, zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space by finding the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation, then intersecting with the container viewport.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @param containerSize The container dimensions in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size,\n\tcontainerSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif (\n\t\telementSize.width === 0 ||\n\t\telementSize.height === 0 ||\n\t\tvisualSize.width === 0 ||\n\t\tvisualSize.height === 0\n\t) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = state.pan.x * visualSize.width;\n\tconst ty = state.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( state.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = state.flip.horizontal ? -1 : 1;\n\tconst sy = state.flip.vertical ? -1 : 1;\n\tconst z = state.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\t// Transform corners through CSS matrix \u2192 screen offsets from element center.\n\t// Screen position = element_center + transformed_offset.\n\t// Element center is at (containerW/2, containerH/2) after CSS centering.\n\t// But we want normalized coords, so work relative to the visual image origin.\n\tconst offsetX = ( containerSize.width - visualSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - visualSize.height ) / 2;\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\t// Container bounds in normalized space.\n\tconst containerMinX = -offsetX / visualSize.width;\n\tconst containerMaxX = ( containerSize.width - offsetX ) / visualSize.width;\n\tconst containerMinY = -offsetY / visualSize.height;\n\tconst containerMaxY =\n\t\t( containerSize.height - offsetY ) / visualSize.height;\n\n\t// Crop bounds = intersection of image AABB and container bounds.\n\treturn {\n\t\tminX: Math.max( imgMinX, containerMinX ),\n\t\tminY: Math.max( imgMinY, containerMinY ),\n\t\tmaxX: Math.min( imgMaxX, containerMaxX ),\n\t\tmaxY: Math.min( imgMaxY, containerMaxY ),\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\tconst W = cropRect.width;\n\tconst H = cropRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * zoom;\n\tconst limitBeta = zoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Position is handled by restrictPanZoom, not here.\n\t\treturn cropRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = cropRect.x + W / 2;\n\tconst centerY = cropRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst aspectRatio =\n\t\timageSize.width > 0 && imageSize.height > 0\n\t\t\t? imageSize.width / imageSize.height\n\t\t\t: 1;\n\tconst minZoom = getMinZoomForCover( state.rotation, aspectRatio, cropRect );\n\tconst zoom = Math.max( state.zoom, minZoom );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...state, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: state.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tstate.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tstate.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: newPanY },\n\t\tzoom,\n\t};\n}\n"],
5
+ "mappings": ";AAGA,SAAS,OAAO,YAAY;AAM5B,SAAS,wBAAwB;AACjC,SAAS,cAAc,gBAAgB,wBAAwB;AAG/D,IAAM,UAAU;AAUhB,SAAS,oBACR,UACA,kBACmE;AACnE,QAAM,MAAM,iBAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,eAAgB,kBAAkB,GAAG,QAAS;AAC3D,SAAO;AAAA,IACN,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,IACd;AAAA,IACA;AAAA,EACD;AACD;AAgBA,SAAS,mBACR,UACA,kBACA,UACS;AACT,QAAM,cAAc,KAAK,IA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