@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,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/rotation-ruler/index.tsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\nimport { useId, useMemo, useRef } from '@wordpress/element';\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `°`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '°',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5° rotation when step is 1°). Same modifier works\n\t\t// on drag — see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15°) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7°\") or the major itself when on-major (e.g. \"0°\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\t// Split the number into sign + digits so the sign is rendered in a\n\t// separate span and excluded from the active label's centering, the\n\t// same way the unit is.\n\tconst numberText = onMajor ? `${ closestMajor }` : formatValue( value );\n\tconst isNegative = numberText.startsWith( '-' );\n\tconst digits = isNegative ? numberText.slice( 1 ) : numberText;\n\tconst majorTicks = ticks.filter( ( tick ) => tick.kind === 'major' );\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'rotation-ruler', className ) }\n\t\t\trole=\"presentation\"\n\t\t\tdata-testid=\"rotation-ruler\"\n\t\t\tdata-disabled={ disabled || undefined }\n\t\t\t{ ...dragHandlers }\n\t\t>\n\t\t\t<input\n\t\t\t\tref={ inputRef }\n\t\t\t\tid={ inputId }\n\t\t\t\ttype=\"range\"\n\t\t\t\tclassName=\"rotation-ruler__input\"\n\t\t\t\tmin={ min }\n\t\t\t\tmax={ max }\n\t\t\t\tstep=\"any\"\n\t\t\t\tvalue={ value }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taria-label={ label }\n\t\t\t\taria-valuetext={ display }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tclampValue( event.target.valueAsNumber, min, max )\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tonKeyDown={ handleKeyDown }\n\t\t\t/>\n\t\t\t<div className=\"rotation-ruler__strip\" aria-hidden=\"true\">\n\t\t\t\t<svg\n\t\t\t\t\tclassName=\"rotation-ruler__ticks\"\n\t\t\t\t\tstyle={ stripStyle }\n\t\t\t\t\twidth={ ( max - min ) * pxPerUnit }\n\t\t\t\t\theight={ STRIP_HEIGHT }\n\t\t\t\t\tviewBox={ `${ min * pxPerUnit } 0 ${\n\t\t\t\t\t\t( max - min ) * pxPerUnit\n\t\t\t\t\t} ${ STRIP_HEIGHT }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t>\n\t\t\t\t\t{ ticks.map( ( tick ) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx1={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\tx2={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty1={ STRIP_HEIGHT - tick.height }\n\t\t\t\t\t\t\ty2={ STRIP_HEIGHT }\n\t\t\t\t\t\t\tclassName={ `rotation-ruler__tick rotation-ruler__tick--${ tick.kind }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ majorTicks.map( ( tick ) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty={ LABEL_BASELINE_Y }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tclassName=\"rotation-ruler__label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ tick.value }\n\t\t\t\t\t\t\t{ unit }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) ) }\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__active-label\" aria-hidden=\"true\">\n\t\t\t\t<span className=\"rotation-ruler__active-label-number\">\n\t\t\t\t\t{ isNegative && (\n\t\t\t\t\t\t<span className=\"rotation-ruler__active-label-sign\">\n\t\t\t\t\t\t\t-\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ digits }\n\t\t\t\t\t<span className=\"rotation-ruler__active-label-unit\">\n\t\t\t\t\t\t{ unit }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__pointer\" aria-hidden=\"true\" />\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";AAAA,OAAO,UAAU;AAEjB,SAAS,OAAO,SAAS,cAAc;AACvC,SAAS,cAAc,kBAAkB;AAqMtC,cAyCG,YAzCH;AAhKH,IAAM,eAAe;AACrB,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;AACxB,IAAM,oBAAoB;AAe1B,SAAS,SAAU,KAAa,KAAsB;AACrD,SAAO,QAAS,MAAM;AACrB,UAAM,MAAc,CAAC;AACrB,aAAU,IAAI,KAAK,KAAM,GAAI,GAAG,KAAK,KAAK,MAAO,GAAI,GAAG,KAAK,GAAI;AAChE,UAAI,OAAiB;AACrB,UAAI,SAAS;AACb,UAAK,IAAI,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AU,MAAM,OAAQ;AAAA,YACxB,QAAS;AAAA,YACT,SAAU,GAAI,MAAM,SAAU,OAC3B,MAAM,OAAQ,SACjB,IAAK,YAAa;AAAA,YAClB,qBAAoB;AAAA,YAElB;AAAA,oBAAM,IAAK,CAAE,SACd;AAAA,gBAAC;AAAA;AAAA,kBAEA,IAAK,KAAK,QAAQ;AAAA,kBAClB,IAAK,KAAK,QAAQ;AAAA,kBAClB,IAAK,eAAe,KAAK;AAAA,kBACzB,IAAK;AAAA,kBACL,WAAY,8CAA+C,KAAK,IAAK;AAAA;AAAA,gBAL/D,KAAK;AAAA,cAMZ,CACC;AAAA,cACA,WAAW,IAAK,CAAE,SACnB;AAAA,gBAAC;AAAA;AAAA,kBAEA,GAAI,KAAK,QAAQ;AAAA,kBACjB,GAAI;AAAA,kBACJ,YAAW;AAAA,kBACX,WAAU;AAAA,kBAER;AAAA,yBAAK;AAAA,oBACL;AAAA;AAAA;AAAA,gBAPI,KAAK;AAAA,cAQZ,CACC;AAAA;AAAA;AAAA,QACH,GACD;AAAA,QACA,oBAAC,SAAI,WAAU,gCAA+B,eAAY,QACzD,+BAAC,UAAK,WAAU,uCACb;AAAA,wBACD,oBAAC,UAAK,WAAU,qCAAoC,eAEpD;AAAA,UAEC;AAAA,UACF,oBAAC,UAAK,WAAU,qCACb,gBACH;AAAA,WACD,GACD;AAAA,QACA,oBAAC,SAAI,WAAU,2BAA0B,eAAY,QAAO;AAAA;AAAA;AAAA,EAC7D;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/rotation-ruler/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\nimport { useId, useMemo, useRef } from '@wordpress/element';\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `°`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '°',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5° rotation when step is 1°). Same modifier works\n\t\t// on drag — see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15°) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7°\") or the major itself when on-major (e.g. \"0°\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\t// Split the number into sign + digits so the sign is rendered in a\n\t// separate span and excluded from the active label's centering, the\n\t// same way the unit is.\n\tconst numberText = onMajor ? `${ closestMajor }` : formatValue( value );\n\tconst isNegative = numberText.startsWith( '-' );\n\tconst digits = isNegative ? numberText.slice( 1 ) : numberText;\n\tconst majorTicks = ticks.filter( ( tick ) => tick.kind === 'major' );\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'rotation-ruler', className ) }\n\t\t\trole=\"presentation\"\n\t\t\tdata-testid=\"rotation-ruler\"\n\t\t\tdata-disabled={ disabled || undefined }\n\t\t\t{ ...dragHandlers }\n\t\t>\n\t\t\t<input\n\t\t\t\tref={ inputRef }\n\t\t\t\tid={ inputId }\n\t\t\t\ttype=\"range\"\n\t\t\t\tclassName=\"rotation-ruler__input\"\n\t\t\t\tmin={ min }\n\t\t\t\tmax={ max }\n\t\t\t\tstep=\"any\"\n\t\t\t\tvalue={ value }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taria-label={ label }\n\t\t\t\taria-valuetext={ display }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tclampValue( event.target.valueAsNumber, min, max )\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tonKeyDown={ handleKeyDown }\n\t\t\t/>\n\t\t\t<div className=\"rotation-ruler__strip\" aria-hidden=\"true\">\n\t\t\t\t<svg\n\t\t\t\t\tclassName=\"rotation-ruler__ticks\"\n\t\t\t\t\tstyle={ stripStyle }\n\t\t\t\t\twidth={ ( max - min ) * pxPerUnit }\n\t\t\t\t\theight={ STRIP_HEIGHT }\n\t\t\t\t\tviewBox={ `${ min * pxPerUnit } 0 ${\n\t\t\t\t\t\t( max - min ) * pxPerUnit\n\t\t\t\t\t} ${ STRIP_HEIGHT }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t>\n\t\t\t\t\t{ ticks.map( ( tick ) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx1={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\tx2={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty1={ STRIP_HEIGHT - tick.height }\n\t\t\t\t\t\t\ty2={ STRIP_HEIGHT }\n\t\t\t\t\t\t\tclassName={ `rotation-ruler__tick rotation-ruler__tick--${ tick.kind }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ majorTicks.map( ( tick ) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty={ LABEL_BASELINE_Y }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tclassName=\"rotation-ruler__label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ tick.value }\n\t\t\t\t\t\t\t{ unit }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) ) }\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__active-label\" aria-hidden=\"true\">\n\t\t\t\t<span className=\"rotation-ruler__active-label-number\">\n\t\t\t\t\t{ isNegative && (\n\t\t\t\t\t\t<span className=\"rotation-ruler__active-label-sign\">\n\t\t\t\t\t\t\t-\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ digits }\n\t\t\t\t\t<span className=\"rotation-ruler__active-label-unit\">\n\t\t\t\t\t\t{ unit }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__pointer\" aria-hidden=\"true\" />\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;;;;;;;AAe1B,SAAS,SAAU,KAAa,KAAsB;CACrD,OAAO,cAAe;EACrB,MAAM,MAAc,CAAC;EACrB,KAAM,IAAI,IAAI,KAAK,KAAM,GAAI,GAAG,KAAK,KAAK,MAAO,GAAI,GAAG,KAAK,GAAI;GAChE,IAAI,OAAiB;GACrB,IAAI,SAAS;GACb,IAAK,IAAI,O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N,CACL,CACE;;GACD,CAAA;GACL,oBAAC,OAAD;IAAK,WAAU;IAA+B,eAAY;IACzD,UAAA,qBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA;MACG,cACD,oBAAC,QAAD;OAAM,WAAU;OAAoC,UAAA;MAE9C,CAAA;MAEL;MACF,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;KACD;;GACF,CAAA;GACL,oBAAC,OAAD;IAAK,WAAU;IAA0B,eAAY;GAAQ,CAAA;EACzD;;AAEP"}
@@ -1,131 +1,134 @@
1
- // packages/media-editor/src/components/rotation-ruler/use-ruler-drag.ts
2
1
  import { useCallback, useEffect, useRef } from "@wordpress/element";
