@wordpress/media-editor 0.9.0 → 0.10.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 (292) hide show
  1. package/build/components/media-editor/index.cjs +34 -135
  2. package/build/components/media-editor/index.cjs.map +3 -3
  3. package/build/components/media-editor/use-crop-options.cjs +87 -0
  4. package/build/components/media-editor/use-crop-options.cjs.map +7 -0
  5. package/build/components/media-editor/use-save-media-editor.cjs +185 -0
  6. package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
  7. package/build/components/media-editor-canvas/index.cjs +32 -11
  8. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  9. package/build/components/media-editor-crop-panel/index.cjs +66 -83
  10. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  11. package/build/components/media-editor-modal/index.cjs +40 -11
  12. package/build/components/media-editor-modal/index.cjs.map +3 -3
  13. package/build/components/media-editor-toolbar/index.cjs +7 -3
  14. package/build/components/media-editor-toolbar/index.cjs.map +2 -2
  15. package/build/components/media-form/index.cjs +19 -1
  16. package/build/components/media-form/index.cjs.map +3 -3
  17. package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
  18. package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
  19. package/build/components/rotation-ruler/index.cjs +8 -2
  20. package/build/components/rotation-ruler/index.cjs.map +2 -2
  21. package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
  22. package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
  23. package/build/image-editor/core/camera.cjs +29 -11
  24. package/build/image-editor/core/camera.cjs.map +2 -2
  25. package/build/image-editor/core/constants.cjs +6 -0
  26. package/build/image-editor/core/constants.cjs.map +2 -2
  27. package/build/image-editor/core/containment.cjs +71 -34
  28. package/build/image-editor/core/containment.cjs.map +2 -2
  29. package/build/image-editor/core/crop-rect.cjs +48 -0
  30. package/build/image-editor/core/crop-rect.cjs.map +7 -0
  31. package/build/image-editor/core/index.cjs +12 -0
  32. package/build/image-editor/core/index.cjs.map +2 -2
  33. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  34. package/build/image-editor/core/math/sanitize.cjs +92 -0
  35. package/build/image-editor/core/math/sanitize.cjs.map +7 -0
  36. package/build/image-editor/core/setter-helpers.cjs +64 -0
  37. package/build/image-editor/core/setter-helpers.cjs.map +7 -0
  38. package/build/image-editor/core/source-region.cjs +16 -14
  39. package/build/image-editor/core/source-region.cjs.map +2 -2
  40. package/build/image-editor/core/state.cjs +20 -10
  41. package/build/image-editor/core/state.cjs.map +2 -2
  42. package/build/image-editor/core/stencil-math.cjs +31 -20
  43. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  44. package/build/image-editor/core/transform-style.cjs +12 -6
  45. package/build/image-editor/core/transform-style.cjs.map +2 -2
  46. package/build/image-editor/core/types.cjs.map +1 -1
  47. package/build/image-editor/index.cjs +12 -2
  48. package/build/image-editor/index.cjs.map +2 -2
  49. package/build/image-editor/react/components/cropper-provider.cjs +2 -2
  50. package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
  51. package/build/image-editor/react/components/cropper.cjs +121 -48
  52. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  53. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
  54. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
  55. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +20 -10
  56. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  57. package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
  58. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
  59. package/build/image-editor/react/hooks/index.cjs +6 -3
  60. package/build/image-editor/react/hooks/index.cjs.map +2 -2
  61. package/build/image-editor/react/hooks/use-aria-announcer.cjs +3 -1
  62. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  63. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
  64. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
  65. package/build/image-editor/react/hooks/use-interaction.cjs +1 -1
  66. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  67. package/build/state/composite-reducer.cjs +115 -0
  68. package/build/state/composite-reducer.cjs.map +7 -0
  69. package/build/state/index.cjs +48 -0
  70. package/build/state/index.cjs.map +7 -0
  71. package/build/state/media-editor-state-provider.cjs +58 -0
  72. package/build/state/media-editor-state-provider.cjs.map +7 -0
  73. package/build/state/types.cjs +34 -0
  74. package/build/state/types.cjs.map +7 -0
  75. package/build/state/use-media-editor-state.cjs +298 -0
  76. package/build/state/use-media-editor-state.cjs.map +7 -0
  77. package/build-module/components/media-editor/index.mjs +40 -140
  78. package/build-module/components/media-editor/index.mjs.map +2 -2
  79. package/build-module/components/media-editor/use-crop-options.mjs +61 -0
  80. package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
  81. package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
  82. package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
  83. package/build-module/components/media-editor-canvas/index.mjs +33 -12
  84. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  85. package/build-module/components/media-editor-crop-panel/index.mjs +68 -83
  86. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  87. package/build-module/components/media-editor-modal/index.mjs +40 -11
  88. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  89. package/build-module/components/media-editor-toolbar/index.mjs +7 -3
  90. package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
  91. package/build-module/components/media-form/index.mjs +9 -1
  92. package/build-module/components/media-form/index.mjs.map +2 -2
  93. package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
  94. package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
  95. package/build-module/components/rotation-ruler/index.mjs +8 -2
  96. package/build-module/components/rotation-ruler/index.mjs.map +2 -2
  97. package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
  98. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
  99. package/build-module/image-editor/core/camera.mjs +34 -11
  100. package/build-module/image-editor/core/camera.mjs.map +2 -2
  101. package/build-module/image-editor/core/constants.mjs +4 -0
  102. package/build-module/image-editor/core/constants.mjs.map +2 -2
  103. package/build-module/image-editor/core/containment.mjs +75 -34
  104. package/build-module/image-editor/core/containment.mjs.map +2 -2
  105. package/build-module/image-editor/core/crop-rect.mjs +23 -0
  106. package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
  107. package/build-module/image-editor/core/index.mjs +12 -0
  108. package/build-module/image-editor/core/index.mjs.map +2 -2
  109. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  110. package/build-module/image-editor/core/math/sanitize.mjs +63 -0
  111. package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
  112. package/build-module/image-editor/core/setter-helpers.mjs +39 -0
  113. package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
  114. package/build-module/image-editor/core/source-region.mjs +16 -14
  115. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  116. package/build-module/image-editor/core/state.mjs +25 -11
  117. package/build-module/image-editor/core/state.mjs.map +2 -2
  118. package/build-module/image-editor/core/stencil-math.mjs +30 -19
  119. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  120. package/build-module/image-editor/core/transform-style.mjs +12 -6
  121. package/build-module/image-editor/core/transform-style.mjs.map +2 -2
  122. package/build-module/image-editor/index.mjs +11 -2
  123. package/build-module/image-editor/index.mjs.map +2 -2
  124. package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
  125. package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
  126. package/build-module/image-editor/react/components/cropper.mjs +122 -49
  127. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  128. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
  129. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
  130. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +20 -10
  131. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  132. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
  133. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
  134. package/build-module/image-editor/react/hooks/index.mjs +4 -2
  135. package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
  136. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +3 -1
  137. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  138. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
  139. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
  140. package/build-module/image-editor/react/hooks/use-interaction.mjs +1 -1
  141. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  142. package/build-module/state/composite-reducer.mjs +94 -0
  143. package/build-module/state/composite-reducer.mjs.map +7 -0
  144. package/build-module/state/index.mjs +26 -0
  145. package/build-module/state/index.mjs.map +7 -0
  146. package/build-module/state/media-editor-state-provider.mjs +34 -0
  147. package/build-module/state/media-editor-state-provider.mjs.map +7 -0
  148. package/build-module/state/types.mjs +9 -0
  149. package/build-module/state/types.mjs.map +7 -0
  150. package/build-module/state/use-media-editor-state.mjs +289 -0
  151. package/build-module/state/use-media-editor-state.mjs.map +7 -0
  152. package/build-style/style-rtl.css +46 -9
  153. package/build-style/style.css +46 -9
  154. package/build-types/components/media-editor/index.d.ts +4 -7
  155. package/build-types/components/media-editor/index.d.ts.map +1 -1
  156. package/build-types/components/media-editor/use-crop-options.d.ts +37 -0
  157. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
  158. package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
  159. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
  160. package/build-types/components/media-editor-canvas/index.d.ts +5 -10
  161. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  162. package/build-types/components/media-editor-crop-panel/index.d.ts +4 -16
  163. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  164. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  165. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
  166. package/build-types/components/media-form/index.d.ts.map +1 -1
  167. package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
  168. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
  169. package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
  170. package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
  171. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
  172. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  173. package/build-types/image-editor/core/constants.d.ts +18 -0
  174. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  175. package/build-types/image-editor/core/containment.d.ts +10 -0
  176. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  177. package/build-types/image-editor/core/crop-rect.d.ts +19 -0
  178. package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
  179. package/build-types/image-editor/core/index.d.ts +3 -1
  180. package/build-types/image-editor/core/index.d.ts.map +1 -1
  181. package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
  182. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  183. package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
  184. package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
  185. package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
  186. package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
  187. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  188. package/build-types/image-editor/core/state.d.ts +12 -0
  189. package/build-types/image-editor/core/state.d.ts.map +1 -1
  190. package/build-types/image-editor/core/stencil-math.d.ts +23 -18
  191. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  192. package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
  193. package/build-types/image-editor/core/types.d.ts +23 -4
  194. package/build-types/image-editor/core/types.d.ts.map +1 -1
  195. package/build-types/image-editor/index.d.ts +4 -4
  196. package/build-types/image-editor/index.d.ts.map +1 -1
  197. package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
  198. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  199. package/build-types/image-editor/react/components/cropper.d.ts +6 -4
  200. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  201. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
  202. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
  203. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
  204. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  205. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
  206. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
  207. package/build-types/image-editor/react/hooks/index.d.ts +4 -2
  208. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  209. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  210. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +58 -0
  211. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
  212. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  213. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  214. package/build-types/state/composite-reducer.d.ts +39 -0
  215. package/build-types/state/composite-reducer.d.ts.map +1 -0
  216. package/build-types/state/index.d.ts +7 -0
  217. package/build-types/state/index.d.ts.map +1 -0
  218. package/build-types/state/media-editor-state-provider.d.ts +34 -0
  219. package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
  220. package/build-types/state/types.d.ts +104 -0
  221. package/build-types/state/types.d.ts.map +1 -0
  222. package/build-types/state/use-media-editor-state.d.ts +104 -0
  223. package/build-types/state/use-media-editor-state.d.ts.map +1 -0
  224. package/package.json +19 -17
  225. package/src/components/media-editor/index.tsx +52 -188
  226. package/src/components/media-editor/test/use-crop-options.tsx +164 -0
  227. package/src/components/media-editor/use-crop-options.ts +115 -0
  228. package/src/components/media-editor/use-save-media-editor.ts +214 -0
  229. package/src/components/media-editor-canvas/index.tsx +56 -24
  230. package/src/components/media-editor-crop-panel/index.tsx +25 -61
  231. package/src/components/media-editor-crop-panel/test/index.tsx +17 -43
  232. package/src/components/media-editor-modal/index.tsx +50 -12
  233. package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
  234. package/src/components/media-editor-modal/test/index.tsx +143 -0
  235. package/src/components/media-editor-toolbar/index.tsx +9 -5
  236. package/src/components/media-form/index.tsx +15 -1
  237. package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
  238. package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
  239. package/src/components/rotation-ruler/README.md +11 -25
  240. package/src/components/rotation-ruler/index.tsx +17 -2
  241. package/src/components/rotation-ruler/style.scss +49 -13
  242. package/src/hooks/use-crop-gesture-handlers.ts +66 -17
  243. package/src/image-editor/README.md +28 -129
  244. package/src/image-editor/core/camera.ts +51 -26
  245. package/src/image-editor/core/constants.ts +19 -0
  246. package/src/image-editor/core/containment.ts +102 -49
  247. package/src/image-editor/core/crop-rect.ts +45 -0
  248. package/src/image-editor/core/index.ts +16 -4
  249. package/src/image-editor/core/interaction-controller.ts +5 -1
  250. package/src/image-editor/core/math/sanitize.ts +158 -0
  251. package/src/image-editor/core/math/test/sanitize.ts +244 -0
  252. package/src/image-editor/core/setter-helpers.ts +66 -0
  253. package/src/image-editor/core/source-region.ts +21 -14
  254. package/src/image-editor/core/state.ts +67 -15
  255. package/src/image-editor/core/stencil-math.ts +55 -35
  256. package/src/image-editor/core/test/camera.ts +367 -1
  257. package/src/image-editor/core/test/state.ts +101 -8
  258. package/src/image-editor/core/test/stencil-math.ts +193 -0
  259. package/src/image-editor/core/transform-style.ts +21 -6
  260. package/src/image-editor/core/types.ts +24 -4
  261. package/src/image-editor/docs/architecture.md +48 -89
  262. package/src/image-editor/docs/recipes.md +123 -659
  263. package/src/image-editor/index.ts +12 -3
  264. package/src/image-editor/react/components/cropper-provider.tsx +16 -12
  265. package/src/image-editor/react/components/cropper.scss +23 -4
  266. package/src/image-editor/react/components/cropper.tsx +197 -90
  267. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
  268. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +22 -9
  269. package/src/image-editor/react/components/test/cropper.tsx +55 -13
  270. package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
  271. package/src/image-editor/react/hooks/index.ts +4 -2
  272. package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
  273. package/src/image-editor/react/hooks/use-aria-announcer.ts +3 -1
  274. package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
  275. package/src/image-editor/react/hooks/use-interaction.ts +3 -2
  276. package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
  277. package/src/state/composite-reducer.ts +152 -0
  278. package/src/state/index.ts +20 -0
  279. package/src/state/media-editor-state-provider.tsx +70 -0
  280. package/src/state/test/use-media-editor-state.ts +402 -0
  281. package/src/state/types.ts +107 -0
  282. package/src/state/use-media-editor-state.ts +488 -0
  283. package/tsconfig.json +2 -0
  284. package/tsconfig.tsbuildinfo +1 -1
  285. package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
  286. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
  287. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
  288. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
  289. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
  290. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
  291. package/src/image-editor/docs/roadmap.md +0 -66
  292. package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
