ropav 0.15.1 → 0.16.1

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 (115) hide show
  1. package/AGENTS.md +4 -0
  2. package/dist/components/portal-provider/portal-provider.types.d.ts +2 -2
  3. package/dist/components/slider/index.d.ts +1 -1
  4. package/dist/components/slider/slider-root.d.ts +7 -7
  5. package/dist/components/slider/slider-root.js +5 -0
  6. package/dist/components/slider/slider-track.d.ts +2 -2
  7. package/dist/components/slider/slider-track.js +9 -1
  8. package/dist/components/slider/slider.types.d.ts +25 -3
  9. package/dist/composables/focus-scope-registry.d.ts +1 -1
  10. package/dist/composables/focus-scope-registry.js +1 -1
  11. package/dist/composables/use-dismissable.d.ts +1 -1
  12. package/dist/composables/use-focus-scope.d.ts +1 -1
  13. package/dist/composables/use-input-otp.js +12 -2
  14. package/dist/composables/use-portal.d.ts +2 -2
  15. package/dist/composables/use-portal.js +2 -2
  16. package/dist/composables/use-slider-thumb.js +2 -2
  17. package/dist/composables/use-slider.d.ts +27 -4
  18. package/dist/composables/use-slider.js +52 -15
  19. package/dist/composables/use-text-field.js +9 -2
  20. package/dist/ropav.min.css +1 -1
  21. package/dist/styles/accordion.css +3 -0
  22. package/dist/styles/alert-dialog.css +4 -0
  23. package/dist/styles/alert.css +3 -0
  24. package/dist/styles/autocomplete.css +4 -0
  25. package/dist/styles/avatar-group.css +4 -0
  26. package/dist/styles/avatar.css +3 -0
  27. package/dist/styles/badge.css +3 -0
  28. package/dist/styles/breadcrumbs.css +4 -0
  29. package/dist/styles/button-group.css +4 -0
  30. package/dist/styles/button.css +3 -0
  31. package/dist/styles/calendar-year-picker.css +3 -0
  32. package/dist/styles/calendar.css +3 -0
  33. package/dist/styles/card.css +3 -0
  34. package/dist/styles/checkbox-group.css +3 -0
  35. package/dist/styles/checkbox.css +3 -0
  36. package/dist/styles/chip.css +3 -0
  37. package/dist/styles/close-button.css +3 -0
  38. package/dist/styles/color-area.css +3 -0
  39. package/dist/styles/color-field.css +3 -0
  40. package/dist/styles/color-input-group.css +3 -0
  41. package/dist/styles/color-picker.css +3 -0
  42. package/dist/styles/color-slider.css +3 -0
  43. package/dist/styles/color-swatch-picker.css +3 -0
  44. package/dist/styles/color-swatch.css +3 -0
  45. package/dist/styles/combo-box.css +3 -0
  46. package/dist/styles/components.css +3 -0
  47. package/dist/styles/core.css +2 -0
  48. package/dist/styles/date-field.css +4 -0
  49. package/dist/styles/date-picker.css +4 -0
  50. package/dist/styles/date-range-picker.css +4 -0
  51. package/dist/styles/description.css +3 -0
  52. package/dist/styles/disclosure-group.css +3 -0
  53. package/dist/styles/disclosure.css +3 -0
  54. package/dist/styles/drawer.css +4 -0
  55. package/dist/styles/drop-zone.css +3 -0
  56. package/dist/styles/dropdown.css +4 -0
  57. package/dist/styles/empty-state.css +3 -0
  58. package/dist/styles/error-message.css +3 -0
  59. package/dist/styles/field-error.css +3 -0
  60. package/dist/styles/fieldset.css +3 -0
  61. package/dist/styles/header.css +3 -0
  62. package/dist/styles/input-group.css +3 -0
  63. package/dist/styles/input-otp.css +3 -0
  64. package/dist/styles/input.css +3 -0
  65. package/dist/styles/kbd.css +3 -0
  66. package/dist/styles/label.css +3 -0
  67. package/dist/styles/link.css +3 -0
  68. package/dist/styles/list-box-item.css +3 -0
  69. package/dist/styles/list-box-section.css +3 -0
  70. package/dist/styles/list-box.css +4 -0
  71. package/dist/styles/menu-item.css +3 -0
  72. package/dist/styles/menu-section.css +3 -0
  73. package/dist/styles/menu.css +3 -0
  74. package/dist/styles/meter.css +3 -0
  75. package/dist/styles/modal.css +4 -0
  76. package/dist/styles/number-field.css +3 -0
  77. package/dist/styles/pagination.css +3 -0
  78. package/dist/styles/popover.css +3 -0
  79. package/dist/styles/progress-bar.css +3 -0
  80. package/dist/styles/progress-circle.css +3 -0
  81. package/dist/styles/radio-group.css +3 -0
  82. package/dist/styles/radio.css +3 -0
  83. package/dist/styles/range-calendar.css +3 -0
  84. package/dist/styles/scroll-shadow.css +3 -0
  85. package/dist/styles/search-field.css +4 -0
  86. package/dist/styles/segmented-control.css +3 -0
  87. package/dist/styles/select.css +3 -0
  88. package/dist/styles/separator.css +3 -0
  89. package/dist/styles/sidebar.css +8 -0
  90. package/dist/styles/skeleton.css +3 -0
  91. package/dist/styles/slider.css +3 -0
  92. package/dist/styles/spinner.css +3 -0
  93. package/dist/styles/splitter.css +3 -0
  94. package/dist/styles/surface.css +3 -0
  95. package/dist/styles/switch-group.css +3 -0
  96. package/dist/styles/switch.css +3 -0
  97. package/dist/styles/table.css +5 -0
  98. package/dist/styles/tabs.css +4 -0
  99. package/dist/styles/tag-group.css +3 -0
  100. package/dist/styles/tag.css +4 -0
  101. package/dist/styles/textarea.css +3 -0
  102. package/dist/styles/textfield.css +3 -0
  103. package/dist/styles/time-field.css +4 -0
  104. package/dist/styles/toast.css +6 -0
  105. package/dist/styles/toggle-button-group.css +3 -0
  106. package/dist/styles/toggle-button.css +3 -0
  107. package/dist/styles/toolbar.css +3 -0
  108. package/dist/styles/tooltip.css +3 -0
  109. package/dist/styles/typography.css +3 -0
  110. package/dist/styles/virtualizer.css +3 -0
  111. package/dist/utils/aria-hide-outside.js +1 -1
  112. package/dist/utils/region.d.ts +3 -3
  113. package/dist/utils/region.js +3 -3
  114. package/dist/version.js +1 -1
  115. package/package.json +362 -2