2
+ // packages/media-editor/src/components/rotation-ruler/use-ruler-drag.ts
3
+ /**
4
+ * Convert a horizontal pointer delta (px) into a value delta.
5
+ *
6
+ * Negative because dragging the ruler to the right should expose
7
+ * smaller values to the left of the fixed center pointer (and vice
8
+ * versa) — the ruler scrubs *under* the pointer.
9
+ *
10
+ * @param deltaPx Pointer movement in CSS pixels.
11
+ * @param pixelsPerStep CSS pixels of pointer travel per `step`.
12
+ * @param step Value units per step.
13
+ */
3
14
  function pxToValueDelta(deltaPx, pixelsPerStep, step) {
4
- return -deltaPx / pixelsPerStep * step;
15
+ return -deltaPx / pixelsPerStep * step;
5
16
  }
17
+ /**
18
+ * Clamp `value` to the inclusive `[min, max]` interval.
19
+ *
20
+ * @param value Value to clamp.
21
+ * @param min Lower bound (inclusive).
22
+ * @param max Upper bound (inclusive).
23
+ */
6
24
  function clampValue(value, min, max) {
7
- if (value < min) {
8
- return min;
9
- }
10
- if (value > max) {
11
- return max;
12
- }
13
- return value;
25
+ if (value < min) return min;
26
+ if (value > max) return max;
27
+ return value;
14
28
  }
29
+ /**
30
+ * Round `value` to the nearest multiple of `step`.
31
+ *
32
+ * @param value Value to quantize.
33
+ * @param step Step granularity (must be > 0).
34
+ */
15
35
  function quantize(value, step) {
16
- return Math.round(value / step) * step;
36
+ return Math.round(value / step) * step;
17
37
  }