@@ -6,19 +6,19 @@ import { renderHook, act } from '@testing-library/react';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { useCropperState } from '../use-cropper-state';
9
+ import { useCropperReducer } from '../use-cropper-reducer';
10
10
  import { DEFAULT_STATE } from '../../../core/constants';
11
11
 
12
- describe( 'useCropperState', () => {
12
+ describe( 'useCropperReducer', () => {
13
13
  it( 'should initialize with DEFAULT_STATE', () => {
14
- const { result } = renderHook( () => useCropperState() );
14
+ const { result } = renderHook( () => useCropperReducer() );
15
15
 
16
16
  expect( result.current.state ).toEqual( DEFAULT_STATE );
17
17
  } );
18
18
 
19
19
  it( 'should initialize with merged partial state', () => {
20
20
  const { result } = renderHook( () =>
21
- useCropperState( { zoom: 2, rotation: 45 } )
21
+ useCropperReducer( { zoom: 2, rotation: 45 } )
22
22
  );
23
23
 
24
24
  expect( result.current.state.zoom ).toBe( 2 );
@@ -28,7 +28,7 @@ describe( 'useCropperState', () => {
28
28
  } );
29
29
 
30
30
  it( 'should dispatch SET_CROP via setCrop', () => {
31
- const { result } = renderHook( () => useCropperState() );
31
+ const { result } = renderHook( () => useCropperReducer() );
32
32
 
33
33
  // At zoom=1, crop is clamped to (0,0) — no panning possible.
34
34
  // Zoom in first to allow panning.
@@ -45,7 +45,7 @@ describe( 'useCropperState', () => {
45
45
  } );
46
46
 
47
47
  it( 'should dispatch SET_ZOOM via setZoom', () => {
48
- const { result } = renderHook( () => useCropperState() );
48
+ const { result } = renderHook( () => useCropperReducer() );
49
49
 
50
50
  act( () => {
51
51
  result.current.setZoom( 3 );
@@ -54,8 +54,67 @@ describe( 'useCropperState', () => {
54
54
  expect( result.current.state.zoom ).toBe( 3 );
55
55
  } );
56
56
 
57
+ it( 'leaves pan at zero on setZoom when the cropRect is centered', () => {
58
+ // Sanity: the default cropRect spans the full image, so its
59
+ // center coincides with the image center and the crop-center
60
+ // focal-point correction degenerates to "no pan change."
61
+ // Guards against regressions where setZoom accidentally pans.
62
+ const { result } = renderHook( () => useCropperReducer() );
63
+
64
+ act( () => {
65
+ result.current.setZoom( 4 );
66
+ } );
67
+
68
+ expect( result.current.state.zoom ).toBe( 4 );
69
+ expect( result.current.state.pan ).toEqual( { x: 0, y: 0 } );
70
+
71
+ act( () => {
72
+ result.current.setZoom( 2 );
73
+ } );
74
+
75
+ expect( result.current.state.zoom ).toBe( 2 );
76
+ expect( result.current.state.pan ).toEqual( { x: 0, y: 0 } );
77
+ } );
78
+
79
+ it( 'anchors setZoom at the crop-rect center', () => {
80
+ // With an off-center crop, setZoom must shift pan toward the
81
+ // crop center as zoom decreases — otherwise `enforceContainment`
82
+ // would translate the image toward the nearest viewport corner
83
+ // (the original bug this method fixes).
84
+ const { result } = renderHook( () => useCropperReducer() );
85
+
86
+ act( () => {
87
+ result.current.setZoom( 4 );
88
+ } );
89
+ // Place the crop in the bottom-right quadrant — center
90
+ // at ( 0.7, 0.7 ), i.e. ( +0.2, +0.2 ) in pan coords.
91
+ act( () => {
92
+ result.current.setCropRect( {
93
+ x: 0.6,
94
+ y: 0.6,
95
+ width: 0.2,
96
+ height: 0.2,
97
+ } );
98
+ } );
99
+ act( () => {
100
+ result.current.setPan( { x: 0, y: 0 } );
101
+ } );
102
+
103
+ expect( result.current.state.pan ).toEqual( { x: 0, y: 0 } );
104
+
105
+ // Zoom out — pan should move toward the focal point in +x, +y,
106
+ // not stay at the origin (which would corner-snap on containment).
107
+ act( () => {
108
+ result.current.setZoom( 2 );
109
+ } );
110
+
111
+ expect( result.current.state.zoom ).toBe( 2 );
112
+ expect( result.current.state.pan.x ).toBeGreaterThan( 0 );
113
+ expect( result.current.state.pan.y ).toBeGreaterThan( 0 );
114
+ } );
115
+
57
116
  it( 'should dispatch SET_ZOOM_AT_POINT via setZoomAtPoint', () => {
58
- const { result } = renderHook( () => useCropperState() );
117
+ const { result } = renderHook( () => useCropperReducer() );
59
118
 
60
119
  act( () => {
61
120
  result.current.setZoomAtPoint( 3, { x: 0.2, y: 0.1 } );
@@ -66,7 +125,7 @@ describe( 'useCropperState', () => {
66
125
  } );
67
126
 
68
127
  it( 'should clamp zoom to valid range via SET_ZOOM', () => {
69
- const { result } = renderHook( () => useCropperState() );
128
+ const { result } = renderHook( () => useCropperReducer() );
70
129
 
71
130
  act( () => {
72
131
  result.current.setZoom( 15 );
@@ -81,8 +140,32 @@ describe( 'useCropperState', () => {
81
140
  expect( result.current.state.zoom ).toBe( 1 );
82
141
  } );
83
142
 
143
+ it( 'allows setZoom below 1 when the coverage minimum permits', () => {
144
+ // Thin, fine-rotated crop on a portrait image: the coverage
145
+ // minimum drops below 1, so `setZoom` (slider / keyboard path)
146
+ // must honour values below 1 rather than clamping at MIN_ZOOM.
147
+ const { result } = renderHook( () =>
148
+ useCropperReducer( {
149
+ image: {
150
+ src: 'portrait.jpg',
151
+ naturalWidth: 900,
152
+ naturalHeight: 1600,
153
+ },
154
+ rotation: 19,
155
+ cropRect: { x: 0.48, y: 0, width: 0.04, height: 1 },
156
+ } )
157
+ );
158
+
159
+ act( () => {
160
+ result.current.setZoom( 0.9 );
161
+ } );
162
+
163
+ expect( result.current.state.zoom ).toBeLessThan( 1 );
164
+ expect( result.current.state.zoom ).toBeGreaterThanOrEqual( 0.9 );
165
+ } );
166
+
84
167
  it( 'should dispatch SET_ROTATION via setRotation', () => {
85
- const { result } = renderHook( () => useCropperState() );
168
+ const { result } = renderHook( () => useCropperReducer() );
86
169
 
87
170
  act( () => {
88
171
  result.current.setRotation( 90 );
@@ -92,7 +175,7 @@ describe( 'useCropperState', () => {
92
175
  } );
93
176
 
94
177
  it( 'should normalize rotation via SET_ROTATION', () => {
95
- const { result } = renderHook( () => useCropperState() );
178
+ const { result } = renderHook( () => useCropperReducer() );
96
179
 
97
180
  act( () => {
98
181
  result.current.setRotation( -90 );
@@ -108,7 +191,7 @@ describe( 'useCropperState', () => {
108
191
  } );
109
192
 
110
193
  it( 'should dispatch SET_FLIP via setFlip', () => {
111
- const { result } = renderHook( () => useCropperState() );
194
+ const { result } = renderHook( () => useCropperReducer() );
112
195
 
113
196
  act( () => {
114
197
  result.current.setFlip( {
@@ -124,7 +207,7 @@ describe( 'useCropperState', () => {
124
207
  } );
125
208
 
126
209
  it( 'toggleFlip should toggle horizontal flip', () => {
127
- const { result } = renderHook( () => useCropperState() );
210
+ const { result } = renderHook( () => useCropperReducer() );
128
211
 
129
212
  act( () => {
130
213
  result.current.toggleFlip( 'horizontal' );
@@ -146,7 +229,7 @@ describe( 'useCropperState', () => {
146
229
  } );
147
230
 
148
231
  it( 'toggleFlip should toggle vertical flip independently', () => {
149
- const { result } = renderHook( () => useCropperState() );
232
+ const { result } = renderHook( () => useCropperReducer() );
150
233
 
151
234
  act( () => {
152
235
  result.current.toggleFlip( 'vertical' );
@@ -159,7 +242,7 @@ describe( 'useCropperState', () => {
159
242
  } );
160
243
 
161
244
  it( 'should dispatch SET_CROP_RECT via setCropRect', () => {
162
- const { result } = renderHook( () => useCropperState() );
245
+ const { result } = renderHook( () => useCropperReducer() );
163
246
 
164
247
  const rect = { x: 0.1, y: 0.2, width: 0.5, height: 0.6 };
165
248
  act( () => {
@@ -170,7 +253,7 @@ describe( 'useCropperState', () => {
170
253
  } );
171
254
 
172
255
  it( 'should dispatch APPLY_OPERATION via applyOperation', () => {
173
- const { result } = renderHook( () => useCropperState() );
256
+ const { result } = renderHook( () => useCropperReducer() );
174
257
 
175
258
  act( () => {
176
259
  result.current.applyOperation( {
@@ -183,7 +266,7 @@ describe( 'useCropperState', () => {
183
266
  } );
184
267
 
185
268
  it( 'should handle APPLY_OPERATION for flip', () => {
186
- const { result } = renderHook( () => useCropperState() );
269
+ const { result } = renderHook( () => useCropperReducer() );
187
270
 
188
271
  act( () => {
189
272
  result.current.applyOperation( {
@@ -197,7 +280,7 @@ describe( 'useCropperState', () => {
197
280
  } );
198
281
 
199
282
  it( 'should accumulate rotation via APPLY_OPERATION', () => {
200
- const { result } = renderHook( () => useCropperState() );
283
+ const { result } = renderHook( () => useCropperReducer() );
201
284
 
202
285
  act( () => {
203
286
  result.current.applyOperation( {
@@ -217,7 +300,7 @@ describe( 'useCropperState', () => {
217
300
  } );
218
301
 
219
302
  it( 'should handle APPLY_OPERATION for crop', () => {
220
- const { result } = renderHook( () => useCropperState() );
303
+ const { result } = renderHook( () => useCropperReducer() );
221
304
 
222
305
  const rect = { x: 0.1, y: 0.2, width: 0.5, height: 0.6 };
223
306
  act( () => {
@@ -231,7 +314,7 @@ describe( 'useCropperState', () => {
231
314
  } );
232
315
 
233
316
  it( 'should handle APPLY_OPERATION for zoom', () => {
234
- const { result } = renderHook( () => useCropperState() );
317
+ const { result } = renderHook( () => useCropperReducer() );
235
318
 
236
319
  act( () => {
237
320
  result.current.applyOperation( {
@@ -244,7 +327,7 @@ describe( 'useCropperState', () => {
244
327
  } );
245
328
 
246
329
  it( 'should reset to DEFAULT_STATE', () => {
247
- const { result } = renderHook( () => useCropperState() );
330
+ const { result } = renderHook( () => useCropperReducer() );
248
331
 
249
332
  act( () => {
250
333
  result.current.setZoom( 5 );
@@ -261,7 +344,7 @@ describe( 'useCropperState', () => {
261
344
  } );
262
345
 
263
346
  it( 'should reset to a custom state', () => {
264
- const { result } = renderHook( () => useCropperState() );
347
+ const { result } = renderHook( () => useCropperReducer() );
265
348
 
266
349
  act( () => {
267
350
  result.current.setZoom( 5 );
@@ -277,13 +360,13 @@ describe( 'useCropperState', () => {
277
360
 
278
361
  describe( 'isDirty', () => {
279
362
  it( 'should be false initially', () => {
280
- const { result } = renderHook( () => useCropperState() );
363
+ const { result } = renderHook( () => useCropperReducer() );
281
364
 
282
365
  expect( result.current.isDirty ).toBe( false );
283
366
  } );
284
367
 
285
368
  it( 'should be true after changing crop', () => {
286
- const { result } = renderHook( () => useCropperState() );
369
+ const { result } = renderHook( () => useCropperReducer() );
287
370
 
288
371
  // Zoom in first so crop change isn't clamped to (0,0).
289
372
  act( () => {
@@ -298,7 +381,7 @@ describe( 'useCropperState', () => {
298
381
  } );
299
382
 
300
383
  it( 'should be true after changing zoom', () => {
301
- const { result } = renderHook( () => useCropperState() );
384
+ const { result } = renderHook( () => useCropperReducer() );
302
385
 
303
386
  act( () => {
304
387
  result.current.setZoom( 2 );
@@ -308,7 +391,7 @@ describe( 'useCropperState', () => {
308
391
  } );
309
392
 
310
393
  it( 'should be true after changing rotation', () => {
311
- const { result } = renderHook( () => useCropperState() );
394
+ const { result } = renderHook( () => useCropperReducer() );
312
395
 
313
396
  act( () => {
314
397
  result.current.setRotation( 45 );
@@ -318,7 +401,7 @@ describe( 'useCropperState', () => {
318
401
  } );
319
402
 
320
403
  it( 'should be true after changing flip', () => {
321
- const { result } = renderHook( () => useCropperState() );
404
+ const { result } = renderHook( () => useCropperReducer() );
322
405
 
323
406
  act( () => {
324
407
  result.current.setFlip( {
@@ -331,7 +414,7 @@ describe( 'useCropperState', () => {
331
414
  } );
332
415
 
333
416
  it( 'should be false after reset', () => {
334
- const { result } = renderHook( () => useCropperState() );
417
+ const { result } = renderHook( () => useCropperReducer() );
335
418
 
336
419
  act( () => {
337
420
  result.current.setZoom( 5 );
@@ -347,7 +430,7 @@ describe( 'useCropperState', () => {
347
430
  } );
348
431
 
349
432
  it( 'should be false after manually resetting fields to initial values', () => {
350
- const { result } = renderHook( () => useCropperState() );
433
+ const { result } = renderHook( () => useCropperReducer() );
351
434
 
352
435
  // Zoom in and pan.
353
436
  act( () => {
@@ -377,7 +460,7 @@ describe( 'useCropperState', () => {
377
460
  // non-square images. The initial snapshot must be refreshed so
378
461
  // isDirty still reports false at a "clean" post-load state.
379
462
  it( 'should be false after setImage on a non-square image', () => {
380
- const { result } = renderHook( () => useCropperState() );
463
+ const { result } = renderHook( () => useCropperReducer() );
381
464
 
382
465
  act( () => {
383
466
  result.current.setImage( {
@@ -390,12 +473,36 @@ describe( 'useCropperState', () => {
390
473
  expect( result.current.isDirty ).toBe( false );
391
474
  } );
392
475
 
476
+ it( 'does not reset the clean baseline when the same image is reported again', () => {
477
+ const image = {
478
+ src: 'test.jpg',
479
+ naturalWidth: 1600,
480
+ naturalHeight: 900,
481
+ };
482
+ const { result } = renderHook( () => useCropperReducer() );
483
+
484
+ act( () => {
485
+ result.current.setImage( image );
486
+ } );
487
+ act( () => {
488
+ result.current.setRotation( 45 );
489
+ } );
490
+ expect( result.current.isDirty ).toBe( true );
491
+
492
+ act( () => {
493
+ result.current.setImage( image );
494
+ } );
495
+
496
+ expect( result.current.isDirty ).toBe( true );
497
+ expect( result.current.state.rotation ).toBe( 45 );
498
+ } );
499
+
393
500
  // Regression: reset() on a loaded image must produce a "clean"
394
501
  // snapshot that matches what the reducer actually stored
395
502
  // (preserving the image, re-enforcing containment). Otherwise
396
503
  // isDirty reports true right after reset.
397
504
  it( 'should be false after reset on a loaded image', () => {
398
- const { result } = renderHook( () => useCropperState() );
505
+ const { result } = renderHook( () => useCropperReducer() );
399
506
 
400
507
  act( () => {
401
508
  result.current.setImage( {
@@ -424,7 +531,7 @@ describe( 'useCropperState', () => {
424
531
  // For these tests, we need a loaded image so the reducer can
425
532
  // compute minZoomForCover and restrict position.
426
533
  function setupWithImage() {
427
- const view = renderHook( () => useCropperState() );
534
+ const view = renderHook( () => useCropperReducer() );
428
535
  act( () => {
429
536
  view.result.current.setImage( {
430
537
  src: 'test.jpg',
@@ -667,7 +774,7 @@ describe( 'useCropperState', () => {
667
774
 
668
775
  describe( 'SETTLE_CROP', () => {
669
776
  function setupWithImage() {
670
- const view = renderHook( () => useCropperState() );
777
+ const view = renderHook( () => useCropperReducer() );
671
778
  act( () => {
672
779
  view.result.current.setImage( {
673
780
  src: 'test.jpg',
@@ -768,7 +875,7 @@ describe( 'useCropperState', () => {
768
875
 
769
876
  describe( 'SNAP_ROTATE_90', () => {
770
877
  function setupWithImage() {
771
- const view = renderHook( () => useCropperState() );
878
+ const view = renderHook( () => useCropperReducer() );
772
879
  act( () => {
773
880
  view.result.current.setImage( {
774
881
  src: 'test.jpg',
@@ -862,260 +969,9 @@ describe( 'useCropperState', () => {
862
969
  } );
863
970
  } );
864
971
 
865
- describe( 'undo/redo history', () => {
866
- const DEBOUNCE_MS = 300;
867
-
868
- beforeEach( () => jest.useFakeTimers() );
869
- afterEach( () => jest.useRealTimers() );
870
-
871
- // --- debounce batching ---
872
-
873
- it( 'does not create a history entry before the debounce fires', () => {
874
- const { result } = renderHook( () => useCropperState() );
875
- act( () => {
876
- result.current.setZoom( 3 );
877
- } );
878
- expect( result.current.hasUndo ).toBe( false );
879
- } );
880
-
881
- it( 'creates one history entry after the debounce settles', () => {
882
- const { result } = renderHook( () => useCropperState() );
883
- act( () => {
884
- result.current.setZoom( 2 );
885
- result.current.setZoom( 3 );
886
- result.current.setZoom( 4 );
887
- } );
888
- act( () => jest.advanceTimersByTime( DEBOUNCE_MS ) );
889
- expect( result.current.hasUndo ).toBe( true );
890
- act( () => result.current.undo() );
891
- expect( result.current.state.zoom ).toBe( 1 );
892
- expect( result.current.hasUndo ).toBe( false );
893
- } );
894
-
895
- it( 'does not create a history entry for a no-op round trip', () => {
896
- const { result } = renderHook( () => useCropperState() );
897
- act( () => result.current.setZoom( 2 ) );
898
- act( () => result.current.setZoom( 1 ) );
899
- act( () => jest.advanceTimersByTime( DEBOUNCE_MS ) );
900
- expect( result.current.hasUndo ).toBe( false );
901
- } );
902
-
903
- // --- commitHistory flush ---
904
-
905
- it( 'commitHistory flushes the pending entry immediately', () => {
906
- const { result } = renderHook( () => useCropperState() );
907
- // Separate act() calls are required: setZoom dispatches a reducer
908
- // action that React processes when act() flushes. If commitHistory
909
- // runs in the same act(), stateRef.current hasn't updated yet and
910
- // the flush sees no change.
911
- act( () => result.current.setZoom( 3 ) );
912
- act( () => result.current.commitHistory() );
913
- expect( result.current.hasUndo ).toBe( true );
914
- } );
915
-
916
- it( 'commitHistory is a no-op when state has not changed', () => {
917
- const { result } = renderHook( () => useCropperState() );
918
- act( () => {
919
- result.current.commitHistory();
920
- } );
921
- expect( result.current.hasUndo ).toBe( false );
922
- } );
923
-
924
- // --- discrete actions ---
925
-
926
- it( 'toggleFlip creates a history entry immediately', () => {
927
- const { result } = renderHook( () => useCropperState() );
928
- act( () => {
929
- result.current.toggleFlip( 'horizontal' );
930
- } );
931
- expect( result.current.hasUndo ).toBe( true );
932
- } );
933
-
934
- it( 'setFlip creates a history entry immediately', () => {
935
- const { result } = renderHook( () => useCropperState() );
936
- act( () => {
937
- result.current.setFlip( { horizontal: true, vertical: false } );
938
- } );
939
- expect( result.current.hasUndo ).toBe( true );
940
- } );
941
-
942
- it( 'snapRotate90 creates a history entry immediately', () => {
943
- const { result } = renderHook( () => useCropperState() );
944
- act( () => {
945
- result.current.snapRotate90( 1 );
946
- } );
947
- expect( result.current.hasUndo ).toBe( true );
948
- } );
949
-
950
- it( 'applyOperation creates a history entry immediately', () => {
951
- const { result } = renderHook( () => useCropperState() );
952
- act( () => {
953
- result.current.applyOperation( { type: 'zoom', factor: 3 } );
954
- } );
955
- expect( result.current.hasUndo ).toBe( true );
956
- } );
957
-
958
- // --- undo / redo round-trip ---
959
-
960
- it( 'undo restores the previous state and enables redo', () => {
961
- const { result } = renderHook( () => useCropperState() );
962
- act( () => result.current.setZoom( 3 ) );
963
- act( () => result.current.commitHistory() );
964
- act( () => result.current.undo() );
965
- expect( result.current.state.zoom ).toBe( 1 );
966
- expect( result.current.hasUndo ).toBe( false );
967
- expect( result.current.hasRedo ).toBe( true );
968
- } );
969
-
970
- it( 'redo re-applies the undone state', () => {
971
- const { result } = renderHook( () => useCropperState() );
972
- act( () => result.current.setZoom( 3 ) );
973
- act( () => result.current.commitHistory() );
974
- act( () => result.current.undo() );
975
- act( () => result.current.redo() );
976
- expect( result.current.state.zoom ).toBe( 3 );
977
- expect( result.current.hasRedo ).toBe( false );
978
- } );
979
-
980
- it( 'undo after redo returns to a clean initial state', () => {
981
- const { result } = renderHook( () => useCropperState() );
982
- act( () => {
983
- result.current.setImage( {
984
- src: 'test.jpg',
985
- naturalWidth: 1000,
986
- naturalHeight: 500,
987
- } );
988
- } );
989
- act( () => result.current.snapRotate90( 1 ) );
990
- expect( result.current.isDirty ).toBe( true );
991
-
992
- act( () => result.current.undo() );
993
- expect( result.current.isDirty ).toBe( false );
994
-
995
- act( () => result.current.redo() );
996
- expect( result.current.isDirty ).toBe( true );
997
-
998
- act( () => result.current.undo() );
999
- expect( result.current.state.rotation ).toBe( 0 );
1000
- expect( result.current.isDirty ).toBe( false );
1001
- } );
1002
-
1003
- // --- undo/redo with a pending gesture ---
1004
-
1005
- it( 'undo flushes a pending gesture before undoing', () => {
1006
- const { result } = renderHook( () => useCropperState() );
1007
- // Commit one step, then start a second change without committing.
1008
- act( () => result.current.setZoom( 3 ) );
1009
- act( () => result.current.commitHistory() );
1010
- act( () => result.current.setZoom( 5 ) );
1011
- // Undo should flush zoom=5 first, then undo back to zoom=3.
1012
- act( () => result.current.undo() );
1013
- expect( result.current.state.zoom ).toBe( 3 );
1014
- expect( result.current.hasRedo ).toBe( true );
1015
- } );
1016
-
1017
- it( 'undo with no prior history flushes and undoes the pending gesture', () => {
1018
- const { result } = renderHook( () => useCropperState() );
1019
- act( () => {
1020
- result.current.setZoom( 3 );
1021
- } );
1022
- // Undo before the debounce fires — flush saves the change, then
1023
- // immediately undoes it.
1024
- act( () => result.current.undo() );
1025
- expect( result.current.state.zoom ).toBe( 1 );
1026
- } );
1027
-
1028
- // --- setImage and reset do not pollute history ---
1029
-
1030
- it( 'setImage does not create a history entry', () => {
1031
- const { result } = renderHook( () => useCropperState() );
1032
- act( () => {
1033
- result.current.setImage( {
1034
- src: 'test.jpg',
1035
- naturalWidth: 100,
1036
- naturalHeight: 100,
1037
- } );
1038
- } );
1039
- act( () => jest.advanceTimersByTime( DEBOUNCE_MS ) );
1040
- expect( result.current.hasUndo ).toBe( false );
1041
- } );
1042
-
1043
- it( 'reset is undoable and restores a clean current state', () => {
1044
- const { result } = renderHook( () => useCropperState() );
1045
- act( () => result.current.setZoom( 3 ) );
1046
- act( () => result.current.commitHistory() );
1047
- expect( result.current.hasUndo ).toBe( true );
1048
- act( () => result.current.reset() );
1049
- expect( result.current.state.zoom ).toBe( 1 );
1050
- expect( result.current.isDirty ).toBe( false );
1051
- expect( result.current.hasUndo ).toBe( true );
1052
- act( () => result.current.undo() );
1053
- expect( result.current.state.zoom ).toBe( 3 );
1054
- } );
1055
-
1056
- it( 'reset does not create a history entry when already clean', () => {
1057
- const { result } = renderHook( () => useCropperState() );
1058
- act( () => result.current.reset() );
1059
- expect( result.current.hasUndo ).toBe( false );
1060
- } );
1061
-
1062
- // --- discrete action flushes a concurrent continuous gesture ---
1063
-
1064
- it( 'discrete action saves the pending gesture as a separate undo step', () => {
1065
- const { result } = renderHook( () => useCropperState() );
1066
- act( () => {
1067
- result.current.setZoom( 3 );
1068
- } );
1069
- act( () => {
1070
- result.current.setFlip( { horizontal: true, vertical: false } );
1071
- } );
1072
- // First undo removes the flip.
1073
- act( () => result.current.undo() );
1074
- expect( result.current.state.flip.horizontal ).toBe( false );
1075
- expect( result.current.state.zoom ).toBe( 3 );
1076
- // Second undo removes the zoom gesture.
1077
- act( () => result.current.undo() );
1078
- expect( result.current.state.zoom ).toBe( 1 );
1079
- } );
1080
-
1081
- it( 'settleCrop is grouped into the resize undo step', () => {
1082
- const { result } = renderHook( () => useCropperState() );
1083
- act( () => {
1084
- result.current.setImage( {
1085
- src: 'test.jpg',
1086
- naturalWidth: 1000,
1087
- naturalHeight: 500,
1088
- } );
1089
- } );
1090
- const initialCropRect = result.current.state.cropRect;
1091
-
1092
- act( () => {
1093
- result.current.setCropRect( {
1094
- x: 0.25,
1095
- y: 0.25,
1096
- width: 0.5,
1097
- height: 0.5,
1098
- } );
1099
- } );
1100
- act( () => result.current.settleCrop() );
1101
- const settledState = result.current.state;
1102
-
1103
- expect( result.current.hasUndo ).toBe( true );
1104
- act( () => result.current.undo() );
1105
- expect( result.current.state.cropRect ).toEqual( initialCropRect );
1106
- expect( result.current.hasUndo ).toBe( false );
1107
-
1108
- act( () => result.current.redo() );
1109
- expect( result.current.state.cropRect ).toEqual(
1110
- settledState.cropRect
1111
- );
1112
- expect( result.current.state.zoom ).toBe( settledState.zoom );
1113
- } );
1114
- } );
1115
-
1116
972
  describe( 'public controller contract', () => {
1117
973
  it( 'does not expose the raw reducer dispatch', () => {
1118
- const { result } = renderHook( () => useCropperState() );
974
+ const { result } = renderHook( () => useCropperReducer() );
1119
975
 
1120
976
  expect( '__dispatch' in result.current ).toBe( false );
1121
977
  } );
@@ -1124,7 +980,7 @@ describe( 'useCropperState', () => {
1124
980
  describe( 'isStateDirty coverage guard', () => {
1125
981
  // This test ensures that isStateDirty checks ALL fields in CropperState.
1126
982
  // If you add a field to CropperState/DEFAULT_STATE and this test fails,
1127
- // you MUST also update isStateDirty() in use-cropper-state.ts.
983
+ // you MUST also update isStateDirty() in use-cropper-reducer.ts.
1128
984
  it( 'should track all CropperState fields', () => {
1129
985
  // Flatten DEFAULT_STATE keys into dot-notation paths.
1130
986
  // e.g., { pan: { x: 0, y: 0 } } → ['crop.x', 'crop.y']
@@ -89,7 +89,9 @@ function buildAnnouncement(
89
89
  */
90
90
  export function useAriaAnnouncer( state: CropperState ): string {
91
91
  const [ ariaMessage, setAriaMessage ] = useState( '' );
92
- const timerRef = useRef< ReturnType< typeof setTimeout > >();
92
+ const timerRef = useRef< ReturnType< typeof setTimeout > | undefined >(
93
+ undefined
94
+ );
93
95
  const prevMessageRef = useRef( '' );
94
96
  const prevStateRef = useRef< CropperState | null >( null );
95
97
  const latestStateRef = useRef( state );