@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131032.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 (217) hide show
  1. package/build/components/media-editor/index.cjs +560 -0
  2. package/build/components/media-editor/index.cjs.map +7 -0
  3. package/build/components/media-editor-canvas/index.cjs +14 -2
  4. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  5. package/build/components/media-editor-crop-panel/index.cjs +34 -27
  6. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  7. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
  8. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
  9. package/build/components/media-editor-modal/index.cjs +42 -430
  10. package/build/components/media-editor-modal/index.cjs.map +3 -3
  11. package/build/components/media-editor-toolbar/index.cjs +143 -75
  12. package/build/components/media-editor-toolbar/index.cjs.map +3 -3
  13. package/build/components/media-form/index.cjs +3 -0
  14. package/build/components/media-form/index.cjs.map +2 -2
  15. package/build/components/rotation-ruler/index.cjs +197 -0
  16. package/build/components/rotation-ruler/index.cjs.map +7 -0
  17. package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
  18. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
  19. package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
  20. package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
  21. package/build/image-editor/core/constants.cjs +9 -0
  22. package/build/image-editor/core/constants.cjs.map +2 -2
  23. package/build/image-editor/core/containment.cjs +7 -13
  24. package/build/image-editor/core/containment.cjs.map +2 -2
  25. package/build/image-editor/core/interaction-controller.cjs +43 -7
  26. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  27. package/build/image-editor/core/state.cjs +5 -1
  28. package/build/image-editor/core/state.cjs.map +2 -2
  29. package/build/image-editor/core/transform-style.cjs.map +1 -1
  30. package/build/image-editor/core/types.cjs.map +1 -1
  31. package/build/image-editor/core/viewport-state.cjs +50 -0
  32. package/build/image-editor/core/viewport-state.cjs.map +7 -0
  33. package/build/image-editor/react/components/cropper.cjs +192 -72
  34. package/build/image-editor/react/components/cropper.cjs.map +3 -3
  35. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
  36. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  37. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
  38. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  39. package/build/image-editor/react/components/viewport-provider.cjs +51 -0
  40. package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
  41. package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
  42. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  43. package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
  44. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
  45. package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
  46. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  47. package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
  48. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
  49. package/build/image-editor/react/visually-hidden-style.cjs +41 -0
  50. package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
  51. package/build/private-apis.cjs +2 -0
  52. package/build/private-apis.cjs.map +2 -2
  53. package/build-module/components/media-editor/index.mjs +545 -0
  54. package/build-module/components/media-editor/index.mjs.map +7 -0
  55. package/build-module/components/media-editor-canvas/index.mjs +14 -2
  56. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  57. package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
  58. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  59. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
  60. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
  61. package/build-module/components/media-editor-modal/index.mjs +46 -455
  62. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  63. package/build-module/components/media-editor-toolbar/index.mjs +137 -77
  64. package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
  65. package/build-module/components/media-form/index.mjs +3 -0
  66. package/build-module/components/media-form/index.mjs.map +2 -2
  67. package/build-module/components/rotation-ruler/index.mjs +166 -0
  68. package/build-module/components/rotation-ruler/index.mjs.map +7 -0
  69. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
  70. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
  71. package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
  72. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
  73. package/build-module/image-editor/core/constants.mjs +6 -0
  74. package/build-module/image-editor/core/constants.mjs.map +2 -2
  75. package/build-module/image-editor/core/containment.mjs +6 -12
  76. package/build-module/image-editor/core/containment.mjs.map +2 -2
  77. package/build-module/image-editor/core/interaction-controller.mjs +50 -8
  78. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  79. package/build-module/image-editor/core/state.mjs +5 -1
  80. package/build-module/image-editor/core/state.mjs.map +2 -2
  81. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  82. package/build-module/image-editor/core/viewport-state.mjs +24 -0
  83. package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
  84. package/build-module/image-editor/react/components/cropper.mjs +195 -73
  85. package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
  86. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
  87. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  88. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
  89. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  90. package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
  91. package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
  92. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
  93. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  94. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
  95. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
  96. package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
  97. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  98. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
  99. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
  100. package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
  101. package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
  102. package/build-module/private-apis.mjs +2 -0
  103. package/build-module/private-apis.mjs.map +2 -2
  104. package/build-style/style-rtl.css +254 -29
  105. package/build-style/style.css +254 -29
  106. package/build-types/components/media-editor/index.d.ts +34 -0
  107. package/build-types/components/media-editor/index.d.ts.map +1 -0
  108. package/build-types/components/media-editor-canvas/index.d.ts +10 -1
  109. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  110. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  111. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  112. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
  113. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
  114. package/build-types/components/media-editor-modal/index.d.ts +2 -2
  115. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  116. package/build-types/components/media-editor-provider/index.d.ts +1 -1
  117. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  118. package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
  119. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
  120. package/build-types/components/media-form/index.d.ts +1 -1
  121. package/build-types/components/media-form/index.d.ts.map +1 -1
  122. package/build-types/components/rotation-ruler/index.d.ts +46 -0
  123. package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
  124. package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
  125. package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
  126. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
  127. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
  128. package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
  129. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
  130. package/build-types/image-editor/core/constants.d.ts +9 -0
  131. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  132. package/build-types/image-editor/core/containment.d.ts +11 -7
  133. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  134. package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
  135. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  136. package/build-types/image-editor/core/state.d.ts.map +1 -1
  137. package/build-types/image-editor/core/transform-style.d.ts +1 -1
  138. package/build-types/image-editor/core/types.d.ts +25 -0
  139. package/build-types/image-editor/core/types.d.ts.map +1 -1
  140. package/build-types/image-editor/core/viewport-state.d.ts +7 -0
  141. package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
  142. package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
  143. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  144. package/build-types/image-editor/react/components/cropper.d.ts +2 -1
  145. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  146. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
  147. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  148. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
  149. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
  150. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
  151. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  152. package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
  153. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
  154. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  155. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
  156. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
  157. package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
  158. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  159. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
  160. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
  161. package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
  162. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
  163. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  164. package/build-types/private-apis.d.ts.map +1 -1
  165. package/build-types/store/actions.d.ts +3 -3
  166. package/build-types/store/actions.d.ts.map +1 -1
  167. package/package.json +16 -15
  168. package/src/components/media-editor/index.tsx +709 -0
  169. package/src/components/media-editor/style.scss +89 -0
  170. package/src/components/media-editor-canvas/index.tsx +24 -0
  171. package/src/components/media-editor-crop-panel/index.tsx +39 -27
  172. package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
  173. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
  174. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
  175. package/src/components/media-editor-modal/index.tsx +49 -589
  176. package/src/components/media-editor-modal/style.scss +13 -112
  177. package/src/components/media-editor-toolbar/index.tsx +122 -63
  178. package/src/components/media-editor-toolbar/style.scss +39 -11
  179. package/src/components/media-form/index.tsx +5 -0
  180. package/src/components/rotation-ruler/README.md +37 -0
  181. package/src/components/rotation-ruler/index.tsx +266 -0
  182. package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
  183. package/src/components/rotation-ruler/style.scss +147 -0
  184. package/src/components/rotation-ruler/test/index.tsx +109 -0
  185. package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
  186. package/src/hooks/use-crop-gesture-handlers.ts +54 -0
  187. package/src/image-editor/core/constants.ts +12 -0
  188. package/src/image-editor/core/containment.ts +16 -28
  189. package/src/image-editor/core/interaction-controller.ts +66 -10
  190. package/src/image-editor/core/state.ts +15 -8
  191. package/src/image-editor/core/test/camera.ts +15 -26
  192. package/src/image-editor/core/test/interaction-controller.ts +158 -7
  193. package/src/image-editor/core/test/state.ts +21 -1
  194. package/src/image-editor/core/transform-style.ts +1 -1
  195. package/src/image-editor/core/types.ts +16 -0
  196. package/src/image-editor/core/viewport-state.ts +33 -0
  197. package/src/image-editor/docs/architecture.md +1 -1
  198. package/src/image-editor/docs/recipes.md +2 -2
  199. package/src/image-editor/react/components/cropper.scss +28 -0
  200. package/src/image-editor/react/components/cropper.tsx +268 -72
  201. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
  202. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
  203. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
  204. package/src/image-editor/react/components/test/cropper.tsx +294 -5
  205. package/src/image-editor/react/components/viewport-provider.tsx +39 -0
  206. package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
  207. package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
  208. package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
  209. package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
  210. package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
  211. package/src/image-editor/react/hooks/use-interaction.ts +36 -6
  212. package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
  213. package/src/image-editor/react/visually-hidden-style.ts +15 -0
  214. package/src/private-apis.ts +2 -0
  215. package/src/style.scss +3 -0
  216. package/tsconfig.json +1 -0
  217. package/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // packages/media-editor/src/components/media-editor-toolbar/index.tsx