38
+ /**
39
+ * Drag-the-ruler gesture for a horizontal slider. Translates pointer
40
+ * movement into value changes quantized to `step`; the caller renders
41
+ * the visuals and holds the value.
42
+ *
43
+ * The hook owns no state of its own — every value change is reported
44
+ * through the supplied `onChange`. The "current value" is read from a
45
+ * ref so closure staleness during a drag is impossible. Drag continues
46
+ * past the wrapper's bounds (standard slider behaviour); a window-level
47
+ * `pointerup` listener guarantees the drag ends and pointer capture
48
+ * releases even if the underlying captured event never fires on the
49
+ * wrapper.
50
+ *
51
+ * @param options Ruler-drag configuration. See `UseRulerDragOptions`.
52
+ */
18
53
  function useRulerDrag(options) {
19
- const {
20
- value,
21
- onChange,
22
- min,
23
- max,
24
- step,
25
- pixelsPerStep,
26
- disabled,
27
- onPointerDownStart
28
- } = options;
29
- const latestRef = useRef({
30
- value,
31
- startX: 0,
32
- startValue: 0,
33
- activeStep: step,
34
- dragging: false,
35
- captureElement: null,
36
- capturePointerId: 0,
37
- windowPointerUp: null
38
- });
39
- useEffect(() => {
40
- latestRef.current.value = value;
41
- }, [value]);
42
- const endDrag = useCallback(() => {
43
- const state = latestRef.current;
44
- if (!state.dragging) {
45
- return;
46
- }
47
- state.dragging = false;
48
- if (state.captureElement && state.captureElement.hasPointerCapture(state.capturePointerId)) {
49
- state.captureElement.releasePointerCapture(
50
- state.capturePointerId
51
- );
52
- }
53
- state.captureElement = null;
54
- if (state.windowPointerUp) {
55
- window.removeEventListener("pointerup", state.windowPointerUp);
56
- window.removeEventListener(
57
- "pointercancel",
58
- state.windowPointerUp
59
- );
60
- state.windowPointerUp = null;
61
- }
62
- }, []);
63
- useEffect(() => endDrag, [endDrag]);
64
- useEffect(() => {
65
- if (disabled) {
66
- endDrag();
67
- }
68
- }, [disabled, endDrag]);
69
- const onPointerDown = useCallback(
70
- (event) => {
71
- if (disabled || event.button !== 0) {
72
- return;
73
- }
74
- const state = latestRef.current;
75
- event.currentTarget.setPointerCapture(event.pointerId);
76
- state.captureElement = event.currentTarget;
77
- state.capturePointerId = event.pointerId;
78
- state.startX = event.clientX;
79
- state.startValue = state.value;
80
- state.activeStep = event.shiftKey ? step / 2 : step;
81
- state.dragging = true;
82
- onPointerDownStart?.();
83
- const onWindowUp = () => endDrag();
84
- state.windowPointerUp = onWindowUp;
85
- window.addEventListener("pointerup", onWindowUp);
86
- window.addEventListener("pointercancel", onWindowUp);
87
- },
88
- [disabled, onPointerDownStart, endDrag, step]
89
- );
90
- const onPointerMove = useCallback(
91
- (event) => {
92
- const state = latestRef.current;
93
- if (disabled || !state.dragging) {
94
- return;
95
- }
96
- const requestedStep = event.shiftKey ? step / 2 : step;
97
- if (requestedStep !== state.activeStep) {
98
- state.startX = event.clientX;
99
- state.startValue = state.value;
100
- state.activeStep = requestedStep;
101
- }
102
- const deltaPx = event.clientX - state.startX;
103
- const deltaValue = pxToValueDelta(
104
- deltaPx,
105
- pixelsPerStep,
106
- state.activeStep
107
- );
108
- const raw = state.startValue + deltaValue;
109
- const stepped = quantize(raw, state.activeStep);
110
- const next = clampValue(stepped, min, max);
111
- if (next !== state.value) {
112
- state.value = next;
113
- onChange(next);
114
- }
115
- },
116
- [disabled, onChange, min, max, step, pixelsPerStep]
117
- );
118
- return {
119
- onPointerDown,
120
- onPointerMove,
121
- onPointerUp: endDrag,
122
- onPointerCancel: endDrag
123
- };
54
+ const { value, onChange, min, max, step, pixelsPerStep, disabled, onPointerDownStart } = options;
55
+ const latestRef = useRef({
56
+ value,
57
+ startX: 0,
58
+ startValue: 0,
59
+ activeStep: step,
60
+ dragging: false,
61
+ captureElement: null,
62
+ capturePointerId: 0,
63
+ windowPointerUp: null
64
+ });
65
+ const endDrag = useCallback(() => {
66
+ const state = latestRef.current;
67
+ if (!state.dragging) return;
68
+ state.dragging = false;
69
+ if (state.captureElement && state.captureElement.hasPointerCapture(state.capturePointerId)) state.captureElement.releasePointerCapture(state.capturePointerId);
70
+ state.captureElement = null;
71
+ if (state.windowPointerUp) {
72
+ window.removeEventListener("pointerup", state.windowPointerUp);
73
+ window.removeEventListener("pointercancel", state.windowPointerUp);
74
+ state.windowPointerUp = null;
75
+ }
76
+ }, []);
77
+ useEffect(() => endDrag, [endDrag]);
78
+ useEffect(() => {
79
+ if (disabled) endDrag();
80
+ }, [disabled, endDrag]);
81
+ return {
82
+ onPointerDown: useCallback((event) => {
83
+ if (disabled || event.button !== 0) return;
84
+ const state = latestRef.current;
85
+ event.currentTarget.setPointerCapture(event.pointerId);
86
+ state.captureElement = event.currentTarget;
87
+ state.capturePointerId = event.pointerId;
88
+ state.startX = event.clientX;
89
+ state.value = value;
90
+ state.startValue = value;
91
+ state.activeStep = event.shiftKey ? step / 2 : step;
92
+ state.dragging = true;
93
+ onPointerDownStart?.();
94
+ const onWindowUp = () => endDrag();
95
+ state.windowPointerUp = onWindowUp;
96
+ window.addEventListener("pointerup", onWindowUp);
97
+ window.addEventListener("pointercancel", onWindowUp);
98
+ }, [
99
+ disabled,
100
+ onPointerDownStart,
101
+ endDrag,
102
+ step,
103
+ value
104
+ ]),
105
+ onPointerMove: useCallback((event) => {
106
+ const state = latestRef.current;
107
+ if (disabled || !state.dragging) return;
108
+ const requestedStep = event.shiftKey ? step / 2 : step;
109
+ if (requestedStep !== state.activeStep) {
110
+ state.startX = event.clientX;
111
+ state.startValue = state.value;
112
+ state.activeStep = requestedStep;
113
+ }
114
+ const deltaValue = pxToValueDelta(event.clientX - state.startX, pixelsPerStep, state.activeStep);
115
+ const next = clampValue(quantize(state.startValue + deltaValue, state.activeStep), min, max);
116
+ if (next !== state.value) {
117
+ state.value = next;
118
+ onChange(next);
119
+ }
120
+ }, [
121
+ disabled,
122
+ onChange,
123
+ min,
124
+ max,
125
+ step,
126
+ pixelsPerStep
127
+ ]),
128
+ onPointerUp: endDrag,
129
+ onPointerCancel: endDrag
130
+ };
124
131
  }
