@zag-js/slider 1.47.0 → 1.49.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.
@@ -1,30 +1,27 @@
1
- import { Scope, Params } from '@zag-js/core';
2
- import { Point } from '@zag-js/types';
3
- import { SliderSchema } from './slider.types.mjs';
4
-
5
- declare const getRootId: (ctx: Scope) => any;
6
- declare const getThumbId: (ctx: Scope, index: number) => any;
7
- declare const getHiddenInputId: (ctx: Scope, index: number) => any;
8
- declare const getControlId: (ctx: Scope) => any;
9
- declare const getTrackId: (ctx: Scope) => any;
10
- declare const getRangeId: (ctx: Scope) => any;
11
- declare const getLabelId: (ctx: Scope) => any;
12
- declare const getValueTextId: (ctx: Scope) => any;
13
- declare const getMarkerId: (ctx: Scope, value: number) => any;
14
- declare const getRootEl: (ctx: Scope) => HTMLElement | null;
15
- declare const getThumbEl: (ctx: Scope, index: number) => HTMLElement | null;
16
- declare const getThumbEls: (ctx: Scope) => HTMLElement[];
17
- declare const getFirstThumbEl: (ctx: Scope) => HTMLElement;
18
- declare const getHiddenInputEl: (ctx: Scope, index: number) => HTMLInputElement | null;
19
- declare const getControlEl: (ctx: Scope) => HTMLElement | null;
20
- declare const getRangeEl: (ctx: Scope) => HTMLElement | null;
21
- declare const getPointValue: (params: Params<SliderSchema>, point: Point) => number | undefined;
22
- declare const dispatchChangeEvent: (ctx: Scope, value: number[]) => void;
23
- declare const getOffsetRect: (el: HTMLElement | undefined) => {
24
- left: number;
25
- top: number;
26
- width: number;
27
- height: number;
28
- };
29
-
30
- export { dispatchChangeEvent, getControlEl, getControlId, getFirstThumbEl, getHiddenInputEl, getHiddenInputId, getLabelId, getMarkerId, getOffsetRect, getPointValue, getRangeEl, getRangeId, getRootEl, getRootId, getThumbEl, getThumbEls, getThumbId, getTrackId, getValueTextId };
1
+ import { Params, Scope } from "@zag-js/core";
2
+ import { Point } from "@zag-js/types";
3
+ import { SliderSchema } from "./slider.types.mjs";
4
+ export declare const getRootId: (ctx: Scope) => any;
5
+ export declare const getThumbId: (ctx: Scope, index: number) => any;
6
+ export declare const getHiddenInputId: (ctx: Scope, index: number) => any;
7
+ export declare const getControlId: (ctx: Scope) => any;
8
+ export declare const getTrackId: (ctx: Scope) => any;
9
+ export declare const getRangeId: (ctx: Scope) => any;
10
+ export declare const getLabelId: (ctx: Scope) => any;
11
+ export declare const getValueTextId: (ctx: Scope) => any;
12
+ export declare const getMarkerId: (ctx: Scope, value: number) => any;
13
+ export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
14
+ export declare const getThumbEl: (ctx: Scope, index: number) => HTMLElement | null;
15
+ export declare const getThumbEls: (ctx: Scope) => HTMLElement[];
16
+ export declare const getFirstThumbEl: (ctx: Scope) => HTMLElement;
17
+ export declare const getHiddenInputEl: (ctx: Scope, index: number) => HTMLInputElement | null;
18
+ export declare const getControlEl: (ctx: Scope) => HTMLElement | null;
19
+ export declare const getRangeEl: (ctx: Scope) => HTMLElement | null;
20
+ export declare const getPointValue: (params: Params<SliderSchema>, point: Point) => number | undefined;
21
+ export declare const dispatchChangeEvent: (ctx: Scope, value: number[]) => void;
22
+ export declare const getOffsetRect: (el: HTMLElement | undefined) => {
23
+ left: number;
24
+ top: number;
25
+ width: number;
26
+ height: number;
27
+ };
@@ -1,30 +1,27 @@
1
- import { Scope, Params } from '@zag-js/core';
2
- import { Point } from '@zag-js/types';
3
- import { SliderSchema } from './slider.types.js';
4
-
5
- declare const getRootId: (ctx: Scope) => any;
6
- declare const getThumbId: (ctx: Scope, index: number) => any;
7
- declare const getHiddenInputId: (ctx: Scope, index: number) => any;
8
- declare const getControlId: (ctx: Scope) => any;
9
- declare const getTrackId: (ctx: Scope) => any;
10
- declare const getRangeId: (ctx: Scope) => any;
11
- declare const getLabelId: (ctx: Scope) => any;
12
- declare const getValueTextId: (ctx: Scope) => any;
13
- declare const getMarkerId: (ctx: Scope, value: number) => any;
14
- declare const getRootEl: (ctx: Scope) => HTMLElement | null;
15
- declare const getThumbEl: (ctx: Scope, index: number) => HTMLElement | null;
16
- declare const getThumbEls: (ctx: Scope) => HTMLElement[];
17
- declare const getFirstThumbEl: (ctx: Scope) => HTMLElement;
18
- declare const getHiddenInputEl: (ctx: Scope, index: number) => HTMLInputElement | null;
19
- declare const getControlEl: (ctx: Scope) => HTMLElement | null;
20
- declare const getRangeEl: (ctx: Scope) => HTMLElement | null;
21
- declare const getPointValue: (params: Params<SliderSchema>, point: Point) => number | undefined;
22
- declare const dispatchChangeEvent: (ctx: Scope, value: number[]) => void;
23
- declare const getOffsetRect: (el: HTMLElement | undefined) => {
24
- left: number;
25
- top: number;
26
- width: number;
27
- height: number;
28
- };
29
-
30
- export { dispatchChangeEvent, getControlEl, getControlId, getFirstThumbEl, getHiddenInputEl, getHiddenInputId, getLabelId, getMarkerId, getOffsetRect, getPointValue, getRangeEl, getRangeId, getRootEl, getRootId, getThumbEl, getThumbEls, getThumbId, getTrackId, getValueTextId };
1
+ import { Params, Scope } from "@zag-js/core";
2
+ import { Point } from "@zag-js/types";
3
+ import { SliderSchema } from "./slider.types.js";
4
+ export declare const getRootId: (ctx: Scope) => any;
5
+ export declare const getThumbId: (ctx: Scope, index: number) => any;
6
+ export declare const getHiddenInputId: (ctx: Scope, index: number) => any;
7
+ export declare const getControlId: (ctx: Scope) => any;
8
+ export declare const getTrackId: (ctx: Scope) => any;
9
+ export declare const getRangeId: (ctx: Scope) => any;
10
+ export declare const getLabelId: (ctx: Scope) => any;
11
+ export declare const getValueTextId: (ctx: Scope) => any;
12
+ export declare const getMarkerId: (ctx: Scope, value: number) => any;
13
+ export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
14
+ export declare const getThumbEl: (ctx: Scope, index: number) => HTMLElement | null;
15
+ export declare const getThumbEls: (ctx: Scope) => HTMLElement[];
16
+ export declare const getFirstThumbEl: (ctx: Scope) => HTMLElement;
17
+ export declare const getHiddenInputEl: (ctx: Scope, index: number) => HTMLInputElement | null;
18
+ export declare const getControlEl: (ctx: Scope) => HTMLElement | null;
19
+ export declare const getRangeEl: (ctx: Scope) => HTMLElement | null;
20
+ export declare const getPointValue: (params: Params<SliderSchema>, point: Point) => number | undefined;
21
+ export declare const dispatchChangeEvent: (ctx: Scope, value: number[]) => void;
22
+ export declare const getOffsetRect: (el: HTMLElement | undefined) => {
23
+ left: number;
24
+ top: number;
25
+ width: number;
26
+ height: number;
27
+ };
@@ -1,144 +1,100 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/slider.dom.ts
21
- var slider_dom_exports = {};
22
- __export(slider_dom_exports, {
23
- dispatchChangeEvent: () => dispatchChangeEvent,
24
- getControlEl: () => getControlEl,
25
- getControlId: () => getControlId,
26
- getFirstThumbEl: () => getFirstThumbEl,
27
- getHiddenInputEl: () => getHiddenInputEl,
28
- getHiddenInputId: () => getHiddenInputId,
29
- getLabelId: () => getLabelId,
30
- getMarkerId: () => getMarkerId,
31
- getOffsetRect: () => getOffsetRect,
32
- getPointValue: () => getPointValue,
33
- getRangeEl: () => getRangeEl,
34
- getRangeId: () => getRangeId,
35
- getRootEl: () => getRootEl,
36
- getRootId: () => getRootId,
37
- getThumbEl: () => getThumbEl,
38
- getThumbEls: () => getThumbEls,
39
- getThumbId: () => getThumbId,
40
- getTrackId: () => getTrackId,
41
- getValueTextId: () => getValueTextId
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
42
4
  });