@@ -26,27 +36,54 @@ module.exports = __toCommonJS(media_editor_toolbar_exports);
26
36
  var import_components = require("@wordpress/components");
27
37
  var import_ui = require("@wordpress/ui");
28
38
  var import_i18n = require("@wordpress/i18n");
39
+ var import_keycodes = require("@wordpress/keycodes");
29
40
  var import_icons = require("@wordpress/icons");
30
41
  var import_image_editor = require("../../image-editor/index.cjs");
42
+ var import_use_crop_gesture_handlers = require("../../hooks/use-crop-gesture-handlers.cjs");
31
43
  var import_constants = require("../../image-editor/core/constants.cjs");
44
+ var import_rotation_ruler = __toESM(require("../rotation-ruler/index.cjs"));
32
45
  var import_jsx_runtime = require("react/jsx-runtime");
33
46
  function MediaEditorToolbar({
34
47
  onReset,
35
- onPlacementControlInteraction
48
+ onPlacementControlInteraction,
49
+ isUndoRedoDisabled = false
36
50
  }) {
37
- const { state, setRotation, setFlip, snapRotate90, reset, isDirty } = (0, import_image_editor.useCropper)();
51
+ const {
52
+ state,
53
+ setRotation,
54
+ setFlip,
55
+ snapRotate90,
56
+ reset,
57
+ isDirty,
58
+ hasUndo,
59
+ hasRedo,
60
+ undo: undoCrop,
61
+ redo: redoCrop
62
+ } = (0, import_image_editor.useCropper)();
63
+ const rotationGestureHandlers = (0, import_use_crop_gesture_handlers.useCropGestureHandlers)({
64
+ commitOnKeyUp: false
65
+ });
38
66
  const handleReset = () => {
39
67
  reset();
40
68
  onReset?.();
41
69
  };
70
+ const handleUndo = () => {
71
+ if (isUndoRedoDisabled) {
72
+ return;
73
+ }
74
+ undoCrop();
75
+ };
76
+ const handleRedo = () => {
77
+ if (isUndoRedoDisabled) {
78
+ return;
79
+ }
80
+ redoCrop();
81
+ };
42
82
  const baseAngle = Math.round(state.rotation / 90) * 90;
43
83
  const singleFlip = state.flip.horizontal !== state.flip.vertical;
44
84
  const visualDir = singleFlip ? -1 : 1;
45
85
  const fineOffset = (state.rotation - baseAngle) * visualDir;
46
86
  const handleRotationSlider = (value) => {
47
- if (value === void 0) {
48
- return;
49
- }
50
87
  const EPS = 0.01;
51
88
  const clamped = Math.max(
52
89
  -import_constants.MAX_ROTATION_OFFSET + EPS,
@@ -66,79 +103,110 @@ function MediaEditorToolbar({
66
103
  wrap: "wrap",
67
104
  children: [
68
105
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
69
- import_components.Button,
70
- {
71
- size: "compact",
72
- icon: import_icons.rotateLeft,
73
- label: (0, import_i18n.__)("Rotate 90\xB0 counter-clockwise"),
74
- showTooltip: true,
75
- onClick: () => snapRotate90(-1)
76
- }
77
- ),
78
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
- import_components.Button,
106
+ "div",
80
107
  {
81
- size: "compact",
82
- icon: import_icons.rotateRight,
83
- label: (0, import_i18n.__)("Rotate 90\xB0 clockwise"),
84
- showTooltip: true,
85
- onClick: () => snapRotate90(1)
108
+ role: "presentation",
109
+ className: "media-editor-toolbar__rotation-slider",
110
+ ...rotationGestureHandlers,
111
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
+ import_rotation_ruler.default,
113
+ {
114
+ label: (0, import_i18n.__)("Fine rotation"),
115
+ min: -import_constants.MAX_ROTATION_OFFSET,
116
+ max: import_constants.MAX_ROTATION_OFFSET,
117
+ value: fineOffset,
118
+ onChange: handleRotationSlider
119
+ }
120
+ )
86
121
  }
87
122
  ),
88
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
- import_components.Button,
90
- {
91
- size: "compact",
92
- icon: import_icons.flipHorizontal,
93
- label: (0, import_i18n.__)("Flip horizontal"),
94
- showTooltip: true,
95
- isPressed: state.flip.horizontal,
96
- onClick: () => setFlip({
97
- horizontal: !state.flip.horizontal,
98
- vertical: state.flip.vertical
99
- })
100
- }
101
- ),
102
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
103
- import_components.Button,
104
- {
105
- size: "compact",
106
- icon: import_icons.flipVertical,
107
- label: (0, import_i18n.__)("Flip vertical"),
108
- showTooltip: true,
109
- isPressed: state.flip.vertical,
110
- onClick: () => setFlip({
111
- horizontal: state.flip.horizontal,
112
- vertical: !state.flip.vertical
113
- })
114
- }
115
- ),
116
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-toolbar__rotation-slider", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
- import_components.RangeControl,
118
- {
119
- __next40pxDefaultSize: true,
120
- __nextHasNoMarginBottom: true,
121
- label: (0, import_i18n.__)("Fine rotation"),
122
- hideLabelFromVision: true,
123
- min: -import_constants.MAX_ROTATION_OFFSET,
124
- max: import_constants.MAX_ROTATION_OFFSET,
125
- step: 0.5,
126
- value: fineOffset,
127
- onChange: handleRotationSlider,
128
- showTooltip: false
129
- }
130
- ) }),
131
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
132
- import_components.Button,
133
- {
134
- size: "compact",
135
- variant: "tertiary",
136
- disabled: !isDirty,
137
- accessibleWhenDisabled: true,
138
- onClick: handleReset,
139
- children: (0, import_i18n.__)("Reset")
140
- }
141
- )
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-toolbar__action-cluster", children: [
124
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ import_components.Button,
126
+ {
127
+ size: "compact",
128
+ icon: import_icons.rotateLeft,
129
+ label: (0, import_i18n.__)("Rotate 90\xB0 counter-clockwise"),
130
+ showTooltip: true,
131
+ onClick: () => snapRotate90(-1)
132
+ }
133
+ ),
134
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
135
+ import_components.Button,
136
+ {
137
+ size: "compact",
138
+ icon: import_icons.rotateRight,
139
+ label: (0, import_i18n.__)("Rotate 90\xB0 clockwise"),
140
+ showTooltip: true,
141
+ onClick: () => snapRotate90(1)
142
+ }
143
+ ),
144
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
145
+ import_components.Button,
146
+ {
147
+ size: "compact",
148
+ icon: import_icons.flipHorizontal,
149
+ label: (0, import_i18n.__)("Flip horizontal"),
150
+ showTooltip: true,
151
+ isPressed: state.flip.horizontal,
152
+ onClick: () => setFlip({
153
+ horizontal: !state.flip.horizontal,
154
+ vertical: state.flip.vertical
155
+ })
156
+ }
157
+ ),
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
+ import_components.Button,
160
+ {
161
+ size: "compact",
162
+ icon: import_icons.flipVertical,
163
+ label: (0, import_i18n.__)("Flip vertical"),
164
+ showTooltip: true,
165
+ isPressed: state.flip.vertical,
166
+ onClick: () => setFlip({
167
+ horizontal: state.flip.horizontal,
168
+ vertical: !state.flip.vertical
169
+ })
170
+ }
171
+ ),
172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
+ import_components.Button,
174
+ {
175
+ size: "compact",
176
+ icon: import_icons.undo,
177
+ label: (0, import_i18n.__)("Undo"),
178
+ showTooltip: true,
179
+ shortcut: import_keycodes.displayShortcut.primary("z"),
180
+ disabled: isUndoRedoDisabled || !hasUndo,
181
+ accessibleWhenDisabled: true,
182
+ onClick: handleUndo
183
+ }
184
+ ),
185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ import_components.Button,
187
+ {
188
+ size: "compact",
189
+ icon: import_icons.redo,
190
+ label: (0, import_i18n.__)("Redo"),
191
+ showTooltip: true,
192
+ shortcut: (0, import_keycodes.isAppleOS)() ? import_keycodes.displayShortcut.primaryShift("z") : import_keycodes.displayShortcut.primary("y"),
193
+ disabled: isUndoRedoDisabled || !hasRedo,
194
+ accessibleWhenDisabled: true,
195
+ onClick: handleRedo
196
+ }
197
+ ),
198
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
+ import_components.Button,
200
+ {
201
+ size: "compact",
202
+ variant: "tertiary",
203
+ disabled: !isDirty,
204
+ accessibleWhenDisabled: true,
205
+ onClick: handleReset,
206
+ children: (0, import_i18n.__)("Reset")
207
+ }
208
+ )
209
+ ] })
142
210
  ]