125
- export {
126
- clampValue,
127
- pxToValueDelta,
128
- quantize,
129
- useRulerDrag
130
- };
131
- //# sourceMappingURL=use-ruler-drag.mjs.map
132
+ export { clampValue, pxToValueDelta, quantize, useRulerDrag };
133
+
134
+ //# sourceMappingURL=use-ruler-drag.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/rotation-ruler/use-ruler-drag.ts"],
4
- "sourcesContent": ["import { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Convert a horizontal pointer delta (px) into a value delta.\n *\n * Negative because dragging the ruler to the right should expose\n * smaller values to the left of the fixed center pointer (and vice\n * versa) — the ruler scrubs *under* the pointer.\n *\n * @param deltaPx Pointer movement in CSS pixels.\n * @param pixelsPerStep CSS pixels of pointer travel per `step`.\n * @param step Value units per step.\n */\nexport function pxToValueDelta(\n\tdeltaPx: number,\n\tpixelsPerStep: number,\n\tstep: number\n): number {\n\treturn ( -deltaPx / pixelsPerStep ) * step;\n}\n\n/**\n * Clamp `value` to the inclusive `[min, max]` interval.\n *\n * @param value Value to clamp.\n * @param min Lower bound (inclusive).\n * @param max Upper bound (inclusive).\n */\nexport function clampValue( value: number, min: number, max: number ): number {\n\tif ( value < min ) {\n\t\treturn min;\n\t}\n\tif ( value > max ) {\n\t\treturn max;\n\t}\n\treturn value;\n}\n\n/**\n * Round `value` to the nearest multiple of `step`.\n *\n * @param value Value to quantize.\n * @param step Step granularity (must be > 0).\n */\nexport function quantize( value: number, step: number ): number {\n\treturn Math.round( value / step ) * step;\n}\n\nexport interface UseRulerDragOptions {\n\tvalue: number;\n\tonChange: ( next: number ) => void;\n\tmin: number;\n\tmax: number;\n\tstep: number;\n\tpixelsPerStep: number;\n\tdisabled: boolean;\n\t/** Called once on pointerdown so the caller can focus the input. */\n\tonPointerDownStart?: () => void;\n}\n\nexport interface RulerDragHandlers {\n\tonPointerDown: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerMove: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerUp: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerCancel: ( event: React.PointerEvent< HTMLElement > ) => void;\n}\n\n/**\n * Drag-the-ruler gesture for a horizontal slider. Translates pointer\n * movement into value changes quantized to `step`; the caller renders\n * the visuals and holds the value.\n *\n * The hook owns no state of its own — every value change is reported\n * through the supplied `onChange`. The \"current value\" is read from a\n * ref so closure staleness during a drag is impossible. Drag continues\n * past the wrapper's bounds (standard slider behaviour); a window-level\n * `pointerup` listener guarantees the drag ends and pointer capture\n * releases even if the underlying captured event never fires on the\n * wrapper.\n *\n * @param options Ruler-drag configuration. See `UseRulerDragOptions`.\n */\nexport function useRulerDrag(\n\toptions: UseRulerDragOptions\n): RulerDragHandlers {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart,\n\t} = options;\n\n\t// Mutable mirror of the latest committed value plus per-drag state.\n\t// Pointermove handlers fire far faster than React commits, so we\n\t// cannot read `value` from closure. The `value` write happens in an\n\t// effect (not at render time) to satisfy `react-hooks/refs`; the\n\t// effect flushes after commit, so by the time any pointer handler\n\t// runs, the ref reflects the latest committed `value`.\n\tconst latestRef = useRef< {\n\t\tvalue: number;\n\t\tstartX: number;\n\t\tstartValue: number;\n\t\tactiveStep: number;\n\t\tdragging: boolean;\n\t\tcaptureElement: HTMLElement | null;\n\t\tcapturePointerId: number;\n\t\twindowPointerUp: ( () => void ) | null;\n\t} >( {\n\t\tvalue,\n\t\tstartX: 0,\n\t\tstartValue: 0,\n\t\tactiveStep: step,\n\t\tdragging: false,\n\t\tcaptureElement: null,\n\t\tcapturePointerId: 0,\n\t\twindowPointerUp: null,\n\t} );\n\tuseEffect( () => {\n\t\tlatestRef.current.value = value;\n\t}, [ value ] );\n\n\tconst endDrag = useCallback( () => {\n\t\tconst state = latestRef.current;\n\t\tif ( ! state.dragging ) {\n\t\t\treturn;\n\t\t}\n\t\tstate.dragging = false;\n\t\tif (\n\t\t\tstate.captureElement &&\n\t\t\tstate.captureElement.hasPointerCapture( state.capturePointerId )\n\t\t) {\n\t\t\tstate.captureElement.releasePointerCapture(\n\t\t\t\tstate.capturePointerId\n\t\t\t);\n\t\t}\n\t\tstate.captureElement = null;\n\t\tif ( state.windowPointerUp ) {\n\t\t\twindow.removeEventListener( 'pointerup', state.windowPointerUp );\n\t\t\twindow.removeEventListener(\n\t\t\t\t'pointercancel',\n\t\t\t\tstate.windowPointerUp\n\t\t\t);\n\t\t\tstate.windowPointerUp = null;\n\t\t}\n\t}, [] );\n\n\t// Cleanup any in-flight drag on unmount so we never leak window\n\t// listeners or stale pointer capture.\n\tuseEffect( () => endDrag, [ endDrag ] );\n\n\t// Becoming disabled mid-drag ends it, so a rotation cannot keep\n\t// changing after a save has read it.\n\tuseEffect( () => {\n\t\tif ( disabled ) {\n\t\t\tendDrag();\n\t\t}\n\t}, [ disabled, endDrag ] );\n\n\tconst onPointerDown = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tif ( disabled || event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst state = latestRef.current;\n\t\t\tevent.currentTarget.setPointerCapture( event.pointerId );\n\t\t\tstate.captureElement = event.currentTarget;\n\t\t\tstate.capturePointerId = event.pointerId;\n\t\t\tstate.startX = event.clientX;\n\t\t\tstate.startValue = state.value;\n\t\t\tstate.activeStep = event.shiftKey ? step / 2 : step;\n\t\t\tstate.dragging = true;\n\t\t\tonPointerDownStart?.();\n\n\t\t\t// Window-level backstop. With `setPointerCapture`, the\n\t\t\t// element should always receive `pointerup` even when the\n\t\t\t// cursor is released outside its bounds — but in practice\n\t\t\t// some browsers / window-blur sequences drop the event. The\n\t\t\t// window listener guarantees the drag ends and capture\n\t\t\t// releases.\n\t\t\tconst onWindowUp = () => endDrag();\n\t\t\tstate.windowPointerUp = onWindowUp;\n\t\t\twindow.addEventListener( 'pointerup', onWindowUp );\n\t\t\twindow.addEventListener( 'pointercancel', onWindowUp );\n\t\t},\n\t\t[ disabled, onPointerDownStart, endDrag, step ]\n\t);\n\n\tconst onPointerMove = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tconst state = latestRef.current;\n\t\t\tif ( disabled || ! state.dragging ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Shift toggles fine mode mid-drag. The drag math computes\n\t\t\t// from `startX` / `startValue`, so naively swapping `step`\n\t\t\t// would yank the value backward. Rebase to the current\n\t\t\t// pointer + value so the granularity changes without a\n\t\t\t// jump.\n\t\t\tconst requestedStep = event.shiftKey ? step / 2 : step;\n\t\t\tif ( requestedStep !== state.activeStep ) {\n\t\t\t\tstate.startX = event.clientX;\n\t\t\t\tstate.startValue = state.value;\n\t\t\t\tstate.activeStep = requestedStep;\n\t\t\t}\n\t\t\tconst deltaPx = event.clientX - state.startX;\n\t\t\tconst deltaValue = pxToValueDelta(\n\t\t\t\tdeltaPx,\n\t\t\t\tpixelsPerStep,\n\t\t\t\tstate.activeStep\n\t\t\t);\n\t\t\tconst raw = state.startValue + deltaValue;\n\t\t\tconst stepped = quantize( raw, state.activeStep );\n\t\t\tconst next = clampValue( stepped, min, max );\n\t\t\tif ( next !== state.value ) {\n\t\t\t\t// Update the ref synchronously so consecutive pointermove\n\t\t\t\t// events that fire before React commits still see the\n\t\t\t\t// last *emitted* value as `previous` for the next math.\n\t\t\t\tstate.value = next;\n\t\t\t\tonChange( next );\n\t\t\t}\n\t\t},\n\t\t[ disabled, onChange, min, max, step, pixelsPerStep ]\n\t);\n\n\treturn {\n\t\tonPointerDown,\n\t\tonPointerMove,\n\t\tonPointerUp: endDrag,\n\t\tonPointerCancel: endDrag,\n\t};\n}\n"],
5
- "mappings": ";AAAA,SAAS,aAAa,WAAW,cAAc;AAaxC,SAAS,eACf,SACA,eACA,MACS;AACT,SAAS,CAAC,UAAU,gBAAkB;AACvC;AASO,SAAS,WAAY,OAAe,KAAa,KAAsB;AAC7E,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,KAAM;AACl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ruler-drag.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Convert a horizontal pointer delta (px) into a value delta.\n *\n * Negative because dragging the ruler to the right should expose\n * smaller values to the left of the fixed center pointer (and vice\n * versa) — the ruler scrubs *under* the pointer.\n *\n * @param deltaPx Pointer movement in CSS pixels.\n * @param pixelsPerStep CSS pixels of pointer travel per `step`.\n * @param step Value units per step.\n */\nexport function pxToValueDelta(\n\tdeltaPx: number,\n\tpixelsPerStep: number,\n\tstep: number\n): number {\n\treturn ( -deltaPx / pixelsPerStep ) * step;\n}\n\n/**\n * Clamp `value` to the inclusive `[min, max]` interval.\n *\n * @param value Value to clamp.\n * @param min Lower bound (inclusive).\n * @param max Upper bound (inclusive).\n */\nexport function clampValue( value: number, min: number, max: number ): number {\n\tif ( value < min ) {\n\t\treturn min;\n\t}\n\tif ( value > max ) {\n\t\treturn max;\n\t}\n\treturn value;\n}\n\n/**\n * Round `value` to the nearest multiple of `step`.\n *\n * @param value Value to quantize.\n * @param step Step granularity (must be > 0).\n */\nexport function quantize( value: number, step: number ): number {\n\treturn Math.round( value / step ) * step;\n}\n\nexport interface UseRulerDragOptions {\n\tvalue: number;\n\tonChange: ( next: number ) => void;\n\tmin: number;\n\tmax: number;\n\tstep: number;\n\tpixelsPerStep: number;\n\tdisabled: boolean;\n\t/** Called once on pointerdown so the caller can focus the input. */\n\tonPointerDownStart?: () => void;\n}\n\nexport interface RulerDragHandlers {\n\tonPointerDown: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerMove: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerUp: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerCancel: ( event: React.PointerEvent< HTMLElement > ) => void;\n}\n\n/**\n * Drag-the-ruler gesture for a horizontal slider. Translates pointer\n * movement into value changes quantized to `step`; the caller renders\n * the visuals and holds the value.\n *\n * The hook owns no state of its own — every value change is reported\n * through the supplied `onChange`. The \"current value\" is read from a\n * ref so closure staleness during a drag is impossible. Drag continues\n * past the wrapper's bounds (standard slider behaviour); a window-level\n * `pointerup` listener guarantees the drag ends and pointer capture\n * releases even if the underlying captured event never fires on the\n * wrapper.\n *\n * @param options Ruler-drag configuration. See `UseRulerDragOptions`.\n */\nexport function useRulerDrag(\n\toptions: UseRulerDragOptions\n): RulerDragHandlers {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart,\n\t} = options;\n\n\t// Per-drag state, including the last emitted value. Pointermove\n\t// handlers fire far faster than React commits, so they cannot read\n\t// `value` from closure. Pointerdown seeds it from the committed `value`.\n\tconst latestRef = useRef< {\n\t\tvalue: number;\n\t\tstartX: number;\n\t\tstartValue: number;\n\t\tactiveStep: number;\n\t\tdragging: boolean;\n\t\tcaptureElement: HTMLElement | null;\n\t\tcapturePointerId: number;\n\t\twindowPointerUp: ( () => void ) | null;\n\t} >( {\n\t\tvalue,\n\t\tstartX: 0,\n\t\tstartValue: 0,\n\t\tactiveStep: step,\n\t\tdragging: false,\n\t\tcaptureElement: null,\n\t\tcapturePointerId: 0,\n\t\twindowPointerUp: null,\n\t} );\n\n\tconst endDrag = useCallback( () => {\n\t\tconst state = latestRef.current;\n\t\tif ( ! state.dragging ) {\n\t\t\treturn;\n\t\t}\n\t\tstate.dragging = false;\n\t\tif (\n\t\t\tstate.captureElement &&\n\t\t\tstate.captureElement.hasPointerCapture( state.capturePointerId )\n\t\t) {\n\t\t\tstate.captureElement.releasePointerCapture(\n\t\t\t\tstate.capturePointerId\n\t\t\t);\n\t\t}\n\t\tstate.captureElement = null;\n\t\tif ( state.windowPointerUp ) {\n\t\t\twindow.removeEventListener( 'pointerup', state.windowPointerUp );\n\t\t\twindow.removeEventListener(\n\t\t\t\t'pointercancel',\n\t\t\t\tstate.windowPointerUp\n\t\t\t);\n\t\t\tstate.windowPointerUp = null;\n\t\t}\n\t}, [] );\n\n\t// Cleanup any in-flight drag on unmount so we never leak window\n\t// listeners or stale pointer capture.\n\tuseEffect( () => endDrag, [ endDrag ] );\n\n\t// Becoming disabled mid-drag ends it, so a rotation cannot keep\n\t// changing after a save has read it.\n\tuseEffect( () => {\n\t\tif ( disabled ) {\n\t\t\tendDrag();\n\t\t}\n\t}, [ disabled, endDrag ] );\n\n\tconst onPointerDown = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tif ( disabled || event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst state = latestRef.current;\n\t\t\tevent.currentTarget.setPointerCapture( event.pointerId );\n\t\t\tstate.captureElement = event.currentTarget;\n\t\t\tstate.capturePointerId = event.pointerId;\n\t\t\tstate.startX = event.clientX;\n\t\t\tstate.value = value;\n\t\t\tstate.startValue = value;\n\t\t\tstate.activeStep = event.shiftKey ? step / 2 : step;\n\t\t\tstate.dragging = true;\n\t\t\tonPointerDownStart?.();\n\n\t\t\t// Window-level backstop. With `setPointerCapture`, the\n\t\t\t// element should always receive `pointerup` even when the\n\t\t\t// cursor is released outside its bounds — but in practice\n\t\t\t// some browsers / window-blur sequences drop the event. The\n\t\t\t// window listener guarantees the drag ends and capture\n\t\t\t// releases.\n\t\t\tconst onWindowUp = () => endDrag();\n\t\t\tstate.windowPointerUp = onWindowUp;\n\t\t\twindow.addEventListener( 'pointerup', onWindowUp );\n\t\t\twindow.addEventListener( 'pointercancel', onWindowUp );\n\t\t},\n\t\t[ disabled, onPointerDownStart, endDrag, step, value ]\n\t);\n\n\tconst onPointerMove = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tconst state = latestRef.current;\n\t\t\tif ( disabled || ! state.dragging ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Shift toggles fine mode mid-drag. The drag math computes\n\t\t\t// from `startX` / `startValue`, so naively swapping `step`\n\t\t\t// would yank the value backward. Rebase to the current\n\t\t\t// pointer + value so the granularity changes without a\n\t\t\t// jump.\n\t\t\tconst requestedStep = event.shiftKey ? step / 2 : step;\n\t\t\tif ( requestedStep !== state.activeStep ) {\n\t\t\t\tstate.startX = event.clientX;\n\t\t\t\tstate.startValue = state.value;\n\t\t\t\tstate.activeStep = requestedStep;\n\t\t\t}\n\t\t\tconst deltaPx = event.clientX - state.startX;\n\t\t\tconst deltaValue = pxToValueDelta(\n\t\t\t\tdeltaPx,\n\t\t\t\tpixelsPerStep,\n\t\t\t\tstate.activeStep\n\t\t\t);\n\t\t\tconst raw = state.startValue + deltaValue;\n\t\t\tconst stepped = quantize( raw, state.activeStep );\n\t\t\tconst next = clampValue( stepped, min, max );\n\t\t\tif ( next !== state.value ) {\n\t\t\t\t// Update the ref synchronously so consecutive pointermove\n\t\t\t\t// events that fire before React commits still see the\n\t\t\t\t// last *emitted* value as `previous` for the next math.\n\t\t\t\tstate.value = next;\n\t\t\t\tonChange( next );\n\t\t\t}\n\t\t},\n\t\t[ disabled, onChange, min, max, step, pixelsPerStep ]\n\t);\n\n\treturn {\n\t\tonPointerDown,\n\t\tonPointerMove,\n\t\tonPointerUp: endDrag,\n\t\tonPointerCancel: endDrag,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,eACf,SACA,eACA,MACS;CACT,OAAS,CAAC,UAAU,gBAAkB;AACvC;;;;;;;;AASA,SAAgB,WAAY,OAAe,KAAa,KAAsB;CAC7E,IAAK,QAAQ,KACZ,OAAO;CAER,IAAK,QAAQ,KACZ,OAAO;CAER,OAAO;AACR;;;;;;;AAQA,SAAgB,SAAU,OAAe,MAAuB;CAC/D,OAAO,KAAK,MAAO,QAAQ,IAAK,IAAI;AACrC;;;;;;;;;;;;;;;;AAoCA,SAAgB,aACf,SACoB;CACpB,MAAM,EACL,OACA,UACA,KACA,KACA,MACA,eACA,UACA,uBACG;CAKJ,MAAM,YAAY,OASb;EACJ;EACA,QAAQ;EACR,YAAY;EACZ,YAAY;EACZ,UAAU;EACV,gBAAgB;EACh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,MAAM;IACzB,MAAM,aAAa;GACpB;GAEA,MAAM,aAAa,eADH,MAAM,UAAU,MAAM,QAGrC,eACA,MAAM,UACP;GAGA,MAAM,OAAO,WADG,SADJ,MAAM,aAAa,YACA,MAAM,UACN,GAAG,KAAK,GAAI;GAC3C,IAAK,SAAS,MAAM,OAAQ;IAI3B,MAAM,QAAQ;IACd,SAAU,IAAK;GAChB;EACD,GACA;GAAE;GAAU;GAAU;GAAK;GAAK;GAAM;EAAc,CAKxC;EACZ,aAAa;EACb,iBAAiB;CAClB;AACD"}
@@ -1,54 +1,80 @@
1
- // packages/media-editor/src/hooks/use-crop-gesture-handlers.ts
2
1
  import { useCallback, useEffect, useRef } from "@wordpress/element";