package/AGENTS.md CHANGED
@@ -18,6 +18,10 @@ so a bundler drops what is never imported. The stylesheet is a separate import:
18
18
  import "ropav/styles/bundled.css";
19
19
  ```
20
20
 
21
+ Through a bundler, it also comes in parts: `ropav/styles/core` once, then `ropav/styles/<name>` for
22
+ each component used (`ropav/styles/modal`), or `ropav/styles/components` for all of them. The
23
+ core holds the theme, so it is never the part loaded late.
24
+
21
25
  Every component takes `class`, `aria-label`, `aria-labelledby` and `aria-describedby`. Props are
22
26
  camelCase in the types and kebab-case in a template: `itemTextValue` is written `item-text-value`.
23
27
 
@@ -13,8 +13,8 @@ export interface PortalProviderRootProps {
13
13
  /**
14
14
  * The part of the page the overlays below belong to, usually an element holding both the content
15
15
  * and the `container`. A modal makes only this element `inert` and holds focus and outside
16
- * presses only within it, and a placed overlay flips and shifts to stay inside it — so an app
17
- * rendered in a window of a larger page leaves the rest of that page alone.
16
+ * presses only within it, and a placed overlay flips and shifts to stay inside it — so content
17
+ * rendered into one region of a larger page leaves the rest of that page alone.
18
18
  *
19
19
  * Omitted, it inherits the enclosing provider's root; `null` goes back to the whole document.
20
20
  */
@@ -5,7 +5,7 @@ import SliderRoot from "./slider-root.js";
5
5
  import SliderThumb from "./slider-thumb.js";
6
6
  import SliderTrack from "./slider-track.js";
7
7
  export { SliderRoot as Slider, SliderOutput, SliderTrack, SliderFill, SliderThumb, SliderMarks };
8
- export type { SliderRootProps as SliderProps, SliderOutputProps, SliderTrackProps, SliderFillProps, SliderThumbProps, SliderMarksProps, SliderSlotProps, SliderThumbSlotProps, } from "./slider.types.js";
8
+ export type { SliderRootProps as SliderProps, SliderOutputProps, SliderTrackProps, SliderFillProps, SliderThumbProps, SliderMarksProps, SliderSlotProps, SliderTrackSlotProps, SliderThumbSlotProps, SliderValue, } from "./slider.types.js";
9
9
  export type { SliderOrientation } from "../../composables/use-slider-state.js";
10
10
  export { sliderVariants } from "@ropav/styles";
11
11
  export type { SliderVariants } from "@ropav/styles";
@@ -1,9 +1,9 @@
1
- import type { SliderRootProps, SliderSlotProps } from "./slider.types.js";
2
- declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>['expose'], __VLS_setup?: Promise<{
3
- props: import('vue').PublicProps & __VLS_PrettifyLocal<SliderRootProps & {
4
- onChange?: ((value: number | number[]) => any) | undefined;
5
- onChangeEnd?: ((value: number | number[]) => any) | undefined;
6
- "onUpdate:value"?: ((value: number | number[]) => any) | undefined;
1
+ import type { SliderRootProps, SliderSlotProps, SliderValue } from "./slider.types.js";
2
+ declare const __VLS_export: <V extends SliderValue = SliderValue>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>['expose'], __VLS_setup?: Promise<{
3
+ props: import('vue').PublicProps & __VLS_PrettifyLocal<SliderRootProps<V> & {
4
+ onChange?: ((value: V extends number ? number : number[]) => any) | undefined;
5
+ onChangeEnd?: ((value: V extends number ? number : number[]) => any) | undefined;
6
+ "onUpdate:value"?: ((value: V extends number ? number : number[]) => any) | undefined;
7
7
  }> & (typeof globalThis extends {
8
8
  __VLS_PROPS_FALLBACK: infer P;
9
9
  } ? P : {});
@@ -12,7 +12,7 @@ declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup
12
12
  slots: {
13
13
  default?: (props: SliderSlotProps) => unknown;
14
14
  };
15
- emit: ((evt: "change", value: number | number[]) => void) & ((evt: "changeEnd", value: number | number[]) => void) & ((evt: "update:value", value: number | number[]) => void);
15
+ emit: ((evt: "change", value: V extends number ? number : number[]) => void) & ((evt: "changeEnd", value: V extends number ? number : number[]) => void) & ((evt: "update:value", value: V extends number ? number : number[]) => void);
16
16
  }>) => import('vue').VNode & {
17
17
  __ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
18
18
  };
@@ -40,7 +40,12 @@ var slider_root_vue_vue_type_script_setup_true_vapor_true_lang_default = /*@__PU
40
40
  const props = __props;
41
41
  const fieldset = useFieldsetContext();
42
42
  const fieldsetIsDisabled = computed(() => props.isDisabled ?? fieldset?.isDisabled.value);
43
+ /**
44
+ * Written out rather than named, so the API reference reads it. `V` is inferred from the value
45
+ * itself, which makes `:default-value="30"` the literal `30`; the events report any number.
46
+ */
43
47
  const emit = __emit;
48
+ /** What the events carry, for the casts below. */
44
49
  const sliderId = useId$1(() => props.id);
45
50
  const numberFormatter = useNumberFormatter(() => props.formatOptions);
46
51
  const state = useSliderState({
@@ -1,4 +1,4 @@
1
- import type { SliderSlotProps, SliderTrackProps } from "./slider.types.js";
1
+ import type { SliderTrackProps, SliderTrackSlotProps } from "./slider.types.js";
2
2
  declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>['expose'], __VLS_setup?: Promise<{
3
3
  props: import('vue').PublicProps & __VLS_PrettifyLocal<SliderTrackProps> & (typeof globalThis extends {
4
4
  __VLS_PROPS_FALLBACK: infer P;
@@ -6,7 +6,7 @@ declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup
6
6
  expose: (exposed: {}) => void;
7
7
  attrs: any;
8
8
  slots: {
9
- default?: (props: SliderSlotProps) => unknown;
9
+ default?: (props: SliderTrackSlotProps) => unknown;
10
10
  };
11
11
  emit: {};
12
12
  }>) => import('vue').VNode & {
@@ -12,6 +12,11 @@ var slider_track_vue_vue_type_script_setup_true_vapor_true_lang_default = /*@__P
12
12
  const props = __props;
13
13
  const { setTrackEl, slider, slots, state } = useSliderContext();
14
14
  const { isHovered, onPointerenter, onPointerleave } = useInteractionStates({ isDisabled: () => state.isDisabled.value });
15
+ /** Leaving ends the hover state and the value the pointer was over, together. */
16
+ const onTrackPointerleave = () => {
17
+ onPointerleave();
18
+ slider.trackHandlers.onPointerleave();
19
+ };
15
20
  /** Where the filled part of the track starts and ends, as fractions of its length. */
16
21
  const offsets = computed(() => {
17
22
  const values = state.values.value;
@@ -52,13 +57,16 @@ var slider_track_vue_vue_type_script_setup_true_vapor_true_lang_default = /*@__P
52
57
  });
53
58
  setInsertionState(n1);
54
59
  createSlot("default", {
60
+ hoverPercent: () => unref(slider).hoverPercent.value,
61
+ hoverValue: () => unref(slider).hoverValue.value,
55
62
  isDisabled: () => unref(state).isDisabled.value,
56
63
  orientation: () => unref(state).orientation.value,
57
64
  values: () => unref(state).values.value
58
65
  });
59
66
  on(n1, "pointerdown", (e) => unref(slider).trackHandlers.onPointerdown(e));
60
67
  on(n1, "pointerenter", (e) => unref(onPointerenter)(e));
61
- on(n1, "pointerleave", (e) => unref(onPointerleave)(e));
68
+ on(n1, "pointerleave", onTrackPointerleave);
69
+ on(n1, "pointermove", (e) => unref(slider).trackHandlers.onPointermove(e));
62
70
  setTemplateRefBinding(n1, () => setTrackEl, void 0, "setTrackEl");
63
71
  return n1;
64
72
  }
@@ -1,10 +1,17 @@
1
1
  import type { SliderOrientation } from "../../composables/use-slider-state.js";
2
- export interface SliderRootProps {
2
+ /** A slider's value: a number for one thumb, an array for one thumb per entry. */
3
+ export type SliderValue = number | number[];
4
+ /**
5
+ * `V` is the shape the caller hands over, inferred from `value` or `defaultValue`, so `change`
6
+ * and `change-end` report a number to a caller who passed one and an array to one who passed an
7
+ * array.
8
+ */
9
+ export interface SliderRootProps<V extends SliderValue = SliderValue> {
3
10
  class?: string;
4
11
  /** Current value. A number drives one thumb, an array one thumb per entry. */
5
- value?: number | number[];
12
+ value?: V;
6
13
  /** Value while the slider is uncontrolled. */
7
- defaultValue?: number | number[];
14
+ defaultValue?: V;
8
15
  /** @default 0 */
9
16
  minValue?: number;
10
17
  /** @default 100 */
@@ -55,6 +62,21 @@ export interface SliderSlotProps {
55
62
  orientation: SliderOrientation;
56
63
  isDisabled: boolean;
57
64
  }
65
+ /** State the track hands to its slot. */
66
+ export interface SliderTrackSlotProps extends SliderSlotProps {
67
+ /**
68
+ * The value a press would set where a mouse or pen hovers over the track, snapped to the step,
69
+ * or `null` while none hovers or the slider is disabled. For a preview of what a press would
70
+ * do, such as a tooltip.
71
+ */
72
+ hoverValue: number | null;
73
+ /**
74
+ * Where `hoverValue` sits along the track, from 0 to 1, or `null` with it. A child of the track
75
+ * placed at this fraction of its width (its height, from the bottom, when vertical) sits where
76
+ * the thumb would land.
77
+ */
78
+ hoverPercent: number | null;
79
+ }
58
80
  /** State a thumb hands to its slot. */
59
81
  export interface SliderThumbSlotProps {
60
82
  isDragging: boolean;
@@ -8,7 +8,7 @@ export interface RegisteredScope {
8
8
  * The innermost scope holding focus in a region, among the scopes whose region overlaps it.
9
9
  *
10
10
  * Without a region every scope overlaps every other, which is the page-wide question. With one, a
11
- * modal in one app's window is not shadowed by a modal another app opened later in its own.
11
+ * modal in one region is not shadowed by a modal opened later in another region beside it.
12
12
  */
13
13
  export declare const innermostContainingScope: (region?: Element | null) => RegisteredScope | null;
14
14
  /**
@@ -12,7 +12,7 @@ var scopes = [];
12
12
  * The innermost scope holding focus in a region, among the scopes whose region overlaps it.
13
13
  *
14
14
  * Without a region every scope overlaps every other, which is the page-wide question. With one, a
15
- * modal in one app's window is not shadowed by a modal another app opened later in its own.
15
+ * modal in one region is not shadowed by a modal opened later in another region beside it.
16
16
  */
17
17
  var innermostContainingScope = (region = null) => {
18
18
  for (let index = scopes.length - 1; index >= 0; index--) {
@@ -24,7 +24,7 @@ export interface UseDismissableOptions {
24
24
  */
25
25
  shouldCloseOnInteractOutside?: (element: Element) => boolean;
26
26
  /**
27
- * The part of the page the overlay belongs to. A press outside it — in another app's window
27
+ * The part of the page the overlay belongs to. A press outside it — in another region
28
28
  * beside this one — is neither an outside interaction nor swallowed, and the overlay is only
29
29
  * stacked with overlays whose region overlaps its own. `null` or absent: the whole document.
30
30
  */
@@ -25,7 +25,7 @@ export interface UseFocusScopeOptions {
25
25
  autoFocus?: MaybeRefOrGetter<boolean | "first" | "last" | undefined>;
26
26
  /**
27
27
  * The part of the page containment holds focus within. Focus moving to something outside it —
28
- * another app's window beside this one — is left alone rather than pulled back, and Tab pressed
28
+ * another region beside this one — is left alone rather than pulled back, and Tab pressed
29
29
  * out there is not taken over. `null` or absent: the whole document.
30
30
  */
31
31
  region?: MaybeRefOrGetter<Element | null | undefined>;
@@ -142,15 +142,25 @@ var useInputOTP = (options) => {
142
142
  const reassert = () => {
143
143
  setFormValue(inputEl.value, value.value);
144
144
  };
145
- watch([inputEl, value], reassert, {
145
+ /** Bumped on every change reported, so the re-assert runs even when the owner keeps the value. */
146
+ const changeCount = shallowRef(0);
147
+ watch([
148
+ inputEl,
149
+ value,
150
+ changeCount
151
+ ], reassert, {
146
152
  flush: "post",
147
153
  immediate: true
148
154
  });
149
155
  const initialValue = value.value;
150
156
  useFormReset(inputEl, () => toValue(options.defaultValue) ?? initialValue, setState);
151
157
  const setValue = (next) => {
158
+ if (next === value.value) {
159
+ reassert();
160
+ return;
161
+ }
152
162
  setState(next);
153
- reassert();
163
+ changeCount.value++;
154
164
  };
155
165
  const badge = usePasswordManagerBadge({
156
166
  container: containerEl,
@@ -16,8 +16,8 @@ export interface Portal {
16
16
  * The portal that applies here: the nearest `PortalProvider`'s, or the document's body.
17
17
  *
18
18
  * Ported from React Aria's `UNSAFE_PortalProvider` (`getContainer`), with the root added: an
19
- * overlay rendered into a region of the page, say an app's window, belongs to that region and has
20
- * to leave the rest of the page alone — hidden, focused and pressed as it was.
19
+ * overlay rendered into a region of the page belongs to that region and has to leave the rest of
20
+ * the page alone — hidden, focused and pressed as it was.
21
21
  */
22
22
  export declare const usePortal: () => Portal;
23
23
  export interface PortalOptions {
@@ -15,8 +15,8 @@ var BODY = {
15
15
  * The portal that applies here: the nearest `PortalProvider`'s, or the document's body.
16
16
  *
17
17
  * Ported from React Aria's `UNSAFE_PortalProvider` (`getContainer`), with the root added: an
18
- * overlay rendered into a region of the page, say an app's window, belongs to that region and has
19
- * to leave the rest of the page alone — hidden, focused and pressed as it was.
18
+ * overlay rendered into a region of the page belongs to that region and has to leave the rest of
19
+ * the page alone — hidden, focused and pressed as it was.
20
20
  */
21
21
  var usePortal = () => usePortalContext() ?? BODY;
22
22
  /**
@@ -2,6 +2,7 @@ import { useMove } from "./use-move.js";
2
2
  import { useFormReset } from "./use-form-reset.js";
3
3
  import { setFormValue } from "../utils/form-value.js";
4
4
  import { clamp } from "../utils/number.js";
5
+ import { getTrackTravel } from "./use-slider.js";
5
6
  import { computed, nextTick, onScopeDispose, toValue, watch, watchEffect } from "vue";
6
7
  //#region src/composables/use-slider-thumb.ts
7
8
  /**
@@ -42,8 +43,7 @@ var useSliderThumb = (options) => {
42
43
  const { handlers: moveHandlers } = useMove({
43
44
  onMove: ({ deltaX, deltaY, pointerType, shiftKey }) => {
44
45
  if (!trackEl.value) return;
45
- const rect = trackEl.value.getBoundingClientRect();
46
- const size = isVertical.value ? rect.height : rect.width;
46
+ const { size } = getTrackTravel(trackEl.value, isVertical.value);
47
47
  if (currentPosition === null) currentPosition = state.getThumbPercent(index.value) * size;
48
48
  if (pointerType === "keyboard") {
49
49
  const stepSize = shiftKey ? state.pageSize.value : state.step.value;
@@ -2,7 +2,10 @@ import type { SliderState } from "./use-slider-state.js";
2
2
  import type { CSSProperties, ComputedRef, MaybeRefOrGetter, Ref } from "vue";
3
3
  export interface UseSliderOptions {
4
4
  state: SliderState;
5
- /** The track element. Its length is the distance a thumb can travel. */
5
+ /**
6
+ * The track element. Its length, less the spacers at either end, is the distance a thumb can
7
+ * travel.
8
+ */
6
9
  trackEl: Ref<HTMLElement | null>;
7
10
  /** The group's own id, and the stem every thumb id grows from. */
8
11
  id: MaybeRefOrGetter<string>;
@@ -26,13 +29,23 @@ export interface UseSliderReturn {
26
29
  /** For the root element: the thumbs are inputs, and the group is what names them together. */
27
30
  groupProps: ComputedRef<SliderGroupAttrs>;
28
31
  /**
29
- * The track accepts clicks and drags for the nearest thumb. Attach with `@pointerdown`, never
30
- * through `v-bind`: a vapor render re-attaches every `on*` key that arrived that way, which
31
- * drops the listener when the press itself is what re-rendered the element.
32
+ * The track accepts clicks and drags for the nearest thumb, and follows a hovering pointer.
33
+ * Attach each with its own `@pointer…` listener, never through `v-bind`: a vapor render
34
+ * re-attaches every `on*` key that arrived that way, which drops the listener when the press
35
+ * itself is what re-rendered the element.
32
36
  */
33
37
  trackHandlers: {
34
38
  onPointerdown: (event: PointerEvent) => void;
39
+ onPointermove: (event: PointerEvent) => void;
40
+ onPointerleave: () => void;
35
41
  };
42
+ /**
43
+ * The value a press would set where a mouse or pen hovers over the track, snapped to the step,
44
+ * or `null` while none hovers or the slider is disabled.
45
+ */
46
+ hoverValue: ComputedRef<number | null>;
47
+ /** Where `hoverValue` sits along the thumb's travel, from 0 to 1. */
48
+ hoverPercent: ComputedRef<number | null>;
36
49
  /** Inline styles the track needs whatever the stylesheet says. */
37
50
  trackStyle: CSSProperties;
38
51
  outputProps: ComputedRef<SliderOutputAttrs>;
@@ -44,6 +57,16 @@ export interface UseSliderReturn {
44
57
  /** Hand focus to the first thumb, for a click on the label. */
45
58
  focusFirstThumb: () => void;
46
59
  }
60
+ /**
61
+ * Where a thumb's travel starts on screen and how long it is. The track's end spacers are
62
+ * borders, and the thumb is positioned inside them, so the travel is the track's box less its
63
+ * borders rather than the box itself: measured against the whole box, a press would land the
64
+ * thumb off the pointer and a drag would trail it. A vertical travel starts at the bottom.
65
+ */
66
+ export declare const getTrackTravel: (track: HTMLElement, isVertical: boolean) => {
67
+ size: number;
68
+ start: number;
69
+ };
47
70
  /**
48
71
  * Labelling, the output element, and click-and-drag on the track.
49
72
  *
@@ -1,9 +1,33 @@
1
1
  import { setInteractionModality } from "./interaction-modality.js";
2
2
  import { useMove } from "./use-move.js";
3
3
  import { clamp } from "../utils/number.js";
4
- import { computed, onScopeDispose, toValue } from "vue";
4
+ import { computed, onScopeDispose, shallowRef, toValue } from "vue";
5
5
  //#region src/composables/use-slider.ts
6
6
  /**
7
+ * Where a thumb's travel starts on screen and how long it is. The track's end spacers are
8
+ * borders, and the thumb is positioned inside them, so the travel is the track's box less its
9
+ * borders rather than the box itself: measured against the whole box, a press would land the
10
+ * thumb off the pointer and a drag would trail it. A vertical travel starts at the bottom.
11
+ */
12
+ var getTrackTravel = (track, isVertical) => {
13
+ const rect = track.getBoundingClientRect();
14
+ const style = getComputedStyle(track);
15
+ if (isVertical) {
16
+ const top = Number.parseFloat(style.borderTopWidth) || 0;
17
+ const bottom = Number.parseFloat(style.borderBottomWidth) || 0;
18
+ return {
19
+ size: rect.height - top - bottom,
20
+ start: rect.bottom - bottom
21
+ };
22
+ }
23
+ const left = Number.parseFloat(style.borderLeftWidth) || 0;
24
+ const right = Number.parseFloat(style.borderRightWidth) || 0;
25
+ return {
26
+ size: rect.width - left - right,
27
+ start: rect.left + left
28
+ };
29
+ };
30
+ /**
7
31
  * Labelling, the output element, and click-and-drag on the track.
8
32
  *
9
33
  * Ported from React Aria's `useSlider`. The track is not decoration: pressing anywhere on it
@@ -33,16 +57,23 @@ var useSlider = (options) => {
33
57
  const ids = [toValue(options.labelId), toValue(options.ariaLabelledby)].filter(Boolean);
34
58
  return ids.length > 0 ? ids.join(" ") : void 0;
35
59
  });
60
+ /** Where a hovering mouse or pen is along the travel, from 0 to 1, unsnapped. */
61
+ const hoverPosition = shallowRef(null);
62
+ const hoverValue = computed(() => hoverPosition.value === null || state.isDisabled.value ? null : state.getPercentValue(hoverPosition.value));
36
63
  /** Index of the thumb the current press on the track is dragging. */
37
64
  let draggingIndex = null;
38
65
  /** Where that thumb sits along the track, in pixels, as the drag goes on. */
39
66
  let currentPosition = null;
40
67
  let currentPointerId;
41
68
  let detachRelease;
42
- const trackSize = () => {
43
- const rect = trackEl.value?.getBoundingClientRect();
44
- if (!rect) return 0;
45
- return isVertical.value ? rect.height : rect.width;
69
+ const measureTravel = () => trackEl.value ? getTrackTravel(trackEl.value, isVertical.value) : null;
70
+ const trackSize = () => measureTravel()?.size ?? 0;
71
+ /** How far along the travel a point on screen is, from 0 to 1. */
72
+ const percentAt = (clientX, clientY) => {
73
+ const travel = measureTravel();
74
+ if (!travel || travel.size <= 0) return 0;
75
+ const offset = isVertical.value ? travel.start - clientY : clientX - travel.start;
76
+ return clamp(offset / travel.size, 0, 1);
46
77
  };
47
78
  const { handlers: moveHandlers } = useMove({
48
79
  onMove: ({ deltaX, deltaY }) => {
@@ -83,11 +114,7 @@ var useSlider = (options) => {
83
114
  const onPointerdown = (event) => {
84
115
  if (event.pointerType === "mouse" && (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey)) return;
85
116
  if (!trackEl.value || state.isDisabled.value || state.values.value.some((_, index) => state.isThumbDragging(index))) return;
86
- const rect = trackEl.value.getBoundingClientRect();
87
- const size = isVertical.value ? rect.height : rect.width;
88
- const offset = isVertical.value ? event.clientY - rect.top : event.clientX - rect.left;
89
- const percent = isVertical.value ? 1 - offset / size : offset / size;
90
- const value = state.getPercentValue(percent);
117
+ const value = state.getPercentValue(percentAt(event.clientX, event.clientY));
91
118
  const index = closestThumb(value);
92
119
  if (index < 0 || !state.isThumbEditable(index)) {
93
120
  draggingIndex = null;
@@ -121,15 +148,25 @@ var useSlider = (options) => {
121
148
  id: toValue(options.id),
122
149
  role: "group"
123
150
  })),
151
+ hoverPercent: computed(() => hoverValue.value === null ? null : state.getValuePercent(hoverValue.value)),
152
+ hoverValue,
124
153
  labelledBy,
125
154
  outputProps: computed(() => ({
126
155
  "aria-live": "off",
127
156
  for: state.values.value.map((_, index) => getThumbId(index)).join(" ")
128
157
  })),
129
- trackHandlers: { onPointerdown: (event) => {
130
- onPointerdown(event);
131
- moveHandlers.onPointerdown(event);
132
- } },
158
+ trackHandlers: {
159
+ onPointerdown: (event) => {
160
+ onPointerdown(event);
161
+ moveHandlers.onPointerdown(event);
162
+ },
163
+ onPointerleave: () => {
164
+ hoverPosition.value = null;
165
+ },
166
+ onPointermove: (event) => {
167
+ hoverPosition.value = event.pointerType === "touch" ? null : percentAt(event.clientX, event.clientY);
168
+ }
169
+ },
133
170
  trackStyle: {
134
171
  position: "relative",
135
172
  touchAction: "none"
@@ -137,4 +174,4 @@ var useSlider = (options) => {
137
174
  };
138
175
  };
139
176
  //#endregion
140
- export { useSlider };
177
+ export { getTrackTravel, useSlider };
@@ -62,6 +62,8 @@ var useTextField = (options = {}) => {
62
62
  "errorMessage"
63
63
  ]
64
64
  });
65
+ /** Bumped on every change the field reports, so the re-assert runs even when the value stays. */
66
+ const changeCount = shallowRef(0);
65
67
  /** Whether a control has taken the value over, in which case the field writes nothing. */
66
68
  const isValueOwned = shallowRef(false);
67
69
  const setValueOwned = (owned) => {
@@ -82,14 +84,19 @@ var useTextField = (options = {}) => {
82
84
  watch([
83
85
  element,
84
86
  value,
85
- isValueOwned
87
+ isValueOwned,
88
+ changeCount
86
89
  ], reassert, {
87
90
  flush: "post",
88
91
  immediate: true
89
92
  });
90
93
  const setValue = (next) => {
94
+ if (next === value.value) {
95
+ reassert();
96
+ return;
97
+ }
91
98
  setState(next);
92
- reassert();
99
+ changeCount.value++;
93
100
  };
94
101
  const initialValue = value.value;
95
102
  if (!options.skipFormReset) useFormReset(element, () => toValue(options.defaultValue) ?? initialValue, setState, options.form);