143
211
  }
144
212
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor-toolbar/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button, RangeControl } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useCropper } from '../../image-editor';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\n\nexport interface MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n}: MediaEditorToolbarProps ) {\n\tconst { state, setRotation, setFlip, snapRotate90, reset, isDirty } =\n\t\tuseCropper();\n\n\tconst handleReset = () => {\n\t\treset();\n\t\tonReset?.();\n\t};\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number | undefined ) => {\n\t\tif ( value === undefined ) {\n\t\t\treturn;\n\t\t}\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly \u00B1MAX lands state on a\n\t\t// 90\u00B0 midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className=\"media-editor-toolbar__rotation-slider\">\n\t\t\t\t<RangeControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tstep={ 0.5 }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<Button\n\t\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AA,EACD;AAEF;",
6
- "names": []
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { displayShortcut, isAppleOS } from '@wordpress/keycodes';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tundo,\n\tredo,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useCropper } from '../../image-editor';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/** Whether undo/redo should be unavailable during an active gesture. */\n\tisUndoRedoDisabled?: boolean;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n * @param props.isUndoRedoDisabled\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n\tisUndoRedoDisabled = false,\n}: MediaEditorToolbarProps ) {\n\tconst {\n\t\tstate,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t} = useCropper();\n\t// `commitOnKeyUp: false` keeps rapid arrow-key adjustments coalesced\n\t// into a single undo entry by the state-change debounce. Pointer-up\n\t// still commits immediately so each drag is its own undo step.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\tconst handleReset = () => {\n\t\treset();\n\t\tonReset?.();\n\t};\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly \u00B1MAX lands state on a\n\t\t// 90\u00B0 midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<div\n\t\t\t\trole=\"presentation\"\n\t\t\t\tclassName=\"media-editor-toolbar__rotation-slider\"\n\t\t\t\t{ ...rotationGestureHandlers }\n\t\t\t>\n\t\t\t\t<RotationRuler\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"media-editor-toolbar__action-cluster\">\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateLeft }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipHorizontal }\n\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipVertical }\n\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ undo }\n\t\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleUndo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ redo }\n\t\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={\n\t\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t\t}\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleRedo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleReset }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t</Stack>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,gBAAsB;AACtB,kBAAmB;AACnB,sBAA2C;AAC3C,mBAOO;AAKP,0BAA2B;AAC3B,uCAAuC;AACvC,uBAAoC;AACpC,4BAA0B;AAqGtB;AA5EW,SAAR,mBAAqC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,qBAAqB;AACtB,GAA6B;A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O;AAAA,cACP,WAAQ,gBAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,cACC,2BAAU,IACP,gCAAgB,aAAc,GAAI,IAClC,gCAAgB,QAAS,GAAI;AAAA,cAEjC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,SAAQ;AAAA,cACR,UAAW,CAAE;AAAA,cACb,wBAAsB;AAAA,cACtB,SAAU;AAAA,cAER,8BAAI,OAAQ;AAAA;AAAA,UACf;AAAA,WACD;AAAA;AAAA;AAAA,EACD;AAEF;",
6
+ "names": ["RotationRuler"]
7
7
  }