3
2
  import { useMediaEditor } from "../state/index.mjs";
4
- var CROP_CONTROL_ATTR = "data-crop-control";
5
- var KEYBOARD_GESTURE_IDLE_MS = 300;
3
+ // packages/media-editor/src/hooks/use-crop-gesture-handlers.ts
4
+ /**
5
+ * Data attribute applied to crop control wrappers. The modal's keyboard
6
+ * shortcut handler uses this to distinguish crop controls (where custom
7
+ * undo/redo should fire) from metadata text fields (where the browser's
8
+ * native undo should be preserved).
9
+ */
10
+ const CROP_CONTROL_ATTR = "data-crop-control";
11
+ /** Idle window used to group repeated keyboard input into one gesture. */
12
+ const KEYBOARD_GESTURE_IDLE_MS = 300;
13
+ /**
14
+ * Event handler props to spread onto a wrapper element around a crop
15
+ * control. Marks the wrapper as a crop control (via `data-crop-control`)
16
+ * so the modal's Cmd+Z handler can identify it, and wires gesture
17
+ * boundaries on the composite store so a slider drag becomes a single
18
+ * undo entry rather than one per tick.
19
+ *
20
+ * Usage:
21
+ * const gestureHandlers = useCropGestureHandlers();
22
+ * <div role="presentation" { ...gestureHandlers }>
23
+ * <RangeControl ... />
24
+ * </div>
25
+ *
26
+ * @param options Optional behavior flags.
27
+ */
6
28
  function useCropGestureHandlers(options = {}) {
7
- const { commitOnKeyUp = true } = options;
8
- const { beginGesture, endGesture } = useMediaEditor();
9
- const keyboardTimerRef = useRef(void 0);
10
- const clearKeyboardTimer = useCallback(() => {
11
- clearTimeout(keyboardTimerRef.current);
12
- }, []);
13
- const scheduleKeyboardEnd = useCallback(() => {
14
- clearKeyboardTimer();
15
- keyboardTimerRef.current = setTimeout(() => {
16
- endGesture();
17
- }, KEYBOARD_GESTURE_IDLE_MS);
18
- }, [clearKeyboardTimer, endGesture]);
19
- useEffect(() => clearKeyboardTimer, [clearKeyboardTimer]);
20
- const handlePointerDownCapture = useCallback(() => {
21
- clearKeyboardTimer();
22
- beginGesture();
23
- }, [beginGesture, clearKeyboardTimer]);
24
- const handlePointerEnd = useCallback(() => {
25
- clearKeyboardTimer();
26
- endGesture();
27
- }, [clearKeyboardTimer, endGesture]);
28
- const handleKeyDownCapture = useCallback(() => {
29
- beginGesture();
30
- if (!commitOnKeyUp) {
31
- scheduleKeyboardEnd();
32
- }
33
- }, [beginGesture, commitOnKeyUp, scheduleKeyboardEnd]);
34
- const handleKeyUp = useCallback(() => {
35
- if (commitOnKeyUp) {
36
- endGesture();
37
- return;
38
- }
39
- scheduleKeyboardEnd();
40
- }, [commitOnKeyUp, endGesture, scheduleKeyboardEnd]);
41
- return {
42
- [CROP_CONTROL_ATTR]: true,
43
- onPointerDownCapture: handlePointerDownCapture,
44
- onPointerUp: handlePointerEnd,
45
- onPointerCancel: handlePointerEnd,
46
- onKeyDownCapture: handleKeyDownCapture,
47
- onKeyUp: handleKeyUp
48
- };
29
+ const { commitOnKeyUp = true } = options;
30
+ const { beginGesture, endGesture } = useMediaEditor();
31
+ const keyboardTimerRef = useRef(void 0);
32
+ const clearKeyboardTimer = useCallback(() => {
33
+ clearTimeout(keyboardTimerRef.current);
34
+ }, []);
35
+ const scheduleKeyboardEnd = useCallback(() => {
36
+ clearKeyboardTimer();
37
+ keyboardTimerRef.current = setTimeout(() => {
38
+ endGesture();
39
+ }, KEYBOARD_GESTURE_IDLE_MS);
40
+ }, [clearKeyboardTimer, endGesture]);
41
+ useEffect(() => clearKeyboardTimer, [clearKeyboardTimer]);
42
+ const handlePointerDownCapture = useCallback(() => {
43
+ clearKeyboardTimer();
44
+ beginGesture();
45
+ }, [beginGesture, clearKeyboardTimer]);
46
+ const handlePointerEnd = useCallback(() => {
47
+ clearKeyboardTimer();
48
+ endGesture();
49
+ }, [clearKeyboardTimer, endGesture]);
50
+ const handleKeyDownCapture = useCallback(() => {
51
+ beginGesture();
52
+ if (!commitOnKeyUp) scheduleKeyboardEnd();
53
+ }, [
54
+ beginGesture,
55
+ commitOnKeyUp,
56
+ scheduleKeyboardEnd
57
+ ]);
58
+ const handleKeyUp = useCallback(() => {
59
+ if (commitOnKeyUp) {
60
+ endGesture();
61
+ return;
62
+ }
63
+ scheduleKeyboardEnd();
64
+ }, [
65
+ commitOnKeyUp,
66
+ endGesture,
67
+ scheduleKeyboardEnd
68
+ ]);
69
+ return {
70
+ [CROP_CONTROL_ATTR]: true,
71
+ onPointerDownCapture: handlePointerDownCapture,
72
+ onPointerUp: handlePointerEnd,
73
+ onPointerCancel: handlePointerEnd,
74
+ onKeyDownCapture: handleKeyDownCapture,
75
+ onKeyUp: handleKeyUp
76
+ };
49
77
  }
