@wordpress/media-editor 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -1,249 +0,0 @@
1
- /**
2
- * Preview ↔ Export parity — the load-bearing invariant of an image cropper.
3
- *
4
- * "What you see in the stencil is what you get in the exported file."
5
- * If this ever breaks silently, users can't trust the tool.
6
- *
7
- * How the test works (read this before changing anything):
8
- *
9
- * 1. Pick a state (rotation, zoom, pan, flip, cropRect).
10
- * 2. Pick a position (u, v) inside the crop rect, where (0,0) is the
11
- * stencil's top-left and (1,1) is its bottom-right.
12
- * 3. Compute the source-image pixel the PREVIEW shows at (u, v):
13
- * - Screen point = stencil origin + (u, v) * stencil size.
14
- * - Inverse of createCamera → world → × imageSize → source pixel.
15
- * 4. Compute the source-image pixel the EXPORT picks at the SAME (u, v):
16
- * - Output canvas point = (u * outW, v * outH).
17
- * - Inverse of createExportCamera → source pixel.
18
- * 5. Assert they agree.
19
- *
20
- * The (u, v) parametrization is deliberate: both the preview and the
21
- * export map the same (u, v) back to a source pixel through entirely
22
- * different code paths. If the two paths disagree anywhere in the
23
- * rotation / zoom / pan / flip / crop / output-size space, the
24
- * invariant has been broken and users see something different from
25
- * what they download.
26
- *
27
- * Why this is load-bearing: the crop regression that shifted exports
28
- * sideways during fine rotation would have been caught by this test —
29
- * the center would agree (symmetric bug) but the corners would drift.
30
- */
31
- import { describe, expect, it } from 'vitest';
32
- import { mat2d, vec2 } from 'gl-matrix';
33
- import {
34
- createCamera,
35
- createExportCamera,
36
- screenToWorld,
37
- getVisibleBounds,
38
- } from '../camera';
39
- import { DEFAULT_STATE } from '../constants';
40
- import type { CropperState, Size } from '../types';
41
-
42
- const CONTAINER: Size = { width: 800, height: 600 };
43
- const IMAGE: Size = { width: 1600, height: 900 };
44
-
45
- function makeState( overrides: Partial< CropperState > = {} ): CropperState {
46
- return {
47
- ...DEFAULT_STATE,
48
- image: {
49
- src: 'test.jpg',
50
- naturalWidth: IMAGE.width,
51
- naturalHeight: IMAGE.height,
52
- },
53
- ...overrides,
54
- };
55
- }
56
-
57
- // (u, v) = (0, 0) is the stencil's top-left, (1, 1) is bottom-right.
58
- function stencilScreenPoint(
59
- state: CropperState,
60
- container: Size,
61
- imageSize: Size,
62
- u: number,
63
- v: number
64
- ): { x: number; y: number } {
65
- // The stencil lives in the snap-rotation visible bounds (that's
66
- // how the render path positions it — see rectangle-stencil.tsx
67
- // and the snap rotation logic in createCamera).
68
- const snapRotation = Math.round( state.rotation / 90 ) * 90;
69
- const baseCamera = createCamera(
70
- {
71
- ...state,
72
- pan: { x: 0, y: 0 },
73
- zoom: 1,
74
- rotation: snapRotation,
75
- },
76
- container,
77
- imageSize
78
- );
79
- const vb = getVisibleBounds( baseCamera );
80
- const cr = state.cropRect;
81
- return {
82
- x: vb.left + ( cr.x + u * cr.width ) * vb.width,
83
- y: vb.top + ( cr.y + v * cr.height ) * vb.height,
84
- };
85
- }
86
-
87
- function previewSourcePixel(
88
- state: CropperState,
89
- container: Size,
90
- imageSize: Size,
91
- screen: { x: number; y: number }
92
- ): { x: number; y: number } {
93
- const camera = createCamera( state, container, imageSize );
94
- const world = screenToWorld( camera, screen );
95
- return {
96
- x: world.x * imageSize.width,
97
- y: world.y * imageSize.height,
98
- };
99
- }
100
-
101
- function exportSourcePixel(
102
- state: CropperState,
103
- imageSize: Size,
104
- outputSize: Size,
105
- outputPoint: { x: number; y: number }
106
- ): { x: number; y: number } {
107
- const camera = createExportCamera( state, imageSize, outputSize );
108
- const inv = mat2d.create();
109
- mat2d.invert( inv, camera );
110
- const out = vec2.create();
111
- vec2.transformMat2d( out, [ outputPoint.x, outputPoint.y ], inv );
112
- return { x: out[ 0 ], y: out[ 1 ] };
113
- }
114
-
115
- // Five probe points: 4 corners + center. Corners catch offset/scale
116
- // drift, center catches uniform bugs, and the asymmetric "interior"
117
- // cases below add two more via the test matrix.
118
- const PROBES: { label: string; u: number; v: number }[] = [
119
- { label: 'top-left', u: 0, v: 0 },
120
- { label: 'top-right', u: 1, v: 0 },
121
- { label: 'bottom-right', u: 1, v: 1 },
122
- { label: 'bottom-left', u: 0, v: 1 },
123
- { label: 'center', u: 0.5, v: 0.5 },
124
- { label: 'interior-1', u: 0.3, v: 0.7 },
125
- { label: 'interior-2', u: 0.8, v: 0.25 },
126
- ];
127
-
128
- // All (state × output-size × probe) combinations flattened into rows.
129
- // Each row is self-describing; on failure, the label
130
- // pinpoints the exact state and probe point where preview / export
131
- // disagreed.
132
- interface ParityRow {
133
- label: string;
134
- state: CropperState;
135
- outputSize: Size;
136
- probeLabel: string;
137
- u: number;
138
- v: number;
139
- }
140
-
141
- function buildRows(): ParityRow[] {
142
- const rotations = [ 0, 15, 45, 60, 90, 135, 200, 270 ];
143
- const zooms = [ 1, 1.5, 2.5 ];
144
- const pans = [
145
- { x: 0, y: 0 },
146
- { x: 0.08, y: -0.05 },
147
- { x: -0.1, y: 0.12 },
148
- ];
149
- const flips = [
150
- { horizontal: false, vertical: false },
151
- { horizontal: true, vertical: false },
152
- { horizontal: false, vertical: true },
153
- { horizontal: true, vertical: true },
154
- ];
155
- const cropRects = [
156
- { label: 'full', rect: { x: 0, y: 0, width: 1, height: 1 } },
157
- {
158
- label: 'centered',
159
- rect: { x: 0.25, y: 0.25, width: 0.5, height: 0.5 },
160
- },
161
- {
162
- label: 'off-center',
163
- rect: { x: 0.1, y: 0.2, width: 0.45, height: 0.55 },
164
- },
165
- ];
166
- const outputSizes: Size[] = [
167
- { width: 400, height: 300 },
168
- { width: 1024, height: 768 },
169
- ];
170
-
171
- const rows: ParityRow[] = [];
172
- for ( const rotation of rotations ) {
173
- for ( const zoom of zooms ) {
174
- for ( const pan of pans ) {
175
- for ( const flip of flips ) {
176
- for ( const { label: cropLabel, rect } of cropRects ) {
177
- for ( const outputSize of outputSizes ) {
178
- const flipLabel = `${
179
- flip.horizontal ? 'H' : '-'
180
- }${ flip.vertical ? 'V' : '-' }`;
181
- const stateLabel = `rot=${ rotation } zoom=${ zoom } pan=(${ pan.x },${ pan.y }) flip=${ flipLabel } crop=${ cropLabel } out=${ outputSize.width }x${ outputSize.height }`;
182
- const state = makeState( {
183
- rotation,
184
- zoom,
185
- pan,
186
- flip,
187
- cropRect: rect,
188
- } );
189
- for ( const {
190
- label: probeLabel,
191
- u,
192
- v,
193
- } of PROBES ) {
194
- rows.push( {
195
- label: `${ stateLabel } probe=${ probeLabel }`,
196
- state,
197
- outputSize,
198
- probeLabel,
199
- u,
200
- v,
201
- } );
202
- }
203
- }
204
- }
205
- }
206
- }
207
- }
208
- }
209
- return rows;
210
- }
211
-
212
- describe( 'Preview ↔ Export parity', () => {
213
- // Parametric sweep: same (u, v) inside the stencil → same source
214
- // pixel, across rotations × zooms × pans × flips × crop rects ×
215
- // output sizes. 5 + 2 probes per state (corners, center, two
216
- // asymmetric interior points) catch drift the center alone would
217
- // miss.
218
- const rows = buildRows();
219
-
220
- for ( const { label, state, outputSize, u, v } of rows ) {
221
- it( label, () => {
222
- const screen = stencilScreenPoint( state, CONTAINER, IMAGE, u, v );
223
- const outputPoint = {
224
- x: u * outputSize.width,
225
- y: v * outputSize.height,
226
- };
227
- const preview = previewSourcePixel(
228
- state,
229
- CONTAINER,
230
- IMAGE,
231
- screen
232
- );
233
- const exported = exportSourcePixel(
234
- state,
235
- IMAGE,
236
- outputSize,
237
- outputPoint
238
- );
239
-
240
- // Tolerance of 1 source pixel. Intermediate scale factors differ
241
- // between the preview (container pixels) and export (output
242
- // pixels) paths, so sub-pixel agreement is unrealistic. A drift
243
- // of ~1px is still visibly correct; anything larger is a real
244
- // coordinate-system mismatch.
245
- expect( preview.x ).toBeCloseTo( exported.x, 0 );
246
- expect( preview.y ).toBeCloseTo( exported.y, 0 );
247
- } );
248
- }
249
- } );
@@ -1,349 +0,0 @@
1
- /**
2
- * Render–Camera Bridge Tests
3
- *
4
- * The image cropper has two parallel code paths that must agree:
5
- *
6
- * 1. **Render path** — manual cos/sin math in `computeTransformStyle`
7
- * (CSS matrix) and stencil positioning (offset + cropRect × visualSize).
8
- * This is what the user sees on screen.
9
- *
10
- * 2. **Camera path** — `createCamera` builds a `mat2d` matrix used by
11
- * `restrictPanZoom` and `getSourceRegion` to enforce containment and
12
- * compute export coordinates.
13
- *
14
- * If either path changes without updating the other, the image will
15
- * appear to cover the crop area on screen but the restriction says it
16
- * doesn't (or vice versa). These tests catch that drift by computing
17
- * the same positions through both paths and asserting they agree.
18
- *
19
- * If you change:
20
- * - `computeTransformStyle` (transform-style.ts)
21
- * - `createCamera` (camera.ts)
22
- * - Stencil positioning formula (rectangle-stencil.tsx)
23
- * - `getImageFit` (camera.ts)
24
- *
25
- * ...run these tests to verify the two paths still agree.
26
- */
27
- import { describe, expect, it } from 'vitest';
28
- import {
29
- createCamera,
30
- worldToScreen,
31
- getImageFit,
32
- getVisibleBounds,
33
- } from '../camera';
34
- import { computeTransformStyle } from '../transform-style';
35
- import { DEFAULT_STATE } from '../constants';
36
- import type { CropperState, Size } from '../types';
37
-
38
- const CONTAINER: Size = { width: 800, height: 600 };
39
- const IMAGE: Size = { width: 1600, height: 900 };
40
-
41
- /**
42
- * Create a test state with an image loaded.
43
- *
44
- * @param overrides Partial state overrides.
45
- * @return A complete CropperState with image set.
46
- */
47
- function makeState( overrides: Partial< CropperState > = {} ): CropperState {
48
- return {
49
- ...DEFAULT_STATE,
50
- image: {
51
- src: 'test.jpg',
52
- naturalWidth: IMAGE.width,
53
- naturalHeight: IMAGE.height,
54
- },
55
- ...overrides,
56
- };
57
- }
58
-
59
- /**
60
- * Compute the stencil corner positions using the render path.
61
- *
62
- * This replicates the exact math from rectangle-stencil.tsx:
63
- * offsetX = (containerW - visualW) / 2
64
- * left = offsetX + cropRect.x * visualW
65
- * top = offsetY + cropRect.y * visualH
66
- *
67
- * @param state The cropper state.
68
- * @param containerSize The container dimensions.
69
- * @param imageSize The natural image dimensions.
70
- * @return The four stencil corners in screen pixels.
71
- */
72
- function stencilCornersViaCssPath(
73
- state: CropperState,
74
- containerSize: Size,
75
- imageSize: Size
76
- ): { x: number; y: number }[] {
77
- const { visualSize } = getImageFit(
78
- containerSize,
79
- imageSize,
80
- state.rotation
81
- );
82
- const offsetX = ( containerSize.width - visualSize.width ) / 2;
83
- const offsetY = ( containerSize.height - visualSize.height ) / 2;
84
- const cr = state.cropRect;
85
-
86
- return [
87
- {
88
- x: offsetX + cr.x * visualSize.width,
89
- y: offsetY + cr.y * visualSize.height,
90
- },
91
- {
92
- x: offsetX + ( cr.x + cr.width ) * visualSize.width,
93
- y: offsetY + cr.y * visualSize.height,
94
- },
95
- {
96
- x: offsetX + ( cr.x + cr.width ) * visualSize.width,
97
- y: offsetY + ( cr.y + cr.height ) * visualSize.height,
98
- },
99
- {
100
- x: offsetX + cr.x * visualSize.width,
101
- y: offsetY + ( cr.y + cr.height ) * visualSize.height,
102
- },
103
- ];
104
- }
105
-
106
- /**
107
- * Compute the stencil corner positions using the camera path.
108
- *
109
- * This replicates the exact math from restrictPanZoom in containment.ts:
110
- * baseCamera = createCamera(state with zoom=1, pan=0)
111
- * visibleBounds = getVisibleBounds(baseCamera)
112
- * stencilX = visibleBounds.left + cropRect.x * visibleBounds.width
113
- *
114
- * @param state The cropper state.
115
- * @param containerSize The container dimensions.
116
- * @param imageSize The natural image dimensions.
117
- * @return The four stencil corners in screen pixels.
118
- */
119
- function stencilCornersViaCameraPath(
120
- state: CropperState,
121
- containerSize: Size,
122
- imageSize: Size
123
- ): { x: number; y: number }[] {
124
- const baseCamera = createCamera(
125
- { ...state, pan: { x: 0, y: 0 }, zoom: 1 },
126
- containerSize,
127
- imageSize
128
- );
129
- const vb = getVisibleBounds( baseCamera );
130
- const cr = state.cropRect;
131
-
132
- return [
133
- {
134
- x: vb.left + cr.x * vb.width,
135
- y: vb.top + cr.y * vb.height,
136
- },
137
- {
138
- x: vb.left + ( cr.x + cr.width ) * vb.width,
139
- y: vb.top + cr.y * vb.height,
140
- },
141
- {
142
- x: vb.left + ( cr.x + cr.width ) * vb.width,
143
- y: vb.top + ( cr.y + cr.height ) * vb.height,
144
- },
145
- {
146
- x: vb.left + cr.x * vb.width,
147
- y: vb.top + ( cr.y + cr.height ) * vb.height,
148
- },
149
- ];
150
- }
151
-
152
- /**
153
- * Compute where an image-center point ends up on screen using the
154
- * render path (the CSS matrix from computeTransformStyle).
155
- *
156
- * The CSS matrix is applied with transform-origin: center center,
157
- * relative to the element. The element is centered in the container.
158
- * So screen position = containerCenter + matrix × (point - elementCenter).
159
- *
160
- * @param state The cropper state.
161
- * @param containerSize The container dimensions.
162
- * @param imageSize The natural image dimensions.
163
- * @param normPoint The point in normalized [0,1] image space.
164
- * @param normPoint.x Horizontal coordinate (0 = left, 1 = right).
165
- * @param normPoint.y Vertical coordinate (0 = top, 1 = bottom).
166
- * @return The screen pixel position.
167
- */
168
- function pointViaCssPath(
169
- state: CropperState,
170
- containerSize: Size,
171
- imageSize: Size,
172
- normPoint: { x: number; y: number }
173
- ): { x: number; y: number } {
174
- const { elementSize, visualSize } = getImageFit(
175
- containerSize,
176
- imageSize,
177
- state.rotation
178
- );
179
-
180
- // computeTransformStyle receives visualSize (the rotated bounding box),
181
- // matching what cropper.tsx passes in production.
182
- const matrixStr = computeTransformStyle( state, visualSize );
183
- const match = matrixStr.match(
184
- /matrix\(([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^)]+)\)/
185
- );
186
- const [ , a, b, c, d, tx, ty ] = match!.map( Number );
187
-
188
- // The point in rendered-pixel space (relative to element origin).
189
- const px = normPoint.x * elementSize.width;
190
- const py = normPoint.y * elementSize.height;
191
-
192
- // CSS transform-origin is element center.
193
- const cx = elementSize.width / 2;
194
- const cy = elementSize.height / 2;
195
-
196
- // Apply the matrix around the center origin, then translate
197
- // to container center (where the element is positioned).
198
- const dx = px - cx;
199
- const dy = py - cy;
200
- return {
201
- x: containerSize.width / 2 + a * dx + c * dy + tx,
202
- y: containerSize.height / 2 + b * dx + d * dy + ty,
203
- };
204
- }
205
-
206
- /**
207
- * Compute where an image point ends up on screen using the camera path.
208
- *
209
- * @param state The cropper state.
210
- * @param containerSize The container dimensions.
211
- * @param imageSize The natural image dimensions.
212
- * @param normPoint The point in normalized [0,1] image space.
213
- * @param normPoint.x Horizontal coordinate (0 = left, 1 = right).
214
- * @param normPoint.y Vertical coordinate (0 = top, 1 = bottom).
215
- * @return The screen pixel position.
216
- */
217
- function pointViaCameraPath(
218
- state: CropperState,
219
- containerSize: Size,
220
- imageSize: Size,
221
- normPoint: { x: number; y: number }
222
- ): { x: number; y: number } {
223
- const camera = createCamera( state, containerSize, imageSize );
224
- return worldToScreen( camera, normPoint );
225
- }
226
-
227
- describe( 'Render–Camera bridge: stencil positioning', () => {
228
- // Stencil positioning uses the snapped rotation for layout (see
229
- // getImageFit), which matches the camera path at 90° multiples but
230
- // diverges during fine rotation (±15°, ±30°, etc.). The CSS stencil
231
- // stays put while the image visibly rotates behind it — this is the
232
- // fixed-stencil layout. Only the snap-multiple angles are expected
233
- // to have exact agreement between the two paths.
234
- const SNAP_ROTATIONS = [ 0, 90, 180, 270 ];
235
- const CROP_RECTS = [
236
- { x: 0, y: 0, width: 1, height: 1 },
237
- { x: 0.1, y: 0.1, width: 0.8, height: 0.8 },
238
- { x: 0.25, y: 0.3, width: 0.5, height: 0.4 },
239
- ];
240
-
241
- for ( const rotation of SNAP_ROTATIONS ) {
242
- for ( const cropRect of CROP_RECTS ) {
243
- const label = `rotation=${ rotation }° crop=${ cropRect.width }×${ cropRect.height }`;
244
- it( `stencil corners agree at ${ label }`, () => {
245
- const state = makeState( { rotation, cropRect } );
246
- const stencilCorners = stencilCornersViaCssPath(
247
- state,
248
- CONTAINER,
249
- IMAGE
250
- );
251
- const cameraCorners = stencilCornersViaCameraPath(
252
- state,
253
- CONTAINER,
254
- IMAGE
255
- );
256
-
257
- for ( let i = 0; i < 4; i++ ) {
258
- expect( stencilCorners[ i ].x ).toBeCloseTo(
259
- cameraCorners[ i ].x,
260
- 1
261
- );
262
- expect( stencilCorners[ i ].y ).toBeCloseTo(
263
- cameraCorners[ i ].y,
264
- 1
265
- );
266
- }
267
- } );
268
- }
269
- }
270
- } );
271
-
272
- describe( 'Render–Camera bridge: image point projection', () => {
273
- const TEST_POINTS = [
274
- { x: 0, y: 0 },
275
- { x: 0.5, y: 0.5 },
276
- { x: 1, y: 1 },
277
- { x: 0.25, y: 0.75 },
278
- ];
279
- const TEST_STATES = [
280
- { label: 'identity', overrides: {} },
281
- { label: 'zoom=2', overrides: { zoom: 2 } },
282
- {
283
- label: 'rotation=30 zoom=1.5',
284
- overrides: { rotation: 30, zoom: 1.5 },
285
- },
286
- {
287
- label: 'flip-h rotation=45',
288
- overrides: {
289
- flip: { horizontal: true, vertical: false },
290
- rotation: 45,
291
- },
292
- },
293
- {
294
- label: 'pan + zoom + rotation',
295
- overrides: {
296
- pan: { x: 0.05, y: -0.03 },
297
- zoom: 2,
298
- rotation: 15,
299
- },
300
- },
301
- ];
302
-
303
- for ( const { label, overrides } of TEST_STATES ) {
304
- for ( const point of TEST_POINTS ) {
305
- it( `(${ point.x },${ point.y }) agrees at ${ label }`, () => {
306
- const state = makeState( overrides );
307
- const cssPos = pointViaCssPath(
308
- state,
309
- CONTAINER,
310
- IMAGE,
311
- point
312
- );
313
- const cameraPos = pointViaCameraPath(
314
- state,
315
- CONTAINER,
316
- IMAGE,
317
- point
318
- );
319
-
320
- expect( cssPos.x ).toBeCloseTo( cameraPos.x, 0 );
321
- expect( cssPos.y ).toBeCloseTo( cameraPos.y, 0 );
322
- } );
323
- }
324
- }
325
- } );
326
-
327
- describe( 'Render–Camera bridge: visual size consistency', () => {
328
- it( 'getImageFit visualSize matches getVisibleBounds dimensions at snap angles', () => {
329
- // At fine rotation (15°, 30°, etc.) the image footprint AABB
330
- // inflates beyond the snapped visual box, so visualSize (which
331
- // snaps) and getVisibleBounds (which sees actual rotated corners)
332
- // diverge by design. They must still agree at snap multiples.
333
- const SNAP_ROTATIONS = [ 0, 90, 180, 270 ];
334
-
335
- for ( const rotation of SNAP_ROTATIONS ) {
336
- const state = makeState( { rotation } );
337
- const { visualSize } = getImageFit( CONTAINER, IMAGE, rotation );
338
- const baseCamera = createCamera(
339
- { ...state, pan: { x: 0, y: 0 }, zoom: 1 },
340
- CONTAINER,
341
- IMAGE
342
- );
343
- const vb = getVisibleBounds( baseCamera );
344
-
345
- expect( visualSize.width ).toBeCloseTo( vb.width, 0 );
346
- expect( visualSize.height ).toBeCloseTo( vb.height, 0 );
347
- }
348
- } );
349
- } );