@zag-js/slider 0.2.6 → 0.2.8

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.
@@ -0,0 +1,48 @@
1
+ import * as _zag_js_types from '@zag-js/types';
2
+ import { MachineContext, Point, SharedContext } from './slider.types.js';
3
+ import '@zag-js/core';
4
+
5
+ declare const dom: {
6
+ getRootNode: (ctx: {
7
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
8
+ }) => Document | ShadowRoot;
9
+ getDoc: (ctx: {
10
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
11
+ }) => Document;
12
+ getWin: (ctx: {
13
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
14
+ }) => Window & typeof globalThis;
15
+ getActiveElement: (ctx: {
16
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
17
+ }) => HTMLElement | null;
18
+ getById: <T = HTMLElement>(ctx: {
19
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
20
+ }, id: string) => T | null;
21
+ } & {
22
+ getRootId: (ctx: MachineContext) => string;
23
+ getThumbId: (ctx: MachineContext) => string;
24
+ getControlId: (ctx: MachineContext) => string;
25
+ getHiddenInputId: (ctx: MachineContext) => string;
26
+ getOutputId: (ctx: MachineContext) => string;
27
+ getTrackId: (ctx: MachineContext) => string;
28
+ getRangeId: (ctx: MachineContext) => string;
29
+ getLabelId: (ctx: MachineContext) => string;
30
+ getMarkerId: (ctx: MachineContext, value: number) => string;
31
+ getRootEl: (ctx: MachineContext) => HTMLElement | null;
32
+ getThumbEl: (ctx: MachineContext) => HTMLElement | null;
33
+ getControlEl: (ctx: MachineContext) => HTMLElement | null;
34
+ getHiddenInputEl: (ctx: MachineContext) => HTMLInputElement | null;
35
+ getValueFromPoint(ctx: MachineContext, point: Point): number | undefined;
36
+ dispatchChangeEvent(ctx: MachineContext): void;
37
+ getThumbOffset: (ctx: SharedContext) => string;
38
+ getControlStyle: () => _zag_js_types.JSX.CSSProperties;
39
+ getThumbStyle: (ctx: SharedContext) => _zag_js_types.JSX.CSSProperties;
40
+ getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => _zag_js_types.JSX.CSSProperties;
41
+ getRootStyle: (ctx: MachineContext) => _zag_js_types.JSX.CSSProperties;
42
+ getMarkerStyle: (ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number) => _zag_js_types.JSX.CSSProperties;
43
+ getLabelStyle: () => _zag_js_types.JSX.CSSProperties;
44
+ getTrackStyle: () => _zag_js_types.JSX.CSSProperties;
45
+ getMarkerGroupStyle: () => _zag_js_types.JSX.CSSProperties;
46
+ };
47
+
48
+ export { dom };
@@ -0,0 +1,297 @@
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
+ dom: () => dom
24
+ });
25
+ module.exports = __toCommonJS(slider_dom_exports);
26
+
27
+ // ../../utilities/dom/src/query.ts
28
+ function isDocument(el) {
29
+ return el.nodeType === Node.DOCUMENT_NODE;
30
+ }
31
+ function isWindow(value) {
32
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
33
+ }
34
+ function getDocument(el) {
35
+ var _a;
36
+ if (isWindow(el))
37
+ return el.document;
38
+ if (isDocument(el))
39
+ return el;
40
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
41
+ }
42
+ function getWindow(el) {
43
+ var _a;
44
+ return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
45
+ }
46
+ function defineDomHelpers(helpers) {
47
+ const dom2 = {
48
+ getRootNode: (ctx) => {
49
+ var _a, _b;
50
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
51
+ },
52
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
53
+ getWin: (ctx) => {
54
+ var _a;
55
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
56
+ },
57
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
58
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
59
+ };
60
+ return {
61
+ ...dom2,
62
+ ...helpers
63
+ };
64
+ }
65
+
66
+ // ../../utilities/dom/src/get-element-offset.ts
67
+ function getElementOffset(element) {
68
+ let left = 0;
69
+ let top = 0;
70
+ let el = element;
71
+ if (el.parentNode) {
72
+ do {
73
+ left += el.offsetLeft;
74
+ top += el.offsetTop;
75
+ } while ((el = el.offsetParent) && el.nodeType < 9);
76
+ el = element;
77
+ do {
78
+ left -= el.scrollLeft;
79
+ top -= el.scrollTop;
80
+ } while ((el = el.parentNode) && !/body/i.test(el.nodeName));
81
+ }
82
+ return {
83
+ top,
84
+ right: innerWidth - left - element.offsetWidth,
85
+ bottom: innerHeight - top - element.offsetHeight,
86
+ left
87
+ };
88
+ }
89
+
90
+ // ../../utilities/dom/src/get-point-relative-to-element.ts
91
+ function getPointRelativeToNode(point, element) {
92
+ const offset = getElementOffset(element);
93
+ const x = point.x - offset.left;
94
+ const y = point.y - offset.top;
95
+ return { x, y };
96
+ }
97
+
98
+ // ../../utilities/form-utils/src/input-event.ts
99
+ function getDescriptor(el, options) {
100
+ var _a;
101
+ const { type, property = "value" } = options;
102
+ const proto = getWindow(el)[type].prototype;
103
+ return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
104
+ }
105
+ function dispatchInputValueEvent(el, value) {
106
+ var _a;
107
+ if (!el)
108
+ return;
109
+ const win = getWindow(el);
110
+ if (!(el instanceof win.HTMLInputElement))
111
+ return;
112
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
113
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
114
+ const event = new win.Event("input", { bubbles: true });
115
+ el.dispatchEvent(event);
116
+ }
117
+
118
+ // src/slider.dom.ts
119
+ var import_numeric_range2 = require("@zag-js/numeric-range");
120
+
121
+ // src/slider.style.ts
122
+ var import_numeric_range = require("@zag-js/numeric-range");
123
+ function getVerticalThumbOffset(ctx) {
124
+ var _a;
125
+ const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
126
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
127
+ return parseFloat(getValue(ctx.value).toFixed(2));
128
+ }
129
+ function getHorizontalThumbOffset(ctx) {
130
+ var _a;
131
+ const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
132
+ if (ctx.isRtl) {
133
+ const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
134
+ return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
135
+ }
136
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
137
+ return parseFloat(getValue(ctx.value).toFixed(2));
138
+ }
139
+ function getThumbOffset(ctx) {
140
+ const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
141
+ if (ctx.thumbAlignment === "center") {
142
+ return `${percent}%`;
143
+ }
144
+ const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
145
+ return `calc(${percent}% - ${offset}px)`;
146
+ }
147
+ function getVisibility(ctx) {
148
+ let visibility = "visible";
149
+ if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
150
+ visibility = "hidden";
151
+ }
152
+ return visibility;
153
+ }
154
+ function getThumbStyle(ctx) {
155
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
156
+ return {
157
+ visibility: getVisibility(ctx),
158
+ position: "absolute",
159
+ transform: "var(--slider-thumb-transform)",
160
+ [placementProp]: "var(--slider-thumb-offset)"
161
+ };
162
+ }
163
+ function getRangeOffsets(ctx) {
164
+ let start = "0%";
165
+ let end = `${100 - ctx.valuePercent}%`;
166
+ if (ctx.origin === "center") {
167
+ const isNegative = ctx.valuePercent < 50;
168
+ start = isNegative ? `${ctx.valuePercent}%` : "50%";
169
+ end = isNegative ? "50%" : end;
170
+ }
171
+ return { start, end };
172
+ }
173
+ function getRangeStyle(ctx) {
174
+ if (ctx.isVertical) {
175
+ return {
176
+ position: "absolute",
177
+ bottom: "var(--slider-range-start)",
178
+ top: "var(--slider-range-end)"
179
+ };
180
+ }
181
+ return {
182
+ position: "absolute",
183
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
184
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
185
+ };
186
+ }
187
+ function getControlStyle() {
188
+ return {
189
+ touchAction: "none",
190
+ userSelect: "none",
191
+ position: "relative"
192
+ };
193
+ }
194
+ function getRootStyle(ctx) {
195
+ const range = getRangeOffsets(ctx);
196
+ return {
197
+ "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
198
+ "--slider-thumb-offset": getThumbOffset(ctx),
199
+ "--slider-range-start": range.start,
200
+ "--slider-range-end": range.end
201
+ };
202
+ }
203
+ function getMarkerStyle(ctx, percent) {
204
+ return {
205
+ position: "absolute",
206
+ pointerEvents: "none",
207
+ [ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
208
+ };
209
+ }
210
+ function getLabelStyle() {
211
+ return { userSelect: "none" };
212
+ }
213
+ function getTrackStyle() {
214
+ return { position: "relative" };
215
+ }
216
+ function getMarkerGroupStyle() {
217
+ return {
218
+ userSelect: "none",
219
+ pointerEvents: "none",
220
+ position: "relative"
221
+ };
222
+ }
223
+ var styles = {
224
+ getThumbOffset,
225
+ getControlStyle,
226
+ getThumbStyle,
227
+ getRangeStyle,
228
+ getRootStyle,
229
+ getMarkerStyle,
230
+ getLabelStyle,
231
+ getTrackStyle,
232
+ getMarkerGroupStyle
233
+ };
234
+
235
+ // src/slider.dom.ts
236
+ var dom = defineDomHelpers({
237
+ ...styles,
238
+ getRootId: (ctx) => {
239
+ var _a, _b;
240
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
241
+ },
242
+ getThumbId: (ctx) => {
243
+ var _a, _b;
244
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
245
+ },
246
+ getControlId: (ctx) => {
247
+ var _a, _b;
248
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
249
+ },
250
+ getHiddenInputId: (ctx) => `slider:${ctx.id}:input`,
251
+ getOutputId: (ctx) => {
252
+ var _a, _b;
253
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
254
+ },
255
+ getTrackId: (ctx) => {
256
+ var _a, _b;
257
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
258
+ },
259
+ getRangeId: (ctx) => {
260
+ var _a, _b;
261
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
262
+ },
263
+ getLabelId: (ctx) => {
264
+ var _a, _b;
265
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
266
+ },
267
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
268
+ getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
269
+ getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
270
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
271
+ getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
272
+ getValueFromPoint(ctx, point) {
273
+ const el = dom.getControlEl(ctx);
274
+ if (!el)
275
+ return;
276
+ const relativePoint = getPointRelativeToNode(point, el);
277
+ const percentX = relativePoint.x / el.offsetWidth;
278
+ const percentY = relativePoint.y / el.offsetHeight;
279
+ let percent;
280
+ if (ctx.isHorizontal) {
281
+ percent = ctx.isRtl ? 1 - percentX : percentX;
282
+ } else {
283
+ percent = 1 - percentY;
284
+ }
285
+ return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
286
+ },
287
+ dispatchChangeEvent(ctx) {
288
+ const input = dom.getHiddenInputEl(ctx);
289
+ if (!input)
290
+ return;
291
+ dispatchInputValueEvent(input, ctx.value);
292
+ }
293
+ });
294
+ // Annotate the CommonJS export names for ESM import in node:
295
+ 0 && (module.exports = {
296
+ dom
297
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ dom
3
+ } from "./chunk-J5IGGBVE.mjs";
4
+ import "./chunk-YREEXXZP.mjs";
5
+ export {
6
+ dom
7
+ };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { UserDefinedContext, MachineContext, MachineState } from './slider.types.js';
3
+ import '@zag-js/types';
4
+
5
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
6
+
7
+ export { machine };