@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,64 +1,61 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/image-editor/core/setter-helpers.ts
21
- var setter_helpers_exports = {};
22
- __export(setter_helpers_exports, {
23
- buildFocalPointZoomAction: () => buildFocalPointZoomAction
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(setter_helpers_exports);
26
- var import_constants = require("./constants.cjs");
27
- var import_containment = require("./containment.cjs");
6
+ let __constants_ts = require("./constants.cjs");
7
+ let __containment_ts = require("./containment.cjs");
8
+ // packages/media-editor/src/image-editor/core/setter-helpers.ts
9
+ /**
10
+ * Build the reducer action that produces a "cursorless" zoom — zoom
11
+ * anchored at the current crop-rect center, with pan clamped to keep
12
+ * the image covering the crop.
13
+ *
14
+ * The slider, the `+`/`-` keys, and the toolbar buttons have no
15
+ * natural focal point (unlike wheel/pinch zoom), so they default to
16
+ * the crop center. Returns `null` when the clamped zoom matches the
17
+ * current zoom (no-op).
18
+ *
19
+ * Extracted so multiple hooks (the pure `useCropperController` and the
20
+ * composite `useMediaEditorState`) can share the math without
21
+ * duplicating it.
22
+ *
23
+ * @param state The current cropper state.
24
+ * @param requestedZoom The zoom value the caller asked for.
25
+ * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.
26
+ */
28
27
  function buildFocalPointZoomAction(state, requestedZoom) {
29
- const clampedZoom = Math.min(
30
- import_constants.MAX_ZOOM,
31
- Math.max((0, import_containment.getMinZoom)(state), requestedZoom)
32
- );
33
- if (clampedZoom === state.zoom) {
34
- return null;
35
- }
36
- const { cropRect } = state;
37
- const focalNormX = cropRect.x + cropRect.width / 2 - 0.5;
38
- const focalNormY = cropRect.y + cropRect.height / 2 - 0.5;
39
- const zoomRatio = 1 - clampedZoom / state.zoom;
40
- const newPanX = state.pan.x + (focalNormX - state.pan.x) * zoomRatio;
41
- const newPanY = state.pan.y + (focalNormY - state.pan.y) * zoomRatio;
42
- const imageSize = state.image ? {
43
- width: state.image.naturalWidth,
44
- height: state.image.naturalHeight
45
- } : { width: 1, height: 1 };
46
- const { pan: clampedPan } = (0, import_containment.restrictPanZoom)(
47
- {
48
- ...state,
49
- zoom: clampedZoom,
50
- pan: { x: newPanX, y: newPanY }
51
- },
52
- imageSize,
53
- state.cropRect
54
- );
55
- return {
56
- type: "SET_ZOOM_AT_POINT",
57
- payload: { zoom: clampedZoom, pan: clampedPan }
58
- };
28
+ const clampedZoom = Math.min(__constants_ts.MAX_ZOOM, Math.max((0, __containment_ts.getMinZoom)(state), requestedZoom));
29
+ if (clampedZoom === state.zoom) return null;
30
+ const { cropRect } = state;
31
+ const focalNormX = cropRect.x + cropRect.width / 2 - .5;
32
+ const focalNormY = cropRect.y + cropRect.height / 2 - .5;
33
+ const zoomRatio = 1 - clampedZoom / state.zoom;
34
+ const newPanX = state.pan.x + (focalNormX - state.pan.x) * zoomRatio;
35
+ const newPanY = state.pan.y + (focalNormY - state.pan.y) * zoomRatio;
36
+ const imageSize = state.image ? {
37
+ width: state.image.naturalWidth,
38
+ height: state.image.naturalHeight
39
+ } : {
40
+ width: 1,
41
+ height: 1
42
+ };
43
+ const { pan: clampedPan } = (0, __containment_ts.restrictPanZoom)({
44
+ ...state,
45
+ zoom: clampedZoom,
46
+ pan: {
47
+ x: newPanX,
48
+ y: newPanY
49
+ }
50
+ }, imageSize, state.cropRect);
51
+ return {
52
+ type: "SET_ZOOM_AT_POINT",
53
+ payload: {
54
+ zoom: clampedZoom,
55
+ pan: clampedPan
56
+ }
57
+ };
59
58
  }
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {
62
- buildFocalPointZoomAction
63
- });
64
- //# sourceMappingURL=setter-helpers.cjs.map
59
+ exports.buildFocalPointZoomAction = buildFocalPointZoomAction;
60
+
61
+ //# sourceMappingURL=setter-helpers.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/image-editor/core/setter-helpers.ts"],
4
- "sourcesContent": ["import type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t\t}\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAyB;AACzB,yBAA4C;AAoBrC,SAAS,0BACf,OACA,eACuB;AACvB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,QAAK,+BAAY,KAAM,GAAG,aAAc;AAAA,EAC9C;AACA,MAAK,gBAAgB,MAAM,MAAO;AACjC,WAAO;AAAA,EACR;AAKA,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;AACrD,QAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;AACtD,QAAM,YAAY,IAAI,cAAc,MAAM;AAC1C,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,YAA+C,MAAM,QACxD;AAAA,IACA,OAAO,MAAM,MAAM;AAAA,IACnB,QAAQ,MAAM,MAAM;AAAA,EACrB,IACC,EAAE,OAAO,GAAG,QAAQ,EAAE;AACzB,QAAM,EAAE,KAAK,WAAW,QAA8B;AAAA,IACrD;AAAA,MACC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AACA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,EAAE,MAAM,aAAa,KAAK,WAAW;AAAA,EAC/C;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"setter-helpers.cjs","names":["MAX_ZOOM","getMinZoom","restrictPanZoom"],"sources":["../../../src/image-editor/core/setter-helpers.ts"],"sourcesContent":["import type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperController` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t\t}\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,0BACf,OACA,eACuB;CACvB,MAAM,cAAc,KAAK,IACxBA,eAAAA,UACA,KAAK,KAAA,GAAKC,iBAAAA,WAAAA,CAAY,KAAM,GAAG,aAAc,CAC9C;CACA,IAAK,gBAAgB,MAAM,MAC1B,OAAO;CAMR,MAAM,EAAE,aAAa;CACrB,MAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;CACrD,MAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;CACtD,MAAM,YAAY,IAAI,cAAc,MAAM;CAC1C,MAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;CAC7D,MAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;CAC7D,MAAM,YAA+C,MAAM,QACxD;EACA,OAAO,MAAM,MAAM;EACnB,QAAQ,MAAM,MAAM;CACrB,IACC;EAAE,OAAO;EAAG,QAAQ;CAAE;CACzB,MAAM,EAAE,KAAK,gBAAA,GAAyCC,iBAAAA,gBAAAA,CACrD;EACC,GAAG;EACH,MAAM;EACN,KAAK;GAAE,GAAG;GAAS,GAAG;EAAQ;CAC/B,GACA,WACA,MAAM,QACP;CACA,OAAO;EACN,MAAM;EACN,SAAS;GAAE,MAAM;GAAa,KAAK;EAAW;CAC/C;AACD"}
@@ -1,206 +1,236 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/image-editor/core/source-region.ts
21
- var source_region_exports = {};
22
- __export(source_region_exports, {
23
- getSourceRegion: () => getSourceRegion,
24
- getSourceRegionPercent: () => getSourceRegionPercent,
25
- snapCropRectToSourcePixelGrid: () => snapCropRectToSourcePixelGrid,
26
- snapCropRectToSourcePixels: () => snapCropRectToSourcePixels
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
27
5
  });
28
- module.exports = __toCommonJS(source_region_exports);
29
- var import_gl_matrix = require("gl-matrix");
30
- var import_camera = require("./camera.cjs");
31
- var import_sanitize = require("./math/sanitize.cjs");
32
- var import_rotation = require("./math/rotation.cjs");
6
+ let gl_matrix = require("gl-matrix");
7
+ let __camera_ts = require("./camera.cjs");
8
+ let __math_sanitize_ts = require("./math/sanitize.cjs");
9
+ let __math_rotation_ts = require("./math/rotation.cjs");
10
+ // packages/media-editor/src/image-editor/core/source-region.ts
11
+ /**
12
+ * Get the selected image region in source-pixel coordinates.
13
+ *
14
+ * Converts the current crop state (normalized visual space) to the actual
15
+ * region of the original image that's selected. This is the bridge between
16
+ * the cropper's internal coordinate system and external tools (image
17
+ * processing libraries, AI APIs, server-side processing) that work in
18
+ * source-pixel coordinates.
19
+ *
20
+ * The returned rectangle accounts for pan, zoom, and the crop rect position,
21
+ * but expresses the crop in the unrotated image's coordinate space. Rotation
22
+ * and flip are included as separate fields since they represent transforms,
23
+ * not a region.
24
+ *
25
+ * @param state The current cropper state.
26
+ * @param imageSize The natural dimensions of the source image.
27
+ * @return The selected region in source pixels plus rotation/flip metadata.
28
+ */
33
29
  function getSourceRegion(state, imageSize) {
34
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
35
- if (!(0, import_sanitize.isValidSize)(imageSize)) {
36
- return {
37
- x: 0,
38
- y: 0,
39
- width: 0,
40
- height: 0,
41
- rotation: safeState.rotation,
42
- flip: { ...safeState.flip },
43
- zoom: safeState.zoom
44
- };
45
- }
46
- const syntheticContainer = { width: 1e3, height: 1e3 };
47
- const camera = (0, import_camera.createCamera)(safeState, syntheticContainer, imageSize);
48
- const inv = import_gl_matrix.mat2d.create();
49
- import_gl_matrix.mat2d.invert(inv, camera);
50
- const baseCamera = (0, import_camera.createCamera)(
51
- { ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },
52
- syntheticContainer,
53
- imageSize
54
- );
55
- const visibleBounds = (0, import_camera.getVisibleBounds)(baseCamera);
56
- const cropRect = safeState.cropRect;
57
- const cropCenterScreenX = visibleBounds.left + (cropRect.x + cropRect.width / 2) * visibleBounds.width;
58
- const cropCenterScreenY = visibleBounds.top + (cropRect.y + cropRect.height / 2) * visibleBounds.height;
59
- const srcCenter = import_gl_matrix.vec2.create();
60
- import_gl_matrix.vec2.transformMat2d(
61
- srcCenter,
62
- [cropCenterScreenX, cropCenterScreenY],
63
- inv
64
- );
65
- const snapRotation = Math.round(safeState.rotation / 90) * 90;
66
- const { width: rotW, height: rotH } = (0, import_camera.getRotatedBBox)(
67
- imageSize.width,
68
- imageSize.height,
69
- snapRotation
70
- );
71
- const sourceW = cropRect.width * rotW / safeState.zoom;
72
- const sourceH = cropRect.height * rotH / safeState.zoom;
73
- return {
74
- x: srcCenter[0] * imageSize.width - sourceW / 2,
75
- y: srcCenter[1] * imageSize.height - sourceH / 2,
76
- width: sourceW,
77
- height: sourceH,
78
- rotation: safeState.rotation,
79
- flip: { ...safeState.flip },
80
- zoom: safeState.zoom
81
- };
30
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
31
+ if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return {
32
+ x: 0,
33
+ y: 0,
34
+ width: 0,
35
+ height: 0,
36
+ rotation: safeState.rotation,
37
+ flip: { ...safeState.flip },
38
+ zoom: safeState.zoom
39
+ };
40
+ const syntheticContainer = {
41
+ width: 1e3,
42
+ height: 1e3
43
+ };
44
+ const camera = (0, __camera_ts.createCamera)(safeState, syntheticContainer, imageSize);
45
+ const inv = gl_matrix.mat2d.create();
46
+ gl_matrix.mat2d.invert(inv, camera);
47
+ const baseCamera = (0, __camera_ts.createCamera)({
48
+ ...safeState,
49
+ pan: {
50
+ x: 0,
51
+ y: 0
52
+ },
53
+ zoom: 1
54
+ }, syntheticContainer, imageSize);
55
+ const visibleBounds = (0, __camera_ts.getVisibleBounds)(baseCamera);
56
+ const cropRect = safeState.cropRect;
57
+ const cropCenterScreenX = visibleBounds.left + (cropRect.x + cropRect.width / 2) * visibleBounds.width;
58
+ const cropCenterScreenY = visibleBounds.top + (cropRect.y + cropRect.height / 2) * visibleBounds.height;
59
+ const srcCenter = gl_matrix.vec2.create();
60
+ gl_matrix.vec2.transformMat2d(srcCenter, [cropCenterScreenX, cropCenterScreenY], inv);
61
+ const snapRotation = Math.round(safeState.rotation / 90) * 90;
62
+ const { width: rotW, height: rotH } = (0, __camera_ts.getRotatedBBox)(imageSize.width, imageSize.height, snapRotation);
63
+ const sourceW = cropRect.width * rotW / safeState.zoom;
64
+ const sourceH = cropRect.height * rotH / safeState.zoom;
65
+ return {
66
+ x: srcCenter[0] * imageSize.width - sourceW / 2,
67
+ y: srcCenter[1] * imageSize.height - sourceH / 2,
68
+ width: sourceW,
69
+ height: sourceH,
70
+ rotation: safeState.rotation,
71
+ flip: { ...safeState.flip },
72
+ zoom: safeState.zoom
73
+ };
82
74
  }
75
+ /**
76
+ * Convert a source-pixel region back to the cropper's normalized crop rect.
77
+ *
78
+ * The math intentionally mirrors `getSourceRegion`: map the requested source
79
+ * center through the current camera, then express that screen point inside the
80
+ * same base visible bounds used to position crop overlays.
81
+ *
82
+ * @param state The current cropper state.
83
+ * @param imageSize The natural dimensions of the source image.
84
+ * @param region The source-pixel region to represent as a crop rect.
85
+ * @return The normalized crop rect, or null when inputs cannot be mapped.
86
+ */
83
87
  function getCropRectFromSourceRegion(state, imageSize, region) {
84
- if (!(0, import_sanitize.isValidSize)(imageSize) || region.width <= 0 || region.height <= 0) {
85
- return null;
86
- }
87
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
88
- const syntheticContainer = { width: 1e3, height: 1e3 };
89
- const baseCamera = (0, import_camera.createCamera)(
90
- { ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },
91
- syntheticContainer,
92
- imageSize
93
- );
94
- const visibleBounds = (0, import_camera.getVisibleBounds)(baseCamera);
95
- if (visibleBounds.width <= 0 || visibleBounds.height <= 0) {
96
- return null;
97
- }
98
- const sourceCenter = import_gl_matrix.vec2.fromValues(
99
- (region.x + region.width / 2) / imageSize.width,
100
- (region.y + region.height / 2) / imageSize.height
101
- );
102
- const screenCenter = import_gl_matrix.vec2.create();
103
- const camera = (0, import_camera.createCamera)(safeState, syntheticContainer, imageSize);
104
- import_gl_matrix.vec2.transformMat2d(screenCenter, sourceCenter, camera);
105
- const snapRotation = Math.round(safeState.rotation / 90) * 90;
106
- const { width: rotW, height: rotH } = (0, import_camera.getRotatedBBox)(
107
- imageSize.width,
108
- imageSize.height,
109
- snapRotation
110
- );
111
- if (rotW <= 0 || rotH <= 0) {
112
- return null;
113
- }
114
- const width = region.width * safeState.zoom / rotW;
115
- const height = region.height * safeState.zoom / rotH;
116
- const centerX = (screenCenter[0] - visibleBounds.left) / visibleBounds.width;
117
- const centerY = (screenCenter[1] - visibleBounds.top) / visibleBounds.height;
118
- return {
119
- x: centerX - width / 2,
120
- y: centerY - height / 2,
121
- width,
122
- height
123
- };
88
+ if (!(0, __math_sanitize_ts.isValidSize)(imageSize) || region.width <= 0 || region.height <= 0) return null;
89
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
90
+ const syntheticContainer = {
91
+ width: 1e3,
92
+ height: 1e3
93
+ };
94
+ const baseCamera = (0, __camera_ts.createCamera)({
95
+ ...safeState,
96
+ pan: {
97
+ x: 0,
98
+ y: 0
99
+ },
100
+ zoom: 1
101
+ }, syntheticContainer, imageSize);
102
+ const visibleBounds = (0, __camera_ts.getVisibleBounds)(baseCamera);
103
+ if (visibleBounds.width <= 0 || visibleBounds.height <= 0) return null;
104
+ const sourceCenter = gl_matrix.vec2.fromValues((region.x + region.width / 2) / imageSize.width, (region.y + region.height / 2) / imageSize.height);
105
+ const screenCenter = gl_matrix.vec2.create();
106
+ const camera = (0, __camera_ts.createCamera)(safeState, syntheticContainer, imageSize);
107
+ gl_matrix.vec2.transformMat2d(screenCenter, sourceCenter, camera);
108
+ const snapRotation = Math.round(safeState.rotation / 90) * 90;
109
+ const { width: rotW, height: rotH } = (0, __camera_ts.getRotatedBBox)(imageSize.width, imageSize.height, snapRotation);
110
+ if (rotW <= 0 || rotH <= 0) return null;
111
+ const width = region.width * safeState.zoom / rotW;
112
+ const height = region.height * safeState.zoom / rotH;
113
+ const centerX = (screenCenter[0] - visibleBounds.left) / visibleBounds.width;
114
+ const centerY = (screenCenter[1] - visibleBounds.top) / visibleBounds.height;
115
+ return {
116
+ x: centerX - width / 2,
117
+ y: centerY - height / 2,
118
+ width,
119
+ height
120
+ };
124
121
  }
125
- var CARDINAL_ROTATION_EPSILON = 1e-6;
122
+ const CARDINAL_ROTATION_EPSILON = 1e-6;
123
+ /**
124
+ * Check whether a rotation is effectively at a 90-degree stop.
125
+ *
126
+ * @param rotation The rotation angle in degrees.
127
+ * @return Whether the rotation is close enough to a cardinal angle.
128
+ */
126
129
  function isCardinalRotation(rotation) {
127
- const normalizedRotation = (0, import_rotation.normalizeRotation)(rotation);
128
- const nearestCardinal = Math.round(normalizedRotation / 90) * 90;
129
- return Math.abs(normalizedRotation - nearestCardinal) < CARDINAL_ROTATION_EPSILON;
130
+ const normalizedRotation = (0, __math_rotation_ts.normalizeRotation)(rotation);
131
+ const nearestCardinal = Math.round(normalizedRotation / 90) * 90;
132
+ return Math.abs(normalizedRotation - nearestCardinal) < CARDINAL_ROTATION_EPSILON;
130
133
  }
134
+ /**
135
+ * Snap a crop rect so the selected source-region edges land on whole pixels.
136
+ *
137
+ * This is a display-time affordance for visible pixel grids; it does not alter
138
+ * pan/zoom/rotation. Callers decide when snapping is appropriate.
139
+ *
140
+ * @param state The current cropper state.
141
+ * @param imageSize The natural dimensions of the source image.
142
+ * @param cropRect The candidate crop rect from resize math.
143
+ * @param handle The active resize handle. Only edges moved by the handle snap.
144
+ * @return A crop rect whose selected source-region edges are whole pixels.
145
+ */
131
146
  function snapCropRectToSourcePixels(state, imageSize, cropRect, handle) {
132
- const safeState = (0, import_sanitize.sanitizeCropperState)(state);
133
- if (!isCardinalRotation(safeState.rotation)) {
134
- return cropRect;
135
- }
136
- return snapCropRectEdgesToSourcePixels(safeState, imageSize, cropRect, {
137
- left: handle.includes("w"),
138
- top: handle.includes("n"),
139
- right: handle.includes("e"),
140
- bottom: handle.includes("s")
141
- });
147
+ const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
148
+ if (!isCardinalRotation(safeState.rotation)) return cropRect;
149
+ return snapCropRectEdgesToSourcePixels(safeState, imageSize, cropRect, {
150
+ left: handle.includes("w"),
151
+ top: handle.includes("n"),
152
+ right: handle.includes("e"),
153
+ bottom: handle.includes("s")
154
+ });
142
155
  }
156
+ /**
157
+ * Snap all source-region edges for a crop rect to the nearest whole pixels.
158
+ *
159
+ * @param state The current cropper state.
160
+ * @param imageSize The natural dimensions of the source image.
161
+ * @param cropRect The crop rect to align to the source-pixel grid.
162
+ * @return A crop rect whose source-region edges are whole pixels.
163
+ */
143
164
  function snapCropRectToSourcePixelGrid(state, imageSize, cropRect) {
144
- return snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, {
145
- left: true,
146
- top: true,
147
- right: true,
148
- bottom: true
149
- });
165
+ return snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, {
166
+ left: true,
167
+ top: true,
168
+ right: true,
169
+ bottom: true
170
+ });
150
171
  }
151
172
  function snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, edges) {
152
- if (!(0, import_sanitize.isValidSize)(imageSize)) {
153
- return cropRect;
154
- }
155
- const stateWithCrop = (0, import_sanitize.sanitizeCropperState)({ ...state, cropRect });
156
- const region = getSourceRegion(stateWithCrop, imageSize);
157
- const shouldSnapX = edges.left || edges.right;
158
- const shouldSnapY = edges.top || edges.bottom;
159
- const left = edges.left ? Math.round(region.x) : region.x;
160
- const top = edges.top ? Math.round(region.y) : region.y;
161
- const right = edges.right ? Math.round(region.x + region.width) : region.x + region.width;
162
- const bottom = edges.bottom ? Math.round(region.y + region.height) : region.y + region.height;
163
- if (right <= left || bottom <= top) {
164
- return cropRect;
165
- }
166
- const snappedCropRect = getCropRectFromSourceRegion(
167
- stateWithCrop,
168
- imageSize,
169
- {
170
- ...region,
171
- x: left,
172
- y: top,
173
- width: right - left,
174
- height: bottom - top
175
- }
176
- );
177
- if (!snappedCropRect) {
178
- return cropRect;
179
- }
180
- return {
181
- x: shouldSnapX ? snappedCropRect.x : cropRect.x,
182
- y: shouldSnapY ? snappedCropRect.y : cropRect.y,
183
- width: shouldSnapX ? snappedCropRect.width : cropRect.width,
184
- height: shouldSnapY ? snappedCropRect.height : cropRect.height
185
- };
173
+ if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return cropRect;
174
+ const stateWithCrop = (0, __math_sanitize_ts.sanitizeCropperState)({
175
+ ...state,
176
+ cropRect
177
+ });
178
+ const region = getSourceRegion(stateWithCrop, imageSize);
179
+ const shouldSnapX = edges.left || edges.right;
180
+ const shouldSnapY = edges.top || edges.bottom;
181
+ const left = edges.left ? Math.round(region.x) : region.x;
182
+ const top = edges.top ? Math.round(region.y) : region.y;
183
+ const right = edges.right ? Math.round(region.x + region.width) : region.x + region.width;
184
+ const bottom = edges.bottom ? Math.round(region.y + region.height) : region.y + region.height;
185
+ if (right <= left || bottom <= top) return cropRect;
186
+ const snappedCropRect = getCropRectFromSourceRegion(stateWithCrop, imageSize, {
187
+ ...region,
188
+ x: left,
189
+ y: top,
190
+ width: right - left,
191
+ height: bottom - top
192
+ });
193
+ if (!snappedCropRect) return cropRect;
194
+ return {
195
+ x: shouldSnapX ? snappedCropRect.x : cropRect.x,
196
+ y: shouldSnapY ? snappedCropRect.y : cropRect.y,
197
+ width: shouldSnapX ? snappedCropRect.width : cropRect.width,
198
+ height: shouldSnapY ? snappedCropRect.height : cropRect.height
199
+ };
186
200
  }
201
+ /**
202
+ * Get the selected image region as percentages of the source image dimensions.
203
+ *
204
+ * Returns `{ x, y, width, height }` where each value is a percentage (0–100)
205
+ * of the source image's natural width or height. This format is compatible
206
+ * with the WordPress REST API attachments `/edit` endpoint and CSS-based
207
+ * crop workflows.
208
+ *
209
+ * Internally delegates to `getSourceRegion` and divides by the image
210
+ * dimensions, so accuracy is identical.
211
+ *
212
+ * @param state The current cropper state.
213
+ * @param imageSize The natural dimensions of the source image.
214
+ * @return The crop region as percentages (0–100).
215
+ */
187
216
  function getSourceRegionPercent(state, imageSize) {
188
- if (!(0, import_sanitize.isValidSize)(imageSize)) {
189
- return { x: 0, y: 0, width: 0, height: 0 };
190
- }
191
- const region = getSourceRegion(state, imageSize);
192
- return {
193
- x: region.x / imageSize.width * 100,
194
- y: region.y / imageSize.height * 100,
195
- width: region.width / imageSize.width * 100,
196
- height: region.height / imageSize.height * 100
197
- };
217
+ if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return {
218
+ x: 0,
219
+ y: 0,
220
+ width: 0,
221
+ height: 0
222
+ };
223
+ const region = getSourceRegion(state, imageSize);
224
+ return {
225
+ x: region.x / imageSize.width * 100,
226
+ y: region.y / imageSize.height * 100,
227
+ width: region.width / imageSize.width * 100,
228
+ height: region.height / imageSize.height * 100
229
+ };
198
230
  }
199
- // Annotate the CommonJS export names for ESM import in node:
200
- 0 && (module.exports = {
201
- getSourceRegion,
202
- getSourceRegionPercent,
203
- snapCropRectToSourcePixelGrid,
204
- snapCropRectToSourcePixels
205
- });
206
- //# sourceMappingURL=source-region.cjs.map
231
+ exports.getSourceRegion = getSourceRegion;
232
+ exports.getSourceRegionPercent = getSourceRegionPercent;
233
+ exports.snapCropRectToSourcePixelGrid = snapCropRectToSourcePixelGrid;
234
+ exports.snapCropRectToSourcePixels = snapCropRectToSourcePixels;
235
+
236
+ //# sourceMappingURL=source-region.cjs.map