50
- export {
51
- CROP_CONTROL_ATTR,
52
- useCropGestureHandlers
53
- };
54
- //# sourceMappingURL=use-crop-gesture-handlers.mjs.map
78
+ export { CROP_CONTROL_ATTR, useCropGestureHandlers };
79
+
80
+ //# sourceMappingURL=use-crop-gesture-handlers.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/hooks/use-crop-gesture-handlers.ts"],
4
- "sourcesContent": ["import { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useMediaEditor } from '../state';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\n/** Idle window used to group repeated keyboard input into one gesture. */\nconst KEYBOARD_GESTURE_IDLE_MS = 300;\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up closes the gesture so each\n\t * discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry across\n\t * the whole gesture.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Event handler props to spread onto a wrapper element around a crop\n * control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires gesture\n * boundaries on the composite store so a slider drag becomes a single\n * undo entry rather than one per tick.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { beginGesture, endGesture } = useMediaEditor();\n\tconst keyboardTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst clearKeyboardTimer = useCallback( () => {\n\t\tclearTimeout( keyboardTimerRef.current );\n\t}, [] );\n\n\tconst scheduleKeyboardEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tkeyboardTimerRef.current = setTimeout( () => {\n\t\t\tendGesture();\n\t\t}, KEYBOARD_GESTURE_IDLE_MS );\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tuseEffect( () => clearKeyboardTimer, [ clearKeyboardTimer ] );\n\n\tconst handlePointerDownCapture = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tbeginGesture();\n\t}, [ beginGesture, clearKeyboardTimer ] );\n\n\tconst handlePointerEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tendGesture();\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tconst handleKeyDownCapture = useCallback( () => {\n\t\tbeginGesture();\n\t\tif ( ! commitOnKeyUp ) {\n\t\t\tscheduleKeyboardEnd();\n\t\t}\n\t}, [ beginGesture, commitOnKeyUp, scheduleKeyboardEnd ] );\n\n\tconst handleKeyUp = useCallback( () => {\n\t\tif ( commitOnKeyUp ) {\n\t\t\tendGesture();\n\t\t\treturn;\n\t\t}\n\t\tscheduleKeyboardEnd();\n\t}, [ commitOnKeyUp, endGesture, scheduleKeyboardEnd ] );\n\n\treturn {\n\t\t[ CROP_CONTROL_ATTR ]: true,\n\t\tonPointerDownCapture: handlePointerDownCapture,\n\t\tonPointerUp: handlePointerEnd,\n\t\tonPointerCancel: handlePointerEnd,\n\t\tonKeyDownCapture: handleKeyDownCapture,\n\t\tonKeyUp: handleKeyUp,\n\t};\n}\n"],
5
- "mappings": ";AAAA,SAAS,aAAa,WAAW,cAAc;AAC/C,SAAS,sBAAsB;AAQxB,IAAM,oBAAoB;AAGjC,IAAM,2BAA2B;AA4B1B,SAAS,uBACf,UAAyC,CAAC,GACzC;AACD,QAAM,EAAE,gBAAgB,KAAK,IAAI;AACjC,QAAM,EAAE,cAAc,WAAW,IAAI,eAAe;AACpD,QAAM,mBAAmB,OAEtB,MAAU;AAEb,QAAM,qBAAqB,YAAa,MAAM;AAC7C,iBAAc,iBAAiB,OAAQ;AAAA,EACxC,GAAG,CAAC,CAAE;AAEN,QAAM,sBAAsB,YAAa,MAAM;AAC9C,uBAAmB;AACnB,qBAAiB,UAAU,WAAY,MAAM;AAC5C,iBAAW;AAAA,IACZ,GAAG,wBAAyB;AAAA,EAC7B,GAAG,CAAE,oBAAoB,UAAW,CAAE;AAEtC,YAAW,MAAM,oBAAoB,CAAE,kBAAmB,CAAE;AAE5D,QAAM,2BAA2B,YAAa,MAAM;AACnD,uBAAmB;AACnB,iBAAa;AAAA,EACd,GAAG,CAAE,cAAc,kBAAmB,CAAE;AAExC,QAAM,mBAAmB,YAAa,MAAM;AAC3C,uBAAmB;AACnB,eAAW;AAAA,EACZ,GAAG,CAAE,oBAAoB,UAAW,CAAE;AAEtC,QAAM,uBAAuB,YAAa,MAAM;AAC/C,iBAAa;AACb,QAAK,CAAE,eAAgB;AACtB,0BAAoB;AAAA,IACrB;AAAA,EACD,GAAG,CAAE,cAAc,eAAe,mBAAoB,CAAE;AAExD,QAAM,cAAc,YAAa,MAAM;AACtC,QAAK,eAAgB;AACpB,iBAAW;AACX;AAAA,IACD;AACA,wBAAoB;AAAA,EACrB,GAAG,CAAE,eAAe,YAAY,mBAAoB,CAAE;AAEtD,SAAO;AAAA,IACN,CAAE,iBAAkB,GAAG;AAAA,IACvB,sBAAsB;AAAA,IACtB,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,kBAAkB;AAAA,IAClB,SAAS;AAAA,EACV;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-crop-gesture-handlers.mjs","names":[],"sources":["../../src/hooks/use-crop-gesture-handlers.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useMediaEditor } from '../state';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\n/** Idle window used to group repeated keyboard input into one gesture. */\nconst KEYBOARD_GESTURE_IDLE_MS = 300;\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up closes the gesture so each\n\t * discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry across\n\t * the whole gesture.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Event handler props to spread onto a wrapper element around a crop\n * control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires gesture\n * boundaries on the composite store so a slider drag becomes a single\n * undo entry rather than one per tick.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { beginGesture, endGesture } = useMediaEditor();\n\tconst keyboardTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst clearKeyboardTimer = useCallback( () => {\n\t\tclearTimeout( keyboardTimerRef.current );\n\t}, [] );\n\n\tconst scheduleKeyboardEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tkeyboardTimerRef.current = setTimeout( () => {\n\t\t\tendGesture();\n\t\t}, KEYBOARD_GESTURE_IDLE_MS );\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tuseEffect( () => clearKeyboardTimer, [ clearKeyboardTimer ] );\n\n\tconst handlePointerDownCapture = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tbeginGesture();\n\t}, [ beginGesture, clearKeyboardTimer ] );\n\n\tconst handlePointerEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tendGesture();\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tconst handleKeyDownCapture = useCallback( () => {\n\t\tbeginGesture();\n\t\tif ( ! commitOnKeyUp ) {\n\t\t\tscheduleKeyboardEnd();\n\t\t}\n\t}, [ beginGesture, commitOnKeyUp, scheduleKeyboardEnd ] );\n\n\tconst handleKeyUp = useCallback( () => {\n\t\tif ( commitOnKeyUp ) {\n\t\t\tendGesture();\n\t\t\treturn;\n\t\t}\n\t\tscheduleKeyboardEnd();\n\t}, [ commitOnKeyUp, endGesture, scheduleKeyboardEnd ] );\n\n\treturn {\n\t\t[ CROP_CONTROL_ATTR ]: true,\n\t\tonPointerDownCapture: handlePointerDownCapture,\n\t\tonPointerUp: handlePointerEnd,\n\t\tonPointerCancel: handlePointerEnd,\n\t\tonKeyDownCapture: handleKeyDownCapture,\n\t\tonKeyUp: handleKeyUp,\n\t};\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,oBAAoB;;AAGjC,MAAM,2BAA2B;;;;;;;;;;;;;;;;AA4BjC,SAAgB,uBACf,UAAyC,CAAC,GACzC;CACD,MAAM,EAAE,gBAAgB,SAAS;CACjC,MAAM,EAAE,cAAc,eAAe,eAAe;CACpD,MAAM,mBAAmB,OAEtB,KAAA,CAAU;CAEb,MAAM,qBAAqB,kBAAmB;EAC7C,aAAc,iBAAiB,OAAQ;CACxC,GAAG,CAAC,CAAE;CAEN,MAAM,sBAAsB,kBAAmB;EAC9C,mBAAmB;EACnB,iBAAiB,UAAU,iBAAkB;GAC5C,WAAW;EACZ,GAAG,wBAAyB;CAC7B,GAAG,CAAE,oBAAoB,UAAW,CAAE;CAEtC,gBAAiB,oBAAoB,CAAE,kBAAmB,CAAE;CAE5D,MAAM,2BAA2B,kBAAmB;EACnD,mBAAmB;EACnB,aAAa;CACd,GAAG,CAAE,cAAc,kBAAmB,CAAE;CAExC,MAAM,mBAAmB,kBAAmB;EAC3C,mBAAmB;EACnB,WAAW;CACZ,GAAG,CAAE,oBAAoB,UAAW,CAAE;CAEtC,MAAM,uBAAuB,kBAAmB;EAC/C,aAAa;EACb,IAAK,CAAE,eACN,oBAAoB;CAEtB,GAAG;EAAE;EAAc;EAAe;CAAoB,CAAE;CAExD,MAAM,cAAc,kBAAmB;EACtC,IAAK,eAAgB;GACpB,WAAW;GACX;EACD;EACA,oBAAoB;CACrB,GAAG;EAAE;EAAe;EAAY;CAAoB,CAAE;CAEtD,OAAO;GACJ,oBAAqB;EACvB,sBAAsB;EACtB,aAAa;EACb,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;CACV;AACD"}