@@ -25,6 +25,8 @@ __export(media_form_exports, {
25
25
  module.exports = __toCommonJS(media_form_exports);
26
26
  var import_dataviews = require("@wordpress/dataviews");
27
27
  var import_components = require("@wordpress/components");
28
+ var import_ui = require("@wordpress/ui");
29
+ var import_i18n = require("@wordpress/i18n");
28
30
  var import_media_editor_provider = require("../media-editor-provider/index.cjs");
29
31
  var import_jsx_runtime = require("react/jsx-runtime");
30
32
  function MediaForm({
@@ -56,6 +58,7 @@ function MediaForm({
56
58
  };
57
59
  const form = formOverrides || defaultForm;
58
60
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-form", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
61
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {}), children: (0, import_i18n.__)("Media details") }),
59
62
  header,
60
63
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
61
64
  import_dataviews.DataForm,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-form/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: fields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif (\n\t\t\t\t[ 'title', 'alt_text', 'caption', 'description' ].includes(\n\t\t\t\t\tfield.id\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAyB;AAEzB,wBAAwD;AAMxD,mCAAsC;AA+BlC;AATW,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM,EAAE,OAAO,QAAQ,SAAS,QAAI,oDAAsB;AAE1D,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,4CAAC,SAAI,WAAU,gDACd,sDAAC,6BAAQ,GACV;AAAA,EAEF;AAGA,QAAM,cAAoB;AAAA,IACzB,QAAQ;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,QAAQ,OAAO,IAAK,CAAE,UAA2B;AAEhD,UACC,CAAE,SAAS,YAAY,WAAW,aAAc,EAAE;AAAA,QACjD,MAAM;AAAA,MACP,GACC;AACD,eAAO;AAAA,UACN,IAAI,MAAM;AAAA,UACV,QAAQ;AAAA,YACP,MAAM;AAAA,YACN,eAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AACA,aAAO,MAAM;AAAA,IACd,CAAE;AAAA,EACH;AAEA,QAAM,OAAO,iBAAiB;AAE9B,SACC,4CAAC,SAAI,WAAU,qBACd,uDAAC,kBAAAA,sBAAA,EAAO,SAAU,GACf;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: fields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif (\n\t\t\t\t[ 'title', 'alt_text', 'caption', 'description' ].includes(\n\t\t\t\t\tfield.id\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAyB;AAEzB,wBAAwD;AACxD,gBAA+B;AAC/B,kBAAmB;AAMnB,mCAAsC;AA+BlC;AATW,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM,EAAE,OAAO,QAAQ,SAAS,QAAI,oDAAsB;AAE1D,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,4CAAC,SAAI,WAAU,gDACd,sDAAC,6BAAQ,GACV;AAAA,EAEF;AAGA,QAAM,cAAoB;AAAA,IACzB,QAAQ;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,QAAQ,OAAO,IAAK,CAAE,UAA2B;AAEhD,UACC,CAAE,SAAS,YAAY,WAAW,aAAc,EAAE;AAAA,QACjD,MAAM;AAAA,MACP,GACC;AACD,eAAO;AAAA,UACN,IAAI,MAAM;AAAA,UACV,QAAQ;AAAA,YACP,MAAM;AAAA,YACN,eAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AACA,aAAO,MAAM;AAAA,IACd,CAAE;AAAA,EACH;AAEA,QAAM,OAAO,iBAAiB;AAE9B,SACC,4CAAC,SAAI,WAAU,qBACd,uDAAC,kBAAAA,sBAAA,EAAO,SAAU,GACjB;AAAA,gDAAC,4BAAe,QAAS,4CAAC,QAAG,GAC1B,8BAAI,eAAgB,GACvB;AAAA,IACE;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
6
  "names": ["VStack"]
7
7
  }
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/media-editor/src/components/rotation-ruler/index.tsx
31
+ var rotation_ruler_exports = {};
32
+ __export(rotation_ruler_exports, {
33
+ default: () => RotationRuler
34
+ });
35
+ module.exports = __toCommonJS(rotation_ruler_exports);
36
+ var import_clsx = __toESM(require("clsx"));
37
+ var import_element = require("@wordpress/element");
38
+ var import_use_ruler_drag = require("./use-ruler-drag.cjs");
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var STRIP_HEIGHT = 32;
41
+ var LABEL_BASELINE_Y = 11;
42
+ var MAJOR_INTERVAL = 15;
43
+ var TICK_HEIGHT_MINOR = 4;
44
+ var TICK_HEIGHT_MID = 8;
45
+ var TICK_HEIGHT_MAJOR = 14;
46
+ function useTicks(min, max) {
47
+ return (0, import_element.useMemo)(() => {
48
+ const out = [];
49
+ for (let v = Math.ceil(min); v <= Math.floor(max); v += 1) {
50
+ let kind = "minor";
51
+ let height = TICK_HEIGHT_MINOR;
52
+ if (v % 15 === 0) {
53
+ kind = "major";
54
+ height = TICK_HEIGHT_MAJOR;
55
+ } else if (v % 5 === 0) {
56
+ kind = "mid";
57
+ height = TICK_HEIGHT_MID;
58
+ }
59
+ out.push({ value: v, kind, height });
60
+ }
61
+ return out;
62
+ }, [min, max]);
63
+ }
64
+ function formatValue(value) {
65
+ const rounded = Math.round(value * 10) / 10;
66
+ return Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1);
67
+ }
68
+ function RotationRuler(props) {
69
+ const {
70
+ value,
71
+ onChange,
72
+ min = -45,
73
+ max = 45,
74
+ step = 1,
75
+ label,
76
+ unit = "\xB0",
77
+ pixelsPerStep = 6,
78
+ className,
79
+ id,
80
+ disabled = false
81
+ } = props;
82
+ const inputRef = (0, import_element.useRef)(null);
83
+ const generatedId = (0, import_element.useId)();
84
+ const inputId = id ?? generatedId;
85
+ const dragHandlers = (0, import_use_ruler_drag.useRulerDrag)({
86
+ value,
87
+ onChange,
88
+ min,
89
+ max,
90
+ step,
91
+ pixelsPerStep,
92
+ disabled,
93
+ onPointerDownStart: () => inputRef.current?.focus()
94
+ });
95
+ const handleKeyDown = (event) => {
96
+ const isIncrement = event.key === "ArrowRight" || event.key === "ArrowUp";
97
+ const isDecrement = event.key === "ArrowLeft" || event.key === "ArrowDown";
98
+ if (!isIncrement && !isDecrement) {
99
+ return;
100
+ }
101
+ event.preventDefault();
102
+ if (disabled) {
103
+ return;
104
+ }
105
+ const direction = isIncrement ? 1 : -1;
106
+ const magnitude = event.shiftKey ? step / 2 : step;
107
+ const next = (0, import_use_ruler_drag.clampValue)(value + direction * magnitude, min, max);
108
+ if (next !== value) {
109
+ onChange(next);
110
+ }
111
+ };
112
+ const display = `${formatValue(value)}${unit}`;
113
+ const ticks = useTicks(min, max);
114
+ const pxPerUnit = pixelsPerStep / step;
115
+ const stripStyle = (0, import_element.useMemo)(() => {
116
+ const offset = -value * pxPerUnit;
117
+ return {
118
+ transform: `translateX(calc(-50% + ${offset}px))`
119
+ };
120
+ }, [value, pxPerUnit]);
121
+ const closestMajor = Math.round(value / MAJOR_INTERVAL) * MAJOR_INTERVAL;
122
+ const onMajor = Math.abs(value - closestMajor) < 0.01;
123
+ const activeText = onMajor ? `${closestMajor}${unit}` : display;
124
+ const majorTicks = ticks.filter((tick) => tick.kind === "major");
125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
126
+ "div",
127
+ {
128
+ className: (0, import_clsx.default)("rotation-ruler", className),
129
+ role: "presentation",
130
+ "data-disabled": disabled || void 0,
131
+ ...dragHandlers,
132
+ children: [
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
134
+ "input",
135
+ {
136
+ ref: inputRef,
137
+ id: inputId,
138
+ type: "range",
139
+ className: "rotation-ruler__input",
140
+ min,
141
+ max,
142
+ step: "any",
143
+ value,
144
+ disabled,
145
+ "aria-label": label,
146
+ "aria-valuetext": display,
147
+ onChange: (event) => onChange(
148
+ (0, import_use_ruler_drag.clampValue)(event.target.valueAsNumber, min, max)
149
+ ),
150
+ onKeyDown: handleKeyDown
151
+ }
152
+ ),
153
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "rotation-ruler__strip", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
154
+ "svg",
155
+ {
156
+ className: "rotation-ruler__ticks",
157
+ style: stripStyle,
158
+ width: (max - min) * pxPerUnit,
159
+ height: STRIP_HEIGHT,
160
+ viewBox: `${min * pxPerUnit} 0 ${(max - min) * pxPerUnit} ${STRIP_HEIGHT}`,
161
+ preserveAspectRatio: "xMidYMid meet",
162
+ children: [
163
+ ticks.map((tick) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
164
+ "line",
165
+ {
166
+ x1: tick.value * pxPerUnit,
167
+ x2: tick.value * pxPerUnit,
168
+ y1: STRIP_HEIGHT - tick.height,
169
+ y2: STRIP_HEIGHT,
170
+ className: `rotation-ruler__tick rotation-ruler__tick--${tick.kind}`
171
+ },
172
+ tick.value
173
+ )),
174
+ majorTicks.map((tick) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
175
+ "text",
176
+ {
177
+ x: tick.value * pxPerUnit,
178
+ y: LABEL_BASELINE_Y,
179
+ textAnchor: "middle",
180
+ className: "rotation-ruler__label",
181
+ children: [
182
+ tick.value,
183
+ unit
184
+ ]
185
+ },
186
+ tick.value
187
+ ))
188
+ ]
189
+ }
190
+ ) }),
191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "rotation-ruler__active-label", "aria-hidden": "true", children: activeText }),
192
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "rotation-ruler__pointer", "aria-hidden": "true" })
193
+ ]
194
+ }
195
+ );
196
+ }
197
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/rotation-ruler/index.tsx"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useId, useMemo, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\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: `\u00B0`.\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 = '\u00B0',\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\u00B0 rotation when step is 1\u00B0). Same modifier works\n\t\t// on drag \u2014 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\u00B0) 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\u00B0\") or the major itself when on-major (e.g. \"0\u00B0\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\tconst activeText = onMajor ? `${ closestMajor }${ unit }` : display;\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-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{ activeText }\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;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,qBAAuC;AAKvC,4BAAyC;AA+LtC;AA1JH,IAAM,eAAe;AACrB,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;AACxB,IAAM,oBAAoB;AAe1B,SAAS,SAAU,KAAa,KAAsB;AACrD,aAAO,wBAAS,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,OAAO,GAAI;AACnB,eAAO;AACP,iBAAS;AAAA,MACV,WAAY,IAAI,MAAM,GAAI;AACzB,eAAO;AACP,iBAAS;AAAA,MACV;AACA,UAAI,KAAM,EAAE,OAAO,GAAG,MAAM,OAAO,CAAE;AAAA,IACtC;AACA,WAAO;AAAA,EACR,GAAG,CAAE,KAAK,GAAI,CAAE;AACjB;AAOA,SAAS,YAAa,OAAwB;AAC7C,QAAM,UAAU,KAAK,MAAO,QAAQ,EAAG,IAAI;AAC3C,SAAO,OAAO,UAAW,OAAQ,IAC9B,QAAQ,QAAS,CAAE,IACnB,QAAQ,QAAS,CAAE;AACvB;AAYe,SAAR,cAAgC,OAA4B;AAClE,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,OAAO;AAAA,IACP;AAAA,IACA,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