43
- module.exports = __toCommonJS(slider_dom_exports);
44
- var import_dom_query = require("@zag-js/dom-query");
45
- var import_utils = require("@zag-js/utils");
46
- var getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
47
- var getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
48
- var getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
49
- var getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
50
- var getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
51
- var getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
52
- var getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
53
- var getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
54
- var getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
55
- var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
56
- var getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
57
- var getThumbEls = (ctx) => (0, import_dom_query.queryAll)(getControlEl(ctx), "[role=slider]");
58
- var getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
59
- var getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
60
- var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
61
- var getRangeEl = (ctx) => ctx.getById(getRangeId(ctx));
62
- var getThumbInset = (thumbSize, thumbAlignment, orientation) => {
63
- const isContain = thumbAlignment === "contain";
64
- const isVertical = orientation === "vertical";
65
- return isContain ? (isVertical ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
5
+ let _zag_js_dom_query = require("@zag-js/dom-query");
6
+ let _zag_js_utils = require("@zag-js/utils");
7
+ // src/slider.dom.ts
8
+ const getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
9
+ const getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
10
+ const getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
11
+ const getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
12
+ const getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
13
+ const getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
14
+ const getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
15
+ const getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
16
+ const getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
17
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
18
+ const getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
19
+ const getThumbEls = (ctx) => (0, _zag_js_dom_query.queryAll)(getControlEl(ctx), "[role=slider]");
20
+ const getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
21
+ const getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
22
+ const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
23
+ const getRangeEl = (ctx) => ctx.getById(getRangeId(ctx));
24
+ const getThumbInset = (thumbSize, thumbAlignment, orientation) => {
25
+ return thumbAlignment === "contain" ? (orientation === "vertical" ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
66
26
  };
67
- var getPointValue = (params, point) => {
68
- const { context, prop, scope, refs } = params;
69
- const controlEl = getControlEl(scope);
70
- if (!controlEl) return;
71
- const offset = refs.get("thumbDragOffset");
72
- const adjustedPoint = {
73
- x: point.x - (offset?.x ?? 0),
74
- y: point.y - (offset?.y ?? 0)
75
- };
76
- const thumbInset = getThumbInset(context.get("thumbSize"), prop("thumbAlignment"), prop("orientation"));
77
- const relativePoint = getRelativePointWithInset(adjustedPoint, controlEl, thumbInset);
78
- const percent = relativePoint.getPercentValue({
79
- orientation: prop("orientation"),
80
- dir: prop("dir"),
81
- inverted: { y: true }
82
- });
83
- return (0, import_utils.getPercentValue)(percent, prop("min"), prop("max"), prop("step"));
27
+ const getPointValue = (params, point) => {
28
+ const { context, prop, scope, refs } = params;
29
+ const controlEl = getControlEl(scope);
30
+ if (!controlEl) return;
31
+ const offset = refs.get("thumbDragOffset");
32
+ const percent = getRelativePointWithInset({
33
+ x: point.x - (offset?.x ?? 0),
34
+ y: point.y - (offset?.y ?? 0)
35
+ }, controlEl, getThumbInset(context.get("thumbSize"), prop("thumbAlignment"), prop("orientation"))).getPercentValue({
36
+ orientation: prop("orientation"),
37
+ dir: prop("dir"),
38
+ inverted: { y: true }
39
+ });
40
+ return (0, _zag_js_utils.getPercentValue)(percent, prop("min"), prop("max"), prop("step"));
84
41
  };
85
42
  function getRelativePointWithInset(point, element, inset) {
86
- const { left, top, width, height } = element.getBoundingClientRect();
87
- const effectiveWidth = width - inset * 2;
88
- const effectiveHeight = height - inset * 2;
89
- const effectiveLeft = left + inset;
90
- const effectiveTop = top + inset;
91
- const offset = {
92
- x: point.x - effectiveLeft,
93
- y: point.y - effectiveTop
94
- };
95
- const percent = {
96
- x: effectiveWidth > 0 ? (0, import_utils.clampPercent)(offset.x / effectiveWidth) : 0,
97
- y: effectiveHeight > 0 ? (0, import_utils.clampPercent)(offset.y / effectiveHeight) : 0
98
- };
99
- function getPercentValue2(options = {}) {
100
- const { dir = "ltr", orientation = "horizontal", inverted } = options;
101
- const invertX = typeof inverted === "object" ? inverted.x : inverted;
102
- const invertY = typeof inverted === "object" ? inverted.y : inverted;
103
- if (orientation === "horizontal") {
104
- return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
105
- }
106
- return invertY ? 1 - percent.y : percent.y;
107
- }
108
- return { offset, percent, getPercentValue: getPercentValue2 };
43
+ const { left, top, width, height } = element.getBoundingClientRect();
44
+ const effectiveWidth = width - inset * 2;
45
+ const effectiveHeight = height - inset * 2;
46
+ const effectiveLeft = left + inset;
47
+ const effectiveTop = top + inset;
48
+ const offset = {
49
+ x: point.x - effectiveLeft,
50
+ y: point.y - effectiveTop
51
+ };
52
+ const percent = {
53
+ x: effectiveWidth > 0 ? (0, _zag_js_utils.clampPercent)(offset.x / effectiveWidth) : 0,
54
+ y: effectiveHeight > 0 ? (0, _zag_js_utils.clampPercent)(offset.y / effectiveHeight) : 0
55
+ };
56
+ function getPercentValue(options = {}) {
57
+ const { dir = "ltr", orientation = "horizontal", inverted } = options;
58
+ const invertX = typeof inverted === "object" ? inverted.x : inverted;
59
+ const invertY = typeof inverted === "object" ? inverted.y : inverted;
60
+ if (orientation === "horizontal") return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
61
+ return invertY ? 1 - percent.y : percent.y;
62
+ }
63
+ return {
64
+ offset,
65
+ percent,
66
+ getPercentValue
67
+ };
109
68
  }
110
- var dispatchChangeEvent = (ctx, value) => {
111
- value.forEach((value2, index) => {
112
- const inputEl = getHiddenInputEl(ctx, index);
113
- if (!inputEl) return;
114
- (0, import_dom_query.dispatchInputValueEvent)(inputEl, { value: value2 });
115
- });
69
+ const dispatchChangeEvent = (ctx, value) => {
70
+ value.forEach((value, index) => {
71
+ const inputEl = getHiddenInputEl(ctx, index);
72
+ if (!inputEl) return;
73
+ (0, _zag_js_dom_query.dispatchInputValueEvent)(inputEl, { value });
74
+ });
116
75
  };
117
- var getOffsetRect = (el) => ({
118
- left: el?.offsetLeft ?? 0,
119
- top: el?.offsetTop ?? 0,
120
- width: el?.offsetWidth ?? 0,
121
- height: el?.offsetHeight ?? 0
122
- });
123
- // Annotate the CommonJS export names for ESM import in node:
124
- 0 && (module.exports = {
125
- dispatchChangeEvent,
126
- getControlEl,
127
- getControlId,
128
- getFirstThumbEl,
129
- getHiddenInputEl,
130
- getHiddenInputId,
131
- getLabelId,
132
- getMarkerId,
133
- getOffsetRect,
134
- getPointValue,
135
- getRangeEl,
136
- getRangeId,
137
- getRootEl,
138
- getRootId,
139
- getThumbEl,
140
- getThumbEls,
141
- getThumbId,
142
- getTrackId,
143
- getValueTextId
76
+ const getOffsetRect = (el) => ({
77
+ left: el?.offsetLeft ?? 0,
78
+ top: el?.offsetTop ?? 0,
79
+ width: el?.offsetWidth ?? 0,
80
+ height: el?.offsetHeight ?? 0
144
81
  });
82
+ exports.dispatchChangeEvent = dispatchChangeEvent;
83
+ exports.getControlEl = getControlEl;
84
+ exports.getControlId = getControlId;
85
+ exports.getFirstThumbEl = getFirstThumbEl;
86
+ exports.getHiddenInputEl = getHiddenInputEl;
87
+ exports.getHiddenInputId = getHiddenInputId;
88
+ exports.getLabelId = getLabelId;
89
+ exports.getMarkerId = getMarkerId;
90
+ exports.getOffsetRect = getOffsetRect;
91
+ exports.getPointValue = getPointValue;
92
+ exports.getRangeEl = getRangeEl;
93
+ exports.getRangeId = getRangeId;
94
+ exports.getRootEl = getRootEl;
95
+ exports.getRootId = getRootId;
96
+ exports.getThumbEl = getThumbEl;
97
+ exports.getThumbEls = getThumbEls;
98
+ exports.getThumbId = getThumbId;
99
+ exports.getTrackId = getTrackId;
100
+ exports.getValueTextId = getValueTextId;
@@ -1,101 +1,78 @@
1
- // src/slider.dom.ts
2
1
  import { dispatchInputValueEvent, queryAll } from "@zag-js/dom-query";
3
2
  import { clampPercent, getPercentValue } from "@zag-js/utils";
4
- var getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
5
- var getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
6
- var getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
7
- var getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
8
- var getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
9
- var getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
10
- var getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
11
- var getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
12
- var getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
13
- var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
14
- var getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
15
- var getThumbEls = (ctx) => queryAll(getControlEl(ctx), "[role=slider]");
16
- var getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
17
- var getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
18
- var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
19
- var getRangeEl = (ctx) => ctx.getById(getRangeId(ctx));
20
- var getThumbInset = (thumbSize, thumbAlignment, orientation) => {
21
- const isContain = thumbAlignment === "contain";
22
- const isVertical = orientation === "vertical";
23
- return isContain ? (isVertical ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
3
+ // src/slider.dom.ts
4
+ const getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
5
+ const getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
6
+ const getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
7
+ const getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
8
+ const getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
9
+ const getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
10
+ const getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
11
+ const getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
12
+ const getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
13
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
14
+ const getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
15
+ const getThumbEls = (ctx) => queryAll(getControlEl(ctx), "[role=slider]");
16
+ const getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
17
+ const getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
18
+ const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
19
+ const getRangeEl = (ctx) => ctx.getById(getRangeId(ctx));
20
+ const getThumbInset = (thumbSize, thumbAlignment, orientation) => {
21
+ return thumbAlignment === "contain" ? (orientation === "vertical" ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
24
22
  };
25
- var getPointValue = (params, point) => {
26
- const { context, prop, scope, refs } = params;
27
- const controlEl = getControlEl(scope);
28
- if (!controlEl) return;
29
- const offset = refs.get("thumbDragOffset");
30
- const adjustedPoint = {
31
- x: point.x - (offset?.x ?? 0),
32
- y: point.y - (offset?.y ?? 0)
33
- };
34
- const thumbInset = getThumbInset(context.get("thumbSize"), prop("thumbAlignment"), prop("orientation"));
35
- const relativePoint = getRelativePointWithInset(adjustedPoint, controlEl, thumbInset);
36
- const percent = relativePoint.getPercentValue({
37
- orientation: prop("orientation"),
38
- dir: prop("dir"),
39
- inverted: { y: true }
40
- });
41
- return getPercentValue(percent, prop("min"), prop("max"), prop("step"));
23
+ const getPointValue = (params, point) => {
24
+ const { context, prop, scope, refs } = params;
25
+ const controlEl = getControlEl(scope);
26
+ if (!controlEl) return;
27
+ const offset = refs.get("thumbDragOffset");
28
+ const percent = getRelativePointWithInset({
29
+ x: point.x - (offset?.x ?? 0),
30
+ y: point.y - (offset?.y ?? 0)
31
+ }, controlEl, getThumbInset(context.get("thumbSize"), prop("thumbAlignment"), prop("orientation"))).getPercentValue({
32
+ orientation: prop("orientation"),
33
+ dir: prop("dir"),
34
+ inverted: { y: true }
35
+ });
36
+ return getPercentValue(percent, prop("min"), prop("max"), prop("step"));
42
37
  };
43
38
  function getRelativePointWithInset(point, element, inset) {
44
- const { left, top, width, height } = element.getBoundingClientRect();
45
- const effectiveWidth = width - inset * 2;
46
- const effectiveHeight = height - inset * 2;
47
- const effectiveLeft = left + inset;
48
- const effectiveTop = top + inset;
49
- const offset = {
50
- x: point.x - effectiveLeft,
51
- y: point.y - effectiveTop
52
- };
53
- const percent = {
54
- x: effectiveWidth > 0 ? clampPercent(offset.x / effectiveWidth) : 0,
55
- y: effectiveHeight > 0 ? clampPercent(offset.y / effectiveHeight) : 0
56
- };
57
- function getPercentValue2(options = {}) {
58
- const { dir = "ltr", orientation = "horizontal", inverted } = options;
59
- const invertX = typeof inverted === "object" ? inverted.x : inverted;
60
- const invertY = typeof inverted === "object" ? inverted.y : inverted;
61
- if (orientation === "horizontal") {
62
- return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
63
- }
64
- return invertY ? 1 - percent.y : percent.y;
65
- }
66
- return { offset, percent, getPercentValue: getPercentValue2 };
39
+ const { left, top, width, height } = element.getBoundingClientRect();
40
+ const effectiveWidth = width - inset * 2;
41
+ const effectiveHeight = height - inset * 2;
42
+ const effectiveLeft = left + inset;
43
+ const effectiveTop = top + inset;
44
+ const offset = {
45
+ x: point.x - effectiveLeft,
46
+ y: point.y - effectiveTop
47
+ };
48
+ const percent = {
49
+ x: effectiveWidth > 0 ? clampPercent(offset.x / effectiveWidth) : 0,
50
+ y: effectiveHeight > 0 ? clampPercent(offset.y / effectiveHeight) : 0
51
+ };
52
+ function getPercentValue(options = {}) {
53
+ const { dir = "ltr", orientation = "horizontal", inverted } = options;
54
+ const invertX = typeof inverted === "object" ? inverted.x : inverted;
55
+ const invertY = typeof inverted === "object" ? inverted.y : inverted;
56
+ if (orientation === "horizontal") return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
57
+ return invertY ? 1 - percent.y : percent.y;
58
+ }
59
+ return {
60
+ offset,
61
+ percent,
62
+ getPercentValue
63
+ };
67
64
  }
68
- var dispatchChangeEvent = (ctx, value) => {
69
- value.forEach((value2, index) => {
70
- const inputEl = getHiddenInputEl(ctx, index);
71
- if (!inputEl) return;
72
- dispatchInputValueEvent(inputEl, { value: value2 });
73
- });
65
+ const dispatchChangeEvent = (ctx, value) => {
66
+ value.forEach((value, index) => {
67
+ const inputEl = getHiddenInputEl(ctx, index);
68
+ if (!inputEl) return;
69
+ dispatchInputValueEvent(inputEl, { value });
70
+ });
74
71
  };
75
- var getOffsetRect = (el) => ({
76
- left: el?.offsetLeft ?? 0,
77
- top: el?.offsetTop ?? 0,
78
- width: el?.offsetWidth ?? 0,
79
- height: el?.offsetHeight ?? 0
72
+ const getOffsetRect = (el) => ({
73
+ left: el?.offsetLeft ?? 0,
74
+ top: el?.offsetTop ?? 0,
75
+ width: el?.offsetWidth ?? 0,
76
+ height: el?.offsetHeight ?? 0
80
77
  });
81
- export {
82
- dispatchChangeEvent,
83
- getControlEl,
84
- getControlId,
85
- getFirstThumbEl,
86
- getHiddenInputEl,
87
- getHiddenInputId,
88
- getLabelId,
89
- getMarkerId,
90
- getOffsetRect,
91
- getPointValue,
92
- getRangeEl,
93
- getRangeId,
94
- getRootEl,
95
- getRootId,
96
- getThumbEl,
97
- getThumbEls,
98
- getThumbId,
99
- getTrackId,
100
- getValueTextId
101
- };
78
+ export { dispatchChangeEvent, getControlEl, getControlId, getFirstThumbEl, getHiddenInputEl, getHiddenInputId, getLabelId, getMarkerId, getOffsetRect, getPointValue, getRangeEl, getRangeId, getRootEl, getRootId, getThumbEl, getThumbEls, getThumbId, getTrackId, getValueTextId };
@@ -1,7 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { SliderSchema } from './slider.types.mjs';
3
- import '@zag-js/types';
4
-
5
- declare const machine: _zag_js_core.Machine<SliderSchema>;
6
-
7
- export { machine };
1
+ import { SliderSchema } from "./slider.types.mjs";
2
+ export declare const machine: import("@zag-js/core").Machine<SliderSchema>;
@@ -1,7 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { SliderSchema } from './slider.types.js';
3
- import '@zag-js/types';
4
-
5
- declare const machine: _zag_js_core.Machine<SliderSchema>;
6
-
7
- export { machine };
1
+ import { SliderSchema } from "./slider.types.js";
2
+ export declare const machine: import("@zag-js/core").Machine<SliderSchema>;